https://mooseframework.inl.gov
INSFVTurbulentAdvection.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 
11 #include "NavierStokesMethods.h"
12 #include "NS.h"
13 
15 
18 {
19  auto params = INSFVAdvectionKernel::validParams();
20  params.addClassDescription(
21  "Advects an arbitrary turbulent quantity, the associated nonlinear 'variable'.");
22  params.addRequiredParam<MooseFunctorName>(NS::density, "fluid density");
23  params.addParam<std::vector<BoundaryName>>(
24  "walls", {}, "Boundaries that correspond to solid walls.");
25  params.addParam<bool>("neglect_advection_derivatives",
26  true,
27  "Whether to remove automatic differentiation derivative terms "
28  "for velocity in the advection term");
29  return params;
30 }
31 
33  : INSFVAdvectionKernel(params),
34  _rho(getFunctor<ADReal>(NS::density)),
35  _wall_boundary_names(getParam<std::vector<BoundaryName>>("walls")),
36  _neglect_advection_derivatives(getParam<bool>("neglect_advection_derivatives"))
37 {
38 }
39 
40 void
42 {
46 }
47 
48 ADReal
50 {
51  const auto v = _rc_vel_provider.getVelocity(
53  const auto var_face = _var(makeFace(*_face_info,
56  determineState());
57  const auto rho_face = _rho(makeFace(*_face_info,
60  determineState());
62  return _normal * v * rho_face * var_face;
63  else
64  return _normal * MetaPhysicL::raw_value(v) * rho_face * var_face;
65 }
66 
67 void
69 {
70  if (skipForBoundary(fi))
71  return;
72 
73  _face_info = &fi;
74  _normal = fi.normal();
75  _face_type = _face_info->faceType(std::make_pair(_var.number(), _var.sys().number()));
77 
78  const Elem * elem = fi.elemPtr();
79  const Elem * neighbor = fi.neighborPtr();
80  const auto bounded_elem = _wall_bounded.find(elem) != _wall_bounded.end();
81  const auto bounded_neigh = _wall_bounded.find(neighbor) != _wall_bounded.end();
82 
85  (!bounded_elem))
86  {
87  // residual contribution of this kernel to the elem element
89  _local_re(0) = r;
91  }
94  (!bounded_neigh))
95  {
96  // residual contribution of this kernel to the neighbor element
98  _local_re(0) = -r;
100  }
101 }
102 
103 void
105 {
106  if (skipForBoundary(fi))
107  return;
108 
109  _face_info = &fi;
110  _normal = fi.normal();
111  _face_type = _face_info->faceType(std::make_pair(_var.number(), _var.sys().number()));
112  const ADReal r = fi.faceArea() * fi.faceCoord() * computeQpResidual();
113 
114  const Elem * elem = fi.elemPtr();
115  const Elem * neighbor = fi.neighborPtr();
116  const auto bounded_elem = _wall_bounded.find(elem) != _wall_bounded.end();
117  const auto bounded_neigh = _wall_bounded.find(neighbor) != _wall_bounded.end();
118 
121  (!bounded_elem))
122  {
123  mooseAssert(_var.dofIndices().size() == 1, "We're currently built to use CONSTANT MONOMIALS");
124 
126  _assembly, std::array<ADReal, 1>{{r}}, _var.dofIndices(), _var.scalingFactor());
127  }
128 
131  (!bounded_neigh))
132  {
134  (_var.dofIndices().size() == 0),
135  "If the variable is only defined on the neighbor hand side of the face, then that "
136  "means it should have no dof indices on the elem element. Conversely if "
137  "the variable is defined on both sides of the face, then it should have a non-zero "
138  "number of degrees of freedom on the elem element");
139 
140  // We switch the sign for the neighbor residual
141  ADReal neighbor_r = -r;
142 
143  mooseAssert(_var.dofIndicesNeighbor().size() == 1,
144  "We're currently built to use CONSTANT MONOMIALS");
145 
147  std::array<ADReal, 1>{{neighbor_r}},
149  _var.scalingFactor());
150  }
151 }
virtual const std::vector< dof_id_type > & dofIndicesNeighbor() const final
Moose::FV::InterpMethod _advected_interp_method
The interpolation method to use for the advected quantity.
void addResidualsAndJacobian(Assembly &assembly, const Residuals &residuals, const Indices &dof_indices, Real scaling_factor)
void accumulateTaggedLocalResidual()
Moose::FV::InterpMethod _velocity_interp_method
The interpolation method to use for the velocity.
Computes the advection term with the assumption that the advected quantity will have special wall tre...
unsigned int number() const
void getWallBoundedElements(const std::vector< BoundaryName > &wall_boundary_name, const FEProblemBase &fe_problem, const SubProblem &subproblem, const std::set< SubdomainID > &block_ids, std::map< const Elem *, bool > &wall_bounded_map)
Map marking wall bounded elements The map passed in wall_bounded_map gets cleared and re-populated...
const FaceInfo * _face_info
Moose::StateArg determineState() const
virtual void initialSetup() override
static const std::string density
Definition: NS.h:33
auto raw_value(const Eigen::Map< T > &in)
const bool _neglect_advection_derivatives
Whether to remove the derivative of this term wrt to velocity.
Real & faceCoord()
virtual const std::set< SubdomainID > & blockIDs() const
RealVectorValue _normal
DualNumber< Real, DNDerivativeType, true > ADReal
THREAD_ID _tid
Real faceArea() const
const RhieChowInterpolatorBase & _rc_vel_provider
The Rhie-Chow user object that provides us with the velocity.
void computeJacobian() override
virtual VectorValue< ADReal > getVelocity(const Moose::FV::InterpMethod m, const FaceInfo &fi, const Moose::StateArg &time, const THREAD_ID tid, bool subtract_mesh_velocity) const =0
Retrieve a face velocity.
ADReal computeQpResidual() override
LimiterType limiterType(InterpMethod interp_method)
const Elem * neighborPtr() const
bool skipForBoundary(const FaceInfo &fi) const override
SubProblem & _subproblem
FEProblemBase & _fe_problem
const Point & normal() const
unsigned int number() const
static InputParameters validParams()
const std::vector< BoundaryName > & _wall_boundary_names
Wall boundaries.
FaceInfo::VarFaceNeighbors _face_type
Assembly & _assembly
const Elem * elemPtr() const
void prepareVectorTagNeighbor(Assembly &assembly, unsigned int ivar)
static const std::string v
Definition: NS.h:84
void initialSetup() override
An advection kernel that implements interpolation schemes specific to Navier-Stokes flow physics...
DenseVector< Number > _local_re
std::map< const Elem *, bool > _wall_bounded
Maps for wall treatment.
MooseVariableFV< Real > & _var
INSFVTurbulentAdvection(const InputParameters &params)
const Moose::Functor< ADReal > & _rho
void prepareVectorTag(Assembly &assembly, unsigned int ivar)
static InputParameters validParams()
void computeResidual() override
registerMooseObject("NavierStokesApp", INSFVTurbulentAdvection)
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
void scalingFactor(const std::vector< Real > &factor)
virtual const std::vector< dof_id_type > & dofIndices() const final
VarFaceNeighbors faceType(const std::pair< unsigned int, unsigned int > &var_sys) const