www.mooseframework.org
PorousFlowMassVolumetricExpansion.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
3 /* */
4 /* All contents are licensed under LGPL V2.1 */
5 /* See LICENSE for full restrictions */
6 /****************************************************************/
7 
9 
10 // MOOSE includes
11 #include "MooseVariable.h"
12 
13 template <>
14 InputParameters
16 {
17  InputParameters params = validParams<TimeKernel>();
18  params.addParam<bool>("strain_at_nearest_qp",
19  false,
20  "When calculating nodal porosity that depends on strain, use the strain at "
21  "the nearest quadpoint. This adds a small extra computational burden, and "
22  "is not necessary for simulations involving only linear lagrange elements. "
23  " If you set this to true, you will also want to set the same parameter to "
24  "true for related Kernels and Materials");
25  params.addParam<unsigned int>(
26  "fluid_component", 0, "The index corresponding to the component for this kernel");
27  params.addRequiredParam<UserObjectName>(
28  "PorousFlowDictator", "The UserObject that holds the list of Porous-Flow variable names.");
29  params.addClassDescription("Component_mass*rate_of_solid_volumetric_expansion");
30  return params;
31 }
32 
34  const InputParameters & parameters)
35  : TimeKernel(parameters),
36  _fluid_component(getParam<unsigned int>("fluid_component")),
37  _dictator(getUserObject<PorousFlowDictator>("PorousFlowDictator")),
38  _var_is_porflow_var(!_dictator.notPorousFlowVariable(_var.number())),
39  _strain_at_nearest_qp(getParam<bool>("strain_at_nearest_qp")),
40  _porosity(getMaterialProperty<Real>("PorousFlow_porosity_nodal")),
41  _dporosity_dvar(getMaterialProperty<std::vector<Real>>("dPorousFlow_porosity_nodal_dvar")),
42  _dporosity_dgradvar(
43  getMaterialProperty<std::vector<RealGradient>>("dPorousFlow_porosity_nodal_dgradvar")),
44  _nearest_qp(_strain_at_nearest_qp
45  ? &getMaterialProperty<unsigned int>("PorousFlow_nearestqp_nodal")
46  : nullptr),
47  _fluid_density(getMaterialProperty<std::vector<Real>>("PorousFlow_fluid_phase_density_nodal")),
48  _dfluid_density_dvar(getMaterialProperty<std::vector<std::vector<Real>>>(
49  "dPorousFlow_fluid_phase_density_nodal_dvar")),
50  _fluid_saturation(getMaterialProperty<std::vector<Real>>("PorousFlow_saturation_nodal")),
51  _dfluid_saturation_dvar(
52  getMaterialProperty<std::vector<std::vector<Real>>>("dPorousFlow_saturation_nodal_dvar")),
53  _mass_frac(getMaterialProperty<std::vector<std::vector<Real>>>("PorousFlow_mass_frac_nodal")),
54  _dmass_frac_dvar(getMaterialProperty<std::vector<std::vector<std::vector<Real>>>>(
55  "dPorousFlow_mass_frac_nodal_dvar")),
56  _strain_rate_qp(getMaterialProperty<Real>("PorousFlow_volumetric_strain_rate_qp")),
57  _dstrain_rate_qp_dvar(getMaterialProperty<std::vector<RealGradient>>(
58  "dPorousFlow_volumetric_strain_rate_qp_dvar"))
59 {
61  mooseError("The Dictator proclaims that the number of components in this simulation is ",
63  " whereas you have used the Kernel PorousFlowComponetMassVolumetricExpansion with "
64  "component = ",
66  ". The Dictator is watching you");
67 }
68 
69 Real
71 {
72  mooseAssert(_fluid_component < _mass_frac[_i][0].size(),
73  "PorousFlowMassVolumetricExpansion: fluid_component is given as "
75  << " which must be less than the number of fluid components described by the "
76  "mass-fraction matrix, which is "
77  << _mass_frac[_i][0].size());
78  unsigned int num_phases = _fluid_density[_i].size();
79  mooseAssert(num_phases == _fluid_saturation[_i].size(),
80  "PorousFlowMassVolumetricExpansion: Size of fluid density = "
81  << num_phases
82  << " size of fluid saturation = "
83  << _fluid_saturation[_i].size()
84  << " but both these must be equal to the number of phases in the system");
85 
86  Real mass = 0.0;
87  for (unsigned ph = 0; ph < num_phases; ++ph)
88  mass +=
89  _fluid_density[_i][ph] * _fluid_saturation[_i][ph] * _mass_frac[_i][ph][_fluid_component];
90 
91  return _test[_i][_qp] * mass * _porosity[_i] * _strain_rate_qp[_qp];
92 }
93 
94 Real
96 {
97  return computedMassQpJac(_var.number()) + computedVolQpJac(_var.number());
98 }
99 
100 Real
102 {
103  return computedMassQpJac(jvar) + computedVolQpJac(jvar);
104 }
105 
106 Real
108 {
110  return 0.0;
111 
112  const unsigned int pvar = _dictator.porousFlowVariableNum(jvar);
113 
114  unsigned int num_phases = _fluid_density[_i].size();
115  Real mass = 0.0;
116  for (unsigned ph = 0; ph < num_phases; ++ph)
117  mass +=
118  _fluid_density[_i][ph] * _fluid_saturation[_i][ph] * _mass_frac[_i][ph][_fluid_component];
119 
120  Real dvol = _dstrain_rate_qp_dvar[_qp][pvar] * _grad_phi[_j][_qp];
121 
122  return _test[_i][_qp] * mass * _porosity[_i] * dvol;
123 }
124 Real
126 {
128  return 0.0;
129 
130  const unsigned int pvar = _dictator.porousFlowVariableNum(jvar);
131  const unsigned nearest_qp = (_strain_at_nearest_qp ? (*_nearest_qp)[_i] : _i);
132 
133  const unsigned int num_phases = _fluid_density[_i].size();
134  Real dmass = 0.0;
135  for (unsigned ph = 0; ph < num_phases; ++ph)
136  dmass += _fluid_density[_i][ph] * _fluid_saturation[_i][ph] *
137  _mass_frac[_i][ph][_fluid_component] * _dporosity_dgradvar[_i][pvar] *
138  _grad_phi[_j][nearest_qp];
139 
140  if (_i != _j)
141  return _test[_i][_qp] * dmass * _strain_rate_qp[_qp];
142 
143  for (unsigned ph = 0; ph < num_phases; ++ph)
144  {
145  dmass += _dfluid_density_dvar[_i][ph][pvar] * _fluid_saturation[_i][ph] *
146  _mass_frac[_i][ph][_fluid_component] * _porosity[_i];
147  dmass += _fluid_density[_i][ph] * _dfluid_saturation_dvar[_i][ph][pvar] *
148  _mass_frac[_i][ph][_fluid_component] * _porosity[_i];
149  dmass += _fluid_density[_i][ph] * _fluid_saturation[_i][ph] *
150  _dmass_frac_dvar[_i][ph][_fluid_component][pvar] * _porosity[_i];
151  dmass += _fluid_density[_i][ph] * _fluid_saturation[_i][ph] *
152  _mass_frac[_i][ph][_fluid_component] * _dporosity_dvar[_i][pvar];
153  }
154 
155  return _test[_i][_qp] * dmass * _strain_rate_qp[_qp];
156 }
const MaterialProperty< std::vector< std::vector< Real > > > & _mass_frac
mass fraction
InputParameters validParams< PorousFlowMassVolumetricExpansion >()
const MaterialProperty< std::vector< std::vector< Real > > > & _dfluid_saturation_dvar
d(fluid saturation)/d(porous-flow variable)
PorousFlowMassVolumetricExpansion(const InputParameters &parameters)
const MaterialProperty< std::vector< Real > > & _dporosity_dvar
d(porosity)/d(porous-flow variable)
const MaterialProperty< Real > & _porosity
porosity
const unsigned int _fluid_component
the fluid component index
const MaterialProperty< std::vector< std::vector< std::vector< Real > > > > & _dmass_frac_dvar
d(mass fraction)/d(porous-flow variable)
const MaterialProperty< std::vector< Real > > & _fluid_saturation
fluid saturation
unsigned int numComponents() const
the number of fluid components
const PorousFlowDictator & _dictator
holds info on the Porous Flow variables
const MaterialProperty< std::vector< Real > > & _fluid_density
fluid density
const MaterialProperty< std::vector< RealGradient > > & _dstrain_rate_qp_dvar
d(strain rate)/d(porous-flow variable)
virtual Real computeQpOffDiagJacobian(unsigned int jvar) override
Real computedMassQpJac(unsigned int jvar) const
Derivative of mass part of the residual with respect to the Variable with variable number jvar...
This holds maps between the nonlinear variables used in a PorousFlow simulation and the variable numb...
const MaterialProperty< Real > & _strain_rate_qp
strain rate
Real computedVolQpJac(unsigned int jvar) const
Derivative of volumetric-strain part of the residual with respect to the Variable with variable numbe...
const MaterialProperty< std::vector< std::vector< Real > > > & _dfluid_density_dvar
d(fluid density)/d(porous-flow variable)
const MaterialProperty< std::vector< RealGradient > > & _dporosity_dgradvar
d(porosity)/d(grad porous-flow variable)
bool notPorousFlowVariable(unsigned int moose_var_num) const
returns true if moose_var_num is not a porous flow variabe
unsigned int porousFlowVariableNum(unsigned int moose_var_num) const
the PorousFlow variable number
const bool _strain_at_nearest_qp
whether the porosity uses the volumetric strain at the closest quadpoint