Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
83e3563
feat: use fmt
sbstndb Sep 11, 2025
8e3f26d
feat: use fmt in demos
sbstndb Sep 11, 2025
aef182f
feat: improve printing
sbstndb Sep 11, 2025
1cee091
feat: use samurai::io::print everywhere
sbstndb Sep 11, 2025
58dff18
feat: remove dont redirect output
sbstndb Sep 11, 2025
90e50a0
fix: resolve issue on flag
sbstndb Sep 11, 2025
56ffba4
feat: use samurai wrapper print for demos
sbstndb Sep 11, 2025
ffe4539
ci: precommit
sbstndb Sep 11, 2025
b98c6d3
fix: typo
sbstndb Sep 11, 2025
f4cd476
fix: typo
sbstndb Sep 11, 2025
1b0e203
fix: resolve compilation issue
sbstndb Sep 11, 2025
12d5378
ci: precommit
sbstndb Sep 11, 2025
6e66569
io(print): add <cstdio>/<utility>; guard MPI rank with MPI_Initialize…
sbstndb Oct 3, 2025
9d0946d
style(print): apply clang-format after pre-commit
sbstndb Oct 3, 2025
5d9c87a
chore(repo): remove editor swap files and ignore them (*.swp, *.swo, …
sbstndb Oct 3, 2025
131ec14
revert: keep std::cerr unchanged; convert only std::cout. Revert unin…
sbstndb Oct 3, 2025
c861e89
revert: keep std::cerr; remove unintended print.hpp/fmt includes in e…
sbstndb Oct 3, 2025
931474a
Revert "revert: keep std::cerr; remove unintended print.hpp/fmt inclu…
sbstndb Oct 3, 2025
7cab315
Revert "revert: keep std::cerr unchanged; convert only std::cout. Rev…
sbstndb Oct 3, 2025
f9be34e
io: convert std::cout to samurai::io::print (root where appropriate);…
sbstndb Oct 3, 2025
5024bfd
style: clang-format includes and wrapping
sbstndb Oct 3, 2025
b63e5df
io: convert std::cerr/std::cout to samurai::io::eprint/print across i…
sbstndb Oct 3, 2025
170bf72
style: apply clang-format
sbstndb Oct 3, 2025
698a916
refactor: rely on print.hpp to provide fmt; remove redundant <fmt/...…
sbstndb Oct 3, 2025
cfb50ca
style: clang-format after header include cleanup
sbstndb Oct 3, 2025
5ee0002
demos: port top offenders to samurai::io::print/eprint (MPI-safe): LB…
sbstndb Oct 3, 2025
9f9d294
style: apply clang-format in demos after IO port
sbstndb Oct 3, 2025
eaa4b66
io: port remaining demos to samurai::io::print/eprint; add <samurai/p…
sbstndb Oct 3, 2025
01c2712
docs: replace std::cout in snippets and RST examples with samurai::io…
sbstndb Oct 3, 2025
9873637
fix: add <samurai/print.hpp> in BZ demos; include <xtensor/xio.hpp> w…
sbstndb Oct 3, 2025
42d582e
fix(fmt+xtensor): avoid printing xtensor indices inside field.hpp err…
sbstndb Oct 3, 2025
42394b1
fmt(streamed): restore index printing in field.hpp using fmt::streame…
sbstndb Oct 3, 2025
e06e7e2
fix: remove stray '<< std::endl' after eprint in PETSc linear_solver.…
sbstndb Oct 3, 2025
535bced
docs/comments: replace commented std::cout examples with samurai::io:…
sbstndb Oct 3, 2025
80d677b
chore(comments): convert remaining commented std::cout/cerr to samura…
sbstndb Oct 3, 2025
48d8812
io(print): avoid constant condition in non-MPI builds; guard should_p…
sbstndb Oct 3, 2025
1e05c89
io(print): remove inline comments in should_print
sbstndb Oct 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 3 additions & 2 deletions demos/FiniteVolume/AMR_Burgers_Hat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <samurai/field.hpp>
#include <samurai/io/hdf5.hpp>
#include <samurai/io/restart.hpp>
#include <samurai/print.hpp>
#include <samurai/samurai.hpp>

#include "stencil_field.hpp"
Expand Down Expand Up @@ -269,7 +270,7 @@ int main(int argc, char* argv[])
std::size_t ite_adapt = 0;
while (true)
{
std::cout << "\tmesh adaptation: " << ite_adapt++ << std::endl;
samurai::io::print("mesh adaptation: {}\n", ite_adapt++);
samurai::update_ghost(phi);
tag.resize();
AMR_criteria(phi, tag);
Expand All @@ -287,7 +288,7 @@ int main(int argc, char* argv[])
t = Tf;
}

std::cout << fmt::format("iteration {}: t = {}, dt = {}", nt++, t, dt) << std::endl;
samurai::io::print(samurai::io::root, "iteration {}: t = {}, dt = {}\n", nt++, t, dt);

// Numerical scheme
samurai::update_ghost(phi);
Expand Down
9 changes: 5 additions & 4 deletions demos/FiniteVolume/BZ/bz_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <samurai/io/hdf5.hpp>
#include <samurai/mr/adapt.hpp>
#include <samurai/mr/mesh.hpp>
#include <samurai/print.hpp>
#include <samurai/stencil_field.hpp>

#include "../../LBM/boundary_conditions.hpp"
Expand Down Expand Up @@ -313,7 +314,7 @@ int main()

while (t < Tf)
{
fmt::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)
{
Expand All @@ -323,20 +324,20 @@ 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)
*/
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)
{
Expand Down
9 changes: 5 additions & 4 deletions demos/FiniteVolume/BZ/bz_2d_AMR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <samurai/mr/operators.hpp>
#include <samurai/numeric/prediction.hpp>
#include <samurai/numeric/projection.hpp>
#include <samurai/print.hpp>
#include <samurai/static_algorithm.hpp>
#include <samurai/stencil_field.hpp>

Expand Down Expand Up @@ -691,7 +692,7 @@ int main()

while (t < Tf)
{
fmt::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;

Expand All @@ -710,20 +711,20 @@ 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)
*/
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)
{
Expand Down
2 changes: 1 addition & 1 deletion demos/FiniteVolume/advection_1d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ int main(int argc, char* argv[])
t = Tf;
}

std::cout << fmt::format("iteration {}: t = {}, dt = {}", nt++, t, dt) << std::endl;
samurai::io::print(samurai::io::root, "iteration {}: t = {}, dt = {}\n", nt++, t, dt);

samurai::update_ghost_mr(u);
unp1.resize();
Expand Down
2 changes: 1 addition & 1 deletion demos/FiniteVolume/advection_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ int main(int argc, char* argv[])
t = Tf;
}

std::cout << fmt::format("iteration {}: t = {}, dt = {}", nt++, t, dt) << std::endl;
samurai::io::print(samurai::io::root, "iteration {}: t = {}, dt = {}\n", nt++, t, dt);

samurai::update_ghost_mr(u);
unp1.resize();
Expand Down
2 changes: 1 addition & 1 deletion demos/FiniteVolume/advection_2d_user_bc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ int main(int argc, char* argv[])
t = Tf;
}

std::cout << fmt::format("iteration {}: t = {}, dt = {}", nt++, t, dt) << std::endl;
samurai::io::print(samurai::io::root, "iteration {}: t = {}, dt = {}\n", nt++, t, dt);

samurai::update_ghost_mr(u);
unp1.resize();
Expand Down
19 changes: 9 additions & 10 deletions demos/FiniteVolume/burgers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ int main_dim(int argc, char* argv[])
using Box = samurai::Box<double, dim>;
using point_t = typename Box::point_t;

std::cout << "------------------------- Burgers -------------------------" << std::endl;
samurai::io::print("------------------------- Burgers -------------------------\n");

//--------------------//
// Program parameters //
Expand Down Expand Up @@ -177,7 +177,7 @@ int main_dim(int argc, char* argv[])
}
else
{
std::cerr << "Unmanaged initial solution '" << init_sol << "'.";
samurai::io::eprint("Unmanaged initial solution '{}' .\n", init_sol);
return EXIT_FAILURE;
}
}
Expand Down Expand Up @@ -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;
samurai::io::print(samurai::io::root, "{}", fmt::format("iteration {}: t = {:.2f}, dt = {}", nt++, t, dt));

// Mesh adaptation
MRadaptation(mra_config);
Expand Down Expand Up @@ -287,7 +287,7 @@ int main_dim(int argc, char* argv[])
{
return exact_solution<n_comp>(coord, t);
});
std::cout << ", L2-error: " << std::scientific << std::setprecision(2) << error;
samurai::io::print(", L2-error: {:.2e}", error);

if (mesh.min_level() != mesh.max_level())
{
Expand All @@ -298,19 +298,18 @@ int main_dim(int argc, char* argv[])
{
return exact_solution<n_comp>(coord, t);
});
std::cout << ", L2-error (recons): " << std::scientific << std::setprecision(2) << error;
samurai::io::print(", L2-error (recons): {:.2e}", error);
}
}

std::cout << std::endl;
samurai::io::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 <<path to samurai>>/python/read_mesh.py " << filename << "_ite_ --field u level --start 0 --end " << nsave
<< std::endl;
samurai::io::print("\n");
samurai::io::print("Run the following command to view the results:\n");
samurai::io::print("python <<path to samurai>>/python/read_mesh.py {}_ite_ --field u level --start 0 --end {}\n", filename, nsave);
}

samurai::finalize();
Expand Down
29 changes: 14 additions & 15 deletions demos/FiniteVolume/burgers_mra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
samurai::io::print("\nmax-level-flux enabled: {}\n", scheme.enable_max_level_flux());

if (scheme.enable_max_level_flux())
{
Expand Down Expand Up @@ -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);
Expand All @@ -179,23 +179,22 @@ 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,
[&](const auto& coord)
{
return hat_exact_solution(coord[0], t);
});
std::cout << "[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);
});
std::cout << ", [w.r.t. exact, recons] " << error;
samurai::io::print(", [w.r.t. exact, recons] {}", error);
}

double error = 0;
Expand All @@ -206,7 +205,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;
samurai::io::print(", [w.r.t. max level, recons] {}", error);

// Save the result
if (t >= static_cast<double>(nsave) * dt_save || t == Tf)
Expand All @@ -219,7 +218,7 @@ void run_simulation(Field& u,
nsave++;
}

std::cout << std::endl;
samurai::io::print("\n");
}
}

Expand All @@ -231,7 +230,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;
samurai::io::print("------------------------- Burgers -------------------------\n");

//--------------------//
// Program parameters //
Expand Down Expand Up @@ -301,12 +300,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;
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;
Expand Down
27 changes: 14 additions & 13 deletions demos/FiniteVolume/burgers_os.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace fs = std::filesystem;

#include <numbers>
#include <xtensor/xio.hpp>

#include "convection_nonlin_os.hpp"

Expand Down Expand Up @@ -51,7 +52,7 @@ void check_diff(auto& field, auto& lca_left, auto& lca_right)
set(
[&](auto& i, auto)
{
std::cout << "Difference found !! " << level << " " << i << "\n";
samurai::io::print("Difference found !! {} {}\n", level, i);
auto level_ = samurai::make_scalar_field<std::size_t>("level", mesh);
samurai::for_each_cell(mesh,
[&](const auto& cell)
Expand All @@ -67,11 +68,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))
{
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;
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<std::size_t>("level", mesh);
samurai::for_each_cell(mesh,
[&](const auto& cell)
Expand All @@ -94,7 +95,7 @@ int main(int argc, char* argv[])
using Box = samurai::Box<double, dim>;
using point_t = typename Box::point_t;

std::cout << "------------------------- Burgers 1D -------------------------" << std::endl;
samurai::io::print("------------------------- Burgers 1D -------------------------\n");

//--------------------//
// Program parameters //
Expand Down Expand Up @@ -134,7 +135,7 @@ int main(int argc, char* argv[])

SAMURAI_PARSE(argc, argv);

std::cout << " max_level = " << max_level << " min_level = " << min_level << std::endl;
samurai::io::print(" max_level = {} min_level = {}\n", max_level, min_level);

//--------------------//
// Problem definition //
Expand Down Expand Up @@ -199,7 +200,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;
samurai::io::print(samurai::io::root, "{}", fmt::format("iteration {}: t = {:.12f}, dt = {}", nt++, t, dt));

// Mesh adaptation
MRadaptation(mra_config);
Expand All @@ -210,7 +211,7 @@ int main(int argc, char* argv[])
}
catch (...)
{
std::cout << "Exception caught in check_diff after adaptation" << std::endl;
samurai::io::print("Exception caught in check_diff after adaptation\n");
samurai::finalize();
return 1;
}
Expand All @@ -228,21 +229,21 @@ int main(int argc, char* argv[])
}
catch (...)
{
std::cout << "Exception caught in check_diff after integration" << std::endl;
samurai::io::print("Exception caught in check_diff after integration\n");
samurai::finalize();
return 1;
}

// Save the result
if (nfiles == 0 || t >= static_cast<double>(nsave) * dt_save || t == Tf)
{
std::cout << " (saving results)" << std::flush;
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++;
}

std::cout << std::endl;
samurai::io::print("\n");
}

samurai::finalize();
Expand Down
Loading
Loading