www.mooseframework.org
PorousFlowJoiner.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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>
19 {
21  params.addRequiredParam<std::string>("material_property",
22  "The property that you want joined into a std::vector");
23  params.set<std::string>("pf_material_type") = "joiner";
24  params.addClassDescription("This Material forms a std::vector of properties, old properties "
25  "(optionally), and derivatives, out of the individual phase "
26  "properties");
27  return params;
28 }
29 
30 template <bool is_ad>
32  : PorousFlowMaterialVectorBase(parameters),
33  _pf_prop(getParam<std::string>("material_property")),
34  _dporepressure_dvar(is_ad ? nullptr
35  : !_nodal_material ? &getMaterialProperty<std::vector<std::vector<Real>>>(
36  "dPorousFlow_porepressure_qp_dvar")
37  : &getMaterialProperty<std::vector<std::vector<Real>>>(
38  "dPorousFlow_porepressure_nodal_dvar")),
39  _dsaturation_dvar(is_ad ? nullptr
40  : !_nodal_material ? &getMaterialProperty<std::vector<std::vector<Real>>>(
41  "dPorousFlow_saturation_qp_dvar")
42  : &getMaterialProperty<std::vector<std::vector<Real>>>(
43  "dPorousFlow_saturation_nodal_dvar")),
44  _dtemperature_dvar(
45  is_ad ? nullptr
46  : !_nodal_material
47  ? &getMaterialProperty<std::vector<Real>>("dPorousFlow_temperature_qp_dvar")
48  : &getMaterialProperty<std::vector<Real>>("dPorousFlow_temperature_nodal_dvar")),
49  _has_mass_fraction(!_nodal_material
50  ? hasGenericMaterialProperty<std::vector<std::vector<Real>>, is_ad>(
51  "PorousFlow_mass_frac_qp")
52  : hasGenericMaterialProperty<std::vector<std::vector<Real>>, is_ad>(
53  "PorousFlow_mass_frac_nodal")),
54  _dmass_fraction_dvar(
55  is_ad ? nullptr
56  : _has_mass_fraction
57  ? (!_nodal_material ? &getMaterialProperty<std::vector<std::vector<std::vector<Real>>>>(
58  "dPorousFlow_mass_frac_qp_dvar")
59  : &getMaterialProperty<std::vector<std::vector<std::vector<Real>>>>(
60  "dPorousFlow_mass_frac_nodal_dvar"))
61  : nullptr),
62  _property(declareGenericProperty<std::vector<Real>, is_ad>(_pf_prop)),
63  _dproperty_dvar(
64  is_ad ? nullptr
65  : &declareProperty<std::vector<std::vector<Real>>>("d" + _pf_prop + "_dvar"))
66 {
68 
69  if (!is_ad)
70  {
75  }
76 
77  for (unsigned int ph = 0; ph < _num_phases; ++ph)
78  {
79  const std::string phase = Moose::stringify(ph);
80  _phase_property[ph] = &getGenericMaterialProperty<Real, is_ad>(_pf_prop + phase);
81 
82  if (!is_ad)
83  {
85  &getMaterialPropertyDerivative<Real>(_pf_prop + phase, _pressure_variable_name);
87  &getMaterialPropertyDerivative<Real>(_pf_prop + phase, _saturation_variable_name);
89  &getMaterialPropertyDerivative<Real>(_pf_prop + phase, _temperature_variable_name);
91  &getMaterialPropertyDerivative<Real>(_pf_prop + phase, _mass_fraction_variable_name);
92  }
93  }
94 }
95 
96 template <bool is_ad>
97 void
99 {
100  _property[_qp].resize(_num_phases);
101 
102  for (unsigned int ph = 0; ph < _num_phases; ++ph)
103  _property[_qp][ph] = (*_phase_property[ph])[_qp];
104 }
105 
106 template <bool is_ad>
107 void
109 {
110  initQpStatefulProperties();
111 
112  if (!is_ad)
113  {
114  (*_dproperty_dvar)[_qp].resize(_num_phases);
115  for (unsigned int ph = 0; ph < _num_phases; ++ph)
116  {
117  (*_dproperty_dvar)[_qp][ph].resize(_num_var);
118  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  (*_dproperty_dvar)[_qp][ph][v] = 0.0;
126  if ((*_dphase_property_dp[ph]).size() > _qp)
127  (*_dproperty_dvar)[_qp][ph][v] +=
128  (*_dphase_property_dp[ph])[_qp] * (*_dporepressure_dvar)[_qp][ph][v];
129  if ((*_dphase_property_ds[ph]).size() > _qp)
130  (*_dproperty_dvar)[_qp][ph][v] +=
131  (*_dphase_property_ds[ph])[_qp] * (*_dsaturation_dvar)[_qp][ph][v];
132  if ((*_dphase_property_dt[ph]).size() > _qp)
133  (*_dproperty_dvar)[_qp][ph][v] +=
134  (*_dphase_property_dt[ph])[_qp] * (*_dtemperature_dvar)[_qp][v];
135 
136  // Only add derivative wrt mass fraction if they exist
137  if (_has_mass_fraction)
138  if ((*_dphase_property_dX[ph]).size() > _qp)
139  (*_dproperty_dvar)[_qp][ph][v] +=
140  (*_dphase_property_dX[ph])[_qp] * (*_dmass_fraction_dvar)[_qp][ph][0][v];
141  }
142  }
143  }
144 }
145 
146 template class PorousFlowJoinerTempl<false>;
147 template class PorousFlowJoinerTempl<true>;
const unsigned int _num_phases
Number of phases.
std::vector< const MaterialProperty< Real > * > _dphase_property_ds
d(property of each phase)/d(saturation)
const std::string _pf_prop
Name of material property to be joined.
std::vector< const MaterialProperty< Real > * > _dphase_property_dp
d(property of each phase)/d(pressure)
T & set(const std::string &name, bool quiet_mode=false)
void addRequiredParam(const std::string &name, const std::string &doc_string)
std::vector< const MaterialProperty< Real > * > _dphase_property_dt
d(property of each phase)/d(temperature)
virtual void initQpStatefulProperties() override
std::vector< const GenericMaterialProperty< Real, is_ad > * > _phase_property
Property of each phase.
Base class for all PorousFlow vector materials.
std::vector< const MaterialProperty< Real > * > _dphase_property_dX
d(property of each phase)/d(mass fraction)
PorousFlowJoinerTempl(const InputParameters &parameters)
std::string stringify(const T &t)
virtual void computeQpProperties() override
Material designed to form a std::vector of property and derivatives of these wrt the nonlinear variab...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
static const std::string v
Definition: NS.h:82
static InputParameters validParams()
void addClassDescription(const std::string &doc_string)
registerMooseObject("PorousFlowApp", PorousFlowJoiner)