Skip to content

Commit 6f7344c

Browse files
jtrammCopilotpaulromano
authored
Weight Window Birth Scaling (openmc-dev#3459)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Paul Romano <paul.k.romano@gmail.com>
1 parent 8c0838e commit 6f7344c

3 files changed

Lines changed: 25 additions & 0 deletions

File tree

include/openmc/particle_data.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,7 @@ class ParticleData : public GeometryState {
435435

436436
double wgt_ {1.0};
437437
double wgt_born_ {1.0};
438+
double wgt_ww_born_ {-1.0};
438439
double mu_;
439440
double time_ {0.0};
440441
double time_last_ {0.0};
@@ -545,6 +546,10 @@ class ParticleData : public GeometryState {
545546
double& wgt_born() { return wgt_born_; }
546547
double wgt_born() const { return wgt_born_; }
547548

549+
// Weight window value at birth
550+
double& wgt_ww_born() { return wgt_ww_born_; }
551+
const double& wgt_ww_born() const { return wgt_ww_born_; }
552+
548553
// Statistic weight of particle at last collision
549554
double& wgt_last() { return wgt_last_; }
550555
const double& wgt_last() const { return wgt_last_; }

src/simulation.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,10 @@ void initialize_history(Particle& p, int64_t index_source)
614614
// Set particle track.
615615
p.write_track() = check_track_criteria(p);
616616

617+
// Set the particle's initial weight window value.
618+
p.wgt_ww_born() = -1.0;
619+
apply_weight_windows(p);
620+
617621
// Display message if high verbosity or trace is on
618622
if (settings::verbosity >= 9 || p.trace()) {
619623
write_message("Simulating Particle {}", p.id());

src/weight_windows.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,26 @@ void apply_weight_windows(Particle& p)
7373
if (weight_window.is_valid())
7474
break;
7575
}
76+
77+
// If particle has not yet had its birth weight window value set, set it to
78+
// the current weight window (or 1.0 if not born in a weight window).
79+
if (p.wgt_ww_born() == -1.0) {
80+
if (weight_window.is_valid()) {
81+
p.wgt_ww_born() =
82+
(weight_window.lower_weight + weight_window.upper_weight) / 2;
83+
} else {
84+
p.wgt_ww_born() = 1.0;
85+
}
86+
}
87+
7688
// particle is not in any of the ww domains, do nothing
7789
if (!weight_window.is_valid())
7890
return;
7991

92+
// Normalize weight windows based on particle's starting weight
93+
// and the value of the weight window the particle was born in.
94+
weight_window.scale(p.wgt_born() / p.wgt_ww_born());
95+
8096
// get the paramters
8197
double weight = p.wgt();
8298

0 commit comments

Comments
 (0)