diff --git a/docs/source/io_formats/settings.rst b/docs/source/io_formats/settings.rst index a162e8de6..7174c5317 100644 --- a/docs/source/io_formats/settings.rst +++ b/docs/source/io_formats/settings.rst @@ -768,10 +768,10 @@ certain surfaces and write out the source bank in a separate file called *Default*: None :mcpl: - An optional boolean which indicates if the banked particles should - be written to a file in the MCPL-format (documented in mcpl_). - instead of the native hdf5-based format.If activated the output - output file name is altered to ``surface_source.mcpl`` + An optional boolean which indicates if the banked particles should be + written to a file in the MCPL-format (documented in mcpl_). instead of the + native HDF5-based format. If activated the output file name is changed to + ``surface_source.mcpl``. *Default*: false diff --git a/include/openmc/state_point.h b/include/openmc/state_point.h index 698ed2c93..730127554 100644 --- a/include/openmc/state_point.h +++ b/include/openmc/state_point.h @@ -26,7 +26,8 @@ void restart_set_keff(); void write_unstructured_mesh_results(); #ifdef OPENMC_MCPL -void write_mcpl_source_point(const char* filename, bool surf_source_bank = false); +void write_mcpl_source_point( + const char* filename, bool surf_source_bank = false); void write_mcpl_source_bank(mcpl_outfile_t file_id, bool surf_source_bank); #endif diff --git a/openmc/settings.py b/openmc/settings.py index b2c184f78..fd622870c 100644 --- a/openmc/settings.py +++ b/openmc/settings.py @@ -1349,7 +1349,7 @@ class Settings: elif key in ('max_particles'): value = int(value) elif key == 'mcpl': - value = True + value = value in ('true', '1') self.surf_source_write[key] = value def _confidence_intervals_from_xml_element(self, root): diff --git a/src/settings.cpp b/src/settings.cpp index b0829c1ba..de298c58d 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -432,12 +432,15 @@ void read_settings_xml() if (check_for_node(node, "file")) { auto path = get_node_value(node, "file", false, true); #ifdef OPENMC_MCPL - if ( (path.size() >= 5 && path.compare(path.size()-5,5,".mcpl")==0 ) || - (path.size() >= 8 && path.compare(path.size()-8,8,".mcpl.gz")==0 ) ) { - model::external_sources.push_back(make_unique(mcpl_open_file(path.c_str()))); - } else -#endif + if (ends_with(path, ".mcpl") || ends_with(path, ".mcpl.gz")) { + model::external_sources.push_back( + make_unique(mcpl_open_file(path.c_str()))); + } else { model::external_sources.push_back(make_unique(path)); + } +#else + model::external_sources.push_back(make_unique(path)); +#endif } else if (check_for_node(node, "library")) { // Get shared library path and parameters auto path = get_node_value(node, "library", false, true); @@ -689,8 +692,8 @@ void read_settings_xml() std::stoll(get_node_value(node_ssw, "max_particles")); } #ifdef OPENMC_MCPL - if(check_for_node(node_ssw, "mcpl")){ - surf_mcpl_write=true; + if (check_for_node(node_ssw, "mcpl")) { + surf_mcpl_write = true; } #endif } diff --git a/src/simulation.cpp b/src/simulation.cpp index d7cc2237d..2c1d1c988 100644 --- a/src/simulation.cpp +++ b/src/simulation.cpp @@ -390,7 +390,7 @@ void finalize_batch() if (settings::run_mode == RunMode::EIGENVALUE) { // Write out a separate source point if it's been specified for this batch #ifdef OPENMC_MCPL - if(! settings::source_mcpl_write) { + if (!settings::source_mcpl_write) { #endif if (contains(settings::sourcepoint_batch, simulation::current_batch) && settings::source_write && settings::source_separate) { @@ -405,8 +405,8 @@ void finalize_batch() #ifdef OPENMC_MCPL } else { if (contains(settings::sourcepoint_batch, simulation::current_batch) && - settings::source_mcpl_write && settings::source_separate) { - write_mcpl_source_point(nullptr); + settings::source_mcpl_write && settings::source_separate) { + write_mcpl_source_point(nullptr); } // Write a continously-overwritten source point if requested. @@ -425,12 +425,12 @@ void finalize_batch() write_source_point(filename.c_str(), true); } #ifdef OPENMC_MCPL - if(settings::surf_mcpl_write && simulation::current_batch == settings::n_batches){ + if (settings::surf_mcpl_write && + simulation::current_batch == settings::n_batches) { auto filename = settings::path_output + "surface_source.mcpl"; write_mcpl_source_point(filename.c_str(), true); } #endif - } void initialize_generation() diff --git a/src/state_point.cpp b/src/state_point.cpp index 3ee5f13b3..9dd0f1374 100644 --- a/src/state_point.cpp +++ b/src/state_point.cpp @@ -604,7 +604,7 @@ void write_source_point(const char* filename, bool surf_source_bank) } #ifdef OPENMC_MCPL -void write_mcpl_source_point(const char *filename, bool surf_source_bank) +void write_mcpl_source_point(const char* filename, bool surf_source_bank) { std::string filename_; if (filename) { @@ -622,21 +622,21 @@ void write_mcpl_source_point(const char *filename, bool surf_source_bank) std::string line; if (mpi::master) { file_id = mcpl_create_outfile(filename_.c_str()); - if (VERSION_DEV){ - line=fmt::format("OpenMC {0}.{1}.{2}-development",VERSION_MAJOR,VERSION_MINOR,VERSION_RELEASE); + if (VERSION_DEV) { + line = fmt::format("OpenMC {0}.{1}.{2}-development", VERSION_MAJOR, + VERSION_MINOR, VERSION_RELEASE); } else { - line=fmt::format("OpenMC {0}.{1}.{2}",VERSION_MAJOR,VERSION_MINOR,VERSION_RELEASE); + line = fmt::format( + "OpenMC {0}.{1}.{2}", VERSION_MAJOR, VERSION_MINOR, VERSION_RELEASE); } - mcpl_hdr_set_srcname(file_id,line.c_str()); + mcpl_hdr_set_srcname(file_id, line.c_str()); } write_mcpl_source_bank(file_id, surf_source_bank); if (mpi::master) { - //change this - this is h5 specific mcpl_close_outfile(file_id); } - } #endif @@ -768,7 +768,7 @@ void write_mcpl_source_bank(mcpl_outfile_t file_id, bool surf_source_bank) vector surf_source_index_vector; vector surf_source_bank_vector; - if(surf_source_bank) { + if (surf_source_bank) { surf_source_index_vector = calculate_surf_source_size(); dims_size = surf_source_index_vector[mpi::n_procs]; count_size = simulation::surf_source_bank.size(); @@ -790,55 +790,56 @@ void write_mcpl_source_bank(mcpl_outfile_t file_id, bool surf_source_bank) vector temp_source {source_bank->begin(), source_bank->end()}; #endif - //loop over the other nodes and receive data - then write those. + // loop over the other nodes and receive data - then write those. for (int i = 0; i < mpi::n_procs; ++i) { // number of particles for node node i size_t count[] { static_cast((*bank_index)[i + 1] - (*bank_index)[i])}; #ifdef OPENMC_MPI - if (i>0) + if (i > 0) MPI_Recv(source_bank->data(), count[0], mpi::source_site, i, i, mpi::intracomm, MPI_STATUS_IGNORE); #endif // now write the source_bank data again. - for (vector::iterator _site=source_bank->begin(); _site!=source_bank->end();_site++){ + for (vector::iterator _site = source_bank->begin(); + _site != source_bank->end(); _site++) { // particle is now at the iterator // write it to the mcpl-file mcpl_particle_t p; - p.position[0]=_site->r.x; - p.position[1]=_site->r.y; - p.position[2]=_site->r.z; + p.position[0] = _site->r.x; + p.position[1] = _site->r.y; + p.position[2] = _site->r.z; // mcpl requires that the direction vector is unit length // which is also the case in openmc - p.direction[0]=_site->u.x; - p.direction[1]=_site->u.y; - p.direction[2]=_site->u.z; + p.direction[0] = _site->u.x; + p.direction[1] = _site->u.y; + p.direction[2] = _site->u.z; // mcpl stores kinetic energy in MeV - p.ekin=_site->E*1e-6; + p.ekin = _site->E * 1e-6; - p.time=_site->time*1e3; + p.time = _site->time * 1e3; - p.weight=_site->wgt; + p.weight = _site->wgt; - switch(_site->particle){ - case ParticleType::neutron: - p.pdgcode=2112; - break; - case ParticleType::photon: - p.pdgcode=22; - break; - case ParticleType::electron: - p.pdgcode=11; - break; - case ParticleType::positron: - p.pdgcode=-11; - break; + switch (_site->particle) { + case ParticleType::neutron: + p.pdgcode = 2112; + break; + case ParticleType::photon: + p.pdgcode = 22; + break; + case ParticleType::electron: + p.pdgcode = 11; + break; + case ParticleType::positron: + p.pdgcode = -11; + break; } - mcpl_add_particle(file_id,&p); + mcpl_add_particle(file_id, &p); } } #ifdef OPENMC_MPI @@ -851,7 +852,6 @@ void write_mcpl_source_bank(mcpl_outfile_t file_id, bool surf_source_bank) mpi::intracomm); #endif } - } #endif