ryujin 2.1.1 revision 0348cbb53a3e4b1da2a4c037e81f88f2d21ce219
time_loop.h
Go to the documentation of this file.
1//
2// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3// Copyright (C) 2020 - 2024 by the ryujin authors
4//
5
6#pragma once
7
8#include <compile_time_options.h>
9
10#include "discretization.h"
11#include "hyperbolic_module.h"
12#include "initial_values.h"
13#include "mesh_adaptor.h"
14#include "mpi_ensemble.h"
15#include "offline_data.h"
16#include "parabolic_module.h"
17#include "postprocessor.h"
18#include "quantities.h"
19#include "time_integrator.h"
20#include "vtu_output.h"
21
22#include <deal.II/base/parameter_acceptor.h>
23#include <deal.II/base/timer.h>
24
25#include <fstream>
26
27namespace ryujin
28{
29
35 template <typename Description, int dim, typename Number = double>
36 class TimeLoop final : public dealii::ParameterAcceptor
37 {
38 public:
43
45
46 using View =
47 typename Description::template HyperbolicSystemView<dim, Number>;
48
50
52 typename Description::template ParabolicSolver<dim, Number>;
53
54 using ScalarNumber = typename View::ScalarNumber;
55
56 static constexpr auto problem_dimension = View::problem_dimension;
57
58 static constexpr auto n_precomputed_values = View::n_precomputed_values;
59
61
63
65
69
73 TimeLoop(const MPI_Comm &mpi_comm);
74
78 void run();
79
80 protected:
85
92 template <typename Callable>
93 void read_checkpoint(StateVector &state_vector,
94 const std::string &base_name,
95 Number &t,
96 unsigned int &output_cycle,
97 const Callable &prepare_compute_kernels);
98
108 void write_checkpoint(const StateVector &state_vector,
109 const std::string &base_name,
110 const Number &t,
111 const unsigned int &output_cycle);
112
118 template <typename Callable>
120 StateVector &state_vector, const Callable &prepare_compute_kernels);
121
122 void compute_error(StateVector &state_vector, Number t);
123
124 void output(StateVector &state_vector,
125 const std::string &name,
126 const Number t,
127 const unsigned int cycle);
128
129 void print_parameters(std::ostream &stream);
130 void print_mpi_partition(std::ostream &stream);
131 void print_memory_statistics(std::ostream &stream);
132 void print_timers(std::ostream &stream);
133 void print_throughput(unsigned int cycle,
134 Number t,
135 std::ostream &stream,
136 bool final_time = false);
137
138 void print_info(const std::string &header);
139 void print_head(const std::string &header,
140 const std::string &secondary,
141 std::ostream &stream);
142
143 void print_cycle_statistics(unsigned int cycle,
144 Number t,
145 unsigned int output_cycle,
146 bool write_to_logfile = false,
147 bool final_time = false);
149
150 private:
155
156 std::string base_name_;
157 std::string base_name_ensemble_;
158
159 std::string debug_filename_;
160
161 Number t_final_;
162 bool enforce_t_final_;
163 Number timer_granularity_;
164
165 bool enable_checkpointing_;
166 bool enable_output_full_;
167 bool enable_output_levelsets_;
168 bool enable_compute_error_;
169 bool enable_compute_quantities_;
170 bool enable_mesh_adaptivity_;
171
172 unsigned int timer_checkpoint_multiplier_;
173 unsigned int timer_output_full_multiplier_;
174 unsigned int timer_output_levelsets_multiplier_;
175 unsigned int timer_compute_quantities_multiplier_;
176
177 std::vector<std::string> error_quantities_;
178 bool error_normalize_;
179
180 bool resume_;
181 bool resume_at_time_zero_;
182
183 Number terminal_update_interval_;
184 bool terminal_show_rank_throughput_;
185
187
191
192 MPIEnsemble mpi_ensemble_;
193
194 std::map<std::string, dealii::Timer> computing_timer_;
195
196 HyperbolicSystem hyperbolic_system_;
197 ParabolicSystem parabolic_system_;
198 Discretization<dim> discretization_;
199 OfflineData<dim, Number> offline_data_;
208
209 dealii::types::global_dof_index n_global_dofs_;
210
211 std::ofstream logfile_; /* log file */
212
214 };
215
216} // namespace ryujin
void write_checkpoint(const StateVector &state_vector, const std::string &base_name, const Number &t, const unsigned int &output_cycle)
Vectors::ScalarVector< Number > ScalarVector
Definition: time_loop.h:62
typename Description::template HyperbolicSystemView< dim, Number > View
Definition: time_loop.h:47
typename Description::HyperbolicSystem HyperbolicSystem
Definition: time_loop.h:44
void print_timers(std::ostream &stream)
static constexpr auto problem_dimension
Definition: time_loop.h:56
typename Description::ParabolicSystem ParabolicSystem
Definition: time_loop.h:49
void output(StateVector &state_vector, const std::string &name, const Number t, const unsigned int cycle)
void print_memory_statistics(std::ostream &stream)
void print_mpi_partition(std::ostream &stream)
void print_parameters(std::ostream &stream)
void compute_error(StateVector &state_vector, Number t)
void read_checkpoint(StateVector &state_vector, const std::string &base_name, Number &t, unsigned int &output_cycle, const Callable &prepare_compute_kernels)
TimeLoop(const MPI_Comm &mpi_comm)
static constexpr auto n_precomputed_values
Definition: time_loop.h:58
typename View::StateVector StateVector
Definition: time_loop.h:60
void print_head(const std::string &header, const std::string &secondary, std::ostream &stream)
void print_throughput(unsigned int cycle, Number t, std::ostream &stream, bool final_time=false)
typename Description::template ParabolicSolver< dim, Number > ParabolicSolver
Definition: time_loop.h:52
void print_cycle_statistics(unsigned int cycle, Number t, unsigned int output_cycle, bool write_to_logfile=false, bool final_time=false)
void print_info(const std::string &header)
typename View::ScalarNumber ScalarNumber
Definition: time_loop.h:54
void adapt_mesh_and_transfer_state_vector(StateVector &state_vector, const Callable &prepare_compute_kernels)
dealii::LinearAlgebra::distributed::Vector< Number > ScalarVector
Definition: state_vector.h:31
std::tuple< MultiComponentVector< Number, problem_dim >, MultiComponentVector< Number, prec_dim >, BlockVector< Number > > StateVector
Definition: state_vector.h:51
Euler::ParabolicSystem ParabolicSystem
Definition: description.h:37
Euler::HyperbolicSystem HyperbolicSystem
Definition: description.h:32