https://mooseframework.inl.gov
Loading...
Searching...
No Matches
LinearFVTurbulentAdvection.C
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://www.mooseframework.org
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
13#include "NavierStokesMethods.h"
14#include "NS.h"
15
17
20{
22 params.addClassDescription("Represents the matrix and right hand side contributions of an "
23 "advection term for a turbulence variable.");
24
25 params.addRequiredParam<UserObjectName>(
26 "rhie_chow_user_object",
27 "The rhie-chow user-object which is used to determine the face velocity.");
28
29 params.addRequiredParam<InterpolationMethodName>(
30 "advected_interp_method_name",
31 "Name of the FVInterpolationMethod to use for the advected quantity.");
32
33 params.addParam<std::vector<BoundaryName>>(
34 "walls", {}, "Boundaries that correspond to solid walls.");
35
36 return params;
37}
38
40 : LinearFVFluxKernel(params),
42 _mass_flux_provider(getUserObject<RhieChowMassFlux>("rhie_chow_user_object")),
43 _adv_interp_method(getFVAdvectedInterpolationMethod(
44 getParam<InterpolationMethodName>("advected_interp_method_name"))),
45 _gradient_field(_adv_interp_method.needsGradients()
46 ? &_var.requestCellGradients(_adv_interp_method.gradientMethodName())
47 : nullptr),
48 _mass_face_flux(0.0),
49 _wall_boundary_names(getParam<std::vector<BoundaryName>>("walls"))
50{
51}
52
53void
60
61void
63{
64 // Coumputing bounding map
65 const Elem * elem = _current_face_info->elemPtr();
66 const auto bounded_elem = _wall_bounded.find(elem) != _wall_bounded.end();
67 const Elem * neighbor = _current_face_info->neighborPtr();
68 const auto bounded_neigh = _wall_bounded.find(neighbor) != _wall_bounded.end();
69
70 // If we are on an internal face, we populate the four entries in the system matrix
71 // which touch the face
72 if (_current_face_type == FaceInfo::VarFaceNeighbors::BOTH)
73 {
74 // The dof ids of the variable corresponding to the element and neighbor
77
78 // Compute the entries which will go to the neighbor (offdiagonal) and element
79 // (diagonal).
80 const auto elem_matrix_contribution = computeElemMatrixContribution();
81 const auto neighbor_matrix_contribution = computeNeighborMatrixContribution();
82
83 // Populate matrix
84 if (hasBlocks(_current_face_info->elemInfo()->subdomain_id()) && !(bounded_elem))
85 {
86 _matrix_contribution(0, 0) = elem_matrix_contribution;
87 _matrix_contribution(0, 1) = neighbor_matrix_contribution;
88 }
89
90 if (hasBlocks(_current_face_info->neighborInfo()->subdomain_id()) && !(bounded_neigh))
91 {
92 _matrix_contribution(1, 0) = -elem_matrix_contribution;
93 _matrix_contribution(1, 1) = -neighbor_matrix_contribution;
94 }
96 }
97 // We are at a block boundary where the variable is not defined on one of the adjacent cells.
98 // We check if we have a boundary condition here
99 else if (_current_face_type == FaceInfo::VarFaceNeighbors::ELEM ||
100 _current_face_type == FaceInfo::VarFaceNeighbors::NEIGHBOR)
101 {
102 mooseAssert(_current_face_info->boundaryIDs().size() == 1,
103 "We should only have one boundary on every face.");
104
105 LinearFVBoundaryCondition * bc_pointer =
107
108 if (bc_pointer || _force_boundary_execution)
109 {
110 if (bc_pointer)
112 const auto matrix_contribution = computeBoundaryMatrixContribution(*bc_pointer);
113
114 // We allow internal (for the mesh) boundaries too, so we have to check on which side we
115 // are on (assuming that this is a boundary for the variable)
116 if ((_current_face_type == FaceInfo::VarFaceNeighbors::ELEM) && !(bounded_elem))
117 {
118 const auto dof_id_elem = _current_face_info->elemInfo()->dofIndices()[_sys_num][_var_num];
119 (*_linear_system.matrix).add(dof_id_elem, dof_id_elem, matrix_contribution);
120 }
121 else if ((_current_face_type == FaceInfo::VarFaceNeighbors::NEIGHBOR) && !(bounded_neigh))
122 {
123 const auto dof_id_neighbor =
125 (*_linear_system.matrix).add(dof_id_neighbor, dof_id_neighbor, matrix_contribution);
126 }
127 }
128 }
129}
130
131void
133{
134 // Coumputing bounding map
135 const Elem * elem = _current_face_info->elemPtr();
136 const auto bounded_elem = _wall_bounded.find(elem) != _wall_bounded.end();
137 const Elem * neighbor = _current_face_info->neighborPtr();
138 const auto bounded_neigh = _wall_bounded.find(neighbor) != _wall_bounded.end();
139
140 // If we are on an internal face, we populate the two entries in the right hand side
141 // which touch the face
142 if (_current_face_type == FaceInfo::VarFaceNeighbors::BOTH)
143 {
144 // The dof ids of the variable corresponding to the element and neighbor
147
148 // Compute the entries which will go to the neighbor and element positions.
149 const auto elem_rhs_contribution = computeElemRightHandSideContribution();
150 const auto neighbor_rhs_contribution = computeNeighborRightHandSideContribution();
151
152 // Populate right hand side
153 if (hasBlocks(_current_face_info->elemInfo()->subdomain_id()) && !(bounded_elem))
154 _rhs_contribution(0) = elem_rhs_contribution;
155 if (hasBlocks(_current_face_info->neighborInfo()->subdomain_id()) && !(bounded_neigh))
156 _rhs_contribution(1) = neighbor_rhs_contribution;
157
159 .add_vector(_rhs_contribution.get_values().data(), _dof_indices.get_values());
160 }
161 // We are at a block boundary where the variable is not defined on one of the adjacent cells.
162 // We check if we have a boundary condition here
163 else if (_current_face_type == FaceInfo::VarFaceNeighbors::ELEM ||
164 _current_face_type == FaceInfo::VarFaceNeighbors::NEIGHBOR)
165 {
166 mooseAssert(_current_face_info->boundaryIDs().size() == 1,
167 "We should only have one boundary on every face.");
168 LinearFVBoundaryCondition * bc_pointer =
170
171 if (bc_pointer || _force_boundary_execution)
172 {
173 if (bc_pointer)
175
176 const auto rhs_contribution = computeBoundaryRHSContribution(*bc_pointer);
177
178 // We allow internal (for the mesh) boundaries too, so we have to check on which side we
179 // are on (assuming that this is a boundary for the variable)
180 if ((_current_face_type == FaceInfo::VarFaceNeighbors::ELEM) && !(bounded_elem))
181 {
182 const auto dof_id_elem = _current_face_info->elemInfo()->dofIndices()[_sys_num][_var_num];
183 (*_linear_system.rhs).add(dof_id_elem, rhs_contribution);
184 }
185 else if ((_current_face_type == FaceInfo::VarFaceNeighbors::NEIGHBOR) && !(bounded_neigh))
186 {
187 const auto dof_id_neighbor =
189 (*_linear_system.rhs).add(dof_id_neighbor, rhs_contribution);
190 }
191 }
192 }
193}
194
195Real
201
202Real
208
209Real
214
215Real
220
221Real
223{
224 const auto * const adv_bc = cast_ptr<const LinearFVAdvectionDiffusionBC *>(&bc);
225 mooseAssert(adv_bc, "This should be a valid BC!");
226
227 const auto boundary_value_matrix_contrib = adv_bc->computeBoundaryValueMatrixContribution();
228
229 // We support internal boundaries too so we have to make sure the normal points always outward
230 const auto factor = (_current_face_type == FaceInfo::VarFaceNeighbors::ELEM) ? 1.0 : -1.0;
231
232 return boundary_value_matrix_contrib * factor * _mass_face_flux * _current_face_area;
233}
234
235Real
237{
238 const auto * const adv_bc = cast_ptr<const LinearFVAdvectionDiffusionBC *>(&bc);
239 mooseAssert(adv_bc, "This should be a valid BC!");
240
241 // We support internal boundaries too so we have to make sure the normal points always outward
242 const auto factor = (_current_face_type == FaceInfo::VarFaceNeighbors::ELEM ? 1.0 : -1.0);
243
244 const auto boundary_value_rhs_contrib = adv_bc->computeBoundaryValueRHSContribution();
245 return -boundary_value_rhs_contrib * factor * _mass_face_flux * _current_face_area;
246}
247
248void
250{
252
253 // Caching the mass flux on the face which will be reused in the advection term's matrix and right
254 // hand side contributions
256
257 // Only internal faces need advected interpolation results; boundary contributions are handled
258 // through the linear FV boundary conditions.
259 if (_current_face_type != FaceInfo::VarFaceNeighbors::BOTH)
260 return;
261
262 const auto state = determineState();
263 const auto & elem_info = *_current_face_info->elemInfo();
264 const auto & neighbor_info = *_current_face_info->neighborInfo();
265
266 const Real elem_value = _var.getElemValue(elem_info, state);
267 const Real neighbor_value = _var.getElemValue(neighbor_info, state);
269 {
270 mooseAssert(_gradient_field, "Gradient field should be registered when gradients are needed.");
273 }
274
276 elem_value,
277 neighbor_value,
281}
registerMooseObject("NavierStokesApp", LinearFVTurbulentAdvection)
bool hasBlocks(const SubdomainName &name) const
virtual const std::set< SubdomainID > & blockIDs() const
SubdomainID subdomain_id() const
const std::vector< std::vector< dof_id_type > > & dofIndices() const
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
virtual bool needsGradients() const
const std::set< BoundaryID > & boundaryIDs() const
const Elem * neighborPtr() const
const ElemInfo * elemInfo() const
const ElemInfo * neighborInfo() const
const Elem * elemPtr() const
void addRequiredParam(const std::string &name, const std::string &doc_string)
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)
void setupFaceData(const FaceInfo *face_info, const FaceInfo::VarFaceNeighbors face_type)
FaceInfo::VarFaceNeighbors _current_face_type
DenseMatrix< Real > _matrix_contribution
virtual void setupFaceData(const FaceInfo *face_info)
DenseVector< Real > _rhs_contribution
DenseVector< dof_id_type > _dof_indices
const bool _force_boundary_execution
const FaceInfo * _current_face_info
static InputParameters validParams()
RealVectorValue gradient(const ElemInfo &elem_info) const
MooseLinearVariableFV< Real > & _var
const unsigned int _sys_num
const unsigned int _var_num
An advection kernel that implements the advection term for the turbulent variables limited for the fi...
virtual Real computeNeighborRightHandSideContribution() override
virtual Real computeElemRightHandSideContribution() override
const RhieChowMassFlux & _mass_flux_provider
The Rhie-Chow user object that provides us with the face velocity.
virtual Real computeNeighborMatrixContribution() override
virtual void addRightHandSideContribution() override
VectorValue< Real > _elem_grad_storage
Reusable gradient storage used when advected interpolation requires gradients.
const std::vector< BoundaryName > & _wall_boundary_names
Wall boundaries.
virtual Real computeBoundaryRHSContribution(const LinearFVBoundaryCondition &bc) override
const LinearFVGradientReader *const _gradient_field
Gradient field used by advected interpolations that require gradients.
virtual void addMatrixContribution() override
const FVAdvectedInterpolationMethod & _adv_interp_method
The interpolation method to use for the advected quantity.
virtual Real computeBoundaryMatrixContribution(const LinearFVBoundaryCondition &bc) override
virtual Real computeElemMatrixContribution() override
FVAdvectedInterpolationMethod::AdvectedSystemContribution _adv_interp_result
Cached weights/correction for the current face (refreshed in setupFaceData)
LinearFVTurbulentAdvection(const InputParameters &params)
std::unordered_set< const Elem * > _wall_bounded
List for wall bounded elements.
Real _mass_face_flux
Container for the mass flux on the face which will be reused in the advection term's matrix and right...
virtual void setupFaceData(const FaceInfo *face_info) override
static InputParameters validParams()
FEProblemBase & _fe_problem
libMesh::LinearImplicitSystem & _linear_system
Real getElemValue(const ElemInfo &elem_info, const StateArg &state) const
LinearFVBoundaryCondition * getBoundaryCondition(const BoundaryID bd_id) const
User object responsible for determining the face fluxes using the Rhie-Chow interpolation in a segreg...
Real getMassFlux(const FaceInfo &fi) const
Get the face velocity times density (used in advection terms)
virtual void initialSetup()
SubProblem & _subproblem
Moose::StateArg determineState() const
std::vector< T > & get_values()
NumericVector< Number > * rhs
SparseMatrix< Number > * matrix
void getWallBoundedElements(const std::vector< BoundaryName > &wall_boundary_name, const FEProblemBase &fe_problem, const SubProblem &subproblem, const std::set< SubdomainID > &block_ids, std::unordered_set< const Elem * > &wall_bounded)
Map marking wall bounded elements The map passed in wall_bounded_map gets cleared and re-populated.