www.mooseframework.org
PorousFlowHeatEnergy.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 "PorousFlowHeatEnergy.h"
11 
12 #include "MooseVariable.h"
13 
14 #include "libmesh/quadrature.h"
15 
17 
18 template <>
19 InputParameters
21 {
22  InputParameters params = validParams<ElementIntegralPostprocessor>();
23  params.addRequiredParam<UserObjectName>(
24  "PorousFlowDictator", "The UserObject that holds the list of PorousFlow variable names.");
25  params.addParam<bool>(
26  "include_porous_skeleton", true, "Include the heat energy of the porous skeleton");
27  params.addParam<std::vector<unsigned int>>("phase",
28  "The index(es) of the fluid phase that this "
29  "Postprocessor is restricted to. Multiple "
30  "indices can be entered.");
31  params.set<bool>("use_displaced_mesh") = true;
32  params.addParam<unsigned int>("kernel_variable_number",
33  0,
34  "The PorousFlow variable number (according to the dictatory) of "
35  "the heat-energy kernel. This is required only in the unusual "
36  "situation where a variety of different finite-element "
37  "interpolation schemes are employed in the simulation");
38  params.addClassDescription("Calculates the sum of heat energy of fluid phase(s) and/or the "
39  "porous skeleton in a region");
40  return params;
41 }
42 
43 PorousFlowHeatEnergy::PorousFlowHeatEnergy(const InputParameters & parameters)
44  : ElementIntegralPostprocessor(parameters),
45  _dictator(getUserObject<PorousFlowDictator>("PorousFlowDictator")),
46  _num_phases(_dictator.numPhases()),
47  _fluid_present(_num_phases > 0),
48  _include_porous_skeleton(getParam<bool>("include_porous_skeleton")),
49  _phase_index(getParam<std::vector<unsigned int>>("phase")),
50  _porosity(getMaterialProperty<Real>("PorousFlow_porosity_nodal")),
51  _rock_energy_nodal(getMaterialProperty<Real>("PorousFlow_matrix_internal_energy_nodal")),
52  _fluid_density(_fluid_present ? &getMaterialProperty<std::vector<Real>>(
53  "PorousFlow_fluid_phase_density_nodal")
54  : nullptr),
55  _fluid_saturation_nodal(
56  _fluid_present ? &getMaterialProperty<std::vector<Real>>("PorousFlow_saturation_nodal")
57  : nullptr),
58  _energy_nodal(_fluid_present ? &getMaterialProperty<std::vector<Real>>(
59  "PorousFlow_fluid_phase_internal_energy_nodal")
60  : nullptr),
61  _var(getParam<unsigned>("kernel_variable_number") < _dictator.numVariables()
62  ? &_fe_problem.getStandardVariable(
63  _tid,
64  _dictator
65  .getCoupledStandardMooseVars()[getParam<unsigned>("kernel_variable_number")]
66  ->name())
67  : nullptr)
68 {
69  if (!_phase_index.empty())
70  {
71  // Check that the phase indices entered are not greater than the number of phases
72  const unsigned int max_phase_num = *std::max_element(_phase_index.begin(), _phase_index.end());
73  if (max_phase_num > _num_phases - 1)
74  paramError("phase",
75  "The Dictator proclaims that the phase index ",
76  max_phase_num,
77  " is greater than the largest phase index possible, which is ",
78  _num_phases - 1);
79  }
80 
81  // Check that kernel_variable_number is OK
82  if (getParam<unsigned>("kernel_variable_number") >= _dictator.numVariables())
83  paramError("kernel_variable_number",
84  "The Dictator pronounces that the number of PorousFlow variables is ",
86  ", however you have used ",
87  getParam<unsigned>("kernel_variable_number"),
88  ". This is an error");
89 
90  // Now that we know kernel_variable_number is OK, _var must be OK,
91  // so ensure that reinit is called on _var:
92  addMooseVariableDependency(_var);
93 }
94 
95 Real
97 {
98  Real sum = 0;
99 
100  // The use of _test in the loops below mean that the
101  // integral is exactly the same as the one computed
102  // by the PorousFlowMassTimeDerivative Kernel. Because that
103  // Kernel is lumped, this Postprocessor also needs to
104  // be lumped. Hence the use of the "nodal" Material
105  // Properties
106  const VariableTestValue & test = _var->phi();
107 
108  for (unsigned node = 0; node < test.size(); ++node)
109  {
110  Real nodal_volume = 0.0;
111  for (_qp = 0; _qp < _qrule->n_points(); ++_qp)
112  nodal_volume += _JxW[_qp] * _coord[_qp] * test[node][_qp];
113 
114  Real energy = 0.0;
116  energy += (1.0 - _porosity[node]) * _rock_energy_nodal[node];
117 
118  for (auto ph : _phase_index)
119  energy += (*_fluid_density)[node][ph] * (*_fluid_saturation_nodal)[node][ph] *
120  (*_energy_nodal)[node][ph] * _porosity[node];
121 
122  sum += nodal_volume * energy;
123  }
124 
125  return sum;
126 }
127 
128 Real
130 {
131  return 0.0;
132 }
PorousFlowHeatEnergy
Postprocessor produces the sum of heat energy of the porous skeleton and/or fluid components in a reg...
Definition: PorousFlowHeatEnergy.h:24
PorousFlowHeatEnergy::PorousFlowHeatEnergy
PorousFlowHeatEnergy(const InputParameters &parameters)
Definition: PorousFlowHeatEnergy.C:43
PorousFlowHeatEnergy::_var
MooseVariable *const _var
The variable for the corresponding PorousFlowEnergyTimeDerivative Kernel: this provides test function...
Definition: PorousFlowHeatEnergy.h:64
PorousFlowHeatEnergy::_phase_index
std::vector< unsigned int > _phase_index
The phase indices that this Postprocessor is restricted to.
Definition: PorousFlowHeatEnergy.h:46
registerMooseObject
registerMooseObject("PorousFlowApp", PorousFlowHeatEnergy)
PorousFlowHeatEnergy::_dictator
const PorousFlowDictator & _dictator
PorousFlowDictator UserObject.
Definition: PorousFlowHeatEnergy.h:34
PorousFlowHeatEnergy::_num_phases
const unsigned int _num_phases
Number of fluid phases.
Definition: PorousFlowHeatEnergy.h:37
PorousFlowHeatEnergy::_include_porous_skeleton
const bool _include_porous_skeleton
Whether to include the heat energy of the porous skeleton in the calculations.
Definition: PorousFlowHeatEnergy.h:43
PorousFlowHeatEnergy::computeQpIntegral
virtual Real computeQpIntegral() override
Definition: PorousFlowHeatEnergy.C:129
PorousFlowHeatEnergy::_porosity
const MaterialProperty< Real > & _porosity
Porosity.
Definition: PorousFlowHeatEnergy.h:49
PorousFlowDictator
This holds maps between the nonlinear variables used in a PorousFlow simulation and the variable numb...
Definition: PorousFlowDictator.h:71
PorousFlowDictator::numVariables
unsigned int numVariables() const
The number of PorousFlow variables.
Definition: PorousFlowDictator.C:99
PorousFlowHeatEnergy::computeIntegral
virtual Real computeIntegral() override
Definition: PorousFlowHeatEnergy.C:96
name
const std::string name
Definition: Setup.h:21
PorousFlowHeatEnergy::_rock_energy_nodal
const MaterialProperty< Real > & _rock_energy_nodal
Nodal rock energy density.
Definition: PorousFlowHeatEnergy.h:52
PorousFlowHeatEnergy.h
validParams< PorousFlowHeatEnergy >
InputParameters validParams< PorousFlowHeatEnergy >()
Definition: PorousFlowHeatEnergy.C:20