From 516ac9e1d372ff2030939dc87fd0699d81bb3c9c Mon Sep 17 00:00:00 2001 From: stevendargaville Date: Tue, 11 Feb 2020 13:37:00 +0000 Subject: [PATCH 01/11] Modified the MAX_LOST_PARTICLES const in particle.h to be a variable stored in settings that can be modified by the c/python/xml layers. --- include/openmc/particle.h | 3 --- include/openmc/settings.h | 9 +++++---- openmc/lib/settings.py | 1 + openmc/settings.py | 26 ++++++++++++++++++++++++++ openmc/statepoint.py | 6 ++++++ src/particle.cpp | 6 +++++- src/settings.cpp | 12 ++++++++++-- 7 files changed, 53 insertions(+), 10 deletions(-) diff --git a/include/openmc/particle.h b/include/openmc/particle.h index 8143ee5a30..ee59d73014 100644 --- a/include/openmc/particle.h +++ b/include/openmc/particle.h @@ -34,9 +34,6 @@ namespace openmc { // use to store the bins for delayed group tallies. constexpr int MAX_DELAYED_GROUPS {8}; -// Maximum number of lost particles -constexpr int MAX_LOST_PARTICLES {10}; - // Maximum number of lost particles, relative to the total number of particles constexpr double REL_MAX_LOST_PARTICLES {1.0e-6}; diff --git a/include/openmc/settings.h b/include/openmc/settings.h index cbc0c488b9..1dcdea3cc7 100644 --- a/include/openmc/settings.h +++ b/include/openmc/settings.h @@ -63,10 +63,11 @@ extern std::string path_source; extern std::string path_sourcepoint; //!< path to a source file extern "C" std::string path_statepoint; //!< path to a statepoint file -extern "C" int32_t n_batches; //!< number of (inactive+active) batches -extern "C" int32_t n_inactive; //!< number of inactive batches -extern "C" int32_t gen_per_batch; //!< number of generations per batch -extern "C" int64_t n_particles; //!< number of particles per generation +extern "C" int32_t n_batches; //!< number of (inactive+active) batches +extern "C" int32_t n_inactive; //!< number of inactive batches +extern "C" int32_t n_max_lost_particles; //!< maximum number of lost particles +extern "C" int32_t gen_per_batch; //!< number of generations per batch +extern "C" int64_t n_particles; //!< number of particles per generation extern int64_t max_particles_in_flight; //!< Max num. event-based particles in flight diff --git a/openmc/lib/settings.py b/openmc/lib/settings.py index 275c73a934..a25ccb962f 100644 --- a/openmc/lib/settings.py +++ b/openmc/lib/settings.py @@ -22,6 +22,7 @@ class _Settings(object): entropy_on = _DLLGlobal(c_bool, 'entropy_on') generations_per_batch = _DLLGlobal(c_int32, 'gen_per_batch') inactive = _DLLGlobal(c_int32, 'n_inactive') + max_lost_particles = _DLLGlobal(c_int32, 'n_max_lost_particles') particles = _DLLGlobal(c_int64, 'n_particles') restart_run = _DLLGlobal(c_bool, 'restart_run') run_CE = _DLLGlobal(c_bool, 'run_CE') diff --git a/openmc/settings.py b/openmc/settings.py index eb2f926f3a..79e7719a3d 100644 --- a/openmc/settings.py +++ b/openmc/settings.py @@ -58,6 +58,8 @@ class Settings(object): history-based parallelism. generations_per_batch : int Number of generations per batch + max_lost_particles : int + Maximum number of lost particles inactive : int Number of inactive batches keff_trigger : dict @@ -176,6 +178,7 @@ class Settings(object): self._batches = None self._generations_per_batch = None self._inactive = None + self._max_lost_particles = None self._particles = None self._keff_trigger = None @@ -254,6 +257,10 @@ class Settings(object): def inactive(self): return self._inactive + @property + def max_lost_particles(self): + return self._max_lost_particles + @property def particles(self): return self._particles @@ -417,6 +424,12 @@ class Settings(object): cv.check_greater_than('inactive batches', inactive, 0, True) self._inactive = inactive + @max_lost_particles.setter + def max_lost_particles(self, max_lost_particles): + cv.check_type('max_lost_particles', max_lost_particles, Integral) + cv.check_greater_than('max_lost_particles', max_lost_particles, 0) + self._max_lost_particles = max_lost_particles + @particles.setter def particles(self, particles): cv.check_type('particles', particles, Integral) @@ -763,6 +776,11 @@ class Settings(object): element = ET.SubElement(root, "inactive") element.text = str(self._inactive) + def _create_max_lost_particles_subelement(self, root): + if self._max_lost_particles is not None: + element = ET.SubElement(root, "max_lost_particles") + element.text = str(self._max_lost_particles) + def _create_particles_subelement(self, root): if self._particles is not None: element = ET.SubElement(root, "particles") @@ -1009,6 +1027,7 @@ class Settings(object): self._particles_from_xml_element(elem) self._batches_from_xml_element(elem) self._inactive_from_xml_element(elem) + self._max_lost_particles_from_xml_element(elem) self._generations_per_batch_from_xml_element(elem) def _run_mode_from_xml_element(self, root): @@ -1031,6 +1050,11 @@ class Settings(object): if text is not None: self.inactive = int(text) + def _max_lost_particles_from_xml_element(self, root): + text = get_text(root, 'max_lost_particles') + if text is not None: + self.max_lost_particles = int(text) + def _generations_per_batch_from_xml_element(self, root): text = get_text(root, 'generations_per_batch') if text is not None: @@ -1270,6 +1294,7 @@ class Settings(object): self._create_particles_subelement(root_element) self._create_batches_subelement(root_element) self._create_inactive_subelement(root_element) + self._create_max_lost_particles_subelement(root_element) self._create_generations_per_batch_subelement(root_element) self._create_keff_trigger_subelement(root_element) self._create_source_subelement(root_element) @@ -1340,6 +1365,7 @@ class Settings(object): settings._particles_from_xml_element(root) settings._batches_from_xml_element(root) settings._inactive_from_xml_element(root) + settings._max_lost_particles_from_xml_element(root) settings._generations_per_batch_from_xml_element(root) settings._keff_trigger_from_xml_element(root) settings._source_from_xml_element(root) diff --git a/openmc/statepoint.py b/openmc/statepoint.py index 5802a74cae..051195ec96 100644 --- a/openmc/statepoint.py +++ b/openmc/statepoint.py @@ -77,6 +77,8 @@ class StatePoint(object): Number of batches n_inactive : int Number of inactive batches + n_max_lost_particles : int + Number of max lost particles n_particles : int Number of particles per generation n_realizations : int @@ -312,6 +314,10 @@ class StatePoint(object): else: return None + @property + def n_max_lost_particles(self): + return self._f['n_max_lost_particles'][()] + @property def n_particles(self): return self._f['n_particles'][()] diff --git a/src/particle.cpp b/src/particle.cpp index bd9a611392..8e66222048 100644 --- a/src/particle.cpp +++ b/src/particle.cpp @@ -164,6 +164,8 @@ Particle::event_calculate_xs() if (cell_born_ == C_NONE) cell_born_ = coord_[n_coord_ - 1].cell; } + std::cout << "settings::n_max_lost_particles " << settings::n_max_lost_particles << std::endl; + // Write particle track. if (write_track_) write_particle_track(*this); @@ -628,9 +630,11 @@ Particle::mark_as_lost(const char* message) auto n = simulation::current_batch * settings::gen_per_batch * simulation::work_per_rank; + std::cout << simulation::n_lost_particles << "HELLLOOOOOOOOOOOO MS DOUBTFIRE" << std::endl; + // Abort the simulation if the maximum number of lost particles has been // reached - if (simulation::n_lost_particles >= MAX_LOST_PARTICLES && + if (simulation::n_lost_particles >= settings::n_max_lost_particles && simulation::n_lost_particles >= REL_MAX_LOST_PARTICLES*n) { fatal_error("Maximum number of lost particles has been reached."); } diff --git a/src/settings.cpp b/src/settings.cpp index 32a7958d8d..41a55501c2 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -79,6 +79,7 @@ std::string path_statepoint; int32_t n_batches; int32_t n_inactive {0}; +int32_t n_max_lost_particles {10}; int32_t gen_per_batch {1}; int64_t n_particles {-1}; @@ -143,6 +144,11 @@ void get_run_parameters(pugi::xml_node node_base) } if (!trigger_on) n_max_batches = n_batches; + // Get max number of lost particles + if (check_for_node(node_base, "max_lost_particles")) { + n_max_lost_particles = std::stoi(get_node_value(node_base, "max_lost_particles")); + } + // Get number of inactive batches if (run_mode == RunMode::EIGENVALUE) { if (check_for_node(node_base, "inactive")) { @@ -343,14 +349,16 @@ void read_settings_xml() // Read run parameters get_run_parameters(node_mode); - // Check number of active batches, inactive batches, and particles + // Check number of active batches, inactive batches, max lost particles and particles if (n_batches <= n_inactive) { fatal_error("Number of active batches must be greater than zero."); } else if (n_inactive < 0) { fatal_error("Number of inactive batches must be non-negative."); } else if (n_particles <= 0) { fatal_error("Number of particles must be greater than zero."); - } + } else if (n_max_lost_particles <= 0) { + fatal_error("Number of max lost particles must be greater than zero."); + } } // Copy random number seed if specified From 9f64dd1a880a150682ae6140da1a9546b1982a35 Mon Sep 17 00:00:00 2001 From: stevendargaville Date: Tue, 11 Feb 2020 13:37:26 +0000 Subject: [PATCH 02/11] Modified the REL_MAX_LOST_PARTICLES const in particle.h to be a variable stored in settings that can be modified by the c/python/xml layers. --- include/openmc/particle.h | 3 --- include/openmc/settings.h | 11 ++++++----- openmc/lib/settings.py | 1 + openmc/settings.py | 31 +++++++++++++++++++++++++++++-- openmc/statepoint.py | 8 +++++++- src/particle.cpp | 6 +----- src/settings.cpp | 10 +++++++++- 7 files changed, 53 insertions(+), 17 deletions(-) diff --git a/include/openmc/particle.h b/include/openmc/particle.h index ee59d73014..2917b45e4a 100644 --- a/include/openmc/particle.h +++ b/include/openmc/particle.h @@ -34,9 +34,6 @@ namespace openmc { // use to store the bins for delayed group tallies. constexpr int MAX_DELAYED_GROUPS {8}; -// Maximum number of lost particles, relative to the total number of particles -constexpr double REL_MAX_LOST_PARTICLES {1.0e-6}; - constexpr double CACHE_INVALID {-1.0}; //============================================================================== diff --git a/include/openmc/settings.h b/include/openmc/settings.h index 1dcdea3cc7..3407eadf4b 100644 --- a/include/openmc/settings.h +++ b/include/openmc/settings.h @@ -63,11 +63,12 @@ extern std::string path_source; extern std::string path_sourcepoint; //!< path to a source file extern "C" std::string path_statepoint; //!< path to a statepoint file -extern "C" int32_t n_batches; //!< number of (inactive+active) batches -extern "C" int32_t n_inactive; //!< number of inactive batches -extern "C" int32_t n_max_lost_particles; //!< maximum number of lost particles -extern "C" int32_t gen_per_batch; //!< number of generations per batch -extern "C" int64_t n_particles; //!< number of particles per generation +extern "C" int32_t n_batches; //!< number of (inactive+active) batches +extern "C" int32_t n_inactive; //!< number of inactive batches +extern "C" int32_t n_max_lost_particles; //!< maximum number of lost particles +extern double relative_max_lost_particles; //!< maximum number of lost particles, relative to the total number of particles +extern "C" int32_t gen_per_batch; //!< number of generations per batch +extern "C" int64_t n_particles; //!< number of particles per generation extern int64_t max_particles_in_flight; //!< Max num. event-based particles in flight diff --git a/openmc/lib/settings.py b/openmc/lib/settings.py index a25ccb962f..8345e00881 100644 --- a/openmc/lib/settings.py +++ b/openmc/lib/settings.py @@ -23,6 +23,7 @@ class _Settings(object): generations_per_batch = _DLLGlobal(c_int32, 'gen_per_batch') inactive = _DLLGlobal(c_int32, 'n_inactive') max_lost_particles = _DLLGlobal(c_int32, 'n_max_lost_particles') + rel_max_lost_particles = _DLLGlobal(c_double, 'relative_max_lost_particles') particles = _DLLGlobal(c_int64, 'n_particles') restart_run = _DLLGlobal(c_bool, 'restart_run') run_CE = _DLLGlobal(c_bool, 'run_CE') diff --git a/openmc/settings.py b/openmc/settings.py index 79e7719a3d..794c97b618 100644 --- a/openmc/settings.py +++ b/openmc/settings.py @@ -60,6 +60,8 @@ class Settings(object): Number of generations per batch max_lost_particles : int Maximum number of lost particles + rel_max_lost_particles : int + Maximum number of lost particles, relative to the total number of particles inactive : int Number of inactive batches keff_trigger : dict @@ -179,6 +181,7 @@ class Settings(object): self._generations_per_batch = None self._inactive = None self._max_lost_particles = None + self._rel_max_lost_particles = None self._particles = None self._keff_trigger = None @@ -261,6 +264,10 @@ class Settings(object): def max_lost_particles(self): return self._max_lost_particles + @property + def rel_max_lost_particles(self): + return self._rel_max_lost_particles + @property def particles(self): return self._particles @@ -430,6 +437,13 @@ class Settings(object): cv.check_greater_than('max_lost_particles', max_lost_particles, 0) self._max_lost_particles = max_lost_particles + @rel_max_lost_particles.setter + def rel_max_lost_particles(self, rel_max_lost_particles): + cv.check_type('rel_max_lost_particles', rel_max_lost_particles, Real) + cv.check_greater_than('rel_max_lost_particles', rel_max_lost_particles, 0) + cv.check_less_than('rel_max_lost_particles', rel_max_lost_particles, 1) + self._rel_max_lost_particles = rel_max_lost_particles + @particles.setter def particles(self, particles): cv.check_type('particles', particles, Integral) @@ -779,7 +793,12 @@ class Settings(object): def _create_max_lost_particles_subelement(self, root): if self._max_lost_particles is not None: element = ET.SubElement(root, "max_lost_particles") - element.text = str(self._max_lost_particles) + element.text = str(self._max_lost_particles) + + def _create_rel_max_lost_particles_subelement(self, root): + if self._rel_max_lost_particles is not None: + element = ET.SubElement(root, "rel_max_lost_particles") + element.text = str(self._rel_max_lost_particles) def _create_particles_subelement(self, root): if self._particles is not None: @@ -1028,6 +1047,7 @@ class Settings(object): self._batches_from_xml_element(elem) self._inactive_from_xml_element(elem) self._max_lost_particles_from_xml_element(elem) + self._rel_max_lost_particles_from_xml_element(elem) self._generations_per_batch_from_xml_element(elem) def _run_mode_from_xml_element(self, root): @@ -1053,7 +1073,12 @@ class Settings(object): def _max_lost_particles_from_xml_element(self, root): text = get_text(root, 'max_lost_particles') if text is not None: - self.max_lost_particles = int(text) + self.max_lost_particles = int(text) + + def _rel_max_lost_particles_from_xml_element(self, root): + text = get_text(root, 'rel_max_lost_particles') + if text is not None: + self.rel_max_lost_particles = float(text) def _generations_per_batch_from_xml_element(self, root): text = get_text(root, 'generations_per_batch') @@ -1295,6 +1320,7 @@ class Settings(object): self._create_batches_subelement(root_element) self._create_inactive_subelement(root_element) self._create_max_lost_particles_subelement(root_element) + self._create_rel_max_lost_particles_subelement(root_element) self._create_generations_per_batch_subelement(root_element) self._create_keff_trigger_subelement(root_element) self._create_source_subelement(root_element) @@ -1366,6 +1392,7 @@ class Settings(object): settings._batches_from_xml_element(root) settings._inactive_from_xml_element(root) settings._max_lost_particles_from_xml_element(root) + settings._rel_max_lost_particles_from_xml_element(root) settings._generations_per_batch_from_xml_element(root) settings._keff_trigger_from_xml_element(root) settings._source_from_xml_element(root) diff --git a/openmc/statepoint.py b/openmc/statepoint.py index 051195ec96..0d78bf68dc 100644 --- a/openmc/statepoint.py +++ b/openmc/statepoint.py @@ -79,6 +79,8 @@ class StatePoint(object): Number of inactive batches n_max_lost_particles : int Number of max lost particles + relative_max_lost_particles : float + Number of max lost particles, relative to the total number of particles n_particles : int Number of particles per generation n_realizations : int @@ -316,7 +318,11 @@ class StatePoint(object): @property def n_max_lost_particles(self): - return self._f['n_max_lost_particles'][()] + return self._f['n_max_lost_particles'][()] + + @property + def relative_max_lost_particles(self): + return self._f['relative_max_lost_particles'][()] @property def n_particles(self): diff --git a/src/particle.cpp b/src/particle.cpp index 8e66222048..79e6625771 100644 --- a/src/particle.cpp +++ b/src/particle.cpp @@ -164,8 +164,6 @@ Particle::event_calculate_xs() if (cell_born_ == C_NONE) cell_born_ = coord_[n_coord_ - 1].cell; } - std::cout << "settings::n_max_lost_particles " << settings::n_max_lost_particles << std::endl; - // Write particle track. if (write_track_) write_particle_track(*this); @@ -630,12 +628,10 @@ Particle::mark_as_lost(const char* message) auto n = simulation::current_batch * settings::gen_per_batch * simulation::work_per_rank; - std::cout << simulation::n_lost_particles << "HELLLOOOOOOOOOOOO MS DOUBTFIRE" << std::endl; - // Abort the simulation if the maximum number of lost particles has been // reached if (simulation::n_lost_particles >= settings::n_max_lost_particles && - simulation::n_lost_particles >= REL_MAX_LOST_PARTICLES*n) { + simulation::n_lost_particles >= settings::relative_max_lost_particles*n) { fatal_error("Maximum number of lost particles has been reached."); } } diff --git a/src/settings.cpp b/src/settings.cpp index 41a55501c2..d72e5f17f7 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -80,6 +80,7 @@ std::string path_statepoint; int32_t n_batches; int32_t n_inactive {0}; int32_t n_max_lost_particles {10}; +double relative_max_lost_particles {1.0e-6}; int32_t gen_per_batch {1}; int64_t n_particles {-1}; @@ -149,6 +150,11 @@ void get_run_parameters(pugi::xml_node node_base) n_max_lost_particles = std::stoi(get_node_value(node_base, "max_lost_particles")); } + // Get relative number of lost particles + if (check_for_node(node_base, "rel_max_lost_particles")) { + relative_max_lost_particles = std::stod(get_node_value(node_base, "rel_max_lost_particles")); + } + // Get number of inactive batches if (run_mode == RunMode::EIGENVALUE) { if (check_for_node(node_base, "inactive")) { @@ -358,7 +364,9 @@ void read_settings_xml() fatal_error("Number of particles must be greater than zero."); } else if (n_max_lost_particles <= 0) { fatal_error("Number of max lost particles must be greater than zero."); - } + } else if (relative_max_lost_particles <= 0.0 || relative_max_lost_particles >= 1.0) { + fatal_error("Relative max lost particles must be between zero and one."); + } } // Copy random number seed if specified From 6a40a535e482aa0ae31949b0836c22f3d6445f48 Mon Sep 17 00:00:00 2001 From: stevendargaville Date: Tue, 11 Feb 2020 13:37:32 +0000 Subject: [PATCH 03/11] Modified the test_settings unit test for new max_lost_particles and rel_max_lost_particles to check they can be assigned/read by the python interface --- tests/unit_tests/test_settings.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/unit_tests/test_settings.py b/tests/unit_tests/test_settings.py index 9c33f6a2d4..c3ff728798 100644 --- a/tests/unit_tests/test_settings.py +++ b/tests/unit_tests/test_settings.py @@ -9,6 +9,8 @@ def test_export_to_xml(run_in_tmpdir): s.generations_per_batch = 10 s.inactive = 100 s.particles = 1000000 + s.max_lost_particles = 5 + s.rel_max_lost_particles = 1e-4 s.keff_trigger = {'type': 'std_dev', 'threshold': 0.001} s.energy_mode = 'continuous-energy' s.max_order = 5 @@ -62,6 +64,8 @@ def test_export_to_xml(run_in_tmpdir): assert s.generations_per_batch == 10 assert s.inactive == 100 assert s.particles == 1000000 + assert s.max_lost_particles == 5 + assert s.rel_max_lost_particles == 1e-4 assert s.keff_trigger == {'type': 'std_dev', 'threshold': 0.001} assert s.energy_mode == 'continuous-energy' assert s.max_order == 5 From 9224ca318675fcbb06c8eb97d9569466874dda21 Mon Sep 17 00:00:00 2001 From: stevendargaville Date: Tue, 11 Feb 2020 13:37:37 +0000 Subject: [PATCH 04/11] Modified an existing regression test to include the new max_lost_particles and relative version. This is mainly a test that the python/xml input/output routines work through the comparison the regression test harness does in this test, neither of these trigger the end of the simulation. --- tests/regression_tests/photon_source/inputs_true.dat | 2 ++ tests/regression_tests/photon_source/test.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/tests/regression_tests/photon_source/inputs_true.dat b/tests/regression_tests/photon_source/inputs_true.dat index 89f4de0e0c..83c909ac69 100644 --- a/tests/regression_tests/photon_source/inputs_true.dat +++ b/tests/regression_tests/photon_source/inputs_true.dat @@ -18,6 +18,8 @@ fixed source 10000 1 + 5 + 0.1 0 0 0 diff --git a/tests/regression_tests/photon_source/test.py b/tests/regression_tests/photon_source/test.py index 94b0280031..09a0b4a2d0 100644 --- a/tests/regression_tests/photon_source/test.py +++ b/tests/regression_tests/photon_source/test.py @@ -31,6 +31,8 @@ class SourceTestHarness(PyAPITestHarness): settings = openmc.Settings() settings.particles = 10000 settings.batches = 1 + settings.max_lost_particles = 5 + settings.rel_max_lost_particles = 0.1 settings.photon_transport = True settings.electron_treatment = 'ttb' settings.cutoff = {'energy_photon' : 1000.0} From b6a03949c82aee90824b9daf60d3d74a587b5b19 Mon Sep 17 00:00:00 2001 From: stevendargaville Date: Tue, 11 Feb 2020 13:37:41 +0000 Subject: [PATCH 05/11] Modified the StatePoint output to include the new max_lost_particles and relative version. Further modified an existing regression test to check the StatePoint write-out of these variables --- src/state_point.cpp | 4 ++++ tests/regression_tests/photon_source/results_true.dat | 2 ++ tests/regression_tests/photon_source/test.py | 2 ++ 3 files changed, 8 insertions(+) diff --git a/src/state_point.cpp b/src/state_point.cpp index 60fd3826de..a9213bcb4e 100644 --- a/src/state_point.cpp +++ b/src/state_point.cpp @@ -93,6 +93,8 @@ openmc_statepoint_write(const char* filename, bool* write_source) write_attribute(file_id, "photon_transport", settings::photon_transport); write_dataset(file_id, "n_particles", settings::n_particles); write_dataset(file_id, "n_batches", settings::n_batches); + write_dataset(file_id, "n_max_lost_particles", settings::n_max_lost_particles); + write_dataset(file_id, "relative_max_lost_particles", settings::relative_max_lost_particles); // Write out current batch number write_dataset(file_id, "current_batch", simulation::current_batch); @@ -373,6 +375,8 @@ void load_state_point() read_dataset(file_id, "n_particles", settings::n_particles); int temp; read_dataset(file_id, "n_batches", temp); + read_dataset(file_id, "n_max_lost_particles", settings::n_max_lost_particles); + read_dataset(file_id, "relative_max_lost_particles", settings::relative_max_lost_particles); // Take maximum of statepoint n_batches and input n_batches settings::n_batches = std::max(settings::n_batches, temp); diff --git a/tests/regression_tests/photon_source/results_true.dat b/tests/regression_tests/photon_source/results_true.dat index 1448ad6db8..ab6ac9ff83 100644 --- a/tests/regression_tests/photon_source/results_true.dat +++ b/tests/regression_tests/photon_source/results_true.dat @@ -1,3 +1,5 @@ tally 1: sum = 2.275713E+02 sum_sq = 5.178870E+04 +max_lost = 5.000000E+00 +rel_max_lost = 1.000000E-01 diff --git a/tests/regression_tests/photon_source/test.py b/tests/regression_tests/photon_source/test.py index 09a0b4a2d0..c5c42d680e 100644 --- a/tests/regression_tests/photon_source/test.py +++ b/tests/regression_tests/photon_source/test.py @@ -54,6 +54,8 @@ class SourceTestHarness(PyAPITestHarness): outstr += 'tally {}:\n'.format(t.id) outstr += 'sum = {:12.6E}\n'.format(t.sum[0, 0, 0]) outstr += 'sum_sq = {:12.6E}\n'.format(t.sum_sq[0, 0, 0]) + outstr += 'max_lost = {:12.6E}\n'.format(sp.n_max_lost_particles) + outstr += 'rel_max_lost = {:12.6E}\n'.format(sp.relative_max_lost_particles) return outstr From 8154eeed13db2a663464e9a204749a6d0bb67c10 Mon Sep 17 00:00:00 2001 From: stevendargaville Date: Thu, 13 Feb 2020 14:41:40 +0000 Subject: [PATCH 06/11] Revert "Modified the StatePoint output to include the new max_lost_particles and relative version. Further modified an existing regression test to check the StatePoint write-out of these variables" This reverts commit b6a03949c82aee90824b9daf60d3d74a587b5b19. --- src/state_point.cpp | 4 ---- tests/regression_tests/photon_source/results_true.dat | 2 -- tests/regression_tests/photon_source/test.py | 2 -- 3 files changed, 8 deletions(-) diff --git a/src/state_point.cpp b/src/state_point.cpp index a9213bcb4e..60fd3826de 100644 --- a/src/state_point.cpp +++ b/src/state_point.cpp @@ -93,8 +93,6 @@ openmc_statepoint_write(const char* filename, bool* write_source) write_attribute(file_id, "photon_transport", settings::photon_transport); write_dataset(file_id, "n_particles", settings::n_particles); write_dataset(file_id, "n_batches", settings::n_batches); - write_dataset(file_id, "n_max_lost_particles", settings::n_max_lost_particles); - write_dataset(file_id, "relative_max_lost_particles", settings::relative_max_lost_particles); // Write out current batch number write_dataset(file_id, "current_batch", simulation::current_batch); @@ -375,8 +373,6 @@ void load_state_point() read_dataset(file_id, "n_particles", settings::n_particles); int temp; read_dataset(file_id, "n_batches", temp); - read_dataset(file_id, "n_max_lost_particles", settings::n_max_lost_particles); - read_dataset(file_id, "relative_max_lost_particles", settings::relative_max_lost_particles); // Take maximum of statepoint n_batches and input n_batches settings::n_batches = std::max(settings::n_batches, temp); diff --git a/tests/regression_tests/photon_source/results_true.dat b/tests/regression_tests/photon_source/results_true.dat index ab6ac9ff83..1448ad6db8 100644 --- a/tests/regression_tests/photon_source/results_true.dat +++ b/tests/regression_tests/photon_source/results_true.dat @@ -1,5 +1,3 @@ tally 1: sum = 2.275713E+02 sum_sq = 5.178870E+04 -max_lost = 5.000000E+00 -rel_max_lost = 1.000000E-01 diff --git a/tests/regression_tests/photon_source/test.py b/tests/regression_tests/photon_source/test.py index c5c42d680e..09a0b4a2d0 100644 --- a/tests/regression_tests/photon_source/test.py +++ b/tests/regression_tests/photon_source/test.py @@ -54,8 +54,6 @@ class SourceTestHarness(PyAPITestHarness): outstr += 'tally {}:\n'.format(t.id) outstr += 'sum = {:12.6E}\n'.format(t.sum[0, 0, 0]) outstr += 'sum_sq = {:12.6E}\n'.format(t.sum_sq[0, 0, 0]) - outstr += 'max_lost = {:12.6E}\n'.format(sp.n_max_lost_particles) - outstr += 'rel_max_lost = {:12.6E}\n'.format(sp.relative_max_lost_particles) return outstr From 68312dd9818cecd8129206b4a1a9d816432169e5 Mon Sep 17 00:00:00 2001 From: stevendargaville Date: Thu, 13 Feb 2020 14:43:31 +0000 Subject: [PATCH 07/11] Revert "Modified an existing regression test to include the new max_lost_particles and relative version. This is mainly a test that the python/xml input/output routines work through the comparison the regression test harness does in this test, neither of these trigger the end of the simulation." This reverts commit 9224ca318675fcbb06c8eb97d9569466874dda21. --- tests/regression_tests/photon_source/inputs_true.dat | 2 -- tests/regression_tests/photon_source/test.py | 2 -- 2 files changed, 4 deletions(-) diff --git a/tests/regression_tests/photon_source/inputs_true.dat b/tests/regression_tests/photon_source/inputs_true.dat index 83c909ac69..89f4de0e0c 100644 --- a/tests/regression_tests/photon_source/inputs_true.dat +++ b/tests/regression_tests/photon_source/inputs_true.dat @@ -18,8 +18,6 @@ fixed source 10000 1 - 5 - 0.1 0 0 0 diff --git a/tests/regression_tests/photon_source/test.py b/tests/regression_tests/photon_source/test.py index 09a0b4a2d0..94b0280031 100644 --- a/tests/regression_tests/photon_source/test.py +++ b/tests/regression_tests/photon_source/test.py @@ -31,8 +31,6 @@ class SourceTestHarness(PyAPITestHarness): settings = openmc.Settings() settings.particles = 10000 settings.batches = 1 - settings.max_lost_particles = 5 - settings.rel_max_lost_particles = 0.1 settings.photon_transport = True settings.electron_treatment = 'ttb' settings.cutoff = {'energy_photon' : 1000.0} From 18b469bfa5cc4b4d1280655e9166c997db267481 Mon Sep 17 00:00:00 2001 From: stevendargaville Date: Thu, 13 Feb 2020 14:44:53 +0000 Subject: [PATCH 08/11] Removed new variables from the statepoint python file as they are no longer read out --- openmc/statepoint.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/openmc/statepoint.py b/openmc/statepoint.py index 0d78bf68dc..a8e13efd25 100644 --- a/openmc/statepoint.py +++ b/openmc/statepoint.py @@ -77,10 +77,6 @@ class StatePoint(object): Number of batches n_inactive : int Number of inactive batches - n_max_lost_particles : int - Number of max lost particles - relative_max_lost_particles : float - Number of max lost particles, relative to the total number of particles n_particles : int Number of particles per generation n_realizations : int @@ -316,10 +312,6 @@ class StatePoint(object): else: return None - @property - def n_max_lost_particles(self): - return self._f['n_max_lost_particles'][()] - @property def relative_max_lost_particles(self): return self._f['relative_max_lost_particles'][()] From a9d1e37aba4aeadb683947861bb0a392c364e878 Mon Sep 17 00:00:00 2001 From: stevendargaville Date: Thu, 13 Feb 2020 14:46:34 +0000 Subject: [PATCH 09/11] Changed the name of the max_lost_particles in the C++ layer to match the python side --- include/openmc/settings.h | 2 +- openmc/lib/settings.py | 2 +- src/particle.cpp | 2 +- src/settings.cpp | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/openmc/settings.h b/include/openmc/settings.h index 3407eadf4b..8cee3c72ab 100644 --- a/include/openmc/settings.h +++ b/include/openmc/settings.h @@ -65,7 +65,7 @@ extern "C" std::string path_statepoint; //!< path to a statepoint file extern "C" int32_t n_batches; //!< number of (inactive+active) batches extern "C" int32_t n_inactive; //!< number of inactive batches -extern "C" int32_t n_max_lost_particles; //!< maximum number of lost particles +extern "C" int32_t max_lost_particles; //!< maximum number of lost particles extern double relative_max_lost_particles; //!< maximum number of lost particles, relative to the total number of particles extern "C" int32_t gen_per_batch; //!< number of generations per batch extern "C" int64_t n_particles; //!< number of particles per generation diff --git a/openmc/lib/settings.py b/openmc/lib/settings.py index 8345e00881..fa72e13234 100644 --- a/openmc/lib/settings.py +++ b/openmc/lib/settings.py @@ -22,7 +22,7 @@ class _Settings(object): entropy_on = _DLLGlobal(c_bool, 'entropy_on') generations_per_batch = _DLLGlobal(c_int32, 'gen_per_batch') inactive = _DLLGlobal(c_int32, 'n_inactive') - max_lost_particles = _DLLGlobal(c_int32, 'n_max_lost_particles') + max_lost_particles = _DLLGlobal(c_int32, 'max_lost_particles') rel_max_lost_particles = _DLLGlobal(c_double, 'relative_max_lost_particles') particles = _DLLGlobal(c_int64, 'n_particles') restart_run = _DLLGlobal(c_bool, 'restart_run') diff --git a/src/particle.cpp b/src/particle.cpp index 79e6625771..7e98b2ce67 100644 --- a/src/particle.cpp +++ b/src/particle.cpp @@ -630,7 +630,7 @@ Particle::mark_as_lost(const char* message) // Abort the simulation if the maximum number of lost particles has been // reached - if (simulation::n_lost_particles >= settings::n_max_lost_particles && + if (simulation::n_lost_particles >= settings::max_lost_particles && simulation::n_lost_particles >= settings::relative_max_lost_particles*n) { fatal_error("Maximum number of lost particles has been reached."); } diff --git a/src/settings.cpp b/src/settings.cpp index d72e5f17f7..933f9a2172 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -79,7 +79,7 @@ std::string path_statepoint; int32_t n_batches; int32_t n_inactive {0}; -int32_t n_max_lost_particles {10}; +int32_t max_lost_particles {10}; double relative_max_lost_particles {1.0e-6}; int32_t gen_per_batch {1}; int64_t n_particles {-1}; @@ -147,7 +147,7 @@ void get_run_parameters(pugi::xml_node node_base) // Get max number of lost particles if (check_for_node(node_base, "max_lost_particles")) { - n_max_lost_particles = std::stoi(get_node_value(node_base, "max_lost_particles")); + max_lost_particles = std::stoi(get_node_value(node_base, "max_lost_particles")); } // Get relative number of lost particles @@ -362,7 +362,7 @@ void read_settings_xml() fatal_error("Number of inactive batches must be non-negative."); } else if (n_particles <= 0) { fatal_error("Number of particles must be greater than zero."); - } else if (n_max_lost_particles <= 0) { + } else if (max_lost_particles <= 0) { fatal_error("Number of max lost particles must be greater than zero."); } else if (relative_max_lost_particles <= 0.0 || relative_max_lost_particles >= 1.0) { fatal_error("Relative max lost particles must be between zero and one."); From a9fc400863952502bad61fd73bb80993448afc74 Mon Sep 17 00:00:00 2001 From: stevendargaville Date: Thu, 13 Feb 2020 14:51:32 +0000 Subject: [PATCH 10/11] Also removed relative_max_lost_particles from statepoint python as it is not being written out --- openmc/statepoint.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/openmc/statepoint.py b/openmc/statepoint.py index a8e13efd25..84512d70e7 100644 --- a/openmc/statepoint.py +++ b/openmc/statepoint.py @@ -310,11 +310,7 @@ class StatePoint(object): if self.run_mode == 'eigenvalue': return self._f['n_inactive'][()] else: - return None - - @property - def relative_max_lost_particles(self): - return self._f['relative_max_lost_particles'][()] + return None @property def n_particles(self): From d763806c43ea05adb25831b8fd11c828fd40d06a Mon Sep 17 00:00:00 2001 From: stevendargaville Date: Thu, 13 Feb 2020 14:52:44 +0000 Subject: [PATCH 11/11] Also made rel_max_lost_particle name consistent between C++ and python layers --- include/openmc/settings.h | 2 +- openmc/lib/settings.py | 2 +- src/particle.cpp | 2 +- src/settings.cpp | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/openmc/settings.h b/include/openmc/settings.h index 8cee3c72ab..2b4203646f 100644 --- a/include/openmc/settings.h +++ b/include/openmc/settings.h @@ -66,7 +66,7 @@ extern "C" std::string path_statepoint; //!< path to a statepoint file extern "C" int32_t n_batches; //!< number of (inactive+active) batches extern "C" int32_t n_inactive; //!< number of inactive batches extern "C" int32_t max_lost_particles; //!< maximum number of lost particles -extern double relative_max_lost_particles; //!< maximum number of lost particles, relative to the total number of particles +extern double rel_max_lost_particles; //!< maximum number of lost particles, relative to the total number of particles extern "C" int32_t gen_per_batch; //!< number of generations per batch extern "C" int64_t n_particles; //!< number of particles per generation diff --git a/openmc/lib/settings.py b/openmc/lib/settings.py index fa72e13234..68d68c29e0 100644 --- a/openmc/lib/settings.py +++ b/openmc/lib/settings.py @@ -23,7 +23,7 @@ class _Settings(object): generations_per_batch = _DLLGlobal(c_int32, 'gen_per_batch') inactive = _DLLGlobal(c_int32, 'n_inactive') max_lost_particles = _DLLGlobal(c_int32, 'max_lost_particles') - rel_max_lost_particles = _DLLGlobal(c_double, 'relative_max_lost_particles') + rel_max_lost_particles = _DLLGlobal(c_double, 'rel_max_lost_particles') particles = _DLLGlobal(c_int64, 'n_particles') restart_run = _DLLGlobal(c_bool, 'restart_run') run_CE = _DLLGlobal(c_bool, 'run_CE') diff --git a/src/particle.cpp b/src/particle.cpp index 7e98b2ce67..8f6dba803f 100644 --- a/src/particle.cpp +++ b/src/particle.cpp @@ -631,7 +631,7 @@ Particle::mark_as_lost(const char* message) // Abort the simulation if the maximum number of lost particles has been // reached if (simulation::n_lost_particles >= settings::max_lost_particles && - simulation::n_lost_particles >= settings::relative_max_lost_particles*n) { + simulation::n_lost_particles >= settings::rel_max_lost_particles*n) { fatal_error("Maximum number of lost particles has been reached."); } } diff --git a/src/settings.cpp b/src/settings.cpp index 933f9a2172..706a171458 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -80,7 +80,7 @@ std::string path_statepoint; int32_t n_batches; int32_t n_inactive {0}; int32_t max_lost_particles {10}; -double relative_max_lost_particles {1.0e-6}; +double rel_max_lost_particles {1.0e-6}; int32_t gen_per_batch {1}; int64_t n_particles {-1}; @@ -152,7 +152,7 @@ void get_run_parameters(pugi::xml_node node_base) // Get relative number of lost particles if (check_for_node(node_base, "rel_max_lost_particles")) { - relative_max_lost_particles = std::stod(get_node_value(node_base, "rel_max_lost_particles")); + rel_max_lost_particles = std::stod(get_node_value(node_base, "rel_max_lost_particles")); } // Get number of inactive batches @@ -364,7 +364,7 @@ void read_settings_xml() fatal_error("Number of particles must be greater than zero."); } else if (max_lost_particles <= 0) { fatal_error("Number of max lost particles must be greater than zero."); - } else if (relative_max_lost_particles <= 0.0 || relative_max_lost_particles >= 1.0) { + } else if (rel_max_lost_particles <= 0.0 || rel_max_lost_particles >= 1.0) { fatal_error("Relative max lost particles must be between zero and one."); } }