https://mooseframework.inl.gov
Loading...
Searching...
No Matches
LinearFVFluxKernel.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 "LinearFVFluxKernel.h"
12
15{
17 params.addParam<bool>("force_boundary_execution",
18 false,
19 "Whether to force execution of this object on all external boundaries.");
20 params.registerSystemAttributeName("LinearFVFluxKernel");
21 return params;
22}
23
25 : LinearFVKernel(params),
27 _current_face_info(nullptr),
28 _current_face_type(FaceInfo::VarFaceNeighbors::NEITHER),
29 _cached_matrix_contribution(false),
30 _cached_rhs_contribution(false),
31 _force_boundary_execution(getParam<bool>("force_boundary_execution")),
32 _dof_indices(2, 0),
33 _matrix_contribution(2, 2),
34 _rhs_contribution(2, 0.0)
35{
36}
37
38void
40{
41 // If we are on an internal face, we populate the four entries in the system matrix
42 // which touch the face
44 {
45 // The dof ids of the variable corresponding to the element and neighbor
48
49 // Compute the entries which will go to the neighbor (offdiagonal) and element
50 // (diagonal).
51 const auto elem_matrix_contribution = computeElemMatrixContribution();
52 const auto neighbor_matrix_contribution = computeNeighborMatrixContribution();
53
54 // Populate matrix
56 {
57 _matrix_contribution(0, 0) = elem_matrix_contribution;
58 _matrix_contribution(0, 1) = neighbor_matrix_contribution;
59 }
60
62 {
63 _matrix_contribution(1, 0) = -elem_matrix_contribution;
64 _matrix_contribution(1, 1) = -neighbor_matrix_contribution;
65 }
66
67 // We add the contributions to every tagged matrix
68 for (auto & matrix : _matrices)
69 (*matrix).add_matrix(_matrix_contribution, _dof_indices.get_values());
70 }
71 // We are at a block boundary where the variable is not defined on one of the adjacent cells.
72 // We check if we have a boundary condition here
75 {
76 if (_current_face_info->boundaryIDs().size() > 1)
77 mooseError("We currently don't support multiple boundary conditions for the same variable on "
78 "the same face. Current face center : " +
80 " boundaries specified: " + Moose::stringify(_current_face_info->boundaryIDs()));
81
82 LinearFVBoundaryCondition * bc_pointer =
84
85 if (bc_pointer || _force_boundary_execution)
86 {
87 if (bc_pointer)
89 const auto matrix_contribution = computeBoundaryMatrixContribution(*bc_pointer);
90
91 // We allow internal (for the mesh) boundaries too, so we have to check on which side we
92 // are on (assuming that this is a boundary for the variable)
94 {
95 const auto dof_id_elem = _current_face_info->elemInfo()->dofIndices()[_sys_num][_var_num];
96
97 // We add the contributions to every tagged matrix
98 for (auto & matrix : _matrices)
99 (*matrix).add(dof_id_elem, dof_id_elem, matrix_contribution);
100 }
102 {
103 const auto dof_id_neighbor =
105
106 // We add the contributions to every tagged matrix
107 for (auto & matrix : _matrices)
108 (*matrix).add(dof_id_neighbor, dof_id_neighbor, matrix_contribution);
109 }
110 }
111 }
112}
113
114void
116{
117 // If we are on an internal face, we populate the two entries in the right hand side
118 // which touch the face
120 {
121 // The dof ids of the variable corresponding to the element and neighbor
124
125 // Compute the entries which will go to the neighbor and element positions.
126 const auto elem_rhs_contribution = computeElemRightHandSideContribution();
127 const auto neighbor_rhs_contribution = computeNeighborRightHandSideContribution();
128
129 // Populate right hand side
131 _rhs_contribution(0) = elem_rhs_contribution;
133 _rhs_contribution(1) = neighbor_rhs_contribution;
134
135 // We add the contributions to every tagged vector
136 for (auto & vector : _vectors)
137 (*vector).add_vector(_rhs_contribution.get_values().data(), _dof_indices.get_values());
138 }
139 // We are at a block boundary where the variable is not defined on one of the adjacent cells.
140 // We check if we have a boundary condition here
143 {
144 if (_current_face_info->boundaryIDs().size() > 1)
145 mooseError("We currently don't support multiple boundary conditions for the same variable on "
146 "the same face. Current face center : " +
148 " boundaries specified: " + Moose::stringify(_current_face_info->boundaryIDs()));
149 LinearFVBoundaryCondition * bc_pointer =
151
152 if (bc_pointer || _force_boundary_execution)
153 {
154 if (bc_pointer)
156
157 const auto rhs_contribution = computeBoundaryRHSContribution(*bc_pointer);
158
159 // We allow internal (for the mesh) boundaries too, so we have to check on which side we
160 // are on (assuming that this is a boundary for the variable)
162 {
163 const auto dof_id_elem = _current_face_info->elemInfo()->dofIndices()[_sys_num][_var_num];
164 // We add the contributions to every tagged vector
165 for (auto & vector : _vectors)
166 (*vector).add(dof_id_elem, rhs_contribution);
167 }
169 {
170 const auto dof_id_neighbor =
172 // We add the contributions to every tagged matrix
173 for (auto & vector : _vectors)
174 (*vector).add(dof_id_neighbor, rhs_contribution);
175 }
176 }
177 }
178}
179
180bool
181LinearFVFluxKernel::hasFaceSide(const FaceInfo & fi, bool fi_elem_side) const
182{
183 const auto ft = fi.faceType(std::make_pair(_var_num, _sys_num));
184 if (fi_elem_side)
186 else
188}
189
192 const Moose::FV::LimiterType limiter_type,
193 const bool correct_skewness) const
194{
195 mooseAssert(fi, "FaceInfo should not be null!");
196 return makeFace(*fi, limiter_type, true, correct_skewness);
197}
198
199Real
208
209void
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
bool hasBlocks(const SubdomainName &name) const
Test if the supplied block name is valid for this object.
SubdomainID subdomain_id() const
We return the subdomain ID of the corresponding libmesh element.
Definition ElemInfo.h:43
const std::vector< std::vector< dof_id_type > > & dofIndices() const
Definition ElemInfo.h:39
An interface for producers of functor face arguments, e.g.
Moose::FaceArg makeFace(const FaceInfo &fi, const Moose::FV::LimiterType limiter_type, const bool elem_is_upwind, const bool correct_skewness=false, const Moose::StateArg *state_limiter=nullptr) const
Create a functor face argument from provided component arguments.
This data structure is used to store geometric and variable related metadata about each cell face in ...
Definition FaceInfo.h:38
VarFaceNeighbors faceType(const std::pair< unsigned int, unsigned int > &var_sys) const
Returns which side(s) the given variable-system number pair is defined on for this face.
Definition FaceInfo.h:229
const std::set< BoundaryID > & boundaryIDs() const
Const getter for every associated boundary ID.
Definition FaceInfo.h:124
const ElemInfo * elemInfo() const
Definition FaceInfo.h:89
const ElemInfo * neighborInfo() const
Definition FaceInfo.h:90
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 registerSystemAttributeName(const std::string &value)
This method is used to define the MOOSE system name that is used by the TheWarehouse object for stori...
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.
Base class for boundary conditions for linear FV systems.
void setupFaceData(const FaceInfo *face_info, const FaceInfo::VarFaceNeighbors face_type)
Set current face info.
virtual Real computeNeighborMatrixContribution()=0
Computes the system matrix contribution from the neighbor side on an internal face.
bool _cached_matrix_contribution
If we already built the matrix contribution.
bool _cached_rhs_contribution
If we already built the right hand side contribution.
LinearFVFluxKernel(const InputParameters &params)
Class constructor.
FaceInfo::VarFaceNeighbors _current_face_type
Face ownership information for the current face.
virtual Real computeBoundaryFlux(const LinearFVBoundaryCondition &bc)
Computes the flux from this kernel on a boundary.
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.
DenseMatrix< Real > _matrix_contribution
Cache for a batch of matrix contributions for faster assembly.
virtual Real computeBoundaryRHSContribution(const LinearFVBoundaryCondition &bc)=0
Computes the right hand side contribution from a boundary face.
virtual Real computeBoundaryMatrixContribution(const LinearFVBoundaryCondition &bc)=0
Computes the matrix contribution from a boundary face.
virtual bool hasFaceSide(const FaceInfo &fi, bool fi_elem_side) const override
virtual void setupFaceData(const FaceInfo *face_info)
Set the current FaceInfo object.
DenseVector< Real > _rhs_contribution
Cache for a batch of vector contributions for faster assembly.
virtual Real computeNeighborRightHandSideContribution()=0
Computes the right hand side contribution from the neighbor side on an internal face.
DenseVector< dof_id_type > _dof_indices
A vector of dof indices that describe where to add the matrix and right hand side batch contribution.
virtual void addRightHandSideContribution() override
Add this object's contribution to the system right hand side.
virtual void addMatrixContribution() override
Add this object's contribution to the system matrix.
virtual Real computeElemMatrixContribution()=0
Computes the system matrix contribution from an element side on an internal face.
virtual Real computeElemRightHandSideContribution()=0
Computes the right hand side contribution from the element side on an internal face.
const bool _force_boundary_execution
Whether to force execution of this kernel on all external boundaries.
const FaceInfo * _current_face_info
Pointer to the face info we are operating on right now.
static InputParameters validParams()
Base class for finite volume kernels that contribute to a linear systems.
MooseLinearVariableFV< Real > & _var
Reference to the linear finite volume variable.
static InputParameters validParams()
const unsigned int _sys_num
Cache for the system number.
const unsigned int _var_num
Cache for the variable number.
std::vector< SparseMatrix< Number > * > _matrices
Pointers to the matrices that need contributions from this kernel.
std::vector< NumericVector< Number > * > _vectors
Pointers to the vectors that need contributions from this kernel.
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...
LinearFVBoundaryCondition * getBoundaryCondition(const BoundaryID bd_id) const
Get the boundary condition object which corresponds to the given boundary ID.
Moose::StateArg determineState() const
Create a functor state argument that corresponds to the implicit state of this object.
std::vector< T > & get_values()
virtual void zero() override final
std::string stringify(const T &t)
conversion to string
Definition Conversion.h:64
A structure defining a "face" evaluation calling argument for Moose functors.