Skip to content

Commit

Permalink
WarpX class: moving initialization of warning manager to WarpXInit (#…
Browse files Browse the repository at this point in the history
…5579)

This PR moves the initialization of the warning manager from the very
large `ReadParameters` function of the WarpX class to a free function
inside `WarpXInit.H/cpp` . This function is now called by the
constructor of the WarpX class.

The final goal is to simplify the WarpX class.
  • Loading branch information
lucafedeli88 authored Feb 11, 2025
1 parent daabdd6 commit bc936fe
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 29 deletions.
9 changes: 7 additions & 2 deletions Source/Initialization/WarpXInit.H
Original file line number Diff line number Diff line change
Expand Up @@ -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 ();

/** Check that warpx.dims matches the binary name
*/
Expand Down
35 changes: 34 additions & 1 deletion Source/Initialization/WarpXInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@

#include <ablastr/math/fft/AnyFFT.H>
#include <ablastr/parallelization/MPIInitHelpers.H>
#include <ablastr/warn_manager/WarnManager.H>

#include <optional>
#include <string>

void warpx::initialization::initialize_external_libraries(int argc, char* argv[])
Expand All @@ -25,13 +27,44 @@ void warpx::initialization::initialize_external_libraries(int argc, char* 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<ablastr::warn_manager::WarnPriority> 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);
}
}

void warpx::initialization::check_dims()
{
// Ensure that geometry.dims is set properly.
Expand Down
28 changes: 2 additions & 26 deletions Source/WarpX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ WarpX::Finalize()

WarpX::WarpX ()
{
warpx::initialization::initialize_warning_manager();

ReadParameters();

BackwardCompatibility();
Expand Down Expand Up @@ -497,32 +499,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<ablastr::warn_manager::WarnPriority> 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<int> numprocs_in;
utils::parser::queryArrWithParser(
pp_warpx, "numprocs", numprocs_in, 0, AMREX_SPACEDIM);
Expand Down

0 comments on commit bc936fe

Please sign in to comment.