https://mooseframework.inl.gov
RhieChowInterpolatorBase.h
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 #pragma once
11 
13 #include "TaggingInterface.h"
14 #include "INSFVPressureVariable.h"
15 #include "ADReal.h"
16 #include "ADFunctorInterface.h"
17 #include "INSFVPressureVariable.h"
18 #include "libmesh/vector_value.h"
19 #include "libmesh/id_types.h"
20 #include "libmesh/stored_range.h"
21 
22 class MooseMesh;
25 namespace libMesh
26 {
27 class Elem;
28 class MeshBase;
29 }
30 
32  public TaggingInterface,
33  public ADFunctorInterface
34 {
35 public:
38 
47  virtual void addToA(const libMesh::Elem * elem, unsigned int component, const ADReal & value) = 0;
48 
57  virtual VectorValue<ADReal> getVelocity(const Moose::FV::InterpMethod m,
58  const FaceInfo & fi,
59  const Moose::StateArg & time,
60  const THREAD_ID tid,
61  bool subtract_mesh_velocity) const = 0;
62 
64  const FaceInfo & fi,
65  const Moose::StateArg & time,
66  const THREAD_ID tid,
67  bool subtract_mesh_velocity) const override;
68 
71 
76  virtual void ghostADataOnBoundary(const BoundaryID /*boundary_id*/) {}
77 
81  const INSFVPressureVariable & pressure(THREAD_ID tid) const;
82 
83  const INSFVVelocityVariable * vel() const { return _u; }
84 
86  virtual bool segregated() const = 0;
87 
88 protected:
92  virtual const Moose::FunctorBase<ADReal> & epsilon(THREAD_ID tid) const;
93 
97  template <typename Container>
98  void fillContainer(const std::string & var_name, Container & container);
99 
103  template <typename VarType>
104  void checkBlocks(const VarType & var) const;
105 
108 
111 
113  const unsigned int _dim;
114 
117 
120 
123 
126 
128  std::vector<MooseVariableFVReal *> _ps;
129 
131  std::vector<MooseVariableFVReal *> _us;
132 
134  std::vector<MooseVariableFVReal *> _vs;
135 
137  std::vector<MooseVariableFVReal *> _ws;
138 
140  std::vector<unsigned int> _var_numbers;
141 
144 
147 
149  const bool _displaced;
150 
151 private:
154 };
155 
156 inline const Moose::FunctorBase<ADReal> &
158 {
159  return _unity_functor;
160 }
161 
162 inline const INSFVPressureVariable &
164 {
165  mooseAssert(tid < _ps.size(), "Attempt to access out-of-bounds in pressure variable container");
166  return *static_cast<INSFVPressureVariable *>(_ps[tid]);
167 }
168 
169 template <typename Container>
170 void
171 RhieChowInterpolatorBase::fillContainer(const std::string & name, Container & container)
172 {
173  typedef typename Container::value_type ContainedType;
174  for (const auto tid : make_range(libMesh::n_threads()))
175  {
176  auto * const var = static_cast<ContainedType>(
177  &UserObject::_subproblem.getVariable(tid, getParam<VariableName>(name)));
178  container[tid] = var;
179  }
180 }
181 
182 template <typename VarType>
183 void
184 RhieChowInterpolatorBase::checkBlocks(const VarType & var) const
185 {
186  const auto & var_blocks = var.blockIDs();
187  const auto & uo_blocks = blockIDs();
188 
189  // Error if this UO has any blocks that the variable does not
190  std::set<SubdomainID> uo_blocks_minus_var_blocks;
191  std::set_difference(uo_blocks.begin(),
192  uo_blocks.end(),
193  var_blocks.begin(),
194  var_blocks.end(),
195  std::inserter(uo_blocks_minus_var_blocks, uo_blocks_minus_var_blocks.end()));
196  if (uo_blocks_minus_var_blocks.size() > 0)
197  mooseError("Block restriction of interpolator user object '",
198  this->name(),
199  "' (",
201  ") includes blocks not in the block restriction of variable '",
202  var.name(),
203  "' (",
204  Moose::stringify(var.blocks()),
205  ")");
206 
207  // Get the blocks in the variable but not this UO
208  std::set<SubdomainID> var_blocks_minus_uo_blocks;
209  std::set_difference(var_blocks.begin(),
210  var_blocks.end(),
211  uo_blocks.begin(),
212  uo_blocks.end(),
213  std::inserter(var_blocks_minus_uo_blocks, var_blocks_minus_uo_blocks.end()));
214 
215  // For each block in the variable but not this UO, error if there is connection
216  // to any blocks on the UO.
217  for (auto & block_id : var_blocks_minus_uo_blocks)
218  {
219  const auto connected_blocks = _moose_mesh.getBlockConnectedBlocks(block_id);
220  std::set<SubdomainID> connected_blocks_on_uo;
221  std::set_intersection(connected_blocks.begin(),
222  connected_blocks.end(),
223  uo_blocks.begin(),
224  uo_blocks.end(),
225  std::inserter(connected_blocks_on_uo, connected_blocks_on_uo.end()));
226  if (connected_blocks_on_uo.size() > 0)
227  mooseError("Block restriction of interpolator user object '",
228  this->name(),
229  "' (",
230  Moose::stringify(uo_blocks),
231  ") doesn't match the block restriction of variable '",
232  var.name(),
233  "' (",
234  Moose::stringify(var_blocks),
235  ")");
236  }
237 }
INSFVPressureVariable *const _p
The thread 0 copy of the pressure variable.
std::vector< MooseVariableFVReal * > _ps
All the thread copies of the pressure variable.
const INSFVPressureVariable & pressure(THREAD_ID tid) const
unsigned int n_threads()
SystemBase & _sys
The nonlinear system.
MooseMesh & _moose_mesh
The MooseMesh that this user object operates on.
virtual const Moose::FunctorBase< ADReal > & epsilon(THREAD_ID tid) const
A virtual method that allows us to only implement getVelocity once for free and porous flows...
INSFVVelocityVariable *const _u
The thread 0 copy of the x-velocity variable.
INSFVVelocityVariable *const _v
The thread 0 copy of the y-velocity variable (null if the problem is 1D)
static const std::string component
Definition: NS.h:153
const std::set< SubdomainID > & getBlockConnectedBlocks(const SubdomainID subdomain_id) const
const bool _displaced
Whether this object is operating on the displaced mesh.
Moose::FV::InterpMethod velocityInterpolationMethod() const
Return the interpolation method used for velocity.
virtual const std::set< SubdomainID > & blockIDs() const
The following methods are specializations for using the Parallel::packed_range_* routines for a vecto...
virtual void ghostADataOnBoundary(const BoundaryID)
makes sure coefficient data gets communicated on both sides of a given boundary.
DualNumber< Real, DNDerivativeType, true > ADReal
virtual const std::string & name() const
SubProblem & _subproblem
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.
std::vector< MooseVariableFVReal * > _us
All the thread copies of the x-velocity variable.
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
RhieChowInterpolatorBase(const InputParameters &params)
virtual bool segregated() const =0
Bool of the Rhie Chow user object is used in monolithic/segregated approaches.
boundary_id_type BoundaryID
const std::string name
Definition: Setup.h:20
const unsigned int _dim
The dimension of the mesh, e.g. 3 for hexes and tets, 2 for quads and tris.
virtual const MooseVariableFieldBase & getVariable(const THREAD_ID tid, const std::string &var_name, Moose::VarKindType expected_var_type=Moose::VarKindType::VAR_ANY, Moose::VarFieldType expected_var_field_type=Moose::VarFieldType::VAR_FIELD_ANY) const=0
std::string stringify(const T &t)
Moose::FV::InterpMethod _velocity_interp_method
The interpolation method to use for the velocity.
void fillContainer(const std::string &var_name, Container &container)
Fill the passed-in variable container with the thread copies of var_name.
const libMesh::MeshBase & _mesh
The libMesh mesh that this object acts on.
virtual Real getVolumetricFaceFlux(const Moose::FV::InterpMethod m, const FaceInfo &fi, const Moose::StateArg &time, const THREAD_ID tid, bool subtract_mesh_velocity) const override
Retrieve the volumetric face flux, will not include derivatives.
void checkBlocks(const VarType &var) const
Check the block consistency between the passed in var and us.
const INSFVVelocityVariable * vel() const
const std::vector< SubdomainName > & blocks() const
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual void addToA(const libMesh::Elem *elem, unsigned int component, const ADReal &value)=0
API for momentum residual objects that have on-diagonals for velocity call.
INSFVVelocityVariable *const _w
The thread 0 copy of the z-velocity variable (null if the problem is not 3D)
std::vector< unsigned int > _var_numbers
The velocity variable numbers.
IntRange< T > make_range(T beg, T end)
void mooseError(Args &&... args) const
std::vector< MooseVariableFVReal * > _ws
All the thread copies of the z-velocity variable.
const Moose::ConstantFunctor< ADReal > _unity_functor
A unity functor used in the epsilon virtual method.
std::vector< MooseVariableFVReal * > _vs
All the thread copies of the y-velocity variable.
static InputParameters validParams()
unsigned int THREAD_ID