diff options
author | 2021-10-20 21:02:22 +0200 | |
---|---|---|
committer | 2021-10-20 19:02:22 +0000 | |
commit | 02096d079680a2f7125db230bcde872dde63732c (patch) | |
tree | 14064a6a0b029a16f77ad357772546334e841867 /Source/WarpX.cpp | |
parent | c3f481bca813d834e248d1adeb5b5a02495b9e1a (diff) | |
download | WarpX-02096d079680a2f7125db230bcde872dde63732c.tar.gz WarpX-02096d079680a2f7125db230bcde872dde63732c.tar.zst WarpX-02096d079680a2f7125db230bcde872dde63732c.zip |
⚠️ Add warning logger (#2113)
* improve error msg
* eliminate final dot
* initial layout of the main classes
* progress
* progress with warnings
* print local errors
* progress with warning logger
* improved MsgLogger
* added file to test warnings
* added method to read debug warnings from inputfile
* progress towards collective gather of warnings
* add missing blank line in warning message
* move misplaced file
* refactoring
* fixed bugs
* progress
* fixed bugs
* fixed some bugs
* it finally works!
* add comments in WarpX.H
* add missing comment
* added comments to WarpX.cpp
* add profiler to WarpX.cpp
* expose option to enable 'warn immediately' feature in cmake
* Add comment to main.cpp
* add missing comment in WarpX.cpp
* add copyright and include guards to WarnManager_fwd.H
* cleaning and added comments to WarnManager.H
* updated test
* added fwd file for MsgLogger
* cleaning
* Added copyright in WarnManager.cpp
* Cleaning
* cleaning
* Add missing copyright
* cleaning
* clean and add comments to MsgLoggerSerialization.H
* cleaning MsgLogger_fwd.H
* cleaning
* continue cleaning MsgLogger
* added comments & bugfixing
* removed test file
* fixed bugs
* Update Source/Utils/MsgLogger/MsgLogger.H
Co-authored-by: Neïl Zaim <49716072+NeilZaim@users.noreply.github.com>
* Update Source/WarpX.H
Co-authored-by: Neïl Zaim <49716072+NeilZaim@users.noreply.github.com>
* Update Source/Utils/MsgLogger/MsgLogger.H
Co-authored-by: Neïl Zaim <49716072+NeilZaim@users.noreply.github.com>
* Update Source/Utils/MsgLogger/MsgLogger.H
Co-authored-by: Neïl Zaim <49716072+NeilZaim@users.noreply.github.com>
* Update Source/Utils/MsgLogger/MsgLogger.cpp
Co-authored-by: Neïl Zaim <49716072+NeilZaim@users.noreply.github.com>
* Update Source/Utils/MsgLogger/MsgLoggerSerialization.H
Co-authored-by: Neïl Zaim <49716072+NeilZaim@users.noreply.github.com>
* Update Source/Utils/MsgLogger/MsgLoggerSerialization.H
Co-authored-by: Neïl Zaim <49716072+NeilZaim@users.noreply.github.com>
* Update Source/Utils/MsgLogger/MsgLoggerSerialization.H
Co-authored-by: Neïl Zaim <49716072+NeilZaim@users.noreply.github.com>
* Update Source/Utils/MsgLogger/MsgLoggerSerialization.H
Co-authored-by: Neïl Zaim <49716072+NeilZaim@users.noreply.github.com>
* Update Source/Utils/MsgLogger/MsgLoggerSerialization.H
Co-authored-by: Neïl Zaim <49716072+NeilZaim@users.noreply.github.com>
* Update Source/Utils/WarnManager.cpp
Co-authored-by: Neïl Zaim <49716072+NeilZaim@users.noreply.github.com>
* Update Source/Utils/WarnManager.H
Co-authored-by: Neïl Zaim <49716072+NeilZaim@users.noreply.github.com>
* Update Source/Utils/WarnManager.H
Co-authored-by: Neïl Zaim <49716072+NeilZaim@users.noreply.github.com>
* Update Source/Utils/WarnManager.cpp
Co-authored-by: Neïl Zaim <49716072+NeilZaim@users.noreply.github.com>
* fixed bugs
* Update Source/Utils/MsgLogger/MsgLogger.cpp
Co-authored-by: Neïl Zaim <49716072+NeilZaim@users.noreply.github.com>
* Added comment to explain rotation
* use last value computed by partial_sum
* fix bug
* now use error stream
* using anonymous namespace for helper functions
* print on both stderr and stdout
* now using runtime parameter to always print warnings
* added documentation
* using long int for counter
* sort affected warnings list
* add doc entry
* removed doc
* added documentation
* fixed bug
* fixed bug
* removing unnecessary text
* reformatting
* reformatting
* fixed bug
* fixed bug
* correction
* add warning_logger.rst to toctree in developers.rst
Co-authored-by: Neïl Zaim <49716072+NeilZaim@users.noreply.github.com>
Diffstat (limited to 'Source/WarpX.cpp')
-rw-r--r-- | Source/WarpX.cpp | 82 |
1 files changed, 72 insertions, 10 deletions
diff --git a/Source/WarpX.cpp b/Source/WarpX.cpp index 7f620e515..acc6e5844 100644 --- a/Source/WarpX.cpp +++ b/Source/WarpX.cpp @@ -29,8 +29,11 @@ #include "Filter/NCIGodfreyFilter.H" #include "Particles/MultiParticleContainer.H" #include "Particles/ParticleBoundaryBuffer.H" +#include "Utils/MsgLogger/MsgLogger.H" +#include "Utils/WarnManager.H" #include "Utils/WarpXAlgorithmSelection.H" #include "Utils/WarpXConst.H" +#include "Utils/WarpXProfilerWrapper.H" #include "Utils/WarpXUtil.H" #ifdef AMREX_USE_SENSEI_INSITU @@ -216,6 +219,9 @@ WarpX::ResetInstance () WarpX::WarpX () { m_instance = this; + + m_p_warn_manager = std::make_unique<Utils::WarnManager>(); + ReadParameters(); BackwardCompatibility(); @@ -410,6 +416,51 @@ WarpX::~WarpX () } void +WarpX::RecordWarning( + std::string topic, + std::string text, + WarnPriority priority) +{ + WARPX_PROFILE("WarpX::RecordWarning"); + + auto msg_priority = Utils::MsgLogger::Priority::high; + if(priority == WarnPriority::low) + msg_priority = Utils::MsgLogger::Priority::low; + else if(priority == WarnPriority::medium) + msg_priority = Utils::MsgLogger::Priority::medium; + + if(m_always_warn_immediately){ + amrex::Warning( + "!!!!!! WARNING: [" + + std::string(Utils::MsgLogger::PriorityToString(msg_priority)) + + "][" + topic + "] " + text); + } + +#ifdef AMREX_USE_OMP + #pragma omp critical +#endif + { + m_p_warn_manager->record_warning(topic, text, msg_priority); + } +} + +void +WarpX::PrintLocalWarnings(const std::string& when) +{ + WARPX_PROFILE("WarpX::PrintLocalWarnings"); + const auto warn_string = m_p_warn_manager->print_local_warnings(when); + amrex::AllPrint() << warn_string; +} + +void +WarpX::PrintGlobalWarnings(const std::string& when) +{ + WARPX_PROFILE("WarpX::PrintGlobalWarnings"); + const auto warn_string = m_p_warn_manager->print_global_warnings(when); + amrex::Print() << warn_string; +} + +void WarpX::ReadParameters () { { @@ -433,6 +484,11 @@ WarpX::ReadParameters () { ParmParse pp_warpx("warpx"); + //"Synthetic" warning messages may be injected in the Warning Manager via + // inputfile for debug&testing purposes. + m_p_warn_manager->debug_read_warnings_from_input(pp_warpx); + pp_warpx.query("always_warn_immediately", m_always_warn_immediately); + std::vector<int> numprocs_in; queryArrWithParser(pp_warpx, "numprocs", numprocs_in, 0, AMREX_SPACEDIM); if (not numprocs_in.empty()) { @@ -620,10 +676,9 @@ WarpX::ReadParameters () // (see https://github.com/ECP-WarpX/WarpX/issues/1943) if (use_filter) { - amrex::Print() << "\nWARNING:" - << "\nFilter currently not working with FDTD solver in RZ geometry:" - << "\nwe recommend setting warpx.use_filter = 0 in the input file.\n" - << std::endl; + this->RecordWarning("Filter", + "Filter currently not working with FDTD solver in RZ geometry." + "We recommend setting warpx.use_filter = 0 in the input file."); } } #endif @@ -904,9 +959,10 @@ WarpX::ReadParameters () if ((maxLevel() > 0) && (particle_shape > 1) && (do_pml_j_damping == 1)) { - amrex::Warning("\nWARNING: When algo.particle_shape > 1," - " some numerical artifact will be present at the interface between coarse and fine patch." - "\nWe recommend setting algo.particle_shape = 1 in order to avoid this issue"); + this->RecordWarning("Particles", + "When algo.particle_shape > 1," + "some numerical artifact will be present at the interface between coarse and fine patch." + "We recommend setting algo.particle_shape = 1 in order to avoid this issue"); } // default sort interval for particles if species or lasers vector is not empty @@ -1279,17 +1335,23 @@ WarpX::BackwardCompatibility () ParmParse pp_particles("particles"); int nspecies; if (pp_particles.query("nspecies", nspecies)){ - amrex::Print()<<"particles.nspecies is ignored. Just use particles.species_names please.\n"; + this->RecordWarning("Species", + "particles.nspecies is ignored. Just use particles.species_names please.", + WarnPriority::low); } ParmParse pp_collisions("collisions"); int ncollisions; if (pp_collisions.query("ncollisions", ncollisions)){ - amrex::Print()<<"collisions.ncollisions is ignored. Just use particles.collision_names please.\n"; + this->RecordWarning("Collisions", + "collisions.ncollisions is ignored. Just use particles.collision_names please.", + WarnPriority::low); } ParmParse pp_lasers("lasers"); int nlasers; if (pp_lasers.query("nlasers", nlasers)){ - amrex::Print()<<"lasers.nlasers is ignored. Just use lasers.names please.\n"; + this->RecordWarning("Laser", + "lasers.nlasers is ignored. Just use lasers.names please.", + WarnPriority::low); } } |