www.mooseframework.org
Q2PNodalMass.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 
8 #include "Q2PNodalMass.h"
9 
10 // MOOSE includes
11 #include "MooseVariable.h"
12 
13 // C++ includes
14 #include <iostream>
15 
16 template <>
17 InputParameters
19 {
20  InputParameters params = validParams<TimeKernel>();
21  params.addRequiredParam<UserObjectName>(
22  "fluid_density",
23  "A RichardsDensity UserObject that defines the fluid density as a function of pressure.");
24  params.addRequiredCoupledVar("other_var",
25  "The other variable in the 2-phase system. If "
26  "Variable=porepressure, then other_var should be the "
27  "saturation Variable, and vice-versa.");
28  params.addRequiredParam<bool>(
29  "var_is_porepressure",
30  "This flag is needed to correctly calculate the Jacobian entries. If "
31  "set to true, this Kernel will assume it is describing the mass of "
32  "the phase with porepressure as its Variable (eg, the liquid phase). "
33  "If set to false, this Kernel will assumed it is describing the mass "
34  "of the phase with saturation as its variable (eg, the gas phase)");
35  params.addClassDescription("Fluid mass lumped to the nodes divided by dt");
36  return params;
37 }
38 
39 Q2PNodalMass::Q2PNodalMass(const InputParameters & parameters)
40  : TimeKernel(parameters),
41  _density(getUserObject<RichardsDensity>("fluid_density")),
42  _other_var_nodal(coupledNodalValue("other_var")),
43  _other_var_num(coupled("other_var")),
44  _var_is_pp(getParam<bool>("var_is_porepressure")),
45  _porosity(getMaterialProperty<Real>("porosity"))
46 {
47 }
48 
49 Real
51 {
52  Real density;
53  Real mass;
54 
55  if (_var_is_pp)
56  {
57  density = _density.density(_var.nodalSln()[_i]);
58  mass = _porosity[_qp] * density * (1 - _other_var_nodal[_i]);
59  }
60  else
61  {
62  density = _density.density(_other_var_nodal[_i]);
63  mass = _porosity[_qp] * density * _var.nodalSln()[_i];
64  }
65 
66  return _test[_i][_qp] * mass / _dt;
67 }
68 
69 Real
71 {
72  if (_i != _j)
73  return 0.0;
74 
75  Real mass_prime;
76 
77  if (_var_is_pp)
78  {
79  // we're calculating the derivative wrt porepressure
80  Real ddensity = _density.ddensity(_var.nodalSln()[_i]);
81  mass_prime = _porosity[_qp] * ddensity * (1 - _other_var_nodal[_i]);
82  }
83  else
84  {
85  // we're calculating the deriv wrt saturation
87  mass_prime = _porosity[_qp] * density;
88  }
89 
90  return _test[_i][_qp] * mass_prime / _dt;
91 }
92 
93 Real
95 {
96  if (jvar != _other_var_num)
97  return 0.0;
98  if (_i != _j)
99  return 0.0;
100 
101  Real mass_prime;
102 
103  if (_var_is_pp)
104  {
105  // we're calculating the deriv wrt saturation
106  Real density = _density.density(_var.nodalSln()[_i]);
107  mass_prime = -_porosity[_qp] * density;
108  }
109  else
110  {
111  // we're calculating the deriv wrt porepressure
112  Real ddensity = _density.ddensity(_other_var_nodal[_i]);
113  mass_prime = _porosity[_qp] * ddensity * _var.nodalSln()[_i];
114  }
115 
116  return _test[_i][_qp] * mass_prime / _dt;
117 }
unsigned int _other_var_num
variable number of the other variable
Definition: Q2PNodalMass.h:42
const RichardsDensity & _density
Definition: Q2PNodalMass.h:36
const std::string density
Definition: NS.h:15
virtual Real computeQpOffDiagJacobian(unsigned int jvar)
Definition: Q2PNodalMass.C:94
virtual Real density(Real p) const =0
fluid density as a function of porepressure This must be over-ridden in derived classes to provide an...
InputParameters validParams< Q2PNodalMass >()
Definition: Q2PNodalMass.C:18
Q2PNodalMass(const InputParameters &parameters)
Definition: Q2PNodalMass.C:39
const VariableValue & _other_var_nodal
the other variable (this is porepressure if the Variable is saturation)
Definition: Q2PNodalMass.h:39
bool _var_is_pp
whether the "other variable" is actually porepressure
Definition: Q2PNodalMass.h:45
const MaterialProperty< Real > & _porosity
current value of the porosity
Definition: Q2PNodalMass.h:48
virtual Real computeQpResidual()
Definition: Q2PNodalMass.C:50
virtual Real ddensity(Real p) const =0
derivative of fluid density wrt porepressure This must be over-ridden in derived classes to provide a...
Base class for fluid density as a function of porepressure The functions density, ddensity and d2dens...
virtual Real computeQpJacobian()
Definition: Q2PNodalMass.C:70