예제 #1
0
        public Expression CreateIntegratedExpression(FunctionType typeToCreate, PropertyFunction func, Variable T, Variable Tref)
        {
            Expression expr = null;

            switch (typeToCreate)
            {
            case FunctionType.PolynomialIntegrated:

                EnsureCoefficients(func.Coefficients, 1);
                expr = func.Coefficients[0] * Sym.Par(T - Tref);

                for (int i = 1; i < func.NumberOfCoefficients; i++)
                {
                    expr += 1.0 / (double)(i + 1) * func.Coefficients[i] * Sym.Par(Sym.Pow(T, i + 1) - Sym.Pow(Tref, i + 1));
                }
                break;

            case FunctionType.Dippr117:
            {
                EnsureCoefficients(func.Coefficients, 5);
                var Tcon    = Sym.Convert(T, func.XUnit);
                var Trefcon = Sym.Convert(Tref, func.XUnit);

                expr = func.Coefficients[0] * Sym.Par(Tcon - Trefcon) + func.Coefficients[1] * func.Coefficients[2] * Sym.Par(Sym.Coth(func.Coefficients[2] / Tcon) - Sym.Coth(func.Coefficients[2] / Trefcon)) - func.Coefficients[3] * func.Coefficients[4] * Sym.Par(Sym.Tanh(func.Coefficients[4] / Tcon) - Sym.Tanh(func.Coefficients[4] / Trefcon));
                break;
            }
            }
            return(expr);
        }
예제 #2
0
        public Variable GetAverageVaporViscosityExpression(ThermodynamicSystem system, Variable[] y, Variable T, Variable p)
        {
            var      NC   = system.Components.Count;
            var      visv = Sym.Sum(0, NC, j => y[j] * Sym.Sqrt(Sym.Convert(system.Components[j].MolarWeight, system.VariableFactory.Internal.UnitDictionary[PhysicalDimension.MolarWeight])) * GetVaporViscosityExpression(system, system.Components[j], T, p)) / Sym.Sum(0, NC, j => y[j] * Sym.Sqrt(Sym.Convert(system.Components[j].MolarWeight, system.VariableFactory.Internal.UnitDictionary[PhysicalDimension.MolarWeight])));
            Variable prop = new Variable("VISV" + "(" + T.FullName + ")", 1);

            prop.Subscript = "avg";
            prop.BindTo(visv);
            return(prop);
        }
예제 #3
0
        public Variable GetAverageMolarWeightExpression(ThermodynamicSystem system, Variable[] z)
        {
            var      NC   = system.Components.Count;
            var      molw = Sym.Sum(0, NC, j => Sym.Convert(system.Components[j].MolarWeight, system.VariableFactory.Internal.UnitDictionary[PhysicalDimension.MolarWeight]) * z[j]);
            Variable prop = new Variable("MOLW", 1);

            prop.Subscript = "avg";
            prop.BindTo(molw);
            return(prop);
        }
예제 #4
0
파일: Valve.cs 프로젝트: shao130/OpenFMSL
        public override void FillEquationSystem(EquationSystem problem)
        {
            int NC  = System.Components.Count;
            var In  = FindMaterialPort("In");
            var Out = FindMaterialPort("Out");


            for (int i = 0; i < NC; i++)
            {
                var cindex = i;
                AddEquationToEquationSystem(problem,
                                            Sym.Sum(0, In.NumberOfStreams, (j) => In.Streams[j].Mixed.ComponentMolarflow[cindex])
                                            .IsEqualTo(Sym.Sum(0, Out.NumberOfStreams, (j) => Out.Streams[j].Mixed.ComponentMolarflow[cindex])), "Mass Balance");
            }

            AddEquationToEquationSystem(problem, (p1 / 1e4).IsEqualTo(Sym.Par(In.Streams[0].Mixed.Pressure) / 1e4), "Pressure Balance");
            AddEquationToEquationSystem(problem, (p2 / 1e4).IsEqualTo(Sym.Par(Out.Streams[0].Mixed.Pressure) / 1e4), "Pressure Balance");
            AddEquationToEquationSystem(problem, (dp / 1e4).IsEqualTo(Sym.Par(p1 - p2) / 1e4), "Pressure drop");


            if (CharacteristicCurve != ValveCharacteristic.User)
            {
                AddEquationToEquationSystem(problem, (Opening).IsEqualTo(GetCharacteristicCurve()), "Performance");
            }
            AddEquationToEquationSystem(problem, (KV).IsEqualTo(Opening / 100 * KVS), "Performance");

            if (Mode == FlowMode.Compressible)
            {
                AddEquationToEquationSystem(problem, (Sym.Convert(Out.Streams[0].Mixed.TotalVolumeflow, (SI.m ^ 3) / SI.h)).IsEqualTo(KV * Sym.Sqrt(Sym.Convert(dp, METRIC.bar) * Out.Streams[0].Mixed.Density / 999.07)), "Performance");
            }
            else if (Mode == FlowMode.Incompressible)
            {
            }
            else if (Mode == FlowMode.Multiphase)
            {
            }


            //Isenthalpic Valve
            AddEquationToEquationSystem(problem,
                                        ((Sym.Sum(0, In.NumberOfStreams, (i) => In.Streams[i].Mixed.SpecificEnthalpy * In.Streams[i].Mixed.TotalMolarflow) / 1e4))
                                        .IsEqualTo(Sym.Par(Sym.Sum(0, Out.NumberOfStreams, (i) => Out.Streams[i].Mixed.SpecificEnthalpy * Out.Streams[i].Mixed.TotalMolarflow)) / 1e4), "Heat Balance");

            base.FillEquationSystem(problem);
        }
예제 #5
0
        private void performMassBalance(MaterialStream stream, Variable[] K)
        {
            var NC = stream.System.Components.Count;

            stream.Vapor.TotalMolarflow.ValueInSI = stream.Vfmolar.ValueInSI * stream.Mixed.TotalMolarflow.ValueInSI;

            stream.Liquid.TotalMolarflow.ValueInSI = stream.Mixed.TotalMolarflow.ValueInSI - stream.Vapor.TotalMolarflow.ValueInSI;
            var eval = new Evaluator();

            for (int i = 0; i < NC; i++)
            {
                eval.Reset();
                stream.Liquid.ComponentMolarFraction[i].ValueInSI = (stream.Mixed.ComponentMolarFraction[i] / (1 + stream.Vfmolar * (K[i] - 1))).Eval(eval);
                stream.Vapor.ComponentMolarFraction[i].ValueInSI  = (stream.Liquid.ComponentMolarFraction[i] * K[i]).Eval(eval);

                stream.Liquid.ComponentMolarflow[i].ValueInSI = stream.Liquid.ComponentMolarFraction[i].ValueInSI * stream.Liquid.TotalMolarflow.ValueInSI;
                stream.Vapor.ComponentMolarflow[i].ValueInSI  = stream.Vapor.ComponentMolarFraction[i].ValueInSI * stream.Vapor.TotalMolarflow.ValueInSI;

                stream.Liquid.ComponentMassflow[i].ValueInSI = (stream.Liquid.ComponentMolarflow[i] * Sym.Convert(stream.System.Components[i].GetConstant(ConstantProperties.MolarWeight), stream.System.VariableFactory.Internal.UnitDictionary[PhysicalDimension.Mass] / stream.System.VariableFactory.Internal.UnitDictionary[PhysicalDimension.Mole])).Eval(eval);
                stream.Vapor.ComponentMassflow[i].ValueInSI  = (stream.Vapor.ComponentMolarflow[i] * Sym.Convert(stream.System.Components[i].GetConstant(ConstantProperties.MolarWeight), stream.System.VariableFactory.Internal.UnitDictionary[PhysicalDimension.Mass] / stream.System.VariableFactory.Internal.UnitDictionary[PhysicalDimension.Mole])).Eval(eval);
                stream.Mixed.ComponentMassflow[i].ValueInSI  = (stream.Mixed.ComponentMolarflow[i] * Sym.Convert(stream.System.Components[i].GetConstant(ConstantProperties.MolarWeight), stream.System.VariableFactory.Internal.UnitDictionary[PhysicalDimension.Mass] / stream.System.VariableFactory.Internal.UnitDictionary[PhysicalDimension.Mole])).Eval(eval);
            }

            stream.Mixed.TotalMassflow.ValueInSI  = stream.Mixed.ComponentMassflow.Sum(v => v.ValueInSI);
            stream.Vapor.TotalMassflow.ValueInSI  = stream.Vapor.ComponentMassflow.Sum(v => v.ValueInSI);
            stream.Liquid.TotalMassflow.ValueInSI = stream.Liquid.ComponentMassflow.Sum(v => v.ValueInSI);

            for (int i = 0; i < NC; i++)
            {
                eval.Reset();

                if (stream.Liquid.TotalMassflow.ValueInSI <= 1e-8)
                {
                    stream.Liquid.ComponentMassFraction[i].ValueInSI = 0;
                }
                else
                {
                    stream.Liquid.ComponentMassFraction[i].ValueInSI = (stream.Liquid.ComponentMassflow[i] / stream.Liquid.TotalMassflow).Eval(eval);
                }

                if (stream.Vapor.TotalMassflow.ValueInSI <= 1e-8)
                {
                    stream.Vapor.ComponentMassFraction[i].ValueInSI = 0;
                }
                else
                {
                    stream.Vapor.ComponentMassFraction[i].ValueInSI = (stream.Vapor.ComponentMassflow[i] / stream.Vapor.TotalMassflow).Eval(eval);
                }

                stream.Mixed.ComponentMassFraction[i].ValueInSI = (stream.Mixed.ComponentMassflow[i] / stream.Mixed.TotalMassflow.ValueInSI).Eval(eval);
            }
        }
예제 #6
0
        public Expression CreateExpression(FunctionType typeToCreate, PropertyFunction func, Variable T, Variable TC, Variable PC)
        {
            Expression expr = null;

            switch (typeToCreate)
            {
            case FunctionType.Polynomial:

                //if (func.NumberOfCoefficients < 1)
                //   throw new InvalidOperationException("Not enough coefficients to create an expression");
                EnsureCoefficients(func.Coefficients, 1);

                expr = func.Coefficients[0];

                for (int i = 1; i < func.NumberOfCoefficients; i++)
                {
                    expr += func.Coefficients[i] * Sym.Pow(T, i);
                }
                break;

            case FunctionType.PolynomialIntegrated:

                EnsureCoefficients(func.Coefficients, 1);
                expr = func.Coefficients[0] * T;

                for (int i = 1; i < func.NumberOfCoefficients; i++)
                {
                    expr += 1.0 / (double)(i + 1) * func.Coefficients[i] * Sym.Pow(T, i + 1);
                }
                break;

            case FunctionType.Dippr106:
                if (System.Math.Abs(TC.ValueInSI - func.Coefficients[0].ValueInSI) < 1e-6)
                {
                    EnsureCoefficients(func.Coefficients, 6);
                    var TR = Sym.Par(T / func.Coefficients[0]);
                    var h  = func.Coefficients[2] + func.Coefficients[3] * TR + func.Coefficients[4] * Sym.Pow(TR, 2) + func.Coefficients[5] * Sym.Pow(TR, 3);
                    expr = func.Coefficients[1] * Sym.Pow(Sym.Par(1 - TR), h);
                }
                else
                {
                    EnsureCoefficients(func.Coefficients, 6);
                    var TR = Sym.Par(T / TC);
                    var h  = func.Coefficients[2] + func.Coefficients[3] * TR + func.Coefficients[4] * Sym.Pow(TR, 2) + func.Coefficients[5] * Sym.Pow(TR, 3);
                    expr = func.Coefficients[1] * Sym.Pow(Sym.Par(1 - TR), h);
                }
                break;

            case FunctionType.Dippr117:
            {
                EnsureCoefficients(func.Coefficients, 5);

                var Tcon = Sym.Convert(T, func.XUnit);
                expr = func.Coefficients[0] * Tcon + func.Coefficients[1] * func.Coefficients[2] * Sym.Coth(func.Coefficients[2] / Tcon) - func.Coefficients[3] * func.Coefficients[4] * Sym.Tanh(func.Coefficients[4] / Tcon);
                break;
            }

            case FunctionType.AlyLee:
            {
                EnsureCoefficients(func.Coefficients, 5);

                Expression Tcon = T;
                if (!Unit.AreEquivalent(SI.K, func.XUnit))
                {
                    Tcon = Sym.Convert(T, func.XUnit);
                }

                expr = func.Coefficients[0] + func.Coefficients[1] * Sym.Pow(Sym.Par((func.Coefficients[2] / Tcon) / Sym.Sinh(func.Coefficients[2] / Tcon)), 2) + func.Coefficients[3] * Sym.Pow(Sym.Par((func.Coefficients[4] / Tcon) / Sym.Cosh(func.Coefficients[4] / Tcon)), 2);
                break;
            }

            case FunctionType.Antoine:
            {
                EnsureCoefficients(func.Coefficients, 3);
                Expression CT = T;
                if (!Unit.AreEquivalent(SI.K, func.XUnit))
                {
                    CT = Sym.Convert(T, func.XUnit);
                }


                expr = Sym.Exp(func.Coefficients[0] - func.Coefficients[1] / Sym.Par(func.Coefficients[2] + CT));
                break;
            }

            case FunctionType.ExtendedAntoine:
            {
                EnsureCoefficients(func.Coefficients, 7);
                Expression CT = T;
                if (!Unit.AreEquivalent(SI.K, func.XUnit))
                {
                    CT = Sym.Convert(T, func.XUnit);
                }

                expr = (Sym.Exp(func.Coefficients[0] + func.Coefficients[1] / Sym.Par(func.Coefficients[2] + CT) + func.Coefficients[3] * CT + func.Coefficients[4] * Sym.Ln(CT) + func.Coefficients[5] * Sym.Pow(CT, func.Coefficients[6])));

                break;
            }

            case FunctionType.Rackett:
            {
                EnsureCoefficients(func.Coefficients, 4);
                var TR = Sym.Convert(T, func.XUnit) / func.Coefficients[2];
                expr = func.Coefficients[0] / (Sym.Pow(func.Coefficients[1], 1 + Sym.Pow(Sym.Par(1 - TR), func.Coefficients[3])));

                break;
            }

            case FunctionType.Wagner:
            {
                EnsureCoefficients(func.Coefficients, 6);

                if (TC == null || PC == null)
                {
                    throw new InvalidOperationException("Not enough coefficients to create an expression");
                }
                var TR  = Sym.Convert(T, func.XUnit) / TC;
                var tau = Sym.Par(1 - TR);
                expr = Sym.Exp(Sym.Ln(PC) + 1 / TR * Sym.Par(func.Coefficients[2] * tau + func.Coefficients[3] * Sym.Pow(tau, 1.5) + func.Coefficients[4] * Sym.Pow(tau, 3) + func.Coefficients[5] * Sym.Pow(tau, 6)));

                break;
            }

            case FunctionType.Watson:
            {
                EnsureCoefficients(func.Coefficients, 4);

                expr = func.Coefficients[0] * Sym.Pow(func.Coefficients[2] - T, func.Coefficients[1]) + func.Coefficients[3];
                break;
            }

            case FunctionType.Dippr102:
            {
                EnsureCoefficients(func.Coefficients, 4);

                expr = func.Coefficients[0] * Sym.Pow(T, func.Coefficients[1]) / (1 + func.Coefficients[2] / T + func.Coefficients[3] / T);
                break;
            }

            case FunctionType.Kirchhoff:
            {
                EnsureCoefficients(func.Coefficients, 3);

                expr = (Sym.Exp(func.Coefficients[0] - func.Coefficients[1] / T + func.Coefficients[2] * Sym.Ln(T)));
                break;
            }

            case FunctionType.Sutherland:
            {
                EnsureCoefficients(func.Coefficients, 2);

                expr = (func.Coefficients[0] * Sym.Sqrt(T)) / (1 + func.Coefficients[1] / T);
                break;
            }

            case FunctionType.Chemsep16:
            {
                EnsureCoefficients(func.Coefficients, 5);
                var a = func.Coefficients[0];
                var b = func.Coefficients[1];
                var c = func.Coefficients[2];
                var d = func.Coefficients[3];
                var e = func.Coefficients[4];
                expr = a + Sym.Exp(b / T + c + d * T + e * Sym.Pow(T, 2));
                break;
            }

            case FunctionType.Chemsep101:
            {
                EnsureCoefficients(func.Coefficients, 5);
                var a = func.Coefficients[0];
                var b = func.Coefficients[1];
                var c = func.Coefficients[2];
                var d = func.Coefficients[3];
                var e = func.Coefficients[4];
                expr = (Sym.Exp(a + b / T + c * Sym.Ln(T) + d * Sym.Pow(T, 2.0)));
                break;
            }

            case FunctionType.Chemsep102:
            {
                EnsureCoefficients(func.Coefficients, 5);
                var a = func.Coefficients[0];
                var b = func.Coefficients[1];
                var c = func.Coefficients[2];
                var d = func.Coefficients[3];
                var e = func.Coefficients[4];
                expr = a * Sym.Pow(T, b) / (1 + c / T + d / Sym.Pow(T, 2));
                break;
            }

            case FunctionType.Chemsep106:
            {
                EnsureCoefficients(func.Coefficients, 6);
                var TR = Sym.Par(T / TC);
                var h  = func.Coefficients[1] + func.Coefficients[2] * TR + func.Coefficients[3] * Sym.Pow(TR, 2) + func.Coefficients[4] * Sym.Pow(TR, 3);
                expr = func.Coefficients[0] * Sym.Pow(Sym.Par(1 - TR), h);
            }
            break;

            default:
                throw new InvalidOperationException("Unknown function type" + typeToCreate);
            }
            return(expr);
        }
예제 #7
0
        public override void FillEquationSystem(EquationSystem problem)
        {
            int NC = System.Components.Count;

            var vliq = Sym.Sum(0, NC, i => Liquid.ComponentMolarflow[i] * Liquid.ComponentMolarVolume[i]);
            var vvap = Vapor.TotalMolarflow / Vapor.DensityMolar;

            MW.BindTo(System.EquationFactory.GetAverageMolarWeightExpression(System, Mixed.ComponentMolarFraction.ToArray()));
            Liquid.TotalVolumeflow.BindTo(vliq);
            Vapor.TotalVolumeflow.BindTo(vvap);
            Mixed.TotalVolumeflow.BindTo(vliq + vvap);

            Mixed.TotalMassflow.BindTo(Sym.Sum(Mixed.ComponentMassflow));
            Liquid.TotalMassflow.BindTo(Sym.Sum(Liquid.ComponentMassflow));
            Vapor.TotalMassflow.BindTo(Sym.Sum(Vapor.ComponentMassflow));

            //Liquid.SpecificEnthalpy.BindTo(Sym.Par(Sym.Sum(0, NC, (idx) => Liquid.ComponentMolarFraction[idx] * Liquid.ComponentEnthalpy[idx])));
            //Vapor.SpecificEnthalpy.BindTo(Sym.Par(Sym.Sum(0, NC, (idx) => Vapor.ComponentMolarFraction[idx] * Vapor.ComponentEnthalpy[idx])));

            Liquid.SpecificEnthalpy.BindTo(new EnthalpyRoute(System, Mixed.Temperature, Mixed.Pressure, Liquid.ComponentMolarFraction, PhaseState.Liquid));
            Vapor.SpecificEnthalpy.BindTo(new EnthalpyRoute(System, Mixed.Temperature, Mixed.Pressure, Vapor.ComponentMolarFraction, PhaseState.Vapour));


            Mixed.Density.BindTo(Mixed.TotalMassflow / Mixed.TotalVolumeflow);
            Liquid.Density.BindTo(Liquid.TotalMassflow / Liquid.TotalVolumeflow);
            Vapor.Density.BindTo(Vapor.TotalMassflow / Vapor.TotalVolumeflow);

            Mixed.DensityMolar.BindTo(Mixed.TotalMolarflow / Mixed.TotalVolumeflow);
            Liquid.DensityMolar.BindTo(Liquid.TotalMolarflow / Liquid.TotalVolumeflow);
            Vapor.DensityMolar.BindTo(System.EquationFactory.GetAverageVaporDensityExpression(System, Mixed.Temperature, Mixed.Pressure, Vapor.ComponentMolarFraction));


            for (int i = 0; i < NC; i++)
            {
                Mixed.ComponentMassflow[i].BindTo(Mixed.ComponentMolarflow[i] * Sym.Convert(System.Components[i].GetConstant(ConstantProperties.MolarWeight), SI.kg / SI.mol));
                Mixed.ComponentMassFraction[i].BindTo(Mixed.ComponentMassflow[i] / Sym.Max(1e-12, Mixed.TotalMassflow));

                Liquid.ComponentMassflow[i].BindTo(Liquid.ComponentMolarflow[i] * Sym.Convert(System.Components[i].GetConstant(ConstantProperties.MolarWeight), SI.kg / SI.mol));
                Liquid.ComponentMassFraction[i].BindTo(Liquid.ComponentMassflow[i] / Sym.Max(1e-12, Liquid.TotalMassflow));

                Liquid.ComponentMolarVolume[i].BindTo((1.0 / System.EquationFactory.GetLiquidDensityExpression(System, System.Components[i], Mixed.Temperature, Mixed.Pressure)));
                Liquid.ComponentEnthalpy[i].BindTo(System.EquationFactory.GetLiquidEnthalpyExpression(System, i, Mixed.Temperature));

                Vapor.ComponentMassflow[i].BindTo(Vapor.ComponentMolarflow[i] * Sym.Convert(System.Components[i].GetConstant(ConstantProperties.MolarWeight), SI.kg / SI.mol));
                Vapor.ComponentMassFraction[i].BindTo(Vapor.ComponentMassflow[i] / Sym.Max(1e-12, Vapor.TotalMassflow));


                Vapor.ComponentEnthalpy[i].BindTo(System.EquationFactory.GetVaporEnthalpyExpression(System, i, Mixed.Temperature));
            }

            Mixed.TotalEnthalpy.BindTo(((Mixed.TotalMolarflow * Mixed.SpecificEnthalpy)));
            Liquid.TotalEnthalpy.BindTo(((Liquid.TotalMolarflow * Liquid.SpecificEnthalpy)));
            Vapor.TotalEnthalpy.BindTo(((Vapor.TotalMolarflow * Vapor.SpecificEnthalpy)));


            if (!Mixed.SpecificEnthalpy.IsFixed)
            {
                Mixed.SpecificEnthalpy.BindTo((Sym.Par(Vapor.TotalMolarflow * Vapor.SpecificEnthalpy + Liquid.TotalMolarflow * Liquid.SpecificEnthalpy) / Mixed.TotalMolarflow));
            }
            else
            {
                AddEquationToEquationSystem(problem, (Mixed.SpecificEnthalpy * Mixed.TotalMolarflow).IsEqualTo(Vapor.TotalMolarflow * Vapor.SpecificEnthalpy + Liquid.TotalMolarflow * Liquid.SpecificEnthalpy), "Enthalpy Balance");
            }


            AddEquationToEquationSystem(problem, Mixed.TotalMolarflow.IsEqualTo(Sym.Sum(Mixed.ComponentMolarflow)), "Mass Balance");

            for (int i = 0; i < NC; i++)
            {
                // AddEquationToEquationSystem(problem, (Mixed.ComponentMolarFraction[i] * Mixed.TotalMolarflow).IsEqualTo(Liquid.ComponentMolarFraction[i] * Liquid.TotalMolarflow + Vapor.ComponentMolarFraction[i] * Vapor.TotalMolarflow));
                AddEquationToEquationSystem(problem, (Mixed.ComponentMolarflow[i]).IsEqualTo(Liquid.ComponentMolarflow[i] + Vapor.ComponentMolarflow[i]));
                // Mixed.ComponentMolarflow[i].BindTo(Liquid.ComponentMolarflow[i] + Vapor.ComponentMolarflow[i]);
            }
            for (int i = 0; i < NC; i++)
            {
                AddEquationToEquationSystem(problem, (Mixed.ComponentMolarFraction[i] * Mixed.TotalMolarflow).IsEqualTo(Mixed.ComponentMolarflow[i]));
                //Mixed.ComponentMolarFraction[i].BindTo(Mixed.ComponentMolarflow[i]/ Mixed.TotalMolarflow);
            }
            for (int i = 0; i < NC; i++)
            {
                AddEquationToEquationSystem(problem, (Liquid.ComponentMolarFraction[i] * Liquid.TotalMolarflow).IsEqualTo(Liquid.ComponentMolarflow[i]));
                //Liquid.ComponentMolarFraction[i].BindTo(Liquid.ComponentMolarflow[i] / Sym.Max(1e-12, Liquid.TotalMolarflow));
            }
            for (int i = 0; i < NC; i++)
            {
                AddEquationToEquationSystem(problem, (Vapor.ComponentMolarFraction[i] * Vapor.TotalMolarflow).IsEqualTo(Vapor.ComponentMolarflow[i]));
                // Vapor.ComponentMolarFraction[i].BindTo(Vapor.ComponentMolarflow[i] / Sym.Max(1e-12, Vapor.TotalMolarflow));
            }

            AddEquationToEquationSystem(problem, (Vfmolar * Mixed.TotalMolarflow).IsEqualTo((Vapor.TotalMolarflow)), "Vapor Fraction");

            switch (State)
            {
            case PhaseState.BubblePoint:
                AddEquationToEquationSystem(problem, (Sym.Sum(Liquid.ComponentMolarFraction) - Sym.Sum(Vapor.ComponentMolarFraction)).IsEqualTo(Beta), "Equilibrium");
                AddEquationToEquationSystem(problem, Beta.IsEqualTo(0), "Equilibrium");
                AddEquationToEquationSystem(problem, Liquid.TotalMolarflow.IsEqualTo(Sym.Sum(Liquid.ComponentMolarflow)), "Mass Balance");
                break;

            case PhaseState.DewPoint:
                AddEquationToEquationSystem(problem, (Sym.Sum(Liquid.ComponentMolarFraction) - Sym.Sum(Vapor.ComponentMolarFraction)).IsEqualTo(Beta), "Equilibrium");
                AddEquationToEquationSystem(problem, Beta.IsEqualTo(0), "Equilibrium");
                AddEquationToEquationSystem(problem, Vapor.TotalMolarflow.IsEqualTo(Sym.Sum(Vapor.ComponentMolarflow)), "Mass Balance");
                break;

            default:
                if (Vfmolar.IsFixed)
                {
                    AddEquationToEquationSystem(problem, (Sym.Sum(Liquid.ComponentMolarFraction) - Sym.Sum(Vapor.ComponentMolarFraction)).IsEqualTo(Beta), "Equilibrium");
                    AddEquationToEquationSystem(problem, Beta.IsEqualTo(0), "Equilibrium");
                }
                else
                {
                    AddEquationToEquationSystem(problem, (Sym.Sum(Liquid.ComponentMolarFraction) - Sym.Sum(Vapor.ComponentMolarFraction)).IsEqualTo(Beta), "Equilibrium");
                    AddEquationToEquationSystem(problem, Sym.Mid(Vfmolar, Beta, Vfmolar - 1).IsEqualTo(0), "Equilibrium");
                }
                AddEquationToEquationSystem(problem, (Mixed.TotalMolarflow).IsEqualTo(Vapor.TotalMolarflow + Liquid.TotalMolarflow), "Mass Balance");
                break;
            }

            for (int i = 0; i < NC; i++)
            {
                System.EquationFactory.EquilibriumCoefficient(System, KValues[i], Mixed.Temperature, Mixed.Pressure, Liquid.ComponentMolarFraction, Vapor.ComponentMolarFraction, i);
                AddEquationToEquationSystem(problem, Vapor.ComponentMolarFraction[i].IsEqualTo(KValues[i] * Liquid.ComponentMolarFraction[i]), "Equilibrium");
            }

            base.FillEquationSystem(problem);
        }