Line data Source code
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 "NSFVPumpFunctorMaterial.h"
11 : #include "NS.h"
12 : #include "Function.h"
13 :
14 : registerMooseObject("NavierStokesApp", NSFVPumpFunctorMaterial);
15 : registerMooseObjectRenamed("NavierStokesApp",
16 : NSFVPumpMaterial,
17 : "08/01/2024 00:00",
18 : NSFVPumpFunctorMaterial);
19 :
20 : InputParameters
21 44 : NSFVPumpFunctorMaterial::validParams()
22 : {
23 44 : InputParameters params = FunctorMaterial::validParams();
24 44 : params.addClassDescription("Computes the effective pump body force.");
25 88 : params.addParam<MooseFunctorName>(
26 : "pump_force_name", "pump_volume_force", "Name of the pump force functor.");
27 88 : params.addParam<FunctionName>("pressure_head_function", "Pressure Head Function.");
28 88 : params.addParam<MooseFunctorName>("area_rated", 1.0, "Rated area of the pump.");
29 88 : params.addParam<MooseFunctorName>("volume_rated", 1.0, "Rated volume of the pump.");
30 44 : params.addRequiredParam<MooseFunctorName>(NS::density, "Density.");
31 44 : params.addRequiredParam<MooseFunctorName>(NS::speed, "Flow speed.");
32 88 : params.addParam<Real>("flow_rate_rated", 1.0, "Rated flow rate.");
33 88 : params.addParam<PostprocessorName>("flow_rate", 1.0, "Flow rate.");
34 44 : params.addParam<RealVectorValue>(
35 44 : "gravity", RealVectorValue(0, -9.81, 0), "The gravitational acceleration vector.");
36 88 : params.addParam<Real>("rotation_speed_rated", 1.0, "The rated rotation speed of the pump.");
37 88 : params.addParam<Real>("rotation_speed", 1.0, "The rotation speed of the pump.");
38 88 : params.addParam<bool>(
39 88 : "enable_negative_rotation", false, "Flag to allow negative rotation speeds.");
40 88 : params.addParam<bool>("symmetric_negative_pressure_head",
41 88 : true,
42 : "Flag to use the pressure head function in the negative direction than the "
43 : "one in the positive direction.");
44 88 : params.addParam<FunctionName>("pressure_head_function_negative_rotation",
45 : "Pressure head function for negative rotation.");
46 88 : params.declareControllable("rotation_speed");
47 44 : return params;
48 0 : }
49 :
50 24 : NSFVPumpFunctorMaterial::NSFVPumpFunctorMaterial(const InputParameters & parameters)
51 : : FunctorMaterial(parameters),
52 24 : _pressure_head_function(
53 42 : isParamValid("pressure_head_function") ? &getFunction("pressure_head_function") : nullptr),
54 48 : _area_rated(getFunctor<Real>("area_rated")),
55 48 : _volume_rated(getFunctor<Real>("volume_rated")),
56 24 : _rho(getFunctor<ADReal>(NS::density)),
57 24 : _speed(getFunctor<ADReal>(NS::speed)),
58 48 : _flow_rate_rated(getParam<Real>("flow_rate_rated")),
59 24 : _flow_rate(getPostprocessorValue("flow_rate")),
60 48 : _gravity(getParam<RealVectorValue>("gravity")),
61 48 : _rotation_speed_rated(getParam<Real>("rotation_speed_rated")),
62 48 : _rotation_speed(getParam<Real>("rotation_speed")),
63 48 : _flow_rate_scaling_bool(isParamSetByUser("flow_rate_rated")),
64 48 : _bool_negative_rotation_speed(getParam<bool>("enable_negative_rotation")),
65 48 : _bool_symmetric_negative_pressure_head(getParam<bool>("symmetric_negative_pressure_head")),
66 24 : _pressure_head_function_negative_rotation(
67 24 : isParamValid("pressure_head_function_negative_rotation")
68 30 : ? &getFunction("pressure_head_function_negative_rotation")
69 24 : : nullptr)
70 : {
71 : // Error checks
72 24 : if (!_pressure_head_function && !_pressure_head_function_negative_rotation)
73 0 : 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 :
77 24 : if (!_bool_negative_rotation_speed && _rotation_speed < 0)
78 0 : paramError("rotation_speed",
79 : "The rotation speed must be positive if 'enable_negative_rotation' is not true.");
80 :
81 24 : if (!_bool_negative_rotation_speed && _pressure_head_function_negative_rotation)
82 0 : paramError(
83 : "pressure_head_function_negative_rotation",
84 : "The negative pressure head won't be used if 'enable_negative_rotation' is not true.");
85 :
86 24 : if (!_bool_symmetric_negative_pressure_head && !_pressure_head_function_negative_rotation)
87 0 : paramError("pressure_head_function_negative_rotation",
88 : "Negative pressure head function should be provided if "
89 : "'symmetric_negative_pressure_head' is false.");
90 :
91 96 : addFunctorProperty<Real>(
92 48 : getParam<MooseFunctorName>("pump_force_name"),
93 92584 : [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;
98 92584 : if (_bool_symmetric_negative_pressure_head)
99 : rated_pressure_head =
100 84408 : (*_pressure_head_function).value(std::abs(_flow_rate), ref_pressure_point);
101 : else
102 8176 : rated_pressure_head = -(*_pressure_head_function_negative_rotation)
103 8176 : .value(std::abs(_flow_rate), ref_pressure_point);
104 :
105 : // Scaling pressure head
106 : const auto flow_rate_scaling =
107 92584 : _flow_rate_scaling_bool ? std::sqrt(std::abs(_flow_rate) / _flow_rate_rated) : 1.0;
108 92584 : const auto rotation_speed_scaling = std::abs(_rotation_speed) / _rotation_speed_rated;
109 92584 : const auto pressure_head =
110 92584 : 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 92584 : const auto rho = raw_value(_rho(r, t));
117 92584 : const Real gravity = _gravity.norm();
118 92584 : const auto area = _area_rated(r, t);
119 92584 : const auto volume = _volume_rated(r, t);
120 92584 : return -rho * gravity * pressure_head * area / volume;
121 : });
122 :
123 24 : const auto & mesh_blocks = _subproblem.mesh().meshSubdomains();
124 24 : const auto & pump_blocks = blockIDs();
125 : std::set<SubdomainID> missing_blocks;
126 :
127 24 : 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 24 : if (missing_blocks.size() >= 1 && *(pump_blocks.begin()) != Moose::ANY_BLOCK_ID)
134 : {
135 24 : _subproblem.addPiecewiseByBlockLambdaFunctor<Real>(
136 48 : getParam<MooseFunctorName>("pump_force_name"),
137 : [](const auto &, const auto &) -> Real { return 0.0; },
138 72 : std::set<ExecFlagType>({EXEC_ALWAYS}),
139 24 : _subproblem.mesh(),
140 : missing_blocks,
141 : _tid);
142 : }
143 72 : }
|