Change declaration order of maps used for vectors

If the destructor of an object tries to remove an entry from the map, there's no
guarantee it exists if the map has already been destroyed (because it was
declared after the vector of objects), resulting in a segfault. By declaring the
map first, we avoid this. Currently an issue for Nuclide, but potentially other
classes in the future.
This commit is contained in:
Paul Romano 2020-07-29 15:48:14 -05:00
parent 7c1371088d
commit 6992e53398
18 changed files with 22 additions and 22 deletions

View file

@ -49,11 +49,11 @@ class Universe;
class UniversePartitioner;
namespace model {
extern std::vector<std::unique_ptr<Cell>> cells;
extern std::unordered_map<int32_t, int32_t> cell_map;
extern std::vector<std::unique_ptr<Cell>> cells;
extern std::vector<std::unique_ptr<Universe>> universes;
extern std::unordered_map<int32_t, int32_t> universe_map;
extern std::vector<std::unique_ptr<Universe>> universes;
} // namespace model
//==============================================================================

View file

@ -43,12 +43,12 @@ using LibraryKey = std::pair<Library::Type, std::string>;
namespace data {
//!< Data libraries
extern std::vector<Library> libraries;
//! Maps (type, name) to index in libraries
extern std::map<LibraryKey, std::size_t> library_map;
//!< Data libraries
extern std::vector<Library> libraries;
} // namespace data
//==============================================================================

View file

@ -35,8 +35,8 @@ enum class LatticeType {
class Lattice;
namespace model {
extern std::vector<std::unique_ptr<Lattice>> lattices;
extern std::unordered_map<int32_t, int32_t> lattice_map;
extern std::vector<std::unique_ptr<Lattice>> lattices;
} // namespace model
//==============================================================================

View file

@ -32,8 +32,8 @@ class Mesh;
namespace model {
extern std::vector<std::unique_ptr<Mesh>> meshes;
extern std::unordered_map<int32_t, int32_t> mesh_map;
extern std::vector<std::unique_ptr<Mesh>> meshes;
} // namespace model

View file

@ -138,8 +138,8 @@ extern double temperature_min;
//! Maximum temperature in [K] that nuclide data is available at
extern double temperature_max;
extern std::vector<std::unique_ptr<Nuclide>> nuclides;
extern std::unordered_map<std::string, int> nuclide_map;
extern std::vector<std::unique_ptr<Nuclide>> nuclides;
} // namespace data

View file

@ -27,8 +27,8 @@ class Plot;
namespace model {
extern std::vector<Plot> plots; //!< Plot instance container
extern std::unordered_map<int, int> plot_map; //!< map of plot ids to index
extern std::vector<Plot> plots; //!< Plot instance container
extern uint64_t plotter_prn_seeds[N_STREAMS]; // Random number seeds used for plotter
extern int plotter_stream; // Stream index used by the plotter

View file

@ -24,8 +24,8 @@ namespace openmc {
class Surface;
namespace model {
extern std::vector<std::unique_ptr<Surface>> surfaces;
extern std::unordered_map<int, int> surface_map;
extern std::vector<std::unique_ptr<Surface>> surfaces;
} // namespace model
//==============================================================================

View file

@ -70,8 +70,8 @@ void score_track_derivative(Particle& p, double distance);
namespace openmc {
namespace model {
extern std::vector<TallyDerivative> tally_derivs;
extern std::unordered_map<int, int> tally_deriv_map;
extern std::vector<TallyDerivative> tally_derivs;
} // namespace model
} // namespace openmc

View file

@ -23,8 +23,8 @@ namespace openmc {
class ThermalScattering;
namespace data {
extern std::vector<std::unique_ptr<ThermalScattering>> thermal_scatt;
extern std::unordered_map<std::string, int> thermal_scatt_map;
extern std::vector<std::unique_ptr<ThermalScattering>> thermal_scatt;
}
//==============================================================================

View file

@ -32,11 +32,11 @@ namespace openmc {
//==============================================================================
namespace model {
std::vector<std::unique_ptr<Cell>> cells;
std::unordered_map<int32_t, int32_t> cell_map;
std::vector<std::unique_ptr<Cell>> cells;
std::vector<std::unique_ptr<Universe>> universes;
std::unordered_map<int32_t, int32_t> universe_map;
std::vector<std::unique_ptr<Universe>> universes;
} // namespace model
//==============================================================================

View file

@ -34,8 +34,8 @@ namespace openmc {
namespace data {
std::vector<Library> libraries;
std::map<LibraryKey, std::size_t> library_map;
std::vector<Library> libraries;
}

View file

@ -22,8 +22,8 @@ namespace openmc {
//==============================================================================
namespace model {
std::vector<std::unique_ptr<Lattice>> lattices;
std::unordered_map<int32_t, int32_t> lattice_map;
std::vector<std::unique_ptr<Lattice>> lattices;
}
//==============================================================================

View file

@ -35,8 +35,8 @@ namespace openmc {
namespace model {
std::vector<std::unique_ptr<Mesh>> meshes;
std::unordered_map<int32_t, int32_t> mesh_map;
std::vector<std::unique_ptr<Mesh>> meshes;
} // namespace model

View file

@ -32,8 +32,8 @@ std::array<double, 2> energy_min {0.0, 0.0};
std::array<double, 2> energy_max {INFTY, INFTY};
double temperature_min {0.0};
double temperature_max {INFTY};
std::vector<std::unique_ptr<Nuclide>> nuclides;
std::unordered_map<std::string, int> nuclide_map;
std::vector<std::unique_ptr<Nuclide>> nuclides;
} // namespace data
//==============================================================================

View file

@ -80,8 +80,8 @@ void PropertyData::set_overlap(size_t y, size_t x) {
namespace model {
std::vector<Plot> plots;
std::unordered_map<int, int> plot_map;
std::vector<Plot> plots;
uint64_t plotter_seed = 1;
} // namespace model

View file

@ -23,8 +23,8 @@ namespace openmc {
//==============================================================================
namespace model {
std::vector<std::unique_ptr<Surface>> surfaces;
std::unordered_map<int, int> surface_map;
std::vector<std::unique_ptr<Surface>> surfaces;
} // namespace model
//==============================================================================

View file

@ -18,8 +18,8 @@ namespace openmc {
//==============================================================================
namespace model {
std::vector<TallyDerivative> tally_derivs;
std::unordered_map<int, int> tally_deriv_map;
std::vector<TallyDerivative> tally_derivs;
}
//==============================================================================

View file

@ -27,8 +27,8 @@ namespace openmc {
//==============================================================================
namespace data {
std::vector<std::unique_ptr<ThermalScattering>> thermal_scatt;
std::unordered_map<std::string, int> thermal_scatt_map;
std::vector<std::unique_ptr<ThermalScattering>> thermal_scatt;
}
//==============================================================================