Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
flow_control.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) 2020-2021, 2023-2024, 2026 The Lethe
2// Authors SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR
3// LGPL-2.1-or-later
4
5#ifndef lethe_flow_control_h
6#define lethe_flow_control_h
7
8#include <core/parameters.h>
9
10#include <deal.II/base/tensor.h>
11
12#include <string>
13
14using namespace dealii;
15
16/**
17 * @brief Dynamic flow controller that drives the average velocity of the flow
18 * towards a target value.
19 *
20 * At each time step, the controller calculates a force coefficient beta,
21 * applied as a source term in the momentum equation along the flow direction,
22 * from the average velocity of the previous time steps. The main controller is
23 * based on Wang, 2009, "A non-body conformal grid method for simulations of
24 * laminar and turbulent flows with a compressible large eddy simulation
25 * solver".
26 *
27 * @tparam dim Number of spatial dimensions.
28 */
29template <int dim>
31{
32public:
33 /**
34 * @brief Constructor of the flow controller.
35 *
36 * @param[in] flow_control Parameters of the dynamic flow control. When the
37 * flow control is enabled, its flow direction must be smaller than @p dim.
38 */
39 explicit FlowControl(const Parameters::DynamicFlowControl &flow_control);
40
41 /**
42 * @brief Calculate the beta force coefficient applied during the current
43 * time step.
44 *
45 * The coefficient adjusts the flow rate towards the target average
46 * velocity. Once the target is reached, the controller calculates the beta
47 * force that keeps the flow rate constant. The new coefficient is stored and
48 * can be obtained with get_beta().
49 *
50 * @param[in] average_velocity_n Average velocity of the last time step.
51 *
52 * @param[in] dt Current time step.
53 *
54 * @param[in] step_number Current time step number.
55 */
56 void
57 calculate_beta(const double &average_velocity_n,
58 const double &dt,
59 const unsigned int &step_number);
60
61 /**
62 * @brief Get the beta force of the current time step.
63 *
64 * @return Beta force tensor, whose only non-zero component is along the flow
65 * direction.
66 */
67 Tensor<1, dim>
68 get_beta() const
69 {
70 return beta;
71 }
72
73 /**
74 * @brief Get the beta force of the current time step scaled for the
75 * particles.
76 *
77 * The particles are subjected to the same pressure gradient as the fluid,
78 * which gives beta_p * rho_p = beta_f * rho_f, in units of a pressure
79 * gradient M/(T²L²).
80 *
81 * @param[in] fluid_density Density of the fluid.
82 *
83 * @param[in] particle_density Density of the particles.
84 *
85 * @return Beta force for the particles. It is a tensor of dimension 3 since
86 * it is added to the gravity of the DEM parameters, which is always a tensor
87 * of dimension 3.
88 */
89 inline Tensor<1, 3>
90 get_beta_particles(const double &fluid_density,
91 const double &particle_density) const
92 {
93 Tensor<1, 3> beta_particle;
94 beta_particle[0] = beta[0];
95 beta_particle[1] = beta[1];
96
97 if constexpr (dim == 3)
98 beta_particle[2] = beta[2];
99
100 return beta_particle * fluid_density / particle_density;
101 }
102
103 /**
104 * @brief Save the state of the flow controller to a checkpoint file.
105 *
106 * @param[in] prefix Prefix of the checkpoint files. The state is written in
107 * the file named @p prefix followed by the extension .flowcontrol.
108 */
109 void
110 save(const std::string &prefix) const;
111
112 /**
113 * @brief Read the state of the flow controller from a checkpoint file.
114 *
115 * @param[in] prefix Prefix of the checkpoint files. The state is read from
116 * the file named @p prefix followed by the extension .flowcontrol.
117 */
118 void
119 read(const std::string &prefix);
120
121private:
122 /**
123 * @brief Calculate a beta force from the last average velocity only. It is
124 * used for the first and second time steps, when no initial beta is given or
125 * when the history of the main controller is not available yet.
126 *
127 * @param[in] average_velocity_n Average velocity of the last time step.
128 *
129 * @param[in] dt Current time step.
130 *
131 * @return Beta force calculated by the proportional controller.
132 */
133 double
134 proportional_flow_controller(const double &average_velocity_n,
135 const double &dt) const;
136
137 /**
138 * @brief Calculate a beta force from the previous beta force and the
139 * average velocities of the last two time steps, following Wang (2009).
140 *
141 * Once the target average velocity has been reached, a beta force opposed to
142 * the target flow is set to zero.
143 *
144 * @param[in] average_velocity_n Average velocity of the last time step.
145 *
146 * @param[in] dt Current time step.
147 *
148 * @return Beta force calculated by the main controller.
149 */
150 double
151 main_flow_controller(const double &average_velocity_n,
152 const double &dt) const;
153
154 /// Below this magnitude, a beta force is considered to be zero.
155 static constexpr double zero_beta_tolerance = 1e-6;
156
157 /// Initial ratio of the upper limit of the force-free velocity band to the
158 /// target average velocity.
159 static constexpr double initial_force_free_velocity_band_factor = 1.01;
160
161 /// Smallest ratio of the upper limit of the force-free velocity band to the
162 /// target average velocity. The band stops shrinking below this value.
163 static constexpr double minimum_force_free_velocity_band_factor = 1.00125;
164
165 /// Beta force of the current time step. Only its component along the flow
166 /// direction is non-zero.
167 Tensor<1, dim> beta;
168
169 /// Target average velocity.
171
172 /// Initial beta force given by the user. It is only used when its magnitude
173 /// is larger than zero_beta_tolerance.
175
176 /// Relaxation coefficient of the controllers.
177 double alpha;
178
179 /// Relative change of the beta force below which the previous beta force is
180 /// kept.
182
183 /// Beta force applied during the previous time step.
184 double previous_beta = 0.0;
185
186 /// Average velocity of the previous time step.
188
189 /// Direction of the flow (0 for x, 1 for y and 2 for z).
190 unsigned int flow_direction;
191
192 /// True while the target average velocity has not been reached once without
193 /// any force applied. In that state, an average velocity slightly above the
194 /// target (within the force-free velocity band) is allowed to decrease
195 /// without any force, through the pressure drop only.
197
198 /// Ratio of the upper limit of the force-free velocity band to the target
199 /// average velocity. Its distance to 1 is halved when the pressure drop alone
200 /// is too slow to bring the average velocity back to the target.
203};
204
205#endif
double alpha
Relaxation coefficient of the controllers.
double force_free_velocity_band_factor
double previous_average_velocity
Average velocity of the previous time step.
static constexpr double initial_force_free_velocity_band_factor
double beta_threshold
void read(const std::string &prefix)
Read the state of the flow controller from a checkpoint file.
unsigned int flow_direction
Direction of the flow (0 for x, 1 for y and 2 for z).
bool force_free_deceleration_is_allowed
double main_flow_controller(const double &average_velocity_n, const double &dt) const
Calculate a beta force from the previous beta force and the average velocities of the last two time s...
static constexpr double zero_beta_tolerance
Below this magnitude, a beta force is considered to be zero.
double proportional_flow_controller(const double &average_velocity_n, const double &dt) const
Calculate a beta force from the last average velocity only. It is used for the first and second time ...
Tensor< 1, dim > get_beta() const
Get the beta force of the current time step.
double target_average_velocity
Target average velocity.
void calculate_beta(const double &average_velocity_n, const double &dt, const unsigned int &step_number)
Calculate the beta force coefficient applied during the current time step.
double previous_beta
Beta force applied during the previous time step.
Tensor< 1, dim > beta
void save(const std::string &prefix) const
Save the state of the flow controller to a checkpoint file.
double initial_beta
static constexpr double minimum_force_free_velocity_band_factor
Tensor< 1, 3 > get_beta_particles(const double &fluid_density, const double &particle_density) const
Get the beta force of the current time step scaled for the particles.
FlowControl(const Parameters::DynamicFlowControl &flow_control)
Constructor of the flow controller.
FlowControl - Set average velocity on a boundary (CFD) or the domain (CFD-DEM).