www.mooseframework.org
PorousFlowDictator.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 // Holds maps between PorousFlow variables (porepressure, saturations) and the variable number used
11 // by MOOSE.
12 #include "PorousFlowDictator.h"
13 #include "NonlinearSystem.h"
14 
15 registerMooseObject("PorousFlowApp", PorousFlowDictator);
16 
17 template <>
18 InputParameters
20 {
21  InputParameters params = validParams<GeneralUserObject>();
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  return params;
48 }
49 
50 PorousFlowDictator::PorousFlowDictator(const InputParameters & parameters)
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 {
63  for (unsigned int i = 0; i < _num_variables; ++i)
64  _moose_var_num[i] = coupled("porous_flow_vars", i);
65 
66  if (_num_variables > 0)
67  {
68  _consistent_fe_type = true;
69  _fe_type = FEType(getVar("porous_flow_vars", 0)->feType());
70  for (unsigned int i = 1; i < _num_variables; ++i)
71  if (getVar("porous_flow_vars", i)->feType() != _fe_type)
72  _consistent_fe_type = false;
73  }
74 
75  _pf_var_num.assign(_fe_problem.getNonlinearSystemBase().nVariables(),
76  _num_variables); // Note: the _num_variables assignment indicates that "this is
77  // not a PorousFlow variable"
78  for (unsigned int i = 0; i < _num_variables; ++i)
79  if (_moose_var_num[i] < _pf_var_num.size())
81  else
82  // should not couple AuxVariables to the Dictator (Jacobian entries are not calculated for
83  // them)
84  mooseError("PorousFlowDictator: AuxVariables variables must not be coupled into the Dictator "
85  "for this is against specification #1984. Variable number ",
86  i,
87  " is an AuxVariable.");
88 
90  mooseError("PorousflowDictator: The aqueous phase number must be less than the number of fluid "
91  "phases. The Dictator does not appreciate jokes.");
92 }
93 
94 unsigned int
96 {
97  return _num_variables;
98 }
99 
100 unsigned int
102 {
103  return _num_phases;
104 }
105 
106 unsigned int
108 {
109  return _num_components;
110 }
111 
112 unsigned int
114 {
116 }
117 
118 unsigned int
120 {
121  return _num_aqueous_kinetic;
122 }
123 
124 unsigned int
126 {
127  return _aqueous_phase_number;
128 }
129 
130 unsigned int
131 PorousFlowDictator::porousFlowVariableNum(unsigned int moose_var_num) const
132 {
133  if (moose_var_num >= _pf_var_num.size() || _pf_var_num[moose_var_num] == _num_variables)
134  mooseError("The Dictator proclaims that the moose variable with number ",
135  moose_var_num,
136  " is not a PorousFlow variable. Exiting with error code 1984.");
137  return _pf_var_num[moose_var_num];
138 }
139 
140 unsigned int
141 PorousFlowDictator::mooseVariableNum(unsigned int porous_flow_var_num) const
142 {
143  if (porous_flow_var_num >= _num_variables)
144  mooseError("The Dictator proclaims that there is no such PorousFlow variable with number ",
145  porous_flow_var_num,
146  ". Exiting with error code 1984.");
147  return _moose_var_num[porous_flow_var_num];
148 }
149 
150 bool
151 PorousFlowDictator::isPorousFlowVariable(unsigned int moose_var_num) const
152 {
153  return !notPorousFlowVariable(moose_var_num);
154 }
155 
156 bool
157 PorousFlowDictator::notPorousFlowVariable(unsigned int moose_var_num) const
158 {
159  return moose_var_num >= _pf_var_num.size() || _pf_var_num[moose_var_num] == _num_variables;
160 }
161 
162 bool
164 {
165  return _consistent_fe_type;
166 }
167 
168 FEType
170 {
171  return _fe_type;
172 }
const unsigned int _num_aqueous_equilibrium
Number of aqueous-equilibrium secondary species.
FEType feType() const
The FEType of the first porous_flow_variable.
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.
registerMooseObject("PorousFlowApp", PorousFlowDictator)
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 isPorousFlowVariable(unsigned int moose_var_num) const
Returns true if moose_var_num is a porous flow variable.
PorousFlowDictator(const InputParameters &parameters)
FEType _fe_type
FE type used by the PorousFlow variables.
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.
This holds maps between the nonlinear variables used in a PorousFlow simulation and the variable numb...
std::vector< unsigned int > _moose_var_num
_moose_var_num[i] = the moose variable number corresponding to porous flow variable i ...
InputParameters validParams< PorousFlowDictator >()
unsigned int porousFlowVariableNum(unsigned int moose_var_num) const
The PorousFlow variable number.
unsigned int numAqueousEquilibrium() const
The number of aqueous equilibrium secondary species.
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...