https://mooseframework.inl.gov
NSFVPumpFunctorMaterial.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 "NS.h"
12 #include "Function.h"
13 
15 registerMooseObjectRenamed("NavierStokesApp",
16  NSFVPumpMaterial,
17  "08/01/2024 00:00",
19 
22 {
24  params.addClassDescription("Computes the effective pump body force.");
25  params.addParam<MooseFunctorName>(
26  "pump_force_name", "pump_volume_force", "Name of the pump force functor.");
27  params.addParam<FunctionName>("pressure_head_function", "Pressure Head Function.");
28  params.addParam<MooseFunctorName>("area_rated", 1.0, "Rated area of the pump.");
29  params.addParam<MooseFunctorName>("volume_rated", 1.0, "Rated volume of the pump.");
30  params.addRequiredParam<MooseFunctorName>(NS::density, "Density.");
31  params.addRequiredParam<MooseFunctorName>(NS::speed, "Flow speed.");
32  params.addParam<Real>("flow_rate_rated", 1.0, "Rated flow rate.");
33  params.addParam<PostprocessorName>("flow_rate", 1.0, "Flow rate.");
34  params.addParam<RealVectorValue>(
35  "gravity", RealVectorValue(0, -9.81, 0), "The gravitational acceleration vector.");
36  params.addParam<Real>("rotation_speed_rated", 1.0, "The rated rotation speed of the pump.");
37  params.addParam<Real>("rotation_speed", 1.0, "The rotation speed of the pump.");
38  params.addParam<bool>(
39  "enable_negative_rotation", false, "Flag to allow negative rotation speeds.");
40  params.addParam<bool>("symmetric_negative_pressure_head",
41  true,
42  "Flag to use the pressure head function in the negative direction than the "
43  "one in the positive direction.");
44  params.addParam<FunctionName>("pressure_head_function_negative_rotation",
45  "Pressure head function for negative rotation.");
46  params.declareControllable("rotation_speed");
47  return params;
48 }
49 
51  : FunctorMaterial(parameters),
52  _pressure_head_function(
53  isParamValid("pressure_head_function") ? &getFunction("pressure_head_function") : nullptr),
54  _area_rated(getFunctor<Real>("area_rated")),
55  _volume_rated(getFunctor<Real>("volume_rated")),
56  _rho(getFunctor<ADReal>(NS::density)),
57  _speed(getFunctor<ADReal>(NS::speed)),
58  _flow_rate_rated(getParam<Real>("flow_rate_rated")),
59  _flow_rate(getPostprocessorValue("flow_rate")),
60  _gravity(getParam<RealVectorValue>("gravity")),
61  _rotation_speed_rated(getParam<Real>("rotation_speed_rated")),
62  _rotation_speed(getParam<Real>("rotation_speed")),
63  _flow_rate_scaling_bool(isParamSetByUser("flow_rate_rated")),
64  _bool_negative_rotation_speed(getParam<bool>("enable_negative_rotation")),
65  _bool_symmetric_negative_pressure_head(getParam<bool>("symmetric_negative_pressure_head")),
66  _pressure_head_function_negative_rotation(
67  isParamValid("pressure_head_function_negative_rotation")
68  ? &getFunction("pressure_head_function_negative_rotation")
69  : nullptr)
70 {
71  // Error checks
73  paramError("pressure_head_function",
74  "Pressure head function should be provided. If negative rotation is used "
75  "'pressure_head_function_negative_rotation' should be provided.");
76 
78  paramError("rotation_speed",
79  "The rotation speed must be positive if 'enable_negative_rotation' is not true.");
80 
82  paramError(
83  "pressure_head_function_negative_rotation",
84  "The negative pressure head won't be used if 'enable_negative_rotation' is not true.");
85 
87  paramError("pressure_head_function_negative_rotation",
88  "Negative pressure head function should be provided if "
89  "'symmetric_negative_pressure_head' is false.");
90 
91  addFunctorProperty<Real>(
92  getParam<MooseFunctorName>("pump_force_name"),
93  [this](const auto & r, const auto & t) -> Real
94  {
95  // Getting rated pressure head
96  const Point ref_pressure_point(0.0, 0.0, 0.0);
97  Real rated_pressure_head;
99  rated_pressure_head =
100  (*_pressure_head_function).value(std::abs(_flow_rate), ref_pressure_point);
101  else
102  rated_pressure_head = -(*_pressure_head_function_negative_rotation)
103  .value(std::abs(_flow_rate), ref_pressure_point);
104 
105  // Scaling pressure head
106  const auto flow_rate_scaling =
107  _flow_rate_scaling_bool ? std::sqrt(std::abs(_flow_rate) / _flow_rate_rated) : 1.0;
108  const auto rotation_speed_scaling = std::abs(_rotation_speed) / _rotation_speed_rated;
109  const auto pressure_head =
110  rated_pressure_head * std::pow(flow_rate_scaling * rotation_speed_scaling, 4.0 / 3.0);
111 
112  // Computing effective volume force
113  mooseAssert(_rho.isConstant(),
114  "The density must be a constant in order for the pump force to not contain "
115  "derivative information.");
116  const auto rho = raw_value(_rho(r, t));
117  const Real gravity = _gravity.norm();
118  const auto area = _area_rated(r, t);
119  const auto volume = _volume_rated(r, t);
120  return -rho * gravity * pressure_head * area / volume;
121  });
122 
123  const auto & mesh_blocks = _subproblem.mesh().meshSubdomains();
124  const auto & pump_blocks = blockIDs();
125  std::set<SubdomainID> missing_blocks;
126 
127  std::set_difference(mesh_blocks.begin(),
128  mesh_blocks.end(),
129  pump_blocks.begin(),
130  pump_blocks.end(),
131  std::inserter(missing_blocks, missing_blocks.begin()));
132 
133  if (missing_blocks.size() >= 1 && *(pump_blocks.begin()) != Moose::ANY_BLOCK_ID)
134  {
136  getParam<MooseFunctorName>("pump_force_name"),
137  [](const auto &, const auto &) -> Real { return 0.0; },
138  std::set<ExecFlagType>({EXEC_ALWAYS}),
139  _subproblem.mesh(),
140  missing_blocks,
141  _tid);
142  }
143 }
virtual MooseMesh & mesh()=0
const bool _bool_negative_rotation_speed
Allow negative rotation speed.
auto norm() const -> decltype(std::norm(Real()))
static const std::string speed
Definition: NS.h:143
static InputParameters validParams()
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
registerMooseObjectRenamed("NavierStokesApp", NSFVPumpMaterial, "08/01/2024 00:00", NSFVPumpFunctorMaterial)
SubProblem & _subproblem
registerMooseObject("NavierStokesApp", NSFVPumpFunctorMaterial)
static const std::string density
Definition: NS.h:33
auto raw_value(const Eigen::Map< T > &in)
NSFVPumpFunctorMaterial(const InputParameters &parameters)
static InputParameters validParams()
const RealVectorValue & _gravity
Gravity.
virtual const std::set< SubdomainID > & blockIDs() const
const ExecFlagType EXEC_ALWAYS
DualNumber< Real, DNDerivativeType, true > ADReal
const Real & _rotation_speed
Actual Rotation Speed.
void addRequiredParam(const std::string &name, const std::string &doc_string)
const Function *const _pressure_head_function
Function providing the pressure head The pressure head should be provided as head (in meters) vs...
THREAD_ID _tid
Computes the effective pump body force as a functor.
const Moose::Functor< Real > & _area_rated
Rated transversal area of the pump.
const PostprocessorValue & _flow_rate
Actual flow rate.
void paramError(const std::string &param, Args... args) const
Real volume(const MeshBase &mesh, unsigned int dim=libMesh::invalid_uint)
const Real & _rotation_speed_rated
Rated Rotation Speed.
const SubdomainID ANY_BLOCK_ID
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const Moose::Functor< ADReal > & _rho
Density.
const Moose::FunctorBase< T > & addPiecewiseByBlockLambdaFunctor(const std::string &name, PolymorphicLambda my_lammy, const std::set< ExecFlagType > &clearance_schedule, const MooseMesh &mesh, const std::set< SubdomainID > &block_ids, const THREAD_ID tid)
const bool _bool_symmetric_negative_pressure_head
Symmetric pressure head function in the negative direction.
void addClassDescription(const std::string &doc_string)
const Moose::Functor< Real > & _volume_rated
Rated volume of the pump.
const Real & _flow_rate_rated
Rated flow rate.
MooseUnits pow(const MooseUnits &, int)
void declareControllable(const std::string &name, std::set< ExecFlagType > execute_flags={})
const bool _flow_rate_scaling_bool
Boolean to determine if flow rate scaling is necessary.
const Function *const _pressure_head_function_negative_rotation
Homologous pressure head function in the negative direction (in meters) vs. flow rate (in m3/s) ...
const std::set< SubdomainID > & meshSubdomains() const