LCOV - code coverage report
Current view: top level - src/fluidproperties - MethaneFluidProperties.C (source / functions) Hit Total Coverage
Test: idaholab/moose fluid_properties: #31405 (292dce) with base fef103 Lines: 175 184 95.1 %
Date: 2025-09-04 07:53:14 Functions: 25 26 96.2 %
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 "MethaneFluidProperties.h"
      11             : #include "MathUtils.h"
      12             : #include "libmesh/utility.h"
      13             : 
      14             : registerMooseObject("FluidPropertiesApp", MethaneFluidProperties);
      15             : 
      16             : InputParameters
      17          59 : MethaneFluidProperties::validParams()
      18             : {
      19          59 :   InputParameters params = HelmholtzFluidProperties::validParams();
      20          59 :   params.addClassDescription("Fluid properties for methane (CH4)");
      21          59 :   return params;
      22           0 : }
      23             : 
      24          31 : MethaneFluidProperties::MethaneFluidProperties(const InputParameters & parameters)
      25             :   : HelmholtzFluidProperties(parameters),
      26          31 :     _Mch4(16.0425e-3),
      27          31 :     _p_critical(4.5992e6),
      28          31 :     _T_critical(190.564),
      29          31 :     _rho_critical(162.66),
      30          31 :     _p_triple(1.169e4),
      31          31 :     _T_triple(90.6941)
      32             : {
      33          31 : }
      34             : 
      35          62 : MethaneFluidProperties::~MethaneFluidProperties() {}
      36             : 
      37             : std::string
      38           1 : MethaneFluidProperties::fluidName() const
      39             : {
      40           1 :   return "methane";
      41             : }
      42             : 
      43             : Real
      44        5320 : MethaneFluidProperties::molarMass() const
      45             : {
      46        5320 :   return _Mch4;
      47             : }
      48             : 
      49             : Real
      50           1 : MethaneFluidProperties::criticalPressure() const
      51             : {
      52           1 :   return _p_critical;
      53             : }
      54             : 
      55             : Real
      56        5320 : MethaneFluidProperties::criticalTemperature() const
      57             : {
      58        5320 :   return _T_critical;
      59             : }
      60             : 
      61             : Real
      62        5320 : MethaneFluidProperties::criticalDensity() const
      63             : {
      64        5320 :   return _rho_critical;
      65             : }
      66             : 
      67             : Real
      68           1 : MethaneFluidProperties::triplePointPressure() const
      69             : {
      70           1 :   return _p_triple;
      71             : }
      72             : 
      73             : Real
      74           1 : MethaneFluidProperties::triplePointTemperature() const
      75             : {
      76           1 :   return _T_triple;
      77             : }
      78             : 
      79             : Real
      80          82 : MethaneFluidProperties::mu_from_p_T(Real /*pressure*/, Real temperature) const
      81             : {
      82             :   // Check the temperature is in the range of validity (200 K <= T <= 1000 K)
      83          82 :   if (temperature <= 200.0 || temperature >= 1000.0)
      84           0 :     mooseException(
      85             :         "Temperature ", temperature, "K out of range (200K, 1000K) in ", name(), ": mu_from_p_T()");
      86             : 
      87             :   Real viscosity = 0.0;
      88         574 :   for (std::size_t i = 0; i < _a.size(); ++i)
      89         492 :     viscosity += _a[i] * MathUtils::pow(temperature, i);
      90             : 
      91          82 :   return viscosity * 1.e-6;
      92             : }
      93             : 
      94             : void
      95           3 : MethaneFluidProperties::mu_from_p_T(
      96             :     Real pressure, Real temperature, Real & mu, Real & dmu_dp, Real & dmu_dT) const
      97             : {
      98             : 
      99           3 :   mu = this->mu_from_p_T(pressure, temperature);
     100           3 :   dmu_dp = 0.0;
     101             : 
     102             :   Real dmudt = 0.0;
     103          21 :   for (std::size_t i = 0; i < _a.size(); ++i)
     104          18 :     dmudt += i * _a[i] * MathUtils::pow(temperature, i) / temperature;
     105           3 :   dmu_dT = dmudt * 1.e-6;
     106           3 : }
     107             : 
     108             : Real
     109          78 : MethaneFluidProperties::k_from_p_T(Real /*pressure*/, Real temperature) const
     110             : {
     111             :   // Check the temperature is in the range of validity (200 K <= T <= 1000 K)
     112          78 :   if (temperature <= 200.0 || temperature >= 1000.0)
     113           0 :     mooseException(
     114             :         "Temperature ", temperature, "K out of range (200K, 1000K) in ", name(), ": k()");
     115             : 
     116             :   Real kt = 0.0;
     117         624 :   for (std::size_t i = 0; i < _b.size(); ++i)
     118         546 :     kt += _b[i] * MathUtils::pow(temperature, i);
     119             : 
     120          78 :   return kt;
     121             : }
     122             : 
     123             : void
     124           1 : MethaneFluidProperties::k_from_p_T(
     125             :     Real /*pressure*/, Real temperature, Real & k, Real & dk_dp, Real & dk_dT) const
     126             : {
     127             :   // Check the temperature is in the range of validity (200 K <= T <= 1000 K)
     128           1 :   if (temperature <= 200.0 || temperature >= 1000.0)
     129           0 :     mooseException(
     130             :         "Temperature ", temperature, "K out of range (200K, 1000K) in ", name(), ": k()");
     131             : 
     132             :   Real kt = 0.0, dkt_dT = 0.0;
     133             : 
     134           8 :   for (std::size_t i = 0; i < _b.size(); ++i)
     135           7 :     kt += _b[i] * MathUtils::pow(temperature, i);
     136             : 
     137           7 :   for (std::size_t i = 1; i < _b.size(); ++i)
     138           6 :     dkt_dT += i * _b[i] * MathUtils::pow(temperature, i) / temperature;
     139             : 
     140           1 :   k = kt;
     141           1 :   dk_dp = 0.0;
     142           1 :   dk_dT = dkt_dT;
     143           1 : }
     144             : 
     145             : Real
     146           3 : MethaneFluidProperties::vaporPressure(Real temperature) const
     147             : {
     148           3 :   if (temperature < _T_triple || temperature > _T_critical)
     149           0 :     mooseException("Temperature is out of range in ", name(), ": vaporPressure()");
     150             : 
     151           3 :   const Real Tr = temperature / _T_critical;
     152           3 :   const Real theta = 1.0 - Tr;
     153             : 
     154           3 :   const Real logpressure = (-6.036219 * theta + 1.409353 * std::pow(theta, 1.5) -
     155           3 :                             0.4945199 * Utility::pow<2>(theta) - 1.443048 * std::pow(theta, 4.5)) /
     156           3 :                            Tr;
     157             : 
     158           3 :   return _p_critical * std::exp(logpressure);
     159             : }
     160             : 
     161             : void
     162           0 : MethaneFluidProperties::vaporPressure(Real, Real &, Real &) const
     163             : {
     164           0 :   mooseError("vaporPressure() is not implemented");
     165             : }
     166             : 
     167             : std::vector<Real>
     168           1 : MethaneFluidProperties::henryCoefficients() const
     169             : {
     170           1 :   return {-10.44708, 4.66491, 12.12986};
     171             : }
     172             : 
     173             : Real
     174           3 : MethaneFluidProperties::saturatedLiquidDensity(Real temperature) const
     175             : {
     176           3 :   if (temperature < _T_triple || temperature > _T_critical)
     177           0 :     mooseException(
     178             :         "Temperature ", temperature, " is out of range in ", name(), ": saturatedLiquidDensity()");
     179             : 
     180           3 :   const Real Tr = temperature / _T_critical;
     181           3 :   const Real theta = 1.0 - Tr;
     182             : 
     183           3 :   const Real logdensity = 1.9906389 * std::pow(theta, 0.354) - 0.78756197 * std::sqrt(theta) +
     184           3 :                           0.036976723 * std::pow(theta, 2.5);
     185             : 
     186           3 :   return _rho_critical * std::exp(logdensity);
     187             : }
     188             : 
     189             : Real
     190           3 : MethaneFluidProperties::saturatedVaporDensity(Real temperature) const
     191             : {
     192           3 :   if (temperature < _T_triple || temperature > _T_critical)
     193           0 :     mooseException(
     194             :         "Temperature ", temperature, " is out of range in ", name(), ": saturatedVaporDensity()");
     195             : 
     196           3 :   const Real Tr = temperature / _T_critical;
     197           3 :   const Real theta = 1.0 - Tr;
     198             : 
     199             :   const Real logdensity =
     200           3 :       -1.880284 * std::pow(theta, 0.354) - 2.8526531 * std::pow(theta, 5.0 / 6.0) -
     201           3 :       3.000648 * std::pow(theta, 1.5) - 5.251169 * std::pow(theta, 2.5) -
     202           3 :       13.191859 * std::pow(theta, 25.0 / 6.0) - 37.553961 * std::pow(theta, 47.0 / 6.0);
     203             : 
     204           3 :   return _rho_critical * std::exp(logdensity);
     205             : }
     206             : 
     207             : Real
     208          73 : MethaneFluidProperties::alpha(Real delta, Real tau) const
     209             : {
     210             :   // Ideal gas component of the Helmholtz free energy
     211          73 :   Real alpha0 = std::log(delta) + 9.91243972 - 6.33270087 * tau + 3.0016 * std::log(tau);
     212             : 
     213         438 :   for (std::size_t i = 0; i < _a0.size(); ++i)
     214         365 :     alpha0 += _a0[i] * std::log(1.0 - std::exp(-_b0[i] * tau));
     215             : 
     216             :   // Residual component of the Helmholtz free energy
     217             :   Real alphar = 0.0;
     218             : 
     219        1022 :   for (std::size_t i = 0; i < _t1.size(); ++i)
     220         949 :     alphar += _N1[i] * MathUtils::pow(delta, _d1[i]) * std::pow(tau, _t1[i]);
     221             : 
     222        1752 :   for (std::size_t i = 0; i < _t2.size(); ++i)
     223        1679 :     alphar += _N2[i] * MathUtils::pow(delta, _d2[i]) * std::pow(tau, _t2[i]) *
     224        1679 :               std::exp(-MathUtils::pow(delta, _c2[i]));
     225             : 
     226         365 :   for (std::size_t i = 0; i < _t3.size(); ++i)
     227         292 :     alphar += _N3[i] * MathUtils::pow(delta, _d3[i]) * std::pow(tau, _t3[i]) *
     228         292 :               std::exp(-_alpha3[i] * Utility::pow<2>(delta - _D3[i]) -
     229         292 :                        _beta3[i] * Utility::pow<2>(tau - _gamma3[i]));
     230             : 
     231             :   // The Helmholtz free energy is the sum of these two
     232          73 :   return alpha0 + alphar;
     233             : }
     234             : 
     235             : Real
     236        5092 : MethaneFluidProperties::dalpha_ddelta(Real delta, Real tau) const
     237             : {
     238             :   // Ideal gas component of the Helmholtz free energy
     239        5092 :   Real dalpha0 = 1.0 / delta;
     240             : 
     241             :   // Residual component of the Helmholtz free energy
     242             :   Real dalphar = 0.0;
     243             : 
     244       71288 :   for (std::size_t i = 0; i < _t1.size(); ++i)
     245       66196 :     dalphar += _N1[i] * _d1[i] * MathUtils::pow(delta, _d1[i]) * std::pow(tau, _t1[i]);
     246             : 
     247      122208 :   for (std::size_t i = 0; i < _t2.size(); ++i)
     248      117116 :     dalphar += _N2[i] * MathUtils::pow(delta, _d2[i]) * std::pow(tau, _t2[i]) *
     249      117116 :                std::exp(-MathUtils::pow(delta, _c2[i])) *
     250      117116 :                (_d2[i] - _c2[i] * MathUtils::pow(delta, _c2[i]));
     251             : 
     252       25460 :   for (std::size_t i = 0; i < _t3.size(); ++i)
     253       20368 :     dalphar += _N3[i] * MathUtils::pow(delta, _d3[i]) * std::pow(tau, _t3[i]) *
     254       20368 :                std::exp(-_alpha3[i] * Utility::pow<2>(delta - _D3[i]) -
     255       20368 :                         _beta3[i] * Utility::pow<2>(tau - _gamma3[i])) *
     256       20368 :                (_d3[i] - delta * (2.0 * _alpha3[i] * (delta - _D3[i])));
     257             : 
     258             :   // The Helmholtz free energy is the sum of these two
     259        5092 :   return dalpha0 + dalphar / delta;
     260             : }
     261             : 
     262             : Real
     263         233 : MethaneFluidProperties::dalpha_dtau(Real delta, Real tau) const
     264             : {
     265             :   // Ideal gas component of the Helmholtz free energy
     266         233 :   Real dalpha0 = -6.33270087 + 3.0016 / tau;
     267             : 
     268        1398 :   for (std::size_t i = 0; i < _a0.size(); ++i)
     269        1165 :     dalpha0 += _a0[i] * _b0[i] * (1.0 / (1.0 - std::exp(-_b0[i] * tau)) - 1.0);
     270             : 
     271             :   // Residual component of the Helmholtz free energy
     272             :   Real dalphar = 0.0;
     273             : 
     274        3262 :   for (std::size_t i = 0; i < _t1.size(); ++i)
     275        3029 :     dalphar += _N1[i] * _t1[i] * MathUtils::pow(delta, _d1[i]) * std::pow(tau, _t1[i]);
     276             : 
     277        5592 :   for (std::size_t i = 0; i < _t2.size(); ++i)
     278        5359 :     dalphar += _N2[i] * _t2[i] * MathUtils::pow(delta, _d2[i]) * std::pow(tau, _t2[i]) *
     279        5359 :                std::exp(-MathUtils::pow(delta, _c2[i]));
     280             : 
     281        1165 :   for (std::size_t i = 0; i < _t3.size(); ++i)
     282         932 :     dalphar += _N3[i] * MathUtils::pow(delta, _d3[i]) * std::pow(tau, _t3[i]) *
     283         932 :                std::exp(-_alpha3[i] * Utility::pow<2>(delta - _D3[i]) -
     284         932 :                         _beta3[i] * Utility::pow<2>(tau - _gamma3[i])) *
     285         932 :                (_t3[i] + tau * (2.0 * _beta3[i] * (tau - _gamma3[i])));
     286             : 
     287             :   // The Helmholtz free energy is the sum of these two
     288         233 :   return dalpha0 + dalphar / tau;
     289             : }
     290             : 
     291             : Real
     292         154 : MethaneFluidProperties::d2alpha_ddelta2(Real delta, Real tau) const
     293             : {
     294             :   // Ideal gas component of the Helmholtz free energy
     295         154 :   Real dalpha0 = -1.0 / delta / delta;
     296             : 
     297             :   // Residual component of the Helmholtz free energy
     298             :   Real dalphar = 0.0;
     299             : 
     300        2156 :   for (std::size_t i = 0; i < _t1.size(); ++i)
     301        2002 :     dalphar +=
     302        2002 :         _N1[i] * _d1[i] * (_d1[i] - 1.0) * MathUtils::pow(delta, _d1[i]) * std::pow(tau, _t1[i]);
     303             : 
     304        3696 :   for (std::size_t i = 0; i < _t2.size(); ++i)
     305        3542 :     dalphar += _N2[i] * MathUtils::pow(delta, _d2[i]) * std::pow(tau, _t2[i]) *
     306        3542 :                std::exp(-MathUtils::pow(delta, _c2[i])) *
     307        3542 :                ((_d2[i] - _c2[i] * MathUtils::pow(delta, _c2[i])) *
     308        3542 :                     (_d2[i] - 1.0 - _c2[i] * MathUtils::pow(delta, _c2[i])) -
     309        3542 :                 _c2[i] * _c2[i] * MathUtils::pow(delta, _c2[i]));
     310             : 
     311         770 :   for (std::size_t i = 0; i < _t3.size(); ++i)
     312         616 :     dalphar += _N3[i] * std::pow(tau, _t3[i]) *
     313         616 :                std::exp(-_alpha3[i] * Utility::pow<2>(delta - _D3[i]) -
     314         616 :                         _beta3[i] * Utility::pow<2>(tau - _gamma3[i])) *
     315         616 :                (-2.0 * _alpha3[i] * MathUtils::pow(delta, _d3[i] + 2) +
     316         616 :                 4.0 * _alpha3[i] * _alpha3[i] * MathUtils::pow(delta, _d3[i] + 2) *
     317         616 :                     MathUtils::pow(delta - _D3[i], 2) -
     318         616 :                 4.0 * _d3[i] * _alpha3[i] * MathUtils::pow(delta, _d3[i] + 1) * (delta - _D3[i]) +
     319         616 :                 _d3[i] * (_d3[i] - 1) * MathUtils::pow(delta, _d3[i]));
     320             : 
     321             :   // The Helmholtz free energy is the sum of these two
     322         154 :   return dalpha0 + dalphar / delta / delta;
     323             : }
     324             : 
     325             : Real
     326         223 : MethaneFluidProperties::d2alpha_dtau2(Real delta, Real tau) const
     327             : {
     328             :   // Ideal gas component of the Helmholtz free energy
     329         223 :   Real dalpha0 = -3.0016 / tau / tau;
     330             : 
     331        1338 :   for (std::size_t i = 0; i < _a0.size(); ++i)
     332             :   {
     333        1115 :     Real exptau = std::exp(-_b0[i] * tau);
     334        1115 :     dalpha0 -= _a0[i] * (_b0[i] * _b0[i] * exptau / (1.0 - exptau) / (1.0 - exptau));
     335             :   }
     336             : 
     337             :   // Residual component of the Helmholtz free energy
     338             :   Real dalphar = 0.0;
     339             : 
     340        3122 :   for (std::size_t i = 0; i < _t1.size(); ++i)
     341        2899 :     dalphar +=
     342        2899 :         _N1[i] * _t1[i] * (_t1[i] - 1.0) * MathUtils::pow(delta, _d1[i]) * std::pow(tau, _t1[i]);
     343             : 
     344        5352 :   for (std::size_t i = 0; i < _t2.size(); ++i)
     345        5129 :     dalphar += _N2[i] * _t2[i] * (_t2[i] - 1.0) * MathUtils::pow(delta, _d2[i]) *
     346        5129 :                std::pow(tau, _t2[i]) * std::exp(-MathUtils::pow(delta, _c2[i]));
     347             : 
     348        1115 :   for (std::size_t i = 0; i < _t3.size(); ++i)
     349         892 :     dalphar += _N3[i] * MathUtils::pow(delta, _d3[i]) * std::pow(tau, _t3[i]) *
     350         892 :                std::exp(-_alpha3[i] * Utility::pow<2>(delta - _D3[i]) -
     351         892 :                         _beta3[i] * Utility::pow<2>(tau - _gamma3[i])) *
     352         892 :                (tau * _t3[i] - _beta3[i] * tau * tau * MathUtils::pow(tau - _gamma3[i], 2) -
     353         892 :                 _t3[i] - 2.0 * tau * tau * _beta3[i]);
     354             : 
     355             :   // The Helmholtz free energy is the sum of these two
     356         223 :   return dalpha0 + dalphar / tau / tau;
     357             : }
     358             : 
     359             : Real
     360         154 : MethaneFluidProperties::d2alpha_ddeltatau(Real delta, Real tau) const
     361             : {
     362             :   // Residual component of the Helmholtz free energy
     363             :   Real dalphar = 0.0;
     364             : 
     365        2156 :   for (std::size_t i = 0; i < _t1.size(); ++i)
     366        2002 :     dalphar += _N1[i] * _d1[i] * _t1[i] * std::pow(delta, _d1[i]) * std::pow(tau, _t1[i]);
     367             : 
     368        3696 :   for (std::size_t i = 0; i < _t2.size(); ++i)
     369        3542 :     dalphar += _N2[i] * _t2[i] * std::pow(delta, _d2[i]) * std::pow(tau, _t2[i]) *
     370        3542 :                std::exp(-MathUtils::pow(delta, _c2[i])) *
     371        3542 :                (_d2[i] - _c2[i] * MathUtils::pow(delta, _c2[i]));
     372             : 
     373         770 :   for (std::size_t i = 0; i < _t3.size(); ++i)
     374         616 :     dalphar += _N3[i] * std::pow(delta, _d3[i]) * std::pow(tau, _t3[i]) *
     375         616 :                std::exp(-_alpha3[i] * Utility::pow<2>(delta - _D3[i]) -
     376         616 :                         _beta3[i] * Utility::pow<2>(tau - _gamma3[i])) *
     377         616 :                (_d3[i] - 2.0 * _alpha3[i] * delta * (delta - _D3[i]) *
     378         616 :                              (_t3[i] - 2.0 * _beta3[i] * tau * (tau - _gamma3[i])));
     379             : 
     380             :   // The Helmholtz free energy is the sum of these two
     381         154 :   return dalphar / delta / tau;
     382             : }

Generated by: LCOV version 1.14