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://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
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 // The boundary contributions rely on the Rhie-Chow flux being oriented outward from this
52 // variable's cell, which only holds if the variable's one-sided faces are one-sided for the
53 // flow too.
55}
56
57void
64
65void
67{
68 // Coumputing bounding map
69 const Elem * elem = _current_face_info->elemPtr();
70 const auto bounded_elem = _wall_bounded.find(elem) != _wall_bounded.end();
71 const Elem * neighbor = _current_face_info->neighborPtr();
72 const auto bounded_neigh = _wall_bounded.find(neighbor) != _wall_bounded.end();
73
74 // If we are on an internal face, we populate the four entries in the system matrix
75 // which touch the face
76 if (_current_face_type == FaceInfo::VarFaceNeighbors::BOTH)
77 {
78 // The dof ids of the variable corresponding to the element and neighbor
81
82 // Compute the entries which will go to the neighbor (offdiagonal) and element
83 // (diagonal).
84 const auto elem_matrix_contribution = computeElemMatrixContribution();
85 const auto neighbor_matrix_contribution = computeNeighborMatrixContribution();
86
87 // Populate matrix
88 if (hasBlocks(_current_face_info->elemInfo()->subdomain_id()) && !(bounded_elem))
89 {
90 _matrix_contribution(0, 0) = elem_matrix_contribution;
91 _matrix_contribution(0, 1) = neighbor_matrix_contribution;
92 }
93
94 if (hasBlocks(_current_face_info->neighborInfo()->subdomain_id()) && !(bounded_neigh))
95 {
96 _matrix_contribution(1, 0) = -elem_matrix_contribution;
97 _matrix_contribution(1, 1) = -neighbor_matrix_contribution;
98 }
100 }
101 // We are at a block boundary where the variable is not defined on one of the adjacent cells.
102 // We check if we have a boundary condition here
103 else if (_current_face_type == FaceInfo::VarFaceNeighbors::ELEM ||
104 _current_face_type == FaceInfo::VarFaceNeighbors::NEIGHBOR)
105 {
106 mooseAssert(_current_face_info->boundaryIDs().size() == 1,
107 "We should only have one boundary on every face.");
108
109 LinearFVBoundaryCondition * bc_pointer =
111
112 if (bc_pointer || _force_boundary_execution)
113 {
114 if (bc_pointer)
116 const auto matrix_contribution = computeBoundaryMatrixContribution(*bc_pointer);
117
118 // We allow internal (for the mesh) boundaries too, so we have to check on which side we
119 // are on (assuming that this is a boundary for the variable)
120 if ((_current_face_type == FaceInfo::VarFaceNeighbors::ELEM) && !(bounded_elem))
121 {
122 const auto dof_id_elem = _current_face_info->elemInfo()->dofIndices()[_sys_num][_var_num];
123 (*_linear_system.matrix).add(dof_id_elem, dof_id_elem, matrix_contribution);
124 }
125 else if ((_current_face_type == FaceInfo::VarFaceNeighbors::NEIGHBOR) && !(bounded_neigh))
126 {
127 const auto dof_id_neighbor =
129 (*_linear_system.matrix).add(dof_id_neighbor, dof_id_neighbor, matrix_contribution);
130 }
131 }
132 }
133}
134
135void
137{
138 // Coumputing bounding map
139 const Elem * elem = _current_face_info->elemPtr();
140 const auto bounded_elem = _wall_bounded.find(elem) != _wall_bounded.end();
141 const Elem * neighbor = _current_face_info->neighborPtr();
142 const auto bounded_neigh = _wall_bounded.find(neighbor) != _wall_bounded.end();
143
144 // If we are on an internal face, we populate the two entries in the right hand side
145 // which touch the face
146 if (_current_face_type == FaceInfo::VarFaceNeighbors::BOTH)
147 {
148 // The dof ids of the variable corresponding to the element and neighbor
151
152 // Compute the entries which will go to the neighbor and element positions.
153 const auto elem_rhs_contribution = computeElemRightHandSideContribution();
154 const auto neighbor_rhs_contribution = computeNeighborRightHandSideContribution();
155
156 // Populate right hand side
157 if (hasBlocks(_current_face_info->elemInfo()->subdomain_id()) && !(bounded_elem))
158 _rhs_contribution(0) = elem_rhs_contribution;
159 if (hasBlocks(_current_face_info->neighborInfo()->subdomain_id()) && !(bounded_neigh))
160 _rhs_contribution(1) = neighbor_rhs_contribution;
161
163 .add_vector(_rhs_contribution.get_values().data(), _dof_indices.get_values());
164 }
165 // We are at a block boundary where the variable is not defined on one of the adjacent cells.
166 // We check if we have a boundary condition here
167 else if (_current_face_type == FaceInfo::VarFaceNeighbors::ELEM ||
168 _current_face_type == FaceInfo::VarFaceNeighbors::NEIGHBOR)
169 {
170 mooseAssert(_current_face_info->boundaryIDs().size() == 1,
171 "We should only have one boundary on every face.");
172 LinearFVBoundaryCondition * bc_pointer =
174
175 if (bc_pointer || _force_boundary_execution)
176 {
177 if (bc_pointer)
179
180 const auto rhs_contribution = computeBoundaryRHSContribution(*bc_pointer);
181
182 // We allow internal (for the mesh) boundaries too, so we have to check on which side we
183 // are on (assuming that this is a boundary for the variable)
184 if ((_current_face_type == FaceInfo::VarFaceNeighbors::ELEM) && !(bounded_elem))
185 {
186 const auto dof_id_elem = _current_face_info->elemInfo()->dofIndices()[_sys_num][_var_num];
187 (*_linear_system.rhs).add(dof_id_elem, rhs_contribution);
188 }
189 else if ((_current_face_type == FaceInfo::VarFaceNeighbors::NEIGHBOR) && !(bounded_neigh))
190 {
191 const auto dof_id_neighbor =
193 (*_linear_system.rhs).add(dof_id_neighbor, rhs_contribution);
194 }
195 }
196 }
197}
198
199Real
205
206Real
212
213Real
218
219Real
224
225Real
227{
228 const auto * const adv_bc = cast_ptr<const LinearFVAdvectionDiffusionBC *>(&bc);
229 mooseAssert(adv_bc, "This should be a valid BC!");
230
231 const auto boundary_value_matrix_contrib = adv_bc->computeBoundaryValueMatrixContribution();
232
233 // Rhie-Chow mass fluxes on one-sided boundary faces are already oriented outward from the
234 // active cell, even when the active cell is the FaceInfo neighbor.
235 return boundary_value_matrix_contrib * _mass_face_flux * _current_face_area;
236}
237
238Real
240{
241 const auto * const adv_bc = cast_ptr<const LinearFVAdvectionDiffusionBC *>(&bc);
242 mooseAssert(adv_bc, "This should be a valid BC!");
243
244 const auto boundary_value_rhs_contrib = adv_bc->computeBoundaryValueRHSContribution();
245 return -boundary_value_rhs_contrib * _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)
void checkBlocks(const VarType &var) const
Check the block consistency between the passed in var and us.
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.