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