Example #1
0
        public double GetStoichiometricFactor(MolecularComponent comp)
        {
            var pair = Stoichiometry.FirstOrDefault(s => s.Component == comp);

            if (pair != null)
            {
                return(pair.StoichiometricFactor);
            }
            else
            {
                return(0);
            }
        }
Example #2
0
        public Expression GetReactingMolesExpression(Expression[] reactionRates, MolecularComponent comp)
        {
            Expression reactingMoles = 0;

            for (int j = 0; j < Reactions.Count; j++)
            {
                var nu = Reactions[j].GetStoichiometricFactor(comp);
                if (Math.Abs(nu) > 1e-16)
                {
                    reactingMoles += nu * reactionRates[j];
                }
            }
            return(reactingMoles);
        }
Example #3
0
        public MolecularComponent FindComponent(string name)
        {
            if (db == null)
            {
                db = XElement.Load(".\\data\\chemsep1.xml");
            }

            var comps = from nm in db.Elements("compound")
                        where (string)nm.Element("CompoundID").Attribute("value") == name
                        select nm;


            if (comps.Count() == 1)
            {
                var c         = comps.First();
                var component = new MolecularComponent()
                {
                    Name      = name,
                    ID        = name,
                    CasNumber = (string)c.Element("CAS").Attribute("value")
                };

                component.Constants.Add(GetConstant(c.Element("MolecularWeight"), ConstantProperties.MolarWeight));
                component.Constants.Add(GetConstant(c.Element("CriticalTemperature"), ConstantProperties.CriticalTemperature));
                component.Constants.Add(GetConstant(c.Element("CriticalPressure"), ConstantProperties.CriticalPressure));
                component.Constants.Add(GetConstant(c.Element("AcentricityFactor"), ConstantProperties.AcentricFactor));

                component.Functions.Add(GetFunction(c.Element("VaporPressure"), EvaluatedProperties.VaporPressure));
                component.Functions.Add(GetFunction(c.Element("HeatOfVaporization"), EvaluatedProperties.HeatOfVaporization));

                component.Functions.Add(GetFunction(c.Element("LiquidDensity"), EvaluatedProperties.LiquidDensity));
                component.Functions.Add(GetFunction(c.Element("LiquidHeatCapacityCp"), EvaluatedProperties.LiquidHeatCapacity));
                component.Functions.Add(GetFunction(c.Element("LiquidViscosity"), EvaluatedProperties.LiquidViscosity));
                component.Functions.Add(GetFunction(c.Element("LiquidThermalConductivity"), EvaluatedProperties.LiquidHeatConductivity));

                component.Functions.Add(GetFunction(c.Element("RPPHeatCapacityCp"), EvaluatedProperties.IdealGasHeatCapacity));
                component.Functions.Add(GetFunction(c.Element("VaporViscosity"), EvaluatedProperties.VaporViscosity));
                component.Functions.Add(GetFunction(c.Element("VaporThermalConductivity"), EvaluatedProperties.VaporHeatConductivity));

                component.Functions.Add(GetFunction(c.Element("SurfaceTension"), EvaluatedProperties.SurfaceTension));


                if (c.Element("UniquacR") != null && c.Element("UniquacQ") != null)
                {
                    var r = (double)c.Element("UniquacR").Attribute("value");
                    var q = (double)c.Element("UniquacQ").Attribute("value");

                    var uniquacPure = new MethodConstantParameters();
                    uniquacPure.Method = MethodTypes.Uniquac;
                    uniquacPure.Parameters.Add("R", new Variable("UniquacR", r));
                    uniquacPure.Parameters.Add("Q", new Variable("UniquacQ", q));
                    uniquacPure.Parameters.Add("Q'", new Variable("UniquacQ'", q));
                    component.MethodParameters.Add(uniquacPure);
                }

                /*
                 *   var uniquacPure = new MethodConstantParameters();
                 * uniquacPure.Method = MethodTypes.Uniquac;
                 * uniquacPure.Parameters.Add("R", new Variable("UniquacR", r));
                 * uniquacPure.Parameters.Add("Q", new Variable("UniquacQ", q));
                 * uniquacPure.Parameters.Add("Q'", new Variable("UniquacQ'", qp));
                 * comp1.MethodParameters.Add(uniquacPure);
                 * */
                //CPIG, HVAP, CL, DENL, VP
                return(component);
            }
            else
            {
                throw new ArgumentException("No compound found for name " + name);
            }
        }
Example #4
0
        MolecularComponent DefaultComponent(string name, string id)
        {
            var newComp = new MolecularComponent();

            newComp.Name      = name;
            newComp.ID        = id;
            newComp.CasNumber = "123-456-7";
            newComp.Constants.Add(new OpenFMSL.Core.Expressions.Variable("MolarWeight", 0.018, SI.kg / SI.mol));
            newComp.Constants.Add(new OpenFMSL.Core.Expressions.Variable("CriticalTemperature", 600, SI.K));
            newComp.Constants.Add(new OpenFMSL.Core.Expressions.Variable("CriticalPressure", 221e5, SI.Pa));
            newComp.Constants.Add(new OpenFMSL.Core.Expressions.Variable("CriticalDensity", 0.1, SI.kmol / SI.cum));
            newComp.Constants.Add(new OpenFMSL.Core.Expressions.Variable("HeatOfFormation", 0, SI.J / SI.kmol));
            newComp.Constants.Add(new OpenFMSL.Core.Expressions.Variable("AcentricFactor", 0.3, SI.nil));
            //  newComp.Constants.Add(new OpenFMSL.Core.Expressions.Variable("UniquacR", 0));
            //   newComp.Constants.Add(new OpenFMSL.Core.Expressions.Variable("UniquacQ", 0));
            // newComp.Constants.Add(new OpenFMSL.Core.Expressions.Variable("UniquacQP", 0));

            //newComp.Constants.Add(new OpenFMSL.Core.Expressions.Variable("RKSA", 0));
            //newComp.Constants.Add(new OpenFMSL.Core.Expressions.Variable("RKSB", 0));

            newComp.Functions.Add(new PropertyFunction()
            {
                Type         = FunctionType.Polynomial,
                Property     = EvaluatedProperties.VaporPressure,
                Coefficients = new List <OpenFMSL.Core.Expressions.Variable> {
                    new OpenFMSL.Core.Expressions.Variable("C1", 1)
                },
                MinimumX = new OpenFMSL.Core.Expressions.Variable("Tmin", 1),
                MaximumX = new OpenFMSL.Core.Expressions.Variable("Tmax", 1000),
                XUnit    = SI.K,
                YUnit    = GetSIUnitForTProperty("VP")
            });

            newComp.Functions.Add(new PropertyFunction()
            {
                Type         = FunctionType.Polynomial,
                Property     = EvaluatedProperties.IdealGasHeatCapacity,
                Coefficients = new List <OpenFMSL.Core.Expressions.Variable> {
                    new OpenFMSL.Core.Expressions.Variable("C1", 0)
                },
                MinimumX = new OpenFMSL.Core.Expressions.Variable("Tmin", 1),
                MaximumX = new OpenFMSL.Core.Expressions.Variable("Tmax", 1000),
                XUnit    = SI.K,
                YUnit    = GetSIUnitForTProperty("CPID")
            });

            newComp.Functions.Add(new PropertyFunction()
            {
                Type         = FunctionType.Polynomial,
                Property     = EvaluatedProperties.LiquidHeatCapacity,
                Coefficients = new List <OpenFMSL.Core.Expressions.Variable> {
                    new OpenFMSL.Core.Expressions.Variable("C1", 0)
                },
                MinimumX = new OpenFMSL.Core.Expressions.Variable("Tmin", 1),
                MaximumX = new OpenFMSL.Core.Expressions.Variable("Tmax", 1000),
                XUnit    = SI.K,
                YUnit    = GetSIUnitForTProperty("CL")
            });
            newComp.Functions.Add(new PropertyFunction()
            {
                Type         = FunctionType.Polynomial,
                Property     = EvaluatedProperties.LiquidDensity,
                Coefficients = new List <OpenFMSL.Core.Expressions.Variable> {
                    new OpenFMSL.Core.Expressions.Variable("C1", 0)
                },
                MinimumX = new OpenFMSL.Core.Expressions.Variable("Tmin", 1),
                MaximumX = new OpenFMSL.Core.Expressions.Variable("Tmax", 1000),
                XUnit    = SI.K,
                YUnit    = GetSIUnitForTProperty("DENL")
            });
            newComp.Functions.Add(new PropertyFunction()
            {
                Type         = FunctionType.Polynomial,
                Property     = EvaluatedProperties.HeatOfVaporization,
                Coefficients = new List <OpenFMSL.Core.Expressions.Variable> {
                    new OpenFMSL.Core.Expressions.Variable("C1", 0)
                },
                MinimumX = new OpenFMSL.Core.Expressions.Variable("Tmin", 1),
                MaximumX = new OpenFMSL.Core.Expressions.Variable("Tmax", 1000),
                XUnit    = SI.K,
                YUnit    = GetSIUnitForTProperty("HVAP")
            });

            newComp.Functions.Add(new PropertyFunction()
            {
                Type         = FunctionType.Polynomial,
                Property     = EvaluatedProperties.SurfaceTension,
                Coefficients = new List <OpenFMSL.Core.Expressions.Variable> {
                    new OpenFMSL.Core.Expressions.Variable("C1", 0)
                },
                MinimumX = new OpenFMSL.Core.Expressions.Variable("Tmin", 1),
                MaximumX = new OpenFMSL.Core.Expressions.Variable("Tmax", 1000),
                XUnit    = SI.K,
                YUnit    = GetSIUnitForTProperty("ST")
            });
            newComp.Functions.Add(new PropertyFunction()
            {
                Type         = FunctionType.Polynomial,
                Property     = EvaluatedProperties.LiquidHeatConductivity,
                Coefficients = new List <OpenFMSL.Core.Expressions.Variable> {
                    new OpenFMSL.Core.Expressions.Variable("C1", 0)
                },
                MinimumX = new OpenFMSL.Core.Expressions.Variable("Tmin", 1),
                MaximumX = new OpenFMSL.Core.Expressions.Variable("Tmax", 1000),
                XUnit    = SI.K,
                YUnit    = GetSIUnitForTProperty("KLIQ")
            });

            newComp.Functions.Add(new PropertyFunction()
            {
                Type         = FunctionType.Polynomial,
                Property     = EvaluatedProperties.VaporHeatConductivity,
                Coefficients = new List <OpenFMSL.Core.Expressions.Variable> {
                    new OpenFMSL.Core.Expressions.Variable("C1", 0)
                },
                MinimumX = new OpenFMSL.Core.Expressions.Variable("Tmin", 1),
                MaximumX = new OpenFMSL.Core.Expressions.Variable("Tmax", 1000),
                XUnit    = SI.K,
                YUnit    = GetSIUnitForTProperty("KVAP")
            });

            newComp.Functions.Add(new PropertyFunction()
            {
                Type         = FunctionType.Polynomial,
                Property     = EvaluatedProperties.LiquidViscosity,
                Coefficients = new List <OpenFMSL.Core.Expressions.Variable> {
                    new OpenFMSL.Core.Expressions.Variable("C1", 0)
                },
                MinimumX = new OpenFMSL.Core.Expressions.Variable("Tmin", 1),
                MaximumX = new OpenFMSL.Core.Expressions.Variable("Tmax", 1000),
                XUnit    = SI.K,
                YUnit    = GetSIUnitForTProperty("VISL")
            });

            newComp.Functions.Add(new PropertyFunction()
            {
                Type         = FunctionType.Polynomial,
                Property     = EvaluatedProperties.VaporViscosity,
                Coefficients = new List <OpenFMSL.Core.Expressions.Variable> {
                    new OpenFMSL.Core.Expressions.Variable("C1", 0)
                },
                MinimumX = new OpenFMSL.Core.Expressions.Variable("Tmin", 1),
                MaximumX = new OpenFMSL.Core.Expressions.Variable("Tmax", 1000),
                XUnit    = SI.K,
                YUnit    = GetSIUnitForTProperty("VISV")
            });

            return(newComp);
        }
Example #5
0
 public StoichiometryPair(int index, MolecularComponent component, double factor)
 {
     Index                = index;
     Component            = component;
     StoichiometricFactor = factor;
 }