https://mooseframework.inl.gov
WCNSFVFluxBCBase.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 
10 #include "WCNSFVFluxBCBase.h"
11 #include "NS.h"
12 
15 {
17  params += INSFVFlowBC::validParams();
18  params.addParam<Real>("scaling_factor", 1, "To scale the mass flux");
19 
20  params.addParam<PostprocessorName>("velocity_pp", "Postprocessor with the inlet velocity norm");
21  params.addParam<Point>(
22  "direction",
23  Point(),
24  "The direction of the flow at the boundary. This is mainly used for cases when an inlet "
25  "angle needs to be defined with respect to the normal and when a boundary is defined on an "
26  "internal face where the normal can point in both directions. Use positive mass flux and "
27  "velocity magnitude if the flux aligns with this direction vector.");
28  params.addRequiredParam<MooseFunctorName>(NS::velocity_x, "The x-axis velocity");
29  params.addParam<MooseFunctorName>(NS::velocity_y, "The y-axis velocity");
30  params.addParam<MooseFunctorName>(NS::velocity_z, "The z-axis velocity");
31  params.addParam<PostprocessorName>("mdot_pp", "Postprocessor with the inlet mass flow rate");
32  params.addParam<PostprocessorName>("area_pp", "Inlet area as a postprocessor");
33  params.addRequiredParam<MooseFunctorName>(NS::density, "Density functor");
34 
35  return params;
36 }
37 
39  : FVFluxBC(params),
40  INSFVFlowBC(params),
41  _scaling_factor(getParam<Real>("scaling_factor")),
42  _velocity_pp(isParamValid("velocity_pp") ? &getPostprocessorValue("velocity_pp") : nullptr),
43  _mdot_pp(isParamValid("mdot_pp") ? &getPostprocessorValue("mdot_pp") : nullptr),
44  _area_pp(isParamValid("area_pp") ? &getPostprocessorValue("area_pp") : nullptr),
45  _rho(getFunctor<ADReal>(NS::density)),
46  _direction(getParam<Point>("direction")),
47  _direction_specified_by_user(params.isParamSetByUser("direction")),
48  _vel_x(getFunctor<ADReal>(NS::velocity_x)),
49  _vel_y(isParamValid(NS::velocity_y) ? &getFunctor<ADReal>(NS::velocity_y) : nullptr),
50  _vel_z(isParamValid(NS::velocity_z) ? &getFunctor<ADReal>(NS::velocity_z) : nullptr)
51 {
53  paramError("direction", "The direction should be a unit vector with a tolerance of 1e-6!");
54 
55  // Density is often set as global parameters so it is not checked
56  if (_mdot_pp && _velocity_pp)
57  mooseWarning("If setting the mass flow rate directly, no need for inlet velocity");
58 
59  if (_subproblem.mesh().dimension() >= 2 && !_vel_y)
60  mooseError("In two or more dimensions, the y-component of the velocity must be supplied.");
61  if (_subproblem.mesh().dimension() == 3 && !_vel_z)
62  mooseError("In three dimensions, the z-component of the velocity must be supplied.");
63 }
64 
65 // inflow is decided based on the sign of mdot or velocity postprocessors
66 // depending on what is provided
67 bool
69 {
70  if (_mdot_pp)
71  return *_mdot_pp >= 0;
72  else if (_velocity_pp)
73  return *_velocity_pp >= 0;
74 
75  mooseError("Either mdot_pp or velocity_pp need to be provided OR this function must be "
76  "overridden in derived classes if other input parameter combinations are valid. "
77  "Neither mdot_pp nor velocity_pp are provided.");
78  return true;
79 }
80 
83 {
84  const auto boundary_face = singleSidedFaceArg();
85 
86  ADRealVectorValue v(_vel_x(boundary_face, state));
87  if (_vel_y)
88  v(1) = (*_vel_y)(boundary_face, state);
89  if (_vel_z)
90  v(2) = (*_vel_z)(boundary_face, state);
91  return v;
92 }
93 
94 ADReal
96 {
98  if (_mdot_pp)
99  return *_mdot_pp / *_area_pp;
101  const ADReal cos_angle = std::abs(incoming_vector * _normal);
102  return _rho(singleSidedFaceArg(), state) * (*_velocity_pp) * cos_angle;
103 }
104 
105 ADReal
107 {
110  const ADReal cos_angle = std::abs(incoming_vector * _normal);
111  if (_mdot_pp)
112  return *_mdot_pp / (*_area_pp * _rho(singleSidedFaceArg(), state) * cos_angle);
113 
114  return (*_velocity_pp) * cos_angle;
115 }
116 
117 void
119 {
120  if (_area_pp)
122  mooseError("Surface area is 0");
124 }
125 
126 void
128 {
129  if (_area_pp)
131  mooseError("Surface area is 0");
133 }
virtual MooseMesh & mesh()=0
void checkForInternalDirection() const
check for improper use on an internal face, e.g.
const PostprocessorValue *const _velocity_pp
Postprocessor with the inlet velocity.
const PostprocessorValue *const _mdot_pp
Postprocessor with the inlet mass flow rate.
const bool _direction_specified_by_user
Flag to store if the flow direction is specified by the user.
const Moose::Functor< ADReal > & _rho
Fluid density functor.
bool absoluteFuzzyEqual(const T &var1, const T2 &var2, const T3 &tol=libMesh::TOLERANCE *libMesh::TOLERANCE)
ADRealVectorValue varVelocity(const Moose::StateArg &state) const
returns the velocity vector (vel_x, vel_y, vel_z)
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
static InputParameters validParams()
const Point _direction
The direction in which the flow is entering/leaving the domain.
static const std::string velocity_z
Definition: NS.h:48
ADReal inflowMassFlux(const Moose::StateArg &state) const
computes the inflow massflux
static const std::string density
Definition: NS.h:33
Moose::FaceArg singleSidedFaceArg(const FaceInfo *fi=nullptr, Moose::FV::LimiterType limiter_type=Moose::FV::LimiterType::CentralDifference, bool correct_skewness=false, const Moose::StateArg *state_limiter=nullptr) const
static const std::string velocity_x
Definition: NS.h:46
DualNumber< Real, DNDerivativeType, true > ADReal
void mooseWarning(Args &&... args) const
const Moose::Functor< ADReal > *const _vel_y
void addRequiredParam(const std::string &name, const std::string &doc_string)
ADReal inflowSpeed(const Moose::StateArg &state) const
computes the inflow speed
static InputParameters validParams()
void jacobianSetup() override
virtual unsigned int dimension() const
SubProblem & _subproblem
const PostprocessorValue *const _area_pp
Postprocessor with the inlet area.
ADRealVectorValue _normal
static const std::string velocity_y
Definition: NS.h:47
void paramError(const std::string &param, Args... args) const
const Moose::Functor< ADReal > *const _vel_z
virtual bool isInflow() const
true if a boundary is an inflow boundary, false if outflow
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
static const std::string v
Definition: NS.h:84
const Moose::Functor< ADReal > & _vel_x
Velocity components.
void mooseError(Args &&... args) const
void residualSetup() override
in residual and jacobian setup we check if the area is zero
virtual void jacobianSetup()
virtual void residualSetup()
A parent class for INSFV flow boundary conditions.
Definition: INSFVFlowBC.h:17
static InputParameters validParams()
Definition: INSFVFlowBC.C:14
WCNSFVFluxBCBase(const InputParameters &params)