https://mooseframework.inl.gov
LinearFVAdvection.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 "LinearFVAdvection.h"
11 #include "Assembly.h"
12 #include "SubProblem.h"
14 
16 
19 {
21  params.addClassDescription("Represents the matrix and right hand side contributions of an "
22  "advection term in a partial differential equation.");
23  params.addRequiredParam<RealVectorValue>("velocity", "Constant advection velocity");
24  params.addRequiredParam<InterpolationMethodName>(
25  "advected_interp_method_name",
26  "Name of the FVInterpolationMethod to use for the advected quantity.");
27  return params;
28 }
29 
31  : LinearFVFluxKernel(params),
33  _velocity(getParam<RealVectorValue>("velocity")),
34  _adv_interp_method(getFVAdvectedInterpolationMethod(
35  getParam<InterpolationMethodName>("advected_interp_method_name")))
36 
37 {
40 }
41 
42 void
44 {
47 
48  // Only internal faces need advected interpolation results; boundary contributions are handled
49  // through the linear FV boundary conditions.
51  return;
52 
53  const auto state = determineState();
54  const auto & elem_info = *_current_face_info->elemInfo();
55  const auto & neighbor_info = *_current_face_info->neighborInfo();
56 
57  const Real elem_value = _var.getElemValue(elem_info, state);
58  const Real neighbor_value = _var.getElemValue(neighbor_info, state);
60  {
61  const auto limiter_type = _adv_interp_method.gradientLimiter();
62  _elem_grad_storage = _var.gradSln(elem_info, state, limiter_type);
63  _neighbor_grad_storage = _var.gradSln(neighbor_info, state, limiter_type);
64  }
65 
67  elem_value,
68  neighbor_value,
72 }
73 
74 void
76 {
77  for (const auto bc : _var.getBoundaryConditionMap())
78  if (!dynamic_cast<const LinearFVAdvectionDiffusionBC *>(bc.second))
79  mooseError(
80  bc.second->type(), " is not a compatible boundary condition with ", this->type(), "!");
81 }
82 
83 Real
85 {
86  const auto & coeffs = _adv_interp_result.weights_matrix;
87  return coeffs.first * _adv_face_flux * _current_face_area;
88 }
89 
90 Real
92 {
93  const auto & coeffs = _adv_interp_result.weights_matrix;
94  return coeffs.second * _adv_face_flux * _current_face_area;
95 }
96 
97 Real
99 {
101 }
102 
103 Real
105 {
107 }
108 
109 Real
111 {
112  const auto * const adv_bc = static_cast<const LinearFVAdvectionDiffusionBC *>(&bc);
113  mooseAssert(adv_bc, "This should be a valid BC!");
114 
115  const auto boundary_value_matrix_contrib = adv_bc->computeBoundaryValueMatrixContribution();
116 
117  // We support internal boundaries too so we have to make sure the normal points always outward
118  const auto factor = (_current_face_type == FaceInfo::VarFaceNeighbors::ELEM) ? 1.0 : -1.0;
119 
120  return boundary_value_matrix_contrib * factor * _adv_face_flux * _current_face_area;
121 }
122 
123 Real
125 {
126  const auto * const adv_bc = static_cast<const LinearFVAdvectionDiffusionBC *>(&bc);
127  mooseAssert(adv_bc, "This should be a valid BC!");
128 
129  // We support internal boundaries too so we have to make sure the normal points always outward
130  const auto factor = (_current_face_type == FaceInfo::VarFaceNeighbors::ELEM ? 1.0 : -1.0);
131 
132  const auto boundary_value_rhs_contrib = adv_bc->computeBoundaryValueRHSContribution();
133  return -boundary_value_rhs_contrib * factor * _adv_face_flux * _current_face_area;
134 }
VectorValue< Real > _elem_grad_storage
Reusable gradient storage used when advected interpolation requires gradients.
VectorValue< Real > _neighbor_grad_storage
Base class for boundary conditions for linear FV systems.
const RealVectorValue _velocity
Constant advecting velocity vector.
FVAdvectedInterpolationMethod::AdvectedSystemContribution _adv_interp_result
Cached weights/correction for the current face (refreshed in setupFaceData)
Kernel that adds contributions from an advection term discretized using the finite volume method to a...
Moose::StateArg determineState() const
Create a functor state argument that corresponds to the implicit state of this object.
const ElemInfo * neighborInfo() const
Definition: FaceInfo.h:90
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.
virtual void setupFaceData(const FaceInfo *face_info)
Set the current FaceInfo object.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
const ElemInfo * elemInfo() const
Definition: FaceInfo.h:89
virtual Moose::FV::GradientLimiterType gradientLimiter() const
Limiter used by interpolations that require limited gradients.
FaceInfo::VarFaceNeighbors _current_face_type
Face ownership information for the current face.
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
registerMooseObject("MooseApp", LinearFVAdvection)
VectorValue< Real > gradSln(const ElemInfo &elem_info, const StateArg &state) const
Get the variable gradient at a cell center.
LinearFVAdvection(const InputParameters &params)
Class constructor.
This data structure is used to store geometric and variable related metadata about each cell face in ...
Definition: FaceInfo.h:37
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 computeNeighborMatrixContribution() override
Computes the system matrix contribution from the neighbor side on an internal face.
const FVAdvectedInterpolationMethod & _adv_interp_method
The interpolation method to use for the advected quantity.
virtual AdvectedSystemContribution advectedInterpolate(const FaceInfo &face, Real elem_value, Real neighbor_value, const VectorValue< Real > *elem_grad, const VectorValue< Real > *neighbor_grad, Real mass_flux) const =0
Compute the matrix weights for the advected face value.
virtual Real computeNeighborRightHandSideContribution() override
Computes the right hand side contribution from the neighbor side on an internal face.
const std::string & type() const
Get the type of this class.
Definition: MooseBase.h:93
virtual Real computeElemMatrixContribution() override
Computes the system matrix contribution from an element side on an internal face. ...
const Point & normal() const
Returns the unit normal vector for the face oriented outward from the face&#39;s elem element...
Definition: FaceInfo.h:72
virtual Real computeBoundaryMatrixContribution(const LinearFVBoundaryCondition &bc) override
Computes the matrix contribution from a boundary face.
virtual Real computeBoundaryRHSContribution(const LinearFVBoundaryCondition &bc) override
Computes the right hand side contribution from a boundary face.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual bool needsGradients() const
Whether advected interpolation requires adjacent-cell gradients.
virtual void initialSetup() override
Gets called at the beginning of the simulation before this object is asked to do its job...
Helper interface for objects that need access to FVInterpolationMethod instances. ...
const std::unordered_map< BoundaryID, LinearFVBoundaryCondition * > & getBoundaryConditionMap()
virtual void setupFaceData(const FaceInfo *face_info) override
Set the current FaceInfo object.
Real getElemValue(const ElemInfo &elem_info, const StateArg &state) const
Get the solution value for the provided element and seed the derivative for the corresponding dof ind...
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:281
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...
Real _current_face_area
The current, coordinate system specific face area.
void computeCellGradients()
Switch to request cell gradient computations.
static InputParameters validParams()
virtual Real computeElemRightHandSideContribution() override
Computes the right hand side contribution from the element side on an internal face.