From dd595c0f3b0b3fe7b23098a76ac582b945bc41b6 Mon Sep 17 00:00:00 2001 From: James McClung Date: Thu, 3 Apr 2025 11:15:05 -0400 Subject: [PATCH 01/16] checks->checks_params; *: rename file --- src/include/{checks.hxx => checks_params.hxx} | 0 src/include/psc.hxx | 2 +- src/libpsc/integrate.cxx | 2 +- src/libpsc/psc_checks/checks_impl.hxx | 2 +- 4 files changed, 3 insertions(+), 3 deletions(-) rename src/include/{checks.hxx => checks_params.hxx} (100%) diff --git a/src/include/checks.hxx b/src/include/checks_params.hxx similarity index 100% rename from src/include/checks.hxx rename to src/include/checks_params.hxx diff --git a/src/include/psc.hxx b/src/include/psc.hxx index 4a25af1eb8..32fbfec941 100644 --- a/src/include/psc.hxx +++ b/src/include/psc.hxx @@ -8,7 +8,7 @@ #include #include "../libpsc/vpic/fields_item_vpic.hxx" -#include +#include #include #include diff --git a/src/libpsc/integrate.cxx b/src/libpsc/integrate.cxx index 2a279638f9..6f67ba3b91 100644 --- a/src/libpsc/integrate.cxx +++ b/src/libpsc/integrate.cxx @@ -6,7 +6,7 @@ #include "sort.hxx" #include "collision.hxx" #include "bnd_particles.hxx" -#include "checks.hxx" +#include "checks_params.hxx" #include #include diff --git a/src/libpsc/psc_checks/checks_impl.hxx b/src/libpsc/psc_checks/checks_impl.hxx index c513712909..70f2615ca9 100644 --- a/src/libpsc/psc_checks/checks_impl.hxx +++ b/src/libpsc/psc_checks/checks_impl.hxx @@ -3,7 +3,7 @@ #include "fields.hxx" #include "fields_item.hxx" -#include "checks.hxx" +#include "checks_params.hxx" #include "../libpsc/psc_output_fields/fields_item_fields.hxx" #include "../libpsc/psc_output_fields/fields_item_moments_1st.hxx" #include From 3ef56590e40240e9fec5003a1a0942bacff52e5d Mon Sep 17 00:00:00 2001 From: James McClung Date: Thu, 3 Apr 2025 11:23:42 -0400 Subject: [PATCH 02/16] checks_params: extract CheckParams this breaks things --- src/include/checks_params.hxx | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/include/checks_params.hxx b/src/include/checks_params.hxx index 50185dc47a..49dd6ea6e2 100644 --- a/src/include/checks_params.hxx +++ b/src/include/checks_params.hxx @@ -1,19 +1,22 @@ #pragma once -struct ChecksParams +struct CheckParams { - int continuity_every_step = - 0; // check charge continuity eqn every so many steps - double continuity_threshold = 1e-13; // acceptable error in continuity eqn - bool continuity_verbose = - true; // always print continuity error, even if acceptable - bool continuity_dump_always = - false; // always dump d_rho, div_j, even if acceptable - - int gauss_every_step = 0; // check Gauss's Law every so many steps - double gauss_threshold = 1e-13; // acceptable error in Gauss's Law - bool gauss_verbose = - true; // always print Gauss's Law error, even if acceptable - bool gauss_dump_always = false; // always dump E, div_rho, even if acceptable + int every_step = 0; // number of steps per check + double threshold = 1e-13; // maximum acceptable error + bool verbose = true; // always print error, even if acceptable + bool dump_always = false; // always dump compared fields, even if acceptable }; + +struct ContinuityCheckParams : CheckParams +{}; + +struct GaussCheckParams : CheckParams +{}; + +struct ChecksParams +{ + ContinuityCheckParams continuity; + GaussCheckParams gauss; +}; \ No newline at end of file From 4bf906a15244d92d2eb464377b31b4328eb7a541 Mon Sep 17 00:00:00 2001 From: James McClung Date: Thu, 3 Apr 2025 11:28:24 -0400 Subject: [PATCH 03/16] *: fix to match new ChecksParams --- src/include/psc.hxx | 12 ++++---- src/libpsc/psc_checks/checks_impl.hxx | 34 +++++++++++----------- src/libpsc/tests/test_push_particles_2.cxx | 12 ++++---- src/psc_2d_shock.cxx | 16 +++++----- src/psc_bgk.cxx | 6 ++-- src/psc_flatfoil_yz.cxx | 24 +++++++-------- src/psc_harris_yz.cxx | 18 ++++++------ src/psc_shock.cxx | 6 ++-- src/psc_whistler.cxx | 6 ++-- 9 files changed, 67 insertions(+), 67 deletions(-) diff --git a/src/include/psc.hxx b/src/include/psc.hxx index 32fbfec941..a546ac1908 100644 --- a/src/include/psc.hxx +++ b/src/include/psc.hxx @@ -489,8 +489,8 @@ struct Psc inject_particles(); prof_stop(pr_inject_prts); - if (checks_.continuity_every_step > 0 && - timestep % checks_.continuity_every_step == 0) { + if (checks_.continuity.every_step > 0 && + timestep % checks_.continuity.every_step == 0) { mpi_printf(comm, "***** Checking continuity...\n"); prof_start(pr_checks); checks_.continuity_before_particle_push(mprts_); @@ -558,8 +558,8 @@ struct Psc // state is now: x^{n+3/2}, p^{n+1}, E^{n+3/2}, B^{n+3/2} #endif - if (checks_.continuity_every_step > 0 && - timestep % checks_.continuity_every_step == 0) { + if (checks_.continuity.every_step > 0 && + timestep % checks_.continuity.every_step == 0) { prof_restart(pr_checks); checks_.continuity_after_particle_push(mprts_, mflds_); prof_stop(pr_checks); @@ -575,8 +575,8 @@ struct Psc prof_stop(pr_marder); } - if (checks_.gauss_every_step > 0 && - timestep % checks_.gauss_every_step == 0) { + if (checks_.gauss.every_step > 0 && + timestep % checks_.gauss.every_step == 0) { prof_restart(pr_checks); checks_.gauss(mprts_, mflds_); prof_stop(pr_checks); diff --git a/src/libpsc/psc_checks/checks_impl.hxx b/src/libpsc/psc_checks/checks_impl.hxx index 70f2615ca9..4baf92298b 100644 --- a/src/libpsc/psc_checks/checks_impl.hxx +++ b/src/libpsc/psc_checks/checks_impl.hxx @@ -47,8 +47,8 @@ public: void before_particle_push(const Mparticles& mprts) { const auto& grid = mprts.grid(); - if (continuity_every_step <= 0 || - grid.timestep() % continuity_every_step != 0) { + if (continuity.every_step <= 0 || + grid.timestep() % continuity.every_step != 0) { return; } @@ -63,8 +63,8 @@ public: void after_particle_push(const Mparticles& mprts, MfieldsState& mflds) { const Grid_t& grid = mprts.grid(); - if (continuity_every_step <= 0 || - grid.timestep() % continuity_every_step != 0) { + if (continuity.every_step <= 0 || + grid.timestep() % continuity.every_step != 0) { return; } @@ -81,16 +81,16 @@ public: double max_err; MPI_Allreduce(&local_err, &max_err, 1, MPI_DOUBLE, MPI_MAX, grid.comm()); - if (max_err >= continuity_threshold) { - psc::helper::print_diff(d_rho, -dt_divj, continuity_threshold); + if (max_err >= continuity.threshold) { + psc::helper::print_diff(d_rho, -dt_divj, continuity.threshold); } - if (continuity_verbose || max_err >= continuity_threshold) { + if (continuity.verbose || max_err >= continuity.threshold) { mpi_printf(grid.comm(), "continuity: max_err = %g (thres %g)\n", max_err, - continuity_threshold); + continuity.threshold); } - if (continuity_dump_always || max_err >= continuity_threshold) { + if (continuity.dump_always || max_err >= continuity.threshold) { if (!writer_) { writer_.open("continuity"); } @@ -101,7 +101,7 @@ public: MPI_Barrier(grid.comm()); } - assert(max_err < continuity_threshold); + assert(max_err < continuity.threshold); } private: @@ -128,7 +128,7 @@ public: void operator()(Mparticles& mprts, MfieldsState& mflds) { const auto& grid = mprts.grid(); - if (gauss_every_step <= 0 || grid.timestep() % gauss_every_step != 0) { + if (gauss.every_step <= 0 || grid.timestep() % gauss.every_step != 0) { return; } @@ -155,8 +155,8 @@ public: double patch_err = gt::norm_linf(patch_dive - patch_rho); max_err = std::max(max_err, patch_err); - if (patch_err > gauss_threshold) { - psc::helper::print_diff(patch_rho, patch_dive, gauss_threshold); + if (patch_err > gauss.threshold) { + psc::helper::print_diff(patch_rho, patch_dive, gauss.threshold); } } @@ -164,12 +164,12 @@ public: double tmp = max_err; MPI_Allreduce(&tmp, &max_err, 1, MPI_DOUBLE, MPI_MAX, grid.comm()); - if (gauss_verbose || max_err >= gauss_threshold) { + if (gauss.verbose || max_err >= gauss.threshold) { mpi_printf(grid.comm(), "gauss: max_err = %g (thres %g)\n", max_err, - gauss_threshold); + gauss.threshold); } - if (gauss_dump_always || max_err >= gauss_threshold) { + if (gauss.dump_always || max_err >= gauss.threshold) { if (!writer_) { writer_.open("gauss"); } @@ -179,7 +179,7 @@ public: writer_.end_step(); } - assert(max_err < gauss_threshold); + assert(max_err < gauss.threshold); } private: diff --git a/src/libpsc/tests/test_push_particles_2.cxx b/src/libpsc/tests/test_push_particles_2.cxx index 7dd682d250..eee654a807 100644 --- a/src/libpsc/tests/test_push_particles_2.cxx +++ b/src/libpsc/tests/test_push_particles_2.cxx @@ -71,9 +71,9 @@ TYPED_TEST(PushParticlesTest, Accel) BndParticles bndp_{grid}; Bnd bnd_{}; ChecksParams checks_params{}; - checks_params.continuity_every_step = 1; - checks_params.continuity_threshold = 1e-7; - checks_params.continuity_verbose = false; + checks_params.continuity.every_step = 1; + checks_params.continuity.threshold = 1e-7; + checks_params.continuity.verbose = false; Checks checks_{grid, MPI_COMM_WORLD, checks_params}; for (int n = 0; n < n_steps; n++) { checks_.continuity_before_particle_push(mprts); @@ -149,9 +149,9 @@ TYPED_TEST(PushParticlesTest, Cyclo) BndParticles bndp_{grid}; Bnd bnd_{}; ChecksParams checks_params{}; - checks_params.continuity_every_step = 1; - checks_params.continuity_threshold = 1e-7; - checks_params.continuity_verbose = false; + checks_params.continuity.every_step = 1; + checks_params.continuity.threshold = 1e-7; + checks_params.continuity.verbose = false; Checks checks_{grid, MPI_COMM_WORLD, checks_params}; for (int n = 0; n < n_steps; n++) { checks_.continuity_before_particle_push(mprts); diff --git a/src/psc_2d_shock.cxx b/src/psc_2d_shock.cxx index 443697208c..5ce91df18d 100644 --- a/src/psc_2d_shock.cxx +++ b/src/psc_2d_shock.cxx @@ -439,14 +439,14 @@ void run() // -- Checks ChecksParams checks_params{}; - checks_params.continuity_every_step = 100; - checks_params.continuity_threshold = 1e-4; - checks_params.continuity_verbose = true; - checks_params.continuity_dump_always = false; - checks_params.gauss_every_step = 100; - checks_params.gauss_threshold = 1e-4; - checks_params.gauss_verbose = true; - checks_params.gauss_dump_always = false; + checks_params.continuity.every_step = 100; + checks_params.continuity.threshold = 1e-4; + checks_params.continuity.verbose = true; + checks_params.continuity.dump_always = false; + checks_params.gauss.every_step = 100; + checks_params.gauss.threshold = 1e-4; + checks_params.gauss.verbose = true; + checks_params.gauss.dump_always = false; Checks checks{grid, MPI_COMM_WORLD, checks_params}; // -- Marder correction diff --git a/src/psc_bgk.cxx b/src/psc_bgk.cxx index 208aedbdb9..87a68224b8 100644 --- a/src/psc_bgk.cxx +++ b/src/psc_bgk.cxx @@ -510,9 +510,9 @@ static void run(int argc, char** argv) // -- Checks ChecksParams checks_params{}; - checks_params.gauss_every_step = g.gauss_every; - // checks_params.gauss_dump_always = true; - checks_params.gauss_threshold = 1e-5; + checks_params.gauss.every_step = g.gauss_every; + // checks_params.gauss.dump_always = true; + checks_params.gauss.threshold = 1e-5; Checks checks{grid, MPI_COMM_WORLD, checks_params}; diff --git a/src/psc_flatfoil_yz.cxx b/src/psc_flatfoil_yz.cxx index 342e520100..ca8856025c 100644 --- a/src/psc_flatfoil_yz.cxx +++ b/src/psc_flatfoil_yz.cxx @@ -478,24 +478,24 @@ void run() // -- Checks ChecksParams checks_params{}; #if CASE == CASE_2D_SMALL - checks_params.continuity_every_step = 1; - checks_params.continuity_dump_always = true; + checks_params.continuity.every_step = 1; + checks_params.continuity.dump_always = true; #else - checks_params.continuity_every_step = 0; - checks_params.continuity_dump_always = false; + checks_params.continuity.every_step = 0; + checks_params.continuity.dump_always = false; #endif - checks_params.continuity_threshold = 1e-4; - checks_params.continuity_verbose = true; + checks_params.continuity.threshold = 1e-4; + checks_params.continuity.verbose = true; #if CASE == CASE_2D_SMALL - checks_params.gauss_every_step = 1; - checks_params.gauss_dump_always = true; + checks_params.gauss.every_step = 1; + checks_params.gauss.dump_always = true; #else - checks_params.gauss_every_step = 100; - checks_params.gauss_dump_always = false; + checks_params.gauss.every_step = 100; + checks_params.gauss.dump_always = false; #endif - checks_params.gauss_threshold = 1e-4; - checks_params.gauss_verbose = true; + checks_params.gauss.threshold = 1e-4; + checks_params.gauss.verbose = true; Checks checks{grid, MPI_COMM_WORLD, checks_params}; diff --git a/src/psc_harris_yz.cxx b/src/psc_harris_yz.cxx index 669c83d9a2..7a78fdc6cc 100644 --- a/src/psc_harris_yz.cxx +++ b/src/psc_harris_yz.cxx @@ -385,15 +385,15 @@ void run() // -- Checks ChecksParams checks_params{}; - checks_params.continuity_every_step = 0; - checks_params.continuity_dump_always = false; - checks_params.continuity_threshold = 1e-4; - checks_params.continuity_verbose = true; - - checks_params.gauss_every_step = -100; - checks_params.gauss_dump_always = false; - checks_params.gauss_threshold = 1e-4; - checks_params.gauss_verbose = true; + checks_params.continuity.every_step = 0; + checks_params.continuity.dump_always = false; + checks_params.continuity.threshold = 1e-4; + checks_params.continuity.verbose = true; + + checks_params.gauss.every_step = -100; + checks_params.gauss.dump_always = false; + checks_params.gauss.threshold = 1e-4; + checks_params.gauss.verbose = true; Checks checks{grid, MPI_COMM_WORLD, checks_params}; diff --git a/src/psc_shock.cxx b/src/psc_shock.cxx index d90053dade..b730d8cb45 100644 --- a/src/psc_shock.cxx +++ b/src/psc_shock.cxx @@ -278,9 +278,9 @@ static void run(int argc, char** argv) // -- Checks ChecksParams checks_params{}; - checks_params.gauss_every_step = out_interval; - // checks_params.gauss_dump_always = true; - checks_params.gauss_threshold = 1e-5; + checks_params.gauss.every_step = out_interval; + // checks_params.gauss.dump_always = true; + checks_params.gauss.threshold = 1e-5; Checks checks{grid, MPI_COMM_WORLD, checks_params}; diff --git a/src/psc_whistler.cxx b/src/psc_whistler.cxx index 04a5500009..a52346040d 100644 --- a/src/psc_whistler.cxx +++ b/src/psc_whistler.cxx @@ -292,9 +292,9 @@ void run() // -- Checks ChecksParams checks_params{}; - checks_params.continuity_every_step = 50; - checks_params.continuity_threshold = 1e-5; - checks_params.continuity_verbose = false; + checks_params.continuity.every_step = 50; + checks_params.continuity.threshold = 1e-5; + checks_params.continuity.verbose = false; Checks checks{grid, MPI_COMM_WORLD, checks_params}; // -- Marder correction From 4d4912e6fde083fa52a6cb6a88adfc0f222bb271 Mon Sep 17 00:00:00 2001 From: James McClung Date: Thu, 3 Apr 2025 11:38:39 -0400 Subject: [PATCH 04/16] checks_impl; psc: inheritance->composition, more fixes --- src/include/psc.hxx | 12 +++---- src/libpsc/psc_checks/checks_impl.hxx | 49 ++++++++++++++------------- 2 files changed, 32 insertions(+), 29 deletions(-) diff --git a/src/include/psc.hxx b/src/include/psc.hxx index a546ac1908..1b4ced1789 100644 --- a/src/include/psc.hxx +++ b/src/include/psc.hxx @@ -489,8 +489,8 @@ struct Psc inject_particles(); prof_stop(pr_inject_prts); - if (checks_.continuity.every_step > 0 && - timestep % checks_.continuity.every_step == 0) { + if (checks_.params.continuity.every_step > 0 && + timestep % checks_.params.continuity.every_step == 0) { mpi_printf(comm, "***** Checking continuity...\n"); prof_start(pr_checks); checks_.continuity_before_particle_push(mprts_); @@ -558,8 +558,8 @@ struct Psc // state is now: x^{n+3/2}, p^{n+1}, E^{n+3/2}, B^{n+3/2} #endif - if (checks_.continuity.every_step > 0 && - timestep % checks_.continuity.every_step == 0) { + if (checks_.params.continuity.every_step > 0 && + timestep % checks_.params.continuity.every_step == 0) { prof_restart(pr_checks); checks_.continuity_after_particle_push(mprts_, mflds_); prof_stop(pr_checks); @@ -575,8 +575,8 @@ struct Psc prof_stop(pr_marder); } - if (checks_.gauss.every_step > 0 && - timestep % checks_.gauss.every_step == 0) { + if (checks_.params.gauss.every_step > 0 && + timestep % checks_.params.gauss.every_step == 0) { prof_restart(pr_checks); checks_.gauss(mprts_, mflds_); prof_stop(pr_checks); diff --git a/src/libpsc/psc_checks/checks_impl.hxx b/src/libpsc/psc_checks/checks_impl.hxx index 4baf92298b..cfd99c122d 100644 --- a/src/libpsc/psc_checks/checks_impl.hxx +++ b/src/libpsc/psc_checks/checks_impl.hxx @@ -32,13 +32,13 @@ namespace checks // psc::checks::continuity: Charge Continuity template -class continuity : ChecksParams +class continuity { public: using storage_type = S; using Item_rho = ITEM_RHO; - continuity(const ChecksParams& params) : ChecksParams(params) {} + continuity(const ContinuityCheckParams& params) : params_(params) {} // ---------------------------------------------------------------------- // before_particle_push @@ -47,8 +47,7 @@ public: void before_particle_push(const Mparticles& mprts) { const auto& grid = mprts.grid(); - if (continuity.every_step <= 0 || - grid.timestep() % continuity.every_step != 0) { + if (params_.every_step <= 0 || grid.timestep() % params_.every_step != 0) { return; } @@ -63,8 +62,7 @@ public: void after_particle_push(const Mparticles& mprts, MfieldsState& mflds) { const Grid_t& grid = mprts.grid(); - if (continuity.every_step <= 0 || - grid.timestep() % continuity.every_step != 0) { + if (params_.every_step <= 0 || grid.timestep() % params_.every_step != 0) { return; } @@ -81,16 +79,16 @@ public: double max_err; MPI_Allreduce(&local_err, &max_err, 1, MPI_DOUBLE, MPI_MAX, grid.comm()); - if (max_err >= continuity.threshold) { - psc::helper::print_diff(d_rho, -dt_divj, continuity.threshold); + if (max_err >= params_.threshold) { + psc::helper::print_diff(d_rho, -dt_divj, params_.threshold); } - if (continuity.verbose || max_err >= continuity.threshold) { + if (params_.verbose || max_err >= params_.threshold) { mpi_printf(grid.comm(), "continuity: max_err = %g (thres %g)\n", max_err, - continuity.threshold); + params_.threshold); } - if (continuity.dump_always || max_err >= continuity.threshold) { + if (params_.dump_always || max_err >= params_.threshold) { if (!writer_) { writer_.open("continuity"); } @@ -101,25 +99,26 @@ public: MPI_Barrier(grid.comm()); } - assert(max_err < continuity.threshold); + assert(max_err < params_.threshold); } private: storage_type rho_m_; WriterDefault writer_; + ContinuityCheckParams params_; }; // ====================================================================== // psc::checks::gauss: Gauss's Law div E = rho template -class gauss : ChecksParams +class gauss { public: using storage_type = S; using Item_rho = ITEM_RHO; - gauss(const ChecksParams& params) : ChecksParams(params) {} + gauss(const GaussCheckParams params) : params_(params) {} // ---------------------------------------------------------------------- // operator() @@ -128,7 +127,7 @@ public: void operator()(Mparticles& mprts, MfieldsState& mflds) { const auto& grid = mprts.grid(); - if (gauss.every_step <= 0 || grid.timestep() % gauss.every_step != 0) { + if (params_.every_step <= 0 || grid.timestep() % params_.every_step != 0) { return; } @@ -155,8 +154,8 @@ public: double patch_err = gt::norm_linf(patch_dive - patch_rho); max_err = std::max(max_err, patch_err); - if (patch_err > gauss.threshold) { - psc::helper::print_diff(patch_rho, patch_dive, gauss.threshold); + if (patch_err > params_.threshold) { + psc::helper::print_diff(patch_rho, patch_dive, params_.threshold); } } @@ -164,12 +163,12 @@ public: double tmp = max_err; MPI_Allreduce(&tmp, &max_err, 1, MPI_DOUBLE, MPI_MAX, grid.comm()); - if (gauss.verbose || max_err >= gauss.threshold) { + if (params_.verbose || max_err >= params_.threshold) { mpi_printf(grid.comm(), "gauss: max_err = %g (thres %g)\n", max_err, - gauss.threshold); + params_.threshold); } - if (gauss.dump_always || max_err >= gauss.threshold) { + if (params_.dump_always || max_err >= params_.threshold) { if (!writer_) { writer_.open("gauss"); } @@ -179,11 +178,12 @@ public: writer_.end_step(); } - assert(max_err < gauss.threshold); + assert(max_err < params_.threshold); } private: WriterDefault writer_; + GaussCheckParams params_; }; } // namespace checks @@ -202,7 +202,7 @@ struct checks_order_2nd }; template -class ChecksCommon : public ChecksParams +class ChecksCommon { public: using Mparticles = MP; @@ -210,7 +210,7 @@ public: using item_rho_type = ITEM_RHO; ChecksCommon(const Grid_t& grid, MPI_Comm comm, const ChecksParams& params) - : ChecksParams{params}, continuity_{params}, gauss_{params} + : params(params), continuity_{params.continuity}, gauss_{params.gauss} {} void continuity_before_particle_push(Mparticles& mprts) @@ -230,6 +230,9 @@ public: gauss_(mprts, mflds); } +public: + ChecksParams params; + private: psc::checks::continuity continuity_; psc::checks::gauss gauss_; From c940b6c5e2bd748f2700fe12e2e15b4a6a031cf6 Mon Sep 17 00:00:00 2001 From: James McClung Date: Thu, 3 Apr 2025 11:44:19 -0400 Subject: [PATCH 05/16] checks_params: +do_check() --- src/include/checks_params.hxx | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/include/checks_params.hxx b/src/include/checks_params.hxx index 49dd6ea6e2..a0f2a9f6b3 100644 --- a/src/include/checks_params.hxx +++ b/src/include/checks_params.hxx @@ -7,6 +7,13 @@ struct CheckParams double threshold = 1e-13; // maximum acceptable error bool verbose = true; // always print error, even if acceptable bool dump_always = false; // always dump compared fields, even if acceptable + + bool enabled() { return every_step > 0; } + + bool do_check(int timestep) + { + return enabled() && timestep % every_step == 0; + } }; struct ContinuityCheckParams : CheckParams From 261c573467644cc4d9b65450031f9112cc68ad09 Mon Sep 17 00:00:00 2001 From: James McClung Date: Thu, 3 Apr 2025 11:48:26 -0400 Subject: [PATCH 06/16] psc, checks_impl: use do_check() --- src/include/psc.hxx | 9 +++------ src/libpsc/psc_checks/checks_impl.hxx | 6 +++--- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/include/psc.hxx b/src/include/psc.hxx index 1b4ced1789..02b3483a1f 100644 --- a/src/include/psc.hxx +++ b/src/include/psc.hxx @@ -489,8 +489,7 @@ struct Psc inject_particles(); prof_stop(pr_inject_prts); - if (checks_.params.continuity.every_step > 0 && - timestep % checks_.params.continuity.every_step == 0) { + if (checks_.params.continuity.do_check(timestep)) { mpi_printf(comm, "***** Checking continuity...\n"); prof_start(pr_checks); checks_.continuity_before_particle_push(mprts_); @@ -558,8 +557,7 @@ struct Psc // state is now: x^{n+3/2}, p^{n+1}, E^{n+3/2}, B^{n+3/2} #endif - if (checks_.params.continuity.every_step > 0 && - timestep % checks_.params.continuity.every_step == 0) { + if (checks_.params.continuity.do_check(timestep)) { prof_restart(pr_checks); checks_.continuity_after_particle_push(mprts_, mflds_); prof_stop(pr_checks); @@ -575,8 +573,7 @@ struct Psc prof_stop(pr_marder); } - if (checks_.params.gauss.every_step > 0 && - timestep % checks_.params.gauss.every_step == 0) { + if (checks_.params.gauss.do_check(timestep)) { prof_restart(pr_checks); checks_.gauss(mprts_, mflds_); prof_stop(pr_checks); diff --git a/src/libpsc/psc_checks/checks_impl.hxx b/src/libpsc/psc_checks/checks_impl.hxx index cfd99c122d..910aece984 100644 --- a/src/libpsc/psc_checks/checks_impl.hxx +++ b/src/libpsc/psc_checks/checks_impl.hxx @@ -47,7 +47,7 @@ public: void before_particle_push(const Mparticles& mprts) { const auto& grid = mprts.grid(); - if (params_.every_step <= 0 || grid.timestep() % params_.every_step != 0) { + if (!params_.do_check(grid.timestep())) { return; } @@ -62,7 +62,7 @@ public: void after_particle_push(const Mparticles& mprts, MfieldsState& mflds) { const Grid_t& grid = mprts.grid(); - if (params_.every_step <= 0 || grid.timestep() % params_.every_step != 0) { + if (!params_.do_check(grid.timestep())) { return; } @@ -127,7 +127,7 @@ public: void operator()(Mparticles& mprts, MfieldsState& mflds) { const auto& grid = mprts.grid(); - if (params_.every_step <= 0 || grid.timestep() % params_.every_step != 0) { + if (!params_.do_check(grid.timestep())) { return; } From 8f01e16ac779ed56dd7605829a3de36e9a315262 Mon Sep 17 00:00:00 2001 From: James McClung Date: Thu, 3 Apr 2025 12:02:43 -0400 Subject: [PATCH 07/16] checks_params; impl: +more util funcs --- src/include/checks_params.hxx | 6 ++++++ src/libpsc/psc_checks/checks_impl.hxx | 12 ++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/include/checks_params.hxx b/src/include/checks_params.hxx index a0f2a9f6b3..7cd5f3f646 100644 --- a/src/include/checks_params.hxx +++ b/src/include/checks_params.hxx @@ -14,6 +14,12 @@ struct CheckParams { return enabled() && timestep % every_step == 0; } + + bool do_print_diffs(double err) { return err > threshold; } + + bool do_print_max(double max_err) { return verbose || max_err > threshold; } + + bool do_dump(double max_err) { return dump_always || max_err > threshold; } }; struct ContinuityCheckParams : CheckParams diff --git a/src/libpsc/psc_checks/checks_impl.hxx b/src/libpsc/psc_checks/checks_impl.hxx index 910aece984..e1f4f08a4c 100644 --- a/src/libpsc/psc_checks/checks_impl.hxx +++ b/src/libpsc/psc_checks/checks_impl.hxx @@ -79,16 +79,16 @@ public: double max_err; MPI_Allreduce(&local_err, &max_err, 1, MPI_DOUBLE, MPI_MAX, grid.comm()); - if (max_err >= params_.threshold) { + if (params_.do_print_diffs(max_err)) { psc::helper::print_diff(d_rho, -dt_divj, params_.threshold); } - if (params_.verbose || max_err >= params_.threshold) { + if (params_.do_print_max(max_err)) { mpi_printf(grid.comm(), "continuity: max_err = %g (thres %g)\n", max_err, params_.threshold); } - if (params_.dump_always || max_err >= params_.threshold) { + if (params_.do_dump(max_err)) { if (!writer_) { writer_.open("continuity"); } @@ -154,7 +154,7 @@ public: double patch_err = gt::norm_linf(patch_dive - patch_rho); max_err = std::max(max_err, patch_err); - if (patch_err > params_.threshold) { + if (params_.do_print_diffs(patch_err)) { psc::helper::print_diff(patch_rho, patch_dive, params_.threshold); } } @@ -163,12 +163,12 @@ public: double tmp = max_err; MPI_Allreduce(&tmp, &max_err, 1, MPI_DOUBLE, MPI_MAX, grid.comm()); - if (params_.verbose || max_err >= params_.threshold) { + if (params_.do_print_max(max_err)) { mpi_printf(grid.comm(), "gauss: max_err = %g (thres %g)\n", max_err, params_.threshold); } - if (params_.dump_always || max_err >= params_.threshold) { + if (params_.do_dump(max_err)) { if (!writer_) { writer_.open("gauss"); } From 5f60b5f9083e2bdcd4b55996307a56e2158da2b0 Mon Sep 17 00:00:00 2001 From: James McClung Date: Thu, 3 Apr 2025 12:05:25 -0400 Subject: [PATCH 08/16] checks_params; *: rename methods to should_ --- src/include/checks_params.hxx | 14 ++++++++++---- src/include/psc.hxx | 6 +++--- src/libpsc/psc_checks/checks_impl.hxx | 18 +++++++++--------- 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/include/checks_params.hxx b/src/include/checks_params.hxx index 7cd5f3f646..b24d36a695 100644 --- a/src/include/checks_params.hxx +++ b/src/include/checks_params.hxx @@ -10,16 +10,22 @@ struct CheckParams bool enabled() { return every_step > 0; } - bool do_check(int timestep) + bool should_do_check(int timestep) { return enabled() && timestep % every_step == 0; } - bool do_print_diffs(double err) { return err > threshold; } + bool should_print_diffs(double err) { return err > threshold; } - bool do_print_max(double max_err) { return verbose || max_err > threshold; } + bool should_print_max(double max_err) + { + return verbose || max_err > threshold; + } - bool do_dump(double max_err) { return dump_always || max_err > threshold; } + bool should_dump(double max_err) + { + return dump_always || max_err > threshold; + } }; struct ContinuityCheckParams : CheckParams diff --git a/src/include/psc.hxx b/src/include/psc.hxx index 02b3483a1f..bb8e8b874d 100644 --- a/src/include/psc.hxx +++ b/src/include/psc.hxx @@ -489,7 +489,7 @@ struct Psc inject_particles(); prof_stop(pr_inject_prts); - if (checks_.params.continuity.do_check(timestep)) { + if (checks_.params.continuity.should_do_check(timestep)) { mpi_printf(comm, "***** Checking continuity...\n"); prof_start(pr_checks); checks_.continuity_before_particle_push(mprts_); @@ -557,7 +557,7 @@ struct Psc // state is now: x^{n+3/2}, p^{n+1}, E^{n+3/2}, B^{n+3/2} #endif - if (checks_.params.continuity.do_check(timestep)) { + if (checks_.params.continuity.should_do_check(timestep)) { prof_restart(pr_checks); checks_.continuity_after_particle_push(mprts_, mflds_); prof_stop(pr_checks); @@ -573,7 +573,7 @@ struct Psc prof_stop(pr_marder); } - if (checks_.params.gauss.do_check(timestep)) { + if (checks_.params.gauss.should_do_check(timestep)) { prof_restart(pr_checks); checks_.gauss(mprts_, mflds_); prof_stop(pr_checks); diff --git a/src/libpsc/psc_checks/checks_impl.hxx b/src/libpsc/psc_checks/checks_impl.hxx index e1f4f08a4c..ab8f36fe6d 100644 --- a/src/libpsc/psc_checks/checks_impl.hxx +++ b/src/libpsc/psc_checks/checks_impl.hxx @@ -47,7 +47,7 @@ public: void before_particle_push(const Mparticles& mprts) { const auto& grid = mprts.grid(); - if (!params_.do_check(grid.timestep())) { + if (!params_.should_do_check(grid.timestep())) { return; } @@ -62,7 +62,7 @@ public: void after_particle_push(const Mparticles& mprts, MfieldsState& mflds) { const Grid_t& grid = mprts.grid(); - if (!params_.do_check(grid.timestep())) { + if (!params_.should_do_check(grid.timestep())) { return; } @@ -79,16 +79,16 @@ public: double max_err; MPI_Allreduce(&local_err, &max_err, 1, MPI_DOUBLE, MPI_MAX, grid.comm()); - if (params_.do_print_diffs(max_err)) { + if (params_.should_print_diffs(max_err)) { psc::helper::print_diff(d_rho, -dt_divj, params_.threshold); } - if (params_.do_print_max(max_err)) { + if (params_.should_print_max(max_err)) { mpi_printf(grid.comm(), "continuity: max_err = %g (thres %g)\n", max_err, params_.threshold); } - if (params_.do_dump(max_err)) { + if (params_.should_dump(max_err)) { if (!writer_) { writer_.open("continuity"); } @@ -127,7 +127,7 @@ public: void operator()(Mparticles& mprts, MfieldsState& mflds) { const auto& grid = mprts.grid(); - if (!params_.do_check(grid.timestep())) { + if (!params_.should_do_check(grid.timestep())) { return; } @@ -154,7 +154,7 @@ public: double patch_err = gt::norm_linf(patch_dive - patch_rho); max_err = std::max(max_err, patch_err); - if (params_.do_print_diffs(patch_err)) { + if (params_.should_print_diffs(patch_err)) { psc::helper::print_diff(patch_rho, patch_dive, params_.threshold); } } @@ -163,12 +163,12 @@ public: double tmp = max_err; MPI_Allreduce(&tmp, &max_err, 1, MPI_DOUBLE, MPI_MAX, grid.comm()); - if (params_.do_print_max(max_err)) { + if (params_.should_print_max(max_err)) { mpi_printf(grid.comm(), "gauss: max_err = %g (thres %g)\n", max_err, params_.threshold); } - if (params_.do_dump(max_err)) { + if (params_.should_dump(max_err)) { if (!writer_) { writer_.open("gauss"); } From 62565eee2180516e2ce66e3a0ec67924f31c63ce Mon Sep 17 00:00:00 2001 From: James McClung Date: Thu, 3 Apr 2025 12:12:50 -0400 Subject: [PATCH 09/16] checks_params; *: rename to check_interval --- src/include/checks_params.hxx | 6 +++--- src/libpsc/tests/test_push_particles_2.cxx | 4 ++-- src/psc_2d_shock.cxx | 4 ++-- src/psc_bgk.cxx | 2 +- src/psc_flatfoil_yz.cxx | 8 ++++---- src/psc_harris_yz.cxx | 4 ++-- src/psc_shock.cxx | 2 +- src/psc_whistler.cxx | 2 +- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/include/checks_params.hxx b/src/include/checks_params.hxx index b24d36a695..1888183f39 100644 --- a/src/include/checks_params.hxx +++ b/src/include/checks_params.hxx @@ -3,16 +3,16 @@ struct CheckParams { - int every_step = 0; // number of steps per check + int check_interval = 0; // number of steps per check double threshold = 1e-13; // maximum acceptable error bool verbose = true; // always print error, even if acceptable bool dump_always = false; // always dump compared fields, even if acceptable - bool enabled() { return every_step > 0; } + bool enabled() { return check_interval > 0; } bool should_do_check(int timestep) { - return enabled() && timestep % every_step == 0; + return enabled() && timestep % check_interval == 0; } bool should_print_diffs(double err) { return err > threshold; } diff --git a/src/libpsc/tests/test_push_particles_2.cxx b/src/libpsc/tests/test_push_particles_2.cxx index eee654a807..b9b7d26064 100644 --- a/src/libpsc/tests/test_push_particles_2.cxx +++ b/src/libpsc/tests/test_push_particles_2.cxx @@ -71,7 +71,7 @@ TYPED_TEST(PushParticlesTest, Accel) BndParticles bndp_{grid}; Bnd bnd_{}; ChecksParams checks_params{}; - checks_params.continuity.every_step = 1; + checks_params.continuity.check_interval = 1; checks_params.continuity.threshold = 1e-7; checks_params.continuity.verbose = false; Checks checks_{grid, MPI_COMM_WORLD, checks_params}; @@ -149,7 +149,7 @@ TYPED_TEST(PushParticlesTest, Cyclo) BndParticles bndp_{grid}; Bnd bnd_{}; ChecksParams checks_params{}; - checks_params.continuity.every_step = 1; + checks_params.continuity.check_interval = 1; checks_params.continuity.threshold = 1e-7; checks_params.continuity.verbose = false; Checks checks_{grid, MPI_COMM_WORLD, checks_params}; diff --git a/src/psc_2d_shock.cxx b/src/psc_2d_shock.cxx index 5ce91df18d..f7528b000b 100644 --- a/src/psc_2d_shock.cxx +++ b/src/psc_2d_shock.cxx @@ -439,11 +439,11 @@ void run() // -- Checks ChecksParams checks_params{}; - checks_params.continuity.every_step = 100; + checks_params.continuity.check_interval = 100; checks_params.continuity.threshold = 1e-4; checks_params.continuity.verbose = true; checks_params.continuity.dump_always = false; - checks_params.gauss.every_step = 100; + checks_params.gauss.check_interval = 100; checks_params.gauss.threshold = 1e-4; checks_params.gauss.verbose = true; checks_params.gauss.dump_always = false; diff --git a/src/psc_bgk.cxx b/src/psc_bgk.cxx index 87a68224b8..db549e65c9 100644 --- a/src/psc_bgk.cxx +++ b/src/psc_bgk.cxx @@ -510,7 +510,7 @@ static void run(int argc, char** argv) // -- Checks ChecksParams checks_params{}; - checks_params.gauss.every_step = g.gauss_every; + checks_params.gauss.check_interval = g.gauss_every; // checks_params.gauss.dump_always = true; checks_params.gauss.threshold = 1e-5; diff --git a/src/psc_flatfoil_yz.cxx b/src/psc_flatfoil_yz.cxx index ca8856025c..7b7a904d9c 100644 --- a/src/psc_flatfoil_yz.cxx +++ b/src/psc_flatfoil_yz.cxx @@ -478,20 +478,20 @@ void run() // -- Checks ChecksParams checks_params{}; #if CASE == CASE_2D_SMALL - checks_params.continuity.every_step = 1; + checks_params.continuity.check_interval = 1; checks_params.continuity.dump_always = true; #else - checks_params.continuity.every_step = 0; + checks_params.continuity.check_interval = 0; checks_params.continuity.dump_always = false; #endif checks_params.continuity.threshold = 1e-4; checks_params.continuity.verbose = true; #if CASE == CASE_2D_SMALL - checks_params.gauss.every_step = 1; + checks_params.gauss.check_interval = 1; checks_params.gauss.dump_always = true; #else - checks_params.gauss.every_step = 100; + checks_params.gauss.check_interval = 100; checks_params.gauss.dump_always = false; #endif checks_params.gauss.threshold = 1e-4; diff --git a/src/psc_harris_yz.cxx b/src/psc_harris_yz.cxx index 7a78fdc6cc..2f53d22af7 100644 --- a/src/psc_harris_yz.cxx +++ b/src/psc_harris_yz.cxx @@ -385,12 +385,12 @@ void run() // -- Checks ChecksParams checks_params{}; - checks_params.continuity.every_step = 0; + checks_params.continuity.check_interval = 0; checks_params.continuity.dump_always = false; checks_params.continuity.threshold = 1e-4; checks_params.continuity.verbose = true; - checks_params.gauss.every_step = -100; + checks_params.gauss.check_interval = -100; checks_params.gauss.dump_always = false; checks_params.gauss.threshold = 1e-4; checks_params.gauss.verbose = true; diff --git a/src/psc_shock.cxx b/src/psc_shock.cxx index b730d8cb45..dee640bc96 100644 --- a/src/psc_shock.cxx +++ b/src/psc_shock.cxx @@ -278,7 +278,7 @@ static void run(int argc, char** argv) // -- Checks ChecksParams checks_params{}; - checks_params.gauss.every_step = out_interval; + checks_params.gauss.check_interval = out_interval; // checks_params.gauss.dump_always = true; checks_params.gauss.threshold = 1e-5; diff --git a/src/psc_whistler.cxx b/src/psc_whistler.cxx index a52346040d..23a352a3d3 100644 --- a/src/psc_whistler.cxx +++ b/src/psc_whistler.cxx @@ -292,7 +292,7 @@ void run() // -- Checks ChecksParams checks_params{}; - checks_params.continuity.every_step = 50; + checks_params.continuity.check_interval = 50; checks_params.continuity.threshold = 1e-5; checks_params.continuity.verbose = false; Checks checks{grid, MPI_COMM_WORLD, checks_params}; From 886416b1cb660f7eca975f599209722aade354dc Mon Sep 17 00:00:00 2001 From: James McClung Date: Thu, 3 Apr 2025 12:15:00 -0400 Subject: [PATCH 10/16] checks_params; *: verbose->print_max_always --- src/include/checks_params.hxx | 8 ++++---- src/libpsc/tests/test_push_particles_2.cxx | 4 ++-- src/psc_2d_shock.cxx | 4 ++-- src/psc_flatfoil_yz.cxx | 4 ++-- src/psc_harris_yz.cxx | 4 ++-- src/psc_whistler.cxx | 2 +- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/include/checks_params.hxx b/src/include/checks_params.hxx index 1888183f39..751fc4d6f5 100644 --- a/src/include/checks_params.hxx +++ b/src/include/checks_params.hxx @@ -3,9 +3,9 @@ struct CheckParams { - int check_interval = 0; // number of steps per check - double threshold = 1e-13; // maximum acceptable error - bool verbose = true; // always print error, even if acceptable + int check_interval = 0; // number of steps per check + double threshold = 1e-13; // maximum acceptable error + bool print_max_always = true; // always print error, even if acceptable bool dump_always = false; // always dump compared fields, even if acceptable bool enabled() { return check_interval > 0; } @@ -19,7 +19,7 @@ struct CheckParams bool should_print_max(double max_err) { - return verbose || max_err > threshold; + return print_max_always || max_err > threshold; } bool should_dump(double max_err) diff --git a/src/libpsc/tests/test_push_particles_2.cxx b/src/libpsc/tests/test_push_particles_2.cxx index b9b7d26064..67cba13c09 100644 --- a/src/libpsc/tests/test_push_particles_2.cxx +++ b/src/libpsc/tests/test_push_particles_2.cxx @@ -73,7 +73,7 @@ TYPED_TEST(PushParticlesTest, Accel) ChecksParams checks_params{}; checks_params.continuity.check_interval = 1; checks_params.continuity.threshold = 1e-7; - checks_params.continuity.verbose = false; + checks_params.continuity.print_max_always = false; Checks checks_{grid, MPI_COMM_WORLD, checks_params}; for (int n = 0; n < n_steps; n++) { checks_.continuity_before_particle_push(mprts); @@ -151,7 +151,7 @@ TYPED_TEST(PushParticlesTest, Cyclo) ChecksParams checks_params{}; checks_params.continuity.check_interval = 1; checks_params.continuity.threshold = 1e-7; - checks_params.continuity.verbose = false; + checks_params.continuity.print_max_always = false; Checks checks_{grid, MPI_COMM_WORLD, checks_params}; for (int n = 0; n < n_steps; n++) { checks_.continuity_before_particle_push(mprts); diff --git a/src/psc_2d_shock.cxx b/src/psc_2d_shock.cxx index f7528b000b..3702bf5d9b 100644 --- a/src/psc_2d_shock.cxx +++ b/src/psc_2d_shock.cxx @@ -441,11 +441,11 @@ void run() ChecksParams checks_params{}; checks_params.continuity.check_interval = 100; checks_params.continuity.threshold = 1e-4; - checks_params.continuity.verbose = true; + checks_params.continuity.print_max_always = true; checks_params.continuity.dump_always = false; checks_params.gauss.check_interval = 100; checks_params.gauss.threshold = 1e-4; - checks_params.gauss.verbose = true; + checks_params.gauss.print_max_always = true; checks_params.gauss.dump_always = false; Checks checks{grid, MPI_COMM_WORLD, checks_params}; diff --git a/src/psc_flatfoil_yz.cxx b/src/psc_flatfoil_yz.cxx index 7b7a904d9c..20d4c0c4df 100644 --- a/src/psc_flatfoil_yz.cxx +++ b/src/psc_flatfoil_yz.cxx @@ -485,7 +485,7 @@ void run() checks_params.continuity.dump_always = false; #endif checks_params.continuity.threshold = 1e-4; - checks_params.continuity.verbose = true; + checks_params.continuity.print_max_always = true; #if CASE == CASE_2D_SMALL checks_params.gauss.check_interval = 1; @@ -495,7 +495,7 @@ void run() checks_params.gauss.dump_always = false; #endif checks_params.gauss.threshold = 1e-4; - checks_params.gauss.verbose = true; + checks_params.gauss.print_max_always = true; Checks checks{grid, MPI_COMM_WORLD, checks_params}; diff --git a/src/psc_harris_yz.cxx b/src/psc_harris_yz.cxx index 2f53d22af7..b5afa0d1ed 100644 --- a/src/psc_harris_yz.cxx +++ b/src/psc_harris_yz.cxx @@ -388,12 +388,12 @@ void run() checks_params.continuity.check_interval = 0; checks_params.continuity.dump_always = false; checks_params.continuity.threshold = 1e-4; - checks_params.continuity.verbose = true; + checks_params.continuity.print_max_always = true; checks_params.gauss.check_interval = -100; checks_params.gauss.dump_always = false; checks_params.gauss.threshold = 1e-4; - checks_params.gauss.verbose = true; + checks_params.gauss.print_max_always = true; Checks checks{grid, MPI_COMM_WORLD, checks_params}; diff --git a/src/psc_whistler.cxx b/src/psc_whistler.cxx index 23a352a3d3..448155838c 100644 --- a/src/psc_whistler.cxx +++ b/src/psc_whistler.cxx @@ -294,7 +294,7 @@ void run() ChecksParams checks_params{}; checks_params.continuity.check_interval = 50; checks_params.continuity.threshold = 1e-5; - checks_params.continuity.verbose = false; + checks_params.continuity.print_max_always = false; Checks checks{grid, MPI_COMM_WORLD, checks_params}; // -- Marder correction From e418f55abff7ed2f91b7c4d75eaea7d88e0a5dbb Mon Sep 17 00:00:00 2001 From: James McClung Date: Thu, 3 Apr 2025 12:16:56 -0400 Subject: [PATCH 11/16] checks_params; *: threshold->err_threshold --- src/include/checks_params.hxx | 8 ++++---- src/libpsc/psc_checks/checks_impl.hxx | 12 ++++++------ src/libpsc/tests/test_push_particles_2.cxx | 4 ++-- src/psc_2d_shock.cxx | 4 ++-- src/psc_bgk.cxx | 2 +- src/psc_flatfoil_yz.cxx | 4 ++-- src/psc_harris_yz.cxx | 4 ++-- src/psc_shock.cxx | 2 +- src/psc_whistler.cxx | 2 +- 9 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/include/checks_params.hxx b/src/include/checks_params.hxx index 751fc4d6f5..6ee6db1bb8 100644 --- a/src/include/checks_params.hxx +++ b/src/include/checks_params.hxx @@ -4,7 +4,7 @@ struct CheckParams { int check_interval = 0; // number of steps per check - double threshold = 1e-13; // maximum acceptable error + double err_threshold = 1e-13; // maximum acceptable error bool print_max_always = true; // always print error, even if acceptable bool dump_always = false; // always dump compared fields, even if acceptable @@ -15,16 +15,16 @@ struct CheckParams return enabled() && timestep % check_interval == 0; } - bool should_print_diffs(double err) { return err > threshold; } + bool should_print_diffs(double err) { return err > err_threshold; } bool should_print_max(double max_err) { - return print_max_always || max_err > threshold; + return print_max_always || max_err > err_threshold; } bool should_dump(double max_err) { - return dump_always || max_err > threshold; + return dump_always || max_err > err_threshold; } }; diff --git a/src/libpsc/psc_checks/checks_impl.hxx b/src/libpsc/psc_checks/checks_impl.hxx index ab8f36fe6d..a6b7aab9da 100644 --- a/src/libpsc/psc_checks/checks_impl.hxx +++ b/src/libpsc/psc_checks/checks_impl.hxx @@ -80,12 +80,12 @@ public: MPI_Allreduce(&local_err, &max_err, 1, MPI_DOUBLE, MPI_MAX, grid.comm()); if (params_.should_print_diffs(max_err)) { - psc::helper::print_diff(d_rho, -dt_divj, params_.threshold); + psc::helper::print_diff(d_rho, -dt_divj, params_.err_threshold); } if (params_.should_print_max(max_err)) { mpi_printf(grid.comm(), "continuity: max_err = %g (thres %g)\n", max_err, - params_.threshold); + params_.err_threshold); } if (params_.should_dump(max_err)) { @@ -99,7 +99,7 @@ public: MPI_Barrier(grid.comm()); } - assert(max_err < params_.threshold); + assert(max_err < params_.err_threshold); } private: @@ -155,7 +155,7 @@ public: max_err = std::max(max_err, patch_err); if (params_.should_print_diffs(patch_err)) { - psc::helper::print_diff(patch_rho, patch_dive, params_.threshold); + psc::helper::print_diff(patch_rho, patch_dive, params_.err_threshold); } } @@ -165,7 +165,7 @@ public: if (params_.should_print_max(max_err)) { mpi_printf(grid.comm(), "gauss: max_err = %g (thres %g)\n", max_err, - params_.threshold); + params_.err_threshold); } if (params_.should_dump(max_err)) { @@ -178,7 +178,7 @@ public: writer_.end_step(); } - assert(max_err < params_.threshold); + assert(max_err < params_.err_threshold); } private: diff --git a/src/libpsc/tests/test_push_particles_2.cxx b/src/libpsc/tests/test_push_particles_2.cxx index 67cba13c09..beadd99249 100644 --- a/src/libpsc/tests/test_push_particles_2.cxx +++ b/src/libpsc/tests/test_push_particles_2.cxx @@ -72,7 +72,7 @@ TYPED_TEST(PushParticlesTest, Accel) Bnd bnd_{}; ChecksParams checks_params{}; checks_params.continuity.check_interval = 1; - checks_params.continuity.threshold = 1e-7; + checks_params.continuity.err_threshold = 1e-7; checks_params.continuity.print_max_always = false; Checks checks_{grid, MPI_COMM_WORLD, checks_params}; for (int n = 0; n < n_steps; n++) { @@ -150,7 +150,7 @@ TYPED_TEST(PushParticlesTest, Cyclo) Bnd bnd_{}; ChecksParams checks_params{}; checks_params.continuity.check_interval = 1; - checks_params.continuity.threshold = 1e-7; + checks_params.continuity.err_threshold = 1e-7; checks_params.continuity.print_max_always = false; Checks checks_{grid, MPI_COMM_WORLD, checks_params}; for (int n = 0; n < n_steps; n++) { diff --git a/src/psc_2d_shock.cxx b/src/psc_2d_shock.cxx index 3702bf5d9b..de2e560450 100644 --- a/src/psc_2d_shock.cxx +++ b/src/psc_2d_shock.cxx @@ -440,11 +440,11 @@ void run() // -- Checks ChecksParams checks_params{}; checks_params.continuity.check_interval = 100; - checks_params.continuity.threshold = 1e-4; + checks_params.continuity.err_threshold = 1e-4; checks_params.continuity.print_max_always = true; checks_params.continuity.dump_always = false; checks_params.gauss.check_interval = 100; - checks_params.gauss.threshold = 1e-4; + checks_params.gauss.err_threshold = 1e-4; checks_params.gauss.print_max_always = true; checks_params.gauss.dump_always = false; Checks checks{grid, MPI_COMM_WORLD, checks_params}; diff --git a/src/psc_bgk.cxx b/src/psc_bgk.cxx index db549e65c9..d6f901ca3d 100644 --- a/src/psc_bgk.cxx +++ b/src/psc_bgk.cxx @@ -512,7 +512,7 @@ static void run(int argc, char** argv) ChecksParams checks_params{}; checks_params.gauss.check_interval = g.gauss_every; // checks_params.gauss.dump_always = true; - checks_params.gauss.threshold = 1e-5; + checks_params.gauss.err_threshold = 1e-5; Checks checks{grid, MPI_COMM_WORLD, checks_params}; diff --git a/src/psc_flatfoil_yz.cxx b/src/psc_flatfoil_yz.cxx index 20d4c0c4df..87bd970f0d 100644 --- a/src/psc_flatfoil_yz.cxx +++ b/src/psc_flatfoil_yz.cxx @@ -484,7 +484,7 @@ void run() checks_params.continuity.check_interval = 0; checks_params.continuity.dump_always = false; #endif - checks_params.continuity.threshold = 1e-4; + checks_params.continuity.err_threshold = 1e-4; checks_params.continuity.print_max_always = true; #if CASE == CASE_2D_SMALL @@ -494,7 +494,7 @@ void run() checks_params.gauss.check_interval = 100; checks_params.gauss.dump_always = false; #endif - checks_params.gauss.threshold = 1e-4; + checks_params.gauss.err_threshold = 1e-4; checks_params.gauss.print_max_always = true; Checks checks{grid, MPI_COMM_WORLD, checks_params}; diff --git a/src/psc_harris_yz.cxx b/src/psc_harris_yz.cxx index b5afa0d1ed..f7cba2a162 100644 --- a/src/psc_harris_yz.cxx +++ b/src/psc_harris_yz.cxx @@ -387,12 +387,12 @@ void run() ChecksParams checks_params{}; checks_params.continuity.check_interval = 0; checks_params.continuity.dump_always = false; - checks_params.continuity.threshold = 1e-4; + checks_params.continuity.err_threshold = 1e-4; checks_params.continuity.print_max_always = true; checks_params.gauss.check_interval = -100; checks_params.gauss.dump_always = false; - checks_params.gauss.threshold = 1e-4; + checks_params.gauss.err_threshold = 1e-4; checks_params.gauss.print_max_always = true; Checks checks{grid, MPI_COMM_WORLD, checks_params}; diff --git a/src/psc_shock.cxx b/src/psc_shock.cxx index dee640bc96..6a8dc48f9c 100644 --- a/src/psc_shock.cxx +++ b/src/psc_shock.cxx @@ -280,7 +280,7 @@ static void run(int argc, char** argv) ChecksParams checks_params{}; checks_params.gauss.check_interval = out_interval; // checks_params.gauss.dump_always = true; - checks_params.gauss.threshold = 1e-5; + checks_params.gauss.err_threshold = 1e-5; Checks checks{grid, MPI_COMM_WORLD, checks_params}; diff --git a/src/psc_whistler.cxx b/src/psc_whistler.cxx index 448155838c..c339a78d3f 100644 --- a/src/psc_whistler.cxx +++ b/src/psc_whistler.cxx @@ -293,7 +293,7 @@ void run() // -- Checks ChecksParams checks_params{}; checks_params.continuity.check_interval = 50; - checks_params.continuity.threshold = 1e-5; + checks_params.continuity.err_threshold = 1e-5; checks_params.continuity.print_max_always = false; Checks checks{grid, MPI_COMM_WORLD, checks_params}; From 534cc3c6b966d0ac9ec5cf6540bd74ad10a31efd Mon Sep 17 00:00:00 2001 From: James McClung Date: Thu, 3 Apr 2025 12:45:00 -0400 Subject: [PATCH 12/16] checks_params; *: max -> max_err --- src/include/checks_params.hxx | 10 +++++----- src/libpsc/psc_checks/checks_impl.hxx | 4 ++-- src/libpsc/tests/test_push_particles_2.cxx | 4 ++-- src/psc_2d_shock.cxx | 4 ++-- src/psc_flatfoil_yz.cxx | 4 ++-- src/psc_harris_yz.cxx | 4 ++-- src/psc_whistler.cxx | 2 +- 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/include/checks_params.hxx b/src/include/checks_params.hxx index 6ee6db1bb8..8b328f6bc6 100644 --- a/src/include/checks_params.hxx +++ b/src/include/checks_params.hxx @@ -3,9 +3,9 @@ struct CheckParams { - int check_interval = 0; // number of steps per check - double err_threshold = 1e-13; // maximum acceptable error - bool print_max_always = true; // always print error, even if acceptable + int check_interval = 0; // number of steps per check + double err_threshold = 1e-13; // maximum acceptable error + bool print_max_err_always = true; // always print error, even if acceptable bool dump_always = false; // always dump compared fields, even if acceptable bool enabled() { return check_interval > 0; } @@ -17,9 +17,9 @@ struct CheckParams bool should_print_diffs(double err) { return err > err_threshold; } - bool should_print_max(double max_err) + bool should_print_max_err(double max_err) { - return print_max_always || max_err > err_threshold; + return print_max_err_always || max_err > err_threshold; } bool should_dump(double max_err) diff --git a/src/libpsc/psc_checks/checks_impl.hxx b/src/libpsc/psc_checks/checks_impl.hxx index a6b7aab9da..ff94b2a2a7 100644 --- a/src/libpsc/psc_checks/checks_impl.hxx +++ b/src/libpsc/psc_checks/checks_impl.hxx @@ -83,7 +83,7 @@ public: psc::helper::print_diff(d_rho, -dt_divj, params_.err_threshold); } - if (params_.should_print_max(max_err)) { + if (params_.should_print_max_err(max_err)) { mpi_printf(grid.comm(), "continuity: max_err = %g (thres %g)\n", max_err, params_.err_threshold); } @@ -163,7 +163,7 @@ public: double tmp = max_err; MPI_Allreduce(&tmp, &max_err, 1, MPI_DOUBLE, MPI_MAX, grid.comm()); - if (params_.should_print_max(max_err)) { + if (params_.should_print_max_err(max_err)) { mpi_printf(grid.comm(), "gauss: max_err = %g (thres %g)\n", max_err, params_.err_threshold); } diff --git a/src/libpsc/tests/test_push_particles_2.cxx b/src/libpsc/tests/test_push_particles_2.cxx index beadd99249..6523b72abc 100644 --- a/src/libpsc/tests/test_push_particles_2.cxx +++ b/src/libpsc/tests/test_push_particles_2.cxx @@ -73,7 +73,7 @@ TYPED_TEST(PushParticlesTest, Accel) ChecksParams checks_params{}; checks_params.continuity.check_interval = 1; checks_params.continuity.err_threshold = 1e-7; - checks_params.continuity.print_max_always = false; + checks_params.continuity.print_max_err_always = false; Checks checks_{grid, MPI_COMM_WORLD, checks_params}; for (int n = 0; n < n_steps; n++) { checks_.continuity_before_particle_push(mprts); @@ -151,7 +151,7 @@ TYPED_TEST(PushParticlesTest, Cyclo) ChecksParams checks_params{}; checks_params.continuity.check_interval = 1; checks_params.continuity.err_threshold = 1e-7; - checks_params.continuity.print_max_always = false; + checks_params.continuity.print_max_err_always = false; Checks checks_{grid, MPI_COMM_WORLD, checks_params}; for (int n = 0; n < n_steps; n++) { checks_.continuity_before_particle_push(mprts); diff --git a/src/psc_2d_shock.cxx b/src/psc_2d_shock.cxx index de2e560450..58eaeef73e 100644 --- a/src/psc_2d_shock.cxx +++ b/src/psc_2d_shock.cxx @@ -441,11 +441,11 @@ void run() ChecksParams checks_params{}; checks_params.continuity.check_interval = 100; checks_params.continuity.err_threshold = 1e-4; - checks_params.continuity.print_max_always = true; + checks_params.continuity.print_max_err_always = true; checks_params.continuity.dump_always = false; checks_params.gauss.check_interval = 100; checks_params.gauss.err_threshold = 1e-4; - checks_params.gauss.print_max_always = true; + checks_params.gauss.print_max_err_always = true; checks_params.gauss.dump_always = false; Checks checks{grid, MPI_COMM_WORLD, checks_params}; diff --git a/src/psc_flatfoil_yz.cxx b/src/psc_flatfoil_yz.cxx index 87bd970f0d..1f2469e9da 100644 --- a/src/psc_flatfoil_yz.cxx +++ b/src/psc_flatfoil_yz.cxx @@ -485,7 +485,7 @@ void run() checks_params.continuity.dump_always = false; #endif checks_params.continuity.err_threshold = 1e-4; - checks_params.continuity.print_max_always = true; + checks_params.continuity.print_max_err_always = true; #if CASE == CASE_2D_SMALL checks_params.gauss.check_interval = 1; @@ -495,7 +495,7 @@ void run() checks_params.gauss.dump_always = false; #endif checks_params.gauss.err_threshold = 1e-4; - checks_params.gauss.print_max_always = true; + checks_params.gauss.print_max_err_always = true; Checks checks{grid, MPI_COMM_WORLD, checks_params}; diff --git a/src/psc_harris_yz.cxx b/src/psc_harris_yz.cxx index f7cba2a162..0d1f27a126 100644 --- a/src/psc_harris_yz.cxx +++ b/src/psc_harris_yz.cxx @@ -388,12 +388,12 @@ void run() checks_params.continuity.check_interval = 0; checks_params.continuity.dump_always = false; checks_params.continuity.err_threshold = 1e-4; - checks_params.continuity.print_max_always = true; + checks_params.continuity.print_max_err_always = true; checks_params.gauss.check_interval = -100; checks_params.gauss.dump_always = false; checks_params.gauss.err_threshold = 1e-4; - checks_params.gauss.print_max_always = true; + checks_params.gauss.print_max_err_always = true; Checks checks{grid, MPI_COMM_WORLD, checks_params}; diff --git a/src/psc_whistler.cxx b/src/psc_whistler.cxx index c339a78d3f..793cd2f89e 100644 --- a/src/psc_whistler.cxx +++ b/src/psc_whistler.cxx @@ -294,7 +294,7 @@ void run() ChecksParams checks_params{}; checks_params.continuity.check_interval = 50; checks_params.continuity.err_threshold = 1e-5; - checks_params.continuity.print_max_always = false; + checks_params.continuity.print_max_err_always = false; Checks checks{grid, MPI_COMM_WORLD, checks_params}; // -- Marder correction From 270fc91331ec36900d58973ac2b382a186508d6b Mon Sep 17 00:00:00 2001 From: James McClung Date: Thu, 3 Apr 2025 12:48:39 -0400 Subject: [PATCH 13/16] checks_impl: make params public --- src/libpsc/psc_checks/checks_impl.hxx | 42 +++++++++++++++------------ 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/src/libpsc/psc_checks/checks_impl.hxx b/src/libpsc/psc_checks/checks_impl.hxx index ff94b2a2a7..d16db1c2d0 100644 --- a/src/libpsc/psc_checks/checks_impl.hxx +++ b/src/libpsc/psc_checks/checks_impl.hxx @@ -38,7 +38,7 @@ public: using storage_type = S; using Item_rho = ITEM_RHO; - continuity(const ContinuityCheckParams& params) : params_(params) {} + continuity(const ContinuityCheckParams& params) : params(params) {} // ---------------------------------------------------------------------- // before_particle_push @@ -47,7 +47,7 @@ public: void before_particle_push(const Mparticles& mprts) { const auto& grid = mprts.grid(); - if (!params_.should_do_check(grid.timestep())) { + if (!params.should_do_check(grid.timestep())) { return; } @@ -62,7 +62,7 @@ public: void after_particle_push(const Mparticles& mprts, MfieldsState& mflds) { const Grid_t& grid = mprts.grid(); - if (!params_.should_do_check(grid.timestep())) { + if (!params.should_do_check(grid.timestep())) { return; } @@ -79,16 +79,16 @@ public: double max_err; MPI_Allreduce(&local_err, &max_err, 1, MPI_DOUBLE, MPI_MAX, grid.comm()); - if (params_.should_print_diffs(max_err)) { - psc::helper::print_diff(d_rho, -dt_divj, params_.err_threshold); + if (params.should_print_diffs(max_err)) { + psc::helper::print_diff(d_rho, -dt_divj, params.err_threshold); } - if (params_.should_print_max_err(max_err)) { + if (params.should_print_max_err(max_err)) { mpi_printf(grid.comm(), "continuity: max_err = %g (thres %g)\n", max_err, - params_.err_threshold); + params.err_threshold); } - if (params_.should_dump(max_err)) { + if (params.should_dump(max_err)) { if (!writer_) { writer_.open("continuity"); } @@ -99,13 +99,15 @@ public: MPI_Barrier(grid.comm()); } - assert(max_err < params_.err_threshold); + assert(max_err < params.err_threshold); } +public: + ContinuityCheckParams params; + private: storage_type rho_m_; WriterDefault writer_; - ContinuityCheckParams params_; }; // ====================================================================== @@ -118,7 +120,7 @@ public: using storage_type = S; using Item_rho = ITEM_RHO; - gauss(const GaussCheckParams params) : params_(params) {} + gauss(const GaussCheckParams params) : params(params) {} // ---------------------------------------------------------------------- // operator() @@ -127,7 +129,7 @@ public: void operator()(Mparticles& mprts, MfieldsState& mflds) { const auto& grid = mprts.grid(); - if (!params_.should_do_check(grid.timestep())) { + if (!params.should_do_check(grid.timestep())) { return; } @@ -154,8 +156,8 @@ public: double patch_err = gt::norm_linf(patch_dive - patch_rho); max_err = std::max(max_err, patch_err); - if (params_.should_print_diffs(patch_err)) { - psc::helper::print_diff(patch_rho, patch_dive, params_.err_threshold); + if (params.should_print_diffs(patch_err)) { + psc::helper::print_diff(patch_rho, patch_dive, params.err_threshold); } } @@ -163,12 +165,12 @@ public: double tmp = max_err; MPI_Allreduce(&tmp, &max_err, 1, MPI_DOUBLE, MPI_MAX, grid.comm()); - if (params_.should_print_max_err(max_err)) { + if (params.should_print_max_err(max_err)) { mpi_printf(grid.comm(), "gauss: max_err = %g (thres %g)\n", max_err, - params_.err_threshold); + params.err_threshold); } - if (params_.should_dump(max_err)) { + if (params.should_dump(max_err)) { if (!writer_) { writer_.open("gauss"); } @@ -178,12 +180,14 @@ public: writer_.end_step(); } - assert(max_err < params_.err_threshold); + assert(max_err < params.err_threshold); } +public: + GaussCheckParams params; + private: WriterDefault writer_; - GaussCheckParams params_; }; } // namespace checks From 523f8df9a547ea55b8f7e41ee472ee9e263dbfc3 Mon Sep 17 00:00:00 2001 From: James McClung Date: Thu, 3 Apr 2025 15:26:04 -0400 Subject: [PATCH 14/16] checks_impl; *: make fields public --- src/include/psc.hxx | 10 ++++----- src/libpsc/psc_checks/checks_impl.hxx | 26 +++------------------- src/libpsc/tests/test_push_particles_2.cxx | 8 +++---- 3 files changed, 12 insertions(+), 32 deletions(-) diff --git a/src/include/psc.hxx b/src/include/psc.hxx index bb8e8b874d..98e2ae04de 100644 --- a/src/include/psc.hxx +++ b/src/include/psc.hxx @@ -489,10 +489,10 @@ struct Psc inject_particles(); prof_stop(pr_inject_prts); - if (checks_.params.continuity.should_do_check(timestep)) { + if (checks_.continuity.params.should_do_check(timestep)) { mpi_printf(comm, "***** Checking continuity...\n"); prof_start(pr_checks); - checks_.continuity_before_particle_push(mprts_); + checks_.continuity.before_particle_push(mprts_); prof_stop(pr_checks); } @@ -557,9 +557,9 @@ struct Psc // state is now: x^{n+3/2}, p^{n+1}, E^{n+3/2}, B^{n+3/2} #endif - if (checks_.params.continuity.should_do_check(timestep)) { + if (checks_.continuity.params.should_do_check(timestep)) { prof_restart(pr_checks); - checks_.continuity_after_particle_push(mprts_, mflds_); + checks_.continuity.after_particle_push(mprts_, mflds_); prof_stop(pr_checks); } @@ -573,7 +573,7 @@ struct Psc prof_stop(pr_marder); } - if (checks_.params.gauss.should_do_check(timestep)) { + if (checks_.gauss.params.should_do_check(timestep)) { prof_restart(pr_checks); checks_.gauss(mprts_, mflds_); prof_stop(pr_checks); diff --git a/src/libpsc/psc_checks/checks_impl.hxx b/src/libpsc/psc_checks/checks_impl.hxx index d16db1c2d0..cda8706388 100644 --- a/src/libpsc/psc_checks/checks_impl.hxx +++ b/src/libpsc/psc_checks/checks_impl.hxx @@ -214,32 +214,12 @@ public: using item_rho_type = ITEM_RHO; ChecksCommon(const Grid_t& grid, MPI_Comm comm, const ChecksParams& params) - : params(params), continuity_{params.continuity}, gauss_{params.gauss} + : continuity{params.continuity}, gauss{params.gauss} {} - void continuity_before_particle_push(Mparticles& mprts) - { - continuity_.before_particle_push(mprts); - } - - template - void continuity_after_particle_push(Mparticles& mprts, MfieldsState& mflds) - { - continuity_.after_particle_push(mprts, mflds); - } - - template - void gauss(Mparticles& mprts, MfieldsState& mflds) - { - gauss_(mprts, mflds); - } - public: - ChecksParams params; - -private: - psc::checks::continuity continuity_; - psc::checks::gauss gauss_; + psc::checks::continuity continuity; + psc::checks::gauss gauss; }; template diff --git a/src/libpsc/tests/test_push_particles_2.cxx b/src/libpsc/tests/test_push_particles_2.cxx index 6523b72abc..ac5d300cb1 100644 --- a/src/libpsc/tests/test_push_particles_2.cxx +++ b/src/libpsc/tests/test_push_particles_2.cxx @@ -76,12 +76,12 @@ TYPED_TEST(PushParticlesTest, Accel) checks_params.continuity.print_max_err_always = false; Checks checks_{grid, MPI_COMM_WORLD, checks_params}; for (int n = 0; n < n_steps; n++) { - checks_.continuity_before_particle_push(mprts); + checks_.continuity.before_particle_push(mprts); pushp_.push_mprts(mprts, mflds); bndp_(mprts); bnd_.add_ghosts(mflds, JXI, JXI + 3); bnd_.fill_ghosts(mflds, JXI, JXI + 3); - checks_.continuity_after_particle_push(mprts, mflds); + checks_.continuity.after_particle_push(mprts, mflds); auto accessor = mprts.accessor(); for (auto prt : accessor[0]) { @@ -154,12 +154,12 @@ TYPED_TEST(PushParticlesTest, Cyclo) checks_params.continuity.print_max_err_always = false; Checks checks_{grid, MPI_COMM_WORLD, checks_params}; for (int n = 0; n < n_steps; n++) { - checks_.continuity_before_particle_push(mprts); + checks_.continuity.before_particle_push(mprts); pushp_.push_mprts(mprts, mflds); bndp_(mprts); bnd_.add_ghosts(mflds, JXI, JXI + 3); bnd_.fill_ghosts(mflds, JXI, JXI + 3); - checks_.continuity_after_particle_push(mprts, mflds); + checks_.continuity.after_particle_push(mprts, mflds); double ux = (cos(2 * M_PI * (0.125 * n_steps - (n + 1)) / (double)n_steps) / cos(2 * M_PI * (0.125 * n_steps) / (double)n_steps)); From a54e63b9008711801aa16538531291623393e094 Mon Sep 17 00:00:00 2001 From: James McClung Date: Thu, 3 Apr 2025 15:36:32 -0400 Subject: [PATCH 15/16] checks_impl; psc: go back to inheritance model Revert this if it's too unclear what's coming from where --- src/include/psc.hxx | 6 ++-- src/libpsc/psc_checks/checks_impl.hxx | 46 ++++++++++++--------------- 2 files changed, 24 insertions(+), 28 deletions(-) diff --git a/src/include/psc.hxx b/src/include/psc.hxx index 98e2ae04de..c96ba36c4c 100644 --- a/src/include/psc.hxx +++ b/src/include/psc.hxx @@ -489,7 +489,7 @@ struct Psc inject_particles(); prof_stop(pr_inject_prts); - if (checks_.continuity.params.should_do_check(timestep)) { + if (checks_.continuity.should_do_check(timestep)) { mpi_printf(comm, "***** Checking continuity...\n"); prof_start(pr_checks); checks_.continuity.before_particle_push(mprts_); @@ -557,7 +557,7 @@ struct Psc // state is now: x^{n+3/2}, p^{n+1}, E^{n+3/2}, B^{n+3/2} #endif - if (checks_.continuity.params.should_do_check(timestep)) { + if (checks_.continuity.should_do_check(timestep)) { prof_restart(pr_checks); checks_.continuity.after_particle_push(mprts_, mflds_); prof_stop(pr_checks); @@ -573,7 +573,7 @@ struct Psc prof_stop(pr_marder); } - if (checks_.gauss.params.should_do_check(timestep)) { + if (checks_.gauss.should_do_check(timestep)) { prof_restart(pr_checks); checks_.gauss(mprts_, mflds_); prof_stop(pr_checks); diff --git a/src/libpsc/psc_checks/checks_impl.hxx b/src/libpsc/psc_checks/checks_impl.hxx index cda8706388..4f6bdf1150 100644 --- a/src/libpsc/psc_checks/checks_impl.hxx +++ b/src/libpsc/psc_checks/checks_impl.hxx @@ -32,13 +32,15 @@ namespace checks // psc::checks::continuity: Charge Continuity template -class continuity +class continuity : public ContinuityCheckParams { public: using storage_type = S; using Item_rho = ITEM_RHO; - continuity(const ContinuityCheckParams& params) : params(params) {} + continuity(const ContinuityCheckParams& params) + : ContinuityCheckParams(params) + {} // ---------------------------------------------------------------------- // before_particle_push @@ -47,7 +49,7 @@ public: void before_particle_push(const Mparticles& mprts) { const auto& grid = mprts.grid(); - if (!params.should_do_check(grid.timestep())) { + if (!should_do_check(grid.timestep())) { return; } @@ -62,7 +64,7 @@ public: void after_particle_push(const Mparticles& mprts, MfieldsState& mflds) { const Grid_t& grid = mprts.grid(); - if (!params.should_do_check(grid.timestep())) { + if (!should_do_check(grid.timestep())) { return; } @@ -79,16 +81,16 @@ public: double max_err; MPI_Allreduce(&local_err, &max_err, 1, MPI_DOUBLE, MPI_MAX, grid.comm()); - if (params.should_print_diffs(max_err)) { - psc::helper::print_diff(d_rho, -dt_divj, params.err_threshold); + if (should_print_diffs(max_err)) { + psc::helper::print_diff(d_rho, -dt_divj, err_threshold); } - if (params.should_print_max_err(max_err)) { + if (should_print_max_err(max_err)) { mpi_printf(grid.comm(), "continuity: max_err = %g (thres %g)\n", max_err, - params.err_threshold); + err_threshold); } - if (params.should_dump(max_err)) { + if (should_dump(max_err)) { if (!writer_) { writer_.open("continuity"); } @@ -99,12 +101,9 @@ public: MPI_Barrier(grid.comm()); } - assert(max_err < params.err_threshold); + assert(max_err < err_threshold); } -public: - ContinuityCheckParams params; - private: storage_type rho_m_; WriterDefault writer_; @@ -114,13 +113,13 @@ private: // psc::checks::gauss: Gauss's Law div E = rho template -class gauss +class gauss : public GaussCheckParams { public: using storage_type = S; using Item_rho = ITEM_RHO; - gauss(const GaussCheckParams params) : params(params) {} + gauss(const GaussCheckParams params) : GaussCheckParams(params) {} // ---------------------------------------------------------------------- // operator() @@ -129,7 +128,7 @@ public: void operator()(Mparticles& mprts, MfieldsState& mflds) { const auto& grid = mprts.grid(); - if (!params.should_do_check(grid.timestep())) { + if (!should_do_check(grid.timestep())) { return; } @@ -156,8 +155,8 @@ public: double patch_err = gt::norm_linf(patch_dive - patch_rho); max_err = std::max(max_err, patch_err); - if (params.should_print_diffs(patch_err)) { - psc::helper::print_diff(patch_rho, patch_dive, params.err_threshold); + if (should_print_diffs(patch_err)) { + psc::helper::print_diff(patch_rho, patch_dive, err_threshold); } } @@ -165,12 +164,12 @@ public: double tmp = max_err; MPI_Allreduce(&tmp, &max_err, 1, MPI_DOUBLE, MPI_MAX, grid.comm()); - if (params.should_print_max_err(max_err)) { + if (should_print_max_err(max_err)) { mpi_printf(grid.comm(), "gauss: max_err = %g (thres %g)\n", max_err, - params.err_threshold); + err_threshold); } - if (params.should_dump(max_err)) { + if (should_dump(max_err)) { if (!writer_) { writer_.open("gauss"); } @@ -180,12 +179,9 @@ public: writer_.end_step(); } - assert(max_err < params.err_threshold); + assert(max_err < err_threshold); } -public: - GaussCheckParams params; - private: WriterDefault writer_; }; From 64bc4adf9e69f521a0c211eed32474db48797c30 Mon Sep 17 00:00:00 2001 From: James McClung Date: Thu, 3 Apr 2025 15:41:57 -0400 Subject: [PATCH 16/16] checks_impl: +last_max_err --- src/libpsc/psc_checks/checks_impl.hxx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/libpsc/psc_checks/checks_impl.hxx b/src/libpsc/psc_checks/checks_impl.hxx index 4f6bdf1150..33ddbe55eb 100644 --- a/src/libpsc/psc_checks/checks_impl.hxx +++ b/src/libpsc/psc_checks/checks_impl.hxx @@ -102,8 +102,12 @@ public: } assert(max_err < err_threshold); + last_max_err = max_err; } +public: + double last_max_err; + private: storage_type rho_m_; WriterDefault writer_; @@ -180,8 +184,12 @@ public: } assert(max_err < err_threshold); + last_max_err = max_err; } +public: + double last_max_err; + private: WriterDefault writer_; };