https://mooseframework.inl.gov
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 
38 void
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  mooseAssert(
77  _current_face_info->boundaryIDs().size() == 1,
78  "We should only have one boundary on every 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 
114 void
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  mooseAssert(_current_face_info->boundaryIDs().size() == 1,
145  "We should only have one boundary on every face.");
146  LinearFVBoundaryCondition * bc_pointer =
148 
149  if (bc_pointer || _force_boundary_execution)
150  {
151  if (bc_pointer)
153 
154  const auto rhs_contribution = computeBoundaryRHSContribution(*bc_pointer);
155 
156  // We allow internal (for the mesh) boundaries too, so we have to check on which side we
157  // are on (assuming that this is a boundary for the variable)
159  {
160  const auto dof_id_elem = _current_face_info->elemInfo()->dofIndices()[_sys_num][_var_num];
161  // We add the contributions to every tagged vector
162  for (auto & vector : _vectors)
163  (*vector).add(dof_id_elem, rhs_contribution);
164  }
166  {
167  const auto dof_id_neighbor =
169  // We add the contributions to every tagged matrix
170  for (auto & vector : _vectors)
171  (*vector).add(dof_id_neighbor, rhs_contribution);
172  }
173  }
174  }
175 }
176 
177 bool
178 LinearFVFluxKernel::hasFaceSide(const FaceInfo & fi, bool fi_elem_side) const
179 {
180  const auto ft = fi.faceType(std::make_pair(_var_num, _sys_num));
181  if (fi_elem_side)
183  else
185 }
186 
189  const Moose::FV::LimiterType limiter_type,
190  const bool correct_skewness) const
191 {
192  mooseAssert(fi, "FaceInfo should not be null!");
193  return makeFace(*fi, limiter_type, true, correct_skewness);
194 }
195 
196 void
198 {
200  _cached_rhs_contribution = false;
201  _current_face_info = face_info;
204  _dof_indices.zero();
205  _rhs_contribution.zero();
206 }
virtual void addMatrixContribution() override
Add this object&#39;s contribution to the system matrix.
const unsigned int _var_num
Cache for the variable number.
Base class for boundary conditions for linear FV systems.
const std::set< BoundaryID > & boundaryIDs() const
Const getter for every associated boundary ID.
Definition: FaceInfo.h:120
Base class for finite volume kernels that contribute to a linear systems.
virtual void zero() override final
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.
const ElemInfo * neighborInfo() const
Definition: FaceInfo.h:86
const Point & faceCentroid() const
Returns the coordinates of the face centroid.
Definition: FaceInfo.h:71
void setupFaceData(const FaceInfo *face_info, const FaceInfo::VarFaceNeighbors face_type)
Set current face info.
MooseLinearVariableFV< Real > & _var
Reference to the linear finite volume variable.
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...
virtual void setupFaceData(const FaceInfo *face_info)
Set the current FaceInfo object.
virtual Real computeElemMatrixContribution()=0
Computes the system matrix contribution from an element side on an internal face. ...
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
const ElemInfo * elemInfo() const
Definition: FaceInfo.h:85
LinearFVBoundaryCondition * getBoundaryCondition(const BoundaryID bd_id) const
Get the boundary condition object which corresponds to the given boundary ID.
static InputParameters validParams()
FaceInfo::VarFaceNeighbors _current_face_type
Face ownership information for the current face.
const bool _force_boundary_execution
Whether to force execution of this kernel on all external boundaries.
std::vector< NumericVector< Number > * > _vectors
Pointers to the vectors that need contributions from this kernel.
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.
This data structure is used to store geometric and variable related metadata about each cell face in ...
Definition: FaceInfo.h:36
static InputParameters validParams()
const FaceInfo * _current_face_info
Pointer to the face info we are operating on right now.
std::vector< SparseMatrix< Number > * > _matrices
Pointers to the matrices that need contributions from this kernel.
A structure defining a "face" evaluation calling argument for Moose functors.
An interface for producers of functor face arguments, e.g.
virtual Real computeNeighborMatrixContribution()=0
Computes the system matrix contribution from the neighbor side on an internal face.
LimiterType
Definition: Limiter.h:26
virtual bool hasFaceSide(const FaceInfo &fi, bool fi_elem_side) const override
std::string stringify(const T &t)
conversion to string
Definition: Conversion.h:64
virtual Real computeBoundaryMatrixContribution(const LinearFVBoundaryCondition &bc)=0
Computes the matrix contribution from a boundary face.
bool _cached_rhs_contribution
If we already built the right hand side contribution.
DenseVector< dof_id_type > _dof_indices
A vector of dof indices that describe where to add the matrix and right hand side batch contribution...
const std::vector< std::vector< dof_id_type > > & dofIndices() const
Definition: ElemInfo.h:39
LinearFVFluxKernel(const InputParameters &params)
Class constructor.
virtual Real computeElemRightHandSideContribution()=0
Computes the right hand side contribution from the element side on an internal face.
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.
bool hasBlocks(const SubdomainName &name) const
Test if the supplied block name is valid for this object.
virtual void addRightHandSideContribution() override
Add this object&#39;s contribution to the system right hand side.
virtual Real computeBoundaryRHSContribution(const LinearFVBoundaryCondition &bc)=0
Computes the right hand side contribution from a boundary face.
const unsigned int _sys_num
Cache for the system number.
SubdomainID subdomain_id() const
We return the subdomain ID of the corresponding libmesh element.
Definition: ElemInfo.h:43
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.
DenseMatrix< Real > _matrix_contribution
Cache for a batch of matrix contributions for faster assembly.
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:225