www.mooseframework.org
Q2PAction.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 /****************************************************************/
7 #include "Q2PAction.h"
8 
9 #include "Factory.h"
10 #include "FEProblem.h"
11 #include "Parser.h"
12 #include "libmesh/string_to_enum.h"
13 
14 template <>
15 InputParameters
17 {
18  MooseEnum orders("CONSTANT FIRST SECOND THIRD FOURTH", "FIRST");
19 
20  InputParameters params = validParams<Action>();
21  params.addRequiredParam<NonlinearVariableName>("porepressure", "The porepressure variable");
22  params.addRequiredParam<NonlinearVariableName>("saturation", "The water saturation variable");
23  params.addRequiredParam<UserObjectName>(
24  "water_density",
25  "A RichardsDensity UserObject that defines the water density as a function of porepressure.");
26  params.addRequiredParam<UserObjectName>(
27  "water_relperm",
28  "A RichardsRelPerm UserObject that defines the water relative permeability "
29  "as a function of water saturation (eg RichardsRelPermPower).");
30  params.addParam<UserObjectName>(
31  "water_relperm_for_diffusion",
32  "A RichardsRelPerm UserObject that defines the water relative permeability as a function of "
33  "water saturation that will be used in the diffusivity Kernel (eg RichardsRelPermPower). If "
34  "not given, water_relperm will be used instead, which is the most common use-case.");
35  params.addRequiredParam<Real>("water_viscosity", "The water viscosity");
36  params.addRequiredParam<UserObjectName>(
37  "gas_density",
38  "A RichardsDensity UserObject that defines the gas density as a function of porepressure.");
39  params.addRequiredParam<UserObjectName>(
40  "gas_relperm",
41  "A RichardsRelPerm UserObject that defines the gas relative permeability as a "
42  "function of water saturation (eg Q2PRelPermPowerGas).");
43  params.addRequiredParam<Real>("gas_viscosity", "The gas viscosity");
44  params.addRequiredParam<Real>("diffusivity", "The diffusivity");
45  params.addParam<std::vector<OutputName>>("output_nodal_masses_to",
46  "Output Nodal masses to this Output object. If you "
47  "don't want any outputs, don't input anything here");
48  params.addParam<std::vector<OutputName>>(
49  "output_total_masses_to",
50  "Output total water and gas mass to this Output object. If you "
51  "don't want any outputs, don't input anything here");
52  params.addParam<bool>("save_gas_flux_in_Q2PGasFluxResidual",
53  false,
54  "Save the residual for the "
55  "Q2PPorepressureFlux into "
56  "the AuxVariable called "
57  "Q2PGasFluxResidual");
58  params.addParam<bool>("save_water_flux_in_Q2PWaterFluxResidual",
59  false,
60  "Save the residual for the Q2PSaturationFlux into the AuxVariable called "
61  "Q2PWaterFluxResidual");
62  params.addParam<bool>("save_gas_Jacobian_in_Q2PGasJacobian",
63  false,
64  "Save the diagonal component of the Q2PPorepressureFlux Jacobian into the "
65  "AuxVariable called Q2PGasJacobian");
66  params.addParam<bool>("save_water_Jacobian_in_Q2PWaterJacobian",
67  false,
68  "Save the diagonal component of the Q2PSaturationFlux Jacobian into the "
69  "AuxVariable called Q2PWaterJacobian");
70  params.addParam<MooseEnum>("ORDER",
71  orders,
72  "The order for the porepressure and saturation: " +
73  orders.getRawNames() +
74  " (only needed if you're calculating masses)");
75  return params;
76 }
77 
78 Q2PAction::Q2PAction(const InputParameters & params)
79  : Action(params),
80  _pp_var(getParam<NonlinearVariableName>("porepressure")),
81  _sat_var(getParam<NonlinearVariableName>("saturation")),
82  _water_density(getParam<UserObjectName>("water_density")),
83  _water_relperm(getParam<UserObjectName>("water_relperm")),
84  _water_relperm_for_diffusivity(isParamValid("water_relperm_for_diffusivity")
85  ? getParam<UserObjectName>("water_relperm_for_diffusivity")
86  : getParam<UserObjectName>("water_relperm")),
87  _water_viscosity(getParam<Real>("water_viscosity")),
88  _gas_density(getParam<UserObjectName>("gas_density")),
89  _gas_relperm(getParam<UserObjectName>("gas_relperm")),
90  _gas_viscosity(getParam<Real>("gas_viscosity")),
91  _diffusivity(getParam<Real>("diffusivity")),
92  _output_nodal_masses_to(getParam<std::vector<OutputName>>("output_nodal_masses_to")),
93  _output_total_masses_to(getParam<std::vector<OutputName>>("output_total_masses_to")),
94  _save_gas_flux_in_Q2PGasFluxResidual(getParam<bool>("save_gas_flux_in_Q2PGasFluxResidual")),
95  _save_water_flux_in_Q2PWaterFluxResidual(
96  getParam<bool>("save_water_flux_in_Q2PWaterFluxResidual")),
97  _save_gas_Jacobian_in_Q2PGasJacobian(getParam<bool>("save_gas_Jacobian_in_Q2PGasJacobian")),
98  _save_water_Jacobian_in_Q2PWaterJacobian(
99  getParam<bool>("save_water_Jacobian_in_Q2PWaterJacobian"))
100 {
102  if (_output_nodal_masses_to.size() == 0)
104 
106  if (_output_total_masses_to.size() == 0)
108 
110 }
111 
112 void
114 {
115  // add the kernels
116  if (_current_task == "add_kernel")
117  {
118  std::string kernel_name;
119  std::string kernel_type;
120  InputParameters params = _factory.getValidParams("Q2PNodalMass");
121 
122  kernel_name = "Q2P_nodal_water_mass";
123  kernel_type = "Q2PNodalMass";
124  params = _factory.getValidParams(kernel_type);
125  params.set<NonlinearVariableName>("variable") = _sat_var;
126  params.set<std::vector<VariableName>>("other_var") = {_pp_var};
127  params.set<bool>("var_is_porepressure") = false;
129  params.set<std::vector<AuxVariableName>>("save_in") = {"Q2P_nodal_water_mass_divided_by_dt"};
130  params.set<UserObjectName>("fluid_density") = _water_density;
131  _problem->addKernel(kernel_type, kernel_name, params);
132 
133  kernel_name = "Q2P_nodal_gas_mass";
134  kernel_type = "Q2PNodalMass";
135  params = _factory.getValidParams(kernel_type);
136  params.set<NonlinearVariableName>("variable") = _pp_var;
137  params.set<std::vector<VariableName>>("other_var") = {_sat_var};
138  params.set<bool>("var_is_porepressure") = true;
140  params.set<std::vector<AuxVariableName>>("save_in") = {"Q2P_nodal_gas_mass_divided_by_dt"};
141  params.set<UserObjectName>("fluid_density") = _gas_density;
142  _problem->addKernel(kernel_type, kernel_name, params);
143 
144  kernel_name = "Q2P_nodal_water_mass_old";
145  kernel_type = "Q2PNegativeNodalMassOld";
146  params = _factory.getValidParams(kernel_type);
147  params.set<NonlinearVariableName>("variable") = _sat_var;
148  params.set<std::vector<VariableName>>("other_var") = {_pp_var};
149  params.set<bool>("var_is_porepressure") = false;
150  params.set<UserObjectName>("fluid_density") = _water_density;
151  _problem->addKernel(kernel_type, kernel_name, params);
152 
153  kernel_name = "Q2P_nodal_gas_mass_old";
154  kernel_type = "Q2PNegativeNodalMassOld";
155  params = _factory.getValidParams(kernel_type);
156  params.set<NonlinearVariableName>("variable") = _pp_var;
157  params.set<std::vector<VariableName>>("other_var") = {_sat_var};
158  params.set<bool>("var_is_porepressure") = true;
159  params.set<UserObjectName>("fluid_density") = _gas_density;
160  _problem->addKernel(kernel_type, kernel_name, params);
161 
162  kernel_name = "Q2P_water_flux";
163  kernel_type = "Q2PSaturationFlux";
164  params = _factory.getValidParams(kernel_type);
165  params.set<NonlinearVariableName>("variable") = _sat_var;
166  params.set<std::vector<VariableName>>("porepressure_variable") = {_pp_var};
167  params.set<UserObjectName>("fluid_density") = _water_density;
168  params.set<UserObjectName>("fluid_relperm") = _water_relperm;
169  params.set<Real>("fluid_viscosity") = _water_viscosity;
171  params.set<std::vector<AuxVariableName>>("save_in") = {"Q2PWaterFluxResidual"};
173  params.set<std::vector<AuxVariableName>>("diag_save_in") = {"Q2PWaterJacobian"};
174  _problem->addKernel(kernel_type, kernel_name, params);
175 
176  kernel_name = "Q2P_gas_flux";
177  kernel_type = "Q2PPorepressureFlux";
178  params = _factory.getValidParams(kernel_type);
179  params.set<NonlinearVariableName>("variable") = _pp_var;
180  params.set<std::vector<VariableName>>("saturation_variable") = {_sat_var};
181  params.set<UserObjectName>("fluid_density") = _gas_density;
182  params.set<UserObjectName>("fluid_relperm") = _gas_relperm;
183  params.set<Real>("fluid_viscosity") = _gas_viscosity;
185  params.set<std::vector<AuxVariableName>>("save_in") = {"Q2PGasFluxResidual"};
187  params.set<std::vector<AuxVariableName>>("diag_save_in") = {"Q2PGasJacobian"};
188  _problem->addKernel(kernel_type, kernel_name, params);
189 
190  kernel_name = "Q2P_liquid_diffusion";
191  kernel_type = "Q2PSaturationDiffusion";
192  params = _factory.getValidParams(kernel_type);
193  params.set<NonlinearVariableName>("variable") = _sat_var;
194  params.set<std::vector<VariableName>>("porepressure_variable") = {_pp_var};
195  params.set<UserObjectName>("fluid_density") = _water_density;
196  params.set<UserObjectName>("fluid_relperm") = _water_relperm_for_diffusivity;
197  params.set<Real>("fluid_viscosity") = _water_viscosity;
198  params.set<Real>("diffusivity") = _diffusivity;
199  _problem->addKernel(kernel_type, kernel_name, params);
200  }
201 
202  if (_current_task == "add_aux_variable")
203  {
205  {
206  // user wants nodal masses or total masses
207  _problem->addAuxVariable("Q2P_nodal_water_mass_divided_by_dt",
208  FEType(Utility::string_to_enum<Order>(getParam<MooseEnum>("ORDER")),
209  Utility::string_to_enum<FEFamily>("LAGRANGE")));
210  _problem->addAuxVariable("Q2P_nodal_gas_mass_divided_by_dt",
211  FEType(Utility::string_to_enum<Order>(getParam<MooseEnum>("ORDER")),
212  Utility::string_to_enum<FEFamily>("LAGRANGE")));
213  }
215  _problem->addAuxVariable("Q2PGasFluxResidual",
216  FEType(Utility::string_to_enum<Order>(getParam<MooseEnum>("ORDER")),
217  Utility::string_to_enum<FEFamily>("LAGRANGE")));
219  _problem->addAuxVariable("Q2PWaterFluxResidual",
220  FEType(Utility::string_to_enum<Order>(getParam<MooseEnum>("ORDER")),
221  Utility::string_to_enum<FEFamily>("LAGRANGE")));
223  _problem->addAuxVariable("Q2PGasJacobian",
224  FEType(Utility::string_to_enum<Order>(getParam<MooseEnum>("ORDER")),
225  Utility::string_to_enum<FEFamily>("LAGRANGE")));
227  _problem->addAuxVariable("Q2PWaterJacobian",
228  FEType(Utility::string_to_enum<Order>(getParam<MooseEnum>("ORDER")),
229  Utility::string_to_enum<FEFamily>("LAGRANGE")));
230  }
231 
232  if (_current_task == "add_function" && _output_total_masses_to.size() > 0)
233  {
234  // user wants total masses, so need to build Functions to do this
235  InputParameters params = _factory.getValidParams("ParsedFunction");
236 
237  params.set<std::string>("value") = "a*b";
238 
239  std::vector<std::string> vars;
240  vars.push_back("a");
241  vars.push_back("b");
242  params.set<std::vector<std::string>>("vars") = vars;
243 
244  std::vector<std::string> vals_water;
245  vals_water.push_back("Q2P_mass_water_divided_by_dt");
246  vals_water.push_back("Q2P_dt");
247  params.set<std::vector<std::string>>("vals") = vals_water;
248  _problem->addFunction("ParsedFunction", "Q2P_water_mass_fcn", params);
249 
250  std::vector<std::string> vals_gas;
251  vals_gas.push_back("Q2P_mass_gas_divided_by_dt");
252  vals_gas.push_back("Q2P_dt");
253  params.set<std::vector<std::string>>("vals") = vals_gas;
254  _problem->addFunction("ParsedFunction", "Q2P_gas_mass_fcn", params);
255  }
256 
257  if (_current_task == "add_postprocessor" && _output_total_masses_to.size() > 0)
258  {
259  // user wants total masses, so need to build Postprocessors to do this
260 
261  InputParameters params = _factory.getValidParams("TimestepSize");
262 
263  params.set<MultiMooseEnum>("execute_on") = "timestep_begin";
264  params.set<std::vector<OutputName>>("outputs") = {"none"};
265  _problem->addPostprocessor("TimestepSize", "Q2P_dt", params);
266 
267  params = _factory.getValidParams("NodalSum");
268  params.set<std::vector<OutputName>>("outputs") = {"none"};
269  params.set<std::vector<VariableName>>("variable") = {"Q2P_nodal_water_mass_divided_by_dt"};
270  _problem->addPostprocessor("NodalSum", "Q2P_mass_water_divided_by_dt", params);
271 
272  params = _factory.getValidParams("FunctionValuePostprocessor");
273  params.set<FunctionName>("function") = "Q2P_water_mass_fcn";
274  params.set<std::vector<OutputName>>("outputs") = _output_total_masses_to;
275  _problem->addPostprocessor("FunctionValuePostprocessor", "mass_water", params);
276 
277  params = _factory.getValidParams("NodalSum");
278  params.set<std::vector<OutputName>>("outputs") = {"none"};
279  params.set<std::vector<VariableName>>("variable") = {"Q2P_nodal_gas_mass_divided_by_dt"};
280  _problem->addPostprocessor("NodalSum", "Q2P_mass_gas_divided_by_dt", params);
281 
282  params = _factory.getValidParams("FunctionValuePostprocessor");
283  params.set<FunctionName>("function") = "Q2P_gas_mass_fcn";
284  params.set<std::vector<OutputName>>("outputs") = _output_total_masses_to;
285  _problem->addPostprocessor("FunctionValuePostprocessor", "mass_gas", params);
286  }
287 }
Real _diffusivity
Definition: Q2PAction.h:34
Real _gas_viscosity
Definition: Q2PAction.h:33
UserObjectName _water_density
Definition: Q2PAction.h:27
bool _total_masses_not_outputted
Definition: Q2PAction.h:42
InputParameters validParams< Q2PAction >()
Definition: Q2PAction.C:16
std::vector< OutputName > _output_total_masses_to
Definition: Q2PAction.h:36
UserObjectName _water_relperm
Definition: Q2PAction.h:28
std::vector< OutputName > _output_nodal_masses_to
Definition: Q2PAction.h:35
bool _save_gas_Jacobian_in_Q2PGasJacobian
Definition: Q2PAction.h:39
UserObjectName _water_relperm_for_diffusivity
Definition: Q2PAction.h:29
virtual void act()
Definition: Q2PAction.C:113
bool _save_water_Jacobian_in_Q2PWaterJacobian
Definition: Q2PAction.h:40
bool _save_water_flux_in_Q2PWaterFluxResidual
Definition: Q2PAction.h:38
Real _water_viscosity
Definition: Q2PAction.h:30
bool _save_gas_flux_in_Q2PGasFluxResidual
Definition: Q2PAction.h:37
UserObjectName _gas_density
Definition: Q2PAction.h:31
VariableName _pp_var
Definition: Q2PAction.h:25
VariableName _sat_var
Definition: Q2PAction.h:26
bool _nodal_masses_not_outputted
Definition: Q2PAction.h:41
Q2PAction(const InputParameters &params)
Definition: Q2PAction.C:78
bool _no_mass_calculations
Definition: Q2PAction.h:43
UserObjectName _gas_relperm
Definition: Q2PAction.h:32