From ef6156307976a325f67d9d26e5289fac7139a8cc Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Mon, 13 Sep 2021 16:01:48 -0500 Subject: [PATCH] Ensure time is propagated to secondary particles --- docs/source/io_formats/source.rst | 4 ++-- docs/source/io_formats/statepoint.rst | 10 +++++----- include/openmc/particle_data.h | 7 ++++--- openmc/lib/core.py | 1 + openmc/source.py | 8 ++++++-- src/initialize.cpp | 25 +++++++++++++------------ src/particle.cpp | 4 ++++ src/source.cpp | 8 -------- 8 files changed, 35 insertions(+), 32 deletions(-) diff --git a/docs/source/io_formats/source.rst b/docs/source/io_formats/source.rst index 86ae8a1e5..4ce2229ed 100644 --- a/docs/source/io_formats/source.rst +++ b/docs/source/io_formats/source.rst @@ -20,7 +20,7 @@ following the same format. - **source_bank** (Compound type) -- Source bank information for each particle. The compound type has fields ``r``, ``u``, ``E``, - ``wgt``, ``delayed_group``, ``surf_id`` and ``particle``, - which represent the position, direction, energy, weight, + ``time``, ``wgt``, ``delayed_group``, ``surf_id`` and ``particle``, + which represent the position, direction, energy, time, weight, delayed group, surface ID, and particle type (0=neutron, 1=photon, 2=electron, 3=positron), respectively. diff --git a/docs/source/io_formats/statepoint.rst b/docs/source/io_formats/statepoint.rst index 46725fa8b..591dc2777 100644 --- a/docs/source/io_formats/statepoint.rst +++ b/docs/source/io_formats/statepoint.rst @@ -52,11 +52,11 @@ The current version of the statepoint file format is 17.0. sum-of-squares for each global tally. - **source_bank** (Compound type) -- Source bank information for each particle. The compound type has fields ``r``, ``u``, ``E``, - ``wgt``, ``delayed_group``, ``surf_id``, and ``particle``, which - represent the position, direction, energy, weight, delayed group, - surface ID, and particle type (0=neutron, 1=photon, 2=electron, - 3=positron), respectively. - Only present when `run_mode` is 'eigenvalue'. + ``time``, ``wgt``, ``delayed_group``, ``surf_id``, and + ``particle``, which represent the position, direction, energy, + time, weight, delayed group, surface ID, and particle type + (0=neutron, 1=photon, 2=electron, 3=positron), respectively. Only + present when `run_mode` is 'eigenvalue'. **/tallies/** diff --git a/include/openmc/particle_data.h b/include/openmc/particle_data.h index 733ed3b81..06fccc092 100644 --- a/include/openmc/particle_data.h +++ b/include/openmc/particle_data.h @@ -44,9 +44,10 @@ struct SourceSite { Position r; Direction u; double E; - double wgt; - int delayed_group; - int surf_id; + double time {0.0}; + double wgt {1.0}; + int delayed_group {0}; + int surf_id {0}; ParticleType particle; int64_t parent_id; int64_t progeny_id; diff --git a/openmc/lib/core.py b/openmc/lib/core.py index e277d527a..e585444fb 100644 --- a/openmc/lib/core.py +++ b/openmc/lib/core.py @@ -16,6 +16,7 @@ class _SourceSite(Structure): _fields_ = [('r', c_double*3), ('u', c_double*3), ('E', c_double), + ('time', c_double), ('wgt', c_double), ('delayed_group', c_int), ('surf_id', c_int), diff --git a/openmc/source.py b/openmc/source.py index 415aacd96..8f25bcab0 100644 --- a/openmc/source.py +++ b/openmc/source.py @@ -253,6 +253,8 @@ class SourceParticle: Directional cosines E : float Energy of particle in [eV] + time : float + Time of particle in [s] wgt : float Weight of the particle delayed_group : int @@ -263,11 +265,12 @@ class SourceParticle: Type of the particle """ - def __init__(self, r=(0., 0., 0.), u=(0., 0., 1.), E=1.0e6, wgt=1.0, + def __init__(self, r=(0., 0., 0.), u=(0., 0., 1.), E=1.0e6, time=0.0, wgt=1.0, delayed_group=0, surf_id=0, particle=ParticleType.NEUTRON): self.r = tuple(r) self.u = tuple(u) self.E = float(E) + self.time = float(time) self.wgt = float(wgt) self.delayed_group = delayed_group self.surf_id = surf_id @@ -282,7 +285,7 @@ class SourceParticle: Source particle attributes """ - return (self.r, self.u, self.E, self.wgt, + return (self.r, self.u, self.E, self.time, self.wgt, self.delayed_group, self.surf_id, self.particle.value) @@ -309,6 +312,7 @@ def write_source_file(source_particles, filename, **kwargs): ('r', pos_dtype), ('u', pos_dtype), ('E', '= 0; --i) { + MPI_Get_address(&b.time, &disp[3]); + MPI_Get_address(&b.wgt, &disp[4]); + MPI_Get_address(&b.delayed_group, &disp[5]); + MPI_Get_address(&b.surf_id, &disp[6]); + MPI_Get_address(&b.particle, &disp[7]); + MPI_Get_address(&b.parent_id, &disp[8]); + MPI_Get_address(&b.progeny_id, &disp[9]); + for (int i = 9; i >= 0; --i) { disp[i] -= disp[0]; } - int blocks[] {3, 3, 1, 1, 1, 1, 1, 1, 1}; - MPI_Datatype types[] {MPI_DOUBLE, MPI_DOUBLE, MPI_DOUBLE, MPI_DOUBLE, MPI_INT, - MPI_INT, MPI_INT, MPI_LONG, MPI_LONG}; - MPI_Type_create_struct(9, blocks, disp, types, &mpi::source_site); + int blocks[] {3, 3, 1, 1, 1, 1, 1, 1, 1, 1}; + MPI_Datatype types[] {MPI_DOUBLE, MPI_DOUBLE, MPI_DOUBLE, MPI_DOUBLE, + MPI_DOUBLE, MPI_INT, MPI_INT, MPI_INT, MPI_LONG, MPI_LONG}; + MPI_Type_create_struct(10, blocks, disp, types, &mpi::source_site); MPI_Type_commit(&mpi::source_site); } #endif // OPENMC_MPI diff --git a/src/particle.cpp b/src/particle.cpp index 501792e31..7397c318f 100644 --- a/src/particle.cpp +++ b/src/particle.cpp @@ -77,6 +77,7 @@ void Particle::create_secondary( bank.r = r(); bank.u = u; bank.E = settings::run_CE ? E : g(); + bank.time = time(); n_bank_second() += 1; } @@ -111,6 +112,8 @@ void Particle::from_source(const SourceSite* src) E() = data::mg.energy_bin_avg_[g()]; } E_last() = E(); + time() = src->time; + time_last() = src->time; } void Particle::event_calculate_xs() @@ -399,6 +402,7 @@ void Particle::cross_surface() site.r = r(); site.u = u(); site.E = E(); + site.time = time(); site.wgt = wgt(); site.delayed_group = delayed_group(); site.surf_id = surf->id_; diff --git a/src/source.cpp b/src/source.cpp index 9c897dcf3..be4270b51 100644 --- a/src/source.cpp +++ b/src/source.cpp @@ -147,9 +147,6 @@ SourceSite IndependentSource::sample(uint64_t* seed) const { SourceSite site; - // Set weight to one by default - site.wgt = 1.0; - // Repeat sampling source location until a good site has been found bool found = false; int n_reject = 0; @@ -227,11 +224,6 @@ SourceSite IndependentSource::sample(uint64_t* seed) const break; } - // Set delayed group - site.delayed_group = 0; - // Set surface ID - site.surf_id = 0; - return site; }