diff --git a/modules/fluid_properties/include/fluidproperties/HelmholtzFluidProperties.h b/modules/fluid_properties/include/fluidproperties/HelmholtzFluidProperties.h index 7dc902495606..9769b0e69c4c 100644 --- a/modules/fluid_properties/include/fluidproperties/HelmholtzFluidProperties.h +++ b/modules/fluid_properties/include/fluidproperties/HelmholtzFluidProperties.h @@ -55,6 +55,8 @@ class HelmholtzFluidProperties : public SinglePhaseFluidProperties virtual Real h_from_p_T(Real pressure, Real temperature) const override; virtual void h_from_p_T(Real p, Real T, Real & h, Real & dh_dp, Real & dh_dT) const override; + virtual Real T_from_p_h(Real pressure, Real enthalpy) const override; + /** * Pressure as a function of density and temperature * diff --git a/modules/fluid_properties/src/fluidproperties/HelmholtzFluidProperties.C b/modules/fluid_properties/src/fluidproperties/HelmholtzFluidProperties.C index e01035794b73..935f2d2a9996 100644 --- a/modules/fluid_properties/src/fluidproperties/HelmholtzFluidProperties.C +++ b/modules/fluid_properties/src/fluidproperties/HelmholtzFluidProperties.C @@ -216,6 +216,24 @@ HelmholtzFluidProperties::h_from_p_T( molarMass(); } +Real +HelmholtzFluidProperties::T_from_p_h(Real pressure, Real enthalpy) const +{ + auto lambda = [&](Real pressure, Real current_T, Real & new_h, Real & dh_dp, Real & dh_dT) + { h_from_p_T(pressure, current_T, new_h, dh_dp, dh_dT); }; + Real T = FluidPropertiesUtils::NewtonSolve( + pressure, enthalpy, _T_initial_guess, _tolerance, lambda, name() + "::T_from_p_h") + .first; + // check for nans + if (std::isnan(T)) + mooseError("Conversion from enthalpy (h = ", + enthalpy, + ") and pressure (p = ", + pressure, + ") to temperature failed to converge."); + return T; +} + Real HelmholtzFluidProperties::p_from_rho_T(Real density, Real temperature) const { diff --git a/modules/fluid_properties/unit/src/TabulatedBicubicFluidPropertiesTest.C b/modules/fluid_properties/unit/src/TabulatedBicubicFluidPropertiesTest.C index 71611465cc24..4bfb672d3401 100644 --- a/modules/fluid_properties/unit/src/TabulatedBicubicFluidPropertiesTest.C +++ b/modules/fluid_properties/unit/src/TabulatedBicubicFluidPropertiesTest.C @@ -213,6 +213,15 @@ TEST_F(TabulatedBicubicFluidPropertiesTest, fromPTFileToVE) REL_TEST(T, Ts, 0.001); } + // check computation of fluids props from p, h + { + Real T = 450; + Real p = 1.5e6; + Real h = _tab_ve_from_pT->h_from_p_T(p, T); + Real Ts = _tab_ve_from_pT->T_from_p_h(p, h); + REL_TEST(T, Ts, 1e-4); + } + // are the two version of functions equivalent { Real e = _tab_ve_from_pT->e_from_p_T(p, T); @@ -373,6 +382,30 @@ TEST_F(TabulatedBicubicFluidPropertiesTest, fromPTFileToVE) // cannot test AD c_from_v_e because co2 props do not // implement enough + + // AD T_from_p_h + { + Real h = _tab_ve_from_pT->h_from_p_T(p, T); + DNDerivativeType dpdx; + DNDerivativeType dhdx; + // set it up so these are the derivatives + // w.r.t. to themselves + Moose::derivInsert(dpdx, 0, 1); + Moose::derivInsert(dpdx, 1, 0); + Moose::derivInsert(dhdx, 0, 0); + Moose::derivInsert(dhdx, 1, 1); + + ADReal p_ad(p, dpdx); + ADReal h_ad(h, dhdx); + ADReal T_ad = _tab_ve_from_pT->T_from_p_h(p_ad, h_ad); + + Real TT_1 = _tab_ve_from_pT->T_from_p_h(p * (1 + pert), h); + Real TT_2 = _tab_ve_from_pT->T_from_p_h(p, h * (1 + pert)); + Real dT_dp = (TT_1 - T) / p / pert; + Real dT_dh = (TT_2 - T) / h / pert; + REL_TEST(T_ad.derivatives()[0], dT_dp, 0.0001); + REL_TEST(T_ad.derivatives()[1], dT_dh, 0.0001); + } } // Test tabulated fluid properties read from file including comments