https://mooseframework.inl.gov
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 "NonlinearSystem.h"
12 
13 registerMooseObject("PorousFlowApp", PorousFlowDictator);
14 
17 {
19  params.addClassDescription("Holds information on the PorousFlow variable names");
20  params.addRequiredCoupledVar("porous_flow_vars",
21  "List of primary variables that are used in the PorousFlow "
22  "simulation. Jacobian entries involving derivatives wrt these "
23  "variables will be computed. In single-phase models you will just "
24  "have one (eg \'pressure\'), in two-phase models you will have two "
25  "(eg \'p_water p_gas\', or \'p_water s_water\'), etc.");
26  params.addRequiredParam<unsigned int>("number_fluid_phases",
27  "The number of fluid phases in the simulation");
28  params.addRequiredParam<unsigned int>("number_fluid_components",
29  "The number of fluid components in the simulation");
30  params.addParam<unsigned int>("number_aqueous_equilibrium",
31  0,
32  "The number of secondary species in the aqueous-equilibrium "
33  "reaction system. (Leave as zero if the simulation does not "
34  "involve chemistry)");
35  params.addParam<unsigned int>("number_aqueous_kinetic",
36  0,
37  "The number of secondary species in the aqueous-kinetic reaction "
38  "system involved in precipitation and dissolution. (Leave as zero "
39  "if the simulation does not involve chemistry)");
40  params.addParam<unsigned int>("aqueous_phase_number",
41  0,
42  "The fluid phase number of the aqueous phase in which the "
43  "equilibrium and kinetic chemical reactions occur");
44 
45  params.addParam<SolverSystemName>("solver_sys", "Name of the solver system for the porepressure");
46  params.addParamNamesToGroup("solver_sys", "Advanced");
47  return params;
48 }
49 
51  : GeneralUserObject(parameters),
52  Coupleable(this, false),
53  _num_variables(coupledComponents("porous_flow_vars")),
54  _num_phases(getParam<unsigned int>("number_fluid_phases")),
55  _num_components(getParam<unsigned int>("number_fluid_components")),
56  _num_aqueous_equilibrium(getParam<unsigned int>("number_aqueous_equilibrium")),
57  _num_aqueous_kinetic(getParam<unsigned int>("number_aqueous_kinetic")),
58  _aqueous_phase_number(getParam<unsigned int>("aqueous_phase_number")),
59  _consistent_fe_type(false),
60  _fe_type(0),
61  _is_fv(false)
62 {
64  for (unsigned int i = 0; i < _num_variables; ++i)
65  _moose_var_num[i] = coupled("porous_flow_vars", i);
66 
67  if (_num_variables > 0)
68  {
69  _consistent_fe_type = true;
70  _is_fv = getFieldVar("porous_flow_vars", 0)->isFV();
71  _fe_type = FEType(getFieldVar("porous_flow_vars", 0)->feType());
72  for (unsigned int i = 1; i < _num_variables; ++i)
73  if (getFieldVar("porous_flow_vars", i)->feType() != _fe_type)
74  _consistent_fe_type = false;
75  }
76 
77  _pf_var_num.assign(_sys.nVariables(),
78  _num_variables); // Note: the _num_variables assignment indicates that "this is
79  // not a PorousFlow variable"
80  for (unsigned int i = 0; i < _num_variables; ++i)
81  {
82  if (_moose_var_num[i] < _pf_var_num.size())
84  else
85  // should not couple AuxVariables to the Dictator (Jacobian entries are not calculated for
86  // them)
87  mooseError("PorousFlowDictator: AuxVariables variables must not be coupled into the Dictator "
88  "for this is against specification #1984. Variable '",
89  coupledName("porous_flow_vars", /*comp=*/i),
90  "' is either an AuxVariable or from a different nonlinear system.");
91  }
92 
94  mooseError("PorousflowDictator: The aqueous phase number must be less than the number of fluid "
95  "phases. The Dictator does not appreciate jokes.");
96 
97  // Don't include permeabiity derivatives in the Jacobian by default (overwrite using
98  // usePermDerivs()) when necessary in permeabiity material classes
99  _perm_derivs = false;
100 }
101 
102 unsigned int
104 {
105  return _num_variables;
106 }
107 
108 unsigned int
110 {
111  return _num_phases;
112 }
113 
114 unsigned int
116 {
117  return _num_components;
118 }
119 
120 unsigned int
122 {
124 }
125 
126 unsigned int
128 {
129  return _num_aqueous_kinetic;
130 }
131 
132 unsigned int
134 {
135  return _aqueous_phase_number;
136 }
137 
138 unsigned int
139 PorousFlowDictator::porousFlowVariableNum(unsigned int moose_var_num) const
140 {
141  if (moose_var_num >= _pf_var_num.size() || _pf_var_num[moose_var_num] == _num_variables)
142  mooseError("The Dictator proclaims that the moose variable with number ",
143  moose_var_num,
144  " is not a PorousFlow variable. Exiting with error code 1984.");
145  return _pf_var_num[moose_var_num];
146 }
147 
148 unsigned int
149 PorousFlowDictator::mooseVariableNum(unsigned int porous_flow_var_num) const
150 {
151  if (porous_flow_var_num >= _num_variables)
152  mooseError("The Dictator proclaims that there is no such PorousFlow variable with number ",
153  porous_flow_var_num,
154  ". Exiting with error code 1984.");
155  return _moose_var_num[porous_flow_var_num];
156 }
157 
158 bool
159 PorousFlowDictator::isPorousFlowVariable(unsigned int moose_var_num) const
160 {
161  return !notPorousFlowVariable(moose_var_num);
162 }
163 
164 bool
165 PorousFlowDictator::notPorousFlowVariable(unsigned int moose_var_num) const
166 {
167  return moose_var_num >= _pf_var_num.size() || _pf_var_num[moose_var_num] == _num_variables;
168 }
169 
170 bool
172 {
173  return _consistent_fe_type;
174 }
175 
176 FEType
178 {
179  return _fe_type;
180 }
181 
182 bool
184 {
185  return _is_fv;
186 }
bool _perm_derivs
Indicates whether the simulation includes derivatives of permeability.
const unsigned int _num_aqueous_equilibrium
Number of aqueous-equilibrium secondary species.
libMesh::FEType feType() const
The FEType of the first porous_flow_variable.
virtual unsigned int coupled(const std::string &var_name, unsigned int comp=0) const
const unsigned int _num_aqueous_kinetic
Number of aqeuous-kinetic secondary species that are involved in mineralisation.
bool _consistent_fe_type
Whether the porous_flow_vars all have the same fe_type.
bool notPorousFlowVariable(unsigned int moose_var_num) const
Returns true if moose_var_num is not a porous flow variabe.
const unsigned int _num_components
Number of fluid components.
VariableName coupledName(const std::string &var_name, unsigned int comp=0) const
static InputParameters validParams()
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
registerMooseObject("PorousFlowApp", PorousFlowDictator)
bool isFV() const
Whether the PorousFlow variables are finite-volume variables.
virtual bool isFV() const
const unsigned int _num_variables
Number of PorousFlow variables.
unsigned int numComponents() const
The number of fluid components.
unsigned int aqueousPhaseNumber() const
The aqueous phase number.
bool _is_fv
Whether the PorousFlow variables are finite-volume variables.
bool isPorousFlowVariable(unsigned int moose_var_num) const
Returns true if moose_var_num is a porous flow variable.
void addRequiredParam(const std::string &name, const std::string &doc_string)
PorousFlowDictator(const InputParameters &parameters)
virtual unsigned int nVariables() const
std::vector< unsigned int > _pf_var_num
_pf_var_num[i] = the porous flow variable corresponding to moose variable i
const unsigned int _aqueous_phase_number
Aqueous phase number.
unsigned int mooseVariableNum(unsigned int porous_flow_var_num) const
The Moose variable number.
unsigned int numPhases() const
The number of fluid phases.
unsigned int numVariables() const
The number of PorousFlow variables.
unsigned int numAqueousKinetic() const
The number of aqueous kinetic secondary species.
static InputParameters validParams()
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
SystemBase & _sys
This holds maps between the nonlinear variables used in a PorousFlow simulation and the variable numb...
void mooseError(Args &&... args) const
std::vector< unsigned int > _moose_var_num
_moose_var_num[i] = the moose variable number corresponding to porous flow variable i ...
void addClassDescription(const std::string &doc_string)
unsigned int porousFlowVariableNum(unsigned int moose_var_num) const
The PorousFlow variable number.
unsigned int numAqueousEquilibrium() const
The number of aqueous equilibrium secondary species.
void ErrorVector unsigned int
const unsigned int _num_phases
Number of fluid phases.
bool consistentFEType() const
Whether the porous_flow_vars all have the same FEType or if no porous_flow_vars were provided...
libMesh::FEType _fe_type
FE type used by the PorousFlow variables.
const MooseVariableFieldBase * getFieldVar(const std::string &var_name, unsigned int comp) const
void addParamNamesToGroup(const std::string &space_delim_names, const std::string group_name)