diff --git a/include/openmc/settings.h b/include/openmc/settings.h index 49e0ab69e1..be56e0b60e 100644 --- a/include/openmc/settings.h +++ b/include/openmc/settings.h @@ -15,21 +15,23 @@ namespace openmc { // Global variable declarations //============================================================================== +namespace settings { + // Defined on Fortran side -extern "C" bool openmc_check_overlaps; -extern "C" bool openmc_particle_restart_run; -extern "C" bool openmc_photon_transport; -extern "C" bool openmc_restart_run; -extern "C" bool openmc_run_CE; -extern "C" bool openmc_write_all_tracks; -extern "C" bool openmc_write_initial_source; +extern "C" bool check_overlaps; +extern "C" bool particle_restart_run; +extern "C" bool photon_transport; +extern "C" bool restart_run; +extern "C" bool run_CE; +extern "C" bool write_all_tracks; +extern "C" bool write_initial_source; // Defined in .cpp // TODO: Make strings instead of char* once Fortran is gone -extern "C" char* openmc_path_input; -extern "C" char* openmc_path_statepoint; -extern "C" char* openmc_path_sourcepoint; -extern "C" char* openmc_path_particle_restart; +extern "C" char* path_input; +extern "C" char* path_statepoint; +extern "C" char* path_sourcepoint; +extern "C" char* path_particle_restart; extern std::string path_cross_sections; extern std::string path_multipole; extern std::string path_output; @@ -41,6 +43,8 @@ extern double temperature_tolerance; extern double temperature_default; extern std::array temperature_range; +} // namespace settings + //============================================================================== //! Read settings from XML file //! \param[in] root XML node for diff --git a/src/initialize.cpp b/src/initialize.cpp index 21ab93b726..dfbf418343 100644 --- a/src/initialize.cpp +++ b/src/initialize.cpp @@ -109,7 +109,7 @@ parse_command_line(int argc, char* argv[]) if (arg[0] == '-') { if (arg == "-p" || arg == "--plot") { openmc_run_mode = RUN_MODE_PLOTTING; - openmc_check_overlaps = true; + settings::check_overlaps = true; } else if (arg == "-n" || arg == "--particles") { i += 1; @@ -127,11 +127,11 @@ parse_command_line(int argc, char* argv[]) // Set path and flag for type of run if (filetype == "statepoint") { - openmc_path_statepoint = argv[i]; - openmc_restart_run = true; + settings::path_statepoint = argv[i]; + settings::restart_run = true; } else if (filetype == "particle restart") { - openmc_path_particle_restart = argv[i]; - openmc_particle_restart_run = true; + settings::path_particle_restart = argv[i]; + settings::particle_restart_run = true; } else { std::stringstream msg; msg << "Unrecognized file after restart flag: " << filetype << "."; @@ -140,7 +140,7 @@ parse_command_line(int argc, char* argv[]) } // If its a restart run check for additional source file - if (openmc_restart_run && i + 1 < argc) { + if (settings::restart_run && i + 1 < argc) { // Check if it has extension we can read if (ends_with(argv[i+1], ".h5")) { @@ -156,21 +156,21 @@ parse_command_line(int argc, char* argv[]) } // It is a source file - openmc_path_sourcepoint = argv[i+1]; + settings::path_sourcepoint = argv[i+1]; i += 1; } else { // Source is in statepoint file - openmc_path_sourcepoint = openmc_path_statepoint; + settings::path_sourcepoint = settings::path_statepoint; } } else { // Source is assumed to be in statepoint file - openmc_path_sourcepoint = openmc_path_statepoint; + settings::path_sourcepoint = settings::path_statepoint; } } else if (arg == "-g" || arg == "--geometry-debug") { - openmc_check_overlaps = true; + settings::check_overlaps = true; } else if (arg == "-c" || arg == "--volume") { openmc_run_mode = RUN_MODE_VOLUME; } else if (arg == "-s" || arg == "--threads") { @@ -200,7 +200,7 @@ parse_command_line(int argc, char* argv[]) return OPENMC_E_UNASSIGNED; } else if (arg == "-t" || arg == "--track") { - openmc_write_all_tracks = true; + settings::write_all_tracks = true; } else { std::cerr << "Unknown option: " << argv[i] << '\n'; @@ -213,7 +213,7 @@ parse_command_line(int argc, char* argv[]) } // Determine directory where XML input files are - if (argc > 1 && last_flag < argc) openmc_path_input = argv[last_flag + 1]; + if (argc > 1 && last_flag < argc) settings::path_input = argv[last_flag + 1]; return 0; } diff --git a/src/particle.cpp b/src/particle.cpp index 51331cea03..3dda0e7c92 100644 --- a/src/particle.cpp +++ b/src/particle.cpp @@ -148,7 +148,8 @@ Particle::write_restart() // Set up file name std::stringstream filename; - filename << path_output << "particle_" << openmc_current_batch << '_' << id << ".h5"; + filename << settings::path_output << "particle_" << openmc_current_batch + << '_' << id << ".h5"; #pragma omp critical (WriteParticleRestart) { diff --git a/src/settings.F90 b/src/settings.F90 index 710a87e1e2..da514757d2 100644 --- a/src/settings.F90 +++ b/src/settings.F90 @@ -9,7 +9,7 @@ module settings ! ============================================================================ ! ENERGY TREATMENT RELATED VARIABLES - logical(C_BOOL), bind(C, name='openmc_run_CE') :: run_CE = .true. ! Run in CE mode? + logical(C_BOOL), bind(C, name='run_CE') :: run_CE = .true. ! Run in CE mode? ! ============================================================================ ! CONTINUOUS-ENERGY CROSS SECTION RELATED VARIABLES @@ -26,7 +26,7 @@ module settings integer :: n_log_bins ! number of bins for logarithmic grid - logical(C_BOOL), bind(C, name='openmc_photon_transport') :: photon_transport = .false. + logical(C_BOOL), bind(C) :: photon_transport = .false. integer :: electron_treatment = ELECTRON_TTB ! ============================================================================ @@ -81,13 +81,13 @@ module settings integer(C_INT), bind(C, name='openmc_run_mode') :: run_mode = NONE ! Restart run - logical(C_BOOL), bind(C, name='openmc_restart_run') :: restart_run = .false. + logical(C_BOOL), bind(C) :: restart_run = .false. ! The verbosity controls how much information will be printed to the screen ! and in logs integer(C_INT), bind(C, name='openmc_verbosity') :: verbosity = 7 - logical(C_BOOL), bind(C, name='openmc_check_overlaps') :: check_overlaps = .false. + logical(C_BOOL), bind(C) :: check_overlaps = .false. ! Trace for single particle integer :: trace_batch @@ -95,17 +95,14 @@ module settings integer(8) :: trace_particle ! Particle tracks - logical(C_BOOL), bind(C, name='openmc_write_all_tracks') :: & - write_all_tracks = .false. + logical(C_BOOL), bind(C) :: write_all_tracks = .false. integer, allocatable :: track_identifiers(:,:) ! Particle restart run - logical(C_BOOL), bind(C, name='openmc_particle_restart_run') :: & - particle_restart_run = .false. + logical(C_BOOL), bind(C) :: particle_restart_run = .false. ! Write out initial source - logical(C_BOOL), bind(C, name='openmc_write_initial_source') :: & - write_initial_source = .false. + logical(C_BOOL), bind(C) :: write_initial_source = .false. ! Whether create fission neutrons or not. Only applied for MODE_FIXEDSOURCE logical :: create_fission_neutrons = .true. diff --git a/src/settings.cpp b/src/settings.cpp index aafa0fb237..d3896f0634 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -16,10 +16,12 @@ namespace openmc { // Global variables //============================================================================== -char* openmc_path_input; -char* openmc_path_statepoint; -char* openmc_path_sourcepoint; -char* openmc_path_particle_restart; +namespace settings { + +char* path_input; +char* path_statepoint; +char* path_sourcepoint; +char* path_particle_restart; std::string path_cross_sections; std::string path_multipole; std::string path_output; @@ -31,12 +33,16 @@ double temperature_tolerance {10.0}; double temperature_default {293.6}; std::array temperature_range {0.0, 0.0}; +} // namespace settings + //============================================================================== // Functions //============================================================================== void read_settings(pugi::xml_node* root) { + using namespace settings; + // Look for deprecated cross_sections.xml file in settings.xml if (check_for_node(*root, "cross_sections")) { warning("Setting cross_sections in settings.xml has been deprecated." diff --git a/src/source.cpp b/src/source.cpp index 70240b10d1..8f28fcf73e 100644 --- a/src/source.cpp +++ b/src/source.cpp @@ -45,7 +45,7 @@ SourceDistribution::SourceDistribution(pugi::xml_node node) particle_ = ParticleType::neutron; } else if (temp_str == "photon") { particle_ = ParticleType::photon; - openmc_photon_transport = true; + settings::photon_transport = true; } else { fatal_error(std::string("Unknown source particle type: ") + temp_str); } @@ -59,12 +59,12 @@ SourceDistribution::SourceDistribution(pugi::xml_node node) // Check for external source file if (check_for_node(node, "file")) { // Copy path of source file - path_source = get_node_value(node, "file", false, true); + settings::path_source = get_node_value(node, "file", false, true); // Check if source file exists - if (!file_exists(path_source)) { + if (!file_exists(settings::path_source)) { std::stringstream msg; - msg << "Source file '" << path_source << "' does not exist."; + msg << "Source file '" << settings::path_source << "' does not exist."; fatal_error(msg); } @@ -243,16 +243,16 @@ void initialize_source() int64_t n; openmc_source_bank(&source_bank, &n); - if (path_source != "") { + if (settings::path_source != "") { // Read the source from a binary file instead of sampling from some // assumed source distribution std::stringstream msg; - msg << "Reading source file from " << path_source << "..."; + msg << "Reading source file from " << settings::path_source << "..."; write_message(msg, 6); // Open the binary file - hid_t file_id = file_open(path_source, 'r', true); + hid_t file_id = file_open(settings::path_source, 'r', true); // Read the file type std::string filetype; @@ -282,9 +282,9 @@ void initialize_source() } // Write out initial source - if (openmc_write_initial_source) { + if (settings::write_initial_source) { write_message("Writing out initial source...", 5); - std::string filename = path_output + "initial_source.h5"; + std::string filename = settings::path_output + "initial_source.h5"; hid_t file_id = file_open(filename, 'w', true); write_source_bank(file_id, work_index.data(), source_bank); file_close(file_id); @@ -318,7 +318,7 @@ Bank sample_external_source() Bank site {external_sources[i].sample()}; // If running in MG, convert site % E to group - if (!openmc_run_CE) { + if (!settings::run_CE) { // Get pointer to rev_energy_bins array on Fortran side double* rev_energy_bins = rev_energy_bins_ptr(); @@ -357,7 +357,7 @@ extern "C" int overall_generation(); //! Fill source bank at end of generation for fixed source simulations extern "C" void fill_source_bank_fixedsource() { - if (path_source.empty()) { + if (settings::path_source.empty()) { // Get pointer to source bank Bank* source_bank; int64_t n; diff --git a/src/thermal.cpp b/src/thermal.cpp index b63d2e6d16..229aa35bc7 100644 --- a/src/thermal.cpp +++ b/src/thermal.cpp @@ -153,10 +153,10 @@ ThermalScattering::calculate_xs(double E, double sqrtkT, int* i_temp, // Determine temperature for S(a,b) table double kT = sqrtkT*sqrtkT; int i; - if (temperature_method == TEMPERATURE_NEAREST) { + if (settings::temperature_method == TEMPERATURE_NEAREST) { // If using nearest temperature, do linear search on temperature for (i = 0; i < kTs_.size(); ++i) { - if (abs(kTs_[i] - kT) < K_BOLTZMANN*temperature_tolerance) { + if (abs(kTs_[i] - kT) < K_BOLTZMANN*settings::temperature_tolerance) { break; } }