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.

This commit is contained in:
stevendargaville 2020-02-11 13:37:00 +00:00
parent dfe4d911b5
commit 516ac9e1d3
7 changed files with 53 additions and 10 deletions

View file

@ -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};

View file

@ -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

View file

@ -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')

View file

@ -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)

View file

@ -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'][()]

View file

@ -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.");
}

View file

@ -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