From 1a35632fe3803ba4d286f62a8caf06a53c6212d4 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Tue, 21 Jan 2020 07:34:10 -0600 Subject: [PATCH 1/2] Ensure Material, Filter, and Tally destructors don't segfault Because these destructors call erase() on the corresponding maps, they expect that the maps still exist. However, based on the current order of declaration, there is no guarantee that they exist because the maps will be deleted first. --- include/openmc/material.h | 2 +- include/openmc/tallies/filter.h | 2 +- include/openmc/tallies/tally.h | 3 +-- src/material.cpp | 2 +- src/tallies/filter.cpp | 2 +- src/tallies/tally.cpp | 2 +- 6 files changed, 6 insertions(+), 7 deletions(-) diff --git a/include/openmc/material.h b/include/openmc/material.h index 7ce845fc0b..93a90d9e4e 100644 --- a/include/openmc/material.h +++ b/include/openmc/material.h @@ -25,8 +25,8 @@ class Material; namespace model { -extern std::vector> materials; extern std::unordered_map material_map; +extern std::vector> materials; } // namespace model diff --git a/include/openmc/tallies/filter.h b/include/openmc/tallies/filter.h index 58246c80be..143bff3d6b 100644 --- a/include/openmc/tallies/filter.h +++ b/include/openmc/tallies/filter.h @@ -108,8 +108,8 @@ private: namespace model { extern "C" int32_t n_filters; - extern std::vector> tally_filters; extern std::unordered_map filter_map; + extern std::vector> tally_filters; } //============================================================================== diff --git a/include/openmc/tallies/tally.h b/include/openmc/tallies/tally.h index 05db26cea2..6302dd5710 100644 --- a/include/openmc/tallies/tally.h +++ b/include/openmc/tallies/tally.h @@ -141,6 +141,7 @@ private: //============================================================================== namespace model { + extern std::unordered_map tally_map; extern std::vector> tallies; extern std::vector active_tallies; extern std::vector active_analog_tallies; @@ -148,8 +149,6 @@ namespace model { extern std::vector active_collision_tallies; extern std::vector active_meshsurf_tallies; extern std::vector active_surface_tallies; - - extern std::unordered_map tally_map; } namespace simulation { diff --git a/src/material.cpp b/src/material.cpp index 38eef82a7f..42696b0820 100644 --- a/src/material.cpp +++ b/src/material.cpp @@ -37,8 +37,8 @@ namespace openmc { namespace model { -std::vector> materials; std::unordered_map material_map; +std::vector> materials; } // namespace model diff --git a/src/tallies/filter.cpp b/src/tallies/filter.cpp index 6e416dd8d7..689abde605 100644 --- a/src/tallies/filter.cpp +++ b/src/tallies/filter.cpp @@ -40,8 +40,8 @@ namespace openmc { //============================================================================== namespace model { - std::vector> tally_filters; std::unordered_map filter_map; + std::vector> tally_filters; } //============================================================================== diff --git a/src/tallies/tally.cpp b/src/tallies/tally.cpp index 134248d699..28acd9e184 100644 --- a/src/tallies/tally.cpp +++ b/src/tallies/tally.cpp @@ -45,6 +45,7 @@ namespace openmc { //============================================================================== namespace model { + std::unordered_map tally_map; std::vector> tallies; std::vector active_tallies; std::vector active_analog_tallies; @@ -52,7 +53,6 @@ namespace model { std::vector active_collision_tallies; std::vector active_meshsurf_tallies; std::vector active_surface_tallies; - std::unordered_map tally_map; } namespace simulation { From 21dd56a343ada532a0d9f7c937b41761300d4086 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Tue, 21 Jan 2020 07:38:04 -0600 Subject: [PATCH 2/2] Fix comment in tally.h regarding order of axes for results_ --- include/openmc/tallies/tally.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/openmc/tallies/tally.h b/include/openmc/tallies/tally.h index 6302dd5710..f39673c1fd 100644 --- a/include/openmc/tallies/tally.h +++ b/include/openmc/tallies/tally.h @@ -98,10 +98,10 @@ public: //! True if this tally has a bin for every nuclide in the problem bool all_nuclides_ {false}; - //! Results for each bin -- the first dimension of the array is for scores - //! (e.g. flux, total reaction rate, fission reaction rate, etc.) and the - //! second dimension of the array is for the combination of filters - //! (e.g. specific cell, specific energy group, etc.) + //! Results for each bin -- the first dimension of the array is for the + //! combination of filters (e.g. specific cell, specific energy group, etc.) + //! and the second dimension of the array is for scores (e.g. flux, total + //! reaction rate, fission reaction rate, etc.) xt::xtensor results_; //! True if this tally should be written to statepoint files