www.mooseframework.org
PorousFlowSinglePhaseBase.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 /****************************************************************/
8 
9 #include "FEProblem.h"
10 #include "Conversion.h"
11 #include "libmesh/string_to_enum.h"
12 
13 template <>
14 InputParameters
16 {
17  InputParameters params = validParams<PorousFlowActionBase>();
18  params.addParam<bool>("add_darcy_aux", true, "Add AuxVariables that record Darcy velocity");
19  params.addParam<bool>("add_stress_aux", true, "Add AuxVariables that record effective stress");
20  params.addParam<bool>("use_brine", false, "Use PorousFlowBrine material for the fluid phase");
21  params.addRequiredParam<NonlinearVariableName>("porepressure",
22  "The name of the porepressure variable");
23  MooseEnum coupling_type("Hydro ThermoHydro HydroMechanical ThermoHydroMechanical", "Hydro");
24  params.addParam<MooseEnum>("coupling_type",
25  coupling_type,
26  "The type of simulation. For simulations involving Mechanical "
27  "deformations, you will need to supply the correct Biot coefficient. "
28  "For simulations involving Thermal flows, you will need an associated "
29  "ConstantThermalExpansionCoefficient Material");
30  MooseEnum simulation_type_choice("steady transient", "transient");
31  params.addParam<MooseEnum>("simulation_type",
32  simulation_type_choice,
33  "Whether a transient or steady-state simulation is being performed");
34  params.addParam<UserObjectName>("fp",
35  "use_brine_material",
36  "The name of the user object for fluid "
37  "properties. Not required if use_brine is true.");
38  params.addCoupledVar("mass_fraction_vars",
39  "List of variables that represent the mass fractions. With only one fluid "
40  "component, this may be left empty. With N fluid components, the format is "
41  "'f_0 f_1 f_2 ... f_(N-1)'. That is, the N^th component need not be "
42  "specified because f_N = 1 - (f_0 + f_1 + ... + f_(N-1)). It is best "
43  "numerically to choose the N-1 mass fraction variables so that they "
44  "represent the fluid components with small concentrations. This Action "
45  "will associated the i^th mass fraction variable to the equation for the "
46  "i^th fluid component, and the pressure variable to the N^th fluid "
47  "component.");
48  params.addParam<unsigned>("nacl_index",
49  0,
50  "Index of NaCl variable in mass_fraction_vars, for "
51  "calculating brine properties. Only required if use_brine is true.");
52  params.addParam<Real>(
53  "biot_coefficient",
54  1.0,
55  "The Biot coefficient (relevant only for mechanically-coupled simulations)");
56  params.addClassDescription("Base class for single-phase simulations");
57  return params;
58 }
59 
61  : PorousFlowActionBase(params),
62  _pp_var(getParam<NonlinearVariableName>("porepressure")),
63  _coupling_type(getParam<MooseEnum>("coupling_type").getEnum<CouplingTypeEnum>()),
64  _simulation_type(getParam<MooseEnum>("simulation_type").getEnum<SimulationTypeChoiceEnum>()),
65  _fp(getParam<UserObjectName>("fp")),
66  _biot_coefficient(getParam<Real>("biot_coefficient")),
67  _add_darcy_aux(getParam<bool>("add_darcy_aux")),
68  _add_stress_aux(getParam<bool>("add_stress_aux")),
69  _use_brine(getParam<bool>("use_brine")),
70  _nacl_index(getParam<unsigned>("nacl_index"))
71 {
74  _temperature_var.size() != 1)
75  mooseError("PorousFlowSinglePhaseBase: You need to specify a temperature variable to perform "
76  "non-isothermal simulations");
77 
78  if (_use_brine && !params.isParamValid("mass_fraction_vars"))
79  mooseError("PorousFlowSinglePhaseBase: You need to specify at least one component in "
80  "mass_fraction_vars if use_brine is true");
81 
83  mooseError(
84  "PorousFlowSinglePhaseBase: nacl_index must be less than length of mass_fraction_vars");
85 
86  if (!_use_brine && _fp == "use_brine_material")
87  mooseError("PorousFlowSinglePhaseBase: You need to specify fp if use_brine is false");
88 
91  {
92  _objects_to_add.push_back("StressDivergenceTensors");
93  _objects_to_add.push_back("Gravity");
94  _objects_to_add.push_back("PorousFlowEffectiveStressCoupling");
95  }
98  {
99  _objects_to_add.push_back("PorousFlowHeatConduction");
101  _objects_to_add.push_back("PorousFlowEnergyTimeDerivative");
102  }
105  _objects_to_add.push_back("PorousFlowHeatVolumetricExpansion");
106  if (_add_darcy_aux)
107  _objects_to_add.push_back("PorousFlowDarcyVelocityComponent");
110  _objects_to_add.push_back("StressAux");
111 }
112 
113 void
115 {
117 
120  _current_task == "add_kernel")
121  {
122  for (unsigned i = 0; i < _ndisp; ++i)
123  {
124  std::string kernel_name = "PorousFlowUnsaturated_grad_stress" + Moose::stringify(i);
125  std::string kernel_type = "StressDivergenceTensors";
126  if (_coord_system == Moose::COORD_RZ)
127  kernel_type = "StressDivergenceRZTensors";
128  InputParameters params = _factory.getValidParams(kernel_type);
129  params.set<NonlinearVariableName>("variable") = _displacements[i];
130  params.set<std::vector<VariableName>>("displacements") = _coupled_displacements;
132  {
133  params.set<std::vector<VariableName>>("temperature") = _temperature_var;
134  params.set<std::string>("thermal_eigenstrain_name") =
135  getParam<std::string>("thermal_eigenstrain_name");
136  }
137  params.set<unsigned>("component") = i;
138  params.set<bool>("use_displaced_mesh") = getParam<bool>("use_displaced_mesh");
139  _problem->addKernel(kernel_type, kernel_name, params);
140 
141  if (_gravity(i) != 0)
142  {
143  kernel_name = "PorousFlowUnsaturated_gravity" + Moose::stringify(i);
144  kernel_type = "Gravity";
145  params = _factory.getValidParams(kernel_type);
146  params.set<NonlinearVariableName>("variable") = _displacements[i];
147  params.set<Real>("value") = _gravity(i);
148  params.set<bool>("use_displaced_mesh") = getParam<bool>("use_displaced_mesh");
149  _problem->addKernel(kernel_type, kernel_name, params);
150  }
151 
152  kernel_name = "PorousFlowUnsaturated_EffStressCoupling" + Moose::stringify(i);
153  kernel_type = "PorousFlowEffectiveStressCoupling";
154  params = _factory.getValidParams(kernel_type);
155  params.set<UserObjectName>("PorousFlowDictator") = _dictator_name;
156  params.set<NonlinearVariableName>("variable") = _displacements[i];
157  params.set<Real>("biot_coefficient") = _biot_coefficient;
158  params.set<unsigned>("component") = i;
159  params.set<bool>("use_displaced_mesh") = getParam<bool>("use_displaced_mesh");
160  _problem->addKernel(kernel_type, kernel_name, params);
161  }
162  }
163 
166  _current_task == "add_kernel")
167  {
168  std::string kernel_name = "PorousFlowUnsaturated_HeatConduction";
169  std::string kernel_type = "PorousFlowHeatConduction";
170  InputParameters params = _factory.getValidParams(kernel_type);
171  params.set<NonlinearVariableName>("variable") = _temperature_var[0];
172  params.set<UserObjectName>("PorousFlowDictator") = _dictator_name;
173  _problem->addKernel(kernel_type, kernel_name, params);
174 
176  {
177  kernel_name = "PorousFlowUnsaturated_EnergyTimeDerivative";
178  kernel_type = "PorousFlowEnergyTimeDerivative";
179  params = _factory.getValidParams(kernel_type);
180  params.set<NonlinearVariableName>("variable") = _temperature_var[0];
181  params.set<UserObjectName>("PorousFlowDictator") = _dictator_name;
182  _problem->addKernel(kernel_type, kernel_name, params);
183  }
184  }
185 
187  _simulation_type == SimulationTypeChoiceEnum::TRANSIENT && _current_task == "add_kernel")
188  {
189  std::string kernel_name = "PorousFlowUnsaturated_HeatVolumetricExpansion";
190  std::string kernel_type = "PorousFlowHeatVolumetricExpansion";
191  InputParameters params = _factory.getValidParams(kernel_type);
192  params.set<UserObjectName>("PorousFlowDictator") = _dictator_name;
193  params.set<NonlinearVariableName>("variable") = _temperature_var[0];
194  _problem->addKernel(kernel_type, kernel_name, params);
195  }
196 
197  // add Materials
198  if (_deps.dependsOn(_objects_to_add, "PorousFlowTemperature_qp"))
199  addTemperatureMaterial(false);
200  if (_deps.dependsOn(_objects_to_add, "PorousFlowTemperature_nodal"))
202  if (_deps.dependsOn(_objects_to_add, "PorousFlowMassFraction_qp"))
204  if (_deps.dependsOn(_objects_to_add, "PorousFlowMassFraction_nodal"))
206 
207  const bool compute_rho_mu_qp = _deps.dependsOn(_objects_to_add, "PorousFlowDensity_qp") ||
208  _deps.dependsOn(_objects_to_add, "PorousFlowViscosity_qp");
209  const bool compute_e_qp = _deps.dependsOn(_objects_to_add, "PorousFlowInternalEnergy_qp");
210  const bool compute_h_qp = _deps.dependsOn(_objects_to_add, "PorousFlowEnthalpy_qp");
211  if (compute_rho_mu_qp || compute_e_qp || compute_h_qp)
212  {
213  if (_use_brine)
214  {
215  const std::string nacl_name = _mass_fraction_vars[_nacl_index];
216  addBrineMaterial(nacl_name, false, 0, compute_rho_mu_qp, compute_e_qp, compute_h_qp);
217  }
218  else
219  addSingleComponentFluidMaterial(false, 0, compute_rho_mu_qp, compute_e_qp, compute_h_qp, _fp);
220  }
221  const bool compute_rho_mu_nodal = _deps.dependsOn(_objects_to_add, "PorousFlowDensity_nodal") ||
222  _deps.dependsOn(_objects_to_add, "PorousFlowViscosity_nodal");
223  const bool compute_e_nodal = _deps.dependsOn(_objects_to_add, "PorousFlowInternalEnergy_nodal");
224  const bool compute_h_nodal = _deps.dependsOn(_objects_to_add, "PorousFlowEnthalpy_nodal");
225  if (compute_rho_mu_nodal || compute_e_nodal || compute_h_nodal)
226  {
227  if (_use_brine)
228  {
229  const std::string nacl_name = _mass_fraction_vars[_nacl_index];
230  addBrineMaterial(nacl_name, true, 0, compute_rho_mu_nodal, compute_e_nodal, compute_h_nodal);
231  }
232  else
234  true, 0, compute_rho_mu_nodal, compute_e_nodal, compute_h_nodal, _fp);
235  }
236 
237  if (compute_rho_mu_qp)
238  {
239  joinDensity(false);
240  joinViscosity(false);
241  }
242  if (compute_rho_mu_nodal)
243  {
244  joinDensity(true);
245  joinViscosity(true);
246  }
247  if (compute_e_qp)
248  joinInternalEnergy(false);
249  if (compute_e_nodal)
250  joinInternalEnergy(true);
251  if (compute_h_qp)
252  joinEnthalpy(false);
253  if (compute_h_nodal)
254  joinEnthalpy(true);
255 
256  if (_deps.dependsOn(_objects_to_add, "PorousFlowRelativePermeability_qp"))
258  if (_deps.dependsOn(_objects_to_add, "PorousFlowRelativePermeability_nodal"))
260 
261  if (_deps.dependsOn(_objects_to_add, "PorousFlowEffectiveFluidPressure_qp"))
263  if (_deps.dependsOn(_objects_to_add, "PorousFlowEffectiveFluidPressure_nodal"))
265 
266  // add AuxVariables and AuxKernels
267  if (_add_darcy_aux)
271  addStressAux();
272 }
273 
274 void
276 {
277  std::string uo_name = _dictator_name;
278  std::string uo_type = "PorousFlowDictator";
279  InputParameters params = _factory.getValidParams(uo_type);
280  std::vector<VariableName> pf_vars = _mass_fraction_vars;
281  pf_vars.push_back(_pp_var);
284  pf_vars.push_back(_temperature_var[0]);
287  pf_vars.insert(pf_vars.end(), _coupled_displacements.begin(), _coupled_displacements.end());
288  params.set<std::vector<VariableName>>("porous_flow_vars") = pf_vars;
289  params.set<unsigned int>("number_fluid_phases") = 1;
290  params.set<unsigned int>("number_fluid_components") = _num_mass_fraction_vars + 1;
291  _problem->addUserObject(uo_type, uo_name, params);
292 }
Moose::CoordinateSystemType _coord_system
Coordinate system of the simulation (eg RZ, XYZ, etc)
void addStressAux()
Add AuxVariables and AuxKernels to compute effective stress.
const std::vector< VariableName > & _mass_fraction_vars
Name of the mass-fraction variables (if any)
const unsigned _nacl_index
index of NaCl in list of fluid components
const Real _biot_coefficient
fluid specific heat capacity at constant volume
const bool _add_stress_aux
add AuxVariables for stress
InputParameters validParams< PorousFlowSinglePhaseBase >()
void joinEnthalpy(bool at_nodes)
Adds a PorousFlowJoiner for the fluid enthalpy.
void addEffectiveFluidPressureMaterial(bool at_nodes)
Adds a nodal and a quadpoint effective fluid pressure material.
InputParameters validParams< PorousFlowActionBase >()
std::vector< VariableName > _coupled_displacements
displacement Variable names
void joinInternalEnergy(bool at_nodes)
Adds a PorousFlowJoiner for the fluid internal energy.
const bool _add_darcy_aux
add a AuxVariables to record Darcy velocity
virtual void act() override
void joinDensity(bool at_nodes)
Adds a PorousFlowJoiner for the fluid density.
const unsigned _ndisp
number of displacement variables supplied
std::vector< std::string > _objects_to_add
List of Kernels, AuxKernels, Materials, etc, to be added.
CouplingTypeEnum
Determines the coupling type.
void addDarcyAux(const RealVectorValue &gravity)
Add AuxVariables and AuxKernels to calculate Darcy velocity.
Base class for PorousFlow actions.
const NonlinearVariableName _pp_var
porepressure NonlinearVariable name
const UserObjectName & _fp
Name of the fluid-properties UserObject.
void addTemperatureMaterial(bool at_nodes)
Adds a nodal and a quadpoint Temperature material.
const RealVectorValue _gravity
gravity
const std::vector< VariableName > & _temperature_var
Name of the temperature variable (if any)
void addMassFractionMaterial(bool at_nodes)
Adds a nodal and a quadpoint MassFraction material.
void joinRelativePermeability(bool at_nodes)
Adds a PorousFlowJoiner for the fluid relative permeability.
void joinViscosity(bool at_nodes)
Adds a PorousFlowJoiner for the fluid viscosity.
PorousFlowSinglePhaseBase(const InputParameters &params)
enum PorousFlowSinglePhaseBase::SimulationTypeChoiceEnum _simulation_type
const std::string _dictator_name
The name of the PorousFlowDictator object to be added.
const unsigned _num_mass_fraction_vars
Number of mass-fraction variables.
void addBrineMaterial(const VariableName xnacl, bool at_nodes, unsigned phase, bool compute_density_and_viscosity, bool compute_internal_energy, bool compute_enthalpy)
Adds a brine fluid Material.
const bool _use_brine
use PorousFlowBrine material
enum PorousFlowSinglePhaseBase::CouplingTypeEnum _coupling_type
const std::vector< NonlinearVariableName > & _displacements
displacement NonlinearVariable names (if any)
SimulationTypeChoiceEnum
whether steady or transient simulation
virtual void addDictator() override
add the PorousFlowDictator object
DependencyResolver< std::string > _deps
All dependencies of kernels, auxkernels, materials, etc, are stored in _dependencies.
void addSingleComponentFluidMaterial(bool at_nodes, unsigned phase, bool compute_density_and_viscosity, bool compute_internal_energy, bool compute_enthalpy, const UserObjectName &fp)
Adds a single-component fluid Material.