Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
postprocessing_probes.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) 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_probes_h
5#define lethe_postprocessing_probes_h
6
7#include <core/parameters.h>
9#include <core/utilities.h>
10#include <core/vector.h>
11
12#include <ranges>
13
14template <int dim>
16{
17public:
18 /**
19 * @brief Object that evaluates variables (e.g., velocity) at specified points
20 * in the domain.
21 *
22 * Within every physics postprocessing attribute (either
23 * NavierStokesBase::postprocess_fd() or AuxiliaryPhysics::postprocess())
24 * the evaluation can made by calling the postprocess_probes() attribute of
25 * this object through the MultiphysicsInterface object.
26 * All evaluated values of variables of a same probe are stored within a same
27 * table. All tables are grouped in the PostprocessingProbes::probe_tables
28 * vector. Within the vector, the tables are ordered in increasing order of
29 * probe IDs.
30 *
31 * @param[in] simulation_control SimulationControl object which is used to
32 * obtain the current time and current iteration number.
33 * @param[in] probing_points_parameters Set of parameters describing the
34 * specified probing point and variables of interest.
35 * @param[in] output_frequency Output iteration frequency for postprocessing.
36 * @param[in] verbosity Verbosity level for console output.
37 *
38 * @remark At the moment, probing for only the velocity, pressure, phase, and
39 * temperature variables are implemented. Implementation for other variables
40 * will follow.
41 */
42 PostprocessingProbes(std::shared_ptr<SimulationControl> &simulation_control,
45 const unsigned int output_frequency,
47
48
49
50 /**
51 * @brief Evaluates scalar variables (e.g., pressure) at specified points
52 * in the domain using evaluate_values_at_points and fills appropriate probe
53 * tables.
54 *
55 * @tparam VectorType Type of vector of the solution vector.
56 *
57 * @param[in] mapping Mapping of the domain.
58 * @param[in] dof_handler DoF handler associated to the solution field.
59 * @param[in] present_solution Vector containing the scalar solution field.
60 * @param[in] variable Variable of interest.
61 * @param[in] pcout Parallel console output stream.
62 * @param[out] evaluated_scalar_values Vector of evaluated scalar values.
63 */
64 template <typename VectorType>
65 void
66 postprocess_probes(const Mapping<dim> &mapping,
67 const DoFHandler<dim> &dof_handler,
68 const VectorType &present_solution,
69 const Variable variable,
70 const ConditionalOStream &pcout,
71 std::vector<double> &evaluated_scalar_values);
72
73 /**
74 * @brief Evaluates vector variables (e.g., velocity) at specified points
75 * in the domain using evaluate_values_at_points() and fills appropriate probe
76 * tables.
77 *
78 * @tparam VectorType Type of vector of the solution vector.
79 *
80 * @param[in] mapping Mapping of the domain.
81 * @param[in] dof_handler DoF handler associated to the solution field.
82 * @param[in] present_solution Vector containing the vector solution field.
83 * For distributed meshes, ghost elements must be updated.
84 * @param[in] variable Variable of interest.
85 * @param[in] pcout Parallel console output stream.
86 * @param[out] evaluated_vector_values Vector of evaluated vector values.
87 *
88 * @remark At the moment, only the velocity variable is implemented.
89 */
90 template <typename VectorType>
91 void
93 const Mapping<dim> &mapping,
94 const DoFHandler<dim> &dof_handler,
95 const VectorType &present_solution,
96 const Variable variable,
97 const ConditionalOStream &pcout,
98 std::vector<Tensor<1, dim, double>> &evaluated_vector_values);
99
100 /**
101 * @brief Writes the probe tables into output `.dat` file.
102 */
103 inline void
105 {
106 if (simulation_control->get_iteration_number() % output_frequency == 0 ||
107 simulation_control->is_at_end())
108 if (Utilities::MPI::this_mpi_process(MPI_COMM_WORLD) == 0)
109 {
110 for (unsigned int i = 0; i < probe_tables.size(); ++i)
111 {
112 std::string file_path =
113 output_folder + "probe_" + Utilities::int_to_string(i, 2) +
114 "_" + probing_points_parameters.probing_points_output_names[i] +
115 ".dat";
116 std::ofstream output(file_path.c_str());
117
118 probe_tables[i].write_text(output);
119 }
120 }
121 }
122
123 /**
124 * @brief Clears the content of the set indicating if the current time has
125 * been added to a probe table. This is reset at every postprocessing time
126 * step.
127 */
128 inline void
133
134 /**
135 * @brief Returns a vector of references to TableHandler objects that needs to
136 * be serialized/deserialized for the postprocessed probes.
137 *
138 * @return Structure containing a vector of references to TableHandler objects
139 * that needs to be serialized/deserialized for the postprocessed probes, and
140 * their corresponding filenames.
141 */
142 std::vector<OutputStructTableHandler>
144
145 /**
146 * @brief Serializes all probe tables.
147 */
148 inline void
150 {
151 const std::vector<OutputStructTableHandler> &table_output_structs =
152 this->gather_tables();
153 serialize_tables_vector(table_output_structs, MPI_COMM_WORLD);
154 }
155
156 /**
157 * @brief Deserializes all probe tables.
158 */
159 inline void
161 {
162 std::vector<OutputStructTableHandler> table_output_structs =
163 this->gather_tables();
164 deserialize_tables_vector(table_output_structs, MPI_COMM_WORLD);
165 }
166
167 /// Set of valid scalar variables
170
171 /// Set of valid vector variables
173
174private:
175 /**
176 * @brief Prepares probe tables by setting the entry formats and precisions
177 * for all probes of the specified `variable`.
178 *
179 * @param[in] variable Variable of interest.
180 *
181 */
182 inline void
184 {
185 const auto &probing_points_of_variable =
186 probing_points_parameters.probing_points_per_variable.at(variable);
187
188 // Go through tables of the variable and prepare them by declaring and
189 // formating the column(s) of the variable
190 for (const unsigned int &id : probing_points_of_variable.ids)
191 {
192 TableHandler &current_table = probe_tables[id];
193 const std::string column_name =
195
196 if (implemented_scalar_variables.contains(variable))
197 {
198 current_table.declare_column(column_name);
199 current_table.set_precision(column_name, table_precision);
200 current_table.set_scientific(column_name, true);
201 }
202 else if (implemented_vector_variables.contains(variable))
203 {
204 // Only velocity is implemented at the moment
205 current_table.declare_column(column_name + "_x");
206 current_table.set_precision(column_name + "_x", table_precision);
207 current_table.set_scientific(column_name + "_x", true);
208 current_table.declare_column(column_name + "_y");
209 current_table.set_precision(column_name + "_y", table_precision);
210 current_table.set_scientific(column_name + "_y", true);
211 if constexpr (dim == 3)
212 {
213 current_table.declare_column(column_name + "_z");
214 current_table.set_precision(column_name + "_z",
216 current_table.set_scientific(column_name + "_z", true);
217 }
218 }
219 }
220 }
221
222 /**
223 * @brief Checks if the table of a specified probing point (@p probe_id)
224 * already has a row entry for the current time step.
225 *
226 * @param[in] probe_id Identifier of the probing point investigated.
227 *
228 * @return
229 * - @p true if there already is an entry for the current time step.
230 * - @p false if there is no row for the current time step.
231 */
232 inline bool
233 check_if_table_contains_current_time(const unsigned int &probe_id)
234 {
235 if (probe_tables_with_current_time.contains(probe_id))
236 return true;
237 else // No entry yet for the current time step
238 {
239 // Add the ID of the probing point to the set
240 probe_tables_with_current_time.insert(probe_id);
241 return false;
242 }
243 };
244
245 /// Simulation control for current time and current iteration number.
246 std::shared_ptr<SimulationControl> simulation_control;
247
248 /** Set of parameters describing the specified probing point and variables of
249 * interest */
252
253 /// Postprocessing output frequency
254 const unsigned int output_frequency;
255
256 /// Path to the output folder where all .dat are saved
257 const std::string output_folder;
258
259 /// Postprocessing verbosity
261
262 /** Contains IDs of probe for which the current time has been added to the
263 * table to avoid duplication of time entries when a probing point contains
264 * multiple variables */
265 std::set<unsigned int> probe_tables_with_current_time;
266
267 /** Tables of probe measures (1 table per probe). The table index in the
268 * vector corresponds to the probe ID. */
269 std::vector<TableHandler> probe_tables;
270
271 /// Remote point evaluators (1 evaluator per variable)
272 std::map<Variable, Utilities::MPI::RemotePointEvaluation<dim>>
274
275 /// Precision of table entries
276 const unsigned int table_precision =
277 6; // TODO change the value with user-input parameter when issue #2039 is
278 // being resolved
279};
280
281#endif
void prepare_probe_tables(const Variable &variable)
Prepares probe tables by setting the entry formats and precisions for all probes of the specified var...
const Parameters::PostProcessing< dim >::ProbingPoints probing_points_parameters
std::shared_ptr< SimulationControl > simulation_control
Simulation control for current time and current iteration number.
const unsigned int output_frequency
Postprocessing output frequency.
const std::set< Variable > implemented_scalar_variables
Set of valid scalar variables.
std::vector< OutputStructTableHandler > gather_tables()
Returns a vector of references to TableHandler objects that needs to be serialized/deserialized for t...
bool check_if_table_contains_current_time(const unsigned int &probe_id)
Checks if the table of a specified probing point (probe_id) already has a row entry for the current t...
void postprocess_probes(const Mapping< dim > &mapping, const DoFHandler< dim > &dof_handler, const VectorType &present_solution, const Variable variable, const ConditionalOStream &pcout, std::vector< double > &evaluated_scalar_values)
Evaluates scalar variables (e.g., pressure) at specified points in the domain using evaluate_values_a...
PostprocessingProbes(std::shared_ptr< SimulationControl > &simulation_control, const Parameters::PostProcessing< dim >::ProbingPoints &probing_points_parameters, const unsigned int output_frequency, const Parameters::Verbosity &verbosity)
Object that evaluates variables (e.g., velocity) at specified points in the domain.
void reset_current_time_set()
Clears the content of the set indicating if the current time has been added to a probe table....
const Parameters::Verbosity verbosity
Postprocessing verbosity.
void write_probing_points_tables()
Writes the probe tables into output .dat file.
const std::string output_folder
Path to the output folder where all .dat are saved.
const unsigned int table_precision
Precision of table entries.
void read_checkpoint()
Deserializes all probe tables.
std::vector< TableHandler > probe_tables
void write_checkpoint()
Serializes all probe tables.
std::set< unsigned int > probe_tables_with_current_time
std::map< Variable, Utilities::MPI::RemotePointEvaluation< dim > > remote_point_evaluators
Remote point evaluators (1 evaluator per variable).
const std::set< Variable > implemented_vector_variables
Set of valid vector variables.
void serialize_tables_vector(const std::vector< OutputStructTableHandler > &table_output_structs, const MPI_Comm mpi_communicator)
Serializes all the TableHandler objects in table_output_structs.
Definition utilities.h:602
void deserialize_tables_vector(std::vector< OutputStructTableHandler > &table_output_structs, const MPI_Comm mpi_communicator)
Deserializes all the TableHandler objects in table_output_structs.
Definition utilities.h:624
Variable
Solution fields of the different physics that are used as an indicator for multiple purposes (e....
@ phase
Phase indicator scalar field from CLS.
@ velocity
Velocity vector field from fluid dynamics.
@ pressure
Pressure scalar field from fluid dynamics.
@ temperature
Temperature scalar field from heat transfer.
std::string get_variable_string_with_underscores(Variable variable)
Gets for every available Variable the string corresponding to the variable. Words are separated by un...
Simulation control classes for managing time-stepping and iteration control in Lethe.
Probing points parameters. This is used to monitor the evolution of variables (e.g....
GlobalVectorType VectorType