https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
26template <bool is_ad>
28{
29public:
31
33
34protected:
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
135 const RealVectorValue _gravity;
136
138 const bool _perm_derivs;
139
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
214 using GenericKernel<is_ad>::_grad_phi;
215
216private:
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
typename GenericMaterialPropertyStruct< T, is_ad >::type GenericMaterialProperty
Moose::GenericType< Real, is_ad > GenericReal
PorousFlowDarcyBaseTempl< true > ADPorousFlowDarcyBase
PorousFlowDarcyBaseTempl< false > PorousFlowDarcyBase
const VariablePhiGradient & _grad_phi
const InputParameters & parameters() const
Darcy advective flux.
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 p...
const GenericMaterialProperty< RealTensorValue, is_ad > & _permeability
Permeability of porous material.
virtual Real darcyQpJacobian(unsigned int jvar, unsigned int ph) const
Jacobian of the Darcy part of the flux – non-AD path only.
void updateUpwindCounts(unsigned elem, unsigned int num_nodes)
Update upwind/downwind counters from the sign of _proto_flux.
void adComputeProtoFlux(bool do_counting)
For the AD path: fills _proto_flux (per-phase, per-node ADReal) by integrating darcyQp and applying t...
virtual void computeResidualAndJacobian()
virtual Real dmobility(unsigned nodenum, unsigned phase, unsigned pvar) const
The derivative of mobility with respect to PorousFlow variable pvar – non-AD path only.
std::vector< unsigned > computeMaxSwaps(unsigned elem, unsigned int num_nodes) const
Compute per-phase maximum upwind/downwind swap counts for this element.
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...
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 GenericMaterialProperty< std::vector< Real >, is_ad > & _pp
Nodal pore pressure in each phase.
const PorousFlowDictator & _dictator
PorousFlowDictator UserObject.
void applyUpwinding(const std::vector< unsigned > &max_swaps, JacRes res_or_jac, unsigned int pvar)
Apply selected upwinding/fallback scheme for all phases.
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< RealTensorValue > > *const _dpermeability_dvar
d(permeabiity)/d(PorousFlow variable) – null for AD path
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.
static InputParameters validParams()
const RealVectorValue _gravity
Gravity. Defaults to 9.81 m/s^2.
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.
virtual void computeResidual() override
virtual GenericReal< is_ad > computeQpResidual() override
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 pat...
std::vector< std::vector< GenericReal< is_ad > > > _proto_flux
The Darcy flux.
const Elem * _my_elem_darcy
Element pointer cached on the first AD computeOffDiagJacobian() call for an element so that the remai...
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.
std::vector< std::vector< std::vector< Real > > > _jacobian
Derivative of _proto_flux with respect to nodal variables.
virtual GenericReal< is_ad > mobility(unsigned nodenum, unsigned phase) const
The mobility of the fluid.
const GenericMaterialProperty< std::vector< RealGradient >, is_ad > & _grad_p
Gradient of the pore pressure in each phase.
virtual void timestepSetup() override
virtual void computeOffDiagJacobian(unsigned int jvar) override
const unsigned _full_upwind_threshold
If the number of upwind-downwind swaps is less than this amount then full upwinding is used.
const MaterialProperty< std::vector< std::vector< RealTensorValue > > > *const _dpermeability_dgradvar
d(permeabiity)/d(grad(PorousFlow variable)) – null for AD path
void assembleProtoFluxResidual()
Assemble the real-valued residual vector from _proto_flux into the tagged local residual (and apply s...
const unsigned int _num_phases
The number of fluid phases.
void fullyUpwind(JacRes res_or_jac, unsigned int ph, unsigned int pvar)
Calculate the residual or Jacobian using full upwinding.
const bool _perm_derivs
Flag to check whether permeabiity derivatives are non-zero.
const GenericMaterialProperty< std::vector< Real >, is_ad > & _fluid_density_qp
Fluid density for each phase (at the qp)
const GenericMaterialProperty< std::vector< Real >, is_ad > & _fluid_density_node
Fluid density for each phase (at the node)
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.
enum PorousFlowDarcyBaseTempl::FallbackEnum _fallback_scheme
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 ...
void computeProtoFluxWithoutMobility()
Build proto fluxes (without mobility weighting) for all phases and nodes.
virtual void computeJacobian() override
FallbackEnum
If full upwinding is failing due to nodes swapping between upwind and downwind in successive nonlinea...
virtual GenericReal< is_ad > darcyQp(unsigned int ph) const
The Darcy part of the flux (this is the non-upwinded part)
virtual void jacobianSetup() override
This holds maps between the nonlinear variables used in a PorousFlow simulation and the variable numb...
virtual void computeResidualAndJacobian()