Esempio n. 1
0
        private void Solve()
        {
            //Mass Transfer--material particles transfer from gas stream to liquid stream
            //Mass Transfer--moisture transfers from liquid stream to gas stream
            //by an adiabaitc saturation process if ScrubberType is General.
            DryingMaterialStream dmsInlet  = liquidInlet as DryingMaterialStream;
            DryingMaterialStream dmsOutlet = liquidOutlet as DryingMaterialStream;

            DryingGasStream dgsInlet  = gasInlet as DryingGasStream;
            DryingGasStream dgsOutlet = gasOutlet as DryingGasStream;

            //gas stream goes through an adiabatic saturation process
            double tg1 = dgsInlet.Temperature.Value;
            double y1  = dgsInlet.Humidity.Value;
            double tw1 = dgsInlet.WetBulbTemperature.Value;
            double td1 = dgsInlet.DewPoint.Value;
            double fy1 = dgsInlet.RelativeHumidity.Value;

            double tg2 = dgsOutlet.Temperature.Value;
            double y2  = dgsOutlet.Humidity.Value;
            double tw2 = dgsOutlet.WetBulbTemperature.Value;
            double td2 = dgsOutlet.DewPoint.Value;
            double fy2 = dgsOutlet.RelativeHumidity.Value;

            double ih = 0;
            double p1 = dgsInlet.Pressure.Value;
            double p2 = dgsOutlet.Pressure.Value;

            if (p1 == Constants.NO_VALUE || p2 == Constants.NO_VALUE)
            {
                return;
            }
            HumidGasCalculator humidGasCalculator = GetHumidGasCalculator();

            if (tg1 != Constants.NO_VALUE && y1 != Constants.NO_VALUE)
            {
                ih = humidGasCalculator.GetHumidEnthalpyFromDryBulbHumidityAndPressure(tg1, y1, p1);
                if (tg2 != Constants.NO_VALUE)
                {
                    y2 = humidGasCalculator.GetHumidityFromHumidEnthalpyTemperatureAndPressure(ih, tg2, p2);
                    if (y2 <= 0.0)
                    {
                        y2 = 1.0e-6;
                    }
                    Calculate(dgsOutlet.MoistureContentDryBase, y2);
                    solveState = SolveState.Solved;
                }
                else if (y2 != Constants.NO_VALUE)
                {
                    tg2 = humidGasCalculator.GetDryBulbFromHumidEnthalpyHumidityAndPressure(ih, y2, p2);
                    Calculate(dgsOutlet.Temperature, tg2);
                    solveState = SolveState.Solved;
                }
                else if (td2 != Constants.NO_VALUE)
                {
                    y2  = humidGasCalculator.GetHumidityFromDewPointAndPressure(td2, p2);
                    tg2 = humidGasCalculator.GetDryBulbFromHumidEnthalpyHumidityAndPressure(ih, y2, p2);
                    Calculate(dgsOutlet.Temperature, tg2);
                    solveState = SolveState.Solved;
                }
                else if (fy2 != Constants.NO_VALUE)
                {
                    double fy_temp    = 0;
                    double delta      = 10.0;
                    double totalDelta = delta;
                    tg2 = tg1 - delta;
                    bool negativeLastTime = false;

                    int counter = 0;
                    do
                    {
                        counter++;
                        y2      = humidGasCalculator.GetHumidityFromHumidEnthalpyTemperatureAndPressure(ih, tg2, p2);
                        fy_temp = humidGasCalculator.GetRelativeHumidityFromDryBulbHumidityAndPressure(tg2, y2, p2);
                        if (fy2 > fy_temp)
                        {
                            if (negativeLastTime)
                            {
                                delta /= 2.0; //testing finds delta/2.0 is almost optimal
                            }
                            totalDelta      += delta;
                            negativeLastTime = false;
                        }
                        else if (fy2 < fy_temp)
                        {
                            delta           /= 2.0; //testing finds delta/2.0 is almost optimal
                            totalDelta      -= delta;
                            negativeLastTime = true;
                        }
                        tg2 = tg1 - totalDelta;
                    } while (Math.Abs(fy2 - fy_temp) > 1.0e-6 && counter <= 200);

                    if (counter < 200)
                    {
                        Calculate(dgsOutlet.Temperature, tg2);
                        solveState = SolveState.Solved;
                    }
                }

                if (solveState == SolveState.Solved)
                {
                    double fy = humidGasCalculator.GetRelativeHumidityFromDryBulbHumidityAndPressure(tg2, y2, p2);
                    if (fy > 1.0)
                    {
                        solveState = SolveState.NotSolved;
                        string msg = "Specified gas inlet state makes the relative humidity of the outlet greater than 1.0.";
                        throw new InappropriateSpecifiedValueException(msg);
                    }
                }
            }
            else if (tg2 != Constants.NO_VALUE && y2 != Constants.NO_VALUE)
            {
                ih = humidGasCalculator.GetHumidEnthalpyFromDryBulbHumidityAndPressure(tg2, y2, p2);
                if (tg1 != Constants.NO_VALUE)
                {
                    y1 = humidGasCalculator.GetHumidityFromHumidEnthalpyTemperatureAndPressure(ih, tg1, p1);
                    Calculate(dgsInlet.MoistureContentDryBase, y1);
                    solveState = SolveState.Solved;
                }
                else if (y1 != Constants.NO_VALUE)
                {
                    tg1 = humidGasCalculator.GetDryBulbFromHumidEnthalpyHumidityAndPressure(ih, y1, p1);
                    Calculate(dgsInlet.Temperature, tg1);
                    solveState = SolveState.Solved;
                }
                else if (td1 != Constants.NO_VALUE)
                {
                    y1  = humidGasCalculator.GetHumidityFromDewPointAndPressure(td1, p1);
                    tg1 = humidGasCalculator.GetDryBulbFromHumidEnthalpyHumidityAndPressure(ih, y1, p1);
                    Calculate(dgsInlet.Temperature, tg1);
                    solveState = SolveState.Solved;
                }
                else if (fy1 != Constants.NO_VALUE)
                {
                    double fy_temp    = 0;
                    double delta      = 10.0;
                    double totalDelta = delta;
                    tg1 = tg2 + delta;
                    bool negativeLastTime = false;

                    int counter = 0;
                    do
                    {
                        counter++;
                        y1      = humidGasCalculator.GetHumidityFromHumidEnthalpyTemperatureAndPressure(ih, tg1, p1);
                        fy_temp = humidGasCalculator.GetRelativeHumidityFromDryBulbHumidityAndPressure(tg1, y1, p1);
                        if (fy1 < fy_temp)
                        {
                            if (negativeLastTime)
                            {
                                delta /= 2.0; //testing finds delta/2.0 is almost optimal
                            }
                            totalDelta      += delta;
                            negativeLastTime = false;
                        }
                        else if (fy1 > fy_temp)
                        {
                            delta           /= 2.0; //testing finds delta/2.0 is almost optimal
                            totalDelta      -= delta;
                            negativeLastTime = true;
                        }
                        tg1 = tg2 + totalDelta;
                    } while (Math.Abs(fy1 - fy_temp) > 1.0e-6 && counter <= 200);

                    if (counter < 200)
                    {
                        Calculate(dgsInlet.Temperature, tg1);
                        solveState = SolveState.Solved;
                    }
                }
            }
            //end of adiabatic saturation process calculatioin


            //have to recalculate the streams so that the following balance calcualtion
            //can have all the latest balance calculated values taken into account
            //PostSolve(false);
            UpdateStreamsIfNecessary();

            balanceModel.DoBalanceCalculation();

            double inletDustMassFlowRate      = Constants.NO_VALUE;
            double outletDustMassFlowRate     = Constants.NO_VALUE;
            double inletDustMoistureFraction  = 0.0;
            double outletDustMoistureFraction = 0.0;

            DryingGasComponents dgc;

            if (InletParticleLoading.HasValue && gasInlet.VolumeFlowRate.HasValue)
            {
                inletDustMassFlowRate = InletParticleLoading.Value * gasInlet.VolumeFlowRate.Value;
                dgc = dgsInlet.GasComponents;
                if (dgc.SolidPhase != null)
                {
                    SolidPhase        sp = dgc.SolidPhase;
                    MaterialComponent mc = sp[1];
                    inletDustMoistureFraction = mc.GetMassFractionValue();
                }
            }

            if (OutletParticleLoading.HasValue && gasOutlet.VolumeFlowRate.HasValue)
            {
                outletDustMassFlowRate = OutletParticleLoading.Value * gasOutlet.VolumeFlowRate.Value;
                dgc = dgsOutlet.GasComponents;
                if (dgc.SolidPhase != null)
                {
                    SolidPhase        sp = dgc.SolidPhase;
                    MaterialComponent mc = sp[1];
                    inletDustMoistureFraction = mc.GetMassFractionValue();
                }
            }

            double inletMoistureFlowRate  = Constants.NO_VALUE;
            double outletMoistureFlowRate = Constants.NO_VALUE;

            if (dgsInlet.MassFlowRateDryBase.HasValue && dgsInlet.MoistureContentDryBase.HasValue)
            {
                inletMoistureFlowRate = dgsInlet.MassFlowRateDryBase.Value * dgsInlet.MoistureContentDryBase.Value;
            }

            if (dgsOutlet.MassFlowRateDryBase.HasValue && dgsOutlet.MoistureContentDryBase.HasValue)
            {
                outletMoistureFlowRate = dgsOutlet.MassFlowRateDryBase.Value * dgsOutlet.MoistureContentDryBase.Value;
            }

            double materialFromGas = 0.0;

            if (inletDustMassFlowRate != Constants.NO_VALUE && outletDustMassFlowRate != Constants.NO_VALUE &&
                inletMoistureFlowRate != Constants.NO_VALUE && outletMoistureFlowRate != Constants.NO_VALUE)
            {
                double moistureToGas = outletMoistureFlowRate - inletMoistureFlowRate;
                materialFromGas = inletDustMassFlowRate - outletDustMassFlowRate;
                double moistureOfMaterialFromGas = inletDustMassFlowRate * inletDustMoistureFraction - outletDustMassFlowRate * outletDustMoistureFraction;

                if (dmsInlet.MassFlowRate.HasValue)
                {
                    double outletMassFlowRate = dmsInlet.MassFlowRate.Value + materialFromGas - moistureToGas;
                    Calculate(dmsOutlet.MassFlowRate, outletMassFlowRate);

                    if (dmsInlet.MoistureContentWetBase.HasValue)
                    {
                        double inletMaterialMoistureFlowRate  = dmsInlet.MassFlowRate.Value * dmsInlet.MoistureContentWetBase.Value;
                        double outletMaterialMoistureFlowRate = inletMaterialMoistureFlowRate - moistureToGas + moistureOfMaterialFromGas;
                        double outletMoistureContentWetBase   = outletMaterialMoistureFlowRate / outletMassFlowRate;
                        Calculate(dmsOutlet.MoistureContentWetBase, outletMoistureContentWetBase);
                        solveState = SolveState.Solved;
                    }
                    else if (dmsOutlet.MoistureContentWetBase.HasValue)
                    {
                        double outletMaterialMoistureFlowRate = dmsOutlet.MassFlowRate.Value * dmsInlet.MoistureContentWetBase.Value;
                        double inletMaterialMoistureFlowRate  = outletMaterialMoistureFlowRate + moistureToGas - moistureOfMaterialFromGas;
                        double inletMoistureContentWetBase    = inletMaterialMoistureFlowRate / dmsInlet.MassFlowRate.Value;
                        Calculate(dmsInlet.MoistureContentWetBase, inletMoistureContentWetBase);
                        solveState = SolveState.Solved;
                    }
                }
                else if (dmsOutlet.MassFlowRate.HasValue)
                {
                    double inletMassFlowRate = dmsOutlet.MassFlowRate.Value - materialFromGas + moistureToGas;
                    Calculate(dmsInlet.MassFlowRate, inletMassFlowRate);

                    if (dmsInlet.MoistureContentWetBase.HasValue)
                    {
                        double inletMaterialMoistureFlowRate  = dmsInlet.MassFlowRate.Value * dmsInlet.MoistureContentWetBase.Value;
                        double outletMaterialMoistureFlowRate = inletMaterialMoistureFlowRate - moistureToGas + moistureOfMaterialFromGas;
                        double outletMoistureContentWetBase   = outletMaterialMoistureFlowRate / dmsOutlet.MassFlowRate.Value;
                        Calculate(dmsOutlet.MoistureContentWetBase, outletMoistureContentWetBase);
                        solveState = SolveState.Solved;
                    }
                    else if (dmsOutlet.MoistureContentWetBase.HasValue)
                    {
                        double outletMaterialMoistureFlowRate = dmsOutlet.MassFlowRate.Value * dmsInlet.MoistureContentWetBase.Value;
                        double inletMaterialMoistureFlowRate  = outletMaterialMoistureFlowRate + moistureToGas - moistureOfMaterialFromGas;
                        double inletMoistureContentWetBase    = inletMaterialMoistureFlowRate / inletMassFlowRate;
                        Calculate(dmsInlet.MoistureContentWetBase, inletMoistureContentWetBase);
                        solveState = SolveState.Solved;
                    }
                }
                else if (dmsOutlet.MassConcentration.HasValue)
                {
                    double cValue            = dmsOutlet.MassConcentration.Value;
                    double inletMassFlowRate = (materialFromGas * (1 - cValue) + moistureToGas * cValue) / cValue;
                    Calculate(dmsInlet.MassFlowRate, inletMassFlowRate);
                    double outletMassFlowRate = inletMassFlowRate + materialFromGas - moistureToGas;
                    Calculate(dmsOutlet.MassFlowRate, outletMassFlowRate);
                    solveState = SolveState.Solved;
                }
            }

            MoistureProperties moistureProperties        = (this.unitOpSystem as EvaporationAndDryingSystem).GetMoistureProperties(((DryingMaterialStream)liquidInlet).MaterialComponents.Moisture.Substance);
            double             enthalpyOfMaterialFromGas = 0.0;

            if (dmsOutlet.GetCpOfAbsoluteDryMaterial() != Constants.NO_VALUE && inletDustMoistureFraction != Constants.NO_VALUE && gasInlet.Temperature.HasValue)
            {
                double tempValue = gasInlet.Temperature.Value;
                double liquidCp  = moistureProperties.GetSpecificHeatOfLiquid(tempValue);
                double specificHeatOfSolidPhase = (1.0 - inletDustMoistureFraction) * dmsOutlet.GetCpOfAbsoluteDryMaterial() + inletDustMoistureFraction * liquidCp;
                enthalpyOfMaterialFromGas = materialFromGas * specificHeatOfSolidPhase * (tempValue - 273.15);
            }

            if (gasInlet.SpecificEnthalpy.HasValue && gasInlet.MassFlowRate.HasValue &&
                gasOutlet.SpecificEnthalpy.HasValue && gasOutlet.MassFlowRate.HasValue)
            {
                double gasEnthalpyLoss = gasInlet.SpecificEnthalpy.Value * gasInlet.MassFlowRate.Value -
                                         gasOutlet.SpecificEnthalpy.Value * gasOutlet.MassFlowRate.Value;

                if (liquidInlet.SpecificEnthalpy.HasValue && liquidInlet.MassFlowRate.HasValue &&
                    liquidOutlet.MassFlowRate.HasValue)
                {
                    double totalLiquidOutletEnthalpy    = gasEnthalpyLoss + enthalpyOfMaterialFromGas + liquidInlet.SpecificEnthalpy.Value * liquidInlet.MassFlowRate.Value;
                    double specificLiquidOutletEnthalpy = totalLiquidOutletEnthalpy / liquidOutlet.MassFlowRate.Value;
                    Calculate(liquidOutlet.SpecificEnthalpy, specificLiquidOutletEnthalpy);
                }
                //else if (gasInlet.SpecificEnthalpy.HasValue && gasInlet.MassFlowRate.HasValue &&
                //               gasOutlet.SpecificEnthalpy.HasValue && gasOutlet.MassFlowRate.HasValue &&
                //               liquidOutlet.SpecificEnthalpy.HasValue && liquidOutlet.MassFlowRate.HasValue &&
                //               liquidInlet.MassFlowRate.HasValue) {
                //   double totalLiquidInletEnthalpy = liquidOutlet.SpecificEnthalpy.Value * liquidOutlet.MassFlowRate.Value - gasEnthalpyLoss - enthalpyOfMaterialFromGas;
                //   double specificLiquidInletEnthalpy = totalLiquidInletEnthalpy / liquidInlet.MassFlowRate.Value;
                //   Calculate(liquidInlet.SpecificEnthalpy, specificLiquidInletEnthalpy);
                //}
            }
            else if (liquidInlet.SpecificEnthalpy.HasValue && liquidInlet.MassFlowRate.HasValue &&
                     liquidOutlet.SpecificEnthalpy.HasValue && liquidOutlet.MassFlowRate.HasValue)
            {
                double liquidEnthalpyLoss = liquidInlet.SpecificEnthalpy.Value * liquidInlet.MassFlowRate.Value -
                                            liquidOutlet.SpecificEnthalpy.Value * liquidOutlet.MassFlowRate.Value;

                if (gasInlet.SpecificEnthalpy.HasValue && gasInlet.MassFlowRate.HasValue &&
                    gasOutlet.MassFlowRate.HasValue)
                {
                    double totalGasOutletEnthalpy    = liquidEnthalpyLoss + gasInlet.SpecificEnthalpy.Value * gasInlet.MassFlowRate.Value + enthalpyOfMaterialFromGas;
                    double specificGasOutletEnthalpy = totalGasOutletEnthalpy / gasOutlet.MassFlowRate.Value;
                    Calculate(gasOutlet.SpecificEnthalpy, specificGasOutletEnthalpy);
                }
                //else if (gasOutlet.SpecificEnthalpy.HasValue && gasOutlet.MassFlowRate.HasValue &&
                //               gasInlet.MassFlowRate.HasValue) {
                //   double totalGasInletEnthalpy = gasOutlet.SpecificEnthalpy.Value * gasOutlet.MassFlowRate.Value - liquidEnthalpyLoss;
                //   double specificGasInletEnthalpy = totalGasInletEnthalpy / gasInlet.MassFlowRate.Value;
                //   Calculate(gasInlet.SpecificEnthalpy, specificGasInletEnthalpy);
                //}
            }

            if (liquidToGasVolumeRatio.HasValue && gasInlet.VolumeFlowRate.HasValue)
            {
                //double recirculationVolumeFlow = liquidToGasVolumeRatio.Value * gasInlet.VolumeFlowRate.Value;
                //Calculate(liquidRecirculationVolumeFlowRate, recirculationVolumeFlow);
                //if (liquidOutlet.Density.HasValue) {
                //   double recirculationMassFlow = recirculationVolumeFlow / liquidOutlet.Density.Value;
                //   Calculate(liquidRecirculationMassFlowRate, recirculationMassFlow);
                //}
            }
        }
Esempio n. 2
0
        public ErrorMessage SetState(DryingGasStream gasStream, PointF pt)
        {
            double p           = pressure.Value;
            double temperature = (double)pt.X;
            double humidity    = (double)pt.Y;
            double wetBulb;
            double dewPoint;
            double relativeHumidity;

            HumidGasCalculator humidGasCalculator = GetHumidGasCalculator();
            Hashtable          varAndValueTable   = new Hashtable();

            if (gasStream.Temperature.IsSpecified)
            {
                if (gasStream.Humidity.IsSpecified)
                {
                    varAndValueTable.Add(gasStream.MoistureContentDryBase, humidity);
                }
                else if (gasStream.WetBulbTemperature.IsSpecified)
                {
                    wetBulb = humidGasCalculator.GetWetBulbFromDryBulbHumidityAndPressure(temperature, humidity, p);
                    varAndValueTable.Add(gasStream.WetBulbTemperature, wetBulb);
                }
                else if (gasStream.DewPoint.IsSpecified)
                {
                    dewPoint = humidGasCalculator.GetDewPointFromHumidityAndPressure(humidity, p);
                    varAndValueTable.Add(gasStream.DewPoint, dewPoint);
                }
                else if (gasStream.RelativeHumidity.IsSpecified)
                {
                    relativeHumidity = humidGasCalculator.GetRelativeHumidityFromDryBulbHumidityAndPressure(temperature, humidity, p);
                    varAndValueTable.Add(gasStream.RelativeHumidity, relativeHumidity);
                }
                varAndValueTable.Add(gasStream.Temperature, temperature);
            }
            else if (gasStream.WetBulbTemperature.IsSpecified)
            {
                if (outputStream.DewPoint.IsSpecified)
                {
                    dewPoint = humidGasCalculator.GetDewPointFromHumidityAndPressure(humidity, p);
                    varAndValueTable.Add(gasStream.DewPoint, dewPoint);
                }
                else if (gasStream.RelativeHumidity.IsSpecified)
                {
                    relativeHumidity = humidGasCalculator.GetRelativeHumidityFromDryBulbHumidityAndPressure(temperature, humidity, p);
                    varAndValueTable.Add(currentStream.RelativeHumidity, relativeHumidity);
                }
                wetBulb = humidGasCalculator.GetWetBulbFromDryBulbHumidityAndPressure(temperature, humidity, p);
                varAndValueTable.Add(gasStream.WetBulbTemperature, wetBulb);
            }
            else if (gasStream.DewPoint.IsSpecified)
            {
                if (gasStream.RelativeHumidity.IsSpecified)
                {
                    relativeHumidity = humidGasCalculator.GetRelativeHumidityFromDryBulbHumidityAndPressure(temperature, humidity, pressure.Value);
                    varAndValueTable.Add(outputStream.RelativeHumidity, relativeHumidity);
                }
                dewPoint = humidGasCalculator.GetDewPointFromHumidityAndPressure(humidity, pressure.Value);
                varAndValueTable.Add(gasStream.DewPoint, dewPoint);
            }

            return(gasStream.Specify(varAndValueTable));
        }
Esempio n. 3
0
        private void Solve()
        {
            double p   = pressure.Value;
            double tg1 = inputStream.Temperature.Value;
            double y1  = inputStream.Humidity.Value;
            double tw1 = inputStream.WetBulbTemperature.Value;
            double td1 = inputStream.DewPoint.Value;
            double fy1 = inputStream.RelativeHumidity.Value;

            double tg2 = outputStream.Temperature.Value;
            double y2  = outputStream.Humidity.Value;
            double tw2 = outputStream.WetBulbTemperature.Value;
            double td2 = outputStream.DewPoint.Value;
            double fy2 = outputStream.RelativeHumidity.Value;

            double ih = 0;

            if (inputStream.Pressure.Value != p)
            {
                Calculate(inputStream.Pressure, p);
            }
            if (outputStream.Pressure.Value != p)
            {
                Calculate(outputStream.Pressure, p);
            }

            HumidGasCalculator humidGasCalculator = GetHumidGasCalculator();

            if (tg1 != Constants.NO_VALUE && y1 != Constants.NO_VALUE)
            {
                //wetBulb = humidGasCalculator.GetWetBulbFromDryBulbHumidityAndPressure(tg1, y1, p);
                ih = humidGasCalculator.GetHumidEnthalpyFromDryBulbHumidityAndPressure(tg1, y1, p);
                if (tg2 != Constants.NO_VALUE)
                {
                    y2 = humidGasCalculator.GetHumidityFromHumidEnthalpyTemperatureAndPressure(ih, tg2, p);
                    if (y2 <= 0.0)
                    {
                        y2 = 1.0e-6;
                    }

                    Calculate(outputStream.MoistureContentDryBase, y2);
                    solveState = SolveState.Solved;
                }
                else if (y2 != Constants.NO_VALUE)
                {
                    tg2 = humidGasCalculator.GetDryBulbFromHumidEnthalpyHumidityAndPressure(ih, y2, p);
                    Calculate(outputStream.Temperature, tg2);
                    solveState = SolveState.Solved;
                }
                else if (td2 != Constants.NO_VALUE)
                {
                    y2  = humidGasCalculator.GetHumidityFromDewPointAndPressure(td2, p);
                    tg2 = humidGasCalculator.GetDryBulbFromHumidEnthalpyHumidityAndPressure(ih, y2, p);
                    Calculate(outputStream.Temperature, tg2);
                    solveState = SolveState.Solved;
                }
                else if (fy2 != Constants.NO_VALUE)
                {
                    double fy_temp    = 0;
                    double delta      = 10.0;
                    double totalDelta = delta;
                    tg2 = tg1 - delta;
                    bool negativeLastTime = false;

                    int counter = 0;
                    do
                    {
                        counter++;
                        y2      = humidGasCalculator.GetHumidityFromHumidEnthalpyTemperatureAndPressure(ih, tg2, p);
                        fy_temp = humidGasCalculator.GetRelativeHumidityFromDryBulbHumidityAndPressure(tg2, y2, p);
                        if (fy2 > fy_temp)
                        {
                            if (negativeLastTime)
                            {
                                delta /= 2.0; //testing finds delta/2.0 is almost optimal
                            }
                            totalDelta      += delta;
                            negativeLastTime = false;
                        }
                        else if (fy2 < fy_temp)
                        {
                            delta           /= 2.0; //testing finds delta/2.0 is almost optimal
                            totalDelta      -= delta;
                            negativeLastTime = true;
                        }
                        tg2 = tg1 - totalDelta;
                    } while (Math.Abs(fy2 - fy_temp) > 1.0e-6 && counter <= 200);

                    if (counter < 200)
                    {
                        Calculate(outputStream.Temperature, tg2);
                        solveState = SolveState.Solved;
                    }
                }

                double fy = humidGasCalculator.GetRelativeHumidityFromDryBulbHumidityAndPressure(tg2, y2, p);
                if (fy > 1.0)
                {
                    solveState = SolveState.NotSolved;
                    string msg = "Specified input state makes the relative humidity of the output greater than 1.0.";
                    throw new InappropriateSpecifiedValueException(msg);
                }
            }
            else if (tg2 != Constants.NO_VALUE && y2 != Constants.NO_VALUE)
            {
                ih = humidGasCalculator.GetHumidEnthalpyFromDryBulbHumidityAndPressure(tg2, y2, p);
                if (tg1 != Constants.NO_VALUE)
                {
                    y1 = humidGasCalculator.GetHumidityFromHumidEnthalpyTemperatureAndPressure(ih, tg1, p);
                    Calculate(inputStream.MoistureContentDryBase, y1);
                    solveState = SolveState.Solved;
                }
                else if (y1 != Constants.NO_VALUE)
                {
                    tg1 = humidGasCalculator.GetDryBulbFromHumidEnthalpyHumidityAndPressure(ih, y1, p);
                    Calculate(inputStream.Temperature, tg1);
                    solveState = SolveState.Solved;
                }
                else if (td1 != Constants.NO_VALUE)
                {
                    y1  = humidGasCalculator.GetHumidityFromDewPointAndPressure(td1, p);
                    tg1 = humidGasCalculator.GetDryBulbFromHumidEnthalpyHumidityAndPressure(ih, y1, p);
                    Calculate(inputStream.Temperature, tg1);
                    solveState = SolveState.Solved;
                }
                else if (fy1 != Constants.NO_VALUE)
                {
                    double fy_temp    = 0;
                    double delta      = 10.0;
                    double totalDelta = delta;
                    tg1 = tg2 + delta;
                    bool negativeLastTime = false;

                    int counter = 0;
                    do
                    {
                        counter++;
                        y1      = humidGasCalculator.GetHumidityFromHumidEnthalpyTemperatureAndPressure(ih, tg1, p);
                        fy_temp = humidGasCalculator.GetRelativeHumidityFromDryBulbHumidityAndPressure(tg1, y1, p);
                        if (fy1 < fy_temp)
                        {
                            if (negativeLastTime)
                            {
                                delta /= 2.0; //testing finds delta/2.0 is almost optimal
                            }
                            totalDelta      += delta;
                            negativeLastTime = false;
                        }
                        else if (fy1 > fy_temp)
                        {
                            delta           /= 2.0; //testing finds delta/2.0 is almost optimal
                            totalDelta      -= delta;
                            negativeLastTime = true;
                        }
                        tg1 = tg2 + totalDelta;
                    } while (Math.Abs(fy1 - fy_temp) > 1.0e-6 && counter <= 200);

                    if (counter < 200)
                    {
                        Calculate(inputStream.Temperature, tg1);
                        solveState = SolveState.Solved;
                    }
                }
            }
        }
Esempio n. 4
0
        public override void Execute(bool propagate)
        {
            //if dew point is known
            //HumidGasCalculator humidGasCalculator = GetHumidGasCalculator();
            if (dewPoint.HasValue)
            {
                if (relativeHumidity.HasValue && !temperature.IsSpecifiedAndHasValue)
                {
                    Calculate(temperature, HumidGasCalculator.GetDryBulbFromDewPointAndRelativeHumidity(dewPoint.Value, relativeHumidity.Value));
                }
                else if (pressure.HasValue)
                {
                    if (dewPoint.Value <= 1.0e-10 && !moistureContentDryBase.IsSpecifiedAndHasValue)
                    {
                        Calculate(moistureContentDryBase, 0);
                    }
                    else if (!moistureContentDryBase.IsSpecifiedAndHasValue)
                    {
                        Calculate(moistureContentDryBase, HumidGasCalculator.GetHumidityFromDewPointAndPressure(dewPoint.Value, pressure.Value));
                    }
                }
                //Pressure should always be known. So it should not be calculated
                else if (moistureContentDryBase.HasValue)
                {
                    //Calculate(pressure, humidGasCalculator.GetPressureFromDewPointAndHumidity(dewPoint.Value, humidity.Value));
                }
            }

            //if humidity is known
            if (moistureContentDryBase.HasValue)
            {
                if (pressure.HasValue && !dewPoint.IsSpecifiedAndHasValue)
                {
                    Calculate(dewPoint, HumidGasCalculator.GetDewPointFromHumidityAndPressure(moistureContentDryBase.Value, pressure.Value));
                }

                //to prevent repeated calculation of the same variable
                //if (relativeHumidity.HasValue && dewPoint.HasValue && !temperature.IsSpecifiedAndHasValue) {
                if (relativeHumidity.HasValue && dewPoint.HasValue && !temperature.HasValue)
                {
                    Calculate(temperature, HumidGasCalculator.GetDryBulbFromDewPointAndRelativeHumidity(dewPoint.Value, relativeHumidity.Value));
                }

                //to prevent repeated calculation of the same variable
                //if (wetBulbTemperature.HasValue && pressure.HasValue && !temperature.IsSpecifiedAndHasValue) {
                if (wetBulbTemperature.HasValue && pressure.HasValue && !temperature.HasValue)
                {
                    Calculate(temperature, HumidGasCalculator.GetDryBulbFromWetBulbHumidityAndPressure(wetBulbTemperature.Value, moistureContentDryBase.Value, pressure.Value));
                }
            }

            //to prevent repeated calculation of the same variable
            //if (wetBulbTemperature.HasValue && relativeHumidity.HasValue && pressure.HasValue
            //   && !temperature.IsSpecifiedAndHasValue) {
            if (wetBulbTemperature.HasValue && relativeHumidity.HasValue && pressure.HasValue &&
                !temperature.HasValue)
            {
                Calculate(temperature, HumidGasCalculator.GetDryBulbFromWetBulbRelativeHumidityAndPressure(wetBulbTemperature.Value, relativeHumidity.Value, pressure.Value));
            }

            double humidEnthalpyValue;
            double mcDryBase = moistureContentDryBase.Value;

            if (specificEnthalpy.HasValue && moistureContentDryBase.HasValue && !specificEnthalpyDryBase.HasValue)
            {
                Calculate(specificEnthalpyDryBase, specificEnthalpy.Value * (1.0 + mcDryBase));
            }

            //if (specificEnthalpyDryBase.HasValue && pressure.HasValue && !temperature.IsSpecifiedAndHasValue) {
            if (specificEnthalpyDryBase.HasValue && pressure.HasValue && !temperature.HasValue)
            {
                if (moistureContentDryBase.HasValue)
                {
                    Calculate(temperature, HumidGasCalculator.GetDryBulbFromHumidEnthalpyHumidityAndPressure(specificEnthalpyDryBase.Value, moistureContentDryBase.Value, pressure.Value));
                }
                else if (relativeHumidity.HasValue)
                {
                    Calculate(temperature, HumidGasCalculator.GetDryBulbFromHumidEnthalpyRelativeHumidityAndPressure(specificEnthalpyDryBase.Value, relativeHumidity.Value, pressure.Value));
                }
                else if (dewPoint.HasValue)
                {
                    Calculate(temperature, HumidGasCalculator.GetDryBulbFromHumidEnthalpyDewPointAndPressure(specificEnthalpyDryBase.Value, relativeHumidity.Value, pressure.Value));
                }
                else if (wetBulbTemperature.HasValue)
                {
                    Calculate(temperature, HumidGasCalculator.GetDryBulbFromHumidEnthalpyWetBulbAndPressure(specificEnthalpyDryBase.Value, wetBulbTemperature.Value, pressure.Value));
                }
            }

            //if temperature is first known
            if (temperature.HasValue)
            {
                if (dewPoint.HasValue || relativeHumidity.HasValue)
                {
                    if (dewPoint.HasValue && !relativeHumidity.IsSpecifiedAndHasValue)
                    {
                        Calculate(relativeHumidity, HumidGasCalculator.GetRelativeHumidityFromDryBulbAndDewPoint(temperature.Value, dewPoint.Value));
                    }
                    else if (relativeHumidity.HasValue && !dewPoint.IsSpecifiedAndHasValue)
                    {
                        Calculate(dewPoint, HumidGasCalculator.GetDewPointFromDryBulbAndRelativeHumidity(temperature.Value, relativeHumidity.Value));
                    }

                    if (pressure.HasValue)
                    {
                        if (!moistureContentDryBase.IsSpecifiedAndHasValue)
                        {
                            Calculate(moistureContentDryBase, HumidGasCalculator.GetHumidityFromDewPointAndPressure(dewPoint.Value, pressure.Value));
                        }
                        if (!wetBulbTemperature.IsSpecifiedAndHasValue)
                        {
                            Calculate(wetBulbTemperature, HumidGasCalculator.GetWetBulbFromDryBulbHumidityAndPressure(temperature.Value, moistureContentDryBase.Value, pressure.Value));
                            //double satTemp = humidGasCalculator.GetSatTempFromDryBulbHumidityAndPressure(temperature.Value, moistureContentDryBase.Value, pressure.Value);
                        }
                    }
                    else if (moistureContentDryBase.HasValue)
                    {
                        if (!pressure.IsSpecifiedAndHasValue)
                        {
                            Calculate(pressure, HumidGasCalculator.GetPressureFromDewPointAndHumidity(dewPoint.Value, moistureContentDryBase.Value));
                        }
                        if (!wetBulbTemperature.IsSpecifiedAndHasValue)
                        {
                            Calculate(wetBulbTemperature, HumidGasCalculator.GetWetBulbFromDryBulbHumidityAndPressure(temperature.Value, moistureContentDryBase.Value, pressure.Value));
                            //double satTemp = humidGasCalculator.GetSatTempFromDryBulbHumidityAndPressure(temperature.Value, moistureContentDryBase.Value, pressure.Value);
                        }
                    }
                }
                else if (wetBulbTemperature.HasValue && pressure.HasValue)
                {
                    if (!moistureContentDryBase.IsSpecifiedAndHasValue)
                    {
                        Calculate(moistureContentDryBase, HumidGasCalculator.GetHumidityFromDryBulbWetBulbAndPressure(temperature.Value, wetBulbTemperature.Value, pressure.Value));
                    }
                    if (!relativeHumidity.IsSpecifiedAndHasValue)
                    {
                        Calculate(relativeHumidity, HumidGasCalculator.GetRelativeHumidityFromDryBulbHumidityAndPressure(temperature.Value, moistureContentDryBase.Value, pressure.Value));
                    }
                    if (!dewPoint.IsSpecifiedAndHasValue)
                    {
                        Calculate(dewPoint, HumidGasCalculator.GetDewPointFromDryBulbAndRelativeHumidity(temperature.Value, relativeHumidity.Value));
                    }
                }

                else if (moistureContentDryBase.HasValue && pressure.HasValue)
                {
                    if (!wetBulbTemperature.IsSpecifiedAndHasValue)
                    {
                        Calculate(wetBulbTemperature, HumidGasCalculator.GetWetBulbFromDryBulbHumidityAndPressure(temperature.Value, moistureContentDryBase.Value, pressure.Value));
                        //double satTemp = humidGasCalculator.GetSatTempFromDryBulbHumidityAndPressure(temperature.Value, moistureContentDryBase.Value, pressure.Value);
                    }

                    if (!relativeHumidity.IsSpecifiedAndHasValue)
                    {
                        Calculate(relativeHumidity, HumidGasCalculator.GetRelativeHumidityFromDryBulbHumidityAndPressure(temperature.Value, moistureContentDryBase.Value, pressure.Value));
                    }
                    if (!dewPoint.IsSpecifiedAndHasValue)
                    {
                        Calculate(dewPoint, HumidGasCalculator.GetDewPointFromDryBulbAndRelativeHumidity(temperature.Value, relativeHumidity.Value));
                    }
                }

                else if (wetBulbTemperature.HasValue && moistureContentDryBase.HasValue)
                {
                    //if (!pressure.IsSpecifiedAndHasValue) {
                    //   Calculate(pressure, humidGasCalculator.GetPressureFromDryBulbWetBulbAndHumidity(temperature.Value, wetBulbTemperature.Value, moistureContentDryBase.Value));
                    //}
                    if (!dewPoint.IsSpecifiedAndHasValue)
                    {
                        Calculate(dewPoint, HumidGasCalculator.GetDewPointFromHumidityAndPressure(temperature.Value, pressure.Value));
                    }
                    if (!relativeHumidity.IsSpecifiedAndHasValue)
                    {
                        Calculate(relativeHumidity, HumidGasCalculator.GetRelativeHumidityFromDryBulbAndDewPoint(temperature.Value, dewPoint.Value));
                    }
                }
            }

            mcDryBase = moistureContentDryBase.Value;
            if (moistureContentDryBase.HasValue && temperature.HasValue)
            {
                double cpDryBase = HumidGasCalculator.GetHumidHeat(moistureContentDryBase.Value, temperature.Value);
                Calculate(specificHeatDryBase, cpDryBase);
                Calculate(specificHeat, cpDryBase / (1.0 + mcDryBase));
                if (pressure.HasValue)
                {
                    double humidVolumeValue = HumidGasCalculator.GetHumidVolume(temperature.Value, moistureContentDryBase.Value, pressure.Value);
                    Calculate(humidVolume, humidVolumeValue);
                    humidEnthalpyValue = HumidGasCalculator.GetHumidEnthalpyFromDryBulbHumidityAndPressure(temperature.Value, moistureContentDryBase.Value, pressure.Value);
                    Calculate(specificEnthalpyDryBase, humidEnthalpyValue);
                    Calculate(specificEnthalpy, humidEnthalpyValue / (1.0 + mcDryBase));
                    Calculate(density, (1.0 + mcDryBase) / humidVolumeValue);
                }
            }

            CalculateFlow();

            //if (temperature.HasValue && pressure.HasValue && massFlowRate.HasValue &&
            //   volumeFlowRate.HasValue && massFlowRateDryBase.HasValue && wetBulbTemperature.HasValue &&
            //   dewPoint.HasValue && moistureContentDryBase.HasValue && relativeHumidity.HasValue &&
            //   density.HasValue && specificEnthalpy.HasValue && specificHeatDryBase.HasValue) {
            //   solveState = SolveState.Solved;
            //}

            bool hasUnsolvedVar = false;

            foreach (ProcessVarDouble pv in varList)
            {
                if (!pv.HasValue)
                {
                    hasUnsolvedVar = true;
                    break;
                }
            }
            if (!hasUnsolvedVar)
            {
                solveState = SolveState.Solved;
            }
            //else
            //{
            //   foreach (ProcessVarDouble pv in varList)
            //   {
            //      if (!pv.IsSpecified && pv.HasValue)
            //      {
            //         solveState = SolveState.PartiallySolved;
            //         break;
            //      }
            //   }
            //}

            if (HasSolvedAlready)
            {
                DryingGasComponents dgc = (DryingGasComponents)materialComponents;
                //we cannot do a calculate operation since these variables are not in the
                //varList and they cannot be erased after they are initially calculated
                dgc.DryMedium.SetMassFractionValue(1.0 / (1.0 + Humidity.Value));
                dgc.Moisture.SetMassFractionValue(Humidity.Value / (1.0 + Humidity.Value));
                dgc.ComponentsFractionsChanged();
            }
            AdjustVarsStates();
            OnSolveComplete();
        }