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

Survival Normalization 0.15.1 #3070

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions docs/source/io_formats/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ time.
roulette.

*Default*: 1.0
:survival_normalization:
If this element is set to "true", this will enable the use of survival biasing source normalization, whereby the weight parameters, weight and weight_avg, are multiplied per
history by the start weight of said history.

*Default*: false


:energy_neutron:
The energy under which neutrons will be killed.
Expand Down
3 changes: 3 additions & 0 deletions include/openmc/particle_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ class ParticleData : public GeometryState {
int g_last_;

double wgt_ {1.0};
double wgt0_ {1.0};
double mu_;
double time_ {0.0};
double time_last_ {0.0};
Expand Down Expand Up @@ -507,6 +508,8 @@ class ParticleData : public GeometryState {
// indicates that the particle is dead.
double& wgt() { return wgt_; }
double wgt() const { return wgt_; }
double& wgt0() { return wgt0_; }
double wgt0() const { return wgt0_; }
double& wgt_last() { return wgt_last_; }
const double& wgt_last() const { return wgt_last_; }
bool alive() const { return wgt_ != 0.0; }
Expand Down
1 change: 1 addition & 0 deletions include/openmc/settings.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#ifndef OPENMC_SETTINGS_H

Check notice on line 1 in include/openmc/settings.h

View workflow job for this annotation

GitHub Actions / cpp-linter

Run clang-format on include/openmc/settings.h

File include/openmc/settings.h does not conform to Custom style guidelines. (lines 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70)
#define OPENMC_SETTINGS_H

//! \file settings.h
Expand Down Expand Up @@ -61,6 +61,7 @@
extern bool surf_mcpl_write; //!< write surface mcpl file?
extern bool surf_source_read; //!< read surface source file?
extern bool survival_biasing; //!< use survival biasing?
extern bool survival_normalization;//!< use survival normalization?
extern bool temperature_multipole; //!< use multipole data?
extern "C" bool trigger_on; //!< tally triggers enabled?
extern bool trigger_predict; //!< predict batches for triggers?
Expand Down
9 changes: 7 additions & 2 deletions src/physics.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "openmc/physics.h"

Check notice on line 1 in src/physics.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

Run clang-format on src/physics.cpp

File src/physics.cpp does not conform to Custom style guidelines. (lines 155, 157, 158, 159, 160)

#include "openmc/bank.h"
#include "openmc/bremsstrahlung.h"
Expand Down Expand Up @@ -152,8 +152,13 @@

// Play russian roulette if survival biasing is turned on
if (settings::survival_biasing) {
if (p.wgt() < settings::weight_cutoff) {
russian_roulette(p, settings::weight_survive);
// if survival normalization is on, use normalized weight cutoff and normalized weight survive
if (settings::survival_normalization) {
if (p.wgt() < settings::weight_cutoff*p.wgt0()) {
russian_roulette(p, settings::weight_survive*p.wgt0());
}
} else if (p.wgt() < settings::weight_cutoff) {
russian_roulette(p, settings::weight_survive);
}
}
}
Expand Down
9 changes: 7 additions & 2 deletions src/physics_mg.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "openmc/physics_mg.h"

Check notice on line 1 in src/physics_mg.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

Run clang-format on src/physics_mg.cpp

File src/physics_mg.cpp does not conform to Custom style guidelines. (lines 67, 69, 70, 71, 72)

#include <stdexcept>

Expand Down Expand Up @@ -64,8 +64,13 @@

// Play Russian roulette if survival biasing is turned on
if (settings::survival_biasing) {
if (p.wgt() < settings::weight_cutoff) {
russian_roulette(p, settings::weight_survive);
// if survival normalization is applicable, use normalized weight cutoff and normalized weight survive
if (settings::survival_normalization) {
if (p.wgt() < settings::weight_cutoff*p.wgt0()) {
russian_roulette(p, settings::weight_survive*p.wgt0());
}
} else if (p.wgt() < settings::weight_cutoff) {
russian_roulette(p, settings::weight_survive);
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/settings.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "openmc/settings.h"

Check notice on line 1 in src/settings.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

Run clang-format on src/settings.cpp

File src/settings.cpp does not conform to Custom style guidelines. (lines 570, 571)

#include <cmath> // for ceil, pow
#include <limits> // for numeric_limits
Expand Down Expand Up @@ -69,6 +69,7 @@
bool surf_mcpl_write {false};
bool surf_source_read {false};
bool survival_biasing {false};
bool survival_normalization {false};
bool temperature_multipole {false};
bool trigger_on {false};
bool trigger_predict {false};
Expand Down Expand Up @@ -566,6 +567,9 @@
if (check_for_node(node_cutoff, "weight_avg")) {
weight_survive = std::stod(get_node_value(node_cutoff, "weight_avg"));
}
if (check_for_node(node_cutoff, "survival_normalization")){
survival_normalization = get_node_value_bool(node_cutoff, "survival_normalization");
}
if (check_for_node(node_cutoff, "energy_neutron")) {
energy_cutoff[0] =
std::stod(get_node_value(node_cutoff, "energy_neutron"));
Expand Down
5 changes: 4 additions & 1 deletion src/simulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,9 @@ void initialize_history(Particle& p, int64_t index_source)
// set identifier for particle
p.id() = simulation::work_index[mpi::rank] + index_source;

// set particle history start weight
p.wgt0() = p.wgt(); // p.wgt0(p.wgt());

// set progeny count to zero
p.n_progeny() = 0;

Expand Down Expand Up @@ -603,7 +606,7 @@ void initialize_history(Particle& p, int64_t index_source)
write_message("Simulating Particle {}", p.id());
}

// Add paricle's starting weight to count for normalizing tallies later
// Add particle's starting weight to count for normalizing tallies later
#pragma omp atomic
simulation::total_weight += p.wgt();

Expand Down
Loading