https://mooseframework.inl.gov
Loading...
Searching...
No Matches
PorousFlowDictator.C
Go to the documentation of this file.
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 "PorousFlowDictator.h"
11#include "Conversion.h"
12#include "NonlinearSystem.h"
13
14#include "libmesh/enum_to_string.h"
15
17
20{
22 params.addClassDescription("Holds information on the PorousFlow variable names");
23 params.addRequiredCoupledVar("porous_flow_vars",
24 "List of primary variables that are used in the PorousFlow "
25 "simulation. Jacobian entries involving derivatives wrt these "
26 "variables will be computed. In single-phase models you will just "
27 "have one (eg \'pressure\'), in two-phase models you will have two "
28 "(eg \'p_water p_gas\', or \'p_water s_water\'), etc.");
29 params.addRequiredParam<unsigned int>("number_fluid_phases",
30 "The number of fluid phases in the simulation");
31 params.addRequiredParam<unsigned int>("number_fluid_components",
32 "The number of fluid components in the simulation");
33 params.addParam<unsigned int>("number_aqueous_equilibrium",
34 0,
35 "The number of secondary species in the aqueous-equilibrium "
36 "reaction system. (Leave as zero if the simulation does not "
37 "involve chemistry)");
38 params.addParam<unsigned int>("number_aqueous_kinetic",
39 0,
40 "The number of secondary species in the aqueous-kinetic reaction "
41 "system involved in precipitation and dissolution. (Leave as zero "
42 "if the simulation does not involve chemistry)");
43 params.addParam<unsigned int>("aqueous_phase_number",
44 0,
45 "The fluid phase number of the aqueous phase in which the "
46 "equilibrium and kinetic chemical reactions occur");
47
48 params.addParam<SolverSystemName>("solver_sys", "Name of the solver system for the porepressure");
49 params.addParamNamesToGroup("solver_sys", "Advanced");
50 return params;
51}
52
54 : GeneralUserObject(parameters),
55 Coupleable(this, false),
56 _num_variables(coupledComponents("porous_flow_vars")),
57 _num_phases(getParam<unsigned int>("number_fluid_phases")),
58 _num_components(getParam<unsigned int>("number_fluid_components")),
59 _num_aqueous_equilibrium(getParam<unsigned int>("number_aqueous_equilibrium")),
60 _num_aqueous_kinetic(getParam<unsigned int>("number_aqueous_kinetic")),
61 _aqueous_phase_number(getParam<unsigned int>("aqueous_phase_number")),
62 _consistent_fe_type(false),
63 _fe_type(0),
64 _is_fv(false)
65{
67 for (unsigned int i = 0; i < _num_variables; ++i)
68 _moose_var_num[i] = coupled("porous_flow_vars", i);
69
70 if (_num_variables > 0)
71 {
73 _is_fv = getFieldVar("porous_flow_vars", 0)->isFV();
74 _fe_type = FEType(getFieldVar("porous_flow_vars", 0)->feType());
75 for (unsigned int i = 1; i < _num_variables; ++i)
76 if (getFieldVar("porous_flow_vars", i)->feType() != _fe_type)
77 _consistent_fe_type = false;
78 }
79
81 _num_variables); // Note: the _num_variables assignment indicates that "this is
82 // not a PorousFlow variable"
83 for (unsigned int i = 0; i < _num_variables; ++i)
84 {
85 if (_moose_var_num[i] < _pf_var_num.size())
87 else
88 // should not couple AuxVariables to the Dictator (Jacobian entries are not calculated for
89 // them)
90 mooseError("PorousFlowDictator: AuxVariables variables must not be coupled into the Dictator "
91 "for this is against specification #1984. Variable '",
92 coupledName("porous_flow_vars", /*comp=*/i),
93 "' is either an AuxVariable or from a different nonlinear system.");
94 }
95
97 mooseError("PorousflowDictator: The aqueous phase number must be less than the number of fluid "
98 "phases. The Dictator does not appreciate jokes.");
99
100 // Don't include permeabiity derivatives in the Jacobian by default (overwrite using
101 // usePermDerivs()) when necessary in permeabiity material classes
102 _perm_derivs = false;
103}
104
105unsigned int
110
111unsigned int
113{
114 return _num_phases;
115}
116
117unsigned int
122
123unsigned int
128
129unsigned int
134
135unsigned int
140
141unsigned int
142PorousFlowDictator::porousFlowVariableNum(unsigned int moose_var_num) const
143{
144 if (moose_var_num >= _pf_var_num.size() || _pf_var_num[moose_var_num] == _num_variables)
145 mooseError("The Dictator proclaims that the moose variable with number ",
146 moose_var_num,
147 " is not a PorousFlow variable. Exiting with error code 1984.");
148 return _pf_var_num[moose_var_num];
149}
150
151unsigned int
152PorousFlowDictator::mooseVariableNum(unsigned int porous_flow_var_num) const
153{
154 if (porous_flow_var_num >= _num_variables)
155 mooseError("The Dictator proclaims that there is no such PorousFlow variable with number ",
156 porous_flow_var_num,
157 ". Exiting with error code 1984.");
158 return _moose_var_num[porous_flow_var_num];
159}
160
161bool
162PorousFlowDictator::isPorousFlowVariable(unsigned int moose_var_num) const
163{
164 return !notPorousFlowVariable(moose_var_num);
165}
166
167bool
168PorousFlowDictator::notPorousFlowVariable(unsigned int moose_var_num) const
169{
170 return moose_var_num >= _pf_var_num.size() || _pf_var_num[moose_var_num] == _num_variables;
171}
172
173bool
178
179FEType
181{
182 return _fe_type;
183}
184
185bool
187{
188 return _is_fv;
189}
190
191void
192PorousFlowDictator::registerNodalVariable(const VariableName & var_name) const
193{
194 // Resolved here rather than passed in by the caller, so the type cannot disagree with the
195 // name. getVariable rather than getFieldVar("porous_flow_vars", ...) because a variable read
196 // at the nodes need not be a PorousFlow variable: an AuxVariable cannot be one at all, yet a
197 // nodal AuxVariable is routinely read at the nodes.
198 const FEType & fe_type = _fe_problem.getVariable(0, var_name).feType();
199
200 // The first variable to be registered defines the type the rest must match
201 if (!_nodal_fe_type)
202 _nodal_fe_type = fe_type;
203
204 if (*_nodal_fe_type != fe_type)
205 mooseError("Nodal PorousFlow Materials read variables of more than one FE type at the nodes: '",
206 var_name,
207 "' is ",
208 feTypeName(fe_type),
209 ", but ",
211 " was already registered by ",
213 ". Every variable read at the nodes must share an FE type, because nodal Materials "
214 "index their properties with a single node counter that must be a valid "
215 "degree-of-freedom index for all of them.");
216
217 _nodal_fe_type_vars.insert(var_name);
218}
219
220std::string
221PorousFlowDictator::feTypeName(const FEType & fe_type)
222{
223 return Utility::enum_to_string<Order>(fe_type.order) + " " + Moose::stringify(fe_type.family);
224}
registerMooseObject("PorousFlowApp", PorousFlowDictator)
void ErrorVector unsigned int
const MooseVariableFieldBase * getFieldVar(const std::string &var_name, unsigned int comp) const
VariableName coupledName(const std::string &var_name, unsigned int comp=0) const
virtual unsigned int coupled(const std::string &var_name, unsigned int comp=0) const
virtual const MooseVariableFieldBase & getVariable(const THREAD_ID tid, const std::string &var_name, Moose::VarKindType expected_var_type=Moose::VarKindType::VAR_ANY, Moose::VarFieldType expected_var_field_type=Moose::VarFieldType::VAR_FIELD_ANY) const override
static InputParameters validParams()
void addParamNamesToGroup(const std::string &space_delim_names, const std::string group_name)
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
void addRequiredParam(const std::string &name, const std::string &doc_string)
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)
void mooseError(Args &&... args) const
const libMesh::FEType & feType() const
virtual bool isFV() const
This holds maps between the nonlinear variables used in a PorousFlow simulation and the variable numb...
void registerNodalVariable(const VariableName &var_name) const
Register a variable that a nodal Material reads by degree of freedom.
unsigned int numPhases() const
The number of fluid phases.
bool _consistent_fe_type
Whether the porous_flow_vars all have the same fe_type.
std::set< VariableName > _nodal_fe_type_vars
Names of the variables that have registered _nodal_fe_type, used to report a disagreement.
unsigned int numVariables() const
The number of PorousFlow variables.
bool _is_fv
Whether the PorousFlow variables are finite-volume variables.
std::vector< unsigned int > _pf_var_num
_pf_var_num[i] = the porous flow variable corresponding to moose variable i
unsigned int numAqueousEquilibrium() const
The number of aqueous equilibrium secondary species.
unsigned int aqueousPhaseNumber() const
The aqueous phase number.
const unsigned int _num_aqueous_equilibrium
Number of aqueous-equilibrium secondary species.
unsigned int numComponents() const
The number of fluid components.
libMesh::FEType feType() const
The FEType of the first porous_flow_variable.
bool _perm_derivs
Indicates whether the simulation includes derivatives of permeability.
unsigned int porousFlowVariableNum(unsigned int moose_var_num) const
The PorousFlow variable number.
static std::string feTypeName(const libMesh::FEType &fe_type)
A human-readable name for an FE type, eg "FIRST LAGRANGE", for error messages.
libMesh::FEType _fe_type
FE type used by the PorousFlow variables.
const unsigned int _aqueous_phase_number
Aqueous phase number.
unsigned int numAqueousKinetic() const
The number of aqueous kinetic secondary species.
const unsigned int _num_components
Number of fluid components.
bool isPorousFlowVariable(unsigned int moose_var_num) const
Returns true if moose_var_num is a porous flow variable.
const unsigned int _num_phases
Number of fluid phases.
bool notPorousFlowVariable(unsigned int moose_var_num) const
Returns true if moose_var_num is not a porous flow variabe.
bool isFV() const
Whether the PorousFlow variables are finite-volume variables.
bool consistentFEType() const
Whether the porous_flow_vars all have the same FEType or if no porous_flow_vars were provided.
unsigned int mooseVariableNum(unsigned int porous_flow_var_num) const
The Moose variable number.
std::vector< unsigned int > _moose_var_num
_moose_var_num[i] = the moose variable number corresponding to porous flow variable i
const unsigned int _num_aqueous_kinetic
Number of aqeuous-kinetic secondary species that are involved in mineralisation.
std::optional< libMesh::FEType > _nodal_fe_type
FE type shared by the variables that nodal Materials read by DOF; see registerNodalVariable.
PorousFlowDictator(const InputParameters &parameters)
static InputParameters validParams()
const unsigned int _num_variables
Number of PorousFlow variables.
virtual unsigned int nVariables() const
FEProblemBase & _fe_problem
SystemBase & _sys
std::string stringify(const T &t)