Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
eb42a86
feat: use fmt
sbstndb Sep 11, 2025
c35f256
feat: use fmt in demos
sbstndb Sep 11, 2025
2cb6e83
feat: improve printing
sbstndb Sep 11, 2025
6537d4b
feat: use samurai::io::print everywhere
sbstndb Sep 11, 2025
f80d9c5
feat: remove dont redirect output
sbstndb Sep 11, 2025
361ccfd
fix: resolve issue on flag
sbstndb Sep 11, 2025
d27376a
feat: use samurai wrapper print for demos
sbstndb Sep 11, 2025
99f411b
ci: precommit
sbstndb Sep 11, 2025
c4ad909
fix: typo
sbstndb Sep 11, 2025
54c1c5c
fix: typo
sbstndb Sep 11, 2025
74a3a9e
fix: resolve compilation issue
sbstndb Sep 11, 2025
6521512
ci: precommit
sbstndb Sep 11, 2025
08cf380
io(print): add <cstdio>/<utility>; guard MPI rank with MPI_Initialize…
sbstndb Oct 3, 2025
790f68a
style(print): apply clang-format after pre-commit
sbstndb Oct 3, 2025
3cc1efe
chore(repo): remove editor swap files and ignore them (*.swp, *.swo, …
sbstndb Oct 3, 2025
27c79ff
revert: keep std::cerr unchanged; convert only std::cout. Revert unin…
sbstndb Oct 3, 2025
dd43730
revert: keep std::cerr; remove unintended print.hpp/fmt includes in e…
sbstndb Oct 3, 2025
283f878
Revert "revert: keep std::cerr; remove unintended print.hpp/fmt inclu…
sbstndb Oct 3, 2025
4dbd0ad
Revert "revert: keep std::cerr unchanged; convert only std::cout. Rev…
sbstndb Oct 3, 2025
b902b20
io: convert std::cout to samurai::io::print (root where appropriate);…
sbstndb Oct 3, 2025
f265882
style: clang-format includes and wrapping
sbstndb Oct 3, 2025
289033b
io: convert std::cerr/std::cout to samurai::io::eprint/print across i…
sbstndb Oct 3, 2025
ad6283a
style: apply clang-format
sbstndb Oct 3, 2025
7448a44
refactor: rely on print.hpp to provide fmt; remove redundant <fmt/...…
sbstndb Oct 3, 2025
6dbe6f3
style: clang-format after header include cleanup
sbstndb Oct 3, 2025
0d1d3d1
demos: port top offenders to samurai::io::print/eprint (MPI-safe): LB…
sbstndb Oct 3, 2025
68e4c7c
style: apply clang-format in demos after IO port
sbstndb Oct 3, 2025
76f543f
io: port remaining demos to samurai::io::print/eprint; add <samurai/p…
sbstndb Oct 3, 2025
e7bd8cc
docs: replace std::cout in snippets and RST examples with samurai::io…
sbstndb Oct 3, 2025
3ae7f91
fix: add <samurai/print.hpp> in BZ demos; include <xtensor/xio.hpp> w…
sbstndb Oct 3, 2025
abccc72
fix(fmt+xtensor): avoid printing xtensor indices inside field.hpp err…
sbstndb Oct 3, 2025
576832d
fmt(streamed): restore index printing in field.hpp using fmt::streame…
sbstndb Oct 3, 2025
6c2c07a
fix: remove stray '<< std::endl' after eprint in PETSc linear_solver.…
sbstndb Oct 3, 2025
5021777
docs/comments: replace commented std::cout examples with samurai::io:…
sbstndb Oct 3, 2025
7c3ca0d
chore(comments): convert remaining commented std::cout/cerr to samura…
sbstndb Oct 3, 2025
8438961
io(print): avoid constant condition in non-MPI builds; guard should_p…
sbstndb Oct 3, 2025
0be3925
io(print): remove inline comments in should_print
sbstndb Oct 3, 2025
4c9588d
fix: update xtensor include path in burgers_os.cpp
sbstndb Dec 23, 2025
3cc36a9
fix: reorder xtensor includes in field.hpp
sbstndb Dec 23, 2025
81dba1b
Update boundary condition handling
sbstndb Jan 5, 2026
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 @@ -263,7 +264,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 @@ -281,7 +282,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 @@ -140,7 +140,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 @@ -133,7 +133,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 @@ -165,7 +165,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 @@ -55,7 +55,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 @@ -176,7 +176,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 @@ -244,7 +244,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 @@ -286,7 +286,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 @@ -297,19 +297,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 @@ -230,7 +229,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 @@ -296,12 +295,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: 15 additions & 12 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/io/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 @@ -132,6 +133,8 @@ int main(int argc, char* argv[])

SAMURAI_PARSE(argc, argv);

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

//--------------------//
// Problem definition //
//--------------------//
Expand Down Expand Up @@ -200,7 +203,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 @@ -211,7 +214,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 @@ -229,21 +232,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