Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
postprocessing_scalar.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_average_scalar_in_time_h
5#define lethe_average_scalar_in_time_h
6
7#include <core/parameters.h>
8
9#include <deal.II/numerics/solution_transfer.h>
10
11using namespace dealii;
12
13/**
14 * @brief Calculates the time-averaged scalar field.
15 *
16 * @tparam dim An integer that denotes the dimension of the space in which
17 * the flow is solved.
18 *
19 * @tparam VectorType The vector type used for the solvers (Trilinos (normal or block)
20 * or deal.II vectors).
21 *
22 * @tparam DofsType The type of storage of indices which differs according to vector.
23 *
24 */
25
26template <int dim>
28{
29public:
30 /**
31 * @brief Constructor that initializes the solution transfer objects for the scalar field.
32 *
33 * @param[in] dof_handler Used to initialize the solution transfer objects.
34 * The solution transfer object is later used for mesh adaptation.
35 */
36 AverageScalar(const DoFHandler<dim> &dof_handler);
37
38
39 /**
40 * @brief Calculate time-averaged scalar field using vector with no ghost
41 * cells.
42 *
43 * @param[in] local_evaluation_point The solution vector with no ghost cells.
44 *
45 * @param[in] post_processing The postprocessing parameters to get the initial
46 * time used for averaging.
47 *
48 * @param[in] current_time The current time.
49 *
50 * @param[in] time_step The time step.
51 */
52 void
54 const GlobalVectorType &local_evaluation_point,
55 const Parameters::PostProcessing<dim> &post_processing,
56 const double current_time,
57 const double time_step);
58
59 /**
60 * @brief Calculate time-averaged scalar field using vector with no ghost
61 * cells.
62 *
63 * @param[in] locally_owned_dofs Degrees of freedom owned by a single
64 * processor.
65 *
66 * @param[in] locally_relevant_dofs Degrees of freedom that live on locally
67 * owned or ghost cells of a single processor.
68 *
69 * @param[in] mpi_communicator The communicator information.
70 */
71 void
72 initialize_vectors(const IndexSet &locally_owned_dofs,
73 const IndexSet &locally_relevant_dofs,
74 const MPI_Comm &mpi_communicator);
75
76 /**
77 * @brief Getter for the average scalar.
78 *
79 */
82 {
83 return average_scalar;
84 }
85
86 /**
87 * @brief Prepare average scalar object for dynamic mesh adaptation.
88 */
89 void
91
92 /**
93 * @brief Prepare average scalar object for dynamic mesh adaptation.
94 */
95 void
97
98 /**
99 * @brief Reestablish solution vectors after dynamic mesh adaptation.
100 */
101 void
103
104 /**
105 * @brief Save checkpoints to continue the averaging after the restart.
106 *
107 * @param[in] prefix Name for checkpointing files.
108 *
109 * @return Vector containing the average values.
110 */
111 std::vector<const GlobalVectorType *>
112 save(const std::string &prefix);
113
114 /**
115 * @brief Read checkpoints to continuing averaging after restart.
116 *
117 * @param[in] prefix Name for checkpoint files.
118 *
119 * @return Vector containing the average values.
120 */
121 std::vector<GlobalVectorType *>
122 read(const std::string &prefix);
123
124
125 /**
126 * @brief Sanitize the average scalar object after a checkpoint has been read by
127 * resetting all of the locally_owned vectors using the locally_relevant
128 * vectors. This is necessary because only the locally_relevant_vectors are
129 * saved, but the calculation routines expect that the content of the
130 * locally_owned vectors match that of the locally_relevant vectors.
131 */
132 void
137
138 /**
139 * @brief Reinitialize the values of sum_scalar_dt_with_ghost_cells vector to 0 and the has_started_averaging flag to false. If the initial time for average temperature and heat flux parameter is greater than the simulation time, the checkpointed time-averaged heat flux is ignored after a restart. This allows users to restart a simulation with a different averaging start time.
140 */
141 void
143
144private:
145 /**
146 * @brief Vector to store the scalar field multiplied by time step.
147 *
148 */
150
151 /**
152 * @brief Vector to store the sum of all the scalar multiplied by time step.
153 *
154 */
156
157 /**
158 * @brief Ghosted vector to store the sum of all the scalar multiplied by time step.
159 *
160 */
162
163 /**
164 * @brief Object to transfer the averaged scalar in case of mesh adaptation.
165 *
166 */
167 SolutionTransfer<dim, GlobalVectorType> solution_transfer_sum_scalar_dt;
168
169 /**
170 * @brief Time averaged scalar.
171 */
173
174 /**
175 * @brief Time averaged scalar containing the locally owned and locally relevant dofs for all processes.
176 */
178
179 /**
180 * @brief Difference between the simulation starting time and the initial averaging time.
181 */
183
184 /**
185 * @brief Vector to store the sum of all the scalar field multiplied by time step.
186 *
187 */
189
190 /**
191 * @brief Time step.
192 *
193 */
194 double dt;
195
196 /**
197 * @brief First time step is stored in dt_0 and added to total_time_for_average to ensure the first average calculation does not result in a division by zero.
198 *
199 */
200 double dt_0;
201
202 /**
203 * @brief Inverse of the total time for averaging.
204 *
205 */
207
208 /**
209 * @brief Track whether we are within the averaging time period.
210 *
211 */
213};
214
215#endif
SolutionTransfer< dim, GlobalVectorType > solution_transfer_sum_scalar_dt
Object to transfer the averaged scalar in case of mesh adaptation.
std::vector< const GlobalVectorType * > save(const std::string &prefix)
Save checkpoints to continue the averaging after the restart.
GlobalVectorType average_scalar_with_ghost_cells
Time averaged scalar containing the locally owned and locally relevant dofs for all processes.
void zero_average_after_restart()
Reinitialize the values of sum_scalar_dt_with_ghost_cells vector to 0 and the has_started_averaging f...
GlobalVectorType get_average_scalar()
Getter for the average scalar.
GlobalVectorType average_scalar
Time averaged scalar.
double inv_range_time
Inverse of the total time for averaging.
void prepare_for_mesh_adaptation()
Prepare average scalar object for dynamic mesh adaptation.
GlobalVectorType scalar_dt
Vector to store the scalar field multiplied by time step.
bool has_started_averaging
Track whether we are within the averaging time period.
GlobalVectorType sum_scalar_dt_with_ghost_cells
Ghosted vector to store the sum of all the scalar multiplied by time step.
GlobalVectorType sum_scalar_dt
Vector to store the sum of all the scalar multiplied by time step.
double dt_0
First time step is stored in dt_0 and added to total_time_for_average to ensure the first average cal...
double total_time_for_average
Vector to store the sum of all the scalar field multiplied by time step.
void calculate_average_scalar(const GlobalVectorType &local_evaluation_point, const Parameters::PostProcessing< dim > &post_processing, const double current_time, const double time_step)
Calculate time-averaged scalar field using vector with no ghost cells.
AverageScalar(const DoFHandler< dim > &dof_handler)
Constructor that initializes the solution transfer objects for the scalar field.
void sanitize_after_restart()
Sanitize the average scalar object after a checkpoint has been read by resetting all of the locally_o...
void initialize_vectors(const IndexSet &locally_owned_dofs, const IndexSet &locally_relevant_dofs, const MPI_Comm &mpi_communicator)
Calculate time-averaged scalar field using vector with no ghost cells.
void post_mesh_adaptation()
Reestablish solution vectors after dynamic mesh adaptation.
double real_initial_time
Difference between the simulation starting time and the initial averaging time.
std::vector< GlobalVectorType * > read(const std::string &prefix)
Read checkpoints to continuing averaging after restart.
double dt
Time step.
void update_average_scalar()
Prepare average scalar object for dynamic mesh adaptation.
Postprocessing - Defines the parameters for the post-processing. In Lethe, post-processing implies th...
dealii::TrilinosWrappers::MPI::Vector GlobalVectorType
Definition vector.h:17