LCOV - code coverage report
Current view: top level - src/materials - PorousFlowMultiComponentFluid.C (source / functions) Hit Total Coverage
Test: idaholab/moose porous_flow: #31405 (292dce) with base fef103 Lines: 65 90 72.2 %
Date: 2025-09-04 07:55:56 Functions: 3 8 37.5 %
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 "PorousFlowMultiComponentFluid.h"
      11             : #include "MultiComponentFluidProperties.h"
      12             : 
      13             : registerMooseObject("PorousFlowApp", PorousFlowMultiComponentFluid);
      14             : registerMooseObject("PorousFlowApp", ADPorousFlowMultiComponentFluid);
      15             : 
      16             : template <bool is_ad>
      17             : InputParameters
      18         170 : PorousFlowMultiComponentFluidTempl<is_ad>::validParams()
      19             : {
      20         170 :   InputParameters params = PorousFlowFluidPropertiesBaseTempl<is_ad>::validParams();
      21         340 :   params.addRequiredParam<UserObjectName>("fp", "The name of the user object for fluid properties");
      22         340 :   params.addCoupledVar("x", 0, "The mass fraction variable");
      23         170 :   params.addClassDescription(
      24             :       "This Material calculates fluid properties for a multicomponent fluid");
      25         170 :   return params;
      26           0 : }
      27             : 
      28             : template <bool is_ad>
      29         132 : PorousFlowMultiComponentFluidTempl<is_ad>::PorousFlowMultiComponentFluidTempl(
      30             :     const InputParameters & parameters)
      31             :   : PorousFlowFluidPropertiesBaseTempl<is_ad>(parameters),
      32         264 :     _ddensity_dX(_compute_rho_mu
      33         264 :                      ? (_nodal_material ? &this->template declarePropertyDerivative<Real>(
      34           0 :                                               "PorousFlow_fluid_phase_density_nodal" + _phase,
      35             :                                               _mass_fraction_variable_name)
      36         660 :                                         : &this->template declarePropertyDerivative<Real>(
      37         132 :                                               "PorousFlow_fluid_phase_density_qp" + _phase,
      38             :                                               _mass_fraction_variable_name))
      39             :                      : nullptr),
      40         132 :     _dviscosity_dX(
      41         132 :         _compute_rho_mu
      42         132 :             ? (_nodal_material
      43         264 :                    ? &this->template declarePropertyDerivative<Real>(
      44           0 :                          "PorousFlow_viscosity_nodal" + _phase, _mass_fraction_variable_name)
      45         660 :                    : &this->template declarePropertyDerivative<Real>(
      46         132 :                          "PorousFlow_viscosity_qp" + _phase, _mass_fraction_variable_name))
      47             :             : nullptr),
      48         264 :     _dinternal_energy_dX(_compute_internal_energy
      49         132 :                              ? (_nodal_material
      50         264 :                                     ? &this->template declarePropertyDerivative<Real>(
      51           0 :                                           "PorousFlow_fluid_phase_internal_energy_nodal" + _phase,
      52             :                                           _mass_fraction_variable_name)
      53         660 :                                     : &this->template declarePropertyDerivative<Real>(
      54         132 :                                           "PorousFlow_fluid_phase_internal_energy_qp" + _phase,
      55             :                                           _mass_fraction_variable_name))
      56             :                              : nullptr),
      57         264 :     _denthalpy_dX(_compute_enthalpy
      58         264 :                       ? (_nodal_material ? &this->template declarePropertyDerivative<Real>(
      59           0 :                                                "PorousFlow_fluid_phase_enthalpy_nodal" + _phase,
      60             :                                                _mass_fraction_variable_name)
      61         660 :                                          : &this->template declarePropertyDerivative<Real>(
      62         132 :                                                "PorousFlow_fluid_phase_enthalpy_qp" + _phase,
      63             :                                                _mass_fraction_variable_name))
      64             :                       : nullptr),
      65         132 :     _fp(this->template getUserObject<MultiComponentFluidProperties>("fp")),
      66         264 :     _is_X_nodal(isCoupled("x") ? getFieldVar("x", 0)->isNodal() : false),
      67         132 :     _X(_nodal_material && _is_X_nodal ? this->template coupledGenericDofValue<is_ad>("x")
      68         396 :                                       : this->template coupledGenericValue<is_ad>("x"))
      69             : {
      70         132 : }
      71             : 
      72             : template <bool is_ad>
      73             : void
      74           0 : PorousFlowMultiComponentFluidTempl<is_ad>::initQpStatefulProperties()
      75             : {
      76           0 :   if (_compute_rho_mu)
      77           0 :     (*_density)[_qp] = _fp.rho_from_p_T_X(
      78           0 :         _porepressure[_qp][_phase_num] * _pressure_to_Pascals, _temperature[_qp] + _t_c2k, _X[_qp]);
      79             : 
      80           0 :   if (_compute_internal_energy)
      81           0 :     (*_internal_energy)[_qp] = _fp.e_from_p_T_X(
      82           0 :         _porepressure[_qp][_phase_num] * _pressure_to_Pascals, _temperature[_qp] + _t_c2k, _X[_qp]);
      83             : 
      84           0 :   if (_compute_enthalpy)
      85           0 :     (*_enthalpy)[_qp] = _fp.h_from_p_T_X(
      86           0 :         _porepressure[_qp][_phase_num] * _pressure_to_Pascals, _temperature[_qp] + _t_c2k, _X[_qp]);
      87           0 : }
      88             : 
      89             : template <bool is_ad>
      90             : void
      91          72 : PorousFlowMultiComponentFluidTempl<is_ad>::computeQpProperties()
      92             : {
      93          72 :   const GenericReal<is_ad> Tk = _temperature[_qp] + _t_c2k;
      94             : 
      95          72 :   if (_compute_rho_mu)
      96             :   {
      97             :     if (is_ad)
      98             :     {
      99           0 :       (*_density)[_qp] =
     100           0 :           _fp.rho_from_p_T_X(_porepressure[_qp][_phase_num] * _pressure_to_Pascals, Tk, _X[_qp]);
     101           0 :       (*_viscosity)[_qp] =
     102           0 :           _fp.mu_from_p_T_X(_porepressure[_qp][_phase_num] * _pressure_to_Pascals, Tk, _X[_qp]) /
     103           0 :           _pressure_to_Pascals / _time_to_seconds;
     104             :     }
     105             :     else
     106             :     {
     107             :       // Density and derivatives wrt pressure and temperature
     108             :       Real rho, drho_dp, drho_dT, drho_dx;
     109          72 :       _fp.rho_from_p_T_X(MetaPhysicL::raw_value(_porepressure[_qp][_phase_num]) *
     110          72 :                              _pressure_to_Pascals,
     111             :                          MetaPhysicL::raw_value(Tk),
     112          72 :                          MetaPhysicL::raw_value(_X[_qp]),
     113             :                          rho,
     114             :                          drho_dp,
     115             :                          drho_dT,
     116             :                          drho_dx);
     117          72 :       (*_density)[_qp] = rho;
     118          72 :       (*_ddensity_dp)[_qp] = drho_dp * _pressure_to_Pascals;
     119          72 :       (*_ddensity_dT)[_qp] = drho_dT;
     120          72 :       (*_ddensity_dX)[_qp] = drho_dx;
     121             : 
     122             :       // Viscosity and derivatives wrt pressure and temperature
     123             :       Real mu, dmu_dp, dmu_dT, dmu_dx;
     124          72 :       _fp.mu_from_p_T_X(MetaPhysicL::raw_value(_porepressure[_qp][_phase_num]) *
     125          72 :                             _pressure_to_Pascals,
     126             :                         MetaPhysicL::raw_value(Tk),
     127          72 :                         MetaPhysicL::raw_value(_X[_qp]),
     128             :                         mu,
     129             :                         dmu_dp,
     130             :                         dmu_dT,
     131             :                         dmu_dx);
     132          72 :       (*_viscosity)[_qp] = mu / _pressure_to_Pascals / _time_to_seconds;
     133          72 :       (*_dviscosity_dp)[_qp] = dmu_dp / _time_to_seconds;
     134          72 :       (*_dviscosity_dT)[_qp] = dmu_dT / _pressure_to_Pascals / _time_to_seconds;
     135          72 :       (*_dviscosity_dX)[_qp] = dmu_dx / _pressure_to_Pascals / _time_to_seconds;
     136             :     }
     137             :   }
     138             : 
     139             :   // Internal energy and derivatives wrt pressure and temperature
     140          72 :   if (_compute_internal_energy)
     141             :   {
     142             :     if (is_ad)
     143           0 :       (*_internal_energy)[_qp] =
     144           0 :           _fp.e_from_p_T_X(_porepressure[_qp][_phase_num] * _pressure_to_Pascals, Tk, _X[_qp]);
     145             :     else
     146             :     {
     147             :       Real e, de_dp, de_dT, de_dx;
     148          72 :       _fp.e_from_p_T_X(MetaPhysicL::raw_value(_porepressure[_qp][_phase_num]) *
     149          72 :                            _pressure_to_Pascals,
     150             :                        MetaPhysicL::raw_value(Tk),
     151          72 :                        MetaPhysicL::raw_value(_X[_qp]),
     152             :                        e,
     153             :                        de_dp,
     154             :                        de_dT,
     155             :                        de_dx);
     156          72 :       (*_internal_energy)[_qp] = e;
     157          72 :       (*_dinternal_energy_dp)[_qp] = de_dp * _pressure_to_Pascals;
     158          72 :       (*_dinternal_energy_dT)[_qp] = de_dT;
     159          72 :       (*_dinternal_energy_dX)[_qp] = de_dx;
     160             :     }
     161             :   }
     162             : 
     163             :   // Enthalpy and derivatives wrt pressure and temperature
     164          72 :   if (_compute_enthalpy)
     165             :   {
     166             :     if (is_ad)
     167           0 :       (*_enthalpy)[_qp] =
     168           0 :           _fp.h_from_p_T_X(_porepressure[_qp][_phase_num] * _pressure_to_Pascals, Tk, _X[_qp]);
     169             :     else
     170             :     {
     171             :       Real h, dh_dp, dh_dT, dh_dx;
     172          72 :       _fp.h_from_p_T_X(MetaPhysicL::raw_value(_porepressure[_qp][_phase_num]) *
     173          72 :                            _pressure_to_Pascals,
     174             :                        MetaPhysicL::raw_value(Tk),
     175          72 :                        MetaPhysicL::raw_value(_X[_qp]),
     176             :                        h,
     177             :                        dh_dp,
     178             :                        dh_dT,
     179             :                        dh_dx);
     180          72 :       (*_enthalpy)[_qp] = h;
     181          72 :       (*_denthalpy_dp)[_qp] = dh_dp * _pressure_to_Pascals;
     182          72 :       (*_denthalpy_dT)[_qp] = dh_dT;
     183          72 :       (*_denthalpy_dX)[_qp] = dh_dx;
     184             :     }
     185             :   }
     186          72 : }
     187             : 
     188             : template class PorousFlowMultiComponentFluidTempl<false>;
     189             : template class PorousFlowMultiComponentFluidTempl<true>;

Generated by: LCOV version 1.14