コード例 #1
0
        private SubstanceFormula ExtractFormula(string aLine, string[] separatorsStr3, string[] separatorsStr4)
        {
            string tmpStr;
            string elementStr;
            int    elementCount;

            substanceFormula = new SubstanceFormula();
            string[] subStrs = aLine.Trim().Split(separatorsStr3, StringSplitOptions.RemoveEmptyEntries);
            subStrs = subStrs[0].Trim().Split(separatorsStr4, StringSplitOptions.RemoveEmptyEntries);
            for (int i = 0; i < subStrs.Length; i++)
            {
                if (!char.IsDigit(subStrs[i][0]))
                {
                    elementStr   = subStrs[i];
                    elementCount = 1;
                    i++;
                    if (i < subStrs.Length && char.IsDigit(subStrs[i][0]))
                    {
                        tmpStr       = subStrs[i];
                        elementCount = int.Parse(tmpStr);
                    }

                    substanceFormula.AddElement(elementStr, elementCount);
                }
            }
            return(substanceFormula);
        }
コード例 #2
0
        private SubstanceFormula ExtractSubstanceFormula(string lineTemp)
        {
            string elementStr;
            string tmpStr;
            int    elementCount;

            string[] separatorsS = { "<sub>", "</sub>" };
            string[] separator1  = { "</td>" };

            string[]         subStrs          = lineTemp.Trim().Split(separatorsS, StringSplitOptions.RemoveEmptyEntries);
            SubstanceFormula substanceFormula = new SubstanceFormula();

            //sb = new StringBuilder();
            for (int i = 0; i < subStrs.Length - 1; i++)
            {
                //sb.Append(subStrs[i]);
                if (!char.IsDigit(subStrs[i][0]))
                {
                    elementStr = subStrs[i];
                    i++;
                    if (char.IsDigit(subStrs[i][0]))
                    {
                        //sb.Append(subStrs[i]);
                        tmpStr = subStrs[i];
                        if (char.IsDigit(subStrs[i + 1][0]))
                        {
                            i++;
                            tmpStr += subStrs[i];
                            //sb.Append(subStrs[i]);
                        }

                        elementCount = int.Parse(tmpStr);
                        substanceFormula.AddElement(elementStr, elementCount);
                    }
                }
            }

            if (!subStrs[subStrs.Length - 1].StartsWith("</td>"))
            {
                subStrs    = subStrs[subStrs.Length - 1].Trim().Split(separator1, StringSplitOptions.RemoveEmptyEntries);
                elementStr = subStrs[0];
                substanceFormula.AddElement(elementStr, 1);
            }

            return(substanceFormula);
        }
コード例 #3
0
        public double CalculateDiffusivity(double temperature, double pressure)
        {
            //air-water vapor diffusivity at 1 atm.
            //diffusivity = -2.775e-6 + 4.479e-8*temperature + 1.656e-10 *temperature*temperature;
            //this is from a website
            double diffusivity = 0;

            //if (gas.Name == "Air" && moisture.Name == "water") {
            if (gas.IsAir && moisture.IsWater)
            {
                diffusivity = -2.775e-6 + 4.479e-8 * temperature + 1.656e-10 * temperature * temperature;
                diffusivity = diffusivity * 1.013e5 / pressure;
            }
            else
            {
                double sumVolumeGas = 0;
                if (molecularDiffusionVolumeTable.ContainsKey(gas.Formula.ToString()))
                {
                    sumVolumeGas = molecularDiffusionVolumeTable[gas.Formula.ToString()];
                }
                else
                {
                    SubstanceFormula gasFormula  = gas.Formula;
                    string[]         gasElements = gasFormula.Elements;
                    foreach (string element in gasElements)
                    {
                        sumVolumeGas += gasFormula.GetElementCount(element) * atomicDiffusionVolumeTable[element];
                    }
                }

                double           sumVolumeMoisture = 0;
                SubstanceFormula moistureFormula   = moisture.Formula;
                string[]         moistureElements  = moistureFormula.Elements;
                foreach (string element in moistureElements)
                {
                    sumVolumeMoisture += moistureFormula.GetElementCount(element) * atomicDiffusionVolumeTable[element];
                }

                double molarWeightTerm = Math.Pow((1.0 / gas.MolarWeight + 1.0 / moisture.MolarWeight), 0.5);
                double sumVolumeTerm   = Math.Pow((Math.Pow(sumVolumeGas, 1.0 / 3) + Math.Pow(sumVolumeMoisture, 1.0 / 3)), 2);
                diffusivity = 0.01013 * Math.Pow(temperature, 1.75) * molarWeightTerm / (pressure * sumVolumeTerm);
            }

            return(diffusivity);
        }
コード例 #4
0
        private void ExtractCoeffs()
        {
            FileStream fsRead = null;

            try {
                //char[] separator1 = { '>' };
                //string[] separator1 = { "</td>" };
                //char[] emptySeparator = { ' ' };
                //char[] separators = { '>', '<' };
                string[] separatorsStr1 = { "</td>" };
                string[] separatorsStr2 = { "<i>", "</i>" };
                //string[] subStrs;
                //string formula;
                string name;
                string casRegestryNo;
                double a, b, c, d = 1, e = 1;
                double molarWeight, criticalRho, criticalT, criticalP, criticalV, criticalComp, accentricF;
                molarWeight = criticalRho = criticalT = criticalP = criticalV = criticalComp = accentricF = -2147483D;
                double minTemp = 1, maxTemp = 1;
                //StringBuilder sb;
                CriticalPropsAndAcentricFactor criticalProps;
                Substance               substance;
                YawsGasCpCorrelation    gasCpCorrelation;
                YawsLiquidCpCorrelation liquidCpCorrelation;
                YawsSolidCpCorrelation  solidCpCorrelation;
                YawsGasThermalConductivityCorrelation    gasKCorrelation;
                YawsLiquidThermalConductivityCorrelation liquidKCorrelation;
                YawsGasViscosityCorrelation        gasViscCorrelation;
                YawsLiquidViscosityCorrelation     liquidViscCorrelation;
                YawsLiquidDensityCorrelation       liquidDensityCorrelation;
                YawsEvaporationHeatCorrelation     evapHeatCorrelation;
                YawsVaporPressureCorrelation       vapPressureCorrelation;
                YawsSurfaceTensionCorrelation      surfaceTensionCorrelation;
                YawsEnthalpyOfFormationCorrelation enthalpyOfFormationCorrelation;

                substanceList               = new ArrayList();
                gasCpCorrList               = new ArrayList();
                liquidCpCorrList            = new ArrayList();
                solidCpCorrList             = new ArrayList();
                evapHeatCorrList            = new ArrayList();
                vapPressureCorrList         = new ArrayList();
                liquidDensityCorrList       = new ArrayList();
                gasKCorrList                = new ArrayList();
                liquidKCorrList             = new ArrayList();
                gasViscCorrList             = new ArrayList();
                liquidViscCorrList          = new ArrayList();
                surfaceTensionCorrList      = new ArrayList();
                enthalpyOfFormationCorrList = new ArrayList();

                string line1, line2, lineTemp;
                //string elementStr;
                //string tmpStr;
                //int elementCount;
                int fileNo      = 0;
                int substanceNo = 0;

                int          counter;
                int          totalCounter = 0;
                StreamReader reader;

                foreach (object fullFileName in listBoxFiles.Items)
                {
                    fileNo++;
                    counter = 0;
                    fsRead  = new FileStream((string)fullFileName, FileMode.Open, FileAccess.Read);
                    reader  = new StreamReader(fsRead);
                    line1   = reader.ReadLine();
                    while (!reader.EndOfStream && counter < 50)
                    {
                        line2 = reader.ReadLine();
                        name  = "";
                        if (thermProp != ThermPropType.CriticalProp)
                        {
                            if (line1.Contains("<a border"))
                            {
                                counter++;

                                name = MainFormYaws.ExtractName(line2, separatorsStr1, separatorsStr2);

                                lineTemp = reader.ReadLine();
                                lineTemp = reader.ReadLine();
                                lineTemp = reader.ReadLine();

                                lineTemp = reader.ReadLine();
                                a        = MainFormYaws.ExtractValue(lineTemp, separatorsStr1);
                                if (a == -2147483D)
                                {
                                    continue;
                                }

                                lineTemp = reader.ReadLine();
                                b        = MainFormYaws.ExtractValue(lineTemp, separatorsStr1);

                                lineTemp = reader.ReadLine();
                                c        = MainFormYaws.ExtractValue(lineTemp, separatorsStr1);

                                if (thermProp == ThermPropType.GasCp || thermProp == ThermPropType.LiquidCp ||
                                    thermProp == ThermPropType.VapPressure || thermProp == ThermPropType.LiquidDensity ||
                                    thermProp == ThermPropType.LiquidDensity || thermProp == ThermPropType.LiquidVisc)
                                {
                                    lineTemp = reader.ReadLine();
                                    d        = MainFormYaws.ExtractValue(lineTemp, separatorsStr1);
                                }

                                if (thermProp == ThermPropType.GasCp || thermProp == ThermPropType.VapPressure)
                                {
                                    lineTemp = reader.ReadLine();
                                    e        = MainFormYaws.ExtractValue(lineTemp, separatorsStr1);
                                }

                                lineTemp = reader.ReadLine();
                                minTemp  = MainFormYaws.ExtractValue(lineTemp, separatorsStr1);

                                lineTemp = reader.ReadLine();
                                maxTemp  = MainFormYaws.ExtractValue(lineTemp, separatorsStr1);

                                if (thermProp == ThermPropType.GasCp)
                                {
                                    gasCpCorrelation = new YawsGasCpCorrelation(name, a, b, c, d, e, minTemp, maxTemp);
                                    gasCpCorrList.Add(gasCpCorrelation);
                                }
                                else if (thermProp == ThermPropType.LiquidCp)
                                {
                                    liquidCpCorrelation = new YawsLiquidCpCorrelation(name, a, b, c, d, minTemp, maxTemp);
                                    liquidCpCorrList.Add(liquidCpCorrelation);
                                }
                                else if (thermProp == ThermPropType.SolidCp)
                                {
                                    solidCpCorrelation = new YawsSolidCpCorrelation(name, a, b, c, minTemp, maxTemp);
                                    solidCpCorrList.Add(solidCpCorrelation);
                                }
                                else if (thermProp == ThermPropType.EvapHeat)
                                {
                                    evapHeatCorrelation = new YawsEvaporationHeatCorrelation(name, a, b, c, minTemp, maxTemp);
                                    evapHeatCorrList.Add(evapHeatCorrelation);
                                }
                                else if (thermProp == ThermPropType.VapPressure)
                                {
                                    vapPressureCorrelation = new YawsVaporPressureCorrelation(name, a, b, c, d, e, minTemp, maxTemp);
                                    vapPressureCorrList.Add(vapPressureCorrelation);
                                }
                                else if (thermProp == ThermPropType.LiquidDensity)
                                {
                                    liquidDensityCorrelation = new YawsLiquidDensityCorrelation(name, a, b, c, d, minTemp, maxTemp);
                                    liquidDensityCorrList.Add(liquidDensityCorrelation);
                                }
                                else if (thermProp == ThermPropType.GasVisc)
                                {
                                    gasViscCorrelation = new YawsGasViscosityCorrelation(name, a, b, c, minTemp, maxTemp);
                                    gasViscCorrList.Add(gasViscCorrelation);
                                }
                                else if (thermProp == ThermPropType.LiquidVisc)
                                {
                                    liquidViscCorrelation = new YawsLiquidViscosityCorrelation(name, a, b, c, d, minTemp, maxTemp);
                                    liquidViscCorrList.Add(liquidViscCorrelation);
                                }
                                else if (thermProp == ThermPropType.GasK)
                                {
                                    gasKCorrelation = new YawsGasThermalConductivityCorrelation(name, a, b, c, minTemp, maxTemp);
                                    gasKCorrList.Add(gasKCorrelation);
                                }
                                else if (thermProp == ThermPropType.LiquidK)
                                {
                                    liquidKCorrelation = new YawsLiquidThermalConductivityCorrelation(name, a, b, c, minTemp, maxTemp);
                                    liquidKCorrList.Add(liquidKCorrelation);
                                }
                                else if (thermProp == ThermPropType.SurfaceTension)
                                {
                                    surfaceTensionCorrelation = new YawsSurfaceTensionCorrelation(name, a, b, c, minTemp, maxTemp);
                                    surfaceTensionCorrList.Add(surfaceTensionCorrelation);
                                }
                                else if (thermProp == ThermPropType.EnthalpyOfFormation)
                                {
                                    enthalpyOfFormationCorrelation = new YawsEnthalpyOfFormationCorrelation(name, a, b, c, minTemp, maxTemp);
                                    enthalpyOfFormationCorrList.Add(enthalpyOfFormationCorrelation);
                                }
                            }

                            line1 = line2;
                        }
                        else
                        {
                            substanceNo = totalCounter + counter + 1;
                            if ((line1.StartsWith(substanceNo.ToString() + "</td><td  align=") ||
                                 //since there is a duplicate for No. 3976 this condition must be added to handle it
                                 line1.StartsWith((substanceNo - 1).ToString() + "</td><td  align=")) && counter < 50)
                            {
                                counter++;

                                name = MainFormYaws.ExtractName(line2, separatorsStr1, separatorsStr2);

                                lineTemp = reader.ReadLine();
                                //if (lineTemp.StartsWith("&nbsp")) {
                                //   casRegestryNo = "";
                                //}
                                //else {
                                //   subStrs = lineTemp.Trim().Split(separatorsStr1, StringSplitOptions.RemoveEmptyEntries);
                                //   casRegestryNo = subStrs[0].Trim();
                                //}
                                casRegestryNo = MainFormYaws.ExtractCasNo(lineTemp, separatorsStr1);

                                lineTemp         = reader.ReadLine();
                                substanceFormula = ExtractSubstanceFormula(lineTemp);

                                //for debugging use only
                                //formula = sb.ToString();

                                lineTemp    = reader.ReadLine();
                                molarWeight = MainFormYaws.ExtractValue(lineTemp, separatorsStr1);

                                lineTemp  = reader.ReadLine();
                                criticalT = MainFormYaws.ExtractValue(lineTemp, separatorsStr1);

                                lineTemp  = reader.ReadLine();
                                criticalP = MainFormYaws.ExtractValue(lineTemp, separatorsStr1);

                                lineTemp  = reader.ReadLine();
                                criticalV = MainFormYaws.ExtractValue(lineTemp, separatorsStr1);

                                lineTemp = reader.ReadLine(); //skip critical density since it can be obtained from critical volume and molar weight
                                //subStrs = lineTemp.Trim().Split(separators);
                                //criticalRho = double.Parse(subStrs[0]);

                                lineTemp     = reader.ReadLine();
                                criticalComp = MainFormYaws.ExtractValue(lineTemp, separatorsStr1);

                                lineTemp   = reader.ReadLine();
                                accentricF = MainFormYaws.ExtractValue(lineTemp, separatorsStr1);

                                criticalProps = new CriticalPropsAndAcentricFactor(criticalT, criticalP, criticalV, criticalComp, accentricF);
                                substance     = new Substance(name, substanceType, casRegestryNo, substanceFormula, molarWeight, criticalProps);
                                substanceList.Add(substance);
                            }

                            line1 = line2;
                        }
                    }

                    totalCounter = totalCounter + counter;

                    reader.Close();
                    fsRead.Close();
                }
            }
            catch (Exception ex) {
                Console.WriteLine("The process failed: {0}", ex.ToString());
            }
            finally {
                if (fsRead != null)
                {
                    fsRead.Close();
                }
            }

            if (thermProp == ThermPropType.CriticalProp)
            {
                PersistSubstances();
            }
            else
            {
                PersistProp(thermProp);
                UnpersistProp(thermProp);
            }
        }
コード例 #5
0
        private SubstanceFormula ExtractFormula(string aLine, string[] separatorsStr3, string[] separatorsStr4)
        {
            string           tmpStr;
            string           elementStr;
            int              elementCount;
            SubstanceFormula substanceFormula = new SubstanceFormula();

            string[] subStrs = aLine.Trim().Split(separatorsStr3, StringSplitOptions.RemoveEmptyEntries);
            subStrs = subStrs[0].Trim().Split(separatorsStr4, StringSplitOptions.RemoveEmptyEntries);
            for (int i = 0; i < subStrs.Length; i++)
            {
                if (!char.IsDigit(subStrs[i][0]))
                {
                    elementStr   = subStrs[i];
                    elementCount = 1;
                    tmpStr       = elementStr;
                    if (tmpStr.Contains("class=BorderHelper>"))
                    {
                        string[] separatorsStr = { "class=BorderHelper>" };
                        string[] subSubStrs    = tmpStr.Trim().Split(separatorsStr, StringSplitOptions.RemoveEmptyEntries);
                        tmpStr = subSubStrs[0];
                    }
                    if (tmpStr.Length == 1 || tmpStr.Length == 2 && char.IsLower(tmpStr[1]))
                    {
                        elementStr = tmpStr;
                    }
                    else if (!char.IsDigit(tmpStr[0]))
                    {
                        if (tmpStr.Length == 2)
                        {
                            elementStr = tmpStr.Substring(0, 1);
                            substanceFormula.AddElement(elementStr, 1);
                            elementStr = tmpStr.Substring(1, 1);
                        }
                        else
                        {
                            for (int j = 0; j < tmpStr.Length; j++)
                            {
                                if (j == (tmpStr.Length - 1) && char.IsUpper(tmpStr[j]))
                                {
                                    elementStr = tmpStr.Substring(j, 1);
                                    continue;
                                }
                                else if (j == (tmpStr.Length - 2) && char.IsLower(tmpStr[tmpStr.Length - 1]))
                                {
                                    elementStr = tmpStr.Substring(j, 2);
                                    j++;
                                    continue;
                                }

                                if (char.IsUpper(tmpStr[j]))
                                {
                                    if (char.IsUpper(tmpStr[j + 1]))
                                    {
                                        elementStr = tmpStr.Substring(j, 1);
                                    }
                                    else if (char.IsLower(tmpStr[j + 1]))
                                    {
                                        elementStr = tmpStr.Substring(j, 2);
                                        j++;
                                    }
                                }
                                if (j < tmpStr.Length - 1)
                                {
                                    substanceFormula.AddElement(elementStr, 1);
                                }
                            }
                        }
                    }

                    i++;
                    if (i < subStrs.Length && char.IsDigit(subStrs[i][0]))
                    {
                        tmpStr       = subStrs[i];
                        elementCount = int.Parse(tmpStr);
                    }

                    substanceFormula.AddElement(elementStr, elementCount);
                }
            }
            return(substanceFormula);
        }
コード例 #6
0
        private void ExtractCoeffs()
        {
            FileStream fsRead = null;

            try {
                char[]   separator1     = { '>' };
                char[]   separator2     = { '<' };
                char[]   emptySeparator = { ' ' };
                char[]   separators     = { '>', '<' };
                string[] subStrs;
                string[] subSubStrs;
                string   formula;
                string   name;
                string   htmlTaggedName;
                string   casRegestryNo;
                double   a, b, c, d = 1, e = 1, f, g, bp = 1;
                double   molarWeight, freezingPoint, boilingPoint, criticalT, criticalP, criticalV, criticalComp, accentricF;
                molarWeight = freezingPoint = boilingPoint = criticalT = criticalP = criticalV = criticalComp = accentricF = -2147483D;
                double        minTemp = 1, maxTemp = 1;
                StringBuilder sb;
                CriticalPropsAndAccentricFactor criticalProps;
                Substance               substance;
                YawsGasCpCorrelation    gasCpCorrelation;
                YawsLiquidCpCorrelation liquidCpCorrelation;
                YawsSolidCpCorrelation  solidCpCorrelation;
                YawsGasThermalConductivityCorrelation    gasKCorrelation;
                YawsLiquidThermalConductivityCorrelation liquidKCorrelation;
                YawsGasViscosityCorrelation        gasViscCorrelation;
                YawsLiquidViscosityCorrelation     liquidViscCorrelation;
                YawsLiquidDensityCorrelation       liquidDensityCorrelation;
                YawsEvaporationHeatCorrelation     evapHeatCorrelation;
                YawsVaporPressureCorrelation       vapPressureCorrelation;
                YawsSurfaceTensionCorrelation      surfaceTensionCorrelation;
                YawsEnthalpyOfFormationCorrelation enthalpyOfFormationCorrelation;

                string       line1, line2, line3, line4, line5, line6, line7, line8, line9, line10, line11, lineTemp;
                string       tmpStrOld = "";
                string       tmpStr;
                int          number;
                StreamReader reader;

                foreach (object fullFileName in listBoxFiles.Items)
                {
                    fsRead = new FileStream((string)fullFileName, FileMode.Open, FileAccess.Read);
                    reader = new StreamReader(fsRead);
                    line1  = reader.ReadLine();
                    while (!reader.EndOfStream)
                    {
                        line2 = reader.ReadLine();
                        if (line1.Contains("<TD class=BorderHelper>") && line2.Contains("<TD class=BorderHelper noWrap>"))
                        {
                            substanceFormula = new SubstanceFormula();

                            subStrs = line1.Split(separator1);
                            sb      = new StringBuilder();
                            for (int i = 1; i < subStrs.Length - 1; i++)
                            {
                                subSubStrs = subStrs[i].Split(separator2);
                                sb.Append(subSubStrs[0]);
                                tmpStr = subSubStrs[0];
                                if (char.IsDigit(tmpStr[0]))
                                {
                                    number = int.Parse(tmpStr);
                                    substanceFormula.AddElement(tmpStrOld, number);
                                }
                                else
                                {
                                    if (!tmpStr.Equals(" "))
                                    {
                                        tmpStr = Parse(tmpStr.TrimEnd());
                                    }
                                    if (i == (subStrs.Length - 2) && !tmpStr.Equals(" ") && !tmpStr.Equals(""))
                                    {
                                        substanceFormula.AddElement(tmpStr, 1);
                                    }
                                }
                                tmpStrOld = tmpStr;
                            }
                            formula = sb.ToString();

                            if (!line2.Contains("</TD>"))
                            {
                                lineTemp = reader.ReadLine();
                                lineTemp = lineTemp.TrimStart();
                                if (!lineTemp.StartsWith("</TD>"))
                                {
                                    line2 = line2 + " " + lineTemp;
                                }
                                else
                                {
                                    line2 = line2 + lineTemp;
                                }
                            }
                            htmlTaggedName = line2;

                            if (!(line2.Contains("<I>") || line2.Contains("</SPAN>")))
                            {
                                subStrs = line2.Split(separators);
                                name    = subStrs[2];
                            }
                            else
                            {
                                subStrs = line2.Split(separators);
                                sb      = new StringBuilder();
                                for (int i = 2; i < subStrs.Length; i++)
                                {
                                    if (!(subStrs[i].Equals("") || subStrs[i].Equals("I") || subStrs[i].Equals("/I") ||
                                          subStrs[i].Equals("SPAN class=Greek") || subStrs[i].Equals("/SPAN") ||
                                          subStrs[i].Equals("/TD")))
                                    {
                                        sb.Append(subStrs[i]);
                                    }
                                }
                                name = sb.ToString();
                            }
                            name = name.TrimEnd(emptySeparator);

                            line3   = reader.ReadLine();
                            subStrs = line3.Split(separators);
                            if (subStrs[2].Contains("&"))
                            {
                                casRegestryNo = "";
                            }
                            else
                            {
                                casRegestryNo = subStrs[2];
                            }

                            line4   = reader.ReadLine();
                            subStrs = line4.Split(separators);
                            a       = double.Parse(subStrs[2]);
                            if (thermProp == ThermProp.CriticalProp)
                            {
                                molarWeight = a;
                            }

                            line5   = reader.ReadLine();
                            subStrs = line5.Split(separators);
                            if (subStrs[2].Contains("&"))
                            {
                                b = -2147483D;
                            }
                            else
                            {
                                b = double.Parse(subStrs[2]);
                            }
                            if (thermProp == ThermProp.CriticalProp)
                            {
                                freezingPoint = b;
                            }

                            line6   = reader.ReadLine();
                            subStrs = line6.Split(separators);
                            if (subStrs[2].Contains("&"))
                            {
                                c = -2147483D;;
                            }
                            else
                            {
                                c = double.Parse(subStrs[2]);
                            }
                            if (thermProp == ThermProp.CriticalProp)
                            {
                                boilingPoint = c;
                            }

                            line7   = reader.ReadLine();
                            subStrs = line7.Split(separators);
                            if (subStrs[2].Contains("&"))
                            {
                                d = -2147483D;
                            }
                            else
                            {
                                d = double.Parse(subStrs[2]);
                            }
                            if (thermProp == ThermProp.SolidCp || thermProp == ThermProp.EvapHeat ||
                                thermProp == ThermProp.GasVisc || thermProp == ThermProp.GasK ||
                                thermProp == ThermProp.LiquidK || thermProp == ThermProp.SurfaceTension ||
                                thermProp == ThermProp.EnthalpyOfFormation)
                            {
                                minTemp = d;
                            }
                            else if (thermProp == ThermProp.CriticalProp)
                            {
                                criticalT = d;
                            }

                            line8   = reader.ReadLine();
                            subStrs = line8.Split(separators);
                            if (subStrs[2].Contains("&"))
                            {
                                e = -2147483D;
                            }
                            else
                            {
                                e = double.Parse(subStrs[2]);
                            }

                            if (thermProp == ThermProp.SolidCp || thermProp == ThermProp.EvapHeat ||
                                thermProp == ThermProp.GasVisc || thermProp == ThermProp.GasK ||
                                thermProp == ThermProp.LiquidK || thermProp == ThermProp.SurfaceTension ||
                                thermProp == ThermProp.EnthalpyOfFormation)
                            {
                                maxTemp = e;
                            }
                            else if (thermProp == ThermProp.LiquidCp || thermProp == ThermProp.LiquidDensity || thermProp == ThermProp.LiquidVisc)
                            {
                                minTemp = e;
                            }
                            else if (thermProp == ThermProp.CriticalProp)
                            {
                                criticalP = 1.0e5 * e;//convert from bar to Pa.sec
                            }

                            if (thermProp == ThermProp.EvapHeat || thermProp == ThermProp.CriticalProp ||
                                thermProp == ThermProp.GasCp || thermProp == ThermProp.VapPressure ||
                                thermProp == ThermProp.LiquidCp || thermProp == ThermProp.LiquidDensity ||
                                thermProp == ThermProp.LiquidVisc)
                            {
                                line9   = reader.ReadLine();
                                subStrs = line9.Split(separators);
                                if (!subStrs[2].Contains("&"))
                                {
                                    f = double.Parse(subStrs[2]);
                                }
                                else
                                {
                                    f = -2147483D;
                                }

                                if (thermProp == ThermProp.EvapHeat)
                                {
                                    bp = f;
                                }
                                else if (thermProp == ThermProp.CriticalProp)
                                {
                                    criticalV = f * 1.0e-6;        //convert from cm3/mol to m3/mol
                                    line9     = reader.ReadLine(); //skip critical density
                                }
                                else if (thermProp == ThermProp.GasCp || thermProp == ThermProp.VapPressure)
                                {
                                    minTemp = f;
                                }
                                else if (thermProp == ThermProp.LiquidCp || thermProp == ThermProp.LiquidDensity || thermProp == ThermProp.LiquidVisc)
                                {
                                    maxTemp = f;
                                }
                            }

                            if (thermProp == ThermProp.CriticalProp || thermProp == ThermProp.GasCp ||
                                thermProp == ThermProp.VapPressure)
                            {
                                line10  = reader.ReadLine();
                                subStrs = line10.Split(separators);
                                if (!subStrs[2].Contains("&"))
                                {
                                    g = double.Parse(subStrs[2]);
                                }
                                else
                                {
                                    g = -2147483D;
                                }


                                if (thermProp == ThermProp.CriticalProp)
                                {
                                    criticalComp = g;
                                }
                                else if (thermProp == ThermProp.GasCp || thermProp == ThermProp.VapPressure)
                                {
                                    maxTemp = g;
                                }
                            }

                            if (thermProp == ThermProp.CriticalProp)
                            {
                                line11  = reader.ReadLine();
                                subStrs = line11.Split(separators);
                                if (!subStrs[2].Contains("&"))
                                {
                                    accentricF = double.Parse(subStrs[2]);
                                }
                                else
                                {
                                    accentricF = -2147483D;
                                }
                            }

                            if (thermProp == ThermProp.CriticalProp)
                            {
                                criticalProps = new CriticalPropsAndAccentricFactor(freezingPoint, boilingPoint, criticalT, criticalP, criticalV, criticalComp, accentricF);
                                substance     = new Substance(name, htmlTaggedName, substanceType, casRegestryNo, substanceFormula, molarWeight, criticalProps);
                                substanceList.Add(substance);
                            }
                            else if (thermProp == ThermProp.GasCp)
                            {
                                gasCpCorrelation = new YawsGasCpCorrelation(name, a, b, c, d, e, minTemp, maxTemp);
                                gasCpCorrList.Add(gasCpCorrelation);
                            }
                            else if (thermProp == ThermProp.LiquidCp)
                            {
                                liquidCpCorrelation = new YawsLiquidCpCorrelation(name, a, b, c, d, minTemp, maxTemp);
                                liquidCpCorrList.Add(liquidCpCorrelation);
                            }
                            else if (thermProp == ThermProp.SolidCp)
                            {
                                solidCpCorrelation = new YawsSolidCpCorrelation(name, a, b, c, minTemp, maxTemp);
                                solidCpCorrList.Add(solidCpCorrelation);
                            }
                            else if (thermProp == ThermProp.EvapHeat)
                            {
                                evapHeatCorrelation = new YawsEvaporationHeatCorrelation(name, a, b, c, minTemp, maxTemp);
                                evapHeatCorrList.Add(evapHeatCorrelation);
                            }
                            else if (thermProp == ThermProp.VapPressure)
                            {
                                vapPressureCorrelation = new YawsVaporPressureCorrelation(name, a, b, c, d, e, minTemp, maxTemp);
                                vapPressureCorrList.Add(vapPressureCorrelation);
                            }
                            else if (thermProp == ThermProp.LiquidDensity)
                            {
                                liquidDensityCorrelation = new YawsLiquidDensityCorrelation(name, a, b, c, d, minTemp, maxTemp);
                                liquidDensityCorrList.Add(liquidDensityCorrelation);
                            }
                            else if (thermProp == ThermProp.GasVisc)
                            {
                                gasViscCorrelation = new YawsGasViscosityCorrelation(name, a, b, c, minTemp, maxTemp);
                                gasViscCorrList.Add(gasViscCorrelation);
                            }
                            else if (thermProp == ThermProp.LiquidVisc)
                            {
                                liquidViscCorrelation = new YawsLiquidViscosityCorrelation(name, a, b, c, d, minTemp, maxTemp);
                                liquidViscCorrList.Add(liquidViscCorrelation);
                            }
                            else if (thermProp == ThermProp.GasK)
                            {
                                gasKCorrelation = new YawsGasThermalConductivityCorrelation(name, a, b, c, minTemp, maxTemp);
                                gasKCorrList.Add(gasKCorrelation);
                            }
                            else if (thermProp == ThermProp.LiquidK)
                            {
                                liquidKCorrelation = new YawsLiquidThermalConductivityCorrelation(name, a, b, c, minTemp, maxTemp);
                                liquidKCorrList.Add(liquidKCorrelation);
                            }
                            else if (thermProp == ThermProp.SurfaceTension)
                            {
                                surfaceTensionCorrelation = new YawsSurfaceTensionCorrelation(name, a, b, c, minTemp, maxTemp);
                                surfaceTensionCorrList.Add(surfaceTensionCorrelation);
                            }
                            else if (thermProp == ThermProp.EnthalpyOfFormation)
                            {
                                enthalpyOfFormationCorrelation = new YawsEnthalpyOfFormationCorrelation(name, a, b, c, minTemp, maxTemp);
                                enthalpyOfFormationCorrList.Add(enthalpyOfFormationCorrelation);
                            }
                        }
                        line1 = line2;
                    }
                    reader.Close();
                    fsRead.Close();
                }
            }
            catch (Exception ex) {
                Console.WriteLine("The process failed: {0}", ex.ToString());
            }
            finally {
                if (fsRead != null)
                {
                    fsRead.Close();
                }
            }

            if (substanceType == SubstanceType.Inorganic && thermProp == ThermProp.CriticalProp)
            {
                PersistSubstances();
            }
            else if (substanceType == SubstanceType.Organic && thermProp == ThermProp.EnthalpyOfFormation)
            {
                PersistProp(thermProp);
                UnpersistProp(thermProp);
            }
            else if (substanceType == SubstanceType.Inorganic)
            {
                PersistProp(thermProp);
                UnpersistProp(thermProp);
            }
        }
コード例 #7
0
        private SubstanceFormula ExtractSubstanceFormula(string lineTemp)
        {
            string elementStr;
            string tmpStr;
            int    elementCount;

            string[] separators = { "<sub>", "</sub>" };

            string[]         subStrs          = lineTemp.Trim().Split(separators, StringSplitOptions.RemoveEmptyEntries);
            SubstanceFormula substanceFormula = new SubstanceFormula();

            for (int i = 0; i < subStrs.Length - 1; i++)
            {
                if (!char.IsDigit(subStrs[i][0]))
                {
                    elementStr = subStrs[i];
                    tmpStr     = elementStr;

                    if (tmpStr.Length == 1 || tmpStr.Length == 2 && char.IsLower(tmpStr[1]))
                    {
                        elementStr = tmpStr;
                    }
                    else if (!char.IsDigit(tmpStr[0]))
                    {
                        if (tmpStr.Length == 2)
                        {
                            elementStr = tmpStr.Substring(0, 1);
                            substanceFormula.AddElement(elementStr, 1);
                            elementStr = tmpStr.Substring(1, 1);
                        }
                        else
                        {
                            for (int j = 0; j < tmpStr.Length; j++)
                            {
                                if (j == (tmpStr.Length - 1) && char.IsUpper(tmpStr[j]))
                                {
                                    elementStr = tmpStr.Substring(j, 1);
                                    continue;
                                }
                                else if (j == (tmpStr.Length - 2) && char.IsLower(tmpStr[tmpStr.Length - 1]))
                                {
                                    elementStr = tmpStr.Substring(j, 2);
                                    j++;
                                    continue;
                                }

                                if (char.IsUpper(tmpStr[j]))
                                {
                                    if (char.IsUpper(tmpStr[j + 1]))
                                    {
                                        elementStr = tmpStr.Substring(j, 1);
                                    }
                                    else if (char.IsLower(tmpStr[j + 1]))
                                    {
                                        elementStr = tmpStr.Substring(j, 2);
                                        j++;
                                    }
                                }
                                if (j < tmpStr.Length - 1)
                                {
                                    substanceFormula.AddElement(elementStr, 1);
                                }
                            }
                        }
                    }
                    i++;
                    if (char.IsDigit(subStrs[i][0]))
                    {
                        tmpStr = subStrs[i];
                        if (char.IsDigit(subStrs[i + 1][0]))
                        {
                            i++;
                            tmpStr += subStrs[i];
                        }

                        elementCount = int.Parse(tmpStr);
                        substanceFormula.AddElement(elementStr, elementCount);
                    }
                }
            }

            if (!subStrs[subStrs.Length - 1].StartsWith("</td>"))
            {
                string[] separator1 = { "</td>" };
                subStrs    = subStrs[subStrs.Length - 1].Trim().Split(separator1, StringSplitOptions.RemoveEmptyEntries);
                elementStr = subStrs[0];
                substanceFormula.AddElement(elementStr, 1);
            }

            return(substanceFormula);
        }
コード例 #8
0
        private void Solve()
        {
            double totalEenthalpyOfReactantInFuelInlet = 0;
            double moleFractionCarbon   = 0;
            double moleFractionHydrogen = 0;
            double moleFractionSulfur   = 0;
            double moleFractionOxygen   = 0;
            //double massAsh = 0;
            double             moleFractionCarbonDioxide = 0;
            double             moleFractionNitrogen      = 0; //mole fraction of nitrogen in original gas fuel
            MaterialComponents components = fuelInlet.Components;

            if (fuelInlet is GenericFuelStream)
            {
                for (int i = 0; i < components.Count; i++)
                {
                    MaterialComponent component   = components[i];
                    Substance         mySubstance = component.Substance;
                    //myMassFraction = component.MassFraction.Value;
                    double myMoleFraction = component.MoleFraction.Value;
                    if (mySubstance == carbon)
                    {
                        moleFractionCarbon = myMoleFraction;
                    }
                    else if (mySubstance == hydrogen)
                    {
                        moleFractionHydrogen = myMoleFraction;
                    }
                    else if (mySubstance == oxygen)
                    {
                        moleFractionOxygen = myMoleFraction;
                    }
                    else if (mySubstance == sulfur)
                    {
                        moleFractionSulfur = myMoleFraction;
                    }
                    //else if (component.Substance == ash) {
                    //   massAsh = myMassFraction;
                    //}
                }
            }
            else if (fuelInlet is DetailedFuelStream)
            {
                totalEenthalpyOfReactantInFuelInlet = 0;
                moleFractionCarbon   = 0;
                moleFractionHydrogen = 0;
                moleFractionOxygen   = 0;
                moleFractionSulfur   = 0;
                double t = fuelInlet.Temperature.Value;
                for (int i = 0; i < components.Count; i++)
                {
                    MaterialComponent component      = components[i];
                    Substance         mySubstance    = component.Substance;
                    double            myMoleFraction = component.MoleFraction.Value;

                    if (mySubstance == carbonDioxide)
                    {
                        moleFractionCarbonDioxide = myMoleFraction;
                    }
                    else if (mySubstance == nitrogen)
                    {
                        moleFractionNitrogen = myMoleFraction;
                    }
                    else
                    {
                        totalEenthalpyOfReactantInFuelInlet += myMoleFraction * propCalculator.CalculateEnthalpyOfFormation(t, mySubstance);
                        SubstanceFormula formula  = mySubstance.Formula;
                        string[]         elements = formula.Elements;
                        foreach (string element in elements)
                        {
                            int elementCount = formula.GetElementCount(element);
                            if (element == "C")
                            {
                                moleFractionCarbon += elementCount * myMoleFraction;
                            }
                            else if (element == "H")
                            {
                                moleFractionHydrogen += elementCount * myMoleFraction;
                            }
                            else if (element == "O")
                            {
                                moleFractionOxygen += elementCount * myMoleFraction;
                            }
                            else if (element == "S")
                            {
                                moleFractionSulfur += elementCount * myMoleFraction;
                            }
                        }
                    }
                }
            }

            moleFractionHydrogen = 0.5 * moleFractionHydrogen; //convert from H to H2
            moleFractionOxygen   = 0.5 * moleFractionOxygen;   //convert from O to O2

            //multiply 0.5 for moleFractionHydrogen because 1 mole of H2 only needs 0.5 mole of O2
            double moleFractionOxygenNeeded = moleFractionCarbon + 0.5 * moleFractionHydrogen + moleFractionSulfur - moleFractionOxygen;
            double exactDryAirMassNeeded    = moleFractionOxygenNeeded / OXYGEN_MOLE_FRACTION_IN_AIR * air.MolarWeight;

            double excessAirValue                = excessAir.HasValue ? excessAir.Value / 100 : 0;
            double excessDryAirNeeded            = exactDryAirMassNeeded * excessAirValue;
            double dryAirMassNeeded              = exactDryAirMassNeeded + excessDryAirNeeded;
            double moistureMassCarriedByInletAir = dryAirMassNeeded * airInlet.Humidity.Value;
            double airMassNeeded = dryAirMassNeeded + moistureMassCarriedByInletAir;

            double moitureGeneratedByReaction = moleFractionHydrogen * water.MolarWeight; //since 1 mole of H2 generates 1 mole of water
            double totalMoistureInFlueGas     = moitureGeneratedByReaction + moistureMassCarriedByInletAir;

            double flueGasTotal = airMassNeeded + fuelInlet.Components.MolarWeight;
            double dryFlueGas   = flueGasTotal - totalMoistureInFlueGas;
            double flueGasMoistureContentDryBase = totalMoistureInFlueGas / dryFlueGas;

            CompositeSubstance  flueGas           = CreateDryFlueGasSubstance(moleFractionCarbon, moleFractionSulfur, moleFractionCarbonDioxide, moleFractionNitrogen, moleFractionOxygenNeeded, dryAirMassNeeded, dryFlueGas, excessAirValue);
            DryingGasComponents flueGasComponents = CreateDryingGasComponents(flueGasMoistureContentDryBase, flueGas);

            flueGasOutlet.GasComponents = flueGasComponents;

            double fuelMoleFlowRate = fuelInlet.MoleFlowRate.Value;

            if (excessAir.HasValue)
            {
                Calculate(flueGasOutlet.Humidity, flueGasMoistureContentDryBase);

                if (fuelInlet.MoleFlowRate.HasValue)
                {
                    Calculate(airInlet.MassFlowRateDryBase, dryAirMassNeeded * fuelMoleFlowRate);
                    Calculate(flueGasOutlet.MassFlowRate, flueGasTotal * fuelMoleFlowRate);
                }
                else if (flueGasOutlet.MassFlowRate.HasValue)
                {
                    fuelMoleFlowRate = flueGasOutlet.MassFlowRate.Value / flueGasTotal;
                    Calculate(fuelInlet.MoleFlowRate, fuelMoleFlowRate);
                    Calculate(airInlet.MassFlowRateDryBase, dryAirMassNeeded * fuelMoleFlowRate);
                }
            }

            double fuelInletEnthalpy  = fuelInlet.SpecificEnthalpy.Value;
            double airInletEnthalpy   = airMassNeeded * airInlet.SpecificEnthalpy.Value;
            double totalHeatGenerated = Constants.NO_VALUE;
            double heatLossValue      = 0;

            if (fuelInlet is GenericFuelStream)
            {
                //GenericFuelStream gfs = fuelInlet as GenericFuelStream;
                //if (gfs.HeatValue.HasValue) {
                //   //total heat genrate eaquls to heat value of the fuel times fuelMassFlowRate
                //   totalHeatGenerated = gfs.HeatValue.Value * fuelMoleFlowRate;

                //   heatLossValue = totalHeatGenerated * percentageHeatLoss.Value / 100;

                //   double totalFlueGasSpecificEnthalpy = (fuelInletEnthalpy + airInletEnthalpy + totalHeatGenerated - heatLossValue) / flueGasTotal;
                //   Calculate(flueGasOutlet.SpecificEnthalpy, totalFlueGasSpecificEnthalpy);
                //}
            }
            else if (fuelInlet is DetailedFuelStream)
            {
                HumidGasCalculator humidGasCalculator = new HumidGasCalculator(flueGas, water);

                //evaporation heat of 2 moles of water
                double evaporationHeat = 2.0 * water.MolarWeight * humidGasCalculator.GetEvaporationHeat(273.15);
                double p = flueGasOutlet.Pressure.Value;
                //double originalTemperature = airInlet.Temperature.Value;
                //double initialHumidEnthalpy = humidGasCalculator.GetHumidEnthalpyFromDryBulbHumidityAndPressure(originalTemperature, flueGasMoistureContentDryBase, p);
                double initialHumidEnthalpy = airInlet.SpecificEnthalpyDryBase.Value;
                initialHumidEnthalpy = initialHumidEnthalpy * dryAirMassNeeded / dryFlueGas;
                double t = airInlet.Temperature.Value;
                double totalEnthalpyOfReactantOxygen = moleFractionOxygenNeeded * propCalculator.CalculateEnthalpyOfFormation(t, oxygen);
                double totalEenthalpyOfReactants     = totalEenthalpyOfReactantInFuelInlet + totalEnthalpyOfReactantOxygen;

                double tNew    = t;
                int    counter = 0;
                if (excessAir.HasValue && percentageHeatLoss.IsSpecifiedAndHasValue)
                {
                    do
                    {
                        counter++;
                        t = tNew;
                        double totalEenthalpyOfProduct = CalculateTotalEntalpyOfProduct(moleFractionCarbon, moleFractionHydrogen, moleFractionSulfur, t);
                        totalHeatGenerated = totalEenthalpyOfReactants - totalEenthalpyOfProduct + evaporationHeat;

                        heatLossValue = totalHeatGenerated * percentageHeatLoss.Value / 100;

                        double flueGasHumidEnthalpy = initialHumidEnthalpy + (totalHeatGenerated - heatLossValue) / dryFlueGas;
                        tNew = humidGasCalculator.GetDryBulbFromHumidEnthalpyHumidityAndPressure(flueGasHumidEnthalpy, flueGasMoistureContentDryBase, p);
                    } while (Math.Abs(tNew - t) / tNew > 1.0e-8 && counter < 100);

                    if (counter == 100)
                    {
                        throw new CalculationFailedException("Calculation of flame temperature failed.");
                    }

                    Calculate(flueGasOutlet.Temperature, tNew);
                    totalHeatGenerated *= fuelMoleFlowRate;

                    Calculate(heatLoss, totalHeatGenerated * percentageHeatLoss.Value / 100);
                }
                else if (excessAir.HasValue && flueGasOutlet.Temperature.IsSpecifiedAndHasValue)
                {
                    double flueGasTemp             = flueGasOutlet.Temperature.Value;
                    double totalEenthalpyOfProduct = CalculateTotalEntalpyOfProduct(moleFractionCarbon, moleFractionHydrogen, moleFractionSulfur, flueGasTemp);
                    totalHeatGenerated = totalEenthalpyOfReactants - totalEenthalpyOfProduct + evaporationHeat;
                    heatLossValue      = totalHeatGenerated * percentageHeatLoss.Value / 100;
                    double flueGasHumidEnthalpy = initialHumidEnthalpy + (totalHeatGenerated - heatLossValue) / dryFlueGas;
                    tNew = humidGasCalculator.GetDryBulbFromHumidEnthalpyHumidityAndPressure(flueGasHumidEnthalpy, flueGasMoistureContentDryBase, p);

                    if (tNew < flueGasTemp)
                    {
                        throw new CalculationFailedException("Specified flue gas temperature cannot be reached.");
                    }

                    counter = 0;
                    double humidEnthanlpy0 = humidGasCalculator.GetHumidEnthalpyFromDryBulbHumidityAndPressure(flueGasTemp, flueGasMoistureContentDryBase, p);
                    do
                    {
                        counter++;
                        double humidEnthanlpy1 = humidGasCalculator.GetHumidEnthalpyFromDryBulbHumidityAndPressure(tNew, flueGasMoistureContentDryBase, p);
                        heatLossValue       += dryFlueGas * (humidEnthanlpy1 - humidEnthanlpy0);
                        flueGasHumidEnthalpy = initialHumidEnthalpy + (totalHeatGenerated - heatLossValue) / dryFlueGas;
                        tNew = humidGasCalculator.GetDryBulbFromHumidEnthalpyHumidityAndPressure(flueGasHumidEnthalpy, flueGasMoistureContentDryBase, p);
                    } while (Math.Abs(tNew - flueGasTemp) / flueGasTemp > 1.0e-8 && counter < 100);

                    if (counter == 100)
                    {
                        throw new CalculationFailedException("Calculation of flame temperature failed.");
                    }

                    totalHeatGenerated *= fuelMoleFlowRate;
                    heatLossValue      *= fuelMoleFlowRate;

                    Calculate(heatLoss, heatLossValue);
                    Calculate(percentageHeatLoss, heatLossValue / totalHeatGenerated * 100);
                }
                else if (flueGasOutlet.Temperature.IsSpecifiedAndHasValue && percentageHeatLoss.IsSpecifiedAndHasValue)
                {
                    double flueGasTemp             = flueGasOutlet.Temperature.Value;
                    double totalEenthalpyOfProduct = CalculateTotalEntalpyOfProduct(moleFractionCarbon, moleFractionHydrogen, moleFractionSulfur, flueGasTemp);
                    totalHeatGenerated = totalEenthalpyOfReactants - totalEenthalpyOfProduct + evaporationHeat;

                    heatLossValue = totalHeatGenerated * percentageHeatLoss.Value / 100;
                    double flueGasHumidEnthalpy = initialHumidEnthalpy + (totalHeatGenerated - heatLossValue) / dryFlueGas;
                    tNew = humidGasCalculator.GetDryBulbFromHumidEnthalpyHumidityAndPressure(flueGasHumidEnthalpy, flueGasMoistureContentDryBase, p);

                    if (tNew < flueGasTemp)
                    {
                        throw new CalculationFailedException("Specified flue gas temperature cannot be reached.");
                    }

                    //double excessDryAirNeededOld;
                    do
                    {
                        counter++;
                        t = tNew;
                        //excessDryAirNeededOld = excessDryAirNeeded;
                        //initialHumidEnthalpy = humidGasCalculator.GetHumidEnthalpyFromDryBulbHumidityAndPressure(originalTemperature, flueGasMoistureContentDryBase, p);
                        flueGasHumidEnthalpy = humidGasCalculator.GetHumidEnthalpyFromDryBulbHumidityAndPressure(flueGasTemp, flueGasMoistureContentDryBase, p);
                        dryFlueGas           = (totalHeatGenerated - heatLossValue) / (flueGasHumidEnthalpy - initialHumidEnthalpy);

                        flueGasTotal  = dryFlueGas + totalMoistureInFlueGas;
                        airMassNeeded = flueGasTotal - fuelInlet.Components.MolarWeight;

                        dryAirMassNeeded       = airMassNeeded / (1 + airInlet.Humidity.Value);
                        totalMoistureInFlueGas = moitureGeneratedByReaction + dryAirMassNeeded * airInlet.Humidity.Value;
                        excessDryAirNeeded     = dryAirMassNeeded - exactDryAirMassNeeded;
                        excessAirValue         = excessDryAirNeeded / exactDryAirMassNeeded;

                        flueGasMoistureContentDryBase = totalMoistureInFlueGas / dryFlueGas;

                        flueGas            = CreateDryFlueGasSubstance(moleFractionCarbon, moleFractionSulfur, moleFractionCarbonDioxide, moleFractionNitrogen, moleFractionOxygenNeeded, dryAirMassNeeded, dryFlueGas, excessAirValue);
                        humidGasCalculator = new HumidGasCalculator(flueGas, water);

                        tNew = humidGasCalculator.GetDryBulbFromHumidEnthalpyHumidityAndPressure(flueGasHumidEnthalpy, flueGasMoistureContentDryBase, p);
                    } while (Math.Abs(tNew - flueGasTemp) / flueGasTemp > 1.0e-8 && counter < 100);
                    //} while (Math.Abs(excessDryAirNeeded - excessDryAirNeededOld) > 1.0e-6 && counter < 100);

                    if (counter == 100)
                    {
                        throw new CalculationFailedException("Calculation of flame temperature failed.");
                    }

                    Calculate(flueGasOutlet.Humidity, flueGasMoistureContentDryBase);
                    Calculate(excessAir, excessAirValue * 100);
                    flueGasComponents           = CreateDryingGasComponents(flueGasMoistureContentDryBase, flueGas);
                    flueGasOutlet.GasComponents = flueGasComponents;

                    if (flueGasOutlet.MassFlowRate.IsSpecifiedAndHasValue)
                    {
                        fuelMoleFlowRate = flueGasOutlet.MassFlowRate.Value / flueGasTotal;
                        Calculate(fuelInlet.MoleFlowRate, fuelMoleFlowRate);
                    }
                    else
                    {
                        Calculate(flueGasOutlet.MassFlowRate, flueGasTotal * fuelMoleFlowRate);
                    }

                    Calculate(airInlet.MassFlowRateDryBase, dryAirMassNeeded * fuelMoleFlowRate);
                    Calculate(heatLoss, heatLossValue * fuelMoleFlowRate);

                    totalHeatGenerated *= fuelMoleFlowRate;
                }

                Calculate(totalHeatGeneration, totalHeatGenerated);
            }

            if (flueGasOutlet.Temperature.HasValue && totalHeatGeneration.HasValue)
            {
                solveState = SolveState.Solved;
                double oxygenMassFraction = moleFractionOxygenNeeded * excessAirValue * oxygen.MolarWeight / flueGasTotal;
                double oxygenMoleFraction = moleFractionOxygenNeeded * excessAirValue / (1 + airMassNeeded / air.MolarWeight);
                Calculate(oxygenMassFractionFlueGas, oxygenMassFraction);
                Calculate(oxygenMoleFractionFlueGas, oxygenMoleFraction);
            }
        }