https://mooseframework.inl.gov
PorousFlowDarcyBase.h
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 
10 #pragma once
11 
12 #include "GenericKernel.h"
13 #include "PorousFlowDictator.h"
14 
26 template <bool is_ad>
28 {
29 public:
31 
33 
34 protected:
35  virtual void timestepSetup() override;
36  virtual void jacobianSetup() override;
37  virtual GenericReal<is_ad> computeQpResidual() override;
38  virtual void computeResidual() override;
39  virtual void computeJacobian() override;
40  virtual void computeOffDiagJacobian(unsigned int jvar) override;
41 
43  virtual GenericReal<is_ad> darcyQp(unsigned int ph) const;
44 
46  virtual Real darcyQpJacobian(unsigned int jvar, unsigned int ph) const;
47 
54  virtual GenericReal<is_ad> mobility(unsigned nodenum, unsigned phase) const;
55 
62  virtual Real dmobility(unsigned nodenum, unsigned phase, unsigned pvar) const;
63 
64  enum class JacRes
65  {
68  };
69 
71 
87  void computeResidualAndJacobian(JacRes res_or_jac, unsigned int jvar);
88 
91 
94 
97 
100 
103 
106 
109 
112 
115 
118 
121 
124 
127 
130 
132  const unsigned int _num_phases;
133 
136 
138  const bool _perm_derivs;
139 
144  const unsigned _full_upwind_threshold;
145 
156 
163  std::vector<std::vector<GenericReal<is_ad>>> _proto_flux;
164 
170  std::vector<std::vector<std::vector<Real>>> _jacobian;
171 
177  std::unordered_map<unsigned, std::vector<std::vector<unsigned>>> _num_upwinds;
178 
184  std::unordered_map<unsigned, std::vector<std::vector<unsigned>>> _num_downwinds;
185 
193  void fullyUpwind(JacRes res_or_jac, unsigned int ph, unsigned int pvar);
194 
202  void quickUpwind(JacRes res_or_jac, unsigned int ph, unsigned int pvar);
203 
211  void harmonicMean(JacRes res_or_jac, unsigned int ph, unsigned int pvar);
212 
215 
216 private:
219 
221  void initializeUpwindTracking(unsigned elem, unsigned int num_nodes);
222 
224  void updateUpwindCounts(unsigned elem, unsigned int num_nodes);
225 
227  std::vector<unsigned> computeMaxSwaps(unsigned elem, unsigned int num_nodes) const;
228 
230  void
231  applyUpwinding(const std::vector<unsigned> & max_swaps, JacRes res_or_jac, unsigned int pvar);
232 
239  void adComputeProtoFlux(bool do_counting);
240 
246  void adComputeJacobian();
247 
251 
255  const Elem * _my_elem_darcy = nullptr;
256 };
257 
virtual void computeResidualAndJacobian()
const MaterialProperty< std::vector< std::vector< Real > > > *const _dfluid_density_qp_dvar
Derivative of the fluid density for each phase wrt PorousFlow variables (at the qp) – null for AD pa...
Moose::GenericType< Real, is_ad > GenericReal
virtual GenericReal< is_ad > darcyQp(unsigned int ph) const
The Darcy part of the flux (this is the non-upwinded part)
const GenericMaterialProperty< std::vector< Real >, is_ad > & _fluid_density_node
Fluid density for each phase (at the node)
const Elem * _my_elem_darcy
Element pointer cached on the first AD computeOffDiagJacobian() call for an element so that the remai...
void applyUpwinding(const std::vector< unsigned > &max_swaps, JacRes res_or_jac, unsigned int pvar)
Apply selected upwinding/fallback scheme for all phases.
std::unordered_map< unsigned, std::vector< std::vector< unsigned > > > _num_upwinds
Number of nonlinear iterations (in this timestep and this element) that a node is an upwind node for ...
const bool _perm_derivs
Flag to check whether permeabiity derivatives are non-zero.
void fullyUpwind(JacRes res_or_jac, unsigned int ph, unsigned int pvar)
Calculate the residual or Jacobian using full upwinding.
const InputParameters & parameters() const
enum PorousFlowDarcyBaseTempl::FallbackEnum _fallback_scheme
std::vector< std::vector< GenericReal< is_ad > > > _proto_flux
The Darcy flux.
virtual void computeResidualAndJacobian() override
void adComputeProtoFlux(bool do_counting)
For the AD path: fills _proto_flux (per-phase, per-node ADReal) by integrating darcyQp and applying t...
const MaterialProperty< std::vector< RealTensorValue > > *const _dpermeability_dvar
d(permeabiity)/d(PorousFlow variable) – null for AD path
Darcy advective flux.
const PorousFlowDictator & _dictator
PorousFlowDictator UserObject.
std::vector< std::vector< std::vector< Real > > > _jacobian
Derivative of _proto_flux with respect to nodal variables.
virtual void computeResidual() override
std::vector< unsigned > computeMaxSwaps(unsigned elem, unsigned int num_nodes) const
Compute per-phase maximum upwind/downwind swap counts for this element.
const GenericMaterialProperty< RealTensorValue, is_ad > & _permeability
Permeability of porous material.
const GenericMaterialProperty< std::vector< Real >, is_ad > & _pp
Nodal pore pressure in each phase.
void assembleProtoFluxResidual()
Assemble the real-valued residual vector from _proto_flux into the tagged local residual (and apply s...
PorousFlowDarcyBaseTempl(const InputParameters &parameters)
void quickUpwind(JacRes res_or_jac, unsigned int ph, unsigned int pvar)
Calculate the residual or Jacobian using the nodal mobilities, but without conserving fluid mass...
const RealVectorValue _gravity
Gravity. Defaults to 9.81 m/s^2.
virtual void computeOffDiagJacobian(unsigned int jvar) override
void initializeUpwindTracking(unsigned elem, unsigned int num_nodes)
Ensure per-element upwind/downwind counters are allocated for this element.
const GenericMaterialProperty< std::vector< Real >, is_ad > & _fluid_viscosity
Viscosity of each component in each phase.
typename GenericMaterialPropertyStruct< T, is_ad >::type GenericMaterialProperty
virtual void timestepSetup() override
void computeProtoFluxWithoutMobility()
Build proto fluxes (without mobility weighting) for all phases and nodes.
static InputParameters validParams()
void harmonicMean(JacRes res_or_jac, unsigned int ph, unsigned int pvar)
Calculate the residual or Jacobian by using the harmonic mean of the nodal mobilities for the entire ...
PorousFlowDarcyBaseTempl< true > ADPorousFlowDarcyBase
const MaterialProperty< std::vector< std::vector< Real > > > *const _dfluid_viscosity_dvar
Derivative of the fluid viscosity for each phase wrt PorousFlow variables – null for AD path...
const MaterialProperty< std::vector< std::vector< RealTensorValue > > > *const _dpermeability_dgradvar
d(permeabiity)/d(grad(PorousFlow variable)) – null for AD path
void adComputeJacobian()
For the AD path: performs the proto-flux/upwinding pass and hands the per-node ADReal residuals to ad...
const MaterialProperty< std::vector< std::vector< RealGradient > > > *const _dgrad_p_dvar
Derivative of Grad porepressure in each phase wrt PorousFlow variables – null for AD path...
const unsigned int _num_phases
The number of fluid phases.
const GenericMaterialProperty< std::vector< Real >, is_ad > & _fluid_density_qp
Fluid density for each phase (at the qp)
const MaterialProperty< std::vector< std::vector< Real > > > *const _dgrad_p_dgrad_var
Derivative of Grad porepressure in each phase wrt grad(PorousFlow variables) – null for AD path...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual Real darcyQpJacobian(unsigned int jvar, unsigned int ph) const
Jacobian of the Darcy part of the flux – non-AD path only.
This holds maps between the nonlinear variables used in a PorousFlow simulation and the variable numb...
virtual Real dmobility(unsigned nodenum, unsigned phase, unsigned pvar) const
The derivative of mobility with respect to PorousFlow variable pvar – non-AD path only...
virtual void jacobianSetup() override
virtual GenericReal< is_ad > mobility(unsigned nodenum, unsigned phase) const
The mobility of the fluid.
std::unordered_map< unsigned, std::vector< std::vector< unsigned > > > _num_downwinds
Number of nonlinear iterations (in this timestep and this element) that a node is an downwind node fo...
const unsigned _full_upwind_threshold
If the number of upwind-downwind swaps is less than this amount then full upwinding is used...
void updateUpwindCounts(unsigned elem, unsigned int num_nodes)
Update upwind/downwind counters from the sign of _proto_flux.
virtual GenericReal< is_ad > computeQpResidual() override
PorousFlowDarcyBaseTempl< false > PorousFlowDarcyBase
const MaterialProperty< std::vector< std::vector< Real > > > *const _dfluid_density_node_dvar
Derivative of the fluid density for each phase wrt PorousFlow variables (at the node) – null for AD ...
virtual void computeJacobian() override
const GenericMaterialProperty< std::vector< RealGradient >, is_ad > & _grad_p
Gradient of the pore pressure in each phase.
FallbackEnum
If full upwinding is failing due to nodes swapping between upwind and downwind in successive nonlinea...