Example #1
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);
        }
Example #2
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);
            }
        }