https://mooseframework.inl.gov
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 
11 #include "MooseLinearVariableFV.h"
12 #include "NSFVUtils.h"
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.addParam<std::vector<BoundaryName>>(
26  "walls", {}, "Boundaries that correspond to solid walls.");
27 
28  return params;
29 }
30 
32  : LinearFVScalarAdvection(params),
33  _advected_interp_coeffs(std::make_pair<Real, Real>(0, 0)),
34  _wall_boundary_names(getParam<std::vector<BoundaryName>>("walls"))
35 {
36  Moose::FV::setInterpolationMethod(*this, _advected_interp_method, "advected_interp_method");
37 }
38 
39 void
41 {
45 }
46 
47 void
49 {
50  // Coumputing bounding map
51  const Elem * elem = _current_face_info->elemPtr();
52  const auto bounded_elem = _wall_bounded.find(elem) != _wall_bounded.end();
53  const Elem * neighbor = _current_face_info->neighborPtr();
54  const auto bounded_neigh = _wall_bounded.find(neighbor) != _wall_bounded.end();
55 
56  // If we are on an internal face, we populate the four entries in the system matrix
57  // which touch the face
59  {
60  // The dof ids of the variable corresponding to the element and neighbor
63 
64  // Compute the entries which will go to the neighbor (offdiagonal) and element
65  // (diagonal).
66  const auto elem_matrix_contribution = computeElemMatrixContribution();
67  const auto neighbor_matrix_contribution = computeNeighborMatrixContribution();
68 
69  // Populate matrix
70  if (hasBlocks(_current_face_info->elemInfo()->subdomain_id()) && !(bounded_elem))
71  {
72  _matrix_contribution(0, 0) = elem_matrix_contribution;
73  _matrix_contribution(0, 1) = neighbor_matrix_contribution;
74  }
75 
76  if (hasBlocks(_current_face_info->neighborInfo()->subdomain_id()) && !(bounded_neigh))
77  {
78  _matrix_contribution(1, 0) = -elem_matrix_contribution;
79  _matrix_contribution(1, 1) = -neighbor_matrix_contribution;
80  }
81  (*_linear_system.matrix).add_matrix(_matrix_contribution, _dof_indices.get_values());
82  }
83  // We are at a block boundary where the variable is not defined on one of the adjacent cells.
84  // We check if we have a boundary condition here
87  {
88  mooseAssert(_current_face_info->boundaryIDs().size() == 1,
89  "We should only have one boundary on every face.");
90 
91  LinearFVBoundaryCondition * bc_pointer =
93 
94  if (bc_pointer || _force_boundary_execution)
95  {
96  if (bc_pointer)
98  const auto matrix_contribution = computeBoundaryMatrixContribution(*bc_pointer);
99 
100  // We allow internal (for the mesh) boundaries too, so we have to check on which side we
101  // are on (assuming that this is a boundary for the variable)
102  if ((_current_face_type == FaceInfo::VarFaceNeighbors::ELEM) && !(bounded_elem))
103  {
104  const auto dof_id_elem = _current_face_info->elemInfo()->dofIndices()[_sys_num][_var_num];
105  (*_linear_system.matrix).add(dof_id_elem, dof_id_elem, matrix_contribution);
106  }
107  else if ((_current_face_type == FaceInfo::VarFaceNeighbors::NEIGHBOR) && !(bounded_neigh))
108  {
109  const auto dof_id_neighbor =
111  (*_linear_system.matrix).add(dof_id_neighbor, dof_id_neighbor, matrix_contribution);
112  }
113  }
114  }
115 }
116 
117 void
119 {
120  // Coumputing bounding map
121  const Elem * elem = _current_face_info->elemPtr();
122  const auto bounded_elem = _wall_bounded.find(elem) != _wall_bounded.end();
123  const Elem * neighbor = _current_face_info->neighborPtr();
124  const auto bounded_neigh = _wall_bounded.find(neighbor) != _wall_bounded.end();
125 
126  // If we are on an internal face, we populate the two entries in the right hand side
127  // which touch the face
129  {
130  // The dof ids of the variable corresponding to the element and neighbor
133 
134  // Compute the entries which will go to the neighbor and element positions.
135  const auto elem_rhs_contribution = computeElemRightHandSideContribution();
136  const auto neighbor_rhs_contribution = computeNeighborRightHandSideContribution();
137 
138  // Populate right hand side
139  if (hasBlocks(_current_face_info->elemInfo()->subdomain_id()) && !(bounded_elem))
140  _rhs_contribution(0) = elem_rhs_contribution;
141  if (hasBlocks(_current_face_info->neighborInfo()->subdomain_id()) && !(bounded_neigh))
142  _rhs_contribution(1) = neighbor_rhs_contribution;
143 
145  .add_vector(_rhs_contribution.get_values().data(), _dof_indices.get_values());
146  }
147  // We are at a block boundary where the variable is not defined on one of the adjacent cells.
148  // We check if we have a boundary condition here
151  {
152  mooseAssert(_current_face_info->boundaryIDs().size() == 1,
153  "We should only have one boundary on every face.");
154  LinearFVBoundaryCondition * bc_pointer =
156 
157  if (bc_pointer || _force_boundary_execution)
158  {
159  if (bc_pointer)
161 
162  const auto rhs_contribution = computeBoundaryRHSContribution(*bc_pointer);
163 
164  // We allow internal (for the mesh) boundaries too, so we have to check on which side we
165  // are on (assuming that this is a boundary for the variable)
166  if ((_current_face_type == FaceInfo::VarFaceNeighbors::ELEM) && !(bounded_elem))
167  {
168  const auto dof_id_elem = _current_face_info->elemInfo()->dofIndices()[_sys_num][_var_num];
169  (*_linear_system.rhs).add(dof_id_elem, rhs_contribution);
170  }
171  else if ((_current_face_type == FaceInfo::VarFaceNeighbors::NEIGHBOR) && !(bounded_neigh))
172  {
173  const auto dof_id_neighbor =
175  (*_linear_system.rhs).add(dof_id_neighbor, rhs_contribution);
176  }
177  }
178  }
179 }
virtual void addRightHandSideContribution() override
const unsigned int _var_num
SubProblem & _subproblem
virtual void addMatrixContribution() override
const std::set< BoundaryID > & boundaryIDs() const
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
libMesh::LinearImplicitSystem & _linear_system
const ElemInfo * neighborInfo() const
virtual Real computeNeighborMatrixContribution() override
void setupFaceData(const FaceInfo *face_info, const FaceInfo::VarFaceNeighbors face_type)
MooseLinearVariableFV< Real > & _var
NumericVector< Number > * rhs
const ElemInfo * elemInfo() const
static InputParameters validParams()
LinearFVBoundaryCondition * getBoundaryCondition(const BoundaryID bd_id) const
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...
virtual const std::set< SubdomainID > & blockIDs() const
virtual void initialSetup() override
FaceInfo::VarFaceNeighbors _current_face_type
const bool _force_boundary_execution
DenseVector< Real > _rhs_contribution
const std::vector< BoundaryName > & _wall_boundary_names
Wall boundaries.
const FaceInfo * _current_face_info
const Elem * neighborPtr() const
virtual Real computeElemRightHandSideContribution() override
An advection kernel that implements the advection term for the turbulent variables limited for the fi...
virtual Real computeElemMatrixContribution() override
const Elem * elemPtr() const
Moose::FV::InterpMethod _advected_interp_method
The interpolation method to use for the advected quantity.
DenseVector< dof_id_type > _dof_indices
const std::vector< std::vector< dof_id_type > > & dofIndices() const
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual Real computeNeighborRightHandSideContribution() override
virtual Real computeBoundaryRHSContribution(const LinearFVBoundaryCondition &bc) override
SparseMatrix< Number > * matrix
static InputParameters validParams()
LinearFVTurbulentAdvection(const InputParameters &params)
void addClassDescription(const std::string &doc_string)
An advection kernel that implements the advection term for the passive scalar transport equation...
registerMooseObject("NavierStokesApp", LinearFVTurbulentAdvection)
FEProblemBase & _fe_problem
virtual Real computeBoundaryMatrixContribution(const LinearFVBoundaryCondition &bc) override
bool hasBlocks(const SubdomainName &name) const
virtual void initialSetup()
std::unordered_set< const Elem * > _wall_bounded
List for wall bounded elements.
const unsigned int _sys_num
bool setInterpolationMethod(const MooseObject &obj, Moose::FV::InterpMethod &interp_method, const std::string &param_name)
SubdomainID subdomain_id() const
DenseMatrix< Real > _matrix_contribution