diff --git a/include/openmc/geometry_aux.h b/include/openmc/geometry_aux.h index ffcdcf885f..557d82193f 100644 --- a/include/openmc/geometry_aux.h +++ b/include/openmc/geometry_aux.h @@ -7,8 +7,78 @@ #include #include #include +#include namespace openmc { + struct CellCountStorage { + private: + CellCountStorage() {} + CellCountStorage(CellCountStorage& c) {} + CellCountStorage(const CellCountStorage& c) {} + + static CellCountStorage* instance_; + + std::map> counts; + + public: + + static CellCountStorage* instance() { + if (instance_ == nullptr) + instance_ = new CellCountStorage; + + return instance_; + } + + + + void clear(); + + void set_cell_count_for_univ(int32_t univ, int32_t cell, int count); + + void increment_count_for_univ(int32_t univ, int32_t cell); + + bool has_count(int32_t univ, int32_t cell); + + bool has_count(int32_t univ); + + void absorb_b_into_a(int32_t a, int32_t b); + + auto get_count(int32_t univ); + }; + + struct LevelCountStorage { + private: + LevelCountStorage() {} + LevelCountStorage(LevelCountStorage& c) {} + LevelCountStorage(const LevelCountStorage& c) {} + + static LevelCountStorage* instance_; + + std::map counts; + + public: + + static LevelCountStorage* instance() { + if (instance_ == nullptr) + instance_ = new LevelCountStorage; + + return instance_; + } + + void clear(); + + void set_cell_count_for_univ(int32_t univ, int count); + + void increment_count_for_univ(int32_t univ); + + bool has_count(int32_t univ); + + void absorb_b_into_a(int32_t a, int32_t b); + + void set_count(int32_t univ, int count); + + int get_count(int32_t univ); + }; void read_geometry_xml(); diff --git a/src/finalize.cpp b/src/finalize.cpp index 3de20d6d09..f2cbc973c2 100644 --- a/src/finalize.cpp +++ b/src/finalize.cpp @@ -135,6 +135,10 @@ int openmc_finalize() int openmc_reset() { + + CellCountStorage::instance()->clear(); + LevelCountStorage::instance()->clear(); + for (auto& t : model::tallies) { t->reset(); } diff --git a/src/geometry_aux.cpp b/src/geometry_aux.cpp index 00b54ad91a..5228bddc1e 100644 --- a/src/geometry_aux.cpp +++ b/src/geometry_aux.cpp @@ -85,106 +85,86 @@ void read_geometry_xml() instance_ = nullptr; } } + } - void set_cell_count_for_univ(int32_t univ, int32_t cell, int count) { - counts[univ][cell] = count; + void CellCountStorage::set_cell_count_for_univ(int32_t univ, int32_t cell, int count) { + counts[univ][cell] = count; + } + + void CellCountStorage::increment_count_for_univ(int32_t univ, int32_t cell) { + if (has_count(univ,cell)) { + counts[univ][cell] += 1; + } else { + counts[univ][cell] = 1; } + } - void increment_count_for_univ(int32_t univ, int32_t cell) { - if (has_count(univ,cell)) { - counts[univ][cell] += 1; + bool CellCountStorage::has_count(int32_t univ, int32_t cell) { + return counts.count(univ) && counts[univ].count(cell); + } + + bool CellCountStorage::has_count(int32_t univ) { + return counts.count(univ); + } + + void CellCountStorage::absorb_b_into_a(int32_t a, int32_t b) { + std::map b_map = counts[b]; + + for (auto it : b_map) { + if (has_count(a, it.first)) { + counts[a][it.first] += it.second; } else { - counts[univ][cell] = 1; + counts[a][it.first] = it.second; } } + } - bool has_count(int32_t univ, int32_t cell) { - return counts.count(univ) && counts[univ].count(cell); + auto CellCountStorage::get_count(int32_t univ) { + return counts[univ]; + } + + void LevelCountStorage::clear() { + if (instance_ != nullptr) { + delete instance_; + instance_ = nullptr; } + } - bool has_count(int32_t univ) { - return counts.count(univ); + void LevelCountStorage::set_cell_count_for_univ(int32_t univ, int count) { + counts[univ] = count; + } + + void LevelCountStorage::increment_count_for_univ(int32_t univ) { + if (has_count(univ)) { + counts[univ] += 1; + } else { + counts[univ] = 1; } + } - void absorb_b_into_a(int32_t a, int32_t b) { - std::map b_map = counts[b]; + bool LevelCountStorage::has_count(int32_t univ) { + return counts.count(univ); + } - for (auto it : b_map) { - if (has_count(a, it.first)) { - counts[a][it.first] += it.second; - } else { - counts[a][it.first] = it.second; - } - } + void LevelCountStorage::absorb_b_into_a(int32_t a, int32_t b) { + + if (has_count(a)) { + counts[a] += counts[b]; + } else { + counts[a] = counts[b]; } + } - std::map get_count(int32_t univ) { - return counts[univ]; - } - }; + void LevelCountStorage::set_count(int32_t univ, int count) { + counts[univ] = count; + } - struct LevelCountStorage { - private: - LevelCountStorage() {} - LevelCountStorage(LevelCountStorage& c) {} - LevelCountStorage(const LevelCountStorage& c) {} + int LevelCountStorage::get_count(int32_t univ) { + return counts[univ]; + } - static LevelCountStorage* instance_; - - std::map counts; - - public: - - static LevelCountStorage* instance() { - if (instance_ == nullptr) - instance_ = new LevelCountStorage; - - return instance_; - } - - void clear() { - if (instance_ != nullptr) { - delete instance_; - instance_ = nullptr; - } - } - - void set_cell_count_for_univ(int32_t univ, int count) { - counts[univ] = count; - } - - void increment_count_for_univ(int32_t univ) { - if (has_count(univ)) { - counts[univ] += 1; - } else { - counts[univ] = 1; - } - } - - bool has_count(int32_t univ) { - return counts.count(univ); - } - - void absorb_b_into_a(int32_t a, int32_t b) { - - if (has_count(a)) { - counts[a] += counts[b]; - } else { - counts[a] = counts[b]; - } - } - - void set_count(int32_t univ, int count) { - counts[univ] = count; - } - - int get_count(int32_t univ) { - return counts[univ]; - } - }; - -CellCountStorage* CellCountStorage::instance_ = nullptr; -LevelCountStorage* LevelCountStorage::instance_ = nullptr; + CellCountStorage* CellCountStorage::instance_ = nullptr; + LevelCountStorage* LevelCountStorage::instance_ = nullptr; //==============================================================================