LCOV - code coverage report
Current view: top level - src/materials - PorousFlowJoiner.C (source / functions) Hit Total Coverage
Test: idaholab/moose porous_flow: #32971 (54bef8) with base c6cf66 Lines: 72 73 98.6 %
Date: 2026-05-29 20:38:56 Functions: 8 8 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 "PorousFlowJoiner.h"
      11             : #include "Conversion.h"
      12             : 
      13             : registerMooseObject("PorousFlowApp", PorousFlowJoiner);
      14             : registerMooseObject("PorousFlowApp", ADPorousFlowJoiner);
      15             : 
      16             : template <bool is_ad>
      17             : InputParameters
      18       95338 : PorousFlowJoinerTempl<is_ad>::validParams()
      19             : {
      20       95338 :   InputParameters params = PorousFlowMaterialVectorBase::validParams();
      21      190676 :   params.addRequiredParam<std::string>("material_property",
      22             :                                        "The property that you want joined into a std::vector");
      23       95338 :   params.set<std::string>("pf_material_type") = "joiner";
      24       95338 :   params.addClassDescription("This Material forms a std::vector of properties, old properties "
      25             :                              "(optionally), and derivatives, out of the individual phase "
      26             :                              "properties");
      27       95338 :   return params;
      28           0 : }
      29             : 
      30             : template <bool is_ad>
      31       74019 : PorousFlowJoinerTempl<is_ad>::PorousFlowJoinerTempl(const InputParameters & parameters)
      32             :   : PorousFlowMaterialVectorBase(parameters),
      33       74019 :     _pf_prop(getParam<std::string>("material_property")),
      34      145497 :     _dporepressure_dvar(is_ad              ? nullptr
      35       71478 :                         : !_nodal_material ? &getMaterialProperty<std::vector<std::vector<Real>>>(
      36             :                                                  "dPorousFlow_porepressure_qp_dvar")
      37      149526 :                                            : &getMaterialProperty<std::vector<std::vector<Real>>>(
      38             :                                                  "dPorousFlow_porepressure_nodal_dvar")),
      39      145497 :     _dsaturation_dvar(is_ad              ? nullptr
      40       71478 :                       : !_nodal_material ? &getMaterialProperty<std::vector<std::vector<Real>>>(
      41             :                                                "dPorousFlow_saturation_qp_dvar")
      42      149526 :                                          : &getMaterialProperty<std::vector<std::vector<Real>>>(
      43             :                                                "dPorousFlow_saturation_nodal_dvar")),
      44       74019 :     _dtemperature_dvar(
      45       71478 :         is_ad ? nullptr
      46       71478 :         : !_nodal_material
      47       32454 :             ? &getMaterialProperty<std::vector<Real>>("dPorousFlow_temperature_qp_dvar")
      48      149526 :             : &getMaterialProperty<std::vector<Real>>("dPorousFlow_temperature_nodal_dvar")),
      49      148038 :     _has_mass_fraction(!_nodal_material
      50       74019 :                            ? hasGenericMaterialProperty<std::vector<std::vector<Real>>, is_ad>(
      51             :                                  "PorousFlow_mass_frac_qp")
      52      152067 :                            : hasGenericMaterialProperty<std::vector<std::vector<Real>>, is_ad>(
      53             :                                  "PorousFlow_mass_frac_nodal")),
      54       74019 :     _dmass_fraction_dvar(
      55       71478 :         is_ad ? nullptr
      56       71478 :         : _has_mass_fraction
      57       51210 :             ? (!_nodal_material ? &getMaterialProperty<std::vector<std::vector<std::vector<Real>>>>(
      58             :                                       "dPorousFlow_mass_frac_qp_dvar")
      59      146112 :                                 : &getMaterialProperty<std::vector<std::vector<std::vector<Real>>>>(
      60             :                                       "dPorousFlow_mass_frac_nodal_dvar"))
      61             :             : nullptr),
      62       74019 :     _property(declareGenericProperty<std::vector<Real>, is_ad>(_pf_prop)),
      63       74019 :     _dproperty_dvar(
      64             :         is_ad ? nullptr
      65      288453 :               : &declareProperty<std::vector<std::vector<Real>>>("d" + _pf_prop + "_dvar"))
      66             : {
      67       74019 :   _phase_property.resize(_num_phases);
      68             : 
      69             :   if (!is_ad)
      70             :   {
      71       71478 :     _dphase_property_dp.resize(_num_phases);
      72       71478 :     _dphase_property_ds.resize(_num_phases);
      73       71478 :     _dphase_property_dt.resize(_num_phases);
      74       71478 :     _dphase_property_dX.resize(_num_phases);
      75             :   }
      76             : 
      77      165498 :   for (unsigned int ph = 0; ph < _num_phases; ++ph)
      78             :   {
      79             :     const std::string phase = Moose::stringify(ph);
      80       91479 :     _phase_property[ph] = &getGenericMaterialProperty<Real, is_ad>(_pf_prop + phase);
      81             : 
      82             :     if (!is_ad)
      83             :     {
      84       88158 :       _dphase_property_dp[ph] =
      85      176316 :           &getMaterialPropertyDerivative<Real>(_pf_prop + phase, _pressure_variable_name);
      86       88158 :       _dphase_property_ds[ph] =
      87      176316 :           &getMaterialPropertyDerivative<Real>(_pf_prop + phase, _saturation_variable_name);
      88       88158 :       _dphase_property_dt[ph] =
      89      176316 :           &getMaterialPropertyDerivative<Real>(_pf_prop + phase, _temperature_variable_name);
      90       88158 :       _dphase_property_dX[ph] =
      91      176316 :           &getMaterialPropertyDerivative<Real>(_pf_prop + phase, _mass_fraction_variable_name);
      92             :     }
      93             :   }
      94       74019 : }
      95             : 
      96             : template <bool is_ad>
      97             : void
      98   220620339 : PorousFlowJoinerTempl<is_ad>::initQpStatefulProperties()
      99             : {
     100   220620339 :   _property[_qp].resize(_num_phases);
     101             : 
     102   455192526 :   for (unsigned int ph = 0; ph < _num_phases; ++ph)
     103   234572187 :     _property[_qp][ph] = (*_phase_property[ph])[_qp];
     104   220620339 : }
     105             : 
     106             : template <bool is_ad>
     107             : void
     108   212068731 : PorousFlowJoinerTempl<is_ad>::computeQpProperties()
     109             : {
     110   212068731 :   initQpStatefulProperties();
     111             : 
     112             :   if (!is_ad)
     113             :   {
     114   210105140 :     (*_dproperty_dvar)[_qp].resize(_num_phases);
     115   433649590 :     for (unsigned int ph = 0; ph < _num_phases; ++ph)
     116             :     {
     117   223544450 :       (*_dproperty_dvar)[_qp][ph].resize(_num_var);
     118   672059017 :       for (unsigned v = 0; v < _num_var; ++v)
     119             :       {
     120             :         // the "if" conditions in the following are because a nodal_material's derivatives might
     121             :         // not have been defined.  If that is the case, then DerivativeMaterial passes back a
     122             :         // MaterialProperty with zeroes (for the derivatives), but that property will be sized
     123             :         // by the number of quadpoints in the element, which may be smaller than the number of
     124             :         // nodes!
     125   448514567 :         (*_dproperty_dvar)[_qp][ph][v] = 0.0;
     126   448514567 :         if ((*_dphase_property_dp[ph]).size() > _qp)
     127   447718998 :           (*_dproperty_dvar)[_qp][ph][v] +=
     128   447718998 :               (*_dphase_property_dp[ph])[_qp] * (*_dporepressure_dvar)[_qp][ph][v];
     129   448514567 :         if ((*_dphase_property_ds[ph]).size() > _qp)
     130   444846573 :           (*_dproperty_dvar)[_qp][ph][v] +=
     131   444846573 :               (*_dphase_property_ds[ph])[_qp] * (*_dsaturation_dvar)[_qp][ph][v];
     132   448514567 :         if ((*_dphase_property_dt[ph]).size() > _qp)
     133   447718998 :           (*_dproperty_dvar)[_qp][ph][v] +=
     134   447718998 :               (*_dphase_property_dt[ph])[_qp] * (*_dtemperature_dvar)[_qp][v];
     135             : 
     136             :         // Only add derivative wrt mass fraction if they exist
     137   448514567 :         if (_has_mass_fraction)
     138   276062680 :           if ((*_dphase_property_dX[ph]).size() > _qp)
     139   271601141 :             (*_dproperty_dvar)[_qp][ph][v] +=
     140   271601141 :                 (*_dphase_property_dX[ph])[_qp] * (*_dmass_fraction_dvar)[_qp][ph][0][v];
     141             :       }
     142             :     }
     143             :   }
     144   212068731 : }
     145             : 
     146             : template class PorousFlowJoinerTempl<false>;
     147             : template class PorousFlowJoinerTempl<true>;

Generated by: LCOV version 1.14