diff --git a/include/openmc/capi.h b/include/openmc/capi.h index 500f38da5..7fd79fccf 100644 --- a/include/openmc/capi.h +++ b/include/openmc/capi.h @@ -135,16 +135,12 @@ extern "C" { extern char openmc_err_msg[256]; extern double openmc_keff; extern double openmc_keff_std; - extern int32_t gen_per_batch; - extern int32_t n_batches; extern int32_t n_cells; extern int32_t n_filters; - extern int32_t n_inactive; extern int32_t n_lattices; extern int32_t n_materials; extern int32_t n_meshes; extern int n_nuclides; - extern int64_t n_particles; extern int32_t n_plots; extern int32_t n_realizations; extern int32_t n_sab_tables; @@ -162,13 +158,6 @@ extern "C" { extern int openmc_rank; extern int64_t openmc_work; - // Run modes - const int RUN_MODE_FIXEDSOURCE = 1; - const int RUN_MODE_EIGENVALUE = 2; - const int RUN_MODE_PLOTTING = 3; - const int RUN_MODE_PARTICLE = 4; - const int RUN_MODE_VOLUME = 5; - #ifdef __cplusplus } #endif diff --git a/include/openmc/constants.h b/include/openmc/constants.h index 12dc21b71..ab31781e2 100644 --- a/include/openmc/constants.h +++ b/include/openmc/constants.h @@ -431,6 +431,13 @@ enum class Interpolation { histogram, lin_lin, lin_log, log_lin, log_log }; +// Run modes +constexpr int RUN_MODE_FIXEDSOURCE {1}; +constexpr int RUN_MODE_EIGENVALUE {2}; +constexpr int RUN_MODE_PLOTTING {3}; +constexpr int RUN_MODE_PARTICLE {4}; +constexpr int RUN_MODE_VOLUME {5}; + } // namespace openmc #endif // OPENMC_CONSTANTS_H diff --git a/include/openmc/settings.h b/include/openmc/settings.h index d7220a042..f800e39f1 100644 --- a/include/openmc/settings.h +++ b/include/openmc/settings.h @@ -60,12 +60,18 @@ extern std::string path_source; extern "C" int32_t index_entropy_mesh; //!< Index of entropy mesh in global mesh array extern "C" int32_t index_ufs_mesh; //!< Index of UFS mesh in global mesh array +extern "C" int32_t n_batches; //!< number of (inactive+active) batches +extern "C" int32_t n_inactive; //!< number of inactive batches +extern "C" int32_t gen_per_batch; //!< number of generations per batch +extern "C" int64_t n_particles; //!< number of particles per generation + extern "C" int electron_treatment; //!< how to treat secondary electrons extern "C" double energy_cutoff[4]; //!< Energy cutoff in [eV] for each particle type extern "C" int legendre_to_tabular_points; //!< number of points to convert Legendres extern "C" int max_order; //!< Maximum Legendre order for multigroup data extern "C" int n_log_bins; //!< number of bins for logarithmic energy grid extern "C" int n_max_batches; //!< Maximum number of batches + extern "C" int res_scat_method; //!< resonance upscattering method extern "C" double res_scat_energy_min; //!< Min energy in [eV] for res. upscattering extern "C" double res_scat_energy_max; //!< Max energy in [eV] for res. upscattering diff --git a/src/initialize.cpp b/src/initialize.cpp index 35f872816..d2cdc6c5a 100644 --- a/src/initialize.cpp +++ b/src/initialize.cpp @@ -10,6 +10,7 @@ #endif #include "openmc/capi.h" +#include "openmc/constants.h" #include "openmc/error.h" #include "openmc/hdf5_interface.h" #include "openmc/message_passing.h" @@ -113,7 +114,7 @@ parse_command_line(int argc, char* argv[]) } else if (arg == "-n" || arg == "--particles") { i += 1; - n_particles = std::stoll(argv[i]); + settings::n_particles = std::stoll(argv[i]); } else if (arg == "-r" || arg == "--restart") { i += 1; diff --git a/src/main.cpp b/src/main.cpp index a6b12123e..f4e2d3f8e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,6 +2,7 @@ #include "mpi.h" #endif #include "openmc/capi.h" +#include "openmc/constants.h" #include "openmc/error.h" #include "openmc/settings.h" @@ -25,17 +26,17 @@ int main(int argc, char* argv[]) { // start problem based on mode switch (openmc::settings::run_mode) { - case RUN_MODE_FIXEDSOURCE: - case RUN_MODE_EIGENVALUE: + case openmc::RUN_MODE_FIXEDSOURCE: + case openmc::RUN_MODE_EIGENVALUE: err = openmc_run(); break; - case RUN_MODE_PLOTTING: + case openmc::RUN_MODE_PLOTTING: err = openmc_plot_geometry(); break; - case RUN_MODE_PARTICLE: + case openmc::RUN_MODE_PARTICLE: if (openmc_master) err = openmc_particle_restart(); break; - case RUN_MODE_VOLUME: + case openmc::RUN_MODE_VOLUME: err = openmc_calculate_volumes(); break; } diff --git a/src/particle.cpp b/src/particle.cpp index 6c5d24113..01fea65ff 100644 --- a/src/particle.cpp +++ b/src/particle.cpp @@ -130,7 +130,7 @@ Particle::mark_as_lost(const char* message) openmc_n_lost_particles += 1; // Count the total number of simulated particles (on this processor) - auto n = openmc_current_batch * gen_per_batch * openmc_work; + auto n = openmc_current_batch * settings::gen_per_batch * openmc_work; // Abort the simulation if the maximum number of lost particles has been // reached @@ -166,9 +166,9 @@ Particle::write_restart() // Write data to file write_dataset(file_id, "current_batch", openmc_current_batch); - write_dataset(file_id, "generations_per_batch", gen_per_batch); + write_dataset(file_id, "generations_per_batch", settings::gen_per_batch); write_dataset(file_id, "current_generation", openmc_current_gen); - write_dataset(file_id, "n_particles", n_particles); + write_dataset(file_id, "n_particles", settings::n_particles); switch (settings::run_mode) { case RUN_MODE_FIXEDSOURCE: write_dataset(file_id, "run_mode", "fixed source"); diff --git a/src/settings.F90 b/src/settings.F90 index e6c50e8d7..ec7bbf2c8 100644 --- a/src/settings.F90 +++ b/src/settings.F90 @@ -50,10 +50,10 @@ module settings ! Use confidence intervals for results instead of standard deviations logical(C_BOOL), bind(C) :: confidence_intervals - integer(C_INT64_T), bind(C) :: n_particles = 0 ! # of particles per generation - integer(C_INT32_T), bind(C) :: n_batches ! # of batches - integer(C_INT32_T), bind(C) :: n_inactive ! # of inactive batches - integer(C_INT32_T), bind(C) :: gen_per_batch = 1 ! # of generations per batch + integer(C_INT64_T), bind(C) :: n_particles ! # of particles per generation + integer(C_INT32_T), bind(C) :: n_batches ! # of batches + integer(C_INT32_T), bind(C) :: n_inactive ! # of inactive batches + integer(C_INT32_T), bind(C) :: gen_per_batch ! # of generations per batch integer(C_INT), bind(C) :: n_max_batches ! max # of batches integer(C_INT), bind(C, name='trigger_batch_interval') :: n_batch_interval ! batch interval for triggers diff --git a/src/settings.cpp b/src/settings.cpp index 3beceabbb..2805a2098 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -58,6 +58,11 @@ std::string path_source; int32_t index_entropy_mesh {-1}; int32_t index_ufs_mesh {-1}; +int32_t n_batches; +int32_t n_inactive; +int32_t gen_per_batch {1}; +int64_t n_particles {0}; + int electron_treatment {ELECTRON_TTB}; double energy_cutoff[4] {0.0, 1000.0, 0.0, 0.0}; int legendre_to_tabular_points {C_NONE}; diff --git a/src/simulation.cpp b/src/simulation.cpp index 3514f4a47..74a3c14fc 100644 --- a/src/simulation.cpp +++ b/src/simulation.cpp @@ -2,6 +2,7 @@ #include "openmc/capi.h" #include "openmc/message_passing.h" +#include "openmc/settings.h" // OPENMC_RUN encompasses all the main logic where iterations are performed // over the batches, generations, and histories in a fixed source or k-eigenvalue @@ -41,10 +42,10 @@ void openmc_simulation_init_c() void calculate_work() { // Determine minimum amount of particles to simulate on each processor - int64_t min_work = n_particles/mpi::n_procs; + int64_t min_work = settings::n_particles / mpi::n_procs; // Determine number of processors that have one extra particle - int64_t remainder = n_particles % mpi::n_procs; + int64_t remainder = settings::n_particles % mpi::n_procs; int64_t i_bank = 0; work_index.reserve(mpi::n_procs); diff --git a/src/source.cpp b/src/source.cpp index 8f28fcf73..23939d796 100644 --- a/src/source.cpp +++ b/src/source.cpp @@ -273,7 +273,8 @@ void initialize_source() // Generation source sites from specified distribution in user input for (int64_t i = 0; i < openmc_work; ++i) { // initialize random number seed - int64_t id = openmc_total_gen*n_particles + work_index[openmc::mpi::rank] + i + 1; + int64_t id = openmc_total_gen*settings::n_particles + + work_index[openmc::mpi::rank] + i + 1; set_particle_seed(id); // sample external source distribution @@ -365,8 +366,8 @@ extern "C" void fill_source_bank_fixedsource() for (int64_t i = 0; i < openmc_work; ++i) { // initialize random number seed - int64_t id = (openmc_total_gen + overall_generation())*n_particles + - work_index[openmc::mpi::rank] + i + 1; + int64_t id = (openmc_total_gen + overall_generation()) * + settings::n_particles + work_index[openmc::mpi::rank] + i + 1; set_particle_seed(id); // sample external source distribution diff --git a/src/state_point.cpp b/src/state_point.cpp index 1e4c8bdfd..dba0fe1b8 100644 --- a/src/state_point.cpp +++ b/src/state_point.cpp @@ -10,6 +10,7 @@ #include "openmc/capi.h" #include "openmc/error.h" #include "openmc/message_passing.h" +#include "openmc/settings.h" namespace openmc { @@ -39,7 +40,7 @@ write_source_bank(hid_t group_id, int64_t* work_index, Bank* source_bank) #ifdef PHDF5 // Set size of total dataspace for all procs and rank - hsize_t dims[] {static_cast(n_particles)}; + hsize_t dims[] {static_cast(settings::n_particles)}; hid_t dspace = H5Screate_simple(1, dims, nullptr); hid_t dset = H5Dcreate(group_id, "source_bank", banktype, dspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); @@ -69,7 +70,7 @@ write_source_bank(hid_t group_id, int64_t* work_index, Bank* source_bank) if (openmc_master) { // Create dataset big enough to hold all source sites - hsize_t dims[] {static_cast(n_particles)}; + hsize_t dims[] {static_cast(settings::n_particles)}; hid_t dspace = H5Screate_simple(1, dims, nullptr); hid_t dset = H5Dcreate(group_id, "source_bank", banktype, dspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);