www.mooseframework.org
PorousFlowFluidMass.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 
8 #include "PorousFlowFluidMass.h"
9 
10 // MOOSE includes
11 #include "MooseVariable.h"
12 
13 #include "libmesh/quadrature.h"
14 
15 template <>
16 InputParameters
18 {
19  InputParameters params = validParams<ElementIntegralPostprocessor>();
20  params.addParam<unsigned int>(
21  "fluid_component",
22  0,
23  "The index corresponding to the fluid component that this Postprocessor acts on");
24  params.addRequiredParam<UserObjectName>(
25  "PorousFlowDictator", "The UserObject that holds the list of PorousFlow variable names.");
26  params.addParam<std::vector<unsigned int>>("phase",
27  "The index of the fluid phase that this "
28  "Postprocessor is restricted to. Multiple "
29  "indices can be entered");
30  params.addRangeCheckedParam<Real>("saturation_threshold",
31  1.0,
32  "saturation_threshold >= 0 & saturation_threshold <= 1",
33  "The saturation threshold below which the mass is calculated "
34  "for a specific phase. Default is 1.0. Note: only one "
35  "phase_index can be entered");
36  params.addParam<unsigned int>("kernel_variable_number",
37  0,
38  "The PorousFlow variable number (according to the dictator) of "
39  "the fluid-mass kernel. This is required only in the unusual "
40  "situation where a variety of different finite-element "
41  "interpolation schemes are employed in the simulation");
42  params.set<bool>("use_displaced_mesh") = true;
43  params.addClassDescription("Calculates the mass of a fluid component in a region");
44  return params;
45 }
46 
47 PorousFlowFluidMass::PorousFlowFluidMass(const InputParameters & parameters)
48  : ElementIntegralPostprocessor(parameters),
49 
50  _dictator(getUserObject<PorousFlowDictator>("PorousFlowDictator")),
51  _fluid_component(getParam<unsigned int>("fluid_component")),
52  _phase_index(getParam<std::vector<unsigned int>>("phase")),
53  _porosity(getMaterialProperty<Real>("PorousFlow_porosity_nodal")),
54  _fluid_density(getMaterialProperty<std::vector<Real>>("PorousFlow_fluid_phase_density_nodal")),
55  _fluid_saturation(getMaterialProperty<std::vector<Real>>("PorousFlow_saturation_nodal")),
56  _mass_fraction(
57  getMaterialProperty<std::vector<std::vector<Real>>>("PorousFlow_mass_frac_nodal")),
58  _saturation_threshold(getParam<Real>("saturation_threshold")),
59  _var(getParam<unsigned>("kernel_variable_number") < _dictator.numVariables()
60  ? _dictator.getCoupledMooseVars()[getParam<unsigned>("kernel_variable_number")]
61  : nullptr)
62 {
63  const unsigned int num_phases = _dictator.numPhases();
64  const unsigned int num_components = _dictator.numComponents();
65 
67  if (_fluid_component >= num_components)
68  mooseError("The Dictator proclaims that the number of components in this simulation is ",
69  num_components,
70  " whereas you have used the Postprocessor PorousFlowFluidMass with component = ",
72  ". The Dictator does not take such mistakes lightly.");
73 
75  if (_phase_index.size() > num_phases)
76  mooseError("The Dictator decrees that the number of phases in this simulation is ",
77  num_phases,
78  " but you have entered ",
79  _phase_index.size(),
80  " phases in the Postprocessor ",
81  _name);
82 
84  if (getParam<unsigned>("kernel_variable_number") >= _dictator.numVariables())
85  mooseError(
86  "PorousFlowFluidMass: The dictator pronounces that the number of porous-flow variables is ",
88  ", however you have used kernel_variable_number = ",
89  getParam<unsigned>("kernel_variable_number"),
90  ". This is an error");
91 
97  if (!_phase_index.empty())
98  {
99  unsigned int max_phase_num = *std::max_element(_phase_index.begin(), _phase_index.end());
100  if (max_phase_num > num_phases - 1)
101  mooseError("The Dictator proclaims that the phase index ",
102  max_phase_num,
103  " in the Postprocessor ",
104  _name,
105  " is greater than the largest phase index possible, which is ",
106  num_phases - 1);
107  }
108 
110  if (_saturation_threshold < 1.0 && _phase_index.size() != 1)
111  mooseError("A single phase_index must be entered when prescribing a saturation_threshold in "
112  "the Postprocessor ",
113  _name);
114 
116  if (_phase_index.empty())
117  for (unsigned int i = 0; i < num_phases; ++i)
118  _phase_index.push_back(i);
119 }
120 
121 Real
123 {
124  Real sum = 0;
125 
133  const VariableTestValue & test = _var->phi();
134 
135  for (unsigned node = 0; node < test.size(); ++node)
136  {
137  Real nodal_volume = 0.0;
138  for (_qp = 0; _qp < _qrule->n_points(); ++_qp)
139  nodal_volume += _JxW[_qp] * _coord[_qp] * test[node][_qp];
140 
141  Real mass = 0.0;
142  for (auto ph : _phase_index)
143  {
144  if (_fluid_saturation[node][ph] <= _saturation_threshold)
145  mass += _fluid_density[node][ph] * _fluid_saturation[node][ph] *
146  _mass_fraction[node][ph][_fluid_component];
147  }
148  sum += nodal_volume * _porosity[node] * mass;
149  }
150 
151  return sum;
152 }
153 
154 Real
156 {
157  return 0.0;
158 }
const MaterialProperty< std::vector< Real > > & _fluid_saturation
Phase saturation (-)
InputParameters validParams< PorousFlowFluidMass >()
unsigned int numComponents() const
the number of fluid components
PorousFlowFluidMass(const InputParameters &parameters)
std::vector< unsigned int > _phase_index
The phase indices that this Postprocessor is restricted to.
const Real _saturation_threshold
Saturation threshold - only fluid mass at saturations below this are calculated.
const MaterialProperty< Real > & _porosity
Porosity.
This holds maps between the nonlinear variables used in a PorousFlow simulation and the variable numb...
const PorousFlowDictator & _dictator
Holds info on the PorousFlow variables.
unsigned int numPhases() const
the number of fluid phases
const MaterialProperty< std::vector< Real > > & _fluid_density
Phase density (kg/m^3)
virtual Real computeIntegral() override
const unsigned int _fluid_component
The fluid component index that this Postprocessor applies to.
unsigned int numVariables() const
The number of PorousFlow variables.
MooseVariable *const _var
the variable for the corresponding PorousFlowMassTimeDerivative Kernel: this provides test functions ...
const MaterialProperty< std::vector< std::vector< Real > > > & _mass_fraction
Mass fraction of each fluid component in each phase.
virtual Real computeQpIntegral() override