ryujin 2.1.1 revision 350e54cc11f3d21282bddcf3e6517944dbc508bf
time_loop.template.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 "instrumentation.h"
9#include "scope.h"
10#include "state_vector.h"
11#include "time_loop.h"
12#include "version_info.h"
13
14#include <deal.II/base/logstream.h>
15#include <deal.II/base/work_stream.h>
16#include <deal.II/numerics/vector_tools.h>
17#include <deal.II/numerics/vector_tools.templates.h>
18
19#include <filesystem>
20#include <fstream>
21#include <iomanip>
22
23using namespace dealii;
24
25namespace ryujin
26{
27 template <typename Description, int dim, typename Number>
29 : ParameterAcceptor("/A - TimeLoop")
30 , mpi_ensemble_(mpi_comm)
31 , hyperbolic_system_(mpi_ensemble_, "/B - Equation")
32 , parabolic_system_(mpi_ensemble_, "/B - Equation")
33 , discretization_(mpi_ensemble_, "/C - Discretization")
34 , offline_data_(mpi_ensemble_, discretization_, "/D - OfflineData")
35 , initial_values_(mpi_ensemble_,
36 "/E - InitialValues",
37 mpi_ensemble_,
38 offline_data_,
39 hyperbolic_system_,
40 parabolic_system_)
41 , hyperbolic_module_(mpi_ensemble_,
42 computing_timer_,
43 offline_data_,
44 hyperbolic_system_,
45 initial_values_,
46 "/F - HyperbolicModule")
47 , parabolic_module_(mpi_ensemble_,
48 computing_timer_,
49 offline_data_,
50 hyperbolic_system_,
51 parabolic_system_,
52 initial_values_,
53 "/G - ParabolicModule")
54 , time_integrator_(mpi_ensemble_,
55 offline_data_,
56 hyperbolic_module_,
57 parabolic_module_,
58 "/H - TimeIntegrator")
59 , mesh_adaptor_(mpi_ensemble_,
60 offline_data_,
61 hyperbolic_system_,
62 parabolic_system_,
63 hyperbolic_module_.initial_precomputed(),
64 hyperbolic_module_.alpha(),
65 "/I - MeshAdaptor")
66 , solution_transfer_(mpi_ensemble_,
67 offline_data_,
68 hyperbolic_system_,
69 parabolic_system_,
70 "/I - MeshAdaptor")
71 , postprocessor_(mpi_ensemble_,
72 offline_data_,
73 hyperbolic_system_,
74 parabolic_system_,
75 "/J - VTUOutput")
76 , vtu_output_(mpi_ensemble_,
77 offline_data_,
78 hyperbolic_system_,
79 parabolic_system_,
80 postprocessor_,
81 hyperbolic_module_.initial_precomputed(),
82 hyperbolic_module_.alpha(),
83 "/J - VTUOutput")
84 , quantities_(mpi_ensemble_,
85 offline_data_,
86 hyperbolic_system_,
87 parabolic_system_,
88 "/K - Quantities")
89 {
90 base_name_ = "test";
91 add_parameter("basename", base_name_, "Base name for all output files");
92
93 t_final_ = Number(5.);
94 add_parameter("final time", t_final_, "Final time");
95
96 enforce_t_final_ = false;
97 add_parameter("enforce final time",
98 enforce_t_final_,
99 "Boolean indicating whether the final time should be "
100 "enforced strictly. If set to true the last time step is "
101 "shortened so that the simulation ends precisely at t_final");
102
103 timer_granularity_ = Number(0.01);
104 add_parameter("timer granularity",
105 timer_granularity_,
106 "The timer granularity specifies the time interval after "
107 "which compute, output, postprocessing, and mesh adaptation "
108 "routines are run. This \"baseline tick\" is further "
109 "modified by the corresponding \"*_multiplier\" options");
110
111 enable_output_full_ = false;
112 add_parameter("enable output full",
113 enable_output_full_,
114 "Write out full pvtu records. The frequency is determined by "
115 "\"timer granularity\" and \"timer output full multiplier\"");
116
117 enable_output_levelsets_ = false;
118 add_parameter(
119 "enable output levelsets",
120 enable_output_levelsets_,
121 "Write out levelsets pvtu records. The frequency is determined by "
122 "\"timer granularity\" and \"timer output levelsets multiplier\"");
123
124 enable_compute_error_ = false;
125 add_parameter("enable compute error",
126 enable_compute_error_,
127 "Flag to control whether we compute the Linfty Linf_norm of "
128 "the difference to an analytic solution. Implemented only "
129 "for certain initial state configurations.");
130
131 enable_compute_quantities_ = false;
132 add_parameter(
133 "enable compute quantities",
134 enable_compute_quantities_,
135 "Flag to control whether we compute quantities of interest. The "
136 "frequency how often quantities are logged is determined by \"timer "
137 "granularity\" and \"timer compute quantities multiplier\"");
138
139 enable_mesh_adaptivity_ = false;
140 add_parameter(
141 "enable mesh adaptivity",
142 enable_mesh_adaptivity_,
143 "Flag to control whether we use an adaptive mesh refinement strategy. "
144 "The frequency how often we query MeshAdaptor::analyze() for deciding "
145 "on adapting the mesh is determined by \"timer granularity\" and "
146 "\"timer mesh refinement multiplier\"");
147
148 timer_output_full_multiplier_ = 1;
149 add_parameter("timer output full multiplier",
150 timer_output_full_multiplier_,
151 "Multiplicative modifier applied to \"timer granularity\" "
152 "that determines the full pvtu writeout granularity");
153
154 timer_output_levelsets_multiplier_ = 1;
155 add_parameter("timer output levelsets multiplier",
156 timer_output_levelsets_multiplier_,
157 "Multiplicative modifier applied to \"timer granularity\" "
158 "that determines the levelsets pvtu writeout granularity");
159
160 timer_compute_quantities_multiplier_ = 1;
161 add_parameter(
162 "timer compute quantities multiplier",
163 timer_compute_quantities_multiplier_,
164 "Multiplicative modifier applied to \"timer granularity\" that "
165 "determines the writeout granularity for quantities of interest");
166
167 std::copy(std::begin(View::component_names),
168 std::end(View::component_names),
169 std::back_inserter(error_quantities_));
170
171 add_parameter("error quantities",
172 error_quantities_,
173 "List of conserved quantities used in the computation of the "
174 "error norms.");
175
176 error_normalize_ = true;
177 add_parameter("error normalize",
178 error_normalize_,
179 "Flag to control whether the error should be normalized by "
180 "the corresponding norm of the analytic solution.");
181
182 resume_ = false;
183 add_parameter("resume", resume_, "Resume an interrupted computation");
184
185 resume_at_time_zero_ = false;
186 add_parameter("resume at time zero",
187 resume_at_time_zero_,
188 "Resume from the latest checkpoint but set the time to t=0.");
189
190 terminal_update_interval_ = 5;
191 add_parameter("terminal update interval",
192 terminal_update_interval_,
193 "Number of seconds after which output statistics are "
194 "recomputed and printed on the terminal. Setting the "
195 "interval to zero disables terminal output.");
196
197 terminal_show_rank_throughput_ = true;
198 add_parameter("terminal show rank throughput",
199 terminal_show_rank_throughput_,
200 "If set to true an average per rank throughput is computed "
201 "by dividing the total consumed CPU time (per rank) by the "
202 "number of threads (per rank). If set to false then a plain "
203 "average per thread \"CPU\" throughput value is computed by "
204 "using the umodified total accumulated CPU time.");
205
206 checkpoint_update_interval_ = 0;
207 add_parameter(
208 "checkpoint update interval",
209 checkpoint_update_interval_,
210 "Number of seconds after which a new checkpoint is written out to "
211 "disk. Setting the interval to zero disables checkpointing.");
212
213 debug_filename_ = "";
214 add_parameter("debug filename",
215 debug_filename_,
216 "If set to a nonempty string then we output the contents of "
217 "this file at the end. This is mainly useful in the "
218 "testsuite to output files we wish to compare");
219 }
220
221
222 /*
223 * ---------------------------------------------------------------------------
224 * Setup and main loop:
225 * ---------------------------------------------------------------------------
226 */
227
228
229 template <typename Description, int dim, typename Number>
231 {
232#ifdef DEBUG_OUTPUT
233 std::cout << "TimeLoop<dim, Number>::run()" << std::endl;
234#endif
235
236 {
237 base_name_ensemble_ = base_name_;
238 if (mpi_ensemble_.n_ensembles() > 1) {
239 print_info("setting up MPI ensemble");
240 base_name_ensemble_ += "-ensemble_" + dealii::Utilities::int_to_string(
241 mpi_ensemble_.ensemble(),
242 mpi_ensemble_.n_ensembles());
243 }
244 }
245
246 /* Attach log file and record runtime parameters: */
247
248 if (mpi_ensemble_.world_rank() == 0)
249 logfile_.open(base_name_ + ".log");
250
251 print_parameters(logfile_);
252
253 /*
254 * Prepare data structures:
255 */
256
257 Number t = 0.;
258 unsigned int timer_cycle = 0;
259 StateVector state_vector;
260
261 /* Create a small lambda for preparing compute kernels: */
262 const auto prepare_compute_kernels = [&]() {
263 print_info("preparing compute kernels");
264
265 unsigned int n_parabolic_state_vectors =
266 parabolic_system_.get().n_parabolic_state_vectors();
267
268 offline_data_.prepare(
269 problem_dimension, n_precomputed_values, n_parabolic_state_vectors);
270
271 hyperbolic_module_.prepare();
272 parabolic_module_.prepare();
273 time_integrator_.prepare();
274 mesh_adaptor_.prepare(/*needs current timepoint*/ t);
275 postprocessor_.prepare();
276 vtu_output_.prepare();
277 quantities_.prepare(base_name_ensemble_);
278 print_mpi_partition(logfile_);
279
280 if (mpi_ensemble_.ensemble_rank() == 0)
281 n_global_dofs_ = dealii::Utilities::MPI::sum(
282 offline_data_.dof_handler().n_dofs(),
283 mpi_ensemble_.ensemble_leader_communicator());
284 };
285
286 {
287 Scope scope(computing_timer_, "(re)initialize data structures");
288 print_info("initializing data structures");
289
290 if (resume_) {
291 print_info("resume: reading mesh and loading state vector");
292
293 read_checkpoint(state_vector,
294 base_name_ensemble_,
295 t,
296 timer_cycle,
297 prepare_compute_kernels);
298
299 if (resume_at_time_zero_) {
300 /* Reset the current time t and the output cycle count to zero: */
301 t = 0.;
302 timer_cycle = 0;
303 }
304
305 } else {
306 print_info("creating mesh and interpolating initial values");
307
308 discretization_.prepare(base_name_ensemble_);
309
310 prepare_compute_kernels();
311
312 Vectors::reinit_state_vector<Description>(state_vector, offline_data_);
313 std::get<0>(state_vector) =
314 initial_values_.get().interpolate_hyperbolic_vector();
315
316 Vectors::debug_poison_constrained_dofs<Description>(state_vector,
317 offline_data_);
318 Vectors::debug_poison_precomputed_values<Description>(state_vector,
319 offline_data_);
320 }
321 }
322
323 /* Prepare the state vector for time stepping. */
324 time_integrator_.prepare_state_vector(state_vector, t);
325
326 /*
327 * The honorable main loop:
328 */
329
330 Number last_terminal_output = terminal_update_interval_ == Number(0.)
331 ? std::numeric_limits<Number>::max()
332 : Number(0.);
333 Number last_checkpoint = checkpoint_update_interval_ == Number(0.)
334 ? std::numeric_limits<Number>::max()
335 : Number(0.);
336
337 print_info("entering main loop");
338 computing_timer_["time loop"].start();
339
340 constexpr Number relax =
341 Number(1.) - Number(10.) * std::numeric_limits<Number>::epsilon();
342
343 unsigned int cycle = 1;
344 for (;; ++cycle) {
345
346#ifdef DEBUG_OUTPUT
347 std::cout << "\n\n### cycle = " << cycle << " ###\n\n" << std::endl;
348#endif
349
350 /* Accumulate quantities of interest: */
351
352 if (enable_compute_quantities_) {
353 Scope scope(computing_timer_,
354 "time step [X] - accumulate quantities");
355 quantities_.accumulate(state_vector, t);
356 }
357
358 /* Perform output tasks whenever we reach a timer tick: */
359
360 if (t >= relax * timer_cycle * timer_granularity_) {
361 if (enable_compute_error_) {
362 /*
363 * FIXME: We interpolate the analytic solution at every timer
364 * tick. If we happen to actually not output anything then this
365 * is terribly inefficient...
366 */
367
368 StateVector analytic;
369 {
370 Scope scope(computing_timer_,
371 "time step [X] - interpolate analytic solution");
372 Vectors::reinit_state_vector<Description>(analytic, offline_data_);
373 std::get<0>(analytic) =
374 initial_values_.get().interpolate_hyperbolic_vector(t);
375 }
376
377 output(analytic,
378 base_name_ensemble_ + "-analytic_solution",
379 t,
380 timer_cycle);
381 }
382
383 output(state_vector, base_name_ensemble_ + "-solution", t, timer_cycle);
384
385 if (enable_compute_quantities_ &&
386 (timer_cycle % timer_compute_quantities_multiplier_ == 0)) {
387 Scope scope(computing_timer_,
388 "time step [X] - write out quantities");
389 quantities_.write_out(state_vector, t, timer_cycle);
390 }
391
392 ++timer_cycle;
393 }
394
395 /* Break if we have reached the final time. */
396
397 if (t >= relax * t_final_)
398 break;
399
400 /* Peform a mesh adaptation cycle: */
401
402 if (enable_mesh_adaptivity_) {
403 {
404 Scope scope(computing_timer_,
405 "time step [X] - analyze for mesh adaptation");
406
407 mesh_adaptor_.analyze(state_vector, t, cycle);
408 }
409
410 if (mesh_adaptor_.need_mesh_adaptation()) {
411 Scope scope(computing_timer_, "(re)initialize data structures");
412 print_info("performing mesh adaptation");
413
414 adapt_mesh_and_transfer_state_vector(state_vector,
415 prepare_compute_kernels);
416
417 /* Prepare the state vector for time stepping. */
418 time_integrator_.prepare_state_vector(state_vector, t);
419 }
420 }
421
422 /* Perform a time step: */
423
424 const auto tau = time_integrator_.step(
425 state_vector,
426 t,
427 enforce_t_final_
428 ? std::min(t_final_, timer_cycle * timer_granularity_)
429 : std::numeric_limits<Number>::max());
430
431 t += tau;
432
433 time_integrator_.prepare_state_vector(state_vector, t);
434
435 /* Synchronize wall time: */
436
437 auto wall_time = computing_timer_["time loop"].wall_time();
438 {
439 Scope scope(computing_timer_,
440 "time step [X] _ - synchronization barriers");
441 wall_time =
442 Utilities::MPI::max(wall_time, mpi_ensemble_.world_communicator());
443 }
444
445 /* Print and record cycle statistics: */
446
447 const bool write_to_log_file =
448 (terminal_update_interval_ != Number(0.)) && /* suppress output */
449 (t >= relax * timer_cycle * timer_granularity_);
450
451 const bool update_terminal =
452 (wall_time >= last_terminal_output + terminal_update_interval_);
453
454 if (write_to_log_file || update_terminal) {
455 Scope scope(computing_timer_,
456 "time step [X] _ - synchronization barriers");
457 print_cycle_statistics(cycle,
458 t,
459 timer_cycle,
460 last_checkpoint,
461 /*logfile*/ write_to_log_file);
462 last_terminal_output = wall_time;
463 }
464
465 const bool update_checkpoint =
466 (wall_time >= last_checkpoint + checkpoint_update_interval_);
467
468 if (update_checkpoint) {
469 Scope scop(computing_timer_, "time step [X] - perform checkpointing");
470
471 print_info("scheduling checkpointing");
472 write_checkpoint(state_vector, base_name_ensemble_, t, timer_cycle);
473 last_checkpoint = wall_time;
474 }
475 } /* end of loop */
476
477 /* We have actually performed one cycle less. */
478 --cycle;
479
480 if (checkpoint_update_interval_ != Number(0.)) {
481 Scope scope(computing_timer_, "time step [X] - perform checkpointing");
482
483 print_info("scheduling checkpointing");
484 write_checkpoint(state_vector, base_name_ensemble_, t, timer_cycle);
485 }
486
487 computing_timer_["time loop"].stop();
488
489 if (terminal_update_interval_ != Number(0.)) {
490 /* Write final timing statistics to screen and logfile: */
491 print_cycle_statistics(cycle,
492 t,
493 timer_cycle,
494 last_checkpoint,
495 /*logfile*/ true,
496 /*final*/ true);
497 }
498
499 if (enable_compute_error_) {
500 /* Output final error: */
501 compute_error(state_vector, t);
502 }
503
504 if (mpi_ensemble_.world_rank() == 0 && debug_filename_ != "") {
505 std::ifstream f(debug_filename_);
506 if (f.is_open())
507 std::cout << f.rdbuf();
508 }
509
510#ifdef WITH_VALGRIND
511 CALLGRIND_DUMP_STATS;
512#endif
513 }
514
515
516 /*
517 * ---------------------------------------------------------------------------
518 * Checkpointing, VTK output, and compute error:
519 * ---------------------------------------------------------------------------
520 */
521
522
523 template <typename Description, int dim, typename Number>
524 template <typename Callable>
526 StateVector &state_vector,
527 const std::string &base_name,
528 Number &t,
529 unsigned int &timer_cycle,
530 const Callable &prepare_compute_kernels)
531 {
532#ifdef DEBUG_OUTPUT
533 std::cout << "TimeLoop<dim, Number>::read_checkpoint()" << std::endl;
534#endif
535
536 /*
537 * Initialize discretization, read in the mesh, and initialize everything:
538 */
539
540#if DEAL_II_VERSION_GTE(9, 6, 0)
541 discretization_.refinement() = 0; /* do not refine */
542 discretization_.prepare(base_name);
543 discretization_.triangulation().load(base_name + "-checkpoint.mesh");
544
545#else
546 AssertThrow(false,
547 dealii::ExcMessage("write_checkpoint() is not available with "
548 "deal.II versions prior to 9.6.0"));
549#endif
550
551 prepare_compute_kernels();
552
553 /*
554 * Read in and broadcast metadata:
555 */
556
557 std::string name = base_name + "-checkpoint";
558
559 unsigned int transfer_handle;
560 if (mpi_ensemble_.ensemble_rank() == 0) {
561 std::string meta = name + ".metadata";
562
563 std::ifstream file(meta, std::ios::binary);
564 boost::archive::binary_iarchive ia(file);
565 ia >> t >> timer_cycle >> transfer_handle;
566 }
567
568 int ierr;
569 if constexpr (std::is_same_v<Number, double>)
570 ierr = MPI_Bcast(
571 &t, 1, MPI_DOUBLE, 0, mpi_ensemble_.ensemble_communicator());
572 else
573 ierr =
574 MPI_Bcast(&t, 1, MPI_FLOAT, 0, mpi_ensemble_.ensemble_communicator());
575 AssertThrowMPI(ierr);
576
577 ierr = MPI_Bcast(&timer_cycle,
578 1,
579 MPI_UNSIGNED,
580 0,
581 mpi_ensemble_.ensemble_communicator());
582 AssertThrowMPI(ierr);
583
584 ierr = MPI_Bcast(&transfer_handle,
585 1,
586 MPI_UNSIGNED,
587 0,
588 mpi_ensemble_.ensemble_communicator());
589 AssertThrowMPI(ierr);
590
591 /* Now read in the state vector: */
592
593 Vectors::reinit_state_vector<Description>(state_vector, offline_data_);
594
595 solution_transfer_.set_handle(transfer_handle);
596 solution_transfer_.project(state_vector);
597 solution_transfer_.reset_handle();
598
599 /*
600 * Poison constrained degrees of freedom and prepare the state vector
601 * for time stepping:
602 */
603
604 Vectors::debug_poison_constrained_dofs<Description>(state_vector,
605 offline_data_);
606
607 Vectors::debug_poison_precomputed_values<Description>(state_vector,
608 offline_data_);
609 time_integrator_.prepare_state_vector(state_vector, t);
610 }
611
612
613 template <typename Description, int dim, typename Number>
615 const StateVector &state_vector,
616 const std::string &base_name,
617 const Number &t,
618 const unsigned int &timer_cycle)
619 {
620#ifdef DEBUG_OUTPUT
621 std::cout << "TimeLoop<dim, Number>::write_checkpoint()" << std::endl;
622#endif
623
624 solution_transfer_.prepare_projection(state_vector);
625 const auto transfer_handle = solution_transfer_.get_handle();
626 solution_transfer_.reset_handle();
627
628 std::string name = base_name + "-checkpoint";
629
630 if (mpi_ensemble_.ensemble_rank() == 0) {
631 for (const std::string suffix :
632 {".mesh", ".mesh_fixed.data", ".mesh.info", ".metadata"})
633 if (std::filesystem::exists(name + suffix))
634 std::filesystem::rename(name + suffix, name + suffix + "~");
635 }
636
637#if DEAL_II_VERSION_GTE(9, 6, 0)
638 const auto &triangulation = discretization_.triangulation();
639 triangulation.save(name + ".mesh");
640
641#else
642 AssertThrow(false,
643 dealii::ExcMessage("write_checkpoint() is not available with "
644 "deal.II versions prior to 9.6.0"));
645#endif
646
647 /*
648 * Now, write out metadata on rank 0:
649 */
650
651 if (mpi_ensemble_.ensemble_rank() == 0) {
652 std::string meta = name + ".metadata";
653 std::ofstream file(meta, std::ios::binary | std::ios::trunc);
654 boost::archive::binary_oarchive oa(file);
655 oa << t << timer_cycle << transfer_handle;
656 }
657
658 const int ierr = MPI_Barrier(mpi_ensemble_.ensemble_communicator());
659 AssertThrowMPI(ierr);
660 }
661
662
663 template <typename Description, int dim, typename Number>
664 template <typename Callable>
666 StateVector &state_vector, const Callable &prepare_compute_kernels)
667 {
668#ifdef DEBUG_OUTPUT
669 std::cout << "TimeLoop<dim, Number>::adapt_mesh_and_transfer_state_vector()"
670 << std::endl;
671#endif
672
673 AssertThrow(mpi_ensemble_.n_ensembles() == 1, dealii::ExcNotImplemented());
674
675 /*
676 * Mark cells for coarsening and refinement and set up triangulation:
677 */
678
679 auto &triangulation = discretization_.triangulation();
680 mesh_adaptor_.mark_cells_for_coarsening_and_refinement(triangulation);
681
682 triangulation.prepare_coarsening_and_refinement();
683
684 solution_transfer_.prepare_projection(state_vector);
685
686 /* Execute mesh adaptation and project old state to new state vector: */
687
688 triangulation.execute_coarsening_and_refinement();
689 prepare_compute_kernels();
690
691 Vectors::reinit_state_vector<Description>(state_vector, offline_data_);
692 solution_transfer_.project(state_vector);
693 solution_transfer_.reset_handle();
694
695 /*
696 * In debug mode poison constrained degrees of freedom and precomputed
697 * values:
698 */
699 Vectors::debug_poison_constrained_dofs<Description>(state_vector,
700 offline_data_);
701 Vectors::debug_poison_precomputed_values<Description>(state_vector,
702 offline_data_);
703 }
704
705
706 template <typename Description, int dim, typename Number>
707 void
709 const Number t)
710 {
711#ifdef DEBUG_OUTPUT
712 std::cout << "TimeLoop<dim, Number>::compute_error()" << std::endl;
713#endif
714
715 Vector<Number> difference_per_cell(
716 discretization_.triangulation().n_active_cells());
717
718 Number linf_norm = 0.;
719 Number l1_norm = 0;
720 Number l2_norm = 0;
721
722 const auto analytic_U =
723 initial_values_.get().interpolate_hyperbolic_vector(t);
724 const auto &U = std::get<0>(state_vector);
725
726 ScalarVector analytic_component;
727 ScalarVector error_component;
728 analytic_component.reinit(offline_data_.scalar_partitioner());
729 error_component.reinit(offline_data_.scalar_partitioner());
730
731 /* Loop over all selected components: */
732 for (const auto &entry : error_quantities_) {
733 const auto &names = View::component_names;
734 const auto pos = std::find(std::begin(names), std::end(names), entry);
735 if (pos == std::end(names)) {
736 AssertThrow(
737 false,
738 dealii::ExcMessage("Unknown component name »" + entry + "«"));
739 __builtin_trap();
740 }
741
742 const auto index = std::distance(std::begin(names), pos);
743
744 analytic_U.extract_component(analytic_component, index);
745
746 /* Compute norms of analytic solution: */
747
748 Number linf_norm_analytic = 0.;
749 Number l1_norm_analytic = 0.;
750 Number l2_norm_analytic = 0.;
751
752 if (error_normalize_) {
753 linf_norm_analytic =
754 Utilities::MPI::max(analytic_component.linfty_norm(),
755 mpi_ensemble_.ensemble_communicator());
756
757 VectorTools::integrate_difference(
758 discretization_.mapping(),
759 offline_data_.dof_handler(),
760 analytic_component,
761 Functions::ZeroFunction<dim, Number>(),
762 difference_per_cell,
763 discretization_.quadrature_high_order(),
764 VectorTools::L1_norm);
765
766 l1_norm_analytic =
767 Utilities::MPI::sum(difference_per_cell.l1_norm(),
768 mpi_ensemble_.ensemble_communicator());
769
770 VectorTools::integrate_difference(
771 discretization_.mapping(),
772 offline_data_.dof_handler(),
773 analytic_component,
774 Functions::ZeroFunction<dim, Number>(),
775 difference_per_cell,
776 discretization_.quadrature_high_order(),
777 VectorTools::L2_norm);
778
779 l2_norm_analytic = Number(std::sqrt(
780 Utilities::MPI::sum(std::pow(difference_per_cell.l2_norm(), 2),
781 mpi_ensemble_.ensemble_communicator())));
782 }
783
784 /* Compute norms of error: */
785
786 U.extract_component(error_component, index);
787 /* Populate constrained dofs due to periodicity: */
788 offline_data_.affine_constraints().distribute(error_component);
789 error_component.update_ghost_values();
790 error_component -= analytic_component;
791
792 const Number linf_norm_error = Utilities::MPI::max(
793 error_component.linfty_norm(), mpi_ensemble_.ensemble_communicator());
794
795 VectorTools::integrate_difference(discretization_.mapping(),
796 offline_data_.dof_handler(),
797 error_component,
798 Functions::ZeroFunction<dim, Number>(),
799 difference_per_cell,
800 discretization_.quadrature_high_order(),
801 VectorTools::L1_norm);
802
803 const Number l1_norm_error = Utilities::MPI::sum(
804 difference_per_cell.l1_norm(), mpi_ensemble_.ensemble_communicator());
805
806 VectorTools::integrate_difference(discretization_.mapping(),
807 offline_data_.dof_handler(),
808 error_component,
809 Functions::ZeroFunction<dim, Number>(),
810 difference_per_cell,
811 discretization_.quadrature_high_order(),
812 VectorTools::L2_norm);
813
814 const Number l2_norm_error = Number(std::sqrt(
815 Utilities::MPI::sum(std::pow(difference_per_cell.l2_norm(), 2),
816 mpi_ensemble_.ensemble_communicator())));
817
818 if (error_normalize_) {
819 linf_norm += linf_norm_error / linf_norm_analytic;
820 l1_norm += l1_norm_error / l1_norm_analytic;
821 l2_norm += l2_norm_error / l2_norm_analytic;
822 } else {
823 linf_norm += linf_norm_error;
824 l1_norm += l1_norm_error;
825 l2_norm += l2_norm_error;
826 }
827 }
828
829 if (mpi_ensemble_.ensemble_rank() != 0)
830 return;
831
832 /*
833 * Sum up over all participating MPI ranks. Note: we only perform this
834 * operation on "peer" ranks zero:
835 */
836
837 if (mpi_ensemble_.n_ensembles() > 1) {
838 linf_norm = Utilities::MPI::sum(
839 linf_norm, mpi_ensemble_.ensemble_leader_communicator());
840 l1_norm = Utilities::MPI::sum(
841 l1_norm, mpi_ensemble_.ensemble_leader_communicator());
842 l2_norm = Utilities::MPI::sum(
843 l2_norm, mpi_ensemble_.ensemble_leader_communicator());
844 }
845
846 if (mpi_ensemble_.world_rank() != 0)
847 return;
848
849 logfile_ << std::endl << "Computed errors:" << std::endl << std::endl;
850 logfile_ << std::setprecision(16);
851
852 std::string description =
853 error_normalize_ ? "Normalized consolidated" : "Consolidated";
854
855 logfile_ << description + " Linf, L1, and L2 errors at final time \n";
856 logfile_ << std::setprecision(16);
857 logfile_ << "#dofs = " << n_global_dofs_ << std::endl;
858 logfile_ << "t = " << t << std::endl;
859 logfile_ << "Linf = " << linf_norm << std::endl;
860 logfile_ << "L1 = " << l1_norm << std::endl;
861 logfile_ << "L2 = " << l2_norm << std::endl;
862
863 std::cout << description + " Linf, L1, and L2 errors at final time \n";
864 std::cout << std::setprecision(16);
865 std::cout << "#dofs = " << n_global_dofs_ << std::endl;
866 std::cout << "t = " << t << std::endl;
867 std::cout << "Linf = " << linf_norm << std::endl;
868 std::cout << "L1 = " << l1_norm << std::endl;
869 std::cout << "L2 = " << l2_norm << std::endl;
870 }
871
872
873 template <typename Description, int dim, typename Number>
875 const std::string &name,
876 const Number t,
877 const unsigned int cycle)
878 {
879#ifdef DEBUG_OUTPUT
880 std::cout << "TimeLoop<dim, Number>::output(t = " << t << ")" << std::endl;
881#endif
882
883 const bool do_full_output =
884 (cycle % timer_output_full_multiplier_ == 0) && enable_output_full_;
885 const bool do_levelsets =
886 (cycle % timer_output_levelsets_multiplier_ == 0) &&
887 enable_output_levelsets_;
888
889 /* There is nothing to do: */
890 if (!(do_full_output || do_levelsets))
891 return;
892
893 /* Data output: */
894
895 Scope scope(computing_timer_, "time step [X] - perform vtu output");
896 print_info("scheduling output");
897
898 postprocessor_.compute(state_vector);
899 /*
900 * Workaround: Manually reset bounds during the first output cycle
901 * (which is often just a uniform flow field) to obtain a better
902 * normailization:
903 */
904 if (cycle == 0)
905 postprocessor_.reset_bounds();
906
907 vtu_output_.schedule_output(
908 state_vector, name, t, cycle, do_full_output, do_levelsets);
909 }
910
911
912 /*
913 * ---------------------------------------------------------------------------
914 * Output and logging related functions:
915 * ---------------------------------------------------------------------------
916 */
917
918
919 template <typename Description, int dim, typename Number>
920 void
922 {
923 if (mpi_ensemble_.world_rank() != 0)
924 return;
925
926 /* Output commit and library information: */
927
929
930 /* Print run time parameters: */
931
932 stream << std::endl << "Run time parameters:" << std::endl << std::endl;
933 ParameterAcceptor::prm.print_parameters(
934 stream, ParameterHandler::OutputStyle::ShortPRM);
935 stream << std::endl;
936
937 /* Also print out parameters to a prm file: */
938
939 std::ofstream output(base_name_ + "-parameters.prm");
940 ParameterAcceptor::prm.print_parameters(output, ParameterHandler::ShortPRM);
941 }
942
943
944 template <typename Description, int dim, typename Number>
945 void
947 {
948 /*
949 * Fixme: this conversion to double is really not elegant. We should
950 * improve the Utilities::MPI::min_max_avg function in deal.II to
951 * handle different data types
952 */
953
954 // NOLINTBEGIN
955 std::vector<double> values = {
956 (double)offline_data_.n_export_indices(),
957 (double)offline_data_.n_locally_internal(),
958 (double)offline_data_.n_locally_owned(),
959 (double)offline_data_.n_locally_relevant(),
960 (double)offline_data_.n_export_indices() /
961 (double)offline_data_.n_locally_relevant(),
962 (double)offline_data_.n_locally_internal() /
963 (double)offline_data_.n_locally_relevant(),
964 (double)offline_data_.n_locally_owned() /
965 (double)offline_data_.n_locally_relevant()};
966 // NOLINTEND
967
968 const auto data =
969 Utilities::MPI::min_max_avg(values, mpi_ensemble_.world_communicator());
970
971 if (mpi_ensemble_.world_rank() != 0)
972 return;
973
974 std::ostringstream output;
975
976 unsigned int n =
977 dealii::Utilities::needed_digits(mpi_ensemble_.n_world_ranks());
978
979 const auto print_snippet = [&output, n](const std::string &name,
980 const auto &values) {
981 output << name << ": ";
982 // NOLINTBEGIN
983 output << std::setw(9) << (unsigned int)values.min //
984 << " [p" << std::setw(n) << values.min_index << "] " //
985 << std::setw(9) << (unsigned int)values.avg << " " //
986 << std::setw(9) << (unsigned int)values.max //
987 << " [p" << std::setw(n) << values.max_index << "]"; //
988 // NOLINTEND
989 };
990
991 const auto print_percentages = [&output, n](const auto &percentages) {
992 output << std::endl << " ";
993 output << " (" << std::setw(3) << std::setprecision(2)
994 << percentages.min * 100 << "% )"
995 << " [p" << std::setw(n) << percentages.min_index << "] "
996 << " (" << std::setw(3) << std::setprecision(2)
997 << percentages.avg * 100 << "% )"
998 << " "
999 << " (" << std::setw(3) << std::setprecision(2)
1000 << percentages.max * 100 << "% )"
1001 << " [p" << std::setw(n) << percentages.max_index << "]";
1002 };
1003
1004 output << std::endl << std::endl << "Partition: ";
1005 print_snippet("exp", data[0]);
1006 print_percentages(data[4]);
1007
1008 output << std::endl << " ";
1009 print_snippet("int", data[1]);
1010 print_percentages(data[5]);
1011
1012 output << std::endl << " ";
1013 print_snippet("own", data[2]);
1014 print_percentages(data[6]);
1015
1016 output << std::endl << " ";
1017 print_snippet("rel", data[3]);
1018
1019 stream << output.str() << std::endl;
1020 }
1021
1022
1023 template <typename Description, int dim, typename Number>
1025 {
1026 if (mpi_ensemble_.world_rank() != 0)
1027 return;
1028
1029 std::cout << "[INFO] " << header << std::endl;
1030 }
1031
1032
1033 template <typename Description, int dim, typename Number>
1034 void
1036 const std::string &secondary,
1037 std::ostream &stream)
1038 {
1039 if (mpi_ensemble_.world_rank() != 0)
1040 return;
1041
1042 const int header_size = header.size();
1043 const auto padded_header =
1044 std::string(std::max(0, 34 - header_size) / 2, ' ') + header +
1045 std::string(std::max(0, 35 - header_size) / 2, ' ');
1046
1047 const int secondary_size = secondary.size();
1048 const auto padded_secondary =
1049 std::string(std::max(0, 34 - secondary_size) / 2, ' ') + secondary +
1050 std::string(std::max(0, 35 - secondary_size) / 2, ' ');
1051
1052 /* clang-format off */
1053 stream << "\n";
1054 stream << " ####################################################\n";
1055 stream << " #########" << padded_header << "#########\n";
1056 stream << " #########" << padded_secondary << "#########\n";
1057 stream << " ####################################################\n";
1058 stream << std::endl;
1059 /* clang-format on */
1060 }
1061
1062
1063 template <typename Description, int dim, typename Number>
1065 unsigned int timer_cycle,
1066 Number last_checkpoint,
1067 std::ostream &stream,
1068 bool final_time)
1069 {
1070 static const std::string vectorization_name = [] {
1071 constexpr auto width = VectorizedArray<Number>::size();
1072
1073 std::string result;
1074 if (width == 1)
1075 result = "scalar ";
1076 else
1077 result = std::to_string(width * 8 * sizeof(Number)) + " bit packed ";
1078
1079 if constexpr (std::is_same_v<Number, double>)
1080 return result + "double";
1081 else if constexpr (std::is_same_v<Number, float>)
1082 return result + "float";
1083 else
1084 __builtin_trap();
1085 }();
1086
1087 stream << "Information: (HYP) " << hyperbolic_system_.get().problem_name;
1088 if constexpr (!ParabolicSystem::is_identity) {
1089 stream << "\n (PAR) " << parabolic_system_.get().problem_name;
1090 }
1091 stream << "\n [" << base_name_ << "] ";
1092 if (mpi_ensemble_.n_ensembles() > 1) {
1093 stream << mpi_ensemble_.n_ensembles() << " ensembles ";
1094 }
1095 stream << "with " //
1096 << n_global_dofs_ << " Qdofs on " //
1097 << mpi_ensemble_.n_world_ranks() << " ranks / " //
1098#ifdef WITH_OPENMP
1099 << MultithreadInfo::n_threads() << " threads <" //
1100#else
1101 << "[openmp disabled] <" //
1102#endif
1103 << vectorization_name << ">\n";
1104
1105 stream << " Last output cycle " //
1106 << timer_cycle - 1 //
1107 << " at t = " << timer_granularity_ * (timer_cycle - 1) //
1108 << " [ log ";
1109
1110 if (enable_output_full_)
1111 stream << "full ";
1112 if (enable_output_levelsets_)
1113 stream << "levelsets ";
1114 if (enable_compute_quantities_)
1115 stream << "quantities ";
1116
1117 stream << "]\n";
1118
1119 if (checkpoint_update_interval_ != Number(0.)) {
1120 const auto wall_time =
1121 Utilities::MPI::min_max_avg(computing_timer_["time loop"].wall_time(),
1122 mpi_ensemble_.world_communicator());
1123
1124 if (final_time) {
1125 stream << " Last checkpoint at FINAL TIME\n";
1126 } else {
1127 stream << " Last checkpoint at wall time " //
1128 << std::setprecision(2) << std::fixed << last_checkpoint //
1129 << "s (" << std::setprecision(0)
1130 << std::max(0., wall_time.max - last_checkpoint)
1131 << "s ago, interval " << checkpoint_update_interval_ << "s)\n";
1132 }
1133 }
1134 }
1135
1136
1137 template <typename Description, int dim, typename Number>
1139 std::ostream &stream)
1140 {
1141 Utilities::System::MemoryStats stats;
1142 Utilities::System::get_memory_stats(stats);
1143
1144 Utilities::MPI::MinMaxAvg data = Utilities::MPI::min_max_avg(
1145 stats.VmRSS / 1024., mpi_ensemble_.world_communicator());
1146
1147 if (mpi_ensemble_.world_rank() != 0)
1148 return;
1149
1150 std::ostringstream output;
1151
1152 unsigned int n =
1153 dealii::Utilities::needed_digits(mpi_ensemble_.n_world_ranks());
1154
1155 output << "\nMemory: [MiB]" //
1156 << std::setw(8) << data.min //
1157 << " [p" << std::setw(n) << data.min_index << "] " //
1158 << std::setw(8) << data.avg << " " //
1159 << std::setw(8) << data.max //
1160 << " [p" << std::setw(n) << data.max_index << "]"; //
1161
1162 stream << output.str() << std::endl;
1163 }
1164
1165
1166 template <typename Description, int dim, typename Number>
1168 {
1169 std::vector<std::ostringstream> output(computing_timer_.size());
1170
1171 const auto equalize = [&]() {
1172 const auto ptr =
1173 std::max_element(output.begin(),
1174 output.end(),
1175 [](const auto &left, const auto &right) {
1176 return left.str().length() < right.str().length();
1177 });
1178 const auto length = ptr->str().length();
1179 for (auto &it : output)
1180 it << std::string(length - it.str().length() + 1, ' ');
1181 };
1182
1183 const auto print_wall_time = [&](auto &timer, auto &stream) {
1184 const auto wall_time = Utilities::MPI::min_max_avg(
1185 timer.wall_time(), mpi_ensemble_.world_communicator());
1186
1187 constexpr auto eps = std::numeric_limits<double>::epsilon();
1188 /*
1189 * Cut off at 99.9% to avoid silly percentages cluttering up the
1190 * output.
1191 */
1192 const auto skew_negative = std::max(
1193 100. * (wall_time.min - wall_time.avg) / wall_time.avg - eps, -99.9);
1194 const auto skew_positive = std::min(
1195 100. * (wall_time.max - wall_time.avg) / wall_time.avg + eps, 99.9);
1196
1197 stream << std::setprecision(2) << std::fixed << std::setw(9)
1198 << wall_time.avg << "s [sk: " << std::setprecision(1)
1199 << std::setw(5) << std::fixed << skew_negative << "%/"
1200 << std::setw(4) << std::fixed << skew_positive << "%]";
1201 unsigned int n =
1202 dealii::Utilities::needed_digits(mpi_ensemble_.n_world_ranks());
1203 stream << " [p" << std::setw(n) << wall_time.min_index << "/"
1204 << wall_time.max_index << "]";
1205 };
1206
1207 const auto cpu_time_statistics =
1208 Utilities::MPI::min_max_avg(computing_timer_["time loop"].cpu_time(),
1209 mpi_ensemble_.world_communicator());
1210 const double total_cpu_time = cpu_time_statistics.sum;
1211
1212 const auto print_cpu_time =
1213 [&](auto &timer, auto &stream, bool percentage) {
1214 const auto cpu_time = Utilities::MPI::min_max_avg(
1215 timer.cpu_time(), mpi_ensemble_.world_communicator());
1216
1217 stream << std::setprecision(2) << std::fixed << std::setw(12)
1218 << cpu_time.sum << "s ";
1219
1220 if (percentage)
1221 stream << "(" << std::setprecision(1) << std::setw(4)
1222 << 100. * cpu_time.sum / total_cpu_time << "%)";
1223 };
1224
1225 auto jt = output.begin();
1226 for (auto &it : computing_timer_)
1227 *jt++ << " " << it.first;
1228 equalize();
1229
1230 jt = output.begin();
1231 for (auto &it : computing_timer_)
1232 print_wall_time(it.second, *jt++);
1233 equalize();
1234
1235 jt = output.begin();
1236 bool compute_percentages = false;
1237 for (auto &it : computing_timer_) {
1238 print_cpu_time(it.second, *jt++, compute_percentages);
1239 if (it.first.starts_with("time loop"))
1240 compute_percentages = true;
1241 }
1242 equalize();
1243
1244 if (mpi_ensemble_.world_rank() != 0)
1245 return;
1246
1247 stream << std::endl << "Timer statistics:\n";
1248 for (auto &it : output)
1249 stream << it.str() << std::endl;
1250 }
1251
1252
1253 template <typename Description, int dim, typename Number>
1255 unsigned int cycle, Number t, std::ostream &stream, bool final_time)
1256 {
1257 /*
1258 * Fixme: The global state kept in this function should be refactored
1259 * into its own class object.
1260 */
1261 static struct Data {
1262 unsigned int cycle = 0;
1263 double t = 0.;
1264 double cpu_time_sum = 0.;
1265 double cpu_time_avg = 0.;
1266 double cpu_time_min = 0.;
1267 double cpu_time_max = 0.;
1268 double wall_time = 0.;
1269 } previous, current;
1270
1271 static double time_per_second_exp = 0.;
1272
1273 /* Update statistics: */
1274
1275 {
1276 previous = current;
1277
1278 current.cycle = cycle;
1279 current.t = t;
1280
1281 const auto wall_time_statistics =
1282 Utilities::MPI::min_max_avg(computing_timer_["time loop"].wall_time(),
1283 mpi_ensemble_.world_communicator());
1284 current.wall_time = wall_time_statistics.max;
1285
1286 const auto cpu_time_statistics =
1287 Utilities::MPI::min_max_avg(computing_timer_["time loop"].cpu_time(),
1288 mpi_ensemble_.world_communicator());
1289 current.cpu_time_sum = cpu_time_statistics.sum;
1290 current.cpu_time_avg = cpu_time_statistics.avg;
1291 current.cpu_time_min = cpu_time_statistics.min;
1292 current.cpu_time_max = cpu_time_statistics.max;
1293 }
1294
1295 if (final_time)
1296 previous = Data();
1297
1298 /* Take averages: */
1299
1300 double delta_cycles = current.cycle - previous.cycle;
1301 const double cycles_per_second =
1302 delta_cycles / (current.wall_time - previous.wall_time);
1303
1304 const auto efficiency = time_integrator_.efficiency();
1305 const auto n_dofs = static_cast<double>(n_global_dofs_);
1306
1307 const double wall_m_dofs_per_sec =
1308 delta_cycles * n_dofs / 1.e6 /
1309 (current.wall_time - previous.wall_time) * efficiency;
1310
1311 double cpu_m_dofs_per_sec = delta_cycles * n_dofs / 1.e6 /
1312 (current.cpu_time_sum - previous.cpu_time_sum) *
1313 efficiency;
1314#ifdef WITH_OPENMP
1315 if (terminal_show_rank_throughput_)
1316 cpu_m_dofs_per_sec *= MultithreadInfo::n_threads();
1317#endif
1318
1319 double cpu_time_skew = (current.cpu_time_max - current.cpu_time_min - //
1320 previous.cpu_time_max + previous.cpu_time_min) /
1321 delta_cycles;
1322 /* avoid printing small negative numbers: */
1323 cpu_time_skew = std::max(0., cpu_time_skew);
1324
1325 const double cpu_time_skew_percentage =
1326 cpu_time_skew * delta_cycles /
1327 (current.cpu_time_avg - previous.cpu_time_avg);
1328
1329 const double delta_time =
1330 (current.t - previous.t) / (current.cycle - previous.cycle);
1331 const double time_per_second =
1332 (current.t - previous.t) / (current.wall_time - previous.wall_time);
1333
1334 /* Print Jean-Luc and Martin metrics: */
1335
1336 std::ostringstream output;
1337
1338 /* clang-format off */
1339 output << std::endl;
1340
1341 output << "Throughput:\n "
1342 << (terminal_show_rank_throughput_? "RANK: " : "CPU : ")
1343 << std::setprecision(4) << std::fixed << cpu_m_dofs_per_sec
1344 << " MQ/s ("
1345 << std::scientific << 1. / cpu_m_dofs_per_sec * 1.e-6
1346 << " s/Qdof/substep)" << std::endl;
1347
1348 output << " [cpu time skew: "
1349 << std::setprecision(2) << std::scientific << cpu_time_skew
1350 << "s/cycle ("
1351 << std::setprecision(1) << std::setw(4) << std::setfill(' ') << std::fixed
1352 << 100. * cpu_time_skew_percentage
1353 << "%)]" << std::endl;
1354
1355 output << " WALL: "
1356 << std::setprecision(4) << std::fixed << wall_m_dofs_per_sec
1357 << " MQ/s ("
1358 << std::scientific << 1. / wall_m_dofs_per_sec * 1.e-6
1359 << " s/Qdof/substep) ("
1360 << std::setprecision(2) << std::fixed << cycles_per_second
1361 << " cycles/s)" << std::endl;
1362
1363 const auto &scheme = time_integrator_.time_stepping_scheme();
1364 output << " [ "
1365 << Patterns::Tools::Convert<TimeSteppingScheme>::to_string(scheme)
1366 << " with CFL = "
1367 << std::setprecision(2) << std::fixed << hyperbolic_module_.cfl()
1368 << " ("
1369 << std::setprecision(0) << std::fixed << hyperbolic_module_.n_restarts()
1370 << "/"
1371 << std::setprecision(0) << std::fixed << parabolic_module_.n_restarts()
1372 << " rsts) ("
1373 << std::setprecision(0) << std::fixed << hyperbolic_module_.n_warnings()
1374 << "/"
1375 << std::setprecision(0) << std::fixed << parabolic_module_.n_warnings()
1376 << " warn) ("
1377 << std::setprecision(0) << std::fixed << hyperbolic_module_.n_corrections()
1378 << "/"
1379 << std::setprecision(0) << std::fixed << parabolic_module_.n_corrections()
1380 << " corr) ]" << std::endl;
1381
1382 if constexpr (!ParabolicSystem::is_identity)
1383 parabolic_module_.print_solver_statistics(output);
1384
1385 output << " [ dt = "
1386 << std::scientific << std::setprecision(2) << delta_time
1387 << " ( "
1388 << time_per_second
1389 << " dt/s) ]" << std::endl;
1390 /* clang-format on */
1391
1392 /* And print an ETA: */
1393
1394 time_per_second_exp = 0.8 * time_per_second_exp + 0.2 * time_per_second;
1395 auto eta = static_cast<unsigned int>(std::max(t_final_ - t, Number(0.)) /
1396 time_per_second_exp);
1397
1398 output << "\n ETA : ";
1399
1400 const unsigned int days = eta / (24 * 3600);
1401 if (days > 0) {
1402 output << days << " d ";
1403 eta %= 24 * 3600;
1404 }
1405
1406 const unsigned int hours = eta / 3600;
1407 if (hours > 0) {
1408 output << hours << " h ";
1409 eta %= 3600;
1410 }
1411
1412 const unsigned int minutes = eta / 60;
1413 output << minutes << " min";
1414
1415 output << " (terminal update every " //
1416 << std::setprecision(2) << std::fixed << terminal_update_interval_
1417 << "s)";
1418
1419 if (mpi_ensemble_.world_rank() != 0)
1420 return;
1421
1422 stream << output.str() << std::endl;
1423 }
1424
1425
1426 template <typename Description, int dim, typename Number>
1428 unsigned int cycle,
1429 Number t,
1430 unsigned int timer_cycle,
1431 Number last_checkpoint,
1432 bool write_to_logfile,
1433 bool final_time)
1434 {
1435 std::ostringstream output;
1436
1437 /* Print header: */
1438
1439 std::ostringstream primary;
1440 if (final_time) {
1441 primary << "FINAL (cycle " << Utilities::int_to_string(cycle, 6) << ")";
1442 } else {
1443 primary << "Cycle " << Utilities::int_to_string(cycle, 6) //
1444 << " (" << std::fixed << std::setprecision(1) //
1445 << t / t_final_ * 100 << "%)";
1446 }
1447
1448 std::ostringstream secondary;
1449 secondary << "at time t = " << std::setprecision(8) << std::fixed << t;
1450
1451 print_head(primary.str(), secondary.str(), output);
1452
1453 /* Print information and statistics: */
1454
1455 print_information(timer_cycle, last_checkpoint, output, final_time);
1456 print_memory_statistics(output);
1457 print_timers(output);
1458 print_throughput(cycle, t, output, final_time);
1459
1460 /* Only output on rank 0: */
1461 if (mpi_ensemble_.world_rank() != 0)
1462 return;
1463
1464#ifndef DEBUG_OUTPUT
1465 std::cout << "\033[2J\033[H";
1466#endif
1467 std::cout << output.str() << std::flush;
1468
1469 if (write_to_logfile) {
1470 logfile_ << "\n" << output.str() << std::flush;
1471 }
1472 }
1473} // 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:63
void print_timers(std::ostream &stream)
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)
void print_cycle_statistics(unsigned int cycle, Number t, unsigned int output_cycle, Number last_checkpoint, bool write_to_logfile=false, bool final_time=false)
typename View::StateVector StateVector
Definition: time_loop.h:61
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)
void print_information(unsigned int output_cycle, Number last_checkpoint, std::ostream &stream, bool final_time=false)
void print_info(const std::string &header)
void adapt_mesh_and_transfer_state_vector(StateVector &state_vector, const Callable &prepare_compute_kernels)
T pow(const T x, const T b)
void print_revision_and_version(std::ostream &stream)