From a6f580999fa4a991c7a190f6f638b423a378de2c Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Mon, 20 Jan 2025 18:32:33 +0100 Subject: [PATCH 1/4] Move initialization of warning manager inside WarpXInit.H/cpp --- Source/Initialization/WarpXInit.H | 9 +++++-- Source/Initialization/WarpXInit.cpp | 41 +++++++++++++++++++++++++++-- 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/Source/Initialization/WarpXInit.H b/Source/Initialization/WarpXInit.H index ce179e2e997..5648d156c63 100644 --- a/Source/Initialization/WarpXInit.H +++ b/Source/Initialization/WarpXInit.H @@ -17,14 +17,19 @@ namespace warpx::initialization * @param[in] argc number of arguments from main() * @param[in] argv argument strings from main() */ - void initialize_external_libraries(int argc, char* argv[]); + void initialize_external_libraries (int argc, char* argv[]); /** Initializes, in the following order: * - the FFT library through the anyfft::cleanup() function in ablastr * - the AMReX library * - the MPI library through the mpi_finalize helper function in ablastr */ - void finalize_external_libraries(); + void finalize_external_libraries (); + + /** + * Initializes the Warning manager in ablastr + */ + void initialize_warning_manager (); } #endif //WARPX_INIT_H_ diff --git a/Source/Initialization/WarpXInit.cpp b/Source/Initialization/WarpXInit.cpp index 7e00760bf30..862f90c417d 100644 --- a/Source/Initialization/WarpXInit.cpp +++ b/Source/Initialization/WarpXInit.cpp @@ -8,22 +8,59 @@ #include "WarpXInit.H" #include "Initialization/WarpXAMReXInit.H" +#include "Utils/TextMsg.H" #include +#include #include #include +#include -void warpx::initialization::initialize_external_libraries(int argc, char* argv[]) +#include +#include + +void warpx::initialization::initialize_external_libraries (int argc, char* argv[]) { ablastr::parallelization::mpi_init(argc, argv); warpx::initialization::amrex_init(argc, argv); ablastr::math::anyfft::setup(); } -void warpx::initialization::finalize_external_libraries() +void warpx::initialization::finalize_external_libraries () { ablastr::math::anyfft::cleanup(); amrex::Finalize(); ablastr::parallelization::mpi_finalize(); } + +void warpx::initialization::initialize_warning_manager () +{ + const auto pp_warpx = amrex::ParmParse{"warpx"}; + + //"Synthetic" warning messages may be injected in the Warning Manager via + // inputfile for debug&testing purposes. + ablastr::warn_manager::GetWMInstance().debug_read_warnings_from_input(pp_warpx); + + // Set the flag to control if WarpX has to emit a warning message as soon as a warning is recorded + bool always_warn_immediately = false; + pp_warpx.query("always_warn_immediately", always_warn_immediately); + ablastr::warn_manager::GetWMInstance().SetAlwaysWarnImmediately(always_warn_immediately); + + // Set the WarnPriority threshold to decide if WarpX has to abort when a warning is recorded + if(std::string str_abort_on_warning_threshold; + pp_warpx.query("abort_on_warning_threshold", str_abort_on_warning_threshold)){ + std::optional abort_on_warning_threshold = std::nullopt; + if (str_abort_on_warning_threshold == "high") { + abort_on_warning_threshold = ablastr::warn_manager::WarnPriority::high; + } else if (str_abort_on_warning_threshold == "medium" ) { + abort_on_warning_threshold = ablastr::warn_manager::WarnPriority::medium; + } else if (str_abort_on_warning_threshold == "low") { + abort_on_warning_threshold = ablastr::warn_manager::WarnPriority::low; + } else { + WARPX_ABORT_WITH_MESSAGE(str_abort_on_warning_threshold + +"is not a valid option for warpx.abort_on_warning_threshold (use: low, medium or high)"); + } + ablastr::warn_manager::GetWMInstance().SetAbortThreshold(abort_on_warning_threshold); + } +} From 5acec0534ec8847fc1b30da871893054e3afb2d8 Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Mon, 20 Jan 2025 18:36:24 +0100 Subject: [PATCH 2/4] add missing file --- Source/WarpX.cpp | 30 ++++-------------------------- 1 file changed, 4 insertions(+), 26 deletions(-) diff --git a/Source/WarpX.cpp b/Source/WarpX.cpp index bd193f11bdc..ebdb995a476 100644 --- a/Source/WarpX.cpp +++ b/Source/WarpX.cpp @@ -256,6 +256,8 @@ WarpX::Finalize() WarpX::WarpX () { + warpx::initialization::initialize_warning_manager(); + ReadParameters(); BackwardCompatibility(); @@ -465,6 +467,8 @@ WarpX::~WarpX () void WarpX::ReadParameters () { + namespace winit = warpx::initialization; + // Ensure that geometry.dims is set properly. CheckDims(); @@ -493,32 +497,6 @@ WarpX::ReadParameters () { ParmParse const pp_warpx("warpx"); - //"Synthetic" warning messages may be injected in the Warning Manager via - // inputfile for debug&testing purposes. - ablastr::warn_manager::GetWMInstance().debug_read_warnings_from_input(pp_warpx); - - // Set the flag to control if WarpX has to emit a warning message as soon as a warning is recorded - bool always_warn_immediately = false; - pp_warpx.query("always_warn_immediately", always_warn_immediately); - ablastr::warn_manager::GetWMInstance().SetAlwaysWarnImmediately(always_warn_immediately); - - // Set the WarnPriority threshold to decide if WarpX has to abort when a warning is recorded - if(std::string str_abort_on_warning_threshold; - pp_warpx.query("abort_on_warning_threshold", str_abort_on_warning_threshold)){ - std::optional abort_on_warning_threshold = std::nullopt; - if (str_abort_on_warning_threshold == "high") { - abort_on_warning_threshold = ablastr::warn_manager::WarnPriority::high; - } else if (str_abort_on_warning_threshold == "medium" ) { - abort_on_warning_threshold = ablastr::warn_manager::WarnPriority::medium; - } else if (str_abort_on_warning_threshold == "low") { - abort_on_warning_threshold = ablastr::warn_manager::WarnPriority::low; - } else { - WARPX_ABORT_WITH_MESSAGE(str_abort_on_warning_threshold - +"is not a valid option for warpx.abort_on_warning_threshold (use: low, medium or high)"); - } - ablastr::warn_manager::GetWMInstance().SetAbortThreshold(abort_on_warning_threshold); - } - std::vector numprocs_in; utils::parser::queryArrWithParser( pp_warpx, "numprocs", numprocs_in, 0, AMREX_SPACEDIM); From 0e128d6fba070a69658e643aa0c7356839ba4648 Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Mon, 20 Jan 2025 18:39:32 +0100 Subject: [PATCH 3/4] fix bug --- Source/WarpX.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/WarpX.cpp b/Source/WarpX.cpp index ebdb995a476..075c8f9cede 100644 --- a/Source/WarpX.cpp +++ b/Source/WarpX.cpp @@ -36,6 +36,7 @@ #include "FieldSolver/WarpX_FDTD.H" #include "Filter/NCIGodfreyFilter.H" #include "Initialization/ExternalField.H" +#include "Initialization/WarpXInit.H" #include "Particles/MultiParticleContainer.H" #include "Fluids/MultiFluidContainer.H" #include "Fluids/WarpXFluidContainer.H" From 3f011b10d5d2d589e8fb48675fdc575848b16a67 Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Tue, 21 Jan 2025 12:17:07 +0100 Subject: [PATCH 4/4] remove unused alias (thanks, clang-tidy) --- Source/WarpX.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/Source/WarpX.cpp b/Source/WarpX.cpp index 075c8f9cede..2de0753d035 100644 --- a/Source/WarpX.cpp +++ b/Source/WarpX.cpp @@ -468,8 +468,6 @@ WarpX::~WarpX () void WarpX::ReadParameters () { - namespace winit = warpx::initialization; - // Ensure that geometry.dims is set properly. CheckDims();