LCOV - code coverage report
Current view: top level - src/fluidproperties - HeliumFluidProperties.C (source / functions) Hit Total Coverage
Test: idaholab/moose fluid_properties: #31405 (292dce) with base fef103 Lines: 116 191 60.7 %
Date: 2025-09-04 07:53:14 Functions: 30 45 66.7 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //* This file is part of the MOOSE framework
       2             : //* https://mooseframework.inl.gov
       3             : //*
       4             : //* All rights reserved, see COPYRIGHT for full restrictions
       5             : //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
       6             : //*
       7             : //* Licensed under LGPL 2.1, please see LICENSE for details
       8             : //* https://www.gnu.org/licenses/lgpl-2.1.html
       9             : 
      10             : #include "HeliumFluidProperties.h"
      11             : 
      12             : registerMooseObject("FluidPropertiesApp", HeliumFluidProperties);
      13             : 
      14             : InputParameters
      15          22 : HeliumFluidProperties::validParams()
      16             : {
      17          22 :   InputParameters params = SinglePhaseFluidProperties::validParams();
      18          22 :   params.addClassDescription("Fluid properties for helium");
      19          22 :   return params;
      20           0 : }
      21             : 
      22          11 : HeliumFluidProperties::HeliumFluidProperties(const InputParameters & parameters)
      23          11 :   : SinglePhaseFluidProperties(parameters), _cv(3117.0), _cp(5195.0)
      24             : {
      25          11 : }
      26             : 
      27             : std::string
      28           1 : HeliumFluidProperties::fluidName() const
      29             : {
      30           1 :   return "helium";
      31             : }
      32             : 
      33             : Real
      34           1 : HeliumFluidProperties::e_from_p_rho(Real p, Real rho) const
      35             : {
      36             :   // Initial guess using ideal gas law
      37           1 :   Real e = p / (_cp / _cv - 1.) / rho;
      38           1 :   const Real v = 1. / rho;
      39             : 
      40             :   Real p_from_props, dp_dv, dp_de;
      41             :   const unsigned int max_its = 10;
      42             :   unsigned int it = 0;
      43             : 
      44             :   do
      45             :   {
      46           2 :     p_from_v_e(v, e, p_from_props, dp_dv, dp_de);
      47             :     const Real & jacobian = dp_de;
      48           2 :     const Real residual = p_from_props - p;
      49             : 
      50           2 :     if (std::abs(residual) / p < 1e-12)
      51             :       break;
      52             : 
      53           1 :     const Real delta_e = -residual / jacobian;
      54           1 :     e += delta_e;
      55           1 :   } while (++it < max_its);
      56             : 
      57           1 :   if (it >= max_its)
      58           0 :     mooseWarning("The e_from_p_rho iteration failed to converge");
      59             : 
      60           1 :   return e;
      61             : }
      62             : 
      63             : ADReal
      64           0 : HeliumFluidProperties::e_from_p_rho(const ADReal & p, const ADReal & rho) const
      65             : {
      66             :   // Initial guess using ideal gas law
      67           0 :   ADReal e = p / (_cp / _cv - 1.) / rho;
      68           0 :   const ADReal v = 1. / rho;
      69             : 
      70             :   ADReal p_from_props, dp_dv, dp_de;
      71             :   const unsigned int max_its = 10;
      72             :   unsigned int it = 0;
      73             : 
      74             :   do
      75             :   {
      76           0 :     p_from_v_e(v, e, p_from_props, dp_dv, dp_de);
      77             :     const ADReal & jacobian = dp_de;
      78             :     const ADReal residual = p_from_props - p;
      79             : 
      80           0 :     if (std::abs(residual.value()) / p.value() < 1e-12)
      81             :       break;
      82             : 
      83           0 :     const ADReal delta_e = -residual / jacobian;
      84           0 :     e += delta_e;
      85           0 :   } while (++it < max_its);
      86             : 
      87           0 :   if (it >= max_its)
      88           0 :     mooseWarning("The e_from_p_rho iteration failed to converge");
      89             : 
      90           0 :   return e;
      91             : }
      92             : 
      93             : Real
      94          10 : HeliumFluidProperties::p_from_v_e(Real v, Real e) const
      95             : {
      96          10 :   Real T = T_from_v_e(v, e);
      97          10 :   return T / (48.14 * v - 0.4446 / std::pow(T, 0.2)) * 1.0e5;
      98             : }
      99             : 
     100             : ADReal
     101           0 : HeliumFluidProperties::p_from_v_e(const ADReal & v, const ADReal & e) const
     102             : {
     103           0 :   const ADReal T = T_from_v_e(v, e);
     104           0 :   return T / (48.14 * v - 0.4446 / std::pow(T, 0.2)) * 1.0e5;
     105             : }
     106             : 
     107             : void
     108           3 : HeliumFluidProperties::p_from_v_e(Real v, Real e, Real & p, Real & dp_dv, Real & dp_de) const
     109             : {
     110           3 :   p = p_from_v_e(v, e);
     111             : 
     112             :   Real T, dT_dv, dT_de;
     113           3 :   T_from_v_e(v, e, T, dT_dv, dT_de);
     114             : 
     115           3 :   Real val = 48.14 * v - 0.4446 / std::pow(T, 0.2);
     116           3 :   Real dp_dT = 1.0e5 / val - 0.4446 * 0.2e5 * std::pow(T, -0.2) / (val * val);
     117             : 
     118           3 :   dp_dv = -48.14e5 * T / (val * val); // taking advantage of dT_dv = 0.0;
     119           3 :   dp_de = dp_dT * dT_de;
     120           3 : }
     121             : 
     122             : void
     123           0 : HeliumFluidProperties::p_from_v_e(
     124             :     const ADReal & v, const ADReal & e, ADReal & p, ADReal & dp_dv, ADReal & dp_de) const
     125             : {
     126           0 :   p = p_from_v_e(v, e);
     127             : 
     128             :   ADReal T, dT_dv, dT_de;
     129           0 :   T_from_v_e(v, e, T, dT_dv, dT_de);
     130             : 
     131           0 :   auto val = 48.14 * v - 0.4446 / std::pow(T, 0.2);
     132           0 :   auto dp_dT = 1.0e5 / val - 0.4446 * 0.2e5 * std::pow(T, -0.2) / (val * val);
     133             : 
     134           0 :   dp_dv = -48.14e5 * T / (val * val); // taking advantage of dT_dv = 0.0;
     135           0 :   dp_de = dp_dT * dT_de;
     136           0 : }
     137             : 
     138             : Real
     139           0 : HeliumFluidProperties::p_from_T_v(const Real T, const Real v) const
     140             : {
     141             :   // Formula taken from p_from_v_e method
     142           0 :   return T / (48.14 * v - 0.4446 / std::pow(T, 0.2)) * 1.0e5;
     143             : }
     144             : 
     145             : ADReal
     146           0 : HeliumFluidProperties::p_from_T_v(const ADReal & T, const ADReal & v) const
     147             : {
     148             :   // Formula taken from p_from_v_e method
     149           0 :   return T / (48.14 * v - 0.4446 / std::pow(T, 0.2)) * 1.0e5;
     150             : }
     151             : 
     152             : Real
     153           0 : HeliumFluidProperties::e_from_T_v(const Real T, const Real /*v*/) const
     154             : {
     155             :   // Formula taken from e_from_p_T method
     156           0 :   return _cv * T;
     157             : }
     158             : 
     159             : void
     160           0 : HeliumFluidProperties::e_from_T_v(
     161             :     const Real T, const Real v, Real & e, Real & de_dT, Real & de_dv) const
     162             : {
     163           0 :   e = e_from_T_v(T, v);
     164           0 :   de_dT = _cv;
     165           0 :   de_dv = 0;
     166           0 : }
     167             : 
     168             : ADReal
     169           0 : HeliumFluidProperties::e_from_T_v(const ADReal & T, const ADReal & /*v*/) const
     170             : {
     171             :   // Formula taken from e_from_p_T method
     172           0 :   return _cv * T;
     173             : }
     174             : 
     175             : void
     176           0 : HeliumFluidProperties::e_from_T_v(
     177             :     const ADReal & T, const ADReal & v, ADReal & e, ADReal & de_dT, ADReal & de_dv) const
     178             : {
     179           0 :   e = e_from_T_v(T, v);
     180           0 :   de_dT = _cv;
     181           0 :   de_dv = 0;
     182           0 : }
     183             : 
     184             : Real
     185          22 : HeliumFluidProperties::T_from_v_e(Real /*v*/, Real e) const
     186             : {
     187          22 :   return e / _cv;
     188             : }
     189             : 
     190             : ADReal
     191           0 : HeliumFluidProperties::T_from_v_e(const ADReal & /*v*/, const ADReal & e) const
     192             : {
     193           0 :   return e / _cv;
     194             : }
     195             : 
     196             : void
     197           4 : HeliumFluidProperties::T_from_v_e(Real v, Real e, Real & T, Real & dT_dv, Real & dT_de) const
     198             : {
     199           4 :   T = T_from_v_e(v, e);
     200           4 :   dT_dv = 0.0;
     201           4 :   dT_de = 1.0 / _cv;
     202           4 : }
     203             : 
     204             : void
     205           0 : HeliumFluidProperties::T_from_v_e(
     206             :     const ADReal & v, const ADReal & e, ADReal & T, ADReal & dT_dv, ADReal & dT_de) const
     207             : {
     208           0 :   T = SinglePhaseFluidProperties::T_from_v_e(v, e);
     209           0 :   dT_dv = 0.0;
     210           0 :   dT_de = 1.0 / _cv;
     211           0 : }
     212             : 
     213             : Real
     214           1 : HeliumFluidProperties::T_from_p_h(Real /* p */, Real h) const
     215             : {
     216           1 :   return h / _cp;
     217             : }
     218             : 
     219             : Real
     220           0 : HeliumFluidProperties::c_from_v_e(Real v, Real e) const
     221             : {
     222           0 :   Real p = p_from_v_e(v, e);
     223           0 :   Real T = T_from_v_e(v, e);
     224             : 
     225             :   Real rho, drho_dp, drho_dT;
     226           0 :   rho_from_p_T(p, T, rho, drho_dp, drho_dT);
     227             : 
     228           0 :   Real c2 = -(p / rho / rho - _cv / drho_dT) / (_cv * drho_dp / drho_dT);
     229           0 :   return std::sqrt(c2);
     230             : }
     231             : 
     232             : void
     233           0 : HeliumFluidProperties::c_from_v_e(Real v, Real e, Real & c, Real & dc_dv, Real & dc_de) const
     234             : {
     235           0 :   ADReal myv = v;
     236             :   Moose::derivInsert(myv.derivatives(), 0, 1);
     237             :   Moose::derivInsert(myv.derivatives(), 1, 0);
     238           0 :   ADReal mye = e;
     239             :   Moose::derivInsert(mye.derivatives(), 0, 0);
     240             :   Moose::derivInsert(mye.derivatives(), 1, 1);
     241             : 
     242           0 :   auto p = SinglePhaseFluidProperties::p_from_v_e(myv, mye);
     243           0 :   auto T = SinglePhaseFluidProperties::T_from_v_e(myv, mye);
     244             : 
     245             :   ADReal rho, drho_dp, drho_dT;
     246           0 :   rho_from_p_T(p, T, rho, drho_dp, drho_dT);
     247             : 
     248           0 :   auto cc = std::sqrt(-(p / rho / rho - _cv / drho_dT) / (_cv * drho_dp / drho_dT));
     249           0 :   c = cc.value();
     250           0 :   dc_dv = cc.derivatives()[0];
     251           0 :   dc_de = cc.derivatives()[1];
     252           0 : }
     253             : 
     254           7 : Real HeliumFluidProperties::cp_from_v_e(Real /*v*/, Real /*e*/) const { return _cp; }
     255             : 
     256             : void
     257           1 : HeliumFluidProperties::cp_from_v_e(Real v, Real e, Real & cp, Real & dcp_dv, Real & dcp_de) const
     258             : {
     259           1 :   cp = cp_from_v_e(v, e);
     260           1 :   dcp_dv = 0.0;
     261           1 :   dcp_de = 0.0;
     262           1 : }
     263             : 
     264           7 : Real HeliumFluidProperties::cv_from_v_e(Real /*v*/, Real /*e*/) const { return _cv; }
     265             : 
     266             : void
     267           1 : HeliumFluidProperties::cv_from_v_e(Real v, Real e, Real & cv, Real & dcv_dv, Real & dcv_de) const
     268             : {
     269           1 :   cv = cv_from_v_e(v, e);
     270           1 :   dcv_dv = 0.0;
     271           1 :   dcv_de = 0.0;
     272           1 : }
     273             : 
     274             : Real
     275           1 : HeliumFluidProperties::mu_from_v_e(Real v, Real e) const
     276             : {
     277           1 :   return 3.674e-7 * std::pow(T_from_v_e(v, e), 0.7);
     278             : }
     279             : 
     280             : Real
     281           1 : HeliumFluidProperties::k_from_v_e(Real v, Real e) const
     282             : {
     283           1 :   Real p_in_bar = p_from_v_e(v, e) * 1.0e-5;
     284           1 :   Real T = T_from_v_e(v, e);
     285           1 :   return 2.682e-3 * (1.0 + 1.123e-3 * p_in_bar) * std::pow(T, 0.71 * (1.0 - 2.0e-4 * p_in_bar));
     286             : }
     287             : 
     288             : Real
     289           0 : HeliumFluidProperties::beta_from_p_T(Real pressure, Real temperature) const
     290             : {
     291             :   Real rho;
     292             :   Real drho_dT;
     293             :   Real drho_dp;
     294           0 :   rho_from_p_T(pressure, temperature, rho, drho_dp, drho_dT);
     295             : 
     296           0 :   return -drho_dT / rho;
     297             : }
     298             : 
     299             : Real
     300          14 : HeliumFluidProperties::rho_from_p_T(Real pressure, Real temperature) const
     301             : {
     302          14 :   Real p_in_bar = pressure * 1.0e-5;
     303          14 :   return 48.14 * p_in_bar / (temperature + 0.4446 * p_in_bar / std::pow(temperature, 0.2));
     304             : }
     305             : 
     306             : void
     307           1 : HeliumFluidProperties::rho_from_p_T(
     308             :     Real pressure, Real temperature, Real & rho, Real & drho_dp, Real & drho_dT) const
     309             : {
     310           1 :   rho = rho_from_p_T(pressure, temperature);
     311           1 :   Real val = 1.0 / (temperature + 0.4446e-5 * pressure / std::pow(temperature, 0.2));
     312           1 :   drho_dp = 48.14e-5 * (val - 0.4446e-5 * pressure * val * val / std::pow(temperature, 0.2));
     313           1 :   drho_dT =
     314           1 :       -48.14e-5 * pressure * val * val * (1.0 - 0.08892e-5 * pressure / std::pow(temperature, 1.2));
     315           1 : }
     316             : 
     317             : void
     318           0 : HeliumFluidProperties::rho_from_p_T(const ADReal & pressure,
     319             :                                     const ADReal & temperature,
     320             :                                     ADReal & rho,
     321             :                                     ADReal & drho_dp,
     322             :                                     ADReal & drho_dT) const
     323             : {
     324           0 :   rho = SinglePhaseFluidProperties::rho_from_p_T(pressure, temperature);
     325           0 :   auto val = 1.0 / (temperature + 0.4446e-5 * pressure / std::pow(temperature, 0.2));
     326           0 :   drho_dp = 48.14e-5 * (val - 0.4446e-5 * pressure * val * val / std::pow(temperature, 0.2));
     327             :   drho_dT =
     328           0 :       -48.14e-5 * pressure * val * val * (1.0 - 0.08892e-5 * pressure / std::pow(temperature, 1.2));
     329           0 : }
     330             : 
     331             : Real
     332          13 : HeliumFluidProperties::e_from_p_T(Real /*pressure*/, Real temperature) const
     333             : {
     334          13 :   return _cv * temperature;
     335             : }
     336             : 
     337             : void
     338           1 : HeliumFluidProperties::e_from_p_T(
     339             :     Real pressure, Real temperature, Real & e, Real & de_dp, Real & de_dT) const
     340             : {
     341           1 :   e = e_from_p_T(pressure, temperature);
     342           1 :   de_dp = 0.0;
     343           1 :   de_dT = _cv;
     344           1 : }
     345             : 
     346             : Real
     347           8 : HeliumFluidProperties::h_from_p_T(Real /*pressure*/, Real temperature) const
     348             : {
     349           8 :   return _cp * temperature;
     350             : }
     351             : 
     352             : void
     353           1 : HeliumFluidProperties::h_from_p_T(
     354             :     Real pressure, Real temperature, Real & h, Real & dh_dp, Real & dh_dT) const
     355             : {
     356           1 :   h = h_from_p_T(pressure, temperature);
     357           1 :   dh_dp = 0.0;
     358           1 :   dh_dT = _cp;
     359           1 : }
     360             : 
     361             : Real
     362           1 : HeliumFluidProperties::molarMass() const
     363             : {
     364           1 :   return 4.002602e-3;
     365             : }
     366             : 
     367           7 : Real HeliumFluidProperties::cp_from_p_T(Real /*pressure*/, Real /*temperature*/) const
     368             : {
     369           7 :   return _cp;
     370             : }
     371             : 
     372             : void
     373           1 : HeliumFluidProperties::cp_from_p_T(
     374             :     Real pressure, Real temperature, Real & cp, Real & dcp_dp, Real & dcp_dT) const
     375             : {
     376           1 :   cp = cp_from_p_T(pressure, temperature);
     377           1 :   dcp_dp = 0.0;
     378           1 :   dcp_dT = 0.0;
     379           1 : }
     380             : 
     381           7 : Real HeliumFluidProperties::cv_from_p_T(Real /*pressure*/, Real /*temperature*/) const
     382             : {
     383           7 :   return _cv;
     384             : }
     385             : 
     386             : void
     387           1 : HeliumFluidProperties::cv_from_p_T(
     388             :     Real pressure, Real temperature, Real & cv, Real & dcv_dp, Real & dcv_dT) const
     389             : {
     390           1 :   cv = cv_from_p_T(pressure, temperature);
     391           1 :   dcv_dp = 0.0;
     392           1 :   dcv_dT = 0.0;
     393           1 : }
     394             : 
     395             : Real
     396           7 : HeliumFluidProperties::mu_from_p_T(Real /*pressure*/, Real temperature) const
     397             : {
     398           7 :   return 3.674e-7 * std::pow(temperature, 0.7);
     399             : }
     400             : 
     401             : void
     402           1 : HeliumFluidProperties::mu_from_p_T(
     403             :     Real pressure, Real temperature, Real & mu, Real & dmu_dp, Real & dmu_dT) const
     404             : {
     405           1 :   mu = mu_from_p_T(pressure, temperature);
     406           1 :   dmu_dp = 0.0;
     407           1 :   dmu_dT = 3.674e-7 * 0.7 * std::pow(temperature, -0.3);
     408           1 : }
     409             : 
     410             : Real
     411           7 : HeliumFluidProperties::k_from_p_T(Real pressure, Real temperature) const
     412             : {
     413           7 :   return 2.682e-3 * (1.0 + 1.123e-8 * pressure) *
     414           7 :          std::pow(temperature, 0.71 * (1.0 - 2.0e-9 * pressure));
     415             : }
     416             : 
     417             : void
     418           1 : HeliumFluidProperties::k_from_p_T(
     419             :     Real pressure, Real temperature, Real & k, Real & dk_dp, Real & dk_dT) const
     420             : {
     421           1 :   k = k_from_p_T(pressure, temperature);
     422             : 
     423           1 :   Real term = 1.0 + 1.123e-8 * pressure;
     424           1 :   Real exp = 0.71 * (1.0 - 2.0e-9 * pressure);
     425             : 
     426           1 :   dk_dp = 2.682e-3 * (term * 0.71 * (-2.0e-9) * std::log(temperature) * std::pow(temperature, exp) +
     427           1 :                       std::pow(temperature, exp) * 1.123e-8);
     428             : 
     429           1 :   dk_dT = 2.682e-3 * term * exp * std::pow(temperature, exp - 1.0);
     430           1 : }

Generated by: LCOV version 1.14