Esempio n. 1
0
        private CompositeSubstance CreateDryFlueGasSubstance(double moleFractionCarbon, double moleFractionSulfur, double moleFractionCarbonDioxide, double moleFractionNitrogen, double moleFractionOxygenNeeded, double dryAirMassNeeded, double dryFlueGas, double excessAirValue)
        {
            ArrayList componentList             = new ArrayList();
            double    massFractionCarbonDioxide = (moleFractionCarbon + moleFractionCarbonDioxide) * carbonDioxide.MolarWeight / dryFlueGas;

            componentList.Add(new MaterialComponent(carbonDioxide, massFractionCarbonDioxide));

            //moleFractionNitrogen is the mole fraction of nitrogen in original gas fuel
            double massFractionNitrogen = (dryAirMassNeeded * NITROGEN_MOLE_FRACTION_IN_AIR * nitrogen.MolarWeight / air.MolarWeight + moleFractionNitrogen * nitrogen.MolarWeight) / dryFlueGas;

            componentList.Add(new MaterialComponent(nitrogen, massFractionNitrogen));

            double massFractionSulfurDioxide = moleFractionSulfur * sulfurDioxide.MolarWeight / dryFlueGas;

            componentList.Add(new MaterialComponent(sulfurDioxide, massFractionSulfurDioxide));

            double massFractionOxygen = moleFractionOxygenNeeded * excessAirValue * oxygen.MolarWeight / dryFlueGas;

            componentList.Add(new MaterialComponent(oxygen, massFractionOxygen));

            double massFractionArgon = dryAirMassNeeded * ARGON_MOLE_FRACTION_IN_AIR * argon.MolarWeight / air.MolarWeight / dryFlueGas;

            componentList.Add(new MaterialComponent(argon, massFractionArgon));

            CompositeSubstance flueGas = new CompositeSubstance("Flue Gas", componentList);

            return(flueGas);
        }
Esempio n. 2
0
        public static double GetDensity(ArrayList materialComponents, double t)
        {
            t = t - 273.15;
            double             total = 0.0;
            double             den   = 0;
            double             massFrac;
            MaterialComponent  dryMatComponent  = materialComponents[0] as MaterialComponent;
            CompositeSubstance drySubstance     = dryMatComponent.Substance as CompositeSubstance;
            double             dryTotalFraction = dryMatComponent.GetMassFractionValue();

            ArrayList components = drySubstance.Components;

            foreach (MaterialComponent mc in components)
            {
                Substance s = mc.Substance;
                massFrac = mc.GetMassFractionValue();
                if (s.Name == "Carbohydrate")
                {
                    den = GetCarbohydrateDensity(t);
                }
                else if (s.Name == "Ash")
                {
                    den = GetAshDensity(t);
                }
                else if (s.Name == "Fiber")
                {
                    den = GetFiberDensity(t);
                }
                else if (s.Name == "Fat")
                {
                    den = GetFatDensity(t);
                }
                else if (s.Name == "Protein")
                {
                    den = GetProteinDensity(t);
                }

                total += dryTotalFraction * massFrac / den;
            }

            MaterialComponent moistureComponent = materialComponents[1] as MaterialComponent;
            double            moistureFraction  = moistureComponent.GetMassFractionValue();
            double            moistureDensity   = GetWaterDensity(t);

            total += moistureFraction / moistureDensity;

            double density = 1.0 / total;

            return(density);
        }
Esempio n. 3
0
        public static double GetCp(ArrayList materialComponents, double t)
        {
            t = t - 273.15;
            double heatCapacity = 0.0;
            double cp           = 0;
            double massFrac;

            MaterialComponent  dryMatComponent  = materialComponents[0] as MaterialComponent;
            CompositeSubstance drySubstance     = dryMatComponent.Substance as CompositeSubstance;
            double             dryTotalFraction = dryMatComponent.GetMassFractionValue();

            ArrayList components = drySubstance.Components;

            foreach (MaterialComponent mc in components)
            {
                Substance s = mc.Substance;
                massFrac = mc.GetMassFractionValue();
                if (s.Name == "Carbohydrate")
                {
                    cp = GetCarbohydrateCp(t);
                }
                else if (s.Name == "Ash")
                {
                    cp = GetAshCp(t);
                }
                else if (s.Name == "Fiber")
                {
                    cp = GetFiberCp(t);
                }
                else if (s.Name == "Fat")
                {
                    cp = GetFatCp(t);
                }
                else if (s.Name == "Protein")
                {
                    cp = GetProteinCp(t);
                }

                heatCapacity += cp * massFrac * dryTotalFraction;
            }

            MaterialComponent moistureComponent = materialComponents[1] as MaterialComponent;
            double            moistureFraction  = moistureComponent.GetMassFractionValue();

            cp = GetWaterCp(t);

            heatCapacity += cp * moistureFraction;

            return(1000 * heatCapacity);
        }
Esempio n. 4
0
        public static double GetCp(ArrayList materialComponents, double t)
        {
            //t = t - 273.15;
            double heatCapacity = 0.0;
            //double cp = 0;
            //double massFrac;

            MaterialComponent  dryMatComponent  = materialComponents[0] as MaterialComponent;
            CompositeSubstance drySubstance     = dryMatComponent.Substance as CompositeSubstance;
            double             dryTotalFraction = dryMatComponent.GetMassFractionValue();
            double             boneDryCp        = GetAbsoluteDryCp(drySubstance, t); //Cp unit is J/kg.k

            //ArrayList components = drySubstance.Components;
            //foreach (MaterialComponent mc in components) {
            //   Substance s = mc.Substance;
            //   massFrac = mc.GetMassFractionValue();
            //   if (s.Name == "Carbohydrate") {
            //      cp = GetCarbohydrateCp(t);
            //   }
            //   else if (s.Name == "Ash") {
            //      cp = GetAshCp(t);
            //   }
            //   else if (s.Name == "Fiber") {
            //      cp = GetFiberCp(t);
            //   }
            //   else if (s.Name == "Fat") {
            //      cp = GetFatCp(t);
            //   }
            //   else if (s.Name == "Protein") {
            //      cp = GetProteinCp(t);
            //   }

            //   heatCapacity += cp * massFrac * dryTotalFraction;
            //}

            MaterialComponent moistureComponent = materialComponents[1] as MaterialComponent;
            double            moistureFraction  = moistureComponent.GetMassFractionValue();
            double            moistureCp        = 1000 * GetWaterCp(t - 273.15);//convert from kJ/kg.k to J/kg.k, we have to multiply 1000

            heatCapacity = boneDryCp * dryTotalFraction + moistureCp * moistureFraction;

            return(heatCapacity);
        }
Esempio n. 5
0
        public static double GetAbsoluteDryCp(CompositeSubstance drySubstance, double t)
        {
            t = t - 273.15;
            double heatCapacity = 0.0;
            double cp           = 0;
            double massFrac;

            ArrayList components = drySubstance.Components;

            foreach (MaterialComponent mc in components)
            {
                Substance s = mc.Substance;
                massFrac = mc.GetMassFractionValue();
                if (s.Name == "Carbohydrate")
                {
                    cp = GetCarbohydrateCp(t);
                }
                else if (s.Name == "Ash")
                {
                    cp = GetAshCp(t);
                }
                else if (s.Name == "Fiber")
                {
                    cp = GetFiberCp(t);
                }
                else if (s.Name == "Fat")
                {
                    cp = GetFatCp(t);
                }
                else if (s.Name == "Protein")
                {
                    cp = GetProteinCp(t);
                }

                heatCapacity += cp * massFrac;
            }

            return(1000 * heatCapacity);
        }
Esempio n. 6
0
        private void Solve()
        {
            SubstanceCatalog catalog       = SubstanceCatalog.GetInstance();
            Substance        carbon        = catalog.GetSubstance("carbon");
            Substance        hydrogen      = catalog.GetSubstance("hydrogen");
            Substance        oxygen        = catalog.GetSubstance("oxygen");
            Substance        sulfur        = catalog.GetSubstance("sulfur");
            Substance        air           = catalog.GetSubstance("air");
            Substance        carbonDioxide = catalog.GetSubstance("carbon dioxide");
            Substance        sulfurDioxide = catalog.GetSubstance("sulfur dioxide");
            Substance        water         = catalog.GetSubstance("water");
            Substance        nitrogen      = catalog.GetSubstance("nitrogen");
            Substance        argon         = catalog.GetSubstance("argon");
            //Substance ash = SubstanceCatalog.GetInstance().GetSubstance("ash");

            double totalEenthalpyOfReactantInFuelInlet = 0;
            double moleFractionCarbon   = 0;
            double moleFractionHydrogen = 0;
            double moleFractionSulfur   = 0;
            double moleFractionOxygen   = 0;
            //double massAsh = 0;
            double             moleFractionCarbonDioxide = 0;
            double             moleFractionNitrogen      = 0;
            MaterialComponents components = fuelInlet.Components;
            MaterialComponent  component;
            Substance          mySubstance;
            double             myMassFraction;

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

                    if (mySubstance == carbonDioxide)
                    {
                        moleFractionCarbonDioxide = myMassFraction / carbonDioxide.MolarWeight;
                    }
                    else if (mySubstance == nitrogen)
                    {
                        moleFractionNitrogen = myMassFraction / nitrogen.MolarWeight;
                    }
                    else
                    {
                        totalEenthalpyOfReactantInFuelInlet += myMassFraction * ThermalPropCalculator.Instance.CalculateEnthalpyOfFormation(t, mySubstance);
                        formula  = mySubstance.Formula;
                        elements = formula.Elements;
                        foreach (string element in elements)
                        {
                            elementCount = formula.GetElementCount(element);
                            if (element == "C")
                            {
                                moleFractionCarbon += elementCount * myMassFraction / carbon.MolarWeight;
                            }
                            else if (element == "H")
                            {
                                moleFractionHydrogen += elementCount * 0.25 * myMassFraction / hydrogen.MolarWeight;
                            }
                            else if (element == "O")
                            {
                                moleFractionOxygen = elementCount * 0.5 * myMassFraction / oxygen.MolarWeight;
                            }
                            else if (element == "S")
                            {
                                moleFractionSulfur += elementCount * myMassFraction / sulfur.MolarWeight;
                            }
                        }
                    }
                }
            }

            double fuelMassFlowRate                   = fuelInlet.MassFlowRate.Value;
            double moleFractionOxygenNeeded           = moleFractionCarbon + moleFractionHydrogen + moleFractionSulfur - moleFractionOxygen;
            double totalExactOxygenMassNeeded         = fuelMassFlowRate * moleFractionOxygenNeeded * oxygen.MolarWeight;
            double totalOxygenMoleNeeded              = fuelMassFlowRate * moleFractionOxygenNeeded * (1.0 + excessAir.Value);
            double totalDryAirMassNeeded              = totalOxygenMoleNeeded * air.MolarWeight / 0.21;
            double totalMoistureMassCarriedByInletAir = totalDryAirMassNeeded * airInlet.Humidity.Value;
            double totalAirMassNeeded                 = totalDryAirMassNeeded + totalMoistureMassCarriedByInletAir;

            Calculate(airInlet.MassFlowRate, totalAirMassNeeded);

            double totalMoitureGeneratedByReaction = fuelMassFlowRate * moleFractionHydrogen * water.MolarWeight;
            double totalMoistureInFlueGas          = totalMoitureGeneratedByReaction + totalMoistureMassCarriedByInletAir;

            double totalDryFlueGas       = totalDryAirMassNeeded + fuelMassFlowRate - totalMoitureGeneratedByReaction;
            double totalFlueGasGenerated = totalDryFlueGas + totalMoistureInFlueGas;

            Calculate(flueGasOutlet.MassFlowRate, totalFlueGasGenerated);

            double flueGasMoistureContentDryBase = totalMoistureInFlueGas / totalDryFlueGas;

            Calculate(flueGasOutlet.Humidity, flueGasMoistureContentDryBase);

            ArrayList componentList             = new ArrayList();
            double    massFractionCarbonDioxide = fuelMassFlowRate * (moleFractionCarbon + moleFractionCarbonDioxide) * carbonDioxide.MolarWeight / totalDryFlueGas;

            componentList.Add(new MaterialComponent(carbonDioxide, massFractionCarbonDioxide));

            double massFractionNitrogen = (totalDryAirMassNeeded * 0.78 + fuelMassFlowRate * moleFractionNitrogen) / totalDryFlueGas;

            componentList.Add(new MaterialComponent(nitrogen, massFractionNitrogen));

            double massFractionSulfurDioxide = fuelMassFlowRate * moleFractionSulfur * sulfurDioxide.MolarWeight / totalDryFlueGas;

            componentList.Add(new MaterialComponent(sulfurDioxide, massFractionSulfurDioxide));

            double massFractionOxygen = fuelMassFlowRate * moleFractionOxygenNeeded * excessAir.Value * oxygen.MolarWeight / totalDryFlueGas;

            componentList.Add(new MaterialComponent(oxygen, massFractionOxygen));

            double massFractionArgon = totalDryAirMassNeeded * 0.01 / totalDryFlueGas;

            componentList.Add(new MaterialComponent(argon, massFractionArgon));

            CompositeSubstance flueGas = new CompositeSubstance("Flue Gas", componentList);

            MaterialComponents flueGasComponents = new MaterialComponents();

            flueGasComponents.Add(new MaterialComponent(flueGas, 1 / (1 + flueGasMoistureContentDryBase)));
            flueGasComponents.Add(new MaterialComponent(water, flueGasMoistureContentDryBase / (1 + flueGasMoistureContentDryBase)));

            flueGasOutlet.Components = flueGasComponents;

            double fuelInletEnthalpy  = fuelMassFlowRate * fuelInlet.SpecificEnthalpy.Value;
            double airInletEnthalpy   = totalAirMassNeeded * airInlet.SpecificEnthalpy.Value;
            double totalHeatGenerated = Constants.NO_VALUE;

            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 * fuelMassFlowRate;
                    double totalFlueGasSpecificEnthalpy = (fuelInletEnthalpy + airInletEnthalpy + totalHeatGenerated) / totalFlueGasGenerated;
                    Calculate(flueGasOutlet.SpecificEnthalpy, totalFlueGasSpecificEnthalpy);
                }
            }
            else if (fuelInlet is DetailedFuelStream)
            {
                HumidGasCalculator    humidGasCalculator = new HumidGasCalculator(flueGas, water);
                ThermalPropCalculator propCalculator     = ThermalPropCalculator.Instance;

                double totalEenthalpyOfProductCarbonDioxide;
                double totalEenthalpyOfProductWater;
                double totalEenthalpyOfProductSulfer;
                double totalEenthalpyOfProduct;
                double totalFlueGasSpecificEnthalpy;

                double t = fuelInlet.Temperature.Value;;
                totalEenthalpyOfReactantInFuelInlet *= fuelMassFlowRate;
                double totalEnthalpyOfReactantOxygen = totalExactOxygenMassNeeded * propCalculator.CalculateEnthalpyOfFormation(t, oxygen);
                double totalEenthalpyOfReactants     = totalEenthalpyOfReactantInFuelInlet + totalEnthalpyOfReactantOxygen;

                double p       = flueGasOutlet.Pressure.Value;
                double tNew    = t;
                int    counter = 0;
                do
                {
                    counter++;
                    t = tNew;
                    totalEenthalpyOfProductCarbonDioxide = fuelMassFlowRate * moleFractionCarbon * propCalculator.CalculateEnthalpyOfFormation(t, carbonDioxide);
                    totalEenthalpyOfProductWater         = fuelMassFlowRate * moleFractionHydrogen * propCalculator.CalculateEnthalpyOfFormation(t, water);
                    totalEenthalpyOfProductSulfer        = fuelMassFlowRate * moleFractionSulfur * propCalculator.CalculateEnthalpyOfFormation(t, sulfurDioxide);
                    totalEenthalpyOfProduct      = totalEenthalpyOfProductCarbonDioxide + totalEenthalpyOfProductWater + totalEenthalpyOfProductSulfer;
                    totalHeatGenerated           = totalEenthalpyOfProduct - totalEenthalpyOfReactants;
                    totalFlueGasSpecificEnthalpy = (fuelInletEnthalpy + airInletEnthalpy + totalHeatGenerated) / totalFlueGasGenerated;

                    tNew = humidGasCalculator.GetDryBulbFromHumidEnthalpyHumidityAndPressure(totalFlueGasSpecificEnthalpy, flueGasMoistureContentDryBase, p);
                } while (Math.Abs(tNew - t) < 1.0e-6 && counter < 100);

                if (counter == 100)
                {
                }

                Calculate(flueGasOutlet.Temperature, tNew);
            }
        }
Esempio n. 7
0
        public static double GetThermalConductivity(ArrayList materialComponents, double t)
        {
            t = t - 273.15;
            double thermalCond = 0.0;
            double k           = 0;
            double den         = 0;
            double massFrac;

            double total = 0.0;

            MaterialComponent  dryMatComponent  = materialComponents[0] as MaterialComponent;
            CompositeSubstance drySubstance     = dryMatComponent.Substance as CompositeSubstance;
            double             dryTotalFraction = dryMatComponent.GetMassFractionValue();

            ArrayList components = drySubstance.Components;

            foreach (MaterialComponent mc in components)
            {
                Substance s = mc.Substance;
                massFrac = mc.GetMassFractionValue();
                if (s.Name == "Carbohydrate")
                {
                    den = GetCarbohydrateDensity(t);
                }
                else if (s.Name == "Ash")
                {
                    den = GetAshDensity(t);
                }
                else if (s.Name == "Fiber")
                {
                    den = GetFiberDensity(t);
                }
                else if (s.Name == "Fat")
                {
                    den = GetFatDensity(t);
                }
                else if (s.Name == "Protein")
                {
                    den = GetProteinDensity(t);
                }

                total += dryTotalFraction * massFrac / den;
            }

            double            volumeFraction;
            double            moistureDensity;
            MaterialComponent moistureComponent = materialComponents[1] as MaterialComponent;
            double            moistureFraction  = moistureComponent.GetMassFractionValue();

            moistureDensity = GetWaterDensity(t);

            total += moistureFraction / moistureDensity;

            foreach (MaterialComponent mc in components)
            {
                Substance s = mc.Substance;
                massFrac = mc.GetMassFractionValue();
                if (s.Name == "")
                {
                    k   = GetCarbohydrateThermalConductivity(t);
                    den = GetCarbohydrateDensity(t);
                }
                else if (s.Name == "Ash")
                {
                    k   = GetAshThermalConductivity(t);
                    den = GetAshDensity(t);
                }
                else if (s.Name == "Fiber")
                {
                    k   = GetFiberThermalConductivity(t);
                    den = GetFiberDensity(t);
                }
                else if (s.Name == "Fat")
                {
                    k   = GetFatThermalConductivity(t);
                    den = GetFatDensity(t);
                }
                else if (s.Name == "Protein")
                {
                    k   = GetProteinThermalConductivity(t);
                    den = GetProteinDensity(t);
                }

                volumeFraction = dryTotalFraction * massFrac / den / total;
                thermalCond   += k * volumeFraction;
            }

            //water conductivity
            k = GetWaterThermalConductivity(t);

            volumeFraction = dryTotalFraction * moistureFraction / moistureDensity / total;
            thermalCond   += k * volumeFraction;

            return(thermalCond);
        }
Esempio n. 8
0
        private static DryingGasComponents CreateDryingGasComponents(double flueGasMoistureContentDryBase, CompositeSubstance flueGas)
        {
            ArrayList compList = new ArrayList();

            compList.Add(new MaterialComponent(flueGas, 1 / (1 + flueGasMoistureContentDryBase)));
            compList.Add(new MaterialComponent(water, flueGasMoistureContentDryBase / (1 + flueGasMoistureContentDryBase)));

            DryingGasComponents flueGasComponents = new DryingGasComponents(compList);

            ArrayList         gasCompList = new ArrayList();
            MaterialComponent pc          = new MaterialComponent(flueGas);

            gasCompList.Add(pc);
            pc = new MaterialComponent(water);
            gasCompList.Add(pc);
            GasPhase gp = new GasPhase("Drying Gas Gas Phase", gasCompList);

            flueGasComponents.AddPhase(gp);

            return(flueGasComponents);
        }
Esempio n. 9
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);
            }
        }