https://mooseframework.inl.gov
LinearFVDiffusion.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 
10 #include "LinearFVDiffusion.h"
11 #include "Assembly.h"
12 #include "SubProblem.h"
14 
16 
19 {
21  params.addClassDescription("Represents the matrix and right hand side contributions of a "
22  "diffusion term in a partial differential equation.");
23  params.addParam<bool>(
24  "use_nonorthogonal_correction",
25  true,
26  "If the nonorthogonal correction should be used when computing the normal gradient.");
27  params.addParam<MooseFunctorName>("diffusion_coeff", 1.0, "The diffusion coefficient.");
28  return params;
29 }
30 
32  : LinearFVFluxKernel(params),
33  _diffusion_coeff(getFunctor<Real>("diffusion_coeff")),
34  _use_nonorthogonal_correction(getParam<bool>("use_nonorthogonal_correction")),
35  _flux_matrix_contribution(0.0),
36  _flux_rhs_contribution(0.0)
37 {
40 }
41 
42 void
44 {
45  for (const auto bc : _var.getBoundaryConditionMap())
46  if (!dynamic_cast<const LinearFVAdvectionDiffusionBC *>(bc.second))
47  mooseError(
48  bc.second->type(), " is not a compatible boundary condition with ", this->type(), "!");
49 }
50 
51 Real
53 {
55 }
56 
57 Real
59 {
61 }
62 
63 Real
65 {
67 }
68 
69 Real
71 {
73 }
74 
75 Real
77 {
78  // If we don't have the value yet, we compute it
80  {
81  const auto face_arg = makeCDFace(*_current_face_info);
82 
83  // If we requested nonorthogonal correction, we use the normal component of the
84  // cell to face vector.
85  const auto d = _use_nonorthogonal_correction
88 
89  // Cache the matrix contribution
93  }
94 
96 }
97 
98 Real
100 {
101  // We only have contributions on the right hand side from internal faces
102  // if the nonorthogonal correction is enabled.
104  {
105  const auto face_arg = makeCDFace(*_current_face_info);
106  const auto state_arg = determineState();
107 
108  // Get the gradients from the adjacent cells
109  const auto grad_elem = _var.gradSln(*_current_face_info->elemInfo());
110  const auto & grad_neighbor = _var.gradSln(*_current_face_info->neighborInfo());
111 
112  // Interpolate the two gradients to the face
113  const auto interp_coeffs =
115 
116  // Compute correction vector. Potential optimization: this only depends on the geometry
117  // so we can cache it in FaceInfo at some point.
118  const auto correction_vector =
121 
122  // Cache the matrix contribution
124  _diffusion_coeff(face_arg, state_arg) *
125  (interp_coeffs.first * grad_elem + interp_coeffs.second * grad_neighbor) *
126  correction_vector * _current_face_area;
128  }
129 
130  return _flux_rhs_contribution;
131 }
132 
133 Real
135 {
136  const auto * const diff_bc = static_cast<const LinearFVAdvectionDiffusionBC *>(&bc);
137  mooseAssert(diff_bc, "This should be a valid BC!");
138 
139  auto grad_contrib = diff_bc->computeBoundaryGradientMatrixContribution() * _current_face_area;
140  // If the boundary condition does not include the diffusivity contribution then
141  // add it here.
142  if (!diff_bc->includesMaterialPropertyMultiplier())
143  {
144  const auto face_arg = singleSidedFaceArg(_current_face_info);
145  grad_contrib *= _diffusion_coeff(face_arg, determineState());
146  }
147 
148  return grad_contrib;
149 }
150 
151 Real
153 {
154  const auto * const diff_bc = static_cast<const LinearFVAdvectionDiffusionBC *>(&bc);
155  mooseAssert(diff_bc, "This should be a valid BC!");
156 
157  const auto face_arg = singleSidedFaceArg(_current_face_info);
158  auto grad_contrib = diff_bc->computeBoundaryGradientRHSContribution() * _current_face_area;
159 
160  // If the boundary condition does not include the diffusivity contribution then
161  // add it here.
162  if (!diff_bc->includesMaterialPropertyMultiplier())
163  grad_contrib *= _diffusion_coeff(face_arg, determineState());
164 
165  // We add the nonorthogonal corrector for the face here. Potential idea: we could do
166  // this in the boundary condition too. For now, however, we keep it like this.
167  // This should only be used for BCs where the gradient of the value is computed and
168  // not prescribed.
169 
170  if (_use_nonorthogonal_correction && diff_bc->useBoundaryGradientExtrapolation())
171  {
172  // We support internal boundaries as well. In that case we have to decide on which side
173  // of the boundary we are on.
174  const auto elem_info = (_current_face_type == FaceInfo::VarFaceNeighbors::ELEM)
177  const Real boundary_normal_multiplier =
179 
180  // Unit vector to the boundary. Unfortunately, we have to recompute it because the value
181  // stored in the face info is only correct for external boundaries
182  const auto e_Cf = _current_face_info->faceCentroid() - elem_info->centroid();
183  const auto correction_vector =
184  _current_face_info->normal() - 1 / (_current_face_info->normal() * e_Cf) * e_Cf;
185 
186  grad_contrib += _diffusion_coeff(face_arg, determineState()) * _var.gradSln(*elem_info) *
187  boundary_normal_multiplier * correction_vector * _current_face_area;
188  }
189 
190  return grad_contrib;
191 }
virtual Real computeElemMatrixContribution() override
Computes the system matrix contribution from an element side on an internal face. ...
MetaPhysicL::DualNumber< V, D, asd > abs(const MetaPhysicL::DualNumber< V, D, asd > &a)
Definition: EigenADReal.h:42
gc*elem+(1-gc)*neighbor
Base class for boundary conditions for linear FV systems.
Kernel that adds contributions from a diffusion term discretized using the finite volume method to a ...
const Moose::Functor< Real > & _diffusion_coeff
The functor for the diffusion coefficient.
virtual Real computeElemRightHandSideContribution() override
Computes the right hand side contribution from the element side on an internal face.
std::pair< Real, Real > interpCoeffs(const InterpMethod m, const FaceInfo &fi, const bool one_is_elem, const T &face_flux=0.0)
Produce the interpolation coefficients in the equation:
Definition: MathFVUtils.h:114
Moose::FaceArg singleSidedFaceArg(const FaceInfo *fi, Moose::FV::LimiterType limiter_type=Moose::FV::LimiterType::CentralDifference, bool correct_skewness=false) const
Determine the single sided face argument when evaluating a functor on a face.
Moose::StateArg determineState() const
Create a functor state argument that corresponds to the implicit state of this object.
Real _flux_rhs_contribution
The cached right hand side contribution.
const ElemInfo * neighborInfo() const
Definition: FaceInfo.h:86
const Point & faceCentroid() const
Returns the coordinates of the face centroid.
Definition: FaceInfo.h:71
Finite volume kernel that contributes approximations of discretized face flux terms to the matrix and...
MooseLinearVariableFV< Real > & _var
Reference to the linear finite volume variable.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
const ElemInfo * elemInfo() const
Definition: FaceInfo.h:85
Real computeFluxMatrixContribution()
Computes the matrix contribution from the diffusive face flux.
FaceInfo::VarFaceNeighbors _current_face_type
Face ownership information for the current face.
static InputParameters validParams()
Base class for boundary conditions that are valid for advection diffusion problems.
static InputParameters validParams()
const FaceInfo * _current_face_info
Pointer to the face info we are operating on right now.
virtual Real computeNeighborRightHandSideContribution() override
Computes the right hand side contribution from the neighbor side on an internal face.
LinearFVDiffusion(const InputParameters &params)
Class constructor.
virtual Real computeBoundaryRHSContribution(const LinearFVBoundaryCondition &bc) override
Computes the right hand side contribution from a boundary face.
Real _flux_matrix_contribution
The cached matrix contribution.
const std::string & type() const
Get the type of this class.
Definition: MooseBase.h:89
const Point & normal() const
Returns the unit normal vector for the face oriented outward from the face&#39;s elem element...
Definition: FaceInfo.h:68
Real dCNMag() const
Definition: FaceInfo.h:144
virtual void initialSetup() override
Gets called at the beginning of the simulation before this object is asked to do its job...
bool _cached_rhs_contribution
If we already built the right hand side contribution.
virtual Real computeBoundaryMatrixContribution(const LinearFVBoundaryCondition &bc) override
Computes the matrix contribution from a boundary face.
registerMooseObject("MooseApp", LinearFVDiffusion)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const Point & eCN() const
Definition: FaceInfo.h:151
const std::unordered_map< BoundaryID, LinearFVBoundaryCondition * > & getBoundaryConditionMap()
const VectorValue< Real > gradSln(const ElemInfo &elem_info) const
Get the variable gradient at a cell center.
virtual Real computeNeighborMatrixContribution() override
Computes the system matrix contribution from the neighbor side on an internal face.
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
Definition: MooseBase.h:267
Real computeFluxRHSContribution()
Computes the right hand side contribution from the diffusive face flux.
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump...
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object...
bool _cached_matrix_contribution
If we already built the matrix contribution.
Real _current_face_area
The current, coordinate system specific face area.
Moose::FaceArg makeCDFace(const FaceInfo &fi, const bool correct_skewness=false) const
Make a functor face argument with a central differencing limiter, e.g.
void computeCellGradients()
Switch to request cell gradient computations.
const Point & dCN() const
Definition: FaceInfo.h:138
const bool _use_nonorthogonal_correction
Switch to enable/disable nonorthogonal correction.