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

Time Cutoff #2454

Closed
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
c9b99ef
time cutoff
Apr 4, 2023
c45da7f
remove empty line
Apr 4, 2023
6b6892d
read time cutoff from xml
Apr 4, 2023
015a2f1
ask for time before particle advances
Apr 5, 2023
9e3ab6b
clang-format
Apr 14, 2023
f6707e1
time cutoff after updating variable
Apr 21, 2023
2e0f15d
documentation time cutoff
Apr 21, 2023
2f21784
suggested changes by gridley/paulromano
Apr 26, 2023
f1bcd7d
regression test time-cutoff
Apr 26, 2023
8ba821c
change dafault cutoff to INFTY
Apr 27, 2023
6423cb9
reproducibility: sort surf source bank before write
gridley Apr 27, 2023
a0a54de
hit_time_boundray as local variable
Apr 27, 2023
dbe80bb
time cutoff
Apr 4, 2023
de0f982
remove empty line
Apr 4, 2023
e44d054
read time cutoff from xml
Apr 4, 2023
66676ed
ask for time before particle advances
Apr 5, 2023
873df5b
clang-format
Apr 14, 2023
9412c75
clang-format
Apr 14, 2023
d36d1f4
time cutoff after updating variable
Apr 21, 2023
b594a8d
time cutoff after updating variable
Apr 21, 2023
7da9ce3
documentation time cutoff
Apr 21, 2023
d1604f8
suggested changes by gridley/paulromano
Apr 26, 2023
f1b7658
regression test time-cutoff
Apr 26, 2023
4e2e2a0
regression test time-cutoff
Apr 26, 2023
43927b9
change dafault cutoff to INFTY
Apr 27, 2023
2f10609
hit_time_boundray as local variable
Apr 27, 2023
4220a75
reabse
Apr 27, 2023
adbd491
if condition time boundary
Apr 27, 2023
1a7f904
dont redeclarate time boundary
Apr 27, 2023
c9ada80
add removed path_statepoint_c in settings.h
Apr 28, 2023
d7f9785
remove trailing whitespaces
Apr 28, 2023
023ad26
addressing issue #2508
May 1, 2023
c8ae430
revert last changes
May 2, 2023
899550e
p.alive in process_advance_particle_events
May 3, 2023
42e4476
check if particle got killed after advance
May 3, 2023
46d57d5
undo sort surf source bank
May 3, 2023
31773e6
run with sort surf source bank again
May 4, 2023
fb56eb6
other readout of the surface source in test
May 11, 2023
36a09c3
inputs xml time cutoff
May 11, 2023
9f82601
change
cfichtlscherer Jul 15, 2023
2607045
Incorporate Paul's suggested changes
cfichtlscherer Aug 2, 2023
d811a14
revert changes in surface_source_test
cfichtlscherer Aug 2, 2023
33325af
merge develop & resolve merge conflict settings.py
cfichtlscherer Aug 2, 2023
6675519
typo
cfichtlscherer Aug 2, 2023
8f06730
clang
cfichtlscherer Aug 2, 2023
8f42e04
revert wrong clang changes in particle_data.h
cfichtlscherer Aug 2, 2023
c04b93f
clang particle data
cfichtlscherer Aug 2, 2023
81cb17f
typo
cfichtlscherer Aug 3, 2023
6482ac9
typo
cfichtlscherer Aug 6, 2023
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
37 changes: 30 additions & 7 deletions docs/source/io_formats/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,16 @@ fission.
``<cutoff>`` Element
--------------------

The ``<cutoff>`` element indicates two kinds of cutoffs. The first is the weight
cutoff used below which particles undergo Russian roulette. Surviving particles
are assigned a user-determined weight. Note that weight cutoffs and Russian
rouletting are not turned on by default. The second is the energy cutoff which
is used to kill particles under certain energy. The energy cutoff should not be
used unless you know particles under the energy are of no importance to results
you care. This element has the following attributes/sub-elements:
The ``<cutoff>`` element indicates three kinds of cutoffs. The first is the
weight cutoff used below which particles undergo Russian roulette. Surviving
particles are assigned a user-determined weight. Note that weight cutoffs and
Russian rouletting are not turned on by default. The second is the energy cutoff
which is used to kill particles under certain energy. The energy cutoff should
not be used unless you know particles under the energy are of no importance to
results you care. The third is the time cutoff used to kill particles whose time
exceeds a specific cutoff.
gridley marked this conversation as resolved.
Show resolved Hide resolved

This element has the following attributes/sub-elements:

:weight:
The weight below which particles undergo Russian roulette.
Expand Down Expand Up @@ -99,6 +102,26 @@ you care. This element has the following attributes/sub-elements:

*Default*: 0.0

:time_neutrons
The time above which neutrons will be killed.

*Default*: 1.7976931348623157E+308
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be better to just say "Infinity"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, thats better.


:time_photons
The time above which photons will be killed.

*Default*: 1.7976931348623157E+308

:time_electrons
The time above which electrons will be killed.

*Default*: 1.7976931348623157E+308

:time_positrons
The time above which positorns will be killed.

*Default*: 1.7976931348623157E+308

----------------------------
``<delayed_photon_scaling>``
----------------------------
Expand Down
32 changes: 17 additions & 15 deletions include/openmc/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ extern bool assume_separate; //!< assume tallies are spatially separate?
extern bool check_overlaps; //!< check overlaps in geometry?
extern bool confidence_intervals; //!< use confidence intervals for results?
extern bool
create_fission_neutrons; //!< create fission neutrons (fixed source)?
create_fission_neutrons; //!< create fission neutrons (fixed source)?
extern bool create_delayed_neutrons; //!< create delayed fission neutrons?
extern "C" bool cmfd_run; //!< is a CMFD run?
extern "C" bool cmfd_run; //!< is a CMFD run?
extern bool
delayed_photon_scaling; //!< Scale fission photon yield to include delayed
extern "C" bool entropy_on; //!< calculate Shannon entropy?
extern "C" bool
event_based; //!< use event-based mode (instead of history-based)
event_based; //!< use event-based mode (instead of history-based)
extern bool legendre_to_tabular; //!< convert Legendre distributions to tabular?
extern bool material_cell_offsets; //!< create material cells offsets?
extern "C" bool output_summary; //!< write summary.h5?
Expand Down Expand Up @@ -70,8 +70,8 @@ extern std::string path_particle_restart; //!< path to a particle restart file
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_inactive; //!< number of inactive batches
extern "C" int32_t max_lost_particles; //!< maximum number of lost particles
extern "C" int32_t n_inactive; //!< number of inactive batches
extern "C" int32_t max_lost_particles; //!< maximum number of lost particles
extern double
rel_max_lost_particles; //!< maximum number of lost particles, relative to the
//!< total number of particles
Expand All @@ -82,9 +82,11 @@ extern int64_t
max_particles_in_flight; //!< Max num. event-based particles in flight

extern ElectronTreatment
electron_treatment; //!< how to treat secondary electrons
electron_treatment; //!< how to treat secondary electrons
extern array<double, 4>
energy_cutoff; //!< Energy cutoff in [eV] for each particle type
energy_cutoff; //!< Energy cutoff in [eV] for each particle type
extern array<double, 4>
time_cutoff; //!< Time cutoff in [s] for each particle type
extern int
legendre_to_tabular_points; //!< number of points to convert Legendres
extern int max_order; //!< Maximum Legendre order for multigroup data
Expand All @@ -99,24 +101,24 @@ extern vector<std::string>
res_scat_nuclides; //!< Nuclides using res. upscattering treatment
extern RunMode run_mode; //!< Run mode (eigenvalue, fixed src, etc.)
extern std::unordered_set<int>
sourcepoint_batch; //!< Batches when source should be written
sourcepoint_batch; //!< Batches when source should be written
extern std::unordered_set<int>
statepoint_batch; //!< Batches when state should be written
statepoint_batch; //!< Batches when state should be written
extern std::unordered_set<int>
source_write_surf_id; //!< Surface ids where sources will be written
source_write_surf_id; //!< Surface ids where sources will be written
extern int max_splits; //!< maximum number of particle splits for weight windows
extern int64_t max_surface_particles; //!< maximum number of particles to be
//!< banked on surfaces per process
extern TemperatureMethod
temperature_method; //!< method for choosing temperatures
temperature_method; //!< method for choosing temperatures
extern double
temperature_tolerance; //!< Tolerance in [K] on choosing temperatures
extern double temperature_default; //!< Default T in [K]
extern array<double, 2>
temperature_range; //!< Min/max T in [K] over which to load xs
extern int trace_batch; //!< Batch to trace particle on
extern int trace_gen; //!< Generation to trace particle on
extern int64_t trace_particle; //!< Particle ID to enable trace on
temperature_range; //!< Min/max T in [K] over which to load xs
extern int trace_batch; //!< Batch to trace particle on
extern int trace_gen; //!< Generation to trace particle on
extern int64_t trace_particle; //!< Particle ID to enable trace on
extern vector<array<int, 3>>
track_identifiers; //!< Particle numbers for writing tracks
extern int trigger_batch_interval; //!< Batch interval for triggers
Expand Down
23 changes: 15 additions & 8 deletions openmc/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,17 @@ class Settings:
deviation.
create_fission_neutrons : bool
Indicate whether fission neutrons should be created or not.
cutoff : dict
Dictionary defining weight cutoff and energy cutoff. The dictionary may
have six keys, 'weight', 'weight_avg', 'energy_neutron', 'energy_photon',
'energy_electron', and 'energy_positron'. Value for 'weight'
cutoff : dict
Dictionary defining weight cutoff, energy cutoff and time cutoff. The
dictionary may have ten keys, 'weight', 'weight_avg', 'energy_neutron',
'energy_photon', 'energy_electron', 'energy_positron', 'time_neutron',
'time_photon', 'time_electron', and 'time_positron'. Value for 'weight'
should be a float indicating weight cutoff below which particle undergo
Russian roulette. Value for 'weight_avg' should be a float indicating
weight assigned to particles that are not killed after Russian
roulette. Value of energy should be a float indicating energy in eV
below which particle type will be killed.
weight assigned to particles that are not killed after Russian roulette.
Value of energy should be a float indicating energy in eV below which
particle type will be killed. Value of time should be a float indicating
time in s above which particle type will be killed.
gridley marked this conversation as resolved.
Show resolved Hide resolved
delayed_photon_scaling : bool
Indicate whether to scale the fission photon yield by (EGP + EGD)/EGP
where EGP is the energy release of prompt photons and EGD is the energy
Expand Down Expand Up @@ -736,6 +738,10 @@ def cutoff(self, cutoff: dict):
'energy_positron']:
cv.check_type('energy cutoff', cutoff[key], Real)
cv.check_greater_than('energy cutoff', cutoff[key], 0.0)
elif key in ['time_neutron', 'time_photon', 'time_electron',
'time_positron']:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slightly more efficient

Suggested change
elif key in ['time_neutron', 'time_photon', 'time_electron',
'time_positron']:
elif key in ('time_neutron', 'time_photon', 'time_electron',
'time_positron'):

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, also changed it for the energy_cutoff

cv.check_type('time cutoff', cutoff[key], Real)
cv.check_greater_than('time cutoff', cutoff[key], 0.0)
else:
msg = f'Unable to set cutoff to "{key}" which is unsupported ' \
'by OpenMC'
Expand Down Expand Up @@ -1457,7 +1463,8 @@ def _cutoff_from_xml_element(self, root):
if elem is not None:
self.cutoff = {}
for key in ('energy_neutron', 'energy_photon', 'energy_electron',
'energy_positron', 'weight', 'weight_avg'):
'energy_positron', 'weight', 'weight_avg', 'time_neutron',
'time_photon', 'time_electron', 'time_positron'):
value = get_text(elem, key)
if value is not None:
self.cutoff[key] = float(value)
Expand Down
4 changes: 4 additions & 0 deletions src/finalize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "openmc/weight_windows.h"

#include "xtensor/xview.hpp"
#include <limits> // for numeric_limits

namespace openmc {

Expand Down Expand Up @@ -78,6 +79,9 @@ int openmc_finalize()
settings::electron_treatment = ElectronTreatment::LED;
settings::delayed_photon_scaling = true;
settings::energy_cutoff = {0.0, 1000.0, 0.0, 0.0};
settings::time_cutoff = {std::numeric_limits<double>::max(),
std::numeric_limits<double>::max(), std::numeric_limits<double>::max(),
std::numeric_limits<double>::max()};
settings::entropy_on = false;
settings::event_based = false;
settings::gen_per_batch = 1;
Expand Down
6 changes: 6 additions & 0 deletions src/particle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,12 @@ void Particle::event_advance()
// Select smaller of the two distances
double distance = std::min(boundary().distance, collision_distance());

// Kill particle if its time exceeds the cutoff
if (time() + (distance / this->speed()) >
gridley marked this conversation as resolved.
Show resolved Hide resolved
settings::time_cutoff[static_cast<int>(type())]) {
wgt() = 0.0;
}

// Advance particle in space and time
for (int j = 0; j < n_coord(); ++j) {
coord(j).r += distance * coord(j).u;
Expand Down
15 changes: 15 additions & 0 deletions src/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ int64_t max_particles_in_flight {100000};

ElectronTreatment electron_treatment {ElectronTreatment::TTB};
array<double, 4> energy_cutoff {0.0, 1000.0, 0.0, 0.0};
array<double, 4> time_cutoff {std::numeric_limits<double>::max(),
std::numeric_limits<double>::max(), std::numeric_limits<double>::max(),
std::numeric_limits<double>::max()};
int legendre_to_tabular_points {C_NONE};
int max_order {0};
int n_log_bins {8000};
Expand Down Expand Up @@ -536,6 +539,18 @@ void read_settings_xml(pugi::xml_node root)
energy_cutoff[3] =
std::stod(get_node_value(node_cutoff, "energy_positron"));
}
if (check_for_node(node_cutoff, "time_neutron")) {
time_cutoff[0] = std::stod(get_node_value(node_cutoff, "time_neutron"));
}
if (check_for_node(node_cutoff, "time_photon")) {
time_cutoff[1] = std::stod(get_node_value(node_cutoff, "time_photon"));
}
if (check_for_node(node_cutoff, "time_electron")) {
time_cutoff[2] = std::stod(get_node_value(node_cutoff, "time_electron"));
}
if (check_for_node(node_cutoff, "time_positron")) {
time_cutoff[3] = std::stod(get_node_value(node_cutoff, "time_positron"));
}
}

// Particle trace
Expand Down
8 changes: 6 additions & 2 deletions tests/unit_tests/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ def test_export_to_xml(run_in_tmpdir):
s.survival_biasing = True
s.cutoff = {'weight': 0.25, 'weight_avg': 0.5, 'energy_neutron': 1.0e-5,
'energy_photon': 1000.0, 'energy_electron': 1.0e-5,
'energy_positron': 1.0e-5}
'energy_positron': 1.0e-5, 'time_neutron': 1.0e-5,
'time_photon': 1.0e-5, 'time_electron': 1.0e-5,
'time_positron': 1.0e-5}
mesh = openmc.RegularMesh()
mesh.lower_left = (-10., -10., -10.)
mesh.upper_right = (10., 10., 10.)
Expand Down Expand Up @@ -86,7 +88,9 @@ def test_export_to_xml(run_in_tmpdir):
assert s.survival_biasing
assert s.cutoff == {'weight': 0.25, 'weight_avg': 0.5,
'energy_neutron': 1.0e-5, 'energy_photon': 1000.0,
'energy_electron': 1.0e-5, 'energy_positron': 1.0e-5}
'energy_electron': 1.0e-5, 'energy_positron': 1.0e-5,
'time_neutron': 1.0e-5, 'time_photon': 1.0e-5,
'time_electron': 1.0e-5, 'time_positron': 1.0e-5}
assert isinstance(s.entropy_mesh, openmc.RegularMesh)
assert s.entropy_mesh.lower_left == [-10., -10., -10.]
assert s.entropy_mesh.upper_right == [10., 10., 10.]
Expand Down