Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
postprocessing_velocities.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) 2020-2026 The Lethe Authors
2// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
3
4#ifndef lethe_postprocessing_velocities_h
5#define lethe_postprocessing_velocities_h
6
7#include <core/parameters.h>
8
9#include <deal.II/base/types.h>
10
11#include <deal.II/dofs/dof_handler.h>
12
13#include <deal.II/numerics/solution_transfer.h>
14
15#include <array>
16#include <memory>
17#include <string>
18#include <vector>
19
20using namespace dealii;
21
22/**
23 * @brief Calculates the time-averaged velocities and pressure \f$(\langle u
24 * \rangle, \langle v \rangle, \langle w \rangle, \langle p \rangle)\f$ and the
25 * independent components of the Reynolds stresses tensor \f$(\langle u'u'
26 * \rangle, \langle v'v' \rangle, \langle w'w' \rangle, \langle u'v' \rangle,
27 * \langle v'w' \rangle, \langle w'u' \rangle)\f$.
28 *
29 * The Reynolds stresses are computed at every velocity support point from the
30 * degrees of freedom of the velocity components at that point. They are stored
31 * in vectors with the layout of the solution: the normal stresses in the
32 * velocity slots and the turbulent kinetic energy in the pressure slot of the
33 * normal stress vector, and \f$\langle u'v' \rangle\f$, \f$\langle v'w'
34 * \rangle\f$ and \f$\langle w'u' \rangle\f$ in the u, v and w slots of the
35 * shear stress vector. The turbulent kinetic energy is only stored at the
36 * pressure degrees of freedom that share their support point with a velocity
37 * support point.
38 *
39 * @tparam dim An integer that denotes the dimension of the space in which
40 * the flow is solved.
41 *
42 * @tparam VectorType The vector type used for the solvers (Trilinos (normal or block)
43 * or deal.II vectors).
44 *
45 * @tparam DofsType The type of storage of indices which differs according to vector.
46 *
47 */
48template <int dim, typename VectorType, typename DofsType>
50{
51public:
52 /**
53 * @brief Constructor that initializes the solution transfer objects for the velocity
54 * and the Reynolds stresses, the total time for average and average
55 * calculation variables.
56 *
57 * @param[in] dof_handler Used to initialize the solution transfer objects
58 * and to pair the degrees of freedom of the velocity components that share a
59 * support point. It must outlive the object.
60 *
61 */
62 AverageVelocities(DoFHandler<dim> &dof_handler);
63
64 /**
65 * @brief Calculate time-averaged velocities and pressure using vector with no ghost
66 * cells.
67 *
68 * @param[in] local_evaluation_point The solution vector with no ghost cells.
69 *
70 * @param[in] post_processing The postprocessing parameters to definie initial
71 * time of averaging.
72 *
73 * @param[in] current_time The current time in the simulation.
74 *
75 * @param[in] time_step The current time step.
76 *
77 */
78 void
80 const VectorType &local_evaluation_point,
81 const Parameters::PostProcessing<dim> &post_processing,
82 const double &current_time,
83 const double &time_step);
84
85
86 void
88
89 /**
90 * @brief Calculate normal and other resolved time-averaged Reynold stresses
91 * \f$(\langle u'u' \rangle, \langle v'v' \rangle, \langle w'w' \rangle)\f$
92 * and \f$(\langle u'v' \rangle, \langle v'w' \rangle, \langle w'u'
93 * \rangle)\f$.
94 *
95 * @param[in] local_evaluation_point The solution vector with no ghost cells.
96 */
97 void
98 calculate_reynolds_stresses(const VectorType &local_evaluation_point);
99
100 /**
101 * @brief Give the average of solutions with ghost cells.
102 *
103 * @return Shared pointer to the vector of average solutions.
104 *
105 */
106 std::shared_ptr<VectorType>
108 {
110 return get_av;
111 }
112
113 /**
114 * @brief Give the time-averaged Reynolds normal stresses with ghost cells.
115 *
116 * @return Vector with average normal Reynolds stresses.
117 *
118 */
119 const VectorType &
124
125 /**
126 * @brief Give the time-averaged Reynolds shear stresses with ghost cells.
127 *
128 * @return Vector with average shear Reynolds stresses.
129 *
130 */
131 const VectorType &
136
137 /**
138 * @brief Initialize all the important vectors for the average velocities and
139 * reynolds stresses calculation. This includes the vector for the
140 * checkpoints. Also gather the degrees of freedom of the locally owned
141 * velocity support points used to calculate the Reynolds stresses. This
142 * must be called after the degrees of freedom of the DoFHandler given to
143 * the constructor have been distributed and renumbered.
144 *
145 * @param[in] locally_owned_dofs The owned dofs.
146 *
147 * @param[in] locally_relevant_dofs The locally relevant dofs.
148 *
149 * @param[in] mpi_communicator The communicator information.
150 *
151 */
152 void
153 initialize_vectors(const DofsType &locally_owned_dofs,
154 const DofsType &locally_relevant_dofs,
155 const MPI_Comm &mpi_communicator);
156
157 /**
158 * @brief Prepare average velocity object for dynamic mesh adaptation.
159 */
160 void
162
163 /**
164 * @brief Reestablish solution vectors after dynamic mesh adaptation.
165 */
166 void
168
169 /**
170 * @brief Save checkpoints to continuing averaging after restart.
171 *
172 * @param[in] prefix Name for checkpointing files.
173 *
174 * @return Vector with average values.
175 */
176 std::vector<const VectorType *>
177 save(const std::string &prefix);
178
179 /**
180 * @brief Read checkpoints to continuing averaging after restart.
181 *
182 * @param[in] prefix Name for checkpoint files.
183 *
184 * @return Vector with average values.
185 */
186 std::vector<VectorType *>
187 read(const std::string &prefix);
188
189
190 /**
191 * @brief Sanitize the average velocity object after a checkpoint has been read by
192 * resetting all of the locally_owned vectors using the locally_relevant
193 * vectors. This is necessary because only the locally_relevant_vectors are
194 * saved, but the calculation routines expect that the content of the
195 * locally_owned vectors match that of the locally_relevant vectors.
196 *
197 * The total time over which the averaging has been carried out is not stored
198 * in the checkpoint file, but it is entirely determined by the time at which
199 * the averaging started, which is stored, and by the time at which the
200 * simulation is restarted. Restoring it here allows the averaged fields to be
201 * reevaluated from the checkpointed sums without accumulating an additional
202 * contribution, which would otherwise be needed to give the averaged fields a
203 * meaningful value right after a restart.
204 *
205 * @param[in] current_time The time at which the simulation is restarted.
206 */
207 void
219
220 /**
221 * @brief Reinitialize the values of sum_velocities_dt_with_ghost_cells vector to 0 and the has_started_averaging flag to false. If the initial time for average velocities parameter is greater than the simulation time, the checkpointed time average velocities are ignored after a restart. This allows users to restart a simulation with a different averaging start time.
222 */
223 void
225
226private:
227 /**
228 * @brief Global indices of the degrees of freedom located at one velocity
229 * support point.
230 */
232 {
233 /**
234 * @brief Degrees of freedom of the dim velocity components.
235 */
236 std::array<types::global_dof_index, dim> velocity;
237
238 /**
239 * @brief Degree of freedom of the pressure at the same support point, or
240 * numbers::invalid_dof_index if the pressure has no degree of freedom
241 * there (e.g. at the velocity support points of a Q2-Q1 element that are
242 * not vertices).
243 */
244 types::global_dof_index pressure;
245 };
246
247 /**
248 * @brief Gather the degrees of freedom of every locally owned velocity
249 * support point, with the pressure degree of freedom at the same point.
250 *
251 * The velocity components of a support point are paired through the finite
252 * element, since the global numbering of the degrees of freedom does not
253 * group them when a mesh object carries more than one degree of freedom per
254 * component (velocity degree of 3 or more, unequal velocity and pressure
255 * degrees, bubble enrichment). The pressure degree of freedom is the one with
256 * the same unit support point.
257 */
258 void
260
261 /**
262 * @brief Inverse for total time for averaging.
263 *
264 */
266
267 /**
268 * @brief Store the first time step in case it varies.
269 *
270 */
271 double dt_0;
272
273 /**
274 * @brief Vector to store the velocity multiplied by time step.
275 *
276 */
278
279 /**
280 * @brief Vector to store the sum of all the velocities multiplied by time step.
281 *
282 */
284
285 /**
286 * @brief Vector to store average velocities.
287 *
288 */
290
291 /**
292 * @brief Shared pointer to the getter vector for the average velocities.
293 *
294 */
295 std::shared_ptr<VectorType> get_av;
296
297 /**
298 * @brief Vector to store the velocities multiplied by the time step to
299 * calculate the normal stresses.
300 *
301 */
303
304 /**
305 * @brief Vector to store sum of the velocities multiplied by the time step to
306 * calculate the normal stresses.
307 *
308 */
310
311 /**
312 * @brief Vector with average Reynolds normal stresses.
313 *
314 */
316
317 /**
318 * @brief Getter vector for the average Reynolds normal stresses.
319 *
320 */
322
323 /**
324 * @brief Vector to store the velocities multiplied by the time step to
325 * calculate the shear stresses.
326 *
327 */
329
330 /**
331 * @brief Vector to store the sum the velocities multiplied by the time step to
332 * calculate the shear stresses.
333 *
334 */
336
337 /**
338 * @brief Vector with average average Reynolds shear stresses.
339 *
340 */
342
343 /**
344 * @brief Getter vector for the average Reynolds shear stresses.
345 *
346 */
348
349 /**
350 * @brief Ghosted vector to store the sum of all the velocities multiplied by time step.
351 *
352 */
354
355 /**
356 * @brief Ghosted vector to store sum of the velocities multiplied by the time step to
357 * calculate the normal stresses.
358 *
359 */
361
362 /**
363 * @brief Ghosted vector to store the sum the velocities multiplied by the time step to
364 * calculate the shear stresses.
365 *
366 */
368
369 /**
370 * @brief Object used to transfer the average velocities in case of mesh adaptation.
371 *
372 */
373 SolutionTransfer<dim, VectorType> solution_transfer_sum_velocity_dt;
374
375 /**
376 * @brief Object used to transfer the average Reynolds normal stresses in case of
377 * mesh adaptation.
378 *
379 */
380 SolutionTransfer<dim, VectorType>
382
383 /**
384 * @brief Object used to transfer the average Reynolds shear stresses in case of
385 * mesh adaptation.
386 *
387 */
388 SolutionTransfer<dim, VectorType>
390
391 /**
392 * @brief Time step.
393 *
394 */
395 double dt;
396
397 /**
398 * @brief Initial time of the simulation.
399 *
400 */
402
403 /**
404 * @brief Total period of time for averaging.
405 *
406 */
408
409 /**
410 * @brief Track whether we are within the averaging time period.
411 *
412 */
414
415 /**
416 * @brief DoFHandler of the velocity and pressure fields.
417 *
418 */
419 const DoFHandler<dim> &dof_handler;
420
421 /**
422 * @brief Degrees of freedom of the locally owned velocity support points.
423 *
424 */
425 std::vector<SupportPointDoFs> locally_owned_support_points;
426};
427
428#endif
VectorType sum_velocity_dt
Vector to store the sum of all the velocities multiplied by time step.
SolutionTransfer< dim, VectorType > solution_transfer_sum_reynolds_normal_stress_dt
Object used to transfer the average Reynolds normal stresses in case of mesh adaptation.
VectorType reynolds_normal_stress_dt
Vector to store the velocities multiplied by the time step to calculate the normal stresses.
VectorType sum_velocity_dt_with_ghost_cells
Ghosted vector to store the sum of all the velocities multiplied by time step.
VectorType average_velocities
Vector to store average velocities.
VectorType sum_rns_dt_with_ghost_cells
Ghosted vector to store sum of the velocities multiplied by the time step to calculate the normal str...
std::vector< const VectorType * > save(const std::string &prefix)
Save checkpoints to continuing averaging after restart.
VectorType velocity_dt
Vector to store the velocity multiplied by time step.
double inv_range_time
Inverse for total time for averaging.
std::shared_ptr< VectorType > get_av
Shared pointer to the getter vector for the average velocities.
SolutionTransfer< dim, VectorType > solution_transfer_sum_reynolds_shear_stress_dt
Object used to transfer the average Reynolds shear stresses in case of mesh adaptation.
void initialize_vectors(const DofsType &locally_owned_dofs, const DofsType &locally_relevant_dofs, const MPI_Comm &mpi_communicator)
Initialize all the important vectors for the average velocities and reynolds stresses calculation....
VectorType get_rns
Getter vector for the average Reynolds normal stresses.
VectorType sum_reynolds_shear_stress_dt
Vector to store the sum the velocities multiplied by the time step to calculate the shear stresses.
void sanitize_after_restart(const double current_time)
Sanitize the average velocity object after a checkpoint has been read by resetting all of the locally...
void post_mesh_adaptation()
Reestablish solution vectors after dynamic mesh adaptation.
VectorType get_rss
Getter vector for the average Reynolds shear stresses.
void calculate_reynolds_stresses(const VectorType &local_evaluation_point)
Calculate normal and other resolved time-averaged Reynold stresses and .
void gather_locally_owned_support_points()
Gather the degrees of freedom of every locally owned velocity support point, with the pressure degree...
VectorType sum_rss_dt_with_ghost_cells
Ghosted vector to store the sum the velocities multiplied by the time step to calculate the shear str...
std::vector< SupportPointDoFs > locally_owned_support_points
Degrees of freedom of the locally owned velocity support points.
const DoFHandler< dim > & dof_handler
DoFHandler of the velocity and pressure fields.
double dt_0
Store the first time step in case it varies.
const VectorType & get_reynolds_shear_stresses()
Give the time-averaged Reynolds shear stresses with ghost cells.
const VectorType & get_reynolds_normal_stresses()
Give the time-averaged Reynolds normal stresses with ghost cells.
void prepare_for_mesh_adaptation()
Prepare average velocity object for dynamic mesh adaptation.
void calculate_average_velocities(const VectorType &local_evaluation_point, const Parameters::PostProcessing< dim > &post_processing, const double &current_time, const double &time_step)
Calculate time-averaged velocities and pressure using vector with no ghost cells.
std::vector< VectorType * > read(const std::string &prefix)
Read checkpoints to continuing averaging after restart.
SolutionTransfer< dim, VectorType > solution_transfer_sum_velocity_dt
Object used to transfer the average velocities in case of mesh adaptation.
std::shared_ptr< VectorType > get_average_velocities()
Give the average of solutions with ghost cells.
bool has_started_averaging
Track whether we are within the averaging time period.
AverageVelocities(DoFHandler< dim > &dof_handler)
Constructor that initializes the solution transfer objects for the velocity and the Reynolds stresses...
void zero_average_after_restart()
Reinitialize the values of sum_velocities_dt_with_ghost_cells vector to 0 and the has_started_averagi...
VectorType reynolds_shear_stress_dt
Vector to store the velocities multiplied by the time step to calculate the shear stresses.
double real_initial_time
Initial time of the simulation.
VectorType reynolds_shear_stresses
Vector with average average Reynolds shear stresses.
VectorType sum_reynolds_normal_stress_dt
Vector to store sum of the velocities multiplied by the time step to calculate the normal stresses.
double total_time_for_average
Total period of time for averaging.
VectorType reynolds_normal_stresses
Vector with average Reynolds normal stresses.
Postprocessing - Defines the parameters for the post-processing. In Lethe, post-processing implies th...
Global indices of the degrees of freedom located at one velocity support point.
types::global_dof_index pressure
Degree of freedom of the pressure at the same support point, or numbers::invalid_dof_index if the pre...
std::array< types::global_dof_index, dim > velocity
Degrees of freedom of the dim velocity components.
GlobalVectorType VectorType