private void CalculateTemperatureFromEnthalpy(double pValue, double hValue, double moistureContentValue) { double tValue = Constants.NO_VALUE; double tValueOld = Constants.NO_VALUE; double vfValue = Constants.NO_VALUE; double tBoilingPointOfSolvent = MoistureProperties.GetSaturationTemperature(pValue); double tBoilingPointOfSolution = GetBoilingPoint(pValue); double cpLiquid = specificHeat.Value; if (cpLiquid == Constants.NO_VALUE) { cpLiquid = GetLiquidCp(MathUtility.Average(273.15, tBoilingPointOfSolution)); } if (cpLiquid == Constants.NO_VALUE) { return; } //SteamTable steamTable = SteamTable.GetInstance(); //SubstanceStatesAndProperties props; double hBoilingPointOfSolvent = CalculateLiquidEnthalpy(pValue, tBoilingPointOfSolvent, moistureContentValue); double hBubble = GetBubblePointEnthalpy(pValue, moistureContentValue); double hDew = GetDewPointEnthalpy(pValue, moistureContentValue); double cs = GetCpOfAbsoluteDryMaterial(); int counter = 0; if (hValue <= hBoilingPointOfSolvent) { double tempH; //tValue = hValue / cpLiquid + 273.15; tValue = tBoilingPointOfSolvent - (hBoilingPointOfSolvent - hValue) / cpLiquid; do { counter++; tValueOld = tValue; tempH = (hValue - (1.0 - moistureContentValue) * cs * (tValue - 273.15)) / moistureContentValue; //props = steamTable.GetPropertiesFromPressureAndEnthalpy(pValue, tempH); //tValue = props.temperature; tValue = MoistureProperties.GetTemperatureFromPressureAndEnthalpy(pValue, tempH); } while (Math.Abs(tValue - tValueOld) > TOLERANCE && counter < 200); if (counter == 200) { string msg = BuildProperErrorMessage(this.name + ": Calculation of temperature from enthalpy failed.\nPlease make sure each specified value in this stream"); throw new CalculationFailedException(msg); } vfValue = 0.0; } else if (hValue <= hBubble) { double moistureLiquidCp; //double hBoilingPointOfSolvent = CalculateLiquidEnthalpy(pValue, tBoilingPointOfSolvent - TOLERANCE); //tValue = hValue / cpLiquid + 273.15; tValue = (hValue - hBoilingPointOfSolvent) / cpLiquid + tBoilingPointOfSolvent; do { counter++; tValueOld = tValue; moistureLiquidCp = MoistureProperties.GetSpecificHeatOfLiquid(MathUtility.Average(tBoilingPointOfSolvent, tValue)); tValue = (hValue - hBoilingPointOfSolvent) / (moistureContentValue * moistureLiquidCp + (1.0 - moistureContentValue) * cs) + tBoilingPointOfSolvent; } while (Math.Abs(tValue - tValueOld) > TOLERANCE && counter < 200); if (counter == 200) { string msg = BuildProperErrorMessage(this.name + ": Calculation of temperature from enthalpy failed.\nPlease make sure each specified value in this stream"); throw new CalculationFailedException(msg); } vfValue = 0.0; } else if (hValue <= hDew) { double tBoilingPointOfSolutionFinal = tBoilingPointOfSolution; double evapHeat = GetEvaporationHeat(tBoilingPointOfSolution); double extraHeat = (hValue - hBubble); if (moistureContentValue > 0.9999) { vfValue = extraHeat / evapHeat; } else { vfValue = 0; double vfValueOld; double moistureLiquidCp; double massConcentrationValue = 1.0 - moistureContentValue; do { counter++; vfValueOld = vfValue; vfValue = extraHeat / evapHeat; massConcentrationValue = (1.0 - moistureContentValue) / (1.0 - vfValue); tBoilingPointOfSolutionFinal = GetBoilingPoint(pValue, massConcentrationValue); evapHeat = GetEvaporationHeat(MathUtility.Average(tBoilingPointOfSolution, tBoilingPointOfSolutionFinal)); moistureLiquidCp = MoistureProperties.GetSpecificHeatOfLiquid(MathUtility.Average(tBoilingPointOfSolution, tBoilingPointOfSolutionFinal)); extraHeat = hValue - hBubble - (moistureContentValue * moistureLiquidCp + (1.0 - moistureContentValue) * cs) * (tBoilingPointOfSolutionFinal - tBoilingPointOfSolution); } while (Math.Abs(vfValue - vfValueOld) > TOLERANCE && counter < 200); if (counter == 200) { string msg = BuildProperErrorMessage(this.name + ": Calculation of temperature from enthalpy failed.\nPlease make sure each specified value in this stream"); throw new CalculationFailedException(msg); } } if (vfValue < 0.0) { vfValue = 0.0; } tValue = tBoilingPointOfSolutionFinal; } else if (hValue > hDew) { double apparentHeat; double hVapor; double cpGas = GetGasCp(tBoilingPointOfSolution); tValue = (hValue - hDew) / cpGas + tBoilingPointOfSolution; do { apparentHeat = (hValue - hDew - (1.0 - moistureContentValue) * cs * (tValue - tBoilingPointOfSolution)) / moistureContentValue; //props = steamTable.GetPropertiesFromPressureAndTemperature(pValue, tBoilingPointOfSolution + TOLERANCE); //hVapor = props.enthalpy + apparentHeat; hVapor = apparentHeat + MoistureProperties.GetEnthalpyFromPressureAndTemperature(pValue, tBoilingPointOfSolution + TOLERANCE); //props = steamTable.GetPropertiesFromPressureAndEnthalpy(pressure.Value, hVapor); tValueOld = tValue; //tValue = props.temperature; tValue = MoistureProperties.GetTemperatureFromPressureAndEnthalpy(pressure.Value, hVapor); } while (Math.Abs(tValue - tValueOld) > TOLERANCE && counter < 200); if (counter == 200) { string msg = BuildProperErrorMessage(this.name + ": Calculation of temperature from enthalpy failed.\nPlease make sure each specified value in this stream"); throw new CalculationFailedException(msg); } vfValue = moistureContentValue; } Calculate(temperature, tValue); Calculate(vaporFraction, vfValue); if (!specificHeat.HasValue) { double cp; if (hValue <= hBubble) { cp = GetLiquidCp(tValue); } else { cp = GetGasCp(tValue); } Calculate(specificHeat, cp); } }
//protected override bool IsSolveReady() { // if (HasSolvedAlready) { // return false; // } // bool retValue = false; // if ((moistureContentDryBase.HasValue && !moistureContentWetBase.IsSpecifiedAndHasValue) // || (moistureContentWetBase.HasValue && !moistureContentDryBase.IsSpecifiedAndHasValue) // || concentration.HasValue && (!moistureContentDryBase.IsSpecifiedAndHasValue || !moistureContentWetBase.IsSpecifiedAndHasValue)) { // retValue = true; // } // if (moistureContentDryBase.HasValue || moistureContentWetBase.HasValue || concentration.HasValue) { // if ((specificHeatDryBase.HasValue && !specificHeat.IsSpecifiedAndHasValue) // || (specificHeat.HasValue && !specificHeatDryBase.IsSpecifiedAndHasValue)) { // retValue = true; // } // if ((massFlowRateDryBase.HasValue && !massFlowRate.IsSpecifiedAndHasValue) // || (massFlowRate.HasValue && !massFlowRateDryBase.IsSpecifiedAndHasValue)) { // retValue = true; // } // if ((massFlowRateDryBase.HasValue || massFlowRate.HasValue) // && (density.HasValue && !volumeFlowRate.IsSpecifiedAndHasValue)) { // retValue = true; // } // } // return retValue; //} public override void Execute(bool propagate) { if (HasSolvedAlready) { return; } if (moistureContentDryBase.HasValue && !moistureContentWetBase.IsSpecifiedAndHasValue) { Calculate(moistureContentWetBase, moistureContentDryBase.Value / (1.0 + moistureContentDryBase.Value)); } else if (moistureContentWetBase.HasValue && !moistureContentDryBase.IsSpecifiedAndHasValue) { if (moistureContentWetBase.Value != 1.0) { Calculate(moistureContentDryBase, moistureContentWetBase.Value / (1.0 - moistureContentWetBase.Value)); } else { Calculate(moistureContentDryBase, Constants.NO_VALUE); } } if (volumeFlowRate.IsSpecifiedAndHasValue && density.IsSpecifiedAndHasValue) { Calculate(massFlowRate, volumeFlowRate.Value * density.Value); } if (materialStateType == MaterialStateType.Liquid) { if (massConcentration.HasValue && massConcentration.Value > TOLERANCE) { if (!moistureContentDryBase.IsSpecifiedAndHasValue) { Calculate(moistureContentDryBase, (1.0 - massConcentration.Value) / massConcentration.Value); } if (!moistureContentWetBase.IsSpecifiedAndHasValue) { Calculate(moistureContentWetBase, 1.0 - massConcentration.Value); } } else if (massConcentration.HasValue && massConcentration.Value <= TOLERANCE) { Calculate(moistureContentDryBase, Constants.NO_VALUE); Calculate(moistureContentWetBase, 1.0); Calculate(massFlowRateDryBase, Constants.NO_VALUE); } else if (moistureContentDryBase.HasValue && !massConcentration.IsSpecifiedAndHasValue) { Calculate(massConcentration, 1.0 / (1.0 + moistureContentDryBase.Value)); } else if (moistureContentWetBase.HasValue && !massConcentration.IsSpecifiedAndHasValue) { Calculate(massConcentration, 1.0 - moistureContentWetBase.Value); } } if (moistureContentWetBase.HasValue) { DryingMaterialComponents dmc = MaterialComponents; dmc.Moisture.SetMassFractionValue(moistureContentWetBase.Value); dmc.AbsoluteDryMaterial.SetMassFractionValue(1.0 - moistureContentWetBase.Value); dmc.ComponentsFractionsChanged(); } //if it is a known meterial in the material database, specific heat can be calculated double moistureLiquidCp = MoistureProperties.GetSpecificHeatOfLiquid(); if (temperature.HasValue) { moistureLiquidCp = MoistureProperties.GetSpecificHeatOfLiquid(temperature.Value); } double cs = GetCpOfAbsoluteDryMaterial(); if (temperature.HasValue && moistureContentWetBase.HasValue) { double cp = CalculateCp(temperature.Value); if (cp != Constants.NO_VALUE) { Calculate(specificHeat, cp); if (moistureContentDryBase.HasValue) { Calculate(specificHeatDryBase, cp * (1.0 + moistureContentDryBase.Value)); } } else if (specificHeat.HasValue && moistureContentDryBase.HasValue) { Calculate(specificHeatDryBase, specificHeat.Value * (1.0 + moistureContentDryBase.Value)); } } //need this when temperature is not not known //else if (cs != Constants.NO_VALUE && moistureContentDryBase.HasValue && !specificHeat.IsSpecifiedAndHasValue) { else if (specificEnthalpy.HasValue && cs != Constants.NO_VALUE && moistureContentDryBase.HasValue && !specificHeat.IsSpecifiedAndHasValue) { double cpMaterialDryBase = cs + moistureContentDryBase.Value * moistureLiquidCp; Calculate(specificHeatDryBase, cpMaterialDryBase); Calculate(specificHeat, cpMaterialDryBase / (1.0 + moistureContentDryBase.Value)); } //else if (moistureContentWetBase.Value == 1.0 && !specificHeat.IsSpecifiedAndHasValue) { // Calculate(specificHeatDryBase, Constants.NO_VALUE); // if (temperature.HasValue && moistureContentWetBase.HasValue) { // moistureLiquidCp = CalculateCp(temperature.Value); // Calculate(specificHeat, moistureLiquidCp); // } //} if (materialStateType == MaterialStateType.Solid && specificHeat.HasValue) { if (temperature.HasValue) { //Calculate(specificEnthalpy, specificHeat.Value * (temperature.Value - 273.15)); CalculateEnthalpyFromTemperature(Constants.ONE_ATM, temperature.Value, moistureContentWetBase.Value); } else if (specificEnthalpy.HasValue && !temperature.IsSpecifiedAndHasValue) { //Calculate(temperature, specificEnthalpy.Value / specificHeat.Value + 273.15); double tValue = CalculateTemperatureFromEnthalpyForSolid(specificEnthalpy.Value, moistureContentWetBase.Value); Calculate(temperature, tValue); } } else if (materialStateType == MaterialStateType.Liquid && pressure.HasValue && moistureContentWetBase.HasValue) { if (massConcentration.Value > TOLERANCE) { if (specificEnthalpy.HasValue && !temperature.IsSpecifiedAndHasValue) { CalculateTemperatureFromEnthalpy(pressure.Value, specificEnthalpy.Value, moistureContentWetBase.Value); } else if (temperature.HasValue) { CalculateEnthalpyFromTemperature(pressure.Value, temperature.Value, moistureContentWetBase.Value); } else if (vaporFraction.HasValue) { CalculateEnthalpyFromVaporFraction(pressure.Value, vaporFraction.Value, moistureContentWetBase.Value); } } else { double h = Constants.NO_VALUE; if (specificEnthalpy.HasValue && !temperature.IsSpecifiedAndHasValue) { double t = MoistureProperties.GetTemperatureFromPressureAndEnthalpy(pressure.Value, specificEnthalpy.Value); Calculate(temperature, t); CalculateVaporFractionIfNeeded(); } else if (temperature.HasValue) { h = MoistureProperties.GetEnthalpyFromPressureAndTemperature(pressure.Value, temperature.Value); Calculate(specificEnthalpy, h); CalculateVaporFractionIfNeeded(); } else if (vaporFraction.HasValue) { double boilingPoint = MoistureProperties.GetSaturationTemperature(pressure.Value); h = MoistureProperties.GetEnthalpyFromPressureAndVaporFraction(pressure.Value, vaporFraction.Value); Calculate(temperature, boilingPoint); Calculate(specificEnthalpy, h); } //CalculateCpOfPureMoisture(); if (specificEnthalpy.HasValue) { CalculateCpOfPureMoisture(); } } } if (massFlowRateDryBase.HasValue && moistureContentDryBase.HasValue && !massFlowRate.IsSpecifiedAndHasValue) { Calculate(massFlowRate, massFlowRateDryBase.Value * (1.0 + moistureContentDryBase.Value)); } else if (massFlowRate.HasValue && moistureContentDryBase.HasValue && !massFlowRateDryBase.IsSpecifiedAndHasValue) { Calculate(massFlowRateDryBase, massFlowRate.Value / (1.0 + moistureContentDryBase.Value)); } if (temperature.HasValue && massConcentration.HasValue) { CalculateDensity(); } if (!volumeFlowRate.IsSpecifiedAndHasValue && massFlowRate.HasValue && density.HasValue) { Calculate(volumeFlowRate, massFlowRate.Value / density.Value); } if (materialStateType == MaterialStateType.Solid && temperature.HasValue && massFlowRate.HasValue && moistureContentWetBase.HasValue && specificHeat.HasValue && specificEnthalpy.HasValue) { solveState = SolveState.Solved; } else if (materialStateType == MaterialStateType.Liquid && pressure.HasValue && temperature.HasValue && massFlowRate.HasValue && moistureContentWetBase.HasValue && specificEnthalpy.HasValue && vaporFraction.HasValue) { solveState = SolveState.Solved; } AdjustVarsStates(); //if (HasSolvedAlready) { // DryingMaterialComponents dmc = MaterialComponents; // dmc.Moisture.SetMassFractionValue(moistureContentWetBase.Value); // dmc.AbsoluteDryMaterial.SetMassFractionValue(1.0 - moistureContentWetBase.Value); // dmc.ComponentsFractionsChanged(); //} OnSolveComplete(); }