From be61af3c0456826f44b109d45e49846764bff48e Mon Sep 17 00:00:00 2001 From: helen-brooks Date: Thu, 7 Apr 2022 15:34:10 +0100 Subject: [PATCH 01/17] Refactor dagmc initialisation into a function --- include/openmc/dagmc.h | 4 ++ src/dagmc.cpp | 92 ++++++++++++++++++++++-------------------- 2 files changed, 53 insertions(+), 43 deletions(-) diff --git a/include/openmc/dagmc.h b/include/openmc/dagmc.h index 64bf4d2091..887810fd35 100644 --- a/include/openmc/dagmc.h +++ b/include/openmc/dagmc.h @@ -22,6 +22,7 @@ void check_dagmc_root_univ(); #ifdef DAGMC #include "DagMC.hpp" +#include "dagmcmetadata.hpp" #include "openmc/cell.h" #include "openmc/particle.h" @@ -139,10 +140,13 @@ public: bool has_graveyard() const { return has_graveyard_; } private: + void init_dagmc(); + std::string filename_; //!< Name of the DAGMC file used to create this universe std::shared_ptr uwuw_; //!< Pointer to the UWUW instance for this universe + std::unique_ptr dmd_ptr; //! Pointer to DAGMC metadata object bool adjust_geometry_ids_; //!< Indicates whether or not to automatically //!< generate new cell and surface IDs for the //!< universe diff --git a/src/dagmc.cpp b/src/dagmc.cpp index 9b894d3bb9..5b6d17e373 100644 --- a/src/dagmc.cpp +++ b/src/dagmc.cpp @@ -12,7 +12,6 @@ #include "openmc/string_utils.h" #ifdef DAGMC -#include "dagmcmetadata.hpp" #include "uwuw.hpp" #endif #include @@ -89,7 +88,7 @@ DAGUniverse::DAGUniverse( void DAGUniverse::initialize() { geom_type() = GeometryType::DAG; - + // determine the next cell id int32_t next_cell_id = 0; for (const auto& c : model::cells) { @@ -108,45 +107,10 @@ void DAGUniverse::initialize() surf_idx_offset_ = model::surfaces.size(); next_surf_id++; - // create a new DAGMC instance - dagmc_instance_ = std::make_shared(); - - // --- Materials --- - - // read any UWUW materials from the file - read_uwuw_materials(); - - // check for uwuw material definitions - bool using_uwuw = uses_uwuw(); - - // notify user if UWUW materials are going to be used - if (using_uwuw) { - write_message("Found UWUW Materials in the DAGMC geometry file.", 6); - } - - // load the DAGMC geometry - filename_ = settings::path_input + filename_; - if (!file_exists(filename_)) { - fatal_error("Geometry DAGMC file '" + filename_ + "' does not exist!"); - } - moab::ErrorCode rval = dagmc_instance_->load_file(filename_.c_str()); - MB_CHK_ERR_CONT(rval); - - // initialize acceleration data structures - rval = dagmc_instance_->init_OBBTree(); - MB_CHK_ERR_CONT(rval); - - // parse model metadata - dagmcMetaData DMD(dagmc_instance_.get(), false, false); - DMD.load_property_data(); - - std::vector keywords {"temp"}; - std::map dum; - std::string delimiters = ":/"; - rval = dagmc_instance_->parse_properties(keywords, dum, delimiters.c_str()); - MB_CHK_ERR_CONT(rval); + init_dagmc(); // --- Cells (Volumes) --- + moab::ErrorCode rval; // initialize cell objects int n_cells = dagmc_instance_->num_entities(3); @@ -175,7 +139,7 @@ void DAGUniverse::initialize() // --- Materials --- // determine volume material assignment - std::string mat_str = DMD.get_volume_property("material", vol_handle); + std::string mat_str = dmd_ptr->get_volume_property("material", vol_handle); if (mat_str.empty()) { fatal_error(fmt::format("Volume {} has no material assignment.", c->id_)); @@ -191,9 +155,9 @@ void DAGUniverse::initialize() if (mat_str == "void" || mat_str == "vacuum" || mat_str == "graveyard") { c->material_.push_back(MATERIAL_VOID); } else { - if (using_uwuw) { + if (uses_uwuw()) { // lookup material in uwuw if present - std::string uwuw_mat = DMD.volume_material_property_data_eh[vol_handle]; + std::string uwuw_mat = dmd_ptr->volume_material_property_data_eh[vol_handle]; if (uwuw_->material_library.count(uwuw_mat) != 0) { // Note: material numbers are set by UWUW int mat_number = uwuw_->material_library.get_material(uwuw_mat) @@ -256,7 +220,7 @@ void DAGUniverse::initialize() : dagmc_instance_->id_by_index(2, i + 1); // set BCs - std::string bc_value = DMD.get_surface_property("boundary", surf_handle); + std::string bc_value = dmd_ptr->get_surface_property("boundary", surf_handle); to_lower(bc_value); if (bc_value.empty() || bc_value == "transmit" || bc_value == "transmission") { @@ -302,6 +266,48 @@ void DAGUniverse::initialize() } // end surface loop } +void DAGUniverse::init_dagmc() +{ + + // create a new DAGMC instance + dagmc_instance_ = std::make_shared(); + + // --- Materials --- + + // read any UWUW materials from the file + read_uwuw_materials(); + + // check for uwuw material definitions + bool using_uwuw = uses_uwuw(); + + // notify user if UWUW materials are going to be used + if (using_uwuw) { + write_message("Found UWUW Materials in the DAGMC geometry file.", 6); + } + + // load the DAGMC geometry + filename_ = settings::path_input + filename_; + if (!file_exists(filename_)) { + fatal_error("Geometry DAGMC file '" + filename_ + "' does not exist!"); + } + moab::ErrorCode rval = dagmc_instance_->load_file(filename_.c_str()); + MB_CHK_ERR_CONT(rval); + + // initialize acceleration data structures + rval = dagmc_instance_->init_OBBTree(); + MB_CHK_ERR_CONT(rval); + + // parse model metadata + dmd_ptr = std::make_unique(dagmc_instance_.get(), false, false); + dmd_ptr->load_property_data(); + + std::vector keywords {"temp"}; + std::map dum; + std::string delimiters = ":/"; + rval = dagmc_instance_->parse_properties(keywords, dum, delimiters.c_str()); + MB_CHK_ERR_CONT(rval); +} + std::string DAGUniverse::dagmc_ids_for_dim(int dim) const { // generate a vector of ids From 290e2fba075eac057a0a1c07b00622e3c2e0ef12 Mon Sep 17 00:00:00 2001 From: helen-brooks Date: Thu, 7 Apr 2022 16:04:00 +0100 Subject: [PATCH 02/17] Refactor initialize of dagmc universe --- include/openmc/dagmc.h | 3 + src/dagmc.cpp | 128 ++++++++++++++++++++++------------------- 2 files changed, 73 insertions(+), 58 deletions(-) diff --git a/include/openmc/dagmc.h b/include/openmc/dagmc.h index 887810fd35..8b26b62247 100644 --- a/include/openmc/dagmc.h +++ b/include/openmc/dagmc.h @@ -141,6 +141,8 @@ public: private: void init_dagmc(); + void init_cells(); + void init_surfaces(); std::string filename_; //!< Name of the DAGMC file used to create this universe @@ -154,6 +156,7 @@ private: //!< generate new material IDs for the universe bool has_graveyard_; //!< Indicates if the DAGMC geometry has a "graveyard" //!< volume + moab::EntityHandle graveyard; //! MOAB index for graveyard }; //============================================================================== diff --git a/src/dagmc.cpp b/src/dagmc.cpp index 5b6d17e373..c28b0ec9a1 100644 --- a/src/dagmc.cpp +++ b/src/dagmc.cpp @@ -88,7 +88,60 @@ DAGUniverse::DAGUniverse( void DAGUniverse::initialize() { geom_type() = GeometryType::DAG; - + + init_dagmc(); + + init_cells(); + + init_surfaces(); +} + +void DAGUniverse::init_dagmc() +{ + + // create a new DAGMC instance + dagmc_instance_ = std::make_shared(); + + // --- Materials --- + + // read any UWUW materials from the file + read_uwuw_materials(); + + // check for uwuw material definitions + bool using_uwuw = uses_uwuw(); + + // notify user if UWUW materials are going to be used + if (using_uwuw) { + write_message("Found UWUW Materials in the DAGMC geometry file.", 6); + } + + // load the DAGMC geometry + filename_ = settings::path_input + filename_; + if (!file_exists(filename_)) { + fatal_error("Geometry DAGMC file '" + filename_ + "' does not exist!"); + } + moab::ErrorCode rval = dagmc_instance_->load_file(filename_.c_str()); + MB_CHK_ERR_CONT(rval); + + // initialize acceleration data structures + rval = dagmc_instance_->init_OBBTree(); + MB_CHK_ERR_CONT(rval); + + // parse model metadata + dmd_ptr = std::make_unique(dagmc_instance_.get(), false, false); + dmd_ptr->load_property_data(); + + std::vector keywords {"temp"}; + std::map dum; + std::string delimiters = ":/"; + rval = dagmc_instance_->parse_properties(keywords, dum, delimiters.c_str()); + MB_CHK_ERR_CONT(rval); +} + +void DAGUniverse::init_cells() +{ + moab::ErrorCode rval; + // determine the next cell id int32_t next_cell_id = 0; for (const auto& c : model::cells) { @@ -98,23 +151,9 @@ void DAGUniverse::initialize() cell_idx_offset_ = model::cells.size(); next_cell_id++; - // determine the next surface id - int32_t next_surf_id = 0; - for (const auto& s : model::surfaces) { - if (s->id_ > next_surf_id) - next_surf_id = s->id_; - } - surf_idx_offset_ = model::surfaces.size(); - next_surf_id++; - - init_dagmc(); - - // --- Cells (Volumes) --- - moab::ErrorCode rval; - // initialize cell objects int n_cells = dagmc_instance_->num_entities(3); - moab::EntityHandle graveyard = 0; + graveyard = 0; for (int i = 0; i < n_cells; i++) { moab::EntityHandle vol_handle = dagmc_instance_->entity_by_index(3, i + 1); @@ -207,7 +246,20 @@ void DAGUniverse::initialize() has_graveyard_ = graveyard; - // --- Surfaces --- +} + +void DAGUniverse::init_surfaces() +{ + moab::ErrorCode rval; + + // determine the next surface id + int32_t next_surf_id = 0; + for (const auto& s : model::surfaces) { + if (s->id_ > next_surf_id) + next_surf_id = s->id_; + } + surf_idx_offset_ = model::surfaces.size(); + next_surf_id++; // initialize surface objects int n_surfaces = dagmc_instance_->num_entities(2); @@ -264,49 +316,9 @@ void DAGUniverse::initialize() model::surfaces.emplace_back(std::move(s)); } // end surface loop + } -void DAGUniverse::init_dagmc() -{ - - // create a new DAGMC instance - dagmc_instance_ = std::make_shared(); - - // --- Materials --- - - // read any UWUW materials from the file - read_uwuw_materials(); - - // check for uwuw material definitions - bool using_uwuw = uses_uwuw(); - - // notify user if UWUW materials are going to be used - if (using_uwuw) { - write_message("Found UWUW Materials in the DAGMC geometry file.", 6); - } - - // load the DAGMC geometry - filename_ = settings::path_input + filename_; - if (!file_exists(filename_)) { - fatal_error("Geometry DAGMC file '" + filename_ + "' does not exist!"); - } - moab::ErrorCode rval = dagmc_instance_->load_file(filename_.c_str()); - MB_CHK_ERR_CONT(rval); - - // initialize acceleration data structures - rval = dagmc_instance_->init_OBBTree(); - MB_CHK_ERR_CONT(rval); - - // parse model metadata - dmd_ptr = std::make_unique(dagmc_instance_.get(), false, false); - dmd_ptr->load_property_data(); - - std::vector keywords {"temp"}; - std::map dum; - std::string delimiters = ":/"; - rval = dagmc_instance_->parse_properties(keywords, dum, delimiters.c_str()); - MB_CHK_ERR_CONT(rval); -} std::string DAGUniverse::dagmc_ids_for_dim(int dim) const { From d3b4cb7fd3d40160b0ce6071e9c9bef380552fbc Mon Sep 17 00:00:00 2001 From: helen-brooks Date: Fri, 8 Apr 2022 12:13:58 +0100 Subject: [PATCH 03/17] More refactoring in DAGUniverse --- include/openmc/dagmc.h | 9 +++++---- src/dagmc.cpp | 27 ++++++++++++--------------- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/include/openmc/dagmc.h b/include/openmc/dagmc.h index 8b26b62247..1fcbb04a0c 100644 --- a/include/openmc/dagmc.h +++ b/include/openmc/dagmc.h @@ -140,9 +140,10 @@ public: bool has_graveyard() const { return has_graveyard_; } private: - void init_dagmc(); - void init_cells(); - void init_surfaces(); + void set_id(); //!< Deduce the universe id from model::universes + void init_dagmc(); //!< Create and initialise DAGMC pointer + void init_cells(); //!< Create cells from DAGMC volumes + void init_surfaces(); //!< Create surfaces from DAGMC surfaces std::string filename_; //!< Name of the DAGMC file used to create this universe @@ -156,7 +157,7 @@ private: //!< generate new material IDs for the universe bool has_graveyard_; //!< Indicates if the DAGMC geometry has a "graveyard" //!< volume - moab::EntityHandle graveyard; //! MOAB index for graveyard + moab::EntityHandle graveyard; //!< MOAB index for graveyard }; //============================================================================== diff --git a/src/dagmc.cpp b/src/dagmc.cpp index c28b0ec9a1..260f58ebbc 100644 --- a/src/dagmc.cpp +++ b/src/dagmc.cpp @@ -70,6 +70,13 @@ DAGUniverse::DAGUniverse( const std::string& filename, bool auto_geom_ids, bool auto_mat_ids) : filename_(filename), adjust_geometry_ids_(auto_geom_ids), adjust_material_ids_(auto_mat_ids) +{ + set_id(); + + initialize(); +} + +void DAGUniverse::set_id() { // determine the next universe id int32_t next_univ_id = 0; @@ -81,8 +88,6 @@ DAGUniverse::DAGUniverse( // set the universe id id_ = next_univ_id; - - initialize(); } void DAGUniverse::initialize() @@ -91,6 +96,8 @@ void DAGUniverse::initialize() init_dagmc(); + read_uwuw_materials(); + init_cells(); init_surfaces(); @@ -102,19 +109,6 @@ void DAGUniverse::init_dagmc() // create a new DAGMC instance dagmc_instance_ = std::make_shared(); - // --- Materials --- - - // read any UWUW materials from the file - read_uwuw_materials(); - - // check for uwuw material definitions - bool using_uwuw = uses_uwuw(); - - // notify user if UWUW materials are going to be used - if (using_uwuw) { - write_message("Found UWUW Materials in the DAGMC geometry file.", 6); - } - // load the DAGMC geometry filename_ = settings::path_input + filename_; if (!file_exists(filename_)) { @@ -514,6 +508,9 @@ void DAGUniverse::read_uwuw_materials() if (mat_lib.size() == 0) return; + // notify user if UWUW materials are going to be used + write_message("Found UWUW Materials in the DAGMC geometry file.", 6); + // if we're using automatic IDs, update the UWUW material metadata if (adjust_material_ids_) { for (auto& mat : uwuw_->material_library) { From 05577e6a2e174c621145951ff6b737c25ccbda83 Mon Sep 17 00:00:00 2001 From: helen-brooks Date: Fri, 8 Apr 2022 14:06:46 +0100 Subject: [PATCH 04/17] Add new DAGUniverse constructor from external DAGMC --- include/openmc/dagmc.h | 5 +++++ src/dagmc.cpp | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/include/openmc/dagmc.h b/include/openmc/dagmc.h index 1fcbb04a0c..959ed71494 100644 --- a/include/openmc/dagmc.h +++ b/include/openmc/dagmc.h @@ -88,6 +88,11 @@ public: explicit DAGUniverse(const std::string& filename, bool auto_geom_ids = false, bool auto_mat_ids = false); + //! Alternative DAGMC universe constructor for external DAGMC + explicit DAGUniverse(std::shared_ptr external_dagmc_ptr, + bool auto_geom_ids = false, + bool auto_mat_ids = false); + //! Initialize the DAGMC accel. data structures, indices, material //! assignments, etc. void initialize(); diff --git a/src/dagmc.cpp b/src/dagmc.cpp index 260f58ebbc..d3a34ca18e 100644 --- a/src/dagmc.cpp +++ b/src/dagmc.cpp @@ -76,6 +76,14 @@ DAGUniverse::DAGUniverse( initialize(); } +DAGUniverse::DAGUniverse(std::shared_ptr external_dagmc_ptr, + bool auto_geom_ids, bool auto_mat_ids) + : dagmc_instance_(external_dagmc_ptr), filename_(""), + adjust_geometry_ids_(auto_geom_ids), adjust_material_ids_(auto_mat_ids) +{ + set_id(); +} + void DAGUniverse::set_id() { // determine the next universe id From cc6c3ac9e69b82d120dd00cf56f23e87934e4bc5 Mon Sep 17 00:00:00 2001 From: helen-brooks Date: Wed, 13 Apr 2022 12:58:33 +0100 Subject: [PATCH 05/17] More refactoring of DAGMC universe metadata; allow external setting of material temperature and population of universes' cells --- include/openmc/cell.h | 3 +++ include/openmc/dagmc.h | 10 +++++++-- include/openmc/material.h | 3 +++ src/cell.cpp | 23 ++++++++++++-------- src/dagmc.cpp | 44 +++++++++++++++++++++------------------ 5 files changed, 52 insertions(+), 31 deletions(-) diff --git a/include/openmc/cell.h b/include/openmc/cell.h index d975750a16..01f0375865 100644 --- a/include/openmc/cell.h +++ b/include/openmc/cell.h @@ -300,5 +300,8 @@ struct CellInstanceHash { void read_cells(pugi::xml_node node); +//! Add cells to universes +void populate_universes(); + } // namespace openmc #endif // OPENMC_CELL_H diff --git a/include/openmc/dagmc.h b/include/openmc/dagmc.h index 959ed71494..4b7a6c45d1 100644 --- a/include/openmc/dagmc.h +++ b/include/openmc/dagmc.h @@ -90,6 +90,7 @@ public: //! Alternative DAGMC universe constructor for external DAGMC explicit DAGUniverse(std::shared_ptr external_dagmc_ptr, + const std::string& filename, bool auto_geom_ids = false, bool auto_mat_ids = false); @@ -97,6 +98,13 @@ public: //! assignments, etc. void initialize(); + //! When providing an external DAGMC instance, the user will need to call + //! these methods manually + void init_metadata(); //!< Create and initialise dagmcMetaData pointer + void init_uwuw(); //!< Create UWUW pointer + void init_cells(); //!< Create cells from DAGMC volumes + void init_surfaces(); //!< Create surfaces from DAGMC surfaces + //! Reads UWUW materials and returns an ID map void read_uwuw_materials(); //! Indicates whether or not UWUW materials are present @@ -147,8 +155,6 @@ public: private: void set_id(); //!< Deduce the universe id from model::universes void init_dagmc(); //!< Create and initialise DAGMC pointer - void init_cells(); //!< Create cells from DAGMC volumes - void init_surfaces(); //!< Create surfaces from DAGMC surfaces std::string filename_; //!< Name of the DAGMC file used to create this universe diff --git a/include/openmc/material.h b/include/openmc/material.h index 709d205738..b251a3ca85 100644 --- a/include/openmc/material.h +++ b/include/openmc/material.h @@ -113,6 +113,9 @@ public: //! \param[in] units Units of density void set_density(double density, gsl::cstring_span units); + //! Set temperature of the material + void set_temperature(double temperature) { temperature_ = temperature; }; + //! Get nuclides in material //! \return Indices into the global nuclides vector gsl::span nuclides() const diff --git a/src/cell.cpp b/src/cell.cpp index 28be2c2cff..f9786ce3eb 100644 --- a/src/cell.cpp +++ b/src/cell.cpp @@ -846,6 +846,20 @@ void read_cells(pugi::xml_node node) read_dagmc_universes(node); + populate_universes(); + + // Allocate the cell overlap count if necessary. + if (settings::check_overlaps) { + model::overlap_check_count.resize(model::cells.size(), 0); + } + + if (model::cells.size() == 0) { + fatal_error("No cells were found in the geometry.xml file"); + } +} + +void populate_universes() +{ // Populate the Universe vector and map. for (int i = 0; i < model::cells.size(); i++) { int32_t uid = model::cells[i]->universe_; @@ -860,15 +874,6 @@ void read_cells(pugi::xml_node node) } } model::universes.shrink_to_fit(); - - // Allocate the cell overlap count if necessary. - if (settings::check_overlaps) { - model::overlap_check_count.resize(model::cells.size(), 0); - } - - if (model::cells.size() == 0) { - fatal_error("No cells were found in the geometry.xml file"); - } } //============================================================================== diff --git a/src/dagmc.cpp b/src/dagmc.cpp index d3a34ca18e..4c72779ce5 100644 --- a/src/dagmc.cpp +++ b/src/dagmc.cpp @@ -77,8 +77,9 @@ DAGUniverse::DAGUniverse( } DAGUniverse::DAGUniverse(std::shared_ptr external_dagmc_ptr, + const std::string& filename, bool auto_geom_ids, bool auto_mat_ids) - : dagmc_instance_(external_dagmc_ptr), filename_(""), + : dagmc_instance_(external_dagmc_ptr), filename_(filename), adjust_geometry_ids_(auto_geom_ids), adjust_material_ids_(auto_mat_ids) { set_id(); @@ -104,6 +105,10 @@ void DAGUniverse::initialize() init_dagmc(); + init_metadata(); + + init_uwuw(); + read_uwuw_materials(); init_cells(); @@ -128,7 +133,10 @@ void DAGUniverse::init_dagmc() // initialize acceleration data structures rval = dagmc_instance_->init_OBBTree(); MB_CHK_ERR_CONT(rval); +} +void DAGUniverse::init_metadata() +{ // parse model metadata dmd_ptr = std::make_unique(dagmc_instance_.get(), false, false); dmd_ptr->load_property_data(); @@ -136,6 +144,7 @@ void DAGUniverse::init_dagmc() std::vector keywords {"temp"}; std::map dum; std::string delimiters = ":/"; + moab::ErrorCode rval; rval = dagmc_instance_->parse_properties(keywords, dum, delimiters.c_str()); MB_CHK_ERR_CONT(rval); } @@ -502,38 +511,33 @@ void DAGUniverse::legacy_assign_material( } } +void DAGUniverse::init_uwuw() +{ + uwuw_ = std::make_shared(filename_.c_str()); +} + void DAGUniverse::read_uwuw_materials() { - - int32_t next_material_id = 0; - for (const auto& m : model::materials) { - next_material_id = std::max(m->id_, next_material_id); - } - next_material_id++; - - uwuw_ = std::make_shared(filename_.c_str()); - const auto& mat_lib = uwuw_->material_library; - if (mat_lib.size() == 0) + if (!uses_uwuw()) return; - // notify user if UWUW materials are going to be used + // Notify user if UWUW materials are going to be used write_message("Found UWUW Materials in the DAGMC geometry file.", 6); // if we're using automatic IDs, update the UWUW material metadata if (adjust_material_ids_) { + int32_t next_material_id = 0; + for (const auto& m : model::materials) { + next_material_id = std::max(m->id_, next_material_id); + } + next_material_id++; + for (auto& mat : uwuw_->material_library) { mat.second->metadata["mat_number"] = next_material_id++; } } - std::stringstream ss; - ss << "\n"; - ss << "\n"; - for (auto mat : mat_lib) { - ss << mat.second->openmc("atom"); - } - ss << ""; - std::string mat_xml_string = ss.str(); + std::string mat_xml_string = get_uwuw_materials_xml(); // create a pugi XML document from this string pugi::xml_document doc; From fb9c12bd14aff9c0d1b32ec6ab304658cdc382c1 Mon Sep 17 00:00:00 2001 From: helen-brooks Date: Thu, 14 Apr 2022 13:08:16 +0100 Subject: [PATCH 06/17] Add switch to disable uwuw in DAGUniverse with external DAG --- include/openmc/dagmc.h | 1 + src/dagmc.cpp | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/include/openmc/dagmc.h b/include/openmc/dagmc.h index 4b7a6c45d1..4c4e7f8c49 100644 --- a/include/openmc/dagmc.h +++ b/include/openmc/dagmc.h @@ -161,6 +161,7 @@ private: std::shared_ptr uwuw_; //!< Pointer to the UWUW instance for this universe std::unique_ptr dmd_ptr; //! Pointer to DAGMC metadata object + bool uwuw_disabled; //!< Switch to disable UWUW materials bool adjust_geometry_ids_; //!< Indicates whether or not to automatically //!< generate new cell and surface IDs for the //!< universe diff --git a/src/dagmc.cpp b/src/dagmc.cpp index 4c72779ce5..061c04f877 100644 --- a/src/dagmc.cpp +++ b/src/dagmc.cpp @@ -83,6 +83,7 @@ DAGUniverse::DAGUniverse(std::shared_ptr external_dagmc_ptr, adjust_geometry_ids_(auto_geom_ids), adjust_material_ids_(auto_mat_ids) { set_id(); + uwuw_disabled = (filename==""); } void DAGUniverse::set_id() @@ -102,6 +103,7 @@ void DAGUniverse::set_id() void DAGUniverse::initialize() { geom_type() = GeometryType::DAG; + uwuw_disabled = false; init_dagmc(); @@ -424,7 +426,8 @@ void DAGUniverse::to_hdf5(hid_t universes_group) const bool DAGUniverse::uses_uwuw() const { - return !uwuw_->material_library.empty(); + if (uwuw_disabled) return false; + else return !uwuw_->material_library.empty(); } std::string DAGUniverse::get_uwuw_materials_xml() const @@ -513,6 +516,7 @@ void DAGUniverse::legacy_assign_material( void DAGUniverse::init_uwuw() { + if (uwuw_disabled) return; uwuw_ = std::make_shared(filename_.c_str()); } From 5dd6da91c5ce40894877fc216d664838f77d5c33 Mon Sep 17 00:00:00 2001 From: helen-brooks Date: Tue, 19 Apr 2022 15:50:34 +0100 Subject: [PATCH 07/17] Only expose methods that are needed externally --- include/openmc/dagmc.h | 10 ++-------- src/dagmc.cpp | 33 ++++++++++++--------------------- 2 files changed, 14 insertions(+), 29 deletions(-) diff --git a/include/openmc/dagmc.h b/include/openmc/dagmc.h index 4c4e7f8c49..2fa0919e51 100644 --- a/include/openmc/dagmc.h +++ b/include/openmc/dagmc.h @@ -98,13 +98,6 @@ public: //! assignments, etc. void initialize(); - //! When providing an external DAGMC instance, the user will need to call - //! these methods manually - void init_metadata(); //!< Create and initialise dagmcMetaData pointer - void init_uwuw(); //!< Create UWUW pointer - void init_cells(); //!< Create cells from DAGMC volumes - void init_surfaces(); //!< Create surfaces from DAGMC surfaces - //! Reads UWUW materials and returns an ID map void read_uwuw_materials(); //! Indicates whether or not UWUW materials are present @@ -155,6 +148,8 @@ public: private: void set_id(); //!< Deduce the universe id from model::universes void init_dagmc(); //!< Create and initialise DAGMC pointer + void init_metadata(); //!< Create and initialise dagmcMetaData pointer + void init_geometry(); //!< Create cells and surfaces from DAGMC entities std::string filename_; //!< Name of the DAGMC file used to create this universe @@ -169,7 +164,6 @@ private: //!< generate new material IDs for the universe bool has_graveyard_; //!< Indicates if the DAGMC geometry has a "graveyard" //!< volume - moab::EntityHandle graveyard; //!< MOAB index for graveyard }; //============================================================================== diff --git a/src/dagmc.cpp b/src/dagmc.cpp index 061c04f877..2d0bab86e4 100644 --- a/src/dagmc.cpp +++ b/src/dagmc.cpp @@ -83,7 +83,9 @@ DAGUniverse::DAGUniverse(std::shared_ptr external_dagmc_ptr, adjust_geometry_ids_(auto_geom_ids), adjust_material_ids_(auto_mat_ids) { set_id(); - uwuw_disabled = (filename==""); + init_metadata(); + read_uwuw_materials(); + init_geometry(); } void DAGUniverse::set_id() @@ -103,19 +105,14 @@ void DAGUniverse::set_id() void DAGUniverse::initialize() { geom_type() = GeometryType::DAG; - uwuw_disabled = false; init_dagmc(); init_metadata(); - init_uwuw(); - read_uwuw_materials(); - init_cells(); - - init_surfaces(); + init_geometry(); } void DAGUniverse::init_dagmc() @@ -151,7 +148,7 @@ void DAGUniverse::init_metadata() MB_CHK_ERR_CONT(rval); } -void DAGUniverse::init_cells() +void DAGUniverse::init_geometry() { moab::ErrorCode rval; @@ -166,7 +163,7 @@ void DAGUniverse::init_cells() // initialize cell objects int n_cells = dagmc_instance_->num_entities(3); - graveyard = 0; + moab::EntityHandle graveyard = 0; for (int i = 0; i < n_cells; i++) { moab::EntityHandle vol_handle = dagmc_instance_->entity_by_index(3, i + 1); @@ -259,12 +256,6 @@ void DAGUniverse::init_cells() has_graveyard_ = graveyard; -} - -void DAGUniverse::init_surfaces() -{ - moab::ErrorCode rval; - // determine the next surface id int32_t next_surf_id = 0; for (const auto& s : model::surfaces) { @@ -514,14 +505,14 @@ void DAGUniverse::legacy_assign_material( } } -void DAGUniverse::init_uwuw() -{ - if (uwuw_disabled) return; - uwuw_ = std::make_shared(filename_.c_str()); -} - void DAGUniverse::read_uwuw_materials() { + // If no filename was provided, disable read UWUW materials + uwuw_disabled = (filename_==""); + + if (uwuw_disabled) return; + uwuw_ = std::make_shared(filename_.c_str()); + if (!uses_uwuw()) return; From 86e44c4e4a60db49365b8958128fcabd7cc8ba12 Mon Sep 17 00:00:00 2001 From: helen-brooks Date: Wed, 20 Apr 2022 10:55:15 +0100 Subject: [PATCH 08/17] Add regression test for new DAGUniverse constructor --- .../dagmc/external/__init__.py | 0 .../regression_tests/dagmc/external/dagmc.h5m | 1 + .../dagmc/external/inputs_true.dat | 39 ++++++ .../regression_tests/dagmc/external/main.cpp | 80 +++++++++++ .../dagmc/external/results_true.dat | 5 + tests/regression_tests/dagmc/external/test.py | 127 ++++++++++++++++++ 6 files changed, 252 insertions(+) create mode 100644 tests/regression_tests/dagmc/external/__init__.py create mode 120000 tests/regression_tests/dagmc/external/dagmc.h5m create mode 100644 tests/regression_tests/dagmc/external/inputs_true.dat create mode 100644 tests/regression_tests/dagmc/external/main.cpp create mode 100644 tests/regression_tests/dagmc/external/results_true.dat create mode 100644 tests/regression_tests/dagmc/external/test.py diff --git a/tests/regression_tests/dagmc/external/__init__.py b/tests/regression_tests/dagmc/external/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/regression_tests/dagmc/external/dagmc.h5m b/tests/regression_tests/dagmc/external/dagmc.h5m new file mode 120000 index 0000000000..92c41719c5 --- /dev/null +++ b/tests/regression_tests/dagmc/external/dagmc.h5m @@ -0,0 +1 @@ +../legacy/dagmc.h5m \ No newline at end of file diff --git a/tests/regression_tests/dagmc/external/inputs_true.dat b/tests/regression_tests/dagmc/external/inputs_true.dat new file mode 100644 index 0000000000..2f56410466 --- /dev/null +++ b/tests/regression_tests/dagmc/external/inputs_true.dat @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + eigenvalue + 100 + 5 + 0 + + + -4 -4 -4 4 4 4 + + + + + + + 1 + + + 1 + total + + diff --git a/tests/regression_tests/dagmc/external/main.cpp b/tests/regression_tests/dagmc/external/main.cpp new file mode 100644 index 0000000000..87b1fcc8c3 --- /dev/null +++ b/tests/regression_tests/dagmc/external/main.cpp @@ -0,0 +1,80 @@ +#include "openmc/capi.h" +#include "openmc/cross_sections.h" +#include "openmc/dagmc.h" +#include "openmc/error.h" +#include "openmc/geometry.h" +#include "openmc/geometry_aux.h" +#include "openmc/nuclide.h" +#include + +int main(int argc, char* argv[]) +{ + using namespace openmc; + int openmc_err; + + // Initialise OpenMC + openmc_err = openmc_init(argc, argv, nullptr); + if (openmc_err == -1) { + // This happens for the -h and -v flags + return EXIT_SUCCESS; + } else if (openmc_err) { + fatal_error(openmc_err_msg); + } + + // Create DAGMC ptr + std::string filename = "dagmc.h5m"; + std::shared_ptr dag_ptr = std::make_shared(); + moab::ErrorCode rval = dag_ptr->load_file(filename.c_str()); + if (rval != moab::MB_SUCCESS) { + fatal_error("Failed to load file"); + } + + // Initialize acceleration data structures + rval = dag_ptr->init_OBBTree(); + if (rval != moab::MB_SUCCESS) { + fatal_error("Failed to initialise OBB tree"); + } + + // Get rid of existing geometry + std::unordered_map nuclide_map_copy = + openmc::data::nuclide_map; + openmc::data::nuclides.clear(); + openmc::data::nuclide_map = nuclide_map_copy; + openmc::model::surfaces.clear(); + openmc::model::surface_map.clear(); + openmc::model::cells.clear(); + openmc::model::cell_map.clear(); + openmc::model::universes.clear(); + openmc::model::universe_map.clear(); + + // Create new DAGMC universe + openmc::model::universes.push_back( + std::make_unique(dag_ptr, "")); + model::universe_map[model::universes.back()->id_] = + model::universes.size() - 1; + + // Add cells to universes + openmc::populate_universes(); + + // Set root universe + openmc::model::root_universe = openmc::find_root_universe(); + openmc::check_dagmc_root_univ(); + + // Final geometry setup and assign temperatures + openmc::finalize_geometry(); + + // Finalize cross sections having assigned temperatures + openmc::finalize_cross_sections(); + + // Run OpenMC + openmc_err = openmc_run(); + if (openmc_err) + fatal_error(openmc_err_msg); + + // Deallocate memory + openmc_err = openmc_finalize(); + if (openmc_err) + fatal_error(openmc_err_msg); + + return EXIT_SUCCESS; +} diff --git a/tests/regression_tests/dagmc/external/results_true.dat b/tests/regression_tests/dagmc/external/results_true.dat new file mode 100644 index 0000000000..e5127c8272 --- /dev/null +++ b/tests/regression_tests/dagmc/external/results_true.dat @@ -0,0 +1,5 @@ +k-combined: +8.426936E-01 5.715847E-02 +tally 1: +8.093843E+00 +1.328829E+01 diff --git a/tests/regression_tests/dagmc/external/test.py b/tests/regression_tests/dagmc/external/test.py new file mode 100644 index 0000000000..c31d814408 --- /dev/null +++ b/tests/regression_tests/dagmc/external/test.py @@ -0,0 +1,127 @@ +from pathlib import Path +import os +import shutil +import subprocess +from subprocess import CalledProcessError +import textwrap +import glob +from itertools import product + +import openmc +import openmc.lib +import numpy as np +import pytest + +from tests.regression_tests import config +from tests.testing_harness import PyAPITestHarness + +pytestmark = pytest.mark.skipif( + not openmc.lib._dagmc_enabled(), + reason="DAGMC is not enabled.") + +TETS_PER_VOXEL = 12 + +# Test that an external DAGMC instance can be passed in through the C API + +@pytest.fixture +def cpp_driver(request): + """Compile the external source""" + + # Get build directory and write CMakeLists.txt file + openmc_dir = Path(str(request.config.rootdir)) / 'build' + with open('CMakeLists.txt', 'w') as f: + f.write(textwrap.dedent(""" + cmake_minimum_required(VERSION 3.3 FATAL_ERROR) + project(openmc_cpp_driver CXX) + add_executable(main main.cpp) + find_package(OpenMC REQUIRED HINTS {}) + target_link_libraries(main OpenMC::libopenmc) + set_target_properties(main PROPERTIES CXX_STANDARD + 14 CXX_STANDARD_REQUIRED YES CXX_EXTENSIONS NO) + set(CMAKE_CXX_FLAGS "-pedantic-errors") + add_compile_definitions(DAGMC=1) + """.format(openmc_dir))) + + # Create temporary build directory and change to there + local_builddir = Path('build') + local_builddir.mkdir(exist_ok=True) + os.chdir(str(local_builddir)) + + if config['mpi']: + os.environ['CXX'] = 'mpicxx' + + try: + print("Building driver") + # Run cmake/make to build the shared libary + subprocess.run(['cmake', os.path.pardir], check=True) + subprocess.run(['make'], check=True) + os.chdir(os.path.pardir) + + yield "./build/main" + + finally: + # Remove local build directory when test is complete + shutil.rmtree('build') + os.remove('CMakeLists.txt') + +@pytest.fixture +def model(): + model = openmc.model.Model() + + # Settings + model.settings.batches = 5 + model.settings.inactive = 0 + model.settings.particles = 100 + source_box = openmc.stats.Box([-4, -4, -4], + [ 4, 4, 4]) + source = openmc.Source(space=source_box) + model.settings.source = source + #model.settings.dagmc = True + + # Geometry + dag_univ = openmc.DAGMCUniverse("dagmc.h5m") + model.geometry = openmc.Geometry(dag_univ) + + # Tallies + tally = openmc.Tally() + tally.scores = ['total'] + tally.filters = [openmc.CellFilter(1)] + model.tallies = [tally] + + # Materials + u235 = openmc.Material(name="no-void fuel") + u235.add_nuclide('U235', 1.0, 'ao') + u235.set_density('g/cc', 11) + u235.id = 40 + water = openmc.Material(name="water") + water.add_nuclide('H1', 2.0, 'ao') + water.add_nuclide('O16', 1.0, 'ao') + water.set_density('g/cc', 1.0) + water.add_s_alpha_beta('c_H_in_H2O') + water.id = 41 + mats = openmc.Materials([u235, water]) + model.materials = mats + + return model + +class ExternalDAGMCTest(PyAPITestHarness): + def __init__(self, executable, statepoint_name, model): + super().__init__(statepoint_name, model) + self.executable = executable + + def _run_openmc(self): + if config['update']: + # Generate the results file with internal python API + openmc.run(openmc_exec=config['exe'], event_based=config['event']) + elif config['mpi']: + mpi_args = [config['mpiexec'], '-n', config['mpi_np']] + openmc.run(openmc_exec=self.executable, + mpi_args=mpi_args, + event_based=config['event']) + else: + openmc.run(openmc_exec=self.executable, + event_based=config['event']) + +def test_external_dagmc(cpp_driver, model): + harness = ExternalDAGMCTest(cpp_driver,'statepoint.5.h5',model) + harness.main() From c35b710a1560857fe24c0ec5418f8aef1c1152f5 Mon Sep 17 00:00:00 2001 From: helen-brooks Date: Wed, 20 Apr 2022 14:35:51 +0100 Subject: [PATCH 09/17] Update external dagmc regression test to include an update of material temperatures --- tests/regression_tests/dagmc/external/inputs_true.dat | 1 + tests/regression_tests/dagmc/external/main.cpp | 9 +++++++++ tests/regression_tests/dagmc/external/test.py | 6 +++--- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/tests/regression_tests/dagmc/external/inputs_true.dat b/tests/regression_tests/dagmc/external/inputs_true.dat index 2f56410466..dd75bbdbd9 100644 --- a/tests/regression_tests/dagmc/external/inputs_true.dat +++ b/tests/regression_tests/dagmc/external/inputs_true.dat @@ -26,6 +26,7 @@ -4 -4 -4 4 4 4 + 293 diff --git a/tests/regression_tests/dagmc/external/main.cpp b/tests/regression_tests/dagmc/external/main.cpp index 87b1fcc8c3..6d9c97f59b 100644 --- a/tests/regression_tests/dagmc/external/main.cpp +++ b/tests/regression_tests/dagmc/external/main.cpp @@ -4,6 +4,7 @@ #include "openmc/error.h" #include "openmc/geometry.h" #include "openmc/geometry_aux.h" +#include "openmc/material.h" #include "openmc/nuclide.h" #include @@ -66,6 +67,14 @@ int main(int argc, char* argv[]) // Finalize cross sections having assigned temperatures openmc::finalize_cross_sections(); + // Check that we correctly assigned cell temperatures with non-void fill + for (auto& cell_ptr : openmc::model::cells) { + if (cell_ptr->material_.front() != openmc::C_NONE && + cell_ptr->temperature() != 300) { + fatal_error("Failed to set cell temperature"); + } + } + // Run OpenMC openmc_err = openmc_run(); if (openmc_err) diff --git a/tests/regression_tests/dagmc/external/test.py b/tests/regression_tests/dagmc/external/test.py index c31d814408..a9fa9e3eed 100644 --- a/tests/regression_tests/dagmc/external/test.py +++ b/tests/regression_tests/dagmc/external/test.py @@ -64,7 +64,7 @@ def cpp_driver(request): shutil.rmtree('build') os.remove('CMakeLists.txt') -@pytest.fixture +@pytest.fixture def model(): model = openmc.model.Model() @@ -76,7 +76,7 @@ def model(): [ 4, 4, 4]) source = openmc.Source(space=source_box) model.settings.source = source - #model.settings.dagmc = True + model.settings.temperature['default'] = 293 # Geometry dag_univ = openmc.DAGMCUniverse("dagmc.h5m") @@ -103,7 +103,7 @@ def model(): model.materials = mats return model - + class ExternalDAGMCTest(PyAPITestHarness): def __init__(self, executable, statepoint_name, model): super().__init__(statepoint_name, model) From 751e92f63b79e3c2027be4e31469337c3192e336 Mon Sep 17 00:00:00 2001 From: helen-brooks Date: Wed, 20 Apr 2022 15:48:39 +0100 Subject: [PATCH 10/17] Run clang-format --- include/openmc/dagmc.h | 17 ++++++++--------- src/dagmc.cpp | 27 +++++++++++++++------------ 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/include/openmc/dagmc.h b/include/openmc/dagmc.h index 2fa0919e51..f50133105b 100644 --- a/include/openmc/dagmc.h +++ b/include/openmc/dagmc.h @@ -90,9 +90,8 @@ public: //! Alternative DAGMC universe constructor for external DAGMC explicit DAGUniverse(std::shared_ptr external_dagmc_ptr, - const std::string& filename, - bool auto_geom_ids = false, - bool auto_mat_ids = false); + const std::string& filename, bool auto_geom_ids = false, + bool auto_mat_ids = false); //! Initialize the DAGMC accel. data structures, indices, material //! assignments, etc. @@ -146,17 +145,17 @@ public: bool has_graveyard() const { return has_graveyard_; } private: - void set_id(); //!< Deduce the universe id from model::universes - void init_dagmc(); //!< Create and initialise DAGMC pointer - void init_metadata(); //!< Create and initialise dagmcMetaData pointer - void init_geometry(); //!< Create cells and surfaces from DAGMC entities + void set_id(); //!< Deduce the universe id from model::universes + void init_dagmc(); //!< Create and initialise DAGMC pointer + void init_metadata(); //!< Create and initialise dagmcMetaData pointer + void init_geometry(); //!< Create cells and surfaces from DAGMC entities std::string filename_; //!< Name of the DAGMC file used to create this universe std::shared_ptr - uwuw_; //!< Pointer to the UWUW instance for this universe + uwuw_; //!< Pointer to the UWUW instance for this universe std::unique_ptr dmd_ptr; //! Pointer to DAGMC metadata object - bool uwuw_disabled; //!< Switch to disable UWUW materials + bool uwuw_disabled; //!< Switch to disable UWUW materials bool adjust_geometry_ids_; //!< Indicates whether or not to automatically //!< generate new cell and surface IDs for the //!< universe diff --git a/src/dagmc.cpp b/src/dagmc.cpp index 2d0bab86e4..2154db363e 100644 --- a/src/dagmc.cpp +++ b/src/dagmc.cpp @@ -77,10 +77,9 @@ DAGUniverse::DAGUniverse( } DAGUniverse::DAGUniverse(std::shared_ptr external_dagmc_ptr, - const std::string& filename, - bool auto_geom_ids, bool auto_mat_ids) + const std::string& filename, bool auto_geom_ids, bool auto_mat_ids) : dagmc_instance_(external_dagmc_ptr), filename_(filename), - adjust_geometry_ids_(auto_geom_ids), adjust_material_ids_(auto_mat_ids) + adjust_geometry_ids_(auto_geom_ids), adjust_material_ids_(auto_mat_ids) { set_id(); init_metadata(); @@ -137,7 +136,8 @@ void DAGUniverse::init_dagmc() void DAGUniverse::init_metadata() { // parse model metadata - dmd_ptr = std::make_unique(dagmc_instance_.get(), false, false); + dmd_ptr = + std::make_unique(dagmc_instance_.get(), false, false); dmd_ptr->load_property_data(); std::vector keywords {"temp"}; @@ -206,7 +206,8 @@ void DAGUniverse::init_geometry() } else { if (uses_uwuw()) { // lookup material in uwuw if present - std::string uwuw_mat = dmd_ptr->volume_material_property_data_eh[vol_handle]; + std::string uwuw_mat = + dmd_ptr->volume_material_property_data_eh[vol_handle]; if (uwuw_->material_library.count(uwuw_mat) != 0) { // Note: material numbers are set by UWUW int mat_number = uwuw_->material_library.get_material(uwuw_mat) @@ -276,7 +277,8 @@ void DAGUniverse::init_geometry() : dagmc_instance_->id_by_index(2, i + 1); // set BCs - std::string bc_value = dmd_ptr->get_surface_property("boundary", surf_handle); + std::string bc_value = + dmd_ptr->get_surface_property("boundary", surf_handle); to_lower(bc_value); if (bc_value.empty() || bc_value == "transmit" || bc_value == "transmission") { @@ -320,10 +322,8 @@ void DAGUniverse::init_geometry() model::surfaces.emplace_back(std::move(s)); } // end surface loop - } - std::string DAGUniverse::dagmc_ids_for_dim(int dim) const { // generate a vector of ids @@ -417,8 +417,10 @@ void DAGUniverse::to_hdf5(hid_t universes_group) const bool DAGUniverse::uses_uwuw() const { - if (uwuw_disabled) return false; - else return !uwuw_->material_library.empty(); + if (uwuw_disabled) + return false; + else + return !uwuw_->material_library.empty(); } std::string DAGUniverse::get_uwuw_materials_xml() const @@ -508,9 +510,10 @@ void DAGUniverse::legacy_assign_material( void DAGUniverse::read_uwuw_materials() { // If no filename was provided, disable read UWUW materials - uwuw_disabled = (filename_==""); + uwuw_disabled = (filename_ == ""); - if (uwuw_disabled) return; + if (uwuw_disabled) + return; uwuw_ = std::make_shared(filename_.c_str()); if (!uses_uwuw()) From 116c7c33c070ce27156efefaf01aff7a9e405390 Mon Sep 17 00:00:00 2001 From: helen-brooks <67463845+helen-brooks@users.noreply.github.com> Date: Wed, 25 May 2022 09:39:34 +0100 Subject: [PATCH 11/17] Apply suggestions from paulromano review Co-authored-by: Paul Romano --- tests/regression_tests/dagmc/external/test.py | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/tests/regression_tests/dagmc/external/test.py b/tests/regression_tests/dagmc/external/test.py index a9fa9e3eed..938e262ffb 100644 --- a/tests/regression_tests/dagmc/external/test.py +++ b/tests/regression_tests/dagmc/external/test.py @@ -2,14 +2,10 @@ from pathlib import Path import os import shutil import subprocess -from subprocess import CalledProcessError import textwrap -import glob -from itertools import product import openmc import openmc.lib -import numpy as np import pytest from tests.regression_tests import config @@ -19,8 +15,6 @@ pytestmark = pytest.mark.skipif( not openmc.lib._dagmc_enabled(), reason="DAGMC is not enabled.") -TETS_PER_VOXEL = 12 - # Test that an external DAGMC instance can be passed in through the C API @pytest.fixture @@ -36,8 +30,7 @@ def cpp_driver(request): add_executable(main main.cpp) find_package(OpenMC REQUIRED HINTS {}) target_link_libraries(main OpenMC::libopenmc) - set_target_properties(main PROPERTIES CXX_STANDARD - 14 CXX_STANDARD_REQUIRED YES CXX_EXTENSIONS NO) + target_compile_features(main PUBLIC cxx_std_14) set(CMAKE_CXX_FLAGS "-pedantic-errors") add_compile_definitions(DAGMC=1) """.format(openmc_dir))) @@ -45,15 +38,13 @@ def cpp_driver(request): # Create temporary build directory and change to there local_builddir = Path('build') local_builddir.mkdir(exist_ok=True) - os.chdir(str(local_builddir)) + os.chdir(local_builddir) - if config['mpi']: - os.environ['CXX'] = 'mpicxx' + mpi_arg = "On" if config['mpi'] else "Off" try: - print("Building driver") # Run cmake/make to build the shared libary - subprocess.run(['cmake', os.path.pardir], check=True) + subprocess.run(['cmake', os.path.pardir, f'-DOPENMC_USE_MPI={mpi_arg}'], check=True) subprocess.run(['make'], check=True) os.chdir(os.path.pardir) @@ -123,5 +114,5 @@ class ExternalDAGMCTest(PyAPITestHarness): event_based=config['event']) def test_external_dagmc(cpp_driver, model): - harness = ExternalDAGMCTest(cpp_driver,'statepoint.5.h5',model) + harness = ExternalDAGMCTest(cpp_driver, 'statepoint.5.h5', model) harness.main() From d9498216dd12c26c5f873453aa4efdb9408e9fe9 Mon Sep 17 00:00:00 2001 From: helen-brooks <67463845+helen-brooks@users.noreply.github.com> Date: Wed, 25 May 2022 10:36:40 +0100 Subject: [PATCH 12/17] Apply minor changes from pshriwise code review Co-authored-by: Patrick Shriwise --- include/openmc/dagmc.h | 2 +- src/dagmc.cpp | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/include/openmc/dagmc.h b/include/openmc/dagmc.h index f50133105b..0a74928b89 100644 --- a/include/openmc/dagmc.h +++ b/include/openmc/dagmc.h @@ -88,7 +88,7 @@ public: explicit DAGUniverse(const std::string& filename, bool auto_geom_ids = false, bool auto_mat_ids = false); - //! Alternative DAGMC universe constructor for external DAGMC + //! Alternative DAGMC universe constructor for external DAGMC instance explicit DAGUniverse(std::shared_ptr external_dagmc_ptr, const std::string& filename, bool auto_geom_ids = false, bool auto_mat_ids = false); diff --git a/src/dagmc.cpp b/src/dagmc.cpp index 2154db363e..8876690316 100644 --- a/src/dagmc.cpp +++ b/src/dagmc.cpp @@ -72,13 +72,12 @@ DAGUniverse::DAGUniverse( adjust_material_ids_(auto_mat_ids) { set_id(); - initialize(); } -DAGUniverse::DAGUniverse(std::shared_ptr external_dagmc_ptr, +DAGUniverse::DAGUniverse(std::shared_ptr dagmc_ptr, const std::string& filename, bool auto_geom_ids, bool auto_mat_ids) - : dagmc_instance_(external_dagmc_ptr), filename_(filename), + : dagmc_instance_(dagmc_ptr), filename_(filename), adjust_geometry_ids_(auto_geom_ids), adjust_material_ids_(auto_mat_ids) { set_id(); From 8bf7de39ca64eadca38d2a6769e552307e8868d1 Mon Sep 17 00:00:00 2001 From: helen-brooks Date: Wed, 25 May 2022 10:47:37 +0100 Subject: [PATCH 13/17] Add empty string default argument for external DAGMC Universe constructor --- include/openmc/dagmc.h | 2 +- tests/regression_tests/dagmc/external/main.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/openmc/dagmc.h b/include/openmc/dagmc.h index 0a74928b89..5bf264b435 100644 --- a/include/openmc/dagmc.h +++ b/include/openmc/dagmc.h @@ -90,7 +90,7 @@ public: //! Alternative DAGMC universe constructor for external DAGMC instance explicit DAGUniverse(std::shared_ptr external_dagmc_ptr, - const std::string& filename, bool auto_geom_ids = false, + const std::string& filename = "", bool auto_geom_ids = false, bool auto_mat_ids = false); //! Initialize the DAGMC accel. data structures, indices, material diff --git a/tests/regression_tests/dagmc/external/main.cpp b/tests/regression_tests/dagmc/external/main.cpp index 6d9c97f59b..9f5c1ceebb 100644 --- a/tests/regression_tests/dagmc/external/main.cpp +++ b/tests/regression_tests/dagmc/external/main.cpp @@ -50,7 +50,7 @@ int main(int argc, char* argv[]) // Create new DAGMC universe openmc::model::universes.push_back( - std::make_unique(dag_ptr, "")); + std::make_unique(dag_ptr)); model::universe_map[model::universes.back()->id_] = model::universes.size() - 1; From 4d52218178fc8310e9da2891fda662649254de4c Mon Sep 17 00:00:00 2001 From: helen-brooks Date: Wed, 25 May 2022 13:17:14 +0100 Subject: [PATCH 14/17] Remove redundant uwuw_disabled boolean member in DAGUniverse --- include/openmc/dagmc.h | 1 - src/dagmc.cpp | 12 ++++-------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/include/openmc/dagmc.h b/include/openmc/dagmc.h index 5bf264b435..9930763474 100644 --- a/include/openmc/dagmc.h +++ b/include/openmc/dagmc.h @@ -155,7 +155,6 @@ private: std::shared_ptr uwuw_; //!< Pointer to the UWUW instance for this universe std::unique_ptr dmd_ptr; //! Pointer to DAGMC metadata object - bool uwuw_disabled; //!< Switch to disable UWUW materials bool adjust_geometry_ids_; //!< Indicates whether or not to automatically //!< generate new cell and surface IDs for the //!< universe diff --git a/src/dagmc.cpp b/src/dagmc.cpp index 8876690316..bb88f64889 100644 --- a/src/dagmc.cpp +++ b/src/dagmc.cpp @@ -416,10 +416,7 @@ void DAGUniverse::to_hdf5(hid_t universes_group) const bool DAGUniverse::uses_uwuw() const { - if (uwuw_disabled) - return false; - else - return !uwuw_->material_library.empty(); + return uwuw_ && !uwuw_->material_library.empty(); } std::string DAGUniverse::get_uwuw_materials_xml() const @@ -508,11 +505,10 @@ void DAGUniverse::legacy_assign_material( void DAGUniverse::read_uwuw_materials() { - // If no filename was provided, disable read UWUW materials - uwuw_disabled = (filename_ == ""); - - if (uwuw_disabled) + // If no filename was provided, don't read UWUW materials + if (filename_ == "") return; + uwuw_ = std::make_shared(filename_.c_str()); if (!uses_uwuw()) From 82a7ccb16db4c11641f80d86fecfbe46a007b0d4 Mon Sep 17 00:00:00 2001 From: helen-brooks Date: Wed, 25 May 2022 15:10:50 +0100 Subject: [PATCH 15/17] Something weird happened during rebase - add back some lines which got removed --- tests/regression_tests/dagmc/external/main.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/regression_tests/dagmc/external/main.cpp b/tests/regression_tests/dagmc/external/main.cpp index 9f5c1ceebb..42f7d97c90 100644 --- a/tests/regression_tests/dagmc/external/main.cpp +++ b/tests/regression_tests/dagmc/external/main.cpp @@ -48,6 +48,11 @@ int main(int argc, char* argv[]) openmc::model::universes.clear(); openmc::model::universe_map.clear(); + // Update materials (emulate an external program) + for (auto& mat_ptr : openmc::model::materials) { + mat_ptr->set_temperature(300); + } + // Create new DAGMC universe openmc::model::universes.push_back( std::make_unique(dag_ptr)); From 33ded6d2d324eb03f1531bea9d5a97a65d5e36b2 Mon Sep 17 00:00:00 2001 From: helen-brooks Date: Fri, 27 May 2022 09:09:55 +0100 Subject: [PATCH 16/17] Additional comments in test --- tests/regression_tests/dagmc/external/test.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/regression_tests/dagmc/external/test.py b/tests/regression_tests/dagmc/external/test.py index 938e262ffb..2671f9a846 100644 --- a/tests/regression_tests/dagmc/external/test.py +++ b/tests/regression_tests/dagmc/external/test.py @@ -101,15 +101,25 @@ class ExternalDAGMCTest(PyAPITestHarness): self.executable = executable def _run_openmc(self): + """ + Just test if results generated with the external C++ API are + self-consistent with the internal python API. + We generate the "truth" results with the python API but + the main test produces the results file by running the + executable compiled from main.cpp. This future-proofs + the test - we only care that the two routes are equivalent. + """ if config['update']: # Generate the results file with internal python API openmc.run(openmc_exec=config['exe'], event_based=config['event']) elif config['mpi']: mpi_args = [config['mpiexec'], '-n', config['mpi_np']] + # Run main cpp executable with MPI openmc.run(openmc_exec=self.executable, mpi_args=mpi_args, event_based=config['event']) else: + # Run main cpp executable openmc.run(openmc_exec=self.executable, event_based=config['event']) From bfa4b575b62b3f6be6e51ebc763384b53a0fb163 Mon Sep 17 00:00:00 2001 From: helen-brooks Date: Tue, 31 May 2022 09:14:51 +0100 Subject: [PATCH 17/17] Forgot the indent on docstring --- tests/regression_tests/dagmc/external/test.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/regression_tests/dagmc/external/test.py b/tests/regression_tests/dagmc/external/test.py index 2671f9a846..93123ae1ed 100644 --- a/tests/regression_tests/dagmc/external/test.py +++ b/tests/regression_tests/dagmc/external/test.py @@ -101,14 +101,14 @@ class ExternalDAGMCTest(PyAPITestHarness): self.executable = executable def _run_openmc(self): - """ - Just test if results generated with the external C++ API are - self-consistent with the internal python API. - We generate the "truth" results with the python API but - the main test produces the results file by running the - executable compiled from main.cpp. This future-proofs - the test - we only care that the two routes are equivalent. - """ + """ + Just test if results generated with the external C++ API are + self-consistent with the internal python API. + We generate the "truth" results with the python API but + the main test produces the results file by running the + executable compiled from main.cpp. This future-proofs + the test - we only care that the two routes are equivalent. + """ if config['update']: # Generate the results file with internal python API openmc.run(openmc_exec=config['exe'], event_based=config['event'])