https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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{
52 if (_direction_specified_by_user && !MooseUtils::absoluteFuzzyEqual(_direction.norm(), 1.0, 1e-6))
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
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
67bool
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
96{
97 using std::abs;
98
100 if (_mdot_pp)
101 return *_mdot_pp / *_area_pp;
103 const ADReal cos_angle = abs(incoming_vector * _normal);
104 return _rho(singleSidedFaceArg(), state) * (*_velocity_pp) * cos_angle;
105}
106
107ADReal
109{
110 using std::abs;
111
114 const ADReal cos_angle = abs(incoming_vector * _normal);
115 if (_mdot_pp)
116 return *_mdot_pp / (*_area_pp * _rho(singleSidedFaceArg(), state) * cos_angle);
117
118 return (*_velocity_pp) * cos_angle;
119}
120
121void
123{
124 if (_area_pp)
125 if (MooseUtils::absoluteFuzzyEqual(*_area_pp, 0))
126 mooseError("Surface area is 0");
128}
129
130void
132{
133 if (_area_pp)
134 if (MooseUtils::absoluteFuzzyEqual(*_area_pp, 0))
135 mooseError("Surface area is 0");
137}
DualNumber< Real, DNDerivativeType, true > ADReal
const double v
SubProblem & _subproblem
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
ADRealVectorValue _normal
static InputParameters validParams()
A parent class for INSFV flow boundary conditions.
Definition INSFVFlowBC.h:18
static InputParameters validParams()
Definition INSFVFlowBC.C:14
void addRequiredParam(const std::string &name, const std::string &doc_string)
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
void paramError(const std::string &param, Args... args) const
void mooseError(Args &&... args) const
void mooseWarning(Args &&... args) const
virtual unsigned int dimension() const
virtual void residualSetup()
virtual void jacobianSetup()
virtual MooseMesh & mesh()=0
WCNSFVFluxBCBase(const InputParameters &params)
const Moose::Functor< ADReal > & _rho
Fluid density functor.
const bool _direction_specified_by_user
Flag to store if the flow direction is specified by the user.
ADReal inflowMassFlux(const Moose::StateArg &state) const
computes the inflow massflux
static InputParameters validParams()
const PostprocessorValue *const _mdot_pp
Postprocessor with the inlet mass flow rate.
void jacobianSetup() override
const Moose::Functor< ADReal > *const _vel_z
const PostprocessorValue *const _velocity_pp
Postprocessor with the inlet velocity.
void residualSetup() override
in residual and jacobian setup we check if the area is zero
void checkForInternalDirection() const
check for improper use on an internal face, e.g.
virtual bool isInflow() const
true if a boundary is an inflow boundary, false if outflow
ADReal inflowSpeed(const Moose::StateArg &state) const
computes the inflow speed
const Moose::Functor< ADReal > & _vel_x
Velocity components.
const Moose::Functor< ADReal > *const _vel_y
const Point _direction
The direction in which the flow is entering/leaving the domain.
const PostprocessorValue *const _area_pp
Postprocessor with the inlet area.
ADRealVectorValue varVelocity(const Moose::StateArg &state) const
returns the velocity vector (vel_x, vel_y, vel_z)
static const std::string density
Definition NS.h:34
static const std::string velocity_y
Definition NS.h:48
static const std::string velocity_z
Definition NS.h:49
static const std::string velocity_x
Definition NS.h:47