https://mooseframework.inl.gov
FVPorousFlowAdvectiveFlux.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
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 
11 #include "PorousFlowDictator.h"
12 
14 
17 {
19  RealVectorValue g(0, 0, -9.81);
20  params.addParam<RealVectorValue>("gravity", g, "Gravity vector. Defaults to (0, 0, -9.81)");
21  params.addRequiredParam<UserObjectName>("PorousFlowDictator",
22  "The PorousFlowDictator UserObject");
23  params.addParam<unsigned int>("fluid_component", 0, "The fluid component for this kernel");
24  params.set<unsigned short>("ghost_layers") = 2;
25  params.addClassDescription("Advective Darcy flux");
26  return params;
27 }
28 
30  : FVFluxKernel(params),
31  _dictator(getUserObject<PorousFlowDictator>("PorousFlowDictator")),
32  _num_phases(_dictator.numPhases()),
33  _fluid_component(getParam<unsigned int>("fluid_component")),
34  _density(getADMaterialProperty<std::vector<Real>>("PorousFlow_fluid_phase_density_qp")),
35  _density_neighbor(
36  getNeighborADMaterialProperty<std::vector<Real>>("PorousFlow_fluid_phase_density_qp")),
37  _viscosity(getADMaterialProperty<std::vector<Real>>("PorousFlow_viscosity_qp")),
38  _viscosity_neighbor(
39  getNeighborADMaterialProperty<std::vector<Real>>("PorousFlow_viscosity_qp")),
40  _relperm(getADMaterialProperty<std::vector<Real>>("PorousFlow_relative_permeability_qp")),
41  _relperm_neighbor(
42  getNeighborADMaterialProperty<std::vector<Real>>("PorousFlow_relative_permeability_qp")),
43  _mass_fractions(
44  getADMaterialProperty<std::vector<std::vector<Real>>>("PorousFlow_mass_frac_qp")),
45  _mass_fractions_neighbor(
46  getNeighborADMaterialProperty<std::vector<std::vector<Real>>>("PorousFlow_mass_frac_qp")),
47  _permeability(getADMaterialProperty<RealTensorValue>("PorousFlow_permeability_qp")),
48  _permeability_neighbor(
49  getNeighborADMaterialProperty<RealTensorValue>("PorousFlow_permeability_qp")),
50  _pressure(getADMaterialProperty<std::vector<Real>>("PorousFlow_porepressure_qp")),
51  _pressure_neighbor(
52  getNeighborADMaterialProperty<std::vector<Real>>("PorousFlow_porepressure_qp")),
53  _grad_p(getADMaterialProperty<std::vector<RealGradient>>("PorousFlow_grad_porepressure_qp")),
54  _gravity(getParam<RealVectorValue>("gravity"))
55 {
57  paramError(
58  "fluid_component",
59  "The Dictator proclaims that the maximum fluid component index in this simulation is ",
61  " whereas you have used ",
63  ". Remember that indexing starts at 0. The Dictator does not take such mistakes lightly.");
64 }
65 
66 ADReal
68 {
69  ADReal flux = 0.0;
70  ADRealGradient pressure_grad;
71  ADRealTensorValue mobility;
72 
73  for (const auto p : make_range(_num_phases))
74  {
75  // If we are on a boundary face, use the gradient computed in _grad_p
76  if (onBoundary(*_face_info))
77  {
78  const auto & gradp = -_grad_p[_qp][p];
79  pressure_grad = gradp + _density[_qp][p] * _gravity;
80 
82  _density[_qp][p] / _viscosity[_qp][p];
83  }
84  else
85  {
86  // If we are on an internal face, calculate the gradient explicitly
87  const auto & p_elem = _pressure[_qp][p];
88  const auto & p_neighbor = _pressure_neighbor[_qp][p];
89 
90  const auto gradp = (p_elem - p_neighbor) * _face_info->eCN() / _face_info->dCNMag();
91 
92  const auto mobility_element = _mass_fractions[_qp][p][_fluid_component] * _relperm[_qp][p] *
94 
95  const auto mobility_neighbor = _mass_fractions_neighbor[_qp][p][_fluid_component] *
98 
99  pressure_grad = gradp + _density[_qp][p] * _gravity;
100 
102  mobility,
103  mobility_element,
104  mobility_neighbor,
105  pressure_grad,
106  *_face_info,
107  true);
108  }
109 
110  flux += mobility * pressure_grad * _normal;
111  }
112 
113  return flux;
114 }
static InputParameters validParams()
const ADMaterialProperty< std::vector< RealGradient > > & _grad_p
const RealVectorValue & _gravity
Gravity vector.
const ADMaterialProperty< RealTensorValue > & _permeability
Permeability.
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
const FaceInfo * _face_info
T & set(const std::string &name, bool quiet_mode=false)
virtual ADReal computeQpResidual() override
unsigned int numComponents() const
The number of fluid components.
RealVectorValue _normal
DualNumber< Real, DNDerivativeType, true > ADReal
void addRequiredParam(const std::string &name, const std::string &doc_string)
const ADMaterialProperty< std::vector< std::vector< Real > > > & _mass_fractions
Mass fraction of fluid components in fluid phases.
bool onBoundary(const FaceInfo &fi) const
TensorValue< Real > RealTensorValue
static InputParameters validParams()
const ADMaterialProperty< std::vector< Real > > & _viscosity_neighbor
const PorousFlowDictator & _dictator
UserObject that holds information (number of phases, components, etc)
const unsigned int _qp
const ADMaterialProperty< std::vector< Real > > & _viscosity
Fluid viscosity.
const ADMaterialProperty< std::vector< Real > > & _density
Fluid density.
void paramError(const std::string &param, Args... args) const
const unsigned int _fluid_component
Index of the fluid component this kernel applies to.
const ADMaterialProperty< std::vector< std::vector< Real > > > & _mass_fractions_neighbor
const ADMaterialProperty< std::vector< Real > > & _density_neighbor
Real dCNMag() const
FVPorousFlowAdvectiveFlux(const InputParameters &params)
const unsigned int _num_phases
Number of fluid phases present.
const ADMaterialProperty< std::vector< Real > > & _relperm_neighbor
const ADMaterialProperty< std::vector< Real > > & _relperm
Relative permeability.
const ADMaterialProperty< std::vector< Real > > & _pressure
Fluid pressure.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const Point & eCN() const
This holds maps between the nonlinear variables used in a PorousFlow simulation and the variable numb...
IntRange< T > make_range(T beg, T end)
Advective flux of fluid component k in fluid phase alpha.
void addClassDescription(const std::string &doc_string)
const ADMaterialProperty< RealTensorValue > & _permeability_neighbor
const ADMaterialProperty< std::vector< Real > > & _pressure_neighbor
void interpolate(InterpMethod m, T &result, const T2 &value1, const T3 &value2, const FaceInfo &fi, const bool one_is_elem)
void ErrorVector unsigned int
registerADMooseObject("PorousFlowApp", FVPorousFlowAdvectiveFlux)