www.mooseframework.org
RichardsFlux.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 "RichardsFlux.h"
11 
12 // MOOSE includes
13 #include "Material.h"
14 #include "MooseVariable.h"
15 
16 // C++ includes
17 #include <iostream>
18 
19 registerMooseObject("RichardsApp", RichardsFlux);
20 
21 template <>
22 InputParameters
24 {
25  InputParameters params = validParams<Kernel>();
26  params.addParam<bool>(
27  "linear_shape_fcns",
28  true,
29  "If you are using second-order Lagrange shape functions you need to set this to false.");
30  params.addRequiredParam<UserObjectName>(
31  "richardsVarNames_UO", "The UserObject that holds the list of Richards variable names.");
32  return params;
33 }
34 
35 RichardsFlux::RichardsFlux(const InputParameters & parameters)
36  : Kernel(parameters),
37  _richards_name_UO(getUserObject<RichardsVarNames>("richardsVarNames_UO")),
38  _pvar(_richards_name_UO.richards_var_num(_var.number())),
39 
40  // This kernel gets lots of things from the material
41  _flux(getMaterialProperty<std::vector<RealVectorValue>>("flux")),
42  _dflux_dv(getMaterialProperty<std::vector<std::vector<RealVectorValue>>>("dflux_dv")),
43  _dflux_dgradv(getMaterialProperty<std::vector<std::vector<RealTensorValue>>>("dflux_dgradv")),
44  _d2flux_dvdv(
45  getMaterialProperty<std::vector<std::vector<std::vector<RealVectorValue>>>>("d2flux_dvdv")),
46  _d2flux_dgradvdv(getMaterialProperty<std::vector<std::vector<std::vector<RealTensorValue>>>>(
47  "d2flux_dgradvdv")),
48  _d2flux_dvdgradv(getMaterialProperty<std::vector<std::vector<std::vector<RealTensorValue>>>>(
49  "d2flux_dvdgradv")),
50 
51  _second_u(getParam<bool>("linear_shape_fcns")
52  ? _second_zero
53  : (_is_implicit ? _var.secondSln() : _var.secondSlnOld())),
54  _second_phi(getParam<bool>("linear_shape_fcns") ? _second_phi_zero : secondPhi()),
55 
56  _tauvel_SUPG(getMaterialProperty<std::vector<RealVectorValue>>("tauvel_SUPG")),
57  _dtauvel_SUPG_dgradv(
58  getMaterialProperty<std::vector<std::vector<RealTensorValue>>>("dtauvel_SUPG_dgradv")),
59  _dtauvel_SUPG_dv(
60  getMaterialProperty<std::vector<std::vector<RealVectorValue>>>("dtauvel_SUPG_dv"))
61 {
62 }
63 
64 Real
66 {
67  Real flux_part = _grad_test[_i][_qp] * _flux[_qp][_pvar];
68 
69  Real supg_test = _tauvel_SUPG[_qp][_pvar] * _grad_test[_i][_qp];
70  Real supg_kernel = 0.0;
71  if (supg_test != 0)
72  // NOTE: Libmesh does not correctly calculate grad(_grad_u) correctly, so following might not be
73  // correct
74  // NOTE: The following is -divergence(flux)
75  // NOTE: The following must be generalised if a non PPPP formalism is used
76  // NOTE: The generalisation will look like
77  // supg_kernel = sum_j {-(_dflux_dgradv[_qp][_pvar][j]*_second_u[_qp][j]).tr() -
78  // _dflux_dv[_qp][_pvar][j]*_grad_u[_qp][j]}
79  // where _grad_u[_qp][j] is the gradient of the j^th variable at the quadpoint.
80  supg_kernel = -(_dflux_dgradv[_qp][_pvar][_pvar] * _second_u[_qp]).tr() -
81  _dflux_dv[_qp][_pvar][_pvar] * _grad_u[_qp];
82 
83  return flux_part + supg_test * supg_kernel;
84 }
85 
86 Real
87 RichardsFlux::computeQpJac(unsigned int wrt_num)
88 {
89  Real flux_prime = _grad_test[_i][_qp] * (_dflux_dgradv[_qp][_pvar][wrt_num] * _grad_phi[_j][_qp] +
90  _dflux_dv[_qp][_pvar][wrt_num] * _phi[_j][_qp]);
91 
92  Real supg_test = _tauvel_SUPG[_qp][_pvar] * _grad_test[_i][_qp];
93  Real supg_test_prime =
94  _grad_phi[_j][_qp] * (_dtauvel_SUPG_dgradv[_qp][_pvar][wrt_num] * _grad_test[_i][_qp]) +
95  _phi[_j][_qp] * _dtauvel_SUPG_dv[_qp][_pvar][wrt_num] * _grad_test[_i][_qp];
96  Real supg_kernel = 0.0;
97  Real supg_kernel_prime = 0.0;
98 
99  if (supg_test != 0)
100  {
101  // NOTE: since Libmesh does not correctly calculate grad(_grad_u) correctly, so following might
102  // not be correct
103  supg_kernel = -(_dflux_dgradv[_qp][_pvar][_pvar] * _second_u[_qp]).tr() -
104  _dflux_dv[_qp][_pvar][_pvar] * _grad_u[_qp];
105 
106  // NOTE: just like supg_kernel, this must be generalised for non-PPPP formulations
107  supg_kernel_prime =
108  -(_d2flux_dvdv[_qp][_pvar][_pvar][wrt_num] * _phi[_j][_qp] * _grad_u[_qp] +
109  _phi[_j][_qp] * (_d2flux_dgradvdv[_qp][_pvar][_pvar][wrt_num] * _second_u[_qp]).tr() +
110  (_d2flux_dvdgradv[_qp][_pvar][_pvar][wrt_num] * _grad_u[_qp]) * _grad_phi[_j][_qp]);
111  if (wrt_num == _pvar)
112  supg_kernel_prime -= _dflux_dv[_qp][_pvar][_pvar] * _grad_phi[_j][_qp];
113  supg_kernel_prime -= (_dflux_dgradv[_qp][_pvar][_pvar] * _second_phi[_j][_qp]).tr();
114  }
115 
116  return flux_prime + supg_test_prime * supg_kernel + supg_test * supg_kernel_prime;
117 }
118 
119 Real
121 {
122  return computeQpJac(_pvar);
123 }
124 
125 Real
127 {
129  return 0.0;
130  unsigned int dvar = _richards_name_UO.richards_var_num(jvar);
131  return computeQpJac(dvar);
132 }
RichardsFlux::_tauvel_SUPG
const MaterialProperty< std::vector< RealVectorValue > > & _tauvel_SUPG
SUPGtau*SUPGvel (a vector of these if multiphase)
Definition: RichardsFlux.h:77
RichardsFlux::_dflux_dgradv
const MaterialProperty< std::vector< std::vector< RealTensorValue > > > & _dflux_dgradv
d(Richards flux_i)/d(grad(variable_j)), here flux_i is the i_th flux, which is itself a RealVectorVal...
Definition: RichardsFlux.h:59
RichardsFlux
Kernel = grad(permeability*relativepermeability/viscosity * (grad(pressure) - density*gravity)) This ...
Definition: RichardsFlux.h:25
RichardsFlux::_dtauvel_SUPG_dv
const MaterialProperty< std::vector< std::vector< RealVectorValue > > > & _dtauvel_SUPG_dv
derivative of SUPGtau*SUPGvel_i wrt variable_j
Definition: RichardsFlux.h:83
RichardsFlux::_d2flux_dgradvdv
const MaterialProperty< std::vector< std::vector< std::vector< RealTensorValue > > > > & _d2flux_dgradvdv
d^2(Richards flux_i)/d(grad(variable_j))/d(variable_k), here flux_i is the i_th flux,...
Definition: RichardsFlux.h:65
RichardsVarNames::richards_var_num
unsigned int richards_var_num(unsigned int moose_var_num) const
the richards variable number
Definition: RichardsVarNames.C:99
RichardsFlux::_d2flux_dvdgradv
const MaterialProperty< std::vector< std::vector< std::vector< RealTensorValue > > > > & _d2flux_dvdgradv
d^2(Richards flux_i)/d(variable_j)/d(grad(variable_k)), here flux_i is the i_th flux,...
Definition: RichardsFlux.h:68
RichardsFlux::computeQpResidual
virtual Real computeQpResidual()
Definition: RichardsFlux.C:65
RichardsFlux::_d2flux_dvdv
const MaterialProperty< std::vector< std::vector< std::vector< RealVectorValue > > > > & _d2flux_dvdv
d^2(Richards flux_i)/d(variable_j)/d(variable_k), here flux_i is the i_th flux, which is itself a Rea...
Definition: RichardsFlux.h:62
RichardsVarNames
This holds maps between pressure_var or pressure_var, sat_var used in RichardsMaterial and kernels,...
Definition: RichardsVarNames.h:25
registerMooseObject
registerMooseObject("RichardsApp", RichardsFlux)
RichardsFlux::_richards_name_UO
const RichardsVarNames & _richards_name_UO
holds info regarding the names of the Richards variables and methods for extracting values of these v...
Definition: RichardsFlux.h:41
RichardsFlux::computeQpOffDiagJacobian
virtual Real computeQpOffDiagJacobian(unsigned int jvar)
Definition: RichardsFlux.C:126
RichardsFlux::_dtauvel_SUPG_dgradv
const MaterialProperty< std::vector< std::vector< RealTensorValue > > > & _dtauvel_SUPG_dgradv
derivative of SUPGtau*SUPGvel_i wrt grad(variable_j)
Definition: RichardsFlux.h:80
validParams< RichardsFlux >
InputParameters validParams< RichardsFlux >()
Definition: RichardsFlux.C:23
RichardsFlux::RichardsFlux
RichardsFlux(const InputParameters &parameters)
Definition: RichardsFlux.C:35
RichardsFlux::_second_phi
const VariablePhiSecond & _second_phi
interpolation function for the _second_u
Definition: RichardsFlux.h:74
RichardsFlux::computeQpJac
Real computeQpJac(unsigned int wrt_num)
Computes diagonal and off-diagonal jacobian entries.
Definition: RichardsFlux.C:87
RichardsFlux::_second_u
const VariableSecond & _second_u
grad_i grad_j porepressure. This is used in SUPG
Definition: RichardsFlux.h:71
RichardsFlux::_dflux_dv
const MaterialProperty< std::vector< std::vector< RealVectorValue > > > & _dflux_dv
d(Richards flux_i)/d(variable_j), here flux_i is the i_th flux, which is itself a RealVectorValue
Definition: RichardsFlux.h:56
RichardsFlux::_flux
const MaterialProperty< std::vector< RealVectorValue > > & _flux
Richards flux.
Definition: RichardsFlux.h:53
RichardsFlux.h
RichardsVarNames::not_richards_var
bool not_richards_var(unsigned int moose_var_num) const
returns true if moose_var_num is not a richards var
Definition: RichardsVarNames.C:109
RichardsFlux::_pvar
unsigned int _pvar
the index of this variable in the list of Richards variables held by _richards_name_UO.
Definition: RichardsFlux.h:50
RichardsFlux::computeQpJacobian
virtual Real computeQpJacobian()
Definition: RichardsFlux.C:120