Move source and fission banks to C++

This commit is contained in:
Paul Romano 2018-11-15 08:13:14 -06:00
parent 887636d398
commit b8187571b3
23 changed files with 385 additions and 299 deletions

View file

@ -1,5 +1,6 @@
#include "openmc/simulation.h"
#include "openmc/bank.h"
#include "openmc/capi.h"
#include "openmc/container_util.h"
#include "openmc/eigenvalue.h"
@ -15,6 +16,8 @@
#include "openmc/tallies/filter.h"
#include "openmc/tallies/tally.h"
#include <omp.h>
#include <algorithm>
#include <string>
@ -24,14 +27,12 @@ namespace openmc {
extern "C" bool cmfd_on;
extern "C" void accumulate_tallies();
extern "C" void allocate_banks();
extern "C" void allocate_tally_results();
extern "C" void check_triggers();
extern "C" void cmfd_init_batch();
extern "C" void cmfd_tally_init();
extern "C" void execute_cmfd();
extern "C" void init_tally_routines();
extern "C" void join_bank_from_threads();
extern "C" void load_state_point();
extern "C" void print_batch_keff();
extern "C" void print_columns();
@ -280,6 +281,36 @@ int thread_id; //!< ID of a given thread
// Non-member functions
//==============================================================================
void allocate_banks()
{
// Allocate source bank
simulation::source_bank.resize(simulation::work);
if (settings::run_mode == RUN_MODE_EIGENVALUE) {
#ifdef _OPENMP
// If OpenMP is being used, each thread needs its own private fission
// bank. Since the private fission banks need to be combined at the end of
// a generation, there is also a 'master_fission_bank' that is used to
// collect the sites from each thread.
simulation::n_threads = omp_get_max_threads();
#pragma omp parallel
{
simulation::thread_id = omp_get_thread_num();
if (simulation::thread_id == 0) {
simulation::fission_bank.resize(3*simulation::work);
} else {
simulation::fission_bank.resize(3*simulation::work / simulation::n_threads);
}
}
simulation::master_fission_bank.resize(3*simulation::work);
#else
simulation::fission_bank.resize(3*simulation::work);
#endif
}
}
void initialize_batch()
{
// Increment current batch
@ -453,13 +484,8 @@ void finalize_generation()
void initialize_history(Particle* p, int64_t index_source)
{
// Get pointer to source bank
Bank* source_bank;
int64_t n;
openmc_source_bank(&source_bank, &n);
// set defaults
p->from_source(&source_bank[index_source - 1]);
p->from_source(&simulation::source_bank[index_source - 1]);
// set identifier for particle
p->id = simulation::work_index[mpi::rank] + index_source;