https://mooseframework.inl.gov
WCNSFVEnergyFluxBC.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 "WCNSFVEnergyFluxBC.h"
11 #include "INSFVEnergyVariable.h"
12 #include "NS.h"
13 
14 registerMooseObject("NavierStokesApp", WCNSFVEnergyFluxBC);
15 
18 {
20  params.addClassDescription("Flux boundary conditions for energy advection.");
21 
22  // Three different ways to input an advected energy flux
23  // 1) Postprocessor with the energy flow rate directly
24  // 2) Postprocessors for velocity and energy, functors for specific heat and density
25  // 3) Postprocessors for mass flow rate and energy, functor for specific heat
26  params.addParam<PostprocessorName>("energy_pp", "Postprocessor with the inlet energy flow rate");
27  params.addParam<PostprocessorName>("temperature_pp", "Postprocessor with the inlet temperature");
28  params.addRequiredParam<MooseFunctorName>(NS::cp, "specific heat capacity functor");
29  params.addRequiredParam<MooseFunctorName>(NS::T_fluid, "temperature functor");
30  return params;
31 }
32 
34  : WCNSFVFluxBCBase(params),
35  _temperature_pp(isParamValid("temperature_pp") ? &getPostprocessorValue("temperature_pp")
36  : nullptr),
37  _energy_pp(isParamValid("energy_pp") ? &getPostprocessorValue("energy_pp") : nullptr),
38  _cp(getFunctor<ADReal>(NS::cp)),
39  _temperature(getFunctor<ADReal>(NS::T_fluid))
40 {
41  if (!dynamic_cast<INSFVEnergyVariable *>(&_var))
42  paramError("variable",
43  "The variable argument to WCNSFVEnergyFluxBC must be of type INSFVEnergyVariable");
44 
45  // Density is often set as global parameters so it is not checked
47  mooseWarning("If setting the energy flow rate directly, "
48  "no need for inlet velocity (magnitude or direction), mass flow or temperature");
49 
50  // Need enough information if trying to use a mass flow rate postprocessor
51  if (!_energy_pp)
52  {
53  if (!_temperature_pp)
54  mooseError("If not providing the energy flow rate, "
55  "the inlet temperature should be provided");
56  if (!_velocity_pp && !_mdot_pp)
57  mooseError("If not providing the inlet energy flow rate, the inlet velocity or mass flow "
58  "should be provided");
59  if (_mdot_pp && !_area_pp)
60  mooseError("If providing the inlet mass flow rate, the flow"
61  " area should be provided as well");
62  }
63  else if (!_area_pp)
64  paramError("energy_pp",
65  "If supplying the energy flow rate, the flow area should be provided as well");
66 }
67 
68 ADReal
70 {
71  const auto state = determineState();
72 
73  if (!isInflow())
74  {
75  const auto fa = singleSidedFaceArg();
76  return varVelocity(state) * _normal * _rho(fa, state) * _cp(fa, state) *
77  _temperature(fa, state);
78  }
79  else if (_energy_pp)
80  return -_scaling_factor * *_energy_pp / *_area_pp;
81 
82  return -_scaling_factor * inflowMassFlux(state) * _cp(singleSidedFaceArg(), state) *
83  (*_temperature_pp);
84 }
85 
86 bool
88 {
89  if (_mdot_pp)
90  return *_mdot_pp >= 0;
91  else if (_velocity_pp)
92  return *_velocity_pp >= 0;
93  else if (_energy_pp)
94  return *_energy_pp >= 0;
95 
96  mooseError(
97  "Either mdot_pp or velocity_pp or energy_pp need to be provided OR this function must be "
98  "overridden in derived classes if other input parameter combinations are valid. "
99  "Neither mdot_pp nor velocity_pp are provided.");
100  return true;
101 }
const PostprocessorValue *const _velocity_pp
Postprocessor with the inlet velocity.
const PostprocessorValue *const _mdot_pp
Postprocessor with the inlet mass flow rate.
const PostprocessorValue *const _temperature_pp
Postprocessor with the inlet temperature.
const bool _direction_specified_by_user
Flag to store if the flow direction is specified by the user.
registerMooseObject("NavierStokesApp", WCNSFVEnergyFluxBC)
const Moose::Functor< ADReal > & _rho
Fluid density functor.
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)
const Moose::Functor< ADReal > & _cp
Fluid specific heat capacity functor.
Moose::StateArg determineState() const
ADReal inflowMassFlux(const Moose::StateArg &state) const
computes the inflow massflux
Base class for weakly compressible flux boundary conditions.
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
MooseVariableFV< Real > & _var
const Moose::Functor< ADReal > & _temperature
Fluid temperature functor.
DualNumber< Real, DNDerivativeType, true > ADReal
void mooseWarning(Args &&... args) const
void addRequiredParam(const std::string &name, const std::string &doc_string)
virtual bool isInflow() const override
override because energy_pp is not considered in base class
static InputParameters validParams()
static const std::string cp
Definition: NS.h:121
static InputParameters validParams()
static const std::string T_fluid
Definition: NS.h:106
const PostprocessorValue *const _energy_pp
Postprocessor with the inlet energy flow rate.
const PostprocessorValue *const _area_pp
Postprocessor with the inlet area.
ADRealVectorValue _normal
ADReal computeQpResidual() override
void paramError(const std::string &param, Args... args) const
const Real _scaling_factor
Scaling factor.
void mooseError(Args &&... args) const
void addClassDescription(const std::string &doc_string)
WCNSFVEnergyFluxBC(const InputParameters &params)
Flux boundary condition for the weakly compressible energy equation.