LCOV - code coverage report
Current view: top level - src/fluidproperties - LinearFluidProperties.C (source / functions) Hit Total Coverage
Test: idaholab/moose thermal_hydraulics: #32971 (54bef8) with base c6cf66 Lines: 138 144 95.8 %
Date: 2026-05-29 20:41:18 Functions: 38 39 97.4 %
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 "LinearFluidProperties.h"
      11             : 
      12             : registerMooseObject("ThermalHydraulicsApp", LinearFluidProperties);
      13             : 
      14             : InputParameters
      15           2 : LinearFluidProperties::validParams()
      16             : {
      17           2 :   InputParameters params = SinglePhaseFluidProperties::validParams();
      18           4 :   params.addRequiredParam<Real>("p_0", "Reference pressure");
      19           4 :   params.addRequiredParam<Real>("rho_0", "Reference density");
      20           4 :   params.addRequiredParam<Real>("a2", "dp/d(rho)");
      21           4 :   params.addRequiredParam<Real>("beta", "Coefficient of thermal expansion");
      22           4 :   params.addRequiredParam<Real>("cv", "Specific heat");
      23           4 :   params.addRequiredParam<Real>("e_0", "Reference internal energy");
      24           4 :   params.addRequiredParam<Real>("T_0", "Reference internal energy");
      25           4 :   params.addRequiredParam<Real>("mu", "Dynamic viscosity, Pa.s");
      26           4 :   params.addRequiredParam<Real>("k", "Thermal conductivity, W/(m-K)");
      27           2 :   params.addClassDescription(
      28             :       "Fluid properties for a fluid with density linearly dependent on temperature and pressure");
      29           2 :   return params;
      30           0 : }
      31             : 
      32           1 : LinearFluidProperties::LinearFluidProperties(const InputParameters & parameters)
      33             :   : SinglePhaseFluidProperties(parameters),
      34           1 :     _rho_0(getParam<Real>("rho_0")),
      35           2 :     _p_0(getParam<Real>("p_0")),
      36           2 :     _a2(getParam<Real>("a2")),
      37           2 :     _beta(getParam<Real>("beta")),
      38           2 :     _cv(getParam<Real>("cv")),
      39           2 :     _e_0(getParam<Real>("e_0")),
      40           2 :     _T_0(getParam<Real>("T_0")),
      41           2 :     _mu(getParam<Real>("mu")),
      42           2 :     _k(getParam<Real>("k")),
      43           1 :     _Pr(_cv / _k * _mu)
      44             : {
      45           1 : }
      46             : 
      47             : Real
      48          13 : LinearFluidProperties::p_from_v_e(Real v, Real e) const
      49             : {
      50          13 :   return _p_0 + _rho_0 * _a2 * ((1 / v / _rho_0 - 1.) + (_beta / _cv) * (e - _e_0));
      51             : }
      52             : 
      53             : void
      54           1 : LinearFluidProperties::p_from_v_e(Real v, Real e, Real & p, Real & dp_dv, Real & dp_de) const
      55             : {
      56           1 :   p = p_from_v_e(v, e);
      57           1 :   dp_dv = -_a2 / v / v;
      58           1 :   dp_de = _rho_0 * _a2 * _beta / _cv;
      59           1 : }
      60             : 
      61             : Real
      62           7 : LinearFluidProperties::T_from_v_e(Real /*v*/, Real e) const
      63             : {
      64             :   // e - e0 = cv * (T - T0)
      65           7 :   return _T_0 + (1. / _cv) * (e - _e_0);
      66             : }
      67             : 
      68             : void
      69           1 : LinearFluidProperties::T_from_v_e(Real v, Real e, Real & T, Real & dT_dv, Real & dT_de) const
      70             : {
      71           1 :   T = T_from_v_e(v, e);
      72           1 :   dT_dv = 0;
      73           1 :   dT_de = 1 / _cv;
      74           1 : }
      75             : 
      76             : Real
      77           6 : LinearFluidProperties::c_from_v_e(Real, Real) const
      78             : {
      79           6 :   return std::sqrt(_a2);
      80             : }
      81             : 
      82             : void
      83           1 : LinearFluidProperties::c_from_v_e(Real v, Real e, Real & c, Real & dc_dv, Real & dc_de) const
      84             : {
      85           1 :   c = c_from_v_e(v, e);
      86           1 :   dc_dv = 0;
      87           1 :   dc_de = 0;
      88           1 : }
      89             : 
      90             : Real
      91           7 : LinearFluidProperties::cp_from_v_e(Real, Real) const
      92             : {
      93           7 :   return _cv;
      94             : }
      95             : 
      96             : void
      97           1 : LinearFluidProperties::cp_from_v_e(Real v, Real e, Real & cp, Real & dcp_dv, Real & dcp_de) const
      98             : {
      99           1 :   cp = cp_from_v_e(v, e);
     100           1 :   dcp_de = 0;
     101           1 :   dcp_dv = 0;
     102           1 : }
     103             : 
     104             : Real
     105           7 : LinearFluidProperties::cv_from_v_e(Real, Real) const
     106             : {
     107           7 :   return _cv;
     108             : }
     109             : 
     110             : void
     111           1 : LinearFluidProperties::cv_from_v_e(Real v, Real e, Real & cv, Real & dcv_dv, Real & dcv_de) const
     112             : {
     113           1 :   cv = cv_from_v_e(v, e);
     114           1 :   dcv_de = 0;
     115           1 :   dcv_dv = 0;
     116           1 : }
     117             : 
     118             : Real
     119           1 : LinearFluidProperties::mu_from_v_e(Real, Real) const
     120             : {
     121           1 :   return _mu;
     122             : }
     123             : 
     124             : Real
     125           1 : LinearFluidProperties::k_from_v_e(Real, Real) const
     126             : {
     127           1 :   return _k;
     128             : }
     129             : 
     130             : Real
     131           1 : LinearFluidProperties::s_from_v_e(Real, Real) const
     132             : {
     133           1 :   mooseError(name(), ": s_from_v_e() not implemented.");
     134             : }
     135             : 
     136             : void
     137           1 : LinearFluidProperties::s_from_v_e(Real, Real, Real &, Real &, Real &) const
     138             : {
     139           1 :   mooseError(name(), ": s_from_v_e() not implemented.");
     140             : }
     141             : 
     142             : Real
     143           1 : LinearFluidProperties::s_from_p_T(Real, Real) const
     144             : {
     145           1 :   mooseError(name(), ": s_from_p_T() not implemented.");
     146             : }
     147             : 
     148             : void
     149           1 : LinearFluidProperties::s_from_p_T(Real, Real, Real &, Real &, Real &) const
     150             : {
     151           1 :   mooseError(name(), ": s_from_p_T() not implemented.");
     152             : }
     153             : 
     154             : Real
     155           1 : LinearFluidProperties::s_from_h_p(Real, Real) const
     156             : {
     157           1 :   mooseError(name(), ": s(h,p) is not implemented");
     158             : }
     159             : 
     160             : void
     161           1 : LinearFluidProperties::s_from_h_p(Real, Real, Real &, Real &, Real &) const
     162             : {
     163           1 :   mooseError(name(), ": s(h,p) is not implemented");
     164             : }
     165             : 
     166             : Real
     167           1 : LinearFluidProperties::rho_from_p_s(Real, Real) const
     168             : {
     169           1 :   mooseError(name(), ": rho_from_p_s() not implemented.");
     170             : }
     171             : 
     172             : void
     173           1 : LinearFluidProperties::rho_from_p_s(Real, Real, Real &, Real &, Real &) const
     174             : {
     175           1 :   mooseError(name(), ": rho_from_p_s() not implemented.");
     176             : }
     177             : 
     178             : Real
     179           6 : LinearFluidProperties::e_from_v_h(Real v, Real h) const
     180             : {
     181           6 :   return (h - v * p_from_v_e(v, 0)) / (1 + v * _beta / _cv * _rho_0 * _a2);
     182             : }
     183             : 
     184             : void
     185           1 : LinearFluidProperties::e_from_v_h(Real v, Real h, Real & e, Real & de_dv, Real & de_dh) const
     186             : {
     187           1 :   const auto num = (h - v * (_p_0 + _a2 * ((1 / v - _rho_0) - _rho_0 * _beta / _cv * _e_0)));
     188           1 :   const auto denum = (1 + v * _beta / _cv * _rho_0 * _a2);
     189           1 :   e = num / denum;
     190           1 :   de_dh = 1 / denum;
     191           1 :   de_dv = ((-_p_0 - _a2 * _rho_0 * (-1 - _beta / _cv * _e_0)) * denum -
     192           1 :            num * _beta / _cv * _rho_0 * _a2) /
     193           1 :           denum / denum;
     194           1 : }
     195             : 
     196             : Real
     197           1 : LinearFluidProperties::beta_from_p_T(Real, Real) const
     198             : {
     199           1 :   return _beta;
     200             : }
     201             : 
     202             : void
     203           0 : LinearFluidProperties::beta_from_p_T(
     204             :     Real p, Real T, Real & beta, Real & dbeta_dp, Real & dbeta_dT) const
     205             : {
     206           0 :   beta = beta_from_p_T(p, T);
     207           0 :   dbeta_dp = 0;
     208           0 :   dbeta_dT = 0;
     209           0 : }
     210             : 
     211             : Real
     212          19 : LinearFluidProperties::rho_from_p_T(Real p, Real T) const
     213             : {
     214          19 :   Real e = _e_0 + _cv * (T - _T_0);
     215          19 :   return (p - _p_0) / _a2 - _rho_0 * (_beta / _cv) * (e - _e_0) + _rho_0;
     216             : }
     217             : 
     218             : void
     219           3 : LinearFluidProperties::rho_from_p_T(
     220             :     Real p, Real T, Real & rho, Real & drho_dp, Real & drho_dT) const
     221             : {
     222           3 :   Real e = _e_0 + _cv * (T - _T_0);
     223           3 :   rho = (p - _p_0) / _a2 - _rho_0 * (_beta / _cv) * (e - _e_0) + _rho_0;
     224           3 :   drho_dp = 1 / _a2;
     225           3 :   drho_dT = -_rho_0 * _beta;
     226           3 : }
     227             : 
     228             : Real
     229           6 : LinearFluidProperties::e_from_p_T(Real p, Real T) const
     230             : {
     231           6 :   const auto rho = rho_from_p_T(p, T);
     232           6 :   return e_from_p_rho(p, rho);
     233             : }
     234             : 
     235             : void
     236           1 : LinearFluidProperties::e_from_p_T(Real p, Real T, Real & e, Real & de_dp, Real & de_dT) const
     237             : {
     238             :   Real rho, drho_dp, drho_dT;
     239           1 :   rho_from_p_T(p, T, rho, drho_dp, drho_dT);
     240             :   Real de_drho, de_dp_rho;
     241           1 :   e_from_p_rho(p, rho, e, de_dp_rho, de_drho);
     242           1 :   de_dp = de_drho * drho_dp + de_dp_rho;
     243           1 :   de_dT = de_drho * drho_dT;
     244           1 : }
     245             : 
     246             : Real
     247          22 : LinearFluidProperties::e_from_p_rho(Real p, Real rho) const
     248             : {
     249          22 :   return (_cv / _beta) * (((p - _p_0) / (_rho_0 * _a2)) - (rho / _rho_0) + 1) + _e_0;
     250             : }
     251             : 
     252             : void
     253           2 : LinearFluidProperties::e_from_p_rho(Real p, Real rho, Real & e, Real & de_dp, Real & de_drho) const
     254             : {
     255           2 :   e = e_from_p_rho(p, rho);
     256           2 :   de_dp = _cv / _beta / _rho_0 / _a2;
     257           2 :   de_drho = -_cv / _beta / _rho_0;
     258           2 : }
     259             : 
     260             : Real
     261           7 : LinearFluidProperties::h_from_p_T(Real p, Real T) const
     262             : {
     263           7 :   Real rho = rho_from_p_T(p, T);
     264           7 :   Real e = e_from_p_rho(p, rho);
     265           7 :   return e + p / rho;
     266             : }
     267             : 
     268             : void
     269           1 : LinearFluidProperties::h_from_p_T(Real p, Real T, Real & h, Real & dh_dp, Real & dh_dT) const
     270             : {
     271           1 :   h = h_from_p_T(p, T);
     272             : 
     273             :   Real rho, drho_dp, drho_dT;
     274           1 :   rho_from_p_T(p, T, rho, drho_dp, drho_dT);
     275             : 
     276           1 :   dh_dp = 1.0 / rho - p / rho / rho * drho_dp;
     277           1 :   dh_dT = _cv - p / rho / rho * drho_dT;
     278           1 : }
     279             : 
     280             : Real
     281           1 : LinearFluidProperties::p_from_h_s(Real, Real) const
     282             : {
     283           1 :   mooseError(name(), ": p_from_h_s() not implemented");
     284             : }
     285             : 
     286             : void
     287           1 : LinearFluidProperties::p_from_h_s(Real, Real, Real &, Real &, Real &) const
     288             : {
     289           1 :   mooseError(name(), ": p_from_h_s() not implemented");
     290             : }
     291             : 
     292             : Real
     293           1 : LinearFluidProperties::g_from_v_e(Real, Real) const
     294             : {
     295           1 :   mooseError(name(), ": g_from_v_e(v, e) not implemented");
     296             : }
     297             : 
     298             : Real
     299           1 : LinearFluidProperties::molarMass() const
     300             : {
     301           1 :   mooseError(name(), ": molarMass() not implemented");
     302             : }
     303             : 
     304             : Real
     305           1 : LinearFluidProperties::Pr(Real, Real) const
     306             : {
     307           1 :   return _Pr;
     308             : }

Generated by: LCOV version 1.14