From be5318fdb0fbb7a447e68fad6787e2b6e221a20d Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Wed, 8 Jul 2020 21:16:36 -0500 Subject: [PATCH] Reorganizing some of the DAGMC-related code and using shared pointers instead. --- include/openmc/cell.h | 17 ++++++++++++++++- include/openmc/dagmc.h | 4 ++-- include/openmc/surface.h | 2 +- src/cell.cpp | 16 ++++++++++++++++ src/dagmc.cpp | 17 +++++++---------- src/finalize.cpp | 3 --- 6 files changed, 42 insertions(+), 17 deletions(-) diff --git a/include/openmc/cell.h b/include/openmc/cell.h index c7ba0ab13..282f00fff 100644 --- a/include/openmc/cell.h +++ b/include/openmc/cell.h @@ -75,6 +75,20 @@ public: unique_ptr partitioner_; }; +#ifdef DAGMC + +class DAGUniverse : public Universe { + +public: + explicit DAGUniverse(std::string filename); + + + // Data Members + std::shared_ptr dag_instance_; //! DAGMC Instance for this universe +}; + +#endif + //============================================================================== //============================================================================== @@ -271,7 +285,7 @@ public: void to_hdf5(hid_t group_id) const; - moab::DagMC* dagmc_ptr_; //!< Pointer to DagMC instance + std::shared_ptr dagmc_ptr_; //!< Pointer to DagMC instance int32_t dag_index_; //!< DagMC index of cell }; #endif @@ -343,6 +357,7 @@ struct CellInstanceHash { void read_cells(pugi::xml_node node); #ifdef DAGMC +void read_dagmc_universes(pugi::xml_node node); int32_t next_cell(DAGCell* cur_cell, DAGSurface* surf_xed); #endif diff --git a/include/openmc/dagmc.h b/include/openmc/dagmc.h index 9f409d873..81aa163dc 100644 --- a/include/openmc/dagmc.h +++ b/include/openmc/dagmc.h @@ -15,7 +15,7 @@ extern "C" const bool DAGMC_ENABLED; namespace openmc { namespace model { - extern moab::DagMC* DAG; + extern std::shared_ptr DAG; } //============================================================================== @@ -23,7 +23,7 @@ namespace model { //============================================================================== void load_dagmc_geometry(); -void free_memory_dagmc(); +void create_dagmc_universe(const std::string& filename); void read_geometry_dagmc(); bool read_uwuw_materials(pugi::xml_document& doc); bool get_uwuw_materials_xml(std::string& s); diff --git a/include/openmc/surface.h b/include/openmc/surface.h index 5a8a88aa4..b729514b9 100644 --- a/include/openmc/surface.h +++ b/include/openmc/surface.h @@ -168,7 +168,7 @@ public: void to_hdf5(hid_t group_id) const; - moab::DagMC* dagmc_ptr_; //!< Pointer to DagMC instance + std::shared_ptr dagmc_ptr_; //!< Pointer to DagMC instance int32_t dag_index_; //!< DagMC index of surface }; #endif diff --git a/src/cell.cpp b/src/cell.cpp index 6b88a6780..733b70f05 100644 --- a/src/cell.cpp +++ b/src/cell.cpp @@ -1013,6 +1013,11 @@ void read_cells(pugi::xml_node node) } } +#ifdef DAGMC + // read any DAGMC universes + read_dagmc_universes(node); +#endif + // Populate the Universe vector and map. for (int i = 0; i < model::cells.size(); i++) { int32_t uid = model::cells[i]->universe_; @@ -1034,6 +1039,17 @@ void read_cells(pugi::xml_node node) } } +void read_dagmc_universes(pugi::xml_node node) { + + // determine the max cell id + int32_t next_cell_id = 0; + for (const auto& c : model::cells) { + if (c->id_ > next_cell_id) next_cell_id = c->id_; + } + next_cell_id++; + +} + //============================================================================== // C-API functions //============================================================================== diff --git a/src/dagmc.cpp b/src/dagmc.cpp index 0c2768834..5b8a61f7e 100644 --- a/src/dagmc.cpp +++ b/src/dagmc.cpp @@ -41,7 +41,7 @@ const std::string DAGMC_FILENAME = "dagmc.h5m"; namespace model { -moab::DagMC* DAG; +std::shared_ptr DAG; } // namespace model @@ -151,14 +151,17 @@ void legacy_assign_material(std::string mat_string, DAGCell* c) void load_dagmc_geometry() { + create_dagmc_universe(dagmc_file()); +} + +void create_dagmc_universe(const std::string& filename) { if (!model::DAG) { - model::DAG = new moab::DagMC(); + model::DAG = std::make_shared(); } // --- Materials --- // create uwuw instance - auto filename = dagmc_file(); UWUW uwuw(filename.c_str()); // check for uwuw material definitions @@ -180,7 +183,7 @@ void load_dagmc_geometry() MB_CHK_ERR_CONT(rval); // parse model metadata - dagmcMetaData DMD(model::DAG, false, false); + dagmcMetaData DMD(model::DAG.get(), false, false); DMD.load_property_data(); vector keywords {"temp"}; @@ -346,11 +349,5 @@ void read_geometry_dagmc() model::root_universe = find_root_universe(); } -void free_memory_dagmc() -{ - delete model::DAG; -} - - } #endif diff --git a/src/finalize.cpp b/src/finalize.cpp index 22dc67183..54a8d681d 100644 --- a/src/finalize.cpp +++ b/src/finalize.cpp @@ -51,9 +51,6 @@ void free_memory() if (settings::event_based) { free_event_queues(); } -#ifdef DAGMC - free_memory_dagmc(); -#endif } }