https://mooseframework.inl.gov
RhieChowInterpolatorBase.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 "INSFVAttributes.h"
13 #include "GatherRCDataFaceThread.h"
14 #include "SubProblem.h"
15 #include "MooseMesh.h"
16 #include "SystemBase.h"
17 #include "NS.h"
18 #include "Assembly.h"
19 #include "INSFVVelocityVariable.h"
20 #include "INSFVPressureVariable.h"
22 #include "VectorCompositeFunctor.h"
23 #include "FVElementalKernel.h"
24 
25 #include "libmesh/mesh_base.h"
26 #include "libmesh/elem_range.h"
27 #include "libmesh/parallel_algebra.h"
28 #include "libmesh/remote_elem.h"
29 #include "metaphysicl/dualsemidynamicsparsenumberarray.h"
30 #include "metaphysicl/parallel_dualnumber.h"
31 #include "metaphysicl/parallel_dynamic_std_array_wrapper.h"
32 #include "metaphysicl/parallel_semidynamicsparsenumberarray.h"
33 #include "timpi/parallel_sync.h"
34 
35 using namespace libMesh;
36 
39 {
43 
44  params.addClassDescription(
45  "Computes the Rhie-Chow velocity based on gathered 'a' coefficient data.");
46 
47  // Avoid uninitialized residual objects
48  params.suppressParameter<bool>("force_preic");
49 
50  params.addRequiredParam<VariableName>(NS::pressure, "The pressure variable.");
51  params.addRequiredParam<VariableName>("u", "The x-component of velocity");
52  params.addParam<VariableName>("v", "The y-component of velocity");
53  params.addParam<VariableName>("w", "The z-component of velocity");
54 
55  MooseEnum velocity_interp_method("average rc", "rc");
56  params.addParam<MooseEnum>(
57  "velocity_interp_method",
58  velocity_interp_method,
59  "The interpolation to use for the velocity. Options are "
60  "'average' and 'rc' which stands for Rhie-Chow. The default is Rhie-Chow.");
61 
62  return params;
63 }
64 
66  : RhieChowFaceFluxProvider(params),
67  TaggingInterface(this),
68  ADFunctorInterface(this),
69  _moose_mesh(UserObject::_subproblem.mesh()),
70  _mesh(_moose_mesh.getMesh()),
71  _dim(blocksMaxDimension()),
72  _p(dynamic_cast<INSFVPressureVariable *>(
73  &UserObject::_subproblem.getVariable(0, getParam<VariableName>(NS::pressure)))),
74  _u(dynamic_cast<INSFVVelocityVariable *>(
75  &UserObject::_subproblem.getVariable(0, getParam<VariableName>("u")))),
76  _v(isParamValid("v") ? dynamic_cast<INSFVVelocityVariable *>(
77  &UserObject::_subproblem.getVariable(0, getParam<VariableName>("v")))
78  : nullptr),
79  _w(isParamValid("w") ? dynamic_cast<INSFVVelocityVariable *>(
80  &UserObject::_subproblem.getVariable(0, getParam<VariableName>("w")))
81  : nullptr),
82  _ps(libMesh::n_threads(), nullptr),
83  _us(libMesh::n_threads(), nullptr),
84  _vs(libMesh::n_threads(), nullptr),
85  _ws(libMesh::n_threads(), nullptr),
86  _sys(*getCheckedPointerParam<SystemBase *>("_sys")),
87  _displaced(dynamic_cast<DisplacedProblem *>(&(UserObject::_subproblem)))
88 {
89  if (!_p)
90  paramError(NS::pressure, "the pressure must be a INSFVPressureVariable.");
91  checkBlocks(*_p);
92 
93  if (!_u)
94  paramError("u", "the u velocity must be an INSFVVelocityVariable.");
95  checkBlocks(*_u);
96  _var_numbers.push_back(_u->number());
97 
98  if (_dim >= 2)
99  {
100  if (!_v)
101  mooseError("In two or more dimensions, the v velocity must be supplied and it must be an "
102  "INSFVVelocityVariable.");
103  checkBlocks(*_v);
104  _var_numbers.push_back(_v->number());
105  }
106 
107  if (_dim >= 3)
108  {
109  if (!_w)
110  mooseError("In three-dimensions, the w velocity must be supplied and it must be an "
111  "INSFVVelocityVariable.");
112  checkBlocks(*_w);
113  _var_numbers.push_back(_w->number());
114  }
115 
117  fillContainer("u", _us);
118 
119  if (_dim >= 2)
120  {
121  fillContainer("v", _vs);
123  mooseError("x and y velocity component face interpolation methods do not match");
124 
125  if (_dim >= 3)
126  {
127  fillContainer("w", _ws);
129  mooseError("x and z velocity component face interpolation methods do not match");
130  }
131  }
132 
134  mooseError("Different subproblems in RhieChowInterpolatorBase!");
135 
136  const auto & velocity_interp_method = params.get<MooseEnum>("velocity_interp_method");
137  if (velocity_interp_method == "average")
139  else if (velocity_interp_method == "rc")
141 }
142 
143 Real
145  const FaceInfo & fi,
146  const Moose::StateArg & time,
147  const THREAD_ID tid,
148  bool subtract_mesh_velocity) const
149 {
150  return raw_value(this->getVelocity(m, fi, time, tid, subtract_mesh_velocity)) * fi.normal();
151 }
INSFVPressureVariable *const _p
The thread 0 copy of the pressure variable.
std::vector< MooseVariableFVReal * > _ps
All the thread copies of the pressure variable.
SubProblem & _subproblem
unsigned int n_threads()
T & getMesh(MooseMesh &mesh)
function to cast mesh
Definition: SCM.h:35
INSFVVelocityVariable *const _u
The thread 0 copy of the x-velocity variable.
unsigned int number() const
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
INSFVVelocityVariable *const _v
The thread 0 copy of the y-velocity variable (null if the problem is 1D)
static InputParameters validParams()
MeshBase & mesh
auto raw_value(const Eigen::Map< T > &in)
The following methods are specializations for using the Parallel::packed_range_* routines for a vecto...
static InputParameters validParams()
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.
RhieChowInterpolatorBase(const InputParameters &params)
const unsigned int _dim
The dimension of the mesh, e.g. 3 for hexes and tets, 2 for quads and tris.
const Point & normal() const
void paramError(const std::string &param, Args... args) const
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.
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.
Moose::FV::InterpMethod faceInterpolationMethod() const
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
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.
static const std::string pressure
Definition: NS.h:56
void mooseError(Args &&... args) const
std::vector< MooseVariableFVReal * > _ws
All the thread copies of the z-velocity variable.
static InputParameters validParams()
std::vector< MooseVariableFVReal * > _vs
All the thread copies of the y-velocity variable.
static InputParameters validParams()
unsigned int THREAD_ID