Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WarpX class: moving initialization of warning manager to WarpXInit #5579

Open
wants to merge 4 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
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 ();
}

#endif //WARPX_INIT_H_
41 changes: 39 additions & 2 deletions Source/Initialization/WarpXInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,59 @@
#include "WarpXInit.H"

#include "Initialization/WarpXAMReXInit.H"
#include "Utils/TextMsg.H"

#include <AMReX.H>
#include <AMReX_ParmParse.H>

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

void warpx::initialization::initialize_external_libraries(int argc, char* argv[])
#include <optional>
#include <string>

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<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);
}
}
29 changes: 3 additions & 26 deletions Source/WarpX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -256,6 +257,8 @@ WarpX::Finalize()

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

ReadParameters();

BackwardCompatibility();
Expand Down Expand Up @@ -493,32 +496,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
Loading