LCOV - code coverage report
Current view: top level - src/materials - PorousFlowFluidStateBaseMaterial.C (source / functions) Hit Total Coverage
Test: idaholab/moose porous_flow: #32971 (54bef8) with base c6cf66 Lines: 98 98 100.0 %
Date: 2026-05-29 20:38:56 Functions: 12 12 100.0 %
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 "PorousFlowFluidStateBaseMaterial.h"
      11             : #include "PorousFlowCapillaryPressure.h"
      12             : 
      13             : template <bool is_ad>
      14             : InputParameters
      15        2980 : PorousFlowFluidStateBaseMaterialTempl<is_ad>::validParams()
      16             : {
      17        2980 :   InputParameters params = PorousFlowVariableBase::validParams();
      18        5960 :   MooseEnum unit_choice("Kelvin=0 Celsius=1", "Kelvin");
      19        5960 :   params.addParam<MooseEnum>(
      20             :       "temperature_unit", unit_choice, "The unit of the temperature variable");
      21        5960 :   params.addRequiredParam<UserObjectName>("capillary_pressure",
      22             :                                           "Name of the UserObject defining the capillary pressure");
      23        5960 :   params.addPrivateParam<std::string>("pf_material_type", "fluid_state");
      24        2980 :   params.addClassDescription("Base class for fluid state calculations using persistent primary "
      25             :                              "variables and a vapor-liquid flash");
      26        2980 :   return params;
      27        2980 : }
      28             : 
      29             : template <bool is_ad>
      30        2298 : PorousFlowFluidStateBaseMaterialTempl<is_ad>::PorousFlowFluidStateBaseMaterialTempl(
      31             :     const InputParameters & parameters)
      32             :   : PorousFlowVariableBaseTempl<is_ad>(parameters),
      33        4536 :     _T_c2k(this->template getParam<MooseEnum>("temperature_unit") == 0 ? 0.0 : 273.15),
      34        2298 :     _is_initqp(false),
      35        2298 :     _pc(this->template getUserObject<PorousFlowCapillaryPressure>("capillary_pressure")),
      36        3657 :     _sfx(_nodal_material ? "_nodal" : "_qp"),
      37        4596 :     _mass_frac(this->template declareGenericProperty<std::vector<std::vector<Real>>, is_ad>(
      38             :         "PorousFlow_mass_frac" + _sfx)),
      39        2298 :     _grad_mass_frac_qp(
      40        2298 :         _nodal_material
      41        2298 :             ? nullptr
      42        3657 :             : &this->template declareGenericProperty<std::vector<std::vector<RealGradient>>, is_ad>(
      43             :                   "PorousFlow_grad_mass_frac" + _sfx)),
      44        2298 :     _dmass_frac_dvar(
      45             :         is_ad ? nullptr
      46        3996 :               : &this->template declareProperty<std::vector<std::vector<std::vector<Real>>>>(
      47             :                     "dPorousFlow_mass_frac" + _sfx + "_dvar")),
      48        4596 :     _fluid_density(this->template declareGenericProperty<std::vector<Real>, is_ad>(
      49             :         "PorousFlow_fluid_phase_density" + _sfx)),
      50        2298 :     _dfluid_density_dvar(is_ad ? nullptr
      51        3996 :                                : &this->template declareProperty<std::vector<std::vector<Real>>>(
      52             :                                      "dPorousFlow_fluid_phase_density" + _sfx + "_dvar")),
      53        4596 :     _fluid_viscosity(this->template declareGenericProperty<std::vector<Real>, is_ad>(
      54             :         "PorousFlow_viscosity" + _sfx)),
      55        2298 :     _dfluid_viscosity_dvar(is_ad ? nullptr
      56        3996 :                                  : &this->template declareProperty<std::vector<std::vector<Real>>>(
      57             :                                        "dPorousFlow_viscosity" + _sfx + "_dvar")),
      58        4596 :     _fluid_enthalpy(this->template declareGenericProperty<std::vector<Real>, is_ad>(
      59             :         "PorousFlow_fluid_phase_enthalpy" + _sfx)),
      60        2298 :     _dfluid_enthalpy_dvar(is_ad ? nullptr
      61        3996 :                                 : &this->template declareProperty<std::vector<std::vector<Real>>>(
      62             :                                       "dPorousFlow_fluid_phase_enthalpy" + _sfx + "_dvar")),
      63        4596 :     _fluid_internal_energy(this->template declareGenericProperty<std::vector<Real>, is_ad>(
      64             :         "PorousFlow_fluid_phase_internal_energy" + _sfx)),
      65        2298 :     _dfluid_internal_energy_dvar(
      66             :         is_ad ? nullptr
      67        3996 :               : &this->template declareProperty<std::vector<std::vector<Real>>>(
      68        2298 :                     "dPorousFlow_fluid_phase_internal_energy" + _sfx + "_dvar"))
      69             : {
      70             :   // Set the size of the FluidStateProperties vector
      71        2298 :   _fsp.resize(_num_phases, FluidStateProperties(_num_components));
      72        2298 : }
      73             : 
      74             : template <>
      75             : GenericReal<false>
      76    16046441 : PorousFlowFluidStateBaseMaterialTempl<false>::genericValue(const ADReal & value)
      77             : {
      78    16046441 :   return MetaPhysicL::raw_value(value);
      79             : }
      80             : 
      81             : template <>
      82             : GenericReal<true>
      83     2876704 : PorousFlowFluidStateBaseMaterialTempl<true>::genericValue(const ADReal & value)
      84             : {
      85     2876704 :   return value;
      86             : }
      87             : 
      88             : template <bool is_ad>
      89             : void
      90       31121 : PorousFlowFluidStateBaseMaterialTempl<is_ad>::initQpStatefulProperties()
      91             : {
      92       31121 :   _is_initqp = true;
      93             :   // Set the size of pressure and saturation vectors
      94       31121 :   PorousFlowVariableBaseTempl<is_ad>::initQpStatefulProperties();
      95             : 
      96             :   // Set the size of all other vectors
      97       31121 :   setMaterialVectorSize();
      98             : 
      99       31121 :   thermophysicalProperties();
     100             : 
     101             :   // Set the initial values of the properties at the nodes.
     102             :   // Note: not required for qp materials as no old values at the qps are requested
     103             :   // unless the material is AD (for the FV case there are no nodal materials)
     104       20188 :   if (_nodal_material || is_ad)
     105       63081 :     for (unsigned int ph = 0; ph < _num_phases; ++ph)
     106             :     {
     107       42054 :       _saturation[_qp][ph] = genericValue(_fsp[ph].saturation);
     108       42054 :       _porepressure[_qp][ph] = genericValue(_fsp[ph].pressure);
     109       42054 :       _fluid_density[_qp][ph] = genericValue(_fsp[ph].density);
     110       42054 :       _fluid_viscosity[_qp][ph] = genericValue(_fsp[ph].viscosity);
     111       42054 :       _fluid_enthalpy[_qp][ph] = genericValue(_fsp[ph].enthalpy);
     112       42054 :       _fluid_internal_energy[_qp][ph] = genericValue(_fsp[ph].internal_energy);
     113             : 
     114      124310 :       for (unsigned int comp = 0; comp < _num_components; ++comp)
     115       82256 :         _mass_frac[_qp][ph][comp] = genericValue(_fsp[ph].mass_fraction[comp]);
     116             :     }
     117       31121 : }
     118             : 
     119             : template <bool is_ad>
     120             : void
     121     1134653 : PorousFlowFluidStateBaseMaterialTempl<is_ad>::computeQpProperties()
     122             : {
     123     1134653 :   _is_initqp = false;
     124             :   // Size pressure and saturation and prepare the derivative vectors
     125     1134653 :   PorousFlowVariableBaseTempl<is_ad>::computeQpProperties();
     126             : 
     127             :   // Set the size of all other vectors
     128     1134653 :   setMaterialVectorSize();
     129             : 
     130             :   // Calculate all required thermophysical properties
     131     1134653 :   thermophysicalProperties();
     132             : 
     133     3403569 :   for (unsigned int ph = 0; ph < _num_phases; ++ph)
     134             :   {
     135     2269046 :     _saturation[_qp][ph] = genericValue(_fsp[ph].saturation);
     136     2269046 :     _porepressure[_qp][ph] = genericValue(_fsp[ph].pressure);
     137     2269046 :     _fluid_density[_qp][ph] = genericValue(_fsp[ph].density);
     138     2269046 :     _fluid_viscosity[_qp][ph] = genericValue(_fsp[ph].viscosity);
     139     2269046 :     _fluid_enthalpy[_qp][ph] = genericValue(_fsp[ph].enthalpy);
     140     2269046 :     _fluid_internal_energy[_qp][ph] = genericValue(_fsp[ph].internal_energy);
     141             : 
     142     7156060 :     for (unsigned int comp = 0; comp < _num_components; ++comp)
     143     4887014 :       _mass_frac[_qp][ph][comp] = genericValue(_fsp[ph].mass_fraction[comp]);
     144             :   }
     145     1134523 : }
     146             : 
     147             : template <bool is_ad>
     148             : void
     149     1165774 : PorousFlowFluidStateBaseMaterialTempl<is_ad>::setMaterialVectorSize() const
     150             : {
     151     1165774 :   _fluid_density[_qp].resize(_num_phases, 0.0);
     152     1165774 :   _fluid_viscosity[_qp].resize(_num_phases, 0.0);
     153     1165774 :   _fluid_enthalpy[_qp].resize(_num_phases, 0.0);
     154     1165774 :   _fluid_internal_energy[_qp].resize(_num_phases, 0.0);
     155     1165774 :   _mass_frac[_qp].resize(_num_phases);
     156             : 
     157     3497322 :   for (unsigned int ph = 0; ph < _num_phases; ++ph)
     158     2331548 :     _mass_frac[_qp][ph].resize(_num_components);
     159             : 
     160             :   // Derivatives and gradients are not required in initQpStatefulProperties
     161     1165774 :   if (!_is_initqp)
     162             :   {
     163             :     // The gradient of the mass fractions are needed for qp materials and AD materials
     164      965792 :     if (!_nodal_material || is_ad)
     165             :     {
     166      650289 :       (*_grad_mass_frac_qp)[_qp].resize(_num_phases);
     167             : 
     168     1950867 :       for (unsigned int ph = 0; ph < _num_phases; ++ph)
     169     1300578 :         (*_grad_mass_frac_qp)[_qp][ph].assign(_num_components, RealGradient());
     170             :     }
     171             : 
     172             :     // No derivatives are required for AD materials
     173             :     if (!is_ad)
     174             :     {
     175      965792 :       (*_dfluid_density_dvar)[_qp].resize(_num_phases);
     176      965792 :       (*_dfluid_viscosity_dvar)[_qp].resize(_num_phases);
     177      965792 :       (*_dfluid_enthalpy_dvar)[_qp].resize(_num_phases);
     178      965792 :       (*_dfluid_internal_energy_dvar)[_qp].resize(_num_phases);
     179      965792 :       (*_dmass_frac_dvar)[_qp].resize(_num_phases);
     180             : 
     181     2897376 :       for (unsigned int ph = 0; ph < _num_phases; ++ph)
     182             :       {
     183     1931584 :         (*_dfluid_density_dvar)[_qp][ph].assign(_num_pf_vars, 0.0);
     184     1931584 :         (*_dfluid_viscosity_dvar)[_qp][ph].assign(_num_pf_vars, 0.0);
     185     1931584 :         (*_dfluid_enthalpy_dvar)[_qp][ph].assign(_num_pf_vars, 0.0);
     186     1931584 :         (*_dfluid_internal_energy_dvar)[_qp][ph].assign(_num_pf_vars, 0.0);
     187     1931584 :         (*_dmass_frac_dvar)[_qp][ph].resize(_num_components);
     188             : 
     189     6143920 :         for (unsigned int comp = 0; comp < _num_components; ++comp)
     190     4212336 :           (*_dmass_frac_dvar)[_qp][ph][comp].assign(_num_pf_vars, 0.0);
     191             :       }
     192             :     }
     193             :   }
     194     1165774 : }
     195             : 
     196             : template class PorousFlowFluidStateBaseMaterialTempl<false>;
     197             : template class PorousFlowFluidStateBaseMaterialTempl<true>;

Generated by: LCOV version 1.14