diff --git a/src/bank.cpp b/src/bank.cpp index bc431f2a5..677645d10 100644 --- a/src/bank.cpp +++ b/src/bank.cpp @@ -39,6 +39,7 @@ void init_shared_fission_bank(int max) { simulation::shared_fission_bank_max = max; simulation::shared_fission_bank = new Particle::Bank[max]; + simulation::shared_fission_bank_length = 0; } void free_shared_fission_bank(void) diff --git a/src/physics.cpp b/src/physics.cpp index e779dec56..9cb93b2ae 100644 --- a/src/physics.cpp +++ b/src/physics.cpp @@ -176,14 +176,22 @@ create_fission_sites(Particle* p, int i_nuclide, const Reaction* rx, double nu_d[MAX_DELAYED_GROUPS] = {0.}; p->fission_ = true; + int skipped = 0; for (int i = 0; i < nu; ++i) { Particle::Bank * site; if(use_fission_bank) { - // Create new bank site and get reference to last element int idx; #pragma omp atomic capture idx = simulation::shared_fission_bank_length++; + if( idx >= simulation::shared_fission_bank_max ) + { + warning("The shared fission bank is full. Additional fission sites created in this generation will not be banked."); + #pragma omp atomic + simulation::shared_fission_bank_length--; + skipped++; + break; + } site = simulation::shared_fission_bank + idx; } else @@ -211,11 +219,23 @@ create_fission_sites(Particle* p, int i_nuclide, const Reaction* rx, // Write fission particles to nuBank if(use_fission_bank) { - p->nu_bank_[nu-1-i].wgt = site->wgt; - p->nu_bank_[nu-1-i].E = site->E; - p->nu_bank_[nu-1-i].delayed_group = site->delayed_group; + p->nu_bank_[i].wgt = site->wgt; + p->nu_bank_[i].E = site->E; + p->nu_bank_[i].delayed_group = site->delayed_group; } } + + // If shared fission bank was full, and no fissions could be added, + // set the particle fission flag to false. + if( nu == skipped ) + { + p->fission_ = false; + return; + } + + // If shared fission bank was full, but some fissions could be added, + // reduce nu accordingly + nu -= skipped; // Store the total weight banked for analog fission tallies p->n_bank_ = nu; diff --git a/src/physics_mg.cpp b/src/physics_mg.cpp index 7aae1294d..11ae2a045 100644 --- a/src/physics_mg.cpp +++ b/src/physics_mg.cpp @@ -119,18 +119,22 @@ create_fission_sites(Particle* p, std::vector& bank, bool use_fi double nu_d[MAX_DELAYED_GROUPS] = {0.}; p->fission_ = true; + int skipped = 0; for (int i = 0; i < nu; ++i) { - // Create new bank site and get reference to last element - //bank.emplace_back(); - //auto& site {bank.back()}; - Particle::Bank * site; if(use_fission_bank) { - // Create new bank site and get reference to last element int idx; #pragma omp atomic capture idx = simulation::shared_fission_bank_length++; + if( idx >= simulation::shared_fission_bank_max ) + { + warning("The shared fission bank is full. Additional fission sites created in this generation will not be banked."); + #pragma omp atomic + simulation::shared_fission_bank_length--; + skipped++; + break; + } site = simulation::shared_fission_bank + idx; } else @@ -178,11 +182,23 @@ create_fission_sites(Particle* p, std::vector& bank, bool use_fi // Write fission particles to nuBank if(use_fission_bank) { - p->nu_bank_[nu-1-i].wgt = site->wgt; - p->nu_bank_[nu-1-i].E = site->E; - p->nu_bank_[nu-1-i].delayed_group = site->delayed_group; + p->nu_bank_[i].wgt = site->wgt; + p->nu_bank_[i].E = site->E; + p->nu_bank_[i].delayed_group = site->delayed_group; } } + + // If shared fission bank was full, and no fissions could be added, + // set the particle fission flag to false. + if( nu == skipped ) + { + p->fission_ = false; + return; + } + + // If shared fission bank was full, but some fissions could be added, + // reduce nu accordingly + nu -= skipped; // Store the total weight banked for analog fission tallies p->n_bank_ = nu; diff --git a/src/simulation.cpp b/src/simulation.cpp index 39ed0bb6c..f08a15e0f 100644 --- a/src/simulation.cpp +++ b/src/simulation.cpp @@ -177,16 +177,10 @@ void transport_event_based() } // Finish particle track output and contribute to global tally variables + #pragma omp parallel for schedule(runtime) for (int i = 0; i < n_particles; i++) { Particle& p = simulation::particles[i]; - if (p.write_track_) { - write_particle_track(p); - finalize_particle_track(p); - } - global_tally_absorption += p.tally_absorption_; - global_tally_collision += p.tally_collision_; - global_tally_tracklength += p.tally_tracklength_; - global_tally_leakage += p.tally_leakage_; + p.event_death(); } remaining_work -= n_particles; @@ -554,49 +548,6 @@ void initialize_generation() } } -/* -struct bank_site_comparator -{ - inline bool operator() (const Particle::Bank & a, const Particle::Bank & b) - { - if( a.E < b.E ) - return true; - else if( a.E > b.E ) - return false; - else // Energy equal, compare by x-coord - { - if(a.r.x < b.r.x ) - return true; - else if (a.r.x > b.r.x) - return false; - else // x-coord equal, compare by y-coord - { - if(a.r.x < b.r.x ) - return true; - else if (a.r.x > b.r.x) - return false; - else // y-coord equal, compare by z-coord - { - if(a.r.y < b.r.y ) - return true; - else if (a.r.y > b.r.y) - return false; - else // y-coord equal, compare by z-coord - { - if(a.r.z < b.r.z ) - return true; - else if (a.r.z > b.r.z) - return false; - else // they are the same - return false; - } - } - } - } - } -}; -*/ - void finalize_generation() { auto& gt = simulation::global_tallies; @@ -654,15 +605,6 @@ void initialize_history(Particle* p, int64_t index_source) // set defaults p->from_source(&simulation::source_bank[index_source - 1]); p->current_work_ = index_source; - /* - p->n_event_ = 0; - - // Initialize global tally variables - p->tally_absorption_ = 0.0; - p->tally_collision_ = 0.0; - p->tally_tracklength_ = 0.0; - p->tally_leakage_ = 0.0; - */ // set identifier for particle p->id_ = simulation::work_index[mpi::rank] + index_source;