LCOV - code coverage report
Current view: top level - src/materials - PorousFlowJoiner.C (source / functions) Hit Total Coverage
Test: idaholab/moose porous_flow: #31405 (292dce) with base fef103 Lines: 72 73 98.6 %
Date: 2025-09-04 07:55: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      192142 : PorousFlowJoinerTempl<is_ad>::validParams()
      19             : {
      20      192142 :   InputParameters params = PorousFlowMaterialVectorBase::validParams();
      21      384284 :   params.addRequiredParam<std::string>("material_property",
      22             :                                        "The property that you want joined into a std::vector");
      23      192142 :   params.set<std::string>("pf_material_type") = "joiner";
      24      192142 :   params.addClassDescription("This Material forms a std::vector of properties, old properties "
      25             :                              "(optionally), and derivatives, out of the individual phase "
      26             :                              "properties");
      27      192142 :   return params;
      28           0 : }
      29             : 
      30             : template <bool is_ad>
      31      150537 : PorousFlowJoinerTempl<is_ad>::PorousFlowJoinerTempl(const InputParameters & parameters)
      32             :   : PorousFlowMaterialVectorBase(parameters),
      33      150537 :     _pf_prop(getParam<std::string>("material_property")),
      34      295677 :     _dporepressure_dvar(is_ad              ? nullptr
      35      145140 :                         : !_nodal_material ? &getMaterialProperty<std::vector<std::vector<Real>>>(
      36             :                                                  "dPorousFlow_porepressure_qp_dvar")
      37      301524 :                                            : &getMaterialProperty<std::vector<std::vector<Real>>>(
      38             :                                                  "dPorousFlow_porepressure_nodal_dvar")),
      39      295677 :     _dsaturation_dvar(is_ad              ? nullptr
      40      145140 :                       : !_nodal_material ? &getMaterialProperty<std::vector<std::vector<Real>>>(
      41             :                                                "dPorousFlow_saturation_qp_dvar")
      42      301524 :                                          : &getMaterialProperty<std::vector<std::vector<Real>>>(
      43             :                                                "dPorousFlow_saturation_nodal_dvar")),
      44      150537 :     _dtemperature_dvar(
      45      145140 :         is_ad ? nullptr
      46      145140 :         : !_nodal_material
      47       66948 :             ? &getMaterialProperty<std::vector<Real>>("dPorousFlow_temperature_qp_dvar")
      48      301524 :             : &getMaterialProperty<std::vector<Real>>("dPorousFlow_temperature_nodal_dvar")),
      49      301074 :     _has_mass_fraction(!_nodal_material
      50      150537 :                            ? hasGenericMaterialProperty<std::vector<std::vector<Real>>, is_ad>(
      51             :                                  "PorousFlow_mass_frac_qp")
      52      306921 :                            : hasGenericMaterialProperty<std::vector<std::vector<Real>>, is_ad>(
      53             :                                  "PorousFlow_mass_frac_nodal")),
      54      150537 :     _dmass_fraction_dvar(
      55      145140 :         is_ad ? nullptr
      56      145140 :         : _has_mass_fraction
      57      104388 :             ? (!_nodal_material ? &getMaterialProperty<std::vector<std::vector<std::vector<Real>>>>(
      58             :                                       "dPorousFlow_mass_frac_qp_dvar")
      59      295950 :                                 : &getMaterialProperty<std::vector<std::vector<std::vector<Real>>>>(
      60             :                                       "dPorousFlow_mass_frac_nodal_dvar"))
      61             :             : nullptr),
      62      150537 :     _property(declareGenericProperty<std::vector<Real>, is_ad>(_pf_prop)),
      63      150537 :     _dproperty_dvar(
      64             :         is_ad ? nullptr
      65      585957 :               : &declareProperty<std::vector<std::vector<Real>>>("d" + _pf_prop + "_dvar"))
      66             : {
      67      150537 :   _phase_property.resize(_num_phases);
      68             : 
      69             :   if (!is_ad)
      70             :   {
      71      145140 :     _dphase_property_dp.resize(_num_phases);
      72      145140 :     _dphase_property_ds.resize(_num_phases);
      73      145140 :     _dphase_property_dt.resize(_num_phases);
      74      145140 :     _dphase_property_dX.resize(_num_phases);
      75             :   }
      76             : 
      77      335676 :   for (unsigned int ph = 0; ph < _num_phases; ++ph)
      78             :   {
      79             :     const std::string phase = Moose::stringify(ph);
      80      185139 :     _phase_property[ph] = &getGenericMaterialProperty<Real, is_ad>(_pf_prop + phase);
      81             : 
      82             :     if (!is_ad)
      83             :     {
      84      178026 :       _dphase_property_dp[ph] =
      85      356052 :           &getMaterialPropertyDerivative<Real>(_pf_prop + phase, _pressure_variable_name);
      86      178026 :       _dphase_property_ds[ph] =
      87      356052 :           &getMaterialPropertyDerivative<Real>(_pf_prop + phase, _saturation_variable_name);
      88      178026 :       _dphase_property_dt[ph] =
      89      356052 :           &getMaterialPropertyDerivative<Real>(_pf_prop + phase, _temperature_variable_name);
      90      178026 :       _dphase_property_dX[ph] =
      91      356052 :           &getMaterialPropertyDerivative<Real>(_pf_prop + phase, _mass_fraction_variable_name);
      92             :     }
      93             :   }
      94      150537 : }
      95             : 
      96             : template <bool is_ad>
      97             : void
      98   325675954 : PorousFlowJoinerTempl<is_ad>::initQpStatefulProperties()
      99             : {
     100   325675954 :   _property[_qp].resize(_num_phases);
     101             : 
     102   671622858 :   for (unsigned int ph = 0; ph < _num_phases; ++ph)
     103   345946904 :     _property[_qp][ph] = (*_phase_property[ph])[_qp];
     104   325675954 : }
     105             : 
     106             : template <bool is_ad>
     107             : void
     108   311963327 : PorousFlowJoinerTempl<is_ad>::computeQpProperties()
     109             : {
     110   311963327 :   initQpStatefulProperties();
     111             : 
     112             :   if (!is_ad)
     113             :   {
     114   309027022 :     (*_dproperty_dvar)[_qp].resize(_num_phases);
     115   637555527 :     for (unsigned int ph = 0; ph < _num_phases; ++ph)
     116             :     {
     117   328528505 :       (*_dproperty_dvar)[_qp][ph].resize(_num_var);
     118   992280533 :       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   663752028 :         (*_dproperty_dvar)[_qp][ph][v] = 0.0;
     126   663752028 :         if ((*_dphase_property_dp[ph]).size() > _qp)
     127   662578718 :           (*_dproperty_dvar)[_qp][ph][v] +=
     128   662578718 :               (*_dphase_property_dp[ph])[_qp] * (*_dporepressure_dvar)[_qp][ph][v];
     129   663752028 :         if ((*_dphase_property_ds[ph]).size() > _qp)
     130   658340182 :           (*_dproperty_dvar)[_qp][ph][v] +=
     131   658340182 :               (*_dphase_property_ds[ph])[_qp] * (*_dsaturation_dvar)[_qp][ph][v];
     132   663752028 :         if ((*_dphase_property_dt[ph]).size() > _qp)
     133   662578718 :           (*_dproperty_dvar)[_qp][ph][v] +=
     134   662578718 :               (*_dphase_property_dt[ph])[_qp] * (*_dtemperature_dvar)[_qp][v];
     135             : 
     136             :         // Only add derivative wrt mass fraction if they exist
     137   663752028 :         if (_has_mass_fraction)
     138   406040884 :           if ((*_dphase_property_dX[ph]).size() > _qp)
     139   399458258 :             (*_dproperty_dvar)[_qp][ph][v] +=
     140   399458258 :                 (*_dphase_property_dX[ph])[_qp] * (*_dmass_fraction_dvar)[_qp][ph][0][v];
     141             :       }
     142             :     }
     143             :   }
     144   311963327 : }
     145             : 
     146             : template class PorousFlowJoinerTempl<false>;
     147             : template class PorousFlowJoinerTempl<true>;

Generated by: LCOV version 1.14