From 83e356322b952365d6434f054e9dd84ced7f5e86 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Thu, 11 Sep 2025 14:50:02 +0000 Subject: [PATCH 01/37] feat: use fmt - Now all print use fmt instead of std::cout. --- include/samurai/algorithm/graduation.hpp | 3 +- include/samurai/algorithm/update.hpp | 47 +++++-- include/samurai/arguments.hpp | 4 + include/samurai/bc/apply_field_bc.hpp | 3 +- .../samurai/bc/polynomial_extrapolation.hpp | 8 +- include/samurai/field.hpp | 6 +- include/samurai/level_cell_array.hpp | 28 ++-- include/samurai/memory.hpp | 3 +- include/samurai/mesh.hpp | 24 ++-- include/samurai/print.hpp | 126 ++++++++++++++++++ include/samurai/samurai.hpp | 4 +- include/samurai/stencil.hpp | 6 +- 12 files changed, 217 insertions(+), 45 deletions(-) create mode 100644 include/samurai/print.hpp diff --git a/include/samurai/algorithm/graduation.hpp b/include/samurai/algorithm/graduation.hpp index e15574ddf..8c5c8a79e 100644 --- a/include/samurai/algorithm/graduation.hpp +++ b/include/samurai/algorithm/graduation.hpp @@ -2,6 +2,7 @@ // SPDX-License-Identifier: BSD-3-Clause #pragma once +#include #include #include @@ -301,7 +302,7 @@ namespace samurai isIntersectionEmpty); break; default: - std::cerr << "Warning: Unsupported number of periodic directions (" << directions.size() << ")." << std::endl; + fmt::print(stderr, "Warning: Unsupported number of periodic directions ({}) .\n", directions.size()); } } } diff --git a/include/samurai/algorithm/update.hpp b/include/samurai/algorithm/update.hpp index 196e8fed5..c87fefbf3 100644 --- a/include/samurai/algorithm/update.hpp +++ b/include/samurai/algorithm/update.hpp @@ -2,6 +2,8 @@ // SPDX-License-Identifier: BSD-3-Clause #pragma once +#include +#include #include @@ -180,14 +182,22 @@ namespace samurai #ifdef SAMURAI_CHECK_NAN if (xt::any(xt::isnan(field(children_level, {ii_child, ii_child + 1}, index_child)))) { - std::cerr << std::endl; + fmt::print(stderr, "\n"); #ifdef SAMURAI_WITH_MPI mpi::communicator world; - std::cerr << "[" << world.rank() << "] "; + fmt::print(stderr, "[{}] ", world.rank()); #endif - std::cerr << "NaN found in field(" << children_level << "," << ii_child << "," << index_child - << ") during projection of the B.C. into the cell at (" << proj_level << ", " << ii << ", " - << index << ") (dir = " << direction << ", layer = " << layer << ")" << std::endl; + fmt::print( + stderr, + "NaN found in field({}, {}, {}) during projection of the B.C. into the cell at ({}, {}, {}) (dir = {}, layer = {})\n", + children_level, + ii_child, + fmt::streamed(index_child), + proj_level, + ii, + fmt::streamed(index), + fmt::streamed(direction), + layer); #ifndef NDEBUG save(fs::current_path(), "update_ghosts", {true, true}, mesh, field); #endif @@ -217,9 +227,15 @@ namespace samurai // However, it can happen in normal conditions if the domain has a hole, so we don't raise an error in that case. if (mesh.domain().is_box()) { - std::cerr << "No children found for the ghost at level " << proj_level << ", i = " << ii - << ", index = " << index << " during projection of the B.C. into the cell at level " << proj_level - << ", i=" << i_cell << ", index=" << index << std::endl; + fmt::print( + stderr, + "No children found for the ghost at level {}, i = {}, index = {} during projection of the B.C. into the cell at level {}, i = {}, index = {}\n", + proj_level, + ii, + fmt::streamed(index), + proj_level, + fmt::streamed(i_cell), + fmt::streamed(index)); save(fs::current_path(), "update_ghosts", {true, true}, mesh, field); assert(false); } @@ -322,14 +338,19 @@ namespace samurai #ifdef SAMURAI_CHECK_NAN if (xt::any(xt::isnan(field(pred_level - 1, i_cell >> 1, index >> 1)))) { - std::cerr << std::endl; + fmt::print(stderr, "\n"); #ifdef SAMURAI_WITH_MPI mpi::communicator world; - std::cerr << "[" << world.rank() << "] "; + fmt::print(stderr, "[{}] ", world.rank()); #endif - std::cerr << "NaN found in field(" << (pred_level - 1) << "," << (i_cell >> 1) << "," << (index >> 1) - << ") during prediction of the B.C. into the cell at (" << pred_level << ", " << ii << ", " << index - << ") " << std::endl; + fmt::print(stderr, + "NaN found in field({}, {}, {}) during prediction of the B.C. into the cell at ({}, {}, {})\n", + (pred_level - 1), + fmt::streamed(i_cell >> 1), + fmt::streamed(index >> 1), + pred_level, + ii, + fmt::streamed(index)); #ifndef NDEBUG samurai::save(fs::current_path(), "update_ghosts", {true, true}, field.mesh(), field); #endif diff --git a/include/samurai/arguments.hpp b/include/samurai/arguments.hpp index 0b00c62c3..4becb1948 100644 --- a/include/samurai/arguments.hpp +++ b/include/samurai/arguments.hpp @@ -11,6 +11,7 @@ namespace samurai static bool timers = false; #ifdef SAMURAI_WITH_MPI static bool dont_redirect_output = false; + static bool print_root_only = false; #endif static int finer_level_flux = 0; static bool refine_boundary = false; @@ -28,6 +29,9 @@ namespace samurai app.add_flag("--dont-redirect-output", args::dont_redirect_output, "Redirect the output for all ranks different of 0") ->capture_default_str() ->group("IO"); + app.add_flag("--print-root-only", args::print_root_only, "Print on root rank only by default for samurai::io::print/eprint") + ->capture_default_str() + ->group("IO"); #endif app.add_flag("--timers", args::timers, "Print timers at the end of the program")->capture_default_str()->group("Tools"); app.add_option( diff --git a/include/samurai/bc/apply_field_bc.hpp b/include/samurai/bc/apply_field_bc.hpp index 37d9689eb..b9c220914 100644 --- a/include/samurai/bc/apply_field_bc.hpp +++ b/include/samurai/bc/apply_field_bc.hpp @@ -2,6 +2,7 @@ // SPDX-License-Identifier: BSD-3-Clause #pragma once +#include #include "../boundary.hpp" #include "../concepts.hpp" @@ -44,7 +45,7 @@ namespace samurai } else { - std::cerr << "Unknown BC type" << std::endl; + fmt::print(stderr, "Unknown BC type\n"); exit(EXIT_FAILURE); } } diff --git a/include/samurai/bc/polynomial_extrapolation.hpp b/include/samurai/bc/polynomial_extrapolation.hpp index 917e33fcb..30e35bad3 100644 --- a/include/samurai/bc/polynomial_extrapolation.hpp +++ b/include/samurai/bc/polynomial_extrapolation.hpp @@ -3,6 +3,8 @@ #pragma once #include "bc.hpp" +#include +#include namespace samurai { @@ -50,8 +52,10 @@ namespace samurai { if (std::isnan(field_value(u, cells[c], field_i))) { - std::cerr << "NaN detected in [" << cells[c] - << "] when applying polynomial extrapolation to fill the outer ghost [" << ghost << "]." << std::endl; + fmt::print(stderr, + "NaN detected in [{}] when applying polynomial extrapolation to fill the outer ghost [{}].\n", + fmt::streamed(cells[c]), + fmt::streamed(ghost)); // save(fs::current_path(), "nan_extrapolation", {true, true}, u.mesh(), u); exit(1); } diff --git a/include/samurai/field.hpp b/include/samurai/field.hpp index fad5aa5d9..0bbab4b9e 100644 --- a/include/samurai/field.hpp +++ b/include/samurai/field.hpp @@ -2,6 +2,8 @@ // SPDX-License-Identifier: BSD-3-Clause #pragma once +#include +#include #include #include @@ -140,7 +142,7 @@ namespace samurai // std::cerr << "READ NaN at level " << level << ", in interval " << interval << std::endl; auto ii = i - interval_tmp.index; auto cell = this->derived_cast().mesh().get_cell(level, static_cast(ii), index...); - std::cerr << "READ NaN in " << cell << std::endl; + fmt::print(stderr, "READ NaN in {}\n", fmt::streamed(cell)); break; } } @@ -179,7 +181,7 @@ namespace samurai // std::cerr << "READ NaN at level " << level << ", in interval " << interval << std::endl; auto ii = i - interval_tmp.index; auto cell = this->derived_cast().mesh().get_cell(level, static_cast(ii), index); - std::cerr << "READ NaN in " << cell << std::endl; + fmt::print(stderr, "READ NaN in {}\n", fmt::streamed(cell)); break; } } diff --git a/include/samurai/level_cell_array.hpp b/include/samurai/level_cell_array.hpp index 48b79c717..0d8e36404 100644 --- a/include/samurai/level_cell_array.hpp +++ b/include/samurai/level_cell_array.hpp @@ -16,6 +16,7 @@ #include #include +#include #include "algorithm.hpp" #include "box.hpp" @@ -639,9 +640,9 @@ namespace samurai #ifndef NDEBUG if (offset < 0) { - std::cerr << "Error: Interval not found: level " << m_level << ", i = " << interval << ", index = "; - ((std::cerr << index << " "), ...); - std::cerr << std::endl; + fmt::print(stderr, "Error: Interval not found: level {}, i = {}, index = ", m_level, fmt::streamed(interval)); + ((fmt::print(stderr, "{} ", index)), ...); + fmt::print(stderr, "\n"); } #endif return m_cells[0][static_cast(offset)]; @@ -660,12 +661,12 @@ namespace samurai #ifndef NDEBUG if (offset < 0) { - std::cerr << "Error: Interval not found: level " << m_level << ", i = " << interval << ", index ="; + fmt::print(stderr, "Error: Interval not found: level {}, i = {}, index =", m_level, fmt::streamed(interval)); for (std::size_t d = 0; d < dim - 1; ++d) { - std::cerr << index[d] << " "; + fmt::print(stderr, "{} ", index[d]); } - std::cerr << std::endl; + fmt::print(stderr, "\n"); } #endif return m_cells[0][static_cast(offset)]; @@ -678,12 +679,12 @@ namespace samurai #ifndef NDEBUG if (offset < 0) { - std::cerr << "Error: Interval not found: level " << m_level << ", coord = "; + fmt::print(stderr, "Error: Interval not found: level {}, coord = ", m_level); for (std::size_t d = 0; d < dim; ++d) { - std::cerr << coord[d] << " "; + fmt::print(stderr, "{} ", coord[d]); } - std::cerr << std::endl; + fmt::print(stderr, "\n"); } #endif return m_cells[0][static_cast(offset)]; @@ -1090,9 +1091,12 @@ namespace samurai const double warning_tol = 0.5; if (scaling_factor > 0 && xt::any(xt::abs(approx_box.length() - box.length()) >= warning_tol * box.length())) { - std::cerr << "Warning: the box " << box << " is poorly approximated by " << approx_box << ". "; - std::cerr << "This is due to a too large scaling factor (" << scaling_factor - << "). Choose a smaller value for a better approximation." << std::endl; + fmt::print( + stderr, + "Warning: the box {} is poorly approximated by {}. This is due to a too large scaling factor ({}). Choose a smaller value for a better approximation.\n", + fmt::streamed(box), + fmt::streamed(approx_box), + scaling_factor); } m_scaling_factor = scaling_factor; diff --git a/include/samurai/memory.hpp b/include/samurai/memory.hpp index 06c0e4e83..46a80ddce 100644 --- a/include/samurai/memory.hpp +++ b/include/samurai/memory.hpp @@ -6,6 +6,7 @@ #include #include +#include #include "level_cell_array.hpp" @@ -47,7 +48,7 @@ namespace samurai std::size_t mem_id = memory_usage(mesh[id]); if (verbose) { - std::cout << fmt::format("Mesh {}: {}", id, mem_id) << std::endl; + fmt::print("Mesh {}: {}\n", id, mem_id); } mem += mem_id; } diff --git a/include/samurai/mesh.hpp b/include/samurai/mesh.hpp index 1fa2192f7..02810522f 100644 --- a/include/samurai/mesh.hpp +++ b/include/samurai/mesh.hpp @@ -7,6 +7,7 @@ #include #include +#include #include "cell_array.hpp" #include "cell_list.hpp" @@ -292,7 +293,7 @@ namespace samurai m_periodic.fill(false); #ifdef SAMURAI_WITH_MPI - std::cerr << "MPI is not implemented with DomainBuilder." << std::endl; + fmt::print(stderr, "MPI is not implemented with DomainBuilder.\n"); std::exit(1); // partition_mesh(start_level, b); // load_balancing(); @@ -482,10 +483,13 @@ namespace samurai { if (box.min_length() < 2 * largest_cell_length * config::max_stencil_width) { - std::cerr << "The hole " << box << " is too small to apply the BC at level " << min_level_bc - << " with the given scaling factor. We need to be able to construct " << (2 * config::max_stencil_width) - << " ghosts in each direction inside the hole." << std::endl; - std::cerr << "Please choose a smaller scaling factor or enlarge the hole." << std::endl; + fmt::print( + stderr, + "The hole {} is too small to apply the BC at level {} with the given scaling factor. We need to be able to construct {} ghosts in each direction inside the hole.\n", + fmt::streamed(box), + min_level_bc, + (2 * config::max_stencil_width)); + fmt::print(stderr, "Please choose a smaller scaling factor or enlarge the hole.\n"); std::exit(1); } } @@ -1151,7 +1155,7 @@ namespace samurai world.barrier(); if (rank == 0) { - std::cout << "---------------- k = " << k << " ----------------" << std::endl; + fmt::print("---------------- k = {} ----------------\n", k); } mpi::all_gather(world, load, loads); @@ -1181,7 +1185,7 @@ namespace samurai load_transfer(load_fluxes); - std::cout << rank << ": load = " << load << ", load_np1 = " << load_np1 << std::endl; + fmt::print("{}: load = {}, load_np1 = {}\n", rank, load, load_np1); load = static_cast(load_np1); } @@ -1193,7 +1197,7 @@ namespace samurai { #ifdef SAMURAI_WITH_MPI mpi::communicator world; - std::cout << world.rank() << ": "; + fmt::print("{}: ", world.rank()); for (std::size_t i_rank = 0; i_rank < m_mpi_neighbourhood.size(); ++i_rank) { auto neighbour = m_mpi_neighbourhood[i_rank]; @@ -1203,9 +1207,9 @@ namespace samurai else if (load_fluxes[i_rank] > 0) // must receive load from the neighbour { } - std::cout << "--> " << neighbour.rank << ": " << load_fluxes[i_rank] << ", "; + fmt::print("--> {}: {}, ", neighbour.rank, load_fluxes[i_rank]); } - std::cout << std::endl; + fmt::print("\n"); #endif } diff --git a/include/samurai/print.hpp b/include/samurai/print.hpp new file mode 100644 index 000000000..c18e7032d --- /dev/null +++ b/include/samurai/print.hpp @@ -0,0 +1,126 @@ +// Copyright 2018-2025 the samurai's authors +// SPDX-License-Identifier: BSD-3-Clause + +#pragma once + +#include +#include + +#ifdef SAMURAI_WITH_MPI +# include +#endif + +#include "arguments.hpp" + +namespace samurai +{ + namespace io + { + struct all_t + { + }; + struct root_t + { + }; + struct rank_t + { + int value; + }; + + inline constexpr all_t all{}; + inline constexpr root_t root{}; + inline constexpr rank_t rank(int value) + { + return rank_t{value}; + } + +#ifdef SAMURAI_WITH_MPI + inline int current_rank() + { + int r = 0; + MPI_Comm_rank(MPI_COMM_WORLD, &r); + return r; + } +#else + inline int current_rank() + { + return 0; + } +#endif + + // stdout printers + template + inline void print(all_t, fmt::format_string fmt, Args&&... args) + { + fmt::print(fmt, std::forward(args)...); + } + + template + inline void print(root_t, fmt::format_string fmt, Args&&... args) + { + if (current_rank() == 0) + { + fmt::print(fmt, std::forward(args)...); + } + } + + template + inline void print(rank_t r, fmt::format_string fmt, Args&&... args) + { + if (current_rank() == r.value) + { + fmt::print(fmt, std::forward(args)...); + } + } + + template + inline void print(fmt::format_string fmt, Args&&... args) + { +#ifdef SAMURAI_WITH_MPI + if (samurai::args::print_root_only && current_rank() != 0) + { + return; + } +#endif + fmt::print(fmt, std::forward(args)...); + } + + // stderr printers + template + inline void eprint(all_t, fmt::format_string fmt, Args&&... args) + { + fmt::print(stderr, fmt, std::forward(args)...); + } + + template + inline void eprint(root_t, fmt::format_string fmt, Args&&... args) + { + if (current_rank() == 0) + { + fmt::print(stderr, fmt, std::forward(args)...); + } + } + + template + inline void eprint(rank_t r, fmt::format_string fmt, Args&&... args) + { + if (current_rank() == r.value) + { + fmt::print(stderr, fmt, std::forward(args)...); + } + } + + template + inline void eprint(fmt::format_string fmt, Args&&... args) + { +#ifdef SAMURAI_WITH_MPI + if (samurai::args::print_root_only && current_rank() != 0) + { + return; + } +#endif + fmt::print(stderr, fmt, std::forward(args)...); + } + } // namespace io +} // namespace samurai + diff --git a/include/samurai/samurai.hpp b/include/samurai/samurai.hpp index 181474f7f..4a94741d5 100644 --- a/include/samurai/samurai.hpp +++ b/include/samurai/samurai.hpp @@ -4,6 +4,7 @@ #ifdef SAMURAI_WITH_MPI #include +#include #include namespace mpi = boost::mpi; #endif @@ -12,6 +13,7 @@ namespace mpi = boost::mpi; #endif #include "arguments.hpp" +#include "print.hpp" #include "timers.hpp" namespace samurai @@ -67,7 +69,7 @@ namespace samurai #ifdef SAMURAI_WITH_MPI MPI_Init(&argc, &argv); - // redirect stdout to /dev/null for all ranks except rank 0 + // Redirect std::cout to /dev/null for non-root ranks, unless disabled by '--dont-redirect-output' mpi::communicator world; if (!args::dont_redirect_output && world.rank() != 0) // cppcheck-suppress knownConditionTrueFalse { diff --git a/include/samurai/stencil.hpp b/include/samurai/stencil.hpp index c2a2aca46..4a64f8651 100644 --- a/include/samurai/stencil.hpp +++ b/include/samurai/stencil.hpp @@ -1,6 +1,8 @@ #pragma once #include "indices.hpp" #include "static_algorithm.hpp" +#include +#include namespace samurai { @@ -591,7 +593,7 @@ namespace samurai #ifndef NDEBUG if (origin_cell.index > 0 && static_cast(origin_cell.index) > m_mesh.nb_cells()) // nb_cells() is very costly { - std::cout << "Cell not found in the mesh: " << origin_cell << std::endl; + fmt::print("Cell not found in the mesh: {}\n", fmt::streamed(origin_cell)); assert(false); } #endif @@ -628,7 +630,7 @@ namespace samurai #ifndef NDEBUG if (cell.index > 0 && static_cast(cell.index) > m_mesh.nb_cells()) // nb_cells() is very costly { - std::cout << "Non-existing neighbour for " << origin_cell << " in the direction " << dir << std::endl; + fmt::print("Non-existing neighbour for {} in the direction {}\n", fmt::streamed(origin_cell), fmt::streamed(dir)); // save(fs::current_path(), "mesh_error", {true, true}, m_mesh); exit(1); } From 8e3f26df39fd488d7544afd1cc0b344c3c26e49f Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Thu, 11 Sep 2025 15:03:23 +0000 Subject: [PATCH 02/37] feat: use fmt in demos --- demos/FiniteVolume/AMR_Burgers_Hat.cpp | 4 +- demos/FiniteVolume/advection_1d.cpp | 2 +- demos/FiniteVolume/advection_2d.cpp | 2 +- demos/FiniteVolume/advection_2d_user_bc.cpp | 2 +- demos/FiniteVolume/burgers.cpp | 19 ++-- demos/FiniteVolume/burgers_mra.cpp | 24 ++--- demos/FiniteVolume/burgers_os.cpp | 98 +++++++++---------- demos/FiniteVolume/heat.cpp | 16 ++- demos/FiniteVolume/heat_heterogeneous.cpp | 6 +- demos/FiniteVolume/heat_nonlinear.cpp | 9 +- demos/FiniteVolume/level_set.cpp | 4 +- demos/FiniteVolume/level_set_from_scratch.cpp | 4 +- demos/FiniteVolume/lid_driven_cavity.cpp | 8 +- demos/FiniteVolume/linear_convection.cpp | 13 ++- .../linear_convection_obstacle.cpp | 6 +- .../manual_block_matrix_assembly.cpp | 10 +- demos/FiniteVolume/nagumo.cpp | 16 ++- demos/FiniteVolume/scalar_burgers_2d.cpp | 2 +- demos/FiniteVolume/stokes_2d.cpp | 33 +++---- demos/multigrid/main.cpp | 43 ++++---- 20 files changed, 156 insertions(+), 165 deletions(-) diff --git a/demos/FiniteVolume/AMR_Burgers_Hat.cpp b/demos/FiniteVolume/AMR_Burgers_Hat.cpp index 0a975c4e8..f1e2ef2b0 100644 --- a/demos/FiniteVolume/AMR_Burgers_Hat.cpp +++ b/demos/FiniteVolume/AMR_Burgers_Hat.cpp @@ -269,7 +269,7 @@ int main(int argc, char* argv[]) std::size_t ite_adapt = 0; while (true) { - std::cout << "\tmesh adaptation: " << ite_adapt++ << std::endl; + fmt::print("\tmesh adaptation: {}\n", ite_adapt++); samurai::update_ghost(phi); tag.resize(); AMR_criteria(phi, tag); @@ -287,7 +287,7 @@ int main(int argc, char* argv[]) t = Tf; } - std::cout << fmt::format("iteration {}: t = {}, dt = {}", nt++, t, dt) << std::endl; + fmt::print("iteration {}: t = {}, dt = {}\n", nt++, t, dt); // Numerical scheme samurai::update_ghost(phi); diff --git a/demos/FiniteVolume/advection_1d.cpp b/demos/FiniteVolume/advection_1d.cpp index b2601d2fb..24128c118 100644 --- a/demos/FiniteVolume/advection_1d.cpp +++ b/demos/FiniteVolume/advection_1d.cpp @@ -145,7 +145,7 @@ int main(int argc, char* argv[]) t = Tf; } - std::cout << fmt::format("iteration {}: t = {}, dt = {}", nt++, t, dt) << std::endl; + fmt::print("iteration {}: t = {}, dt = {}\n", nt++, t, dt); samurai::update_ghost_mr(u); unp1.resize(); diff --git a/demos/FiniteVolume/advection_2d.cpp b/demos/FiniteVolume/advection_2d.cpp index 89beea56f..0cce3707c 100644 --- a/demos/FiniteVolume/advection_2d.cpp +++ b/demos/FiniteVolume/advection_2d.cpp @@ -139,7 +139,7 @@ int main(int argc, char* argv[]) t = Tf; } - std::cout << fmt::format("iteration {}: t = {}, dt = {}", nt++, t, dt) << std::endl; + fmt::print("iteration {}: t = {}, dt = {}\n", nt++, t, dt); samurai::update_ghost_mr(u); unp1.resize(); diff --git a/demos/FiniteVolume/advection_2d_user_bc.cpp b/demos/FiniteVolume/advection_2d_user_bc.cpp index b8ed6f850..ac978bacf 100644 --- a/demos/FiniteVolume/advection_2d_user_bc.cpp +++ b/demos/FiniteVolume/advection_2d_user_bc.cpp @@ -171,7 +171,7 @@ int main(int argc, char* argv[]) t = Tf; } - std::cout << fmt::format("iteration {}: t = {}, dt = {}", nt++, t, dt) << std::endl; + fmt::print("iteration {}: t = {}, dt = {}\n", nt++, t, dt); samurai::update_ghost_mr(u); unp1.resize(); diff --git a/demos/FiniteVolume/burgers.cpp b/demos/FiniteVolume/burgers.cpp index c965fe9eb..0562c7b76 100644 --- a/demos/FiniteVolume/burgers.cpp +++ b/demos/FiniteVolume/burgers.cpp @@ -56,7 +56,7 @@ int main_dim(int argc, char* argv[]) using Box = samurai::Box; using point_t = typename Box::point_t; - std::cout << "------------------------- Burgers -------------------------" << std::endl; + fmt::print("------------------------- Burgers -------------------------\n"); //--------------------// // Program parameters // @@ -177,7 +177,7 @@ int main_dim(int argc, char* argv[]) } else { - std::cerr << "Unmanaged initial solution '" << init_sol << "'."; + fmt::print(stderr, "Unmanaged initial solution '{}' .\n", init_sol); return EXIT_FAILURE; } } @@ -245,7 +245,7 @@ int main_dim(int argc, char* argv[]) dt += Tf - t; t = Tf; } - std::cout << fmt::format("iteration {}: t = {:.2f}, dt = {}", nt++, t, dt) << std::flush; + fmt::print("{}", fmt::format("iteration {}: t = {:.2f}, dt = {}", nt++, t, dt)); // Mesh adaptation MRadaptation(mra_config); @@ -287,7 +287,7 @@ int main_dim(int argc, char* argv[]) { return exact_solution(coord, t); }); - std::cout << ", L2-error: " << std::scientific << std::setprecision(2) << error; + fmt::print(", L2-error: {:.2e}", error); if (mesh.min_level() != mesh.max_level()) { @@ -298,19 +298,18 @@ int main_dim(int argc, char* argv[]) { return exact_solution(coord, t); }); - std::cout << ", L2-error (recons): " << std::scientific << std::setprecision(2) << error; + fmt::print(", L2-error (recons): {:.2e}", error); } } - std::cout << std::endl; + fmt::print("\n"); } if constexpr (dim == 1) { - std::cout << std::endl; - std::cout << "Run the following command to view the results:" << std::endl; - std::cout << "python <>/python/read_mesh.py " << filename << "_ite_ --field u level --start 0 --end " << nsave - << std::endl; + fmt::print("\n"); + fmt::print("Run the following command to view the results:\n"); + fmt::print("python <>/python/read_mesh.py {}_ite_ --field u level --start 0 --end {}\n", filename, nsave); } samurai::finalize(); diff --git a/demos/FiniteVolume/burgers_mra.cpp b/demos/FiniteVolume/burgers_mra.cpp index ea6e74dbe..9b9551d12 100644 --- a/demos/FiniteVolume/burgers_mra.cpp +++ b/demos/FiniteVolume/burgers_mra.cpp @@ -82,7 +82,7 @@ void run_simulation(Field& u, { auto& mesh = u.mesh(); - std::cout << std::endl << "max-level-flux enabled: " << scheme.enable_max_level_flux() << std::endl; + fmt::print("\nmax-level-flux enabled: {}\n", scheme.enable_max_level_flux()); if (scheme.enable_max_level_flux()) { @@ -188,14 +188,14 @@ void run_simulation(Field& u, { return hat_exact_solution(coord[0], t); }); - std::cout << "[w.r.t. exact, no recons] " << error; + fmt::print("[w.r.t. exact, no recons] {}", error); error = samurai::L2_error(u_recons, [&](const auto& coord) { return hat_exact_solution(coord[0], t); }); - std::cout << ", [w.r.t. exact, recons] " << error; + fmt::print(", [w.r.t. exact, recons] {}", error); } double error = 0; @@ -206,7 +206,7 @@ void run_simulation(Field& u, error += std::pow(u_max[cell] - u_recons[cell2], 2) * std::pow(cell.length, 1); }); error = std::sqrt(error); - std::cout << ", [w.r.t. max level, recons] " << error; + fmt::print(", [w.r.t. max level, recons] {}", error); // Save the result if (t >= static_cast(nsave) * dt_save || t == Tf) @@ -219,7 +219,7 @@ void run_simulation(Field& u, nsave++; } - std::cout << std::endl; + fmt::print("\n"); } } @@ -231,7 +231,7 @@ int main(int argc, char* argv[]) auto& app = samurai::initialize("Finite volume example for the Burgers equation in 1d", argc, argv); - std::cout << "------------------------- Burgers -------------------------" << std::endl; + fmt::print("------------------------- Burgers -------------------------\n"); //--------------------// // Program parameters // @@ -301,12 +301,12 @@ int main(int argc, char* argv[]) scheme.enable_max_level_flux(true); run_simulation(u, unp1, u_max, unp1_max, scheme, cfl, mra_config, init_sol, nfiles, path, filename, nsave); - std::cout << std::endl; - std::cout << "Run the following commands to view the results:" << std::endl; - std::cout << "max-level-flux disabled:" << std::endl; - std::cout << " python ../python/read_mesh.py " << filename << "_recons_ite_ --field u --start 0 --end " << nsave << std::endl; - std::cout << "max-level-flux enabled:" << std::endl; - std::cout << " python ../python/read_mesh.py " << filename << "_mlf_recons_ite_ --field u --start 0 --end " << nsave << std::endl; + fmt::print("\n"); + fmt::print("Run the following commands to view the results:\n"); + fmt::print("max-level-flux disabled:\n"); + fmt::print(" python ../python/read_mesh.py {}_recons_ite_ --field u --start 0 --end {}\n", filename, nsave); + fmt::print("max-level-flux enabled:\n"); + fmt::print(" python ../python/read_mesh.py {}_mlf_recons_ite_ --field u --start 0 --end {}\n", filename, nsave); samurai::finalize(); return 0; diff --git a/demos/FiniteVolume/burgers_os.cpp b/demos/FiniteVolume/burgers_os.cpp index e9965ec1c..56f27dfdb 100644 --- a/demos/FiniteVolume/burgers_os.cpp +++ b/demos/FiniteVolume/burgers_os.cpp @@ -41,48 +41,48 @@ void check_diff(auto& field, auto& lca_left, auto& lca_right) { auto& mesh = field.mesh(); using mesh_id_t = typename std::decay_t::mesh_id_t; - samurai::for_each_level( - mesh, - [&](auto level) - { - auto set = samurai::difference(samurai::intersection(mesh[mesh_id_t::cells][level], self(lca_left).on(level)), - samurai::translate(samurai::intersection(mesh[mesh_id_t::cells][level], self(lca_right).on(level)), - xt::xtensor_fixed>{-(1 << level)})); - set( - [&](auto& i, auto) - { - std::cout << "Difference found !! " << level << " " << i << "\n"; - auto level_ = samurai::make_scalar_field("level", mesh); - samurai::for_each_cell(mesh, - [&](const auto& cell) - { - level_[cell] = cell.level; - }); - samurai::save("mesh_throw", mesh, field, level_); - throw std::runtime_error("Difference found in check_diff function for the mesh"); - }); - auto set_field = samurai::intersection(mesh[mesh_id_t::cells][level], self(lca_left).on(level)); - set_field( - [&](auto i, auto) - { - if (xt::any(xt::abs(field(level, i) - field(level, i + (1 << level))) > 1e-13)) - { - std::cout << fmt::format("\nDifference found at level {} on interval {}:\n", level, i); - std::cout << fmt::format("\tleft = {}\n", field(level, i)); - std::cout << fmt::format("\tright = {}\n", field(level, i + (1 << level))); - std::cout << fmt::format("\terror = {}\n", xt::abs(field(level, i) - field(level, i + (1 << level)))); - std::cout << mesh << std::endl; - auto level_ = samurai::make_scalar_field("level", mesh); - samurai::for_each_cell(mesh, - [&](const auto& cell) - { - level_[cell] = cell.level; - }); - samurai::save("mesh_throw", mesh, field, level_); - throw std::runtime_error("Difference found in check_diff function for the field values"); - } - }); - }); + samurai::for_each_level(mesh, + [&](auto level) + { + auto set = samurai::difference( + samurai::intersection(mesh[mesh_id_t::cells][level], self(lca_left).on(level)), + samurai::translate(samurai::intersection(mesh[mesh_id_t::cells][level], self(lca_right).on(level)), + xt::xtensor_fixed>{-(1 << level)})); + set( + [&](auto& i, auto) + { + fmt::print("Difference found !! {} {}\n", level, i); + auto level_ = samurai::make_scalar_field("level", mesh); + samurai::for_each_cell(mesh, + [&](const auto& cell) + { + level_[cell] = cell.level; + }); + samurai::save("mesh_throw", mesh, field, level_); + throw std::runtime_error("Difference found in check_diff function for the mesh"); + }); + auto set_field = samurai::intersection(mesh[mesh_id_t::cells][level], self(lca_left).on(level)); + set_field( + [&](auto i, auto) + { + if (xt::any(xt::abs(field(level, i) - field(level, i + (1 << level))) > 1e-13)) + { + fmt::print("\nDifference found at level {} on interval {}:\n", level, i); + fmt::print("\tleft = {}\n", field(level, i)); + fmt::print("\tright = {}\n", field(level, i + (1 << level))); + fmt::print("\terror = {}\n", xt::abs(field(level, i) - field(level, i + (1 << level)))); + fmt::print("{}\n", fmt::streamed(mesh)); + auto level_ = samurai::make_scalar_field("level", mesh); + samurai::for_each_cell(mesh, + [&](const auto& cell) + { + level_[cell] = cell.level; + }); + samurai::save("mesh_throw", mesh, field, level_); + throw std::runtime_error("Difference found in check_diff function for the field values"); + } + }); + }); } int main(int argc, char* argv[]) @@ -94,7 +94,7 @@ int main(int argc, char* argv[]) using Box = samurai::Box; using point_t = typename Box::point_t; - std::cout << "------------------------- Burgers 1D -------------------------" << std::endl; + fmt::print("------------------------- Burgers 1D -------------------------\n"); //--------------------// // Program parameters // @@ -134,7 +134,7 @@ int main(int argc, char* argv[]) SAMURAI_PARSE(argc, argv); - std::cout << " max_level = " << max_level << " min_level = " << min_level << std::endl; + fmt::print(" max_level = {} min_level = {}\n", max_level, min_level); //--------------------// // Problem definition // @@ -199,7 +199,7 @@ int main(int argc, char* argv[]) dt += Tf - t; t = Tf; } - std::cout << fmt::format("iteration {}: t = {:.12f}, dt = {}", nt++, t, dt) << std::flush; + fmt::print("{}", fmt::format("iteration {}: t = {:.12f}, dt = {}", nt++, t, dt)); // Mesh adaptation MRadaptation(mra_config); @@ -210,7 +210,7 @@ int main(int argc, char* argv[]) } catch (...) { - std::cout << "Exception caught in check_diff after adaptation" << std::endl; + fmt::print("Exception caught in check_diff after adaptation\n"); samurai::finalize(); return 1; } @@ -228,7 +228,7 @@ int main(int argc, char* argv[]) } catch (...) { - std::cout << "Exception caught in check_diff after integration" << std::endl; + fmt::print("Exception caught in check_diff after integration\n"); samurai::finalize(); return 1; } @@ -236,13 +236,13 @@ int main(int argc, char* argv[]) // Save the result if (nfiles == 0 || t >= static_cast(nsave) * dt_save || t == Tf) { - std::cout << " (saving results)" << std::flush; + fmt::print(" (saving results)"); std::string suffix = (nfiles != 1) ? fmt::format("_level_{}_{}_ite_{}", min_level, max_level, nsave) : ""; save(path, filename, u, suffix); nsave++; } - std::cout << std::endl; + fmt::print("\n"); } samurai::finalize(); diff --git a/demos/FiniteVolume/heat.cpp b/demos/FiniteVolume/heat.cpp index 0062ae1dc..caa52a0f9 100644 --- a/demos/FiniteVolume/heat.cpp +++ b/demos/FiniteVolume/heat.cpp @@ -53,7 +53,7 @@ int main(int argc, char* argv[]) using Box = samurai::Box; using point_t = typename Box::point_t; - std::cout << "------------------------- Heat -------------------------" << std::endl; + fmt::print("------------------------- Heat -------------------------\n"); //--------------------// // Program parameters // @@ -199,7 +199,7 @@ int main(int argc, char* argv[]) dt += Tf - t; t = Tf; } - std::cout << fmt::format("iteration {}: t = {:.2f}, dt = {}", nt++, t, dt) << std::flush; + fmt::print("{}", fmt::format("iteration {}: t = {:.2f}, dt = {}", nt++, t, dt)); // Mesh adaptation MRadaptation(mra_config); @@ -232,18 +232,16 @@ int main(int argc, char* argv[]) { return exact_solution(coord, t, diff_coeff); }); - std::cout.precision(2); - std::cout << ", L2-error: " << std::scientific << error; + fmt::print(", L2-error: {:.2e}", error); } - std::cout << std::endl; + fmt::print("\n"); } if (!save_final_state_only && dim == 1) { - std::cout << std::endl; - std::cout << "Run the following command to view the results:" << std::endl; - std::cout << "python <>/python/read_mesh.py " << filename << "_ite_ --field u level --start 1 --end " << nsave - << std::endl; + fmt::print("\n"); + fmt::print("Run the following command to view the results:\n"); + fmt::print("python <>/python/read_mesh.py {}_ite_ --field u level --start 1 --end {}\n", filename, nsave); } if (save_final_state_only) diff --git a/demos/FiniteVolume/heat_heterogeneous.cpp b/demos/FiniteVolume/heat_heterogeneous.cpp index 8b4823da2..192c7fec3 100644 --- a/demos/FiniteVolume/heat_heterogeneous.cpp +++ b/demos/FiniteVolume/heat_heterogeneous.cpp @@ -41,7 +41,7 @@ int main(int argc, char* argv[]) using Box = samurai::Box; using point_t = typename Box::point_t; - std::cout << "------------------------- Heat -------------------------" << std::endl; + fmt::print("------------------------- Heat -------------------------\n"); //--------------------// // Program parameters // @@ -176,7 +176,7 @@ int main(int argc, char* argv[]) dt += Tf - t; t = Tf; } - std::cout << fmt::format("iteration {}: t = {:.2f}, dt = {}", nt++, t, dt) << std::flush; + fmt::print("{}", fmt::format("iteration {}: t = {:.2f}, dt = {}", nt++, t, dt)); // Mesh adaptation MRadaptation(mra_config); @@ -203,7 +203,7 @@ int main(int argc, char* argv[]) save(path, filename, u, fmt::format("_ite_{}", nsave++)); } - std::cout << std::endl; + fmt::print("\n"); } if (save_final_state_only) diff --git a/demos/FiniteVolume/heat_nonlinear.cpp b/demos/FiniteVolume/heat_nonlinear.cpp index c9c259e11..94bd2dc16 100644 --- a/demos/FiniteVolume/heat_nonlinear.cpp +++ b/demos/FiniteVolume/heat_nonlinear.cpp @@ -106,7 +106,7 @@ int main(int argc, char* argv[]) using Box = samurai::Box; using point_t = typename Box::point_t; - std::cout << "------------------------- Non-linear heat -------------------------" << std::endl; + fmt::print("------------------------- Non-linear heat -------------------------\n"); /* Solves the non-linear heat equation @@ -227,7 +227,7 @@ int main(int argc, char* argv[]) dt += Tf - t; t = Tf; } - std::cout << fmt::format("iteration {}: t = {:.2f}, dt = {}", nt++, t, dt) << std::flush; + fmt::print("{}", fmt::format("iteration {}: t = {:.2f}, dt = {}", nt++, t, dt)); // Update boundary conditions if (explicit_scheme) @@ -271,8 +271,7 @@ int main(int argc, char* argv[]) { return exact_solution(coords, t); }); - std::cout.precision(2); - std::cout << ", L2-error: " << std::scientific << error; + fmt::print(", L2-error: {:.2e}", error); // Save the result if (!save_final_state_only) @@ -280,7 +279,7 @@ int main(int argc, char* argv[]) save(path, filename, u, fmt::format("_ite_{}", nsave++)); } - std::cout << std::endl; + fmt::print("\n"); } if (save_final_state_only) diff --git a/demos/FiniteVolume/level_set.cpp b/demos/FiniteVolume/level_set.cpp index 49d2b7c60..07fe1ea3e 100644 --- a/demos/FiniteVolume/level_set.cpp +++ b/demos/FiniteVolume/level_set.cpp @@ -331,7 +331,7 @@ int main(int argc, char* argv[]) std::size_t ite = 0; while (true) { - std::cout << "Mesh adaptation iteration " << ite++ << std::endl; + fmt::print("Mesh adaptation iteration {}\n", ite++); tag.resize(); AMR_criteria(phi, tag); samurai::graduation(tag, stencil_grad); @@ -349,7 +349,7 @@ int main(int argc, char* argv[]) t = Tf; } - std::cout << fmt::format("iteration {}: t = {}, dt = {}", nt++, t, dt) << std::endl; + fmt::print("iteration {}: t = {}, dt = {}\n", nt++, t, dt); // Numerical scheme samurai::update_ghost(phi, u); diff --git a/demos/FiniteVolume/level_set_from_scratch.cpp b/demos/FiniteVolume/level_set_from_scratch.cpp index 2000b1adc..c3192742a 100644 --- a/demos/FiniteVolume/level_set_from_scratch.cpp +++ b/demos/FiniteVolume/level_set_from_scratch.cpp @@ -667,7 +667,7 @@ int main(int argc, char* argv[]) std::size_t ite = 0; while (true) { - std::cout << "Mesh adaptation iteration " << ite++ << std::endl; + fmt::print("Mesh adaptation iteration {}\n", ite++); auto tag = samurai::make_scalar_field("tag", mesh); AMR_criteria(phi, tag); ::make_graduation(tag); @@ -686,7 +686,7 @@ int main(int argc, char* argv[]) t = Tf; } - std::cout << fmt::format("iteration {}: t = {}, dt = {}", nt++, t, dt) << std::endl; + fmt::print("iteration {}: t = {}, dt = {}\n", nt++, t, dt); // Numerical scheme update_ghosts(phi, u); diff --git a/demos/FiniteVolume/lid_driven_cavity.cpp b/demos/FiniteVolume/lid_driven_cavity.cpp index 004cdde63..5da909f31 100644 --- a/demos/FiniteVolume/lid_driven_cavity.cpp +++ b/demos/FiniteVolume/lid_driven_cavity.cpp @@ -148,7 +148,7 @@ int main(int argc, char* argv[]) auto box = samurai::Box({0, 0}, {1, 1}); - std::cout << "lid-driven cavity" << std::endl; + fmt::print("lid-driven cavity\n"); //-------------------- 1 ----------------------------------------------------------------- // @@ -322,7 +322,7 @@ int main(int argc, char* argv[]) t = Tf; dt_has_changed = true; } - std::cout << fmt::format("iteration {}: t = {:.2f}, dt = {}", nt++, t, dt); + fmt::print("{}", fmt::format("iteration {}: t = {:.2f}, dt = {}", nt++, t, dt)); // Mesh adaptation for Navier-Stokes if (min_level != max_level) @@ -338,9 +338,9 @@ int main(int argc, char* argv[]) zero.resize(); rhs.resize(); } - std::cout << ", levels " << min_level_np1 << "-" << max_level_np1; + fmt::print(", levels {}-{}", min_level_np1, max_level_np1); } - std::cout << std::endl; + fmt::print("\n"); // Update solver if (mesh_has_changed || dt_has_changed) diff --git a/demos/FiniteVolume/linear_convection.cpp b/demos/FiniteVolume/linear_convection.cpp index a7ae59070..ab182d3be 100644 --- a/demos/FiniteVolume/linear_convection.cpp +++ b/demos/FiniteVolume/linear_convection.cpp @@ -41,7 +41,7 @@ int main(int argc, char* argv[]) using Box = samurai::Box; using point_t = typename Box::point_t; - std::cout << "------------------------- Linear convection -------------------------" << std::endl; + fmt::print("------------------------- Linear convection -------------------------\n"); //--------------------// // Program parameters // @@ -171,7 +171,7 @@ int main(int argc, char* argv[]) dt += Tf - t; t = Tf; } - std::cout << fmt::format("iteration {}: t = {:.2f}, dt = {}", nt++, t, dt) << std::flush; + fmt::print("{}", fmt::format("iteration {}: t = {:.2f}, dt = {}", nt++, t, dt)); // Mesh adaptation MRadaptation(mra_config); @@ -226,15 +226,14 @@ int main(int argc, char* argv[]) } } - std::cout << std::endl; + fmt::print("\n"); } if constexpr (dim == 1) { - std::cout << std::endl; - std::cout << "Run the following command to view the results:" << std::endl; - std::cout << "python <>/python/read_mesh.py " << filename << "_ite_ --field u level --start 0 --end " << nsave - << std::endl; + fmt::print("\n"); + fmt::print("Run the following command to view the results:\n"); + fmt::print("python <>/python/read_mesh.py {}_ite_ --field u level --start 0 --end {}\n", filename, nsave); } samurai::finalize(); diff --git a/demos/FiniteVolume/linear_convection_obstacle.cpp b/demos/FiniteVolume/linear_convection_obstacle.cpp index 00a048657..e7c66c43d 100644 --- a/demos/FiniteVolume/linear_convection_obstacle.cpp +++ b/demos/FiniteVolume/linear_convection_obstacle.cpp @@ -39,7 +39,7 @@ int main(int argc, char* argv[]) using Config = samurai::MRConfig; using Mesh = samurai::MRMesh; - std::cout << "------------------------- Linear convection -------------------------" << std::endl; + fmt::print("------------------------- Linear convection -------------------------\n"); //--------------------// // Program parameters // @@ -145,7 +145,7 @@ int main(int argc, char* argv[]) dt += Tf - t; t = Tf; } - std::cout << fmt::format("iteration {}: t = {:.2f}, dt = {}", nt++, t, dt) << std::flush; + fmt::print("{}", fmt::format("iteration {}: t = {:.2f}, dt = {}", nt++, t, dt)); // Mesh adaptation @@ -185,7 +185,7 @@ int main(int argc, char* argv[]) } } - std::cout << std::endl; + fmt::print("\n"); } samurai::finalize(); diff --git a/demos/FiniteVolume/manual_block_matrix_assembly.cpp b/demos/FiniteVolume/manual_block_matrix_assembly.cpp index 03b86f243..b7359c97d 100644 --- a/demos/FiniteVolume/manual_block_matrix_assembly.cpp +++ b/demos/FiniteVolume/manual_block_matrix_assembly.cpp @@ -191,7 +191,7 @@ int main(int argc, char* argv[]) using Config = samurai::MRConfig; using Box = samurai::Box; - std::cout << "------------------------- Begin -------------------------" << std::endl; + fmt::print("------------------------- Begin -------------------------\n"); std::size_t min_level = 3; std::size_t max_level = 3; @@ -275,18 +275,18 @@ int main(int argc, char* argv[]) // Insert the coefficients into the matrix assembly.assemble_matrix(J); - std::cout << "Useless ghost rows: "; + fmt::print("Useless ghost rows: "); // assembly.get<0, 0>().for_each_useless_ghost_row( assembly.for_each_useless_ghost_row( [](auto row) { - std::cout << row << " "; + fmt::print("{} ", row); }); - std::cout << std::endl; + fmt::print("\n"); Vec v = assembly.create_vector(u_e, aux_Ce, u_s); VecView(v, PETSC_VIEWER_STDOUT_(PETSC_COMM_SELF)); - std::cout << std::endl; + fmt::print("\n"); samurai::finalize(); return 0; diff --git a/demos/FiniteVolume/nagumo.cpp b/demos/FiniteVolume/nagumo.cpp index 5f051d90e..35cf0c696 100644 --- a/demos/FiniteVolume/nagumo.cpp +++ b/demos/FiniteVolume/nagumo.cpp @@ -41,7 +41,7 @@ int main(int argc, char* argv[]) using Box = samurai::Box; using point_t = typename Box::point_t; - std::cout << "------------------------- Nagumo -------------------------" << std::endl; + fmt::print("------------------------- Nagumo -------------------------\n"); /** * Nagumo, or Fisher-KPP equation: @@ -203,7 +203,7 @@ int main(int argc, char* argv[]) dt += Tf - t; t = Tf; } - std::cout << fmt::format("iteration {}: t = {:.2f}, dt = {}", nt++, t, dt) << std::flush; + fmt::print("{}", fmt::format("iteration {}: t = {:.2f}, dt = {}", nt++, t, dt)); // Mesh adaptation MRadaptation(mra_config); @@ -252,8 +252,7 @@ int main(int argc, char* argv[]) { return exact_solution(coord(0), t); }); - std::cout.precision(2); - std::cout << ", L2-error: " << std::scientific << error; + fmt::print(", L2-error: {:.2e}", error); // Save the result if (!save_final_state_only) @@ -261,15 +260,14 @@ int main(int argc, char* argv[]) save(path, filename, u, fmt::format("_ite_{}", nsave++)); } - std::cout << std::endl; + fmt::print("\n"); } if (!save_final_state_only && dim == 1) { - std::cout << std::endl; - std::cout << "Run the following command to view the results:" << std::endl; - std::cout << "python <>/python/read_mesh.py " << filename << "_ite_ --field u level --start 1 --end " << nsave - << std::endl; + fmt::print("\n"); + fmt::print("Run the following command to view the results:\n"); + fmt::print("python <>/python/read_mesh.py {}_ite_ --field u level --start 1 --end {}\n", filename, nsave); } if (save_final_state_only) diff --git a/demos/FiniteVolume/scalar_burgers_2d.cpp b/demos/FiniteVolume/scalar_burgers_2d.cpp index 0d062a215..05a831291 100644 --- a/demos/FiniteVolume/scalar_burgers_2d.cpp +++ b/demos/FiniteVolume/scalar_burgers_2d.cpp @@ -264,7 +264,7 @@ int main(int argc, char* argv[]) t = Tf; } - std::cout << fmt::format("iteration {}: t = {}, dt = {}", nt++, t, dt) << std::endl; + fmt::print("iteration {}: t = {}, dt = {}\n", nt++, t, dt); samurai::update_ghost_mr(u); unp1.resize(); diff --git a/demos/FiniteVolume/stokes_2d.cpp b/demos/FiniteVolume/stokes_2d.cpp index 463786eb7..20c9c9b85 100644 --- a/demos/FiniteVolume/stokes_2d.cpp +++ b/demos/FiniteVolume/stokes_2d.cpp @@ -21,7 +21,7 @@ template if (std::isnan(value) || std::isinf(value) || (abs(value) < 1e-300 && abs(value) != 0)) { is_nan_or_inf = true; - std::cout << f << std::endl; + fmt::print("{}\n", fmt::streamed(f)); break; } } @@ -203,11 +203,11 @@ int main(int argc, char* argv[]) // Stationary problem // //--------------------// - std::cout << "Problem solved: "; + fmt::print("Problem solved: "); if (test_case == "s") { - std::cout << "stationary" << std::endl; + fmt::print("stationary\n"); if (filename.empty()) { filename = "stokes"; @@ -273,14 +273,14 @@ int main(int argc, char* argv[]) zero.fill(0); // Linear solver - std::cout << "Solving Stokes system..." << std::endl; + fmt::print("Solving Stokes system...\n"); auto stokes_solver = samurai::petsc::make_solver(stokes); stokes_solver.set_unknowns(velocity, pressure); configure_solver(stokes_solver); stokes_solver.solve(f, zero); - std::cout << stokes_solver.iterations() << " iterations" << std::endl << std::endl; + fmt::print("{} iterations\n\n", stokes_solver.iterations()); // Error double error = L2_error(velocity, @@ -292,11 +292,10 @@ int main(int argc, char* argv[]) auto v_y = -v_x; return samurai::Array{v_x, v_y}; }); - std::cout.precision(2); - std::cout << "L2-error on the velocity: " << std::scientific << error << std::endl; + fmt::print("L2-error on the velocity: {:.2e}\n", error); // Save solution - std::cout << "Saving solution..." << std::endl; + fmt::print("Saving solution...\n"); samurai::save(path, filename, mesh, velocity); samurai::save(path, "pressure", mesh, pressure); @@ -337,7 +336,7 @@ int main(int argc, char* argv[]) else if (test_case == "ns") { - std::cout << "non stationary" << std::endl; + fmt::print("non stationary\n"); if (filename.empty()) { @@ -464,7 +463,7 @@ int main(int argc, char* argv[]) t_np1 = Tf; dt_has_changed = true; } - std::cout << fmt::format("iteration {}: t = {:.2f}, dt = {}", nt++, t_np1, dt); + fmt::print("{}", fmt::format("iteration {}: t = {:.2f}, dt = {}", nt++, t_np1, dt)); // Mesh adaptation if (min_level != max_level) @@ -480,9 +479,9 @@ int main(int argc, char* argv[]) rhs.resize(); zero.resize(); } - std::cout << ", levels " << min_level_np1 << "-" << max_level_np1; + fmt::print(", levels {}-{}", min_level_np1, max_level_np1); } - std::cout.flush(); + // flush no-op with fmt // Boundary conditions velocity_np1.get_bc().clear(); @@ -536,8 +535,7 @@ int main(int argc, char* argv[]) { return exact_velocity(t_n, coord); }); - std::cout.precision(2); - std::cout << ", L2-error: " << std::scientific << error; + fmt::print(", L2-error: {:.2e}", error); // Divergence auto div_velocity = div(velocity); @@ -558,8 +556,7 @@ int main(int argc, char* argv[]) { return exact_velocity(t_n, coord); }); - std::cout.precision(2); - std::cout << ", L2-error (recons): " << std::scientific << error_recons; + fmt::print(", L2-error (recons): {:.2e}", error_recons); // Save if (nfiles != 1) { @@ -570,7 +567,7 @@ int main(int argc, char* argv[]) { nsave++; } - std::cout << std::endl; + fmt::print("\n"); } if (nfiles == 1) @@ -580,7 +577,7 @@ int main(int argc, char* argv[]) } else { - std::cerr << "Unknown test case. Allowed options are 's' = stationary, 'ns' = non-stationary." << std::endl; + fmt::print(stderr, "Unknown test case. Allowed options are 's' = stationary, 'ns' = non-stationary.\n"); } samurai::finalize(); diff --git a/demos/multigrid/main.cpp b/demos/multigrid/main.cpp index c7eb04e8d..d39ec11ce 100644 --- a/demos/multigrid/main.cpp +++ b/demos/multigrid/main.cpp @@ -1,6 +1,8 @@ // Copyright 2018-2025 the samurai's authors // SPDX-License-Identifier: BSD-3-Clause +#include +#include #include #include #include @@ -166,9 +168,9 @@ int main(int argc, char* argv[]) } else { - std::cerr << "unknown value for argument --tc" << std::endl; + fmt::print(stderr, "unknown value for argument --tc\n"); } - std::cout << "Test case: " << test_case_code << std::endl; + fmt::print("Test case: {}\n", test_case_code); PetscOptionsGetBool(NULL, NULL, "--save_sol", &save_solution, NULL); PetscOptionsGetBool(NULL, NULL, "--save_mesh", &save_mesh, NULL); @@ -202,11 +204,11 @@ int main(int argc, char* argv[]) if (save_mesh) { - std::cout << "Saving mesh..." << std::endl; + fmt::print("Saving mesh...\n"); samurai::save(path, "mesh", mesh); } - std::cout << "Unknowns: " << (mesh.nb_cells() * n_comp) << std::endl; + fmt::print("Unknowns: {}\n", (mesh.nb_cells() * n_comp)); //----------------// // Create problem // @@ -243,19 +245,19 @@ int main(int argc, char* argv[]) total_timer.Start(); - std::cout << "Setup solver..." << std::endl; + fmt::print("Setup solver...\n"); setup_timer.Start(); solver.setup(); setup_timer.Stop(); - std::cout << "Solving..." << std::endl; + fmt::print("Solving...\n"); solve_timer.Start(); solver.solve(source); solve_timer.Stop(); total_timer.Stop(); - std::cout << solver.iterations() << " iterations" << std::endl << std::endl; + fmt::print("{} iterations\n\n", solver.iterations()); solver.destroy_petsc_objects(); @@ -263,16 +265,16 @@ int main(int argc, char* argv[]) // Print exec times // //--------------------// - std::cout << "---- Setup ----" << std::endl; - std::cout << "CPU time : " << setup_timer.CPU() << std::endl; - std::cout << "Elapsed time: " << setup_timer.Elapsed() << std::endl; - std::cout << "---- Solve ----" << std::endl; - std::cout << "CPU time : " << solve_timer.CPU() << std::endl; - std::cout << "Elapsed time: " << solve_timer.Elapsed() << std::endl; - std::cout << "---- Total ----" << std::endl; - std::cout << "CPU time : " << total_timer.CPU() << std::endl; - std::cout << "Elapsed time: " << total_timer.Elapsed() << std::endl; - std::cout << std::endl; + fmt::print("---- Setup ----\n"); + fmt::print("CPU time : {}\n", fmt::streamed(setup_timer.CPU())); + fmt::print("Elapsed time: {}\n", fmt::streamed(setup_timer.Elapsed())); + fmt::print("---- Solve ----\n"); + fmt::print("CPU time : {}\n", fmt::streamed(solve_timer.CPU())); + fmt::print("Elapsed time: {}\n", fmt::streamed(solve_timer.Elapsed())); + fmt::print("---- Total ----\n"); + fmt::print("CPU time : {}\n", fmt::streamed(total_timer.CPU())); + fmt::print("Elapsed time: {}\n", fmt::streamed(total_timer.Elapsed())); + fmt::print("\n"); /*auto right_fluxes = samurai::make_vector_field("fluxes", mesh); samurai::DirectionVector right = {1, 0}; @@ -292,8 +294,7 @@ int main(int argc, char* argv[]) if (test_case->solution_is_known()) { double error = L2_error(solution, test_case->solution()); - std::cout.precision(2); - std::cout << "L2-error: " << std::scientific << error << std::endl; + fmt::print("L2-error: {:.2e}\n", error); if (test_case_code == "poly") { @@ -306,7 +307,7 @@ int main(int argc, char* argv[]) // std::cout << "theoretical_bound: " << theoretical_bound << std::endl; if (error > theoretical_bound) { - std::cerr << "Convergence order failure: the error must be < " << theoretical_bound << "." << std::endl; + fmt::print(stderr, "Convergence order failure: the error must be < {}.\n", theoretical_bound); } } } @@ -314,7 +315,7 @@ int main(int argc, char* argv[]) // Save solution if (save_solution) { - std::cout << "Saving solution..." << std::endl; + fmt::print("Saving solution...\n"); samurai::save(path, filename, mesh, solution); } From aef182f166c68aa836bd44232cde246ecab406c7 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Thu, 11 Sep 2025 15:03:45 +0000 Subject: [PATCH 03/37] feat: improve printing --- include/samurai/print.hpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/include/samurai/print.hpp b/include/samurai/print.hpp index c18e7032d..ae8cee4d0 100644 --- a/include/samurai/print.hpp +++ b/include/samurai/print.hpp @@ -7,7 +7,7 @@ #include #ifdef SAMURAI_WITH_MPI -# include +#include #endif #include "arguments.hpp" @@ -19,9 +19,11 @@ namespace samurai struct all_t { }; + struct root_t { }; + struct rank_t { int value; @@ -29,6 +31,7 @@ namespace samurai inline constexpr all_t all{}; inline constexpr root_t root{}; + inline constexpr rank_t rank(int value) { return rank_t{value}; @@ -123,4 +126,3 @@ namespace samurai } } // namespace io } // namespace samurai - From 1cee09128fdde2fb9df448bd1ba0095f40ee96d0 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Thu, 11 Sep 2025 16:49:19 +0000 Subject: [PATCH 04/37] feat: use samurai::io::print everywhere --- demos/FiniteVolume/AMR_Burgers_Hat.cpp | 5 +- demos/FiniteVolume/BZ/bz_2d.cpp | 8 +- demos/FiniteVolume/BZ/bz_2d_AMR.cpp | 8 +- demos/FiniteVolume/advection_1d.cpp | 2 +- demos/FiniteVolume/advection_2d.cpp | 2 +- demos/FiniteVolume/advection_2d_user_bc.cpp | 2 +- demos/FiniteVolume/burgers.cpp | 18 +-- demos/FiniteVolume/burgers_mra.cpp | 24 ++-- demos/FiniteVolume/burgers_os.cpp | 26 ++--- demos/FiniteVolume/heat.cpp | 15 +-- demos/FiniteVolume/heat_heterogeneous.cpp | 7 +- demos/FiniteVolume/heat_nonlinear.cpp | 9 +- demos/FiniteVolume/level_set.cpp | 4 +- demos/FiniteVolume/level_set_from_scratch.cpp | 4 +- demos/FiniteVolume/lid_driven_cavity.cpp | 8 +- demos/FiniteVolume/linear_convection.cpp | 13 ++- .../linear_convection_obstacle.cpp | 7 +- .../manual_block_matrix_assembly.cpp | 11 +- demos/FiniteVolume/nagumo.cpp | 15 +-- demos/FiniteVolume/scalar_burgers_2d.cpp | 2 +- demos/FiniteVolume/stokes_2d.cpp | 29 ++--- demos/multigrid/main.cpp | 41 +++---- demos/tutorial/AMR_1D_Burgers/step_2/main.cpp | 2 +- demos/tutorial/AMR_1D_Burgers/step_3/main.cpp | 2 +- demos/tutorial/AMR_1D_Burgers/step_6/main.cpp | 4 +- include/samurai/.print.hpp.swo | Bin 0 -> 12288 bytes include/samurai/.print.hpp.swp | Bin 0 -> 12288 bytes include/samurai/algorithm/graduation.hpp | 3 +- include/samurai/algorithm/update.hpp | 30 +++-- include/samurai/bc/apply_field_bc.hpp | 3 +- .../samurai/bc/polynomial_extrapolation.hpp | 8 +- include/samurai/field.hpp | 4 +- include/samurai/level_cell_array.hpp | 22 ++-- include/samurai/memory.hpp | 3 +- include/samurai/mesh.hpp | 18 +-- include/samurai/print.hpp | 107 +++++++++--------- include/samurai/stencil.hpp | 7 +- 37 files changed, 242 insertions(+), 231 deletions(-) create mode 100644 include/samurai/.print.hpp.swo create mode 100644 include/samurai/.print.hpp.swp diff --git a/demos/FiniteVolume/AMR_Burgers_Hat.cpp b/demos/FiniteVolume/AMR_Burgers_Hat.cpp index f1e2ef2b0..6eb989d2d 100644 --- a/demos/FiniteVolume/AMR_Burgers_Hat.cpp +++ b/demos/FiniteVolume/AMR_Burgers_Hat.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include "stencil_field.hpp" @@ -269,7 +270,7 @@ int main(int argc, char* argv[]) std::size_t ite_adapt = 0; while (true) { - fmt::print("\tmesh adaptation: {}\n", ite_adapt++); + samurai::io::print("\tmesh adaptation: {}\n", ite_adapt++); samurai::update_ghost(phi); tag.resize(); AMR_criteria(phi, tag); @@ -287,7 +288,7 @@ int main(int argc, char* argv[]) t = Tf; } - fmt::print("iteration {}: t = {}, dt = {}\n", nt++, t, dt); + samurai::io::print("iteration {}: t = {}, dt = {}\n", nt++, t, dt); // Numerical scheme samurai::update_ghost(phi); diff --git a/demos/FiniteVolume/BZ/bz_2d.cpp b/demos/FiniteVolume/BZ/bz_2d.cpp index 05d7efd64..35a51a8f9 100644 --- a/demos/FiniteVolume/BZ/bz_2d.cpp +++ b/demos/FiniteVolume/BZ/bz_2d.cpp @@ -313,7 +313,7 @@ int main() while (t < Tf) { - fmt::print(fmt::format("Iteration = {:4d}, t: {}\n", nb_ite, t)); + samurai::io::print("{}", fmt::format("Iteration = {:4d}, t: {}\n", nb_ite, t)); if (max_level > min_level) { @@ -323,12 +323,12 @@ int main() tic(); reaction(field, t, t + .5 * dt); auto duration = toc(); - fmt::print(fmt::format("first reaction: {}\n", duration)); + samurai::io::print("{}", fmt::format("first reaction: {}\n", duration)); tic(); RK4(field, dt, std::ceil(dt / dt_diffusion), update_bc, D_b, D_c); duration = toc(); - fmt::print(fmt::format("diffusion: {}\n", duration)); + samurai::io::print("{}", fmt::format("diffusion: {}\n", duration)); /* rock4_integration(double tini, double tend, int neq, double *u, func_rock fcn, double tol, int *info) @@ -336,7 +336,7 @@ int main() tic(); reaction(field, t + .5 * dt, t + dt); duration = toc(); - fmt::print(fmt::format("second reaction: {}\n", duration)); + samurai::io::print("{}", fmt::format("second reaction: {}\n", duration)); if (nsave == 20) { diff --git a/demos/FiniteVolume/BZ/bz_2d_AMR.cpp b/demos/FiniteVolume/BZ/bz_2d_AMR.cpp index 4cbde0f21..da3ff8964 100644 --- a/demos/FiniteVolume/BZ/bz_2d_AMR.cpp +++ b/demos/FiniteVolume/BZ/bz_2d_AMR.cpp @@ -691,7 +691,7 @@ int main() while (t < Tf) { - fmt::print(fmt::format("Iteration = {:4d}, t: {}\n", nb_ite, t)); + samurai::io::print("{}", fmt::format("Iteration = {:4d}, t: {}\n", nb_ite, t)); std::size_t idx = 0; @@ -710,12 +710,12 @@ int main() tic(); reaction(field, t, t + .5 * dt); auto duration = toc(); - fmt::print(fmt::format("first reaction: {}\n", duration)); + samurai::io::print("{}", fmt::format("first reaction: {}\n", duration)); tic(); RK4(field, dt, std::ceil(dt / dt_diffusion), update_bc_for_level, D_b, D_c); duration = toc(); - fmt::print(fmt::format("diffusion: {}\n", duration)); + samurai::io::print("{}", fmt::format("diffusion: {}\n", duration)); /* rock4_integration(double tini, double tend, int neq, double *u, func_rock fcn, double tol, int *info) @@ -723,7 +723,7 @@ int main() tic(); reaction(field, t + .5 * dt, t + dt); duration = toc(); - fmt::print(fmt::format("second reaction: {}\n", duration)); + samurai::io::print("{}", fmt::format("second reaction: {}\n", duration)); if (nsave == 20) { diff --git a/demos/FiniteVolume/advection_1d.cpp b/demos/FiniteVolume/advection_1d.cpp index 24128c118..9f09aa8ec 100644 --- a/demos/FiniteVolume/advection_1d.cpp +++ b/demos/FiniteVolume/advection_1d.cpp @@ -145,7 +145,7 @@ int main(int argc, char* argv[]) t = Tf; } - fmt::print("iteration {}: t = {}, dt = {}\n", nt++, t, dt); + samurai::io::print("iteration {}: t = {}, dt = {}\n", nt++, t, dt); samurai::update_ghost_mr(u); unp1.resize(); diff --git a/demos/FiniteVolume/advection_2d.cpp b/demos/FiniteVolume/advection_2d.cpp index 0cce3707c..e20930605 100644 --- a/demos/FiniteVolume/advection_2d.cpp +++ b/demos/FiniteVolume/advection_2d.cpp @@ -139,7 +139,7 @@ int main(int argc, char* argv[]) t = Tf; } - fmt::print("iteration {}: t = {}, dt = {}\n", nt++, t, dt); + samurai::io::print("iteration {}: t = {}, dt = {}\n", nt++, t, dt); samurai::update_ghost_mr(u); unp1.resize(); diff --git a/demos/FiniteVolume/advection_2d_user_bc.cpp b/demos/FiniteVolume/advection_2d_user_bc.cpp index ac978bacf..53fb06243 100644 --- a/demos/FiniteVolume/advection_2d_user_bc.cpp +++ b/demos/FiniteVolume/advection_2d_user_bc.cpp @@ -171,7 +171,7 @@ int main(int argc, char* argv[]) t = Tf; } - fmt::print("iteration {}: t = {}, dt = {}\n", nt++, t, dt); + samurai::io::print("iteration {}: t = {}, dt = {}\n", nt++, t, dt); samurai::update_ghost_mr(u); unp1.resize(); diff --git a/demos/FiniteVolume/burgers.cpp b/demos/FiniteVolume/burgers.cpp index 0562c7b76..826feec13 100644 --- a/demos/FiniteVolume/burgers.cpp +++ b/demos/FiniteVolume/burgers.cpp @@ -56,7 +56,7 @@ int main_dim(int argc, char* argv[]) using Box = samurai::Box; using point_t = typename Box::point_t; - fmt::print("------------------------- Burgers -------------------------\n"); + samurai::io::print("------------------------- Burgers -------------------------\n"); //--------------------// // Program parameters // @@ -177,7 +177,7 @@ int main_dim(int argc, char* argv[]) } else { - fmt::print(stderr, "Unmanaged initial solution '{}' .\n", init_sol); + samurai::io::eprint("Unmanaged initial solution '{}' .\n", init_sol); return EXIT_FAILURE; } } @@ -245,7 +245,7 @@ int main_dim(int argc, char* argv[]) dt += Tf - t; t = Tf; } - fmt::print("{}", fmt::format("iteration {}: t = {:.2f}, dt = {}", nt++, t, dt)); + samurai::io::print("{}", fmt::format("iteration {}: t = {:.2f}, dt = {}", nt++, t, dt)); // Mesh adaptation MRadaptation(mra_config); @@ -287,7 +287,7 @@ int main_dim(int argc, char* argv[]) { return exact_solution(coord, t); }); - fmt::print(", L2-error: {:.2e}", error); + samurai::io::print(", L2-error: {:.2e}", error); if (mesh.min_level() != mesh.max_level()) { @@ -298,18 +298,18 @@ int main_dim(int argc, char* argv[]) { return exact_solution(coord, t); }); - fmt::print(", L2-error (recons): {:.2e}", error); + samurai::io::print(", L2-error (recons): {:.2e}", error); } } - fmt::print("\n"); + samurai::io::print("\n"); } if constexpr (dim == 1) { - fmt::print("\n"); - fmt::print("Run the following command to view the results:\n"); - fmt::print("python <>/python/read_mesh.py {}_ite_ --field u level --start 0 --end {}\n", filename, nsave); + samurai::io::print("\n"); + samurai::io::print("Run the following command to view the results:\n"); + samurai::io::print("python <>/python/read_mesh.py {}_ite_ --field u level --start 0 --end {}\n", filename, nsave); } samurai::finalize(); diff --git a/demos/FiniteVolume/burgers_mra.cpp b/demos/FiniteVolume/burgers_mra.cpp index 9b9551d12..f449943e9 100644 --- a/demos/FiniteVolume/burgers_mra.cpp +++ b/demos/FiniteVolume/burgers_mra.cpp @@ -82,7 +82,7 @@ void run_simulation(Field& u, { auto& mesh = u.mesh(); - fmt::print("\nmax-level-flux enabled: {}\n", scheme.enable_max_level_flux()); + samurai::io::print("\nmax-level-flux enabled: {}\n", scheme.enable_max_level_flux()); if (scheme.enable_max_level_flux()) { @@ -188,14 +188,14 @@ void run_simulation(Field& u, { return hat_exact_solution(coord[0], t); }); - fmt::print("[w.r.t. exact, no recons] {}", error); + samurai::io::print("[w.r.t. exact, no recons] {}", error); error = samurai::L2_error(u_recons, [&](const auto& coord) { return hat_exact_solution(coord[0], t); }); - fmt::print(", [w.r.t. exact, recons] {}", error); + samurai::io::print(", [w.r.t. exact, recons] {}", error); } double error = 0; @@ -206,7 +206,7 @@ void run_simulation(Field& u, error += std::pow(u_max[cell] - u_recons[cell2], 2) * std::pow(cell.length, 1); }); error = std::sqrt(error); - fmt::print(", [w.r.t. max level, recons] {}", error); + samurai::io::print(", [w.r.t. max level, recons] {}", error); // Save the result if (t >= static_cast(nsave) * dt_save || t == Tf) @@ -219,7 +219,7 @@ void run_simulation(Field& u, nsave++; } - fmt::print("\n"); + samurai::io::print("\n"); } } @@ -231,7 +231,7 @@ int main(int argc, char* argv[]) auto& app = samurai::initialize("Finite volume example for the Burgers equation in 1d", argc, argv); - fmt::print("------------------------- Burgers -------------------------\n"); + samurai::io::print("------------------------- Burgers -------------------------\n"); //--------------------// // Program parameters // @@ -301,12 +301,12 @@ int main(int argc, char* argv[]) scheme.enable_max_level_flux(true); run_simulation(u, unp1, u_max, unp1_max, scheme, cfl, mra_config, init_sol, nfiles, path, filename, nsave); - fmt::print("\n"); - fmt::print("Run the following commands to view the results:\n"); - fmt::print("max-level-flux disabled:\n"); - fmt::print(" python ../python/read_mesh.py {}_recons_ite_ --field u --start 0 --end {}\n", filename, nsave); - fmt::print("max-level-flux enabled:\n"); - fmt::print(" python ../python/read_mesh.py {}_mlf_recons_ite_ --field u --start 0 --end {}\n", filename, nsave); + samurai::io::print("\n"); + samurai::io::print("Run the following commands to view the results:\n"); + samurai::io::print("max-level-flux disabled:\n"); + samurai::io::print(" python ../python/read_mesh.py {}_recons_ite_ --field u --start 0 --end {}\n", filename, nsave); + samurai::io::print("max-level-flux enabled:\n"); + samurai::io::print(" python ../python/read_mesh.py {}_mlf_recons_ite_ --field u --start 0 --end {}\n", filename, nsave); samurai::finalize(); return 0; diff --git a/demos/FiniteVolume/burgers_os.cpp b/demos/FiniteVolume/burgers_os.cpp index 56f27dfdb..262c8a7b2 100644 --- a/demos/FiniteVolume/burgers_os.cpp +++ b/demos/FiniteVolume/burgers_os.cpp @@ -51,7 +51,7 @@ void check_diff(auto& field, auto& lca_left, auto& lca_right) set( [&](auto& i, auto) { - fmt::print("Difference found !! {} {}\n", level, i); + samurai::io::print("Difference found !! {} {}\n", level, i); auto level_ = samurai::make_scalar_field("level", mesh); samurai::for_each_cell(mesh, [&](const auto& cell) @@ -67,11 +67,11 @@ void check_diff(auto& field, auto& lca_left, auto& lca_right) { if (xt::any(xt::abs(field(level, i) - field(level, i + (1 << level))) > 1e-13)) { - fmt::print("\nDifference found at level {} on interval {}:\n", level, i); - fmt::print("\tleft = {}\n", field(level, i)); - fmt::print("\tright = {}\n", field(level, i + (1 << level))); - fmt::print("\terror = {}\n", xt::abs(field(level, i) - field(level, i + (1 << level)))); - fmt::print("{}\n", fmt::streamed(mesh)); + samurai::io::print("\nDifference found at level {} on interval {}:\n", level, i); + samurai::io::print("\tleft = {}\n", field(level, i)); + samurai::io::print("\tright = {}\n", field(level, i + (1 << level))); + samurai::io::print("\terror = {}\n", xt::abs(field(level, i) - field(level, i + (1 << level)))); + samurai::io::print("{}\n", fmt::streamed(mesh)); auto level_ = samurai::make_scalar_field("level", mesh); samurai::for_each_cell(mesh, [&](const auto& cell) @@ -94,7 +94,7 @@ int main(int argc, char* argv[]) using Box = samurai::Box; using point_t = typename Box::point_t; - fmt::print("------------------------- Burgers 1D -------------------------\n"); + samurai::io::print("------------------------- Burgers 1D -------------------------\n"); //--------------------// // Program parameters // @@ -134,7 +134,7 @@ int main(int argc, char* argv[]) SAMURAI_PARSE(argc, argv); - fmt::print(" max_level = {} min_level = {}\n", max_level, min_level); + samurai::io::print(" max_level = {} min_level = {}\n", max_level, min_level); //--------------------// // Problem definition // @@ -199,7 +199,7 @@ int main(int argc, char* argv[]) dt += Tf - t; t = Tf; } - fmt::print("{}", fmt::format("iteration {}: t = {:.12f}, dt = {}", nt++, t, dt)); + samurai::io::print("{}", fmt::format("iteration {}: t = {:.12f}, dt = {}", nt++, t, dt)); // Mesh adaptation MRadaptation(mra_config); @@ -210,7 +210,7 @@ int main(int argc, char* argv[]) } catch (...) { - fmt::print("Exception caught in check_diff after adaptation\n"); + samurai::io::print("Exception caught in check_diff after adaptation\n"); samurai::finalize(); return 1; } @@ -228,7 +228,7 @@ int main(int argc, char* argv[]) } catch (...) { - fmt::print("Exception caught in check_diff after integration\n"); + samurai::io::print("Exception caught in check_diff after integration\n"); samurai::finalize(); return 1; } @@ -236,13 +236,13 @@ int main(int argc, char* argv[]) // Save the result if (nfiles == 0 || t >= static_cast(nsave) * dt_save || t == Tf) { - fmt::print(" (saving results)"); + samurai::io::print(" (saving results)"); std::string suffix = (nfiles != 1) ? fmt::format("_level_{}_{}_ite_{}", min_level, max_level, nsave) : ""; save(path, filename, u, suffix); nsave++; } - fmt::print("\n"); + samurai::io::print("\n"); } samurai::finalize(); diff --git a/demos/FiniteVolume/heat.cpp b/demos/FiniteVolume/heat.cpp index caa52a0f9..3844855da 100644 --- a/demos/FiniteVolume/heat.cpp +++ b/demos/FiniteVolume/heat.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -53,7 +54,7 @@ int main(int argc, char* argv[]) using Box = samurai::Box; using point_t = typename Box::point_t; - fmt::print("------------------------- Heat -------------------------\n"); + samurai::io::print("------------------------- Heat -------------------------\n"); //--------------------// // Program parameters // @@ -199,7 +200,7 @@ int main(int argc, char* argv[]) dt += Tf - t; t = Tf; } - fmt::print("{}", fmt::format("iteration {}: t = {:.2f}, dt = {}", nt++, t, dt)); + samurai::io::print("{}", fmt::format("iteration {}: t = {:.2f}, dt = {}", nt++, t, dt)); // Mesh adaptation MRadaptation(mra_config); @@ -232,16 +233,16 @@ int main(int argc, char* argv[]) { return exact_solution(coord, t, diff_coeff); }); - fmt::print(", L2-error: {:.2e}", error); + samurai::io::print(", L2-error: {:.2e}", error); } - fmt::print("\n"); + samurai::io::print("\n"); } if (!save_final_state_only && dim == 1) { - fmt::print("\n"); - fmt::print("Run the following command to view the results:\n"); - fmt::print("python <>/python/read_mesh.py {}_ite_ --field u level --start 1 --end {}\n", filename, nsave); + samurai::io::print("\n"); + samurai::io::print("Run the following command to view the results:\n"); + samurai::io::print("python <>/python/read_mesh.py {}_ite_ --field u level --start 1 --end {}\n", filename, nsave); } if (save_final_state_only) diff --git a/demos/FiniteVolume/heat_heterogeneous.cpp b/demos/FiniteVolume/heat_heterogeneous.cpp index 192c7fec3..513481fad 100644 --- a/demos/FiniteVolume/heat_heterogeneous.cpp +++ b/demos/FiniteVolume/heat_heterogeneous.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -41,7 +42,7 @@ int main(int argc, char* argv[]) using Box = samurai::Box; using point_t = typename Box::point_t; - fmt::print("------------------------- Heat -------------------------\n"); + samurai::io::print("------------------------- Heat -------------------------\n"); //--------------------// // Program parameters // @@ -176,7 +177,7 @@ int main(int argc, char* argv[]) dt += Tf - t; t = Tf; } - fmt::print("{}", fmt::format("iteration {}: t = {:.2f}, dt = {}", nt++, t, dt)); + samurai::io::print("{}", fmt::format("iteration {}: t = {:.2f}, dt = {}", nt++, t, dt)); // Mesh adaptation MRadaptation(mra_config); @@ -203,7 +204,7 @@ int main(int argc, char* argv[]) save(path, filename, u, fmt::format("_ite_{}", nsave++)); } - fmt::print("\n"); + samurai::io::print("\n"); } if (save_final_state_only) diff --git a/demos/FiniteVolume/heat_nonlinear.cpp b/demos/FiniteVolume/heat_nonlinear.cpp index 94bd2dc16..d1b92fbc4 100644 --- a/demos/FiniteVolume/heat_nonlinear.cpp +++ b/demos/FiniteVolume/heat_nonlinear.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -106,7 +107,7 @@ int main(int argc, char* argv[]) using Box = samurai::Box; using point_t = typename Box::point_t; - fmt::print("------------------------- Non-linear heat -------------------------\n"); + samurai::io::print("------------------------- Non-linear heat -------------------------\n"); /* Solves the non-linear heat equation @@ -227,7 +228,7 @@ int main(int argc, char* argv[]) dt += Tf - t; t = Tf; } - fmt::print("{}", fmt::format("iteration {}: t = {:.2f}, dt = {}", nt++, t, dt)); + samurai::io::print("{}", fmt::format("iteration {}: t = {:.2f}, dt = {}", nt++, t, dt)); // Update boundary conditions if (explicit_scheme) @@ -271,7 +272,7 @@ int main(int argc, char* argv[]) { return exact_solution(coords, t); }); - fmt::print(", L2-error: {:.2e}", error); + samurai::io::print(", L2-error: {:.2e}", error); // Save the result if (!save_final_state_only) @@ -279,7 +280,7 @@ int main(int argc, char* argv[]) save(path, filename, u, fmt::format("_ite_{}", nsave++)); } - fmt::print("\n"); + samurai::io::print("\n"); } if (save_final_state_only) diff --git a/demos/FiniteVolume/level_set.cpp b/demos/FiniteVolume/level_set.cpp index 07fe1ea3e..e05c6ba3f 100644 --- a/demos/FiniteVolume/level_set.cpp +++ b/demos/FiniteVolume/level_set.cpp @@ -331,7 +331,7 @@ int main(int argc, char* argv[]) std::size_t ite = 0; while (true) { - fmt::print("Mesh adaptation iteration {}\n", ite++); + samurai::io::print("Mesh adaptation iteration {}\n", ite++); tag.resize(); AMR_criteria(phi, tag); samurai::graduation(tag, stencil_grad); @@ -349,7 +349,7 @@ int main(int argc, char* argv[]) t = Tf; } - fmt::print("iteration {}: t = {}, dt = {}\n", nt++, t, dt); + samurai::io::print("iteration {}: t = {}, dt = {}\n", nt++, t, dt); // Numerical scheme samurai::update_ghost(phi, u); diff --git a/demos/FiniteVolume/level_set_from_scratch.cpp b/demos/FiniteVolume/level_set_from_scratch.cpp index c3192742a..703acda56 100644 --- a/demos/FiniteVolume/level_set_from_scratch.cpp +++ b/demos/FiniteVolume/level_set_from_scratch.cpp @@ -667,7 +667,7 @@ int main(int argc, char* argv[]) std::size_t ite = 0; while (true) { - fmt::print("Mesh adaptation iteration {}\n", ite++); + samurai::io::print("Mesh adaptation iteration {}\n", ite++); auto tag = samurai::make_scalar_field("tag", mesh); AMR_criteria(phi, tag); ::make_graduation(tag); @@ -686,7 +686,7 @@ int main(int argc, char* argv[]) t = Tf; } - fmt::print("iteration {}: t = {}, dt = {}\n", nt++, t, dt); + samurai::io::print("iteration {}: t = {}, dt = {}\n", nt++, t, dt); // Numerical scheme update_ghosts(phi, u); diff --git a/demos/FiniteVolume/lid_driven_cavity.cpp b/demos/FiniteVolume/lid_driven_cavity.cpp index 5da909f31..685e22826 100644 --- a/demos/FiniteVolume/lid_driven_cavity.cpp +++ b/demos/FiniteVolume/lid_driven_cavity.cpp @@ -148,7 +148,7 @@ int main(int argc, char* argv[]) auto box = samurai::Box({0, 0}, {1, 1}); - fmt::print("lid-driven cavity\n"); + samurai::io::print("lid-driven cavity\n"); //-------------------- 1 ----------------------------------------------------------------- // @@ -322,7 +322,7 @@ int main(int argc, char* argv[]) t = Tf; dt_has_changed = true; } - fmt::print("{}", fmt::format("iteration {}: t = {:.2f}, dt = {}", nt++, t, dt)); + samurai::io::print("{}", fmt::format("iteration {}: t = {:.2f}, dt = {}", nt++, t, dt)); // Mesh adaptation for Navier-Stokes if (min_level != max_level) @@ -338,9 +338,9 @@ int main(int argc, char* argv[]) zero.resize(); rhs.resize(); } - fmt::print(", levels {}-{}", min_level_np1, max_level_np1); + samurai::io::print(", levels {}-{}", min_level_np1, max_level_np1); } - fmt::print("\n"); + samurai::io::print("\n"); // Update solver if (mesh_has_changed || dt_has_changed) diff --git a/demos/FiniteVolume/linear_convection.cpp b/demos/FiniteVolume/linear_convection.cpp index ab182d3be..e12a167b0 100644 --- a/demos/FiniteVolume/linear_convection.cpp +++ b/demos/FiniteVolume/linear_convection.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -41,7 +42,7 @@ int main(int argc, char* argv[]) using Box = samurai::Box; using point_t = typename Box::point_t; - fmt::print("------------------------- Linear convection -------------------------\n"); + samurai::io::print("------------------------- Linear convection -------------------------\n"); //--------------------// // Program parameters // @@ -171,7 +172,7 @@ int main(int argc, char* argv[]) dt += Tf - t; t = Tf; } - fmt::print("{}", fmt::format("iteration {}: t = {:.2f}, dt = {}", nt++, t, dt)); + samurai::io::print("{}", fmt::format("iteration {}: t = {:.2f}, dt = {}", nt++, t, dt)); // Mesh adaptation MRadaptation(mra_config); @@ -226,14 +227,14 @@ int main(int argc, char* argv[]) } } - fmt::print("\n"); + samurai::io::print("\n"); } if constexpr (dim == 1) { - fmt::print("\n"); - fmt::print("Run the following command to view the results:\n"); - fmt::print("python <>/python/read_mesh.py {}_ite_ --field u level --start 0 --end {}\n", filename, nsave); + samurai::io::print("\n"); + samurai::io::print("Run the following command to view the results:\n"); + samurai::io::print("python <>/python/read_mesh.py {}_ite_ --field u level --start 0 --end {}\n", filename, nsave); } samurai::finalize(); diff --git a/demos/FiniteVolume/linear_convection_obstacle.cpp b/demos/FiniteVolume/linear_convection_obstacle.cpp index e7c66c43d..445ee990a 100644 --- a/demos/FiniteVolume/linear_convection_obstacle.cpp +++ b/demos/FiniteVolume/linear_convection_obstacle.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -39,7 +40,7 @@ int main(int argc, char* argv[]) using Config = samurai::MRConfig; using Mesh = samurai::MRMesh; - fmt::print("------------------------- Linear convection -------------------------\n"); + samurai::io::print("------------------------- Linear convection -------------------------\n"); //--------------------// // Program parameters // @@ -145,7 +146,7 @@ int main(int argc, char* argv[]) dt += Tf - t; t = Tf; } - fmt::print("{}", fmt::format("iteration {}: t = {:.2f}, dt = {}", nt++, t, dt)); + samurai::io::print("{}", fmt::format("iteration {}: t = {:.2f}, dt = {}", nt++, t, dt)); // Mesh adaptation @@ -185,7 +186,7 @@ int main(int argc, char* argv[]) } } - fmt::print("\n"); + samurai::io::print("\n"); } samurai::finalize(); diff --git a/demos/FiniteVolume/manual_block_matrix_assembly.cpp b/demos/FiniteVolume/manual_block_matrix_assembly.cpp index b7359c97d..18b7ec0be 100644 --- a/demos/FiniteVolume/manual_block_matrix_assembly.cpp +++ b/demos/FiniteVolume/manual_block_matrix_assembly.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -191,7 +192,7 @@ int main(int argc, char* argv[]) using Config = samurai::MRConfig; using Box = samurai::Box; - fmt::print("------------------------- Begin -------------------------\n"); + samurai::io::print("------------------------- Begin -------------------------\n"); std::size_t min_level = 3; std::size_t max_level = 3; @@ -275,18 +276,18 @@ int main(int argc, char* argv[]) // Insert the coefficients into the matrix assembly.assemble_matrix(J); - fmt::print("Useless ghost rows: "); + samurai::io::print("Useless ghost rows: "); // assembly.get<0, 0>().for_each_useless_ghost_row( assembly.for_each_useless_ghost_row( [](auto row) { - fmt::print("{} ", row); + samurai::io::print("{} ", row); }); - fmt::print("\n"); + samurai::io::print("\n"); Vec v = assembly.create_vector(u_e, aux_Ce, u_s); VecView(v, PETSC_VIEWER_STDOUT_(PETSC_COMM_SELF)); - fmt::print("\n"); + samurai::io::print("\n"); samurai::finalize(); return 0; diff --git a/demos/FiniteVolume/nagumo.cpp b/demos/FiniteVolume/nagumo.cpp index 35cf0c696..ca7ff0705 100644 --- a/demos/FiniteVolume/nagumo.cpp +++ b/demos/FiniteVolume/nagumo.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -41,7 +42,7 @@ int main(int argc, char* argv[]) using Box = samurai::Box; using point_t = typename Box::point_t; - fmt::print("------------------------- Nagumo -------------------------\n"); + samurai::io::print("------------------------- Nagumo -------------------------\n"); /** * Nagumo, or Fisher-KPP equation: @@ -203,7 +204,7 @@ int main(int argc, char* argv[]) dt += Tf - t; t = Tf; } - fmt::print("{}", fmt::format("iteration {}: t = {:.2f}, dt = {}", nt++, t, dt)); + samurai::io::print("{}", fmt::format("iteration {}: t = {:.2f}, dt = {}", nt++, t, dt)); // Mesh adaptation MRadaptation(mra_config); @@ -252,7 +253,7 @@ int main(int argc, char* argv[]) { return exact_solution(coord(0), t); }); - fmt::print(", L2-error: {:.2e}", error); + samurai::io::print(", L2-error: {:.2e}", error); // Save the result if (!save_final_state_only) @@ -260,14 +261,14 @@ int main(int argc, char* argv[]) save(path, filename, u, fmt::format("_ite_{}", nsave++)); } - fmt::print("\n"); + samurai::io::print("\n"); } if (!save_final_state_only && dim == 1) { - fmt::print("\n"); - fmt::print("Run the following command to view the results:\n"); - fmt::print("python <>/python/read_mesh.py {}_ite_ --field u level --start 1 --end {}\n", filename, nsave); + samurai::io::print("\n"); + samurai::io::print("Run the following command to view the results:\n"); + samurai::io::print("python <>/python/read_mesh.py {}_ite_ --field u level --start 1 --end {}\n", filename, nsave); } if (save_final_state_only) diff --git a/demos/FiniteVolume/scalar_burgers_2d.cpp b/demos/FiniteVolume/scalar_burgers_2d.cpp index 05a831291..d5b068e2e 100644 --- a/demos/FiniteVolume/scalar_burgers_2d.cpp +++ b/demos/FiniteVolume/scalar_burgers_2d.cpp @@ -264,7 +264,7 @@ int main(int argc, char* argv[]) t = Tf; } - fmt::print("iteration {}: t = {}, dt = {}\n", nt++, t, dt); + samurai::io::print("iteration {}: t = {}, dt = {}\n", nt++, t, dt); samurai::update_ghost_mr(u); unp1.resize(); diff --git a/demos/FiniteVolume/stokes_2d.cpp b/demos/FiniteVolume/stokes_2d.cpp index 20c9c9b85..06b281463 100644 --- a/demos/FiniteVolume/stokes_2d.cpp +++ b/demos/FiniteVolume/stokes_2d.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -21,7 +22,7 @@ template if (std::isnan(value) || std::isinf(value) || (abs(value) < 1e-300 && abs(value) != 0)) { is_nan_or_inf = true; - fmt::print("{}\n", fmt::streamed(f)); + samurai::io::print("{}\n", fmt::streamed(f)); break; } } @@ -203,11 +204,11 @@ int main(int argc, char* argv[]) // Stationary problem // //--------------------// - fmt::print("Problem solved: "); + samurai::io::print("Problem solved: "); if (test_case == "s") { - fmt::print("stationary\n"); + samurai::io::print("stationary\n"); if (filename.empty()) { filename = "stokes"; @@ -273,14 +274,14 @@ int main(int argc, char* argv[]) zero.fill(0); // Linear solver - fmt::print("Solving Stokes system...\n"); + samurai::io::print("Solving Stokes system...\n"); auto stokes_solver = samurai::petsc::make_solver(stokes); stokes_solver.set_unknowns(velocity, pressure); configure_solver(stokes_solver); stokes_solver.solve(f, zero); - fmt::print("{} iterations\n\n", stokes_solver.iterations()); + samurai::io::print("{} iterations\n\n", stokes_solver.iterations()); // Error double error = L2_error(velocity, @@ -292,10 +293,10 @@ int main(int argc, char* argv[]) auto v_y = -v_x; return samurai::Array{v_x, v_y}; }); - fmt::print("L2-error on the velocity: {:.2e}\n", error); + samurai::io::print("L2-error on the velocity: {:.2e}\n", error); // Save solution - fmt::print("Saving solution...\n"); + samurai::io::print("Saving solution...\n"); samurai::save(path, filename, mesh, velocity); samurai::save(path, "pressure", mesh, pressure); @@ -336,7 +337,7 @@ int main(int argc, char* argv[]) else if (test_case == "ns") { - fmt::print("non stationary\n"); + samurai::io::print("non stationary\n"); if (filename.empty()) { @@ -463,7 +464,7 @@ int main(int argc, char* argv[]) t_np1 = Tf; dt_has_changed = true; } - fmt::print("{}", fmt::format("iteration {}: t = {:.2f}, dt = {}", nt++, t_np1, dt)); + samurai::io::print("{}", fmt::format("iteration {}: t = {:.2f}, dt = {}", nt++, t_np1, dt)); // Mesh adaptation if (min_level != max_level) @@ -479,7 +480,7 @@ int main(int argc, char* argv[]) rhs.resize(); zero.resize(); } - fmt::print(", levels {}-{}", min_level_np1, max_level_np1); + samurai::io::print(", levels {}-{}", min_level_np1, max_level_np1); } // flush no-op with fmt @@ -535,7 +536,7 @@ int main(int argc, char* argv[]) { return exact_velocity(t_n, coord); }); - fmt::print(", L2-error: {:.2e}", error); + samurai::io::print(", L2-error: {:.2e}", error); // Divergence auto div_velocity = div(velocity); @@ -556,7 +557,7 @@ int main(int argc, char* argv[]) { return exact_velocity(t_n, coord); }); - fmt::print(", L2-error (recons): {:.2e}", error_recons); + samurai::io::print(", L2-error (recons): {:.2e}", error_recons); // Save if (nfiles != 1) { @@ -567,7 +568,7 @@ int main(int argc, char* argv[]) { nsave++; } - fmt::print("\n"); + samurai::io::print("\n"); } if (nfiles == 1) @@ -577,7 +578,7 @@ int main(int argc, char* argv[]) } else { - fmt::print(stderr, "Unknown test case. Allowed options are 's' = stationary, 'ns' = non-stationary.\n"); + samurai::io::eprint("Unknown test case. Allowed options are 's' = stationary, 'ns' = non-stationary.\n"); } samurai::finalize(); diff --git a/demos/multigrid/main.cpp b/demos/multigrid/main.cpp index d39ec11ce..7558c0c61 100644 --- a/demos/multigrid/main.cpp +++ b/demos/multigrid/main.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -168,9 +169,9 @@ int main(int argc, char* argv[]) } else { - fmt::print(stderr, "unknown value for argument --tc\n"); + samurai::io::eprint("unknown value for argument --tc\n"); } - fmt::print("Test case: {}\n", test_case_code); + samurai::io::print("Test case: {}\n", test_case_code); PetscOptionsGetBool(NULL, NULL, "--save_sol", &save_solution, NULL); PetscOptionsGetBool(NULL, NULL, "--save_mesh", &save_mesh, NULL); @@ -204,11 +205,11 @@ int main(int argc, char* argv[]) if (save_mesh) { - fmt::print("Saving mesh...\n"); + samurai::io::print("Saving mesh...\n"); samurai::save(path, "mesh", mesh); } - fmt::print("Unknowns: {}\n", (mesh.nb_cells() * n_comp)); + samurai::io::print("Unknowns: {}\n", (mesh.nb_cells() * n_comp)); //----------------// // Create problem // @@ -245,19 +246,19 @@ int main(int argc, char* argv[]) total_timer.Start(); - fmt::print("Setup solver...\n"); + samurai::io::print("Setup solver...\n"); setup_timer.Start(); solver.setup(); setup_timer.Stop(); - fmt::print("Solving...\n"); + samurai::io::print("Solving...\n"); solve_timer.Start(); solver.solve(source); solve_timer.Stop(); total_timer.Stop(); - fmt::print("{} iterations\n\n", solver.iterations()); + samurai::io::print("{} iterations\n\n", solver.iterations()); solver.destroy_petsc_objects(); @@ -265,16 +266,16 @@ int main(int argc, char* argv[]) // Print exec times // //--------------------// - fmt::print("---- Setup ----\n"); - fmt::print("CPU time : {}\n", fmt::streamed(setup_timer.CPU())); - fmt::print("Elapsed time: {}\n", fmt::streamed(setup_timer.Elapsed())); - fmt::print("---- Solve ----\n"); - fmt::print("CPU time : {}\n", fmt::streamed(solve_timer.CPU())); - fmt::print("Elapsed time: {}\n", fmt::streamed(solve_timer.Elapsed())); - fmt::print("---- Total ----\n"); - fmt::print("CPU time : {}\n", fmt::streamed(total_timer.CPU())); - fmt::print("Elapsed time: {}\n", fmt::streamed(total_timer.Elapsed())); - fmt::print("\n"); + samurai::io::print("---- Setup ----\n"); + samurai::io::print("CPU time : {}\n", fmt::streamed(setup_timer.CPU())); + samurai::io::print("Elapsed time: {}\n", fmt::streamed(setup_timer.Elapsed())); + samurai::io::print("---- Solve ----\n"); + samurai::io::print("CPU time : {}\n", fmt::streamed(solve_timer.CPU())); + samurai::io::print("Elapsed time: {}\n", fmt::streamed(solve_timer.Elapsed())); + samurai::io::print("---- Total ----\n"); + samurai::io::print("CPU time : {}\n", fmt::streamed(total_timer.CPU())); + samurai::io::print("Elapsed time: {}\n", fmt::streamed(total_timer.Elapsed())); + samurai::io::print("\n"); /*auto right_fluxes = samurai::make_vector_field("fluxes", mesh); samurai::DirectionVector right = {1, 0}; @@ -294,7 +295,7 @@ int main(int argc, char* argv[]) if (test_case->solution_is_known()) { double error = L2_error(solution, test_case->solution()); - fmt::print("L2-error: {:.2e}\n", error); + samurai::io::print("L2-error: {:.2e}\n", error); if (test_case_code == "poly") { @@ -307,7 +308,7 @@ int main(int argc, char* argv[]) // std::cout << "theoretical_bound: " << theoretical_bound << std::endl; if (error > theoretical_bound) { - fmt::print(stderr, "Convergence order failure: the error must be < {}.\n", theoretical_bound); + samurai::io::eprint("Convergence order failure: the error must be < {}.\n", theoretical_bound); } } } @@ -315,7 +316,7 @@ int main(int argc, char* argv[]) // Save solution if (save_solution) { - fmt::print("Saving solution...\n"); + samurai::io::print("Saving solution...\n"); samurai::save(path, filename, mesh, solution); } diff --git a/demos/tutorial/AMR_1D_Burgers/step_2/main.cpp b/demos/tutorial/AMR_1D_Burgers/step_2/main.cpp index eac549dc7..0cd490f5e 100644 --- a/demos/tutorial/AMR_1D_Burgers/step_2/main.cpp +++ b/demos/tutorial/AMR_1D_Burgers/step_2/main.cpp @@ -79,7 +79,7 @@ int main(int argc, char* argv[]) t = Tf; } - fmt::print("Iteration = {:4d} Time = {:5.4}\n", nt++, t); + samurai::io::print("Iteration = {:4d} Time = {:5.4}\n", nt++, t); update_sol(dt, phi, phi_np1); diff --git a/demos/tutorial/AMR_1D_Burgers/step_3/main.cpp b/demos/tutorial/AMR_1D_Burgers/step_3/main.cpp index 920d331aa..13ef9ea58 100644 --- a/demos/tutorial/AMR_1D_Burgers/step_3/main.cpp +++ b/demos/tutorial/AMR_1D_Burgers/step_3/main.cpp @@ -81,7 +81,7 @@ int main(int argc, char* argv[]) t = Tf; } - fmt::print("Iteration = {:4d} Time = {:5.4}\n", nt++, t); + samurai::io::print("Iteration = {:4d} Time = {:5.4}\n", nt++, t); update_sol(dt, phi, phi_np1); diff --git a/demos/tutorial/AMR_1D_Burgers/step_6/main.cpp b/demos/tutorial/AMR_1D_Burgers/step_6/main.cpp index 48d4573fd..5a8883770 100644 --- a/demos/tutorial/AMR_1D_Burgers/step_6/main.cpp +++ b/demos/tutorial/AMR_1D_Burgers/step_6/main.cpp @@ -90,14 +90,14 @@ int main(int argc, char* argv[]) t = Tf; } - fmt::print("Iteration = {:4d} Time = {:5.4}\n", nt++, t); + samurai::io::print("Iteration = {:4d} Time = {:5.4}\n", nt++, t); std::size_t i_adapt = 0; while (i_adapt < (max_level - min_level + 1)) { auto tag = samurai::make_scalar_field("tag", mesh); - fmt::print("adaptation iteration : {:4d}\n", i_adapt++); + samurai::io::print("adaptation iteration : {:4d}\n", i_adapt++); update_ghost(phi); AMR_criterion(phi, tag); make_graduation(tag); diff --git a/include/samurai/.print.hpp.swo b/include/samurai/.print.hpp.swo new file mode 100644 index 0000000000000000000000000000000000000000..c4e819f2d3095e693f8b0698833066d038af51b5 GIT binary patch literal 12288 zcmeI2UuYaf9LJ}kt?3_?Rv|tplSI!u$^A)6XnRdkW1@JH(3rGVim*&>=W=WJ&oMij zSVI(xuLVUgpbsJ{*g~rhzSPI&!AkL|B2^F{d=d(Z4+h6D( zC>-i5WcvmR1MO{Ijtu5~<^+OS2D5ErMxbSt`}NE$GP8|L^mKr5gX&at?e1-T`leGr$5>FbR%;gWv#o5Ig{Ofe!H7U4;As zu7hQ830wphz!EqM&VX0JDZs$f;0PE7o#5v^g!}}S!6on>SORYW30?qG;4s(?e%*~W z;9GDFd;zY2kHLpv9$4TRK)~<22>A|t4X%LC!JEJZonR;UekUPcg0o-&IKT#vfqrlw z*a5bKZ#oFM3f={8fY$*7)1V9N1AD=ZI|=y=oCM<_1?~l3?I7eb_!OK6=fDz}0|k%* zKWs-o;5s-DPJ&6$0sgpykelEJxC&kaFM$If3wps#%<~2CK6oBXfkB|={~@50R-jFR zMVil3mpR<8u`;Le`5i)$RuoxYm>ZTf?$ndXC9~{e(e#Y)RNTd2<^h~K$p=rPB1-4m_=5i*9ruH_?0o&LCo-B<&@hJ6sqiEZ7?5f^27Qc1x)fF)i z2DwQ?QLszUDz|G~Btold?P3Zp1L4wgAOv@%f#Zv((iu85L`80n*#S@XE7iVLx>$x8 z&$DTZe9DR;smN@)_rm7-^*m|FjrJ8yPli%)oaeothZ=;xNBM!qAWD0c*u!m~ljdS| zA6My0$1nL}k>Q0|EQV2H2(?~3*FH^Csg)tnHAD+|TlZKMNK2yl#COlV^0|q zlcko9){cr*=cds%X_tJAL~q|DZWhTZgO5jrAZZ_UTqarr2re6=p5sIT9zGqNm@rNp zof;qOr76+$U7}>eS!60G6j)z?WDxOopxU->C(WZ#*6S&DbzyEXakkA|*~4*c{$fqg z`mUn3DAmbaQ=rFvH&qU|0;*)eRkNIEDZ^#%6t*inn(^EQvZu77;#M7fAA0|G>p!j!vD^ZbU)gV8i#- zk@IexpN%4{QDM-jS-I-)n#(^iHHZx(??D94oTx?IM_7PQV0^f$e9}`BY}R4a!_j&| z)C+5J?78f?RpzeGvn3PWSQU$lBBhT{k7f5~M{O1$q)~I!tDP3sY*o_!Lf^sgTt1c6 Q#+UmeK4pQddcr4v0$g0B*8l(j literal 0 HcmV?d00001 diff --git a/include/samurai/.print.hpp.swp b/include/samurai/.print.hpp.swp new file mode 100644 index 0000000000000000000000000000000000000000..601a1ea5809f16d7bfcbdfb0fb0e6fbb55c0475b GIT binary patch literal 12288 zcmeI2J8T?97{@0>JVFu(gu+q+8ryLA65qp4Op@~>GB$_n0HxwT`?$UHp20C79-5JU*_+ol z^Zmb>*|jor#b?Ts^hmysAnhXLp>IB{zxQSb`D%d>f6ljrFDrgO>6Ry$RpGh*V*fz# zNMAA6H&7f%_jx`vSn!zXyG+-ZVQ6zMde*rY7v@lyYZS_iZslsGDCkzj@T)v-S8!b2 z68XC0q{mSuN&%%nI|X)<1O0tPS<~IsNq65n+pdu+Qwk^rlmbctrGQdEDWDWk3Md8s zrwRyX3wZ&)-4gk?96h(Jc}7|FPzopolmbctrGQdEDWDWk3Md7X0!jg;fKuQ;r~s=H zvUe*X_uY!g2Hd!lkng~^;0m||o&y#z z!65iz8zG;73*Z$n3&y|z*bnxB4)DtzguD+ffMswJWWgSA57-61zMYV>;AJoh4uMC& zgJ3JTavLEZfR}&|4uTBW3-*BT5!2VfS@0AX1^a=F^=_b&Qa~w?R$!GD3e;jI_Z(K? zG`g-tDAJlL-405Fn#M1gt8&3~qg1NeT5wUR#}ifVy1mq^^wJt0qFO4|Y~y)?+kron_rqxov%7e#8#$&z3St!{42McFxVQ|9y< z?TNL+< zY854NaL%?3+9Hg!q6z9|lK@H!H!*r~bK}~!(8NYZ749b8lXqy-qjYnts@F&?Rs4(u z4hQSzhR4@y(%BQe^-3j%H%O@zY%$H1PT7`mie@rvopwNbY^sNc6zj| zohToFLYtf_w+ys?=-Qt7jlN00zZ%&Mp}G)nu|Ma}^uc zvH7y&(s=31eIy52Y+8-c*iDUt^-5)gSDMVH+64=a;$PW{#4~H^A&Y|1TDNR6Pkg2L z704BA%(f=dZG*{etZgvC#>DW>KF;PnnxS=WINbGuns9(*5#c*-g(TVdiw}!Aymd~y zunT+>r;;bHoOj{=Y`DW34Teld&(}xRUH*xwA-o9+Hbmge40}Xl1Qqxu#Fv~bC*6+A z=1oRzT&*Vrj?7GrKbxD-E8OyUu3W`z^qS7y5~YvMjOPyI#ti0TOQYqO?VNJ;`MRL} X#lFMAy?iR_jZfK!J<5Dhx1q*wJ2PKq literal 0 HcmV?d00001 diff --git a/include/samurai/algorithm/graduation.hpp b/include/samurai/algorithm/graduation.hpp index 8c5c8a79e..1b4de3338 100644 --- a/include/samurai/algorithm/graduation.hpp +++ b/include/samurai/algorithm/graduation.hpp @@ -10,6 +10,7 @@ #include "../array_of_interval_and_point.hpp" #include "../cell_flag.hpp" #include "../mesh.hpp" +#include "../print.hpp" #include "../stencil.hpp" #include "../subset/node.hpp" #include "../subset/utils.hpp" @@ -302,7 +303,7 @@ namespace samurai isIntersectionEmpty); break; default: - fmt::print(stderr, "Warning: Unsupported number of periodic directions ({}) .\n", directions.size()); + samurai::io::eprint("Warning: Unsupported number of periodic directions ({}) .\n", directions.size()); } } } diff --git a/include/samurai/algorithm/update.hpp b/include/samurai/algorithm/update.hpp index c87fefbf3..b889f991e 100644 --- a/include/samurai/algorithm/update.hpp +++ b/include/samurai/algorithm/update.hpp @@ -15,6 +15,7 @@ #include "../field.hpp" #include "../numeric/prediction.hpp" #include "../numeric/projection.hpp" +#include "../print.hpp" #include "../subset/node.hpp" #include "../timers.hpp" #include "graduation.hpp" @@ -182,13 +183,12 @@ namespace samurai #ifdef SAMURAI_CHECK_NAN if (xt::any(xt::isnan(field(children_level, {ii_child, ii_child + 1}, index_child)))) { - fmt::print(stderr, "\n"); + samurai::io::eprint("\n"); #ifdef SAMURAI_WITH_MPI mpi::communicator world; - fmt::print(stderr, "[{}] ", world.rank()); + samurai::io::eprint("[{}] ", world.rank()); #endif - fmt::print( - stderr, + samurai::io::eprint( "NaN found in field({}, {}, {}) during projection of the B.C. into the cell at ({}, {}, {}) (dir = {}, layer = {})\n", children_level, ii_child, @@ -227,8 +227,7 @@ namespace samurai // However, it can happen in normal conditions if the domain has a hole, so we don't raise an error in that case. if (mesh.domain().is_box()) { - fmt::print( - stderr, + samurai::io::eprint( "No children found for the ghost at level {}, i = {}, index = {} during projection of the B.C. into the cell at level {}, i = {}, index = {}\n", proj_level, ii, @@ -338,19 +337,18 @@ namespace samurai #ifdef SAMURAI_CHECK_NAN if (xt::any(xt::isnan(field(pred_level - 1, i_cell >> 1, index >> 1)))) { - fmt::print(stderr, "\n"); + samurai::io::eprint("\n"); #ifdef SAMURAI_WITH_MPI mpi::communicator world; - fmt::print(stderr, "[{}] ", world.rank()); + samurai::io::eprint("[{}] ", world.rank()); #endif - fmt::print(stderr, - "NaN found in field({}, {}, {}) during prediction of the B.C. into the cell at ({}, {}, {})\n", - (pred_level - 1), - fmt::streamed(i_cell >> 1), - fmt::streamed(index >> 1), - pred_level, - ii, - fmt::streamed(index)); + samurai::io::eprint("NaN found in field({}, {}, {}) during prediction of the B.C. into the cell at ({}, {}, {})\n", + (pred_level - 1), + fmt::streamed(i_cell >> 1), + fmt::streamed(index >> 1), + pred_level, + ii, + fmt::streamed(index)); #ifndef NDEBUG samurai::save(fs::current_path(), "update_ghosts", {true, true}, field.mesh(), field); #endif diff --git a/include/samurai/bc/apply_field_bc.hpp b/include/samurai/bc/apply_field_bc.hpp index b9c220914..ab48a0378 100644 --- a/include/samurai/bc/apply_field_bc.hpp +++ b/include/samurai/bc/apply_field_bc.hpp @@ -6,6 +6,7 @@ #include "../boundary.hpp" #include "../concepts.hpp" +#include "../print.hpp" #include "polynomial_extrapolation.hpp" namespace samurai @@ -45,7 +46,7 @@ namespace samurai } else { - fmt::print(stderr, "Unknown BC type\n"); + samurai::io::eprint("Unknown BC type\n"); exit(EXIT_FAILURE); } } diff --git a/include/samurai/bc/polynomial_extrapolation.hpp b/include/samurai/bc/polynomial_extrapolation.hpp index 30e35bad3..912583aaa 100644 --- a/include/samurai/bc/polynomial_extrapolation.hpp +++ b/include/samurai/bc/polynomial_extrapolation.hpp @@ -2,6 +2,7 @@ // SPDX-License-Identifier: BSD-3-Clause #pragma once +#include "../print.hpp" #include "bc.hpp" #include #include @@ -52,10 +53,9 @@ namespace samurai { if (std::isnan(field_value(u, cells[c], field_i))) { - fmt::print(stderr, - "NaN detected in [{}] when applying polynomial extrapolation to fill the outer ghost [{}].\n", - fmt::streamed(cells[c]), - fmt::streamed(ghost)); + samurai::io::eprint("NaN detected in [{}] when applying polynomial extrapolation to fill the outer ghost [{}].\n", + fmt::streamed(cells[c]), + fmt::streamed(ghost)); // save(fs::current_path(), "nan_extrapolation", {true, true}, u.mesh(), u); exit(1); } diff --git a/include/samurai/field.hpp b/include/samurai/field.hpp index 0bbab4b9e..dcc968a3b 100644 --- a/include/samurai/field.hpp +++ b/include/samurai/field.hpp @@ -142,7 +142,7 @@ namespace samurai // std::cerr << "READ NaN at level " << level << ", in interval " << interval << std::endl; auto ii = i - interval_tmp.index; auto cell = this->derived_cast().mesh().get_cell(level, static_cast(ii), index...); - fmt::print(stderr, "READ NaN in {}\n", fmt::streamed(cell)); + samurai::io::eprint("READ NaN in {}\n", fmt::streamed(cell)); break; } } @@ -181,7 +181,7 @@ namespace samurai // std::cerr << "READ NaN at level " << level << ", in interval " << interval << std::endl; auto ii = i - interval_tmp.index; auto cell = this->derived_cast().mesh().get_cell(level, static_cast(ii), index); - fmt::print(stderr, "READ NaN in {}\n", fmt::streamed(cell)); + samurai::io::eprint("READ NaN in {}\n", fmt::streamed(cell)); break; } } diff --git a/include/samurai/level_cell_array.hpp b/include/samurai/level_cell_array.hpp index 0d8e36404..0eb2e2410 100644 --- a/include/samurai/level_cell_array.hpp +++ b/include/samurai/level_cell_array.hpp @@ -14,6 +14,7 @@ #include #endif +#include "print.hpp" #include #include #include @@ -640,9 +641,9 @@ namespace samurai #ifndef NDEBUG if (offset < 0) { - fmt::print(stderr, "Error: Interval not found: level {}, i = {}, index = ", m_level, fmt::streamed(interval)); - ((fmt::print(stderr, "{} ", index)), ...); - fmt::print(stderr, "\n"); + samurai::io::eprint("Error: Interval not found: level {}, i = {}, index = ", m_level, fmt::streamed(interval)); + ((samurai::io::eprint("{} ", index)), ...); + samurai::io::eprint("\n"); } #endif return m_cells[0][static_cast(offset)]; @@ -661,12 +662,12 @@ namespace samurai #ifndef NDEBUG if (offset < 0) { - fmt::print(stderr, "Error: Interval not found: level {}, i = {}, index =", m_level, fmt::streamed(interval)); + samurai::io::eprint("Error: Interval not found: level {}, i = {}, index =", m_level, fmt::streamed(interval)); for (std::size_t d = 0; d < dim - 1; ++d) { - fmt::print(stderr, "{} ", index[d]); + samurai::io::eprint("{} ", index[d]); } - fmt::print(stderr, "\n"); + samurai::io::eprint("\n"); } #endif return m_cells[0][static_cast(offset)]; @@ -679,12 +680,12 @@ namespace samurai #ifndef NDEBUG if (offset < 0) { - fmt::print(stderr, "Error: Interval not found: level {}, coord = ", m_level); + samurai::io::eprint("Error: Interval not found: level {}, coord = ", m_level); for (std::size_t d = 0; d < dim; ++d) { - fmt::print(stderr, "{} ", coord[d]); + samurai::io::eprint("{} ", coord[d]); } - fmt::print(stderr, "\n"); + samurai::io::eprint("\n"); } #endif return m_cells[0][static_cast(offset)]; @@ -1091,8 +1092,7 @@ namespace samurai const double warning_tol = 0.5; if (scaling_factor > 0 && xt::any(xt::abs(approx_box.length() - box.length()) >= warning_tol * box.length())) { - fmt::print( - stderr, + samurai::io::eprint( "Warning: the box {} is poorly approximated by {}. This is due to a too large scaling factor ({}). Choose a smaller value for a better approximation.\n", fmt::streamed(box), fmt::streamed(approx_box), diff --git a/include/samurai/memory.hpp b/include/samurai/memory.hpp index 46a80ddce..73ed78348 100644 --- a/include/samurai/memory.hpp +++ b/include/samurai/memory.hpp @@ -5,6 +5,7 @@ #include +#include "print.hpp" #include #include @@ -48,7 +49,7 @@ namespace samurai std::size_t mem_id = memory_usage(mesh[id]); if (verbose) { - fmt::print("Mesh {}: {}\n", id, mem_id); + samurai::io::print("Mesh {}: {}\n", id, mem_id); } mem += mem_id; } diff --git a/include/samurai/mesh.hpp b/include/samurai/mesh.hpp index 02810522f..73f1b7a4a 100644 --- a/include/samurai/mesh.hpp +++ b/include/samurai/mesh.hpp @@ -12,6 +12,7 @@ #include "cell_array.hpp" #include "cell_list.hpp" #include "domain_builder.hpp" +#include "print.hpp" #include "static_algorithm.hpp" #include "stencil.hpp" #include "subset/node.hpp" @@ -293,7 +294,7 @@ namespace samurai m_periodic.fill(false); #ifdef SAMURAI_WITH_MPI - fmt::print(stderr, "MPI is not implemented with DomainBuilder.\n"); + samurai::io::eprint("MPI is not implemented with DomainBuilder.\n"); std::exit(1); // partition_mesh(start_level, b); // load_balancing(); @@ -483,13 +484,12 @@ namespace samurai { if (box.min_length() < 2 * largest_cell_length * config::max_stencil_width) { - fmt::print( - stderr, + samurai::io::eprint( "The hole {} is too small to apply the BC at level {} with the given scaling factor. We need to be able to construct {} ghosts in each direction inside the hole.\n", fmt::streamed(box), min_level_bc, (2 * config::max_stencil_width)); - fmt::print(stderr, "Please choose a smaller scaling factor or enlarge the hole.\n"); + samurai::io::eprint("Please choose a smaller scaling factor or enlarge the hole.\n"); std::exit(1); } } @@ -1155,7 +1155,7 @@ namespace samurai world.barrier(); if (rank == 0) { - fmt::print("---------------- k = {} ----------------\n", k); + samurai::io::print("---------------- k = {} ----------------\n", k); } mpi::all_gather(world, load, loads); @@ -1185,7 +1185,7 @@ namespace samurai load_transfer(load_fluxes); - fmt::print("{}: load = {}, load_np1 = {}\n", rank, load, load_np1); + samurai::io::print("{}: load = {}, load_np1 = {}\n", rank, load, load_np1); load = static_cast(load_np1); } @@ -1197,7 +1197,7 @@ namespace samurai { #ifdef SAMURAI_WITH_MPI mpi::communicator world; - fmt::print("{}: ", world.rank()); + samurai::io::print("{}: ", world.rank()); for (std::size_t i_rank = 0; i_rank < m_mpi_neighbourhood.size(); ++i_rank) { auto neighbour = m_mpi_neighbourhood[i_rank]; @@ -1207,9 +1207,9 @@ namespace samurai else if (load_fluxes[i_rank] > 0) // must receive load from the neighbour { } - fmt::print("--> {}: {}, ", neighbour.rank, load_fluxes[i_rank]); + samurai::io::print("--> {}: {}, ", neighbour.rank, load_fluxes[i_rank]); } - fmt::print("\n"); + samurai::io::print("\n"); #endif } diff --git a/include/samurai/print.hpp b/include/samurai/print.hpp index ae8cee4d0..84ba8bdfb 100644 --- a/include/samurai/print.hpp +++ b/include/samurai/print.hpp @@ -16,6 +16,7 @@ namespace samurai { namespace io { + // Tags & helpers struct all_t { }; @@ -32,97 +33,93 @@ namespace samurai inline constexpr all_t all{}; inline constexpr root_t root{}; - inline constexpr rank_t rank(int value) + inline constexpr rank_t rank(int v) { - return rank_t{value}; + return {v}; } -#ifdef SAMURAI_WITH_MPI inline int current_rank() { +#ifdef SAMURAI_WITH_MPI int r = 0; MPI_Comm_rank(MPI_COMM_WORLD, &r); return r; - } #else - inline int current_rank() - { return 0; - } #endif - - // stdout printers - template - inline void print(all_t, fmt::format_string fmt, Args&&... args) - { - fmt::print(fmt, std::forward(args)...); } - template - inline void print(root_t, fmt::format_string fmt, Args&&... args) + namespace detail { - if (current_rank() == 0) + inline bool allow_default_print() { - fmt::print(fmt, std::forward(args)...); +#ifdef SAMURAI_WITH_MPI + return !(samurai::args::print_root_only && current_rank() != 0); +#else + return true; +#endif } - } - template - inline void print(rank_t r, fmt::format_string fmt, Args&&... args) - { - if (current_rank() == r.value) + // Default (non-scoped) printing helper + template + inline void do_print(FILE* s, fmt::format_string f, Args&&... a) { - fmt::print(fmt, std::forward(args)...); + if (allow_default_print()) + { + fmt::print(s, f, std::forward(a)...); + } } - } - template - inline void print(fmt::format_string fmt, Args&&... args) - { -#ifdef SAMURAI_WITH_MPI - if (samurai::args::print_root_only && current_rank() != 0) + inline bool should_print(all_t) { - return; + return true; + } + + inline bool should_print(root_t) + { + return current_rank() == 0; + } + + inline bool should_print(rank_t r) + { + return current_rank() == r.value; + } + + // Scoped printing helper + template + inline void do_print(FILE* s, Scope sc, fmt::format_string f, Args&&... a) + { + if (should_print(sc)) + { + fmt::print(s, f, std::forward(a)...); + } } -#endif - fmt::print(fmt, std::forward(args)...); } - // stderr printers + // stdout template - inline void eprint(all_t, fmt::format_string fmt, Args&&... args) + inline void print(fmt::format_string f, Args&&... a) { - fmt::print(stderr, fmt, std::forward(args)...); + detail::do_print(stdout, f, std::forward(a)...); } - template - inline void eprint(root_t, fmt::format_string fmt, Args&&... args) + template + inline void print(Scope sc, fmt::format_string f, Args&&... a) { - if (current_rank() == 0) - { - fmt::print(stderr, fmt, std::forward(args)...); - } + detail::do_print(stdout, sc, f, std::forward(a)...); } + // stderr template - inline void eprint(rank_t r, fmt::format_string fmt, Args&&... args) + inline void eprint(fmt::format_string f, Args&&... a) { - if (current_rank() == r.value) - { - fmt::print(stderr, fmt, std::forward(args)...); - } + detail::do_print(stderr, f, std::forward(a)...); } - template - inline void eprint(fmt::format_string fmt, Args&&... args) + template + inline void eprint(Scope sc, fmt::format_string f, Args&&... a) { -#ifdef SAMURAI_WITH_MPI - if (samurai::args::print_root_only && current_rank() != 0) - { - return; - } -#endif - fmt::print(stderr, fmt, std::forward(args)...); + detail::do_print(stderr, sc, f, std::forward(a)...); } } // namespace io } // namespace samurai diff --git a/include/samurai/stencil.hpp b/include/samurai/stencil.hpp index 4a64f8651..885ea4813 100644 --- a/include/samurai/stencil.hpp +++ b/include/samurai/stencil.hpp @@ -1,5 +1,6 @@ #pragma once #include "indices.hpp" +#include "print.hpp" #include "static_algorithm.hpp" #include #include @@ -593,7 +594,7 @@ namespace samurai #ifndef NDEBUG if (origin_cell.index > 0 && static_cast(origin_cell.index) > m_mesh.nb_cells()) // nb_cells() is very costly { - fmt::print("Cell not found in the mesh: {}\n", fmt::streamed(origin_cell)); + samurai::io::eprint("Cell not found in the mesh: {}\n", fmt::streamed(origin_cell)); assert(false); } #endif @@ -630,7 +631,9 @@ namespace samurai #ifndef NDEBUG if (cell.index > 0 && static_cast(cell.index) > m_mesh.nb_cells()) // nb_cells() is very costly { - fmt::print("Non-existing neighbour for {} in the direction {}\n", fmt::streamed(origin_cell), fmt::streamed(dir)); + samurai::io::eprint("Non-existing neighbour for {} in the direction {}\n", + fmt::streamed(origin_cell), + fmt::streamed(dir)); // save(fs::current_path(), "mesh_error", {true, true}, m_mesh); exit(1); } From 58dff181affe4c88408cee0c81e49c31d53c48d8 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Thu, 11 Sep 2025 16:57:30 +0000 Subject: [PATCH 05/37] feat: remove dont redirect output --- include/samurai/arguments.hpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/include/samurai/arguments.hpp b/include/samurai/arguments.hpp index 4becb1948..cfa5339ff 100644 --- a/include/samurai/arguments.hpp +++ b/include/samurai/arguments.hpp @@ -10,8 +10,7 @@ namespace samurai { static bool timers = false; #ifdef SAMURAI_WITH_MPI - static bool dont_redirect_output = false; - static bool print_root_only = false; + static bool print_root_only = true; #endif static int finer_level_flux = 0; static bool refine_boundary = false; @@ -26,9 +25,6 @@ namespace samurai inline void read_samurai_arguments(CLI::App& app, int& argc, char**& argv) { #ifdef SAMURAI_WITH_MPI - app.add_flag("--dont-redirect-output", args::dont_redirect_output, "Redirect the output for all ranks different of 0") - ->capture_default_str() - ->group("IO"); app.add_flag("--print-root-only", args::print_root_only, "Print on root rank only by default for samurai::io::print/eprint") ->capture_default_str() ->group("IO"); From 90e50a03e231afe38e901f975620426497721c09 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Thu, 11 Sep 2025 17:40:19 +0000 Subject: [PATCH 06/37] fix: resolve issue on flag --- include/samurai/.print.hpp.swn | Bin 0 -> 12288 bytes include/samurai/arguments.hpp | 16 ++++++++-------- include/samurai/print.hpp | 2 +- include/samurai/samurai.hpp | 12 ++---------- 4 files changed, 11 insertions(+), 19 deletions(-) create mode 100644 include/samurai/.print.hpp.swn diff --git a/include/samurai/.print.hpp.swn b/include/samurai/.print.hpp.swn new file mode 100644 index 0000000000000000000000000000000000000000..564402f8cb21bddc832b92d9f8cbdbe90a485a7d GIT binary patch literal 12288 zcmeI2UuYaf9LJ}kt?3_?Rv|tplSI#)++8jyq3tzEjfvt(LSxd}QiNr4JC|F#e~#JN z#2TVl^s%4_2J}Hh1zTwK!I%2jJXk3{Rip~ygHJ+1@j=9g>UVbcZtrr5iAe;N8Te#( z=g)6`^PTz4?va_!KU*B9hjP6H=^jFse!NooA;nND){SUxxQp>iD&!r zef{}Ez4>f!f4;x9%}bHN9-ldZV3xsb+n5$;S>b*yGmFe@JyShcZno^m9?LD+fyrz2 zdaA;5Wv)`Kw)UfQv;tazl@!=R_V@MXRY_N82i>>#_)3*@o>o9BpcT*xXa%$aS^=$q zRzNH8KUF|hw~?1Iw%g+IEyUMt%dYXGzGwxs0$KsBfL1^&pcT*xXa%$aS^=$qRzNH8 zA5?&ugxrrG{}0~|=kfpl+VB7CcN20Rd<5PBZ-cYI0u?X;j(~&U0C*5Q0Cs^k@Y`L4 z`~q%(C2$#B0vEv|I0w#xSHNk&z|-Ie7y|9!=RJh{1eU;M@E%wMZvhFO2b171*bRQ& zjW*z0a234tx!+g3rO5zy-QY29JS0 za39zKwu5il2)PE{1#f`Y0RvN@1MCBP!Oc4f`3#%_V;}|Y1z+tTe;3l{RUIj0L10V}B;1=fjB6uG>2PVM)Q1kx~&`B%M zqQC;}>7g!jxL;)@PUG`Cgd!~~vb-=iEUDkACzDHN*@c4X8R5yDZeN;Qhz#{h8Cu3g znuS8y6LUo zB{UP-gRLRek+Pji;fbo5p~x?*LC0$DVkU`k5%&HXOUExAnzu&3ko4 z41_^$(ohua612kYDi?{+s#>d;_2=*9UP=0H_PmRC;OFZ-z;4$ z!?fqwv`Ic?#gJ5_H{5%EWBq!bG~{}Fm12X#QwKfQ?xj_0rQp^tTzKQn8742Yz?Sj) z-NfqMNZhM|EnBm#+q9~LWjY!;O1oXp&HCy!XQtO$v|Zdatuj#-8dJP>qj~J&w$Djp zvAU0|baclr`9gu=g;^+sQDO+SUOd-6LsO~cA1$7L*`Y zxaX~CqP1@5-1_Q<4%Qt*03Bm9K262jyC0TB9VCkgpRMyGd8~clVlhXj&S@v2AaJnZ z`|8MfC(h4C5mv7-;8d+#WoXsqpO_lJhSB3e1kRkOMchYNfKOn2xT<{8RTXT;VbsIX zdP39-Yhv_dcFZbq*XP-y32&^j#YKVA$EQZK`?Di93lP$%IpS5%2y3PyX::infinity(); - static double regularity = std::numeric_limits::infinity(); - static bool rel_detail = false; + inline double epsilon = std::numeric_limits::infinity(); + inline double regularity = std::numeric_limits::infinity(); + inline bool rel_detail = false; } inline void read_samurai_arguments(CLI::App& app, int& argc, char**& argv) diff --git a/include/samurai/print.hpp b/include/samurai/print.hpp index 84ba8bdfb..b84a889e8 100644 --- a/include/samurai/print.hpp +++ b/include/samurai/print.hpp @@ -10,7 +10,7 @@ #include #endif -#include "arguments.hpp" +#include namespace samurai { diff --git a/include/samurai/samurai.hpp b/include/samurai/samurai.hpp index 4a94741d5..87837a31e 100644 --- a/include/samurai/samurai.hpp +++ b/include/samurai/samurai.hpp @@ -4,8 +4,6 @@ #ifdef SAMURAI_WITH_MPI #include -#include -#include namespace mpi = boost::mpi; #endif #ifdef SAMURAI_WITH_PETSC @@ -18,7 +16,7 @@ namespace mpi = boost::mpi; namespace samurai { - static CLI::App app; + inline CLI::App app; #ifdef SAMURAI_WITH_PETSC #define SAMURAI_PARSE(argc, argv) \ @@ -69,13 +67,7 @@ namespace samurai #ifdef SAMURAI_WITH_MPI MPI_Init(&argc, &argv); - // Redirect std::cout to /dev/null for non-root ranks, unless disabled by '--dont-redirect-output' - mpi::communicator world; - if (!args::dont_redirect_output && world.rank() != 0) // cppcheck-suppress knownConditionTrueFalse - { - static std::ofstream null_stream("/dev/null"); - std::cout.rdbuf(null_stream.rdbuf()); - } + // No output redirection: fmt wrapper handles output uniformly across ranks #endif times::timers.start("total runtime"); From 56ffba402046c9c483353dbbe2748427df5b3ae3 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Thu, 11 Sep 2025 17:49:17 +0000 Subject: [PATCH 07/37] feat: use samurai wrapper print for demos --- demos/FiniteVolume/AMR_Burgers_Hat.cpp | 2 +- demos/FiniteVolume/BZ/bz_2d.cpp | 2 +- demos/FiniteVolume/BZ/bz_2d_AMR.cpp | 2 +- demos/FiniteVolume/advection_1d.cpp | 2 +- demos/FiniteVolume/advection_2d.cpp | 2 +- demos/FiniteVolume/advection_2d_user_bc.cpp | 2 +- demos/FiniteVolume/burgers.cpp | 2 +- demos/FiniteVolume/burgers_mra.cpp | 2 +- demos/FiniteVolume/burgers_os.cpp | 2 +- demos/FiniteVolume/heat.cpp | 2 +- demos/FiniteVolume/heat_heterogeneous.cpp | 2 +- demos/FiniteVolume/heat_nonlinear.cpp | 2 +- demos/FiniteVolume/level_set.cpp | 2 +- demos/FiniteVolume/level_set_from_scratch.cpp | 2 +- demos/FiniteVolume/lid_driven_cavity.cpp | 2 +- demos/FiniteVolume/linear_convection.cpp | 2 +- demos/FiniteVolume/linear_convection_obstacle.cpp | 2 +- demos/FiniteVolume/nagumo.cpp | 2 +- demos/FiniteVolume/scalar_burgers_2d.cpp | 2 +- demos/FiniteVolume/stokes_2d.cpp | 2 +- 20 files changed, 20 insertions(+), 20 deletions(-) diff --git a/demos/FiniteVolume/AMR_Burgers_Hat.cpp b/demos/FiniteVolume/AMR_Burgers_Hat.cpp index 6eb989d2d..ddff4fdee 100644 --- a/demos/FiniteVolume/AMR_Burgers_Hat.cpp +++ b/demos/FiniteVolume/AMR_Burgers_Hat.cpp @@ -288,7 +288,7 @@ int main(int argc, char* argv[]) t = Tf; } - samurai::io::print("iteration {}: t = {}, dt = {}\n", nt++, t, dt); + samurai::io::print(samurai::io::root, \"iteration {}: t = {}, dt = {}\\n\", nt++, t, dt); // Numerical scheme samurai::update_ghost(phi); diff --git a/demos/FiniteVolume/BZ/bz_2d.cpp b/demos/FiniteVolume/BZ/bz_2d.cpp index 35a51a8f9..17b2b0257 100644 --- a/demos/FiniteVolume/BZ/bz_2d.cpp +++ b/demos/FiniteVolume/BZ/bz_2d.cpp @@ -313,7 +313,7 @@ int main() while (t < Tf) { - samurai::io::print("{}", fmt::format("Iteration = {:4d}, t: {}\n", nb_ite, t)); + samurai::io::print(samurai::io::root, "{}", fmt::format("Iteration = {:4d}, t: {}\n", nb_ite, t)); if (max_level > min_level) { diff --git a/demos/FiniteVolume/BZ/bz_2d_AMR.cpp b/demos/FiniteVolume/BZ/bz_2d_AMR.cpp index da3ff8964..9a82ff6b6 100644 --- a/demos/FiniteVolume/BZ/bz_2d_AMR.cpp +++ b/demos/FiniteVolume/BZ/bz_2d_AMR.cpp @@ -691,7 +691,7 @@ int main() while (t < Tf) { - samurai::io::print("{}", fmt::format("Iteration = {:4d}, t: {}\n", nb_ite, t)); + samurai::io::print(samurai::io::root, "{}", fmt::format("Iteration = {:4d}, t: {}\n", nb_ite, t)); std::size_t idx = 0; diff --git a/demos/FiniteVolume/advection_1d.cpp b/demos/FiniteVolume/advection_1d.cpp index 9f09aa8ec..3f3ae82ed 100644 --- a/demos/FiniteVolume/advection_1d.cpp +++ b/demos/FiniteVolume/advection_1d.cpp @@ -145,7 +145,7 @@ int main(int argc, char* argv[]) t = Tf; } - samurai::io::print("iteration {}: t = {}, dt = {}\n", nt++, t, dt); + samurai::io::print(samurai::io::root, "iteration {}: t = {}, dt = {}\n", nt++, t, dt); samurai::update_ghost_mr(u); unp1.resize(); diff --git a/demos/FiniteVolume/advection_2d.cpp b/demos/FiniteVolume/advection_2d.cpp index e20930605..c7f51db96 100644 --- a/demos/FiniteVolume/advection_2d.cpp +++ b/demos/FiniteVolume/advection_2d.cpp @@ -139,7 +139,7 @@ int main(int argc, char* argv[]) t = Tf; } - samurai::io::print("iteration {}: t = {}, dt = {}\n", nt++, t, dt); + samurai::io::print(samurai::io::root, "iteration {}: t = {}, dt = {}\n", nt++, t, dt); samurai::update_ghost_mr(u); unp1.resize(); diff --git a/demos/FiniteVolume/advection_2d_user_bc.cpp b/demos/FiniteVolume/advection_2d_user_bc.cpp index 53fb06243..eb860634b 100644 --- a/demos/FiniteVolume/advection_2d_user_bc.cpp +++ b/demos/FiniteVolume/advection_2d_user_bc.cpp @@ -171,7 +171,7 @@ int main(int argc, char* argv[]) t = Tf; } - samurai::io::print("iteration {}: t = {}, dt = {}\n", nt++, t, dt); + samurai::io::print(samurai::io::root, "iteration {}: t = {}, dt = {}\n", nt++, t, dt); samurai::update_ghost_mr(u); unp1.resize(); diff --git a/demos/FiniteVolume/burgers.cpp b/demos/FiniteVolume/burgers.cpp index 826feec13..8854ab75d 100644 --- a/demos/FiniteVolume/burgers.cpp +++ b/demos/FiniteVolume/burgers.cpp @@ -245,7 +245,7 @@ int main_dim(int argc, char* argv[]) dt += Tf - t; t = Tf; } - samurai::io::print("{}", fmt::format("iteration {}: t = {:.2f}, dt = {}", nt++, t, dt)); + samurai::io::print(samurai::io::root, "{}", fmt::format("iteration {}: t = {:.2f}, dt = {}", nt++, t, dt)); // Mesh adaptation MRadaptation(mra_config); diff --git a/demos/FiniteVolume/burgers_mra.cpp b/demos/FiniteVolume/burgers_mra.cpp index f449943e9..dadcb1740 100644 --- a/demos/FiniteVolume/burgers_mra.cpp +++ b/demos/FiniteVolume/burgers_mra.cpp @@ -162,7 +162,7 @@ void run_simulation(Field& u, dt += Tf - t; t = Tf; } - std::cout << fmt::format("iteration {}: t = {:.2f}, dt = {}", nt++, t, dt) << std::flush; + samurai::io::print(samurai::io::root, "iteration {}: t = {:.2f}, dt = {}\n", nt++, t, dt); // Mesh adaptation MRadaptation(mra_config); diff --git a/demos/FiniteVolume/burgers_os.cpp b/demos/FiniteVolume/burgers_os.cpp index 262c8a7b2..40112a3f0 100644 --- a/demos/FiniteVolume/burgers_os.cpp +++ b/demos/FiniteVolume/burgers_os.cpp @@ -199,7 +199,7 @@ int main(int argc, char* argv[]) dt += Tf - t; t = Tf; } - samurai::io::print("{}", fmt::format("iteration {}: t = {:.12f}, dt = {}", nt++, t, dt)); + samurai::io::print(samurai::io::root, "{}", fmt::format("iteration {}: t = {:.12f}, dt = {}", nt++, t, dt)); // Mesh adaptation MRadaptation(mra_config); diff --git a/demos/FiniteVolume/heat.cpp b/demos/FiniteVolume/heat.cpp index 3844855da..5fc690966 100644 --- a/demos/FiniteVolume/heat.cpp +++ b/demos/FiniteVolume/heat.cpp @@ -200,7 +200,7 @@ int main(int argc, char* argv[]) dt += Tf - t; t = Tf; } - samurai::io::print("{}", fmt::format("iteration {}: t = {:.2f}, dt = {}", nt++, t, dt)); + samurai::io::print(samurai::io::root, "{}", fmt::format("iteration {}: t = {:.2f}, dt = {}", nt++, t, dt)); // Mesh adaptation MRadaptation(mra_config); diff --git a/demos/FiniteVolume/heat_heterogeneous.cpp b/demos/FiniteVolume/heat_heterogeneous.cpp index 513481fad..7269c3ce2 100644 --- a/demos/FiniteVolume/heat_heterogeneous.cpp +++ b/demos/FiniteVolume/heat_heterogeneous.cpp @@ -177,7 +177,7 @@ int main(int argc, char* argv[]) dt += Tf - t; t = Tf; } - samurai::io::print("{}", fmt::format("iteration {}: t = {:.2f}, dt = {}", nt++, t, dt)); + samurai::io::print(samurai::io::root, "{}", fmt::format("iteration {}: t = {:.2f}, dt = {}", nt++, t, dt)); // Mesh adaptation MRadaptation(mra_config); diff --git a/demos/FiniteVolume/heat_nonlinear.cpp b/demos/FiniteVolume/heat_nonlinear.cpp index d1b92fbc4..c2e6d8e8e 100644 --- a/demos/FiniteVolume/heat_nonlinear.cpp +++ b/demos/FiniteVolume/heat_nonlinear.cpp @@ -228,7 +228,7 @@ int main(int argc, char* argv[]) dt += Tf - t; t = Tf; } - samurai::io::print("{}", fmt::format("iteration {}: t = {:.2f}, dt = {}", nt++, t, dt)); + samurai::io::print(samurai::io::root, "{}", fmt::format("iteration {}: t = {:.2f}, dt = {}", nt++, t, dt)); // Update boundary conditions if (explicit_scheme) diff --git a/demos/FiniteVolume/level_set.cpp b/demos/FiniteVolume/level_set.cpp index e05c6ba3f..53198993e 100644 --- a/demos/FiniteVolume/level_set.cpp +++ b/demos/FiniteVolume/level_set.cpp @@ -349,7 +349,7 @@ int main(int argc, char* argv[]) t = Tf; } - samurai::io::print("iteration {}: t = {}, dt = {}\n", nt++, t, dt); + samurai::io::print(samurai::io::root, "iteration {}: t = {}, dt = {}\n", nt++, t, dt); // Numerical scheme samurai::update_ghost(phi, u); diff --git a/demos/FiniteVolume/level_set_from_scratch.cpp b/demos/FiniteVolume/level_set_from_scratch.cpp index 703acda56..19a614f99 100644 --- a/demos/FiniteVolume/level_set_from_scratch.cpp +++ b/demos/FiniteVolume/level_set_from_scratch.cpp @@ -686,7 +686,7 @@ int main(int argc, char* argv[]) t = Tf; } - samurai::io::print("iteration {}: t = {}, dt = {}\n", nt++, t, dt); + samurai::io::print(samurai::io::root, "iteration {}: t = {}, dt = {}\n", nt++, t, dt); // Numerical scheme update_ghosts(phi, u); diff --git a/demos/FiniteVolume/lid_driven_cavity.cpp b/demos/FiniteVolume/lid_driven_cavity.cpp index 685e22826..82a7ba201 100644 --- a/demos/FiniteVolume/lid_driven_cavity.cpp +++ b/demos/FiniteVolume/lid_driven_cavity.cpp @@ -322,7 +322,7 @@ int main(int argc, char* argv[]) t = Tf; dt_has_changed = true; } - samurai::io::print("{}", fmt::format("iteration {}: t = {:.2f}, dt = {}", nt++, t, dt)); + samurai::io::print(samurai::io::root, "{}", fmt::format("iteration {}: t = {:.2f}, dt = {}", nt++, t, dt)); // Mesh adaptation for Navier-Stokes if (min_level != max_level) diff --git a/demos/FiniteVolume/linear_convection.cpp b/demos/FiniteVolume/linear_convection.cpp index e12a167b0..cc432d67f 100644 --- a/demos/FiniteVolume/linear_convection.cpp +++ b/demos/FiniteVolume/linear_convection.cpp @@ -172,7 +172,7 @@ int main(int argc, char* argv[]) dt += Tf - t; t = Tf; } - samurai::io::print("{}", fmt::format("iteration {}: t = {:.2f}, dt = {}", nt++, t, dt)); + samurai::io::print(samurai::io::root, "{}", fmt::format("iteration {}: t = {:.2f}, dt = {}", nt++, t, dt)); // Mesh adaptation MRadaptation(mra_config); diff --git a/demos/FiniteVolume/linear_convection_obstacle.cpp b/demos/FiniteVolume/linear_convection_obstacle.cpp index 445ee990a..7588464d6 100644 --- a/demos/FiniteVolume/linear_convection_obstacle.cpp +++ b/demos/FiniteVolume/linear_convection_obstacle.cpp @@ -146,7 +146,7 @@ int main(int argc, char* argv[]) dt += Tf - t; t = Tf; } - samurai::io::print("{}", fmt::format("iteration {}: t = {:.2f}, dt = {}", nt++, t, dt)); + samurai::io::print(samurai::io::root, "{}", fmt::format("iteration {}: t = {:.2f}, dt = {}", nt++, t, dt)); // Mesh adaptation diff --git a/demos/FiniteVolume/nagumo.cpp b/demos/FiniteVolume/nagumo.cpp index ca7ff0705..80d25d314 100644 --- a/demos/FiniteVolume/nagumo.cpp +++ b/demos/FiniteVolume/nagumo.cpp @@ -204,7 +204,7 @@ int main(int argc, char* argv[]) dt += Tf - t; t = Tf; } - samurai::io::print("{}", fmt::format("iteration {}: t = {:.2f}, dt = {}", nt++, t, dt)); + samurai::io::print(samurai::io::root, "{}", fmt::format("iteration {}: t = {:.2f}, dt = {}", nt++, t, dt)); // Mesh adaptation MRadaptation(mra_config); diff --git a/demos/FiniteVolume/scalar_burgers_2d.cpp b/demos/FiniteVolume/scalar_burgers_2d.cpp index d5b068e2e..11d21edf8 100644 --- a/demos/FiniteVolume/scalar_burgers_2d.cpp +++ b/demos/FiniteVolume/scalar_burgers_2d.cpp @@ -264,7 +264,7 @@ int main(int argc, char* argv[]) t = Tf; } - samurai::io::print("iteration {}: t = {}, dt = {}\n", nt++, t, dt); + samurai::io::print(samurai::io::root, "iteration {}: t = {}, dt = {}\n", nt++, t, dt); samurai::update_ghost_mr(u); unp1.resize(); diff --git a/demos/FiniteVolume/stokes_2d.cpp b/demos/FiniteVolume/stokes_2d.cpp index 06b281463..68d2ba2bd 100644 --- a/demos/FiniteVolume/stokes_2d.cpp +++ b/demos/FiniteVolume/stokes_2d.cpp @@ -464,7 +464,7 @@ int main(int argc, char* argv[]) t_np1 = Tf; dt_has_changed = true; } - samurai::io::print("{}", fmt::format("iteration {}: t = {:.2f}, dt = {}", nt++, t_np1, dt)); + samurai::io::print(samurai::io::root, "{}", fmt::format("iteration {}: t = {:.2f}, dt = {}", nt++, t_np1, dt)); // Mesh adaptation if (min_level != max_level) From ffe453904ee8374148081c6156f43a81cf97744a Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Thu, 11 Sep 2025 17:52:57 +0000 Subject: [PATCH 08/37] ci: precommit --- include/samurai/arguments.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/samurai/arguments.hpp b/include/samurai/arguments.hpp index b0d704754..aa14cf498 100644 --- a/include/samurai/arguments.hpp +++ b/include/samurai/arguments.hpp @@ -10,16 +10,16 @@ namespace samurai { inline bool timers = false; #ifdef SAMURAI_WITH_MPI - inline bool print_root_only = false; + inline bool print_root_only = false; #endif - inline int finer_level_flux = 0; + inline int finer_level_flux = 0; inline bool refine_boundary = false; inline bool save_debug_fields = false; // MRA arguments inline double epsilon = std::numeric_limits::infinity(); inline double regularity = std::numeric_limits::infinity(); - inline bool rel_detail = false; + inline bool rel_detail = false; } inline void read_samurai_arguments(CLI::App& app, int& argc, char**& argv) From b98c6d3995888cdc2bf69fc0038aca63348b9591 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Thu, 11 Sep 2025 17:54:16 +0000 Subject: [PATCH 09/37] fix: typo --- demos/FiniteVolume/AMR_Burgers_Hat.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/demos/FiniteVolume/AMR_Burgers_Hat.cpp b/demos/FiniteVolume/AMR_Burgers_Hat.cpp index ddff4fdee..a8dbf3e3c 100644 --- a/demos/FiniteVolume/AMR_Burgers_Hat.cpp +++ b/demos/FiniteVolume/AMR_Burgers_Hat.cpp @@ -270,7 +270,7 @@ int main(int argc, char* argv[]) std::size_t ite_adapt = 0; while (true) { - samurai::io::print("\tmesh adaptation: {}\n", ite_adapt++); + samurai::io::print("mesh adaptation: {}\n", ite_adapt++); samurai::update_ghost(phi); tag.resize(); AMR_criteria(phi, tag); @@ -288,7 +288,7 @@ int main(int argc, char* argv[]) t = Tf; } - samurai::io::print(samurai::io::root, \"iteration {}: t = {}, dt = {}\\n\", nt++, t, dt); + samurai::io::print(samurai::io::root, "iteration {}: t = {}, dt = {}\\n\", nt++, t, dt); // Numerical scheme samurai::update_ghost(phi); From f4cd476f483bfedddd3d141a1ea0e77921b3ff5a Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Thu, 11 Sep 2025 17:58:27 +0000 Subject: [PATCH 10/37] fix: typo --- demos/FiniteVolume/AMR_Burgers_Hat.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demos/FiniteVolume/AMR_Burgers_Hat.cpp b/demos/FiniteVolume/AMR_Burgers_Hat.cpp index a8dbf3e3c..fa514aa58 100644 --- a/demos/FiniteVolume/AMR_Burgers_Hat.cpp +++ b/demos/FiniteVolume/AMR_Burgers_Hat.cpp @@ -288,7 +288,7 @@ int main(int argc, char* argv[]) t = Tf; } - samurai::io::print(samurai::io::root, "iteration {}: t = {}, dt = {}\\n\", nt++, t, dt); + samurai::io::print(samurai::io::root, "iteration {}: t = {}, dt = {}\n", nt++, t, dt); // Numerical scheme samurai::update_ghost(phi); From 1b0e2036e42409d55f147e4107a1518ee75eae6f Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Thu, 11 Sep 2025 18:10:04 +0000 Subject: [PATCH 11/37] fix: resolve compilation issue --- include/samurai/print.hpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/include/samurai/print.hpp b/include/samurai/print.hpp index b84a889e8..4b2b4472b 100644 --- a/include/samurai/print.hpp +++ b/include/samurai/print.hpp @@ -5,6 +5,7 @@ #include #include +#include #ifdef SAMURAI_WITH_MPI #include @@ -103,7 +104,13 @@ namespace samurai detail::do_print(stdout, f, std::forward(a)...); } - template + // Constrain scoped overloads to known scope tag types to avoid + // ambiguity with string literals and other types. + template , all_t> + || std::is_same_v, root_t> + || std::is_same_v, rank_t>, + int> = 0> inline void print(Scope sc, fmt::format_string f, Args&&... a) { detail::do_print(stdout, sc, f, std::forward(a)...); @@ -116,7 +123,11 @@ namespace samurai detail::do_print(stderr, f, std::forward(a)...); } - template + template , all_t> + || std::is_same_v, root_t> + || std::is_same_v, rank_t>, + int> = 0> inline void eprint(Scope sc, fmt::format_string f, Args&&... a) { detail::do_print(stderr, sc, f, std::forward(a)...); From 12d5378bc9db468705a7a6a2bc8b3742481b78d1 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Thu, 11 Sep 2025 18:12:43 +0000 Subject: [PATCH 12/37] ci: precommit --- include/samurai/print.hpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/include/samurai/print.hpp b/include/samurai/print.hpp index 4b2b4472b..a838c08d3 100644 --- a/include/samurai/print.hpp +++ b/include/samurai/print.hpp @@ -106,9 +106,9 @@ namespace samurai // Constrain scoped overloads to known scope tag types to avoid // ambiguity with string literals and other types. - template , all_t> - || std::is_same_v, root_t> + template , all_t> || std::is_same_v, root_t> || std::is_same_v, rank_t>, int> = 0> inline void print(Scope sc, fmt::format_string f, Args&&... a) @@ -123,9 +123,9 @@ namespace samurai detail::do_print(stderr, f, std::forward(a)...); } - template , all_t> - || std::is_same_v, root_t> + template , all_t> || std::is_same_v, root_t> || std::is_same_v, rank_t>, int> = 0> inline void eprint(Scope sc, fmt::format_string f, Args&&... a) From 6e66569f176d4ab70ac0a5406e1ca738a1adc78f Mon Sep 17 00:00:00 2001 From: sbstndb/sbstndbs Date: Fri, 3 Oct 2025 10:45:13 +0200 Subject: [PATCH 13/37] io(print): add /; guard MPI rank with MPI_Initialized/MPI_Finalized --- include/samurai/print.hpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/include/samurai/print.hpp b/include/samurai/print.hpp index a838c08d3..1ea99faaf 100644 --- a/include/samurai/print.hpp +++ b/include/samurai/print.hpp @@ -6,6 +6,8 @@ #include #include #include +#include +#include #ifdef SAMURAI_WITH_MPI #include @@ -43,6 +45,18 @@ namespace samurai { #ifdef SAMURAI_WITH_MPI int r = 0; + int initialized = 0; + int finalized = 0; + MPI_Initialized(&initialized); + if (!initialized) + { + return 0; + } + MPI_Finalized(&finalized); + if (finalized) + { + return 0; + } MPI_Comm_rank(MPI_COMM_WORLD, &r); return r; #else From 9d0946d44f7cdd9555cea07c5ea096b4597f50a8 Mon Sep 17 00:00:00 2001 From: sbstndb/sbstndbs Date: Fri, 3 Oct 2025 10:50:58 +0200 Subject: [PATCH 14/37] style(print): apply clang-format after pre-commit --- include/samurai/print.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/samurai/print.hpp b/include/samurai/print.hpp index 1ea99faaf..0f1b15918 100644 --- a/include/samurai/print.hpp +++ b/include/samurai/print.hpp @@ -3,10 +3,10 @@ #pragma once +#include #include #include #include -#include #include #ifdef SAMURAI_WITH_MPI @@ -44,7 +44,7 @@ namespace samurai inline int current_rank() { #ifdef SAMURAI_WITH_MPI - int r = 0; + int r = 0; int initialized = 0; int finalized = 0; MPI_Initialized(&initialized); From 5d9c87a4554886340c49cb9eea9f5e308930416b Mon Sep 17 00:00:00 2001 From: sbstndb/sbstndbs Date: Fri, 3 Oct 2025 10:58:27 +0200 Subject: [PATCH 15/37] chore(repo): remove editor swap files and ignore them (*.swp, *.swo, *.swn) --- .gitignore | 5 +++++ include/samurai/.print.hpp.swn | Bin 12288 -> 0 bytes include/samurai/.print.hpp.swo | Bin 12288 -> 0 bytes include/samurai/.print.hpp.swp | Bin 12288 -> 0 bytes 4 files changed, 5 insertions(+) delete mode 100644 include/samurai/.print.hpp.swn delete mode 100644 include/samurai/.print.hpp.swo delete mode 100644 include/samurai/.print.hpp.swp diff --git a/.gitignore b/.gitignore index cd78c3d5b..28bc43723 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,11 @@ __pycache__ .cache *.old +# Editor swap files +*.swp +*.swo +*.swn + # Created by https://www.toptal.com/developers/gitignore/api/cmake,linux,macos,visualstudiocode,python # Edit at https://www.toptal.com/developers/gitignore?templates=cmake,linux,macos,visualstudiocode,python diff --git a/include/samurai/.print.hpp.swn b/include/samurai/.print.hpp.swn deleted file mode 100644 index 564402f8cb21bddc832b92d9f8cbdbe90a485a7d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI2UuYaf9LJ}kt?3_?Rv|tplSI#)++8jyq3tzEjfvt(LSxd}QiNr4JC|F#e~#JN z#2TVl^s%4_2J}Hh1zTwK!I%2jJXk3{Rip~ygHJ+1@j=9g>UVbcZtrr5iAe;N8Te#( z=g)6`^PTz4?va_!KU*B9hjP6H=^jFse!NooA;nND){SUxxQp>iD&!r zef{}Ez4>f!f4;x9%}bHN9-ldZV3xsb+n5$;S>b*yGmFe@JyShcZno^m9?LD+fyrz2 zdaA;5Wv)`Kw)UfQv;tazl@!=R_V@MXRY_N82i>>#_)3*@o>o9BpcT*xXa%$aS^=$q zRzNH8KUF|hw~?1Iw%g+IEyUMt%dYXGzGwxs0$KsBfL1^&pcT*xXa%$aS^=$qRzNH8 zA5?&ugxrrG{}0~|=kfpl+VB7CcN20Rd<5PBZ-cYI0u?X;j(~&U0C*5Q0Cs^k@Y`L4 z`~q%(C2$#B0vEv|I0w#xSHNk&z|-Ie7y|9!=RJh{1eU;M@E%wMZvhFO2b171*bRQ& zjW*z0a234tx!+g3rO5zy-QY29JS0 za39zKwu5il2)PE{1#f`Y0RvN@1MCBP!Oc4f`3#%_V;}|Y1z+tTe;3l{RUIj0L10V}B;1=fjB6uG>2PVM)Q1kx~&`B%M zqQC;}>7g!jxL;)@PUG`Cgd!~~vb-=iEUDkACzDHN*@c4X8R5yDZeN;Qhz#{h8Cu3g znuS8y6LUo zB{UP-gRLRek+Pji;fbo5p~x?*LC0$DVkU`k5%&HXOUExAnzu&3ko4 z41_^$(ohua612kYDi?{+s#>d;_2=*9UP=0H_PmRC;OFZ-z;4$ z!?fqwv`Ic?#gJ5_H{5%EWBq!bG~{}Fm12X#QwKfQ?xj_0rQp^tTzKQn8742Yz?Sj) z-NfqMNZhM|EnBm#+q9~LWjY!;O1oXp&HCy!XQtO$v|Zdatuj#-8dJP>qj~J&w$Djp zvAU0|baclr`9gu=g;^+sQDO+SUOd-6LsO~cA1$7L*`Y zxaX~CqP1@5-1_Q<4%Qt*03Bm9K262jyC0TB9VCkgpRMyGd8~clVlhXj&S@v2AaJnZ z`|8MfC(h4C5mv7-;8d+#WoXsqpO_lJhSB3e1kRkOMchYNfKOn2xT<{8RTXT;VbsIX zdP39-Yhv_dcFZbq*XP-y32&^j#YKVA$EQZK`?Di93lP$%IpS5%2y3PyX=W=WJ&oMij zSVI(xuLVUgpbsJ{*g~rhzSPI&!AkL|B2^F{d=d(Z4+h6D( zC>-i5WcvmR1MO{Ijtu5~<^+OS2D5ErMxbSt`}NE$GP8|L^mKr5gX&at?e1-T`leGr$5>FbR%;gWv#o5Ig{Ofe!H7U4;As zu7hQ830wphz!EqM&VX0JDZs$f;0PE7o#5v^g!}}S!6on>SORYW30?qG;4s(?e%*~W z;9GDFd;zY2kHLpv9$4TRK)~<22>A|t4X%LC!JEJZonR;UekUPcg0o-&IKT#vfqrlw z*a5bKZ#oFM3f={8fY$*7)1V9N1AD=ZI|=y=oCM<_1?~l3?I7eb_!OK6=fDz}0|k%* zKWs-o;5s-DPJ&6$0sgpykelEJxC&kaFM$If3wps#%<~2CK6oBXfkB|={~@50R-jFR zMVil3mpR<8u`;Le`5i)$RuoxYm>ZTf?$ndXC9~{e(e#Y)RNTd2<^h~K$p=rPB1-4m_=5i*9ruH_?0o&LCo-B<&@hJ6sqiEZ7?5f^27Qc1x)fF)i z2DwQ?QLszUDz|G~Btold?P3Zp1L4wgAOv@%f#Zv((iu85L`80n*#S@XE7iVLx>$x8 z&$DTZe9DR;smN@)_rm7-^*m|FjrJ8yPli%)oaeothZ=;xNBM!qAWD0c*u!m~ljdS| zA6My0$1nL}k>Q0|EQV2H2(?~3*FH^Csg)tnHAD+|TlZKMNK2yl#COlV^0|q zlcko9){cr*=cds%X_tJAL~q|DZWhTZgO5jrAZZ_UTqarr2re6=p5sIT9zGqNm@rNp zof;qOr76+$U7}>eS!60G6j)z?WDxOopxU->C(WZ#*6S&DbzyEXakkA|*~4*c{$fqg z`mUn3DAmbaQ=rFvH&qU|0;*)eRkNIEDZ^#%6t*inn(^EQvZu77;#M7fAA0|G>p!j!vD^ZbU)gV8i#- zk@IexpN%4{QDM-jS-I-)n#(^iHHZx(??D94oTx?IM_7PQV0^f$e9}`BY}R4a!_j&| z)C+5J?78f?RpzeGvn3PWSQU$lBBhT{k7f5~M{O1$q)~I!tDP3sY*o_!Lf^sgTt1c6 Q#+UmeK4pQddcr4v0$g0B*8l(j diff --git a/include/samurai/.print.hpp.swp b/include/samurai/.print.hpp.swp deleted file mode 100644 index 601a1ea5809f16d7bfcbdfb0fb0e6fbb55c0475b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI2J8T?97{@0>JVFu(gu+q+8ryLA65qp4Op@~>GB$_n0HxwT`?$UHp20C79-5JU*_+ol z^Zmb>*|jor#b?Ts^hmysAnhXLp>IB{zxQSb`D%d>f6ljrFDrgO>6Ry$RpGh*V*fz# zNMAA6H&7f%_jx`vSn!zXyG+-ZVQ6zMde*rY7v@lyYZS_iZslsGDCkzj@T)v-S8!b2 z68XC0q{mSuN&%%nI|X)<1O0tPS<~IsNq65n+pdu+Qwk^rlmbctrGQdEDWDWk3Md8s zrwRyX3wZ&)-4gk?96h(Jc}7|FPzopolmbctrGQdEDWDWk3Md7X0!jg;fKuQ;r~s=H zvUe*X_uY!g2Hd!lkng~^;0m||o&y#z z!65iz8zG;73*Z$n3&y|z*bnxB4)DtzguD+ffMswJWWgSA57-61zMYV>;AJoh4uMC& zgJ3JTavLEZfR}&|4uTBW3-*BT5!2VfS@0AX1^a=F^=_b&Qa~w?R$!GD3e;jI_Z(K? zG`g-tDAJlL-405Fn#M1gt8&3~qg1NeT5wUR#}ifVy1mq^^wJt0qFO4|Y~y)?+kron_rqxov%7e#8#$&z3St!{42McFxVQ|9y< z?TNL+< zY854NaL%?3+9Hg!q6z9|lK@H!H!*r~bK}~!(8NYZ749b8lXqy-qjYnts@F&?Rs4(u z4hQSzhR4@y(%BQe^-3j%H%O@zY%$H1PT7`mie@rvopwNbY^sNc6zj| zohToFLYtf_w+ys?=-Qt7jlN00zZ%&Mp}G)nu|Ma}^uc zvH7y&(s=31eIy52Y+8-c*iDUt^-5)gSDMVH+64=a;$PW{#4~H^A&Y|1TDNR6Pkg2L z704BA%(f=dZG*{etZgvC#>DW>KF;PnnxS=WINbGuns9(*5#c*-g(TVdiw}!Aymd~y zunT+>r;;bHoOj{=Y`DW34Teld&(}xRUH*xwA-o9+Hbmge40}Xl1Qqxu#Fv~bC*6+A z=1oRzT&*Vrj?7GrKbxD-E8OyUu3W`z^qS7y5~YvMjOPyI#ti0TOQYqO?VNJ;`MRL} X#lFMAy?iR_jZfK!J<5Dhx1q*wJ2PKq From 131ec14e3eb69a919505c2142045c164ab2f1fc6 Mon Sep 17 00:00:00 2001 From: sbstndb/sbstndbs Date: Fri, 3 Oct 2025 11:10:36 +0200 Subject: [PATCH 16/37] revert: keep std::cerr unchanged; convert only std::cout. Revert unintended eprint changes and stray includes in FV headers (part 1) --- include/samurai/box.hpp | 8 +++--- include/samurai/field.hpp | 5 ++-- include/samurai/io/cgal.hpp | 3 ++- include/samurai/mr/operators.hpp | 5 ++-- include/samurai/numeric/prediction.hpp | 6 +++-- .../samurai/petsc/fv/FV_scheme_assembly.hpp | 26 ++++++++++++++----- include/samurai/schemes/block_operator.hpp | 10 +++++-- .../cell_based/cell_based_scheme__nonlin.hpp | 7 +++-- .../samurai/schemes/fv/explicit_FV_scheme.hpp | 3 ++- .../explicit_flux_based_scheme__lin_het.hpp | 12 ++++++--- .../explicit_flux_based_scheme__lin_hom.hpp | 6 ++--- .../fv/flux_based/flux_based_scheme.hpp | 5 ++-- .../flux_based/flux_based_scheme__nonlin.hpp | 13 +++++++--- 13 files changed, 74 insertions(+), 35 deletions(-) diff --git a/include/samurai/box.hpp b/include/samurai/box.hpp index 8f0dd1c76..9e9362f25 100644 --- a/include/samurai/box.hpp +++ b/include/samurai/box.hpp @@ -6,6 +6,8 @@ #include "utils.hpp" #include #include +#include +#include "print.hpp" namespace samurai { @@ -309,9 +311,9 @@ namespace samurai // ... and no tolerance is allowed, we raise an error. if (tol == 0) { - std::cerr << "The box " << box << " cannot be exactly represented with a reasonable cell length. "; - std::cerr << "You can modify the box's dimensions or you can set a tolerance so it can be approximately represented." - << std::endl; + samurai::io::eprint(samurai::io::root, + "The box {} cannot be exactly represented with a reasonable cell length. You can modify the box's dimensions or set a tolerance so it can be approximately represented.\n", + fmt::streamed(box)); std::exit(1); } diff --git a/include/samurai/field.hpp b/include/samurai/field.hpp index dcc968a3b..726d305ad 100644 --- a/include/samurai/field.hpp +++ b/include/samurai/field.hpp @@ -29,6 +29,7 @@ namespace fs = std::filesystem; #include "numeric/gauss_legendre.hpp" #include "storage/containers.hpp" #include "timers.hpp" +#include "print.hpp" namespace samurai { @@ -257,7 +258,7 @@ namespace samurai if (xt::any(xt::isnan(data))) { // std::cout << data << std::endl; - std::cerr << "READ NaN at level " << level << ", " << interval << std::endl; + samurai::io::eprint("READ NaN at level {}, {}\n", level, fmt::streamed(interval)); } #endif return data; @@ -748,7 +749,7 @@ namespace samurai if (field1.mesh() != field2.mesh()) { - std::cout << "mesh different" << std::endl; + samurai::io::eprint(samurai::io::root, "mesh different\n"); return false; } diff --git a/include/samurai/io/cgal.hpp b/include/samurai/io/cgal.hpp index 0b15b03c5..76414c1f6 100644 --- a/include/samurai/io/cgal.hpp +++ b/include/samurai/io/cgal.hpp @@ -12,6 +12,7 @@ #include #include #include +#include "../print.hpp" #include @@ -166,7 +167,7 @@ namespace samurai CGALMesh cgal_mesh; if (!PMP::IO::read_polygon_mesh(input_file, cgal_mesh) || cgal_mesh.is_empty()) { - std::cerr << "Invalid input file." << std::endl; + samurai::io::eprint(samurai::io::root, "Invalid input file.\n"); return CGALMesh(); } diff --git a/include/samurai/mr/operators.hpp b/include/samurai/mr/operators.hpp index a533680ec..ecb6510e9 100644 --- a/include/samurai/mr/operators.hpp +++ b/include/samurai/mr/operators.hpp @@ -12,6 +12,7 @@ #include "../numeric/prediction.hpp" #include "../operators_base.hpp" #include "../utils.hpp" +#include "../print.hpp" namespace samurai { @@ -288,7 +289,7 @@ namespace samurai { if (std::isnan(qs_i(ii)) || std::isnan(qs_j(ii)) || std::isnan(qs_ij(ii))) { - std::cerr << "NaN detected during the computation of details." << std::endl; + samurai::io::eprint("NaN detected during the computation of details.\n"); save(fs::current_path(), "check_nan", {true, true}, field.mesh(), field); break; } @@ -298,7 +299,7 @@ namespace samurai { if (xt::any(xt::isnan(qs_ij))) { - std::cerr << "NaN detected during the computation of details." << std::endl; + samurai::io::eprint("NaN detected during the computation of details.\n"); save(fs::current_path(), "check_nan", {true, true}, field.mesh(), field); } } diff --git a/include/samurai/numeric/prediction.hpp b/include/samurai/numeric/prediction.hpp index d95209fc9..efda52e1e 100644 --- a/include/samurai/numeric/prediction.hpp +++ b/include/samurai/numeric/prediction.hpp @@ -8,6 +8,8 @@ #include #include +#include +#include "../print.hpp" #include "../operators_base.hpp" #include "../storage/utils.hpp" @@ -576,8 +578,8 @@ namespace samurai #ifdef SAMURAI_CHECK_NAN if (xt::any(xt::isnan(qs_ij))) { - std::cerr << "NaN detected in the prediction stencil (Qs_ij)." << std::endl; - std::cerr << qs_ij << std::endl; + samurai::io::eprint("NaN detected in the prediction stencil (Qs_ij).\n{} +", fmt::streamed(qs_ij)); save(fs::current_path(), "check_nan", {true, true}, src.mesh(), src); } #endif diff --git a/include/samurai/petsc/fv/FV_scheme_assembly.hpp b/include/samurai/petsc/fv/FV_scheme_assembly.hpp index abe9ab2b9..3cb364625 100644 --- a/include/samurai/petsc/fv/FV_scheme_assembly.hpp +++ b/include/samurai/petsc/fv/FV_scheme_assembly.hpp @@ -4,6 +4,8 @@ #include "../../numeric/prediction.hpp" #include "../../schemes/fv/FV_scheme.hpp" #include "../../schemes/fv/scheme_operators.hpp" +#include "../../print.hpp" +#include #include "../matrix_assembly.hpp" namespace samurai @@ -516,8 +518,11 @@ namespace samurai VecGetSize(b, &b_rows); if (b_rows != this->matrix_cols()) { - std::cerr << "Operator '" << this->name() << "': the number of rows in vector (" << b_rows - << ") does not equal the number of columns of the matrix (" << this->matrix_cols() << ")" << std::endl; + samurai::io::eprint(samurai::io::root, + "Operator '{}': the number of rows in vector ({}) does not equal the number of columns of the matrix ({})\n", + this->name(), + b_rows, + this->matrix_cols()); assert(false); return; } @@ -606,9 +611,13 @@ namespace samurai INSERT_VALUES); if (error) { - std::cerr << scheme().name() << ": failure to insert diagonal coefficient at (" - << m_row_shift + static_cast(i) << ", " << m_col_shift + static_cast(i) - << "), i.e. (" << i << ", " << i << ") in the block." << std::endl; + samurai::io::eprint(samurai::io::root, + "{}: failure to insert diagonal coefficient at ({}, {}), i.e. ({}, {}) in the block.\n", + scheme().name(), + m_row_shift + static_cast(i), + m_col_shift + static_cast(i), + i, + i); assert(false); exit(EXIT_FAILURE); } @@ -753,8 +762,11 @@ namespace samurai current_insert_mode()); if (error) { - std::cerr << scheme().name() << ": failure to insert projection coefficient at (" << ghost_index - << ", " << m_col_shift + col_index(children[i], field_i) << ")." << std::endl; + samurai::io::eprint(samurai::io::root, + "{}: failure to insert projection coefficient at ({}, {}).\n", + scheme().name(), + ghost_index, + m_col_shift + col_index(children[i], field_i)); assert(false); exit(EXIT_FAILURE); } diff --git a/include/samurai/schemes/block_operator.hpp b/include/samurai/schemes/block_operator.hpp index 48e08b557..92ae7ef34 100644 --- a/include/samurai/schemes/block_operator.hpp +++ b/include/samurai/schemes/block_operator.hpp @@ -1,5 +1,6 @@ #pragma once #include "../utils.hpp" +#include "../print.hpp" namespace samurai { @@ -94,8 +95,13 @@ namespace samurai using op_field_t = typename operator_t::field_t; if constexpr (!std::is_same_v, op_field_t>) { - std::cerr << "unknown " << i << " is not compatible with the scheme (" << row << ", " << col - << ") (named '" << op.name() << "')" << std::endl; + samurai::io::eprint( + samurai::io::root, + "unknown {} is not compatible with the scheme ({}, {}) (named '{}')\n", + i, + row, + col, + op.name()); assert(false); exit(EXIT_FAILURE); } diff --git a/include/samurai/schemes/fv/cell_based/cell_based_scheme__nonlin.hpp b/include/samurai/schemes/fv/cell_based/cell_based_scheme__nonlin.hpp index eb75c38b4..ac782fd15 100644 --- a/include/samurai/schemes/fv/cell_based/cell_based_scheme__nonlin.hpp +++ b/include/samurai/schemes/fv/cell_based/cell_based_scheme__nonlin.hpp @@ -178,8 +178,11 @@ namespace samurai { if (!jacobian_function()) { - std::cerr << "The jacobian function of operator '" << this->name() << "' has not been implemented." << std::endl; - std::cerr << "Use option -snes_mf or -snes_fd for an automatic computation of the jacobian matrix." << std::endl; + samurai::io::eprint(samurai::io::root, + "The jacobian function of operator '{}' has not been implemented.\n", + this->name()); + samurai::io::eprint(samurai::io::root, + "Use option -snes_mf or -snes_fd for an automatic computation of the jacobian matrix.\n"); exit(EXIT_FAILURE); } diff --git a/include/samurai/schemes/fv/explicit_FV_scheme.hpp b/include/samurai/schemes/fv/explicit_FV_scheme.hpp index 5b6b096f3..61e233ae2 100644 --- a/include/samurai/schemes/fv/explicit_FV_scheme.hpp +++ b/include/samurai/schemes/fv/explicit_FV_scheme.hpp @@ -1,6 +1,7 @@ #pragma once #include "../explicit_scheme.hpp" #include "FV_scheme.hpp" +#include "../../print.hpp" namespace samurai { @@ -83,7 +84,7 @@ namespace samurai virtual void apply(std::size_t /* d */, output_field_t& /* output_field */, input_field_t& /* input_field */) { - std::cerr << "The scheme '" << scheme().name() << "' cannot be applied by direction." << std::endl; + samurai::io::eprint(samurai::io::root, "The scheme '{}' cannot be applied by direction.\n", scheme().name()); assert(false); exit(EXIT_FAILURE); } diff --git a/include/samurai/schemes/fv/flux_based/explicit_flux_based_scheme__lin_het.hpp b/include/samurai/schemes/fv/flux_based/explicit_flux_based_scheme__lin_het.hpp index 1a120fe49..b2a034811 100644 --- a/include/samurai/schemes/fv/flux_based/explicit_flux_based_scheme__lin_het.hpp +++ b/include/samurai/schemes/fv/flux_based/explicit_flux_based_scheme__lin_het.hpp @@ -63,8 +63,9 @@ namespace samurai #ifdef SAMURAI_CHECK_NAN if (std::isnan(field_value(input_field, comput_cells[c], field_j))) { - std::cerr << "NaN detected when computing the flux on the interior interfaces: " << comput_cells[c] - << std::endl; + samurai::io::eprint( + "NaN detected when computing the flux on the interior interfaces: {}\n", + fmt::streamed(comput_cells[c])); assert(false); } #endif @@ -96,8 +97,9 @@ namespace samurai #ifdef SAMURAI_CHECK_NAN if (std::isnan(field_value(input_field, comput_cells[c], field_j))) { - std::cerr << "NaN detected when computing the flux on the boundary interfaces: " << comput_cells[c] - << std::endl; + samurai::io::eprint( + "NaN detected when computing the flux on the boundary interfaces: {}\n", + fmt::streamed(comput_cells[c])); assert(false); } #endif @@ -112,3 +114,5 @@ namespace samurai }; } // end namespace samurai +#include "../../../print.hpp" +#include diff --git a/include/samurai/schemes/fv/flux_based/explicit_flux_based_scheme__lin_hom.hpp b/include/samurai/schemes/fv/flux_based/explicit_flux_based_scheme__lin_hom.hpp index ecc2cdddc..c57e2092a 100644 --- a/include/samurai/schemes/fv/flux_based/explicit_flux_based_scheme__lin_hom.hpp +++ b/include/samurai/schemes/fv/flux_based/explicit_flux_based_scheme__lin_hom.hpp @@ -287,9 +287,7 @@ namespace samurai #ifdef SAMURAI_CHECK_NAN if (std::isnan(field_value(input_field, stencil.cells()[c], field_j))) { - std::cerr - << "NaN detected when computing the flux on the boundary interfaces: " << stencil.cells()[c] - << std::endl; + std::cerr << "NaN detected when computing the flux on the boundary interfaces: " << stencil.cells()[c] << std::endl; assert(false); } #endif @@ -318,3 +316,5 @@ namespace samurai }; } // end namespace samurai +#include "../../../print.hpp" +#include diff --git a/include/samurai/schemes/fv/flux_based/flux_based_scheme.hpp b/include/samurai/schemes/fv/flux_based/flux_based_scheme.hpp index 5d41b8fe1..73c64dc52 100644 --- a/include/samurai/schemes/fv/flux_based/flux_based_scheme.hpp +++ b/include/samurai/schemes/fv/flux_based/flux_based_scheme.hpp @@ -1,5 +1,6 @@ #pragma once #include "../../../arguments.hpp" +#include "../../../print.hpp" #include "../../../interface.hpp" #include "../../../reconstruction.hpp" #include "../../explicit_scheme.hpp" @@ -24,8 +25,8 @@ namespace samurai // cppcheck-suppress knownConditionTrueFalse if (args::finer_level_flux != 0 && cfg::dim > 1 && cfg::stencil_size > 4 && !args::refine_boundary) { - std::cout << "Warning: for stencils larger than 4, computing fluxes at max_level may cause issues close to the boundary." - << std::endl; + samurai::io::eprint(samurai::io::root, + "Warning: for stencils larger than 4, computing fluxes at max_level may cause issues close to the boundary.\n"); } return FluxBasedScheme(flux_definition); diff --git a/include/samurai/schemes/fv/flux_based/flux_based_scheme__nonlin.hpp b/include/samurai/schemes/fv/flux_based/flux_based_scheme__nonlin.hpp index c8c5eced7..5619da51b 100644 --- a/include/samurai/schemes/fv/flux_based/flux_based_scheme__nonlin.hpp +++ b/include/samurai/schemes/fv/flux_based/flux_based_scheme__nonlin.hpp @@ -1,5 +1,7 @@ #pragma once #include "flux_based_scheme.hpp" +#include "../../../print.hpp" +#include namespace samurai { @@ -103,8 +105,8 @@ namespace samurai { if (enable && dim > 1 && stencil_size > 4 && !args::refine_boundary) // cppcheck-suppress knownConditionTrueFalse { - std::cout << "Warning: for stencils larger than 4, computing fluxes at max_level may cause issues close to the boundary." - << std::endl; + samurai::io::eprint(samurai::io::root, + "Warning: for stencils larger than 4, computing fluxes at max_level may cause issues close to the boundary.\n"); } m_finer_level_flux = enable ? -1 : 0; } @@ -595,8 +597,11 @@ namespace samurai if (!jacobian_function) { - std::cerr << "The jacobian function of operator '" << this->name() << "' has not been implemented." << std::endl; - std::cerr << "Use option -snes_mf or -snes_fd for an automatic computation of the jacobian matrix." << std::endl; + samurai::io::eprint(samurai::io::root, + "The jacobian function of operator '{}' has not been implemented.\n", + this->name()); + samurai::io::eprint(samurai::io::root, + "Use option -snes_mf or -snes_fd for an automatic computation of the jacobian matrix.\n"); exit(EXIT_FAILURE); } From c861e8931d6a8ed0dcb6bb4a0705b02fd9f5a2c1 Mon Sep 17 00:00:00 2001 From: sbstndb/sbstndbs Date: Fri, 3 Oct 2025 11:11:22 +0200 Subject: [PATCH 17/37] revert: keep std::cerr; remove unintended print.hpp/fmt includes in explicit flux-based schemes --- .../flux_based/explicit_flux_based_scheme__lin_het.hpp | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/include/samurai/schemes/fv/flux_based/explicit_flux_based_scheme__lin_het.hpp b/include/samurai/schemes/fv/flux_based/explicit_flux_based_scheme__lin_het.hpp index b2a034811..ab2eed1b5 100644 --- a/include/samurai/schemes/fv/flux_based/explicit_flux_based_scheme__lin_het.hpp +++ b/include/samurai/schemes/fv/flux_based/explicit_flux_based_scheme__lin_het.hpp @@ -63,9 +63,7 @@ namespace samurai #ifdef SAMURAI_CHECK_NAN if (std::isnan(field_value(input_field, comput_cells[c], field_j))) { - samurai::io::eprint( - "NaN detected when computing the flux on the interior interfaces: {}\n", - fmt::streamed(comput_cells[c])); + std::cerr << "NaN detected when computing the flux on the interior interfaces: " << comput_cells[c] << std::endl; assert(false); } #endif @@ -97,9 +95,7 @@ namespace samurai #ifdef SAMURAI_CHECK_NAN if (std::isnan(field_value(input_field, comput_cells[c], field_j))) { - samurai::io::eprint( - "NaN detected when computing the flux on the boundary interfaces: {}\n", - fmt::streamed(comput_cells[c])); + std::cerr << "NaN detected when computing the flux on the boundary interfaces: " << comput_cells[c] << std::endl; assert(false); } #endif @@ -114,5 +110,3 @@ namespace samurai }; } // end namespace samurai -#include "../../../print.hpp" -#include From 931474a67a12cb9d7d7d36ca25ddcd4ef47cb042 Mon Sep 17 00:00:00 2001 From: sbstndb/sbstndbs Date: Fri, 3 Oct 2025 11:13:19 +0200 Subject: [PATCH 18/37] Revert "revert: keep std::cerr; remove unintended print.hpp/fmt includes in explicit flux-based schemes" This reverts commit c5e8ef489c93b65b5d9de73f051a19032c190377. --- .../flux_based/explicit_flux_based_scheme__lin_het.hpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/include/samurai/schemes/fv/flux_based/explicit_flux_based_scheme__lin_het.hpp b/include/samurai/schemes/fv/flux_based/explicit_flux_based_scheme__lin_het.hpp index ab2eed1b5..b2a034811 100644 --- a/include/samurai/schemes/fv/flux_based/explicit_flux_based_scheme__lin_het.hpp +++ b/include/samurai/schemes/fv/flux_based/explicit_flux_based_scheme__lin_het.hpp @@ -63,7 +63,9 @@ namespace samurai #ifdef SAMURAI_CHECK_NAN if (std::isnan(field_value(input_field, comput_cells[c], field_j))) { - std::cerr << "NaN detected when computing the flux on the interior interfaces: " << comput_cells[c] << std::endl; + samurai::io::eprint( + "NaN detected when computing the flux on the interior interfaces: {}\n", + fmt::streamed(comput_cells[c])); assert(false); } #endif @@ -95,7 +97,9 @@ namespace samurai #ifdef SAMURAI_CHECK_NAN if (std::isnan(field_value(input_field, comput_cells[c], field_j))) { - std::cerr << "NaN detected when computing the flux on the boundary interfaces: " << comput_cells[c] << std::endl; + samurai::io::eprint( + "NaN detected when computing the flux on the boundary interfaces: {}\n", + fmt::streamed(comput_cells[c])); assert(false); } #endif @@ -110,3 +114,5 @@ namespace samurai }; } // end namespace samurai +#include "../../../print.hpp" +#include From 7cab315b17d097c126c8f7662d6b140b46e0f10f Mon Sep 17 00:00:00 2001 From: sbstndb/sbstndbs Date: Fri, 3 Oct 2025 11:13:19 +0200 Subject: [PATCH 19/37] Revert "revert: keep std::cerr unchanged; convert only std::cout. Revert unintended eprint changes and stray includes in FV headers (part 1)" This reverts commit 4fbdc57b867bb94bb21e6fc7a292a74632dae752. --- include/samurai/box.hpp | 8 +++--- include/samurai/field.hpp | 5 ++-- include/samurai/io/cgal.hpp | 3 +-- include/samurai/mr/operators.hpp | 5 ++-- include/samurai/numeric/prediction.hpp | 6 ++--- .../samurai/petsc/fv/FV_scheme_assembly.hpp | 26 +++++-------------- include/samurai/schemes/block_operator.hpp | 10 ++----- .../cell_based/cell_based_scheme__nonlin.hpp | 7 ++--- .../samurai/schemes/fv/explicit_FV_scheme.hpp | 3 +-- .../explicit_flux_based_scheme__lin_het.hpp | 12 +++------ .../explicit_flux_based_scheme__lin_hom.hpp | 6 ++--- .../fv/flux_based/flux_based_scheme.hpp | 5 ++-- .../flux_based/flux_based_scheme__nonlin.hpp | 13 +++------- 13 files changed, 35 insertions(+), 74 deletions(-) diff --git a/include/samurai/box.hpp b/include/samurai/box.hpp index 9e9362f25..8f0dd1c76 100644 --- a/include/samurai/box.hpp +++ b/include/samurai/box.hpp @@ -6,8 +6,6 @@ #include "utils.hpp" #include #include -#include -#include "print.hpp" namespace samurai { @@ -311,9 +309,9 @@ namespace samurai // ... and no tolerance is allowed, we raise an error. if (tol == 0) { - samurai::io::eprint(samurai::io::root, - "The box {} cannot be exactly represented with a reasonable cell length. You can modify the box's dimensions or set a tolerance so it can be approximately represented.\n", - fmt::streamed(box)); + std::cerr << "The box " << box << " cannot be exactly represented with a reasonable cell length. "; + std::cerr << "You can modify the box's dimensions or you can set a tolerance so it can be approximately represented." + << std::endl; std::exit(1); } diff --git a/include/samurai/field.hpp b/include/samurai/field.hpp index 726d305ad..dcc968a3b 100644 --- a/include/samurai/field.hpp +++ b/include/samurai/field.hpp @@ -29,7 +29,6 @@ namespace fs = std::filesystem; #include "numeric/gauss_legendre.hpp" #include "storage/containers.hpp" #include "timers.hpp" -#include "print.hpp" namespace samurai { @@ -258,7 +257,7 @@ namespace samurai if (xt::any(xt::isnan(data))) { // std::cout << data << std::endl; - samurai::io::eprint("READ NaN at level {}, {}\n", level, fmt::streamed(interval)); + std::cerr << "READ NaN at level " << level << ", " << interval << std::endl; } #endif return data; @@ -749,7 +748,7 @@ namespace samurai if (field1.mesh() != field2.mesh()) { - samurai::io::eprint(samurai::io::root, "mesh different\n"); + std::cout << "mesh different" << std::endl; return false; } diff --git a/include/samurai/io/cgal.hpp b/include/samurai/io/cgal.hpp index 76414c1f6..0b15b03c5 100644 --- a/include/samurai/io/cgal.hpp +++ b/include/samurai/io/cgal.hpp @@ -12,7 +12,6 @@ #include #include #include -#include "../print.hpp" #include @@ -167,7 +166,7 @@ namespace samurai CGALMesh cgal_mesh; if (!PMP::IO::read_polygon_mesh(input_file, cgal_mesh) || cgal_mesh.is_empty()) { - samurai::io::eprint(samurai::io::root, "Invalid input file.\n"); + std::cerr << "Invalid input file." << std::endl; return CGALMesh(); } diff --git a/include/samurai/mr/operators.hpp b/include/samurai/mr/operators.hpp index ecb6510e9..a533680ec 100644 --- a/include/samurai/mr/operators.hpp +++ b/include/samurai/mr/operators.hpp @@ -12,7 +12,6 @@ #include "../numeric/prediction.hpp" #include "../operators_base.hpp" #include "../utils.hpp" -#include "../print.hpp" namespace samurai { @@ -289,7 +288,7 @@ namespace samurai { if (std::isnan(qs_i(ii)) || std::isnan(qs_j(ii)) || std::isnan(qs_ij(ii))) { - samurai::io::eprint("NaN detected during the computation of details.\n"); + std::cerr << "NaN detected during the computation of details." << std::endl; save(fs::current_path(), "check_nan", {true, true}, field.mesh(), field); break; } @@ -299,7 +298,7 @@ namespace samurai { if (xt::any(xt::isnan(qs_ij))) { - samurai::io::eprint("NaN detected during the computation of details.\n"); + std::cerr << "NaN detected during the computation of details." << std::endl; save(fs::current_path(), "check_nan", {true, true}, field.mesh(), field); } } diff --git a/include/samurai/numeric/prediction.hpp b/include/samurai/numeric/prediction.hpp index efda52e1e..d95209fc9 100644 --- a/include/samurai/numeric/prediction.hpp +++ b/include/samurai/numeric/prediction.hpp @@ -8,8 +8,6 @@ #include #include -#include -#include "../print.hpp" #include "../operators_base.hpp" #include "../storage/utils.hpp" @@ -578,8 +576,8 @@ namespace samurai #ifdef SAMURAI_CHECK_NAN if (xt::any(xt::isnan(qs_ij))) { - samurai::io::eprint("NaN detected in the prediction stencil (Qs_ij).\n{} -", fmt::streamed(qs_ij)); + std::cerr << "NaN detected in the prediction stencil (Qs_ij)." << std::endl; + std::cerr << qs_ij << std::endl; save(fs::current_path(), "check_nan", {true, true}, src.mesh(), src); } #endif diff --git a/include/samurai/petsc/fv/FV_scheme_assembly.hpp b/include/samurai/petsc/fv/FV_scheme_assembly.hpp index 3cb364625..abe9ab2b9 100644 --- a/include/samurai/petsc/fv/FV_scheme_assembly.hpp +++ b/include/samurai/petsc/fv/FV_scheme_assembly.hpp @@ -4,8 +4,6 @@ #include "../../numeric/prediction.hpp" #include "../../schemes/fv/FV_scheme.hpp" #include "../../schemes/fv/scheme_operators.hpp" -#include "../../print.hpp" -#include #include "../matrix_assembly.hpp" namespace samurai @@ -518,11 +516,8 @@ namespace samurai VecGetSize(b, &b_rows); if (b_rows != this->matrix_cols()) { - samurai::io::eprint(samurai::io::root, - "Operator '{}': the number of rows in vector ({}) does not equal the number of columns of the matrix ({})\n", - this->name(), - b_rows, - this->matrix_cols()); + std::cerr << "Operator '" << this->name() << "': the number of rows in vector (" << b_rows + << ") does not equal the number of columns of the matrix (" << this->matrix_cols() << ")" << std::endl; assert(false); return; } @@ -611,13 +606,9 @@ namespace samurai INSERT_VALUES); if (error) { - samurai::io::eprint(samurai::io::root, - "{}: failure to insert diagonal coefficient at ({}, {}), i.e. ({}, {}) in the block.\n", - scheme().name(), - m_row_shift + static_cast(i), - m_col_shift + static_cast(i), - i, - i); + std::cerr << scheme().name() << ": failure to insert diagonal coefficient at (" + << m_row_shift + static_cast(i) << ", " << m_col_shift + static_cast(i) + << "), i.e. (" << i << ", " << i << ") in the block." << std::endl; assert(false); exit(EXIT_FAILURE); } @@ -762,11 +753,8 @@ namespace samurai current_insert_mode()); if (error) { - samurai::io::eprint(samurai::io::root, - "{}: failure to insert projection coefficient at ({}, {}).\n", - scheme().name(), - ghost_index, - m_col_shift + col_index(children[i], field_i)); + std::cerr << scheme().name() << ": failure to insert projection coefficient at (" << ghost_index + << ", " << m_col_shift + col_index(children[i], field_i) << ")." << std::endl; assert(false); exit(EXIT_FAILURE); } diff --git a/include/samurai/schemes/block_operator.hpp b/include/samurai/schemes/block_operator.hpp index 92ae7ef34..48e08b557 100644 --- a/include/samurai/schemes/block_operator.hpp +++ b/include/samurai/schemes/block_operator.hpp @@ -1,6 +1,5 @@ #pragma once #include "../utils.hpp" -#include "../print.hpp" namespace samurai { @@ -95,13 +94,8 @@ namespace samurai using op_field_t = typename operator_t::field_t; if constexpr (!std::is_same_v, op_field_t>) { - samurai::io::eprint( - samurai::io::root, - "unknown {} is not compatible with the scheme ({}, {}) (named '{}')\n", - i, - row, - col, - op.name()); + std::cerr << "unknown " << i << " is not compatible with the scheme (" << row << ", " << col + << ") (named '" << op.name() << "')" << std::endl; assert(false); exit(EXIT_FAILURE); } diff --git a/include/samurai/schemes/fv/cell_based/cell_based_scheme__nonlin.hpp b/include/samurai/schemes/fv/cell_based/cell_based_scheme__nonlin.hpp index ac782fd15..eb75c38b4 100644 --- a/include/samurai/schemes/fv/cell_based/cell_based_scheme__nonlin.hpp +++ b/include/samurai/schemes/fv/cell_based/cell_based_scheme__nonlin.hpp @@ -178,11 +178,8 @@ namespace samurai { if (!jacobian_function()) { - samurai::io::eprint(samurai::io::root, - "The jacobian function of operator '{}' has not been implemented.\n", - this->name()); - samurai::io::eprint(samurai::io::root, - "Use option -snes_mf or -snes_fd for an automatic computation of the jacobian matrix.\n"); + std::cerr << "The jacobian function of operator '" << this->name() << "' has not been implemented." << std::endl; + std::cerr << "Use option -snes_mf or -snes_fd for an automatic computation of the jacobian matrix." << std::endl; exit(EXIT_FAILURE); } diff --git a/include/samurai/schemes/fv/explicit_FV_scheme.hpp b/include/samurai/schemes/fv/explicit_FV_scheme.hpp index 61e233ae2..5b6b096f3 100644 --- a/include/samurai/schemes/fv/explicit_FV_scheme.hpp +++ b/include/samurai/schemes/fv/explicit_FV_scheme.hpp @@ -1,7 +1,6 @@ #pragma once #include "../explicit_scheme.hpp" #include "FV_scheme.hpp" -#include "../../print.hpp" namespace samurai { @@ -84,7 +83,7 @@ namespace samurai virtual void apply(std::size_t /* d */, output_field_t& /* output_field */, input_field_t& /* input_field */) { - samurai::io::eprint(samurai::io::root, "The scheme '{}' cannot be applied by direction.\n", scheme().name()); + std::cerr << "The scheme '" << scheme().name() << "' cannot be applied by direction." << std::endl; assert(false); exit(EXIT_FAILURE); } diff --git a/include/samurai/schemes/fv/flux_based/explicit_flux_based_scheme__lin_het.hpp b/include/samurai/schemes/fv/flux_based/explicit_flux_based_scheme__lin_het.hpp index b2a034811..1a120fe49 100644 --- a/include/samurai/schemes/fv/flux_based/explicit_flux_based_scheme__lin_het.hpp +++ b/include/samurai/schemes/fv/flux_based/explicit_flux_based_scheme__lin_het.hpp @@ -63,9 +63,8 @@ namespace samurai #ifdef SAMURAI_CHECK_NAN if (std::isnan(field_value(input_field, comput_cells[c], field_j))) { - samurai::io::eprint( - "NaN detected when computing the flux on the interior interfaces: {}\n", - fmt::streamed(comput_cells[c])); + std::cerr << "NaN detected when computing the flux on the interior interfaces: " << comput_cells[c] + << std::endl; assert(false); } #endif @@ -97,9 +96,8 @@ namespace samurai #ifdef SAMURAI_CHECK_NAN if (std::isnan(field_value(input_field, comput_cells[c], field_j))) { - samurai::io::eprint( - "NaN detected when computing the flux on the boundary interfaces: {}\n", - fmt::streamed(comput_cells[c])); + std::cerr << "NaN detected when computing the flux on the boundary interfaces: " << comput_cells[c] + << std::endl; assert(false); } #endif @@ -114,5 +112,3 @@ namespace samurai }; } // end namespace samurai -#include "../../../print.hpp" -#include diff --git a/include/samurai/schemes/fv/flux_based/explicit_flux_based_scheme__lin_hom.hpp b/include/samurai/schemes/fv/flux_based/explicit_flux_based_scheme__lin_hom.hpp index c57e2092a..ecc2cdddc 100644 --- a/include/samurai/schemes/fv/flux_based/explicit_flux_based_scheme__lin_hom.hpp +++ b/include/samurai/schemes/fv/flux_based/explicit_flux_based_scheme__lin_hom.hpp @@ -287,7 +287,9 @@ namespace samurai #ifdef SAMURAI_CHECK_NAN if (std::isnan(field_value(input_field, stencil.cells()[c], field_j))) { - std::cerr << "NaN detected when computing the flux on the boundary interfaces: " << stencil.cells()[c] << std::endl; + std::cerr + << "NaN detected when computing the flux on the boundary interfaces: " << stencil.cells()[c] + << std::endl; assert(false); } #endif @@ -316,5 +318,3 @@ namespace samurai }; } // end namespace samurai -#include "../../../print.hpp" -#include diff --git a/include/samurai/schemes/fv/flux_based/flux_based_scheme.hpp b/include/samurai/schemes/fv/flux_based/flux_based_scheme.hpp index 73c64dc52..5d41b8fe1 100644 --- a/include/samurai/schemes/fv/flux_based/flux_based_scheme.hpp +++ b/include/samurai/schemes/fv/flux_based/flux_based_scheme.hpp @@ -1,6 +1,5 @@ #pragma once #include "../../../arguments.hpp" -#include "../../../print.hpp" #include "../../../interface.hpp" #include "../../../reconstruction.hpp" #include "../../explicit_scheme.hpp" @@ -25,8 +24,8 @@ namespace samurai // cppcheck-suppress knownConditionTrueFalse if (args::finer_level_flux != 0 && cfg::dim > 1 && cfg::stencil_size > 4 && !args::refine_boundary) { - samurai::io::eprint(samurai::io::root, - "Warning: for stencils larger than 4, computing fluxes at max_level may cause issues close to the boundary.\n"); + std::cout << "Warning: for stencils larger than 4, computing fluxes at max_level may cause issues close to the boundary." + << std::endl; } return FluxBasedScheme(flux_definition); diff --git a/include/samurai/schemes/fv/flux_based/flux_based_scheme__nonlin.hpp b/include/samurai/schemes/fv/flux_based/flux_based_scheme__nonlin.hpp index 5619da51b..c8c5eced7 100644 --- a/include/samurai/schemes/fv/flux_based/flux_based_scheme__nonlin.hpp +++ b/include/samurai/schemes/fv/flux_based/flux_based_scheme__nonlin.hpp @@ -1,7 +1,5 @@ #pragma once #include "flux_based_scheme.hpp" -#include "../../../print.hpp" -#include namespace samurai { @@ -105,8 +103,8 @@ namespace samurai { if (enable && dim > 1 && stencil_size > 4 && !args::refine_boundary) // cppcheck-suppress knownConditionTrueFalse { - samurai::io::eprint(samurai::io::root, - "Warning: for stencils larger than 4, computing fluxes at max_level may cause issues close to the boundary.\n"); + std::cout << "Warning: for stencils larger than 4, computing fluxes at max_level may cause issues close to the boundary." + << std::endl; } m_finer_level_flux = enable ? -1 : 0; } @@ -597,11 +595,8 @@ namespace samurai if (!jacobian_function) { - samurai::io::eprint(samurai::io::root, - "The jacobian function of operator '{}' has not been implemented.\n", - this->name()); - samurai::io::eprint(samurai::io::root, - "Use option -snes_mf or -snes_fd for an automatic computation of the jacobian matrix.\n"); + std::cerr << "The jacobian function of operator '" << this->name() << "' has not been implemented." << std::endl; + std::cerr << "Use option -snes_mf or -snes_fd for an automatic computation of the jacobian matrix." << std::endl; exit(EXIT_FAILURE); } From f9be34eb2d0b245a893900ff9d434fe0639f3c0d Mon Sep 17 00:00:00 2001 From: sbstndb/sbstndbs Date: Fri, 3 Oct 2025 11:16:36 +0200 Subject: [PATCH 20/37] io: convert std::cout to samurai::io::print (root where appropriate); keep std::cerr and timers.hpp unchanged --- include/samurai/algorithm/update.hpp | 14 +++++++------- include/samurai/field.hpp | 11 +++++++---- include/samurai/mr/adapt.hpp | 2 +- include/samurai/samurai.hpp | 2 +- .../schemes/fv/flux_based/flux_based_scheme.hpp | 5 +++-- .../fv/flux_based/flux_based_scheme__nonlin.hpp | 5 +++-- 6 files changed, 22 insertions(+), 17 deletions(-) diff --git a/include/samurai/algorithm/update.hpp b/include/samurai/algorithm/update.hpp index b889f991e..62d0b93ec 100644 --- a/include/samurai/algorithm/update.hpp +++ b/include/samurai/algorithm/update.hpp @@ -849,13 +849,13 @@ namespace samurai [&](const auto& i, const auto& index) { // delete cell - std::cout << fmt::format("fall intersection between {} {} on level {} in {} {}", - world.rank(), - neighbour.rank, - level, - i, - index[0]) - << std::endl; + samurai::io::print(samurai::io::root, + "fall intersection between {} {} on level {} in {} {}\n", + world.rank(), + neighbour.rank, + level, + fmt::streamed(i), + fmt::streamed(index[0])); }); } } diff --git a/include/samurai/field.hpp b/include/samurai/field.hpp index dcc968a3b..6b988968f 100644 --- a/include/samurai/field.hpp +++ b/include/samurai/field.hpp @@ -29,6 +29,7 @@ namespace fs = std::filesystem; #include "numeric/gauss_legendre.hpp" #include "storage/containers.hpp" #include "timers.hpp" +#include "print.hpp" namespace samurai { @@ -536,7 +537,8 @@ namespace samurai // level_field[cell] = cell.level; // }); // save(fs::current_path(), "mesh_throw", {true, true}, this->mesh(), coords, level_field); - (std::cout << ... << index) << std::endl; + ((samurai::io::print("{} ", index)), ...); + samurai::io::print("\n"); throw std::out_of_range(fmt::format("FIELD ERROR on level {}: try to find interval {}", level, interval)); } @@ -748,7 +750,7 @@ namespace samurai if (field1.mesh() != field2.mesh()) { - std::cout << "mesh different" << std::endl; + samurai::io::print(samurai::io::root, "mesh different\n"); return false; } @@ -1166,7 +1168,8 @@ namespace samurai // level_field[cell] = cell.level; // }); // save(fs::current_path(), "mesh_throw", {true, true}, this->mesh(), coords, level_field); - (std::cout << ... << index) << std::endl; + ((samurai::io::print("{} ", index)), ...); + samurai::io::print("\n"); throw std::out_of_range(fmt::format("FIELD ERROR on level {}: try to find interval {}", level, interval)); } @@ -1377,7 +1380,7 @@ namespace samurai if (field1.mesh() != field2.mesh()) { - std::cout << "mesh different" << std::endl; + samurai::io::print(samurai::io::root, "mesh different\n"); return false; } diff --git a/include/samurai/mr/adapt.hpp b/include/samurai/mr/adapt.hpp index 958c14a7f..8eb6ba32b 100644 --- a/include/samurai/mr/adapt.hpp +++ b/include/samurai/mr/adapt.hpp @@ -418,7 +418,7 @@ namespace samurai requires(!IsField) && (IsField && ...) auto make_MRAdapt(Prediction_fn&& prediction_fn, TFields&... fields) { - std::cout << "Use custom prediction function for MRAdapt" << std::endl; + samurai::io::print(samurai::io::root, "Use custom prediction function for MRAdapt\n"); return Adapt(std::forward(prediction_fn), fields...); } diff --git a/include/samurai/samurai.hpp b/include/samurai/samurai.hpp index 87837a31e..1bfbf16b2 100644 --- a/include/samurai/samurai.hpp +++ b/include/samurai/samurai.hpp @@ -97,7 +97,7 @@ namespace samurai if (args::timers) // cppcheck-suppress knownConditionTrueFalse { times::timers.stop("total runtime"); - std::cout << std::endl; + samurai::io::print(samurai::io::root, "\n"); times::timers.print(); } #ifdef SAMURAI_WITH_MPI diff --git a/include/samurai/schemes/fv/flux_based/flux_based_scheme.hpp b/include/samurai/schemes/fv/flux_based/flux_based_scheme.hpp index 5d41b8fe1..b6f4a07d1 100644 --- a/include/samurai/schemes/fv/flux_based/flux_based_scheme.hpp +++ b/include/samurai/schemes/fv/flux_based/flux_based_scheme.hpp @@ -5,6 +5,7 @@ #include "../../explicit_scheme.hpp" #include "../FV_scheme.hpp" #include "flux_definition.hpp" +#include "../../../print.hpp" namespace samurai { @@ -24,8 +25,8 @@ namespace samurai // cppcheck-suppress knownConditionTrueFalse if (args::finer_level_flux != 0 && cfg::dim > 1 && cfg::stencil_size > 4 && !args::refine_boundary) { - std::cout << "Warning: for stencils larger than 4, computing fluxes at max_level may cause issues close to the boundary." - << std::endl; + samurai::io::print(samurai::io::root, + "Warning: for stencils larger than 4, computing fluxes at max_level may cause issues close to the boundary.\n"); } return FluxBasedScheme(flux_definition); diff --git a/include/samurai/schemes/fv/flux_based/flux_based_scheme__nonlin.hpp b/include/samurai/schemes/fv/flux_based/flux_based_scheme__nonlin.hpp index c8c5eced7..1b349cd2a 100644 --- a/include/samurai/schemes/fv/flux_based/flux_based_scheme__nonlin.hpp +++ b/include/samurai/schemes/fv/flux_based/flux_based_scheme__nonlin.hpp @@ -1,5 +1,6 @@ #pragma once #include "flux_based_scheme.hpp" +#include "../../../print.hpp" namespace samurai { @@ -103,8 +104,8 @@ namespace samurai { if (enable && dim > 1 && stencil_size > 4 && !args::refine_boundary) // cppcheck-suppress knownConditionTrueFalse { - std::cout << "Warning: for stencils larger than 4, computing fluxes at max_level may cause issues close to the boundary." - << std::endl; + samurai::io::print(samurai::io::root, + "Warning: for stencils larger than 4, computing fluxes at max_level may cause issues close to the boundary.\n"); } m_finer_level_flux = enable ? -1 : 0; } From 5024bfd587f3a2ef112e89432da5f78839ec7e37 Mon Sep 17 00:00:00 2001 From: sbstndb/sbstndbs Date: Fri, 3 Oct 2025 11:16:52 +0200 Subject: [PATCH 21/37] style: clang-format includes and wrapping --- include/samurai/field.hpp | 2 +- .../samurai/schemes/fv/flux_based/flux_based_scheme.hpp | 7 ++++--- .../schemes/fv/flux_based/flux_based_scheme__nonlin.hpp | 7 ++++--- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/include/samurai/field.hpp b/include/samurai/field.hpp index 6b988968f..0901c3490 100644 --- a/include/samurai/field.hpp +++ b/include/samurai/field.hpp @@ -27,9 +27,9 @@ namespace fs = std::filesystem; #include "field_expression.hpp" #include "mesh_holder.hpp" #include "numeric/gauss_legendre.hpp" +#include "print.hpp" #include "storage/containers.hpp" #include "timers.hpp" -#include "print.hpp" namespace samurai { diff --git a/include/samurai/schemes/fv/flux_based/flux_based_scheme.hpp b/include/samurai/schemes/fv/flux_based/flux_based_scheme.hpp index b6f4a07d1..5d903c9c2 100644 --- a/include/samurai/schemes/fv/flux_based/flux_based_scheme.hpp +++ b/include/samurai/schemes/fv/flux_based/flux_based_scheme.hpp @@ -1,11 +1,11 @@ #pragma once #include "../../../arguments.hpp" #include "../../../interface.hpp" +#include "../../../print.hpp" #include "../../../reconstruction.hpp" #include "../../explicit_scheme.hpp" #include "../FV_scheme.hpp" #include "flux_definition.hpp" -#include "../../../print.hpp" namespace samurai { @@ -25,8 +25,9 @@ namespace samurai // cppcheck-suppress knownConditionTrueFalse if (args::finer_level_flux != 0 && cfg::dim > 1 && cfg::stencil_size > 4 && !args::refine_boundary) { - samurai::io::print(samurai::io::root, - "Warning: for stencils larger than 4, computing fluxes at max_level may cause issues close to the boundary.\n"); + samurai::io::print( + samurai::io::root, + "Warning: for stencils larger than 4, computing fluxes at max_level may cause issues close to the boundary.\n"); } return FluxBasedScheme(flux_definition); diff --git a/include/samurai/schemes/fv/flux_based/flux_based_scheme__nonlin.hpp b/include/samurai/schemes/fv/flux_based/flux_based_scheme__nonlin.hpp index 1b349cd2a..55180c707 100644 --- a/include/samurai/schemes/fv/flux_based/flux_based_scheme__nonlin.hpp +++ b/include/samurai/schemes/fv/flux_based/flux_based_scheme__nonlin.hpp @@ -1,6 +1,6 @@ #pragma once -#include "flux_based_scheme.hpp" #include "../../../print.hpp" +#include "flux_based_scheme.hpp" namespace samurai { @@ -104,8 +104,9 @@ namespace samurai { if (enable && dim > 1 && stencil_size > 4 && !args::refine_boundary) // cppcheck-suppress knownConditionTrueFalse { - samurai::io::print(samurai::io::root, - "Warning: for stencils larger than 4, computing fluxes at max_level may cause issues close to the boundary.\n"); + samurai::io::print( + samurai::io::root, + "Warning: for stencils larger than 4, computing fluxes at max_level may cause issues close to the boundary.\n"); } m_finer_level_flux = enable ? -1 : 0; } From b63e5dfa6ef5e37a90b5cbe1f9b04b698b47a3c4 Mon Sep 17 00:00:00 2001 From: sbstndb/sbstndbs Date: Fri, 3 Oct 2025 11:29:01 +0200 Subject: [PATCH 22/37] io: convert std::cerr/std::cout to samurai::io::eprint/print across include/ (excluding timers.hpp); add includes and fmt::streamed where needed --- include/samurai/assert_log_trace.hpp | 9 +++-- include/samurai/box.hpp | 8 ++-- include/samurai/field.hpp | 2 +- include/samurai/io/cgal.hpp | 2 +- include/samurai/mr/operators.hpp | 6 ++- include/samurai/numeric/prediction.hpp | 5 ++- include/samurai/petsc/block_assembly.hpp | 32 ++++++++++++---- .../samurai/petsc/fv/FV_scheme_assembly.hpp | 38 +++++++++++++------ .../petsc/fv/operator_sum_assembly.hpp | 27 ++++++++----- include/samurai/petsc/linear_block_solver.hpp | 3 +- include/samurai/petsc/linear_solver.hpp | 13 +++---- .../samurai/petsc/nonlinear_local_solvers.hpp | 17 +++++---- include/samurai/petsc/nonlinear_solver.hpp | 19 +++++----- include/samurai/petsc/utils.hpp | 3 +- include/samurai/petsc/zero_block_assembly.hpp | 3 +- include/samurai/schemes/block_operator.hpp | 9 ++++- include/samurai/schemes/fv/FV_scheme.hpp | 9 +++-- .../cell_based/cell_based_scheme__nonlin.hpp | 9 ++++- .../samurai/schemes/fv/explicit_FV_scheme.hpp | 3 +- .../explicit_flux_based_scheme__lin_het.hpp | 12 ++++-- .../explicit_flux_based_scheme__lin_hom.hpp | 8 ++-- .../flux_based/flux_based_scheme__nonlin.hpp | 7 +++- 22 files changed, 160 insertions(+), 84 deletions(-) diff --git a/include/samurai/assert_log_trace.hpp b/include/samurai/assert_log_trace.hpp index 62ede9861..fe9ca459b 100644 --- a/include/samurai/assert_log_trace.hpp +++ b/include/samurai/assert_log_trace.hpp @@ -1,13 +1,16 @@ #pragma once + #include +#include "print.hpp" +#include #define SAMURAI_ASSERT(condition, msg) \ do \ { \ if (!(condition)) \ { \ - std::cerr << "Assertion failed \nin " << __FILE__ << "\n @line " << __LINE__ << ": " << msg << std::endl; \ + samurai::io::eprint("Assertion failed \nin {} \n @line {}: {}\n", __FILE__, __LINE__, fmt::streamed(msg)); \ std::terminate(); \ } \ } while (false) @@ -16,13 +19,13 @@ #define SAMURAI_LOG(msg) \ do \ { \ - std::cerr << "SMR::Log:: " << msg << std::endl; \ + samurai::io::eprint("SMR::Log:: {}\n", fmt::streamed(msg)); \ } while (0) #define SAMURAI_TRACE(msg) \ do \ { \ - std::cerr << "SMR::Trace[line " << __LINE__ << "] :" << msg << std::endl; \ + samurai::io::eprint("SMR::Trace[line {}] :{}\n", __LINE__, fmt::streamed(msg)); \ } while (0) // #else // #define MGS_LOG( msg ) diff --git a/include/samurai/box.hpp b/include/samurai/box.hpp index 8f0dd1c76..1efa4839b 100644 --- a/include/samurai/box.hpp +++ b/include/samurai/box.hpp @@ -6,6 +6,8 @@ #include "utils.hpp" #include #include +#include +#include "print.hpp" namespace samurai { @@ -309,9 +311,9 @@ namespace samurai // ... and no tolerance is allowed, we raise an error. if (tol == 0) { - std::cerr << "The box " << box << " cannot be exactly represented with a reasonable cell length. "; - std::cerr << "You can modify the box's dimensions or you can set a tolerance so it can be approximately represented." - << std::endl; + samurai::io::eprint( + "The box {} cannot be exactly represented with a reasonable cell length. You can modify the box's dimensions or you can set a tolerance so it can be approximately represented.\n", + fmt::streamed(box)); std::exit(1); } diff --git a/include/samurai/field.hpp b/include/samurai/field.hpp index 0901c3490..04774aab4 100644 --- a/include/samurai/field.hpp +++ b/include/samurai/field.hpp @@ -258,7 +258,7 @@ namespace samurai if (xt::any(xt::isnan(data))) { // std::cout << data << std::endl; - std::cerr << "READ NaN at level " << level << ", " << interval << std::endl; + samurai::io::eprint("READ NaN at level {}, {}\n", level, fmt::streamed(interval)); } #endif return data; diff --git a/include/samurai/io/cgal.hpp b/include/samurai/io/cgal.hpp index 0b15b03c5..b69b67543 100644 --- a/include/samurai/io/cgal.hpp +++ b/include/samurai/io/cgal.hpp @@ -166,7 +166,7 @@ namespace samurai CGALMesh cgal_mesh; if (!PMP::IO::read_polygon_mesh(input_file, cgal_mesh) || cgal_mesh.is_empty()) { - std::cerr << "Invalid input file." << std::endl; + samurai::io::eprint("Invalid input file.\n"); return CGALMesh(); } diff --git a/include/samurai/mr/operators.hpp b/include/samurai/mr/operators.hpp index a533680ec..6732e5619 100644 --- a/include/samurai/mr/operators.hpp +++ b/include/samurai/mr/operators.hpp @@ -12,6 +12,8 @@ #include "../numeric/prediction.hpp" #include "../operators_base.hpp" #include "../utils.hpp" +#include "../print.hpp" +#include namespace samurai { @@ -288,7 +290,7 @@ namespace samurai { if (std::isnan(qs_i(ii)) || std::isnan(qs_j(ii)) || std::isnan(qs_ij(ii))) { - std::cerr << "NaN detected during the computation of details." << std::endl; + samurai::io::eprint("NaN detected during the computation of details.\n"); save(fs::current_path(), "check_nan", {true, true}, field.mesh(), field); break; } @@ -298,7 +300,7 @@ namespace samurai { if (xt::any(xt::isnan(qs_ij))) { - std::cerr << "NaN detected during the computation of details." << std::endl; + samurai::io::eprint("NaN detected during the computation of details.\n"); save(fs::current_path(), "check_nan", {true, true}, field.mesh(), field); } } diff --git a/include/samurai/numeric/prediction.hpp b/include/samurai/numeric/prediction.hpp index d95209fc9..fd4114125 100644 --- a/include/samurai/numeric/prediction.hpp +++ b/include/samurai/numeric/prediction.hpp @@ -8,6 +8,8 @@ #include #include +#include "../print.hpp" +#include #include "../operators_base.hpp" #include "../storage/utils.hpp" @@ -576,8 +578,7 @@ namespace samurai #ifdef SAMURAI_CHECK_NAN if (xt::any(xt::isnan(qs_ij))) { - std::cerr << "NaN detected in the prediction stencil (Qs_ij)." << std::endl; - std::cerr << qs_ij << std::endl; + samurai::io::eprint("NaN detected in the prediction stencil (Qs_ij).\n{}\n", fmt::streamed(qs_ij)); save(fs::current_path(), "check_nan", {true, true}, src.mesh(), src); } #endif diff --git a/include/samurai/petsc/block_assembly.hpp b/include/samurai/petsc/block_assembly.hpp index ec0311c06..2b789c4b3 100644 --- a/include/samurai/petsc/block_assembly.hpp +++ b/include/samurai/petsc/block_assembly.hpp @@ -1,6 +1,8 @@ #pragma once #include "../schemes/block_operator.hpp" #include "utils.hpp" +#include "../print.hpp" +#include #include "zero_block_assembly.hpp" namespace samurai @@ -121,8 +123,12 @@ namespace samurai } else if (op.matrix_rows() != block_rows) { - std::cerr << "Assembly failure: incompatible number of rows of block (" << row << ", " << col - << "): " << op.matrix_rows() << " (expected " << block_rows << ")" << std::endl; + samurai::io::eprint( + "Assembly failure: incompatible number of rows of block ({}, {}): {} (expected {})\n", + row, + col, + op.matrix_rows(), + block_rows); exit(EXIT_FAILURE); } } @@ -154,8 +160,12 @@ namespace samurai } else if (op.matrix_cols() != block_cols) { - std::cerr << "Assembly failure: incompatible number of columns of block (" << row << ", " << col - << "): " << op.matrix_cols() << " (expected " << block_cols << ")" << std::endl; + samurai::io::eprint( + "Assembly failure: incompatible number of columns of block ({}, {}): {} (expected {})\n", + row, + col, + op.matrix_cols(), + block_cols); exit(EXIT_FAILURE); } } @@ -192,8 +202,12 @@ namespace samurai } else { - std::cerr << "unknown " << i << " is not compatible with the scheme (" << row << ", " - << col << ") (named '" << op.name() << "')" << std::endl; + samurai::io::eprint( + "unknown {} is not compatible with the scheme ({}, {}) (named '{}')\n", + i, + row, + col, + op.name()); assert(false); exit(EXIT_FAILURE); } @@ -241,8 +255,10 @@ namespace samurai { if (row == col && op.matrix_rows() != op.matrix_cols()) { - std::cerr << "Function 'create_vector()' is ambiguous in this context, because the block (" << row << ", " << col - << ") is not square. Use 'create_applicable_vector()' or 'create_rhs_vector()' instead." << std::endl; + samurai::io::eprint( + "Function 'create_vector()' is ambiguous in this context, because the block ({}, {}) is not square. Use 'create_applicable_vector()' or 'create_rhs_vector()' instead.\n", + row, + col); exit(EXIT_FAILURE); } }); diff --git a/include/samurai/petsc/fv/FV_scheme_assembly.hpp b/include/samurai/petsc/fv/FV_scheme_assembly.hpp index abe9ab2b9..a0af5f52b 100644 --- a/include/samurai/petsc/fv/FV_scheme_assembly.hpp +++ b/include/samurai/petsc/fv/FV_scheme_assembly.hpp @@ -4,6 +4,8 @@ #include "../../numeric/prediction.hpp" #include "../../schemes/fv/FV_scheme.hpp" #include "../../schemes/fv/scheme_operators.hpp" +#include "../../print.hpp" +#include #include "../matrix_assembly.hpp" namespace samurai @@ -90,7 +92,7 @@ namespace samurai { if (!m_unknown) { - std::cerr << "Undefined unknown for operator " << scheme().name() << ". Assembly initialization failed!" << std::endl; + samurai::io::eprint("Undefined unknown for operator {}. Assembly initialization failed!\n", this->name()); assert(false); exit(EXIT_FAILURE); } @@ -280,8 +282,10 @@ namespace samurai if (cfg_t::stencil_size > 1 && unknown().get_bc().empty()) { - std::cerr << "Failure to assemble the boundary conditions in the operator '" << this->name() - << "': no boundary condition attached to the field '" << unknown().name() << "'." << std::endl; + samurai::io::eprint( + "Failure to assemble the boundary conditions in the operator '{}': no boundary condition attached to the field '{}'.\n", + this->name(), + unknown().name()); assert(false); continue; } @@ -329,8 +333,8 @@ namespace samurai } else { - std::cerr << "Unknown boundary condition type. Only Dirichlet and Neumann are implemented at the moment." - << std::endl; + samurai::io::eprint( + "Unknown boundary condition type. Only Dirichlet and Neumann are implemented at the moment.\n"); } } } @@ -516,8 +520,11 @@ namespace samurai VecGetSize(b, &b_rows); if (b_rows != this->matrix_cols()) { - std::cerr << "Operator '" << this->name() << "': the number of rows in vector (" << b_rows - << ") does not equal the number of columns of the matrix (" << this->matrix_cols() << ")" << std::endl; + samurai::io::eprint( + "Operator '{}': the number of rows in vector ({}) does not equal the number of columns of the matrix ({})\n", + this->name(), + b_rows, + this->matrix_cols()); assert(false); return; } @@ -606,9 +613,13 @@ namespace samurai INSERT_VALUES); if (error) { - std::cerr << scheme().name() << ": failure to insert diagonal coefficient at (" - << m_row_shift + static_cast(i) << ", " << m_col_shift + static_cast(i) - << "), i.e. (" << i << ", " << i << ") in the block." << std::endl; + samurai::io::eprint( + "{}: failure to insert diagonal coefficient at ({}, {}), i.e. ({}, {}) in the block.\n", + scheme().name(), + m_row_shift + static_cast(i), + m_col_shift + static_cast(i), + i, + i); assert(false); exit(EXIT_FAILURE); } @@ -753,8 +764,11 @@ namespace samurai current_insert_mode()); if (error) { - std::cerr << scheme().name() << ": failure to insert projection coefficient at (" << ghost_index - << ", " << m_col_shift + col_index(children[i], field_i) << ")." << std::endl; + samurai::io::eprint( + "{}: failure to insert projection coefficient at ({}, {}).\n", + scheme().name(), + ghost_index, + m_col_shift + col_index(children[i], field_i)); assert(false); exit(EXIT_FAILURE); } diff --git a/include/samurai/petsc/fv/operator_sum_assembly.hpp b/include/samurai/petsc/fv/operator_sum_assembly.hpp index 78fbc4272..01c914b6b 100644 --- a/include/samurai/petsc/fv/operator_sum_assembly.hpp +++ b/include/samurai/petsc/fv/operator_sum_assembly.hpp @@ -1,6 +1,8 @@ #pragma once #include "../../schemes/fv/scheme_operators.hpp" #include "../matrix_assembly.hpp" +#include "../../print.hpp" +#include namespace samurai { @@ -130,10 +132,14 @@ namespace samurai { if (op.matrix_rows() != rows) { - std::cerr << "Invalid '+' operation: all schemes must generate the same number of matrix rows." << std::endl; - std::cerr << " '" << std::get<0>(m_assembly_ops).name() - << "': " << std::get<0>(m_assembly_ops).matrix_rows() << ", " << op.name() << ": " - << op.matrix_rows() << std::endl; + samurai::io::eprint( + "Invalid '+' operation: all schemes must generate the same number of matrix rows.\n"); + samurai::io::eprint( + " '{}' : {}, {}: {}\n", + std::get<0>(m_assembly_ops).name(), + std::get<0>(m_assembly_ops).matrix_rows(), + op.name(), + op.matrix_rows()); assert(false); } }); @@ -148,11 +154,14 @@ namespace samurai { if (op.matrix_cols() != cols) { - std::cerr << "Invalid '+' operation: all schemes must generate the same number of matrix columns." - << std::endl; - std::cerr << " '" << std::get<0>(m_assembly_ops).name() - << "': " << std::get<0>(m_assembly_ops).matrix_cols() << ", " << op.name() << ": " - << op.matrix_cols() << std::endl; + samurai::io::eprint( + "Invalid '+' operation: all schemes must generate the same number of matrix columns.\n"); + samurai::io::eprint( + " '{}' : {}, {}: {}\n", + std::get<0>(m_assembly_ops).name(), + std::get<0>(m_assembly_ops).matrix_cols(), + op.name(), + op.matrix_cols()); assert(false); } }); diff --git a/include/samurai/petsc/linear_block_solver.hpp b/include/samurai/petsc/linear_block_solver.hpp index bcbe16f0c..eb6260921 100644 --- a/include/samurai/petsc/linear_block_solver.hpp +++ b/include/samurai/petsc/linear_block_solver.hpp @@ -2,6 +2,7 @@ #include "block_assembly.hpp" #include "linear_solver.hpp" +#include "../print.hpp" namespace samurai { @@ -71,7 +72,7 @@ namespace samurai { if (m_A == nullptr) { - std::cerr << "The matrix must be assemble before calling set_pc_fieldsplit()." << std::endl; + samurai::io::eprint("The matrix must be assemble before calling set_pc_fieldsplit().\n"); exit(EXIT_FAILURE); } IS IS_fields[cols]; diff --git a/include/samurai/petsc/linear_solver.hpp b/include/samurai/petsc/linear_solver.hpp index 28afc89e9..ec6b6e9fb 100644 --- a/include/samurai/petsc/linear_solver.hpp +++ b/include/samurai/petsc/linear_solver.hpp @@ -4,6 +4,7 @@ #include "fv/cell_based_scheme_assembly.hpp" #include "fv/flux_based_scheme_assembly.hpp" #include "fv/operator_sum_assembly.hpp" +#include "../print.hpp" #ifdef ENABLE_MG #include "multigrid/petsc/GeometricMultigrid.hpp" #else @@ -129,7 +130,7 @@ namespace samurai { if (assembly().undefined_unknown()) { - std::cerr << "Undefined unknown(s) for this linear system. Please set the unknowns using the instruction '[solver].set_unknown(u);' or '[solver].set_unknowns(u1, u2...);'." + samurai::io::eprint("Undefined unknown(s) for this linear system. Please set the unknowns using the instruction '[solver].set_unknown(u);' or '[solver].set_unknowns(u1, u2...).\n"); << std::endl; assert(false && "Undefined unknown(s)"); exit(EXIT_FAILURE); @@ -161,7 +162,7 @@ namespace samurai if (err != PETSC_SUCCESS) { - std::cerr << "The setup of the solver failed!" << std::endl; + samurai::io::eprint("The setup of the solver failed!\n"); assert(false && "Failed solver setup"); exit(EXIT_FAILURE); } @@ -204,7 +205,7 @@ namespace samurai using namespace std::string_literals; const char* reason_text; KSPGetConvergedReasonString(m_ksp, &reason_text); - std::cerr << "Divergence of the solver ("s + reason_text + ")" << std::endl; + samurai::io::eprint("Divergence of the solver ({})\n", reason_text); // VecView(b, PETSC_VIEWER_STDOUT_(PETSC_COMM_SELF)); // std::cout << std::endl; // assert(check_nan_or_inf(b)); @@ -290,9 +291,7 @@ namespace samurai { if constexpr (Mesh::dim > 2) { - std::cerr << "Samurai Multigrid is not implemented for " - "dim > 2." - << std::endl; + samurai::io::eprint("Samurai Multigrid is not implemented for dim > 2.\n"); assert(false); exit(EXIT_FAILURE); } @@ -325,7 +324,7 @@ namespace samurai } if (assembly().undefined_unknown()) { - std::cerr << "Undefined unknown for this linear system. Please set the unknown using the instruction '[solver].set_unknown(u);'." + samurai::io::eprint("Undefined unknown for this linear system. Please set the unknown using the instruction '[solver].set_unknown(u);'.\n"); << std::endl; assert(false && "Undefined unknown"); exit(EXIT_FAILURE); diff --git a/include/samurai/petsc/nonlinear_local_solvers.hpp b/include/samurai/petsc/nonlinear_local_solvers.hpp index 6bd6201ff..f5afacba1 100644 --- a/include/samurai/petsc/nonlinear_local_solvers.hpp +++ b/include/samurai/petsc/nonlinear_local_solvers.hpp @@ -3,6 +3,7 @@ #include "fv/flux_based_scheme_assembly.hpp" #include "fv/operator_sum_assembly.hpp" #include "utils.hpp" +#include "../print.hpp" #include namespace samurai @@ -50,15 +51,17 @@ namespace samurai { if (!m_scheme.scheme_definition().local_scheme_function) { - std::cerr << "The scheme function 'local_scheme_function' of operator '" << scheme.name() - << "' has not been implemented." << std::endl; + samurai::io::eprint( + "The scheme function 'local_scheme_function' of operator '{}' has not been implemented.\n", + scheme.name()); assert(false && "Undefined 'local_scheme_function'"); exit(EXIT_FAILURE); } if (!m_scheme.scheme_definition().local_jacobian_function) { - std::cerr << "The function 'local_jacobian_function' of operator '" << scheme.name() << "' has not been implemented." - << std::endl; + samurai::io::eprint( + "The function 'local_jacobian_function' of operator '{}' has not been implemented.\n", + scheme.name()); assert(false && "Undefined 'local_jacobian_function'"); exit(EXIT_FAILURE); } @@ -114,8 +117,8 @@ namespace samurai { if (!m_unknown) { - std::cerr << "Undefined unknown for this non-linear system. Please set the unknowns using the instruction '[solver].set_unknown(u);'." - << std::endl; + samurai::io::eprint( + "Undefined unknown for this non-linear system. Please set the unknowns using the instruction '[solver].set_unknown(u);'.\n"); assert(false && "Undefined unknown"); exit(EXIT_FAILURE); } @@ -285,7 +288,7 @@ namespace samurai using namespace std::string_literals; const char* reason_text; SNESGetConvergedReasonString(snes, &reason_text); - std::cerr << "Divergence of the non-linear solver ("s + reason_text + ")" << std::endl; + samurai::io::eprint("Divergence of the non-linear solver ({})\n", reason_text); // VecView(b, PETSC_VIEWER_STDOUT_(PETSC_COMM_SELF)); // std::cout << std::endl; // assert(check_nan_or_inf(b)); diff --git a/include/samurai/petsc/nonlinear_solver.hpp b/include/samurai/petsc/nonlinear_solver.hpp index f8dd96929..d0e4aaf42 100644 --- a/include/samurai/petsc/nonlinear_solver.hpp +++ b/include/samurai/petsc/nonlinear_solver.hpp @@ -3,6 +3,7 @@ #include "fv/flux_based_scheme_assembly.hpp" #include "fv/operator_sum_assembly.hpp" #include "utils.hpp" +#include "../print.hpp" #include namespace samurai @@ -133,8 +134,8 @@ namespace samurai if (assembly().undefined_unknown()) { - std::cerr << "Undefined unknown(s) for this non-linear system. Please set the unknowns using the instruction '[solver].set_unknown(u);' or '[solver].set_unknowns(u1, u2...);'." - << std::endl; + samurai::io::eprint( + "Undefined unknown(s) for this non-linear system. Please set the unknowns using the instruction '[solver].set_unknown(u);' or '[solver].set_unknowns(u1, u2...).\n"); assert(false && "Undefined unknown(s)"); exit(EXIT_FAILURE); } @@ -266,13 +267,13 @@ namespace samurai using namespace std::string_literals; const char* reason_text; SNESGetConvergedReasonString(m_snes, &reason_text); - std::cerr << "Divergence of the non-linear solver ("s + reason_text + ")" << std::endl; - // VecView(b, PETSC_VIEWER_STDOUT_(PETSC_COMM_SELF)); - // std::cout << std::endl; - // assert(check_nan_or_inf(b)); - assert(false && "Divergence of the solver"); - exit(EXIT_FAILURE); - } + samurai::io::eprint("Divergence of the non-linear solver ({})\n", reason_text); + // VecView(b, PETSC_VIEWER_STDOUT_(PETSC_COMM_SELF)); + // std::cout << std::endl; + // assert(check_nan_or_inf(b)); + assert(false && "Divergence of the solver"); + exit(EXIT_FAILURE); + } // VecView(x, PETSC_VIEWER_STDOUT_(PETSC_COMM_SELF)); std::cout << std::endl; } diff --git a/include/samurai/petsc/utils.hpp b/include/samurai/petsc/utils.hpp index 704c42b76..44d57fc08 100644 --- a/include/samurai/petsc/utils.hpp +++ b/include/samurai/petsc/utils.hpp @@ -1,6 +1,7 @@ #pragma once #include #include +#include "../print.hpp" namespace samurai { @@ -160,7 +161,7 @@ namespace samurai { is_nan_or_inf = true; VecView(v, PETSC_VIEWER_STDOUT_(PETSC_COMM_SELF)); - std::cout << std::endl; + samurai::io::print(samurai::io::root, "\n"); break; } } diff --git a/include/samurai/petsc/zero_block_assembly.hpp b/include/samurai/petsc/zero_block_assembly.hpp index e0070026e..2372ae50f 100644 --- a/include/samurai/petsc/zero_block_assembly.hpp +++ b/include/samurai/petsc/zero_block_assembly.hpp @@ -1,5 +1,6 @@ #pragma once #include "matrix_assembly.hpp" +#include "../print.hpp" namespace samurai { @@ -18,7 +19,7 @@ namespace samurai { if (value != 0) { - std::cerr << "Unimplemented Assembly(" << value << ")" << std::endl; + samurai::io::eprint("Unimplemented Assembly({})\n", value); exit(EXIT_FAILURE); } this->fit_block_dimensions(true); diff --git a/include/samurai/schemes/block_operator.hpp b/include/samurai/schemes/block_operator.hpp index 48e08b557..314b72387 100644 --- a/include/samurai/schemes/block_operator.hpp +++ b/include/samurai/schemes/block_operator.hpp @@ -1,5 +1,6 @@ #pragma once #include "../utils.hpp" +#include "../print.hpp" namespace samurai { @@ -94,8 +95,12 @@ namespace samurai using op_field_t = typename operator_t::field_t; if constexpr (!std::is_same_v, op_field_t>) { - std::cerr << "unknown " << i << " is not compatible with the scheme (" << row << ", " << col - << ") (named '" << op.name() << "')" << std::endl; + samurai::io::eprint( + "unknown {} is not compatible with the scheme ({}, {}) (named '{}')\n", + i, + row, + col, + op.name()); assert(false); exit(EXIT_FAILURE); } diff --git a/include/samurai/schemes/fv/FV_scheme.hpp b/include/samurai/schemes/fv/FV_scheme.hpp index cdfa0d2e3..f285b6835 100644 --- a/include/samurai/schemes/fv/FV_scheme.hpp +++ b/include/samurai/schemes/fv/FV_scheme.hpp @@ -5,6 +5,8 @@ #include "../../field.hpp" #include "../../static_algorithm.hpp" #include "../../timers.hpp" +#include "../../print.hpp" +#include #include "utils.hpp" namespace samurai @@ -181,7 +183,8 @@ namespace samurai { if (input_field.mesh().is_periodic()) { - std::cerr << "Error: apply_directional_bc() not implemented for non-box domains with periodic directions." << std::endl; + samurai::io::eprint( + "Error: apply_directional_bc() not implemented for non-box domains with periodic directions.\n"); assert(false); return; } @@ -320,7 +323,7 @@ namespace samurai return m_dirichlet_config[d]; } } - std::cerr << "No Dirichlet config found for direction " << direction << std::endl; + samurai::io::eprint("No Dirichlet config found for direction {}\n", fmt::streamed(direction)); assert(false); return m_dirichlet_config[0]; } @@ -373,7 +376,7 @@ namespace samurai return m_neumann_config[d]; } } - std::cerr << "No Neumann config found for direction " << direction << std::endl; + samurai::io::eprint("No Neumann config found for direction {}\n", fmt::streamed(direction)); assert(false); return m_neumann_config[0]; } diff --git a/include/samurai/schemes/fv/cell_based/cell_based_scheme__nonlin.hpp b/include/samurai/schemes/fv/cell_based/cell_based_scheme__nonlin.hpp index eb75c38b4..180cad04f 100644 --- a/include/samurai/schemes/fv/cell_based/cell_based_scheme__nonlin.hpp +++ b/include/samurai/schemes/fv/cell_based/cell_based_scheme__nonlin.hpp @@ -1,5 +1,7 @@ #pragma once #include "cell_based_scheme.hpp" +#include "../../../print.hpp" +#include namespace samurai { @@ -178,8 +180,11 @@ namespace samurai { if (!jacobian_function()) { - std::cerr << "The jacobian function of operator '" << this->name() << "' has not been implemented." << std::endl; - std::cerr << "Use option -snes_mf or -snes_fd for an automatic computation of the jacobian matrix." << std::endl; + samurai::io::eprint( + "The jacobian function of operator '{}' has not been implemented.\n", + this->name()); + samurai::io::eprint( + "Use option -snes_mf or -snes_fd for an automatic computation of the jacobian matrix.\n"); exit(EXIT_FAILURE); } diff --git a/include/samurai/schemes/fv/explicit_FV_scheme.hpp b/include/samurai/schemes/fv/explicit_FV_scheme.hpp index 5b6b096f3..e0685052a 100644 --- a/include/samurai/schemes/fv/explicit_FV_scheme.hpp +++ b/include/samurai/schemes/fv/explicit_FV_scheme.hpp @@ -1,6 +1,7 @@ #pragma once #include "../explicit_scheme.hpp" #include "FV_scheme.hpp" +#include "../../print.hpp" namespace samurai { @@ -83,7 +84,7 @@ namespace samurai virtual void apply(std::size_t /* d */, output_field_t& /* output_field */, input_field_t& /* input_field */) { - std::cerr << "The scheme '" << scheme().name() << "' cannot be applied by direction." << std::endl; + samurai::io::eprint("The scheme '{}' cannot be applied by direction.\n", scheme().name()); assert(false); exit(EXIT_FAILURE); } diff --git a/include/samurai/schemes/fv/flux_based/explicit_flux_based_scheme__lin_het.hpp b/include/samurai/schemes/fv/flux_based/explicit_flux_based_scheme__lin_het.hpp index 1a120fe49..19e9b56ff 100644 --- a/include/samurai/schemes/fv/flux_based/explicit_flux_based_scheme__lin_het.hpp +++ b/include/samurai/schemes/fv/flux_based/explicit_flux_based_scheme__lin_het.hpp @@ -2,6 +2,8 @@ // #include "../../../petsc/fv/flux_based_scheme_assembly.hpp" #include "../explicit_FV_scheme.hpp" #include "flux_based_scheme__lin_het.hpp" +#include "../../../print.hpp" +#include namespace samurai { @@ -63,8 +65,9 @@ namespace samurai #ifdef SAMURAI_CHECK_NAN if (std::isnan(field_value(input_field, comput_cells[c], field_j))) { - std::cerr << "NaN detected when computing the flux on the interior interfaces: " << comput_cells[c] - << std::endl; + samurai::io::eprint( + "NaN detected when computing the flux on the interior interfaces: {}\n", + fmt::streamed(comput_cells[c])); assert(false); } #endif @@ -96,8 +99,9 @@ namespace samurai #ifdef SAMURAI_CHECK_NAN if (std::isnan(field_value(input_field, comput_cells[c], field_j))) { - std::cerr << "NaN detected when computing the flux on the boundary interfaces: " << comput_cells[c] - << std::endl; + samurai::io::eprint( + "NaN detected when computing the flux on the boundary interfaces: {}\n", + fmt::streamed(comput_cells[c])); assert(false); } #endif diff --git a/include/samurai/schemes/fv/flux_based/explicit_flux_based_scheme__lin_hom.hpp b/include/samurai/schemes/fv/flux_based/explicit_flux_based_scheme__lin_hom.hpp index ecc2cdddc..7ee582a86 100644 --- a/include/samurai/schemes/fv/flux_based/explicit_flux_based_scheme__lin_hom.hpp +++ b/include/samurai/schemes/fv/flux_based/explicit_flux_based_scheme__lin_hom.hpp @@ -2,6 +2,8 @@ // #include "../../../petsc/fv/flux_based_scheme_assembly.hpp" #include "../explicit_FV_scheme.hpp" #include "flux_based_scheme__lin_hom.hpp" +#include "../../../print.hpp" +#include namespace samurai { @@ -287,9 +289,9 @@ namespace samurai #ifdef SAMURAI_CHECK_NAN if (std::isnan(field_value(input_field, stencil.cells()[c], field_j))) { - std::cerr - << "NaN detected when computing the flux on the boundary interfaces: " << stencil.cells()[c] - << std::endl; + samurai::io::eprint( + "NaN detected when computing the flux on the boundary interfaces: {}\n", + fmt::streamed(stencil.cells()[c])); assert(false); } #endif diff --git a/include/samurai/schemes/fv/flux_based/flux_based_scheme__nonlin.hpp b/include/samurai/schemes/fv/flux_based/flux_based_scheme__nonlin.hpp index 55180c707..647e3f22b 100644 --- a/include/samurai/schemes/fv/flux_based/flux_based_scheme__nonlin.hpp +++ b/include/samurai/schemes/fv/flux_based/flux_based_scheme__nonlin.hpp @@ -597,8 +597,11 @@ namespace samurai if (!jacobian_function) { - std::cerr << "The jacobian function of operator '" << this->name() << "' has not been implemented." << std::endl; - std::cerr << "Use option -snes_mf or -snes_fd for an automatic computation of the jacobian matrix." << std::endl; + samurai::io::eprint( + "The jacobian function of operator '{}' has not been implemented.\n", + this->name()); + samurai::io::eprint( + "Use option -snes_mf or -snes_fd for an automatic computation of the jacobian matrix.\n"); exit(EXIT_FAILURE); } From 170bf72f6428b94f5c682576afac9a00924da040 Mon Sep 17 00:00:00 2001 From: sbstndb/sbstndbs Date: Fri, 3 Oct 2025 11:29:15 +0200 Subject: [PATCH 23/37] style: apply clang-format --- include/samurai/assert_log_trace.hpp | 29 +++++++++--------- include/samurai/box.hpp | 4 +-- include/samurai/mr/operators.hpp | 2 +- include/samurai/numeric/prediction.hpp | 4 +-- include/samurai/petsc/block_assembly.hpp | 26 ++++++++-------- .../samurai/petsc/fv/FV_scheme_assembly.hpp | 26 ++++++++-------- .../petsc/fv/operator_sum_assembly.hpp | 30 ++++++++----------- include/samurai/petsc/linear_block_solver.hpp | 2 +- include/samurai/petsc/linear_solver.hpp | 12 ++++---- .../samurai/petsc/nonlinear_local_solvers.hpp | 11 +++---- include/samurai/petsc/nonlinear_solver.hpp | 14 ++++----- include/samurai/petsc/utils.hpp | 2 +- include/samurai/petsc/zero_block_assembly.hpp | 2 +- include/samurai/schemes/block_operator.hpp | 13 ++++---- include/samurai/schemes/fv/FV_scheme.hpp | 7 ++--- .../cell_based/cell_based_scheme__nonlin.hpp | 9 ++---- .../samurai/schemes/fv/explicit_FV_scheme.hpp | 2 +- .../explicit_flux_based_scheme__lin_het.hpp | 12 ++++---- .../explicit_flux_based_scheme__lin_hom.hpp | 7 ++--- .../flux_based/flux_based_scheme__nonlin.hpp | 7 ++--- 20 files changed, 100 insertions(+), 121 deletions(-) diff --git a/include/samurai/assert_log_trace.hpp b/include/samurai/assert_log_trace.hpp index fe9ca459b..2a05e4601 100644 --- a/include/samurai/assert_log_trace.hpp +++ b/include/samurai/assert_log_trace.hpp @@ -1,30 +1,29 @@ #pragma once - -#include #include "print.hpp" #include +#include -#define SAMURAI_ASSERT(condition, msg) \ - do \ - { \ - if (!(condition)) \ - { \ +#define SAMURAI_ASSERT(condition, msg) \ + do \ + { \ + if (!(condition)) \ + { \ samurai::io::eprint("Assertion failed \nin {} \n @line {}: {}\n", __FILE__, __LINE__, fmt::streamed(msg)); \ - std::terminate(); \ - } \ + std::terminate(); \ + } \ } while (false) // #ifdef NDEBUG -#define SAMURAI_LOG(msg) \ - do \ - { \ +#define SAMURAI_LOG(msg) \ + do \ + { \ samurai::io::eprint("SMR::Log:: {}\n", fmt::streamed(msg)); \ } while (0) -#define SAMURAI_TRACE(msg) \ - do \ - { \ +#define SAMURAI_TRACE(msg) \ + do \ + { \ samurai::io::eprint("SMR::Trace[line {}] :{}\n", __LINE__, fmt::streamed(msg)); \ } while (0) // #else diff --git a/include/samurai/box.hpp b/include/samurai/box.hpp index 1efa4839b..1a11c3d36 100644 --- a/include/samurai/box.hpp +++ b/include/samurai/box.hpp @@ -3,11 +3,11 @@ #pragma once +#include "print.hpp" #include "utils.hpp" +#include #include #include -#include -#include "print.hpp" namespace samurai { diff --git a/include/samurai/mr/operators.hpp b/include/samurai/mr/operators.hpp index 6732e5619..aaba49a69 100644 --- a/include/samurai/mr/operators.hpp +++ b/include/samurai/mr/operators.hpp @@ -11,8 +11,8 @@ #include "../field.hpp" #include "../numeric/prediction.hpp" #include "../operators_base.hpp" -#include "../utils.hpp" #include "../print.hpp" +#include "../utils.hpp" #include namespace samurai diff --git a/include/samurai/numeric/prediction.hpp b/include/samurai/numeric/prediction.hpp index fd4114125..a5f87e33d 100644 --- a/include/samurai/numeric/prediction.hpp +++ b/include/samurai/numeric/prediction.hpp @@ -6,10 +6,10 @@ #include #include -#include -#include #include "../print.hpp" #include +#include +#include #include "../operators_base.hpp" #include "../storage/utils.hpp" diff --git a/include/samurai/petsc/block_assembly.hpp b/include/samurai/petsc/block_assembly.hpp index 2b789c4b3..9849ac071 100644 --- a/include/samurai/petsc/block_assembly.hpp +++ b/include/samurai/petsc/block_assembly.hpp @@ -1,9 +1,9 @@ #pragma once +#include "../print.hpp" #include "../schemes/block_operator.hpp" #include "utils.hpp" -#include "../print.hpp" -#include #include "zero_block_assembly.hpp" +#include namespace samurai { @@ -123,12 +123,11 @@ namespace samurai } else if (op.matrix_rows() != block_rows) { - samurai::io::eprint( - "Assembly failure: incompatible number of rows of block ({}, {}): {} (expected {})\n", - row, - col, - op.matrix_rows(), - block_rows); + samurai::io::eprint("Assembly failure: incompatible number of rows of block ({}, {}): {} (expected {})\n", + row, + col, + op.matrix_rows(), + block_rows); exit(EXIT_FAILURE); } } @@ -202,12 +201,11 @@ namespace samurai } else { - samurai::io::eprint( - "unknown {} is not compatible with the scheme ({}, {}) (named '{}')\n", - i, - row, - col, - op.name()); + samurai::io::eprint("unknown {} is not compatible with the scheme ({}, {}) (named '{}')\n", + i, + row, + col, + op.name()); assert(false); exit(EXIT_FAILURE); } diff --git a/include/samurai/petsc/fv/FV_scheme_assembly.hpp b/include/samurai/petsc/fv/FV_scheme_assembly.hpp index a0af5f52b..a9eabb472 100644 --- a/include/samurai/petsc/fv/FV_scheme_assembly.hpp +++ b/include/samurai/petsc/fv/FV_scheme_assembly.hpp @@ -2,11 +2,11 @@ #include "../../algorithm/update.hpp" #include "../../boundary.hpp" #include "../../numeric/prediction.hpp" +#include "../../print.hpp" #include "../../schemes/fv/FV_scheme.hpp" #include "../../schemes/fv/scheme_operators.hpp" -#include "../../print.hpp" -#include #include "../matrix_assembly.hpp" +#include namespace samurai { @@ -613,13 +613,12 @@ namespace samurai INSERT_VALUES); if (error) { - samurai::io::eprint( - "{}: failure to insert diagonal coefficient at ({}, {}), i.e. ({}, {}) in the block.\n", - scheme().name(), - m_row_shift + static_cast(i), - m_col_shift + static_cast(i), - i, - i); + samurai::io::eprint("{}: failure to insert diagonal coefficient at ({}, {}), i.e. ({}, {}) in the block.\n", + scheme().name(), + m_row_shift + static_cast(i), + m_col_shift + static_cast(i), + i, + i); assert(false); exit(EXIT_FAILURE); } @@ -764,11 +763,10 @@ namespace samurai current_insert_mode()); if (error) { - samurai::io::eprint( - "{}: failure to insert projection coefficient at ({}, {}).\n", - scheme().name(), - ghost_index, - m_col_shift + col_index(children[i], field_i)); + samurai::io::eprint("{}: failure to insert projection coefficient at ({}, {}).\n", + scheme().name(), + ghost_index, + m_col_shift + col_index(children[i], field_i)); assert(false); exit(EXIT_FAILURE); } diff --git a/include/samurai/petsc/fv/operator_sum_assembly.hpp b/include/samurai/petsc/fv/operator_sum_assembly.hpp index 01c914b6b..5e14d5034 100644 --- a/include/samurai/petsc/fv/operator_sum_assembly.hpp +++ b/include/samurai/petsc/fv/operator_sum_assembly.hpp @@ -1,7 +1,7 @@ #pragma once +#include "../../print.hpp" #include "../../schemes/fv/scheme_operators.hpp" #include "../matrix_assembly.hpp" -#include "../../print.hpp" #include namespace samurai @@ -132,14 +132,12 @@ namespace samurai { if (op.matrix_rows() != rows) { - samurai::io::eprint( - "Invalid '+' operation: all schemes must generate the same number of matrix rows.\n"); - samurai::io::eprint( - " '{}' : {}, {}: {}\n", - std::get<0>(m_assembly_ops).name(), - std::get<0>(m_assembly_ops).matrix_rows(), - op.name(), - op.matrix_rows()); + samurai::io::eprint("Invalid '+' operation: all schemes must generate the same number of matrix rows.\n"); + samurai::io::eprint(" '{}' : {}, {}: {}\n", + std::get<0>(m_assembly_ops).name(), + std::get<0>(m_assembly_ops).matrix_rows(), + op.name(), + op.matrix_rows()); assert(false); } }); @@ -154,14 +152,12 @@ namespace samurai { if (op.matrix_cols() != cols) { - samurai::io::eprint( - "Invalid '+' operation: all schemes must generate the same number of matrix columns.\n"); - samurai::io::eprint( - " '{}' : {}, {}: {}\n", - std::get<0>(m_assembly_ops).name(), - std::get<0>(m_assembly_ops).matrix_cols(), - op.name(), - op.matrix_cols()); + samurai::io::eprint("Invalid '+' operation: all schemes must generate the same number of matrix columns.\n"); + samurai::io::eprint(" '{}' : {}, {}: {}\n", + std::get<0>(m_assembly_ops).name(), + std::get<0>(m_assembly_ops).matrix_cols(), + op.name(), + op.matrix_cols()); assert(false); } }); diff --git a/include/samurai/petsc/linear_block_solver.hpp b/include/samurai/petsc/linear_block_solver.hpp index eb6260921..8f4b2f4a3 100644 --- a/include/samurai/petsc/linear_block_solver.hpp +++ b/include/samurai/petsc/linear_block_solver.hpp @@ -1,8 +1,8 @@ #pragma once +#include "../print.hpp" #include "block_assembly.hpp" #include "linear_solver.hpp" -#include "../print.hpp" namespace samurai { diff --git a/include/samurai/petsc/linear_solver.hpp b/include/samurai/petsc/linear_solver.hpp index ec6b6e9fb..d9ad2e0ba 100644 --- a/include/samurai/petsc/linear_solver.hpp +++ b/include/samurai/petsc/linear_solver.hpp @@ -1,10 +1,10 @@ #pragma once // #define ENABLE_MG +#include "../print.hpp" #include "fv/cell_based_scheme_assembly.hpp" #include "fv/flux_based_scheme_assembly.hpp" #include "fv/operator_sum_assembly.hpp" -#include "../print.hpp" #ifdef ENABLE_MG #include "multigrid/petsc/GeometricMultigrid.hpp" #else @@ -130,8 +130,9 @@ namespace samurai { if (assembly().undefined_unknown()) { - samurai::io::eprint("Undefined unknown(s) for this linear system. Please set the unknowns using the instruction '[solver].set_unknown(u);' or '[solver].set_unknowns(u1, u2...).\n"); - << std::endl; + samurai::io::eprint( + "Undefined unknown(s) for this linear system. Please set the unknowns using the instruction '[solver].set_unknown(u);' or '[solver].set_unknowns(u1, u2...).\n"); + << std::endl; assert(false && "Undefined unknown(s)"); exit(EXIT_FAILURE); } @@ -324,8 +325,9 @@ namespace samurai } if (assembly().undefined_unknown()) { - samurai::io::eprint("Undefined unknown for this linear system. Please set the unknown using the instruction '[solver].set_unknown(u);'.\n"); - << std::endl; + samurai::io::eprint( + "Undefined unknown for this linear system. Please set the unknown using the instruction '[solver].set_unknown(u);'.\n"); + << std::endl; assert(false && "Undefined unknown"); exit(EXIT_FAILURE); } diff --git a/include/samurai/petsc/nonlinear_local_solvers.hpp b/include/samurai/petsc/nonlinear_local_solvers.hpp index f5afacba1..1ff013a04 100644 --- a/include/samurai/petsc/nonlinear_local_solvers.hpp +++ b/include/samurai/petsc/nonlinear_local_solvers.hpp @@ -1,9 +1,9 @@ #pragma once +#include "../print.hpp" #include "fv/cell_based_scheme_assembly.hpp" #include "fv/flux_based_scheme_assembly.hpp" #include "fv/operator_sum_assembly.hpp" #include "utils.hpp" -#include "../print.hpp" #include namespace samurai @@ -51,17 +51,14 @@ namespace samurai { if (!m_scheme.scheme_definition().local_scheme_function) { - samurai::io::eprint( - "The scheme function 'local_scheme_function' of operator '{}' has not been implemented.\n", - scheme.name()); + samurai::io::eprint("The scheme function 'local_scheme_function' of operator '{}' has not been implemented.\n", + scheme.name()); assert(false && "Undefined 'local_scheme_function'"); exit(EXIT_FAILURE); } if (!m_scheme.scheme_definition().local_jacobian_function) { - samurai::io::eprint( - "The function 'local_jacobian_function' of operator '{}' has not been implemented.\n", - scheme.name()); + samurai::io::eprint("The function 'local_jacobian_function' of operator '{}' has not been implemented.\n", scheme.name()); assert(false && "Undefined 'local_jacobian_function'"); exit(EXIT_FAILURE); } diff --git a/include/samurai/petsc/nonlinear_solver.hpp b/include/samurai/petsc/nonlinear_solver.hpp index d0e4aaf42..ff1182149 100644 --- a/include/samurai/petsc/nonlinear_solver.hpp +++ b/include/samurai/petsc/nonlinear_solver.hpp @@ -1,9 +1,9 @@ #pragma once +#include "../print.hpp" #include "fv/cell_based_scheme_assembly.hpp" #include "fv/flux_based_scheme_assembly.hpp" #include "fv/operator_sum_assembly.hpp" #include "utils.hpp" -#include "../print.hpp" #include namespace samurai @@ -268,12 +268,12 @@ namespace samurai const char* reason_text; SNESGetConvergedReasonString(m_snes, &reason_text); samurai::io::eprint("Divergence of the non-linear solver ({})\n", reason_text); - // VecView(b, PETSC_VIEWER_STDOUT_(PETSC_COMM_SELF)); - // std::cout << std::endl; - // assert(check_nan_or_inf(b)); - assert(false && "Divergence of the solver"); - exit(EXIT_FAILURE); - } + // VecView(b, PETSC_VIEWER_STDOUT_(PETSC_COMM_SELF)); + // std::cout << std::endl; + // assert(check_nan_or_inf(b)); + assert(false && "Divergence of the solver"); + exit(EXIT_FAILURE); + } // VecView(x, PETSC_VIEWER_STDOUT_(PETSC_COMM_SELF)); std::cout << std::endl; } diff --git a/include/samurai/petsc/utils.hpp b/include/samurai/petsc/utils.hpp index 44d57fc08..fc7a37911 100644 --- a/include/samurai/petsc/utils.hpp +++ b/include/samurai/petsc/utils.hpp @@ -1,7 +1,7 @@ #pragma once +#include "../print.hpp" #include #include -#include "../print.hpp" namespace samurai { diff --git a/include/samurai/petsc/zero_block_assembly.hpp b/include/samurai/petsc/zero_block_assembly.hpp index 2372ae50f..663ca0b24 100644 --- a/include/samurai/petsc/zero_block_assembly.hpp +++ b/include/samurai/petsc/zero_block_assembly.hpp @@ -1,6 +1,6 @@ #pragma once -#include "matrix_assembly.hpp" #include "../print.hpp" +#include "matrix_assembly.hpp" namespace samurai { diff --git a/include/samurai/schemes/block_operator.hpp b/include/samurai/schemes/block_operator.hpp index 314b72387..7588fe1ae 100644 --- a/include/samurai/schemes/block_operator.hpp +++ b/include/samurai/schemes/block_operator.hpp @@ -1,6 +1,6 @@ #pragma once -#include "../utils.hpp" #include "../print.hpp" +#include "../utils.hpp" namespace samurai { @@ -95,12 +95,11 @@ namespace samurai using op_field_t = typename operator_t::field_t; if constexpr (!std::is_same_v, op_field_t>) { - samurai::io::eprint( - "unknown {} is not compatible with the scheme ({}, {}) (named '{}')\n", - i, - row, - col, - op.name()); + samurai::io::eprint("unknown {} is not compatible with the scheme ({}, {}) (named '{}')\n", + i, + row, + col, + op.name()); assert(false); exit(EXIT_FAILURE); } diff --git a/include/samurai/schemes/fv/FV_scheme.hpp b/include/samurai/schemes/fv/FV_scheme.hpp index f285b6835..3dfed8dc9 100644 --- a/include/samurai/schemes/fv/FV_scheme.hpp +++ b/include/samurai/schemes/fv/FV_scheme.hpp @@ -3,11 +3,11 @@ #include "../../boundary.hpp" #include "../../concepts.hpp" #include "../../field.hpp" +#include "../../print.hpp" #include "../../static_algorithm.hpp" #include "../../timers.hpp" -#include "../../print.hpp" -#include #include "utils.hpp" +#include namespace samurai { @@ -183,8 +183,7 @@ namespace samurai { if (input_field.mesh().is_periodic()) { - samurai::io::eprint( - "Error: apply_directional_bc() not implemented for non-box domains with periodic directions.\n"); + samurai::io::eprint("Error: apply_directional_bc() not implemented for non-box domains with periodic directions.\n"); assert(false); return; } diff --git a/include/samurai/schemes/fv/cell_based/cell_based_scheme__nonlin.hpp b/include/samurai/schemes/fv/cell_based/cell_based_scheme__nonlin.hpp index 180cad04f..a60023f24 100644 --- a/include/samurai/schemes/fv/cell_based/cell_based_scheme__nonlin.hpp +++ b/include/samurai/schemes/fv/cell_based/cell_based_scheme__nonlin.hpp @@ -1,6 +1,6 @@ #pragma once -#include "cell_based_scheme.hpp" #include "../../../print.hpp" +#include "cell_based_scheme.hpp" #include namespace samurai @@ -180,11 +180,8 @@ namespace samurai { if (!jacobian_function()) { - samurai::io::eprint( - "The jacobian function of operator '{}' has not been implemented.\n", - this->name()); - samurai::io::eprint( - "Use option -snes_mf or -snes_fd for an automatic computation of the jacobian matrix.\n"); + samurai::io::eprint("The jacobian function of operator '{}' has not been implemented.\n", this->name()); + samurai::io::eprint("Use option -snes_mf or -snes_fd for an automatic computation of the jacobian matrix.\n"); exit(EXIT_FAILURE); } diff --git a/include/samurai/schemes/fv/explicit_FV_scheme.hpp b/include/samurai/schemes/fv/explicit_FV_scheme.hpp index e0685052a..f1bc38caf 100644 --- a/include/samurai/schemes/fv/explicit_FV_scheme.hpp +++ b/include/samurai/schemes/fv/explicit_FV_scheme.hpp @@ -1,7 +1,7 @@ #pragma once +#include "../../print.hpp" #include "../explicit_scheme.hpp" #include "FV_scheme.hpp" -#include "../../print.hpp" namespace samurai { diff --git a/include/samurai/schemes/fv/flux_based/explicit_flux_based_scheme__lin_het.hpp b/include/samurai/schemes/fv/flux_based/explicit_flux_based_scheme__lin_het.hpp index 19e9b56ff..08e41abda 100644 --- a/include/samurai/schemes/fv/flux_based/explicit_flux_based_scheme__lin_het.hpp +++ b/include/samurai/schemes/fv/flux_based/explicit_flux_based_scheme__lin_het.hpp @@ -1,8 +1,8 @@ #pragma once // #include "../../../petsc/fv/flux_based_scheme_assembly.hpp" +#include "../../../print.hpp" #include "../explicit_FV_scheme.hpp" #include "flux_based_scheme__lin_het.hpp" -#include "../../../print.hpp" #include namespace samurai @@ -65,9 +65,8 @@ namespace samurai #ifdef SAMURAI_CHECK_NAN if (std::isnan(field_value(input_field, comput_cells[c], field_j))) { - samurai::io::eprint( - "NaN detected when computing the flux on the interior interfaces: {}\n", - fmt::streamed(comput_cells[c])); + samurai::io::eprint("NaN detected when computing the flux on the interior interfaces: {}\n", + fmt::streamed(comput_cells[c])); assert(false); } #endif @@ -99,9 +98,8 @@ namespace samurai #ifdef SAMURAI_CHECK_NAN if (std::isnan(field_value(input_field, comput_cells[c], field_j))) { - samurai::io::eprint( - "NaN detected when computing the flux on the boundary interfaces: {}\n", - fmt::streamed(comput_cells[c])); + samurai::io::eprint("NaN detected when computing the flux on the boundary interfaces: {}\n", + fmt::streamed(comput_cells[c])); assert(false); } #endif diff --git a/include/samurai/schemes/fv/flux_based/explicit_flux_based_scheme__lin_hom.hpp b/include/samurai/schemes/fv/flux_based/explicit_flux_based_scheme__lin_hom.hpp index 7ee582a86..9988e70c4 100644 --- a/include/samurai/schemes/fv/flux_based/explicit_flux_based_scheme__lin_hom.hpp +++ b/include/samurai/schemes/fv/flux_based/explicit_flux_based_scheme__lin_hom.hpp @@ -1,8 +1,8 @@ #pragma once // #include "../../../petsc/fv/flux_based_scheme_assembly.hpp" +#include "../../../print.hpp" #include "../explicit_FV_scheme.hpp" #include "flux_based_scheme__lin_hom.hpp" -#include "../../../print.hpp" #include namespace samurai @@ -289,9 +289,8 @@ namespace samurai #ifdef SAMURAI_CHECK_NAN if (std::isnan(field_value(input_field, stencil.cells()[c], field_j))) { - samurai::io::eprint( - "NaN detected when computing the flux on the boundary interfaces: {}\n", - fmt::streamed(stencil.cells()[c])); + samurai::io::eprint("NaN detected when computing the flux on the boundary interfaces: {}\n", + fmt::streamed(stencil.cells()[c])); assert(false); } #endif diff --git a/include/samurai/schemes/fv/flux_based/flux_based_scheme__nonlin.hpp b/include/samurai/schemes/fv/flux_based/flux_based_scheme__nonlin.hpp index 647e3f22b..b5a78f236 100644 --- a/include/samurai/schemes/fv/flux_based/flux_based_scheme__nonlin.hpp +++ b/include/samurai/schemes/fv/flux_based/flux_based_scheme__nonlin.hpp @@ -597,11 +597,8 @@ namespace samurai if (!jacobian_function) { - samurai::io::eprint( - "The jacobian function of operator '{}' has not been implemented.\n", - this->name()); - samurai::io::eprint( - "Use option -snes_mf or -snes_fd for an automatic computation of the jacobian matrix.\n"); + samurai::io::eprint("The jacobian function of operator '{}' has not been implemented.\n", this->name()); + samurai::io::eprint("Use option -snes_mf or -snes_fd for an automatic computation of the jacobian matrix.\n"); exit(EXIT_FAILURE); } From 698a9165fb716894dad33f0b6e1fd8d896e3bd60 Mon Sep 17 00:00:00 2001 From: sbstndb/sbstndbs Date: Fri, 3 Oct 2025 12:06:40 +0200 Subject: [PATCH 24/37] refactor: rely on print.hpp to provide fmt; remove redundant includes where print.hpp is already included --- include/samurai/algorithm/update.hpp | 2 -- include/samurai/assert_log_trace.hpp | 1 - include/samurai/bc/polynomial_extrapolation.hpp | 2 -- include/samurai/box.hpp | 1 - include/samurai/field.hpp | 3 --- include/samurai/level_cell_array.hpp | 2 -- include/samurai/memory.hpp | 2 -- include/samurai/mesh.hpp | 2 -- include/samurai/mr/operators.hpp | 1 - include/samurai/numeric/prediction.hpp | 1 - include/samurai/petsc/fv/FV_scheme_assembly.hpp | 1 - include/samurai/schemes/fv/FV_scheme.hpp | 1 - .../schemes/fv/cell_based/cell_based_scheme__nonlin.hpp | 1 - .../fv/flux_based/explicit_flux_based_scheme__lin_het.hpp | 1 - .../fv/flux_based/explicit_flux_based_scheme__lin_hom.hpp | 1 - include/samurai/stencil.hpp | 2 -- 16 files changed, 24 deletions(-) diff --git a/include/samurai/algorithm/update.hpp b/include/samurai/algorithm/update.hpp index 62d0b93ec..8e16f3033 100644 --- a/include/samurai/algorithm/update.hpp +++ b/include/samurai/algorithm/update.hpp @@ -2,8 +2,6 @@ // SPDX-License-Identifier: BSD-3-Clause #pragma once -#include -#include #include diff --git a/include/samurai/assert_log_trace.hpp b/include/samurai/assert_log_trace.hpp index 2a05e4601..0959539bf 100644 --- a/include/samurai/assert_log_trace.hpp +++ b/include/samurai/assert_log_trace.hpp @@ -1,7 +1,6 @@ #pragma once #include "print.hpp" -#include #include #define SAMURAI_ASSERT(condition, msg) \ diff --git a/include/samurai/bc/polynomial_extrapolation.hpp b/include/samurai/bc/polynomial_extrapolation.hpp index 912583aaa..b64a93681 100644 --- a/include/samurai/bc/polynomial_extrapolation.hpp +++ b/include/samurai/bc/polynomial_extrapolation.hpp @@ -4,8 +4,6 @@ #pragma once #include "../print.hpp" #include "bc.hpp" -#include -#include namespace samurai { diff --git a/include/samurai/box.hpp b/include/samurai/box.hpp index 1a11c3d36..25c5ef030 100644 --- a/include/samurai/box.hpp +++ b/include/samurai/box.hpp @@ -5,7 +5,6 @@ #include "print.hpp" #include "utils.hpp" -#include #include #include diff --git a/include/samurai/field.hpp b/include/samurai/field.hpp index 04774aab4..eb0d0ab27 100644 --- a/include/samurai/field.hpp +++ b/include/samurai/field.hpp @@ -2,8 +2,6 @@ // SPDX-License-Identifier: BSD-3-Clause #pragma once -#include -#include #include #include @@ -14,7 +12,6 @@ #include namespace fs = std::filesystem; -#include #include #include diff --git a/include/samurai/level_cell_array.hpp b/include/samurai/level_cell_array.hpp index 0eb2e2410..2555a8057 100644 --- a/include/samurai/level_cell_array.hpp +++ b/include/samurai/level_cell_array.hpp @@ -16,8 +16,6 @@ #include "print.hpp" #include -#include -#include #include "algorithm.hpp" #include "box.hpp" diff --git a/include/samurai/memory.hpp b/include/samurai/memory.hpp index 73ed78348..a234ff043 100644 --- a/include/samurai/memory.hpp +++ b/include/samurai/memory.hpp @@ -6,8 +6,6 @@ #include #include "print.hpp" -#include -#include #include "level_cell_array.hpp" diff --git a/include/samurai/mesh.hpp b/include/samurai/mesh.hpp index 73f1b7a4a..2474c4874 100644 --- a/include/samurai/mesh.hpp +++ b/include/samurai/mesh.hpp @@ -6,8 +6,6 @@ #include #include -#include -#include #include "cell_array.hpp" #include "cell_list.hpp" diff --git a/include/samurai/mr/operators.hpp b/include/samurai/mr/operators.hpp index aaba49a69..6a42b0e70 100644 --- a/include/samurai/mr/operators.hpp +++ b/include/samurai/mr/operators.hpp @@ -13,7 +13,6 @@ #include "../operators_base.hpp" #include "../print.hpp" #include "../utils.hpp" -#include namespace samurai { diff --git a/include/samurai/numeric/prediction.hpp b/include/samurai/numeric/prediction.hpp index a5f87e33d..b46da1516 100644 --- a/include/samurai/numeric/prediction.hpp +++ b/include/samurai/numeric/prediction.hpp @@ -7,7 +7,6 @@ #include #include "../print.hpp" -#include #include #include diff --git a/include/samurai/petsc/fv/FV_scheme_assembly.hpp b/include/samurai/petsc/fv/FV_scheme_assembly.hpp index a9eabb472..dbb0650c5 100644 --- a/include/samurai/petsc/fv/FV_scheme_assembly.hpp +++ b/include/samurai/petsc/fv/FV_scheme_assembly.hpp @@ -6,7 +6,6 @@ #include "../../schemes/fv/FV_scheme.hpp" #include "../../schemes/fv/scheme_operators.hpp" #include "../matrix_assembly.hpp" -#include namespace samurai { diff --git a/include/samurai/schemes/fv/FV_scheme.hpp b/include/samurai/schemes/fv/FV_scheme.hpp index 3dfed8dc9..109c0cda3 100644 --- a/include/samurai/schemes/fv/FV_scheme.hpp +++ b/include/samurai/schemes/fv/FV_scheme.hpp @@ -7,7 +7,6 @@ #include "../../static_algorithm.hpp" #include "../../timers.hpp" #include "utils.hpp" -#include namespace samurai { diff --git a/include/samurai/schemes/fv/cell_based/cell_based_scheme__nonlin.hpp b/include/samurai/schemes/fv/cell_based/cell_based_scheme__nonlin.hpp index a60023f24..d18cb43ad 100644 --- a/include/samurai/schemes/fv/cell_based/cell_based_scheme__nonlin.hpp +++ b/include/samurai/schemes/fv/cell_based/cell_based_scheme__nonlin.hpp @@ -1,7 +1,6 @@ #pragma once #include "../../../print.hpp" #include "cell_based_scheme.hpp" -#include namespace samurai { diff --git a/include/samurai/schemes/fv/flux_based/explicit_flux_based_scheme__lin_het.hpp b/include/samurai/schemes/fv/flux_based/explicit_flux_based_scheme__lin_het.hpp index 08e41abda..e4ad4ffb0 100644 --- a/include/samurai/schemes/fv/flux_based/explicit_flux_based_scheme__lin_het.hpp +++ b/include/samurai/schemes/fv/flux_based/explicit_flux_based_scheme__lin_het.hpp @@ -3,7 +3,6 @@ #include "../../../print.hpp" #include "../explicit_FV_scheme.hpp" #include "flux_based_scheme__lin_het.hpp" -#include namespace samurai { diff --git a/include/samurai/schemes/fv/flux_based/explicit_flux_based_scheme__lin_hom.hpp b/include/samurai/schemes/fv/flux_based/explicit_flux_based_scheme__lin_hom.hpp index 9988e70c4..d8845fc7d 100644 --- a/include/samurai/schemes/fv/flux_based/explicit_flux_based_scheme__lin_hom.hpp +++ b/include/samurai/schemes/fv/flux_based/explicit_flux_based_scheme__lin_hom.hpp @@ -3,7 +3,6 @@ #include "../../../print.hpp" #include "../explicit_FV_scheme.hpp" #include "flux_based_scheme__lin_hom.hpp" -#include namespace samurai { diff --git a/include/samurai/stencil.hpp b/include/samurai/stencil.hpp index 885ea4813..466564cc8 100644 --- a/include/samurai/stencil.hpp +++ b/include/samurai/stencil.hpp @@ -2,8 +2,6 @@ #include "indices.hpp" #include "print.hpp" #include "static_algorithm.hpp" -#include -#include namespace samurai { From cfb50cad79adf51db79351db50e2b4c63efcf028 Mon Sep 17 00:00:00 2001 From: sbstndb/sbstndbs Date: Fri, 3 Oct 2025 12:06:46 +0200 Subject: [PATCH 25/37] style: clang-format after header include cleanup --- include/samurai/field.hpp | 1 - include/samurai/mesh.hpp | 1 - 2 files changed, 2 deletions(-) diff --git a/include/samurai/field.hpp b/include/samurai/field.hpp index eb0d0ab27..c8ac44059 100644 --- a/include/samurai/field.hpp +++ b/include/samurai/field.hpp @@ -12,7 +12,6 @@ #include namespace fs = std::filesystem; - #include #include diff --git a/include/samurai/mesh.hpp b/include/samurai/mesh.hpp index 2474c4874..57ca272a1 100644 --- a/include/samurai/mesh.hpp +++ b/include/samurai/mesh.hpp @@ -6,7 +6,6 @@ #include #include - #include "cell_array.hpp" #include "cell_list.hpp" #include "domain_builder.hpp" From 5ee0002675f9de848f9db49c04772c43b04e57ca Mon Sep 17 00:00:00 2001 From: sbstndb/sbstndbs Date: Fri, 3 Oct 2025 12:16:24 +0200 Subject: [PATCH 26/37] demos: port top offenders to samurai::io::print/eprint (MPI-safe): LBM tests, highorder, set_operator, p4est simple_2d, WENO examples, bubble_2d; add includes --- demos/LBM/test_D1Q2.cpp | 19 ++++++------ demos/LBM/test_D1Q222.cpp | 19 ++++++------ demos/LBM/test_D1Q3.cpp | 19 ++++++------ demos/LBM/test_D1Q5.cpp | 19 ++++++------ demos/Weno/VF_level_set_houc5_amr.cpp | 5 +-- demos/Weno/VF_level_set_os5_amr.cpp | 5 +-- demos/Weno/heat_weno5_amr.cpp | 5 +-- demos/highorder/main.cpp | 15 ++++----- .../multigrid/petsc/GeometricMultigrid.hpp | 31 ++++++++++--------- demos/p4est/simple_2d.cpp | 15 ++++----- demos/pablo/bubble_2d.cpp | 3 +- demos/tutorial/set_operator.cpp | 15 ++++----- 12 files changed, 91 insertions(+), 79 deletions(-) diff --git a/demos/LBM/test_D1Q2.cpp b/demos/LBM/test_D1Q2.cpp index 1ea703f47..e4f9dde6a 100644 --- a/demos/LBM/test_D1Q2.cpp +++ b/demos/LBM/test_D1Q2.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include "boundary_conditions.hpp" @@ -369,7 +370,7 @@ int main(int argc, char* argv[]) if (result.count("help")) { - std::cout << options.help() << "\n"; + samurai::io::print(samurai::io::root, "{}\n", options.help()); } else { @@ -445,11 +446,11 @@ int main(int argc, char* argv[]) for (auto s : s_vect) { - std::cout << std::endl << "Relaxation parameter s = " << s; + samurai::io::print(samurai::io::root, "\nRelaxation parameter s = {}", s); std::string prefix(case_name + "_s_" + std::to_string(s) + "_"); - std::cout << std::endl << "Testing time behavior" << std::endl; + samurai::io::print(samurai::io::root, "\nTesting time behavior\n"); { double eps = 1.0e-4; // This remains fixed @@ -492,7 +493,7 @@ int main(int argc, char* argv[]) / static_cast(meshR.nb_cells(mesh_id_t::cells)) << std::endl; - std::cout << std::endl << "n = " << nb_ite << " Time = " << t << " Diff = " << error[1] << std::endl; + samurai::io::print(samurai::io::root, "\nn = {} Time = {} Diff = {}\n", nb_ite, t, error[1]); ; one_time_step(f, update_bc_for_level, s, lambda, ad_vel, test_number, finest_collision); @@ -500,7 +501,7 @@ int main(int argc, char* argv[]) t += dt; } - std::cout << std::endl; + samurai::io::print(samurai::io::root, "\n"); out_time_frames.close(); out_error_exact_ref.close(); @@ -508,7 +509,7 @@ int main(int argc, char* argv[]) out_compression.close(); } - std::cout << std::endl << "Testing eps behavior" << std::endl; + samurai::io::print(samurai::io::root, "\nTesting eps behavior\n"); { double eps = 0.1; std::size_t N_test = 50; @@ -525,7 +526,7 @@ int main(int argc, char* argv[]) for (std::size_t n_test = 0; n_test < N_test; ++n_test) { - std::cout << std::endl << "Test " << n_test << " eps = " << eps; + samurai::io::print(samurai::io::root, "\nTest {} eps = {}", n_test, eps); mesh_t mesh{box, min_level, max_level}; mesh_t meshR{box, max_level, max_level}; // This is the reference scheme @@ -555,7 +556,7 @@ int main(int argc, char* argv[]) } auto error = compute_error(f, fR, update_bc_for_level, t, ad_vel, test_number); - std::cout << "Diff = " << error[1] << std::endl; + samurai::io::print(samurai::io::root, "Diff = {}\n", error[1]); std::size_t max_level_effective = mesh.min_level(); @@ -589,7 +590,7 @@ int main(int argc, char* argv[]) catch (const cxxopts::OptionException& e) { - std::cout << options.help() << "\n"; + samurai::io::print(samurai::io::root, "{}\n", options.help()); } samurai::finalize(); diff --git a/demos/LBM/test_D1Q222.cpp b/demos/LBM/test_D1Q222.cpp index e1ee32b20..cd5a89751 100644 --- a/demos/LBM/test_D1Q222.cpp +++ b/demos/LBM/test_D1Q222.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include "boundary_conditions.hpp" #include "prediction_map_1d.hpp" @@ -440,7 +441,7 @@ int main(int argc, char* argv[]) if (result.count("help")) { - std::cout << options.help() << "\n"; + samurai::io::print(samurai::io::root, "{}\n", options.help()); } else { @@ -474,11 +475,11 @@ int main(int argc, char* argv[]) for (auto s : s_vect) { - std::cout << std::endl << "Relaxation parameter s = " << s; + samurai::io::print(samurai::io::root, "\nRelaxation parameter s = {}", s); std::string prefix(case_name + "_s_" + std::to_string(s) + "_"); - std::cout << std::endl << "Testing time behavior" << std::endl; + samurai::io::print(samurai::io::root, "\nTesting time behavior\n"); { double eps = 1.0e-4; // This remains fixed @@ -535,7 +536,7 @@ int main(int argc, char* argv[]) / static_cast(meshR.nb_cells(mesh_id_t::cells)) << std::endl; - std::cout << std::endl + samurai::io::print(samurai::io::root, "\n"); << "Time = " << t << " Diff_h = " << error[1] << std::endl << "Diff q = " << error[3] << std::endl << "Diff E = " << error[5]; @@ -545,7 +546,7 @@ int main(int argc, char* argv[]) t += dt; } - std::cout << std::endl; + samurai::io::print(samurai::io::root, "\n"); out_time_frames.close(); out_error_rho_exact_ref.close(); @@ -557,7 +558,7 @@ int main(int argc, char* argv[]) out_compression.close(); } - std::cout << std::endl << "Testing eps behavior" << std::endl; + samurai::io::print(samurai::io::root, "\nTesting eps behavior\n"); { double eps = 1.0e-1; // 0.1; std::size_t N_test = 50; // 50; @@ -577,7 +578,7 @@ int main(int argc, char* argv[]) for (std::size_t n_test = 0; n_test < N_test; ++n_test) { - std::cout << std::endl << "Test " << n_test << " eps = " << eps; + samurai::io::print(samurai::io::root, "\nTest {} eps = {}", n_test, eps); samurai::MROMesh mesh{box, min_level, max_level}; samurai::MROMesh meshR{box, max_level, max_level}; // This is the reference scheme @@ -604,7 +605,7 @@ int main(int argc, char* argv[]) } auto error = compute_error(f, fR, update_bc_for_level, t); - std::cout << "Diff h= " << error[1] << std::endl + samurai::io::print(samurai::io::root, "Diff h= {}\n", error[1]); << "Diff q = " << error[3] << std::endl << "Diff E = " << error[5] << std::endl; @@ -631,7 +632,7 @@ int main(int argc, char* argv[]) } catch (const cxxopts::OptionException& e) { - std::cout << options.help() << "\n"; + samurai::io::print(samurai::io::root, "{}\n", options.help()); } samurai::finalize(); return 0; diff --git a/demos/LBM/test_D1Q3.cpp b/demos/LBM/test_D1Q3.cpp index 970b65d3a..b1e95659b 100644 --- a/demos/LBM/test_D1Q3.cpp +++ b/demos/LBM/test_D1Q3.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include "boundary_conditions.hpp" #include "prediction_map_1d.hpp" @@ -318,7 +319,7 @@ int main(int argc, char* argv[]) if (result.count("help")) { - std::cout << options.help() << "\n"; + samurai::io::print(samurai::io::root, "{}\n", options.help()); } else { @@ -354,11 +355,11 @@ int main(int argc, char* argv[]) for (auto s : s_vect) { - std::cout << std::endl << "Relaxation parameter s = " << s; + samurai::io::print(samurai::io::root, "\nRelaxation parameter s = {}", s); std::string prefix(case_name + "_s_" + std::to_string(s) + "_"); - std::cout << std::endl << "Testing time behavior" << std::endl; + samurai::io::print(samurai::io::root, "\nTesting time behavior\n"); { double eps = 1.0e-4; // This remains fixed @@ -409,14 +410,14 @@ int main(int argc, char* argv[]) / static_cast(meshR.nb_cells(mesh_id_t::cells)) << std::endl; - std::cout << std::endl << "Time = " << t << " Diff_h = " << error[1] << std::endl << "Diff q = " << error[3]; + samurai::io::print(samurai::io::root, "\nTime = {} Diff_h = {}\nDiff q = {}", t, error[1], error[3]); one_time_step(f, pred_coeff_separate, update_bc_for_level, s, lambda, g); one_time_step(fR, pred_coeff_separate, update_bc_for_level, s, lambda, g); t += dt; } - std::cout << std::endl; + samurai::io::print(samurai::io::root, "\n"); out_time_frames.close(); out_error_h_exact_ref.close(); @@ -426,7 +427,7 @@ int main(int argc, char* argv[]) out_compression.close(); } - std::cout << std::endl << "Testing eps behavior" << std::endl; + samurai::io::print(samurai::io::root, "\nTesting eps behavior\n"); { double eps = 1.0e-1; // 0.1; std::size_t N_test = 50; // 50; @@ -443,7 +444,7 @@ int main(int argc, char* argv[]) for (std::size_t n_test = 0; n_test < N_test; ++n_test) { - std::cout << std::endl << "Test " << n_test << " eps = " << eps; + samurai::io::print(samurai::io::root, "\nTest {} eps = {}", n_test, eps); samurai::MROMesh mesh{box, min_level, max_level}; samurai::MROMesh meshR{box, max_level, max_level}; // This is the reference scheme @@ -470,7 +471,7 @@ int main(int argc, char* argv[]) } auto error = compute_error(f, fR, update_bc_for_level, t, lambda, g); - std::cout << "Diff h= " << error[1] << std::endl << "Diff q = " << error[3] << std::endl; + samurai::io::print(samurai::io::root, "Diff h= {}\nDiff q = {}\n", error[1], error[3]); out_eps << eps << std::endl; out_diff_h_ref_adap << error[1] << std::endl; @@ -493,7 +494,7 @@ int main(int argc, char* argv[]) catch (const cxxopts::OptionException& e) { - std::cout << options.help() << "\n"; + samurai::io::print(samurai::io::root, "{}\n", options.help()); } samurai::finalize(); diff --git a/demos/LBM/test_D1Q5.cpp b/demos/LBM/test_D1Q5.cpp index 7b1c2682e..da9846d56 100644 --- a/demos/LBM/test_D1Q5.cpp +++ b/demos/LBM/test_D1Q5.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include "boundary_conditions.hpp" #include "prediction_map_1d.hpp" @@ -554,7 +555,7 @@ int main(int argc, char* argv[]) if (result.count("help")) { - std::cout << options.help() << "\n"; + samurai::io::print(samurai::io::root, "{}\n", options.help()); } else { @@ -591,11 +592,11 @@ int main(int argc, char* argv[]) for (auto s : s_vect) { - std::cout << std::endl << "Relaxation parameter s = " << s; + samurai::io::print(samurai::io::root, "\nRelaxation parameter s = {}", s); std::string prefix(case_name + "_s_" + std::to_string(s) + "_"); - std::cout << std::endl << "Testing time behavior" << std::endl; + samurai::io::print(samurai::io::root, "\nTesting time behavior\n"); { double eps = 1.0e-4; // This remains fixed @@ -646,14 +647,14 @@ int main(int argc, char* argv[]) / static_cast(meshR.nb_cells(mesh_id_t::cells)) << std::endl; - std::cout << std::endl << "Time = " << t << " Diff_h = " << error[1] << std::endl << "Diff q = " << error[3]; + samurai::io::print(samurai::io::root, "\nTime = {} Diff_h = {}\nDiff q = {}", t, error[1], error[3]); one_time_step_overleaves(f, pred_coeff_separate, update_bc_for_level, s, lambda, g); one_time_step_overleaves(fR, pred_coeff_separate, update_bc_for_level, s, lambda, g); t += dt; } - std::cout << std::endl; + samurai::io::print(samurai::io::root, "\n"); out_time_frames.close(); out_error_h_exact_ref.close(); @@ -663,7 +664,7 @@ int main(int argc, char* argv[]) out_compression.close(); } - std::cout << std::endl << "Testing eps behavior" << std::endl; + samurai::io::print(samurai::io::root, "\nTesting eps behavior\n"); { double eps = 1.0e-1; // 0.1; std::size_t N_test = 50; // 50; @@ -680,7 +681,7 @@ int main(int argc, char* argv[]) for (std::size_t n_test = 0; n_test < N_test; ++n_test) { - std::cout << std::endl << "Test " << n_test << " eps = " << eps; + samurai::io::print(samurai::io::root, "\nTest {} eps = {}", n_test, eps); samurai::MROMesh mesh{box, min_level, max_level}; samurai::MROMesh meshR{box, max_level, max_level}; // This is the reference scheme @@ -707,7 +708,7 @@ int main(int argc, char* argv[]) } auto error = compute_error(f, fR, update_bc_for_level, t, lambda, g); - std::cout << "Diff h= " << error[1] << std::endl << "Diff q = " << error[3] << std::endl; + samurai::io::print(samurai::io::root, "Diff h= {}\nDiff q = {}\n", error[1], error[3]); out_eps << eps << std::endl; out_diff_h_ref_adap << error[1] << std::endl; @@ -729,7 +730,7 @@ int main(int argc, char* argv[]) } catch (const cxxopts::OptionException& e) { - std::cout << options.help() << "\n"; + samurai::io::print(samurai::io::root, "{}\n", options.help()); } samurai::finalize(); return 0; diff --git a/demos/Weno/VF_level_set_houc5_amr.cpp b/demos/Weno/VF_level_set_houc5_amr.cpp index b6ae884a7..f9f3fdc6c 100644 --- a/demos/Weno/VF_level_set_houc5_amr.cpp +++ b/demos/Weno/VF_level_set_houc5_amr.cpp @@ -1,6 +1,7 @@ // #include #include #include +#include #include #include @@ -290,12 +291,12 @@ int main() std::array a{1, 0}; for (std::size_t ite = 0; ite < max_ite; ++ite) { - std::cout << "iteration: " << ite << std::endl; + samurai::io::print(samurai::io::root, "iteration: {}\n", ite); std::size_t ite_adapt = 0; while (1) { - std::cout << "\tmesh adaptation: " << ite_adapt++ << std::endl; + samurai::io::print(samurai::io::root, "\tmesh adaptation: {}\n", ite_adapt++); samurai::update_ghost(update_bc, field); auto tag = samurai::make_scalar_field("tag", mesh); AMR_criteria(field, tag); diff --git a/demos/Weno/VF_level_set_os5_amr.cpp b/demos/Weno/VF_level_set_os5_amr.cpp index 41d1f4a56..d36888814 100644 --- a/demos/Weno/VF_level_set_os5_amr.cpp +++ b/demos/Weno/VF_level_set_os5_amr.cpp @@ -1,6 +1,7 @@ // #include #include #include +#include #include #include @@ -309,12 +310,12 @@ int main() std::array a{1, 0}; for (std::size_t ite = 0; ite < max_ite; ++ite) { - std::cout << "iteration: " << ite << std::endl; + samurai::io::print(samurai::io::root, "iteration: {}\n", ite); std::size_t ite_adapt = 0; while (1) { - std::cout << "\tmesh adaptation: " << ite_adapt++ << std::endl; + samurai::io::print(samurai::io::root, "\tmesh adaptation: {}\n", ite_adapt++); samurai::update_ghost(update_bc, field); tag.resize(); AMR_criteria(field, tag); diff --git a/demos/Weno/heat_weno5_amr.cpp b/demos/Weno/heat_weno5_amr.cpp index 178c84fc2..1fb32b50b 100644 --- a/demos/Weno/heat_weno5_amr.cpp +++ b/demos/Weno/heat_weno5_amr.cpp @@ -1,6 +1,7 @@ // #include #include #include +#include #include #include @@ -749,12 +750,12 @@ int main() for (std::size_t ite = 0; ite < max_ite; ++ite) { - std::cout << "iteration: " << ite << std::endl; + samurai::io::print(samurai::io::root, "iteration: {}\n", ite); std::size_t ite_adapt = 0; while (1) { - std::cout << "\tmesh adaptation: " << ite_adapt++ << std::endl; + samurai::io::print(samurai::io::root, "\tmesh adaptation: {}\n", ite_adapt++); samurai::update_ghost(update_bc, field); auto tag = samurai::make_scalar_field("tag", mesh); AMR_criteria(field, tag); diff --git a/demos/highorder/main.cpp b/demos/highorder/main.cpp index 9c68c95a0..a2ca4b7ad 100644 --- a/demos/highorder/main.cpp +++ b/demos/highorder/main.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -274,28 +275,28 @@ int main(int argc, char* argv[]) double error = L2_error(u, exact_func); std::cout.precision(2); - std::cout << "refinement: " << ite << std::endl; - std::cout << "L2-error : " << std::scientific << error; + samurai::io::print(samurai::io::root, "refinement: {}\n", ite); + samurai::io::print(samurai::io::root, "L2-error : {:e}", error); if (h_coarse != -1) { double convergence_order = samurai::convergence_order(h, error, h_coarse, error_coarse); - std::cout << " (order = " << std::defaultfloat << convergence_order << ")"; + samurai::io::print(samurai::io::root, " (order = {})", convergence_order); } - std::cout << std::endl; + samurai::io::print(samurai::io::root, "\n"); auto u_recons = samurai::reconstruction(u); double error_recons = L2_error(u_recons, exact_func); std::cout.precision(2); - std::cout << "L2-error (recons): " << std::scientific << error_recons; + samurai::io::print(samurai::io::root, "L2-error (recons): {:e}", error_recons); if (h_coarse != -1) { double convergence_order = samurai::convergence_order(h, error_recons, h_coarse, error_recons_coarse); - std::cout << " (order = " << std::defaultfloat << convergence_order << ")"; + samurai::io::print(samurai::io::root, " (order = {})", convergence_order); } - std::cout << std::endl; + samurai::io::print(samurai::io::root, "\n"); auto error_field = samurai::make_scalar_field("error", mesh); samurai::for_each_cell(mesh, diff --git a/demos/multigrid/samurai_new/multigrid/petsc/GeometricMultigrid.hpp b/demos/multigrid/samurai_new/multigrid/petsc/GeometricMultigrid.hpp index 1e2603914..8cf6c72d4 100644 --- a/demos/multigrid/samurai_new/multigrid/petsc/GeometricMultigrid.hpp +++ b/demos/multigrid/samurai_new/multigrid/petsc/GeometricMultigrid.hpp @@ -1,5 +1,6 @@ #pragma once #include "SamuraiDM.hpp" +#include namespace samurai_new { @@ -81,47 +82,47 @@ namespace samurai_new } else { - std::cout << "ERROR: unknown value for argument --smooth" << std::endl << std::endl; + samurai::io::eprint("ERROR: unknown value for argument --smooth\n\n"); } } - std::cout << "Samurai multigrid: " << std::endl; + samurai::io::print(samurai::io::root, "Samurai multigrid: \n"); - std::cout << " smoothers : "; + samurai::io::print(samurai::io::root, " smoothers : "); if (smoother == GaussSeidel) { - std::cout << "Gauss-Seidel (pre: lexico., post: antilexico.)"; + samurai::io::print(samurai::io::root, "Gauss-Seidel (pre: lexico., post: antilexico.)"); } else if (smoother == SymGaussSeidel) { - std::cout << "symmetric Gauss-Seidel"; + samurai::io::print(samurai::io::root, "symmetric Gauss-Seidel"); } else if (smoother == Petsc) { - std::cout << "petsc options"; + samurai::io::print(samurai::io::root, "petsc options"); } - std::cout << std::endl; + samurai::io::print(samurai::io::root, "\n"); - std::cout << " transfer operators: "; + samurai::io::print(samurai::io::root, " transfer operators: "); if (transfer_ops == TransferOperators::Assembled) { - std::cout << "P assembled, R assembled"; + samurai::io::print(samurai::io::root, "P assembled, R assembled"); } else if (transfer_ops == TransferOperators::Assembled_PTranspose) { - std::cout << "P assembled, R = P^T"; + samurai::io::print(samurai::io::root, "P assembled, R = P^T"); } else if (transfer_ops == TransferOperators::MatrixFree_Arrays) { - std::cout << "P mat-free, R mat-free (via double*)"; + samurai::io::print(samurai::io::root, "P mat-free, R mat-free (via double*)"); } else if (transfer_ops == TransferOperators::MatrixFree_Fields) { - std::cout << "P mat-free, R mat-free (via Fields)"; + samurai::io::print(samurai::io::root, "P mat-free, R mat-free (via Fields)"); } - std::cout << std::endl; + samurai::io::print(samurai::io::root, "\n"); - std::cout << " prediction order : " << prediction_order << std::endl; + samurai::io::print(samurai::io::root, " prediction order : {}\n", prediction_order); _samuraiDM = new SamuraiDM(PETSC_COMM_SELF, *_discretizer, *_mesh, transfer_ops, prediction_order); KSPSetDM(ksp, _samuraiDM->PetscDM()); @@ -147,7 +148,7 @@ namespace samurai_new levels = std::max(static_cast(_mesh->max_level()) - 3, 2); levels = std::min(levels, 8); } - std::cout << " levels : " << levels << std::endl; + samurai::io::print(samurai::io::root, " levels : {}\n", levels); PCMGSetLevels(mg, levels, nullptr); // All of the following must be called after PCMGSetLevels() diff --git a/demos/p4est/simple_2d.cpp b/demos/p4est/simple_2d.cpp index e7fea6a03..d14dd2f96 100644 --- a/demos/p4est/simple_2d.cpp +++ b/demos/p4est/simple_2d.cpp @@ -2,6 +2,7 @@ // SPDX-License-Identifier: BSD-3-Clause #include +#include #include @@ -229,14 +230,14 @@ int main(int argc, char* argv[]) cl[2][{3}].add_interval({2, 4}); samurai::CellArray mesh_1(cl); - std::cout << "nb_cells: " << mesh_1.nb_cells() << "\n"; + samurai::io::print(samurai::io::root, "nb_cells: {}\n", mesh_1.nb_cells()); tic(); refine_1(mesh_1, max_level); auto duration = toc(); - std::cout << "Version 1: " << duration << "s" << std::endl; + samurai::io::print(samurai::io::root, "Version 1: {}s\n", duration); toc(); - std::cout << "nb_cells: " << mesh_1.nb_cells() << "\n"; + samurai::io::print(samurai::io::root, "nb_cells: {}\n", mesh_1.nb_cells()); // samurai::CellArray mesh_2(cl); using Config = samurai::MRConfig; @@ -246,12 +247,12 @@ int main(int argc, char* argv[]) tic(); refine_2(mesh_2, max_level); duration = toc(); - std::cout << "Version 2: " << duration << "s" << std::endl; - std::cout << "nb_cells: " << mesh_2.nb_cells(mesh_id_t::cells) << "\n"; + samurai::io::print(samurai::io::root, "Version 2: {}s\n", duration); + samurai::io::print(samurai::io::root, "nb_cells: {}\n", mesh_2.nb_cells(mesh_id_t::cells)); - std::cout << "Memory used " << std::endl; + samurai::io::print(samurai::io::root, "Memory used \n"); auto mem = samurai::memory_usage(mesh_2, /*verbose*/ true); - std::cout << "Total: " << mem << std::endl; + samurai::io::print(samurai::io::root, "Total: {}\n", mem); auto level = samurai::make_scalar_field("level", mesh_2); samurai::for_each_cell(mesh_2, diff --git a/demos/pablo/bubble_2d.cpp b/demos/pablo/bubble_2d.cpp index 6a9188ee2..3167f2e90 100644 --- a/demos/pablo/bubble_2d.cpp +++ b/demos/pablo/bubble_2d.cpp @@ -2,6 +2,7 @@ // SPDX-License-Identifier: BSD-3-Clause #include +#include #include @@ -309,7 +310,7 @@ int main(int argc, char* argv[]) bb_xcenter = bb0_xcenter + aa * xt::cos(omega * t); bb_ycenter = bb_ycenter + dt * dy; - std::cout << fmt::format("iteration -> {} t -> {}", nt++, t) << std::endl; + samurai::io::print(samurai::io::root, "iteration -> {} t -> {}\n", nt++, t); for (std::size_t rep = 0; rep < 10; ++rep) { diff --git a/demos/tutorial/set_operator.cpp b/demos/tutorial/set_operator.cpp index 4f46700b1..4664a6812 100644 --- a/demos/tutorial/set_operator.cpp +++ b/demos/tutorial/set_operator.cpp @@ -2,6 +2,7 @@ // SPDX-License-Identifier: BSD-3-Clause #include +#include #include #include @@ -61,33 +62,33 @@ int main() ca = {cl, true}; - std::cout << ca << "\n"; + samurai::io::print(samurai::io::root, "{}\n", fmt::streamed(ca)); auto subset = samurai::intersection(ca[0], ca[1]); subset( [&](const auto& i, auto) { - std::cout << "intersection found in " << i << std::endl; + samurai::io::print(samurai::io::root, "intersection found in {}\n", fmt::streamed(i)); }); subset.on(0)( [&](const auto& i, auto) { - std::cout << "intersection found in " << i << std::endl; + samurai::io::print(samurai::io::root, "intersection found in {}\n", fmt::streamed(i)); }); subset.on(3)( [&](const auto& i, auto) { - std::cout << "intersection found in " << i << std::endl; + samurai::io::print(samurai::io::root, "intersection found in {}\n", fmt::streamed(i)); }); auto subset_d = samurai::difference(ca[0], ca[1]); subset_d( [&](const auto& i, auto) { - std::cout << "difference found in " << i << std::endl; + samurai::io::print(samurai::io::root, "difference found in {}\n", fmt::streamed(i)); }); auto u = samurai::make_scalar_field("u", ca); @@ -105,11 +106,11 @@ int main() u(0, i) = 0.5 * (u(1, 2 * i) + u(1, 2 * i + 1)); }); - std::cout << u << "\n"; + samurai::io::print(samurai::io::root, "{}\n", fmt::streamed(u)); subset1.on(0).apply_op(projection(u)); - std::cout << u << "\n"; + samurai::io::print(samurai::io::root, "{}\n", fmt::streamed(u)); samurai::finalize(); return 0; From 9f9d294e93f2cfdcee87331e2fd1af5c227d3ee2 Mon Sep 17 00:00:00 2001 From: sbstndb/sbstndbs Date: Fri, 3 Oct 2025 12:16:42 +0200 Subject: [PATCH 27/37] style: apply clang-format in demos after IO port --- demos/LBM/test_D1Q2.cpp | 2 +- demos/LBM/test_D1Q222.cpp | 11 +++++------ demos/LBM/test_D1Q3.cpp | 2 +- demos/LBM/test_D1Q5.cpp | 2 +- demos/highorder/main.cpp | 2 +- 5 files changed, 9 insertions(+), 10 deletions(-) diff --git a/demos/LBM/test_D1Q2.cpp b/demos/LBM/test_D1Q2.cpp index e4f9dde6a..090d73be0 100644 --- a/demos/LBM/test_D1Q2.cpp +++ b/demos/LBM/test_D1Q2.cpp @@ -11,9 +11,9 @@ #include #include #include +#include #include #include -#include #include "boundary_conditions.hpp" diff --git a/demos/LBM/test_D1Q222.cpp b/demos/LBM/test_D1Q222.cpp index cd5a89751..3241c4e72 100644 --- a/demos/LBM/test_D1Q222.cpp +++ b/demos/LBM/test_D1Q222.cpp @@ -13,8 +13,8 @@ #include #include #include -#include #include +#include #include "boundary_conditions.hpp" #include "prediction_map_1d.hpp" @@ -537,9 +537,9 @@ int main(int argc, char* argv[]) << std::endl; samurai::io::print(samurai::io::root, "\n"); - << "Time = " << t << " Diff_h = " << error[1] << std::endl - << "Diff q = " << error[3] << std::endl - << "Diff E = " << error[5]; + << "Time = " << t << " Diff_h = " << error[1] << std::endl + << "Diff q = " << error[3] << std::endl + << "Diff E = " << error[5]; one_time_step(f, pred_coeff_separate, update_bc_for_level, s, lambda); one_time_step(fR, pred_coeff_separate, update_bc_for_level, s, lambda); @@ -606,8 +606,7 @@ int main(int argc, char* argv[]) auto error = compute_error(f, fR, update_bc_for_level, t); samurai::io::print(samurai::io::root, "Diff h= {}\n", error[1]); - << "Diff q = " << error[3] << std::endl - << "Diff E = " << error[5] << std::endl; + << "Diff q = " << error[3] << std::endl << "Diff E = " << error[5] << std::endl; out_eps << eps << std::endl; out_diff_rho_ref_adap << error[1] << std::endl; diff --git a/demos/LBM/test_D1Q3.cpp b/demos/LBM/test_D1Q3.cpp index b1e95659b..8dd553997 100644 --- a/demos/LBM/test_D1Q3.cpp +++ b/demos/LBM/test_D1Q3.cpp @@ -12,8 +12,8 @@ #include #include #include -#include #include +#include #include "boundary_conditions.hpp" #include "prediction_map_1d.hpp" diff --git a/demos/LBM/test_D1Q5.cpp b/demos/LBM/test_D1Q5.cpp index da9846d56..6a00b3ee4 100644 --- a/demos/LBM/test_D1Q5.cpp +++ b/demos/LBM/test_D1Q5.cpp @@ -13,8 +13,8 @@ #include #include #include -#include #include +#include #include "boundary_conditions.hpp" #include "prediction_map_1d.hpp" diff --git a/demos/highorder/main.cpp b/demos/highorder/main.cpp index a2ca4b7ad..5d1f41f65 100644 --- a/demos/highorder/main.cpp +++ b/demos/highorder/main.cpp @@ -4,8 +4,8 @@ #include #include #include -#include #include +#include #include #include From eaa4b6687bf1eee1b515209a675652d3642b4665 Mon Sep 17 00:00:00 2001 From: sbstndb/sbstndbs Date: Fri, 3 Oct 2025 12:31:35 +0200 Subject: [PATCH 28/37] io: port remaining demos to samurai::io::print/eprint; add ; fix prediction_map to_stream; run clang-format --- demos/FiniteVolume/burgers_mra.cpp | 3 +-- demos/LBM/D1Q222_Euler_Sod.cpp | 22 +++++++++---------- demos/LBM/D1Q2_Advection_and_Burgers.cpp | 8 +++---- demos/LBM/D1Q3_Shallow_Waters_Dam.cpp | 15 +++++-------- demos/LBM/D1Q5_Shallow_Waters_Dam.cpp | 16 +++++--------- demos/LBM/D2Q4444_Euler_Implosion.cpp | 7 +++--- demos/LBM/D2Q4444_Euler_Lax_Liu.cpp | 9 ++++---- demos/LBM/D2Q4444_Euler_Lax_Liu_uniform.cpp | 8 +++---- demos/LBM/D2Q5444_Euler_Rayleigh_Taylor.cpp | 7 +++--- .../D2Q9_Navier_Stokes_von_Karman_street.cpp | 9 ++++---- demos/LBM/prediction_map_1d.hpp | 2 +- demos/LBM/prediction_map_2d.hpp | 2 +- demos/Weno/weno5_amr.cpp | 5 +++-- demos/highorder/main.cpp | 3 +-- demos/multigrid/samurai_new/utils.cpp | 6 ++--- demos/tutorial/2D_mesh.cpp | 4 ++-- demos/tutorial/AMR_1D_Burgers/step_0/main.cpp | 3 ++- demos/tutorial/AMR_1D_Burgers/step_1/main.cpp | 3 ++- demos/tutorial/graduation_case_2.cpp | 5 +++-- demos/tutorial/graduation_case_3.cpp | 3 ++- demos/tutorial/interval.cpp | 6 ++--- demos/tutorial/reconstruction_1d.cpp | 3 ++- demos/tutorial/reconstruction_2d.cpp | 3 ++- demos/tutorial/reconstruction_3d.cpp | 3 ++- 24 files changed, 79 insertions(+), 76 deletions(-) diff --git a/demos/FiniteVolume/burgers_mra.cpp b/demos/FiniteVolume/burgers_mra.cpp index dadcb1740..25957315e 100644 --- a/demos/FiniteVolume/burgers_mra.cpp +++ b/demos/FiniteVolume/burgers_mra.cpp @@ -179,8 +179,7 @@ void run_simulation(Field& u, auto u_recons = samurai::reconstruction(u); // Error - std::cout << ", L2-error: " << std::scientific; - std::cout.precision(2); + samurai::io::print(", L2-error: "); if (init_sol == "hat") { double error = samurai::L2_error(u, diff --git a/demos/LBM/D1Q222_Euler_Sod.cpp b/demos/LBM/D1Q222_Euler_Sod.cpp index a8622eb20..3c53cf86a 100644 --- a/demos/LBM/D1Q222_Euler_Sod.cpp +++ b/demos/LBM/D1Q222_Euler_Sod.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -470,7 +471,7 @@ int main(int argc, char* argv[]) if (result.count("help")) { - std::cout << options.help() << "\n"; + samurai::io::print("{}\n", options.help()); } else { @@ -514,21 +515,20 @@ int main(int argc, char* argv[]) for (std::size_t nb_ite = 0; nb_ite < N; ++nb_ite) { - std::cout << std::endl << "Iteration = " << nb_ite << std::endl; + samurai::io::print("\nIteration = {}\n", nb_ite); MRadaptation(eps, regularity); save_solution(f, eps, nb_ite); auto error = compute_error(f, fR, update_bc_for_level, t); - std::cout << std::endl - << "Error rho = " << error[0] << std::endl - << "Diff rho = " << error[1] << std::endl - << "Error q = " << error[2] << std::endl - << "Diff q = " << error[3] << std::endl - << "Error E = " << error[4] << std::endl - << "Diff E = " << error[5]; - std::cout << std::endl; + samurai::io::print("\nError rho = {}\nDiff rho = {}\nError q = {}\nDiff q = {}\nError E = {}\nDiff E = {}\n", + error[0], + error[1], + error[2], + error[3], + error[4], + error[5]); one_time_step(f, pred_coeff_separate, update_bc_for_level, s, lambda); one_time_step(fR, pred_coeff_separate, update_bc_for_level, s, lambda); @@ -538,7 +538,7 @@ int main(int argc, char* argv[]) } catch (const cxxopts::OptionException& e) { - std::cout << options.help() << "\n"; + samurai::io::print("{}\n", options.help()); } samurai::finalize(); return 0; diff --git a/demos/LBM/D1Q2_Advection_and_Burgers.cpp b/demos/LBM/D1Q2_Advection_and_Burgers.cpp index 153b91fdd..4197fbebe 100644 --- a/demos/LBM/D1Q2_Advection_and_Burgers.cpp +++ b/demos/LBM/D1Q2_Advection_and_Burgers.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include "boundary_conditions.hpp" @@ -534,7 +535,7 @@ int main(int argc, char* argv[]) if (result.count("help")) { - std::cout << options.help() << "\n"; + samurai::io::print("{}\n", options.help()); } else { @@ -594,8 +595,7 @@ int main(int argc, char* argv[]) save_reconstructed(f, fR, update_bc_for_level, eps, nb_ite); auto error = compute_error(f, fR, update_bc_for_level, t); - - std::cout << std::endl << "Diff = " << error[1] << std::flush; + samurai::io::print("\nDiff = {}", error[1]); out_time_frames << t << std::endl; out_error_exact_ref << error[0] << std::endl; @@ -618,7 +618,7 @@ int main(int argc, char* argv[]) } catch (const cxxopts::OptionException& e) { - std::cout << options.help() << "\n"; + samurai::io::print("{}\n", options.help()); } samurai::finalize(); return 0; diff --git a/demos/LBM/D1Q3_Shallow_Waters_Dam.cpp b/demos/LBM/D1Q3_Shallow_Waters_Dam.cpp index 43207281e..030771dfc 100644 --- a/demos/LBM/D1Q3_Shallow_Waters_Dam.cpp +++ b/demos/LBM/D1Q3_Shallow_Waters_Dam.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include "boundary_conditions.hpp" @@ -346,7 +347,7 @@ int main(int argc, char* argv[]) if (result.count("help")) { - std::cout << options.help() << "\n"; + samurai::io::print("{}\n", options.help()); } else { @@ -393,18 +394,14 @@ int main(int argc, char* argv[]) for (std::size_t nb_ite = 0; nb_ite < N; ++nb_ite) { - std::cout << std::endl << "Iteration " << nb_ite << " Time = " << t; + samurai::io::print("\nIteration {} Time = {}", nb_ite, t); MRadaptation(eps, 0.); // Regularity 0 save_solution(f, eps, nb_ite, lambda); auto error = compute_error(f, fR, update_bc_for_level, t, lambda, g); - std::cout << std::endl - << "Error h = " << error[0] << std::endl - << "Diff h = " << error[1] << std::endl - << "Error q = " << error[2] << std::endl - << "Diff q = " << error[3]; + samurai::io::print("\nError h = {}\nDiff h = {}\nError q = {}\nDiff q = {}", error[0], error[1], error[2], error[3]); tic(); one_time_step(f, pred_coeff_separate, update_bc_for_level, s, lambda, g); @@ -417,9 +414,9 @@ int main(int argc, char* argv[]) } catch (const cxxopts::OptionException& e) { - std::cout << options.help() << "\n"; + samurai::io::print("{}\n", options.help()); } - std::cout << std::endl; + samurai::io::print("\n"); samurai::finalize(); return 0; } diff --git a/demos/LBM/D1Q5_Shallow_Waters_Dam.cpp b/demos/LBM/D1Q5_Shallow_Waters_Dam.cpp index eb51fe094..42b682beb 100644 --- a/demos/LBM/D1Q5_Shallow_Waters_Dam.cpp +++ b/demos/LBM/D1Q5_Shallow_Waters_Dam.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include "boundary_conditions.hpp" @@ -583,7 +584,7 @@ int main(int argc, char* argv[]) if (result.count("help")) { - std::cout << options.help() << "\n"; + samurai::io::print("{}\n", options.help()); } else { @@ -629,19 +630,14 @@ int main(int argc, char* argv[]) for (std::size_t nb_ite = 0; nb_ite < N; ++nb_ite) { - std::cout << std::endl << "Iteration " << nb_ite << " Time = " << t; + samurai::io::print("\nIteration {} Time = {}", nb_ite, t); MRadaptation(eps, 0.); // Regularity 0 save_solution(f, eps, nb_ite, lambda); auto error = compute_error(f, fR, update_bc_for_level, t, lambda, g); - - std::cout << std::endl - << "Error h = " << error[0] << std::endl - << "Diff h = " << error[1] << std::endl - << "Error q = " << error[2] << std::endl - << "Diff q = " << error[3]; + samurai::io::print("\nError h = {}\nDiff h = {}\nError q = {}\nDiff q = {}", error[0], error[1], error[2], error[3]); tic(); one_time_step_overleaves(f, pred_coeff_separate, update_bc_for_level, s, lambda, g); @@ -654,9 +650,9 @@ int main(int argc, char* argv[]) } catch (const cxxopts::OptionException& e) { - std::cout << options.help() << "\n"; + samurai::io::print("{}\n", options.help()); } - std::cout << std::endl; + samurai::io::print("\n"); samurai::finalize(); return 0; } diff --git a/demos/LBM/D2Q4444_Euler_Implosion.cpp b/demos/LBM/D2Q4444_Euler_Implosion.cpp index 598f0ba12..c2a4cc986 100644 --- a/demos/LBM/D2Q4444_Euler_Implosion.cpp +++ b/demos/LBM/D2Q4444_Euler_Implosion.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include "boundary_conditions.hpp" @@ -1024,7 +1025,7 @@ int main(int argc, char* argv[]) if (result.count("help")) { - std::cout << options.help() << "\n"; + samurai::io::print("{}\n", options.help()); } else { @@ -1093,7 +1094,7 @@ int main(int argc, char* argv[]) for (std::size_t nb_ite = 0; nb_ite <= N; ++nb_ite) { - std::cout << std::endl << "Time = " << t << " Iteration number = " << nb_ite << std::endl; + samurai::io::print("\nTime = {} Iteration number = {}\n", t, nb_ite); if (max_level > min_level) { @@ -1114,7 +1115,7 @@ int main(int argc, char* argv[]) } catch (const cxxopts::OptionException& e) { - std::cout << options.help() << "\n"; + samurai::io::print("{}\n", options.help()); } samurai::finalize(); return 0; diff --git a/demos/LBM/D2Q4444_Euler_Lax_Liu.cpp b/demos/LBM/D2Q4444_Euler_Lax_Liu.cpp index d45c07f86..7b050c791 100644 --- a/demos/LBM/D2Q4444_Euler_Lax_Liu.cpp +++ b/demos/LBM/D2Q4444_Euler_Lax_Liu.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -779,7 +780,7 @@ int main(int argc, char* argv[]) if (result.count("help")) { - std::cout << options.help() << "\n"; + samurai::io::print("{}\n", options.help()); } else { @@ -880,7 +881,7 @@ int main(int argc, char* argv[]) for (std::size_t nb_ite = 0; nb_ite <= N; ++nb_ite) { - std::cout << std::endl << " Iteration number = " << nb_ite << std::endl; + samurai::io::print("\n Iteration number = {}\n", nb_ite); if (max_level > min_level) { @@ -890,7 +891,7 @@ int main(int argc, char* argv[]) if (nb_ite == N) { auto error_density = compute_error(f, f_ref, update_bc_for_level); - std::cout << std::endl << "#### Epsilon = " << eps << " error = " << error_density << std::endl; + samurai::io::print("\n#### Epsilon = {} error = {}\n", eps, error_density); save_solution(f, eps, nb_ite, std::string("final_")); save_reconstructed(f, f_ref, update_bc_for_level, eps, nb_ite); } @@ -923,7 +924,7 @@ int main(int argc, char* argv[]) } catch (const cxxopts::OptionException& e) { - std::cout << options.help() << "\n"; + samurai::io::print("{}\n", options.help()); } samurai::finalize(); return 0; diff --git a/demos/LBM/D2Q4444_Euler_Lax_Liu_uniform.cpp b/demos/LBM/D2Q4444_Euler_Lax_Liu_uniform.cpp index d58a65e49..16fab89d2 100644 --- a/demos/LBM/D2Q4444_Euler_Lax_Liu_uniform.cpp +++ b/demos/LBM/D2Q4444_Euler_Lax_Liu_uniform.cpp @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -355,7 +356,7 @@ int main(int argc, char* argv[]) if (result.count("help")) { - std::cout << options.help() << "\n"; + samurai::io::print("{}\n", options.help()); } else { @@ -427,13 +428,12 @@ int main(int argc, char* argv[]) // samurai::statistics("D2Q4444_Euler_Lax_Liu", mesh); } auto duration = toc(); - std::cout << "nb_ite: " << N << " execution time: " << duration - << " MLUPS: " << N * (1 << level) * (1 << level) / duration / 1e6 << std::endl; + samurai::io::print("nb_ite: {} execution time: {} MLUPS: {}\n", N, duration, N * (1 << level) * (1 << level) / duration / 1e6); } } catch (const cxxopts::OptionException& e) { - std::cout << options.help() << "\n"; + samurai::io::print("{}\n", options.help()); } samurai::finalize(); return 0; diff --git a/demos/LBM/D2Q5444_Euler_Rayleigh_Taylor.cpp b/demos/LBM/D2Q5444_Euler_Rayleigh_Taylor.cpp index de8e8b846..32a3e6600 100644 --- a/demos/LBM/D2Q5444_Euler_Rayleigh_Taylor.cpp +++ b/demos/LBM/D2Q5444_Euler_Rayleigh_Taylor.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include "boundary_conditions.hpp" @@ -1104,7 +1105,7 @@ int main(int argc, char* argv[]) if (result.count("help")) { - std::cout << options.help() << "\n"; + samurai::io::print("{}\n", options.help()); } else { @@ -1152,7 +1153,7 @@ int main(int argc, char* argv[]) for (std::size_t nb_ite = 0; nb_ite <= N; ++nb_ite) { - std::cout << std::endl << "Time = " << t << " Iteration number = " << nb_ite << std::endl; + samurai::io::print("\nTime = {} Iteration number = {}\n", t, nb_ite); if (max_level > min_level) { @@ -1173,7 +1174,7 @@ int main(int argc, char* argv[]) } catch (const cxxopts::OptionException& e) { - std::cout << options.help() << "\n"; + samurai::io::print("{}\n", options.help()); } samurai::finalize(); return 0; diff --git a/demos/LBM/D2Q9_Navier_Stokes_von_Karman_street.cpp b/demos/LBM/D2Q9_Navier_Stokes_von_Karman_street.cpp index 26df36daa..88d30afa4 100644 --- a/demos/LBM/D2Q9_Navier_Stokes_von_Karman_street.cpp +++ b/demos/LBM/D2Q9_Navier_Stokes_von_Karman_street.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include "boundary_conditions.hpp" @@ -1359,7 +1360,7 @@ int main(int argc, char* argv[]) if (result.count("help")) { - std::cout << options.help() << "\n"; + samurai::io::print("{}\n", options.help()); } else { @@ -1424,7 +1425,7 @@ int main(int argc, char* argv[]) for (std::size_t nb_ite = 0; nb_ite < N; ++nb_ite) { - std::cout << std::endl << "Iteration number = " << nb_ite << std::endl; + samurai::io::print("\nIteration number = {}\n", nb_ite); time_frames << nb_ite * dt << std::endl; if (max_level > min_level) @@ -1440,7 +1441,7 @@ int main(int argc, char* argv[]) } auto CDCL = one_time_step(f, update_bc_for_level, pred_coeff, rho0, u0, lambda, mu, zeta, radius, momenti); - std::cout << std::endl << "CD = " << CDCL.first << " CL = " << CDCL.second << std::endl; + samurai::io::print("\nCD = {} CL = {}\n", CDCL.first, CDCL.second); CD << CDCL.first << std::endl; CL << CDCL.second << std::endl; @@ -1457,7 +1458,7 @@ int main(int argc, char* argv[]) } catch (const cxxopts::OptionException& e) { - std::cout << options.help() << "\n"; + samurai::io::print("{}\n", options.help()); } samurai::finalize(); return 0; diff --git a/demos/LBM/prediction_map_1d.hpp b/demos/LBM/prediction_map_1d.hpp index 5aee55928..b16f3bc55 100644 --- a/demos/LBM/prediction_map_1d.hpp +++ b/demos/LBM/prediction_map_1d.hpp @@ -72,7 +72,7 @@ class prediction_map { for (auto& c : coeff) { - std::cout << "( " << c.first << ", ): " << c.second << "\n"; + out << "( " << c.first << ", ): " << c.second << "\n"; } } diff --git a/demos/LBM/prediction_map_2d.hpp b/demos/LBM/prediction_map_2d.hpp index 1c5354532..2e47b1213 100644 --- a/demos/LBM/prediction_map_2d.hpp +++ b/demos/LBM/prediction_map_2d.hpp @@ -72,7 +72,7 @@ class prediction_map { for (auto& c : coeff) { - std::cout << "( " << std::get<0>(c.first) << ", " << std::get<1>(c.first) << " ): " << c.second << "\n"; + out << "( " << std::get<0>(c.first) << ", " << std::get<1>(c.first) << " ): " << c.second << "\n"; } } diff --git a/demos/Weno/weno5_amr.cpp b/demos/Weno/weno5_amr.cpp index cb7c8bd59..ac31f78bf 100644 --- a/demos/Weno/weno5_amr.cpp +++ b/demos/Weno/weno5_amr.cpp @@ -1,6 +1,7 @@ // #include #include #include +#include #include #include @@ -464,12 +465,12 @@ int main() for (std::size_t ite = 0; ite < max_ite; ++ite) { - std::cout << "iteration: " << ite << std::endl; + samurai::io::print("iteration: {}\n", ite); std::size_t ite_adapt = 0; while (1) { - std::cout << "\tmesh adaptation: " << ite_adapt++ << std::endl; + samurai::io::print("\tmesh adaptation: {}\n", ite_adapt++); samurai::update_ghost(update_bc, field); auto tag = samurai::make_scalar_field("tag", mesh); AMR_criteria(field, tag); diff --git a/demos/highorder/main.cpp b/demos/highorder/main.cpp index 5d1f41f65..b942e6ad7 100644 --- a/demos/highorder/main.cpp +++ b/demos/highorder/main.cpp @@ -274,7 +274,7 @@ int main(int argc, char* argv[]) double h = mesh.cell_length(mesh.min_level()); double error = L2_error(u, exact_func); - std::cout.precision(2); + samurai::io::print(samurai::io::root, "refinement: {}\n", ite); samurai::io::print(samurai::io::root, "L2-error : {:e}", error); if (h_coarse != -1) @@ -288,7 +288,6 @@ int main(int argc, char* argv[]) double error_recons = L2_error(u_recons, exact_func); - std::cout.precision(2); samurai::io::print(samurai::io::root, "L2-error (recons): {:e}", error_recons); if (h_coarse != -1) diff --git a/demos/multigrid/samurai_new/utils.cpp b/demos/multigrid/samurai_new/utils.cpp index 69846fbe8..ea1a029b1 100644 --- a/demos/multigrid/samurai_new/utils.cpp +++ b/demos/multigrid/samurai_new/utils.cpp @@ -1,15 +1,15 @@ #pragma once #include +#include template void print_mesh(Mesh& mesh) { - std::cout << mesh << std::endl; + samurai::io::print("{}\n", fmt::streamed(mesh)); samurai::for_each_cell(mesh, [](const auto& cell) { - std::cout << "level: " << cell.level << ", cell index: " << cell.index << ", center: " << cell.center(0) - << std::endl; + samurai::io::print("level: {}, cell index: {}, center: {}\n", cell.level, cell.index, cell.center(0)); }); } diff --git a/demos/tutorial/2D_mesh.cpp b/demos/tutorial/2D_mesh.cpp index 8e08ea98b..4d64d834a 100644 --- a/demos/tutorial/2D_mesh.cpp +++ b/demos/tutorial/2D_mesh.cpp @@ -1,7 +1,7 @@ // Copyright 2018-2025 the samurai's authors // SPDX-License-Identifier: BSD-3-Clause -#include +#include #include @@ -54,7 +54,7 @@ int main(int argc, char* argv[]) const samurai::CellArray ca{cl}; - std::cout << ca << std::endl; + samurai::io::print("{}\n", fmt::streamed(ca)); samurai::save(path, filename, ca); samurai::finalize(); diff --git a/demos/tutorial/AMR_1D_Burgers/step_0/main.cpp b/demos/tutorial/AMR_1D_Burgers/step_0/main.cpp index 925614ecc..4707a0620 100644 --- a/demos/tutorial/AMR_1D_Burgers/step_0/main.cpp +++ b/demos/tutorial/AMR_1D_Burgers/step_0/main.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include namespace fs = std::filesystem; @@ -53,7 +54,7 @@ int main(int argc, char* argv[]) mesh[init_level] = {init_level, box, 0, 1}; - std::cout << mesh << "\n"; + samurai::io::print("{}\n", fmt::streamed(mesh)); samurai::save(path, filename, mesh); diff --git a/demos/tutorial/AMR_1D_Burgers/step_1/main.cpp b/demos/tutorial/AMR_1D_Burgers/step_1/main.cpp index 037641a0e..1f274abde 100644 --- a/demos/tutorial/AMR_1D_Burgers/step_1/main.cpp +++ b/demos/tutorial/AMR_1D_Burgers/step_1/main.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include "init_sol.hpp" @@ -52,7 +53,7 @@ int main(int argc, char* argv[]) auto phi = init_sol(mesh); ///////////////////////////////// - std::cout << mesh << "\n"; + samurai::io::print("{}\n", fmt::streamed(mesh)); samurai::save(path, filename, mesh, phi); diff --git a/demos/tutorial/graduation_case_2.cpp b/demos/tutorial/graduation_case_2.cpp index 8f6821325..08e73849c 100644 --- a/demos/tutorial/graduation_case_2.cpp +++ b/demos/tutorial/graduation_case_2.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -69,7 +70,7 @@ int main(int argc, char* argv[]) std::size_t ite = 0; while (true) { - std::cout << "Iteration for remove intersection: " << ite++ << "\n"; + samurai::io::print("Iteration for remove intersection: {}\n", ite++); auto tag = samurai::make_scalar_field("tag", ca); tag.fill(false); @@ -137,7 +138,7 @@ int main(int argc, char* argv[]) ite = 0; while (true) { - std::cout << "Iteration for graduation: " << ite++ << "\n"; + samurai::io::print("Iteration for graduation: {}\n", ite++); auto tag = samurai::make_scalar_field("tag", ca); tag.fill(false); diff --git a/demos/tutorial/graduation_case_3.cpp b/demos/tutorial/graduation_case_3.cpp index 73dcd2904..540042b7c 100644 --- a/demos/tutorial/graduation_case_3.cpp +++ b/demos/tutorial/graduation_case_3.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -59,7 +60,7 @@ int main(int argc, char* argv[]) std::size_t ite = 0; while (true) { - std::cout << "Iteration for remove intersection: " << ite++ << "\n"; + samurai::io::print("Iteration for remove intersection: {}\n", ite++); auto tag = samurai::make_scalar_field("tag", ca); tag.fill(false); diff --git a/demos/tutorial/interval.cpp b/demos/tutorial/interval.cpp index 1d93544ce..496b3b7b6 100644 --- a/demos/tutorial/interval.cpp +++ b/demos/tutorial/interval.cpp @@ -1,7 +1,7 @@ // Copyright 2018-2025 the samurai's authors // SPDX-License-Identifier: BSD-3-Clause -#include +#include #include #include @@ -20,7 +20,7 @@ int main() const samurai::CellArray ca{cl}; - std::cout << ca << std::endl; + samurai::io::print("{}\n", fmt::streamed(ca)); constexpr std::size_t start_level = 3; const samurai::Box box({-1, -1}, {1, 1}); @@ -28,7 +28,7 @@ int main() ca_box[start_level] = {start_level, box}; - std::cout << ca_box << std::endl; + samurai::io::print("{}\n", fmt::streamed(ca_box)); return 0; } diff --git a/demos/tutorial/reconstruction_1d.cpp b/demos/tutorial/reconstruction_1d.cpp index 3e0946dc1..ac442695a 100644 --- a/demos/tutorial/reconstruction_1d.cpp +++ b/demos/tutorial/reconstruction_1d.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -120,7 +121,7 @@ int main(int argc, char* argv[]) auto t1 = std::chrono::high_resolution_clock::now(); auto u_reconstruct = reconstruction(u); auto t2 = std::chrono::high_resolution_clock::now(); - std::cout << "execution time " << std::chrono::duration_cast(t2 - t1).count() << std::endl; + samurai::io::print("execution time {}\n", std::chrono::duration_cast(t2 - t1).count()); auto error = samurai::make_scalar_field("error", u_reconstruct.mesh()); samurai::for_each_interval(u_reconstruct.mesh(), diff --git a/demos/tutorial/reconstruction_2d.cpp b/demos/tutorial/reconstruction_2d.cpp index 8dbd50d88..9e75837ed 100644 --- a/demos/tutorial/reconstruction_2d.cpp +++ b/demos/tutorial/reconstruction_2d.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -148,7 +149,7 @@ int main(int argc, char* argv[]) auto t1 = std::chrono::high_resolution_clock::now(); auto u_reconstruct = reconstruction(u); auto t2 = std::chrono::high_resolution_clock::now(); - std::cout << "execution time " << std::chrono::duration_cast(t2 - t1).count() << std::endl; + samurai::io::print("execution time {}\n", std::chrono::duration_cast(t2 - t1).count()); auto error = samurai::make_scalar_field("error", u_reconstruct.mesh()); samurai::for_each_interval(u_reconstruct.mesh(), diff --git a/demos/tutorial/reconstruction_3d.cpp b/demos/tutorial/reconstruction_3d.cpp index b2def1b5b..34dc63527 100644 --- a/demos/tutorial/reconstruction_3d.cpp +++ b/demos/tutorial/reconstruction_3d.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -154,7 +155,7 @@ int main(int argc, char* argv[]) auto t1 = std::chrono::high_resolution_clock::now(); auto u_reconstruct = reconstruction(u); auto t2 = std::chrono::high_resolution_clock::now(); - std::cout << "execution time " << std::chrono::duration_cast(t2 - t1).count() << std::endl; + samurai::io::print("execution time {}\n", std::chrono::duration_cast(t2 - t1).count()); auto error = samurai::make_scalar_field("error", u_reconstruct.mesh()); samurai::for_each_interval(u_reconstruct.mesh(), From 01c2712457482a6d30fb177ed452010ff8f946b7 Mon Sep 17 00:00:00 2001 From: sbstndb/sbstndbs Date: Fri, 3 Oct 2025 12:41:59 +0200 Subject: [PATCH 29/37] docs: replace std::cout in snippets and RST examples with samurai::io::print; include --- docs/source/reference/snippet/subset_1d.cpp | 10 +++++----- docs/source/tutorial/operator_on_subset.rst | 8 ++++---- docs/source/tutorial/snippet/2d_mesh_box.cpp | 4 ++-- .../source/tutorial/snippet/2d_mesh_representation.cpp | 4 ++-- docs/source/tutorial/snippet/interval.cpp | 4 ++-- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/docs/source/reference/snippet/subset_1d.cpp b/docs/source/reference/snippet/subset_1d.cpp index 8e0bf48ec..3263293fc 100644 --- a/docs/source/reference/snippet/subset_1d.cpp +++ b/docs/source/reference/snippet/subset_1d.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include @@ -24,8 +24,8 @@ int main() u[cell] = cell.indices[0]; }); - std::cout << "before projection" << std::endl; - std::cout << u << std::endl; + samurai::io::print("before projection\n"); + samurai::io::print("{}\n", fmt::streamed(u)); // Make projection on the intersection auto subset = samurai::intersection(ca[0], ca[1]).on(0); @@ -35,8 +35,8 @@ int main() u(0, i) = 0.5 * (u(1, 2 * i) + u(1, 2 * i + 1)); }); - std::cout << "after projection" << std::endl; - std::cout << u << std::endl; + samurai::io::print("after projection\n"); + samurai::io::print("{}\n", fmt::streamed(u)); return 0; } diff --git a/docs/source/tutorial/operator_on_subset.rst b/docs/source/tutorial/operator_on_subset.rst index 80212ad3f..818838e23 100644 --- a/docs/source/tutorial/operator_on_subset.rst +++ b/docs/source/tutorial/operator_on_subset.rst @@ -37,7 +37,7 @@ The output of .. code-block:: c++ - std::cout << ca << std::endl; + samurai::io::print("{}\\n", fmt::streamed(ca)); is @@ -84,7 +84,7 @@ Once again, we use the `operator()` of the subset set([&](const auto& i, auto) { - std::cout << "Intersection found in " << i << std::endl; + samurai::io::print("Intersection found in {}\\n", i); }); This operator takes a lambda function with two parameters: the first one is the interval in the x-direction, whereas the second argument is an array of size `dim - 1` with the coordinates of the other dimensions. @@ -107,7 +107,7 @@ Then if we want the result on level `0`, we employ set.on(0)([&](const auto& i, auto) { - std::cout << "intersection found in " << i << std::endl; + samurai::io::print("intersection found in {}\\n", i); }); The output is @@ -123,7 +123,7 @@ It is also possible to compute this intersection on a level which does not actua set.on(3)([&](const auto& i, auto) { - std::cout << "intersection found in " << i << std::endl; + samurai::io::print("intersection found in {}\\n", i); }); The corresponding output is diff --git a/docs/source/tutorial/snippet/2d_mesh_box.cpp b/docs/source/tutorial/snippet/2d_mesh_box.cpp index e400f174d..520730f36 100644 --- a/docs/source/tutorial/snippet/2d_mesh_box.cpp +++ b/docs/source/tutorial/snippet/2d_mesh_box.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include @@ -14,7 +14,7 @@ int main() ca_box[start_level] = {start_level, box}; - std::cout << ca_box << std::endl; + samurai::io::print("{}\n", fmt::streamed(ca_box)); samurai::save("2d_mesh_box", ca_box); return 0; diff --git a/docs/source/tutorial/snippet/2d_mesh_representation.cpp b/docs/source/tutorial/snippet/2d_mesh_representation.cpp index 3a98eac4c..e9e1ca236 100644 --- a/docs/source/tutorial/snippet/2d_mesh_representation.cpp +++ b/docs/source/tutorial/snippet/2d_mesh_representation.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include @@ -31,7 +31,7 @@ int main() samurai::CellArray ca{cl}; - std::cout << ca << std::endl; + samurai::io::print("{}\n", fmt::streamed(ca)); samurai::save("2d_mesh_representation", ca); return 0; diff --git a/docs/source/tutorial/snippet/interval.cpp b/docs/source/tutorial/snippet/interval.cpp index 59cab7576..e5d03431a 100644 --- a/docs/source/tutorial/snippet/interval.cpp +++ b/docs/source/tutorial/snippet/interval.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include @@ -16,7 +16,7 @@ int main() samurai::CellArray ca{cl}; - std::cout << ca << std::endl; + samurai::io::print("{}\n", fmt::streamed(ca)); return 0; } From 9873637a9d722e683186b692240a67d4bef93f63 Mon Sep 17 00:00:00 2001 From: sbstndb/sbstndbs Date: Fri, 3 Oct 2025 12:58:49 +0200 Subject: [PATCH 30/37] fix: add in BZ demos; include where xtensor objects are printed --- demos/FiniteVolume/BZ/bz_2d.cpp | 1 + demos/FiniteVolume/BZ/bz_2d_AMR.cpp | 1 + demos/FiniteVolume/burgers_os.cpp | 1 + 3 files changed, 3 insertions(+) diff --git a/demos/FiniteVolume/BZ/bz_2d.cpp b/demos/FiniteVolume/BZ/bz_2d.cpp index 17b2b0257..55c193729 100644 --- a/demos/FiniteVolume/BZ/bz_2d.cpp +++ b/demos/FiniteVolume/BZ/bz_2d.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include "../../LBM/boundary_conditions.hpp" diff --git a/demos/FiniteVolume/BZ/bz_2d_AMR.cpp b/demos/FiniteVolume/BZ/bz_2d_AMR.cpp index 9a82ff6b6..700e4e907 100644 --- a/demos/FiniteVolume/BZ/bz_2d_AMR.cpp +++ b/demos/FiniteVolume/BZ/bz_2d_AMR.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include diff --git a/demos/FiniteVolume/burgers_os.cpp b/demos/FiniteVolume/burgers_os.cpp index 40112a3f0..b09308456 100644 --- a/demos/FiniteVolume/burgers_os.cpp +++ b/demos/FiniteVolume/burgers_os.cpp @@ -12,6 +12,7 @@ namespace fs = std::filesystem; #include +#include #include "convection_nonlin_os.hpp" From 42d582e7e059169e8848e3cf02d821e7bb9b2c25 Mon Sep 17 00:00:00 2001 From: sbstndb/sbstndbs Date: Fri, 3 Oct 2025 13:06:53 +0200 Subject: [PATCH 31/37] fix(fmt+xtensor): avoid printing xtensor indices inside field.hpp error paths to prevent unformattable type errors in fmt; print placeholder instead --- include/samurai/field.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/samurai/field.hpp b/include/samurai/field.hpp index c8ac44059..1a1d41901 100644 --- a/include/samurai/field.hpp +++ b/include/samurai/field.hpp @@ -533,8 +533,8 @@ namespace samurai // level_field[cell] = cell.level; // }); // save(fs::current_path(), "mesh_throw", {true, true}, this->mesh(), coords, level_field); - ((samurai::io::print("{} ", index)), ...); - samurai::io::print("\n"); + // Avoid formatting of xtensor views/expressions which may be unformattable for fmt + samurai::io::print("indices: \n"); throw std::out_of_range(fmt::format("FIELD ERROR on level {}: try to find interval {}", level, interval)); } @@ -1164,8 +1164,8 @@ namespace samurai // level_field[cell] = cell.level; // }); // save(fs::current_path(), "mesh_throw", {true, true}, this->mesh(), coords, level_field); - ((samurai::io::print("{} ", index)), ...); - samurai::io::print("\n"); + // Avoid formatting of xtensor views/expressions which may be unformattable for fmt + samurai::io::print("indices: \n"); throw std::out_of_range(fmt::format("FIELD ERROR on level {}: try to find interval {}", level, interval)); } From 42394b1c586be24c0fb1f00c81888f2936f081a1 Mon Sep 17 00:00:00 2001 From: sbstndb/sbstndbs Date: Fri, 3 Oct 2025 13:14:28 +0200 Subject: [PATCH 32/37] fmt(streamed): restore index printing in field.hpp using fmt::streamed; include ; wrap xtensor prints in burgers_os.cpp --- demos/FiniteVolume/burgers_os.cpp | 84 +++++++++++++++---------------- include/samurai/field.hpp | 9 ++-- 2 files changed, 47 insertions(+), 46 deletions(-) diff --git a/demos/FiniteVolume/burgers_os.cpp b/demos/FiniteVolume/burgers_os.cpp index b09308456..553581af7 100644 --- a/demos/FiniteVolume/burgers_os.cpp +++ b/demos/FiniteVolume/burgers_os.cpp @@ -42,48 +42,48 @@ void check_diff(auto& field, auto& lca_left, auto& lca_right) { auto& mesh = field.mesh(); using mesh_id_t = typename std::decay_t::mesh_id_t; - samurai::for_each_level(mesh, - [&](auto level) - { - auto set = samurai::difference( - samurai::intersection(mesh[mesh_id_t::cells][level], self(lca_left).on(level)), - samurai::translate(samurai::intersection(mesh[mesh_id_t::cells][level], self(lca_right).on(level)), - xt::xtensor_fixed>{-(1 << level)})); - set( - [&](auto& i, auto) - { - samurai::io::print("Difference found !! {} {}\n", level, i); - auto level_ = samurai::make_scalar_field("level", mesh); - samurai::for_each_cell(mesh, - [&](const auto& cell) - { - level_[cell] = cell.level; - }); - samurai::save("mesh_throw", mesh, field, level_); - throw std::runtime_error("Difference found in check_diff function for the mesh"); - }); - auto set_field = samurai::intersection(mesh[mesh_id_t::cells][level], self(lca_left).on(level)); - set_field( - [&](auto i, auto) - { - if (xt::any(xt::abs(field(level, i) - field(level, i + (1 << level))) > 1e-13)) - { - samurai::io::print("\nDifference found at level {} on interval {}:\n", level, i); - samurai::io::print("\tleft = {}\n", field(level, i)); - samurai::io::print("\tright = {}\n", field(level, i + (1 << level))); - samurai::io::print("\terror = {}\n", xt::abs(field(level, i) - field(level, i + (1 << level)))); - samurai::io::print("{}\n", fmt::streamed(mesh)); - auto level_ = samurai::make_scalar_field("level", mesh); - samurai::for_each_cell(mesh, - [&](const auto& cell) - { - level_[cell] = cell.level; - }); - samurai::save("mesh_throw", mesh, field, level_); - throw std::runtime_error("Difference found in check_diff function for the field values"); - } - }); - }); + samurai::for_each_level( + mesh, + [&](auto level) + { + auto set = samurai::difference(samurai::intersection(mesh[mesh_id_t::cells][level], self(lca_left).on(level)), + samurai::translate(samurai::intersection(mesh[mesh_id_t::cells][level], self(lca_right).on(level)), + xt::xtensor_fixed>{-(1 << level)})); + set( + [&](auto& i, auto) + { + samurai::io::print("Difference found !! {} {}\n", level, i); + auto level_ = samurai::make_scalar_field("level", mesh); + samurai::for_each_cell(mesh, + [&](const auto& cell) + { + level_[cell] = cell.level; + }); + samurai::save("mesh_throw", mesh, field, level_); + throw std::runtime_error("Difference found in check_diff function for the mesh"); + }); + auto set_field = samurai::intersection(mesh[mesh_id_t::cells][level], self(lca_left).on(level)); + set_field( + [&](auto i, auto) + { + if (xt::any(xt::abs(field(level, i) - field(level, i + (1 << level))) > 1e-13)) + { + samurai::io::print("\nDifference found at level {} on interval {}:\n", level, i); + samurai::io::print("\tleft = {}\n", fmt::streamed(field(level, i))); + samurai::io::print("\tright = {}\n", fmt::streamed(field(level, i + (1 << level)))); + samurai::io::print("\terror = {}\n", fmt::streamed(xt::abs(field(level, i) - field(level, i + (1 << level))))); + samurai::io::print("{}\n", fmt::streamed(mesh)); + auto level_ = samurai::make_scalar_field("level", mesh); + samurai::for_each_cell(mesh, + [&](const auto& cell) + { + level_[cell] = cell.level; + }); + samurai::save("mesh_throw", mesh, field, level_); + throw std::runtime_error("Difference found in check_diff function for the field values"); + } + }); + }); } int main(int argc, char* argv[]) diff --git a/include/samurai/field.hpp b/include/samurai/field.hpp index 1a1d41901..0a64c9e3e 100644 --- a/include/samurai/field.hpp +++ b/include/samurai/field.hpp @@ -12,6 +12,7 @@ #include namespace fs = std::filesystem; +#include #include #include @@ -533,8 +534,8 @@ namespace samurai // level_field[cell] = cell.level; // }); // save(fs::current_path(), "mesh_throw", {true, true}, this->mesh(), coords, level_field); - // Avoid formatting of xtensor views/expressions which may be unformattable for fmt - samurai::io::print("indices: \n"); + ((samurai::io::print("{} ", fmt::streamed(index))), ...); + samurai::io::print("\n"); throw std::out_of_range(fmt::format("FIELD ERROR on level {}: try to find interval {}", level, interval)); } @@ -1164,8 +1165,8 @@ namespace samurai // level_field[cell] = cell.level; // }); // save(fs::current_path(), "mesh_throw", {true, true}, this->mesh(), coords, level_field); - // Avoid formatting of xtensor views/expressions which may be unformattable for fmt - samurai::io::print("indices: \n"); + ((samurai::io::print("{} ", fmt::streamed(index))), ...); + samurai::io::print("\n"); throw std::out_of_range(fmt::format("FIELD ERROR on level {}: try to find interval {}", level, interval)); } From e06e7e278cc9a3b65f761c81271c21eaab0e68fc Mon Sep 17 00:00:00 2001 From: sbstndb/sbstndbs Date: Fri, 3 Oct 2025 13:27:07 +0200 Subject: [PATCH 33/37] fix: remove stray '<< std::endl' after eprint in PETSc linear_solver.hpp to fix compile error --- include/samurai/petsc/linear_solver.hpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/include/samurai/petsc/linear_solver.hpp b/include/samurai/petsc/linear_solver.hpp index d9ad2e0ba..9eb3be2b8 100644 --- a/include/samurai/petsc/linear_solver.hpp +++ b/include/samurai/petsc/linear_solver.hpp @@ -132,7 +132,6 @@ namespace samurai { samurai::io::eprint( "Undefined unknown(s) for this linear system. Please set the unknowns using the instruction '[solver].set_unknown(u);' or '[solver].set_unknowns(u1, u2...).\n"); - << std::endl; assert(false && "Undefined unknown(s)"); exit(EXIT_FAILURE); } @@ -327,7 +326,6 @@ namespace samurai { samurai::io::eprint( "Undefined unknown for this linear system. Please set the unknown using the instruction '[solver].set_unknown(u);'.\n"); - << std::endl; assert(false && "Undefined unknown"); exit(EXIT_FAILURE); } From 535bcedbb3399dcfbd2af3a842be42b452c8693a Mon Sep 17 00:00:00 2001 From: sbstndb/sbstndbs Date: Fri, 3 Oct 2025 15:26:30 +0200 Subject: [PATCH 34/37] docs/comments: replace commented std::cout examples with samurai::io::print across repo (excluding timers.hpp) --- demos/FiniteVolume/lid_driven_cavity.cpp | 9 +-- demos/FiniteVolume/stencil_field.hpp | 6 +- demos/LBM/D2Q4444_Euler_Implosion.cpp | 18 ++--- demos/LBM/D2Q4444_Euler_Lax_Liu_uniform.cpp | 2 +- demos/LBM/D2Q5444_Euler_Rayleigh_Taylor.cpp | 18 ++--- .../samurai_new/multigrid/petsc/SamuraiDM.hpp | 75 +++++++++---------- include/samurai/box.hpp | 10 +-- include/samurai/field.hpp | 6 +- include/samurai/mr/adapt.hpp | 2 +- include/samurai/petsc/block_assembly.hpp | 10 +-- .../samurai/petsc/fv/FV_scheme_assembly.hpp | 8 +- .../petsc/fv/cell_based_scheme_assembly.hpp | 6 +- .../petsc/fv/flux_based_scheme_assembly.hpp | 2 +- include/samurai/petsc/linear_block_solver.hpp | 2 +- include/samurai/petsc/matrix_assembly.hpp | 4 +- .../samurai/petsc/nonlinear_local_solvers.hpp | 6 +- include/samurai/petsc/nonlinear_solver.hpp | 8 +- tests/test_operator_set.cpp | 2 +- 18 files changed, 96 insertions(+), 98 deletions(-) diff --git a/demos/FiniteVolume/lid_driven_cavity.cpp b/demos/FiniteVolume/lid_driven_cavity.cpp index 82a7ba201..201709b9c 100644 --- a/demos/FiniteVolume/lid_driven_cavity.cpp +++ b/demos/FiniteVolume/lid_driven_cavity.cpp @@ -443,20 +443,19 @@ int main(int argc, char* argv[]) // Vec nest_result = nestedAssembly.create_rhs_vector(result_nest); // MatMult(nestedA, nest_x, nest_result); - // std::cout << std::setprecision(15); - // std::cout << std::fixed; + // samurai::io::print("(setprecision 15, fixed)\n"); // samurai::for_each_cell( // mesh[mesh_id_t::reference], // [&](auto cell) // { - // std::cout << round(result_velocity_mono[cell][0] * 1.e8) / 1.e8 << std::endl; + // samurai::io::print("{}\n", round(result_velocity_mono[cell][0] * 1.e8) / 1.e8); // if (round(result_velocity_mono[cell][0] * 1.e5) / 1.e5 != round(result_velocity_nest[cell][0] * 1.e5) / 1.e5) // { - // std::cout << result_velocity_mono[cell][0] << " =? " << result_velocity_nest[cell][0] << std::endl; + // samurai::io::print("{} =? {}\n", result_velocity_mono[cell][0], result_velocity_nest[cell][0]); // } // if (result_pressure_mono[cell] != result_pressure_nest[cell]) // { - // std::cout << result_pressure_mono[cell] << " =? " << result_pressure_nest[cell] << std::endl; + // samurai::io::print("{} =? {}\n", result_pressure_mono[cell], result_pressure_nest[cell]); // } // }); } diff --git a/demos/FiniteVolume/stencil_field.hpp b/demos/FiniteVolume/stencil_field.hpp index 8adbf15ab..bd1841ed4 100644 --- a/demos/FiniteVolume/stencil_field.hpp +++ b/demos/FiniteVolume/stencil_field.hpp @@ -317,15 +317,15 @@ namespace samurai template inline auto left_flux(const T1& u, double lb) const { - // std::cout << "left flux " << level << " " << i << " " << lb << std::endl; - // std::cout << flux(u(level, i - 1), u(level, i), lb) << std::endl; + // samurai::io::print("left flux {} {} {}\n", level, i, lb); + // samurai::io::print("{}\n", flux(u(level, i - 1), u(level, i), lb)); return flux(u(level, i - 1), u(level, i), lb); } template inline auto right_flux(const T1& u, double lb) const { - // std::cout << flux(u(level, i), u(level, i + 1), lb) << std::endl; + // samurai::io::print("{}\n", flux(u(level, i), u(level, i + 1), lb)); return flux(u(level, i), u(level, i + 1), lb); } }; diff --git a/demos/LBM/D2Q4444_Euler_Implosion.cpp b/demos/LBM/D2Q4444_Euler_Implosion.cpp index c2a4cc986..8efcadd3e 100644 --- a/demos/LBM/D2Q4444_Euler_Implosion.cpp +++ b/demos/LBM/D2Q4444_Euler_Implosion.cpp @@ -392,7 +392,7 @@ void one_time_step(Field& f, std::size_t j = max_level - (lev_p_1); double coeff = 1. / (1 << (2 * j)); // ATTENTION A LA DIMENSION 2 !!!! - // std::cout< vld_flx{0, 2, 6}; @@ -480,7 +480,7 @@ void one_time_step(Field& f, auto k = interval; // Logical index in x auto h = index[0]; // Logical index in y - // std::cout< vld_flx{0, 2}; @@ -517,7 +517,7 @@ void one_time_step(Field& f, auto k = interval; // Logical index in x auto h = index[0]; // Logical index in y - // std::cout< vld_flx{0, 6}; @@ -553,7 +553,7 @@ void one_time_step(Field& f, { auto k = interval; // Logical index in x auto h = index[0]; // Logical index in y - // std::cout< vld_flx{2, 4, 6}; @@ -585,7 +585,7 @@ void one_time_step(Field& f, { auto k = interval; // Logical index in x auto h = index[0]; // Logical index in y - // std::cout< vld_flx{2, 4}; @@ -621,7 +621,7 @@ void one_time_step(Field& f, { auto k = interval; // Logical index in x auto h = index[0]; // Logical index in y - // std::cout< vld_flx{4, 6}; @@ -657,7 +657,7 @@ void one_time_step(Field& f, { auto k = interval; // Logical index in x auto h = index[0]; // Logical index in y - // std::cout< vld_flx{0, 2, 4}; @@ -689,7 +689,7 @@ void one_time_step(Field& f, { auto k = interval; // Logical index in x auto h = index[0]; // Logical index in y - // std::cout< vld_flx{0, 4, 6}; diff --git a/demos/LBM/D2Q4444_Euler_Lax_Liu_uniform.cpp b/demos/LBM/D2Q4444_Euler_Lax_Liu_uniform.cpp index 16fab89d2..70653da0d 100644 --- a/demos/LBM/D2Q4444_Euler_Lax_Liu_uniform.cpp +++ b/demos/LBM/D2Q4444_Euler_Lax_Liu_uniform.cpp @@ -415,7 +415,7 @@ int main(int argc, char* argv[]) tic(); for (std::size_t nb_ite = 0; nb_ite <= N; ++nb_ite) { - // std::cout< vld_flx{0, 2, 6}; @@ -605,7 +605,7 @@ void one_time_step(Field& f, auto k = interval; // Logical index in x auto h = index[0]; // Logical index in y - // std::cout< vld_flx{0, 2}; @@ -649,7 +649,7 @@ void one_time_step(Field& f, auto k = interval; // Logical index in x auto h = index[0]; // Logical index in y - // std::cout< vld_flx{0, 6}; @@ -690,7 +690,7 @@ void one_time_step(Field& f, { auto k = interval; // Logical index in x auto h = index[0]; // Logical index in y - // std::cout< vld_flx{2, 4, 6}; @@ -728,7 +728,7 @@ void one_time_step(Field& f, { auto k = interval; // Logical index in x auto h = index[0]; // Logical index in y - // std::cout< vld_flx{2, 4}; @@ -770,7 +770,7 @@ void one_time_step(Field& f, { auto k = interval; // Logical index in x auto h = index[0]; // Logical index in y - // std::cout< vld_flx{4, 6}; @@ -811,7 +811,7 @@ void one_time_step(Field& f, { auto k = interval; // Logical index in x auto h = index[0]; // Logical index in y - // std::cout< vld_flx{0, 2, 4}; @@ -850,7 +850,7 @@ void one_time_step(Field& f, { auto k = interval; // Logical index in x auto h = index[0]; // Logical index in y - // std::cout< vld_flx{0, 4, 6}; diff --git a/demos/multigrid/samurai_new/multigrid/petsc/SamuraiDM.hpp b/demos/multigrid/samurai_new/multigrid/petsc/SamuraiDM.hpp index 3c56c1458..3d11a9455 100644 --- a/demos/multigrid/samurai_new/multigrid/petsc/SamuraiDM.hpp +++ b/demos/multigrid/samurai_new/multigrid/petsc/SamuraiDM.hpp @@ -72,7 +72,7 @@ namespace samurai_new static PetscErrorCode Coarsen(DM fine_dm, MPI_Comm /*comm*/, DM* coarse_dm) { - // std::cout << "Coarsen - begin" << std::endl; + // samurai::io::print("Coarsen - begin\n"); LevelContext* fine_ctx; DMShellGetContext(fine_dm, &fine_ctx); @@ -84,10 +84,9 @@ namespace samurai_new DMShellCreate(PetscObjectComm(reinterpret_cast(fine_dm)), coarse_dm); DefineShellFunctions(*coarse_dm, *coarse_ctx); - // DMShellCreate(PetscObjectComm((PetscObject)fine_dm), - // coarse_dm); DefineShellFunctions(*coarse_dm, *coarse_ctx); - // std::cout << "Coarsen (create level " << coarse_ctx->level << - // ")" << std::endl; + // DMShellCreate(PetscObjectComm((PetscObject)fine_dm), coarse_dm); + // DefineShellFunctions(*coarse_dm, *coarse_ctx); + // samurai::io::print("Coarsen (create level {})\n", coarse_ctx->level); return 0; } @@ -97,8 +96,7 @@ namespace samurai_new DMShellGetContext(shell, &ctx); ctx->assembly().create_matrix(*A); - // std::cout << "CreateMatrix - level " << ctx->level << - // std::endl; + // samurai::io::print("CreateMatrix - level {}\n", ctx->level); MatSetDM(*A, shell); // Why??? return 0; @@ -116,7 +114,7 @@ namespace samurai_new ctx->assembly().assemble_matrix(jac); // MatView(jac, PETSC_VIEWER_STDOUT_(PETSC_COMM_SELF)); - // std::cout << std::endl; + // samurai::io::print("\n"); return 0; } @@ -147,9 +145,9 @@ namespace samurai_new MatShellGetContext(P, &coarse_ctx); fine_ctx = coarse_ctx->finer; - // std::cout << "coarse vector x:" << std::endl; - // VecView(x, PETSC_VIEWER_STDOUT_(PETSC_COMM_SELF)); std::cout - // << std::endl; + // samurai::io::print("coarse vector x:\n"); + // VecView(x, PETSC_VIEWER_STDOUT_(PETSC_COMM_SELF)); + // samurai::io::print("\n"); if (coarse_ctx->transfer_ops == TransferOperators::MatrixFree_Fields) { @@ -172,9 +170,9 @@ namespace samurai_new VecRestoreArrayRead(x, &xarray); VecRestoreArray(y, &yarray); - /*std::cout << "prolongated vector (marche):" << std::endl; - VecView(y, PETSC_VIEWER_STDOUT_(PETSC_COMM_SELF)); std::cout - << std::endl; + /*samurai::io::print("prolongated vector (marche):\n"); + VecView(y, PETSC_VIEWER_STDOUT_(PETSC_COMM_SELF)); + samurai::io::print("\n"); // With matrix std::size_t nf = fine_ctx->mesh().nb_cells(); @@ -191,17 +189,18 @@ namespace samurai_new fine_ctx->mesh(), P2); MatAssemblyBegin(P2, MAT_FINAL_ASSEMBLY); MatAssemblyEnd(P2, MAT_FINAL_ASSEMBLY); - std::cout << "prolongated vector with matrix (marche pas):" - << std::endl; Vec y2; VecCreateSeq(PETSC_COMM_SELF, nf, - &y2); MatMult(P2, x, y2); VecView(y2, - PETSC_VIEWER_STDOUT_(PETSC_COMM_SELF)); std::cout << - std::endl;*/ + samurai::io::print("prolongated vector with matrix (marche pas):\n"); + Vec y2; VecCreateSeq(PETSC_COMM_SELF, nf, &y2); + MatMult(P2, x, y2); + VecView(y2, PETSC_VIEWER_STDOUT_(PETSC_COMM_SELF)); + samurai::io::print("\n");*/ } - // std::cout << "prolongated vector:" << std::endl; - // VecView(y, PETSC_VIEWER_STDOUT_(PETSC_COMM_SELF)); std::cout - // << std::endl; PetscReal norm; VecNorm(y, NORM_2, &norm); - // std::cout << "prolongated vector norm:" << norm << std::endl; + // samurai::io::print("prolongated vector:\n"); + // VecView(y, PETSC_VIEWER_STDOUT_(PETSC_COMM_SELF)); + // samurai::io::print("\n"); + // PetscReal norm; VecNorm(y, NORM_2, &norm); + // samurai::io::print("prolongated vector norm:{}\n", norm); assert(samurai::petsc::check_nan_or_inf(y) && "Nan or Inf after prolongation"); return 0; @@ -231,8 +230,8 @@ namespace samurai_new MatAssemblyBegin(*P, MAT_FINAL_ASSEMBLY); MatAssemblyEnd(*P, MAT_FINAL_ASSEMBLY); - // MatView(*P, PETSC_VIEWER_STDOUT_(PETSC_COMM_SELF)); std::cout - // << std::endl; + // MatView(*P, PETSC_VIEWER_STDOUT_(PETSC_COMM_SELF)); + // samurai::io::print("\n"); *scaling = nullptr; // Why??? @@ -260,9 +259,9 @@ namespace samurai_new MatShellGetContext(R, &fine_ctx); LevelContext* coarse_ctx = fine_ctx->coarser; - // std::cout << "restriction - fine vector:" << std::endl; - // VecView(x, PETSC_VIEWER_STDOUT_(PETSC_COMM_SELF)); std::cout - // << std::endl; + // samurai::io::print("restriction - fine vector:\n"); + // VecView(x, PETSC_VIEWER_STDOUT_(PETSC_COMM_SELF)); + // samurai::io::print("\n"); if (coarse_ctx->transfer_ops == TransferOperators::MatrixFree_Fields) { @@ -282,10 +281,11 @@ namespace samurai_new VecRestoreArray(y, &yarray); } - // std::cout << "restriction - restricted vector:" << std::endl; - // VecView(y, PETSC_VIEWER_STDOUT_(PETSC_COMM_SELF)); std::cout - // << std::endl; PetscReal norm; VecNorm(y, NORM_2, &norm); - // std::cout << "restricted vector norm:" << norm << std::endl; + // samurai::io::print("restriction - restricted vector:\n"); + // VecView(y, PETSC_VIEWER_STDOUT_(PETSC_COMM_SELF)); + // samurai::io::print("\n"); + // PetscReal norm; VecNorm(y, NORM_2, &norm); + // samurai::io::print("restricted vector norm:{}\n", norm); assert(samurai::petsc::check_nan_or_inf(y) && "Nan or Inf after restriction"); return 0; @@ -320,31 +320,30 @@ namespace samurai_new MatAssemblyEnd(*R, MAT_FINAL_ASSEMBLY); // MatView(*R, PETSC_VIEWER_STDOUT_(PETSC_COMM_SELF)); - // std::cout << std::endl; + // samurai::io::print("\n"); return 0; } static PetscErrorCode CreateGlobalVector(DM shell, Vec* x) { - // std::cout << "CreateGlobalVector - begin " << std::endl; + // samurai::io::print("CreateGlobalVector - begin\n"); LevelContext* ctx; DMShellGetContext(shell, &ctx); VecCreateSeq(PETSC_COMM_SELF, static_cast(ctx->mesh().nb_cells()), x); VecSetDM(*x, shell); - // std::cout << "CreateGlobalVector - level " << ctx->level << - // std::endl; + // samurai::io::print("CreateGlobalVector - level {}\n", ctx->level); return 0; } static PetscErrorCode CreateLocalVector(DM shell, Vec* x) { - // std::cout << "CreateLocalVector - begin" << std::endl; + // samurai::io::print("CreateLocalVector - begin\n"); LevelContext* ctx; DMShellGetContext(shell, &ctx); VecCreateSeq(PETSC_COMM_SELF, static_cast(ctx->mesh().nb_cells()), x); VecSetDM(*x, shell); - // std::cout << "CreateLocalVector - end" << std::endl; + // samurai::io::print("CreateLocalVector - end\n"); return 0; } }; diff --git a/include/samurai/box.hpp b/include/samurai/box.hpp index 25c5ef030..b75c4c50e 100644 --- a/include/samurai/box.hpp +++ b/include/samurai/box.hpp @@ -178,7 +178,7 @@ namespace samurai if (d == dim - 1 && box.is_valid()) { boxes.push_back(box); - // std::cout << box << std::endl; + // samurai::io::print("{}\n", fmt::streamed(box)); } difference_impl_rec(box, intersection, d + 1, boxes); @@ -188,7 +188,7 @@ namespace samurai if (d == dim - 1 && box.is_valid() && box != intersection) // The intersection is what we want to remove, so we don't add it { boxes.push_back(box); - // std::cout << box << std::endl; + // samurai::io::print("{}\n", fmt::streamed(box)); } difference_impl_rec(box, intersection, d + 1, boxes); @@ -198,7 +198,7 @@ namespace samurai if (d == dim - 1 && box.is_valid()) { boxes.push_back(box); - // std::cout << box << std::endl; + // samurai::io::print("{}\n", fmt::streamed(box)); } difference_impl_rec(box, intersection, d + 1, boxes); @@ -326,7 +326,7 @@ namespace samurai subdivision_length /= 2; approx_length = xt::ceil(box.length() / subdivision_length) * subdivision_length; error = xt::abs(approx_length - box.length()); - // std::cout << "Approximation error: " << error << std::endl; + // samurai::io::print("Approximation error: {}\n", error); } } else if (tol > 0) @@ -341,7 +341,7 @@ namespace samurai subdivision_length *= 2; approx_length = xt::ceil(box.length() / subdivision_length) * subdivision_length; error = xt::abs(approx_length - box.length()); - // std::cout << "Approximation error: " << error << std::endl; + // samurai::io::print("Approximation error: {}\n", error); } subdivision_length /= 2; approx_length = xt::ceil(box.length() / subdivision_length) * subdivision_length; diff --git a/include/samurai/field.hpp b/include/samurai/field.hpp index 0a64c9e3e..b3ec4df30 100644 --- a/include/samurai/field.hpp +++ b/include/samurai/field.hpp @@ -155,7 +155,7 @@ namespace samurai { auto interval_tmp = this->derived_cast().get_interval(level, interval, index); - // std::cout << "READ OR WRITE: " << level << " " << interval << " " << (... << index) << std::endl; + // samurai::io::print("READ OR WRITE: {} {} ...\n", level, interval); return view(m_storage, {interval_tmp.index + interval.start, interval_tmp.index + interval.end, interval.step}); } @@ -165,7 +165,7 @@ namespace samurai const xt::xtensor_fixed>& index) const { auto interval_tmp = this->derived_cast().get_interval(level, interval, index); - // std::cout << "READ: " << level << " " << interval << " " << (... << index) << std::endl; + // samurai::io::print("READ: {} {} ...\n", level, interval); auto data = view(m_storage, {interval_tmp.index + interval.start, interval_tmp.index + interval.end, interval.step}); #ifdef SAMURAI_CHECK_NAN @@ -254,7 +254,7 @@ namespace samurai if (xt::any(xt::isnan(data))) { - // std::cout << data << std::endl; + // samurai::io::print("{}\n", fmt::streamed(data)); samurai::io::eprint("READ NaN at level {}, {}\n", level, fmt::streamed(interval)); } #endif diff --git a/include/samurai/mr/adapt.hpp b/include/samurai/mr/adapt.hpp index 8eb6ba32b..0e234ccc7 100644 --- a/include/samurai/mr/adapt.hpp +++ b/include/samurai/mr/adapt.hpp @@ -154,7 +154,7 @@ namespace samurai cfg.parse_args(); for (std::size_t i = 0; i < max_level - min_level; ++i) { - // std::cout << "MR mesh adaptation " << i << std::endl; + // samurai::io::print("MR mesh adaptation {}\n", i); m_detail.resize(); m_detail.fill(0); m_tag.resize(); diff --git a/include/samurai/petsc/block_assembly.hpp b/include/samurai/petsc/block_assembly.hpp index 9849ac071..9e6f81840 100644 --- a/include/samurai/petsc/block_assembly.hpp +++ b/include/samurai/petsc/block_assembly.hpp @@ -307,7 +307,7 @@ namespace samurai for_each_assembly_op( [&](auto& op, auto row, auto col) { - // std::cout << "create_matrix (" << row << ", " << col << ")" << std::endl; + // samurai::io::print("create_matrix ({}, {})\n", row, col); op.create_matrix(block(row, col)); }); MatCreateNest(PETSC_COMM_SELF, rows, PETSC_IGNORE, cols, PETSC_IGNORE, m_blocks.data(), &A); @@ -318,7 +318,7 @@ namespace samurai for_each_assembly_op( [&](auto& op, auto row, auto col) { - // std::cout << "assemble_matrix (" << row << ", " << col << ") '" << op.name() << "'" << std::endl; + // samurai::io::print("assemble_matrix ({}, {}) '{}'\n", row, col, op.name()); op.assemble_matrix(block(row, col)); }); if (final_assembly) @@ -371,7 +371,7 @@ namespace samurai { if (op.include_bc()) { - // std::cout << "enforce_bc (" << row << ", " << col << ") on b[" << row << "]" << std::endl; + // samurai::io::print("enforce_bc ({}, {}) on b[{}]\n", row, col, row); Vec b_block; VecNestGetSubVec(b, static_cast(row), &b_block); op.enforce_bc(b_block); @@ -647,7 +647,7 @@ namespace samurai { op.set_current_insert_mode(insert_mode); } - // std::cout << "assemble_scheme (" << row << ", " << col << ") '" << op.name() << "'" << std::endl; + // samurai::io::print("assemble_scheme ({}, {}) '{}'\n", row, col, op.name()); op.assemble_scheme(A); insert_mode = op.current_insert_mode(); }); @@ -792,7 +792,7 @@ namespace samurai { if (op.include_bc()) { - // std::cout << "enforce_bc (" << row << ", " << col << ") on b[" << row << "]" << std::endl; + // samurai::io::print("enforce_bc ({}, {}) on b[{}]\n", row, col, row); op.enforce_bc(b); } }); diff --git a/include/samurai/petsc/fv/FV_scheme_assembly.hpp b/include/samurai/petsc/fv/FV_scheme_assembly.hpp index dbb0650c5..bf2dbd31d 100644 --- a/include/samurai/petsc/fv/FV_scheme_assembly.hpp +++ b/include/samurai/petsc/fv/FV_scheme_assembly.hpp @@ -96,7 +96,7 @@ namespace samurai exit(EXIT_FAILURE); } m_n_cells = mesh().nb_cells(); - // std::cout << "reset " << this->name() << ", rows = " << matrix_rows() << std::endl; + // samurai::io::print("reset {}, rows = {}\n", this->name(), matrix_rows()); m_is_row_empty.resize(static_cast(matrix_rows())); std::fill(m_is_row_empty.begin(), m_is_row_empty.end(), true); @@ -430,7 +430,7 @@ namespace samurai void assemble_boundary_conditions(Mat& A) override { - // std::cout << "assemble_boundary_conditions of " << this->name() << std::endl; + // samurai::io::print("assemble_boundary_conditions of {}\n", this->name()); if (current_insert_mode() == ADD_VALUES) { // Must flush to use INSERT_VALUES instead of ADD_VALUES @@ -512,7 +512,7 @@ namespace samurai virtual void enforce_bc(Vec& b) const { - // std::cout << "enforce_bc of " << this->name() << std::endl; + // samurai::io::print("enforce_bc of {}\n", this->name()); if (!this->is_block()) { PetscInt b_rows; @@ -600,7 +600,7 @@ namespace samurai MatAssemblyEnd(A, MAT_FLUSH_ASSEMBLY); set_current_insert_mode(INSERT_VALUES); } - // std::cout << "insert_value_on_diag_for_useless_ghosts of " << this->name() << std::endl; + // samurai::io::print("insert_value_on_diag_for_useless_ghosts of {}\n", this->name()); for (std::size_t i = 0; i < m_is_row_empty.size(); i++) { if (m_is_row_empty[i]) diff --git a/include/samurai/petsc/fv/cell_based_scheme_assembly.hpp b/include/samurai/petsc/fv/cell_based_scheme_assembly.hpp index 929d313e2..c988ac5ea 100644 --- a/include/samurai/petsc/fv/cell_based_scheme_assembly.hpp +++ b/include/samurai/petsc/fv/cell_based_scheme_assembly.hpp @@ -159,7 +159,7 @@ namespace samurai void assemble_scheme(Mat& A) override { - // std::cout << "assemble_scheme() of " << this->name() << std::endl; + // samurai::io::print("assemble_scheme() of {}\n", this->name()); if (this->current_insert_mode() == INSERT_VALUES) { @@ -174,9 +174,9 @@ namespace samurai unknown(), [&](const auto& cells, const auto& coeffs) { - // std::cout << "coeffs: " << std::endl; + // samurai::io::print("coeffs:\n"); // for (std::size_t i=0; i rows; diff --git a/include/samurai/petsc/fv/flux_based_scheme_assembly.hpp b/include/samurai/petsc/fv/flux_based_scheme_assembly.hpp index fb6434efa..b817737b0 100644 --- a/include/samurai/petsc/fv/flux_based_scheme_assembly.hpp +++ b/include/samurai/petsc/fv/flux_based_scheme_assembly.hpp @@ -134,7 +134,7 @@ namespace samurai void assemble_scheme(Mat& A) override { - // std::cout << "assemble_scheme() of " << this->name() << std::endl; + // samurai::io::print("assemble_scheme() of {}\n", this->name()); if (this->current_insert_mode() == INSERT_VALUES) { diff --git a/include/samurai/petsc/linear_block_solver.hpp b/include/samurai/petsc/linear_block_solver.hpp index 8f4b2f4a3..6d97353a2 100644 --- a/include/samurai/petsc/linear_block_solver.hpp +++ b/include/samurai/petsc/linear_block_solver.hpp @@ -116,7 +116,7 @@ namespace samurai } this->assemble_matrix(); - // MatView(m_A, PETSC_VIEWER_STDOUT_(PETSC_COMM_SELF)); std::cout << std::endl; + // MatView(m_A, PETSC_VIEWER_STDOUT_(PETSC_COMM_SELF)); samurai::io::print("\n"); KSPSetOperators(m_ksp, m_A, m_A); PC pc; diff --git a/include/samurai/petsc/matrix_assembly.hpp b/include/samurai/petsc/matrix_assembly.hpp index 2366da65d..b69587281 100644 --- a/include/samurai/petsc/matrix_assembly.hpp +++ b/include/samurai/petsc/matrix_assembly.hpp @@ -194,7 +194,7 @@ namespace samurai // for (std::size_t row = 0; row < nnz.size(); ++row) // { - // std::cout << "nnz[" << row << "] = " << nnz[row] << std::endl; + // samurai::io::print("nnz[{}] = {}\n", row, nnz[row]); // } if (!m_is_block) { @@ -246,7 +246,7 @@ namespace samurai virtual ~MatrixAssembly() { - // std::cout << "Destruction of '" << name() << "'" << std::endl; + // samurai::io::print("Destruction of '{}'\n", name()); m_is_deleted = true; } diff --git a/include/samurai/petsc/nonlinear_local_solvers.hpp b/include/samurai/petsc/nonlinear_local_solvers.hpp index 1ff013a04..dcfa2cb91 100644 --- a/include/samurai/petsc/nonlinear_local_solvers.hpp +++ b/include/samurai/petsc/nonlinear_local_solvers.hpp @@ -264,7 +264,7 @@ namespace samurai } // MatView(B, PETSC_VIEWER_STDOUT_(PETSC_COMM_SELF)); - // std::cout << std::endl; + // samurai::io::print("\n"); VecRestoreArrayRead(x, &x_data); @@ -287,12 +287,12 @@ namespace samurai SNESGetConvergedReasonString(snes, &reason_text); samurai::io::eprint("Divergence of the non-linear solver ({})\n", reason_text); // VecView(b, PETSC_VIEWER_STDOUT_(PETSC_COMM_SELF)); - // std::cout << std::endl; + // samurai::io::print("\n"); // assert(check_nan_or_inf(b)); assert(false && "Divergence of the solver"); exit(EXIT_FAILURE); } - // VecView(x, PETSC_VIEWER_STDOUT_(PETSC_COMM_SELF)); std::cout << std::endl; + // VecView(x, PETSC_VIEWER_STDOUT_(PETSC_COMM_SELF)); samurai::io::print("\n"); } public: diff --git a/include/samurai/petsc/nonlinear_solver.hpp b/include/samurai/petsc/nonlinear_solver.hpp index ff1182149..5c2f31479 100644 --- a/include/samurai/petsc/nonlinear_solver.hpp +++ b/include/samurai/petsc/nonlinear_solver.hpp @@ -221,7 +221,7 @@ namespace samurai } // MatView(B, PETSC_VIEWER_STDOUT_(PETSC_COMM_SELF)); - // std::cout << std::endl; + // samurai::io::print("\n"); // Put back the real unknown: we need its B.C. for the evaluation of the non-linear function assembly.set_unknown(*real_system_unknown); @@ -243,7 +243,7 @@ namespace samurai // assembly().set_0_for_useless_ghosts(b); // VecView(b, PETSC_VIEWER_STDOUT_(PETSC_COMM_SELF)); - // std::cout << std::endl; + // samurai::io::print("\n"); // assert(check_nan_or_inf(b)); } @@ -269,12 +269,12 @@ namespace samurai SNESGetConvergedReasonString(m_snes, &reason_text); samurai::io::eprint("Divergence of the non-linear solver ({})\n", reason_text); // VecView(b, PETSC_VIEWER_STDOUT_(PETSC_COMM_SELF)); - // std::cout << std::endl; + // samurai::io::print("\n"); // assert(check_nan_or_inf(b)); assert(false && "Divergence of the solver"); exit(EXIT_FAILURE); } - // VecView(x, PETSC_VIEWER_STDOUT_(PETSC_COMM_SELF)); std::cout << std::endl; + // VecView(x, PETSC_VIEWER_STDOUT_(PETSC_COMM_SELF)); samurai::io::print("\n"); } public: diff --git a/tests/test_operator_set.cpp b/tests/test_operator_set.cpp index e14b026cf..078488e78 100644 --- a/tests/test_operator_set.cpp +++ b/tests/test_operator_set.cpp @@ -18,7 +18,7 @@ namespace samurai // LevelCellArray<1> lca{lcl}; - // std::cout << lca << "\n\n"; + // samurai::io::print("{}\n\n", fmt::streamed(lca)); // } template From 80d677b7743f631ad75238e415b1e0ef5887cd49 Mon Sep 17 00:00:00 2001 From: sbstndb/sbstndbs Date: Fri, 3 Oct 2025 15:42:35 +0200 Subject: [PATCH 35/37] chore(comments): convert remaining commented std::cout/cerr to samurai::io::print/eprint (excluding timers.hpp) --- demos/LBM/D1Q2_Advection_and_Burgers.cpp | 4 ++-- demos/highorder/main.cpp | 2 +- demos/multigrid/main.cpp | 4 ++-- demos/multigrid/samurai_new/multigrid/petsc/SamuraiDM.hpp | 4 ++-- .../samurai_new/multigrid/petsc/intergrid_operators.hpp | 8 +++----- include/samurai/field.hpp | 4 ++-- include/samurai/petsc/fv/operator_sum_assembly.hpp | 2 +- include/samurai/petsc/linear_solver.hpp | 6 +++--- 8 files changed, 16 insertions(+), 18 deletions(-) diff --git a/demos/LBM/D1Q2_Advection_and_Burgers.cpp b/demos/LBM/D1Q2_Advection_and_Burgers.cpp index 4197fbebe..a7a56af94 100644 --- a/demos/LBM/D1Q2_Advection_and_Burgers.cpp +++ b/demos/LBM/D1Q2_Advection_and_Burgers.cpp @@ -135,7 +135,7 @@ xt::xtensor prediction(const Field& f, auto it = mem_map.find({item, level_g, level, i}); if (it != mem_map.end()) { - // std::cout<second; } else @@ -145,7 +145,7 @@ xt::xtensor prediction(const Field& f, xt::xtensor out = xt::empty({i.size() / i.step}); // xt::eval(f(item, level_g, i)); auto mask = mesh.exists(mesh_id_t::cells_and_ghosts, level_g + level, i); - // std::cout << level_g + level << " " << i << " " << mask << "\n"; + // samurai::io::print("{} {} {}\n", level_g + level, i, mask); if (xt::all(mask)) { return xt::eval(f(item, level_g + level, i)); diff --git a/demos/highorder/main.cpp b/demos/highorder/main.cpp index b942e6ad7..b42ae5e7e 100644 --- a/demos/highorder/main.cpp +++ b/demos/highorder/main.cpp @@ -199,7 +199,7 @@ int main(int argc, char* argv[]) // mesh = {cl, mesh.min_level() + 1, mesh.max_level() + 1}; mesh = {cl, min_level + i_ref + 1, max_level + i_ref + 1}; } - // std::cout << mesh << std::endl; + // samurai::io::print("{}\n", fmt::streamed(mesh)); // samurai::save("refine_mesh", mesh); // Equation: -Lap u = f in [0, 1]^2 diff --git a/demos/multigrid/main.cpp b/demos/multigrid/main.cpp index 7558c0c61..9aa4f7f8d 100644 --- a/demos/multigrid/main.cpp +++ b/demos/multigrid/main.cpp @@ -300,12 +300,12 @@ int main(int argc, char* argv[]) if (test_case_code == "poly") { // double hidden_constant = samurai::compute_error_bound_hidden_constant(h, error); - // std::cout << "hidden_constant: " << hidden_constant << std::endl; + // samurai::io::print("hidden_constant: {}\n", hidden_constant); static constexpr std::size_t order = 2; double h = mesh.cell_length(mesh.min_level()); double hidden_constant = 5e-2; double theoretical_bound = samurai::theoretical_error_bound(n_comp * hidden_constant, h); - // std::cout << "theoretical_bound: " << theoretical_bound << std::endl; + // samurai::io::print("theoretical_bound: {}\n", theoretical_bound); if (error > theoretical_bound) { samurai::io::eprint("Convergence order failure: the error must be < {}.\n", theoretical_bound); diff --git a/demos/multigrid/samurai_new/multigrid/petsc/SamuraiDM.hpp b/demos/multigrid/samurai_new/multigrid/petsc/SamuraiDM.hpp index 3d11a9455..2f4cd458d 100644 --- a/demos/multigrid/samurai_new/multigrid/petsc/SamuraiDM.hpp +++ b/demos/multigrid/samurai_new/multigrid/petsc/SamuraiDM.hpp @@ -156,9 +156,9 @@ namespace samurai_new Field fine_field = multigrid::prolong(coarse_field, fine_ctx->mesh(), coarse_ctx->prediction_order); samurai::petsc::copy(fine_field, y); - // std::cout << "prolongated vector (marche):" << std::endl; + // samurai::io::print("prolongated vector (marche):\n"); // VecView(y, PETSC_VIEWER_STDOUT_(PETSC_COMM_SELF)); - // std::cout << std::endl; + // samurai::io::print("\n"); } else { diff --git a/demos/multigrid/samurai_new/multigrid/petsc/intergrid_operators.hpp b/demos/multigrid/samurai_new/multigrid/petsc/intergrid_operators.hpp index b0d6853a2..bafc2dd9d 100644 --- a/demos/multigrid/samurai_new/multigrid/petsc/intergrid_operators.hpp +++ b/demos/multigrid/samurai_new/multigrid/petsc/intergrid_operators.hpp @@ -1047,8 +1047,7 @@ namespace samurai_new auto& i, const auto& index) { auto j = index[0]; - std::cout << "avant i = " << i << ", j = " << j - << ":" << coarse_field(level, i, j) << std::endl; if + samurai::io::print("avant i = {}, j = {}:{}\n", i, j, coarse_field(level, i, j)); if (s(0) == 1 && s(1) == 1) // top-right coarse_field(level, i, j) = fine_field(level+1, 2*i , 2*j ); else if (s(0) == -1 @@ -1057,9 +1056,8 @@ namespace samurai_new && s(1) == -1) // bottom-left coarse_field(level, i, j) = fine_field(level+1, 2*i+1, 2*j+1); else if (s(0) == 1 && s(1) == -1) // bottom-right coarse_field(level, i, j) - = fine_field(level+1, 2*i , 2*j+1); std::cout << "apres - i = " << i << ", j = " << j << ":" << - coarse_field(level, i, j) << std::endl; + = fine_field(level+1, 2*i , 2*j+1); samurai::io::print("apres i = {}, j = {}:{}\n", i, j, coarse_field(level, i, + j)); }); }*/ } diff --git a/include/samurai/field.hpp b/include/samurai/field.hpp index b3ec4df30..a37a3c899 100644 --- a/include/samurai/field.hpp +++ b/include/samurai/field.hpp @@ -137,7 +137,7 @@ namespace samurai { if (std::isnan(this->derived_cast().m_storage.data()[static_cast(i)])) { - // std::cerr << "READ NaN at level " << level << ", in interval " << interval << std::endl; + // samurai::io::eprint("READ NaN at level {}, in interval {}\n", level, interval); auto ii = i - interval_tmp.index; auto cell = this->derived_cast().mesh().get_cell(level, static_cast(ii), index...); samurai::io::eprint("READ NaN in {}\n", fmt::streamed(cell)); @@ -176,7 +176,7 @@ namespace samurai { if (std::isnan(this->derived_cast().m_storage.data()[static_cast(i)])) { - // std::cerr << "READ NaN at level " << level << ", in interval " << interval << std::endl; + // samurai::io::eprint("READ NaN at level {}, in interval {}\n", level, interval); auto ii = i - interval_tmp.index; auto cell = this->derived_cast().mesh().get_cell(level, static_cast(ii), index); samurai::io::eprint("READ NaN in {}\n", fmt::streamed(cell)); diff --git a/include/samurai/petsc/fv/operator_sum_assembly.hpp b/include/samurai/petsc/fv/operator_sum_assembly.hpp index 5e14d5034..c5d15b2b4 100644 --- a/include/samurai/petsc/fv/operator_sum_assembly.hpp +++ b/include/samurai/petsc/fv/operator_sum_assembly.hpp @@ -193,7 +193,7 @@ namespace samurai for_each(m_assembly_ops, [&](auto& op) { - // std::cout << "Assembly of " << op.name() << std::endl; + // samurai::io::print("Assembly of {}\n", op.name()); op.assemble_scheme(A); set_current_insert_mode(op.current_insert_mode()); }); diff --git a/include/samurai/petsc/linear_solver.hpp b/include/samurai/petsc/linear_solver.hpp index 9eb3be2b8..5b889998f 100644 --- a/include/samurai/petsc/linear_solver.hpp +++ b/include/samurai/petsc/linear_solver.hpp @@ -182,7 +182,7 @@ namespace samurai // assembly().enforce_projection_prediction(b); // // Set to zero the right-hand side of the useless ghosts' equations // assembly().set_0_for_useless_ghosts(b); - // VecView(b, PETSC_VIEWER_STDOUT_(PETSC_COMM_SELF)); std::cout << std::endl; + // VecView(b, PETSC_VIEWER_STDOUT_(PETSC_COMM_SELF)); samurai::io::print("\n"); // assert(check_nan_or_inf(b)); times::timers.stop("system solve"); @@ -207,12 +207,12 @@ namespace samurai KSPGetConvergedReasonString(m_ksp, &reason_text); samurai::io::eprint("Divergence of the solver ({})\n", reason_text); // VecView(b, PETSC_VIEWER_STDOUT_(PETSC_COMM_SELF)); - // std::cout << std::endl; + // samurai::io::print("\n"); // assert(check_nan_or_inf(b)); assert(false && "Divergence of the solver"); exit(EXIT_FAILURE); } - // VecView(x, PETSC_VIEWER_STDOUT_(PETSC_COMM_SELF)); std::cout << std::endl; + // VecView(x, PETSC_VIEWER_STDOUT_(PETSC_COMM_SELF)); samurai::io::print("\n"); } public: From 48d88126e5f4985fc2cc1ecccc80cbaea7cd23a0 Mon Sep 17 00:00:00 2001 From: sbstndb/sbstndbs Date: Fri, 3 Oct 2025 19:19:02 +0200 Subject: [PATCH 36/37] io(print): avoid constant condition in non-MPI builds; guard should_print for root/rank by MPI --- include/samurai/print.hpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/samurai/print.hpp b/include/samurai/print.hpp index 0f1b15918..acbea04aa 100644 --- a/include/samurai/print.hpp +++ b/include/samurai/print.hpp @@ -92,12 +92,22 @@ namespace samurai inline bool should_print(root_t) { +#ifdef SAMURAI_WITH_MPI return current_rank() == 0; +#else + // Without MPI, current_rank() is always 0; root prints by default + return true; +#endif } inline bool should_print(rank_t r) { +#ifdef SAMURAI_WITH_MPI return current_rank() == r.value; +#else + // Without MPI, only rank 0 exists + return r.value == 0; +#endif } // Scoped printing helper From 1e05c898517b4fe3c2aed0b1934555f4260b59b6 Mon Sep 17 00:00:00 2001 From: sbstndb/sbstndbs Date: Fri, 3 Oct 2025 19:19:24 +0200 Subject: [PATCH 37/37] io(print): remove inline comments in should_print --- include/samurai/print.hpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/include/samurai/print.hpp b/include/samurai/print.hpp index acbea04aa..82cbf029f 100644 --- a/include/samurai/print.hpp +++ b/include/samurai/print.hpp @@ -95,7 +95,6 @@ namespace samurai #ifdef SAMURAI_WITH_MPI return current_rank() == 0; #else - // Without MPI, current_rank() is always 0; root prints by default return true; #endif } @@ -105,7 +104,6 @@ namespace samurai #ifdef SAMURAI_WITH_MPI return current_rank() == r.value; #else - // Without MPI, only rank 0 exists return r.value == 0; #endif }