Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
postprocessing_probes.cc
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
5
6template <int dim>
8 std::shared_ptr<SimulationControl> &simulation_control,
11 const unsigned int output_frequency,
16 , output_folder(simulation_control->get_output_path())
18 , probe_tables(probing_points_parameters.number_of_probing_points)
19{
20 // Initialize time column for all tables
21 for (auto &current_table : probe_tables)
22 {
23 current_table.declare_column("time");
24 current_table.set_precision("time", table_precision);
25 current_table.set_scientific("time", true);
26 }
27
28 // Get all variable with probes
29 auto keys_range =
30 std::views::keys(probing_points_parameters.probing_points_per_variable);
31
32 // Loop over all variables with probes to declare table columns and format
33 // them. Also, add remote point evaluator to map.
34 for (auto variable_it = keys_range.begin(); variable_it != keys_range.end();
35 ++variable_it)
36 {
37 prepare_probe_tables(*variable_it);
38 remote_point_evaluators.try_emplace(*variable_it);
39 }
40};
41
42template <int dim>
43template <typename VectorType>
44void
46 const Mapping<dim> &mapping,
47 const DoFHandler<dim> &dof_handler,
48 const VectorType &present_solution,
49 const Variable variable,
50 const ConditionalOStream &pcout,
51 std::vector<double> &evaluated_scalar_values)
52{
53 const auto &probing_points_of_the_variable =
54 probing_points_parameters.probing_points_per_variable.at(variable);
55
56 // Some scalar field solutions are not contiguous with the solution vector.
57 // We identify here the correct component of the solution vector.
58 const unsigned int first_selected_component =
59 (variable == Variable::pressure) ? dim :
61 0;
63 dof_handler,
64 present_solution,
65 probing_points_of_the_variable.points,
66 remote_point_evaluators.at(variable),
67 evaluated_scalar_values,
68 first_selected_component);
69
70 // Get variable strings
71 const std::string variable_name = get_variable_string(variable);
72 const std::string column_name =
74
75 const double current_time = simulation_control->get_current_time();
76
78 announce_string(pcout, variable_name + " probes");
79
80 // For each probing point fill the correct table
81 for (unsigned int i = 0; i < probing_points_of_the_variable.ids.size(); ++i)
82 {
83 // Get ID of the probe
84 const unsigned int &id = probing_points_of_the_variable.ids[i];
85
86 const std::string &table_name =
87 probing_points_parameters.probing_points_output_names[id];
88 const double &evaluated_value = evaluated_scalar_values[i];
89
90 // Console output
92 {
93 pcout << "At probe " << id << " ("
94 << Patterns::Tools::Convert<Point<dim>>::to_string(
95 probing_points_of_the_variable.points[i])
96 << ") - " << table_name << std::endl;
97 pcout << " Evaluated " << variable_name
98 << " value: " << evaluated_value << std::endl;
99 }
100
101 // Access the table associated with the probe
102 TableHandler &current_table = probe_tables[id];
103
104 // Add entries to table
106 current_table.add_value("time", current_time);
107 current_table.add_value(column_name, evaluated_value);
108 }
109}
110
111template void
113 const Mapping<2> &mapping,
114 const DoFHandler<2> &dof_handler,
115 const GlobalVectorType &present_solution,
116 const Variable variable,
117 const ConditionalOStream &pcout,
118 std::vector<double> &evaluated_scalar_values);
119
120template void
122 const Mapping<3> &mapping,
123 const DoFHandler<3> &dof_handler,
124 const GlobalVectorType &present_solution,
125 const Variable variable,
126 const ConditionalOStream &pcout,
127 std::vector<double> &evaluated_scalar_values);
128
129template void
131 const Mapping<2> &mapping,
132 const DoFHandler<2> &dof_handler,
133 const GlobalBlockVectorType &present_solution,
134 const Variable variable,
135 const ConditionalOStream &pcout,
136 std::vector<double> &evaluated_scalar_values);
137
138template void
140 const Mapping<3> &mapping,
141 const DoFHandler<3> &dof_handler,
142 const GlobalBlockVectorType &present_solution,
143 const Variable variable,
144 const ConditionalOStream &pcout,
145 std::vector<double> &evaluated_scalar_values);
146
147#ifndef LETHE_USE_LDV
148template void
150 const Mapping<2> &mapping,
151 const DoFHandler<2> &dof_handler,
152 const LinearAlgebra::distributed::Vector<double> &present_solution,
153 const Variable variable,
154 const ConditionalOStream &pcout,
155 std::vector<double> &evaluated_scalar_values);
156
157template void
159 const Mapping<3> &mapping,
160 const DoFHandler<3> &dof_handler,
161 const LinearAlgebra::distributed::Vector<double> &present_solution,
162 const Variable variable,
163 const ConditionalOStream &pcout,
164 std::vector<double> &evaluated_scalar_values);
165#endif
166
167template <int dim>
168template <typename VectorType>
169void
171 const Mapping<dim> &mapping,
172 const DoFHandler<dim> &dof_handler,
173 const VectorType &present_solution,
174 const Variable variable,
175 const ConditionalOStream &pcout,
176 std::vector<Tensor<1, dim, double>> &evaluated_vector_values)
177{
178 AssertThrow(variable == Variable::velocity,
179 ExcMessage(
180 "Only implemented for velocity for now. Implementations for "
181 "TimeHarmonicMaxwell variables will be done later."));
182
183 const auto &probing_points_of_the_variable =
184 probing_points_parameters.probing_points_per_variable.at(variable);
185
186 const unsigned int first_selected_component = 0;
187
189 dof_handler,
190 present_solution,
191 probing_points_of_the_variable.points,
192 remote_point_evaluators.at(variable),
193 evaluated_vector_values,
194 first_selected_component);
195
196 // Get variable strings
197 const std::string variable_name = get_variable_string(variable);
198 const std::string column_name_prefix =
200
201 const double current_time = simulation_control->get_current_time();
202
204 announce_string(pcout, variable_name + " probes");
205
206 // For each probing point fill the correct table
207 for (unsigned int i = 0; i < probing_points_of_the_variable.ids.size(); ++i)
208 {
209 // Get ID of the probe
210 const unsigned int &id = probing_points_of_the_variable.ids[i];
211
212 const std::string &table_name =
213 probing_points_parameters.probing_points_output_names[id];
214 const Tensor<1, dim, double> &evaluated_value =
215 evaluated_vector_values[i];
216
217 // Console output
219 {
220 pcout << "At probe " << id << " ("
221 << Patterns::Tools::Convert<Point<dim>>::to_string(
222 probing_points_of_the_variable.points[i])
223 << ") - " << table_name << std::endl;
224 pcout << " Evaluated " << variable_name << " vector: "
225 << Patterns::Tools::Convert<Tensor<1, dim, double>>::to_string(
226 evaluated_value)
227 << std::endl;
228 }
229
230 // Access the table associated with the probe
231 TableHandler &current_table = probe_tables[id];
232
233 // Add entries to table
235 current_table.add_value("time", current_time);
236 current_table.add_value(column_name_prefix + "_x", evaluated_value[0]);
237 current_table.add_value(column_name_prefix + "_y", evaluated_value[1]);
238 if constexpr (dim == 3)
239 current_table.add_value(column_name_prefix + "_z", evaluated_value[2]);
240 }
241}
242
243template void
245 const Mapping<2> &mapping,
246 const DoFHandler<2> &dof_handler,
247 const GlobalVectorType &present_solution,
248 const Variable variable,
249 const ConditionalOStream &pcout,
250 std::vector<Tensor<1, 2, double>> &evaluated_vector_values);
251
252template void
254 const Mapping<3> &mapping,
255 const DoFHandler<3> &dof_handler,
256 const GlobalVectorType &present_solution,
257 const Variable variable,
258 const ConditionalOStream &pcout,
259 std::vector<Tensor<1, 3, double>> &evaluated_vector_values);
260
261template void
263 const Mapping<2> &mapping,
264 const DoFHandler<2> &dof_handler,
265 const GlobalBlockVectorType &present_solution,
266 const Variable variable,
267 const ConditionalOStream &pcout,
268 std::vector<Tensor<1, 2, double>> &evaluated_vector_values);
269
270template void
272 const Mapping<3> &mapping,
273 const DoFHandler<3> &dof_handler,
274 const GlobalBlockVectorType &present_solution,
275 const Variable variable,
276 const ConditionalOStream &pcout,
277 std::vector<Tensor<1, 3, double>> &evaluated_vector_values);
278
279#ifndef LETHE_USE_LDV
280template void
282 const Mapping<2> &mapping,
283 const DoFHandler<2> &dof_handler,
284 const LinearAlgebra::distributed::Vector<double> &present_solution,
285 const Variable variable,
286 const ConditionalOStream &pcout,
287 std::vector<Tensor<1, 2, double>> &evaluated_vector_values);
288
289template void
291 const Mapping<3> &mapping,
292 const DoFHandler<3> &dof_handler,
293 const LinearAlgebra::distributed::Vector<double> &present_solution,
294 const Variable variable,
295 const ConditionalOStream &pcout,
296 std::vector<Tensor<1, 3, double>> &evaluated_vector_values);
297#endif
298
299template <int dim>
300std::vector<OutputStructTableHandler>
302{
303 std::vector<OutputStructTableHandler> table_output_structs;
304
305 std::string prefix = output_folder;
306 std::string suffix = ".checkpoint";
307
308 for (unsigned int i = 0; i < probe_tables.size(); ++i)
309 {
310 const auto &filename =
311 "probe_" + Utilities::int_to_string(i, 2) + "_" +
312 probing_points_parameters.probing_points_output_names[i];
313
314 table_output_structs.emplace_back(probe_tables[i],
315 prefix + filename + suffix);
316 }
317
318 return table_output_structs;
319}
320
321template class PostprocessingProbes<2>;
322template class PostprocessingProbes<3>;
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.
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.
const Parameters::Verbosity verbosity
Postprocessing verbosity.
const std::string output_folder
Path to the output folder where all .dat are saved.
const unsigned int table_precision
Precision of table entries.
std::vector< TableHandler > probe_tables
std::map< Variable, Utilities::MPI::RemotePointEvaluation< dim > > remote_point_evaluators
Remote point evaluators (1 evaluator per variable).
void evaluate_values_at_points(const Mapping< dim > &mapping, const DoFHandler< dim > &dof_handler, const VectorType &solution_field, const std::vector< Point< dim > > &evaluation_points, Utilities::MPI::RemotePointEvaluation< dim > &remote_point_evaluator, std::vector< double > &evaluated_scalar_values, const unsigned int first_selected_component=0)
Evaluates the values of a scalar field at remote points of the domain from the mapping,...
Definition utilities.cc:930
void announce_string(const ConditionalOStream &pcout, const std::string &expression, const char delimiter='-')
Prints a string and then adds a line above and below made with dashes containing as many dashes as th...
Definition utilities.h:500
Variable
Solution fields of the different physics that are used as an indicator for multiple purposes (e....
@ chemical_potential_cahn_hilliard
Chemical potential scalar field from Cahn Hilliard.
@ velocity
Velocity vector field from fluid dynamics.
@ pressure
Pressure scalar field from fluid dynamics.
std::string get_variable_string(Variable variable)
Gets for every available Variable the string corresponding to the variable.
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...
Probing points parameters. This is used to monitor the evolution of variables (e.g....
GlobalVectorType VectorType
dealii::TrilinosWrappers::MPI::Vector GlobalVectorType
Definition vector.h:17
dealii::TrilinosWrappers::MPI::BlockVector GlobalBlockVectorType
Definition vector.h:18