From fd643be22a8ab9ae2114b7815bd1f3222ae553e4 Mon Sep 17 00:00:00 2001 From: Cyrus Wyett <34195737+cjwyett@users.noreply.github.com> Date: Mon, 3 Aug 2020 17:17:15 +0100 Subject: [PATCH 01/24] Solve issue #1365 Added link to docs --- src/tallies/tally.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tallies/tally.cpp b/src/tallies/tally.cpp index ecdf92613..3e7763482 100644 --- a/src/tallies/tally.cpp +++ b/src/tallies/tally.cpp @@ -240,10 +240,10 @@ score_str_to_int(std::string score_str) try { MT = std::stoi(score_str); } catch (const std::invalid_argument& ex) { - throw std::invalid_argument("Invalid tally score \"" + score_str + "\""); + throw std::invalid_argument("Invalid tally score \"" + score_str + "\ See the docs for more detail: https://docs.openmc.org/en/latest/usersguide/tallies.html#scores\"); } if (MT < 1) - throw std::invalid_argument("Invalid tally score \"" + score_str + "\""); + throw std::invalid_argument("Invalid tally score \"" + score_str + "\ See the docs for more detail: https://docs.openmc.org/en/latest/usersguide/tallies.html#scores\"); return MT; } From 518f352a08fbb0cd7749ef5af828a0f394886234 Mon Sep 17 00:00:00 2001 From: Cyrus Wyett <34195737+cjwyett@users.noreply.github.com> Date: Mon, 3 Aug 2020 18:02:37 +0100 Subject: [PATCH 02/24] hopefully --- src/tallies/tally.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tallies/tally.cpp b/src/tallies/tally.cpp index 3e7763482..c7e043e89 100644 --- a/src/tallies/tally.cpp +++ b/src/tallies/tally.cpp @@ -240,10 +240,10 @@ score_str_to_int(std::string score_str) try { MT = std::stoi(score_str); } catch (const std::invalid_argument& ex) { - throw std::invalid_argument("Invalid tally score \"" + score_str + "\ See the docs for more detail: https://docs.openmc.org/en/latest/usersguide/tallies.html#scores\"); + throw std::invalid_argument("Invalid tally score \"" + score_str + "\" See the docs for details: https://docs.openmc.org/en/latest/usersguide/tallies.html#scores"); } if (MT < 1) - throw std::invalid_argument("Invalid tally score \"" + score_str + "\ See the docs for more detail: https://docs.openmc.org/en/latest/usersguide/tallies.html#scores\"); + throw std::invalid_argument("Invalid tally score \"" + score_str + "\" See the docs for details: https://docs.openmc.org/en/latest/usersguide/tallies.html#scores"); return MT; } From 585ec0fc860ad1508ed605d7ebe5b12598e7599b Mon Sep 17 00:00:00 2001 From: Cyrus Wyett <34195737+cjwyett@users.noreply.github.com> Date: Tue, 4 Aug 2020 13:59:24 +0100 Subject: [PATCH 03/24] Update src/tallies/tally.cpp Brilliant! Thanks. Co-authored-by: Paul Romano --- src/tallies/tally.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/tallies/tally.cpp b/src/tallies/tally.cpp index c7e043e89..533f931f1 100644 --- a/src/tallies/tally.cpp +++ b/src/tallies/tally.cpp @@ -243,7 +243,8 @@ score_str_to_int(std::string score_str) throw std::invalid_argument("Invalid tally score \"" + score_str + "\" See the docs for details: https://docs.openmc.org/en/latest/usersguide/tallies.html#scores"); } if (MT < 1) - throw std::invalid_argument("Invalid tally score \"" + score_str + "\" See the docs for details: https://docs.openmc.org/en/latest/usersguide/tallies.html#scores"); + throw std::invalid_argument("Invalid tally score \"" + score_str + "\". See the docs " + "for details: https://docs.openmc.org/en/stable/usersguide/tallies.html#scores"); return MT; } From ceb8ade044850cfac533cd506ac043ce8939a27f Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Tue, 4 Aug 2020 11:09:38 -0500 Subject: [PATCH 04/24] Check for existence of decay_rate attribute --- src/reaction_product.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/reaction_product.cpp b/src/reaction_product.cpp index 495e4dfa5..6a3b231cc 100644 --- a/src/reaction_product.cpp +++ b/src/reaction_product.cpp @@ -3,7 +3,10 @@ #include // for unique_ptr #include // for string +#include + #include "openmc/endf.h" +#include "openmc/error.h" #include "openmc/hdf5_interface.h" #include "openmc/particle.h" #include "openmc/random_lcg.h" @@ -36,8 +39,14 @@ ReactionProduct::ReactionProduct(hid_t group) } // Read decay rate for delayed emission - if (emission_mode_ == EmissionMode::delayed) - read_attribute(group, "decay_rate", decay_rate_); + if (emission_mode_ == EmissionMode::delayed) { + if (attribute_exists(group, "decay_rate")) { + read_attribute(group, "decay_rate", decay_rate_); + } else if (particle_ == Particle::Type::neutron) { + warning(fmt::format("Decay rate doesn't exist for delayed neutron " + "emission ({}).", object_name(group))); + } + } // Read secondary particle yield yield_ = read_function(group, "yield"); From 4b0c9eac77ca3da5d50a1bd5e85c61729e31d9c1 Mon Sep 17 00:00:00 2001 From: Cyrus Wyett <34195737+cjwyett@users.noreply.github.com> Date: Tue, 4 Aug 2020 19:07:07 +0100 Subject: [PATCH 05/24] Update src/tallies/tally.cpp Co-authored-by: Paul Romano --- src/tallies/tally.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/tallies/tally.cpp b/src/tallies/tally.cpp index 533f931f1..5619c669c 100644 --- a/src/tallies/tally.cpp +++ b/src/tallies/tally.cpp @@ -240,7 +240,8 @@ score_str_to_int(std::string score_str) try { MT = std::stoi(score_str); } catch (const std::invalid_argument& ex) { - throw std::invalid_argument("Invalid tally score \"" + score_str + "\" See the docs for details: https://docs.openmc.org/en/latest/usersguide/tallies.html#scores"); + throw std::invalid_argument("Invalid tally score \"" + score_str + "\". See the docs " + "for details: https://docs.openmc.org/en/stable/usersguide/tallies.html#scores"); } if (MT < 1) throw std::invalid_argument("Invalid tally score \"" + score_str + "\". See the docs " From a5ef3dc405bce9f84d2435be351225e100cb3ea8 Mon Sep 17 00:00:00 2001 From: Sterling Harper Date: Wed, 5 Aug 2020 18:34:12 -0400 Subject: [PATCH 06/24] Sample source sites in parallel --- src/source.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/source.cpp b/src/source.cpp index 3f31541db..2ee8ecf13 100644 --- a/src/source.cpp +++ b/src/source.cpp @@ -292,6 +292,7 @@ void initialize_source() } else { // Generation source sites from specified distribution in user input + #pragma omp parallel for for (int64_t i = 0; i < simulation::work_per_rank; ++i) { // initialize random number seed int64_t id = simulation::total_gen*settings::n_particles + From b6276ea9e4ca82592230a8f3910f05fbb442fb9f Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Sun, 2 Aug 2020 22:10:26 -0400 Subject: [PATCH 07/24] Reduce number of string concats with fmt::format --- src/mgxs_interface.cpp | 13 ++++++------- src/particle.cpp | 10 +++++----- src/plot.cpp | 2 +- src/simulation.cpp | 4 +++- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/mgxs_interface.cpp b/src/mgxs_interface.cpp index 936eeb31f..7ad07d0c9 100644 --- a/src/mgxs_interface.cpp +++ b/src/mgxs_interface.cpp @@ -3,6 +3,8 @@ #include #include +#include + #include "openmc/cell.h" #include "openmc/cross_sections.h" #include "openmc/container_util.h" @@ -57,8 +59,7 @@ void MgxsInterface::init() // Check if MGXS Library exists if (!file_exists(cross_sections_path_)) { // Could not find MGXS Library file - fatal_error("Cross sections HDF5 file '" + cross_sections_path_ + - "' does not exist."); + fatal_error(fmt::format("Cross sections HDF5 file '{}' does not exist!", cross_sections_path_)); } write_message("Loading cross section data...", 5); @@ -98,15 +99,14 @@ void MgxsInterface::add_mgxs(hid_t file_id, const std::string& name, const std::vector& temperature) { - write_message("Loading " + std::string(name) + " data...", 6); + write_message(fmt::format("Loading {} data...", name), 6); // Check to make sure cross section set exists in the library hid_t xs_grp; if (object_exists(file_id, name.c_str())) { xs_grp = open_group(file_id, name.c_str()); } else { - fatal_error("Data for " + std::string(name) + " does not exist in " - + "provided MGXS Library"); + fatal_error(fmt::format("Data for {} does not exist in provided MGXS Library", name)); } nuclides_.emplace_back(xs_grp, temperature, num_energy_groups_, @@ -187,8 +187,7 @@ void MgxsInterface::read_header(const std::string& path_cross_sections) // Check if MGXS Library exists if (!file_exists(cross_sections_path_)) { // Could not find MGXS Library file - fatal_error("Cross sections HDF5 file '" + cross_sections_path_ + - "' does not exist."); + fatal_error(fmt::format("Cross section HDF5 file '{}' does not exist", cross_sections_path_)); } write_message("Reading cross sections HDF5 file...", 5); diff --git a/src/particle.cpp b/src/particle.cpp index ae75d91b4..3916eacba 100644 --- a/src/particle.cpp +++ b/src/particle.cpp @@ -410,7 +410,7 @@ Particle::cross_surface() // TODO: off-by-one const auto& surf {model::surfaces[i_surface - 1].get()}; if (settings::verbosity >= 10 || trace_) { - write_message(" Crossing surface " + std::to_string(surf->id_)); + write_message(fmt::format(" Crossing surface {}", surf->id_)); } if (surf->bc_ == Surface::BoundaryType::VACUUM && (settings::run_mode != RunMode::PLOTTING)) { @@ -437,7 +437,7 @@ Particle::cross_surface() // Display message if (settings::verbosity >= 10 || trace_) { - write_message(" Leaked out of surface " + std::to_string(surf->id_)); + write_message(fmt::format(" Leaked out of surface {}", surf->id_)); } return; @@ -502,7 +502,7 @@ Particle::cross_surface() // Diagnostic message if (settings::verbosity >= 10 || trace_) { - write_message(" Reflected from surface " + std::to_string(surf->id_)); + write_message(fmt::format(" Reflected from surface {}", surf->id_)); } return; @@ -556,8 +556,8 @@ Particle::cross_surface() // Diagnostic message if (settings::verbosity >= 10 || trace_) { - write_message(" Hit periodic boundary on surface " + - std::to_string(surf->id_)); + write_message(fmt::format(" Hit periodic boundary on surface {}", + surf->id_)); } return; } diff --git a/src/plot.cpp b/src/plot.cpp index e2fe5abde..267810712 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -114,7 +114,7 @@ void read_plots_xml() // Check if plots.xml exists std::string filename = settings::path_input + "plots.xml"; if (!file_exists(filename)) { - fatal_error("Plots XML file '" + filename + "' does not exist!"); + fatal_error(fmt::format("Plots XML file '{}' does not exist!", filename)); } write_message("Reading plot XML file...", 5); diff --git a/src/simulation.cpp b/src/simulation.cpp index 1b39c1329..92cee64cd 100644 --- a/src/simulation.cpp +++ b/src/simulation.cpp @@ -33,6 +33,8 @@ #include #endif +#include + #include #include #include @@ -500,7 +502,7 @@ void initialize_history(Particle& p, int64_t index_source) // Display message if high verbosity or trace is on if (settings::verbosity >= 9 || p.trace_) { - write_message("Simulating Particle " + std::to_string(p.id_)); + write_message(fmt::format("Simulating Particle {}", p.id_)); } // Add paricle's starting weight to count for normalizing tallies later From cf763e2477720df7847efc45d4c914a0efbbfcf5 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Sun, 2 Aug 2020 22:10:59 -0400 Subject: [PATCH 08/24] Add templated write_message for formatting messages This new function lives inside include/openmc/error.h and checks if a message will be written by checking the current verbosity level prior to formatting the message. This works very similar to python logging modules and the spdlog project, where the call to the logging function accepts a formattable message string and the format arguments separately, e.g. write_message(1, "Writing data for statepoint {}", point) The function accepts any number and type of argument after the format message and passes directly to fmt::format and in-turn to the non-templated write_message. While this later function does similar checking with the level and MPI rank, the real goal is the output function in src/error.cpp which is not currently exposed through the error header file Thanks to @paulromano for feedback and suggestions --- include/openmc/error.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/include/openmc/error.h b/include/openmc/error.h index 32ed36c8b..4c4efe6a7 100644 --- a/include/openmc/error.h +++ b/include/openmc/error.h @@ -5,7 +5,10 @@ #include #include +#include + #include "openmc/capi.h" +#include "openmc/settings.h" #ifdef __GNUC__ #define UNREACHABLE() __builtin_unreachable() @@ -63,6 +66,21 @@ void write_message(const std::stringstream& message, int level) write_message(message.str(), level); } +template +void write_message( + int level, const std::string& message, const Params&... fmt_args) +{ + if (settings::verbosity >= level) { + write_message(fmt::format(message, fmt_args...)); + } +} + +template +void write_message(const std::string& message, const Params&... fmt_args) +{ + write_message(fmt::format(message, fmt_args...)); +} + #ifdef OPENMC_MPI extern "C" void abort_mpi(int code); #endif From 2113c4c06b67389f40eb54d4c57eb09769135896 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Sun, 2 Aug 2020 22:11:50 -0400 Subject: [PATCH 09/24] Apply templated write_message to cross_sections.cpp --- src/cross_sections.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/cross_sections.cpp b/src/cross_sections.cpp index c06a11924..b82a690e6 100644 --- a/src/cross_sections.cpp +++ b/src/cross_sections.cpp @@ -228,7 +228,7 @@ read_ce_cross_sections(const std::vector>& nuc_temps, int idx = data::library_map[key]; std::string& filename = data::libraries[idx].path_; - write_message("Reading " + name + " from " + filename, 6); + write_message(6, "Reading {} from {}", name, filename); // Open file and make sure version matches hid_t file_id = file_open(filename, 'r'); @@ -256,10 +256,8 @@ read_ce_cross_sections(const std::vector>& nuc_temps, } // Show minimum/maximum temperature - write_message("Minimum neutron data temperature: " + - std::to_string(data::temperature_min) + " K", 4); - write_message("Maximum neutron data temperature: " + - std::to_string(data::temperature_max) + " K", 4); + write_message(4, "Minimum neutron data temperature: {} K", data::temperature_min); + write_message(4, "Maximum neutron data temperature: {} K", data::temperature_max); // If the user wants multipole, make sure we found a multipole library. if (settings::temperature_multipole) { From 1ae1d9dc8f24380d54f4f3e2b8bbf9a60d3343d3 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Sun, 2 Aug 2020 22:11:51 -0400 Subject: [PATCH 10/24] Apply templated write_message to mesh.cpp --- src/mesh.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mesh.cpp b/src/mesh.cpp index 4954ca373..82bacdcf5 100644 --- a/src/mesh.cpp +++ b/src/mesh.cpp @@ -2051,7 +2051,7 @@ void UnstructuredMesh::write(std::string base_filename) const { // add extension to the base name auto filename = base_filename + ".vtk"; - write_message("Writing unstructured mesh " + filename + "...", 5); + write_message(5, "Writing unstructured mesh {}...", filename); filename = settings::path_output + filename; // write the tetrahedral elements of the mesh only From 4feb40364696a02853ae783959f0507fbe3308ec Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Sun, 2 Aug 2020 22:11:51 -0400 Subject: [PATCH 11/24] Apply templated write_message to nuclide.cpp --- src/nuclide.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/nuclide.cpp b/src/nuclide.cpp index 59e5f6e8c..0a0e40057 100644 --- a/src/nuclide.cpp +++ b/src/nuclide.cpp @@ -944,7 +944,7 @@ extern "C" int openmc_load_nuclide(const char* name, const double* temps, int n) // Get filename for library containing nuclide int idx = it->second; const auto& filename = data::libraries[idx].path_; - write_message("Reading " + std::string{name} + " from " + filename, 6); + write_message(6, "Reading {} from {}", std::string{name}, filename); // Open file and make sure version is sufficient hid_t file_id = file_open(filename, 'r'); @@ -977,7 +977,7 @@ extern "C" int openmc_load_nuclide(const char* name, const double* temps, int n) int idx = it->second; const auto& filename = data::libraries[idx].path_; - write_message("Reading " + element + " from " + filename, 6); + write_message(6, "Reading {} from {} ", element, filename); // Open file and make sure version is sufficient hid_t file_id = file_open(filename, 'r'); From a6c9f173a4bde3b5d296e9a0d37e293260e60fab Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Sun, 2 Aug 2020 22:11:51 -0400 Subject: [PATCH 12/24] Apply templated write_message to particle_restart.cpp --- src/particle_restart.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/particle_restart.cpp b/src/particle_restart.cpp index b0f739bd0..be9eda77f 100644 --- a/src/particle_restart.cpp +++ b/src/particle_restart.cpp @@ -24,8 +24,7 @@ namespace openmc { void read_particle_restart(Particle& p, RunMode& previous_run_mode) { // Write meessage - write_message("Loading particle restart file " + - settings::path_particle_restart + "...", 5); + write_message(5, "Loading particle restart file {}", settings::path_particle_restart); // Open file hid_t file_id = file_open(settings::path_particle_restart, 'r'); From 697f8c77eb4ddae0982e2c9957ee299d6b2b36b6 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Sun, 2 Aug 2020 22:11:51 -0400 Subject: [PATCH 13/24] Apply templated write_message to plot.cpp --- src/plot.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/plot.cpp b/src/plot.cpp index 267810712..283207a42 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -94,8 +94,7 @@ extern "C" int openmc_plot_geometry() { for (auto pl : model::plots) { - write_message(fmt::format("Processing plot {}: {}...", - pl.id_, pl.path_plot_), 5); + write_message(5, "Processing plot {}: {}...", pl.id_, pl.path_plot_); if (PlotType::slice == pl.type_) { // create 2D image From 9bb219af8eb12cbb128a78870e54c2bfd7b81697 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Sun, 2 Aug 2020 22:11:52 -0400 Subject: [PATCH 14/24] Apply templated write_message to simulation.cpp --- src/simulation.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/simulation.cpp b/src/simulation.cpp index 92cee64cd..def9cee5d 100644 --- a/src/simulation.cpp +++ b/src/simulation.cpp @@ -307,8 +307,7 @@ void initialize_batch() ++simulation::current_batch; if (settings::run_mode == RunMode::FIXED_SOURCE) { - int b = simulation::current_batch; - write_message("Simulating batch " + std::to_string(b), 6); + write_message(6, "Simulating batch {}", simulation::current_batch); } // Reset total starting particle weight used for normalizing tallies @@ -612,9 +611,8 @@ void initialize_data() double max_E = nuc->grid_[0].energy.back(); int neutron = static_cast(Particle::Type::neutron); if (max_E == data::energy_max[neutron]) { - write_message("Maximum neutron transport energy: " + - std::to_string(data::energy_max[neutron]) + " eV for " + - nuc->name_, 7); + write_message(7, "Maximum neutron transport energy: {} eV for {}", + data::energy_max[neutron], nuc->name_); if (mpi::master && data::energy_max[neutron] < 20.0e6) { warning("Maximum neutron energy is below 20 MeV. This may bias " "the results."); From bd76dbd9a2b58b70f8ca4b611ee26aeb2abe1b2c Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Sun, 2 Aug 2020 22:11:52 -0400 Subject: [PATCH 15/24] Apply templated write_message to source.cpp --- src/source.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/source.cpp b/src/source.cpp index 3f31541db..7e9b16859 100644 --- a/src/source.cpp +++ b/src/source.cpp @@ -263,8 +263,7 @@ void initialize_source() // Read the source from a binary file instead of sampling from some // assumed source distribution - write_message(fmt::format("Reading source file from {}...", - settings::path_source), 6); + write_message(6, "Reading source file from {}...", settings::path_source); // Open the binary file hid_t file_id = file_open(settings::path_source, 'r', true); @@ -285,8 +284,7 @@ void initialize_source() file_close(file_id); } else if (!settings::path_source_library.empty()) { - write_message(fmt::format("Sampling from library source {}...", - settings::path_source), 6); + write_message(6, "Sampling library source {}...", settings::path_source); fill_source_bank_custom_source(); From 67e8e0ab77f33cae94b927f70b4562c596700291 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Sun, 2 Aug 2020 22:11:52 -0400 Subject: [PATCH 16/24] Apply templated write_message to tallies/trigger.cpp --- src/tallies/trigger.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/tallies/trigger.cpp b/src/tallies/trigger.cpp index cc8fff1d7..56f5c4c56 100644 --- a/src/tallies/trigger.cpp +++ b/src/tallies/trigger.cpp @@ -164,8 +164,7 @@ check_triggers() // If all the triggers are satisfied, alert the user and return. if (std::max(keff_ratio, tally_ratio) <= 1.) { simulation::satisfy_triggers = true; - write_message("Triggers satisfied for batch " - + std::to_string(current_batch), 7); + write_message(7, "Triggers satisfied for batch {}", current_batch); return; } From 27e102066604e14db4ababa38c773e51398942ab Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Sun, 2 Aug 2020 22:11:52 -0400 Subject: [PATCH 17/24] Apply templated write_message to volume_calc.cpp --- src/volume_calc.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/volume_calc.cpp b/src/volume_calc.cpp index d1b14e329..96ef55234 100644 --- a/src/volume_calc.cpp +++ b/src/volume_calc.cpp @@ -468,9 +468,7 @@ int openmc_calculate_volumes() { time_volume.start(); for (int i = 0; i < model::volume_calcs.size(); ++i) { - if (mpi::master) { - write_message(fmt::format("Running volume calculation {}...", i + 1), 4); - } + write_message(4, "Running volume calculation {}", i+1); // Run volume calculation const auto& vol_calc {model::volume_calcs[i]}; @@ -488,8 +486,8 @@ int openmc_calculate_volumes() { // Display domain volumes for (int j = 0; j < vol_calc.domain_ids_.size(); j++) { - write_message(fmt::format("{}{}: {} +/- {} cm^3", domain_type, - vol_calc.domain_ids_[j], results[j].volume[0], results[j].volume[1]), 4); + write_message(4, "{}{}: {} +/- {} cm^3", domain_type, + vol_calc.domain_ids_[j], results[j].volume[0], results[j].volume[1]); } // Write volumes to HDF5 file @@ -502,9 +500,7 @@ int openmc_calculate_volumes() { // Show elapsed time time_volume.stop(); - if (mpi::master) { - write_message(fmt::format("Elapsed time: {} s", time_volume.elapsed()), 6); - } + write_message(6, "Elapsed time: {} s", time_volume.elapsed()); return 0; } From b441fe1c29c7f5966d44f5c321afaaec7ca1b27f Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Sun, 2 Aug 2020 22:11:53 -0400 Subject: [PATCH 18/24] Apply templated write_message to wmp.cpp --- src/wmp.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/wmp.cpp b/src/wmp.cpp index 96e1d5641..44f7eb51a 100644 --- a/src/wmp.cpp +++ b/src/wmp.cpp @@ -5,6 +5,7 @@ #include "openmc/hdf5_interface.h" #include "openmc/math_functions.h" #include "openmc/nuclide.h" +#include "openmc/error.h" // for writing messages #include @@ -227,7 +228,7 @@ void read_multipole_data(int i_nuclide) std::string& filename = data::libraries[idx].path_; // Display message - write_message("Reading " + nuc->name_ + " WMP data from " + filename, 6); + write_message(6, "Reading {} WMP data from {}", nuc->name_, filename); // Open file and make sure version is sufficient hid_t file = file_open(filename, 'r'); From 4de893043eac2402309648a1e03b76e5b7755b88 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Thu, 6 Aug 2020 07:01:10 -0400 Subject: [PATCH 19/24] Apply templated write_message to mgxs_interface.cpp --- src/mgxs_interface.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mgxs_interface.cpp b/src/mgxs_interface.cpp index 7ad07d0c9..31294e3c9 100644 --- a/src/mgxs_interface.cpp +++ b/src/mgxs_interface.cpp @@ -99,7 +99,7 @@ void MgxsInterface::add_mgxs(hid_t file_id, const std::string& name, const std::vector& temperature) { - write_message(fmt::format("Loading {} data...", name), 6); + write_message(5, "Loading {} data...", name); // Check to make sure cross section set exists in the library hid_t xs_grp; From f1b7cd79382675f83dfa5738d47d85f92c5a4259 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Thu, 6 Aug 2020 08:19:03 -0400 Subject: [PATCH 20/24] Use templated write_message in a few more places From review suggestions Co-authored-by: Paul Romano --- src/nuclide.cpp | 2 +- src/particle.cpp | 9 ++++----- src/simulation.cpp | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/nuclide.cpp b/src/nuclide.cpp index 0a0e40057..59c631167 100644 --- a/src/nuclide.cpp +++ b/src/nuclide.cpp @@ -944,7 +944,7 @@ extern "C" int openmc_load_nuclide(const char* name, const double* temps, int n) // Get filename for library containing nuclide int idx = it->second; const auto& filename = data::libraries[idx].path_; - write_message(6, "Reading {} from {}", std::string{name}, filename); + write_message(6, "Reading {} from {}", name, filename); // Open file and make sure version is sufficient hid_t file_id = file_open(filename, 'r'); diff --git a/src/particle.cpp b/src/particle.cpp index 3916eacba..a983b6600 100644 --- a/src/particle.cpp +++ b/src/particle.cpp @@ -410,7 +410,7 @@ Particle::cross_surface() // TODO: off-by-one const auto& surf {model::surfaces[i_surface - 1].get()}; if (settings::verbosity >= 10 || trace_) { - write_message(fmt::format(" Crossing surface {}", surf->id_)); + write_message(" Crossing surface {}", surf->id_); } if (surf->bc_ == Surface::BoundaryType::VACUUM && (settings::run_mode != RunMode::PLOTTING)) { @@ -437,7 +437,7 @@ Particle::cross_surface() // Display message if (settings::verbosity >= 10 || trace_) { - write_message(fmt::format(" Leaked out of surface {}", surf->id_)); + write_message(" Leaked out of surface {}", surf->id_); } return; @@ -502,7 +502,7 @@ Particle::cross_surface() // Diagnostic message if (settings::verbosity >= 10 || trace_) { - write_message(fmt::format(" Reflected from surface {}", surf->id_)); + write_message(" Reflected from surface {}", surf->id_); } return; @@ -556,8 +556,7 @@ Particle::cross_surface() // Diagnostic message if (settings::verbosity >= 10 || trace_) { - write_message(fmt::format(" Hit periodic boundary on surface {}", - surf->id_)); + write_message(" Hit periodic boundary on surface {}", surf->id_); } return; } diff --git a/src/simulation.cpp b/src/simulation.cpp index def9cee5d..c8115ae37 100644 --- a/src/simulation.cpp +++ b/src/simulation.cpp @@ -501,7 +501,7 @@ void initialize_history(Particle& p, int64_t index_source) // Display message if high verbosity or trace is on if (settings::verbosity >= 9 || p.trace_) { - write_message(fmt::format("Simulating Particle {}", p.id_)); + write_message("Simulating Particle {}", p.id_); } // Add paricle's starting weight to count for normalizing tallies later From c37f0e66579671e5c1ffd236616f7e18f5575b67 Mon Sep 17 00:00:00 2001 From: Cyrus Wyett <34195737+cjwyett@users.noreply.github.com> Date: Sun, 9 Aug 2020 00:53:23 +0100 Subject: [PATCH 21/24] Remove word "Fortran" Not sure if this is right? --- examples/jupyter/pincell.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/jupyter/pincell.ipynb b/examples/jupyter/pincell.ipynb index 88fe0ca35..7d0f4e65a 100644 --- a/examples/jupyter/pincell.ipynb +++ b/examples/jupyter/pincell.ipynb @@ -1373,7 +1373,7 @@ "source": [ "## Geometry plotting\n", "\n", - "We saw before that we could call the `Universe.plot()` method to show a universe while we were creating our geometry. There is also a built-in plotter in the Fortran codebase that is much faster than the Python plotter and has more options. The interface looks somewhat similar to the `Universe.plot()` method. Instead though, we create `Plot` instances, assign them to a `Plots` collection, export it to XML, and then run OpenMC in geometry plotting mode. As an example, let's specify that we want the plot to be colored by material (rather than by cell) and we assign yellow to fuel and blue to water." + "We saw before that we could call the `Universe.plot()` method to show a universe while we were creating our geometry. There is also a built-in plotter in the codebase that is much faster than the Python plotter and has more options. The interface looks somewhat similar to the `Universe.plot()` method. Instead though, we create `Plot` instances, assign them to a `Plots` collection, export it to XML, and then run OpenMC in geometry plotting mode. As an example, let's specify that we want the plot to be colored by material (rather than by cell) and we assign yellow to fuel and blue to water." ] }, { From 1a2af8eb5480537fc649ca434c1e209d1f8d06b2 Mon Sep 17 00:00:00 2001 From: Cyrus Wyett <34195737+cjwyett@users.noreply.github.com> Date: Sun, 9 Aug 2020 05:22:07 +0100 Subject: [PATCH 22/24] Fix #1634 --- examples/jupyter/post-processing.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/jupyter/post-processing.ipynb b/examples/jupyter/post-processing.ipynb index 22ccb2b5b..889e16877 100644 --- a/examples/jupyter/post-processing.ipynb +++ b/examples/jupyter/post-processing.ipynb @@ -911,7 +911,7 @@ "print(sum(probability*np.diff(energy_bins)))\n", "\n", "# Plot source energy PDF\n", - "plt.semilogx(energy_bins[:-1], probability*np.diff(energy_bins), linestyle='steps')\n", + "plt.semilogx(energy_bins[:-1], probability*np.diff(energy_bins), drawstyle='steps')\n", "plt.xlabel('Energy (eV)')\n", "plt.ylabel('Probability/eV')" ] From 0a3c4e489ae7ca01b20d3686cec969ecc9f27987 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Thu, 6 Aug 2020 09:03:13 -0500 Subject: [PATCH 23/24] If source rate is 0, don't run OpenMC transport solve --- openmc/deplete/operator.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/openmc/deplete/operator.py b/openmc/deplete/operator.py index a11f6d95d..fd9f1bf31 100644 --- a/openmc/deplete/operator.py +++ b/openmc/deplete/operator.py @@ -276,6 +276,16 @@ class Operator(TransportOperator): Eigenvalue and reaction rates resulting from transport operator """ + # Reset results in OpenMC + openmc.lib.reset() + + # If the source rate is zero, return zero reaction rates without running + # a transport solve + if power == 0.0: + rates = self.reaction_rates.copy() + rates.fill(0.0) + return OperatorResult(ufloat(0.0, 0.0), rates) + # Prevent OpenMC from complaining about re-creating tallies openmc.reset_auto_ids() @@ -290,7 +300,6 @@ class Operator(TransportOperator): self._yield_helper.update_tally_nuclides(nuclides) # Run OpenMC - openmc.lib.reset() openmc.lib.run() openmc.lib.reset_timers() From ec0d2fb6d0fb8c2c98f354961527ccbb1cd58409 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Thu, 6 Aug 2020 09:46:51 -0500 Subject: [PATCH 24/24] Allow final transport solve to be omitted in depletion --- openmc/deplete/abc.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/openmc/deplete/abc.py b/openmc/deplete/abc.py index 4924e4f6f..968af66fa 100644 --- a/openmc/deplete/abc.py +++ b/openmc/deplete/abc.py @@ -858,16 +858,29 @@ class Integrator(ABC): return (self.operator.prev_res[-1].time[-1], len(self.operator.prev_res) - 1) - def integrate(self): - """Perform the entire depletion process across all steps""" + def integrate(self, final_step=True): + """Perform the entire depletion process across all steps + + Parameters + ---------- + final_step : bool, optional + Indicate whether or not a transport solve should be run at the end + of the last timestep. + + .. versionadded:: 0.12.1 + + """ with self.operator as conc: t, self._i_res = self._get_start_data() for i, (dt, p) in enumerate(self): + # Solve transport equation (or obtain result from restart) if i > 0 or self.operator.prev_res is None: conc, res = self._get_bos_data_from_operator(i, p, conc) else: conc, res = self._get_bos_data_from_restart(i, p, conc) + + # Solve Bateman equations over time interval proc_time, conc_list, res_list = self(conc, res.rates, dt, p, i) # Insert BOS concentration, transport results @@ -882,8 +895,11 @@ class Integrator(ABC): t += dt - # Final simulation - res_list = [self.operator(conc, p)] + # Final simulation -- in the case that final_step is False, a zero + # source rate is passed to the transport operator (which knows to + # just return zero reaction rates without actually doing a transport + # solve) + res_list = [self.operator(conc, p if final_step else 0.0)] Results.save(self.operator, [conc], res_list, [t, t], p, self._i_res + len(self), proc_time) self.operator.write_bos_data(len(self) + self._i_res)