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