https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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 params.addParam<InterpolationMethodName>(
29 "coeff_interp_method",
30 "Optional finite volume interpolation method used to compute a face-centered diffusion "
31 "coefficient. If omitted, the functor is evaluated directly on the face.");
32 return params;
33}
34
36 : LinearFVFluxKernel(params),
38 _diffusion_coeff(getFunctor<Real>("diffusion_coeff")),
39 _coeff_interp_method(isParamValid("coeff_interp_method")
40 ? &getFVFaceInterpolationMethod(
41 getParam<InterpolationMethodName>("coeff_interp_method"))
42 : nullptr),
43 _use_nonorthogonal_correction(getParam<bool>("use_nonorthogonal_correction")),
44 _flux_matrix_contribution(0.0),
45 _flux_rhs_contribution(0.0),
46 _cached_face_diffusivity(false),
47 _face_diffusivity(0.0)
48{
51}
52
53Real
55{
57 {
59 "faceDiffusivity() is only valid for two-sided internal faces.");
60
61 const auto state = determineState();
62
66 else
68
70 }
71
72 return _face_diffusivity;
73}
74
75void
81
82void
84{
85 for (const auto bc : _var.getBoundaryConditionMap())
86 if (!dynamic_cast<const LinearFVAdvectionDiffusionBC *>(bc.second))
88 bc.second->type(), " is not a compatible boundary condition with ", this->type(), "!");
89}
90
91Real
96
97Real
102
103Real
108
109Real
114
115Real
117{
118 // If we don't have the value yet, we compute it
120 {
121 // If we requested nonorthogonal correction, we use the normal component of the
122 // cell to face vector.
123 const auto d = _use_nonorthogonal_correction
126
127 // Cache the matrix contribution
130 }
131
133}
134
135Real
137{
138 // We only have contributions on the right hand side from internal faces
139 // if the nonorthogonal correction is enabled.
141 {
142 const auto state = determineState();
143
144 // Get the gradients from the adjacent cells
145 const auto grad_elem = _var.gradSln(*_current_face_info->elemInfo(), state);
146 const auto & grad_neighbor = _var.gradSln(*_current_face_info->neighborInfo(), state);
147
148 // Interpolate the two gradients to the face
149 const auto interp_coeffs =
151
152 // Compute correction vector. Potential optimization: this only depends on the geometry
153 // so we can cache it in FaceInfo at some point.
154 const auto correction_vector =
157
158 // Cache the matrix contribution
161 (interp_coeffs.first * grad_elem + interp_coeffs.second * grad_neighbor) *
162 correction_vector * _current_face_area;
164 }
165
167}
168
169Real
171{
172 const auto * const diff_bc = libMesh::cast_ptr<const LinearFVAdvectionDiffusionBC *>(&bc);
173
174 auto grad_contrib = diff_bc->computeBoundaryGradientMatrixContribution() * _current_face_area;
175 // If the boundary condition does not include the diffusivity contribution then
176 // add it here.
177 if (!diff_bc->includesMaterialPropertyMultiplier())
178 {
179 const auto face_arg = singleSidedFaceArg(_current_face_info);
180 grad_contrib *= _diffusion_coeff(face_arg, determineState());
181 }
182
183 return grad_contrib;
184}
185
186Real
188{
189 const auto * const diff_bc = static_cast<const LinearFVAdvectionDiffusionBC *>(&bc);
190 mooseAssert(diff_bc, "This should be a valid BC!");
191
192 const auto face_arg = singleSidedFaceArg(_current_face_info);
193 const auto state = determineState();
194 auto grad_contrib = diff_bc->computeBoundaryGradientRHSContribution() * _current_face_area;
195
196 // If the boundary condition does not include the diffusivity contribution then
197 // add it here.
198 if (!diff_bc->includesMaterialPropertyMultiplier())
199 grad_contrib *= _diffusion_coeff(face_arg, state);
200
201 // We add the nonorthogonal corrector for the face here. Potential idea: we could do
202 // this in the boundary condition too. For now, however, we keep it like this.
203 // This should only be used for BCs where the gradient of the value is computed and
204 // not prescribed.
205
206 if (_use_nonorthogonal_correction && diff_bc->needsBoundaryNonorthogonalCorrection())
207 {
208 // We support internal boundaries as well. In that case we have to decide on which side
209 // of the boundary we are on.
210 const auto elem_info = (_current_face_type == FaceInfo::VarFaceNeighbors::ELEM)
213 const Real boundary_normal_multiplier =
215
216 // Unit vector to the boundary. Unfortunately, we have to recompute it because the value
217 // stored in the face info is only correct for external boundaries
218 const auto e_Cf = _current_face_info->faceCentroid() - elem_info->centroid();
219 const auto correction_vector =
220 _current_face_info->normal() - 1 / (_current_face_info->normal() * e_Cf) * e_Cf;
221
222 grad_contrib += _diffusion_coeff(face_arg, state) * _var.gradSln(*elem_info, state) *
223 boundary_normal_multiplier * correction_vector * _current_face_area;
224 }
225
226 return grad_contrib;
227}
registerMooseObject("MooseApp", LinearFVDiffusion)
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
virtual Real interpolate(const FaceInfo &face, Real elem_value, Real neighbor_value) const =0
Face interpolation operation for this method.
Helper interface for objects that need access to FVInterpolationMethod instances.
Moose::FaceArg makeCDFace(const FaceInfo &fi, const bool correct_skewness=false) const
Make a functor face argument with a central differencing limiter, e.g.
This data structure is used to store geometric and variable related metadata about each cell face in ...
Definition FaceInfo.h:38
const Point & normal() const
Returns the unit normal vector for the face oriented outward from the face's elem element.
Definition FaceInfo.h:72
const Point & eCN() const
Definition FaceInfo.h:155
const ElemInfo * elemInfo() const
Definition FaceInfo.h:89
Real dCNMag() const
Definition FaceInfo.h:148
const ElemInfo * neighborInfo() const
Definition FaceInfo.h:90
const Point & dCN() const
Definition FaceInfo.h:142
const Point & faceCentroid() const
Returns the coordinates of the face centroid.
Definition FaceInfo.h:75
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
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.
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.
Base class for boundary conditions that are valid for advection diffusion problems.
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 FVFaceInterpolationMethod * _coeff_interp_method
Optional interpolation method for the diffusion coefficient.
const bool _use_nonorthogonal_correction
Switch to enable/disable nonorthogonal correction.
LinearFVDiffusion(const InputParameters &params)
Class constructor.
virtual Real computeNeighborMatrixContribution() override
Computes the system matrix contribution from the neighbor side on an internal face.
static InputParameters validParams()
virtual Real computeElemRightHandSideContribution() override
Computes the right hand side contribution from the element side on an internal face.
Real computeFluxMatrixContribution()
Computes the matrix contribution from the diffusive face flux.
virtual Real computeBoundaryMatrixContribution(const LinearFVBoundaryCondition &bc) override
Computes the matrix contribution from a boundary face.
Real _flux_matrix_contribution
The cached matrix contribution.
bool _cached_face_diffusivity
Cache for interpolated diffusion coefficient.
virtual void setupFaceData(const FaceInfo *face_info) override
Set the current FaceInfo object.
Real computeFluxRHSContribution()
Computes the right hand side contribution from the diffusive face flux.
virtual Real computeBoundaryRHSContribution(const LinearFVBoundaryCondition &bc) override
Computes the right hand side contribution from a boundary face.
const Moose::Functor< Real > & _diffusion_coeff
The functor for the diffusion coefficient.
Real faceDiffusivity() const
Returns the diffusion coefficient interpolated to the current face.
Real _flux_rhs_contribution
The cached right hand side contribution.
virtual Real computeElemMatrixContribution() override
Computes the system matrix contribution from an element side on an internal face.
virtual Real computeNeighborRightHandSideContribution() override
Computes the right hand side contribution from the neighbor side on an internal face.
virtual void initialSetup() override
Gets called at the beginning of the simulation before this object is asked to do its job.
Finite volume kernel that contributes approximations of discretized face flux terms to the matrix and...
bool _cached_matrix_contribution
If we already built the matrix contribution.
bool _cached_rhs_contribution
If we already built the right hand side contribution.
FaceInfo::VarFaceNeighbors _current_face_type
Face ownership information for the current face.
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.
virtual void setupFaceData(const FaceInfo *face_info)
Set the current FaceInfo object.
Real _current_face_area
The current, coordinate system specific face area.
const FaceInfo * _current_face_info
Pointer to the face info we are operating on right now.
static InputParameters validParams()
MooseLinearVariableFV< Real > & _var
Reference to the linear finite volume variable.
const std::string & type() const
Get the type of this class.
Definition MooseBase.h:93
void computeCellGradients()
Switch to request cell gradient computations.
const std::unordered_map< BoundaryID, LinearFVBoundaryCondition * > & getBoundaryConditionMap() const
VectorValue< Real > gradSln(const ElemInfo &elem_info, const StateArg &state) const
Get the variable gradient at a cell center.
Moose::StateArg determineState() const
Create a functor state argument that corresponds to the implicit state of this object.
@ Average
gc*elem+(1-gc)*neighbor