Skip to content

Commit

Permalink
Changed thread_safe_append() to require a value argument, and re-arra…
Browse files Browse the repository at this point in the history
…nged create_fission_sites() in physics.cpp and physics_mg.cpp to use the new interface.
  • Loading branch information
jtramm committed Jan 29, 2020
1 parent 18b1166 commit 76e58e7
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 51 deletions.
2 changes: 1 addition & 1 deletion include/openmc/shared_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class SharedArray {
//! \return The index in the array written to. In the event that this
//! index would be greater than what was allocated for the container,
//! return -1.
int64_t thread_safe_append(const T& value = {})
int64_t thread_safe_append(const T& value)
{
// Atomically capture the index we want to write to
int64_t idx;
Expand Down
37 changes: 18 additions & 19 deletions src/physics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,33 +179,32 @@ create_fission_sites(Particle* p, int i_nuclide, const Reaction* rx)
bool use_fission_bank = (settings::run_mode == RunMode::EIGENVALUE);

for (int i = 0; i < nu; ++i) {
Particle::Bank* site;
// Initialize fission site object with particle data
Particle::Bank site;
site.r = p->r();
site.particle = Particle::Type::neutron;
site.wgt = 1. / weight;
site.parent_id = p->id_;
site.progeny_id = p->n_progeny_++;

// Sample delayed group and angle/energy for fission reaction
sample_fission_neutron(i_nuclide, rx, p->E_, &site, p->current_seed());

// Store fission site in bank
if (use_fission_bank) {
int64_t idx = simulation::fission_bank.thread_safe_append();
int64_t idx = simulation::fission_bank.thread_safe_append(site);
if (idx == -1) {
warning("The shared fission bank is full. Additional fission sites created "
"in this generation will not be banked.");
skipped++;
break;
}
site = &simulation::fission_bank[idx];
} else {
// Create new bank site and get reference to last element
auto& bank = p->secondary_bank_;
bank.emplace_back();
site = &bank.back();
p->secondary_bank_.push_back(site);
}
site->r = p->r();
site->particle = Particle::Type::neutron;
site->wgt = 1. / weight;
site->parent_id = p->id_;
site->progeny_id = p->n_progeny_++;

// Sample delayed group and angle/energy for fission reaction
sample_fission_neutron(i_nuclide, rx, p->E_, site, p->current_seed());

// Set the delayed group on the particle as well
p->delayed_group_ = site->delayed_group;
p->delayed_group_ = site.delayed_group;

// Increment the number of neutrons born delayed
if (p->delayed_group_ > 0) {
Expand All @@ -216,9 +215,9 @@ create_fission_sites(Particle* p, int i_nuclide, const Reaction* rx)
if (use_fission_bank) {
p->nu_bank_.emplace_back();
Particle::NuBank* nu_bank_entry = &p->nu_bank_.back();
nu_bank_entry->wgt = site->wgt;
nu_bank_entry->E = site->E;
nu_bank_entry->delayed_group = site->delayed_group;
nu_bank_entry->wgt = site.wgt;
nu_bank_entry->E = site.E;
nu_bank_entry->delayed_group = site.delayed_group;
}
}

Expand Down
61 changes: 30 additions & 31 deletions src/physics_mg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,50 +125,49 @@ create_fission_sites(Particle* p)
bool use_fission_bank = (settings::run_mode == RunMode::EIGENVALUE);

for (int i = 0; i < nu; ++i) {
Particle::Bank* site;
if (use_fission_bank) {
int64_t idx = simulation::fission_bank.thread_safe_append();
if (idx == -1) {
warning("The shared fission bank is full. Additional fission sites created "
"in this generation will not be banked.");
skipped++;
break;
}
site = &simulation::fission_bank[idx];
} else {
// Create new bank site and get reference to last element
auto& bank = p->secondary_bank_;
bank.emplace_back();
site = &bank.back();
}

// Bank source neutrons by copying the particle data
site->r = p->r();
site->particle = Particle::Type::neutron;
site->wgt = 1. / weight;
site->parent_id = p->id_;
site->progeny_id = p->n_progeny_++;
// Initialize fission site object with particle data
Particle::Bank site;
site.r = p->r();
site.particle = Particle::Type::neutron;
site.wgt = 1. / weight;
site.parent_id = p->id_;
site.progeny_id = p->n_progeny_++;

// Sample the cosine of the angle, assuming fission neutrons are emitted
// isotropically
double mu = 2.*prn(p->current_seed()) - 1.;

// Sample the azimuthal angle uniformly in [0, 2.pi)
double phi = 2. * PI * prn(p->current_seed() );
site->u.x = mu;
site->u.y = std::sqrt(1. - mu * mu) * std::cos(phi);
site->u.z = std::sqrt(1. - mu * mu) * std::sin(phi);
site.u.x = mu;
site.u.y = std::sqrt(1. - mu * mu) * std::cos(phi);
site.u.z = std::sqrt(1. - mu * mu) * std::sin(phi);

// Sample secondary energy distribution for the fission reaction
int dg;
int gout;
data::mg.macro_xs_[p->material_].sample_fission_energy(p->g_, dg, gout,
p->current_seed());

// Store the energy and delayed groups on the fission bank
site->E = gout;
site.E = gout;

// We add 1 to the delayed_group bc in MG, -1 is prompt, but in the rest
// of the code, 0 is prompt.
site->delayed_group = dg + 1;
site.delayed_group = dg + 1;

// Store fission site in bank
if (use_fission_bank) {
int64_t idx = simulation::fission_bank.thread_safe_append(site);
if (idx == -1) {
warning("The shared fission bank is full. Additional fission sites created "
"in this generation will not be banked.");
skipped++;
break;
}
} else {
p->secondary_bank_.push_back(site);
}

// Set the delayed group on the particle as well
p->delayed_group_ = dg + 1;
Expand All @@ -182,9 +181,9 @@ create_fission_sites(Particle* p)
if (use_fission_bank) {
p->nu_bank_.emplace_back();
Particle::NuBank* nu_bank_entry = &p->nu_bank_.back();
nu_bank_entry->wgt = site->wgt;
nu_bank_entry->E = site->E;
nu_bank_entry->delayed_group = site->delayed_group;
nu_bank_entry->wgt = site.wgt;
nu_bank_entry->E = site.E;
nu_bank_entry->delayed_group = site.delayed_group;
}
}

Expand Down

0 comments on commit 76e58e7

Please sign in to comment.