diff --git a/.github/workflows/name: dockerhub-publish-develop-dagmc.yml b/.github/workflows/dockerhub-publish-develop-dagmc.yml similarity index 100% rename from .github/workflows/name: dockerhub-publish-develop-dagmc.yml rename to .github/workflows/dockerhub-publish-develop-dagmc.yml diff --git a/CMakeLists.txt b/CMakeLists.txt index 3ab04837e..79ed7a0a5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -295,6 +295,7 @@ list(APPEND libopenmc_SOURCES src/nuclide.cpp src/output.cpp src/particle.cpp + src/particle_data.cpp src/particle_restart.cpp src/photon.cpp src/physics.cpp diff --git a/docs/source/usersguide/settings.rst b/docs/source/usersguide/settings.rst index 39a011ec7..95b7fdf45 100644 --- a/docs/source/usersguide/settings.rst +++ b/docs/source/usersguide/settings.rst @@ -295,11 +295,11 @@ below. class CustomSource : public openmc::Source { - openmc::Particle::Bank sample(uint64_t* seed) const + openmc::SourceSite sample(uint64_t* seed) const { - openmc::Particle::Bank particle; + openmc::SourceSite particle; // weight - particle.particle = openmc::Particle::Type::neutron; + particle.particle = openmc::ParticleType::neutron; particle.wgt = 1.0; // position double angle = 2.0 * M_PI * openmc::prn(seed); @@ -370,11 +370,11 @@ the source class when it is created: CustomSource(double energy) : energy_{energy} { } // Samples from an instance of this class. - openmc::Particle::Bank sample(uint64_t* seed) const + openmc::SourceSite sample(uint64_t* seed) const { - openmc::Particle::Bank particle; + openmc::SourceSite particle; // weight - particle.particle = openmc::Particle::Type::neutron; + particle.particle = openmc::ParticleType::neutron; particle.wgt = 1.0; // position particle.r.x = 0.0; diff --git a/examples/custom_source/source_ring.cpp b/examples/custom_source/source_ring.cpp index a752216dc..4b90f801a 100644 --- a/examples/custom_source/source_ring.cpp +++ b/examples/custom_source/source_ring.cpp @@ -7,11 +7,11 @@ class RingSource : public openmc::Source { - openmc::Particle::Bank sample(uint64_t* seed) const + openmc::SourceSite sample(uint64_t* seed) const { - openmc::Particle::Bank particle; + openmc::SourceSite particle; // wgt - particle.particle = openmc::Particle::Type::neutron; + particle.particle = openmc::ParticleType::neutron; particle.wgt = 1.0; // position double angle = 2.0 * M_PI * openmc::prn(seed); diff --git a/examples/parameterized_custom_source/parameterized_source_ring.cpp b/examples/parameterized_custom_source/parameterized_source_ring.cpp index 9f913dfee..a334666ed 100644 --- a/examples/parameterized_custom_source/parameterized_source_ring.cpp +++ b/examples/parameterized_custom_source/parameterized_source_ring.cpp @@ -31,11 +31,11 @@ class RingSource : public openmc::Source { } // Samples from an instance of this class. - openmc::Particle::Bank sample(uint64_t* seed) const + openmc::SourceSite sample(uint64_t* seed) const { - openmc::Particle::Bank particle; + openmc::SourceSite particle; // wgt - particle.particle = openmc::Particle::Type::neutron; + particle.particle = openmc::ParticleType::neutron; particle.wgt = 1.0; // position double angle = 2.0 * M_PI * openmc::prn(seed); diff --git a/include/openmc/array.h b/include/openmc/array.h new file mode 100644 index 000000000..f8e49ccfd --- /dev/null +++ b/include/openmc/array.h @@ -0,0 +1,18 @@ +#ifndef OPENMC_ARRAY_H +#define OPENMC_ARRAY_H + +/* + * See notes in include/openmc/vector.h + * + * In an implementation of OpenMC that uses an accelerator, we may remove the + * use of array below and replace it with a custom + * implementation behaving as expected on the device. + */ + +#include + +namespace openmc { +using std::array; +} // namespace openmc + +#endif // OPENMC_ARRAY_H diff --git a/include/openmc/bank.h b/include/openmc/bank.h index 4f6f95c19..95386514d 100644 --- a/include/openmc/bank.h +++ b/include/openmc/bank.h @@ -2,11 +2,11 @@ #define OPENMC_BANK_H #include -#include -#include "openmc/shared_array.h" #include "openmc/particle.h" #include "openmc/position.h" +#include "openmc/shared_array.h" +#include "openmc/vector.h" namespace openmc { @@ -16,13 +16,13 @@ namespace openmc { namespace simulation { -extern std::vector source_bank; +extern vector source_bank; -extern SharedArray surf_source_bank; +extern SharedArray surf_source_bank; -extern SharedArray fission_bank; +extern SharedArray fission_bank; -extern std::vector progeny_per_particle; +extern vector progeny_per_particle; } // namespace simulation diff --git a/include/openmc/cell.h b/include/openmc/cell.h index 5cd819c26..c7ba0ab13 100644 --- a/include/openmc/cell.h +++ b/include/openmc/cell.h @@ -4,10 +4,8 @@ #include #include // for hash #include -#include // for unique_ptr #include #include -#include #include #include "hdf5.h" @@ -15,9 +13,11 @@ #include "dagmc.h" #include "openmc/constants.h" +#include "openmc/memory.h" // for unique_ptr #include "openmc/neighbor_list.h" #include "openmc/position.h" #include "openmc/surface.h" +#include "openmc/vector.h" namespace openmc { @@ -50,10 +50,10 @@ class UniversePartitioner; namespace model { extern std::unordered_map cell_map; - extern std::vector> cells; + extern vector> cells; extern std::unordered_map universe_map; - extern std::vector> universes; + extern vector> universes; } // namespace model //============================================================================== @@ -64,7 +64,7 @@ class Universe { public: int32_t id_; //!< Unique ID - std::vector cells_; //!< Cells within this universe + vector cells_; //!< Cells within this universe //! \brief Write universe information to an HDF5 group. //! \param group_id An HDF5 group id. @@ -72,7 +72,7 @@ public: BoundingBox bounding_box() const; - std::unique_ptr partitioner_; + unique_ptr partitioner_; }; //============================================================================== @@ -151,13 +151,12 @@ public: //! Get all cell instances contained by this cell //! \return Map with cell indexes as keys and instances as values - std::unordered_map> - get_contained_cells() const; + std::unordered_map> get_contained_cells() const; protected: - void - get_contained_cells_inner(std::unordered_map>& contained_cells, - std::vector& parent_cells) const; + void get_contained_cells_inner( + std::unordered_map>& contained_cells, + vector& parent_cells) const; public: //---------------------------------------------------------------------------- @@ -176,18 +175,18 @@ public: //! \brief Material(s) within this cell. //! //! May be multiple materials for distribcell. - std::vector material_; + vector material_; //! \brief Temperature(s) within this cell. //! //! The stored values are actually sqrt(k_Boltzmann * T) for each temperature //! T. The units are sqrt(eV). - std::vector sqrtkT_; + vector sqrtkT_; //! Definition of spatial region as Boolean expression of half-spaces - std::vector region_; + vector region_; //! Reverse Polish notation for region expression - std::vector rpn_; + vector rpn_; bool simple_; //!< Does the region contain only intersections? //! \brief Neighboring cells in the same universe. @@ -201,9 +200,9 @@ public: //! give the rotation matrix in row-major order. When the user specifies //! rotation angles about the x-, y- and z- axes in degrees, these values are //! also present at the end of the vector, making it of length 12. - std::vector rotation_; + vector rotation_; - std::vector offset_; //!< Distribcell offset table + vector offset_; //!< Distribcell offset table }; struct CellInstanceItem { @@ -234,27 +233,25 @@ protected: bool contains_simple(Position r, Direction u, int32_t on_surface) const; bool contains_complex(Position r, Direction u, int32_t on_surface) const; BoundingBox bounding_box_simple() const; - static BoundingBox bounding_box_complex(std::vector rpn); + static BoundingBox bounding_box_complex(vector rpn); //! Applies DeMorgan's laws to a section of the RPN //! \param start Starting point for token modification //! \param stop Stopping point for token modification - static void apply_demorgan(std::vector::iterator start, - std::vector::iterator stop); + static void apply_demorgan( + vector::iterator start, vector::iterator stop); //! Removes complement operators from the RPN //! \param rpn The rpn to remove complement operators from. - static void remove_complement_ops(std::vector& rpn); + static void remove_complement_ops(vector& rpn); //! Returns the beginning position of a parenthesis block (immediately before //! two surface tokens) in the RPN given a starting position at the end of //! that block (immediately after two surface tokens) //! \param start Starting position of the search //! \param rpn The rpn being searched - static std::vector::iterator - find_left_parenthesis(std::vector::iterator start, - const std::vector& rpn); - + static vector::iterator find_left_parenthesis( + vector::iterator start, const vector& rpn); }; //============================================================================== @@ -293,11 +290,11 @@ public: explicit UniversePartitioner(const Universe& univ); //! Return the list of cells that could contain the given coordinates. - const std::vector& get_cells(Position r, Direction u) const; + const vector& get_cells(Position r, Direction u) const; private: //! A sorted vector of indices to surfaces that partition the universe - std::vector surfs_; + vector surfs_; //! Vectors listing the indices of the cells that lie within each partition // @@ -306,7 +303,7 @@ private: //! `partitions_.back()` gives the cells that lie on the positive side of //! `surfs_.back()`. Otherwise, `partitions_[i]` gives cells sandwiched //! between `surfs_[i-1]` and `surfs_[i]`. - std::vector> partitions_; + vector> partitions_; }; diff --git a/include/openmc/constants.h b/include/openmc/constants.h index 49acf1d57..aac3a52a8 100644 --- a/include/openmc/constants.h +++ b/include/openmc/constants.h @@ -4,18 +4,18 @@ #ifndef OPENMC_CONSTANTS_H #define OPENMC_CONSTANTS_H -#include #include #include -#include +#include "openmc/array.h" +#include "openmc/vector.h" #include "openmc/version.h" namespace openmc { -using double_2dvec = std::vector>; -using double_3dvec = std::vector>>; -using double_4dvec = std::vector>>>; +using double_2dvec = vector>; +using double_3dvec = vector>>; +using double_4dvec = vector>>>; // ============================================================================ // VERSIONING NUMBERS @@ -24,13 +24,13 @@ using double_4dvec = std::vector>>>; constexpr int HDF5_VERSION[] {3, 0}; // Version numbers for binary files -constexpr std::array VERSION_STATEPOINT {17, 0}; -constexpr std::array VERSION_PARTICLE_RESTART {2, 0}; -constexpr std::array VERSION_TRACK {2, 0}; -constexpr std::array VERSION_SUMMARY {6, 0}; -constexpr std::array VERSION_VOLUME {1, 0}; -constexpr std::array VERSION_VOXEL {2, 0}; -constexpr std::array VERSION_MGXS_LIBRARY {1, 0}; +constexpr array VERSION_STATEPOINT {17, 0}; +constexpr array VERSION_PARTICLE_RESTART {2, 0}; +constexpr array VERSION_TRACK {2, 0}; +constexpr array VERSION_SUMMARY {6, 0}; +constexpr array VERSION_VOLUME {1, 0}; +constexpr array VERSION_VOXEL {2, 0}; +constexpr array VERSION_MGXS_LIBRARY {1, 0}; // ============================================================================ // ADJUSTABLE PARAMETERS @@ -90,13 +90,10 @@ constexpr double N_AVOGADRO {0.602214076}; // Avogadro's number in 10^24/m constexpr double K_BOLTZMANN {8.617333262e-5}; // Boltzmann constant in eV/K // Electron subshell labels -constexpr std::array SUBSHELLS = { - "K", "L1", "L2", "L3", "M1", "M2", "M3", "M4", "M5", - "N1", "N2", "N3", "N4", "N5", "N6", "N7", "O1", "O2", - "O3", "O4", "O5", "O6", "O7", "O8", "O9", "P1", "P2", - "P3", "P4", "P5", "P6", "P7", "P8", "P9", "P10", "P11", - "Q1", "Q2", "Q3" -}; +constexpr array SUBSHELLS = {"K", "L1", "L2", "L3", "M1", "M2", + "M3", "M4", "M5", "N1", "N2", "N3", "N4", "N5", "N6", "N7", "O1", "O2", "O3", + "O4", "O5", "O6", "O7", "O8", "O9", "P1", "P2", "P3", "P4", "P5", "P6", "P7", + "P8", "P9", "P10", "P11", "Q1", "Q2", "Q3"}; // Void material and nuclide // TODO: refactor and remove @@ -241,7 +238,7 @@ enum ReactionType { HEATING_LOCAL = 901 }; -constexpr std::array DEPLETION_RX {N_GAMMA, N_P, N_A, N_2N, N_3N, N_4N}; +constexpr array DEPLETION_RX {N_GAMMA, N_P, N_A, N_2N, N_3N, N_4N}; enum class URRTableParam { CUM_PROB, diff --git a/include/openmc/cross_sections.h b/include/openmc/cross_sections.h index aa1ba3661..8a78a4099 100644 --- a/include/openmc/cross_sections.h +++ b/include/openmc/cross_sections.h @@ -5,7 +5,8 @@ #include #include -#include + +#include "openmc/vector.h" namespace openmc { @@ -31,7 +32,7 @@ public: // Data members Type type_; //!< Type of data library - std::vector materials_; //!< Materials contained in library + vector materials_; //!< Materials contained in library std::string path_; //!< File path to library }; @@ -47,7 +48,7 @@ namespace data { extern std::map library_map; //!< Data libraries -extern std::vector libraries; +extern vector libraries; } // namespace data @@ -64,8 +65,8 @@ void read_cross_sections_xml(); // //! \param[in] nuc_temps Temperatures for each nuclide in [K] //! \param[in] thermal_temps Temperatures for each thermal scattering table in [K] -void read_ce_cross_sections(const std::vector>& nuc_temps, - const std::vector>& thermal_temps); +void read_ce_cross_sections(const vector>& nuc_temps, + const vector>& thermal_temps); //! Read cross_sections.xml and populate data libraries void read_ce_cross_sections_xml(); diff --git a/include/openmc/distribution.h b/include/openmc/distribution.h index 026b3d723..888fab7d8 100644 --- a/include/openmc/distribution.h +++ b/include/openmc/distribution.h @@ -5,12 +5,12 @@ #define OPENMC_DISTRIBUTION_H #include // for size_t -#include // for unique_ptr -#include // for vector #include "pugixml.hpp" #include "openmc/constants.h" +#include "openmc/memory.h" // for unique_ptr +#include "openmc/vector.h" // for vector namespace openmc { @@ -39,11 +39,12 @@ public: double sample(uint64_t* seed) const; // Properties - const std::vector& x() const { return x_; } - const std::vector& p() const { return p_; } + const vector& x() const { return x_; } + const vector& p() const { return p_; } + private: - std::vector x_; //!< Possible outcomes - std::vector p_; //!< Probability of each outcome + vector x_; //!< Possible outcomes + vector p_; //!< Probability of each outcome //! Normalize distribution so that probabilities sum to unity void normalize(); @@ -174,14 +175,14 @@ public: double sample(uint64_t* seed) const; // x property - std::vector& x() { return x_; } - const std::vector& x() const { return x_; } - const std::vector& p() const { return p_; } + vector& x() { return x_; } + const vector& x() const { return x_; } + const vector& p() const { return p_; } Interpolation interp() const { return interp_; } private: - std::vector x_; //!< tabulated independent variable - std::vector p_; //!< tabulated probability density - std::vector c_; //!< cumulative distribution at tabulated values + vector x_; //!< tabulated independent variable + vector p_; //!< tabulated probability density + vector c_; //!< cumulative distribution at tabulated values Interpolation interp_; //!< interpolation rule //! Initialize tabulated probability density function @@ -206,13 +207,13 @@ public: //! \return Sampled value double sample(uint64_t* seed) const; - const std::vector& x() const { return x_; } + const vector& x() const { return x_; } + private: - std::vector x_; //! Possible outcomes + vector x_; //! Possible outcomes }; - -using UPtrDist = std::unique_ptr; +using UPtrDist = unique_ptr; //! Return univariate probability distribution specified in XML file //! \param[in] node XML node representing distribution diff --git a/include/openmc/distribution_angle.h b/include/openmc/distribution_angle.h index b5b663caf..efd4e5842 100644 --- a/include/openmc/distribution_angle.h +++ b/include/openmc/distribution_angle.h @@ -4,11 +4,10 @@ #ifndef OPENMC_DISTRIBUTION_ANGLE_H #define OPENMC_DISTRIBUTION_ANGLE_H -#include // for vector - #include "hdf5.h" #include "openmc/distribution.h" +#include "openmc/vector.h" namespace openmc { @@ -32,8 +31,8 @@ public: bool empty() const { return energy_.empty(); } private: - std::vector energy_; - std::vector> distribution_; + vector energy_; + vector> distribution_; }; } // namespace openmc diff --git a/include/openmc/distribution_energy.h b/include/openmc/distribution_energy.h index 7b739ba94..9c7438f33 100644 --- a/include/openmc/distribution_energy.h +++ b/include/openmc/distribution_energy.h @@ -4,13 +4,12 @@ #ifndef OPENMC_DISTRIBUTION_ENERGY_H #define OPENMC_DISTRIBUTION_ENERGY_H -#include - #include "xtensor/xtensor.hpp" #include "hdf5.h" #include "openmc/constants.h" #include "openmc/endf.h" +#include "openmc/vector.h" namespace openmc { @@ -90,10 +89,10 @@ private: }; int n_region_; //!< Number of inteprolation regions - std::vector breakpoints_; //!< Breakpoints between regions - std::vector interpolation_; //!< Interpolation laws - std::vector energy_; //!< Incident energy in [eV] - std::vector distribution_; //!< Distributions for each incident energy + vector breakpoints_; //!< Breakpoints between regions + vector interpolation_; //!< Interpolation laws + vector energy_; //!< Incident energy in [eV] + vector distribution_; //!< Distributions for each incident energy }; //=============================================================================== diff --git a/include/openmc/distribution_multi.h b/include/openmc/distribution_multi.h index ddefa422c..793e8f719 100644 --- a/include/openmc/distribution_multi.h +++ b/include/openmc/distribution_multi.h @@ -1,7 +1,7 @@ #ifndef DISTRIBUTION_MULTI_H #define DISTRIBUTION_MULTI_H -#include +#include "openmc/memory.h" #include "pugixml.hpp" @@ -84,7 +84,7 @@ public: Direction sample(uint64_t* seed) const; }; -using UPtrAngle = std::unique_ptr; +using UPtrAngle = unique_ptr; } // namespace openmc diff --git a/include/openmc/distribution_spatial.h b/include/openmc/distribution_spatial.h index fb0c0fe73..a56ff2dcf 100644 --- a/include/openmc/distribution_spatial.h +++ b/include/openmc/distribution_spatial.h @@ -135,7 +135,7 @@ private: Position r_; //!< Single position at which sites are generated }; -using UPtrSpace = std::unique_ptr; +using UPtrSpace = unique_ptr; } // namespace openmc diff --git a/include/openmc/eigenvalue.h b/include/openmc/eigenvalue.h index 8f430f548..b456fee21 100644 --- a/include/openmc/eigenvalue.h +++ b/include/openmc/eigenvalue.h @@ -4,14 +4,14 @@ #ifndef OPENMC_EIGENVALUE_H #define OPENMC_EIGENVALUE_H -#include #include // for int64_t -#include #include "xtensor/xtensor.hpp" #include +#include "openmc/array.h" #include "openmc/particle.h" +#include "openmc/vector.h" namespace openmc { @@ -22,8 +22,8 @@ namespace openmc { namespace simulation { extern double keff_generation; //!< Single-generation k on each processor -extern std::array k_sum; //!< Used to reduce sum and sum_sq -extern std::vector entropy; //!< Shannon entropy at each generation +extern array k_sum; //!< Used to reduce sum and sum_sq +extern vector entropy; //!< Shannon entropy at each generation extern xt::xtensor source_frac; //!< Source fraction for UFS } // namespace simulation diff --git a/include/openmc/endf.h b/include/openmc/endf.h index 27958db5c..40e1cef83 100644 --- a/include/openmc/endf.h +++ b/include/openmc/endf.h @@ -4,12 +4,11 @@ #ifndef OPENMC_ENDF_H #define OPENMC_ENDF_H -#include -#include - #include "hdf5.h" #include "openmc/constants.h" +#include "openmc/memory.h" +#include "openmc/vector.h" namespace openmc { @@ -59,7 +58,7 @@ public: //! \return Polynomial evaluated at x double operator()(double x) const override; private: - std::vector coef_; //!< Polynomial coefficients + vector coef_; //!< Polynomial coefficients }; //============================================================================== @@ -80,15 +79,16 @@ public: double operator()(double x) const override; // Accessors - const std::vector& x() const { return x_; } - const std::vector& y() const { return y_; } + const vector& x() const { return x_; } + const vector& y() const { return y_; } + private: std::size_t n_regions_ {0}; //!< number of interpolation regions - std::vector nbt_; //!< values separating interpolation regions - std::vector int_; //!< interpolation schemes + vector nbt_; //!< values separating interpolation regions + vector int_; //!< interpolation schemes std::size_t n_pairs_; //!< number of (x,y) pairs - std::vector x_; //!< values of abscissa - std::vector y_; //!< values of ordinate + vector x_; //!< values of abscissa + vector y_; //!< values of ordinate }; //============================================================================== @@ -101,11 +101,12 @@ public: double operator()(double E) const override; - const std::vector& bragg_edges() const { return bragg_edges_; } - const std::vector& factors() const { return factors_; } + const vector& bragg_edges() const { return bragg_edges_; } + const vector& factors() const { return factors_; } + private: - std::vector bragg_edges_; //!< Bragg edges in [eV] - std::vector factors_; //!< Partial sums of structure factors [eV-b] + vector bragg_edges_; //!< Bragg edges in [eV] + vector factors_; //!< Partial sums of structure factors [eV-b] }; //============================================================================== @@ -126,7 +127,7 @@ private: //! \param[in] group HDF5 group containing dataset //! \param[in] name Name of dataset //! \return Unique pointer to 1D function -std::unique_ptr read_function(hid_t group, const char* name); +unique_ptr read_function(hid_t group, const char* name); } // namespace openmc diff --git a/include/openmc/event.h b/include/openmc/event.h index 5b60922a4..981fa9b17 100644 --- a/include/openmc/event.h +++ b/include/openmc/event.h @@ -25,14 +25,15 @@ namespace openmc { // consistent locality improvements. struct EventQueueItem{ int64_t idx; //!< particle index in event-based particle buffer - Particle::Type type; //!< particle type + ParticleType type; //!< particle type int64_t material; //!< material that particle is in double E; //!< particle energy // Constructors EventQueueItem() = default; - EventQueueItem(const Particle& p, int64_t buffer_idx) : - idx(buffer_idx), type(p.type_), material(p.material_), E(p.E_) {} + EventQueueItem(const Particle& p, int64_t buffer_idx) + : idx(buffer_idx), type(p.type()), material(p.material()), E(p.E()) + {} // Compare by particle type, then by material type (4.5% fuel/7.0% fuel/cladding/etc), // then by energy. @@ -64,7 +65,7 @@ extern SharedArray surface_crossing_queue; extern SharedArray collision_queue; // Particle buffer -extern std::vector particles; +extern vector particles; } // namespace simulation diff --git a/include/openmc/geometry.h b/include/openmc/geometry.h index 0681952ad..0ba29ef48 100644 --- a/include/openmc/geometry.h +++ b/include/openmc/geometry.h @@ -1,16 +1,18 @@ #ifndef OPENMC_GEOMETRY_H #define OPENMC_GEOMETRY_H -#include #include #include -#include - -#include "openmc/particle.h" +#include "openmc/array.h" +#include "openmc/constants.h" +#include "openmc/vector.h" namespace openmc { +class BoundaryInfo; +class Particle; + //============================================================================== // Global variables //============================================================================== @@ -20,7 +22,7 @@ namespace model { extern int root_universe; //!< Index of root universe extern "C" int n_coord_levels; //!< Number of CSG coordinate levels -extern std::vector overlap_check_count; +extern vector overlap_check_count; } // namespace model diff --git a/include/openmc/geometry_aux.h b/include/openmc/geometry_aux.h index 43e4e71cd..28b19e315 100644 --- a/include/openmc/geometry_aux.h +++ b/include/openmc/geometry_aux.h @@ -6,9 +6,10 @@ #include #include -#include #include +#include "openmc/vector.h" + namespace openmc { namespace model { @@ -41,8 +42,8 @@ void assign_temperatures(); //! table //============================================================================== -void get_temperatures(std::vector>& nuc_temps, - std::vector>& thermal_temps); +void get_temperatures( + vector>& nuc_temps, vector>& thermal_temps); //============================================================================== //! \brief Perform final setup for geometry diff --git a/include/openmc/hdf5_interface.h b/include/openmc/hdf5_interface.h index 88a73415a..f60167304 100644 --- a/include/openmc/hdf5_interface.h +++ b/include/openmc/hdf5_interface.h @@ -2,22 +2,22 @@ #define OPENMC_HDF5_INTERFACE_H #include // for min -#include #include #include #include // for strlen #include #include #include -#include #include "hdf5.h" #include "hdf5_hl.h" #include "xtensor/xadapt.hpp" #include "xtensor/xarray.hpp" -#include "openmc/position.h" +#include "openmc/array.h" #include "openmc/error.h" +#include "openmc/position.h" +#include "openmc/vector.h" namespace openmc { @@ -55,11 +55,11 @@ hid_t file_open(const std::string& filename, char mode, bool parallel=false); void write_string(hid_t group_id, const char* name, const std::string& buffer, bool indep); -std::vector attribute_shape(hid_t obj_id, const char* name); -std::vector dataset_names(hid_t group_id); +vector attribute_shape(hid_t obj_id, const char* name); +vector dataset_names(hid_t group_id); void ensure_exists(hid_t obj_id, const char* name, bool attribute=false); -std::vector group_names(hid_t group_id); -std::vector object_shape(hid_t obj_id); +vector group_names(hid_t group_id); +vector object_shape(hid_t obj_id); std::string object_name(hid_t obj_id); //============================================================================== @@ -141,15 +141,15 @@ void read_attribute(hid_t obj_id, const char* name, T& buffer) } // array version -template inline void -read_attribute(hid_t obj_id, const char* name, std::array& buffer) +template +inline void read_attribute(hid_t obj_id, const char* name, array& buffer) { read_attr(obj_id, name, H5TypeMap::type_id, buffer.data()); } // vector version template -void read_attribute(hid_t obj_id, const char* name, std::vector& vec) +void read_attribute(hid_t obj_id, const char* name, vector& vec) { // Get shape of attribute array auto shape = attribute_shape(obj_id, name); @@ -175,7 +175,7 @@ void read_attribute(hid_t obj_id, const char* name, xt::xarray& arr) std::size_t size = 1; for (const auto x : shape) size *= x; - std::vector buffer(size); + vector buffer(size); // Read data from attribute read_attr(obj_id, name, H5TypeMap::type_id, buffer.data()); @@ -198,9 +198,9 @@ read_attribute(hid_t obj_id, const char* name, std::string& str) delete[] buffer; } -// overload for std::vector -inline void -read_attribute(hid_t obj_id, const char* name, std::vector& vec) +// overload for vector +inline void read_attribute( + hid_t obj_id, const char* name, vector& vec) { auto dims = attribute_shape(obj_id, name); auto m = dims[0]; @@ -254,20 +254,20 @@ read_dataset(hid_t obj_id, const char* name, std::string& str, bool indep=false) } // array version -template inline void -read_dataset(hid_t dset, const char* name, std::array& buffer, - bool indep=false) +template +inline void read_dataset( + hid_t dset, const char* name, array& buffer, bool indep = false) { read_dataset_lowlevel(dset, name, H5TypeMap::type_id, H5S_ALL, indep, buffer.data()); } // vector version -template -void read_dataset(hid_t dset, std::vector& vec, bool indep=false) +template +void read_dataset(hid_t dset, vector& vec, bool indep = false) { // Get shape of dataset - std::vector shape = object_shape(dset); + vector shape = object_shape(dset); // Resize vector to appropriate size vec.resize(shape[0]); @@ -277,9 +277,9 @@ void read_dataset(hid_t dset, std::vector& vec, bool indep=false) vec.data()); } -template -void read_dataset(hid_t obj_id, const char* name, std::vector& vec, - bool indep=false) +template +void read_dataset( + hid_t obj_id, const char* name, vector& vec, bool indep = false) { hid_t dset = open_dataset(obj_id, name); read_dataset(dset, vec, indep); @@ -290,7 +290,7 @@ template void read_dataset(hid_t dset, xt::xarray& arr, bool indep=false) { // Get shape of dataset - std::vector shape = object_shape(dset); + vector shape = object_shape(dset); // Allocate space in the array to read data into std::size_t size = 1; @@ -326,11 +326,11 @@ void read_dataset(hid_t obj_id, const char* name, xt::xtensor& arr, hid_t dset = open_dataset(obj_id, name); // Get shape of dataset - std::vector hsize_t_shape = object_shape(dset); + vector hsize_t_shape = object_shape(dset); close_dataset(dset); // cast from hsize_t to size_t - std::vector shape(hsize_t_shape.size()); + vector shape(hsize_t_shape.size()); for (int i = 0; i < shape.size(); i++) { shape[i] = static_cast(hsize_t_shape[i]); } @@ -349,7 +349,7 @@ void read_dataset(hid_t obj_id, const char* name, xt::xtensor& arr, inline void read_dataset(hid_t obj_id, const char* name, Position& r, bool indep=false) { - std::array x; + array x; read_dataset(obj_id, name, x, indep); r.x = x[0]; r.y = x[1]; @@ -366,7 +366,7 @@ inline void read_dataset_as_shape(hid_t obj_id, const char* name, std::size_t size = 1; for (const auto x : arr.shape()) size *= x; - std::vector buffer(size); + vector buffer(size); // Read data from attribute read_dataset_lowlevel(dset, nullptr, H5TypeMap::type_id, H5S_ALL, indep, @@ -412,15 +412,17 @@ write_attribute(hid_t obj_id, const char* name, const std::string& buffer) write_attr_string(obj_id, name, buffer.c_str()); } -template inline void -write_attribute(hid_t obj_id, const char* name, const std::array& buffer) +template +inline void write_attribute( + hid_t obj_id, const char* name, const array& buffer) { hsize_t dims[] {N}; write_attr(obj_id, 1, dims, name, H5TypeMap::type_id, buffer.data()); } -template inline void -write_attribute(hid_t obj_id, const char* name, const std::vector& buffer) +template +inline void write_attribute( + hid_t obj_id, const char* name, const vector& buffer) { hsize_t dims[] {buffer.size()}; write_attr(obj_id, 1, dims, name, H5TypeMap::type_id, buffer.data()); @@ -429,7 +431,7 @@ write_attribute(hid_t obj_id, const char* name, const std::vector& buffer) inline void write_attribute(hid_t obj_id, const char* name, Position r) { - std::array buffer {r.x, r.y, r.z}; + array buffer {r.x, r.y, r.z}; write_attribute(obj_id, name, buffer); } @@ -454,17 +456,17 @@ write_dataset(hid_t obj_id, const char* name, const char* buffer) write_string(obj_id, name, buffer, false); } -template inline void -write_dataset(hid_t obj_id, const char* name, const std::array& buffer) +template +inline void write_dataset( + hid_t obj_id, const char* name, const array& buffer) { hsize_t dims[] {N}; write_dataset_lowlevel(obj_id, 1, dims, name, H5TypeMap::type_id, H5S_ALL, false, buffer.data()); } -inline void -write_dataset(hid_t obj_id, const char* name, - const std::vector& buffer) +inline void write_dataset( + hid_t obj_id, const char* name, const vector& buffer) { auto n {buffer.size()}; hsize_t dims[] {n}; @@ -489,8 +491,9 @@ write_dataset(hid_t obj_id, const char* name, delete[] temp; } -template inline void -write_dataset(hid_t obj_id, const char* name, const std::vector& buffer) +template +inline void write_dataset( + hid_t obj_id, const char* name, const vector& buffer) { hsize_t dims[] {buffer.size()}; write_dataset_lowlevel(obj_id, 1, dims, name, H5TypeMap::type_id, @@ -503,7 +506,7 @@ write_dataset(hid_t obj_id, const char* name, const xt::xcontainer& arr) { using T = typename D::value_type; auto s = arr.shape(); - std::vector dims {s.cbegin(), s.cend()}; + vector dims {s.cbegin(), s.cend()}; write_dataset_lowlevel(obj_id, dims.size(), dims.data(), name, H5TypeMap::type_id, H5S_ALL, false, arr.data()); } @@ -511,7 +514,7 @@ write_dataset(hid_t obj_id, const char* name, const xt::xcontainer& arr) inline void write_dataset(hid_t obj_id, const char* name, Position r) { - std::array buffer {r.x, r.y, r.z}; + array buffer {r.x, r.y, r.z}; write_dataset(obj_id, name, buffer); } diff --git a/include/openmc/lattice.h b/include/openmc/lattice.h index 618859c80..e7db9016b 100644 --- a/include/openmc/lattice.h +++ b/include/openmc/lattice.h @@ -1,19 +1,18 @@ #ifndef OPENMC_LATTICE_H #define OPENMC_LATTICE_H -#include #include -#include // for unique_ptr #include #include -#include #include "hdf5.h" #include "pugixml.hpp" +#include "openmc/array.h" #include "openmc/constants.h" +#include "openmc/memory.h" #include "openmc/position.h" - +#include "openmc/vector.h" namespace openmc { @@ -27,7 +26,6 @@ enum class LatticeType { rect, hex }; - //============================================================================== // Global variables //============================================================================== @@ -36,7 +34,7 @@ class Lattice; namespace model { extern std::unordered_map lattice_map; - extern std::vector> lattices; + extern vector> lattices; } // namespace model //============================================================================== @@ -53,15 +51,15 @@ public: int32_t id_; //!< Universe ID number std::string name_; //!< User-defined name LatticeType type_; - std::vector universes_; //!< Universes filling each lattice tile + vector universes_; //!< Universes filling each lattice tile int32_t outer_ {NO_OUTER_UNIVERSE}; //!< Universe tiled outside the lattice - std::vector offsets_; //!< Distribcell offset table + vector offsets_; //!< Distribcell offset table explicit Lattice(pugi::xml_node lat_node); virtual ~Lattice() {} - virtual int32_t& operator[](std::array i_xyz) = 0; + virtual int32_t const& operator[](array const& i_xyz) = 0; virtual LatticeIter begin(); LatticeIter end(); @@ -84,14 +82,7 @@ public: //! \param i_xyz[3] The indices for a lattice tile. //! \return true if the given indices fit within the lattice bounds. False //! otherwise. - virtual bool are_valid_indices(const int i_xyz[3]) const = 0; - - bool - are_valid_indices(std::array i_xyz) const - { - int i_xyz_[3] {i_xyz[0], i_xyz[1], i_xyz[2]}; - return are_valid_indices(i_xyz_); - } + virtual bool are_valid_indices(array const& i_xyz) const = 0; //! \brief Find the next lattice surface crossing //! \param r A 3D Cartesian coordinate. @@ -99,21 +90,22 @@ public: //! \param i_xyz The indices for a lattice tile. //! \return The distance to the next crossing and an array indicating how the //! lattice indices would change after crossing that boundary. - virtual std::pair> - distance(Position r, Direction u, const std::array& i_xyz) const - = 0; + virtual std::pair> distance( + Position r, Direction u, const array& i_xyz) const = 0; //! \brief Find the lattice tile indices for a given point. //! \param r A 3D Cartesian coordinate. - //! \return An array containing the indices of a lattice tile. - virtual std::array get_indices(Position r, Direction u) const = 0; + //! \param u Direction of a particle + //! \param result resulting indices to save to + virtual void get_indices( + Position r, Direction u, array& result) const = 0; //! \brief Get coordinates local to a lattice tile. //! \param r A 3D Cartesian coordinate. //! \param i_xyz The indices for a lattice tile. //! \return Local 3D Cartesian coordinates. - virtual Position - get_local_position(Position r, const std::array i_xyz) const = 0; + virtual Position get_local_position( + Position r, const array& i_xyz) const = 0; //! \brief Check flattened lattice index. //! \param indx The index for a lattice tile. @@ -127,7 +119,7 @@ public: //! \param i_xyz[3] The indices for a lattice tile. //! \return Distribcell offset i.e. the largest instance number for the target //! cell found in the geometry tree under this lattice tile. - virtual int32_t& offset(int map, const int i_xyz[3]) = 0; + virtual int32_t& offset(int map, array const& i_xyz) = 0; //! \brief Get the distribcell offset for a lattice tile. //! \param The map index for the target cell. @@ -213,19 +205,18 @@ class RectLattice : public Lattice public: explicit RectLattice(pugi::xml_node lat_node); - int32_t& operator[](std::array i_xyz); + int32_t const& operator[](array const& i_xyz); - bool are_valid_indices(const int i_xyz[3]) const; + bool are_valid_indices(array const& i_xyz) const; - std::pair> - distance(Position r, Direction u, const std::array& i_xyz) const; + std::pair> distance( + Position r, Direction u, const array& i_xyz) const; - std::array get_indices(Position r, Direction u) const; + void get_indices(Position r, Direction u, array& result) const; - Position - get_local_position(Position r, const std::array i_xyz) const; + Position get_local_position(Position r, const array& i_xyz) const; - int32_t& offset(int map, const int i_xyz[3]); + int32_t& offset(int map, array const& i_xyz); int32_t offset(int map, int indx) const; @@ -234,14 +225,9 @@ public: void to_hdf5_inner(hid_t group_id) const; private: - std::array n_cells_; //!< Number of cells along each axis + array n_cells_; //!< Number of cells along each axis Position lower_left_; //!< Global lower-left corner of the lattice Position pitch_; //!< Lattice tile width along each axis - - // Convenience aliases - int &nx {n_cells_[0]}; - int &ny {n_cells_[1]}; - int &nz {n_cells_[2]}; }; //============================================================================== @@ -251,25 +237,24 @@ class HexLattice : public Lattice public: explicit HexLattice(pugi::xml_node lat_node); - int32_t& operator[](std::array i_xyz); + int32_t const& operator[](array const& i_xyz); LatticeIter begin(); ReverseLatticeIter rbegin(); - bool are_valid_indices(const int i_xyz[3]) const; + bool are_valid_indices(array const& i_xyz) const; - std::pair> - distance(Position r, Direction u, const std::array& i_xyz) const; + std::pair> distance( + Position r, Direction u, const array& i_xyz) const; - std::array get_indices(Position r, Direction u) const; + void get_indices(Position r, Direction u, array& result) const; - Position - get_local_position(Position r, const std::array i_xyz) const; + Position get_local_position(Position r, const array& i_xyz) const; bool is_valid_index(int indx) const; - int32_t& offset(int map, const int i_xyz[3]); + int32_t& offset(int map, array const& i_xyz); int32_t offset(int map, int indx) const; @@ -284,16 +269,16 @@ private: }; //! Fill universes_ vector for 'y' orientation - void fill_lattice_y(const std::vector& univ_words); + void fill_lattice_y(const vector& univ_words); //! Fill universes_ vector for 'x' orientation - void fill_lattice_x(const std::vector& univ_words); + void fill_lattice_x(const vector& univ_words); int n_rings_; //!< Number of radial tile positions int n_axial_; //!< Number of axial tile positions Orientation orientation_; //!< Orientation of lattice Position center_; //!< Global center of lattice - std::array pitch_; //!< Lattice tile width and height + array pitch_; //!< Lattice tile width and height }; //============================================================================== diff --git a/include/openmc/material.h b/include/openmc/material.h index 9adb9ff97..7e975a1bb 100644 --- a/include/openmc/material.h +++ b/include/openmc/material.h @@ -1,19 +1,19 @@ #ifndef OPENMC_MATERIAL_H #define OPENMC_MATERIAL_H -#include // for unique_ptr #include #include -#include #include #include #include "pugixml.hpp" #include "xtensor/xtensor.hpp" -#include "openmc/constants.h" #include "openmc/bremsstrahlung.h" +#include "openmc/constants.h" +#include "openmc/memory.h" // for unique_ptr #include "openmc/particle.h" +#include "openmc/vector.h" namespace openmc { @@ -26,7 +26,7 @@ class Material; namespace model { extern std::unordered_map material_map; -extern std::vector> materials; +extern vector> materials; } // namespace model @@ -79,8 +79,8 @@ public: // //! \param[in] name Name of each nuclide //! \param[in] density Density of each nuclide in [atom/b-cm] - void set_densities(const std::vector& name, - const std::vector& density); + void set_densities( + const vector& name, const vector& density); //---------------------------------------------------------------------------- // Accessors @@ -139,26 +139,27 @@ public: // Data int32_t id_ {C_NONE}; //!< Unique ID std::string name_; //!< Name of material - std::vector nuclide_; //!< Indices in nuclides vector - std::vector element_; //!< Indices in elements vector + vector nuclide_; //!< Indices in nuclides vector + vector element_; //!< Indices in elements vector xt::xtensor atom_density_; //!< Nuclide atom density in [atom/b-cm] double density_; //!< Total atom density in [atom/b-cm] double density_gpcc_; //!< Total atom density in [g/cm^3] double volume_ {-1.0}; //!< Volume in [cm^3] bool fissionable_ {false}; //!< Does this material contain fissionable nuclides bool depletable_ {false}; //!< Is the material depletable? - std::vector p0_; //!< Indicate which nuclides are to be treated with iso-in-lab scattering + vector p0_; //!< Indicate which nuclides are to be treated with + //!< iso-in-lab scattering // To improve performance of tallying, we store an array (direct address // table) that indicates for each nuclide in data::nuclides the index of the // corresponding nuclide in the nuclide_ vector. If it is not present in the // material, the entry is set to -1. - std::vector mat_nuclide_index_; + vector mat_nuclide_index_; // Thermal scattering tables - std::vector thermal_tables_; + vector thermal_tables_; - std::unique_ptr ttb_; + unique_ptr ttb_; private: //---------------------------------------------------------------------------- @@ -191,13 +192,13 @@ private: //============================================================================== //! Calculate Sternheimer adjustment factor -double sternheimer_adjustment(const std::vector& f, const - std::vector& e_b_sq, double e_p_sq, double n_conduction, double - log_I, double tol, int max_iter); +double sternheimer_adjustment(const vector& f, + const vector& e_b_sq, double e_p_sq, double n_conduction, + double log_I, double tol, int max_iter); //! Calculate density effect correction -double density_effect(const std::vector& f, const std::vector& - e_b_sq, double e_p_sq, double n_conduction, double rho, double E, double tol, +double density_effect(const vector& f, const vector& e_b_sq, + double e_p_sq, double n_conduction, double rho, double E, double tol, int max_iter); //! Read material data from materials.xml diff --git a/include/openmc/memory.h b/include/openmc/memory.h new file mode 100644 index 000000000..99666da7d --- /dev/null +++ b/include/openmc/memory.h @@ -0,0 +1,19 @@ +#ifndef OPENMC_MEMORY_H +#define OPENMC_MEMORY_H + +/* + * See notes in include/openmc/vector.h + * + * In an implementation of OpenMC that uses an accelerator, we may remove the + * use of unique_ptr, etc. below and replace it with a custom + * implementation behaving as expected on the device. + */ + +#include + +namespace openmc { +using std::make_unique; +using std::unique_ptr; +} // namespace openmc + +#endif // OPENMC_MEMORY_H diff --git a/include/openmc/mesh.h b/include/openmc/mesh.h index 2af2e87df..eca32ad4a 100644 --- a/include/openmc/mesh.h +++ b/include/openmc/mesh.h @@ -4,16 +4,16 @@ #ifndef OPENMC_MESH_H #define OPENMC_MESH_H -#include // for unique_ptr -#include #include #include "hdf5.h" #include "pugixml.hpp" #include "xtensor/xtensor.hpp" +#include "openmc/memory.h" // for unique_ptr #include "openmc/particle.h" #include "openmc/position.h" +#include "openmc/vector.h" #ifdef DAGMC #include "moab/Core.hpp" @@ -47,14 +47,14 @@ class Mesh; namespace model { extern std::unordered_map mesh_map; -extern std::vector> meshes; +extern vector> meshes; } // namespace model #ifdef LIBMESH namespace settings { // used when creating new libMesh::Mesh instances -extern std::unique_ptr libmesh_init; +extern unique_ptr libmesh_init; extern const libMesh::Parallel::Communicator* libmesh_comm; } #endif @@ -79,8 +79,8 @@ public: virtual void bins_crossed(Position r0, Position r1, const Direction& u, - std::vector& bins, - std::vector& lengths) const = 0; + vector& bins, + vector& lengths) const = 0; //! Determine which surface bins were crossed by a particle // @@ -92,7 +92,7 @@ public: surface_bins_crossed(Position r0, Position r1, const Direction& u, - std::vector& bins) const = 0; + vector& bins) const = 0; //! Get bin at a given position in space // @@ -122,8 +122,8 @@ public: //! of the plot's axes. For example an xy-slice plot will get back a vector //! of x-coordinates and another of y-coordinates. These vectors may be //! empty for low-dimensional meshes. - virtual std::pair, std::vector> - plot(Position plot_ll, Position plot_ur) const = 0; + virtual std::pair, vector> plot( + Position plot_ll, Position plot_ur) const = 0; //! Return a string representation of the mesh bin // @@ -150,16 +150,16 @@ public: void bins_crossed(Position r0, Position r1, const Direction& u, - std::vector& bins, - std::vector& lengths) const override; + vector& bins, + vector& lengths) const override; //! Count number of bank sites in each mesh bin / energy bin // //! \param[in] Pointer to bank sites //! \param[in] Number of bank sites //! \param[out] Whether any bank sites are outside the mesh - xt::xtensor count_sites(const Particle::Bank* bank, - int64_t length, bool* outside) const; + xt::xtensor count_sites( + const SourceSite* bank, int64_t length, bool* outside) const; //! Get bin given mesh indices // @@ -236,7 +236,7 @@ public: surface_bins_crossed(Position r0, Position r1, const Direction& u, - std::vector& bins) const override; + vector& bins) const override; int get_index_in_direction(double r, int i) const override; @@ -244,8 +244,8 @@ public: double negative_grid_boundary(int* ijk, int i) const override; - std::pair, std::vector> - plot(Position plot_ll, Position plot_ur) const override; + std::pair, vector> plot( + Position plot_ll, Position plot_ur) const override; void to_hdf5(hid_t group) const override; @@ -256,9 +256,8 @@ public: //! \param[in] bank Array of bank sites //! \param[out] Whether any bank sites are outside the mesh //! \return Array indicating number of sites in each mesh/energy bin - xt::xtensor count_sites(const Particle::Bank* bank, - int64_t length, - bool* outside) const; + xt::xtensor count_sites( + const SourceSite* bank, int64_t length, bool* outside) const; // Data members double volume_frac_; //!< Volume fraction of each mesh element @@ -278,7 +277,7 @@ public: surface_bins_crossed(Position r0, Position r1, const Direction& u, - std::vector& bins) const override; + vector& bins) const override; int get_index_in_direction(double r, int i) const override; @@ -286,12 +285,12 @@ public: double negative_grid_boundary(int* ijk, int i) const override; - std::pair, std::vector> - plot(Position plot_ll, Position plot_ur) const override; + std::pair, vector> plot( + Position plot_ll, Position plot_ur) const override; void to_hdf5(hid_t group) const override; - std::vector> grid_; + vector> grid_; int set_grid(); }; @@ -316,8 +315,7 @@ public: //! Set the value of a bin for a variable on the internal // mesh instance virtual void set_score_data(const std::string& var_name, - const std::vector& values, - const std::vector& std_dev) = 0; + const vector& values, const vector& std_dev) = 0; //! Write the unstructured mesh to file // @@ -343,7 +341,7 @@ public: void surface_bins_crossed(Position r0, Position r1, - std::vector& bins) const; + vector& bins) const; void to_hdf5(hid_t group) const override; @@ -369,14 +367,11 @@ public: void bins_crossed(Position r0, Position r1, const Direction& u, - std::vector& bins, - std::vector& lengths) const override; + vector& bins, + vector& lengths) const override; - void - surface_bins_crossed(Position r0, - Position r1, - const Direction& u, - std::vector& bins) const override; + void surface_bins_crossed(Position r0, Position r1, const Direction& u, + vector& bins) const override; int get_bin(Position r) const; @@ -384,8 +379,8 @@ public: int n_surface_bins() const override; - std::pair, std::vector> - plot(Position plot_ll, Position plot_ur) const override; + std::pair, vector> plot( + Position plot_ll, Position plot_ur) const override; std::string library() const override; @@ -396,9 +391,8 @@ public: void remove_scores() override; //! Set data for a score - void set_score_data(const std::string& score, - const std::vector& values, - const std::vector& std_dev) override; + void set_score_data(const std::string& score, const vector& values, + const vector& std_dev) override; //! Write the mesh with any current tally data void write(const std::string& base_filename) const; @@ -417,11 +411,8 @@ private: //! \param[in] dir Normalized particle direction //! \param[in] track_len length of particle track //! \param[out] Mesh intersections - void - intersect_track(const moab::CartVect& start, - const moab::CartVect& dir, - double track_len, - std::vector& hits) const; + void intersect_track(const moab::CartVect& start, const moab::CartVect& dir, + double track_len, vector& hits) const; //! Calculate the volume for a given tetrahedron handle. // @@ -505,10 +496,10 @@ private: moab::Range ehs_; //!< Range of tetrahedra EntityHandle's in the mesh moab::EntityHandle tetset_; //!< EntitySet containing all tetrahedra moab::EntityHandle kdtree_root_; //!< Root of the MOAB KDTree - std::unique_ptr mbi_; //!< MOAB instance - std::unique_ptr kdtree_; //!< MOAB KDTree instance - std::vector baryc_data_; //!< Barycentric data for tetrahedra - std::vector tag_names_; //!< Names of score tags added to the mesh + unique_ptr mbi_; //!< MOAB instance + unique_ptr kdtree_; //!< MOAB KDTree instance + vector baryc_data_; //!< Barycentric data for tetrahedra + vector tag_names_; //!< Names of score tags added to the mesh }; #endif @@ -525,14 +516,11 @@ public: void bins_crossed(Position r0, Position r1, const Direction& u, - std::vector& bins, - std::vector& lengths) const override; + vector& bins, + vector& lengths) const override; - void - surface_bins_crossed(Position r0, - Position r1, - const Direction& u, - std::vector& bins) const override; + void surface_bins_crossed(Position r0, Position r1, const Direction& u, + vector& bins) const override; int get_bin(Position r) const override; @@ -540,16 +528,15 @@ public: int n_surface_bins() const override; - std::pair, std::vector> - plot(Position plot_ll, Position plot_ur) const override; + std::pair, vector> plot( + Position plot_ll, Position plot_ur) const override; void add_score(const std::string& var_name) override; void remove_scores() override; - void set_score_data(const std::string& var_name, - const std::vector& values, - const std::vector& std_dev) override; + void set_score_data(const std::string& var_name, const vector& values, + const vector& std_dev) override; void write(const std::string& base_filename) const override; @@ -570,9 +557,11 @@ private: int get_bin_from_element(const libMesh::Elem* elem) const; // Data members - std::unique_ptr m_; //!< pointer to the libMesh mesh instance - std::vector> pl_; //!< per-thread point locators - std::unique_ptr equation_systems_; //!< pointer to the equation systems of the mesh + unique_ptr m_; //!< pointer to the libMesh mesh instance + vector> + pl_; //!< per-thread point locators + unique_ptr + equation_systems_; //!< pointer to the equation systems of the mesh std::string eq_system_name_; //!< name of the equation system holding OpenMC results std::unordered_map variable_map_; //!< mapping of variable names (tally scores) to libMesh variable numbers libMesh::BoundingBox bbox_; //!< bounding box of the mesh diff --git a/include/openmc/message_passing.h b/include/openmc/message_passing.h index c730674ab..82b27a779 100644 --- a/include/openmc/message_passing.h +++ b/include/openmc/message_passing.h @@ -13,7 +13,7 @@ namespace mpi { extern bool master; #ifdef OPENMC_MPI - extern MPI_Datatype bank; + extern MPI_Datatype source_site; extern MPI_Comm intracomm; #endif diff --git a/include/openmc/mgxs.h b/include/openmc/mgxs.h index ae7a54ad3..bfa1200e8 100644 --- a/include/openmc/mgxs.h +++ b/include/openmc/mgxs.h @@ -5,16 +5,15 @@ #define OPENMC_MGXS_H #include -#include #include "xtensor/xtensor.hpp" #include "openmc/constants.h" #include "openmc/hdf5_interface.h" #include "openmc/particle.h" +#include "openmc/vector.h" #include "openmc/xsdata.h" - namespace openmc { //============================================================================== @@ -42,13 +41,13 @@ class Mgxs { AngleDistributionType scatter_format; // flag for if this is legendre, histogram, or tabular int num_groups; // number of energy groups int num_delayed_groups; // number of delayed neutron groups - std::vector xs; // Cross section data + vector xs; // Cross section data // MGXS Incoming Flux Angular grid information bool is_isotropic; // used to skip search for angle indices if isotropic int n_pol; int n_azi; - std::vector polar; - std::vector azimuthal; + vector polar; + vector azimuthal; //! \brief Initializes the Mgxs object metadata //! @@ -62,10 +61,10 @@ class Mgxs { //! the incoming particle. //! @param in_polar Polar angle grid. //! @param in_azimuthal Azimuthal angle grid. - void - init(const std::string& in_name, double in_awr, const std::vector& in_kTs, - bool in_fissionable, AngleDistributionType in_scatter_format, bool in_is_isotropic, - const std::vector& in_polar, const std::vector& in_azimuthal); + void init(const std::string& in_name, double in_awr, + const vector& in_kTs, bool in_fissionable, + AngleDistributionType in_scatter_format, bool in_is_isotropic, + const vector& in_polar, const vector& in_azimuthal); //! \brief Initializes the Mgxs object metadata from the HDF5 file //! @@ -74,9 +73,8 @@ class Mgxs { //! @param temps_to_read Resultant list of temperatures in the library //! to read which correspond to the requested temperatures. //! @param order_dim Resultant dimensionality of the scattering order. - void - metadata_from_hdf5(hid_t xs_id, const std::vector& temperature, - std::vector& temps_to_read, int& order_dim); + void metadata_from_hdf5(hid_t xs_id, const vector& temperature, + vector& temps_to_read, int& order_dim); //! \brief Performs the actual act of combining the microscopic data for a //! single temperature. @@ -86,9 +84,8 @@ class Mgxs { //! @param micro_ts The temperature index of the microscopic objects that //! corresponds to the temperature of interest. //! @param this_t The temperature index of the macroscopic object. - void - combine(const std::vector& micros, const std::vector& scalars, - const std::vector& micro_ts, int this_t); + void combine(const vector& micros, const vector& scalars, + const vector& micro_ts, int this_t); //! \brief Checks to see if this and that are able to be combined //! @@ -103,7 +100,7 @@ class Mgxs { std::string name; // name of dataset, e.g., UO2 double awr; // atomic weight ratio bool fissionable; // Is this fissionable - std::vector cache; // index and data cache + vector cache; // index and data cache Mgxs() = default; @@ -113,8 +110,8 @@ class Mgxs { //! @param temperature Temperatures to read. //! @param num_group number of energy groups //! @param num_delay number of delayed groups - Mgxs(hid_t xs_id, const std::vector& temperature, - int num_group, int num_delay); + Mgxs(hid_t xs_id, const vector& temperature, int num_group, + int num_delay); //! \brief Constructor that initializes and populates all data to build a //! macroscopic cross section from microscopic cross sections. @@ -125,9 +122,9 @@ class Mgxs { //! @param atom_densities Atom densities of those microscopic quantities. //! @param num_group number of energy groups //! @param num_delay number of delayed groups - Mgxs(const std::string& in_name, const std::vector& mat_kTs, - const std::vector& micros, const std::vector& atom_densities, - int num_group, int num_delay); + Mgxs(const std::string& in_name, const vector& mat_kTs, + const vector& micros, const vector& atom_densities, + int num_group, int num_delay); //! \brief Provides a cross section value given certain parameters //! @@ -187,7 +184,7 @@ class Mgxs { set_angle_index(Direction u); //! \brief Provide const access to list of XsData held by this - const std::vector& get_xsdata() const { return xs; } + const vector& get_xsdata() const { return xs; } }; } // namespace openmc diff --git a/include/openmc/mgxs_interface.h b/include/openmc/mgxs_interface.h index 6beda5778..57b5d9bf3 100644 --- a/include/openmc/mgxs_interface.h +++ b/include/openmc/mgxs_interface.h @@ -4,10 +4,9 @@ #ifndef OPENMC_MGXS_INTERFACE_H #define OPENMC_MGXS_INTERFACE_H -#include "hdf5_interface.h" -#include "mgxs.h" - -#include +#include "openmc/hdf5_interface.h" +#include "openmc/mgxs.h" +#include "openmc/vector.h" namespace openmc { @@ -23,20 +22,20 @@ public: // Construct from path to cross sections file, as well as a list // of XS to read and the corresponding temperatures for each XS MgxsInterface(const std::string& path_cross_sections, - const std::vector xs_to_read, - const std::vector> xs_temps); + const vector xs_to_read, + const vector> xs_temps); // Does things to construct after the nuclides and temperatures to // read have been specified. void init(); // Set which nuclides and temperatures are to be read - void set_nuclides_and_temperatures(std::vector xs_to_read, - std::vector> xs_temps); + void set_nuclides_and_temperatures( + vector xs_to_read, vector> xs_temps); // Add an Mgxs object to be managed - void add_mgxs(hid_t file_id, const std::string& name, - const std::vector& temperature); + void add_mgxs( + hid_t file_id, const std::string& name, const vector& temperature); // Reads just the header of the cross sections file, to find // min & max energies as well as the available XS @@ -46,20 +45,20 @@ public: void create_macro_xs(); // Get the kT values which are used in the OpenMC model - std::vector> get_mat_kTs(); + vector> get_mat_kTs(); int num_energy_groups_; int num_delayed_groups_; - std::vector xs_names_; // available names in HDF5 file - std::vector xs_to_read_; // XS which appear in materials - std::vector> xs_temps_to_read_; // temperatures used + vector xs_names_; // available names in HDF5 file + vector xs_to_read_; // XS which appear in materials + vector> xs_temps_to_read_; // temperatures used std::string cross_sections_path_; // path to MGXS h5 file - std::vector nuclides_; - std::vector macro_xs_; - std::vector energy_bins_; - std::vector energy_bin_avg_; - std::vector rev_energy_bins_; - std::vector> nuc_temps_; // all available temperatures + vector nuclides_; + vector macro_xs_; + vector energy_bins_; + vector energy_bin_avg_; + vector rev_energy_bins_; + vector> nuc_temps_; // all available temperatures }; namespace data { diff --git a/include/openmc/nuclide.h b/include/openmc/nuclide.h index 69bb50cc8..6067c53a0 100644 --- a/include/openmc/nuclide.h +++ b/include/openmc/nuclide.h @@ -4,21 +4,21 @@ #ifndef OPENMC_NUCLIDE_H #define OPENMC_NUCLIDE_H -#include -#include // for unique_ptr #include #include // for pair -#include #include #include +#include "openmc/array.h" #include "openmc/constants.h" #include "openmc/endf.h" +#include "openmc/memory.h" // for unique_ptr #include "openmc/particle.h" #include "openmc/reaction.h" #include "openmc/reaction_product.h" #include "openmc/urr.h" +#include "openmc/vector.h" #include "openmc/wmp.h" namespace openmc { @@ -32,12 +32,12 @@ public: // Types, aliases using EmissionMode = ReactionProduct::EmissionMode; struct EnergyGrid { - std::vector grid_index; - std::vector energy; + vector grid_index; + vector energy; }; // Constructors/destructors - Nuclide(hid_t group, const std::vector& temperature); + Nuclide(hid_t group, const vector& temperature); ~Nuclide(); //! Initialize logarithmic grid for energy searches @@ -78,40 +78,41 @@ public: gsl::index index_; //!< Index in the nuclides array // Temperature dependent cross section data - std::vector kTs_; //!< temperatures in eV (k*T) - std::vector grid_; //!< Energy grid at each temperature - std::vector> xs_; //!< Cross sections at each temperature + vector kTs_; //!< temperatures in eV (k*T) + vector grid_; //!< Energy grid at each temperature + vector> xs_; //!< Cross sections at each temperature // Multipole data - std::unique_ptr multipole_; + unique_ptr multipole_; // Fission data bool fissionable_ {false}; //!< Whether nuclide is fissionable bool has_partial_fission_ {false}; //!< has partial fission reactions? - std::vector fission_rx_; //!< Fission reactions + vector fission_rx_; //!< Fission reactions int n_precursor_ {0}; //!< Number of delayed neutron precursors - std::unique_ptr total_nu_; //!< Total neutron yield - std::unique_ptr fission_q_prompt_; //!< Prompt fission energy release - std::unique_ptr fission_q_recov_; //!< Recoverable fission energy release - std::unique_ptr prompt_photons_; //!< Prompt photon energy release - std::unique_ptr delayed_photons_; //!< Delayed photon energy release - std::unique_ptr fragments_; //!< Fission fragment energy release - std::unique_ptr betas_; //!< Delayed beta energy release + unique_ptr total_nu_; //!< Total neutron yield + unique_ptr fission_q_prompt_; //!< Prompt fission energy release + unique_ptr + fission_q_recov_; //!< Recoverable fission energy release + unique_ptr prompt_photons_; //!< Prompt photon energy release + unique_ptr delayed_photons_; //!< Delayed photon energy release + unique_ptr fragments_; //!< Fission fragment energy release + unique_ptr betas_; //!< Delayed beta energy release // Resonance scattering information bool resonant_ {false}; - std::vector energy_0K_; - std::vector elastic_0K_; - std::vector xs_cdf_; + vector energy_0K_; + vector elastic_0K_; + vector xs_cdf_; // Unresolved resonance range information bool urr_present_ {false}; int urr_inelastic_ {C_NONE}; - std::vector urr_data_; + vector urr_data_; - std::vector> reactions_; //!< Reactions - std::array reaction_index_; //!< Index of each reaction - std::vector index_inelastic_scatter_; + vector> reactions_; //!< Reactions + array reaction_index_; //!< Index of each reaction + vector index_inelastic_scatter_; private: void create_derived(const Function1D* prompt_photons, const Function1D* delayed_photons); @@ -146,8 +147,8 @@ namespace data { // Minimum/maximum transport energy for each particle type. Order corresponds to // that of the ParticleType enum -extern std::array energy_min; -extern std::array energy_max; +extern array energy_min; +extern array energy_max; //! Minimum temperature in [K] that nuclide data is available at extern double temperature_min; @@ -156,7 +157,7 @@ extern double temperature_min; extern double temperature_max; extern std::unordered_map nuclide_map; -extern std::vector> nuclides; +extern vector> nuclides; } // namespace data diff --git a/include/openmc/particle.h b/include/openmc/particle.h index e8002cedb..0fda3d307 100644 --- a/include/openmc/particle.h +++ b/include/openmc/particle.h @@ -4,213 +4,37 @@ //! \file particle.h //! \brief Particle type -#include #include -#include // for unique_ptr #include #include -#include #include "openmc/constants.h" +#include "openmc/memory.h" // for unique_ptr +#include "openmc/particle_data.h" #include "openmc/position.h" #include "openmc/random_lcg.h" #include "openmc/tallies/filter_match.h" - -#ifdef DAGMC -#include "DagMC.hpp" -#endif - +#include "openmc/vector.h" namespace openmc { -//============================================================================== -// Constants -//============================================================================== - -// Since cross section libraries come with different numbers of delayed groups -// (e.g. ENDF/B-VII.1 has 6 and JEFF 3.1.1 has 8 delayed groups) and we don't -// yet know what cross section library is being used when the tallies.xml file -// is read in, we want to have an upper bound on the size of the array we -// use to store the bins for delayed group tallies. -constexpr int MAX_DELAYED_GROUPS {8}; - -constexpr double CACHE_INVALID {-1.0}; - -//============================================================================== -// Class declarations -//============================================================================== - -// Forward declare the Surface class for use in function arguments. +// Forward declare the Surface class for use in Particle::cross_vacuum_bc, etc. class Surface; -class LocalCoord { +/* + * The Particle class encompasses data and methods for transporting particles + * through their lifecycle. Its base class defines particle data layout in + * memory. A more detailed description of the rationale behind this approach + * can be found in particle_data.h. + */ + +class Particle : public ParticleData { public: - void rotate(const std::vector& rotation); - - //! clear data from a single coordinate level - void reset(); - - Position r; //!< particle position - Direction u; //!< particle direction - int cell {-1}; - int universe {-1}; - int lattice {-1}; - int lattice_x {-1}; - int lattice_y {-1}; - int lattice_z {-1}; - bool rotated {false}; //!< Is the level rotated? -}; - -//============================================================================== -//! Cached microscopic cross sections for a particular nuclide at the current -//! energy -//============================================================================== - -struct NuclideMicroXS { - // Microscopic cross sections in barns - double total; //!< total cross section - double absorption; //!< absorption (disappearance) - double fission; //!< fission - double nu_fission; //!< neutron production from fission - - double elastic; //!< If sab_frac is not 1 or 0, then this value is - //!< averaged over bound and non-bound nuclei - double thermal; //!< Bound thermal elastic & inelastic scattering - double thermal_elastic; //!< Bound thermal elastic scattering - double photon_prod; //!< microscopic photon production xs - - // Cross sections for depletion reactions (note that these are not stored in - // macroscopic cache) - double reaction[DEPLETION_RX.size()]; - - // Indicies and factors needed to compute cross sections from the data tables - int index_grid; //!< Index on nuclide energy grid - int index_temp; //!< Temperature index for nuclide - double interp_factor; //!< Interpolation factor on nuc. energy grid - int index_sab {-1}; //!< Index in sab_tables - int index_temp_sab; //!< Temperature index for sab_tables - double sab_frac; //!< Fraction of atoms affected by S(a,b) - bool use_ptable; //!< In URR range with probability tables? - - // Energy and temperature last used to evaluate these cross sections. If - // these values have changed, then the cross sections must be re-evaluated. - double last_E {0.0}; //!< Last evaluated energy - double last_sqrtkT {0.0}; //!< Last temperature in sqrt(Boltzmann constant - //!< * temperature (eV)) -}; - -//============================================================================== -//! Cached microscopic photon cross sections for a particular element at the -//! current energy -//============================================================================== - -struct ElementMicroXS { - int index_grid; //!< index on element energy grid - double last_E {0.0}; //!< last evaluated energy in [eV] - double interp_factor; //!< interpolation factor on energy grid - double total; //!< microscopic total photon xs - double coherent; //!< microscopic coherent xs - double incoherent; //!< microscopic incoherent xs - double photoelectric; //!< microscopic photoelectric xs - double pair_production; //!< microscopic pair production xs -}; - -//============================================================================== -// MACROXS contains cached macroscopic cross sections for the material a -// particle is traveling through -//============================================================================== - -struct MacroXS { - double total; //!< macroscopic total xs - double absorption; //!< macroscopic absorption xs - double fission; //!< macroscopic fission xs - double nu_fission; //!< macroscopic production xs - double photon_prod; //!< macroscopic photon production xs - - // Photon cross sections - double coherent; //!< macroscopic coherent xs - double incoherent; //!< macroscopic incoherent xs - double photoelectric; //!< macroscopic photoelectric xs - double pair_production; //!< macroscopic pair production xs -}; - -//============================================================================== -// Information about nearest boundary crossing -//============================================================================== - -struct BoundaryInfo { - double distance {INFINITY}; //!< distance to nearest boundary - int surface_index {0}; //!< if boundary is surface, index in surfaces vector - int coord_level; //!< coordinate level after crossing boundary - std::array lattice_translation {}; //!< which way lattice indices will change -}; - -//============================================================================ -//! State of a particle being transported through geometry -//============================================================================ - -class Particle { -public: - //========================================================================== - // Aliases and type definitions - - //! Particle types - enum class Type { - neutron, photon, electron, positron - }; - - //! Saved ("banked") state of a particle - //! NOTE: This structure's MPI type is built in initialize_mpi() of - //! initialize.cpp. Any changes made to the struct here must also be - //! made when building the Bank MPI type in initialize_mpi(). - //! NOTE: This structure is also used on the python side, and is defined - //! in lib/core.py. Changes made to the type here must also be made to the - //! python defintion. - struct Bank { - Position r; - Direction u; - double E; - double wgt; - int delayed_group; - int surf_id; - Type particle; - int64_t parent_id; - int64_t progeny_id; - }; - - //! Saved ("banked") state of a particle, for nu-fission tallying - struct NuBank { - double E; //!< particle energy - double wgt; //!< particle weight - int delayed_group; //!< particle delayed group - }; //========================================================================== // Constructors - Particle(); - - //========================================================================== - // Methods and accessors - - // Accessors for position in global coordinates - Position& r() { return coord_[0].r; } - const Position& r() const { return coord_[0].r; } - - // Accessors for position in local coordinates - Position& r_local() { return coord_[n_coord_ - 1].r; } - const Position& r_local() const { return coord_[n_coord_ - 1].r; } - - // Accessors for direction in global coordinates - Direction& u() { return coord_[0].u; } - const Direction& u() const { return coord_[0].u; } - - // Accessors for direction in local coordinates - Direction& u_local() { return coord_[n_coord_ - 1].u; } - const Direction& u_local() const { return coord_[n_coord_ - 1].u; } - - //! resets all coordinate levels for the particle - void clear(); + Particle() = default; //! create a secondary particle // @@ -220,7 +44,7 @@ public: //! \param u Direction of the secondary particle //! \param E Energy of the secondary particle in [eV] //! \param type Particle type - void create_secondary(double wgt, Direction u, double E, Type type); + void create_secondary(double wgt, Direction u, double E, ParticleType type); //! initialize from a source site // @@ -228,7 +52,7 @@ public: //! site may have been produced from an external source, from fission, or //! simply as a secondary particle. //! \param src Source site data - void from_source(const Bank* src); + void from_source(const SourceSite* src); // Coarse-grained particle events void event_calculate_xs(); @@ -277,128 +101,15 @@ public: //! create a particle restart HDF5 file void write_restart() const; - - //! Gets the pointer to the particle's current PRN seed - uint64_t* current_seed() {return seeds_ + stream_;} - const uint64_t* current_seed() const {return seeds_ + stream_;} - - //========================================================================== - // Data members - - // Cross section caches - std::vector neutron_xs_; //!< Microscopic neutron cross sections - std::vector photon_xs_; //!< Microscopic photon cross sections - MacroXS macro_xs_; //!< Macroscopic cross sections - - int64_t id_; //!< Unique ID - Type type_ {Type::neutron}; //!< Particle type (n, p, e, etc.) - - int n_coord_ {1}; //!< number of current coordinate levels - int cell_instance_; //!< offset for distributed properties - std::vector coord_; //!< coordinates for all levels - - // Particle coordinates before crossing a surface - int n_coord_last_ {1}; //!< number of current coordinates - std::vector cell_last_; //!< coordinates for all levels - - // Energy data - double E_; //!< post-collision energy in eV - double E_last_; //!< pre-collision energy in eV - int g_ {0}; //!< post-collision energy group (MG only) - int g_last_; //!< pre-collision energy group (MG only) - - // Other physical data - double wgt_ {1.0}; //!< particle weight - double mu_; //!< angle of scatter - bool alive_ {true}; //!< is particle alive? - - // Other physical data - Position r_last_current_; //!< coordinates of the last collision or - //!< reflective/periodic surface crossing for - //!< current tallies - Position r_last_; //!< previous coordinates - Direction u_last_; //!< previous direction coordinates - double wgt_last_ {1.0}; //!< pre-collision particle weight - double wgt_absorb_ {0.0}; //!< weight absorbed for survival biasing - - // What event took place - bool fission_ {false}; //!< did particle cause implicit fission - TallyEvent event_; //!< scatter, absorption - int event_nuclide_; //!< index in nuclides array - int event_mt_; //!< reaction MT - int delayed_group_ {0}; //!< delayed group - - // Post-collision physical data - int n_bank_ {0}; //!< number of fission sites banked - int n_bank_second_ {0}; //!< number of secondary particles banked - double wgt_bank_ {0.0}; //!< weight of fission sites banked - int n_delayed_bank_[MAX_DELAYED_GROUPS]; //!< number of delayed fission - //!< sites banked - - // Indices for various arrays - int surface_ {0}; //!< index for surface particle is on - int cell_born_ {-1}; //!< index for cell particle was born in - int material_ {-1}; //!< index for current material - int material_last_ {-1}; //!< index for last material - - // Boundary information - BoundaryInfo boundary_; - - // Temperature of current cell - double sqrtkT_ {-1.0}; //!< sqrt(k_Boltzmann * temperature) in eV - double sqrtkT_last_ {0.0}; //!< last temperature - - // Statistical data - int n_collision_ {0}; //!< number of collisions - - // Track output - bool write_track_ {false}; - - // Current PRNG state - uint64_t seeds_[N_STREAMS]; // current seeds - int stream_; // current RNG stream - - // Secondary particle bank - std::vector secondary_bank_; - - int64_t current_work_; // current work index - - std::vector flux_derivs_; // for derivatives for this particle - - std::vector filter_matches_; // tally filter matches - - std::vector> tracks_; // tracks for outputting to file - - std::vector nu_bank_; // bank of most recently fissioned particles - - // Global tally accumulators - double keff_tally_absorption_ {0.0}; - double keff_tally_collision_ {0.0}; - double keff_tally_tracklength_ {0.0}; - double keff_tally_leakage_ {0.0}; - - bool trace_ {false}; //!< flag to show debug information - - double collision_distance_; // distance to particle's next closest collision - - int n_event_ {0}; // number of events executed in this particle's history - - // DagMC state variables - #ifdef DAGMC - moab::DagMC::RayHistory history_; - Direction last_dir_; - #endif - - int64_t n_progeny_ {0}; // Number of progeny produced by this particle }; //============================================================================ //! Functions //============================================================================ -std::string particle_type_to_str(Particle::Type type); +std::string particle_type_to_str(ParticleType type); -Particle::Type str_to_particle_type(std::string str); +ParticleType str_to_particle_type(std::string str); } // namespace openmc diff --git a/include/openmc/particle_data.h b/include/openmc/particle_data.h new file mode 100644 index 000000000..f871e8032 --- /dev/null +++ b/include/openmc/particle_data.h @@ -0,0 +1,481 @@ +#ifndef OPENMC_PARTICLE_DATA_H +#define OPENMC_PARTICLE_DATA_H + +#include "openmc/array.h" +#include "openmc/constants.h" +#include "openmc/position.h" +#include "openmc/random_lcg.h" +#include "openmc/tallies/filter_match.h" +#include "openmc/vector.h" + +#ifdef DAGMC +#include "DagMC.hpp" +#endif + +namespace openmc { + +//============================================================================== +// Constants +//============================================================================== + +// Since cross section libraries come with different numbers of delayed groups +// (e.g. ENDF/B-VII.1 has 6 and JEFF 3.1.1 has 8 delayed groups) and we don't +// yet know what cross section library is being used when the tallies.xml file +// is read in, we want to have an upper bound on the size of the array we +// use to store the bins for delayed group tallies. +constexpr int MAX_DELAYED_GROUPS {8}; + +constexpr double CACHE_INVALID {-1.0}; + +//========================================================================== +// Aliases and type definitions + +//! Particle types +enum class ParticleType { neutron, photon, electron, positron }; + +//! Saved ("banked") state of a particle +//! NOTE: This structure's MPI type is built in initialize_mpi() of +//! initialize.cpp. Any changes made to the struct here must also be +//! made when building the Bank MPI type in initialize_mpi(). +//! NOTE: This structure is also used on the python side, and is defined +//! in lib/core.py. Changes made to the type here must also be made to the +//! python defintion. +struct SourceSite { + Position r; + Direction u; + double E; + double wgt; + int delayed_group; + int surf_id; + ParticleType particle; + int64_t parent_id; + int64_t progeny_id; +}; + +//! Saved ("banked") state of a particle, for nu-fission tallying +struct NuBank { + double E; //!< particle energy + double wgt; //!< particle weight + int delayed_group; //!< particle delayed group +}; + +class LocalCoord { +public: + void rotate(const vector& rotation); + + //! clear data from a single coordinate level + void reset(); + + Position r; //!< particle position + Direction u; //!< particle direction + int cell {-1}; + int universe {-1}; + int lattice {-1}; + array lattice_i {{-1, -1, -1}}; + bool rotated {false}; //!< Is the level rotated? +}; + +//============================================================================== +//! Cached microscopic cross sections for a particular nuclide at the current +//! energy +//============================================================================== + +struct NuclideMicroXS { + // Microscopic cross sections in barns + double total; //!< total cross section + double absorption; //!< absorption (disappearance) + double fission; //!< fission + double nu_fission; //!< neutron production from fission + + double elastic; //!< If sab_frac is not 1 or 0, then this value is + //!< averaged over bound and non-bound nuclei + double thermal; //!< Bound thermal elastic & inelastic scattering + double thermal_elastic; //!< Bound thermal elastic scattering + double photon_prod; //!< microscopic photon production xs + + // Cross sections for depletion reactions (note that these are not stored in + // macroscopic cache) + double reaction[DEPLETION_RX.size()]; + + // Indicies and factors needed to compute cross sections from the data tables + int index_grid; //!< Index on nuclide energy grid + int index_temp; //!< Temperature index for nuclide + double interp_factor; //!< Interpolation factor on nuc. energy grid + int index_sab {-1}; //!< Index in sab_tables + int index_temp_sab; //!< Temperature index for sab_tables + double sab_frac; //!< Fraction of atoms affected by S(a,b) + bool use_ptable; //!< In URR range with probability tables? + + // Energy and temperature last used to evaluate these cross sections. If + // these values have changed, then the cross sections must be re-evaluated. + double last_E {0.0}; //!< Last evaluated energy + double last_sqrtkT {0.0}; //!< Last temperature in sqrt(Boltzmann constant + //!< * temperature (eV)) +}; + +//============================================================================== +//! Cached microscopic photon cross sections for a particular element at the +//! current energy +//============================================================================== + +struct ElementMicroXS { + int index_grid; //!< index on element energy grid + double last_E {0.0}; //!< last evaluated energy in [eV] + double interp_factor; //!< interpolation factor on energy grid + double total; //!< microscopic total photon xs + double coherent; //!< microscopic coherent xs + double incoherent; //!< microscopic incoherent xs + double photoelectric; //!< microscopic photoelectric xs + double pair_production; //!< microscopic pair production xs +}; + +//============================================================================== +// MacroXS contains cached macroscopic cross sections for the material a +// particle is traveling through +//============================================================================== + +struct MacroXS { + double total; //!< macroscopic total xs + double absorption; //!< macroscopic absorption xs + double fission; //!< macroscopic fission xs + double nu_fission; //!< macroscopic production xs + double photon_prod; //!< macroscopic photon production xs + + // Photon cross sections + double coherent; //!< macroscopic coherent xs + double incoherent; //!< macroscopic incoherent xs + double photoelectric; //!< macroscopic photoelectric xs + double pair_production; //!< macroscopic pair production xs +}; + +//============================================================================== +// Information about nearest boundary crossing +//============================================================================== + +struct BoundaryInfo { + double distance {INFINITY}; //!< distance to nearest boundary + int surface_index {0}; //!< if boundary is surface, index in surfaces vector + int coord_level; //!< coordinate level after crossing boundary + array + lattice_translation {}; //!< which way lattice indices will change +}; + +//============================================================================ +//! Defines how particle data is laid out in memory +//============================================================================ + +/* + * This class was added in order to separate the layout and access of particle + * data from particle physics operations during a development effort to get + * OpenMC running on GPUs. In the event-based Monte Carlo method, one creates + * an array of particles on which actions like cross section lookup and surface + * crossing are done en masse, which works best on vector computers of yore and + * modern GPUs. It has been shown in the below publication [1] that arranging + * particle data into a structure of arrays rather than an array of structures + * enhances performance on GPUs. For instance, rather than having an + * std::vector where consecutive particle energies would be separated + * by about 400 bytes, one would create a structure which has a single + * std::vector of energies. The motivation here is that more coalesced + * memory accesses occur, in the parlance of GPU programming. + * + * So, this class enables switching between the array-of-structures and + * structure- of-array data layout at compile time. In GPU branches of the + * code, our Particle class inherits from a class that provides an array of + * particle energies, and can access them using the E() method (defined below). + * In the CPU code, we inherit from this class which gives the conventional + * layout of particle data, useful for history-based tracking. + * + * As a result, we always use the E(), r_last(), etc. methods to access + * particle data in order to keep a unified interface between + * structure-of-array and array-of-structure code on either CPU or GPU code + * while sharing the same physics code on each codebase. + * + * [1] Hamilton, Steven P., Stuart R. Slattery, and Thomas M. Evans. + * “Multigroup Monte Carlo on GPUs: Comparison of History- and Event-Based + * Algorithms.” Annals of Nuclear Energy 113 (March 2018): 506–18. + * https://doi.org/10.1016/j.anucene.2017.11.032. + */ +class ParticleData { + +public: + ParticleData(); + +private: + //========================================================================== + // Data members (accessor methods are below) + + // Cross section caches + vector neutron_xs_; //!< Microscopic neutron cross sections + vector photon_xs_; //!< Microscopic photon cross sections + MacroXS macro_xs_; //!< Macroscopic cross sections + + int64_t id_; //!< Unique ID + ParticleType type_ {ParticleType::neutron}; //!< Particle type (n, p, e, etc.) + + int n_coord_ {1}; //!< number of current coordinate levels + int cell_instance_; //!< offset for distributed properties + vector coord_; //!< coordinates for all levels + + // Particle coordinates before crossing a surface + int n_coord_last_ {1}; //!< number of current coordinates + vector cell_last_; //!< coordinates for all levels + + // Energy data + double E_; //!< post-collision energy in eV + double E_last_; //!< pre-collision energy in eV + int g_ {0}; //!< post-collision energy group (MG only) + int g_last_; //!< pre-collision energy group (MG only) + + // Other physical data + double wgt_ {1.0}; //!< particle weight + double mu_; //!< angle of scatter + bool alive_ {true}; //!< is particle alive? + + // Other physical data + Position r_last_current_; //!< coordinates of the last collision or + //!< reflective/periodic surface crossing for + //!< current tallies + Position r_last_; //!< previous coordinates + Direction u_last_; //!< previous direction coordinates + double wgt_last_ {1.0}; //!< pre-collision particle weight + double wgt_absorb_ {0.0}; //!< weight absorbed for survival biasing + + // What event took place + bool fission_ {false}; //!< did particle cause implicit fission + TallyEvent event_; //!< scatter, absorption + int event_nuclide_; //!< index in nuclides array + int event_mt_; //!< reaction MT + int delayed_group_ {0}; //!< delayed group + + // Post-collision physical data + int n_bank_ {0}; //!< number of fission sites banked + int n_bank_second_ {0}; //!< number of secondary particles banked + double wgt_bank_ {0.0}; //!< weight of fission sites banked + int n_delayed_bank_[MAX_DELAYED_GROUPS]; //!< number of delayed fission + //!< sites banked + + // Indices for various arrays + int surface_ {0}; //!< index for surface particle is on + int cell_born_ {-1}; //!< index for cell particle was born in + int material_ {-1}; //!< index for current material + int material_last_ {-1}; //!< index for last material + + // Boundary information + BoundaryInfo boundary_; + + // Temperature of current cell + double sqrtkT_ {-1.0}; //!< sqrt(k_Boltzmann * temperature) in eV + double sqrtkT_last_ {0.0}; //!< last temperature + + // Statistical data + int n_collision_ {0}; //!< number of collisions + + // Track output + bool write_track_ {false}; + + // Current PRNG state + uint64_t seeds_[N_STREAMS]; // current seeds + int stream_; // current RNG stream + + // Secondary particle bank + vector secondary_bank_; + + int64_t current_work_; // current work index + + vector flux_derivs_; // for derivatives for this particle + + vector filter_matches_; // tally filter matches + + vector> tracks_; // tracks for outputting to file + + vector nu_bank_; // bank of most recently fissioned particles + + // Global tally accumulators + double keff_tally_absorption_ {0.0}; + double keff_tally_collision_ {0.0}; + double keff_tally_tracklength_ {0.0}; + double keff_tally_leakage_ {0.0}; + + bool trace_ {false}; //!< flag to show debug information + + double collision_distance_; // distance to particle's next closest collision + + int n_event_ {0}; // number of events executed in this particle's history + +// DagMC state variables +#ifdef DAGMC + moab::DagMC::RayHistory history_; + Direction last_dir_; +#endif + + int64_t n_progeny_ {0}; // Number of progeny produced by this particle + +public: + //========================================================================== + // Methods and accessors + + NuclideMicroXS& neutron_xs(int i) { return neutron_xs_[i]; } + const NuclideMicroXS& neutron_xs(int i) const { return neutron_xs_[i]; } + ElementMicroXS& photon_xs(int i) { return photon_xs_[i]; } + MacroXS& macro_xs() { return macro_xs_; } + const MacroXS& macro_xs() const { return macro_xs_; } + + int64_t& id() { return id_; } + const int64_t& id() const { return id_; } + ParticleType& type() { return type_; } + const ParticleType& type() const { return type_; } + + int& n_coord() { return n_coord_; } + const int& n_coord() const { return n_coord_; } + int& cell_instance() { return cell_instance_; } + const int& cell_instance() const { return cell_instance_; } + LocalCoord& coord(int i) { return coord_[i]; } + const LocalCoord& coord(int i) const { return coord_[i]; } + + int& n_coord_last() { return n_coord_last_; } + const int& n_coord_last() const { return n_coord_last_; } + int& cell_last(int i) { return cell_last_[i]; } + const int& cell_last(int i) const { return cell_last_[i]; } + + double& E() { return E_; } + const double& E() const { return E_; } + double& E_last() { return E_last_; } + const double& E_last() const { return E_last_; } + int& g() { return g_; } + const int& g() const { return g_; } + int& g_last() { return g_last_; } + const int& g_last() const { return g_last_; } + + double& wgt() { return wgt_; } + double& mu() { return mu_; } + const double& mu() const { return mu_; } + bool& alive() { return alive_; } + + Position& r_last_current() { return r_last_current_; } + const Position& r_last_current() const { return r_last_current_; } + Position& r_last() { return r_last_; } + const Position& r_last() const { return r_last_; } + Position& u_last() { return u_last_; } + const Position& u_last() const { return u_last_; } + double& wgt_last() { return wgt_last_; } + const double& wgt_last() const { return wgt_last_; } + double& wgt_absorb() { return wgt_absorb_; } + const double& wgt_absorb() const { return wgt_absorb_; } + + bool& fission() { return fission_; } + TallyEvent& event() { return event_; } + const TallyEvent& event() const { return event_; } + int& event_nuclide() { return event_nuclide_; } + const int& event_nuclide() const { return event_nuclide_; } + int& event_mt() { return event_mt_; } + int& delayed_group() { return delayed_group_; } + + int& n_bank() { return n_bank_; } + int& n_bank_second() { return n_bank_second_; } + double& wgt_bank() { return wgt_bank_; } + int* n_delayed_bank() { return n_delayed_bank_; } + int& n_delayed_bank(int i) { return n_delayed_bank_[i]; } + + int& surface() { return surface_; } + const int& surface() const { return surface_; } + int& cell_born() { return cell_born_; } + const int& cell_born() const { return cell_born_; } + int& material() { return material_; } + const int& material() const { return material_; } + int& material_last() { return material_last_; } + + BoundaryInfo& boundary() { return boundary_; } + + double& sqrtkT() { return sqrtkT_; } + const double& sqrtkT() const { return sqrtkT_; } + double& sqrtkT_last() { return sqrtkT_last_; } + + int& n_collision() { return n_collision_; } + const int& n_collision() const { return n_collision_; } + + bool& write_track() { return write_track_; } + uint64_t& seeds(int i) { return seeds_[i]; } + uint64_t* seeds() { return seeds_; } + int& stream() { return stream_; } + + SourceSite& secondary_bank(int i) { return secondary_bank_[i]; } + decltype(secondary_bank_)& secondary_bank() { return secondary_bank_; } + int64_t& current_work() { return current_work_; } + const int64_t& current_work() const { return current_work_; } + double& flux_derivs(int i) { return flux_derivs_[i]; } + const double& flux_derivs(int i) const { return flux_derivs_[i]; } + decltype(filter_matches_)& filter_matches() { return filter_matches_; } + FilterMatch& filter_matches(int i) { return filter_matches_[i]; } + decltype(tracks_)& tracks() { return tracks_; } + decltype(nu_bank_)& nu_bank() { return nu_bank_; } + NuBank& nu_bank(int i) { return nu_bank_[i]; } + + double& keff_tally_absorption() { return keff_tally_absorption_; } + double& keff_tally_collision() { return keff_tally_collision_; } + double& keff_tally_tracklength() { return keff_tally_tracklength_; } + double& keff_tally_leakage() { return keff_tally_leakage_; } + + bool& trace() { return trace_; } + double& collision_distance() { return collision_distance_; } + int& n_event() { return n_event_; } + +#ifdef DAGMC + moab::DagMC::RayHistory& history() { return history_; } + Direction& last_dir() { return last_dir_; } +#endif + + int64_t& n_progeny() { return n_progeny_; } + + // Accessors for position in global coordinates + Position& r() { return coord_[0].r; } + const Position& r() const { return coord_[0].r; } + + // Accessors for position in local coordinates + Position& r_local() { return coord_[n_coord_ - 1].r; } + const Position& r_local() const { return coord_[n_coord_ - 1].r; } + + // Accessors for direction in global coordinates + Direction& u() { return coord_[0].u; } + const Direction& u() const { return coord_[0].u; } + + // Accessors for direction in local coordinates + Direction& u_local() { return coord_[n_coord_ - 1].u; } + const Direction& u_local() const { return coord_[n_coord_ - 1].u; } + + //! Gets the pointer to the particle's current PRN seed + uint64_t* current_seed() { return seeds_ + stream_; } + const uint64_t* current_seed() const { return seeds_ + stream_; } + + //! Force recalculation of neutron xs by setting last energy to zero + void invalidate_neutron_xs() + { + for (auto& micro : neutron_xs_) + micro.last_E = 0.0; + } + + //! resets all coordinate levels for the particle + void clear() + { + for (auto& level : coord_) + level.reset(); + n_coord_ = 1; + } + + void zero_delayed_bank() + { + for (int& n : n_delayed_bank_) { + n = 0; + } + } + + void zero_flux_derivs() + { + for (double& d : flux_derivs_) { + d = 0; + } + } +}; + +} // namespace openmc + +#endif // OPENMC_PARTICLE_DATA_H diff --git a/include/openmc/photon.h b/include/openmc/photon.h index 43a37a9e3..ca8f75474 100644 --- a/include/openmc/photon.h +++ b/include/openmc/photon.h @@ -2,17 +2,17 @@ #define OPENMC_PHOTON_H #include "openmc/endf.h" +#include "openmc/memory.h" // for unique_ptr #include "openmc/particle.h" +#include "openmc/vector.h" #include #include #include "xtensor/xtensor.hpp" -#include // for unique_ptr #include #include #include // for pair -#include namespace openmc { @@ -81,7 +81,7 @@ public: // Photoionization and atomic relaxation data std::unordered_map shell_map_; //!< Given a shell designator, e.g. 3, this //!< dictionary gives an index in shells_ - std::vector shells_; + vector shells_; // Compton profile data xt::xtensor profile_pdf_; @@ -121,7 +121,7 @@ extern xt::xtensor compton_profile_pz; //! Compton profile momentum g //! Photon interaction data for each element extern std::unordered_map element_map; -extern std::vector> elements; +extern vector> elements; } // namespace data diff --git a/include/openmc/physics.h b/include/openmc/physics.h index b6b2fc204..bf16083ef 100644 --- a/include/openmc/physics.h +++ b/include/openmc/physics.h @@ -6,8 +6,7 @@ #include "openmc/particle.h" #include "openmc/position.h" #include "openmc/reaction.h" - -#include +#include "openmc/vector.h" namespace openmc { @@ -81,7 +80,7 @@ Direction sample_cxs_target_velocity(double awr, double E, Direction u, double k uint64_t* seed); void sample_fission_neutron(int i_nuclide, const Reaction& rx, double E_in, - Particle::Bank* site, uint64_t* seed); + SourceSite* site, uint64_t* seed); //! handles all reactions with a single secondary neutron (other than fission), //! i.e. level scattering, (n,np), (n,na), etc. diff --git a/include/openmc/physics_mg.h b/include/openmc/physics_mg.h index c73bd2eb5..05184d959 100644 --- a/include/openmc/physics_mg.h +++ b/include/openmc/physics_mg.h @@ -5,10 +5,8 @@ #define OPENMC_PHYSICS_MG_H #include "openmc/capi.h" -#include "openmc/particle.h" #include "openmc/nuclide.h" - -#include +#include "openmc/particle.h" namespace openmc { diff --git a/include/openmc/plot.h b/include/openmc/plot.h index 7b66c6696..0e9ceea78 100644 --- a/include/openmc/plot.h +++ b/include/openmc/plot.h @@ -28,7 +28,7 @@ class Plot; namespace model { extern std::unordered_map plot_map; //!< map of plot ids to index -extern std::vector plots; //!< Plot instance container +extern vector 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 @@ -45,7 +45,8 @@ struct RGBColor { RGBColor(const int v[3]) : red(v[0]), green(v[1]), blue(v[2]) { }; RGBColor(int r, int g, int b) : red(r), green(g), blue(b) { }; - RGBColor(const std::vector &v) { + RGBColor(const vector& v) + { if (v.size() != 3) { throw std::out_of_range("Incorrect vector size for RGBColor."); } @@ -121,7 +122,7 @@ public: Position origin_; //!< Plot origin in geometry Position width_; //!< Plot width in geometry PlotBasis basis_; //!< Plot basis (XY/XZ/YZ) - std::array pixels_; //!< Plot size in pixels + array pixels_; //!< Plot size in pixels bool color_overlaps_; //!< Show overlapping cells? int level_; //!< Plot universe level }; @@ -171,7 +172,7 @@ T PlotBase::get_map() const { Particle p; p.r() = xyz; p.u() = dir; - p.coord_[0].universe = model::root_universe; + p.coord(0).universe = model::root_universe; int level = level_; int j{}; @@ -180,10 +181,10 @@ T PlotBase::get_map() const { p.r()[out_i] = xyz[out_i] - out_pixel * y; for (int x = 0; x < width; x++) { p.r()[in_i] = xyz[in_i] + in_pixel * x; - p.n_coord_ = 1; + p.n_coord() = 1; // local variables bool found_cell = exhaustive_find_cell(p); - j = p.n_coord_ - 1; + j = p.n_coord() - 1; if (level >= 0) { j = level; } if (found_cell) { data.set_value(y, x, p, j); @@ -230,7 +231,7 @@ public: RGBColor meshlines_color_; //!< Color of meshlines on the plot RGBColor not_found_ {WHITE}; //!< Plot background color RGBColor overlap_color_ {RED}; //!< Plot overlap color - std::vector colors_; //!< Plot colors + vector colors_; //!< Plot colors std::string path_plot_; //!< Plot output filename }; diff --git a/include/openmc/position.h b/include/openmc/position.h index 26cd6bb3f..ff258d0de 100644 --- a/include/openmc/position.h +++ b/include/openmc/position.h @@ -1,11 +1,12 @@ #ifndef OPENMC_POSITION_H #define OPENMC_POSITION_H -#include #include // for sqrt #include #include // for out_of_range -#include + +#include "openmc/array.h" +#include "openmc/vector.h" namespace openmc { @@ -18,8 +19,8 @@ struct Position { Position() = default; Position(double x_, double y_, double z_) : x{x_}, y{y_}, z{z_} { }; Position(const double xyz[]) : x{xyz[0]}, y{xyz[1]}, z{xyz[2]} { }; - Position(const std::vector& xyz) : x{xyz[0]}, y{xyz[1]}, z{xyz[2]} { }; - Position(const std::array& xyz) : x{xyz[0]}, y{xyz[1]}, z{xyz[2]} { }; + Position(const vector& xyz) : x {xyz[0]}, y {xyz[1]}, z {xyz[2]} {}; + Position(const array& xyz) : x {xyz[0]}, y {xyz[1]}, z {xyz[2]} {}; // Unary operators Position& operator+=(Position); @@ -81,7 +82,7 @@ struct Position { Position reflect(Position n) const; //! Rotate the position based on a rotation matrix - Position rotate(const std::vector& rotation) const; + Position rotate(const vector& rotation) const; // Data members double x = 0.; diff --git a/include/openmc/reaction.h b/include/openmc/reaction.h index d1e3d6f82..a597e6237 100644 --- a/include/openmc/reaction.h +++ b/include/openmc/reaction.h @@ -5,12 +5,12 @@ #define OPENMC_REACTION_H #include -#include #include #include "hdf5.h" #include "openmc/reaction_product.h" +#include "openmc/vector.h" namespace openmc { @@ -25,7 +25,7 @@ public: //! Construct reaction from HDF5 data //! \param[in] group HDF5 group containing reaction data //! \param[in] temperatures Desired temperatures for cross sections - explicit Reaction(hid_t group, const std::vector& temperatures); + explicit Reaction(hid_t group, const vector& temperatures); //! \brief Calculate reaction rate based on group-wise flux distribution // @@ -35,20 +35,20 @@ public: //! \param[in] grid Nuclide energy grid //! \return Reaction rate double collapse_rate(gsl::index i_temp, gsl::span energy, - gsl::span flux, const std::vector& grid) const; + gsl::span flux, const vector& grid) const; //! Cross section at a single temperature struct TemperatureXS { int threshold; - std::vector value; + vector value; }; int mt_; //!< ENDF MT value double q_value_; //!< Reaction Q value in [eV] bool scatter_in_cm_; //!< scattering system in center-of-mass? bool redundant_; //!< redundant reaction? - std::vector xs_; //!< Cross section at each temperature - std::vector products_; //!< Reaction products + vector xs_; //!< Cross section at each temperature + vector products_; //!< Reaction products }; //============================================================================== diff --git a/include/openmc/reaction_product.h b/include/openmc/reaction_product.h index c842b6f96..2c0a703dc 100644 --- a/include/openmc/reaction_product.h +++ b/include/openmc/reaction_product.h @@ -4,14 +4,13 @@ #ifndef OPENMC_REACTION_PRODUCT_H #define OPENMC_REACTION_PRODUCT_H -#include // for unique_ptr -#include // for vector - #include "hdf5.h" #include "openmc/angle_energy.h" #include "openmc/endf.h" +#include "openmc/memory.h" // for unique_ptr #include "openmc/particle.h" +#include "openmc/vector.h" // for vector namespace openmc { @@ -32,7 +31,7 @@ public: total // Delayed emission of secondary particle }; - using Secondary = std::unique_ptr; + using Secondary = unique_ptr; //! Construct reaction product from HDF5 data //! \param[in] group HDF5 group containing data @@ -45,12 +44,12 @@ public: //! \param[inout] seed Pseudorandom seed pointer void sample(double E_in, double& E_out, double& mu, uint64_t* seed) const; - Particle::Type particle_; //!< Particle type + ParticleType particle_; //!< Particle type EmissionMode emission_mode_; //!< Emission mode double decay_rate_; //!< Decay rate (for delayed neutron precursors) in [1/s] - std::unique_ptr yield_; //!< Yield as a function of energy - std::vector applicability_; //!< Applicability of distribution - std::vector distribution_; //!< Secondary angle-energy distribution + unique_ptr yield_; //!< Yield as a function of energy + vector applicability_; //!< Applicability of distribution + vector distribution_; //!< Secondary angle-energy distribution }; } // namespace opemc diff --git a/include/openmc/scattdata.h b/include/openmc/scattdata.h index aa91d5688..bc1700319 100644 --- a/include/openmc/scattdata.h +++ b/include/openmc/scattdata.h @@ -4,11 +4,10 @@ #ifndef OPENMC_SCATTDATA_H #define OPENMC_SCATTDATA_H -#include - #include "xtensor/xtensor.hpp" #include "openmc/constants.h" +#include "openmc/vector.h" namespace openmc { @@ -32,12 +31,10 @@ class ScattData { const double_2dvec& in_mult); //! \brief Combines microscopic ScattDatas into a macroscopic one. - void - base_combine(size_t max_order, size_t order_dim, - const std::vector& those_scatts, - const std::vector& scalars, xt::xtensor& in_gmin, - xt::xtensor& in_gmax, double_2dvec& sparse_mult, - double_3dvec& sparse_scatter); + void base_combine(size_t max_order, size_t order_dim, + const vector& those_scatts, const vector& scalars, + xt::xtensor& in_gmin, xt::xtensor& in_gmax, + double_2dvec& sparse_mult, double_3dvec& sparse_scatter); public: @@ -85,9 +82,8 @@ class ScattData { //! //! @param those_scatts Microscopic objects to combine. //! @param scalars Scalars to multiply the microscopic data by. - virtual void - combine(const std::vector& those_scatts, - const std::vector& scalars) = 0; + virtual void combine(const vector& those_scatts, + const vector& scalars) = 0; //! \brief Getter for the dimensionality of the scattering order. //! @@ -151,9 +147,8 @@ class ScattDataLegendre: public ScattData { init(const xt::xtensor& in_gmin, const xt::xtensor& in_gmax, const double_2dvec& in_mult, const double_3dvec& coeffs); - void - combine(const std::vector& those_scatts, - const std::vector& scalars); + void combine( + const vector& those_scatts, const vector& scalars); //! \brief Find the maximal value of the angular distribution to use as a // bounding box with rejection sampling. @@ -192,9 +187,8 @@ class ScattDataHistogram: public ScattData { init(const xt::xtensor& in_gmin, const xt::xtensor& in_gmax, const double_2dvec& in_mult, const double_3dvec& coeffs); - void - combine(const std::vector& those_scatts, - const std::vector& scalars); + void combine( + const vector& those_scatts, const vector& scalars); double calc_f(int gin, int gout, double mu); @@ -233,9 +227,8 @@ class ScattDataTabular: public ScattData { init(const xt::xtensor& in_gmin, const xt::xtensor& in_gmax, const double_2dvec& in_mult, const double_3dvec& coeffs); - void - combine(const std::vector& those_scatts, - const std::vector& scalars); + void combine( + const vector& those_scatts, const vector& scalars); double calc_f(int gin, int gout, double mu); diff --git a/include/openmc/secondary_correlated.h b/include/openmc/secondary_correlated.h index ac568f689..46910c507 100644 --- a/include/openmc/secondary_correlated.h +++ b/include/openmc/secondary_correlated.h @@ -4,14 +4,13 @@ #ifndef OPENMC_SECONDARY_CORRELATED_H #define OPENMC_SECONDARY_CORRELATED_H -#include - #include "hdf5.h" #include "xtensor/xtensor.hpp" #include "openmc/angle_energy.h" -#include "openmc/endf.h" #include "openmc/distribution.h" +#include "openmc/endf.h" +#include "openmc/vector.h" namespace openmc { @@ -29,7 +28,7 @@ public: xt::xtensor e_out; //!< Outgoing energies [eV] xt::xtensor p; //!< Probability density xt::xtensor c; //!< Cumulative distribution - std::vector> angle; //!< Angle distribution + vector> angle; //!< Angle distribution }; explicit CorrelatedAngleEnergy(hid_t group); @@ -43,19 +42,20 @@ public: uint64_t* seed) const override; // energy property - std::vector& energy() { return energy_; } - const std::vector& energy() const { return energy_; } + vector& energy() { return energy_; } + const vector& energy() const { return energy_; } // distribution property - std::vector& distribution() { return distribution_; } - const std::vector& distribution() const { return distribution_; } + vector& distribution() { return distribution_; } + const vector& distribution() const { return distribution_; } + private: int n_region_; //!< Number of interpolation regions - std::vector breakpoints_; //!< Breakpoints between regions - std::vector interpolation_; //!< Interpolation laws - std::vector energy_; //!< Energies [eV] at which distributions - //!< are tabulated - std::vector distribution_; //!< Distribution at each energy + vector breakpoints_; //!< Breakpoints between regions + vector interpolation_; //!< Interpolation laws + vector energy_; //!< Energies [eV] at which distributions + //!< are tabulated + vector distribution_; //!< Distribution at each energy }; } // namespace openmc diff --git a/include/openmc/secondary_kalbach.h b/include/openmc/secondary_kalbach.h index 0864367c0..ea9b8199a 100644 --- a/include/openmc/secondary_kalbach.h +++ b/include/openmc/secondary_kalbach.h @@ -4,14 +4,13 @@ #ifndef OPENMC_SECONDARY_KALBACH_H #define OPENMC_SECONDARY_KALBACH_H -#include - #include "hdf5.h" #include "xtensor/xtensor.hpp" #include "openmc/angle_energy.h" #include "openmc/constants.h" #include "openmc/endf.h" +#include "openmc/vector.h" namespace openmc { @@ -45,11 +44,11 @@ private: }; int n_region_; //!< Number of interpolation regions - std::vector breakpoints_; //!< Breakpoints between regions - std::vector interpolation_; //!< Interpolation laws - std::vector energy_; //!< Energies [eV] at which distributions - //!< are tabulated - std::vector distribution_; //!< Distribution at each energy + vector breakpoints_; //!< Breakpoints between regions + vector interpolation_; //!< Interpolation laws + vector energy_; //!< Energies [eV] at which distributions + //!< are tabulated + vector distribution_; //!< Distribution at each energy }; } // namespace openmc diff --git a/include/openmc/secondary_thermal.h b/include/openmc/secondary_thermal.h index 6e1768f46..9848c37fe 100644 --- a/include/openmc/secondary_thermal.h +++ b/include/openmc/secondary_thermal.h @@ -7,12 +7,11 @@ #include "openmc/angle_energy.h" #include "openmc/endf.h" #include "openmc/secondary_correlated.h" +#include "openmc/vector.h" #include #include "xtensor/xtensor.hpp" -#include - namespace openmc { //============================================================================== @@ -70,7 +69,8 @@ public: // //! \param[in] group HDF5 group //! \param[in] energy Energies at which cosines are tabulated - explicit IncoherentElasticAEDiscrete(hid_t group, const std::vector& energy); + explicit IncoherentElasticAEDiscrete( + hid_t group, const vector& energy); //! Sample distribution for an angle and energy //! \param[in] E_in Incoming energy in [eV] @@ -80,7 +80,7 @@ public: void sample(double E_in, double& E_out, double& mu, uint64_t* seed) const override; private: - const std::vector& energy_; //!< Energies at which cosines are tabulated + const vector& energy_; //!< Energies at which cosines are tabulated xt::xtensor mu_out_; //!< Cosines for each incident energy }; @@ -94,7 +94,8 @@ public: // //! \param[in] group HDF5 group //! \param[in] energy Incident energies at which distributions are tabulated - explicit IncoherentInelasticAEDiscrete(hid_t group, const std::vector& energy); + explicit IncoherentInelasticAEDiscrete( + hid_t group, const vector& energy); //! Sample distribution for an angle and energy //! \param[in] E_in Incoming energy in [eV] @@ -104,7 +105,7 @@ public: void sample(double E_in, double& E_out, double& mu, uint64_t* seed) const override; private: - const std::vector& energy_; //!< Incident energies + const vector& energy_; //!< Incident energies xt::xtensor energy_out_; //!< Outgoing energies for each incident energy xt::xtensor mu_out_; //!< Outgoing cosines for each incident/outgoing energy bool skewed_; //!< Whether outgoing energy distribution is skewed @@ -138,9 +139,9 @@ private: xt::xtensor mu; //!< Equiprobable angles at each outgoing energy }; - std::vector energy_; //!< Incident energies - std::vector distribution_; //!< Secondary angle-energy at - //!< each incident energy + vector energy_; //!< Incident energies + vector distribution_; //!< Secondary angle-energy at + //!< each incident energy }; diff --git a/include/openmc/secondary_uncorrelated.h b/include/openmc/secondary_uncorrelated.h index 673a299dc..58527047d 100644 --- a/include/openmc/secondary_uncorrelated.h +++ b/include/openmc/secondary_uncorrelated.h @@ -4,14 +4,13 @@ #ifndef OPENMC_SECONDARY_UNCORRELATED_H #define OPENMC_SECONDARY_UNCORRELATED_H -#include -#include - #include "hdf5.h" #include "openmc/angle_energy.h" #include "openmc/distribution_angle.h" #include "openmc/distribution_energy.h" +#include "openmc/memory.h" +#include "openmc/vector.h" namespace openmc { @@ -37,7 +36,7 @@ public: AngleDistribution& angle() { return angle_; } private: AngleDistribution angle_; //!< Angle distribution - std::unique_ptr energy_; //!< Energy distribution + unique_ptr energy_; //!< Energy distribution }; } // namespace openmc diff --git a/include/openmc/settings.h b/include/openmc/settings.h index 85468a733..384f629b0 100644 --- a/include/openmc/settings.h +++ b/include/openmc/settings.h @@ -4,15 +4,15 @@ //! \file settings.h //! \brief Settings for OpenMC -#include #include #include #include -#include #include "pugixml.hpp" +#include "openmc/array.h" #include "openmc/constants.h" +#include "openmc/vector.h" namespace openmc { @@ -75,7 +75,8 @@ extern "C" int64_t n_particles; //!< number of particles per genera extern int64_t max_particles_in_flight; //!< Max num. event-based particles in flight extern ElectronTreatment electron_treatment; //!< how to treat secondary electrons -extern std::array energy_cutoff; //!< Energy cutoff in [eV] for each particle type +extern array + energy_cutoff; //!< Energy cutoff in [eV] for each particle type extern int legendre_to_tabular_points; //!< number of points to convert Legendres extern int max_order; //!< Maximum Legendre order for multigroup data extern int n_log_bins; //!< number of bins for logarithmic energy grid @@ -84,7 +85,8 @@ extern int n_max_batches; //!< Maximum number of batches extern ResScatMethod res_scat_method; //!< resonance upscattering method extern double res_scat_energy_min; //!< Min energy in [eV] for res. upscattering extern double res_scat_energy_max; //!< Max energy in [eV] for res. upscattering -extern std::vector res_scat_nuclides; //!< Nuclides using res. upscattering treatment +extern vector + res_scat_nuclides; //!< Nuclides using res. upscattering treatment extern RunMode run_mode; //!< Run mode (eigenvalue, fixed src, etc.) extern std::unordered_set sourcepoint_batch; //!< Batches when source should be written extern std::unordered_set statepoint_batch; //!< Batches when state should be written @@ -93,11 +95,13 @@ extern int64_t max_surface_particles; //!< maximum number of particles to be extern TemperatureMethod temperature_method; //!< method for choosing temperatures extern double temperature_tolerance; //!< Tolerance in [K] on choosing temperatures extern double temperature_default; //!< Default T in [K] -extern std::array temperature_range; //!< Min/max T in [K] over which to load xs +extern array + temperature_range; //!< Min/max T in [K] over which to load xs extern int trace_batch; //!< Batch to trace particle on extern int trace_gen; //!< Generation to trace particle on extern int64_t trace_particle; //!< Particle ID to enable trace on -extern std::vector> track_identifiers; //!< Particle numbers for writing tracks +extern vector> + track_identifiers; //!< Particle numbers for writing tracks extern int trigger_batch_interval; //!< Batch interval for triggers extern "C" int verbosity; //!< How verbose to make output extern double weight_cutoff; //!< Weight cutoff for Russian roulette diff --git a/include/openmc/shared_array.h b/include/openmc/shared_array.h index bdce58fab..588b8812b 100644 --- a/include/openmc/shared_array.h +++ b/include/openmc/shared_array.h @@ -4,8 +4,7 @@ //! \file shared_array.h //! \brief Shared array data structure -#include - +#include "openmc/memory.h" namespace openmc { @@ -38,7 +37,7 @@ public: //! space for SharedArray(int64_t capacity) : capacity_(capacity) { - data_ = std::make_unique(capacity); + data_ = make_unique(capacity); } //========================================================================== @@ -55,7 +54,7 @@ public: //! \param capacity The number of elements to allocate in the container void reserve(int64_t capacity) { - data_ = std::make_unique(capacity); + data_ = make_unique(capacity); capacity_ = capacity; } @@ -120,7 +119,7 @@ private: //========================================================================== // Data members - std::unique_ptr data_; //!< An RAII handle to the elements + unique_ptr data_; //!< An RAII handle to the elements int64_t size_ {0}; //!< The current number of elements int64_t capacity_ {0}; //!< The total space allocated for elements diff --git a/include/openmc/simulation.h b/include/openmc/simulation.h index 32e2c6730..e7f8eb758 100644 --- a/include/openmc/simulation.h +++ b/include/openmc/simulation.h @@ -6,9 +6,9 @@ #include "openmc/mesh.h" #include "openmc/particle.h" +#include "openmc/vector.h" #include -#include namespace openmc { @@ -42,8 +42,8 @@ extern int64_t work_per_rank; //!< number of particles per MPI rank extern const RegularMesh* entropy_mesh; extern const RegularMesh* ufs_mesh; -extern std::vector k_generation; -extern std::vector work_index; +extern vector k_generation; +extern vector work_index; } // namespace simulation @@ -69,9 +69,6 @@ void initialize_generation(); //! Full initialization of a particle history void initialize_history(Particle& p, int64_t index_source); -//! Helper function for initialize_history() that is called independently elsewhere -void initialize_history_partial(Particle& p); - //! Finalize a batch //! //! Handles synchronization and accumulation of tallies, calculation of Shannon diff --git a/include/openmc/source.h b/include/openmc/source.h index 12e815699..5cbccf272 100644 --- a/include/openmc/source.h +++ b/include/openmc/source.h @@ -4,14 +4,13 @@ #ifndef OPENMC_SOURCE_H #define OPENMC_SOURCE_H -#include -#include - #include "pugixml.hpp" #include "openmc/distribution_multi.h" #include "openmc/distribution_spatial.h" +#include "openmc/memory.h" #include "openmc/particle.h" +#include "openmc/vector.h" namespace openmc { @@ -23,7 +22,7 @@ class Source; namespace model { -extern std::vector> external_sources; +extern vector> external_sources; } // namespace model @@ -36,7 +35,7 @@ public: virtual ~Source() = default; // Methods that must be implemented - virtual Particle::Bank sample(uint64_t* seed) const = 0; + virtual SourceSite sample(uint64_t* seed) const = 0; // Methods that can be overridden virtual double strength() const { return 1.0; } @@ -55,10 +54,10 @@ public: //! Sample from the external source distribution //! \param[inout] seed Pseudorandom seed pointer //! \return Sampled site - Particle::Bank sample(uint64_t* seed) const override; + SourceSite sample(uint64_t* seed) const override; // Properties - Particle::Type particle_type() const { return particle_; } + ParticleType particle_type() const { return particle_; } double strength() const override { return strength_; } // Make observing pointers available @@ -67,7 +66,7 @@ public: Distribution* energy() const { return energy_.get(); } private: - Particle::Type particle_ {Particle::Type::neutron}; //!< Type of particle emitted + ParticleType particle_ {ParticleType::neutron}; //!< Type of particle emitted double strength_ {1.0}; //!< Source strength UPtrSpace space_; //!< Spatial distribution UPtrAngle angle_; //!< Angular distribution @@ -84,10 +83,10 @@ public: explicit FileSource(std::string path); // Methods - Particle::Bank sample(uint64_t* seed) const override; + SourceSite sample(uint64_t* seed) const override; private: - std::vector sites_; //!< Source sites from a file + vector sites_; //!< Source sites from a file }; //============================================================================== @@ -101,7 +100,7 @@ public: ~CustomSourceWrapper(); // Defer implementation to custom source library - Particle::Bank sample(uint64_t* seed) const override + SourceSite sample(uint64_t* seed) const override { return custom_source_->sample(seed); } @@ -109,10 +108,10 @@ public: double strength() const override { return custom_source_->strength(); } private: void* shared_library_; //!< library from dlopen - std::unique_ptr custom_source_; + unique_ptr custom_source_; }; -typedef std::unique_ptr create_custom_source_t(std::string parameters); +typedef unique_ptr create_custom_source_t(std::string parameters); //============================================================================== // Functions @@ -125,7 +124,7 @@ extern "C" void initialize_source(); //! source strength //! \param[inout] seed Pseudorandom seed pointer //! \return Sampled source site -Particle::Bank sample_external_source(uint64_t* seed); +SourceSite sample_external_source(uint64_t* seed); void free_memory_source(); diff --git a/include/openmc/state_point.h b/include/openmc/state_point.h index f93fa00aa..5ada2bf88 100644 --- a/include/openmc/state_point.h +++ b/include/openmc/state_point.h @@ -2,20 +2,21 @@ #define OPENMC_STATE_POINT_H #include -#include #include "hdf5.h" #include "openmc/capi.h" #include "openmc/particle.h" +#include "openmc/vector.h" namespace openmc { void load_state_point(); -std::vector calculate_surf_source_size(); +vector calculate_surf_source_size(); void write_source_point(const char* filename, bool surf_source_bank = false); void write_source_bank(hid_t group_id, bool surf_source_bank); -void read_source_bank(hid_t group_id, std::vector& sites, bool distribute); +void read_source_bank( + hid_t group_id, vector& sites, bool distribute); void write_tally_results_nr(hid_t file_id); void restart_set_keff(); void write_unstructured_mesh_results(); diff --git a/include/openmc/string_utils.h b/include/openmc/string_utils.h index a60fd06a8..6b4c69d48 100644 --- a/include/openmc/string_utils.h +++ b/include/openmc/string_utils.h @@ -2,7 +2,8 @@ #define OPENMC_STRING_UTILS_H #include -#include + +#include "openmc/vector.h" namespace openmc { @@ -16,7 +17,7 @@ void to_lower(std::string& str); int word_count(std::string const& str); -std::vector split(const std::string& in); +vector split(const std::string& in); bool ends_with(const std::string& value, const std::string& ending); diff --git a/include/openmc/surface.h b/include/openmc/surface.h index def7cb1eb..5a8a88aa4 100644 --- a/include/openmc/surface.h +++ b/include/openmc/surface.h @@ -1,20 +1,20 @@ #ifndef OPENMC_SURFACE_H #define OPENMC_SURFACE_H -#include // for unique_ptr #include // For numeric_limits #include #include -#include #include "hdf5.h" #include "pugixml.hpp" +#include "dagmc.h" #include "openmc/boundary_condition.h" #include "openmc/constants.h" +#include "openmc/memory.h" // for unique_ptr #include "openmc/particle.h" #include "openmc/position.h" -#include "dagmc.h" +#include "openmc/vector.h" namespace openmc { @@ -26,7 +26,7 @@ class Surface; namespace model { extern std::unordered_map surface_map; - extern std::vector> surfaces; + extern vector> surfaces; } // namespace model //============================================================================== diff --git a/include/openmc/tallies/derivative.h b/include/openmc/tallies/derivative.h index 53e6925ba..d3a7b8b20 100644 --- a/include/openmc/tallies/derivative.h +++ b/include/openmc/tallies/derivative.h @@ -2,9 +2,9 @@ #define OPENMC_TALLIES_DERIVATIVE_H #include "openmc/particle.h" +#include "openmc/vector.h" #include -#include #include "pugixml.hpp" @@ -71,7 +71,7 @@ namespace openmc { namespace model { extern std::unordered_map tally_deriv_map; -extern std::vector tally_derivs; +extern vector tally_derivs; } // namespace model } // namespace openmc diff --git a/include/openmc/tallies/filter.h b/include/openmc/tallies/filter.h index cde55fa7b..9620632a3 100644 --- a/include/openmc/tallies/filter.h +++ b/include/openmc/tallies/filter.h @@ -2,19 +2,18 @@ #define OPENMC_TALLIES_FILTER_H #include -#include #include #include -#include +#include "pugixml.hpp" #include #include "openmc/constants.h" #include "openmc/hdf5_interface.h" +#include "openmc/memory.h" #include "openmc/particle.h" #include "openmc/tallies/filter_match.h" -#include "pugixml.hpp" - +#include "openmc/vector.h" namespace openmc { @@ -120,7 +119,7 @@ private: namespace model { extern "C" int32_t n_filters; extern std::unordered_map filter_map; - extern std::vector> tally_filters; + extern vector> tally_filters; } //============================================================================== diff --git a/include/openmc/tallies/filter_azimuthal.h b/include/openmc/tallies/filter_azimuthal.h index 7259f0f00..d1c468233 100644 --- a/include/openmc/tallies/filter_azimuthal.h +++ b/include/openmc/tallies/filter_azimuthal.h @@ -1,8 +1,8 @@ #ifndef OPENMC_TALLIES_FILTER_AZIMUTHAL_H #define OPENMC_TALLIES_FILTER_AZIMUTHAL_H +#include "openmc/vector.h" #include -#include #include @@ -45,7 +45,7 @@ private: //---------------------------------------------------------------------------- // Data members - std::vector bins_; + vector bins_; }; } // namespace openmc diff --git a/include/openmc/tallies/filter_cell.h b/include/openmc/tallies/filter_cell.h index 83114ea12..e4180148f 100644 --- a/include/openmc/tallies/filter_cell.h +++ b/include/openmc/tallies/filter_cell.h @@ -3,11 +3,11 @@ #include #include -#include #include #include "openmc/tallies/filter.h" +#include "openmc/vector.h" namespace openmc { @@ -40,7 +40,7 @@ public: //---------------------------------------------------------------------------- // Accessors - const std::vector& cells() const { return cells_; } + const vector& cells() const { return cells_; } void set_cells(gsl::span cells); @@ -49,7 +49,7 @@ protected: // Data members //! The indices of the cells binned by this filter. - std::vector cells_; + vector cells_; //! A map from cell indices to filter bin indices. std::unordered_map map_; diff --git a/include/openmc/tallies/filter_cell_instance.h b/include/openmc/tallies/filter_cell_instance.h index a406e73d7..dee9b8bea 100644 --- a/include/openmc/tallies/filter_cell_instance.h +++ b/include/openmc/tallies/filter_cell_instance.h @@ -3,13 +3,12 @@ #include #include -#include #include #include "openmc/cell.h" #include "openmc/tallies/filter.h" - +#include "openmc/vector.h" namespace openmc { @@ -43,7 +42,7 @@ public: //---------------------------------------------------------------------------- // Accessors - const std::vector& cell_instances() const { return cell_instances_; } + const vector& cell_instances() const { return cell_instances_; } void set_cell_instances(gsl::span instances); @@ -52,7 +51,7 @@ private: // Data members //! The indices of the cells binned by this filter. - std::vector cell_instances_; + vector cell_instances_; //! A map from cell/instance indices to filter bin indices. std::unordered_map map_; diff --git a/include/openmc/tallies/filter_collision.h b/include/openmc/tallies/filter_collision.h index 45e6d9405..1b23bd440 100644 --- a/include/openmc/tallies/filter_collision.h +++ b/include/openmc/tallies/filter_collision.h @@ -1,11 +1,11 @@ #ifndef OPENMC_TALLIES_FILTER_COLLISIONS_H #define OPENMC_TALLIES_FILTER_COLLISIONS_H -#include #include #include #include "openmc/tallies/filter.h" +#include "openmc/vector.h" namespace openmc { @@ -37,14 +37,14 @@ public: //---------------------------------------------------------------------------- // Accessors - const std::vector& bins() const { return bins_; } + const vector& bins() const { return bins_; } void set_bins(gsl::span bins); protected: //---------------------------------------------------------------------------- // Data members - std::vector bins_; + vector bins_; std::unordered_map map_; diff --git a/include/openmc/tallies/filter_delayedgroup.h b/include/openmc/tallies/filter_delayedgroup.h index 64bdd3398..63987e339 100644 --- a/include/openmc/tallies/filter_delayedgroup.h +++ b/include/openmc/tallies/filter_delayedgroup.h @@ -1,11 +1,10 @@ #ifndef OPENMC_TALLIES_FILTER_DELAYEDGROUP_H #define OPENMC_TALLIES_FILTER_DELAYEDGROUP_H -#include - #include #include "openmc/tallies/filter.h" +#include "openmc/vector.h" namespace openmc { @@ -41,7 +40,7 @@ public: //---------------------------------------------------------------------------- // Accessors - const std::vector& groups() const { return groups_; } + const vector& groups() const { return groups_; } void set_groups(gsl::span groups); @@ -49,7 +48,7 @@ private: //---------------------------------------------------------------------------- // Data members - std::vector groups_; + vector groups_; }; } // namespace openmc diff --git a/include/openmc/tallies/filter_energy.h b/include/openmc/tallies/filter_energy.h index 3eac0a9c1..2db0231e2 100644 --- a/include/openmc/tallies/filter_energy.h +++ b/include/openmc/tallies/filter_energy.h @@ -1,11 +1,10 @@ #ifndef OPENMC_TALLIES_FILTER_ENERGY_H #define OPENMC_TALLIES_FILTER_ENERGY_H -#include - #include #include "openmc/tallies/filter.h" +#include "openmc/vector.h" namespace openmc { @@ -38,7 +37,7 @@ public: //---------------------------------------------------------------------------- // Accessors - const std::vector& bins() const { return bins_; } + const vector& bins() const { return bins_; } void set_bins(gsl::span bins); bool matches_transport_groups() const { return matches_transport_groups_; } @@ -47,7 +46,7 @@ protected: //---------------------------------------------------------------------------- // Data members - std::vector bins_; + vector bins_; //! True if transport group number can be used directly to get bin number bool matches_transport_groups_ {false}; diff --git a/include/openmc/tallies/filter_energyfunc.h b/include/openmc/tallies/filter_energyfunc.h index 562d7f36d..5c131ba69 100644 --- a/include/openmc/tallies/filter_energyfunc.h +++ b/include/openmc/tallies/filter_energyfunc.h @@ -1,9 +1,8 @@ #ifndef OPENMC_TALLIES_FILTER_ENERGYFUNC_H #define OPENMC_TALLIES_FILTER_ENERGYFUNC_H -#include - #include "openmc/tallies/filter.h" +#include "openmc/vector.h" namespace openmc { @@ -43,8 +42,8 @@ public: //---------------------------------------------------------------------------- // Accessors - const std::vector& energy() const { return energy_; } - const std::vector& y() const { return y_; } + const vector& energy() const { return energy_; } + const vector& y() const { return y_; } void set_data(gsl::span energy, gsl::span y); private: @@ -52,10 +51,10 @@ private: // Data members //! Incident neutron energy interpolation grid. - std::vector energy_; + vector energy_; //! Interpolant values. - std::vector y_; + vector y_; }; } // namespace openmc diff --git a/include/openmc/tallies/filter_match.h b/include/openmc/tallies/filter_match.h index a4ab2e407..b07656f17 100644 --- a/include/openmc/tallies/filter_match.h +++ b/include/openmc/tallies/filter_match.h @@ -11,8 +11,8 @@ namespace openmc { class FilterMatch { public: - std::vector bins_; - std::vector weights_; + vector bins_; + vector weights_; int i_bin_; bool bins_present_ {false}; }; diff --git a/include/openmc/tallies/filter_material.h b/include/openmc/tallies/filter_material.h index 71396cf2b..65bfce04e 100644 --- a/include/openmc/tallies/filter_material.h +++ b/include/openmc/tallies/filter_material.h @@ -3,11 +3,11 @@ #include #include -#include #include #include "openmc/tallies/filter.h" +#include "openmc/vector.h" namespace openmc { @@ -40,9 +40,9 @@ public: //---------------------------------------------------------------------------- // Accessors - std::vector& materials() { return materials_; } + vector& materials() { return materials_; } - const std::vector& materials() const { return materials_; } + const vector& materials() const { return materials_; } void set_materials(gsl::span materials); @@ -51,7 +51,7 @@ private: // Data members //! The indices of the materials binned by this filter. - std::vector materials_; + vector materials_; //! A map from material indices to filter bin indices. std::unordered_map map_; diff --git a/include/openmc/tallies/filter_mu.h b/include/openmc/tallies/filter_mu.h index 7f6f29e5f..cad5bad1f 100644 --- a/include/openmc/tallies/filter_mu.h +++ b/include/openmc/tallies/filter_mu.h @@ -1,11 +1,10 @@ #ifndef OPENMC_TALLIES_FILTER_MU_H #define OPENMC_TALLIES_FILTER_MU_H -#include - #include #include "openmc/tallies/filter.h" +#include "openmc/vector.h" namespace openmc { @@ -45,7 +44,7 @@ private: //---------------------------------------------------------------------------- // Data members - std::vector bins_; + vector bins_; }; } // namespace openmc diff --git a/include/openmc/tallies/filter_particle.h b/include/openmc/tallies/filter_particle.h index c7eb3ce41..da022b81e 100644 --- a/include/openmc/tallies/filter_particle.h +++ b/include/openmc/tallies/filter_particle.h @@ -1,10 +1,9 @@ #ifndef OPENMC_TALLIES_FILTER_PARTICLE_H #define OPENMC_TALLIES_FILTER_PARTICLE_H -#include - #include "openmc/particle.h" #include "openmc/tallies/filter.h" +#include "openmc/vector.h" namespace openmc { @@ -37,15 +36,15 @@ public: //---------------------------------------------------------------------------- // Accessors - const std::vector& particles() const { return particles_; } + const vector& particles() const { return particles_; } - void set_particles(gsl::span particles); + void set_particles(gsl::span particles); private: //---------------------------------------------------------------------------- // Data members - std::vector particles_; + vector particles_; }; } // namespace openmc diff --git a/include/openmc/tallies/filter_polar.h b/include/openmc/tallies/filter_polar.h index fd800e2ed..ecfbc6f9c 100644 --- a/include/openmc/tallies/filter_polar.h +++ b/include/openmc/tallies/filter_polar.h @@ -2,11 +2,11 @@ #define OPENMC_TALLIES_FILTER_POLAR_H #include -#include #include #include "openmc/tallies/filter.h" +#include "openmc/vector.h" namespace openmc { @@ -45,7 +45,7 @@ private: //---------------------------------------------------------------------------- // Data members - std::vector bins_; + vector bins_; }; } // namespace openmc diff --git a/include/openmc/tallies/filter_surface.h b/include/openmc/tallies/filter_surface.h index cf27024c5..28b510534 100644 --- a/include/openmc/tallies/filter_surface.h +++ b/include/openmc/tallies/filter_surface.h @@ -3,11 +3,11 @@ #include #include -#include #include #include "openmc/tallies/filter.h" +#include "openmc/vector.h" namespace openmc { @@ -47,7 +47,7 @@ private: // Data members //! The indices of the surfaces binned by this filter. - std::vector surfaces_; + vector surfaces_; //! A map from surface indices to filter bin indices. std::unordered_map map_; diff --git a/include/openmc/tallies/filter_universe.h b/include/openmc/tallies/filter_universe.h index 1dabf9671..dfdbb8cf9 100644 --- a/include/openmc/tallies/filter_universe.h +++ b/include/openmc/tallies/filter_universe.h @@ -3,11 +3,11 @@ #include #include -#include #include #include "openmc/tallies/filter.h" +#include "openmc/vector.h" namespace openmc { @@ -47,7 +47,7 @@ private: // Data members //! The indices of the universes binned by this filter. - std::vector universes_; + vector universes_; //! A map from universe indices to filter bin indices. std::unordered_map map_; diff --git a/include/openmc/tallies/tally.h b/include/openmc/tallies/tally.h index 1de372f3c..aaaff0e70 100644 --- a/include/openmc/tallies/tally.h +++ b/include/openmc/tallies/tally.h @@ -2,18 +2,18 @@ #define OPENMC_TALLIES_TALLY_H #include "openmc/constants.h" +#include "openmc/memory.h" // for unique_ptr #include "openmc/tallies/filter.h" #include "openmc/tallies/trigger.h" +#include "openmc/vector.h" #include #include "pugixml.hpp" #include "xtensor/xfixed.hpp" #include "xtensor/xtensor.hpp" -#include // for unique_ptr -#include #include -#include +#include namespace openmc { @@ -41,13 +41,13 @@ public: void set_scores(pugi::xml_node node); - void set_scores(const std::vector& scores); + void set_scores(const vector& scores); void set_nuclides(pugi::xml_node node); - void set_nuclides(const std::vector& nuclides); + void set_nuclides(const vector& nuclides); - const std::vector& filters() const {return filters_;} + const vector& filters() const { return filters_; } int32_t filters(int i) const {return filters_[i];} @@ -96,10 +96,10 @@ public: //! Number of realizations int n_realizations_ {0}; - std::vector scores_; //!< Filter integrands (e.g. flux, fission) + vector scores_; //!< Filter integrands (e.g. flux, fission) //! Index of each nuclide to be tallied. -1 indicates total material. - std::vector nuclides_ {-1}; + vector nuclides_ {-1}; //! True if this tally has a bin for every nuclide in the problem bool all_nuclides_ {false}; @@ -122,7 +122,7 @@ public: int energyout_filter_ {C_NONE}; int delayedgroup_filter_ {C_NONE}; - std::vector triggers_; + vector triggers_; int deriv_ {C_NONE}; //!< Index of a TallyDerivative object for diff tallies. @@ -130,10 +130,10 @@ private: //---------------------------------------------------------------------------- // Private data. - std::vector filters_; //!< Filter indices in global filters array + vector filters_; //!< Filter indices in global filters array //! Index strides assigned to each filter to support 1D indexing. - std::vector strides_; + vector strides_; int32_t n_filter_bins_ {0}; @@ -146,13 +146,13 @@ private: namespace model { extern std::unordered_map tally_map; - extern std::vector> tallies; - extern std::vector active_tallies; - extern std::vector active_analog_tallies; - extern std::vector active_tracklength_tallies; - extern std::vector active_collision_tallies; - extern std::vector active_meshsurf_tallies; - extern std::vector active_surface_tallies; + extern vector> tallies; + extern vector active_tallies; + extern vector active_analog_tallies; + extern vector active_tracklength_tallies; + extern vector active_collision_tallies; + extern vector active_meshsurf_tallies; + extern vector active_surface_tallies; } namespace simulation { diff --git a/include/openmc/tallies/tally_scoring.h b/include/openmc/tallies/tally_scoring.h index 20329e0c7..4510f725f 100644 --- a/include/openmc/tallies/tally_scoring.h +++ b/include/openmc/tallies/tally_scoring.h @@ -28,8 +28,8 @@ public: //! Construct an iterator over all filter bin combinations. // //! \param end if true, the returned iterator indicates the end of a loop. - FilterBinIter(const Tally& tally, bool end, - std::vector* particle_filter_matches); + FilterBinIter( + const Tally& tally, bool end, vector* particle_filter_matches); bool operator==(const FilterBinIter& other) const {return index_ == other.index_;} @@ -42,7 +42,7 @@ public: int index_ {1}; double weight_ {1.}; - std::vector& filter_matches_; + vector& filter_matches_; private: void compute_index_weight(); @@ -93,7 +93,7 @@ void score_tracklength_tally(Particle& p, double distance); // //! \param p The particle being tracked //! \param tallies A vector of tallies to score to -void score_surface_tally(Particle& p, const std::vector& tallies); +void score_surface_tally(Particle& p, const vector& tallies); } // namespace openmc diff --git a/include/openmc/thermal.h b/include/openmc/thermal.h index a18658fe3..d2db789e2 100644 --- a/include/openmc/thermal.h +++ b/include/openmc/thermal.h @@ -2,17 +2,17 @@ #define OPENMC_THERMAL_H #include -#include #include #include -#include #include "xtensor/xtensor.hpp" #include "openmc/angle_energy.h" #include "openmc/endf.h" #include "openmc/hdf5_interface.h" +#include "openmc/memory.h" #include "openmc/particle.h" +#include "openmc/vector.h" namespace openmc { @@ -24,7 +24,7 @@ class ThermalScattering; namespace data { extern std::unordered_map thermal_scatt_map; -extern std::vector> thermal_scatt; +extern vector> thermal_scatt; } //============================================================================== @@ -58,8 +58,9 @@ private: Reaction() { } // Data members - std::unique_ptr xs; //!< Cross section - std::unique_ptr distribution; //!< Secondary angle-energy distribution + unique_ptr xs; //!< Cross section + unique_ptr + distribution; //!< Secondary angle-energy distribution }; // Inelastic scattering data @@ -77,7 +78,7 @@ private: class ThermalScattering { public: - ThermalScattering(hid_t group, const std::vector& temperature); + ThermalScattering(hid_t group, const vector& temperature); //! Determine inelastic/elastic cross section at given energy //! @@ -103,11 +104,11 @@ public: std::string name_; //!< name of table, e.g. "c_H_in_H2O" double awr_; //!< weight of nucleus in neutron masses double energy_max_; //!< maximum energy for thermal scattering in [eV] - std::vector kTs_; //!< temperatures in [eV] (k*T) - std::vector nuclides_; //!< Valid nuclides + vector kTs_; //!< temperatures in [eV] (k*T) + vector nuclides_; //!< Valid nuclides //! cross sections and distributions at each temperature - std::vector data_; + vector data_; }; void free_memory_thermal(); diff --git a/include/openmc/vector.h b/include/openmc/vector.h new file mode 100644 index 000000000..a67eccc46 --- /dev/null +++ b/include/openmc/vector.h @@ -0,0 +1,23 @@ +#ifndef OPENMC_VECTOR_H +#define OPENMC_VECTOR_H + +/* + * In an implementation of OpenMC that offloads computations to an accelerator, + * we may need to provide replacements for standard library containers and + * algorithms that have no native implementations on the device of interest. + * Because some developers are currently in the process of creating such code, + * introducing the below typedef lessens the amount of rebase conflicts that + * happen as they rebase their code on OpenMC's develop branch. + * + * In an implementation of OpenMC that uses such an accelerator, we may remove + * the use of vector below and replace it with a custom implementation + * behaving as expected on the device. + */ + +#include + +namespace openmc { +using std::vector; +} + +#endif // OPENMC_VECTOR_H diff --git a/include/openmc/version.h.in b/include/openmc/version.h.in index a7cf51d04..995f20c3b 100644 --- a/include/openmc/version.h.in +++ b/include/openmc/version.h.in @@ -1,4 +1,4 @@ -#include +#include "openmc/array.h" namespace openmc { diff --git a/include/openmc/volume_calc.h b/include/openmc/volume_calc.h index 3258be9d6..2071411f8 100644 --- a/include/openmc/volume_calc.h +++ b/include/openmc/volume_calc.h @@ -1,15 +1,15 @@ #ifndef OPENMC_VOLUME_CALC_H #define OPENMC_VOLUME_CALC_H +#include "openmc/array.h" #include "openmc/position.h" #include "openmc/tallies/trigger.h" +#include "openmc/vector.h" #include "pugixml.hpp" #include "xtensor/xtensor.hpp" -#include #include -#include #include namespace openmc { @@ -23,10 +23,10 @@ class VolumeCalculation { public: // Aliases, types struct Result { - std::array volume; //!< Mean/standard deviation of volume - std::vector nuclides; //!< Index of nuclides - std::vector atoms; //!< Number of atoms for each nuclide - std::vector uncertainty; //!< Uncertainty on number of atoms + array volume; //!< Mean/standard deviation of volume + vector nuclides; //!< Index of nuclides + vector atoms; //!< Number of atoms for each nuclide + vector uncertainty; //!< Uncertainty on number of atoms int iterations; //!< Number of iterations needed to obtain the results }; // Results for a single domain @@ -39,13 +39,14 @@ public: //! average number densities of nuclides within the domain // //! \return Vector of results for each user-specified domain - std::vector execute() const; + vector execute() const; //! \brief Write volume calculation results to HDF5 file // //! \param[in] filename Path to HDF5 file to write //! \param[in] results Vector of results for each domain - void to_hdf5(const std::string& filename, const std::vector& results) const; + void to_hdf5( + const std::string& filename, const vector& results) const; // Tally filter and map types enum class TallyDomain { @@ -61,7 +62,7 @@ public: TriggerMetric trigger_type_ {TriggerMetric::not_active}; //!< Trigger metric for the volume calculation Position lower_left_; //!< Lower-left position of bounding box Position upper_right_; //!< Upper-right position of bounding box - std::vector domain_ids_; //!< IDs of domains to find volumes of + vector domain_ids_; //!< IDs of domains to find volumes of private: //! \brief Check whether a material has already been hit for a given domain. @@ -70,9 +71,7 @@ private: //! \param[in] i_material Index in global materials vector //! \param[in,out] indices Vector of material indices //! \param[in,out] hits Number of hits corresponding to each material - void check_hit(int i_material, std::vector& indices, - std::vector& hits) const; - + void check_hit(int i_material, vector& indices, vector& hits) const; }; //============================================================================== @@ -80,7 +79,7 @@ private: //============================================================================== namespace model { - extern std::vector volume_calcs; +extern vector volume_calcs; } //============================================================================== diff --git a/include/openmc/wmp.h b/include/openmc/wmp.h index 014ee7fe7..5b3104afc 100644 --- a/include/openmc/wmp.h +++ b/include/openmc/wmp.h @@ -4,11 +4,13 @@ #include "hdf5.h" #include "xtensor/xtensor.hpp" -#include #include #include #include +#include "openmc/array.h" +#include "openmc/vector.h" + namespace openmc { //======================================================================== @@ -27,7 +29,7 @@ constexpr int FIT_A {1}; // Absorption constexpr int FIT_F {2}; // Fission // Multipole HDF5 file version -constexpr std::array WMP_VERSION {1, 1}; +constexpr array WMP_VERSION {1, 1}; //======================================================================== // Windowed multipole data @@ -73,7 +75,7 @@ public: double inv_spacing_; //!< 1 / spacing in sqrt(E) space int fit_order_; //!< Order of the fit bool fissionable_; //!< Is the nuclide fissionable? - std::vector window_info_; // Information about a window + vector window_info_; // Information about a window xt::xtensor curvefit_; // Curve fit coefficients (window, poly order, reaction) xt::xtensor, 2> data_; //!< Poles and residues diff --git a/include/openmc/xml_interface.h b/include/openmc/xml_interface.h index 6ab8c148c..ddd92ad7e 100644 --- a/include/openmc/xml_interface.h +++ b/include/openmc/xml_interface.h @@ -4,12 +4,13 @@ #include // for size_t #include // for stringstream #include -#include #include "pugixml.hpp" #include "xtensor/xarray.hpp" #include "xtensor/xadapt.hpp" +#include "openmc/vector.h" + namespace openmc { inline bool @@ -23,9 +24,9 @@ std::string get_node_value(pugi::xml_node node, const char* name, bool get_node_value_bool(pugi::xml_node node, const char* name); -template -std::vector get_node_array(pugi::xml_node node, const char* name, - bool lowercase=false) +template +vector get_node_array( + pugi::xml_node node, const char* name, bool lowercase = false) { // Get value of node attribute/child std::string s {get_node_value(node, name, lowercase)}; @@ -33,7 +34,7 @@ std::vector get_node_array(pugi::xml_node node, const char* name, // Read values one by one into vector std::stringstream iss {s}; T value; - std::vector values; + vector values; while (iss >> value) values.push_back(value); @@ -44,8 +45,8 @@ template xt::xarray get_node_xarray(pugi::xml_node node, const char* name, bool lowercase=false) { - std::vector v = get_node_array(node, name, lowercase); - std::vector shape = {v.size()}; + vector v = get_node_array(node, name, lowercase); + vector shape = {v.size()}; return xt::adapt(v, shape); } diff --git a/include/openmc/xsdata.h b/include/openmc/xsdata.h index 64d0c01cf..cf6d8058b 100644 --- a/include/openmc/xsdata.h +++ b/include/openmc/xsdata.h @@ -4,14 +4,12 @@ #ifndef OPENMC_XSDATA_H #define OPENMC_XSDATA_H -#include -#include - #include "xtensor/xtensor.hpp" #include "openmc/hdf5_interface.h" +#include "openmc/memory.h" #include "openmc/scattdata.h" - +#include "openmc/vector.h" namespace openmc { @@ -99,7 +97,7 @@ class XsData { // [angle][incoming group][outgoing group][delayed group] xt::xtensor chi_delayed; // scatter has the following dimensions: [angle] - std::vector> scatter; + vector> scatter; XsData() = default; @@ -138,8 +136,8 @@ class XsData { //! //! @param micros Microscopic objects to combine. //! @param scalars Scalars to multiply the microscopic data by. - void - combine(const std::vector& those_xs, const std::vector& scalars); + void combine( + const vector& those_xs, const vector& scalars); //! \brief Checks to see if this and that are able to be combined //! diff --git a/openmc/lib/core.py b/openmc/lib/core.py index 6d9a680e3..e740e2869 100644 --- a/openmc/lib/core.py +++ b/openmc/lib/core.py @@ -11,7 +11,7 @@ from .error import _error_handler import openmc.lib -class _Bank(Structure): +class _SourceSite(Structure): _fields_ = [('r', c_double*3), ('u', c_double*3), ('E', c_double), @@ -73,7 +73,7 @@ _run_linsolver_argtypes = [_array_1d_dble, _array_1d_dble, _array_1d_dble, c_double] _dll.openmc_run_linsolver.argtypes = _run_linsolver_argtypes _dll.openmc_run_linsolver.restype = c_int -_dll.openmc_source_bank.argtypes = [POINTER(POINTER(_Bank)), POINTER(c_int64)] +_dll.openmc_source_bank.argtypes = [POINTER(POINTER(_SourceSite)), POINTER(c_int64)] _dll.openmc_source_bank.restype = c_int _dll.openmc_source_bank.errcheck = _error_handler _dll.openmc_simulation_init.restype = c_int @@ -342,13 +342,13 @@ def source_bank(): """ # Get pointer to source bank - ptr = POINTER(_Bank)() + ptr = POINTER(_SourceSite)() n = c_int64() _dll.openmc_source_bank(ptr, n) try: # Convert to numpy array with appropriate datatype - bank_dtype = np.dtype(_Bank) + bank_dtype = np.dtype(_SourceSite) return as_array(ptr, (n.value,)).view(bank_dtype) except ValueError as err: diff --git a/src/bank.cpp b/src/bank.cpp index 958676d6e..d5d364756 100644 --- a/src/bank.cpp +++ b/src/bank.cpp @@ -1,8 +1,9 @@ #include "openmc/bank.h" #include "openmc/capi.h" #include "openmc/error.h" -#include "openmc/simulation.h" #include "openmc/message_passing.h" +#include "openmc/simulation.h" +#include "openmc/vector.h" #include @@ -15,20 +16,20 @@ namespace openmc { namespace simulation { -std::vector source_bank; +vector source_bank; -SharedArray surf_source_bank; +SharedArray surf_source_bank; // The fission bank is allocated as a SharedArray, rather than a vector, as it will // be shared by all threads in the simulation. It will be allocated to a fixed // maximum capacity in the init_fission_bank() function. Then, Elements will be // added to it by using SharedArray's special thread_safe_append() function. -SharedArray fission_bank; +SharedArray fission_bank; // Each entry in this vector corresponds to the number of progeny produced // this generation for the particle located at that index. This vector is // used to efficiently sort the fission bank after each iteration. -std::vector progeny_per_particle; +vector progeny_per_particle; } // namespace simulation @@ -79,8 +80,8 @@ void sort_fission_bank() // We need a scratch vector to make permutation of the fission bank into // sorted order easy. Under normal usage conditions, the fission bank is // over provisioned, so we can use that as scratch space. - Particle::Bank* sorted_bank; - std::vector sorted_bank_holder; + SourceSite* sorted_bank; + vector sorted_bank_holder; // If there is not enough space, allocate a temporary vector and point to it if (simulation::fission_bank.size() > simulation::fission_bank.capacity() / 2) { diff --git a/src/boundary_condition.cpp b/src/boundary_condition.cpp index fccae191b..884b06f81 100644 --- a/src/boundary_condition.cpp +++ b/src/boundary_condition.cpp @@ -113,7 +113,7 @@ void TranslationalPeriodicBC::handle_particle(Particle& p, const Surface& surf) const { // TODO: off-by-one on surface indices throughout this function. - int i_particle_surf = std::abs(p.surface_) - 1; + int i_particle_surf = std::abs(p.surface()) - 1; // Figure out which of the two BC surfaces were struck then find the // particle's new location and surface. @@ -121,10 +121,10 @@ TranslationalPeriodicBC::handle_particle(Particle& p, const Surface& surf) const int new_surface; if (i_particle_surf == i_surf_) { new_r = p.r() + translation_; - new_surface = p.surface_ > 0 ? j_surf_ + 1 : -(j_surf_ + 1); + new_surface = p.surface() > 0 ? j_surf_ + 1 : -(j_surf_ + 1); } else if (i_particle_surf == j_surf_) { new_r = p.r() - translation_; - new_surface = p.surface_ > 0 ? i_surf_ + 1 : -(i_surf_ + 1); + new_surface = p.surface() > 0 ? i_surf_ + 1 : -(i_surf_ + 1); } else { throw std::runtime_error("Called BoundaryCondition::handle_particle after " "hitting a surface, but that surface is not recognized by the BC."); @@ -222,7 +222,7 @@ void RotationalPeriodicBC::handle_particle(Particle& p, const Surface& surf) const { // TODO: off-by-one on surface indices throughout this function. - int i_particle_surf = std::abs(p.surface_) - 1; + int i_particle_surf = std::abs(p.surface()) - 1; // Figure out which of the two BC surfaces were struck to figure out if a // forward or backward rotation is required. Specify the other surface as @@ -231,10 +231,10 @@ RotationalPeriodicBC::handle_particle(Particle& p, const Surface& surf) const int new_surface; if (i_particle_surf == i_surf_) { theta = angle_; - new_surface = p.surface_ > 0 ? -(j_surf_ + 1) : j_surf_ + 1; + new_surface = p.surface() > 0 ? -(j_surf_ + 1) : j_surf_ + 1; } else if (i_particle_surf == j_surf_) { theta = -angle_; - new_surface = p.surface_ > 0 ? -(i_surf_ + 1) : i_surf_ + 1; + new_surface = p.surface() > 0 ? -(i_surf_ + 1) : i_surf_ + 1; } else { throw std::runtime_error("Called BoundaryCondition::handle_particle after " "hitting a surface, but that surface is not recognized by the BC."); diff --git a/src/bremsstrahlung.cpp b/src/bremsstrahlung.cpp index a7fae50c1..099e0ca0c 100644 --- a/src/bremsstrahlung.cpp +++ b/src/bremsstrahlung.cpp @@ -18,7 +18,7 @@ namespace data { xt::xtensor ttb_e_grid; xt::xtensor ttb_k_grid; -std::vector ttb; +vector ttb; } // namespace data @@ -28,20 +28,22 @@ std::vector ttb; void thick_target_bremsstrahlung(Particle& p, double* E_lost) { - if (p.material_ == MATERIAL_VOID) return; + if (p.material() == MATERIAL_VOID) + return; - int photon = static_cast(Particle::Type::photon); - if (p.E_ < settings::energy_cutoff[photon]) return; + int photon = static_cast(ParticleType::photon); + if (p.E() < settings::energy_cutoff[photon]) + return; // Get bremsstrahlung data for this material and particle type BremsstrahlungData* mat; - if (p.type_ == Particle::Type::positron) { - mat = &model::materials[p.material_]->ttb_->positron; + if (p.type() == ParticleType::positron) { + mat = &model::materials[p.material()]->ttb_->positron; } else { - mat = &model::materials[p.material_]->ttb_->electron; + mat = &model::materials[p.material()]->ttb_->electron; } - double e = std::log(p.E_); + double e = std::log(p.E()); auto n_e = data::ttb_e_grid.size(); // Find the lower bounding index of the incident electron energy @@ -108,7 +110,7 @@ void thick_target_bremsstrahlung(Particle& p, double* E_lost) if (w > settings::energy_cutoff[photon]) { // Create secondary photon - p.create_secondary(p.wgt_, p.u(), w, Particle::Type::photon); + p.create_secondary(p.wgt(), p.u(), w, ParticleType::photon); *E_lost += w; } } diff --git a/src/cell.cpp b/src/cell.cpp index 4b18319b6..6b88a6780 100644 --- a/src/cell.cpp +++ b/src/cell.cpp @@ -33,10 +33,10 @@ namespace openmc { namespace model { std::unordered_map cell_map; - std::vector> cells; + vector> cells; std::unordered_map universe_map; - std::vector> universes; + vector> universes; } // namespace model //============================================================================== @@ -46,10 +46,10 @@ namespace model { //! operators. //============================================================================== -std::vector -tokenize(const std::string region_spec) { +vector tokenize(const std::string region_spec) +{ // Check for an empty region_spec first. - std::vector tokens; + vector tokens; if (region_spec.empty()) { return tokens; } @@ -113,11 +113,10 @@ tokenize(const std::string region_spec) { //! This function uses the shunting-yard algorithm. //============================================================================== -std::vector -generate_rpn(int32_t cell_id, std::vector infix) +vector generate_rpn(int32_t cell_id, vector infix) { - std::vector rpn; - std::vector stack; + vector rpn; + vector stack; for (int32_t token : infix) { if (token < OP_UNION) { @@ -197,7 +196,7 @@ Universe::to_hdf5(hid_t universes_group) const // Write the contained cells. if (cells_.size() > 0) { - std::vector cell_ids; + vector cell_ids; for (auto i_cell : cells_) cell_ids.push_back(model::cells[i_cell]->id_); write_dataset(group, "cells", cell_ids); } @@ -333,8 +332,8 @@ CSGCell::CSGCell(pugi::xml_node cell_node) // universe), more than one material (distribmats), and some materials may // be "void". if (material_present) { - std::vector mats - {get_node_array(cell_node, "material", true)}; + vector mats { + get_node_array(cell_node, "material", true)}; if (mats.size() > 0) { material_.reserve(mats.size()); for (std::string mat : mats) { @@ -563,7 +562,7 @@ CSGCell::to_hdf5(hid_t cell_group) const // Write fill information. if (type_ == Fill::MATERIAL) { write_dataset(group, "fill_type", "material"); - std::vector mat_ids; + vector mat_ids; for (auto i_mat : material_) { if (i_mat != MATERIAL_VOID) { mat_ids.push_back(model::materials[i_mat]->id_); @@ -577,7 +576,7 @@ CSGCell::to_hdf5(hid_t cell_group) const write_dataset(group, "material", mat_ids); } - std::vector temps; + vector temps; for (auto sqrtkT_val : sqrtkT_) temps.push_back(sqrtkT_val * sqrtkT_val / K_BOLTZMANN); write_dataset(group, "temperature", temps); @@ -590,7 +589,7 @@ CSGCell::to_hdf5(hid_t cell_group) const } if (!rotation_.empty()) { if (rotation_.size() == 12) { - std::array rot {rotation_[9], rotation_[10], rotation_[11]}; + array rot {rotation_[9], rotation_[10], rotation_[11]}; write_dataset(group, "rotation", rot); } else { write_dataset(group, "rotation", rotation_); @@ -613,8 +612,8 @@ BoundingBox CSGCell::bounding_box_simple() const { return bbox; } -void CSGCell::apply_demorgan(std::vector::iterator start, - std::vector::iterator stop) +void CSGCell::apply_demorgan( + vector::iterator start, vector::iterator stop) { while (start < stop) { if (*start < OP_UNION) { *start *= -1; } @@ -624,9 +623,9 @@ void CSGCell::apply_demorgan(std::vector::iterator start, } } -std::vector::iterator -CSGCell::find_left_parenthesis(std::vector::iterator start, - const std::vector& rpn) { +vector::iterator CSGCell::find_left_parenthesis( + vector::iterator start, const vector& rpn) +{ // start search at zero int parenthesis_level = 0; auto it = start; @@ -657,12 +656,13 @@ CSGCell::find_left_parenthesis(std::vector::iterator start, return it; } -void CSGCell::remove_complement_ops(std::vector& rpn) { +void CSGCell::remove_complement_ops(vector& rpn) +{ auto it = std::find(rpn.begin(), rpn.end(), OP_COMPLEMENT); while (it != rpn.end()) { // find the opening parenthesis (if any) auto left = find_left_parenthesis(it, rpn); - std::vector tmp(left, it+1); + vector tmp(left, it + 1); // apply DeMorgan's law to any surfaces/operators between these // positions in the RPN @@ -674,11 +674,12 @@ void CSGCell::remove_complement_ops(std::vector& rpn) { } } -BoundingBox CSGCell::bounding_box_complex(std::vector rpn) { +BoundingBox CSGCell::bounding_box_complex(vector rpn) +{ // remove complements by adjusting surface signs and operators remove_complement_ops(rpn); - std::vector stack(rpn.size()); + vector stack(rpn.size()); int i_stack = -1; for (auto& token : rpn) { @@ -731,7 +732,7 @@ CSGCell::contains_complex(Position r, Direction u, int32_t on_surface) const { // Make a stack of booleans. We don't know how big it needs to be, but we do // know that rpn.size() is an upper-bound. - std::vector stack(rpn_.size()); + vector stack(rpn_.size()); int i_stack = -1; for (int32_t token : rpn_) { @@ -787,9 +788,9 @@ DAGCell::distance(Position r, Direction u, int32_t on_surface, Particle* p) cons Expects(p); // if we've changed direction or we're not on a surface, // reset the history and update last direction - if (u != p->last_dir_ || on_surface == 0) { - p->history_.reset(); - p->last_dir_ = u; + if (u != p->last_dir() || on_surface == 0) { + p->history().reset(); + p->last_dir() = u; } moab::ErrorCode rval; @@ -798,7 +799,7 @@ DAGCell::distance(Position r, Direction u, int32_t on_surface, Particle* p) cons double dist; double pnt[3] = {r.x, r.y, r.z}; double dir[3] = {u.x, u.y, u.z}; - rval = dagmc_ptr_->ray_fire(vol, pnt, dir, hit_surf, dist, &p->history_); + rval = dagmc_ptr_->ray_fire(vol, pnt, dir, hit_surf, dist, &p->history()); MB_CHK_ERR_CONT(rval); int surf_idx; if (hit_surf != 0) { @@ -945,8 +946,8 @@ UniversePartitioner::UniversePartitioner(const Universe& univ) } } -const std::vector& -UniversePartitioner::get_cells(Position r, Direction u) const +const vector& UniversePartitioner::get_cells( + Position r, Direction u) const { // Perform a binary search for the partition containing the given coordinates. int left = 0; @@ -998,7 +999,7 @@ void read_cells(pugi::xml_node node) // Loop over XML cell elements and populate the array. model::cells.reserve(n_cells); for (pugi::xml_node cell_node : node.children("cell")) { - model::cells.push_back(std::make_unique(cell_node)); + model::cells.push_back(make_unique(cell_node)); } // Fill the cell map. @@ -1017,7 +1018,7 @@ void read_cells(pugi::xml_node node) int32_t uid = model::cells[i]->universe_; auto it = model::universe_map.find(uid); if (it == model::universe_map.end()) { - model::universes.push_back(std::make_unique()); + model::universes.push_back(make_unique()); model::universes.back()->id_ = uid; model::universes.back()->cells_.push_back(i); model::universe_map[uid] = model::universes.size() - 1; @@ -1175,11 +1176,10 @@ openmc_cell_set_name(int32_t index, const char* name) { return 0; } - -std::unordered_map> -Cell::get_contained_cells() const { - std::unordered_map> contained_cells; - std::vector parent_cells; +std::unordered_map> Cell::get_contained_cells() const +{ + std::unordered_map> contained_cells; + vector parent_cells; // if this cell is filled w/ a material, it contains no other cells if (type_ != Fill::MATERIAL) { @@ -1190,9 +1190,9 @@ Cell::get_contained_cells() const { } //! Get all cells within this cell -void -Cell::get_contained_cells_inner(std::unordered_map>& contained_cells, - std::vector& parent_cells) const +void Cell::get_contained_cells_inner( + std::unordered_map>& contained_cells, + vector& parent_cells) const { // filled by material, determine instance based on parent cells @@ -1285,7 +1285,7 @@ openmc_extend_cells(int32_t n, int32_t* index_start, int32_t* index_end) if (index_start) *index_start = model::cells.size(); if (index_end) *index_end = model::cells.size() + n - 1; for (int32_t i = 0; i < n; i++) { - model::cells.push_back(std::make_unique()); + model::cells.push_back(make_unique()); } return 0; } diff --git a/src/cmfd_solver.cpp b/src/cmfd_solver.cpp index ab6283662..4efc515ad 100644 --- a/src/cmfd_solver.cpp +++ b/src/cmfd_solver.cpp @@ -1,6 +1,5 @@ #include "openmc/cmfd_solver.h" -#include #include #ifdef _OPENMP @@ -9,14 +8,15 @@ #include "xtensor/xtensor.hpp" #include "openmc/bank.h" -#include "openmc/error.h" -#include "openmc/constants.h" #include "openmc/capi.h" +#include "openmc/constants.h" +#include "openmc/error.h" #include "openmc/mesh.h" #include "openmc/message_passing.h" #include "openmc/tallies/filter_energy.h" #include "openmc/tallies/filter_mesh.h" #include "openmc/tallies/tally.h" +#include "openmc/vector.h" namespace openmc { @@ -26,9 +26,9 @@ namespace cmfd { // Global variables //============================================================================== -std::vector indptr; +vector indptr; -std::vector indices; +vector indices; int dim; @@ -42,7 +42,7 @@ int use_all_threads; StructuredMesh* mesh; -std::vector egrid; +vector egrid; double norm; @@ -83,7 +83,7 @@ xt::xtensor count_bank_sites(xt::xtensor& bins, bool* outside { // Determine shape of array for counts std::size_t cnt_size = cmfd::nx * cmfd::ny * cmfd::nz * cmfd::ng; - std::vector cnt_shape = {cnt_size}; + vector cnt_shape = {cnt_size}; // Create array of zeros xt::xarray cnt {cnt_shape, 0.0}; @@ -299,7 +299,7 @@ int cmfd_linsolver_1g(const double* A_data, const double* b, double* x, double err = 0.0; // Copy over x vector - std::vector tmpx {x, x+cmfd::dim}; + vector tmpx {x, x + cmfd::dim}; // Perform red/black Gauss-Seidel iterations for (int irb = 0; irb < 2; irb++) { @@ -366,7 +366,7 @@ int cmfd_linsolver_2g(const double* A_data, const double* b, double* x, double err = 0.0; // Copy over x vector - std::vector tmpx {x, x+cmfd::dim}; + vector tmpx {x, x + cmfd::dim}; // Perform red/black Gauss-Seidel iterations for (int irb = 0; irb < 2; irb++) { @@ -458,7 +458,7 @@ int cmfd_linsolver_ng(const double* A_data, const double* b, double* x, double err = 0.0; // Copy over x vector - std::vector tmpx {x, x+cmfd::dim}; + vector tmpx {x, x + cmfd::dim}; // Loop around matrix rows for (int irow = 0; irow < cmfd::dim; irow++) { @@ -554,7 +554,7 @@ int openmc_run_linsolver(const double* A_data, const double* b, double* x, void free_memory_cmfd() { - // Clear std::vectors + // Clear vectors cmfd::indptr.clear(); cmfd::indices.clear(); cmfd::egrid.clear(); diff --git a/src/cross_sections.cpp b/src/cross_sections.cpp index dc071cbac..ea8d0cfbb 100644 --- a/src/cross_sections.cpp +++ b/src/cross_sections.cpp @@ -37,8 +37,7 @@ namespace openmc { namespace data { std::map library_map; -std::vector libraries; - +vector libraries; } //============================================================================== @@ -182,16 +181,15 @@ void read_cross_sections_xml() } } -void -read_ce_cross_sections(const std::vector>& nuc_temps, - const std::vector>& thermal_temps) +void read_ce_cross_sections(const vector>& nuc_temps, + const vector>& thermal_temps) { std::unordered_set already_read; // Construct a vector of nuclide names because we haven't loaded nuclide data // yet, but we need to know the name of the i-th nuclide - std::vector nuclide_names(data::nuclide_map.size()); - std::vector thermal_names(data::thermal_scatt_map.size()); + vector nuclide_names(data::nuclide_map.size()); + vector thermal_names(data::thermal_scatt_map.size()); for (const auto& kv : data::nuclide_map) { nuclide_names[kv.second] = kv.first; } @@ -238,8 +236,8 @@ read_ce_cross_sections(const std::vector>& nuc_temps, // Read thermal scattering data from HDF5 hid_t group = open_group(file_id, name.c_str()); - data::thermal_scatt.push_back(std::make_unique( - group, thermal_temps[i_table])); + data::thermal_scatt.push_back( + make_unique(group, thermal_temps[i_table])); close_group(group); file_close(file_id); diff --git a/src/dagmc.cpp b/src/dagmc.cpp index 5939f3f40..0c2768834 100644 --- a/src/dagmc.cpp +++ b/src/dagmc.cpp @@ -183,7 +183,7 @@ void load_dagmc_geometry() dagmcMetaData DMD(model::DAG, false, false); DMD.load_property_data(); - std::vector keywords {"temp"}; + vector keywords {"temp"}; std::map dum; std::string delimiters = ":/"; rval = model::DAG->parse_properties(keywords, dum, delimiters.c_str()); @@ -211,7 +211,7 @@ void load_dagmc_geometry() // Populate the Universe vector and dict auto it = model::universe_map.find(dagmc_univ_id); if (it == model::universe_map.end()) { - model::universes.push_back(std::make_unique()); + model::universes.push_back(make_unique()); model::universes.back()->id_ = dagmc_univ_id; model::universes.back()->cells_.push_back(i); model::universe_map[dagmc_univ_id] = model::universes.size() - 1; diff --git a/src/distribution_angle.cpp b/src/distribution_angle.cpp index 970ea9040..13e8c480f 100644 --- a/src/distribution_angle.cpp +++ b/src/distribution_angle.cpp @@ -1,7 +1,6 @@ #include "openmc/distribution_angle.h" #include // for abs, copysign -#include // for vector #include "xtensor/xarray.hpp" #include "xtensor/xview.hpp" @@ -10,6 +9,7 @@ #include "openmc/hdf5_interface.h" #include "openmc/random_lcg.h" #include "openmc/search.h" +#include "openmc/vector.h" // for vector namespace openmc { @@ -24,8 +24,8 @@ AngleDistribution::AngleDistribution(hid_t group) int n_energy = energy_.size(); // Get outgoing energy distribution data - std::vector offsets; - std::vector interp; + vector offsets; + vector interp; hid_t dset = open_dataset(group, "mu"); read_attribute(dset, "offsets", offsets); read_attribute(dset, "interpolation", interp); @@ -47,9 +47,9 @@ AngleDistribution::AngleDistribution(hid_t group) auto xs = xt::view(temp, 0, xt::range(j, j+n)); auto ps = xt::view(temp, 1, xt::range(j, j+n)); auto cs = xt::view(temp, 2, xt::range(j, j+n)); - std::vector x {xs.begin(), xs.end()}; - std::vector p {ps.begin(), ps.end()}; - std::vector c {cs.begin(), cs.end()}; + vector x {xs.begin(), xs.end()}; + vector p {ps.begin(), ps.end()}; + vector c {cs.begin(), cs.end()}; // To get answers that match ACE data, for now we still use the tabulated // CDF values that were passed through to the HDF5 library. At a later diff --git a/src/distribution_energy.cpp b/src/distribution_energy.cpp index 338486804..1fd95d401 100644 --- a/src/distribution_energy.cpp +++ b/src/distribution_energy.cpp @@ -78,9 +78,9 @@ ContinuousTabular::ContinuousTabular(hid_t group) // Get outgoing energy distribution data dset = open_dataset(group, "distribution"); - std::vector offsets; - std::vector interp; - std::vector n_discrete; + vector offsets; + vector interp; + vector n_discrete; read_attribute(dset, "offsets", offsets); read_attribute(dset, "interpolation", interp); read_attribute(dset, "n_discrete_lines", n_discrete); diff --git a/src/distribution_spatial.cpp b/src/distribution_spatial.cpp index 125d8afa6..356383eb7 100644 --- a/src/distribution_spatial.cpp +++ b/src/distribution_spatial.cpp @@ -65,7 +65,7 @@ CylindricalIndependent::CylindricalIndependent(pugi::xml_node node) // If no distribution was specified, default to a single point at r=0 double x[] {0.0}; double p[] {1.0}; - r_ = std::make_unique(x, p, 1); + r_ = make_unique(x, p, 1); } // Read distribution for phi-coordinate @@ -76,7 +76,7 @@ CylindricalIndependent::CylindricalIndependent(pugi::xml_node node) // If no distribution was specified, default to a single point at phi=0 double x[] {0.0}; double p[] {1.0}; - phi_ = std::make_unique(x, p, 1); + phi_ = make_unique(x, p, 1); } // Read distribution for z-coordinate @@ -87,7 +87,7 @@ CylindricalIndependent::CylindricalIndependent(pugi::xml_node node) // If no distribution was specified, default to a single point at z=0 double x[] {0.0}; double p[] {1.0}; - z_ = std::make_unique(x, p, 1); + z_ = make_unique(x, p, 1); } // Read cylinder center coordinates @@ -129,7 +129,7 @@ SphericalIndependent::SphericalIndependent(pugi::xml_node node) // If no distribution was specified, default to a single point at r=0 double x[] {0.0}; double p[] {1.0}; - r_ = std::make_unique(x, p, 1); + r_ = make_unique(x, p, 1); } // Read distribution for theta-coordinate @@ -140,7 +140,7 @@ SphericalIndependent::SphericalIndependent(pugi::xml_node node) // If no distribution was specified, default to a single point at theta=0 double x[] {0.0}; double p[] {1.0}; - theta_ = std::make_unique(x, p, 1); + theta_ = make_unique(x, p, 1); } // Read distribution for phi-coordinate @@ -151,7 +151,7 @@ SphericalIndependent::SphericalIndependent(pugi::xml_node node) // If no distribution was specified, default to a single point at phi=0 double x[] {0.0}; double p[] {1.0}; - phi_ = std::make_unique(x, p, 1); + phi_ = make_unique(x, p, 1); } // Read sphere center coordinates diff --git a/src/eigenvalue.cpp b/src/eigenvalue.cpp index f5d8a9c80..1e0d7d972 100644 --- a/src/eigenvalue.cpp +++ b/src/eigenvalue.cpp @@ -5,6 +5,7 @@ #include "xtensor/xtensor.hpp" #include "xtensor/xview.hpp" +#include "openmc/array.h" #include "openmc/bank.h" #include "openmc/capi.h" #include "openmc/constants.h" @@ -17,11 +18,10 @@ #include "openmc/search.h" #include "openmc/settings.h" #include "openmc/simulation.h" -#include "openmc/timer.h" #include "openmc/tallies/tally.h" +#include "openmc/timer.h" #include // for min -#include #include // for sqrt, abs, pow #include // for back_inserter #include @@ -36,8 +36,8 @@ namespace openmc { namespace simulation { double keff_generation; -std::array k_sum; -std::vector entropy; +array k_sum; +vector entropy; xt::xtensor source_frac; } // namespace simulation @@ -137,7 +137,7 @@ void synchronize_bank() // Allocate temporary source bank -- we don't really know how many fission // sites were created, so overallocate by a factor of 3 int64_t index_temp = 0; - std::vector temp_sites(3*simulation::work_per_rank); + vector temp_sites(3 * simulation::work_per_rank); for (int64_t i = 0; i < simulation::fission_bank.size(); i++ ) { const auto& site = simulation::fission_bank[i]; @@ -214,7 +214,7 @@ void synchronize_bank() // SEND BANK SITES TO NEIGHBORS int64_t index_local = 0; - std::vector requests; + vector requests; if (start < settings::n_particles) { // Determine the index of the processor which has the first part of the @@ -230,7 +230,7 @@ void synchronize_bank() // process if (neighbor != mpi::rank) { requests.emplace_back(); - MPI_Isend(&temp_sites[index_local], static_cast(n), mpi::bank, + MPI_Isend(&temp_sites[index_local], static_cast(n), mpi::source_site, neighbor, mpi::rank, mpi::intracomm, &requests.back()); } @@ -276,7 +276,7 @@ void synchronize_bank() // asynchronous receive for the source sites requests.emplace_back(); - MPI_Irecv(&simulation::source_bank[index_local], static_cast(n), mpi::bank, + MPI_Irecv(&simulation::source_bank[index_local], static_cast(n), mpi::source_site, neighbor, neighbor, mpi::intracomm, &requests.back()); } else { @@ -372,7 +372,7 @@ int openmc_get_keff(double* k_combined) // Copy estimates of k-effective and its variance (not variance of the mean) const auto& gt = simulation::global_tallies; - std::array kv {}; + array kv {}; xt::xtensor cov = xt::zeros({3, 3}); kv[0] = gt(GlobalTally::K_COLLISION, TallyResult::SUM) / n; kv[1] = gt(GlobalTally::K_ABSORPTION, TallyResult::SUM) / n; @@ -427,7 +427,7 @@ int openmc_get_keff(double* k_combined) // Initialize variables double g = 0.0; - std::array S {}; + array S {}; for (int l = 0; l < 3; ++l) { // Permutations of estimates @@ -601,7 +601,7 @@ void write_eigenvalue_hdf5(hid_t group) write_dataset(group, "k_col_abs", simulation::k_col_abs); write_dataset(group, "k_col_tra", simulation::k_col_tra); write_dataset(group, "k_abs_tra", simulation::k_abs_tra); - std::array k_combined; + array k_combined; openmc_get_keff(k_combined.data()); write_dataset(group, "k_combined", k_combined); } diff --git a/src/endf.cpp b/src/endf.cpp index 99afe39fc..eb7e00e28 100644 --- a/src/endf.cpp +++ b/src/endf.cpp @@ -1,7 +1,6 @@ #include "openmc/endf.h" #include // for copy -#include #include // for log, exp #include // for back_inserter #include // for runtime_error @@ -9,6 +8,7 @@ #include "xtensor/xarray.hpp" #include "xtensor/xview.hpp" +#include "openmc/array.h" #include "openmc/constants.h" #include "openmc/hdf5_interface.h" #include "openmc/search.h" @@ -77,21 +77,20 @@ bool is_inelastic_scatter(int mt) } } -std::unique_ptr -read_function(hid_t group, const char* name) +unique_ptr read_function(hid_t group, const char* name) { hid_t dset = open_dataset(group, name); std::string func_type; read_attribute(dset, "type", func_type); - std::unique_ptr func; + unique_ptr func; if (func_type == "Tabulated1D") { - func = std::make_unique(dset); + func = make_unique(dset); } else if (func_type == "Polynomial") { - func = std::make_unique(dset); + func = make_unique(dset); } else if (func_type == "CoherentElastic") { - func = std::make_unique(dset); + func = make_unique(dset); } else if (func_type == "IncoherentElastic") { - func = std::make_unique(dset); + func = make_unique(dset); } else { throw std::runtime_error{"Unknown function type " + func_type + " for dataset " + object_name(dset)}; @@ -133,7 +132,7 @@ Tabulated1D::Tabulated1D(hid_t dset) // Change 1-indexing to 0-indexing for (auto& b : nbt_) --b; - std::vector int_temp; + vector int_temp; read_attribute(dset, "interpolation", int_temp); // Convert vector of ints into Interpolation @@ -245,7 +244,7 @@ double CoherentElasticXS::operator()(double E) const IncoherentElasticXS::IncoherentElasticXS(hid_t dset) { - std::array tmp; + array tmp; read_dataset(dset, nullptr, tmp); bound_xs_ = tmp[0]; debye_waller_ = tmp[1]; diff --git a/src/event.cpp b/src/event.cpp index d1b4a36a7..895b1d62e 100644 --- a/src/event.cpp +++ b/src/event.cpp @@ -17,7 +17,7 @@ SharedArray advance_particle_queue; SharedArray surface_crossing_queue; SharedArray collision_queue; -std::vector particles; +vector particles; } // namespace simulation @@ -50,7 +50,8 @@ void free_event_queues(void) void dispatch_xs_event(int64_t buffer_idx) { Particle& p = simulation::particles[buffer_idx]; - if (p.material_ == MATERIAL_VOID || !model::materials[p.material_]->fissionable_) { + if (p.material() == MATERIAL_VOID || + !model::materials[p.material()]->fissionable_) { simulation::calculate_nonfuel_xs_queue.thread_safe_append({p, buffer_idx}); } else { simulation::calculate_fuel_xs_queue.thread_safe_append({p, buffer_idx}); @@ -109,7 +110,7 @@ void process_advance_particle_events() int64_t buffer_idx = simulation::advance_particle_queue[i].idx; Particle& p = simulation::particles[buffer_idx]; p.event_advance(); - if (p.collision_distance_ > p.boundary_.distance) { + if (p.collision_distance() > p.boundary().distance) { simulation::surface_crossing_queue.thread_safe_append({p, buffer_idx}); } else { simulation::collision_queue.thread_safe_append({p, buffer_idx}); @@ -131,7 +132,7 @@ void process_surface_crossing_events() Particle& p = simulation::particles[buffer_idx]; p.event_cross_surface(); p.event_revive_from_secondary(); - if (p.alive_) + if (p.alive()) dispatch_xs_event(buffer_idx); } @@ -150,7 +151,7 @@ void process_collision_events() Particle& p = simulation::particles[buffer_idx]; p.event_collide(); p.event_revive_from_secondary(); - if (p.alive_) + if (p.alive()) dispatch_xs_event(buffer_idx); } diff --git a/src/finalize.cpp b/src/finalize.cpp index 45dd0fc7c..22dc67183 100644 --- a/src/finalize.cpp +++ b/src/finalize.cpp @@ -143,7 +143,7 @@ int openmc_finalize() // Free all MPI types #ifdef OPENMC_MPI - if (mpi::bank != MPI_DATATYPE_NULL) MPI_Type_free(&mpi::bank); + if (mpi::source_site != MPI_DATATYPE_NULL) MPI_Type_free(&mpi::source_site); #endif return 0; diff --git a/src/geometry.cpp b/src/geometry.cpp index 23622ebad..59607f637 100644 --- a/src/geometry.cpp +++ b/src/geometry.cpp @@ -1,10 +1,9 @@ #include "openmc/geometry.h" -#include - #include #include +#include "openmc/array.h" #include "openmc/cell.h" #include "openmc/constants.h" #include "openmc/error.h" @@ -27,7 +26,7 @@ namespace model { int root_universe {-1}; int n_coord_levels; -std::vector overlap_check_count; +vector overlap_check_count; } // namespace model @@ -37,25 +36,25 @@ std::vector overlap_check_count; bool check_cell_overlap(Particle& p, bool error) { - int n_coord = p.n_coord_; + int n_coord = p.n_coord(); // Loop through each coordinate level for (int j = 0; j < n_coord; j++) { - Universe& univ = *model::universes[p.coord_[j].universe]; + Universe& univ = *model::universes[p.coord(j).universe]; // Loop through each cell on this level for (auto index_cell : univ.cells_) { Cell& c = *model::cells[index_cell]; - if (c.contains(p.coord_[j].r, p.coord_[j].u, p.surface_)) { - if (index_cell != p.coord_[j].cell) { + if (c.contains(p.coord(j).r, p.coord(j).u, p.surface())) { + if (index_cell != p.coord(j).cell) { if (error) { - fatal_error(fmt::format( - "Overlapping cells detected: {}, {} on universe {}", - c.id_, model::cells[p.coord_[j].cell]->id_, univ.id_)); + fatal_error( + fmt::format("Overlapping cells detected: {}, {} on universe {}", + c.id_, model::cells[p.coord(j).cell]->id_, univ.id_)); } return true; } - #pragma omp atomic +#pragma omp atomic ++model::overlap_check_count[index_cell]; } } @@ -78,15 +77,15 @@ find_cell_inner(Particle& p, const NeighborList* neighbor_list) i_cell = *it; // Make sure the search cell is in the same universe. - int i_universe = p.coord_[p.n_coord_-1].universe; + int i_universe = p.coord(p.n_coord() - 1).universe; if (model::cells[i_cell]->universe_ != i_universe) continue; // Check if this cell contains the particle. Position r {p.r_local()}; Direction u {p.u_local()}; - auto surf = p.surface_; + auto surf = p.surface(); if (model::cells[i_cell]->contains(r, u, surf)) { - p.coord_[p.n_coord_-1].cell = i_cell; + p.coord(p.n_coord() - 1).cell = i_cell; found = true; break; } @@ -102,7 +101,7 @@ find_cell_inner(Particle& p, const NeighborList* neighbor_list) } // Check successively lower coordinate levels until finding material fill - for (;;++p.n_coord_) { + for (;;++p.n_coord()) { // If we did not attempt to use neighbor lists, i_cell is still C_NONE. In // that case, we should now do an exhaustive search to find the right value // of i_cell. @@ -112,7 +111,7 @@ find_cell_inner(Particle& p, const NeighborList* neighbor_list) // code below this conditional, we set i_cell back to C_NONE to indicate // that. if (i_cell == C_NONE) { - int i_universe = p.coord_[p.n_coord_-1].universe; + int i_universe = p.coord(p.n_coord() - 1).universe; const auto& univ {*model::universes[i_universe]}; const auto& cells { !univ.partitioner_ @@ -124,15 +123,15 @@ find_cell_inner(Particle& p, const NeighborList* neighbor_list) i_cell = *it; // Make sure the search cell is in the same universe. - int i_universe = p.coord_[p.n_coord_-1].universe; + int i_universe = p.coord(p.n_coord() - 1).universe; if (model::cells[i_cell]->universe_ != i_universe) continue; // Check if this cell contains the particle. Position r {p.r_local()}; Direction u {p.u_local()}; - auto surf = p.surface_; + auto surf = p.surface(); if (model::cells[i_cell]->contains(r, u, surf)) { - p.coord_[p.n_coord_-1].cell = i_cell; + p.coord(p.n_coord() - 1).cell = i_cell; found = true; break; } @@ -143,7 +142,7 @@ find_cell_inner(Particle& p, const NeighborList* neighbor_list) } // Announce the cell that the particle is entering. - if (found && (settings::verbosity >= 10 || p.trace_)) { + if (found && (settings::verbosity >= 10 || p.trace())) { auto msg = fmt::format(" Entering cell {}", model::cells[i_cell]->id_); write_message(msg, 1); } @@ -155,34 +154,33 @@ find_cell_inner(Particle& p, const NeighborList* neighbor_list) // Find the distribcell instance number. int offset = 0; if (c.distribcell_index_ >= 0) { - for (int i = 0; i < p.n_coord_; i++) { - const auto& c_i {*model::cells[p.coord_[i].cell]}; + for (int i = 0; i < p.n_coord(); i++) { + const auto& c_i {*model::cells[p.coord(i).cell]}; if (c_i.type_ == Fill::UNIVERSE) { offset += c_i.offset_[c.distribcell_index_]; } else if (c_i.type_ == Fill::LATTICE) { - auto& lat {*model::lattices[p.coord_[i + 1].lattice]}; - int i_xyz[3] {p.coord_[i + 1].lattice_x, p.coord_[i + 1].lattice_y, - p.coord_[i + 1].lattice_z}; + auto& lat {*model::lattices[p.coord(i + 1).lattice]}; + const auto& i_xyz {p.coord(i + 1).lattice_i}; if (lat.are_valid_indices(i_xyz)) { offset += lat.offset(c.distribcell_index_, i_xyz); } } } } - p.cell_instance_ = offset; + p.cell_instance() = offset; // Set the material and temperature. - p.material_last_ = p.material_; + p.material_last() = p.material(); if (c.material_.size() > 1) { - p.material_ = c.material_[p.cell_instance_]; + p.material() = c.material_[p.cell_instance()]; } else { - p.material_ = c.material_[0]; + p.material() = c.material_[0]; } - p.sqrtkT_last_ = p.sqrtkT_; + p.sqrtkT_last() = p.sqrtkT(); if (c.sqrtkT_.size() > 1) { - p.sqrtkT_ = c.sqrtkT_[p.cell_instance_]; + p.sqrtkT() = c.sqrtkT_[p.cell_instance()]; } else { - p.sqrtkT_ = c.sqrtkT_[0]; + p.sqrtkT() = c.sqrtkT_[0]; } return true; @@ -192,7 +190,7 @@ find_cell_inner(Particle& p, const NeighborList* neighbor_list) //! Found a lower universe, update this coord level then search the next. // Set the lower coordinate level universe. - auto& coord {p.coord_[p.n_coord_]}; + auto& coord {p.coord(p.n_coord())}; coord.universe = c.fill_; // Set the position and direction. @@ -214,7 +212,7 @@ find_cell_inner(Particle& p, const NeighborList* neighbor_list) Lattice& lat {*model::lattices[c.fill_]}; // Set the position and direction. - auto& coord {p.coord_[p.n_coord_]}; + auto& coord {p.coord(p.n_coord())}; coord.r = p.r_local(); coord.u = p.u_local(); @@ -227,16 +225,14 @@ find_cell_inner(Particle& p, const NeighborList* neighbor_list) } // Determine lattice indices. - auto i_xyz = lat.get_indices(coord.r, coord.u); + auto& i_xyz {coord.lattice_i}; + lat.get_indices(coord.r, coord.u, i_xyz); // Get local position in appropriate lattice cell coord.r = lat.get_local_position(coord.r, i_xyz); // Set lattice indices. coord.lattice = c.fill_; - coord.lattice_x = i_xyz[0]; - coord.lattice_y = i_xyz[1]; - coord.lattice_z = i_xyz[2]; // Set the lower coordinate level universe. if (lat.are_valid_indices(i_xyz)) { @@ -247,7 +243,7 @@ find_cell_inner(Particle& p, const NeighborList* neighbor_list) } else { warning(fmt::format("Particle {} is outside lattice {} but the " "lattice has no defined outer universe.", - p.id_, lat.id_)); + p.id(), lat.id_)); return false; } } @@ -265,13 +261,13 @@ bool neighbor_list_find_cell(Particle& p) { // Reset all the deeper coordinate levels. - for (int i = p.n_coord_; i < p.coord_.size(); i++) { - p.coord_[i].reset(); + for (int i = p.n_coord(); i < model::n_coord_levels; i++) { + p.coord(i).reset(); } // Get the cell this particle was in previously. - auto coord_lvl = p.n_coord_ - 1; - auto i_cell = p.coord_[coord_lvl].cell; + auto coord_lvl = p.n_coord() - 1; + auto i_cell = p.coord(coord_lvl).cell; Cell& c {*model::cells[i_cell]}; // Search for the particle in that cell's neighbor list. Return if we @@ -285,21 +281,21 @@ bool neighbor_list_find_cell(Particle& p) // neighboring cell. found = find_cell_inner(p, nullptr); if (found) - c.neighbors_.push_back(p.coord_[coord_lvl].cell); + c.neighbors_.push_back(p.coord(coord_lvl).cell); return found; } bool exhaustive_find_cell(Particle& p) { - int i_universe = p.coord_[p.n_coord_-1].universe; + int i_universe = p.coord(p.n_coord() - 1).universe; if (i_universe == C_NONE) { - p.coord_[0].universe = model::root_universe; - p.n_coord_ = 1; + p.coord(0).universe = model::root_universe; + p.n_coord() = 1; i_universe = model::root_universe; } // Reset all the deeper coordinate levels. - for (int i = p.n_coord_; i < p.coord_.size(); i++) { - p.coord_[i].reset(); + for (int i = p.n_coord(); i < model::n_coord_levels; i++) { + p.coord(i).reset(); } return find_cell_inner(p, nullptr); } @@ -309,53 +305,54 @@ bool exhaustive_find_cell(Particle& p) void cross_lattice(Particle& p, const BoundaryInfo& boundary) { - auto& coord {p.coord_[p.n_coord_ - 1]}; + auto& coord {p.coord(p.n_coord() - 1)}; auto& lat {*model::lattices[coord.lattice]}; - if (settings::verbosity >= 10 || p.trace_) { + if (settings::verbosity >= 10 || p.trace()) { write_message(fmt::format( " Crossing lattice {}. Current position ({},{},{}). r={}", - lat.id_, coord.lattice_x, coord.lattice_y, coord.lattice_z, p.r()), 1); + lat.id_, coord.lattice_i[0], coord.lattice_i[1], coord.lattice_i[2], p.r()), 1); } // Set the lattice indices. - coord.lattice_x += boundary.lattice_translation[0]; - coord.lattice_y += boundary.lattice_translation[1]; - coord.lattice_z += boundary.lattice_translation[2]; - std::array i_xyz {coord.lattice_x, coord.lattice_y, coord.lattice_z}; + coord.lattice_i[0] += boundary.lattice_translation[0]; + coord.lattice_i[1] += boundary.lattice_translation[1]; + coord.lattice_i[2] += boundary.lattice_translation[2]; // Set the new coordinate position. - const auto& upper_coord {p.coord_[p.n_coord_ - 2]}; + const auto& upper_coord {p.coord(p.n_coord() - 2)}; const auto& cell {model::cells[upper_coord.cell]}; Position r = upper_coord.r; r -= cell->translation_; if (!cell->rotation_.empty()) { r = r.rotate(cell->rotation_); } - p.r_local() = lat.get_local_position(r, i_xyz); + p.r_local() = lat.get_local_position(r, coord.lattice_i); - if (!lat.are_valid_indices(i_xyz)) { + if (!lat.are_valid_indices(coord.lattice_i)) { // The particle is outside the lattice. Search for it from the base coords. - p.n_coord_ = 1; + p.n_coord() = 1; bool found = exhaustive_find_cell(p); - if (!found && p.alive_) { + if (!found && p.alive()) { p.mark_as_lost(fmt::format("Could not locate particle {} after " - "crossing a lattice boundary", p.id_)); + "crossing a lattice boundary", + p.id())); } } else { // Find cell in next lattice element. - p.coord_[p.n_coord_-1].universe = lat[i_xyz]; + p.coord(p.n_coord() - 1).universe = lat[coord.lattice_i]; bool found = exhaustive_find_cell(p); if (!found) { // A particle crossing the corner of a lattice tile may not be found. In // this case, search for it from the base coords. - p.n_coord_ = 1; + p.n_coord() = 1; bool found = exhaustive_find_cell(p); - if (!found && p.alive_) { + if (!found && p.alive()) { p.mark_as_lost(fmt::format("Could not locate particle {} after " - "crossing a lattice boundary", p.id_)); + "crossing a lattice boundary", + p.id())); } } } @@ -369,40 +366,39 @@ BoundaryInfo distance_to_boundary(Particle& p) double d_lat = INFINITY; double d_surf = INFINITY; int32_t level_surf_cross; - std::array level_lat_trans {}; + array level_lat_trans {}; // Loop over each coordinate level. - for (int i = 0; i < p.n_coord_; i++) { - const auto& coord {p.coord_[i]}; - Position r {coord.r}; - Direction u {coord.u}; + for (int i = 0; i < p.n_coord(); i++) { + const auto& coord {p.coord(i)}; + const Position& r {coord.r}; + const Direction& u {coord.u}; Cell& c {*model::cells[coord.cell]}; // Find the oncoming surface in this cell and the distance to it. - auto surface_distance = c.distance(r, u, p.surface_, &p); + auto surface_distance = c.distance(r, u, p.surface(), &p); d_surf = surface_distance.first; level_surf_cross = surface_distance.second; // Find the distance to the next lattice tile crossing. if (coord.lattice != C_NONE) { auto& lat {*model::lattices[coord.lattice]}; - std::array i_xyz {coord.lattice_x, coord.lattice_y, coord.lattice_z}; //TODO: refactor so both lattice use the same position argument (which //also means the lat.type attribute can be removed) - std::pair> lattice_distance; + std::pair> lattice_distance; switch (lat.type_) { case LatticeType::rect: - lattice_distance = lat.distance(r, u, i_xyz); + lattice_distance = lat.distance(r, u, coord.lattice_i); break; case LatticeType::hex: - auto& cell_above {model::cells[p.coord_[i-1].cell]}; - Position r_hex {p.coord_[i-1].r}; + auto& cell_above {model::cells[p.coord(i - 1).cell]}; + Position r_hex {p.coord(i - 1).r}; r_hex -= cell_above->translation_; if (coord.rotated) { r_hex = r_hex.rotate(cell_above->rotation_); } r_hex.z = coord.r.z; - lattice_distance = lat.distance(r_hex, u, i_xyz); + lattice_distance = lat.distance(r_hex, u, coord.lattice_i); break; } d_lat = lattice_distance.first; @@ -410,7 +406,7 @@ BoundaryInfo distance_to_boundary(Particle& p) if (d_lat < 0) { p.mark_as_lost(fmt::format( - "Particle {} had a negative distance to a lattice boundary", p.id_)); + "Particle {} had a negative distance to a lattice boundary", p.id())); } } @@ -473,8 +469,8 @@ openmc_find_cell(const double* xyz, int32_t* index, int32_t* instance) return OPENMC_E_GEOMETRY; } - *index = p.coord_[p.n_coord_-1].cell; - *instance = p.cell_instance_; + *index = p.coord(p.n_coord() - 1).cell; + *instance = p.cell_instance(); return 0; } diff --git a/src/geometry_aux.cpp b/src/geometry_aux.cpp index e2b079ba7..17000129d 100644 --- a/src/geometry_aux.cpp +++ b/src/geometry_aux.cpp @@ -157,7 +157,7 @@ partition_universes() if (dynamic_cast(model::surfaces[i_surf].get())) { ++n_zplanes; if (n_zplanes > 5) { - univ->partitioner_ = std::make_unique(*univ); + univ->partitioner_ = make_unique(*univ); break; } } @@ -191,9 +191,8 @@ assign_temperatures() //============================================================================== -void -get_temperatures(std::vector>& nuc_temps, - std::vector>& thermal_temps) +void get_temperatures( + vector>& nuc_temps, vector>& thermal_temps) { for (const auto& cell : model::cells) { // Skip non-material cells. @@ -205,7 +204,7 @@ get_temperatures(std::vector>& nuc_temps, if (i_material == MATERIAL_VOID) continue; // Get temperature(s) of cell (rounding to nearest integer) - std::vector cell_temps; + vector cell_temps; if (cell->sqrtkT_.size() == 1) { double sqrtkT = cell->sqrtkT_[0]; cell_temps.push_back(sqrtkT*sqrtkT / K_BOLTZMANN); @@ -351,7 +350,7 @@ prepare_distribcell() // Search through universes for material cells and assign each one a // unique distribcell array index. int distribcell_index = 0; - std::vector target_univ_ids; + vector target_univ_ids; for (const auto& u : model::universes) { for (auto idx : u->cells_) { if (distribcells.find(idx) != distribcells.end()) { @@ -495,8 +494,8 @@ distribcell_path_inner(int32_t target_cell, int32_t map, int32_t target_offset, // The target must be further down the geometry tree and contained in a fill // cell or lattice cell in this universe. Find which cell contains the // target. - std::vector::const_reverse_iterator cell_it - {search_univ.cells_.crbegin()}; + vector::const_reverse_iterator cell_it { + search_univ.cells_.crbegin()}; for (; cell_it != search_univ.cells_.crend(); ++cell_it) { Cell& c = *model::cells[*cell_it]; diff --git a/src/hdf5_interface.cpp b/src/hdf5_interface.cpp index 1fcc97f3c..0f8db2dc5 100644 --- a/src/hdf5_interface.cpp +++ b/src/hdf5_interface.cpp @@ -1,6 +1,5 @@ #include "openmc/hdf5_interface.h" -#include #include #include #include @@ -16,6 +15,7 @@ #include "openmc/message_passing.h" #endif +#include "openmc/array.h" namespace openmc { @@ -56,16 +56,15 @@ get_shape(hid_t obj_id, hsize_t* dims) H5Sclose(dspace); } - -std::vector attribute_shape(hid_t obj_id, const char* name) +vector attribute_shape(hid_t obj_id, const char* name) { hid_t attr = H5Aopen(obj_id, name, H5P_DEFAULT); - std::vector shape = object_shape(attr); + vector shape = object_shape(attr); H5Aclose(attr); return shape; } -std::vector object_shape(hid_t obj_id) +vector object_shape(hid_t obj_id) { // Get number of dimensions auto type = H5Iget_type(obj_id); @@ -81,7 +80,7 @@ std::vector object_shape(hid_t obj_id) int n = H5Sget_simple_extent_ndims(dspace); // Get shape of array - std::vector shape(n); + vector shape(n); H5Sget_simple_extent_dims(dspace, shape.data(), nullptr); // Free resources and return @@ -337,8 +336,7 @@ get_groups(hid_t group_id, char* name[]) } } -std::vector -member_names(hid_t group_id, H5O_type_t type) +vector member_names(hid_t group_id, H5O_type_t type) { // Determine number of links in the group H5G_info_t info; @@ -347,7 +345,7 @@ member_names(hid_t group_id, H5O_type_t type) // Iterate over links to get names H5O_info_t oinfo; size_t size; - std::vector names; + vector names; for (hsize_t i = 0; i < info.nlinks; ++i) { // Determine type of object (and skip non-group) H5Oget_info_by_idx(group_id, ".", H5_INDEX_NAME, H5_ITER_INC, i, &oinfo, @@ -368,14 +366,12 @@ member_names(hid_t group_id, H5O_type_t type) return names; } -std::vector -group_names(hid_t group_id) +vector group_names(hid_t group_id) { return member_names(group_id, H5O_TYPE_GROUP); } -std::vector -dataset_names(hid_t group_id) +vector dataset_names(hid_t group_id) { return member_names(group_id, H5O_TYPE_DATASET); } @@ -492,13 +488,13 @@ template<> void read_dataset(hid_t dset, xt::xarray>& arr, bool indep) { // Get shape of dataset - std::vector shape = object_shape(dset); + vector shape = object_shape(dset); // Allocate new array to read data into std::size_t size = 1; for (const auto x : shape) size *= x; - std::vector> buffer(size); + vector> buffer(size); // Read data from attribute read_complex(dset, nullptr, buffer.data(), indep); diff --git a/src/initialize.cpp b/src/initialize.cpp index e84678feb..d67d6b3b3 100644 --- a/src/initialize.cpp +++ b/src/initialize.cpp @@ -3,9 +3,7 @@ #include #include // for getenv #include -#include #include -#include #ifdef _OPENMP #include @@ -19,6 +17,7 @@ #include "openmc/geometry_aux.h" #include "openmc/hdf5_interface.h" #include "openmc/material.h" +#include "openmc/memory.h" #include "openmc/message_passing.h" #include "openmc/mgxs_interface.h" #include "openmc/nuclide.h" @@ -32,6 +31,7 @@ #include "openmc/tallies/tally.h" #include "openmc/thermal.h" #include "openmc/timer.h" +#include "openmc/vector.h" #ifdef LIBMESH #include "libmesh/libmesh.h" @@ -74,10 +74,12 @@ if (!settings::libmesh_init && !libMesh::initialized()) { // pass command line args, empty MPI communicator, and number of threads. // Because libMesh was not initialized, we assume that OpenMC is the primary // application and that its main MPI comm should be used. - settings::libmesh_init = std::make_unique(argc, argv, comm, n_threads); + settings::libmesh_init = + make_unique(argc, argv, comm, n_threads); #else // pass command line args, empty MPI communicator, and number of threads - settings::libmesh_init = std::make_unique(argc, argv, 0, n_threads); + settings::libmesh_init = + make_unique(argc, argv, 0, n_threads); #endif settings::libmesh_comm = &(settings::libmesh_init->comm()); @@ -132,7 +134,7 @@ void initialize_mpi(MPI_Comm intracomm) mpi::master = (mpi::rank == 0); // Create bank datatype - Particle::Bank b; + SourceSite b; MPI_Aint disp[9]; MPI_Get_address(&b.r, &disp[0]); MPI_Get_address(&b.u, &disp[1]); @@ -149,8 +151,8 @@ void initialize_mpi(MPI_Comm intracomm) int blocks[] {3, 3, 1, 1, 1, 1, 1, 1, 1}; MPI_Datatype types[] {MPI_DOUBLE, MPI_DOUBLE, MPI_DOUBLE, MPI_DOUBLE, MPI_INT, MPI_INT, MPI_INT, MPI_LONG, MPI_LONG}; - MPI_Type_create_struct(9, blocks, disp, types, &mpi::bank); - MPI_Type_commit(&mpi::bank); + MPI_Type_create_struct(9, blocks, disp, types, &mpi::source_site); + MPI_Type_commit(&mpi::source_site); } #endif // OPENMC_MPI diff --git a/src/lattice.cpp b/src/lattice.cpp index 5301f3d14..ee102eb3b 100644 --- a/src/lattice.cpp +++ b/src/lattice.cpp @@ -2,7 +2,6 @@ #include #include -#include #include @@ -12,9 +11,9 @@ #include "openmc/geometry_aux.h" #include "openmc/hdf5_interface.h" #include "openmc/string_utils.h" +#include "openmc/vector.h" #include "openmc/xml_interface.h" - namespace openmc { //============================================================================== @@ -23,7 +22,7 @@ namespace openmc { namespace model { std::unordered_map lattice_map; - std::vector> lattices; + vector> lattices; } //============================================================================== @@ -142,7 +141,7 @@ RectLattice::RectLattice(pugi::xml_node lat_node) // Read the number of lattice cells in each dimension. std::string dimension_str {get_node_value(lat_node, "dimension")}; - std::vector dimension_words {split(dimension_str)}; + vector dimension_words {split(dimension_str)}; if (dimension_words.size() == 2) { n_cells_[0] = std::stoi(dimension_words[0]); n_cells_[1] = std::stoi(dimension_words[1]); @@ -159,7 +158,7 @@ RectLattice::RectLattice(pugi::xml_node lat_node) // Read the lattice lower-left location. std::string ll_str {get_node_value(lat_node, "lower_left")}; - std::vector ll_words {split(ll_str)}; + vector ll_words {split(ll_str)}; if (ll_words.size() != dimension_words.size()) { fatal_error("Number of entries on must be the same as the " "number of entries on ."); @@ -170,7 +169,7 @@ RectLattice::RectLattice(pugi::xml_node lat_node) // Read the lattice pitches. std::string pitch_str {get_node_value(lat_node, "pitch")}; - std::vector pitch_words {split(pitch_str)}; + vector pitch_words {split(pitch_str)}; if (pitch_words.size() != dimension_words.size()) { fatal_error("Number of entries on must be the same as the " "number of entries on ."); @@ -181,20 +180,23 @@ RectLattice::RectLattice(pugi::xml_node lat_node) // Read the universes and make sure the correct number was specified. std::string univ_str {get_node_value(lat_node, "universes")}; - std::vector univ_words {split(univ_str)}; - if (univ_words.size() != nx*ny*nz) { + vector univ_words {split(univ_str)}; + if (univ_words.size() != n_cells_[0] * n_cells_[1] * n_cells_[2]) { fatal_error(fmt::format( "Expected {} universes for a rectangular lattice of size {}x{}x{} but {} " - "were specified.", nx*ny*nz, nx, ny, nz, univ_words.size())); + "were specified.", + n_cells_[0] * n_cells_[1] * n_cells_[2], n_cells_[0], n_cells_[1], + n_cells_[2], univ_words.size())); } // Parse the universes. - universes_.resize(nx*ny*nz, C_NONE); - for (int iz = 0; iz < nz; iz++) { - for (int iy = ny-1; iy > -1; iy--) { - for (int ix = 0; ix < nx; ix++) { - int indx1 = nx*ny*iz + nx*(ny-iy-1) + ix; - int indx2 = nx*ny*iz + nx*iy + ix; + universes_.resize(n_cells_[0] * n_cells_[1] * n_cells_[2], C_NONE); + for (int iz = 0; iz < n_cells_[2]; iz++) { + for (int iy = n_cells_[1] - 1; iy > -1; iy--) { + for (int ix = 0; ix < n_cells_[0]; ix++) { + int indx1 = n_cells_[0] * n_cells_[1] * iz + + n_cells_[0] * (n_cells_[1] - iy - 1) + ix; + int indx2 = n_cells_[0] * n_cells_[1] * iz + n_cells_[0] * iy + ix; universes_[indx1] = std::stoi(univ_words[indx2]); } } @@ -203,17 +205,16 @@ RectLattice::RectLattice(pugi::xml_node lat_node) //============================================================================== -int32_t& -RectLattice::operator[](std::array i_xyz) +int32_t const& RectLattice::operator[](array const& i_xyz) { - int indx = nx*ny*i_xyz[2] + nx*i_xyz[1] + i_xyz[0]; + int indx = + n_cells_[0] * n_cells_[1] * i_xyz[2] + n_cells_[0] * i_xyz[1] + i_xyz[0]; return universes_[indx]; } //============================================================================== -bool -RectLattice::are_valid_indices(const int i_xyz[3]) const +bool RectLattice::are_valid_indices(array const& i_xyz) const { return ( (i_xyz[0] >= 0) && (i_xyz[0] < n_cells_[0]) && (i_xyz[1] >= 0) && (i_xyz[1] < n_cells_[1]) @@ -222,9 +223,8 @@ RectLattice::are_valid_indices(const int i_xyz[3]) const //============================================================================== -std::pair> -RectLattice::distance(Position r, Direction u, const std::array& i_xyz) -const +std::pair> RectLattice::distance( + Position r, Direction u, const array& i_xyz) const { // Get short aliases to the coordinates. double x = r.x; @@ -237,7 +237,7 @@ const // Left and right sides double d {INFTY}; - std::array lattice_trans; + array lattice_trans; if ((std::abs(x - x0) > FP_PRECISION) && u.x != 0) { d = (x0 - x) / u.x; if (u.x > 0) { @@ -281,48 +281,44 @@ const //============================================================================== -std::array -RectLattice::get_indices(Position r, Direction u) const +void RectLattice::get_indices( + Position r, Direction u, array& result) const { // Determine x index, accounting for coincidence double ix_ {(r.x - lower_left_.x) / pitch_.x}; long ix_close {std::lround(ix_)}; - int ix; if (coincident(ix_, ix_close)) { - ix = (u.x > 0) ? ix_close : ix_close - 1; + result[0] = (u.x > 0) ? ix_close : ix_close - 1; } else { - ix = std::floor(ix_); + result[0] = std::floor(ix_); } // Determine y index, accounting for coincidence double iy_ {(r.y - lower_left_.y) / pitch_.y}; long iy_close {std::lround(iy_)}; - int iy; if (coincident(iy_, iy_close)) { - iy = (u.y > 0) ? iy_close : iy_close - 1; + result[1] = (u.y > 0) ? iy_close : iy_close - 1; } else { - iy = std::floor(iy_); + result[1] = std::floor(iy_); } // Determine z index, accounting for coincidence - int iz = 0; + result[2] = 0; if (is_3d_) { double iz_ {(r.z - lower_left_.z) / pitch_.z}; long iz_close {std::lround(iz_)}; if (coincident(iz_, iz_close)) { - iz = (u.z > 0) ? iz_close : iz_close - 1; + result[2] = (u.z > 0) ? iz_close : iz_close - 1; } else { - iz = std::floor(iz_); + result[2] = std::floor(iz_); } } - return {ix, iy, iz}; } //============================================================================== -Position -RectLattice::get_local_position(Position r, const std::array i_xyz) -const +Position RectLattice::get_local_position( + Position r, const array& i_xyz) const { r.x -= (lower_left_.x + (i_xyz[0] + 0.5)*pitch_.x); r.y -= (lower_left_.y + (i_xyz[1] + 0.5)*pitch_.y); @@ -334,10 +330,11 @@ const //============================================================================== -int32_t& -RectLattice::offset(int map, const int i_xyz[3]) +int32_t& RectLattice::offset(int map, array const& i_xyz) { - return offsets_[nx*ny*nz*map + nx*ny*i_xyz[2] + nx*i_xyz[1] + i_xyz[0]]; + return offsets_[n_cells_[0] * n_cells_[1] * n_cells_[2] * map + + n_cells_[0] * n_cells_[1] * i_xyz[2] + + n_cells_[0] * i_xyz[1] + i_xyz[0]]; } //============================================================================== @@ -345,7 +342,7 @@ RectLattice::offset(int map, const int i_xyz[3]) int32_t RectLattice::offset(int map, int indx) const { - return offsets_[nx*ny*nz*map + indx]; + return offsets_[n_cells_[0] * n_cells_[1] * n_cells_[2] * map + indx]; } //============================================================================== @@ -353,9 +350,9 @@ RectLattice::offset(int map, int indx) const std::string RectLattice::index_to_string(int indx) const { - int iz {indx / (nx * ny)}; - int iy {(indx - nx * ny * iz) / nx}; - int ix {indx - nx * ny * iz - nx * iy}; + int iz {indx / (n_cells_[0] * n_cells_[1])}; + int iy {(indx - n_cells_[0] * n_cells_[1] * iz) / n_cells_[0]}; + int ix {indx - n_cells_[0] * n_cells_[1] * iz - n_cells_[0] * iy}; std::string out {std::to_string(ix)}; out += ','; out += std::to_string(iy); @@ -378,11 +375,11 @@ RectLattice::to_hdf5_inner(hid_t lat_group) const write_dataset(lat_group, "lower_left", lower_left_); write_dataset(lat_group, "dimension", n_cells_); } else { - std::array pitch_short {{pitch_[0], pitch_[1]}}; + array pitch_short {{pitch_[0], pitch_[1]}}; write_dataset(lat_group, "pitch", pitch_short); - std::array ll_short {{lower_left_[0], lower_left_[1]}}; + array ll_short {{lower_left_[0], lower_left_[1]}}; write_dataset(lat_group, "lower_left", ll_short); - std::array nc_short {{n_cells_[0], n_cells_[1]}}; + array nc_short {{n_cells_[0], n_cells_[1]}}; write_dataset(lat_group, "dimension", nc_short); } @@ -392,7 +389,7 @@ RectLattice::to_hdf5_inner(hid_t lat_group) const hsize_t nx {static_cast(n_cells_[0])}; hsize_t ny {static_cast(n_cells_[1])}; hsize_t nz {static_cast(n_cells_[2])}; - std::vector out(nx*ny*nz); + vector out(nx * ny * nz); for (int m = 0; m < nz; m++) { for (int k = 0; k < ny; k++) { @@ -410,7 +407,7 @@ RectLattice::to_hdf5_inner(hid_t lat_group) const } else { hsize_t nx {static_cast(n_cells_[0])}; hsize_t ny {static_cast(n_cells_[1])}; - std::vector out(nx*ny); + vector out(nx * ny); for (int k = 0; k < ny; k++) { for (int j = 0; j < nx; j++) { @@ -461,7 +458,7 @@ HexLattice::HexLattice(pugi::xml_node lat_node) // Read the lattice center. std::string center_str {get_node_value(lat_node, "center")}; - std::vector center_words {split(center_str)}; + vector center_words {split(center_str)}; if (is_3d_ && (center_words.size() != 3)) { fatal_error("A hexagonal lattice with must have
" "specified by 3 numbers."); @@ -475,7 +472,7 @@ HexLattice::HexLattice(pugi::xml_node lat_node) // Read the lattice pitches. std::string pitch_str {get_node_value(lat_node, "pitch")}; - std::vector pitch_words {split(pitch_str)}; + vector pitch_words {split(pitch_str)}; if (is_3d_ && (pitch_words.size() != 2)) { fatal_error("A hexagonal lattice with must have " "specified by 2 numbers."); @@ -489,7 +486,7 @@ HexLattice::HexLattice(pugi::xml_node lat_node) // Read the universes and make sure the correct number was specified. int n_univ = (3*n_rings_*n_rings_ - 3*n_rings_ + 1) * n_axial_; std::string univ_str {get_node_value(lat_node, "universes")}; - std::vector univ_words {split(univ_str)}; + vector univ_words {split(univ_str)}; if (univ_words.size() != n_univ) { fatal_error(fmt::format( "Expected {} universes for a hexagonal lattice with {} rings and {} " @@ -516,8 +513,7 @@ HexLattice::HexLattice(pugi::xml_node lat_node) //============================================================================== -void -HexLattice::fill_lattice_x(const std::vector& univ_words) +void HexLattice::fill_lattice_x(const vector& univ_words) { int input_index = 0; for (int m = 0; m < n_axial_; m++) { @@ -569,8 +565,7 @@ HexLattice::fill_lattice_x(const std::vector& univ_words) //============================================================================== -void -HexLattice::fill_lattice_y(const std::vector& univ_words) +void HexLattice::fill_lattice_y(const vector& univ_words) { int input_index = 0; for (int m = 0; m < n_axial_; m++) { @@ -657,8 +652,7 @@ HexLattice::fill_lattice_y(const std::vector& univ_words) //============================================================================== -int32_t& -HexLattice::operator[](std::array i_xyz) +int32_t const& HexLattice::operator[](array const& i_xyz) { int indx = (2*n_rings_-1)*(2*n_rings_-1) * i_xyz[2] + (2*n_rings_-1) * i_xyz[1] @@ -676,8 +670,7 @@ ReverseLatticeIter HexLattice::rbegin() //============================================================================== -bool -HexLattice::are_valid_indices(const int i_xyz[3]) const +bool HexLattice::are_valid_indices(array const& i_xyz) const { // Check if (x, alpha, z) indices are valid, accounting for number of rings return ((i_xyz[0] >= 0) && (i_xyz[1] >= 0) && (i_xyz[2] >= 0) @@ -689,9 +682,8 @@ HexLattice::are_valid_indices(const int i_xyz[3]) const //============================================================================== -std::pair> -HexLattice::distance(Position r, Direction u, const std::array& i_xyz) -const +std::pair> HexLattice::distance( + Position r, Direction u, const array& i_xyz) const { // Short description of the direction vectors used here. The beta, gamma, and // delta vectors point towards the flat sides of each hexagonal tile. @@ -729,14 +721,14 @@ const // beta direction double d {INFTY}; - std::array lattice_trans; + array lattice_trans; double edge = -copysign(0.5*pitch_[0], beta_dir); // Oncoming edge Position r_t; if (beta_dir > 0) { - const std::array i_xyz_t {i_xyz[0]+1, i_xyz[1], i_xyz[2]}; + const array i_xyz_t {i_xyz[0] + 1, i_xyz[1], i_xyz[2]}; r_t = get_local_position(r, i_xyz_t); } else { - const std::array i_xyz_t {i_xyz[0]-1, i_xyz[1], i_xyz[2]}; + const array i_xyz_t {i_xyz[0] - 1, i_xyz[1], i_xyz[2]}; r_t = get_local_position(r, i_xyz_t); } double beta; @@ -757,10 +749,10 @@ const // gamma direction edge = -copysign(0.5*pitch_[0], gamma_dir); if (gamma_dir > 0) { - const std::array i_xyz_t {i_xyz[0]+1, i_xyz[1]-1, i_xyz[2]}; + const array i_xyz_t {i_xyz[0] + 1, i_xyz[1] - 1, i_xyz[2]}; r_t = get_local_position(r, i_xyz_t); } else { - const std::array i_xyz_t {i_xyz[0]-1, i_xyz[1]+1, i_xyz[2]}; + const array i_xyz_t {i_xyz[0] - 1, i_xyz[1] + 1, i_xyz[2]}; r_t = get_local_position(r, i_xyz_t); } double gamma; @@ -784,10 +776,10 @@ const // delta direction edge = -copysign(0.5*pitch_[0], delta_dir); if (delta_dir > 0) { - const std::array i_xyz_t {i_xyz[0], i_xyz[1]+1, i_xyz[2]}; + const array i_xyz_t {i_xyz[0], i_xyz[1] + 1, i_xyz[2]}; r_t = get_local_position(r, i_xyz_t); } else { - const std::array i_xyz_t {i_xyz[0], i_xyz[1]-1, i_xyz[2]}; + const array i_xyz_t {i_xyz[0], i_xyz[1] - 1, i_xyz[2]}; r_t = get_local_position(r, i_xyz_t); } double delta; @@ -831,44 +823,43 @@ const //============================================================================== -std::array -HexLattice::get_indices(Position r, Direction u) const +void HexLattice::get_indices( + Position r, Direction u, array& result) const { // Offset the xyz by the lattice center. Position r_o {r.x - center_.x, r.y - center_.y, r.z}; if (is_3d_) {r_o.z -= center_.z;} // Index the z direction, accounting for coincidence - int iz = 0; + result[2] = 0; if (is_3d_) { double iz_ {r_o.z / pitch_[1] + 0.5 * n_axial_}; long iz_close {std::lround(iz_)}; if (coincident(iz_, iz_close)) { - iz = (u.z > 0) ? iz_close : iz_close - 1; + result[2] = (u.z > 0) ? iz_close : iz_close - 1; } else { - iz = std::floor(iz_); + result[2] = std::floor(iz_); } } - int i1, i2; if (orientation_ == Orientation::y) { // Convert coordinates into skewed bases. The (x, alpha) basis is used to // find the index of the global coordinates to within 4 cells. double alpha = r_o.y - r_o.x / std::sqrt(3.0); - i1 = std::floor(r_o.x / (0.5*std::sqrt(3.0) * pitch_[0])); - i2 = std::floor(alpha / pitch_[0]); + result[0] = std::floor(r_o.x / (0.5 * std::sqrt(3.0) * pitch_[0])); + result[1] = std::floor(alpha / pitch_[0]); } else { // Convert coordinates into skewed bases. The (alpha, y) basis is used to // find the index of the global coordinates to within 4 cells. double alpha = r_o.y - r_o.x * std::sqrt(3.0); - i1 = std::floor(-alpha / (std::sqrt(3.0) * pitch_[0])); - i2 = std::floor(r_o.y / (0.5*std::sqrt(3.0) * pitch_[0])); + result[0] = std::floor(-alpha / (std::sqrt(3.0) * pitch_[0])); + result[1] = std::floor(r_o.y / (0.5 * std::sqrt(3.0) * pitch_[0])); } // Add offset to indices (the center cell is (i1, i2) = (0, 0) but // the array is offset so that the indices never go below 0). - i1 += n_rings_-1; - i2 += n_rings_-1; + result[0] += n_rings_ - 1; + result[1] += n_rings_ - 1; // Calculate the (squared) distance between the particle and the centers of // the four possible cells. Regular hexagonal tiles form a Voronoi @@ -887,14 +878,14 @@ HexLattice::get_indices(Position r, Direction u) const // is kept (i.e. the cell with the lowest dot product as the vectors will be // completely opposed if the particle is moving directly toward the center of // the cell). - int i1_chg {}; - int i2_chg {}; + int i1_chg; + int i2_chg; double d_min {INFTY}; double dp_min {INFTY}; for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { // get local coordinates - const std::array i_xyz {i1 + j, i2 + i, 0}; + const array i_xyz {result[0] + j, result[1] + i, 0}; Position r_t = get_local_position(r, i_xyz); // calculate distance double d = r_t.x*r_t.x + r_t.y*r_t.y; @@ -921,17 +912,14 @@ HexLattice::get_indices(Position r, Direction u) const } // update outgoing indices - i1 += i1_chg; - i2 += i2_chg; - - return {i1, i2, iz}; + result[0] += i1_chg; + result[1] += i2_chg; } //============================================================================== -Position -HexLattice::get_local_position(Position r, const std::array i_xyz) -const +Position HexLattice::get_local_position( + Position r, const array& i_xyz) const { if (orientation_ == Orientation::y) { // x_l = x_g - (center + pitch_x*cos(30)*index_x) @@ -966,14 +954,13 @@ HexLattice::is_valid_index(int indx) const int iz = indx / (nx * ny); int iy = (indx - nx*ny*iz) / nx; int ix = indx - nx*ny*iz - nx*iy; - int i_xyz[3] {ix, iy, iz}; + array i_xyz {ix, iy, iz}; return are_valid_indices(i_xyz); } //============================================================================== -int32_t& -HexLattice::offset(int map, const int i_xyz[3]) +int32_t& HexLattice::offset(int map, array const& i_xyz) { int nx {2*n_rings_ - 1}; int ny {2*n_rings_ - 1}; @@ -1028,9 +1015,9 @@ HexLattice::to_hdf5_inner(hid_t lat_group) const write_dataset(lat_group, "pitch", pitch_); write_dataset(lat_group, "center", center_); } else { - std::array pitch_short {{pitch_[0]}}; + array pitch_short {{pitch_[0]}}; write_dataset(lat_group, "pitch", pitch_short); - std::array center_short {{center_[0], center_[1]}}; + array center_short {{center_[0], center_[1]}}; write_dataset(lat_group, "center", center_short); } @@ -1038,7 +1025,7 @@ HexLattice::to_hdf5_inner(hid_t lat_group) const hsize_t nx {static_cast(2*n_rings_ - 1)}; hsize_t ny {static_cast(2*n_rings_ - 1)}; hsize_t nz {static_cast(n_axial_)}; - std::vector out(nx*ny*nz); + vector out(nx * ny * nz); for (int m = 0; m < nz; m++) { for (int k = 0; k < ny; k++) { @@ -1068,10 +1055,10 @@ HexLattice::to_hdf5_inner(hid_t lat_group) const void read_lattices(pugi::xml_node node) { for (pugi::xml_node lat_node : node.children("lattice")) { - model::lattices.push_back(std::make_unique(lat_node)); + model::lattices.push_back(make_unique(lat_node)); } for (pugi::xml_node lat_node : node.children("hex_lattice")) { - model::lattices.push_back(std::make_unique(lat_node)); + model::lattices.push_back(make_unique(lat_node)); } // Fill the lattice map. diff --git a/src/material.cpp b/src/material.cpp index 89d5d5add..59d2f954e 100644 --- a/src/material.cpp +++ b/src/material.cpp @@ -39,7 +39,7 @@ namespace openmc { namespace model { std::unordered_map material_map; -std::vector> materials; +vector> materials; } // namespace model @@ -127,8 +127,8 @@ Material::Material(pugi::xml_node node) auto node_macros = node.children("macroscopic"); int num_macros = std::distance(node_macros.begin(), node_macros.end()); - std::vector names; - std::vector densities; + vector names; + vector densities; if (settings::run_CE && num_macros > 0) { fatal_error("Macroscopic can not be used in continuous-energy mode."); } else if (num_macros > 1) { @@ -194,7 +194,7 @@ Material::Material(pugi::xml_node node) // ======================================================================= // READ AND PARSE element - std::vector iso_lab; + vector iso_lab; if (check_for_node(node, "isotropic")) { iso_lab = get_node_array(node, "isotropic"); } @@ -295,7 +295,7 @@ Material::Material(pugi::xml_node node) if (settings::run_CE) { // Loop over elements - std::vector sab_names; + vector sab_names; for (auto node_sab : node.children("sab")) { // Determine name of thermal scattering table if (!check_for_node(node_sab, "name")) { @@ -413,7 +413,7 @@ void Material::normalize_density() void Material::init_thermal() { - std::vector tables; + vector tables; std::unordered_set already_checked; for (const auto& table : thermal_tables_) { @@ -481,8 +481,8 @@ void Material::collision_stopping_power(double* s_col, bool positron) // Oscillator strength and square of the binding energy for each oscillator // in material - std::vector f; - std::vector e_b_sq; + vector f; + vector e_b_sq; for (int i = 0; i < element_.size(); ++i) { const auto& elm = *data::elements[element_[i]]; @@ -565,7 +565,7 @@ void Material::collision_stopping_power(double* s_col, bool positron) void Material::init_bremsstrahlung() { // Create new object - ttb_ = std::make_unique(); + ttb_ = make_unique(); // Get the size of the energy grids auto n_k = data::ttb_k_grid.size(); @@ -748,14 +748,14 @@ void Material::init_nuclide_index() void Material::calculate_xs(Particle& p) const { // Set all material macroscopic cross sections to zero - p.macro_xs_.total = 0.0; - p.macro_xs_.absorption = 0.0; - p.macro_xs_.fission = 0.0; - p.macro_xs_.nu_fission = 0.0; + p.macro_xs().total = 0.0; + p.macro_xs().absorption = 0.0; + p.macro_xs().fission = 0.0; + p.macro_xs().nu_fission = 0.0; - if (p.type_ == Particle::Type::neutron) { + if (p.type() == ParticleType::neutron) { this->calculate_neutron_xs(p); - } else if (p.type_ == Particle::Type::photon) { + } else if (p.type() == ParticleType::photon) { this->calculate_photon_xs(p); } } @@ -763,8 +763,9 @@ void Material::calculate_xs(Particle& p) const void Material::calculate_neutron_xs(Particle& p) const { // Find energy index on energy grid - int neutron = static_cast(Particle::Type::neutron); - int i_grid = std::log(p.E_/data::energy_min[neutron])/simulation::log_spacing; + int neutron = static_cast(ParticleType::neutron); + int i_grid = + std::log(p.E() / data::energy_min[neutron]) / simulation::log_spacing; // Determine if this material has S(a,b) tables bool check_sab = (thermal_tables_.size() > 0); @@ -791,7 +792,8 @@ void Material::calculate_neutron_xs(Particle& p) const // If particle energy is greater than the highest energy for the // S(a,b) table, then don't use the S(a,b) table - if (p.E_ > data::thermal_scatt[i_sab]->energy_max_) i_sab = C_NONE; + if (p.E() > data::thermal_scatt[i_sab]->energy_max_) + i_sab = C_NONE; // Increment position in thermal_tables_ ++j; @@ -808,11 +810,9 @@ void Material::calculate_neutron_xs(Particle& p) const int i_nuclide = nuclide_[i]; // Calculate microscopic cross section for this nuclide - const auto& micro {p.neutron_xs_[i_nuclide]}; - if (p.E_ != micro.last_E - || p.sqrtkT_ != micro.last_sqrtkT - || i_sab != micro.index_sab - || sab_frac != micro.sab_frac) { + const auto& micro {p.neutron_xs(i_nuclide)}; + if (p.E() != micro.last_E || p.sqrtkT() != micro.last_sqrtkT || + i_sab != micro.index_sab || sab_frac != micro.sab_frac) { data::nuclides[i_nuclide]->calculate_xs(i_sab, i_grid, sab_frac, p); } @@ -823,19 +823,19 @@ void Material::calculate_neutron_xs(Particle& p) const double atom_density = atom_density_(i); // Add contributions to cross sections - p.macro_xs_.total += atom_density * micro.total; - p.macro_xs_.absorption += atom_density * micro.absorption; - p.macro_xs_.fission += atom_density * micro.fission; - p.macro_xs_.nu_fission += atom_density * micro.nu_fission; + p.macro_xs().total += atom_density * micro.total; + p.macro_xs().absorption += atom_density * micro.absorption; + p.macro_xs().fission += atom_density * micro.fission; + p.macro_xs().nu_fission += atom_density * micro.nu_fission; } } void Material::calculate_photon_xs(Particle& p) const { - p.macro_xs_.coherent = 0.0; - p.macro_xs_.incoherent = 0.0; - p.macro_xs_.photoelectric = 0.0; - p.macro_xs_.pair_production = 0.0; + p.macro_xs().coherent = 0.0; + p.macro_xs().incoherent = 0.0; + p.macro_xs().photoelectric = 0.0; + p.macro_xs().pair_production = 0.0; // Add contribution from each nuclide in material for (int i = 0; i < nuclide_.size(); ++i) { @@ -846,8 +846,8 @@ void Material::calculate_photon_xs(Particle& p) const int i_element = element_[i]; // Calculate microscopic cross section for this nuclide - const auto& micro {p.photon_xs_[i_element]}; - if (p.E_ != micro.last_E) { + const auto& micro {p.photon_xs(i_element)}; + if (p.E() != micro.last_E) { data::elements[i_element]->calculate_xs(p); } @@ -858,11 +858,11 @@ void Material::calculate_photon_xs(Particle& p) const double atom_density = atom_density_(i); // Add contributions to material macroscopic cross sections - p.macro_xs_.total += atom_density * micro.total; - p.macro_xs_.coherent += atom_density * micro.coherent; - p.macro_xs_.incoherent += atom_density * micro.incoherent; - p.macro_xs_.photoelectric += atom_density * micro.photoelectric; - p.macro_xs_.pair_production += atom_density * micro.pair_production; + p.macro_xs().total += atom_density * micro.total; + p.macro_xs().coherent += atom_density * micro.coherent; + p.macro_xs().incoherent += atom_density * micro.incoherent; + p.macro_xs().photoelectric += atom_density * micro.photoelectric; + p.macro_xs().pair_production += atom_density * micro.pair_production; } } @@ -936,8 +936,8 @@ void Material::set_density(double density, gsl::cstring_span units) } } -void Material::set_densities(const std::vector& name, - const std::vector& density) +void Material::set_densities( + const vector& name, const vector& density) { auto n = name.size(); Expects(n > 0); @@ -1010,9 +1010,9 @@ void Material::to_hdf5(hid_t group) const write_dataset(material_group, "atom_density", density_); // Copy nuclide/macro name for each nuclide to vector - std::vector nuc_names; - std::vector macro_names; - std::vector nuc_densities; + vector nuc_names; + vector macro_names; + vector nuc_densities; if (settings::run_CE) { for (int i = 0; i < nuclide_.size(); ++i) { int i_nuc = nuclide_[i]; @@ -1043,7 +1043,7 @@ void Material::to_hdf5(hid_t group) const } if (!thermal_tables_.empty()) { - std::vector sab_names; + vector sab_names; for (const auto& table : thermal_tables_) { sab_names.push_back(data::thermal_scatt[table.index_table]->name_); } @@ -1099,9 +1099,9 @@ void Material::add_nuclide(const std::string& name, double density) // Non-method functions //============================================================================== -double sternheimer_adjustment(const std::vector& f, const - std::vector& e_b_sq, double e_p_sq, double n_conduction, double - log_I, double tol, int max_iter) +double sternheimer_adjustment(const vector& f, + const vector& e_b_sq, double e_p_sq, double n_conduction, + double log_I, double tol, int max_iter) { // Get the total number of oscillators int n = f.size(); @@ -1144,8 +1144,8 @@ double sternheimer_adjustment(const std::vector& f, const return rho; } -double density_effect(const std::vector& f, const std::vector& - e_b_sq, double e_p_sq, double n_conduction, double rho, double E, double tol, +double density_effect(const vector& f, const vector& e_b_sq, + double e_p_sq, double n_conduction, double rho, double E, double tol, int max_iter) { // Get the total number of oscillators @@ -1245,7 +1245,7 @@ void read_materials_xml() // Loop over XML material elements and populate the array. pugi::xml_node root = doc.document_element(); for (pugi::xml_node material_node : root.children("material")) { - model::materials.push_back(std::make_unique(material_node)); + model::materials.push_back(make_unique(material_node)); } model::materials.shrink_to_fit(); } @@ -1475,7 +1475,7 @@ openmc_extend_materials(int32_t n, int32_t* index_start, int32_t* index_end) if (index_start) *index_start = model::materials.size(); if (index_end) *index_end = model::materials.size() + n - 1; for (int32_t i = 0; i < n; i++) { - model::materials.push_back(std::make_unique()); + model::materials.push_back(make_unique()); } return 0; } diff --git a/src/math_functions.cpp b/src/math_functions.cpp index 1dd2726c7..b9d058b70 100644 --- a/src/math_functions.cpp +++ b/src/math_functions.cpp @@ -540,8 +540,8 @@ void calc_zn(int n, double rho, double phi, double zn[]) { double sin_phi = std::sin(phi); double cos_phi = std::cos(phi); - std::vector sin_phi_vec(n + 1); // Sin[n * phi] - std::vector cos_phi_vec(n + 1); // Cos[n * phi] + vector sin_phi_vec(n + 1); // Sin[n * phi] + vector cos_phi_vec(n + 1); // Cos[n * phi] sin_phi_vec[0] = 1.0; cos_phi_vec[0] = 1.0; sin_phi_vec[1] = 2.0 * cos_phi; @@ -559,7 +559,7 @@ void calc_zn(int n, double rho, double phi, double zn[]) { // =========================================================================== // Calculate R_pq(rho) // Matrix forms of the coefficients which are easier to work with - std::vector> zn_mat(n + 1, std::vector(n + 1)); + vector> zn_mat(n + 1, vector(n + 1)); // Fill the main diagonal first (Eq 3.9 in Chong) for (int p = 0; p <= n; p++) { @@ -674,7 +674,7 @@ Direction rotate_angle(Direction u, double mu, const double* phi, uint64_t* seed void spline(int n, const double x[], const double y[], double z[]) { - std::vector c_new(n-1); + vector c_new(n - 1); // Set natural boundary conditions c_new[0] = 0.0; diff --git a/src/mesh.cpp b/src/mesh.cpp index 9e974477c..11c7767eb 100644 --- a/src/mesh.cpp +++ b/src/mesh.cpp @@ -2,7 +2,6 @@ #include // for copy, equal, min, min_element #include // for size_t #include // for ceil -#include // for allocator #include #include @@ -25,11 +24,12 @@ #include "openmc/error.h" #include "openmc/file_utils.h" #include "openmc/hdf5_interface.h" +#include "openmc/memory.h" #include "openmc/message_passing.h" #include "openmc/search.h" #include "openmc/settings.h" -#include "openmc/tallies/tally.h" #include "openmc/tallies/filter.h" +#include "openmc/tallies/tally.h" #include "openmc/xml_interface.h" #ifdef LIBMESH @@ -53,13 +53,13 @@ const bool LIBMESH_ENABLED = false; namespace model { std::unordered_map mesh_map; -std::vector> meshes; +vector> meshes; } // namespace model #ifdef LIBMESH namespace settings { -std::unique_ptr libmesh_init; +unique_ptr libmesh_init; const libMesh::Parallel::Communicator* libmesh_comm {nullptr}; } #endif @@ -143,7 +143,7 @@ Mesh::set_id(int32_t id) { std::string StructuredMesh::bin_label(int bin) const { - std::vector ijk(n_dimension_); + vector ijk(n_dimension_); get_indices_from_bin(bin, ijk.data()); if (n_dimension_ > 2) { @@ -192,7 +192,7 @@ UnstructuredMesh::UnstructuredMesh(pugi::xml_node node) : Mesh(node) { void UnstructuredMesh::surface_bins_crossed(Position r0, Position r1, - std::vector& bins) const { + vector& bins) const { fatal_error("Unstructured mesh surface tallies are not implemented."); } @@ -210,7 +210,7 @@ UnstructuredMesh::to_hdf5(hid_t group) const write_dataset(mesh_group, "filename", filename_); write_dataset(mesh_group, "library", this->library()); // write volume of each element - std::vector tet_vols; + vector tet_vols; xt::xtensor centroids({static_cast(this->n_bins()), 3}); for (int i = 0; i < this->n_bins(); i++) { tet_vols.emplace_back(this->volume(i)); @@ -264,7 +264,7 @@ void StructuredMesh::get_indices_from_bin(int bin, int* ijk) const int StructuredMesh::get_bin(Position r) const { // Determine indices - std::vector ijk(n_dimension_); + vector ijk(n_dimension_); bool in_mesh; get_indices(r, ijk.data(), &in_mesh); if (!in_mesh) return -1; @@ -283,14 +283,12 @@ int StructuredMesh::n_surface_bins() const return 4 * n_dimension_ * n_bins(); } -xt::xtensor -StructuredMesh::count_sites(const Particle::Bank* bank, - int64_t length, - bool* outside) const +xt::xtensor StructuredMesh::count_sites( + const SourceSite* bank, int64_t length, bool* outside) const { // Determine shape of array for counts std::size_t m = this->n_bins(); - std::vector shape = {m}; + vector shape = {m}; // Create array of zeros xt::xarray cnt {shape, 0.0}; @@ -585,8 +583,8 @@ bool StructuredMesh::intersects_3d(Position& r0, Position r1, int* ijk) const void StructuredMesh::bins_crossed(Position r0, Position r1, const Direction& u, - std::vector& bins, - std::vector& lengths) const + vector& bins, + vector& lengths) const { // ======================================================================== // Determine where the track intersects the mesh and if it intersects at all. @@ -602,7 +600,7 @@ void StructuredMesh::bins_crossed(Position r0, Position r = r1 - TINY_BIT*u; // Determine the mesh indices for the starting and ending coords. Here, we - // use arrays for ijk0 and ijk1 instead of std::vector because we obtain a + // use arrays for ijk0 and ijk1 instead of vector because we obtain a // small performance improvement by forcing this data to live on the stack, // rather than on the heap. We know the maximum length is 3, and by // ensuring that all loops are only indexed up to n_dimension, we will not @@ -800,11 +798,11 @@ void RegularMesh::surface_bins_crossed(Position r0, Position r1, const Direction& u, - std::vector& bins) const + vector& bins) const { // Determine indices for starting and ending location. int n = n_dimension_; - std::vector ijk0(n), ijk1(n); + vector ijk0(n), ijk1(n); bool start_in_mesh; get_indices(r0, ijk0.data(), &start_in_mesh); bool end_in_mesh; @@ -813,7 +811,7 @@ RegularMesh::surface_bins_crossed(Position r0, // Check if the track intersects any part of the mesh. if (!start_in_mesh) { Position r0_copy = r0; - std::vector ijk0_copy(ijk0); + vector ijk0_copy(ijk0); if (!intersects(r0_copy, r1, ijk0_copy.data())) return; } @@ -940,11 +938,11 @@ RegularMesh::surface_bins_crossed(Position r0, } } -std::pair, std::vector> -RegularMesh::plot(Position plot_ll, Position plot_ur) const +std::pair, vector> RegularMesh::plot( + Position plot_ll, Position plot_ur) const { // Figure out which axes lie in the plane of the plot. - std::array axes {-1, -1}; + array axes {-1, -1}; if (plot_ur.z == plot_ll.z) { axes[0] = 0; if (n_dimension_ > 1) axes[1] = 1; @@ -959,7 +957,7 @@ RegularMesh::plot(Position plot_ll, Position plot_ur) const } // Get the coordinates of the mesh lines along both of the axes. - std::array, 2> axis_lines; + array, 2> axis_lines; for (int i_ax = 0; i_ax < 2; ++i_ax) { int axis = axes[i_ax]; if (axis == -1) continue; @@ -989,14 +987,12 @@ void RegularMesh::to_hdf5(hid_t group) const close_group(mesh_group); } -xt::xtensor -RegularMesh::count_sites(const Particle::Bank* bank, - int64_t length, - bool* outside) const +xt::xtensor RegularMesh::count_sites( + const SourceSite* bank, int64_t length, bool* outside) const { // Determine shape of array for counts std::size_t m = this->n_bins(); - std::vector shape = {m}; + vector shape = {m}; // Create array of zeros xt::xarray cnt {shape, 0.0}; @@ -1104,7 +1100,7 @@ int RectilinearMesh::set_grid() void RectilinearMesh::surface_bins_crossed(Position r0, Position r1, const Direction& u, - std::vector& bins) const + vector& bins) const { // Determine indices for starting and ending location. int ijk0[3], ijk1[3]; @@ -1268,11 +1264,11 @@ int RectilinearMesh::get_index_in_direction(double r, int i) const return lower_bound_index(grid_[i].begin(), grid_[i].end(), r) + 1; } -std::pair, std::vector> -RectilinearMesh::plot(Position plot_ll, Position plot_ur) const +std::pair, vector> RectilinearMesh::plot( + Position plot_ll, Position plot_ur) const { // Figure out which axes lie in the plane of the plot. - std::array axes {-1, -1}; + array axes {-1, -1}; if (plot_ur.z == plot_ll.z) { axes = {0, 1}; } else if (plot_ur.y == plot_ll.y) { @@ -1284,10 +1280,10 @@ RectilinearMesh::plot(Position plot_ll, Position plot_ur) const } // Get the coordinates of the mesh lines along both of the axes. - std::array, 2> axis_lines; + array, 2> axis_lines; for (int i_ax = 0; i_ax < 2; ++i_ax) { int axis = axes[i_ax]; - std::vector& lines {axis_lines[i_ax]}; + vector& lines {axis_lines[i_ax]}; for (auto coord : grid_[axis]) { if (coord >= plot_ll[axis] && coord <= plot_ur[axis]) @@ -1370,9 +1366,9 @@ openmc_extend_meshes(int32_t n, const char* type, int32_t* index_start, for (int i = 0; i < n; ++i) { if (std::strcmp(type, "regular") == 0) { - model::meshes.push_back(std::make_unique()); + model::meshes.push_back(make_unique()); } else if (std::strcmp(type, "rectilinear") == 0) { - model::meshes.push_back(std::make_unique()); + model::meshes.push_back(make_unique()); } else { throw std::runtime_error{"Unknown mesh type: " + std::string(type)}; } @@ -1393,14 +1389,14 @@ extern "C" int openmc_add_unstructured_mesh(const char filename[], #ifdef DAGMC if (lib_name == "moab") { - model::meshes.push_back(std::move(std::make_unique(mesh_file))); + model::meshes.push_back(std::move(make_unique(mesh_file))); valid_lib = true; } #endif #ifdef LIBMESH if (lib_name == "libmesh") { - model::meshes.push_back(std::move(std::make_unique(mesh_file))); + model::meshes.push_back(std::move(make_unique(mesh_file))); valid_lib = true; } #endif @@ -1470,7 +1466,7 @@ openmc_regular_mesh_set_dimension(int32_t index, int n, const int* dims) RegularMesh* mesh = dynamic_cast(model::meshes[index].get()); // Copy dimension - std::vector shape = {static_cast(n)}; + vector shape = {static_cast(n)}; mesh->shape_ = xt::adapt(dims, n, xt::no_ownership(), shape); mesh->n_dimension_ = mesh->shape_.size(); return 0; @@ -1504,7 +1500,7 @@ openmc_regular_mesh_set_params(int32_t index, int n, const double* ll, if (int err = check_mesh_type(index)) return err; RegularMesh* m = dynamic_cast(model::meshes[index].get()); - std::vector shape = {static_cast(n)}; + vector shape = {static_cast(n)}; if (ll && ur) { m->lower_left_ = xt::adapt(ll, n, xt::no_ownership(), shape); m->upper_right_ = xt::adapt(ur, n, xt::no_ownership(), shape); @@ -1587,7 +1583,7 @@ MOABMesh::MOABMesh(const std::string& filename) { void MOABMesh::initialize() { // create MOAB instance - mbi_ = std::make_unique(); + mbi_ = make_unique(); // load unstructured mesh file moab::ErrorCode rval = mbi_->load_file(filename_.c_str()); if (rval != moab::MB_SUCCESS) { @@ -1647,7 +1643,7 @@ MOABMesh::build_kdtree(const moab::Range& all_tets) all_tets_and_tris.merge(all_tris); // create a kd-tree instance - kdtree_ = std::make_unique(mbi_.get()); + kdtree_ = make_unique(mbi_.get()); // build the tree rval = kdtree_->build_tree(all_tets_and_tris, &kdtree_root_); @@ -1657,15 +1653,13 @@ MOABMesh::build_kdtree(const moab::Range& all_tets) } } -void -MOABMesh::intersect_track(const moab::CartVect& start, - const moab::CartVect& dir, - double track_len, - std::vector& hits) const { +void MOABMesh::intersect_track(const moab::CartVect& start, + const moab::CartVect& dir, double track_len, vector& hits) const +{ hits.clear(); moab::ErrorCode rval; - std::vector tris; + vector tris; // get all intersections with triangles in the tet mesh // (distances are relative to the start point, not the previous intersection) rval = kdtree_->ray_intersect_triangles(kdtree_root_, @@ -1685,15 +1679,14 @@ MOABMesh::intersect_track(const moab::CartVect& start, // sorts by first component of std::pair by default std::sort(hits.begin(), hits.end()); - } void MOABMesh::bins_crossed(Position r0, Position r1, const Direction& u, - std::vector& bins, - std::vector& lengths) const + vector& bins, + vector& lengths) const { moab::CartVect start(r0.x, r0.y, r0.z); moab::CartVect end(r1.x, r1.y, r1.z); @@ -1706,7 +1699,7 @@ MOABMesh::bins_crossed(Position r0, start -= TINY_BIT * dir; end += TINY_BIT * dir; - std::vector hits; + vector hits; intersect_track(start, dir, track_len, hits); bins.clear(); @@ -1805,7 +1798,7 @@ std::string MOABMesh::library() const double MOABMesh::tet_volume(moab::EntityHandle tet) const { - std::vector conn; + vector conn; moab::ErrorCode rval = mbi_->get_connectivity(&tet, 1, conn); if (rval != moab::MB_SUCCESS) { fatal_error("Failed to get tet connectivity"); @@ -1820,10 +1813,8 @@ double MOABMesh::tet_volume(moab::EntityHandle tet) const return 1.0 / 6.0 * (((p[1] - p[0]) * (p[2] - p[0])) % (p[3] - p[0])); } -void MOABMesh::surface_bins_crossed(Position r0, - Position r1, - const Direction& u, - std::vector& bins) const +void MOABMesh::surface_bins_crossed( + Position r0, Position r1, const Direction& u, vector& bins) const { // TODO: Implement triangle crossings here @@ -1850,7 +1841,7 @@ MOABMesh::compute_barycentric_data(const moab::Range& tets) { // compute the barycentric data for each tet element // and store it as a 3x3 matrix for (auto& tet : tets) { - std::vector verts; + vector verts; rval = mbi_->get_connectivity(&tet, 1, verts); if (rval != moab::MB_SUCCESS) { fatal_error("Failed to get connectivity of tet on umesh: " + filename_); @@ -1878,7 +1869,7 @@ MOABMesh::point_in_tet(const moab::CartVect& r, moab::ErrorCode rval; // get tet vertices - std::vector verts; + vector verts; rval = mbi_->get_connectivity(&tet, 1, verts); if (rval != moab::MB_SUCCESS) { warning("Failed to get vertices of tet in umesh: " + filename_); @@ -1930,8 +1921,8 @@ int MOABMesh::get_index_from_bin(int bin) const return bin; } -std::pair, std::vector> -MOABMesh::plot(Position plot_ll, Position plot_ur) const +std::pair, vector> MOABMesh::plot( + Position plot_ll, Position plot_ur) const { // TODO: Implement mesh lines return {}; @@ -1982,7 +1973,7 @@ MOABMesh::centroid(int bin) const auto tet = this->get_ent_handle_from_bin(bin); // look up the tet connectivity - std::vector conn; + vector conn; rval = mbi_->get_connectivity(&tet, 1, conn); if (rval != moab::MB_SUCCESS) { warning("Failed to get connectivity of a mesh element."); @@ -1990,7 +1981,7 @@ MOABMesh::centroid(int bin) const } // get the coordinates - std::vector coords(conn.size()); + vector coords(conn.size()); rval = mbi_->get_coords(conn.data(), conn.size(), coords[0].array()); if (rval != moab::MB_SUCCESS) { warning("Failed to get the coordinates of a mesh element."); @@ -2089,10 +2080,8 @@ void MOABMesh::remove_scores() tag_names_.clear(); } -void -MOABMesh::set_score_data(const std::string& score, - const std::vector& values, - const std::vector& std_dev) +void MOABMesh::set_score_data(const std::string& score, + const vector& values, const vector& std_dev) { auto score_tags = this->get_score_tags(score); @@ -2157,7 +2146,7 @@ void LibMesh::initialize() // assuming that unstructured meshes used in OpenMC are 3D n_dimension_ = 3; - m_ = std::make_unique(*settings::libmesh_comm, n_dimension_); + m_ = make_unique(*settings::libmesh_comm, n_dimension_); m_->read(filename_); m_->prepare_for_use(); @@ -2169,7 +2158,7 @@ void LibMesh::initialize() // create an equation system for storing values eq_system_name_ = fmt::format("mesh_{}_system", id_); - equation_systems_ = std::make_unique(*m_); + equation_systems_ = make_unique(*m_); libMesh::ExplicitSystem& eq_sys = equation_systems_->add_system(eq_system_name_); @@ -2209,11 +2198,8 @@ int LibMesh::n_bins() const return m_->n_elem(); } -void -LibMesh::surface_bins_crossed(Position r0, - Position r1, - const Direction& u, - std::vector& bins) const +void LibMesh::surface_bins_crossed( + Position r0, Position r1, const Direction& u, vector& bins) const { // TODO: Implement triangle crossings here throw std::runtime_error{"Unstructured mesh surface tallies are not implemented."}; @@ -2263,10 +2249,8 @@ LibMesh::remove_scores() variable_map_.clear(); } -void -LibMesh::set_score_data(const std::string& var_name, - const std::vector& values, - const std::vector& std_dev) +void LibMesh::set_score_data(const std::string& var_name, + const vector& values, const vector& std_dev) { auto& eqn_sys = equation_systems_->get_system(eq_system_name_); @@ -2285,13 +2269,13 @@ LibMesh::set_score_data(const std::string& var_name, auto bin = get_bin_from_element(*it); // set value - std::vector value_dof_indices; + vector value_dof_indices; dof_map.dof_indices(*it, value_dof_indices, value_num); Ensures(value_dof_indices.size() == 1); eqn_sys.solution->set(value_dof_indices[0], values.at(bin)); // set std dev - std::vector std_dev_dof_indices; + vector std_dev_dof_indices; dof_map.dof_indices(*it, std_dev_dof_indices, std_dev_num); Ensures(std_dev_dof_indices.size() == 1); eqn_sys.solution->set(std_dev_dof_indices[0], std_dev.at(bin)); @@ -2310,8 +2294,8 @@ void LibMesh::bins_crossed(Position r0, Position r1, const Direction& u, - std::vector& bins, - std::vector& lengths) const + vector& bins, + vector& lengths) const { // TODO: Implement triangle crossings here fatal_error("Tracklength tallies on libMesh instances are not implemented."); @@ -2348,8 +2332,8 @@ LibMesh::get_bin_from_element(const libMesh::Elem* elem) const return bin; } -std::pair, std::vector> -LibMesh::plot(Position plot_ll, Position plot_ur) const +std::pair, vector> LibMesh::plot( + Position plot_ll, Position plot_ur) const { return {}; } @@ -2389,16 +2373,16 @@ void read_meshes(pugi::xml_node root) // Read mesh and add to vector if (mesh_type == "regular") { - model::meshes.push_back(std::make_unique(node)); + model::meshes.push_back(make_unique(node)); } else if (mesh_type == "rectilinear") { - model::meshes.push_back(std::make_unique(node)); + model::meshes.push_back(make_unique(node)); #ifdef DAGMC } else if (mesh_type == "unstructured" && mesh_lib == "moab") { - model::meshes.push_back(std::make_unique(node)); + model::meshes.push_back(make_unique(node)); #endif #ifdef LIBMESH } else if (mesh_type == "unstructured" && mesh_lib == "libmesh") { - model::meshes.push_back(std::make_unique(node)); + model::meshes.push_back(make_unique(node)); #endif } else if (mesh_type == "unstructured") { fatal_error("Unstructured mesh support is not enabled or the mesh library is invalid."); @@ -2420,7 +2404,7 @@ void meshes_to_hdf5(hid_t group) if (n_meshes > 0) { // Write IDs of meshes - std::vector ids; + vector ids; for (const auto& m : model::meshes) { m->to_hdf5(meshes_group); ids.push_back(m->id_); diff --git a/src/message_passing.cpp b/src/message_passing.cpp index aea17f9f4..f479d3db7 100644 --- a/src/message_passing.cpp +++ b/src/message_passing.cpp @@ -9,7 +9,7 @@ bool master {true}; #ifdef OPENMC_MPI MPI_Comm intracomm {MPI_COMM_NULL}; -MPI_Datatype bank {MPI_DATATYPE_NULL}; +MPI_Datatype source_site {MPI_DATATYPE_NULL}; #endif extern "C" bool openmc_master() { return mpi::master; } diff --git a/src/mgxs.cpp b/src/mgxs.cpp index dec505f3c..00263b541 100644 --- a/src/mgxs.cpp +++ b/src/mgxs.cpp @@ -29,11 +29,10 @@ namespace openmc { // Mgxs base-class methods //============================================================================== -void -Mgxs::init(const std::string& in_name, double in_awr, - const std::vector& in_kTs, bool in_fissionable, - AngleDistributionType in_scatter_format, bool in_is_isotropic, - const std::vector& in_polar, const std::vector& in_azimuthal) +void Mgxs::init(const std::string& in_name, double in_awr, + const vector& in_kTs, bool in_fissionable, + AngleDistributionType in_scatter_format, bool in_is_isotropic, + const vector& in_polar, const vector& in_azimuthal) { // Set the metadata name = in_name; @@ -56,14 +55,13 @@ Mgxs::init(const std::string& in_name, double in_awr, int n_threads = 1; #endif cache.resize(n_threads); - // std::vector.resize() will value-initialize the members of cache[:] + // vector.resize() will value-initialize the members of cache[:] } //============================================================================== -void -Mgxs::metadata_from_hdf5(hid_t xs_id, const std::vector& temperature, - std::vector& temps_to_read, int& order_dim) +void Mgxs::metadata_from_hdf5(hid_t xs_id, const vector& temperature, + vector& temps_to_read, int& order_dim) { // get name char char_name[MAX_WORD_LEN]; @@ -88,7 +86,7 @@ Mgxs::metadata_from_hdf5(hid_t xs_id, const std::vector& temperature, dset_names[i] = new char[151]; } get_datasets(kT_group, dset_names); - std::vector shape = {num_temps}; + vector shape = {num_temps}; xt::xarray available_temps(shape); for (int i = 0; i < num_temps; i++) { read_double(kT_group, dset_names[i], &available_temps[i], true); @@ -160,7 +158,7 @@ Mgxs::metadata_from_hdf5(hid_t xs_id, const std::vector& temperature, // Get the library's temperatures int n_temperature = temps_to_read.size(); - std::vector in_kTs(n_temperature); + vector in_kTs(n_temperature); for (int i = 0; i < n_temperature; i++) { std::string temp_str(std::to_string(temps_to_read[i]) + "K"); @@ -254,12 +252,12 @@ Mgxs::metadata_from_hdf5(hid_t xs_id, const std::vector& temperature, } // Set the angular bins to use equally-spaced bins - std::vector in_polar(in_n_pol); + vector in_polar(in_n_pol); double dangle = PI / in_n_pol; for (int p = 0; p < in_n_pol; p++) { in_polar[p] = (p + 0.5) * dangle; } - std::vector in_azimuthal(in_n_azi); + vector in_azimuthal(in_n_azi); dangle = 2. * PI / in_n_azi; for (int a = 0; a < in_n_azi; a++) { in_azimuthal[a] = (a + 0.5) * dangle - PI; @@ -273,14 +271,13 @@ Mgxs::metadata_from_hdf5(hid_t xs_id, const std::vector& temperature, //============================================================================== -Mgxs::Mgxs(hid_t xs_id, const std::vector& temperature, - int num_group, int num_delay) : - num_groups(num_group), - num_delayed_groups(num_delay) +Mgxs::Mgxs( + hid_t xs_id, const vector& temperature, int num_group, int num_delay) + : num_groups(num_group), num_delayed_groups(num_delay) { // Call generic data gathering routine (will populate the metadata) int order_data; - std::vector temps_to_read; + vector temps_to_read; metadata_from_hdf5(xs_id, temperature, temps_to_read, order_data); // Set number of energy and delayed groups @@ -309,11 +306,10 @@ Mgxs::Mgxs(hid_t xs_id, const std::vector& temperature, //============================================================================== -Mgxs::Mgxs(const std::string& in_name, const std::vector& mat_kTs, - const std::vector& micros, const std::vector& atom_densities, - int num_group, int num_delay) : - num_groups(num_group), - num_delayed_groups(num_delay) +Mgxs::Mgxs(const std::string& in_name, const vector& mat_kTs, + const vector& micros, const vector& atom_densities, + int num_group, int num_delay) + : num_groups(num_group), num_delayed_groups(num_delay) { // Get the minimum data needed to initialize: // Dont need awr, but lets just initialize it anyways @@ -328,8 +324,8 @@ Mgxs::Mgxs(const std::string& in_name, const std::vector& mat_kTs, // to be true later AngleDistributionType in_scatter_format = micros[0]->scatter_format; bool in_is_isotropic = micros[0]->is_isotropic; - std::vector in_polar = micros[0]->polar; - std::vector in_azimuthal = micros[0]->azimuthal; + vector in_polar = micros[0]->polar; + vector in_azimuthal = micros[0]->azimuthal; init(in_name, in_awr, mat_kTs, in_fissionable, in_scatter_format, in_is_isotropic, in_polar, in_azimuthal); @@ -344,8 +340,8 @@ Mgxs::Mgxs(const std::string& in_name, const std::vector& mat_kTs, // Create the list of temperature indices and interpolation factors for // each microscopic data at the material temperature - std::vector micro_t(micros.size(), 0); - std::vector micro_t_interp(micros.size(), 0.); + vector micro_t(micros.size(), 0); + vector micro_t_interp(micros.size(), 0.); for (int m = 0; m < micros.size(); m++) { switch(settings::temperature_method) { case TemperatureMethod::NEAREST: @@ -383,9 +379,9 @@ Mgxs::Mgxs(const std::string& in_name, const std::vector& mat_kTs, // a different nuclide. Mathematically this just means the temperature // interpolant is included in the number density. // These interpolants are contained within interpolant. - std::vector interpolant; // the interpolant for the Mgxs - std::vector temp_indices; // the temperature index for each Mgxs - std::vector mgxs_to_combine; // The Mgxs to combine + vector interpolant; // the interpolant for the Mgxs + vector temp_indices; // the temperature index for each Mgxs + vector mgxs_to_combine; // The Mgxs to combine // Now go through and build the above vectors so that we can use them to // combine the data. We will step through each microscopic data and // add in its lower and upper temperature points @@ -419,12 +415,11 @@ Mgxs::Mgxs(const std::string& in_name, const std::vector& mat_kTs, //============================================================================== -void -Mgxs::combine(const std::vector& micros, const std::vector& scalars, - const std::vector& micro_ts, int this_t) +void Mgxs::combine(const vector& micros, const vector& scalars, + const vector& micro_ts, int this_t) { // Build the vector of pointers to the xs objects within micros - std::vector those_xs(micros.size()); + vector those_xs(micros.size()); for (int i = 0; i < micros.size(); i++) { those_xs[i] = &(micros[i]->xs[micro_ts[i]]); } @@ -627,13 +622,13 @@ Mgxs::calculate_xs(Particle& p) #else int tid = 0; #endif - set_temperature_index(p.sqrtkT_); + set_temperature_index(p.sqrtkT()); set_angle_index(p.u_local()); XsData* xs_t = &xs[cache[tid].t]; - p.macro_xs_.total = xs_t->total(cache[tid].a, p.g_); - p.macro_xs_.absorption = xs_t->absorption(cache[tid].a, p.g_); - p.macro_xs_.nu_fission = - fissionable ? xs_t->nu_fission(cache[tid].a, p.g_) : 0.; + p.macro_xs().total = xs_t->total(cache[tid].a, p.g()); + p.macro_xs().absorption = xs_t->absorption(cache[tid].a, p.g()); + p.macro_xs().nu_fission = + fissionable ? xs_t->nu_fission(cache[tid].a, p.g()) : 0.; } //============================================================================== diff --git a/src/mgxs_interface.cpp b/src/mgxs_interface.cpp index 31294e3c9..227896d80 100644 --- a/src/mgxs_interface.cpp +++ b/src/mgxs_interface.cpp @@ -29,8 +29,7 @@ namespace data { } MgxsInterface::MgxsInterface(const std::string& path_cross_sections, - const std::vector xs_to_read, - const std::vector> xs_temps) + const vector xs_to_read, const vector> xs_temps) { read_header(path_cross_sections); set_nuclides_and_temperatures(xs_to_read, xs_temps); @@ -38,8 +37,7 @@ MgxsInterface::MgxsInterface(const std::string& path_cross_sections, } void MgxsInterface::set_nuclides_and_temperatures( - std::vector xs_to_read, - std::vector> xs_temps) + vector xs_to_read, vector> xs_temps) { // Check to remove all duplicates xs_to_read_ = xs_to_read; @@ -76,7 +74,7 @@ void MgxsInterface::init() // Read revision number for the MGXS Library file and make sure it matches // with the current version - std::array array; + array array; read_attribute(file_id, "version", array); if (array != VERSION_MGXS_LIBRARY) { fatal_error("MGXS Library file version does not match current version " @@ -95,9 +93,8 @@ void MgxsInterface::init() //============================================================================== -void -MgxsInterface::add_mgxs(hid_t file_id, const std::string& name, - const std::vector& temperature) +void MgxsInterface::add_mgxs( + hid_t file_id, const std::string& name, const vector& temperature) { write_message(5, "Loading {} data...", name); @@ -129,12 +126,12 @@ void MgxsInterface::create_macro_xs() if (kTs[i].size() > 0) { // Convert atom_densities to a vector auto& mat {model::materials[i]}; - std::vector atom_densities(mat->atom_density_.begin(), - mat->atom_density_.end()); + vector atom_densities( + mat->atom_density_.begin(), mat->atom_density_.end()); // Build array of pointers to nuclides's Mgxs objects needed for this // material - std::vector mgxs_ptr; + vector mgxs_ptr; for (int i_nuclide : mat->nuclide_) { mgxs_ptr.push_back(&nuclides_[i_nuclide]); } @@ -150,9 +147,9 @@ void MgxsInterface::create_macro_xs() //============================================================================== -std::vector> MgxsInterface::get_mat_kTs() +vector> MgxsInterface::get_mat_kTs() { - std::vector> kTs(model::materials.size()); + vector> kTs(model::materials.size()); for (const auto& cell : model::cells) { // Skip non-material cells @@ -230,7 +227,7 @@ void MgxsInterface::read_header(const std::string& path_cross_sections) void put_mgxs_header_data_to_globals() { // Get the minimum and maximum energies - int neutron = static_cast(Particle::Type::neutron); + int neutron = static_cast(ParticleType::neutron); data::energy_min[neutron] = data::mg.energy_bins_.back(); data::energy_max[neutron] = data::mg.energy_bins_.front(); @@ -248,12 +245,12 @@ void put_mgxs_header_data_to_globals() void set_mg_interface_nuclides_and_temps() { // Get temperatures from global data - std::vector> nuc_temps(data::nuclide_map.size()); - std::vector> dummy; + vector> nuc_temps(data::nuclide_map.size()); + vector> dummy; get_temperatures(nuc_temps, dummy); // Build vector of nuclide names which are to be read - std::vector nuclide_names(data::nuclide_map.size()); + vector nuclide_names(data::nuclide_map.size()); for (const auto& kv : data::nuclide_map) { nuclide_names[kv.second] = kv.first; } diff --git a/src/nuclide.cpp b/src/nuclide.cpp index b29c0463a..a7eff14f9 100644 --- a/src/nuclide.cpp +++ b/src/nuclide.cpp @@ -30,12 +30,12 @@ namespace openmc { //============================================================================== namespace data { -std::array energy_min {0.0, 0.0}; -std::array energy_max {INFTY, INFTY}; +array energy_min {0.0, 0.0}; +array energy_max {INFTY, INFTY}; double temperature_min {INFTY}; double temperature_max {0.0}; std::unordered_map nuclide_map; -std::vector> nuclides; +vector> nuclides; } // namespace data //============================================================================== @@ -48,7 +48,7 @@ int Nuclide::XS_FISSION {2}; int Nuclide::XS_NU_FISSION {3}; int Nuclide::XS_PHOTON_PROD {4}; -Nuclide::Nuclide(hid_t group, const std::vector& temperature) +Nuclide::Nuclide(hid_t group, const vector& temperature) { // Set index of nuclide in global vector index_ = data::nuclides.size(); @@ -65,7 +65,7 @@ Nuclide::Nuclide(hid_t group, const std::vector& temperature) // Determine temperatures available hid_t kT_group = open_group(group, "kTs"); auto dset_names = dataset_names(kT_group); - std::vector temps_available; + vector temps_available; for (const auto& name : dset_names) { double T; read_dataset(kT_group, name.c_str(), T); @@ -86,7 +86,7 @@ Nuclide::Nuclide(hid_t group, const std::vector& temperature) // temperature range was given (indicated by T_max > 0), in which case all // temperatures in the range are loaded irrespective of what temperatures // actually appear in the model - std::vector temps_to_read; + vector temps_to_read; int n = temperature.size(); double T_min = n > 0 ? settings::temperature_range[0] : 0.0; double T_max = n > 0 ? settings::temperature_range[1] : INFTY; @@ -200,7 +200,7 @@ Nuclide::Nuclide(hid_t group, const std::vector& temperature) for (auto name : group_names(rxs_group)) { if (starts_with(name, "reaction_")) { hid_t rx_group = open_group(rxs_group, name.c_str()); - reactions_.push_back(std::make_unique(rx_group, temps_to_read)); + reactions_.push_back(make_unique(rx_group, temps_to_read)); // Check for 0K elastic scattering const auto& rx = reactions_.back(); @@ -310,7 +310,7 @@ void Nuclide::create_derived(const Function1D* prompt_photons, const Function1D* { for (const auto& grid : grid_) { // Allocate and initialize cross section - std::array shape {grid.energy.size(), 5}; + array shape {grid.energy.size(), 5}; xs_.emplace_back(shape, 0.0); } @@ -327,7 +327,7 @@ void Nuclide::create_derived(const Function1D* prompt_photons, const Function1D* auto xs = xt::adapt(rx->xs_[t].value); for (const auto& p : rx->products_) { - if (p.particle_ == Particle::Type::photon) { + if (p.particle_ == ParticleType::photon) { auto pprod = xt::view(xs_[t], xt::range(j, j+n), XS_PHOTON_PROD); for (int k = 0; k < n; ++k) { double E = grid_[t].energy[k+j]; @@ -445,7 +445,7 @@ void Nuclide::create_derived(const Function1D* prompt_photons, const Function1D* void Nuclide::init_grid() { - int neutron = static_cast(Particle::Type::neutron); + int neutron = static_cast(ParticleType::neutron); double E_min = data::energy_min[neutron]; double E_max = data::energy_max[neutron]; int M = settings::n_log_bins; @@ -494,7 +494,8 @@ double Nuclide::nu(double E, EmissionMode mode, int group) const for (int i = 1; i < rx->products_.size(); ++i) { // Skip any non-neutron products const auto& product = rx->products_[i]; - if (product.particle_ != Particle::Type::neutron) continue; + if (product.particle_ != ParticleType::neutron) + continue; // Evaluate yield if (product.emission_mode_ == EmissionMode::delayed) { @@ -519,7 +520,7 @@ double Nuclide::nu(double E, EmissionMode mode, int group) const void Nuclide::calculate_elastic_xs(Particle& p) const { // Get temperature index, grid index, and interpolation factor - auto& micro {p.neutron_xs_[index_]}; + auto& micro {p.neutron_xs(index_)}; int i_temp = micro.index_temp; int i_grid = micro.index_grid; double f = micro.interp_factor; @@ -555,7 +556,7 @@ double Nuclide::elastic_xs_0K(double E) const void Nuclide::calculate_xs(int i_sab, int i_log_union, double sab_frac, Particle& p) { - auto& micro {p.neutron_xs_[index_]}; + auto& micro {p.neutron_xs(index_)}; // Initialize cached cross sections to zero micro.elastic = CACHE_INVALID; @@ -565,21 +566,21 @@ void Nuclide::calculate_xs(int i_sab, int i_log_union, double sab_frac, Particle // Check to see if there is multipole data present at this energy bool use_mp = false; if (multipole_) { - use_mp = (p.E_ >= multipole_->E_min_ && p.E_ <= multipole_->E_max_); + use_mp = (p.E() >= multipole_->E_min_ && p.E() <= multipole_->E_max_); } // Evaluate multipole or interpolate if (use_mp) { // Call multipole kernel double sig_s, sig_a, sig_f; - std::tie(sig_s, sig_a, sig_f) = multipole_->evaluate(p.E_, p.sqrtkT_); + std::tie(sig_s, sig_a, sig_f) = multipole_->evaluate(p.E(), p.sqrtkT()); micro.total = sig_s + sig_a; micro.elastic = sig_s; micro.absorption = sig_a; micro.fission = sig_f; - micro.nu_fission = fissionable_ ? - sig_f * this->nu(p.E_, EmissionMode::total) : 0.0; + micro.nu_fission = + fissionable_ ? sig_f * this->nu(p.E(), EmissionMode::total) : 0.0; if (simulation::need_depletion_rx) { // Only non-zero reaction is (n,gamma) @@ -607,7 +608,7 @@ void Nuclide::calculate_xs(int i_sab, int i_log_union, double sab_frac, Particle } else { // Find the appropriate temperature index. - double kT = p.sqrtkT_*p.sqrtkT_; + double kT = p.sqrtkT() * p.sqrtkT(); double f; int i_temp = -1; switch (settings::temperature_method) { @@ -644,9 +645,9 @@ void Nuclide::calculate_xs(int i_sab, int i_log_union, double sab_frac, Particle const auto& xs {xs_[i_temp]}; int i_grid; - if (p.E_ < grid.energy.front()) { + if (p.E() < grid.energy.front()) { i_grid = 0; - } else if (p.E_ > grid.energy.back()) { + } else if (p.E() > grid.energy.back()) { i_grid = grid.energy.size() - 2; } else { // Determine bounding indices based on which equal log-spaced @@ -655,15 +656,16 @@ void Nuclide::calculate_xs(int i_sab, int i_log_union, double sab_frac, Particle int i_high = grid.grid_index[i_log_union + 1] + 1; // Perform binary search over reduced range - i_grid = i_low + lower_bound_index(&grid.energy[i_low], &grid.energy[i_high], p.E_); + i_grid = i_low + lower_bound_index( + &grid.energy[i_low], &grid.energy[i_high], p.E()); } // check for rare case where two energy points are the same if (grid.energy[i_grid] == grid.energy[i_grid + 1]) ++i_grid; // calculate interpolation factor - f = (p.E_ - grid.energy[i_grid]) / - (grid.energy[i_grid + 1]- grid.energy[i_grid]); + f = (p.E() - grid.energy[i_grid]) / + (grid.energy[i_grid + 1] - grid.energy[i_grid]); micro.index_temp = i_temp; micro.index_grid = i_grid; @@ -750,19 +752,19 @@ void Nuclide::calculate_xs(int i_sab, int i_log_union, double sab_frac, Particle // probability tables, we need to determine cross sections from the table if (settings::urr_ptables_on && urr_present_ && !use_mp) { int n = urr_data_[micro.index_temp].n_energy_; - if ((p.E_ > urr_data_[micro.index_temp].energy_(0)) && - (p.E_ < urr_data_[micro.index_temp].energy_(n-1))) { + if ((p.E() > urr_data_[micro.index_temp].energy_(0)) && + (p.E() < urr_data_[micro.index_temp].energy_(n - 1))) { this->calculate_urr_xs(micro.index_temp, p); } } - micro.last_E = p.E_; - micro.last_sqrtkT = p.sqrtkT_; + micro.last_E = p.E(); + micro.last_sqrtkT = p.sqrtkT(); } void Nuclide::calculate_sab_xs(int i_sab, double sab_frac, Particle& p) { - auto& micro {p.neutron_xs_[index_]}; + auto& micro {p.neutron_xs(index_)}; // Set flag that S(a,b) treatment should be used for scattering micro.index_sab = i_sab; @@ -771,7 +773,8 @@ void Nuclide::calculate_sab_xs(int i_sab, double sab_frac, Particle& p) int i_temp; double elastic; double inelastic; - data::thermal_scatt[i_sab]->calculate_xs(p.E_, p.sqrtkT_, &i_temp, &elastic, &inelastic, p.current_seed()); + data::thermal_scatt[i_sab]->calculate_xs( + p.E(), p.sqrtkT(), &i_temp, &elastic, &inelastic, p.current_seed()); // Store the S(a,b) cross sections. micro.thermal = sab_frac * (elastic + inelastic); @@ -791,7 +794,7 @@ void Nuclide::calculate_sab_xs(int i_sab, double sab_frac, Particle& p) void Nuclide::calculate_urr_xs(int i_temp, Particle& p) const { - auto& micro = p.neutron_xs_[index_]; + auto& micro = p.neutron_xs(index_); micro.use_ptable = true; // Create a shorthand for the URR data @@ -799,17 +802,19 @@ void Nuclide::calculate_urr_xs(int i_temp, Particle& p) const // Determine the energy table int i_energy = 0; - while (p.E_ >= urr.energy_(i_energy + 1)) {++i_energy;}; + while (p.E() >= urr.energy_(i_energy + 1)) { + ++i_energy; + }; // Sample the probability table using the cumulative distribution - // Random nmbers for the xs calculation are sampled from a separate stream. + // Random numbers for the xs calculation are sampled from a separate stream. // This guarantees the randomness and, at the same time, makes sure we // reuse random numbers for the same nuclide at different temperatures, // therefore preserving correlation of temperature in probability tables. - p.stream_ = STREAM_URR_PTABLE; + p.stream() = STREAM_URR_PTABLE; double r = future_prn(static_cast(index_), *p.current_seed()); - p.stream_ = STREAM_TRACKING; + p.stream() = STREAM_TRACKING; int i_low = 0; while (urr.prob_(i_energy, URRTableParam::CUM_PROB, i_low) <= r) {++i_low;}; @@ -825,8 +830,8 @@ void Nuclide::calculate_urr_xs(int i_temp, Particle& p) const double f; if (urr.interp_ == Interpolation::lin_lin) { // Determine the interpolation factor on the table - f = (p.E_ - urr.energy_(i_energy)) / - (urr.energy_(i_energy + 1) - urr.energy_(i_energy)); + f = (p.E() - urr.energy_(i_energy)) / + (urr.energy_(i_energy + 1) - urr.energy_(i_energy)); elastic = (1. - f) * urr.prob_(i_energy, URRTableParam::ELASTIC, i_low) + f * urr.prob_(i_energy + 1, URRTableParam::ELASTIC, i_up); @@ -836,8 +841,8 @@ void Nuclide::calculate_urr_xs(int i_temp, Particle& p) const f * urr.prob_(i_energy + 1, URRTableParam::N_GAMMA, i_up); } else if (urr.interp_ == Interpolation::log_log) { // Determine interpolation factor on the table - f = std::log(p.E_ / urr.energy_(i_energy)) / - std::log(urr.energy_(i_energy + 1) / urr.energy_(i_energy)); + f = std::log(p.E() / urr.energy_(i_energy)) / + std::log(urr.energy_(i_energy + 1) / urr.energy_(i_energy)); // Calculate the elastic cross section/factor if ((urr.prob_(i_energy, URRTableParam::ELASTIC, i_low) > 0.) && @@ -914,7 +919,7 @@ void Nuclide::calculate_urr_xs(int i_temp, Particle& p) const // Determine nu-fission cross-section if (fissionable_) { - micro.nu_fission = nu(p.E_, EmissionMode::total) * micro.fission; + micro.nu_fission = nu(p.E(), EmissionMode::total) * micro.fission; } } @@ -992,7 +997,7 @@ double Nuclide::collapse_rate(int MT, double temperature, gsl::span version; + vector version; read_attribute(file_id, "version", version); if (version[0] != HDF5_VERSION[0]) { fatal_error("HDF5 data format uses version " + std::to_string(version[0]) @@ -1039,8 +1044,8 @@ extern "C" int openmc_load_nuclide(const char* name, const double* temps, int n) // Read nuclide data from HDF5 hid_t group = open_group(file_id, name); - std::vector temperature{temps, temps + n}; - data::nuclides.push_back(std::make_unique(group, temperature)); + vector temperature {temps, temps + n}; + data::nuclides.push_back(make_unique(group, temperature)); close_group(group); file_close(file_id); @@ -1072,7 +1077,7 @@ extern "C" int openmc_load_nuclide(const char* name, const double* temps, int n) // Read element data from HDF5 hid_t group = open_group(file_id, element.c_str()); - data::elements.push_back(std::make_unique(group)); + data::elements.push_back(make_unique(group)); close_group(group); file_close(file_id); diff --git a/src/output.cpp b/src/output.cpp index 89a9070a2..beac21ddd 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -146,62 +146,62 @@ std::string time_stamp() void print_particle(Particle& p) { // Display particle type and ID. - switch (p.type_) { - case Particle::Type::neutron: - fmt::print("Neutron "); - break; - case Particle::Type::photon: - fmt::print("Photon "); - break; - case Particle::Type::electron: - fmt::print("Electron "); - break; - case Particle::Type::positron: - fmt::print("Positron "); - break; - default: - fmt::print("Unknown Particle "); + switch (p.type()) { + case ParticleType::neutron: + fmt::print("Neutron "); + break; + case ParticleType::photon: + fmt::print("Photon "); + break; + case ParticleType::electron: + fmt::print("Electron "); + break; + case ParticleType::positron: + fmt::print("Positron "); + break; + default: + fmt::print("Unknown Particle "); } - fmt::print("{}\n", p.id_); + fmt::print("{}\n", p.id()); // Display particle geometry hierarchy. - for (auto i = 0; i < p.n_coord_; i++) { + for (auto i = 0; i < p.n_coord(); i++) { fmt::print(" Level {}\n", i); - if (p.coord_[i].cell != C_NONE) { - const Cell& c {*model::cells[p.coord_[i].cell]}; + if (p.coord(i).cell != C_NONE) { + const Cell& c {*model::cells[p.coord(i).cell]}; fmt::print(" Cell = {}\n", c.id_); } - if (p.coord_[i].universe != C_NONE) { - const Universe& u {*model::universes[p.coord_[i].universe]}; + if (p.coord(i).universe != C_NONE) { + const Universe& u {*model::universes[p.coord(i).universe]}; fmt::print(" Universe = {}\n", u.id_); } - if (p.coord_[i].lattice != C_NONE) { - const Lattice& lat {*model::lattices[p.coord_[i].lattice]}; + if (p.coord(i).lattice != C_NONE) { + const Lattice& lat {*model::lattices[p.coord(i).lattice]}; fmt::print(" Lattice = {}\n", lat.id_); - fmt::print(" Lattice position = ({},{},{})\n", p.coord_[i].lattice_x, - p.coord_[i].lattice_y, p.coord_[i].lattice_z); + fmt::print(" Lattice position = ({},{},{})\n", p.coord(i).lattice_i[0], + p.coord(i).lattice_i[1], p.coord(i).lattice_i[2]); } - fmt::print(" r = {}\n", p.coord_[i].r); - fmt::print(" u = {}\n", p.coord_[i].u); + fmt::print(" r = {}\n", p.coord(i).r); + fmt::print(" u = {}\n", p.coord(i).u); } // Display miscellaneous info. - if (p.surface_ != 0) { + if (p.surface() != 0) { // Surfaces identifiers are >= 1, but indices are >= 0 so we need -1 - const Surface& surf {*model::surfaces[std::abs(p.surface_)-1]}; - fmt::print(" Surface = {}\n", (p.surface_ > 0) ? surf.id_ : -surf.id_); + const Surface& surf {*model::surfaces[std::abs(p.surface()) - 1]}; + fmt::print(" Surface = {}\n", (p.surface() > 0) ? surf.id_ : -surf.id_); } - fmt::print(" Weight = {}\n", p.wgt_); + fmt::print(" Weight = {}\n", p.wgt()); if (settings::run_CE) { - fmt::print(" Energy = {}\n", p.E_); + fmt::print(" Energy = {}\n", p.E()); } else { - fmt::print(" Energy Group = {}\n", p.g_); + fmt::print(" Energy Group = {}\n", p.g()); } - fmt::print(" Delayed Group = {}\n\n", p.delayed_group_); + fmt::print(" Delayed Group = {}\n\n", p.delayed_group()); } //============================================================================== @@ -269,17 +269,16 @@ void print_overlap_check() { #ifdef OPENMC_MPI - std::vector temp(model::overlap_check_count); - MPI_Reduce(temp.data(), model::overlap_check_count.data(), - model::overlap_check_count.size(), MPI_INT64_T, - MPI_SUM, 0, mpi::intracomm); - #endif + vector temp(model::overlap_check_count); + MPI_Reduce(temp.data(), model::overlap_check_count.data(), + model::overlap_check_count.size(), MPI_INT64_T, MPI_SUM, 0, mpi::intracomm); +#endif if (mpi::master) { header("cell overlap check summary", 1); fmt::print(" Cell ID No. Overlap Checks\n"); - std::vector sparse_cell_ids; + vector sparse_cell_ids; for (int i = 0; i < model::cells.size(); i++) { fmt::print(" {:8} {:17}\n", model::cells[i]->id_, model::overlap_check_count[i]); if (model::overlap_check_count[i] < 10) { @@ -606,7 +605,7 @@ write_tallies() } // Initialize Filter Matches Object - std::vector filter_matches; + vector filter_matches; // Allocate space for tally filter matches filter_matches.resize(model::tally_filters.size()); diff --git a/src/particle.cpp b/src/particle.cpp index 037566290..fe2579593 100644 --- a/src/particle.cpp +++ b/src/particle.cpp @@ -29,167 +29,120 @@ #include "openmc/tallies/tally_scoring.h" #include "openmc/track_output.h" +#ifdef DAGMC +#include "DagMC.hpp" +#endif + namespace openmc { -//============================================================================== -// LocalCoord implementation -//============================================================================== - -void -LocalCoord::rotate(const std::vector& rotation) +void Particle::create_secondary( + double wgt, Direction u, double E, ParticleType type) { - this->r = this->r.rotate(rotation); - this->u = this->u.rotate(rotation); - this->rotated = true; -} + secondary_bank().emplace_back(); -void -LocalCoord::reset() -{ - cell = C_NONE; - universe = C_NONE; - lattice = C_NONE; - lattice_x = 0; - lattice_y = 0; - lattice_z = 0; - rotated = false; -} - -//============================================================================== -// Particle implementation -//============================================================================== - -Particle::Particle() -{ - // Create and clear coordinate levels - coord_.resize(model::n_coord_levels); - cell_last_.resize(model::n_coord_levels); - clear(); - - for (int& n : n_delayed_bank_) { - n = 0; - } - - // Create microscopic cross section caches - neutron_xs_.resize(data::nuclides.size()); - photon_xs_.resize(data::elements.size()); -} - -void -Particle::clear() -{ - // Reset any coordinate levels - for (auto& level : coord_) level.reset(); - n_coord_ = 1; -} - -void -Particle::create_secondary(double wgt, Direction u, double E, Type type) -{ - secondary_bank_.emplace_back(); - - auto& bank {secondary_bank_.back()}; + auto& bank {secondary_bank().back()}; bank.particle = type; bank.wgt = wgt; - bank.r = this->r(); + bank.r = r(); bank.u = u; - bank.E = settings::run_CE ? E : g_; + bank.E = settings::run_CE ? E : g(); - n_bank_second_ += 1; + n_bank_second() += 1; } -void -Particle::from_source(const Bank* src) +void Particle::from_source(const SourceSite* src) { // Reset some attributes - this->clear(); - alive_ = true; - surface_ = 0; - cell_born_ = C_NONE; - material_ = C_NONE; - n_collision_ = 0; - fission_ = false; - std::fill(flux_derivs_.begin(), flux_derivs_.end(), 0.0); + clear(); + alive() = true; + surface() = 0; + cell_born() = C_NONE; + material() = C_NONE; + n_collision() = 0; + fission() = false; + zero_flux_derivs(); // Copy attributes from source bank site - type_ = src->particle; - wgt_ = src->wgt; - wgt_last_ = src->wgt; - this->r() = src->r; - this->u() = src->u; - r_last_current_ = src->r; - r_last_ = src->r; - u_last_ = src->u; + type() = src->particle; + wgt() = src->wgt; + wgt_last() = src->wgt; + r() = src->r; + u() = src->u; + r_last_current() = src->r; + r_last() = src->r; + u_last() = src->u; if (settings::run_CE) { - E_ = src->E; - g_ = 0; + E() = src->E; + g() = 0; } else { - g_ = static_cast(src->E); - g_last_ = static_cast(src->E); - E_ = data::mg.energy_bin_avg_[g_]; + g() = static_cast(src->E); + g_last() = static_cast(src->E); + E() = data::mg.energy_bin_avg_[g()]; } - E_last_ = E_; + E_last() = E(); } void Particle::event_calculate_xs() { // Set the random number stream - stream_ = STREAM_TRACKING; + stream() = STREAM_TRACKING; // Store pre-collision particle properties - wgt_last_ = wgt_; - E_last_ = E_; - u_last_ = this->u(); - r_last_ = this->r(); + wgt_last() = wgt(); + E_last() = E(); + u_last() = u(); + r_last() = r(); // Reset event variables - event_ = TallyEvent::KILL; - event_nuclide_ = NUCLIDE_NONE; - event_mt_ = REACTION_NONE; + event() = TallyEvent::KILL; + event_nuclide() = NUCLIDE_NONE; + event_mt() = REACTION_NONE; // If the cell hasn't been determined based on the particle's location, // initiate a search for the current cell. This generally happens at the // beginning of the history and again for any secondary particles - if (coord_[n_coord_ - 1].cell == C_NONE) { + if (coord(n_coord() - 1).cell == C_NONE) { if (!exhaustive_find_cell(*this)) { - this->mark_as_lost("Could not find the cell containing particle " - + std::to_string(id_)); + mark_as_lost( + "Could not find the cell containing particle " + std::to_string(id())); return; } // Set birth cell attribute - if (cell_born_ == C_NONE) cell_born_ = coord_[n_coord_ - 1].cell; + if (cell_born() == C_NONE) + cell_born() = coord(n_coord() - 1).cell; } // Write particle track. - if (write_track_) write_particle_track(*this); + if (write_track()) + write_particle_track(*this); if (settings::check_overlaps) check_cell_overlap(*this); // Calculate microscopic and macroscopic cross sections - if (material_ != MATERIAL_VOID) { + if (material() != MATERIAL_VOID) { if (settings::run_CE) { - if (material_ != material_last_ || sqrtkT_ != sqrtkT_last_) { + if (material() != material_last() || sqrtkT() != sqrtkT_last()) { // If the material is the same as the last material and the // temperature hasn't changed, we don't need to lookup cross // sections again. - model::materials[material_]->calculate_xs(*this); + model::materials[material()]->calculate_xs(*this); } } else { // Get the MG data; unlike the CE case above, we have to re-calculate // cross sections for every collision since the cross sections may // be angle-dependent - data::mg.macro_xs_[material_].calculate_xs(*this); + data::mg.macro_xs_[material()].calculate_xs(*this); // Update the particle's group while we know we are multi-group - g_last_ = g_; + g_last() = g(); } } else { - macro_xs_.total = 0.0; - macro_xs_.absorption = 0.0; - macro_xs_.fission = 0.0; - macro_xs_.nu_fission = 0.0; + macro_xs().total = 0.0; + macro_xs().absorption = 0.0; + macro_xs().fission = 0.0; + macro_xs().nu_fission = 0.0; } } @@ -197,24 +150,23 @@ void Particle::event_advance() { // Find the distance to the nearest boundary - boundary_ = distance_to_boundary(*this); + boundary() = distance_to_boundary(*this); // Sample a distance to collision - if (type_ == Particle::Type::electron || - type_ == Particle::Type::positron) { - collision_distance_ = 0.0; - } else if (macro_xs_.total == 0.0) { - collision_distance_ = INFINITY; + if (type() == ParticleType::electron || type() == ParticleType::positron) { + collision_distance() = 0.0; + } else if (macro_xs().total == 0.0) { + collision_distance() = INFINITY; } else { - collision_distance_ = -std::log(prn(this->current_seed())) / macro_xs_.total; + collision_distance() = -std::log(prn(current_seed())) / macro_xs().total; } // Select smaller of the two distances - double distance = std::min(boundary_.distance, collision_distance_); + double distance = std::min(boundary().distance, collision_distance()); // Advance particle - for (int j = 0; j < n_coord_; ++j) { - coord_[j].r += distance * coord_[j].u; + for (int j = 0; j < n_coord(); ++j) { + coord(j).r += distance * coord(j).u; } // Score track-length tallies @@ -224,8 +176,8 @@ Particle::event_advance() // Score track-length estimate of k-eff if (settings::run_mode == RunMode::EIGENVALUE && - type_ == Particle::Type::neutron) { - keff_tally_tracklength_ += wgt_ * distance * macro_xs_.nu_fission; + type() == ParticleType::neutron) { + keff_tally_tracklength() += wgt() * distance * macro_xs().nu_fission; } // Score flux derivative accumulators for differential tallies. @@ -238,25 +190,25 @@ void Particle::event_cross_surface() { // Set surface that particle is on and adjust coordinate levels - surface_ = boundary_.surface_index; - n_coord_ = boundary_.coord_level; + surface() = boundary().surface_index; + n_coord() = boundary().coord_level; // Saving previous cell data - for (int j = 0; j < n_coord_; ++j) { - cell_last_[j] = coord_[j].cell; + for (int j = 0; j < n_coord(); ++j) { + cell_last(j) = coord(j).cell; } - n_coord_last_ = n_coord_; + n_coord_last() = n_coord(); - if (boundary_.lattice_translation[0] != 0 || - boundary_.lattice_translation[1] != 0 || - boundary_.lattice_translation[2] != 0) { + if (boundary().lattice_translation[0] != 0 || + boundary().lattice_translation[1] != 0 || + boundary().lattice_translation[2] != 0) { // Particle crosses lattice boundary - cross_lattice(*this, boundary_); - event_ = TallyEvent::LATTICE; + cross_lattice(*this, boundary()); + event() = TallyEvent::LATTICE; } else { // Particle crosses surface - this->cross_surface(); - event_ = TallyEvent::SURFACE; + cross_surface(); + event() = TallyEvent::SURFACE; } // Score cell to cell partial currents if (!model::active_surface_tallies.empty()) { @@ -269,9 +221,8 @@ Particle::event_collide() { // Score collision estimate of keff if (settings::run_mode == RunMode::EIGENVALUE && - type_ == Particle::Type::neutron) { - keff_tally_collision_ += wgt_ * macro_xs_.nu_fission - / macro_xs_.total; + type() == ParticleType::neutron) { + keff_tally_collision() += wgt() * macro_xs().nu_fission / macro_xs().total; } // Score surface current tallies -- this has to be done before the collision @@ -282,7 +233,7 @@ Particle::event_collide() score_surface_tally(*this, model::active_meshsurf_tallies); // Clear surface component - surface_ = 0; + surface() = 0; if (settings::run_CE) { collision(*this); @@ -303,32 +254,32 @@ Particle::event_collide() } // Reset banked weight during collision - n_bank_ = 0; - n_bank_second_ = 0; - wgt_bank_ = 0.0; - for (int& v : n_delayed_bank_) v = 0; + n_bank() = 0; + n_bank_second() = 0; + wgt_bank() = 0.0; + zero_delayed_bank(); // Reset fission logical - fission_ = false; + fission() = false; // Save coordinates for tallying purposes - r_last_current_ = this->r(); + r_last_current() = r(); // Set last material to none since cross sections will need to be // re-evaluated - material_last_ = C_NONE; + material_last() = C_NONE; // Set all directions to base level -- right now, after a collision, only // the base level directions are changed - for (int j = 0; j < n_coord_ - 1; ++j) { - if (coord_[j + 1].rotated) { + for (int j = 0; j < n_coord() - 1; ++j) { + if (coord(j + 1).rotated) { // If next level is rotated, apply rotation matrix - const auto& m {model::cells[coord_[j].cell]->rotation_}; - const auto& u {coord_[j].u}; - coord_[j + 1].u = u.rotate(m); + const auto& m {model::cells[coord(j).cell]->rotation_}; + const auto& u {coord(j).u}; + coord(j + 1).u = u.rotate(m); } else { // Otherwise, copy this level's direction - coord_[j+1].u = coord_[j].u; + coord(j + 1).u = coord(j).u; } } @@ -340,24 +291,26 @@ void Particle::event_revive_from_secondary() { // If particle has too many events, display warning and kill it - ++n_event_; - if (n_event_ == MAX_EVENTS) { - warning("Particle " + std::to_string(id_) + - " underwent maximum number of events."); - alive_ = false; + ++n_event(); + if (n_event() == MAX_EVENTS) { + warning("Particle " + std::to_string(id()) + + " underwent maximum number of events."); + alive() = false; } // Check for secondary particles if this particle is dead - if (!alive_) { + if (!alive()) { // If no secondary particles, break out of event loop - if (secondary_bank_.empty()) return; + if (secondary_bank().empty()) + return; - this->from_source(&secondary_bank_.back()); - secondary_bank_.pop_back(); - n_event_ = 0; + from_source(&secondary_bank().back()); + secondary_bank().pop_back(); + n_event() = 0; // Enter new particle in particle track file - if (write_track_) add_particle_track(*this); + if (write_track()) + add_particle_track(*this); } } @@ -365,36 +318,37 @@ void Particle::event_death() { #ifdef DAGMC - if (settings::dagmc) history_.reset(); - #endif + if (settings::dagmc) + history().reset(); +#endif // Finish particle track output. - if (write_track_) { + if (write_track()) { write_particle_track(*this); finalize_particle_track(*this); } // Contribute tally reduction variables to global accumulator #pragma omp atomic - global_tally_absorption += keff_tally_absorption_; - #pragma omp atomic - global_tally_collision += keff_tally_collision_; - #pragma omp atomic - global_tally_tracklength += keff_tally_tracklength_; - #pragma omp atomic - global_tally_leakage += keff_tally_leakage_; + global_tally_absorption += keff_tally_absorption(); +#pragma omp atomic + global_tally_collision += keff_tally_collision(); +#pragma omp atomic + global_tally_tracklength += keff_tally_tracklength(); +#pragma omp atomic + global_tally_leakage += keff_tally_leakage(); // Reset particle tallies once accumulated - keff_tally_absorption_ = 0.0; - keff_tally_collision_ = 0.0; - keff_tally_tracklength_ = 0.0; - keff_tally_leakage_ = 0.0; + keff_tally_absorption() = 0.0; + keff_tally_collision() = 0.0; + keff_tally_tracklength() = 0.0; + keff_tally_leakage() = 0.0; // Record the number of progeny created by this particle. // This data will be used to efficiently sort the fission bank. if (settings::run_mode == RunMode::EIGENVALUE) { - int64_t offset = id_ - 1 - simulation::work_index[mpi::rank]; - simulation::progeny_per_particle[offset] = n_progeny_; + int64_t offset = id() - 1 - simulation::work_index[mpi::rank]; + simulation::progeny_per_particle[offset] = n_progeny(); } } @@ -402,24 +356,24 @@ Particle::event_death() void Particle::cross_surface() { - int i_surface = std::abs(surface_); + int i_surface = std::abs(surface()); // TODO: off-by-one const auto& surf {model::surfaces[i_surface - 1].get()}; - if (settings::verbosity >= 10 || trace_) { + if (settings::verbosity >= 10 || trace()) { write_message(1, " Crossing surface {}", surf->id_); } if (surf->surf_source_ && simulation::current_batch == settings::n_batches) { - Particle::Bank site; - site.r = this->r(); - site.u = this->u(); - site.E = this->E_; - site.wgt = this->wgt_; - site.delayed_group = this->delayed_group_; + SourceSite site; + site.r = r(); + site.u = u(); + site.E = E(); + site.wgt = wgt(); + site.delayed_group = delayed_group(); site.surf_id = surf->id_; - site.particle = this->type_; - site.parent_id = this->id_; - site.progeny_id = this->n_progeny_; + site.particle = type(); + site.parent_id = id(); + site.progeny_id = n_progeny(); int64_t idx = simulation::surf_source_bank.thread_safe_append(site); } @@ -434,18 +388,19 @@ Particle::cross_surface() #ifdef DAGMC if (settings::dagmc) { - auto cellp = dynamic_cast(model::cells[cell_last_[0]].get()); + auto cellp = dynamic_cast(model::cells[cell_last(0)].get()); // TODO: off-by-one - auto surfp = dynamic_cast(model::surfaces[std::abs(surface_) - 1].get()); + auto surfp = + dynamic_cast(model::surfaces[std::abs(surface()) - 1].get()); int32_t i_cell = next_cell(cellp, surfp) - 1; // save material and temp - material_last_ = material_; - sqrtkT_last_ = sqrtkT_; + material_last() = material(); + sqrtkT_last() = sqrtkT(); // set new cell value - coord_[0].cell = i_cell; - cell_instance_ = 0; - material_ = model::cells[i_cell]->material_[0]; - sqrtkT_ = model::cells[i_cell]->sqrtkT_[0]; + coord(0).cell = i_cell; + cell_instance() = 0; + material() = model::cells[i_cell]->material_[0]; + sqrtkT() = model::cells[i_cell]->sqrtkT_[0]; return; } #endif @@ -457,8 +412,8 @@ Particle::cross_surface() // COULDN'T FIND PARTICLE IN NEIGHBORING CELLS, SEARCH ALL CELLS // Remove lower coordinate levels and assignment of surface - surface_ = 0; - n_coord_ = 1; + surface() = 0; + n_coord() = 1; bool found = exhaustive_find_cell(*this); if (settings::run_mode != RunMode::PLOTTING && (!found)) { @@ -467,16 +422,16 @@ Particle::cross_surface() // the particle is really traveling tangent to a surface, if we move it // forward a tiny bit it should fix the problem. - n_coord_ = 1; - this->r() += TINY_BIT * this->u(); + n_coord() = 1; + r() += TINY_BIT * u(); // Couldn't find next cell anywhere! This probably means there is an actual // undefined region in the geometry. if (!exhaustive_find_cell(*this)) { - this->mark_as_lost("After particle " + std::to_string(id_) + - " crossed surface " + std::to_string(surf->id_) + - " it could not be located in any cell and it did not leak."); + mark_as_lost("After particle " + std::to_string(id()) + + " crossed surface " + std::to_string(surf->id_) + + " it could not be located in any cell and it did not leak."); return; } } @@ -486,7 +441,7 @@ void Particle::cross_vacuum_bc(const Surface& surf) { // Kill the particle - alive_ = false; + alive() = false; // Score any surface current tallies -- note that the particle is moved // forward slightly so that if the mesh boundary is on the surface, it is @@ -496,15 +451,15 @@ Particle::cross_vacuum_bc(const Surface& surf) // TODO: Find a better solution to score surface currents than // physically moving the particle forward slightly - this->r() += TINY_BIT * this->u(); + r() += TINY_BIT * u(); score_surface_tally(*this, model::active_meshsurf_tallies); } // Score to global leakage tally - keff_tally_leakage_ += wgt_; + keff_tally_leakage() += wgt(); // Display message - if (settings::verbosity >= 10 || trace_) { + if (settings::verbosity >= 10 || trace()) { write_message(1, " Leaked out of surface {}", surf.id_); } } @@ -513,9 +468,9 @@ void Particle::cross_reflective_bc(const Surface& surf, Direction new_u) { // Do not handle reflective boundary conditions on lower universes - if (n_coord_ != 1) { - this->mark_as_lost("Cannot reflect particle " + std::to_string(id_) + - " off surface in a lower universe."); + if (n_coord() != 1) { + mark_as_lost("Cannot reflect particle " + std::to_string(id()) + + " off surface in a lower universe."); return; } @@ -532,36 +487,36 @@ Particle::cross_reflective_bc(const Surface& surf, Direction new_u) if (!model::active_meshsurf_tallies.empty()) { Position r {this->r()}; - this->r() -= TINY_BIT * this->u(); + this->r() -= TINY_BIT * u(); score_surface_tally(*this, model::active_meshsurf_tallies); this->r() = r; } // Set the new particle direction - this->u() = new_u; + u() = new_u; // Reassign particle's cell and surface - coord_[0].cell = cell_last_[n_coord_last_ - 1]; - surface_ = -surface_; + coord(0).cell = cell_last(n_coord_last() - 1); + surface() = -surface(); // If a reflective surface is coincident with a lattice or universe // boundary, it is necessary to redetermine the particle's coordinates in // the lower universes. // (unless we're using a dagmc model, which has exactly one universe) if (!settings::dagmc) { - n_coord_ = 1; + n_coord() = 1; if (!neighbor_list_find_cell(*this)) { - this->mark_as_lost("Couldn't find particle after reflecting from surface " - + std::to_string(surf.id_) + "."); + mark_as_lost("Couldn't find particle after reflecting from surface " + + std::to_string(surf.id_) + "."); return; } } // Set previous coordinate going slightly past surface crossing - r_last_current_ = this->r() + TINY_BIT*this->u(); + r_last_current() = r() + TINY_BIT * u(); // Diagnostic message - if (settings::verbosity >= 10 || trace_) { + if (settings::verbosity >= 10 || trace()) { write_message(1, " Reflected from surface {}", surf.id_); } } @@ -571,8 +526,9 @@ Particle::cross_periodic_bc(const Surface& surf, Position new_r, Direction new_u, int new_surface) { // Do not handle periodic boundary conditions on lower universes - if (n_coord_ != 1) { - this->mark_as_lost("Cannot transfer particle " + std::to_string(id_) + + if (n_coord() != 1) { + mark_as_lost( + "Cannot transfer particle " + std::to_string(id()) + " across surface in a lower universe. Boundary conditions must be " "applied to root universe."); return; @@ -583,7 +539,7 @@ Particle::cross_periodic_bc(const Surface& surf, Position new_r, // case the surface crossing is coincident with a mesh boundary if (!model::active_meshsurf_tallies.empty()) { Position r {this->r()}; - this->r() -= TINY_BIT * this->u(); + this->r() -= TINY_BIT * u(); score_surface_tally(*this, model::active_meshsurf_tallies); this->r() = r; } @@ -593,23 +549,25 @@ Particle::cross_periodic_bc(const Surface& surf, Position new_r, u() = new_u; // Reassign particle's surface - surface_ = new_surface; + surface() = new_surface; // Figure out what cell particle is in now - n_coord_ = 1; + n_coord() = 1; if (!neighbor_list_find_cell(*this)) { - this->mark_as_lost("Couldn't find particle after hitting periodic " - "boundary on surface " + std::to_string(surf.id_) + ". The normal vector " - "of one periodic surface may need to be reversed."); + mark_as_lost("Couldn't find particle after hitting periodic " + "boundary on surface " + + std::to_string(surf.id_) + + ". The normal vector " + "of one periodic surface may need to be reversed."); return; } // Set previous coordinate going slightly past surface crossing - r_last_current_ = this->r() + TINY_BIT*this->u(); + r_last_current() = r() + TINY_BIT * u(); // Diagnostic message - if (settings::verbosity >= 10 || trace_) { + if (settings::verbosity >= 10 || trace()) { write_message(1, " Hit periodic boundary on surface {}", surf.id_); } } @@ -622,8 +580,8 @@ Particle::mark_as_lost(const char* message) write_restart(); // Increment number of lost particles - alive_ = false; - #pragma omp atomic + alive() = false; +#pragma omp atomic simulation::n_lost_particles += 1; // Count the total number of simulated particles (on this processor) @@ -646,9 +604,9 @@ Particle::write_restart() const // Set up file name auto filename = fmt::format("{}particle_{}_{}.h5", settings::path_output, - simulation::current_batch, id_); + simulation::current_batch, id()); - #pragma omp critical (WriteParticleRestart) +#pragma omp critical (WriteParticleRestart) { // Create file hid_t file_id = file_open(filename, 'w'); @@ -679,10 +637,10 @@ Particle::write_restart() const default: break; } - write_dataset(file_id, "id", id_); - write_dataset(file_id, "type", static_cast(type_)); + write_dataset(file_id, "id", id()); + write_dataset(file_id, "type", static_cast(type())); - int64_t i = current_work_; + int64_t i = current_work(); if (settings::run_mode == RunMode::EIGENVALUE) { //take source data from primary bank for eigenvalue simulation write_dataset(file_id, "weight", simulation::source_bank[i-1].wgt); @@ -707,31 +665,31 @@ Particle::write_restart() const } // #pragma omp critical } -std::string particle_type_to_str(Particle::Type type) +std::string particle_type_to_str(ParticleType type) { switch (type) { - case Particle::Type::neutron: - return "neutron"; - case Particle::Type::photon: - return "photon"; - case Particle::Type::electron: - return "electron"; - case Particle::Type::positron: - return "positron"; + case ParticleType::neutron: + return "neutron"; + case ParticleType::photon: + return "photon"; + case ParticleType::electron: + return "electron"; + case ParticleType::positron: + return "positron"; } UNREACHABLE(); } -Particle::Type str_to_particle_type(std::string str) +ParticleType str_to_particle_type(std::string str) { if (str == "neutron") { - return Particle::Type::neutron; + return ParticleType::neutron; } else if (str == "photon") { - return Particle::Type::photon; + return ParticleType::photon; } else if (str == "electron") { - return Particle::Type::electron; + return ParticleType::electron; } else if (str == "positron") { - return Particle::Type::positron; + return ParticleType::positron; } else { throw std::invalid_argument{fmt::format("Invalid particle name: {}", str)}; } diff --git a/src/particle_data.cpp b/src/particle_data.cpp new file mode 100644 index 000000000..701e6cbc0 --- /dev/null +++ b/src/particle_data.cpp @@ -0,0 +1,56 @@ +#include "openmc/particle_data.h" + +#include "openmc/geometry.h" +#include "openmc/nuclide.h" +#include "openmc/photon.h" +#include "openmc/settings.h" +#include "openmc/tallies/derivative.h" +#include "openmc/tallies/filter.h" +#include "openmc/tallies/tally.h" + +namespace openmc { + +void LocalCoord::rotate(const vector& rotation) +{ + r = r.rotate(rotation); + u = u.rotate(rotation); + rotated = true; +} + +void LocalCoord::reset() +{ + cell = C_NONE; + universe = C_NONE; + lattice = C_NONE; + lattice_i[0] = 0; + lattice_i[1] = 0; + lattice_i[2] = 0; + rotated = false; +} + +ParticleData::ParticleData() +{ + // Create and clear coordinate levels + coord_.resize(model::n_coord_levels); + cell_last_.resize(model::n_coord_levels); + clear(); + + zero_delayed_bank(); + + // Every particle starts with no accumulated flux derivative. Note that in + // event mode, we construct the particle once up front, so have to run this + // even if the current batch is inactive. + if (!model::active_tallies.empty() || settings::event_based) { + flux_derivs_.resize(model::tally_derivs.size()); + zero_flux_derivs(); + } + + // Allocate space for tally filter matches + filter_matches_.resize(model::tally_filters.size()); + + // Create microscopic cross section caches + neutron_xs_.resize(data::nuclides.size()); + photon_xs_.resize(data::elements.size()); +} + +} // namespace openmc diff --git a/src/particle_restart.cpp b/src/particle_restart.cpp index be9eda77f..7150bc6da 100644 --- a/src/particle_restart.cpp +++ b/src/particle_restart.cpp @@ -1,5 +1,6 @@ #include "openmc/particle_restart.h" +#include "openmc/array.h" #include "openmc/constants.h" #include "openmc/hdf5_interface.h" #include "openmc/mgxs_interface.h" @@ -15,7 +16,6 @@ #include "openmc/track_output.h" #include // for copy -#include #include #include @@ -41,28 +41,28 @@ void read_particle_restart(Particle& p, RunMode& previous_run_mode) } else if (mode == "fixed source") { previous_run_mode = RunMode::FIXED_SOURCE; } - read_dataset(file_id, "id", p.id_); + read_dataset(file_id, "id", p.id()); int type; read_dataset(file_id, "type", type); - p.type_ = static_cast(type); - read_dataset(file_id, "weight", p.wgt_); - read_dataset(file_id, "energy", p.E_); + p.type() = static_cast(type); + read_dataset(file_id, "weight", p.wgt()); + read_dataset(file_id, "energy", p.E()); read_dataset(file_id, "xyz", p.r()); read_dataset(file_id, "uvw", p.u()); // Set energy group and average energy in multi-group mode if (!settings::run_CE) { - p.g_ = p.E_; - p.E_ = data::mg.energy_bin_avg_[p.g_]; + p.g() = p.E(); + p.E() = data::mg.energy_bin_avg_[p.g()]; } // Set particle last attributes - p.wgt_last_ = p.wgt_; - p.r_last_current_ = p.r(); - p.r_last_ = p.r(); - p.u_last_ = p.u(); - p.E_last_ = p.E_; - p.g_last_ = p.g_; + p.wgt_last() = p.wgt(); + p.r_last_current() = p.r(); + p.r_last() = p.r(); + p.u_last() = p.u(); + p.E_last() = p.E(); + p.g_last() = p.g(); // Close hdf5 file file_close(file_id); @@ -84,7 +84,8 @@ void run_particle_restart() read_particle_restart(p, previous_run_mode); // write track if that was requested on command line - if (settings::write_all_tracks) p.write_track_ = true; + if (settings::write_all_tracks) + p.write_track() = true; // Set all tallies to 0 for now (just tracking errors) model::tallies.clear(); @@ -93,33 +94,27 @@ void run_particle_restart() int64_t particle_seed; switch (previous_run_mode) { case RunMode::EIGENVALUE: - particle_seed = (simulation::total_gen + overall_generation() - 1)*settings::n_particles + p.id_; + particle_seed = (simulation::total_gen + overall_generation() - 1) * + settings::n_particles + + p.id(); break; case RunMode::FIXED_SOURCE: - particle_seed = p.id_; + particle_seed = p.id(); break; default: throw std::runtime_error{"Unexpected run mode: " + std::to_string(static_cast(previous_run_mode))}; } - init_particle_seeds(particle_seed, p.seeds_); + init_particle_seeds(particle_seed, p.seeds()); // Force calculation of cross-sections by setting last energy to zero if (settings::run_CE) { - for (auto& micro : p.neutron_xs_) micro.last_E = 0.0; + p.invalidate_neutron_xs(); } // Prepare to write out particle track. - if (p.write_track_) add_particle_track(p); - - // Every particle starts with no accumulated flux derivative. - if (!model::active_tallies.empty()) { - p.flux_derivs_.resize(model::tally_derivs.size(), 0.0); - std::fill(p.flux_derivs_.begin(), p.flux_derivs_.end(), 0.0); - } - - // Allocate space for tally filter matches - p.filter_matches_.resize(model::tally_filters.size()); + if (p.write_track()) + add_particle_track(p); // Transport neutron transport_history_based_single_particle(p); diff --git a/src/photon.cpp b/src/photon.cpp index 78c8e86ae..1e9a2557a 100644 --- a/src/photon.cpp +++ b/src/photon.cpp @@ -1,5 +1,6 @@ #include "openmc/photon.h" +#include "openmc/array.h" #include "openmc/bremsstrahlung.h" #include "openmc/constants.h" #include "openmc/distribution_multi.h" @@ -15,7 +16,6 @@ #include "xtensor/xoperation.hpp" #include "xtensor/xview.hpp" -#include #include #include // for tie @@ -30,7 +30,7 @@ namespace data { xt::xtensor compton_profile_pz; std::unordered_map element_map; -std::vector> elements; +vector> elements; } // namespace data @@ -112,7 +112,7 @@ PhotonInteraction::PhotonInteraction(hid_t group) // Read subshell photoionization cross section and atomic relaxation data rgroup = open_group(group, "subshells"); - std::vector designators; + vector designators; read_attribute(rgroup, "designators", designators); auto n_shell = designators.size(); if (n_shell == 0) { @@ -233,7 +233,7 @@ PhotonInteraction::PhotonInteraction(hid_t group) close_group(rgroup); // Truncate the bremsstrahlung data at the cutoff energy - int photon = static_cast(Particle::Type::photon); + int photon = static_cast(ParticleType::photon); const auto& E {electron_energy}; double cutoff = settings::energy_cutoff[photon]; if (cutoff > E(0)) { @@ -456,7 +456,7 @@ void PhotonInteraction::calculate_xs(Particle& p) const // Perform binary search on the element energy grid in order to determine // which points to interpolate between int n_grid = energy_.size(); - double log_E = std::log(p.E_); + double log_E = std::log(p.E()); int i_grid; if (log_E <= energy_[0]) { i_grid = 0; @@ -474,7 +474,7 @@ void PhotonInteraction::calculate_xs(Particle& p) const // calculate interpolation factor double f = (log_E - energy_(i_grid)) / (energy_(i_grid+1) - energy_(i_grid)); - auto& xs {p.photon_xs_[index_]}; + auto& xs {p.photon_xs(index_)}; xs.index_grid = i_grid; xs.interp_factor = f; @@ -508,7 +508,7 @@ void PhotonInteraction::calculate_xs(Particle& p) const // Calculate microscopic total cross section xs.total = xs.coherent + xs.incoherent + xs.photoelectric + xs.pair_production; - xs.last_E = p.E_; + xs.last_E = p.E(); } double PhotonInteraction::rayleigh_scatter(double alpha, uint64_t* seed) const @@ -666,7 +666,7 @@ void PhotonInteraction::atomic_relaxation(const ElectronSubshell& shell, Particl if (shell.n_transitions == 0) { Direction u = isotropic_direction(p.current_seed()); double E = shell.binding_energy; - p.create_secondary(p.wgt_, u, E, Particle::Type::photon); + p.create_secondary(p.wgt(), u, E, ParticleType::photon); return; } @@ -693,7 +693,7 @@ void PhotonInteraction::atomic_relaxation(const ElectronSubshell& shell, Particl // Non-radiative transition -- Auger/Coster-Kronig effect // Create auger electron - p.create_secondary(p.wgt_, u, E, Particle::Type::electron); + p.create_secondary(p.wgt(), u, E, ParticleType::electron); // Fill hole left by emitted auger electron int i_hole = shell_map_.at(secondary); @@ -703,7 +703,7 @@ void PhotonInteraction::atomic_relaxation(const ElectronSubshell& shell, Particl // Radiative transition -- get X-ray energy // Create fluorescent photon - p.create_secondary(p.wgt_, u, E, Particle::Type::photon); + p.create_secondary(p.wgt(), u, E, ParticleType::photon); } // Fill hole created by electron transitioning to the photoelectron hole diff --git a/src/physics.cpp b/src/physics.cpp index fd61350e5..212149694 100644 --- a/src/physics.cpp +++ b/src/physics.cpp @@ -38,46 +38,46 @@ namespace openmc { void collision(Particle& p) { // Add to collision counter for particle - ++(p.n_collision_); + ++(p.n_collision()); // Sample reaction for the material the particle is in - switch (p.type_) { - case Particle::Type::neutron: + switch (p.type()) { + case ParticleType::neutron: sample_neutron_reaction(p); break; - case Particle::Type::photon: + case ParticleType::photon: sample_photon_reaction(p); break; - case Particle::Type::electron: + case ParticleType::electron: sample_electron_reaction(p); break; - case Particle::Type::positron: + case ParticleType::positron: sample_positron_reaction(p); break; } // Kill particle if energy falls below cutoff - int type = static_cast(p.type_); - if (p.E_ < settings::energy_cutoff[type]) { - p.alive_ = false; - p.wgt_ = 0.0; + int type = static_cast(p.type()); + if (p.E() < settings::energy_cutoff[type]) { + p.alive() = false; + p.wgt() = 0.0; } // Display information about collision - if (settings::verbosity >= 10 || p.trace_) { + if (settings::verbosity >= 10 || p.trace()) { std::string msg; - if (p.event_ == TallyEvent::KILL) { - msg = fmt::format(" Killed. Energy = {} eV.", p.E_); - } else if (p.type_ == Particle::Type::neutron) { + if (p.event() == TallyEvent::KILL) { + msg = fmt::format(" Killed. Energy = {} eV.", p.E()); + } else if (p.type() == ParticleType::neutron) { msg = fmt::format(" {} with {}. Energy = {} eV.", - reaction_name(p.event_mt_), data::nuclides[p.event_nuclide_]->name_, - p.E_); - } else if (p.type_ == Particle::Type::photon) { + reaction_name(p.event_mt()), data::nuclides[p.event_nuclide()]->name_, + p.E()); + } else if (p.type() == ParticleType::photon) { msg = fmt::format(" {} with {}. Energy = {} eV.", - reaction_name(p.event_mt_), - to_element(data::nuclides[p.event_nuclide_]->name_), p.E_); + reaction_name(p.event_mt()), + to_element(data::nuclides[p.event_nuclide()]->name_), p.E()); } else { - msg = fmt::format(" Disappeared. Energy = {} eV.", p.E_); + msg = fmt::format(" Disappeared. Energy = {} eV.", p.E()); } write_message(msg, 1); } @@ -89,7 +89,7 @@ void sample_neutron_reaction(Particle& p) int i_nuclide = sample_nuclide(p); // Save which nuclide particle had collision with - p.event_nuclide_ = i_nuclide; + p.event_nuclide() = i_nuclide; // Create fission bank sites. Note that while a fission reaction is sampled, // it never actually "happens", i.e. the weight of the particle does not @@ -108,7 +108,7 @@ void sample_neutron_reaction(Particle& p) // Make sure particle population doesn't grow out of control for // subcritical multiplication problems. - if (p.secondary_bank_.size() >= 10000) { + if (p.secondary_bank().size() >= 10000) { fatal_error("The secondary particle bank appears to be growing without " "bound. You are likely running a subcritical multiplication problem " "with k-effective close to or greater than one."); @@ -124,28 +124,30 @@ void sample_neutron_reaction(Particle& p) // If survival biasing is being used, the following subroutine adjusts the // weight of the particle. Otherwise, it checks to see if absorption occurs - if (p.neutron_xs_[i_nuclide].absorption > 0.0) { + if (p.neutron_xs(i_nuclide).absorption > 0.0) { absorption(p, i_nuclide); } else { - p.wgt_absorb_ = 0.0; + p.wgt_absorb() = 0.0; } - if (!p.alive_) return; + if (!p.alive()) + return; // Sample a scattering reaction and determine the secondary energy of the // exiting neutron scatter(p, i_nuclide); // Advance URR seed stream 'N' times after energy changes - if (p.E_ != p.E_last_) { - p.stream_ = STREAM_URR_PTABLE; + if (p.E() != p.E_last()) { + p.stream() = STREAM_URR_PTABLE; advance_prn_seed(data::nuclides.size(), p.current_seed()); - p.stream_ = STREAM_TRACKING; + p.stream() = STREAM_TRACKING; } // Play russian roulette if survival biasing is turned on if (settings::survival_biasing) { russian_roulette(p); - if (!p.alive_) return; + if (!p.alive()) + return; } } @@ -157,8 +159,9 @@ create_fission_sites(Particle& p, int i_nuclide, const Reaction& rx) double weight = settings::ufs_on ? ufs_get_weight(p) : 1.0; // Determine the expected number of neutrons produced - double nu_t = p.wgt_ / simulation::keff * weight * p.neutron_xs_[ - i_nuclide].nu_fission / p.neutron_xs_[i_nuclide].total; + double nu_t = p.wgt() / simulation::keff * weight * + p.neutron_xs(i_nuclide).nu_fission / + p.neutron_xs(i_nuclide).total; // Sample the number of neutrons produced int nu = static_cast(nu_t); @@ -173,9 +176,9 @@ create_fission_sites(Particle& p, int i_nuclide, const Reaction& rx) double nu_d[MAX_DELAYED_GROUPS] = {0.}; // Clear out particle's nu fission bank - p.nu_bank_.clear(); + p.nu_bank().clear(); - p.fission_ = true; + p.fission() = true; int skipped = 0; // Determine whether to place fission sites into the shared fission bank @@ -184,16 +187,16 @@ create_fission_sites(Particle& p, int i_nuclide, const Reaction& rx) for (int i = 0; i < nu; ++i) { // Initialize fission site object with particle data - Particle::Bank site; + SourceSite site; site.r = p.r(); - site.particle = Particle::Type::neutron; + site.particle = ParticleType::neutron; site.wgt = 1. / weight; - site.parent_id = p.id_; - site.progeny_id = p.n_progeny_++; + site.parent_id = p.id(); + site.progeny_id = p.n_progeny()++; site.surf_id = 0; // Sample delayed group and angle/energy for fission reaction - sample_fission_neutron(i_nuclide, rx, p.E_, &site, p.current_seed()); + sample_fission_neutron(i_nuclide, rx, p.E(), &site, p.current_seed()); // Store fission site in bank if (use_fission_bank) { @@ -205,20 +208,20 @@ create_fission_sites(Particle& p, int i_nuclide, const Reaction& rx) break; } } else { - p.secondary_bank_.push_back(site); + p.secondary_bank().push_back(site); } // Set the delayed group on the particle as well - p.delayed_group_ = site.delayed_group; + p.delayed_group() = site.delayed_group; // Increment the number of neutrons born delayed - if (p.delayed_group_ > 0) { - nu_d[p.delayed_group_-1]++; + if (p.delayed_group() > 0) { + nu_d[p.delayed_group() - 1]++; } // Write fission particles to nuBank - p.nu_bank_.emplace_back(); - Particle::NuBank* nu_bank_entry = &p.nu_bank_.back(); + p.nu_bank().emplace_back(); + NuBank* nu_bank_entry = &p.nu_bank().back(); nu_bank_entry->wgt = site.wgt; nu_bank_entry->E = site.E; nu_bank_entry->delayed_group = site.delayed_group; @@ -227,7 +230,7 @@ create_fission_sites(Particle& p, int i_nuclide, const Reaction& rx) // If shared fission bank was full, and no fissions could be added, // set the particle fission flag to false. if (nu == skipped) { - p.fission_ = false; + p.fission() = false; return; } @@ -236,10 +239,10 @@ create_fission_sites(Particle& p, int i_nuclide, const Reaction& rx) nu -= skipped; // Store the total weight banked for analog fission tallies - p.n_bank_ = nu; - p.wgt_bank_ = nu / weight; + p.n_bank() = nu; + p.wgt_bank() = nu / weight; for (size_t d = 0; d < MAX_DELAYED_GROUPS; d++) { - p.n_delayed_bank_[d] = nu_d[d]; + p.n_delayed_bank(d) = nu_d[d]; } } @@ -248,20 +251,20 @@ void sample_photon_reaction(Particle& p) // Kill photon if below energy cutoff -- an extra check is made here because // photons with energy below the cutoff may have been produced by neutrons // reactions or atomic relaxation - int photon = static_cast(Particle::Type::photon); - if (p.E_ < settings::energy_cutoff[photon]) { - p.E_ = 0.0; - p.alive_ = false; + int photon = static_cast(ParticleType::photon); + if (p.E() < settings::energy_cutoff[photon]) { + p.E() = 0.0; + p.alive() = false; return; } // Sample element within material int i_element = sample_element(p); - const auto& micro {p.photon_xs_[i_element]}; + const auto& micro {p.photon_xs(i_element)}; const auto& element {*data::elements[i_element]}; // Calculate photon energy over electron rest mass equivalent - double alpha = p.E_/MASS_ELECTRON_EV; + double alpha = p.E() / MASS_ELECTRON_EV; // For tallying purposes, this routine might be called directly. In that // case, we need to sample a reaction via the cutoff variable @@ -273,8 +276,8 @@ void sample_photon_reaction(Particle& p) if (prob > cutoff) { double mu = element.rayleigh_scatter(alpha, p.current_seed()); p.u() = rotate_angle(p.u(), mu, nullptr, p.current_seed()); - p.event_ = TallyEvent::SCATTER; - p.event_mt_ = COHERENT; + p.event() = TallyEvent::SCATTER; + p.event_mt() = COHERENT; return; } @@ -297,12 +300,12 @@ void sample_photon_reaction(Particle& p) // Create Compton electron double phi = uniform_distribution(0., 2.0*PI, p.current_seed()); double E_electron = (alpha - alpha_out)*MASS_ELECTRON_EV - e_b; - int electron = static_cast(Particle::Type::electron); + int electron = static_cast(ParticleType::electron); if (E_electron >= settings::energy_cutoff[electron]) { double mu_electron = (alpha - alpha_out*mu) / std::sqrt(alpha*alpha + alpha_out*alpha_out - 2.0*alpha*alpha_out*mu); Direction u = rotate_angle(p.u(), mu_electron, &phi, p.current_seed()); - p.create_secondary(p.wgt_, u, E_electron, Particle::Type::electron); + p.create_secondary(p.wgt(), u, E_electron, ParticleType::electron); } // TODO: Compton subshell data does not match atomic relaxation data @@ -314,10 +317,10 @@ void sample_photon_reaction(Particle& p) } phi += PI; - p.E_ = alpha_out*MASS_ELECTRON_EV; + p.E() = alpha_out * MASS_ELECTRON_EV; p.u() = rotate_angle(p.u(), mu, &phi, p.current_seed()); - p.event_ = TallyEvent::SCATTER; - p.event_mt_ = INCOHERENT; + p.event() = TallyEvent::SCATTER; + p.event_mt() = INCOHERENT; return; } @@ -340,7 +343,7 @@ void sample_photon_reaction(Particle& p) prob += xs; if (prob > cutoff) { - double E_electron = p.E_ - shell.binding_energy; + double E_electron = p.E() - shell.binding_energy; // Sample mu using non-relativistic Sauter distribution. // See Eqns 3.19 and 3.20 in "Implementing a photon physics @@ -363,15 +366,15 @@ void sample_photon_reaction(Particle& p) u.z = std::sqrt(1.0 - mu*mu)*std::sin(phi); // Create secondary electron - p.create_secondary(p.wgt_, u, E_electron, Particle::Type::electron); + p.create_secondary(p.wgt(), u, E_electron, ParticleType::electron); // Allow electrons to fill orbital and produce auger electrons // and fluorescent photons element.atomic_relaxation(shell, p); - p.event_ = TallyEvent::ABSORB; - p.event_mt_ = 533 + shell.index_subshell; - p.alive_ = false; - p.E_ = 0.0; + p.event() = TallyEvent::ABSORB; + p.event_mt() = 533 + shell.index_subshell; + p.alive() = false; + p.E() = 0.0; return; } } @@ -388,16 +391,16 @@ void sample_photon_reaction(Particle& p) // Create secondary electron Direction u = rotate_angle(p.u(), mu_electron, nullptr, p.current_seed()); - p.create_secondary(p.wgt_, u, E_electron, Particle::Type::electron); + p.create_secondary(p.wgt(), u, E_electron, ParticleType::electron); // Create secondary positron u = rotate_angle(p.u(), mu_positron, nullptr, p.current_seed()); - p.create_secondary(p.wgt_, u, E_positron, Particle::Type::positron); + p.create_secondary(p.wgt(), u, E_positron, ParticleType::positron); - p.event_ = TallyEvent::ABSORB; - p.event_mt_ = PAIR_PROD; - p.alive_ = false; - p.E_ = 0.0; + p.event() = TallyEvent::ABSORB; + p.event_mt() = PAIR_PROD; + p.alive() = false; + p.E() = 0.0; } } @@ -410,9 +413,9 @@ void sample_electron_reaction(Particle& p) thick_target_bremsstrahlung(p, &E_lost); } - p.E_ = 0.0; - p.alive_ = false; - p.event_ = TallyEvent::ABSORB; + p.E() = 0.0; + p.alive() = false; + p.event() = TallyEvent::ABSORB; } void sample_positron_reaction(Particle& p) @@ -428,21 +431,21 @@ void sample_positron_reaction(Particle& p) Direction u = isotropic_direction(p.current_seed()); // Create annihilation photon pair traveling in opposite directions - p.create_secondary(p.wgt_, u, MASS_ELECTRON_EV, Particle::Type::photon); - p.create_secondary(p.wgt_, -u, MASS_ELECTRON_EV, Particle::Type::photon); + p.create_secondary(p.wgt(), u, MASS_ELECTRON_EV, ParticleType::photon); + p.create_secondary(p.wgt(), -u, MASS_ELECTRON_EV, ParticleType::photon); - p.E_ = 0.0; - p.alive_ = false; - p.event_ = TallyEvent::ABSORB; + p.E() = 0.0; + p.alive() = false; + p.event() = TallyEvent::ABSORB; } int sample_nuclide(Particle& p) { // Sample cumulative distribution function - double cutoff = prn(p.current_seed()) * p.macro_xs_.total; + double cutoff = prn(p.current_seed()) * p.macro_xs().total; // Get pointers to nuclide/density arrays - const auto& mat {model::materials[p.material_]}; + const auto& mat {model::materials[p.material()]}; int n = mat->nuclide_.size(); double prob = 0.0; @@ -452,7 +455,7 @@ int sample_nuclide(Particle& p) double atom_density = mat->atom_density_[i]; // Increment probability to compare to cutoff - prob += atom_density * p.neutron_xs_[i_nuclide].total; + prob += atom_density * p.neutron_xs(i_nuclide).total; if (prob >= cutoff) return i_nuclide; } @@ -464,10 +467,10 @@ int sample_nuclide(Particle& p) int sample_element(Particle& p) { // Sample cumulative distribution function - double cutoff = prn(p.current_seed()) * p.macro_xs_.total; + double cutoff = prn(p.current_seed()) * p.macro_xs().total; // Get pointers to elements, densities - const auto& mat {model::materials[p.material_]}; + const auto& mat {model::materials[p.material()]}; double prob = 0.0; for (int i = 0; i < mat->element_.size(); ++i) { @@ -476,13 +479,13 @@ int sample_element(Particle& p) double atom_density = mat->atom_density_[i]; // Determine microscopic cross section - double sigma = atom_density * p.photon_xs_[i_element].total; + double sigma = atom_density * p.photon_xs(i_element).total; // Increment probability to compare to cutoff prob += sigma; if (prob > cutoff) { // Save which nuclide particle had collision with for tally purpose - p.event_nuclide_ = mat->nuclide_[i]; + p.event_nuclide() = mat->nuclide_[i]; return i_element; } @@ -501,23 +504,23 @@ Reaction& sample_fission(int i_nuclide, Particle& p) // If we're in the URR, by default use the first fission reaction. We also // default to the first reaction if we know that there are no partial fission // reactions - if (p.neutron_xs_[i_nuclide].use_ptable || !nuc->has_partial_fission_) { + if (p.neutron_xs(i_nuclide).use_ptable || !nuc->has_partial_fission_) { return *nuc->fission_rx_[0]; } // Check to see if we are in a windowed multipole range. WMP only supports // the first fission reaction. if (nuc->multipole_) { - if (p.E_ >= nuc->multipole_->E_min_ && p.E_ <= nuc->multipole_->E_max_) { + if (p.E() >= nuc->multipole_->E_min_ && p.E() <= nuc->multipole_->E_max_) { return *nuc->fission_rx_[0]; } } // Get grid index and interpolatoin factor and sample fission cdf - int i_temp = p.neutron_xs_[i_nuclide].index_temp; - int i_grid = p.neutron_xs_[i_nuclide].index_grid; - double f = p.neutron_xs_[i_nuclide].interp_factor; - double cutoff = prn(p.current_seed()) * p.neutron_xs_[i_nuclide].fission; + int i_temp = p.neutron_xs(i_nuclide).index_temp; + int i_grid = p.neutron_xs(i_nuclide).index_grid; + double f = p.neutron_xs(i_nuclide).interp_factor; + double cutoff = prn(p.current_seed()) * p.neutron_xs(i_nuclide).fission; double prob = 0.0; // Loop through each partial fission reaction type @@ -541,10 +544,10 @@ Reaction& sample_fission(int i_nuclide, Particle& p) void sample_photon_product(int i_nuclide, Particle& p, int* i_rx, int* i_product) { // Get grid index and interpolation factor and sample photon production cdf - int i_temp = p.neutron_xs_[i_nuclide].index_temp; - int i_grid = p.neutron_xs_[i_nuclide].index_grid; - double f = p.neutron_xs_[i_nuclide].interp_factor; - double cutoff = prn(p.current_seed()) * p.neutron_xs_[i_nuclide].photon_prod; + int i_temp = p.neutron_xs(i_nuclide).index_temp; + int i_grid = p.neutron_xs(i_nuclide).index_grid; + double f = p.neutron_xs(i_nuclide).interp_factor; + double cutoff = prn(p.current_seed()) * p.neutron_xs(i_nuclide).photon_prod; double prob = 0.0; // Loop through each reaction type @@ -561,22 +564,22 @@ void sample_photon_product(int i_nuclide, Particle& p, int* i_rx, int* i_product + f*(rx->xs_[i_temp].value[i_grid - threshold + 1])); for (int j = 0; j < rx->products_.size(); ++j) { - if (rx->products_[j].particle_ == Particle::Type::photon) { + if (rx->products_[j].particle_ == ParticleType::photon) { // For fission, artificially increase the photon yield to account // for delayed photons double f = 1.0; if (settings::delayed_photon_scaling) { if (is_fission(rx->mt_)) { if (nuc->prompt_photons_ && nuc->delayed_photons_) { - double energy_prompt = (*nuc->prompt_photons_)(p.E_); - double energy_delayed = (*nuc->delayed_photons_)(p.E_); + double energy_prompt = (*nuc->prompt_photons_)(p.E()); + double energy_delayed = (*nuc->delayed_photons_)(p.E()); f = (energy_prompt + energy_delayed)/(energy_prompt); } } } // add to cumulative probability - prob += f * (*rx->products_[j].yield_)(p.E_) * xs; + prob += f * (*rx->products_[j].yield_)(p.E()) * xs; *i_rx = i; *i_product = j; @@ -590,31 +593,33 @@ void absorption(Particle& p, int i_nuclide) { if (settings::survival_biasing) { // Determine weight absorbed in survival biasing - p.wgt_absorb_ = p.wgt_ * p.neutron_xs_[i_nuclide].absorption / - p.neutron_xs_[i_nuclide].total; + p.wgt_absorb() = p.wgt() * p.neutron_xs(i_nuclide).absorption / + p.neutron_xs(i_nuclide).total; // Adjust weight of particle by probability of absorption - p.wgt_ -= p.wgt_absorb_; - p.wgt_last_ = p.wgt_; + p.wgt() -= p.wgt_absorb(); + p.wgt_last() = p.wgt(); // Score implicit absorption estimate of keff if (settings::run_mode == RunMode::EIGENVALUE) { - p.keff_tally_absorption_ += p.wgt_absorb_ * p.neutron_xs_[ - i_nuclide].nu_fission / p.neutron_xs_[i_nuclide].absorption; + p.keff_tally_absorption() += p.wgt_absorb() * + p.neutron_xs(i_nuclide).nu_fission / + p.neutron_xs(i_nuclide).absorption; } } else { // See if disappearance reaction happens - if (p.neutron_xs_[i_nuclide].absorption > - prn(p.current_seed()) * p.neutron_xs_[i_nuclide].total) { + if (p.neutron_xs(i_nuclide).absorption > + prn(p.current_seed()) * p.neutron_xs(i_nuclide).total) { // Score absorption estimate of keff if (settings::run_mode == RunMode::EIGENVALUE) { - p.keff_tally_absorption_ += p.wgt_ * p.neutron_xs_[ - i_nuclide].nu_fission / p.neutron_xs_[i_nuclide].absorption; + p.keff_tally_absorption() += p.wgt() * + p.neutron_xs(i_nuclide).nu_fission / + p.neutron_xs(i_nuclide).absorption; } - p.alive_ = false; - p.event_ = TallyEvent::ABSORB; - p.event_mt_ = N_DISAPPEAR; + p.alive() = false; + p.event() = TallyEvent::ABSORB; + p.event_mt() = N_DISAPPEAR; } } } @@ -626,7 +631,7 @@ void scatter(Particle& p, int i_nuclide) // Get pointer to nuclide and grid index/interpolation factor const auto& nuc {data::nuclides[i_nuclide]}; - const auto& micro {p.neutron_xs_[i_nuclide]}; + const auto& micro {p.neutron_xs(i_nuclide)}; int i_temp = micro.index_temp; int i_grid = micro.index_grid; double f = micro.interp_factor; @@ -647,12 +652,12 @@ void scatter(Particle& p, int i_nuclide) // NON-S(A,B) ELASTIC SCATTERING // Determine temperature - double kT = nuc->multipole_ ? p.sqrtkT_*p.sqrtkT_ : nuc->kTs_[i_temp]; + double kT = nuc->multipole_ ? p.sqrtkT() * p.sqrtkT() : nuc->kTs_[i_temp]; // Perform collision physics for elastic scattering elastic_scatter(i_nuclide, *nuc->reactions_[0], kT, p); - p.event_mt_ = ELASTIC; + p.event_mt() = ELASTIC; sampled = true; } @@ -663,7 +668,7 @@ void scatter(Particle& p, int i_nuclide) sab_scatter(i_nuclide, micro.index_sab, p); - p.event_mt_ = ELASTIC; + p.event_mt() = ELASTIC; sampled = true; } @@ -695,20 +700,20 @@ void scatter(Particle& p, int i_nuclide) // Perform collision physics for inelastic scattering const auto& rx {nuc->reactions_[i]}; inelastic_scatter(*nuc, *rx, p); - p.event_mt_ = rx->mt_; + p.event_mt() = rx->mt_; } // Set event component - p.event_ = TallyEvent::SCATTER; + p.event() = TallyEvent::SCATTER; // Sample new outgoing angle for isotropic-in-lab scattering - const auto& mat {model::materials[p.material_]}; + const auto& mat {model::materials[p.material()]}; if (!mat->p0_.empty()) { int i_nuc_mat = mat->mat_nuclide_index_[i_nuclide]; if (mat->p0_[i_nuc_mat]) { // Sample isotropic-in-lab outgoing direction p.u() = isotropic_direction(p.current_seed()); - p.mu_ = u_old.dot(p.u()); + p.mu() = u_old.dot(p.u()); } } } @@ -719,7 +724,7 @@ void elastic_scatter(int i_nuclide, const Reaction& rx, double kT, // get pointer to nuclide const auto& nuc {data::nuclides[i_nuclide]}; - double vel = std::sqrt(p.E_); + double vel = std::sqrt(p.E()); double awr = nuc->awr_; // Neutron velocity in LAB @@ -727,9 +732,9 @@ void elastic_scatter(int i_nuclide, const Reaction& rx, double kT, // Sample velocity of target nucleus Direction v_t {}; - if (!p.neutron_xs_[i_nuclide].use_ptable) { - v_t = sample_target_velocity(*nuc, p.E_, p.u(), v_n, - p.neutron_xs_[i_nuclide].elastic, kT, p.current_seed()); + if (!p.neutron_xs(i_nuclide).use_ptable) { + v_t = sample_target_velocity(*nuc, p.E(), p.u(), v_n, + p.neutron_xs(i_nuclide).elastic, kT, p.current_seed()); } // Velocity of center-of-mass @@ -747,7 +752,7 @@ void elastic_scatter(int i_nuclide, const Reaction& rx, double kT, auto& d = rx.products_[0].distribution_[0]; auto d_ = dynamic_cast(d.get()); if (!d_->angle().empty()) { - mu_cm = d_->angle().sample(p.E_, p.current_seed()); + mu_cm = d_->angle().sample(p.E(), p.current_seed()); } else { mu_cm = uniform_distribution(-1., 1., p.current_seed()); } @@ -763,12 +768,12 @@ void elastic_scatter(int i_nuclide, const Reaction& rx, double kT, // Transform back to LAB frame v_n += v_cm; - p.E_ = v_n.dot(v_n); - vel = std::sqrt(p.E_); + p.E() = v_n.dot(v_n); + vel = std::sqrt(p.E()); // compute cosine of scattering angle in LAB frame by taking dot product of // neutron's pre- and post-collision angle - p.mu_ = p.u().dot(v_n) / vel; + p.mu() = p.u().dot(v_n) / vel; // Set energy and direction of particle in LAB frame p.u() = v_n / vel; @@ -776,22 +781,24 @@ void elastic_scatter(int i_nuclide, const Reaction& rx, double kT, // Because of floating-point roundoff, it may be possible for mu_lab to be // outside of the range [-1,1). In these cases, we just set mu_lab to exactly // -1 or 1 - if (std::abs(p.mu_) > 1.0) p.mu_ = std::copysign(1.0, p.mu_); + if (std::abs(p.mu()) > 1.0) + p.mu() = std::copysign(1.0, p.mu()); } void sab_scatter(int i_nuclide, int i_sab, Particle& p) { // Determine temperature index - const auto& micro {p.neutron_xs_[i_nuclide]}; + const auto& micro {p.neutron_xs(i_nuclide)}; int i_temp = micro.index_temp_sab; // Sample energy and angle double E_out; - data::thermal_scatt[i_sab]->data_[i_temp].sample(micro, p.E_, &E_out, &p.mu_, p.current_seed()); + data::thermal_scatt[i_sab]->data_[i_temp].sample( + micro, p.E(), &E_out, &p.mu(), p.current_seed()); // Set energy to outgoing, change direction of particle - p.E_ = E_out; - p.u() = rotate_angle(p.u(), p.mu_, nullptr, p.current_seed()); + p.E() = E_out; + p.u() = rotate_angle(p.u(), p.mu(), nullptr, p.current_seed()); } Direction sample_target_velocity(const Nuclide& nuc, double E, Direction u, @@ -996,7 +1003,8 @@ sample_cxs_target_velocity(double awr, double E, Direction u, double kT, uint64_ return vt * rotate_angle(u, mu, nullptr, seed); } -void sample_fission_neutron(int i_nuclide, const Reaction& rx, double E_in, Particle::Bank* site, uint64_t* seed) +void sample_fission_neutron(int i_nuclide, const Reaction& rx, double E_in, + SourceSite* site, uint64_t* seed) { // Determine total nu, delayed nu, and delayed neutron fraction const auto& nuc {data::nuclides[i_nuclide]}; @@ -1044,7 +1052,7 @@ void sample_fission_neutron(int i_nuclide, const Reaction& rx, double E_in, Part rx.products_[site->delayed_group].sample(E_in, site->E, mu, seed); // resample if energy is greater than maximum neutron energy - constexpr int neutron = static_cast(Particle::Type::neutron); + constexpr int neutron = static_cast(ParticleType::neutron); if (site->E < data::energy_max[neutron]) break; // check for large number of resamples @@ -1065,7 +1073,7 @@ void sample_fission_neutron(int i_nuclide, const Reaction& rx, double E_in, Part void inelastic_scatter(const Nuclide& nuc, const Reaction& rx, Particle& p) { // copy energy of neutron - double E_in = p.E_; + double E_in = p.E(); // sample outgoing energy and scattering cosine double E; @@ -1092,8 +1100,8 @@ void inelastic_scatter(const Nuclide& nuc, const Reaction& rx, Particle& p) if (std::abs(mu) > 1.0) mu = std::copysign(1.0, mu); // Set outgoing energy and scattering angle - p.E_ = E; - p.mu_ = mu; + p.E() = E; + p.mu() = mu; // change direction of particle p.u() = rotate_angle(p.u(), mu, nullptr, p.current_seed()); @@ -1103,19 +1111,19 @@ void inelastic_scatter(const Nuclide& nuc, const Reaction& rx, Particle& p) if (std::floor(yield) == yield) { // If yield is integral, create exactly that many secondary particles for (int i = 0; i < static_cast(std::round(yield)) - 1; ++i) { - p.create_secondary(p.wgt_, p.u(), p.E_, Particle::Type::neutron); + p.create_secondary(p.wgt(), p.u(), p.E(), ParticleType::neutron); } } else { // Otherwise, change weight of particle based on yield - p.wgt_ *= yield; + p.wgt() *= yield; } } void sample_secondary_photons(Particle& p, int i_nuclide) { // Sample the number of photons produced - double y_t = p.neutron_xs_[i_nuclide].photon_prod / - p.neutron_xs_[i_nuclide].total; + double y_t = + p.neutron_xs(i_nuclide).photon_prod / p.neutron_xs(i_nuclide).total; int y = static_cast(y_t); if (prn(p.current_seed()) <= y_t - y) ++y; @@ -1130,7 +1138,7 @@ void sample_secondary_photons(Particle& p, int i_nuclide) auto& rx = data::nuclides[i_nuclide]->reactions_[i_rx]; double E; double mu; - rx->products_[i_product].sample(p.E_, E, mu, p.current_seed()); + rx->products_[i_product].sample(p.E(), E, mu, p.current_seed()); // Sample the new direction Direction u = rotate_angle(p.u(), mu, nullptr, p.current_seed()); @@ -1142,14 +1150,13 @@ void sample_secondary_photons(Particle& p, int i_nuclide) // calculations", Proc. PHYSOR, Cambridge, UK, Mar 29-Apr 2, 2020. double wgt; if (settings::run_mode == RunMode::EIGENVALUE && !is_fission(rx->mt_)) { - wgt = simulation::keff * p.wgt_; + wgt = simulation::keff * p.wgt(); } else { - wgt = p.wgt_; + wgt = p.wgt(); } // Create the secondary photon - p.create_secondary(wgt, u, E, Particle::Type::photon); - + p.create_secondary(wgt, u, E, ParticleType::photon); } } diff --git a/src/physics_common.cpp b/src/physics_common.cpp index 32e00056d..2a63b188d 100644 --- a/src/physics_common.cpp +++ b/src/physics_common.cpp @@ -11,14 +11,14 @@ namespace openmc { void russian_roulette(Particle& p) { - if (p.wgt_ < settings::weight_cutoff) { - if (prn(p.current_seed()) < p.wgt_ / settings::weight_survive) { - p.wgt_ = settings::weight_survive; - p.wgt_last_ = p.wgt_; + if (p.wgt() < settings::weight_cutoff) { + if (prn(p.current_seed()) < p.wgt() / settings::weight_survive) { + p.wgt() = settings::weight_survive; + p.wgt_last() = p.wgt(); } else { - p.wgt_ = 0.; - p.wgt_last_ = 0.; - p.alive_ = false; + p.wgt() = 0.; + p.wgt_last() = 0.; + p.alive() = false; } } } diff --git a/src/physics_mg.cpp b/src/physics_mg.cpp index b2dd4078e..06ed845de 100644 --- a/src/physics_mg.cpp +++ b/src/physics_mg.cpp @@ -13,6 +13,7 @@ #include "openmc/math_functions.h" #include "openmc/message_passing.h" #include "openmc/mgxs_interface.h" +#include "openmc/particle.h" #include "openmc/physics_common.h" #include "openmc/random_lcg.h" #include "openmc/settings.h" @@ -25,14 +26,14 @@ void collision_mg(Particle& p) { // Add to the collision counter for the particle - p.n_collision_++; + p.n_collision()++; // Sample the reaction type sample_reaction(p); // Display information about collision - if ((settings::verbosity >= 10) || p.trace_) { - write_message(fmt::format(" Energy Group = {}", p.g_), 1); + if ((settings::verbosity >= 10) || p.trace()) { + write_message(fmt::format(" Energy Group = {}", p.g()), 1); } } @@ -44,7 +45,7 @@ sample_reaction(Particle& p) // change when sampling fission sites. The following block handles all // absorption (including fission) - if (model::materials[p.material_]->fissionable_) { + if (model::materials[p.material()]->fissionable_) { if (settings::run_mode == RunMode::EIGENVALUE || (settings::run_mode == RunMode::FIXED_SOURCE && settings::create_fission_neutrons)) { @@ -54,12 +55,13 @@ sample_reaction(Particle& p) // If survival biasing is being used, the following subroutine adjusts the // weight of the particle. Otherwise, it checks to see if absorption occurs. - if (p.macro_xs_.absorption > 0.) { + if (p.macro_xs().absorption > 0.) { absorption(p); } else { - p.wgt_absorb_ = 0.; + p.wgt_absorb() = 0.; } - if (!p.alive_) return; + if (!p.alive()) + return; // Sample a scattering event to determine the energy of the exiting neutron scatter(p); @@ -67,24 +69,25 @@ sample_reaction(Particle& p) // Play Russian roulette if survival biasing is turned on if (settings::survival_biasing) { russian_roulette(p); - if (!p.alive_) return; + if (!p.alive()) + return; } } void scatter(Particle& p) { - data::mg.macro_xs_[p.material_].sample_scatter(p.g_last_, p.g_, p.mu_, - p.wgt_, p.current_seed()); + data::mg.macro_xs_[p.material()].sample_scatter( + p.g_last(), p.g(), p.mu(), p.wgt(), p.current_seed()); // Rotate the angle - p.u() = rotate_angle(p.u(), p.mu_, nullptr, p.current_seed()); + p.u() = rotate_angle(p.u(), p.mu(), nullptr, p.current_seed()); // Update energy value for downstream compatability (in tallying) - p.E_ = data::mg.energy_bin_avg_[p.g_]; + p.E() = data::mg.energy_bin_avg_[p.g()]; // Set event component - p.event_ = TallyEvent::SCATTER; + p.event() = TallyEvent::SCATTER; } void @@ -95,8 +98,8 @@ create_fission_sites(Particle& p) double weight = settings::ufs_on ? ufs_get_weight(p) : 1.0; // Determine the expected number of neutrons produced - double nu_t = p.wgt_ / simulation::keff * weight * - p.macro_xs_.nu_fission / p.macro_xs_.total; + double nu_t = p.wgt() / simulation::keff * weight * p.macro_xs().nu_fission / + p.macro_xs().total; // Sample the number of neutrons produced int nu = static_cast(nu_t); @@ -113,9 +116,9 @@ create_fission_sites(Particle& p) double nu_d[MAX_DELAYED_GROUPS] = {0.}; // Clear out particle's nu fission bank - p.nu_bank_.clear(); + p.nu_bank().clear(); - p.fission_ = true; + p.fission() = true; int skipped = 0; // Determine whether to place fission sites into the shared fission bank @@ -124,12 +127,12 @@ create_fission_sites(Particle& p) for (int i = 0; i < nu; ++i) { // Initialize fission site object with particle data - Particle::Bank site; + SourceSite site; site.r = p.r(); - site.particle = Particle::Type::neutron; + site.particle = ParticleType::neutron; site.wgt = 1. / weight; - site.parent_id = p.id_; - site.progeny_id = p.n_progeny_++; + site.parent_id = p.id(); + site.progeny_id = p.n_progeny()++; // Sample the cosine of the angle, assuming fission neutrons are emitted // isotropically @@ -144,8 +147,8 @@ create_fission_sites(Particle& p) // Sample secondary energy distribution for the fission reaction int dg; int gout; - data::mg.macro_xs_[p.material_].sample_fission_energy(p.g_, dg, gout, - p.current_seed()); + data::mg.macro_xs_[p.material()].sample_fission_energy( + p.g(), dg, gout, p.current_seed()); // Store the energy and delayed groups on the fission bank site.E = gout; @@ -164,20 +167,20 @@ create_fission_sites(Particle& p) break; } } else { - p.secondary_bank_.push_back(site); + p.secondary_bank().push_back(site); } // Set the delayed group on the particle as well - p.delayed_group_ = dg + 1; + p.delayed_group() = dg + 1; // Increment the number of neutrons born delayed - if (p.delayed_group_ > 0) { + if (p.delayed_group() > 0) { nu_d[dg]++; } // Write fission particles to nuBank - p.nu_bank_.emplace_back(); - Particle::NuBank* nu_bank_entry = &p.nu_bank_.back(); + p.nu_bank().emplace_back(); + NuBank* nu_bank_entry = &p.nu_bank().back(); nu_bank_entry->wgt = site.wgt; nu_bank_entry->E = site.E; nu_bank_entry->delayed_group = site.delayed_group; @@ -186,7 +189,7 @@ create_fission_sites(Particle& p) // If shared fission bank was full, and no fissions could be added, // set the particle fission flag to false. if (nu == skipped) { - p.fission_ = false; + p.fission() = false; return; } @@ -195,10 +198,10 @@ create_fission_sites(Particle& p) nu -= skipped; // Store the total weight banked for analog fission tallies - p.n_bank_ = nu; - p.wgt_bank_ = nu / weight; + p.n_bank() = nu; + p.wgt_bank() = nu / weight; for (size_t d = 0; d < MAX_DELAYED_GROUPS; d++) { - p.n_delayed_bank_[d] = nu_d[d]; + p.n_delayed_bank(d) = nu_d[d]; } } @@ -207,23 +210,22 @@ absorption(Particle& p) { if (settings::survival_biasing) { // Determine weight absorbed in survival biasing - p.wgt_absorb_ = p.wgt_ * p.macro_xs_.absorption / p.macro_xs_.total; + p.wgt_absorb() = p.wgt() * p.macro_xs().absorption / p.macro_xs().total; // Adjust weight of particle by the probability of absorption - p.wgt_ -= p.wgt_absorb_; - p.wgt_last_ = p.wgt_; + p.wgt() -= p.wgt_absorb(); + p.wgt_last() = p.wgt(); // Score implicit absorpion estimate of keff - p.keff_tally_absorption_ += p.wgt_absorb_ * p.macro_xs_.nu_fission / - p.macro_xs_.absorption; + p.keff_tally_absorption() += + p.wgt_absorb() * p.macro_xs().nu_fission / p.macro_xs().absorption; } else { - if (p.macro_xs_.absorption > prn(p.current_seed()) * p.macro_xs_.total) { - p.keff_tally_absorption_ += p.wgt_ * p.macro_xs_.nu_fission / - p.macro_xs_.absorption; - p.alive_ = false; - p.event_ = TallyEvent::ABSORB; + if (p.macro_xs().absorption > prn(p.current_seed()) * p.macro_xs().total) { + p.keff_tally_absorption() += + p.wgt() * p.macro_xs().nu_fission / p.macro_xs().absorption; + p.alive() = false; + p.event() = TallyEvent::ABSORB; } - } } diff --git a/src/plot.cpp b/src/plot.cpp index c7739c2c6..615701341 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -42,19 +42,19 @@ IdData::IdData(size_t h_res, size_t v_res) void IdData::set_value(size_t y, size_t x, const Particle& p, int level) { // set cell data - if (p.n_coord_ <= level) { + if (p.n_coord() <= level) { data_(y, x, 0) = NOT_FOUND; } else { - data_(y, x, 0) = model::cells.at(p.coord_.at(level).cell)->id_; + data_(y, x, 0) = model::cells.at(p.coord(level).cell)->id_; } // set material data - Cell* c = model::cells.at(p.coord_.at(p.n_coord_ - 1).cell).get(); - if (p.material_ == MATERIAL_VOID) { + Cell* c = model::cells.at(p.coord(p.n_coord() - 1).cell).get(); + if (p.material() == MATERIAL_VOID) { data_(y, x, 1) = MATERIAL_VOID; return; } else if (c->type_ == Fill::MATERIAL) { - Material* m = model::materials.at(p.material_).get(); + Material* m = model::materials.at(p.material()).get(); data_(y, x, 1) = m->id_; } } @@ -69,10 +69,10 @@ PropertyData::PropertyData(size_t h_res, size_t v_res) void PropertyData::set_value(size_t y, size_t x, const Particle& p, int level) { - Cell* c = model::cells.at(p.coord_.at(p.n_coord_ - 1).cell).get(); - data_(y,x,0) = (p.sqrtkT_ * p.sqrtkT_) / K_BOLTZMANN; - if (c->type_ != Fill::UNIVERSE && p.material_ != MATERIAL_VOID) { - Material* m = model::materials.at(p.material_).get(); + Cell* c = model::cells.at(p.coord(p.n_coord() - 1).cell).get(); + data_(y, x, 0) = (p.sqrtkT() * p.sqrtkT()) / K_BOLTZMANN; + if (c->type_ != Fill::UNIVERSE && p.material() != MATERIAL_VOID) { + Material* m = model::materials.at(p.material()).get(); data_(y,x,1) = m->density_gpcc_; } } @@ -88,7 +88,7 @@ void PropertyData::set_overlap(size_t y, size_t x) { namespace model { std::unordered_map plot_map; -std::vector plots; +vector plots; uint64_t plotter_seed = 1; } // namespace model @@ -244,7 +244,7 @@ Plot::set_output_path(pugi::xml_node plot_node) path_plot_ = filename; // Copy plot pixel size - std::vector pxls = get_node_array(plot_node, "pixels"); + vector pxls = get_node_array(plot_node, "pixels"); if (PlotType::slice == type_) { if (pxls.size() == 2) { pixels_[0] = pxls[0]; @@ -268,7 +268,7 @@ Plot::set_bg_color(pugi::xml_node plot_node) { // Copy plot background color if (check_for_node(plot_node, "background")) { - std::vector bg_rgb = get_node_array(plot_node, "background"); + vector bg_rgb = get_node_array(plot_node, "background"); if (PlotType::voxel == type_) { if (mpi::master) { warning(fmt::format("Background color ignored in voxel plot {}", id_)); @@ -320,7 +320,7 @@ void Plot::set_width(pugi::xml_node plot_node) { // Copy plotting width - std::vector pl_width = get_node_array(plot_node, "width"); + vector pl_width = get_node_array(plot_node, "width"); if (PlotType::slice == type_) { if (pl_width.size() == 2) { width_.x = pl_width[0]; @@ -391,7 +391,7 @@ Plot::set_user_colors(pugi::xml_node plot_node) for (auto cn : plot_node.children("color")) { // Make sure 3 values are specified for RGB - std::vector user_rgb = get_node_array(cn, "rgb"); + vector user_rgb = get_node_array(cn, "rgb"); if (user_rgb.size() != 3) { fatal_error(fmt::format("Bad RGB in plot {}", id_)); } @@ -461,7 +461,7 @@ Plot::set_meshlines(pugi::xml_node plot_node) // Check for color if (check_for_node(meshlines_node, "color")) { // Check and make sure 3 values are specified for RGB - std::vector ml_rgb = get_node_array(meshlines_node, "color"); + vector ml_rgb = get_node_array(meshlines_node, "color"); if (ml_rgb.size() != 3) { fatal_error(fmt::format("Bad RGB for meshlines color in plot {}", id_)); } @@ -544,7 +544,7 @@ Plot::set_mask(pugi::xml_node plot_node) pugi::xml_node mask_node = mask_nodes[0].node(); // Determine how many components there are and allocate - std::vector iarray = get_node_array(mask_node, "components"); + vector iarray = get_node_array(mask_node, "components"); if (iarray.size() == 0) { fatal_error(fmt::format("Missing in mask of plot {}", id_)); } @@ -575,7 +575,7 @@ Plot::set_mask(pugi::xml_node plot_node) for (int j = 0; j < colors_.size(); j++) { if (std::find(iarray.begin(), iarray.end(), j) == iarray.end()) { if (check_for_node(mask_node, "background")) { - std::vector bg_rgb = get_node_array(mask_node, "background"); + vector bg_rgb = get_node_array(mask_node, "background"); colors_[j] = bg_rgb; } else { colors_[j] = WHITE; @@ -599,7 +599,7 @@ void Plot::set_overlap_color(pugi::xml_node plot_node) { warning(fmt::format( "Overlap color specified in plot {} but overlaps won't be shown.", id_)); } - std::vector olap_clr = get_node_array(plot_node, "overlap_color"); + vector olap_clr = get_node_array(plot_node, "overlap_color"); if (olap_clr.size() == 3) { overlap_color_ = olap_clr; } else { @@ -778,7 +778,7 @@ void draw_mesh_lines(Plot const& pl, ImageData& data) void create_voxel(Plot const& pl) { // compute voxel widths in each direction - std::array vox; + array vox; vox[0] = pl.width_[0]/(double)pl.pixels_[0]; vox[1] = pl.width_[1]/(double)pl.pixels_[1]; vox[2] = pl.width_[2]/(double)pl.pixels_[2]; @@ -803,7 +803,7 @@ void create_voxel(Plot const& pl) // Write current date and time write_attribute(file_id, "date_and_time", time_stamp().c_str()); - std::array pixels; + array pixels; std::copy(pl.pixels_.begin(), pl.pixels_.end(), pixels.begin()); write_attribute(file_id, "num_voxels", pixels); write_attribute(file_id, "voxel_width", vox); diff --git a/src/position.cpp b/src/position.cpp index d29e8d81c..46611df99 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -84,8 +84,7 @@ Position::operator-() const return {-x, -y, -z}; } -Position -Position::rotate(const std::vector& rotation) const +Position Position::rotate(const vector& rotation) const { return { x*rotation[0] + y*rotation[1] + z*rotation[2], diff --git a/src/reaction.cpp b/src/reaction.cpp index 303bd3393..ddb82a224 100644 --- a/src/reaction.cpp +++ b/src/reaction.cpp @@ -19,7 +19,7 @@ namespace openmc { // Reaction implementation //============================================================================== -Reaction::Reaction(hid_t group, const std::vector& temperatures) +Reaction::Reaction(hid_t group, const vector& temperatures) { read_attribute(group, "Q_value", q_value_); read_attribute(group, "mt", mt_); @@ -65,9 +65,9 @@ Reaction::Reaction(hid_t group, const std::vector& temperatures) } } -double -Reaction::collapse_rate(gsl::index i_temp, gsl::span energy, - gsl::span flux, const std::vector& grid) const +double Reaction::collapse_rate(gsl::index i_temp, + gsl::span energy, gsl::span flux, + const vector& grid) const { // Find index corresponding to first energy const auto& xs = xs_[i_temp].value; diff --git a/src/reaction_product.cpp b/src/reaction_product.cpp index 6a3b231cc..f73f63335 100644 --- a/src/reaction_product.cpp +++ b/src/reaction_product.cpp @@ -1,6 +1,5 @@ #include "openmc/reaction_product.h" -#include // for unique_ptr #include // for string #include @@ -8,6 +7,7 @@ #include "openmc/endf.h" #include "openmc/error.h" #include "openmc/hdf5_interface.h" +#include "openmc/memory.h" #include "openmc/particle.h" #include "openmc/random_lcg.h" #include "openmc/secondary_correlated.h" @@ -42,7 +42,7 @@ ReactionProduct::ReactionProduct(hid_t group) if (emission_mode_ == EmissionMode::delayed) { if (attribute_exists(group, "decay_rate")) { read_attribute(group, "decay_rate", decay_rate_); - } else if (particle_ == Particle::Type::neutron) { + } else if (particle_ == ParticleType::neutron) { warning(fmt::format("Decay rate doesn't exist for delayed neutron " "emission ({}).", object_name(group))); } @@ -69,13 +69,13 @@ ReactionProduct::ReactionProduct(hid_t group) // Determine distribution type and read data read_attribute(dgroup, "type", temp); if (temp == "uncorrelated") { - distribution_.push_back(std::make_unique(dgroup)); + distribution_.push_back(make_unique(dgroup)); } else if (temp == "correlated") { - distribution_.push_back(std::make_unique(dgroup)); + distribution_.push_back(make_unique(dgroup)); } else if (temp == "nbody") { - distribution_.push_back(std::make_unique(dgroup)); + distribution_.push_back(make_unique(dgroup)); } else if (temp == "kalbach-mann") { - distribution_.push_back(std::make_unique(dgroup)); + distribution_.push_back(make_unique(dgroup)); } close_group(dgroup); diff --git a/src/scattdata.cpp b/src/scattdata.cpp index 6c20b8e37..a0341b153 100644 --- a/src/scattdata.cpp +++ b/src/scattdata.cpp @@ -70,12 +70,10 @@ ScattData::base_init(int order, const xt::xtensor& in_gmin, //============================================================================== -void -ScattData::base_combine(size_t max_order, size_t order_dim, - const std::vector& those_scatts, - const std::vector& scalars, xt::xtensor& in_gmin, - xt::xtensor& in_gmax, double_2dvec& sparse_mult, - double_3dvec& sparse_scatter) +void ScattData::base_combine(size_t max_order, size_t order_dim, + const vector& those_scatts, const vector& scalars, + xt::xtensor& in_gmin, xt::xtensor& in_gmax, + double_2dvec& sparse_mult, double_3dvec& sparse_scatter) { size_t groups = those_scatts[0] -> energy.size(); @@ -378,9 +376,8 @@ ScattDataLegendre::sample(int gin, int& gout, double& mu, double& wgt, //============================================================================== -void -ScattDataLegendre::combine(const std::vector& those_scatts, - const std::vector& scalars) +void ScattDataLegendre::combine( + const vector& those_scatts, const vector& scalars) { // Find the max order in the data set and make sure we can combine the sets size_t max_order = 0; @@ -595,9 +592,8 @@ ScattDataHistogram::get_matrix(size_t max_order) //============================================================================== -void -ScattDataHistogram::combine(const std::vector& those_scatts, - const std::vector& scalars) +void ScattDataHistogram::combine( + const vector& those_scatts, const vector& scalars) { // Find the max order in the data set and make sure we can combine the sets size_t max_order = those_scatts[0]->get_order(); @@ -814,9 +810,8 @@ ScattDataTabular::get_matrix(size_t max_order) //============================================================================== -void -ScattDataTabular::combine(const std::vector& those_scatts, - const std::vector& scalars) +void ScattDataTabular::combine( + const vector& those_scatts, const vector& scalars) { // Find the max order in the data set and make sure we can combine the sets size_t max_order = those_scatts[0]->get_order(); diff --git a/src/secondary_correlated.cpp b/src/secondary_correlated.cpp index f79104efb..0e4891dd3 100644 --- a/src/secondary_correlated.cpp +++ b/src/secondary_correlated.cpp @@ -43,9 +43,9 @@ CorrelatedAngleEnergy::CorrelatedAngleEnergy(hid_t group) // Get outgoing energy distribution data dset = open_dataset(group, "energy_out"); - std::vector offsets; - std::vector interp; - std::vector n_discrete; + vector offsets; + vector interp; + vector n_discrete; read_attribute(dset, "offsets", offsets); read_attribute(dset, "interpolation", interp); read_attribute(dset, "n_discrete_lines", n_discrete); @@ -136,9 +136,9 @@ CorrelatedAngleEnergy::CorrelatedAngleEnergy(hid_t group) auto ps = xt::view(mu, 1, xt::range(offset_mu, offset_mu + m)); auto cs = xt::view(mu, 2, xt::range(offset_mu, offset_mu + m)); - std::vector x {xs.begin(), xs.end()}; - std::vector p {ps.begin(), ps.end()}; - std::vector c {cs.begin(), cs.end()}; + vector x {xs.begin(), xs.end()}; + vector p {ps.begin(), ps.end()}; + vector c {cs.begin(), cs.end()}; // To get answers that match ACE data, for now we still use the tabulated // CDF values that were passed through to the HDF5 library. At a later diff --git a/src/secondary_kalbach.cpp b/src/secondary_kalbach.cpp index a2bb343f5..637650b43 100644 --- a/src/secondary_kalbach.cpp +++ b/src/secondary_kalbach.cpp @@ -4,7 +4,6 @@ #include // for log, sqrt, sinh #include // for size_t #include // for back_inserter -#include #include "xtensor/xarray.hpp" #include "xtensor/xview.hpp" @@ -13,6 +12,7 @@ #include "openmc/random_dist.h" #include "openmc/random_lcg.h" #include "openmc/search.h" +#include "openmc/vector.h" namespace openmc { @@ -44,9 +44,9 @@ KalbachMann::KalbachMann(hid_t group) // Get outgoing energy distribution data dset = open_dataset(group, "distribution"); - std::vector offsets; - std::vector interp; - std::vector n_discrete; + vector offsets; + vector interp; + vector n_discrete; read_attribute(dset, "offsets", offsets); read_attribute(dset, "interpolation", interp); read_attribute(dset, "n_discrete_lines", n_discrete); diff --git a/src/secondary_thermal.cpp b/src/secondary_thermal.cpp index f61922a82..dd86c0d07 100644 --- a/src/secondary_thermal.cpp +++ b/src/secondary_thermal.cpp @@ -11,8 +11,8 @@ namespace openmc { // Helper function to get index on incident energy grid -void -get_energy_index(const std::vector& energies, double E, int& i, double& f) +void get_energy_index( + const vector& energies, double E, int& i, double& f) { // Get index and interpolation factor for elastic grid i = 0; @@ -81,9 +81,9 @@ IncoherentElasticAE::sample(double E_in, double& E_out, double& mu, // IncoherentElasticAEDiscrete implementation //============================================================================== -IncoherentElasticAEDiscrete::IncoherentElasticAEDiscrete(hid_t group, - const std::vector& energy) - : energy_{energy} +IncoherentElasticAEDiscrete::IncoherentElasticAEDiscrete( + hid_t group, const vector& energy) + : energy_ {energy} { read_dataset(group, "mu_out", mu_out_); } @@ -135,9 +135,9 @@ IncoherentElasticAEDiscrete::sample(double E_in, double& E_out, double& mu, // IncoherentInelasticAEDiscrete implementation //============================================================================== -IncoherentInelasticAEDiscrete::IncoherentInelasticAEDiscrete(hid_t group, - const std::vector& energy) - : energy_{energy} +IncoherentInelasticAEDiscrete::IncoherentInelasticAEDiscrete( + hid_t group, const vector& energy) + : energy_ {energy} { read_dataset(group, "energy_out", energy_out_); read_dataset(group, "mu_out", mu_out_); diff --git a/src/secondary_uncorrelated.cpp b/src/secondary_uncorrelated.cpp index a4f188674..39b3eb4ed 100644 --- a/src/secondary_uncorrelated.cpp +++ b/src/secondary_uncorrelated.cpp @@ -29,7 +29,7 @@ UncorrelatedAngleEnergy::UncorrelatedAngleEnergy(hid_t group) std::string type; read_attribute(energy_group, "type", type); - using UPtrEDist = std::unique_ptr; + using UPtrEDist = unique_ptr; if (type == "discrete_photon") { energy_ = UPtrEDist{new DiscretePhoton{energy_group}}; } else if (type == "level") { diff --git a/src/settings.cpp b/src/settings.cpp index 41b18942c..2617da978 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -87,7 +87,7 @@ int64_t n_particles {-1}; int64_t max_particles_in_flight {100000}; ElectronTreatment electron_treatment {ElectronTreatment::TTB}; -std::array energy_cutoff {0.0, 1000.0, 0.0, 0.0}; +array energy_cutoff {0.0, 1000.0, 0.0, 0.0}; int legendre_to_tabular_points {C_NONE}; int max_order {0}; int n_log_bins {8000}; @@ -96,7 +96,7 @@ int n_max_batches; ResScatMethod res_scat_method {ResScatMethod::rvs}; double res_scat_energy_min {0.01}; double res_scat_energy_max {1000.0}; -std::vector res_scat_nuclides; +vector res_scat_nuclides; RunMode run_mode {RunMode::UNSET}; std::unordered_set sourcepoint_batch; std::unordered_set statepoint_batch; @@ -105,11 +105,11 @@ int64_t max_surface_particles; TemperatureMethod temperature_method {TemperatureMethod::NEAREST}; double temperature_tolerance {10.0}; double temperature_default {293.6}; -std::array temperature_range {0.0, 0.0}; +array temperature_range {0.0, 0.0}; int trace_batch; int trace_gen; int64_t trace_particle; -std::vector> track_identifiers; +vector> track_identifiers; int trigger_batch_interval {1}; int verbosity {7}; double weight_cutoff {0.25}; @@ -425,7 +425,7 @@ void read_settings_xml() for (pugi::xml_node node : root.children("source")) { if (check_for_node(node, "file")) { auto path = get_node_value(node, "file", false, true); - model::external_sources.push_back(std::make_unique(path)); + model::external_sources.push_back(make_unique(path)); } else if (check_for_node(node, "library")) { // Get shared library path and parameters auto path = get_node_value(node, "library", false, true); @@ -435,9 +435,10 @@ void read_settings_xml() } // Create custom source - model::external_sources.push_back(std::make_unique(path, parameters)); + model::external_sources.push_back( + make_unique(path, parameters)); } else { - model::external_sources.push_back(std::make_unique(node)); + model::external_sources.push_back(make_unique(node)); } } @@ -452,16 +453,14 @@ void read_settings_xml() if (check_for_node(node_ssr, "path")) { path = get_node_value(node_ssr, "path", false, true); } - model::external_sources.push_back(std::make_unique(path)); + model::external_sources.push_back(make_unique(path)); } // If no source specified, default to isotropic point source at origin with Watt spectrum if (model::external_sources.empty()) { - model::external_sources.push_back(std::make_unique( - UPtrSpace{new SpatialPoint({0.0, 0.0, 0.0})}, - UPtrAngle{new Isotropic()}, - UPtrDist{new Watt(0.988e6, 2.249e-6)} - )); + model::external_sources.push_back(make_unique( + UPtrSpace {new SpatialPoint({0.0, 0.0, 0.0})}, + UPtrAngle {new Isotropic()}, UPtrDist {new Watt(0.988e6, 2.249e-6)})); } // Check if we want to write out source diff --git a/src/simulation.cpp b/src/simulation.cpp index 21630ad25..e6de68b7e 100644 --- a/src/simulation.cpp +++ b/src/simulation.cpp @@ -267,9 +267,8 @@ int64_t work_per_rank; const RegularMesh* entropy_mesh {nullptr}; const RegularMesh* ufs_mesh {nullptr}; -std::vector k_generation; -std::vector work_index; - +vector k_generation; +vector work_index; } // namespace simulation @@ -464,74 +463,61 @@ void initialize_history(Particle& p, int64_t index_source) auto site = sample_external_source(&seed); p.from_source(&site); } - p.current_work_ = index_source; + p.current_work() = index_source; // set identifier for particle - p.id_ = simulation::work_index[mpi::rank] + index_source; + p.id() = simulation::work_index[mpi::rank] + index_source; // set progeny count to zero - p.n_progeny_ = 0; + p.n_progeny() = 0; // Reset particle event counter - p.n_event_ = 0; + p.n_event() = 0; // set random number seed - int64_t particle_seed = (simulation::total_gen + overall_generation() - 1) - * settings::n_particles + p.id_; - init_particle_seeds(particle_seed, p.seeds_); + int64_t particle_seed = + (simulation::total_gen + overall_generation() - 1) * settings::n_particles + + p.id(); + init_particle_seeds(particle_seed, p.seeds()); // set particle trace - p.trace_ = false; + p.trace() = false; if (simulation::current_batch == settings::trace_batch && simulation::current_gen == settings::trace_gen && - p.id_ == settings::trace_particle) p.trace_ = true; + p.id() == settings::trace_particle) + p.trace() = true; // Set particle track. - p.write_track_ = false; + p.write_track() = false; if (settings::write_all_tracks) { - p.write_track_ = true; + p.write_track() = true; } else if (settings::track_identifiers.size() > 0) { for (const auto& t : settings::track_identifiers) { if (simulation::current_batch == t[0] && - simulation::current_gen == t[1] && - p.id_ == t[2]) { - p.write_track_ = true; + simulation::current_gen == t[1] && p.id() == t[2]) { + p.write_track() = true; break; } } } // Display message if high verbosity or trace is on - if (settings::verbosity >= 9 || p.trace_) { - write_message("Simulating Particle {}", p.id_); + if (settings::verbosity >= 9 || p.trace()) { + write_message("Simulating Particle {}", p.id()); } // Add paricle's starting weight to count for normalizing tallies later #pragma omp atomic - simulation::total_weight += p.wgt_; + simulation::total_weight += p.wgt(); - initialize_history_partial(p); -} - -void initialize_history_partial(Particle& p) -{ // Force calculation of cross-sections by setting last energy to zero if (settings::run_CE) { - for (auto& micro : p.neutron_xs_) micro.last_E = 0.0; + p.invalidate_neutron_xs(); } // Prepare to write out particle track. - if (p.write_track_) add_particle_track(p); - - // Every particle starts with no accumulated flux derivative. - if (!model::active_tallies.empty()) - { - p.flux_derivs_.resize(model::tally_derivs.size(), 0.0); - std::fill(p.flux_derivs_.begin(), p.flux_derivs_.end(), 0.0); - } - - // Allocate space for tally filter matches - p.filter_matches_.resize(model::tally_filters.size()); + if (p.write_track()) + add_particle_track(p); } int overall_generation() @@ -571,7 +557,7 @@ void initialize_data() data::energy_min = {0.0, 0.0}; for (const auto& nuc : data::nuclides) { if (nuc->grid_.size() >= 1) { - int neutron = static_cast(Particle::Type::neutron); + int neutron = static_cast(ParticleType::neutron); data::energy_min[neutron] = std::max(data::energy_min[neutron], nuc->grid_[0].energy.front()); data::energy_max[neutron] = std::min(data::energy_max[neutron], @@ -582,7 +568,7 @@ void initialize_data() if (settings::photon_transport) { for (const auto& elem : data::elements) { if (elem->energy_.size() >= 1) { - int photon = static_cast(Particle::Type::photon); + int photon = static_cast(ParticleType::photon); int n = elem->energy_.size(); data::energy_min[photon] = std::max(data::energy_min[photon], std::exp(elem->energy_(1))); @@ -595,7 +581,7 @@ void initialize_data() // Determine if minimum/maximum energy for bremsstrahlung is greater/less // than the current minimum/maximum if (data::ttb_e_grid.size() >= 1) { - int photon = static_cast(Particle::Type::photon); + int photon = static_cast(ParticleType::photon); int n_e = data::ttb_e_grid.size(); data::energy_min[photon] = std::max(data::energy_min[photon], std::exp(data::ttb_e_grid(1))); @@ -611,7 +597,7 @@ void initialize_data() // grid has not been allocated if (nuc->grid_.size() > 0) { double max_E = nuc->grid_[0].energy.back(); - int neutron = static_cast(Particle::Type::neutron); + int neutron = static_cast(ParticleType::neutron); if (max_E == data::energy_max[neutron]) { write_message(7, "Maximum neutron transport energy: {} eV for {}", data::energy_max[neutron], nuc->name_); @@ -628,7 +614,7 @@ void initialize_data() for (auto& nuc : data::nuclides) { nuc->init_grid(); } - int neutron = static_cast(Particle::Type::neutron); + int neutron = static_cast(ParticleType::neutron); simulation::log_spacing = std::log(data::energy_max[neutron] / data::energy_min[neutron]) / settings::n_log_bins; } @@ -678,13 +664,13 @@ void transport_history_based_single_particle(Particle& p) while (true) { p.event_calculate_xs(); p.event_advance(); - if (p.collision_distance_ > p.boundary_.distance) { + if (p.collision_distance() > p.boundary().distance) { p.event_cross_surface(); } else { p.event_collide(); } p.event_revive_from_secondary(); - if (!p.alive_) + if (!p.alive()) break; } p.event_death(); diff --git a/src/source.cpp b/src/source.cpp index 2bbe7c321..909e87125 100644 --- a/src/source.cpp +++ b/src/source.cpp @@ -5,7 +5,6 @@ #endif #include // for move -#include // for unique_ptr #ifdef HAS_DYNAMIC_LINKING #include // for dlopen, dlsym, dlclose, dlerror @@ -15,15 +14,16 @@ #include "xtensor/xadapt.hpp" #include "openmc/bank.h" +#include "openmc/capi.h" #include "openmc/cell.h" #include "openmc/error.h" #include "openmc/file_utils.h" #include "openmc/hdf5_interface.h" #include "openmc/material.h" +#include "openmc/memory.h" #include "openmc/message_passing.h" #include "openmc/mgxs_interface.h" #include "openmc/nuclide.h" -#include "openmc/capi.h" #include "openmc/random_lcg.h" #include "openmc/search.h" #include "openmc/settings.h" @@ -39,8 +39,7 @@ namespace openmc { namespace model { -std::vector> external_sources; - +vector> external_sources; } //============================================================================== @@ -56,9 +55,9 @@ IndependentSource::IndependentSource(pugi::xml_node node) if (check_for_node(node, "particle")) { auto temp_str = get_node_value(node, "particle", true, true); if (temp_str == "neutron") { - particle_ = Particle::Type::neutron; + particle_ = ParticleType::neutron; } else if (temp_str == "photon") { - particle_ = Particle::Type::photon; + particle_ = ParticleType::photon; settings::photon_transport = true; } else { fatal_error(std::string("Unknown source particle type: ") + temp_str); @@ -141,9 +140,9 @@ IndependentSource::IndependentSource(pugi::xml_node node) } } -Particle::Bank IndependentSource::sample(uint64_t* seed) const +SourceSite IndependentSource::sample(uint64_t* seed) const { - Particle::Bank site; + SourceSite site; // Set weight to one by default site.wgt = 1.0; @@ -263,7 +262,7 @@ FileSource::FileSource(std::string path) file_close(file_id); } -Particle::Bank FileSource::sample(uint64_t* seed) const +SourceSite FileSource::sample(uint64_t* seed) const { size_t i_site = sites_.size()*prn(seed); return sites_[i_site]; @@ -349,7 +348,7 @@ void initialize_source() } } -Particle::Bank sample_external_source(uint64_t* seed) +SourceSite sample_external_source(uint64_t* seed) { // Determine total source strength double total_strength = 0.0; @@ -368,7 +367,7 @@ Particle::Bank sample_external_source(uint64_t* seed) } // Sample source site from i-th source distribution - Particle::Bank site {model::external_sources[i]->sample(seed)}; + SourceSite site {model::external_sources[i]->sample(seed)}; // If running in MG, convert site.E to group if (!settings::run_CE) { diff --git a/src/state_point.cpp b/src/state_point.cpp index d1663c0b9..f98727a08 100644 --- a/src/state_point.cpp +++ b/src/state_point.cpp @@ -3,7 +3,6 @@ #include #include // for int64_t #include -#include #include #include "xtensor/xbuilder.hpp" // for empty_like @@ -27,6 +26,7 @@ #include "openmc/tallies/filter_mesh.h" #include "openmc/tallies/tally.h" #include "openmc/timer.h" +#include "openmc/vector.h" namespace openmc { @@ -141,7 +141,7 @@ openmc_statepoint_write(const char* filename, bool* write_source) write_attribute(filters_group, "n_filters", model::tally_filters.size()); if (!model::tally_filters.empty()) { // Write filter IDs - std::vector filter_ids; + vector filter_ids; filter_ids.reserve(model::tally_filters.size()); for (const auto& filt : model::tally_filters) filter_ids.push_back(filt->id()); @@ -161,7 +161,7 @@ openmc_statepoint_write(const char* filename, bool* write_source) write_attribute(tallies_group, "n_tallies", model::tallies.size()); if (!model::tallies.empty()) { // Write tally IDs - std::vector tally_ids; + vector tally_ids; tally_ids.reserve(model::tallies.size()); for (const auto& tally : model::tallies) tally_ids.push_back(tally->id_); @@ -195,7 +195,7 @@ openmc_statepoint_write(const char* filename, bool* write_source) // Write the ID of each filter attached to this tally write_dataset(tally_group, "n_filters", tally->filters().size()); if (!tally->filters().empty()) { - std::vector filter_ids; + vector filter_ids; filter_ids.reserve(tally->filters().size()); for (auto i_filt : tally->filters()) filter_ids.push_back(model::tally_filters[i_filt]->id()); @@ -203,7 +203,7 @@ openmc_statepoint_write(const char* filename, bool* write_source) } // Write the nuclides this tally scores - std::vector nuclides; + vector nuclides; for (auto i_nuclide : tally->nuclides_) { if (i_nuclide == -1) { nuclides.push_back("total"); @@ -221,7 +221,7 @@ openmc_statepoint_write(const char* filename, bool* write_source) model::tally_derivs[tally->deriv_].id); // Write the tally score bins - std::vector scores; + vector scores; for (auto sc : tally->scores_) scores.push_back(reaction_name(sc)); write_dataset(tally_group, "n_score_bins", scores.size()); write_dataset(tally_group, "score_bins", scores); @@ -351,7 +351,7 @@ void load_state_point() // Read revision number for state point file and make sure it matches with // current version - std::array array; + array array; read_attribute(file_id, "version", array); if (array != VERSION_STATEPOINT) { fatal_error("State point version does not match current version in OpenMC."); @@ -512,27 +512,29 @@ hid_t h5banktype() { // - openmc/statepoint.py // - docs/source/io_formats/statepoint.rst // - docs/source/io_formats/source.rst - hid_t banktype = H5Tcreate(H5T_COMPOUND, sizeof(struct Particle::Bank)); - H5Tinsert(banktype, "r", HOFFSET(Particle::Bank, r), postype); - H5Tinsert(banktype, "u", HOFFSET(Particle::Bank, u), postype); - H5Tinsert(banktype, "E", HOFFSET(Particle::Bank, E), H5T_NATIVE_DOUBLE); - H5Tinsert(banktype, "wgt", HOFFSET(Particle::Bank, wgt), H5T_NATIVE_DOUBLE); - H5Tinsert(banktype, "delayed_group", HOFFSET(Particle::Bank, delayed_group), H5T_NATIVE_INT); - H5Tinsert(banktype, "surf_id", HOFFSET(Particle::Bank, surf_id), H5T_NATIVE_INT); - H5Tinsert(banktype, "particle", HOFFSET(Particle::Bank, particle), H5T_NATIVE_INT); + hid_t banktype = H5Tcreate(H5T_COMPOUND, sizeof(struct SourceSite)); + H5Tinsert(banktype, "r", HOFFSET(SourceSite, r), postype); + H5Tinsert(banktype, "u", HOFFSET(SourceSite, u), postype); + H5Tinsert(banktype, "E", HOFFSET(SourceSite, E), H5T_NATIVE_DOUBLE); + H5Tinsert(banktype, "wgt", HOFFSET(SourceSite, wgt), H5T_NATIVE_DOUBLE); + H5Tinsert(banktype, "delayed_group", HOFFSET(SourceSite, delayed_group), + H5T_NATIVE_INT); + H5Tinsert(banktype, "surf_id", HOFFSET(SourceSite, surf_id), H5T_NATIVE_INT); + H5Tinsert( + banktype, "particle", HOFFSET(SourceSite, particle), H5T_NATIVE_INT); H5Tclose(postype); return banktype; } -std::vector calculate_surf_source_size() +vector calculate_surf_source_size() { - std::vector surf_source_index; + vector surf_source_index; surf_source_index.reserve(mpi::n_procs + 1); #ifdef OPENMC_MPI surf_source_index.resize(mpi::n_procs); - std::vector bank_size(mpi::n_procs); + vector bank_size(mpi::n_procs); // Populate the surf_source_index with cumulative sum of the number of // surface source banks per process @@ -594,10 +596,10 @@ write_source_bank(hid_t group_id, bool surf_source_bank) int64_t count_size = simulation::work_per_rank; // Set vectors for source bank and starting bank index of each process - std::vector* bank_index = &simulation::work_index; - std::vector* source_bank = &simulation::source_bank; - std::vector surf_source_index_vector; - std::vector surf_source_bank_vector; + vector* bank_index = &simulation::work_index; + vector* source_bank = &simulation::source_bank; + vector surf_source_index_vector; + vector surf_source_bank_vector; // Reset dataspace sizes and vectors for surface source bank if (surf_source_bank) { @@ -653,7 +655,7 @@ write_source_bank(hid_t group_id, bool surf_source_bank) // Save source bank sites since the array is overwritten below #ifdef OPENMC_MPI - std::vector temp_source {source_bank->begin(), source_bank->end()}; + vector temp_source {source_bank->begin(), source_bank->end()}; #endif for (int i = 0; i < mpi::n_procs; ++i) { @@ -664,7 +666,7 @@ write_source_bank(hid_t group_id, bool surf_source_bank) #ifdef OPENMC_MPI // Receive source sites from other processes if (i > 0) - MPI_Recv(source_bank->data(), count[0], mpi::bank, i, i, + MPI_Recv(source_bank->data(), count[0], mpi::source_site, i, i, mpi::intracomm, MPI_STATUS_IGNORE); #endif @@ -689,7 +691,7 @@ write_source_bank(hid_t group_id, bool surf_source_bank) #endif } else { #ifdef OPENMC_MPI - MPI_Send(source_bank->data(), count_size, mpi::bank, + MPI_Send(source_bank->data(), count_size, mpi::source_site, 0, mpi::rank, mpi::intracomm); #endif } @@ -710,7 +712,8 @@ std::string dtype_member_names(hid_t dtype_id) return names; } -void read_source_bank(hid_t group_id, std::vector& sites, bool distribute) +void read_source_bank( + hid_t group_id, vector& sites, bool distribute) { hid_t banktype = h5banktype(); @@ -774,7 +777,7 @@ void write_unstructured_mesh_results() { for (auto& tally : model::tallies) { - std::vector tally_scores; + vector tally_scores; for (auto filter_idx : tally->filters()) { auto& filter = model::tally_filters[filter_idx]; if (filter->type() != "mesh") continue; @@ -824,8 +827,8 @@ void write_unstructured_mesh_results() { int nuc_score_idx = score_idx + nuc_idx*tally->scores_.size(); // construct result vectors - std::vector mean_vec(umesh->n_bins()), - std_dev_vec(umesh->n_bins()); + vector mean_vec(umesh->n_bins()), + std_dev_vec(umesh->n_bins()); for (int j = 0; j < tally->results_.shape()[0]; j++) { // get the volume for this bin double volume = umesh->volume(j); diff --git a/src/string_utils.cpp b/src/string_utils.cpp index 614e38767..5ad977aab 100644 --- a/src/string_utils.cpp +++ b/src/string_utils.cpp @@ -46,9 +46,9 @@ int word_count(std::string const& str) return count; } -std::vector split(const std::string& in) +vector split(const std::string& in) { - std::vector out; + vector out; for (int i = 0; i < in.size(); ) { // Increment i until we find a non-whitespace character. diff --git a/src/summary.cpp b/src/summary.cpp index 1f5f7a097..3d2c6816b 100644 --- a/src/summary.cpp +++ b/src/summary.cpp @@ -47,9 +47,9 @@ void write_nuclides(hid_t file) { // Build vectors of nuclide names and awrs while only sorting nuclides from // macroscopics - std::vector nuc_names; - std::vector macro_names; - std::vector awrs; + vector nuc_names; + vector macro_names; + vector awrs; for (int i = 0; i < data::nuclides.size(); ++i) { if (settings::run_CE) { diff --git a/src/surface.cpp b/src/surface.cpp index 1f542e64e..76542fcd8 100644 --- a/src/surface.cpp +++ b/src/surface.cpp @@ -1,6 +1,5 @@ #include "openmc/surface.h" -#include #include #include #include @@ -8,15 +7,16 @@ #include #include +#include "openmc/array.h" #include "openmc/container_util.h" -#include "openmc/error.h" #include "openmc/dagmc.h" +#include "openmc/error.h" #include "openmc/hdf5_interface.h" +#include "openmc/math_functions.h" +#include "openmc/random_lcg.h" #include "openmc/settings.h" #include "openmc/string_utils.h" #include "openmc/xml_interface.h" -#include "openmc/random_lcg.h" -#include "openmc/math_functions.h" namespace openmc { @@ -26,7 +26,7 @@ namespace openmc { namespace model { std::unordered_map surface_map; - std::vector> surfaces; + vector> surfaces; } // namespace model //============================================================================== @@ -264,15 +264,15 @@ Direction DAGSurface::normal(Position r) const Direction DAGSurface::reflect(Position r, Direction u, Particle* p) const { Expects(p); - p->history_.reset_to_last_intersection(); + p->history().reset_to_last_intersection(); moab::ErrorCode rval; moab::EntityHandle surf = dagmc_ptr_->entity_by_index(2, dag_index_); double pnt[3] = {r.x, r.y, r.z}; double dir[3]; - rval = dagmc_ptr_->get_angle(surf, pnt, dir, &p->history_); + rval = dagmc_ptr_->get_angle(surf, pnt, dir, &p->history()); MB_CHK_ERR_CONT(rval); - p->last_dir_ = u.reflect(dir); - return p->last_dir_; + p->last_dir() = u.reflect(dir); + return p->last_dir(); } void DAGSurface::to_hdf5(hid_t group_id) const {} @@ -322,7 +322,7 @@ Direction SurfaceXPlane::normal(Position r) const void SurfaceXPlane::to_hdf5_inner(hid_t group_id) const { write_string(group_id, "type", "x-plane", false); - std::array coeffs {{x0_}}; + array coeffs {{x0_}}; write_dataset(group_id, "coefficients", coeffs); } @@ -364,7 +364,7 @@ Direction SurfaceYPlane::normal(Position r) const void SurfaceYPlane::to_hdf5_inner(hid_t group_id) const { write_string(group_id, "type", "y-plane", false); - std::array coeffs {{y0_}}; + array coeffs {{y0_}}; write_dataset(group_id, "coefficients", coeffs); } @@ -406,7 +406,7 @@ Direction SurfaceZPlane::normal(Position r) const void SurfaceZPlane::to_hdf5_inner(hid_t group_id) const { write_string(group_id, "type", "z-plane", false); - std::array coeffs {{z0_}}; + array coeffs {{z0_}}; write_dataset(group_id, "coefficients", coeffs); } @@ -459,7 +459,7 @@ SurfacePlane::normal(Position r) const void SurfacePlane::to_hdf5_inner(hid_t group_id) const { write_string(group_id, "type", "plane", false); - std::array coeffs {{A_, B_, C_, D_}}; + array coeffs {{A_, B_, C_, D_}}; write_dataset(group_id, "coefficients", coeffs); } @@ -567,7 +567,7 @@ Direction SurfaceXCylinder::normal(Position r) const void SurfaceXCylinder::to_hdf5_inner(hid_t group_id) const { write_string(group_id, "type", "x-cylinder", false); - std::array coeffs {{y0_, z0_, radius_}}; + array coeffs {{y0_, z0_, radius_}}; write_dataset(group_id, "coefficients", coeffs); } @@ -607,7 +607,7 @@ Direction SurfaceYCylinder::normal(Position r) const void SurfaceYCylinder::to_hdf5_inner(hid_t group_id) const { write_string(group_id, "type", "y-cylinder", false); - std::array coeffs {{x0_, z0_, radius_}}; + array coeffs {{x0_, z0_, radius_}}; write_dataset(group_id, "coefficients", coeffs); } @@ -648,7 +648,7 @@ Direction SurfaceZCylinder::normal(Position r) const void SurfaceZCylinder::to_hdf5_inner(hid_t group_id) const { write_string(group_id, "type", "z-cylinder", false); - std::array coeffs {{x0_, y0_, radius_}}; + array coeffs {{x0_, y0_, radius_}}; write_dataset(group_id, "coefficients", coeffs); } @@ -725,7 +725,7 @@ Direction SurfaceSphere::normal(Position r) const void SurfaceSphere::to_hdf5_inner(hid_t group_id) const { write_string(group_id, "type", "sphere", false); - std::array coeffs {{x0_, y0_, z0_, radius_}}; + array coeffs {{x0_, y0_, z0_, radius_}}; write_dataset(group_id, "coefficients", coeffs); } @@ -854,7 +854,7 @@ Direction SurfaceXCone::normal(Position r) const void SurfaceXCone::to_hdf5_inner(hid_t group_id) const { write_string(group_id, "type", "x-cone", false); - std::array coeffs {{x0_, y0_, z0_, radius_sq_}}; + array coeffs {{x0_, y0_, z0_, radius_sq_}}; write_dataset(group_id, "coefficients", coeffs); } @@ -887,7 +887,7 @@ Direction SurfaceYCone::normal(Position r) const void SurfaceYCone::to_hdf5_inner(hid_t group_id) const { write_string(group_id, "type", "y-cone", false); - std::array coeffs {{x0_, y0_, z0_, radius_sq_}}; + array coeffs {{x0_, y0_, z0_, radius_sq_}}; write_dataset(group_id, "coefficients", coeffs); } @@ -920,7 +920,7 @@ Direction SurfaceZCone::normal(Position r) const void SurfaceZCone::to_hdf5_inner(hid_t group_id) const { write_string(group_id, "type", "z-cone", false); - std::array coeffs {{x0_, y0_, z0_, radius_sq_}}; + array coeffs {{x0_, y0_, z0_, radius_sq_}}; write_dataset(group_id, "coefficients", coeffs); } @@ -1025,7 +1025,7 @@ SurfaceQuadric::normal(Position r) const void SurfaceQuadric::to_hdf5_inner(hid_t group_id) const { write_string(group_id, "type", "quadric", false); - std::array coeffs {{A_, B_, C_, D_, E_, F_, G_, H_, J_, K_}}; + array coeffs {{A_, B_, C_, D_, E_, F_, G_, H_, J_, K_}}; write_dataset(group_id, "coefficients", coeffs); } @@ -1054,40 +1054,40 @@ void read_surfaces(pugi::xml_node node) // Allocate and initialize the new surface if (surf_type == "x-plane") { - model::surfaces.push_back(std::make_unique(surf_node)); + model::surfaces.push_back(make_unique(surf_node)); } else if (surf_type == "y-plane") { - model::surfaces.push_back(std::make_unique(surf_node)); + model::surfaces.push_back(make_unique(surf_node)); } else if (surf_type == "z-plane") { - model::surfaces.push_back(std::make_unique(surf_node)); + model::surfaces.push_back(make_unique(surf_node)); } else if (surf_type == "plane") { - model::surfaces.push_back(std::make_unique(surf_node)); + model::surfaces.push_back(make_unique(surf_node)); } else if (surf_type == "x-cylinder") { - model::surfaces.push_back(std::make_unique(surf_node)); + model::surfaces.push_back(make_unique(surf_node)); } else if (surf_type == "y-cylinder") { - model::surfaces.push_back(std::make_unique(surf_node)); + model::surfaces.push_back(make_unique(surf_node)); } else if (surf_type == "z-cylinder") { - model::surfaces.push_back(std::make_unique(surf_node)); + model::surfaces.push_back(make_unique(surf_node)); } else if (surf_type == "sphere") { - model::surfaces.push_back(std::make_unique(surf_node)); + model::surfaces.push_back(make_unique(surf_node)); } else if (surf_type == "x-cone") { - model::surfaces.push_back(std::make_unique(surf_node)); + model::surfaces.push_back(make_unique(surf_node)); } else if (surf_type == "y-cone") { - model::surfaces.push_back(std::make_unique(surf_node)); + model::surfaces.push_back(make_unique(surf_node)); } else if (surf_type == "z-cone") { - model::surfaces.push_back(std::make_unique(surf_node)); + model::surfaces.push_back(make_unique(surf_node)); } else if (surf_type == "quadric") { - model::surfaces.push_back(std::make_unique(surf_node)); + model::surfaces.push_back(make_unique(surf_node)); } else { fatal_error(fmt::format("Invalid surface type, \"{}\"", surf_type)); diff --git a/src/tallies/derivative.cpp b/src/tallies/derivative.cpp index fecfa3f1c..41ea57370 100644 --- a/src/tallies/derivative.cpp +++ b/src/tallies/derivative.cpp @@ -9,7 +9,7 @@ #include -template class std::vector; +template class openmc::vector; namespace openmc { @@ -19,7 +19,7 @@ namespace openmc { namespace model { std::unordered_map tally_deriv_map; - std::vector tally_derivs; + vector tally_derivs; } //============================================================================== @@ -109,17 +109,17 @@ apply_derivative_to_score(const Particle& p, int i_tally, int i_nuclide, // perturbated variable. const auto& deriv {model::tally_derivs[tally.deriv_]}; - const auto flux_deriv = p.flux_derivs_[tally.deriv_]; + const auto flux_deriv = p.flux_derivs(tally.deriv_); // Handle special cases where we know that d_c/d_p must be zero. if (score_bin == SCORE_FLUX) { score *= flux_deriv; return; - } else if (p.material_ == MATERIAL_VOID) { + } else if (p.material() == MATERIAL_VOID) { score *= flux_deriv; return; } - const Material& material {*model::materials[p.material_]}; + const Material& material {*model::materials[p.material()]}; if (material.id_ != deriv.diff_material) { score *= flux_deriv; return; @@ -179,7 +179,7 @@ apply_derivative_to_score(const Particle& p, int i_tally, int i_nuclide, switch (tally.estimator_) { case TallyEstimator::ANALOG: - if (p.event_nuclide_ != deriv.diff_nuclide) { + if (p.event_nuclide() != deriv.diff_nuclide) { score *= flux_deriv; return; } @@ -210,12 +210,11 @@ apply_derivative_to_score(const Particle& p, int i_tally, int i_nuclide, switch (score_bin) { case SCORE_TOTAL: - if (i_nuclide == -1 && p.macro_xs_.total > 0.0) { - score *= flux_deriv - + p.neutron_xs_[deriv.diff_nuclide].total - / p.macro_xs_.total; - } else if (i_nuclide == deriv.diff_nuclide - && p.neutron_xs_[i_nuclide].total) { + if (i_nuclide == -1 && p.macro_xs().total > 0.0) { + score *= flux_deriv + + p.neutron_xs(deriv.diff_nuclide).total / p.macro_xs().total; + } else if (i_nuclide == deriv.diff_nuclide && + p.neutron_xs(i_nuclide).total) { score *= flux_deriv + 1. / atom_density; } else { score *= flux_deriv; @@ -223,13 +222,12 @@ apply_derivative_to_score(const Particle& p, int i_tally, int i_nuclide, break; case SCORE_SCATTER: - if (i_nuclide == -1 && (p.macro_xs_.total - - p.macro_xs_.absorption) > 0.0) { - score *= flux_deriv - + (p.neutron_xs_[deriv.diff_nuclide].total - - p.neutron_xs_[deriv.diff_nuclide].absorption) - / (p.macro_xs_.total - - p.macro_xs_.absorption); + if (i_nuclide == -1 && + (p.macro_xs().total - p.macro_xs().absorption) > 0.0) { + score *= + flux_deriv + (p.neutron_xs(deriv.diff_nuclide).total - + p.neutron_xs(deriv.diff_nuclide).absorption) / + (p.macro_xs().total - p.macro_xs().absorption); } else if (i_nuclide == deriv.diff_nuclide) { score *= flux_deriv + 1. / atom_density; } else { @@ -238,12 +236,11 @@ apply_derivative_to_score(const Particle& p, int i_tally, int i_nuclide, break; case SCORE_ABSORPTION: - if (i_nuclide == -1 && p.macro_xs_.absorption > 0.0) { - score *= flux_deriv - + p.neutron_xs_[deriv.diff_nuclide].absorption - / p.macro_xs_.absorption; - } else if (i_nuclide == deriv.diff_nuclide - && p.neutron_xs_[i_nuclide].absorption) { + if (i_nuclide == -1 && p.macro_xs().absorption > 0.0) { + score *= flux_deriv + p.neutron_xs(deriv.diff_nuclide).absorption / + p.macro_xs().absorption; + } else if (i_nuclide == deriv.diff_nuclide && + p.neutron_xs(i_nuclide).absorption) { score *= flux_deriv + 1. / atom_density; } else { score *= flux_deriv; @@ -251,12 +248,11 @@ apply_derivative_to_score(const Particle& p, int i_tally, int i_nuclide, break; case SCORE_FISSION: - if (i_nuclide == -1 && p.macro_xs_.fission > 0.0) { - score *= flux_deriv - + p.neutron_xs_[deriv.diff_nuclide].fission - / p.macro_xs_.fission; - } else if (i_nuclide == deriv.diff_nuclide - && p.neutron_xs_[i_nuclide].fission) { + if (i_nuclide == -1 && p.macro_xs().fission > 0.0) { + score *= flux_deriv + p.neutron_xs(deriv.diff_nuclide).fission / + p.macro_xs().fission; + } else if (i_nuclide == deriv.diff_nuclide && + p.neutron_xs(i_nuclide).fission) { score *= flux_deriv + 1. / atom_density; } else { score *= flux_deriv; @@ -264,12 +260,11 @@ apply_derivative_to_score(const Particle& p, int i_tally, int i_nuclide, break; case SCORE_NU_FISSION: - if (i_nuclide == -1 && p.macro_xs_.nu_fission > 0.0) { - score *= flux_deriv - + p.neutron_xs_[deriv.diff_nuclide].nu_fission - / p.macro_xs_.nu_fission; - } else if (i_nuclide == deriv.diff_nuclide - && p.neutron_xs_[i_nuclide].nu_fission) { + if (i_nuclide == -1 && p.macro_xs().nu_fission > 0.0) { + score *= flux_deriv + p.neutron_xs(deriv.diff_nuclide).nu_fission / + p.macro_xs().nu_fission; + } else if (i_nuclide == deriv.diff_nuclide && + p.neutron_xs(i_nuclide).nu_fission) { score *= flux_deriv + 1. / atom_density; } else { score *= flux_deriv; @@ -309,10 +304,11 @@ apply_derivative_to_score(const Particle& p, int i_tally, int i_nuclide, // Find the index of the event nuclide. int i; for (i = 0; i < material.nuclide_.size(); ++i) - if (material.nuclide_[i] == p.event_nuclide_) break; + if (material.nuclide_[i] == p.event_nuclide()) + break; - const auto& nuc {*data::nuclides[p.event_nuclide_]}; - if (!multipole_in_range(nuc, p.E_last_)) { + const auto& nuc {*data::nuclides[p.event_nuclide()]}; + if (!multipole_in_range(nuc, p.E_last())) { score *= flux_deriv; break; } @@ -320,63 +316,65 @@ apply_derivative_to_score(const Particle& p, int i_tally, int i_nuclide, switch (score_bin) { case SCORE_TOTAL: - if (p.neutron_xs_[p.event_nuclide_].total) { + if (p.neutron_xs(p.event_nuclide()).total) { double dsig_s, dsig_a, dsig_f; - std::tie(dsig_s, dsig_a, dsig_f) - = nuc.multipole_->evaluate_deriv(p.E_last_, p.sqrtkT_); - score *= flux_deriv + (dsig_s + dsig_a) * material.atom_density_(i) - / p.macro_xs_.total; + std::tie(dsig_s, dsig_a, dsig_f) = + nuc.multipole_->evaluate_deriv(p.E_last(), p.sqrtkT()); + score *= flux_deriv + (dsig_s + dsig_a) * + material.atom_density_(i) / + p.macro_xs().total; } else { score *= flux_deriv; } break; case SCORE_SCATTER: - if (p.neutron_xs_[p.event_nuclide_].total - - p.neutron_xs_[p.event_nuclide_].absorption) { + if (p.neutron_xs(p.event_nuclide()).total - + p.neutron_xs(p.event_nuclide()).absorption) { double dsig_s, dsig_a, dsig_f; - std::tie(dsig_s, dsig_a, dsig_f) - = nuc.multipole_->evaluate_deriv(p.E_last_, p.sqrtkT_); - score *= flux_deriv + dsig_s * material.atom_density_(i) - / (p.macro_xs_.total - p.macro_xs_.absorption); + std::tie(dsig_s, dsig_a, dsig_f) = + nuc.multipole_->evaluate_deriv(p.E_last(), p.sqrtkT()); + score *= + flux_deriv + dsig_s * material.atom_density_(i) / + (p.macro_xs().total - p.macro_xs().absorption); } else { score *= flux_deriv; } break; case SCORE_ABSORPTION: - if (p.neutron_xs_[p.event_nuclide_].absorption) { + if (p.neutron_xs(p.event_nuclide()).absorption) { double dsig_s, dsig_a, dsig_f; - std::tie(dsig_s, dsig_a, dsig_f) - = nuc.multipole_->evaluate_deriv(p.E_last_, p.sqrtkT_); - score *= flux_deriv + dsig_a * material.atom_density_(i) - / p.macro_xs_.absorption; + std::tie(dsig_s, dsig_a, dsig_f) = + nuc.multipole_->evaluate_deriv(p.E_last(), p.sqrtkT()); + score *= flux_deriv + dsig_a * material.atom_density_(i) / + p.macro_xs().absorption; } else { score *= flux_deriv; } break; case SCORE_FISSION: - if (p.neutron_xs_[p.event_nuclide_].fission) { + if (p.neutron_xs(p.event_nuclide()).fission) { double dsig_s, dsig_a, dsig_f; - std::tie(dsig_s, dsig_a, dsig_f) - = nuc.multipole_->evaluate_deriv(p.E_last_, p.sqrtkT_); - score *= flux_deriv + dsig_f * material.atom_density_(i) - / p.macro_xs_.fission; + std::tie(dsig_s, dsig_a, dsig_f) = + nuc.multipole_->evaluate_deriv(p.E_last(), p.sqrtkT()); + score *= flux_deriv + + dsig_f * material.atom_density_(i) / p.macro_xs().fission; } else { score *= flux_deriv; } break; case SCORE_NU_FISSION: - if (p.neutron_xs_[p.event_nuclide_].fission) { - double nu = p.neutron_xs_[p.event_nuclide_].nu_fission - / p.neutron_xs_[p.event_nuclide_].fission; + if (p.neutron_xs(p.event_nuclide()).fission) { + double nu = p.neutron_xs(p.event_nuclide()).nu_fission / + p.neutron_xs(p.event_nuclide()).fission; double dsig_s, dsig_a, dsig_f; - std::tie(dsig_s, dsig_a, dsig_f) - = nuc.multipole_->evaluate_deriv(p.E_last_, p.sqrtkT_); - score *= flux_deriv + nu * dsig_f * material.atom_density_(i) - / p.macro_xs_.nu_fission; + std::tie(dsig_s, dsig_a, dsig_f) = + nuc.multipole_->evaluate_deriv(p.E_last(), p.sqrtkT()); + score *= flux_deriv + nu * dsig_f * material.atom_density_(i) / + p.macro_xs().nu_fission; } else { score *= flux_deriv; } @@ -392,7 +390,7 @@ apply_derivative_to_score(const Particle& p, int i_tally, int i_nuclide, case TallyEstimator::COLLISION: if (i_nuclide != -1) { const auto& nuc {data::nuclides[i_nuclide]}; - if (!multipole_in_range(*nuc, p.E_last_)) { + if (!multipole_in_range(*nuc, p.E_last())) { score *= flux_deriv; return; } @@ -401,141 +399,136 @@ apply_derivative_to_score(const Particle& p, int i_tally, int i_nuclide, switch (score_bin) { case SCORE_TOTAL: - if (i_nuclide == -1 && p.macro_xs_.total > 0.0) { + if (i_nuclide == -1 && p.macro_xs().total > 0.0) { double cum_dsig = 0; for (auto i = 0; i < material.nuclide_.size(); ++i) { auto i_nuc = material.nuclide_[i]; const auto& nuc {*data::nuclides[i_nuc]}; - if (multipole_in_range(nuc, p.E_last_) - && p.neutron_xs_[i_nuc].total) { + if (multipole_in_range(nuc, p.E_last()) && + p.neutron_xs(i_nuc).total) { double dsig_s, dsig_a, dsig_f; - std::tie(dsig_s, dsig_a, dsig_f) - = nuc.multipole_->evaluate_deriv(p.E_last_, p.sqrtkT_); + std::tie(dsig_s, dsig_a, dsig_f) = + nuc.multipole_->evaluate_deriv(p.E_last(), p.sqrtkT()); cum_dsig += (dsig_s + dsig_a) * material.atom_density_(i); } } - score *= flux_deriv + cum_dsig / p.macro_xs_.total; - } else if (p.neutron_xs_[i_nuclide].total) { + score *= flux_deriv + cum_dsig / p.macro_xs().total; + } else if (p.neutron_xs(i_nuclide).total) { const auto& nuc {*data::nuclides[i_nuclide]}; double dsig_s, dsig_a, dsig_f; - std::tie(dsig_s, dsig_a, dsig_f) - = nuc.multipole_->evaluate_deriv(p.E_last_, p.sqrtkT_); - score *= flux_deriv - + (dsig_s + dsig_a) / p.neutron_xs_[i_nuclide].total; + std::tie(dsig_s, dsig_a, dsig_f) = + nuc.multipole_->evaluate_deriv(p.E_last(), p.sqrtkT()); + score *= + flux_deriv + (dsig_s + dsig_a) / p.neutron_xs(i_nuclide).total; } else { score *= flux_deriv; } break; case SCORE_SCATTER: - if (i_nuclide == -1 && (p.macro_xs_.total - - p.macro_xs_.absorption)) { + if (i_nuclide == -1 && (p.macro_xs().total - p.macro_xs().absorption)) { double cum_dsig = 0; for (auto i = 0; i < material.nuclide_.size(); ++i) { auto i_nuc = material.nuclide_[i]; const auto& nuc {*data::nuclides[i_nuc]}; - if (multipole_in_range(nuc, p.E_last_) - && (p.neutron_xs_[i_nuc].total - - p.neutron_xs_[i_nuc].absorption)) { + if (multipole_in_range(nuc, p.E_last()) && + (p.neutron_xs(i_nuc).total - p.neutron_xs(i_nuc).absorption)) { double dsig_s, dsig_a, dsig_f; - std::tie(dsig_s, dsig_a, dsig_f) - = nuc.multipole_->evaluate_deriv(p.E_last_, p.sqrtkT_); + std::tie(dsig_s, dsig_a, dsig_f) = + nuc.multipole_->evaluate_deriv(p.E_last(), p.sqrtkT()); cum_dsig += dsig_s * material.atom_density_(i); } } - score *= flux_deriv + cum_dsig / (p.macro_xs_.total - - p.macro_xs_.absorption); - } else if (p.neutron_xs_[i_nuclide].total - - p.neutron_xs_[i_nuclide].absorption) { + score *= flux_deriv + + cum_dsig / (p.macro_xs().total - p.macro_xs().absorption); + } else if (p.neutron_xs(i_nuclide).total - + p.neutron_xs(i_nuclide).absorption) { const auto& nuc {*data::nuclides[i_nuclide]}; double dsig_s, dsig_a, dsig_f; - std::tie(dsig_s, dsig_a, dsig_f) - = nuc.multipole_->evaluate_deriv(p.E_last_, p.sqrtkT_); - score *= flux_deriv + dsig_s / (p.neutron_xs_[i_nuclide].total - - p.neutron_xs_[i_nuclide].absorption); + std::tie(dsig_s, dsig_a, dsig_f) = + nuc.multipole_->evaluate_deriv(p.E_last(), p.sqrtkT()); + score *= flux_deriv + dsig_s / (p.neutron_xs(i_nuclide).total - + p.neutron_xs(i_nuclide).absorption); } else { score *= flux_deriv; } break; case SCORE_ABSORPTION: - if (i_nuclide == -1 && p.macro_xs_.absorption > 0.0) { + if (i_nuclide == -1 && p.macro_xs().absorption > 0.0) { double cum_dsig = 0; for (auto i = 0; i < material.nuclide_.size(); ++i) { auto i_nuc = material.nuclide_[i]; const auto& nuc {*data::nuclides[i_nuc]}; - if (multipole_in_range(nuc, p.E_last_) - && p.neutron_xs_[i_nuc].absorption) { + if (multipole_in_range(nuc, p.E_last()) && + p.neutron_xs(i_nuc).absorption) { double dsig_s, dsig_a, dsig_f; - std::tie(dsig_s, dsig_a, dsig_f) - = nuc.multipole_->evaluate_deriv(p.E_last_, p.sqrtkT_); + std::tie(dsig_s, dsig_a, dsig_f) = + nuc.multipole_->evaluate_deriv(p.E_last(), p.sqrtkT()); cum_dsig += dsig_a * material.atom_density_(i); } } - score *= flux_deriv + cum_dsig / p.macro_xs_.absorption; - } else if (p.neutron_xs_[i_nuclide].absorption) { + score *= flux_deriv + cum_dsig / p.macro_xs().absorption; + } else if (p.neutron_xs(i_nuclide).absorption) { const auto& nuc {*data::nuclides[i_nuclide]}; double dsig_s, dsig_a, dsig_f; - std::tie(dsig_s, dsig_a, dsig_f) - = nuc.multipole_->evaluate_deriv(p.E_last_, p.sqrtkT_); - score *= flux_deriv - + dsig_a / p.neutron_xs_[i_nuclide].absorption; + std::tie(dsig_s, dsig_a, dsig_f) = + nuc.multipole_->evaluate_deriv(p.E_last(), p.sqrtkT()); + score *= flux_deriv + dsig_a / p.neutron_xs(i_nuclide).absorption; } else { score *= flux_deriv; } break; case SCORE_FISSION: - if (i_nuclide == -1 && p.macro_xs_.fission > 0.0) { + if (i_nuclide == -1 && p.macro_xs().fission > 0.0) { double cum_dsig = 0; for (auto i = 0; i < material.nuclide_.size(); ++i) { auto i_nuc = material.nuclide_[i]; const auto& nuc {*data::nuclides[i_nuc]}; - if (multipole_in_range(nuc, p.E_last_) - && p.neutron_xs_[i_nuc].fission) { + if (multipole_in_range(nuc, p.E_last()) && + p.neutron_xs(i_nuc).fission) { double dsig_s, dsig_a, dsig_f; - std::tie(dsig_s, dsig_a, dsig_f) - = nuc.multipole_->evaluate_deriv(p.E_last_, p.sqrtkT_); + std::tie(dsig_s, dsig_a, dsig_f) = + nuc.multipole_->evaluate_deriv(p.E_last(), p.sqrtkT()); cum_dsig += dsig_f * material.atom_density_(i); } } - score *= flux_deriv + cum_dsig / p.macro_xs_.fission; - } else if (p.neutron_xs_[i_nuclide].fission) { + score *= flux_deriv + cum_dsig / p.macro_xs().fission; + } else if (p.neutron_xs(i_nuclide).fission) { const auto& nuc {*data::nuclides[i_nuclide]}; double dsig_s, dsig_a, dsig_f; - std::tie(dsig_s, dsig_a, dsig_f) - = nuc.multipole_->evaluate_deriv(p.E_last_, p.sqrtkT_); - score *= flux_deriv - + dsig_f / p.neutron_xs_[i_nuclide].fission; + std::tie(dsig_s, dsig_a, dsig_f) = + nuc.multipole_->evaluate_deriv(p.E_last(), p.sqrtkT()); + score *= flux_deriv + dsig_f / p.neutron_xs(i_nuclide).fission; } else { score *= flux_deriv; } break; case SCORE_NU_FISSION: - if (i_nuclide == -1 && p.macro_xs_.nu_fission > 0.0) { + if (i_nuclide == -1 && p.macro_xs().nu_fission > 0.0) { double cum_dsig = 0; for (auto i = 0; i < material.nuclide_.size(); ++i) { auto i_nuc = material.nuclide_[i]; const auto& nuc {*data::nuclides[i_nuc]}; - if (multipole_in_range(nuc, p.E_last_) - && p.neutron_xs_[i_nuc].fission) { - double nu = p.neutron_xs_[i_nuc].nu_fission - / p.neutron_xs_[i_nuc].fission; + if (multipole_in_range(nuc, p.E_last()) && + p.neutron_xs(i_nuc).fission) { + double nu = + p.neutron_xs(i_nuc).nu_fission / p.neutron_xs(i_nuc).fission; double dsig_s, dsig_a, dsig_f; - std::tie(dsig_s, dsig_a, dsig_f) - = nuc.multipole_->evaluate_deriv(p.E_last_, p.sqrtkT_); + std::tie(dsig_s, dsig_a, dsig_f) = + nuc.multipole_->evaluate_deriv(p.E_last(), p.sqrtkT()); cum_dsig += nu * dsig_f * material.atom_density_(i); } } - score *= flux_deriv + cum_dsig / p.macro_xs_.nu_fission; - } else if (p.neutron_xs_[i_nuclide].fission) { + score *= flux_deriv + cum_dsig / p.macro_xs().nu_fission; + } else if (p.neutron_xs(i_nuclide).fission) { const auto& nuc {*data::nuclides[i_nuclide]}; double dsig_s, dsig_a, dsig_f; - std::tie(dsig_s, dsig_a, dsig_f) - = nuc.multipole_->evaluate_deriv(p.E_last_, p.sqrtkT_); - score *= flux_deriv - + dsig_f / p.neutron_xs_[i_nuclide].fission; + std::tie(dsig_s, dsig_a, dsig_f) = + nuc.multipole_->evaluate_deriv(p.E_last(), p.sqrtkT()); + score *= flux_deriv + dsig_f / p.neutron_xs(i_nuclide).fission; } else { score *= flux_deriv; } @@ -558,13 +551,14 @@ void score_track_derivative(Particle& p, double distance) { // A void material cannot be perturbed so it will not affect flux derivatives. - if (p.material_ == MATERIAL_VOID) return; + if (p.material() == MATERIAL_VOID) + return; - const Material& material {*model::materials[p.material_]}; + const Material& material {*model::materials[p.material()]}; for (auto idx = 0; idx < model::tally_derivs.size(); idx++) { const auto& deriv = model::tally_derivs[idx]; - auto& flux_deriv = p.flux_derivs_[idx]; + auto& flux_deriv = p.flux_derivs(idx); if (deriv.diff_material != material.id_) continue; switch (deriv.variable) { @@ -573,28 +567,26 @@ score_track_derivative(Particle& p, double distance) // phi is proportional to e^(-Sigma_tot * dist) // (1 / phi) * (d_phi / d_rho) = - (d_Sigma_tot / d_rho) * dist // (1 / phi) * (d_phi / d_rho) = - Sigma_tot / rho * dist - flux_deriv -= distance * p.macro_xs_.total - / material.density_gpcc_; + flux_deriv -= distance * p.macro_xs().total / material.density_gpcc_; break; case DerivativeVariable::NUCLIDE_DENSITY: // phi is proportional to e^(-Sigma_tot * dist) // (1 / phi) * (d_phi / d_N) = - (d_Sigma_tot / d_N) * dist // (1 / phi) * (d_phi / d_N) = - sigma_tot * dist - flux_deriv -= distance - * p.neutron_xs_[deriv.diff_nuclide].total; + flux_deriv -= distance * p.neutron_xs(deriv.diff_nuclide).total; break; case DerivativeVariable::TEMPERATURE: for (auto i = 0; i < material.nuclide_.size(); ++i) { const auto& nuc {*data::nuclides[material.nuclide_[i]]}; - if (multipole_in_range(nuc, p.E_last_)) { + if (multipole_in_range(nuc, p.E_last())) { // phi is proportional to e^(-Sigma_tot * dist) // (1 / phi) * (d_phi / d_T) = - (d_Sigma_tot / d_T) * dist // (1 / phi) * (d_phi / d_T) = - N (d_sigma_tot / d_T) * dist double dsig_s, dsig_a, dsig_f; - std::tie(dsig_s, dsig_a, dsig_f) - = nuc.multipole_->evaluate_deriv(p.E_, p.sqrtkT_); + std::tie(dsig_s, dsig_a, dsig_f) = + nuc.multipole_->evaluate_deriv(p.E(), p.sqrtkT()); flux_deriv -= distance * (dsig_s + dsig_a) * material.atom_density_(i); } @@ -607,13 +599,14 @@ score_track_derivative(Particle& p, double distance) void score_collision_derivative(Particle& p) { // A void material cannot be perturbed so it will not affect flux derivatives. - if (p.material_ == MATERIAL_VOID) return; + if (p.material() == MATERIAL_VOID) + return; - const Material& material {*model::materials[p.material_]}; + const Material& material {*model::materials[p.material()]}; for (auto idx = 0; idx < model::tally_derivs.size(); idx++) { const auto& deriv = model::tally_derivs[idx]; - auto& flux_deriv = p.flux_derivs_[idx]; + auto& flux_deriv = p.flux_derivs(idx); if (deriv.diff_material != material.id_) continue; @@ -627,7 +620,8 @@ void score_collision_derivative(Particle& p) break; case DerivativeVariable::NUCLIDE_DENSITY: - if (p.event_nuclide_ != deriv.diff_nuclide) continue; + if (p.event_nuclide() != deriv.diff_nuclide) + continue; // Find the index in this material for the diff_nuclide. int i; for (i = 0; i < material.nuclide_.size(); ++i) @@ -649,14 +643,14 @@ void score_collision_derivative(Particle& p) // Loop over the material's nuclides until we find the event nuclide. for (auto i_nuc : material.nuclide_) { const auto& nuc {*data::nuclides[i_nuc]}; - if (i_nuc == p.event_nuclide_ && multipole_in_range(nuc, p.E_last_)) { + if (i_nuc == p.event_nuclide() && multipole_in_range(nuc, p.E_last())) { // phi is proportional to Sigma_s // (1 / phi) * (d_phi / d_T) = (d_Sigma_s / d_T) / Sigma_s // (1 / phi) * (d_phi / d_T) = (d_sigma_s / d_T) / sigma_s - const auto& micro_xs {p.neutron_xs_[i_nuc]}; + const auto& micro_xs {p.neutron_xs(i_nuc)}; double dsig_s, dsig_a, dsig_f; - std::tie(dsig_s, dsig_a, dsig_f) - = nuc.multipole_->evaluate_deriv(p.E_last_, p.sqrtkT_); + std::tie(dsig_s, dsig_a, dsig_f) = + nuc.multipole_->evaluate_deriv(p.E_last(), p.sqrtkT()); flux_deriv += dsig_s / (micro_xs.total - micro_xs.absorption); // Note that this is an approximation! The real scattering cross // section is diff --git a/src/tallies/filter.cpp b/src/tallies/filter.cpp index 31f572e4b..55916401f 100644 --- a/src/tallies/filter.cpp +++ b/src/tallies/filter.cpp @@ -34,7 +34,7 @@ #include "openmc/tallies/filter_zernike.h" // explicit template instantiation definition -template class std::vector; +template class openmc::vector; namespace openmc { @@ -44,7 +44,7 @@ namespace openmc { namespace model { std::unordered_map filter_map; - std::vector> tally_filters; + vector> tally_filters; } //============================================================================== @@ -75,7 +75,7 @@ T* Filter::create(int32_t id) { static_assert(std::is_base_of::value, "Type specified is not derived from openmc::Filter"); // Create filter and add to filters vector - auto filter = std::make_unique(); + auto filter = make_unique(); auto ptr_out = filter.get(); model::tally_filters.emplace_back(std::move(filter)); // Assign ID diff --git a/src/tallies/filter_azimuthal.cpp b/src/tallies/filter_azimuthal.cpp index 4c64587ee..7bf5343b7 100644 --- a/src/tallies/filter_azimuthal.cpp +++ b/src/tallies/filter_azimuthal.cpp @@ -54,7 +54,7 @@ void AzimuthalFilter::get_all_bins(const Particle& p, TallyEstimator estimator, FilterMatch& match) const { - Direction u = (estimator == TallyEstimator::TRACKLENGTH) ? p.u() : p.u_last_; + Direction u = (estimator == TallyEstimator::TRACKLENGTH) ? p.u() : p.u_last(); double phi = std::atan2(u.y, u.x); if (phi >= bins_.front() && phi <= bins_.back()) { diff --git a/src/tallies/filter_cell.cpp b/src/tallies/filter_cell.cpp index f6b804ab9..10fa0040e 100644 --- a/src/tallies/filter_cell.cpp +++ b/src/tallies/filter_cell.cpp @@ -49,8 +49,8 @@ void CellFilter::get_all_bins(const Particle& p, TallyEstimator estimator, FilterMatch& match) const { - for (int i = 0; i < p.n_coord_; i++) { - auto search = map_.find(p.coord_[i].cell); + for (int i = 0; i < p.n_coord(); i++) { + auto search = map_.find(p.coord(i).cell); if (search != map_.end()) { match.bins_.push_back(search->second); match.weights_.push_back(1.0); @@ -62,7 +62,7 @@ void CellFilter::to_statepoint(hid_t filter_group) const { Filter::to_statepoint(filter_group); - std::vector cell_ids; + vector cell_ids; for (auto c : cells_) cell_ids.push_back(model::cells[c]->id_); write_dataset(filter_group, "bins", cell_ids); } diff --git a/src/tallies/filter_cell_instance.cpp b/src/tallies/filter_cell_instance.cpp index d44cdfcf6..c41077631 100644 --- a/src/tallies/filter_cell_instance.cpp +++ b/src/tallies/filter_cell_instance.cpp @@ -24,7 +24,7 @@ CellInstanceFilter::from_xml(pugi::xml_node node) Expects(cells.size() % 2 == 0); // Convert into vector of CellInstance - std::vector instances; + vector instances; for (gsl::index i = 0; i < cells.size() / 2; ++i) { int32_t cell_id = cells[2*i]; gsl::index instance = cells[2*i + 1]; @@ -69,8 +69,8 @@ void CellInstanceFilter::get_all_bins(const Particle& p, TallyEstimator estimator, FilterMatch& match) const { - gsl::index index_cell = p.coord_[p.n_coord_ - 1].cell; - gsl::index instance = p.cell_instance_; + gsl::index index_cell = p.coord(p.n_coord() - 1).cell; + gsl::index instance = p.cell_instance(); auto search = map_.find({index_cell, instance}); if (search != map_.end()) { int index_bin = search->second; diff --git a/src/tallies/filter_cellborn.cpp b/src/tallies/filter_cellborn.cpp index 572b1503c..ac5b8be9d 100644 --- a/src/tallies/filter_cellborn.cpp +++ b/src/tallies/filter_cellborn.cpp @@ -8,7 +8,7 @@ void CellbornFilter::get_all_bins(const Particle& p, TallyEstimator estimator, FilterMatch& match) const { - auto search = map_.find(p.cell_born_); + auto search = map_.find(p.cell_born()); if (search != map_.end()) { match.bins_.push_back(search->second); match.weights_.push_back(1.0); diff --git a/src/tallies/filter_cellfrom.cpp b/src/tallies/filter_cellfrom.cpp index 39fde3976..9d6af07dd 100644 --- a/src/tallies/filter_cellfrom.cpp +++ b/src/tallies/filter_cellfrom.cpp @@ -8,8 +8,8 @@ void CellFromFilter::get_all_bins(const Particle& p, TallyEstimator estimator, FilterMatch& match) const { - for (int i = 0; i < p.n_coord_last_; i++) { - auto search = map_.find(p.cell_last_[i]); + for (int i = 0; i < p.n_coord_last(); i++) { + auto search = map_.find(p.cell_last(i)); if (search != map_.end()) { match.bins_.push_back(search->second); match.weights_.push_back(1.0); diff --git a/src/tallies/filter_collision.cpp b/src/tallies/filter_collision.cpp index daa553942..cf7d98c85 100644 --- a/src/tallies/filter_collision.cpp +++ b/src/tallies/filter_collision.cpp @@ -39,7 +39,7 @@ void CollisionFilter::get_all_bins( const Particle& p, TallyEstimator estimator, FilterMatch& match) const { // Get the number of collisions for the particle - auto n = p.n_collision_; + auto n = p.n_collision(); // Bin the collision number. Must fit exactly the desired collision number. auto search = map_.find(n); diff --git a/src/tallies/filter_distribcell.cpp b/src/tallies/filter_distribcell.cpp index d3a2ffe5f..c33c88cbc 100644 --- a/src/tallies/filter_distribcell.cpp +++ b/src/tallies/filter_distribcell.cpp @@ -43,20 +43,18 @@ DistribcellFilter::get_all_bins(const Particle& p, TallyEstimator estimator, { int offset = 0; auto distribcell_index = model::cells[cell_]->distribcell_index_; - for (int i = 0; i < p.n_coord_; i++) { - auto& c {*model::cells[p.coord_[i].cell]}; + for (int i = 0; i < p.n_coord(); i++) { + auto& c {*model::cells[p.coord(i).cell]}; if (c.type_ == Fill::UNIVERSE) { offset += c.offset_[distribcell_index]; } else if (c.type_ == Fill::LATTICE) { - auto& lat {*model::lattices[p.coord_[i+1].lattice]}; - int i_xyz[3] {p.coord_[i+1].lattice_x, - p.coord_[i+1].lattice_y, - p.coord_[i+1].lattice_z}; + auto& lat {*model::lattices[p.coord(i + 1).lattice]}; + const auto& i_xyz {p.coord(i + 1).lattice_i}; if (lat.are_valid_indices(i_xyz)) { offset += lat.offset(distribcell_index, i_xyz); } } - if (cell_ == p.coord_[i].cell) { + if (cell_ == p.coord(i).cell) { match.bins_.push_back(offset); match.weights_.push_back(1.0); return; diff --git a/src/tallies/filter_energy.cpp b/src/tallies/filter_energy.cpp index 097e8429e..9169c4d85 100644 --- a/src/tallies/filter_energy.cpp +++ b/src/tallies/filter_energy.cpp @@ -61,17 +61,17 @@ void EnergyFilter::get_all_bins(const Particle& p, TallyEstimator estimator, FilterMatch& match) const { - if (p.g_ != F90_NONE && matches_transport_groups_) { + if (p.g() != F90_NONE && matches_transport_groups_) { if (estimator == TallyEstimator::TRACKLENGTH) { - match.bins_.push_back(data::mg.num_energy_groups_ - p.g_ - 1); + match.bins_.push_back(data::mg.num_energy_groups_ - p.g() - 1); } else { - match.bins_.push_back(data::mg.num_energy_groups_ - p.g_last_ - 1); + match.bins_.push_back(data::mg.num_energy_groups_ - p.g_last() - 1); } match.weights_.push_back(1.0); } else { // Get the pre-collision energy of the particle. - auto E = p.E_last_; + auto E = p.E_last(); // Bin the energy. if (E >= bins_.front() && E <= bins_.back()) { @@ -103,13 +103,13 @@ void EnergyoutFilter::get_all_bins(const Particle& p, TallyEstimator estimator, FilterMatch& match) const { - if (p.g_ != F90_NONE && matches_transport_groups_) { - match.bins_.push_back(data::mg.num_energy_groups_ - p.g_ - 1); + if (p.g() != F90_NONE && matches_transport_groups_) { + match.bins_.push_back(data::mg.num_energy_groups_ - p.g() - 1); match.weights_.push_back(1.0); } else { - if (p.E_ >= bins_.front() && p.E_ <= bins_.back()) { - auto bin = lower_bound_index(bins_.begin(), bins_.end(), p.E_); + if (p.E() >= bins_.front() && p.E() <= bins_.back()) { + auto bin = lower_bound_index(bins_.begin(), bins_.end(), p.E()); match.bins_.push_back(bin); match.weights_.push_back(1.0); } diff --git a/src/tallies/filter_energyfunc.cpp b/src/tallies/filter_energyfunc.cpp index 498fd52e8..bea35c8e0 100644 --- a/src/tallies/filter_energyfunc.cpp +++ b/src/tallies/filter_energyfunc.cpp @@ -56,12 +56,12 @@ void EnergyFunctionFilter::get_all_bins(const Particle& p, TallyEstimator estimator, FilterMatch& match) const { - if (p.E_last_ >= energy_.front() && p.E_last_ <= energy_.back()) { + if (p.E_last() >= energy_.front() && p.E_last() <= energy_.back()) { // Search for the incoming energy bin. - auto i = lower_bound_index(energy_.begin(), energy_.end(), p.E_last_); + auto i = lower_bound_index(energy_.begin(), energy_.end(), p.E_last()); // Compute the interpolation factor between the nearest bins. - double f = (p.E_last_ - energy_[i]) / (energy_[i+1] - energy_[i]); + double f = (p.E_last() - energy_[i]) / (energy_[i + 1] - energy_[i]); // Interpolate on the lin-lin grid. match.bins_.push_back(0); diff --git a/src/tallies/filter_legendre.cpp b/src/tallies/filter_legendre.cpp index 57912983c..6626f5ea1 100644 --- a/src/tallies/filter_legendre.cpp +++ b/src/tallies/filter_legendre.cpp @@ -27,8 +27,8 @@ void LegendreFilter::get_all_bins(const Particle& p, TallyEstimator estimator, FilterMatch& match) const { - std::vector wgt(n_bins_); - calc_pn_c(order_, p.mu_, wgt.data()); + vector wgt(n_bins_); + calc_pn_c(order_, p.mu(), wgt.data()); for (int i = 0; i < n_bins_; i++) { match.bins_.push_back(i); match.weights_.push_back(wgt[i]); diff --git a/src/tallies/filter_material.cpp b/src/tallies/filter_material.cpp index df50ff697..e9247457f 100644 --- a/src/tallies/filter_material.cpp +++ b/src/tallies/filter_material.cpp @@ -48,7 +48,7 @@ void MaterialFilter::get_all_bins(const Particle& p, TallyEstimator estimator, FilterMatch& match) const { - auto search = map_.find(p.material_); + auto search = map_.find(p.material()); if (search != map_.end()) { match.bins_.push_back(search->second); match.weights_.push_back(1.0); @@ -59,7 +59,7 @@ void MaterialFilter::to_statepoint(hid_t filter_group) const { Filter::to_statepoint(filter_group); - std::vector material_ids; + vector material_ids; for (auto c : materials_) material_ids.push_back(model::materials[c]->id_); write_dataset(filter_group, "bins", material_ids); } diff --git a/src/tallies/filter_mesh.cpp b/src/tallies/filter_mesh.cpp index 1595de70c..d36fdb6f7 100644 --- a/src/tallies/filter_mesh.cpp +++ b/src/tallies/filter_mesh.cpp @@ -40,7 +40,7 @@ MeshFilter::get_all_bins(const Particle& p, TallyEstimator estimator, FilterMatc const { - Position last_r = p.r_last_; + Position last_r = p.r_last(); Position r = p.r(); Position u = p.u(); diff --git a/src/tallies/filter_meshsurface.cpp b/src/tallies/filter_meshsurface.cpp index af595ad52..8f94e5ecb 100644 --- a/src/tallies/filter_meshsurface.cpp +++ b/src/tallies/filter_meshsurface.cpp @@ -11,7 +11,7 @@ void MeshSurfaceFilter::get_all_bins(const Particle& p, TallyEstimator estimator, FilterMatch& match) const { - Position r0 = p.r_last_current_; + Position r0 = p.r_last_current(); Position r1 = p.r(); if (translated_) { r0 -= translation(); diff --git a/src/tallies/filter_mu.cpp b/src/tallies/filter_mu.cpp index d1f5569cd..b157ff2db 100644 --- a/src/tallies/filter_mu.cpp +++ b/src/tallies/filter_mu.cpp @@ -52,8 +52,8 @@ void MuFilter::get_all_bins(const Particle& p, TallyEstimator estimator, FilterMatch& match) const { - if (p.mu_ >= bins_.front() && p.mu_ <= bins_.back()) { - auto bin = lower_bound_index(bins_.begin(), bins_.end(), p.mu_); + if (p.mu() >= bins_.front() && p.mu() <= bins_.back()) { + auto bin = lower_bound_index(bins_.begin(), bins_.end(), p.mu()); match.bins_.push_back(bin); match.weights_.push_back(1.0); } diff --git a/src/tallies/filter_particle.cpp b/src/tallies/filter_particle.cpp index c2b045a67..a9669661e 100644 --- a/src/tallies/filter_particle.cpp +++ b/src/tallies/filter_particle.cpp @@ -11,16 +11,15 @@ ParticleFilter::from_xml(pugi::xml_node node) { auto particles = get_node_array(node, "bins"); - // Convert to vector of Particle::Type - std::vector types; + // Convert to vector of ParticleType + vector types; for (auto& p : particles) { types.push_back(str_to_particle_type(p)); } this->set_particles(types); } -void -ParticleFilter::set_particles(gsl::span particles) +void ParticleFilter::set_particles(gsl::span particles) { // Clear existing particles particles_.clear(); @@ -38,7 +37,7 @@ ParticleFilter::get_all_bins(const Particle& p, TallyEstimator estimator, FilterMatch& match) const { for (auto i = 0; i < particles_.size(); i++) { - if (particles_[i] == p.type_) { + if (particles_[i] == p.type()) { match.bins_.push_back(i); match.weights_.push_back(1.0); } @@ -49,7 +48,7 @@ void ParticleFilter::to_statepoint(hid_t filter_group) const { Filter::to_statepoint(filter_group); - std::vector particles; + vector particles; for (auto p : particles_) { particles.push_back(particle_type_to_str(p)); } diff --git a/src/tallies/filter_polar.cpp b/src/tallies/filter_polar.cpp index 6d4d899cf..51ff496cd 100644 --- a/src/tallies/filter_polar.cpp +++ b/src/tallies/filter_polar.cpp @@ -53,7 +53,8 @@ void PolarFilter::get_all_bins(const Particle& p, TallyEstimator estimator, FilterMatch& match) const { - double z = (estimator == TallyEstimator::TRACKLENGTH) ? p.u().z : p.u_last_.z; + double z = + (estimator == TallyEstimator::TRACKLENGTH) ? p.u().z : p.u_last().z; double theta = std::acos(z); if (theta >= bins_.front() && theta <= bins_.back()) { diff --git a/src/tallies/filter_sph_harm.cpp b/src/tallies/filter_sph_harm.cpp index 44ec5f160..e8f8eed21 100644 --- a/src/tallies/filter_sph_harm.cpp +++ b/src/tallies/filter_sph_harm.cpp @@ -49,9 +49,9 @@ SphericalHarmonicsFilter::get_all_bins(const Particle& p, TallyEstimator estimat FilterMatch& match) const { // Determine cosine term for scatter expansion if necessary - std::vector wgt(order_ + 1); + vector wgt(order_ + 1); if (cosine_ == SphericalHarmonicsCosine::scatter) { - calc_pn_c(order_, p.mu_, wgt.data()); + calc_pn_c(order_, p.mu(), wgt.data()); } else { for (int i = 0; i < order_ + 1; i++) { wgt[i] = 1; @@ -59,8 +59,8 @@ SphericalHarmonicsFilter::get_all_bins(const Particle& p, TallyEstimator estimat } // Find the Rn,m values - std::vector rn(n_bins_); - calc_rn(order_, p.u_last_, rn.data()); + vector rn(n_bins_); + calc_rn(order_, p.u_last(), rn.data()); int j = 0; for (int n = 0; n < order_ + 1; n++) { diff --git a/src/tallies/filter_sptl_legendre.cpp b/src/tallies/filter_sptl_legendre.cpp index c32cc49d6..c835f1dd9 100644 --- a/src/tallies/filter_sptl_legendre.cpp +++ b/src/tallies/filter_sptl_legendre.cpp @@ -81,7 +81,7 @@ SpatialLegendreFilter::get_all_bins(const Particle& p, TallyEstimator estimator, double x_norm = 2.0*(x - min_) / (max_ - min_) - 1.0; // Compute and return the Legendre weights. - std::vector wgt(order_ + 1); + vector wgt(order_ + 1); calc_pn_c(order_, x_norm, wgt.data()); for (int i = 0; i < order_ + 1; i++) { match.bins_.push_back(i); diff --git a/src/tallies/filter_surface.cpp b/src/tallies/filter_surface.cpp index 141e1e847..53bbf4045 100644 --- a/src/tallies/filter_surface.cpp +++ b/src/tallies/filter_surface.cpp @@ -50,10 +50,10 @@ void SurfaceFilter::get_all_bins(const Particle& p, TallyEstimator estimator, FilterMatch& match) const { - auto search = map_.find(std::abs(p.surface_)-1); + auto search = map_.find(std::abs(p.surface()) - 1); if (search != map_.end()) { match.bins_.push_back(search->second); - if (p.surface_ < 0) { + if (p.surface() < 0) { match.weights_.push_back(-1.0); } else { match.weights_.push_back(1.0); @@ -65,7 +65,7 @@ void SurfaceFilter::to_statepoint(hid_t filter_group) const { Filter::to_statepoint(filter_group); - std::vector surface_ids; + vector surface_ids; for (auto c : surfaces_) surface_ids.push_back(model::surfaces[c]->id_); write_dataset(filter_group, "bins", surface_ids); } diff --git a/src/tallies/filter_universe.cpp b/src/tallies/filter_universe.cpp index d1b0d057e..8dbfa6462 100644 --- a/src/tallies/filter_universe.cpp +++ b/src/tallies/filter_universe.cpp @@ -48,8 +48,8 @@ void UniverseFilter::get_all_bins(const Particle& p, TallyEstimator estimator, FilterMatch& match) const { - for (int i = 0; i < p.n_coord_; i++) { - auto search = map_.find(p.coord_[i].universe); + for (int i = 0; i < p.n_coord(); i++) { + auto search = map_.find(p.coord(i).universe); if (search != map_.end()) { match.bins_.push_back(search->second); match.weights_.push_back(1.0); @@ -61,7 +61,7 @@ void UniverseFilter::to_statepoint(hid_t filter_group) const { Filter::to_statepoint(filter_group); - std::vector universe_ids; + vector universe_ids; for (auto u : universes_) universe_ids.push_back(model::universes[u]->id_); write_dataset(filter_group, "bins", universe_ids); } diff --git a/src/tallies/filter_zernike.cpp b/src/tallies/filter_zernike.cpp index f57a0be7c..d86298c45 100644 --- a/src/tallies/filter_zernike.cpp +++ b/src/tallies/filter_zernike.cpp @@ -39,7 +39,7 @@ ZernikeFilter::get_all_bins(const Particle& p, TallyEstimator estimator, if (r <= 1.0) { // Compute and return the Zernike weights. - std::vector zn(n_bins_); + vector zn(n_bins_); calc_zn(order_, r, theta, zn.data()); for (int i = 0; i < n_bins_; i++) { match.bins_.push_back(i); @@ -98,7 +98,7 @@ ZernikeRadialFilter::get_all_bins(const Particle& p, TallyEstimator estimator, if (r <= 1.0) { // Compute and return the Zernike weights. - std::vector zn(n_bins_); + vector zn(n_bins_); calc_zn_rad(order_, r, zn.data()); for (int i = 0; i < n_bins_; i++) { match.bins_.push_back(i); diff --git a/src/tallies/tally.cpp b/src/tallies/tally.cpp index dd67e02ad..4c776528a 100644 --- a/src/tallies/tally.cpp +++ b/src/tallies/tally.cpp @@ -1,11 +1,12 @@ #include "openmc/tallies/tally.h" +#include "openmc/array.h" #include "openmc/capi.h" #include "openmc/constants.h" #include "openmc/error.h" #include "openmc/file_utils.h" -#include "openmc/message_passing.h" #include "openmc/mesh.h" +#include "openmc/message_passing.h" #include "openmc/mgxs_interface.h" #include "openmc/nuclide.h" #include "openmc/particle.h" @@ -18,9 +19,9 @@ #include "openmc/tallies/filter.h" #include "openmc/tallies/filter_cell.h" #include "openmc/tallies/filter_cellfrom.h" +#include "openmc/tallies/filter_collision.h" #include "openmc/tallies/filter_delayedgroup.h" #include "openmc/tallies/filter_energy.h" -#include "openmc/tallies/filter_collision.h" #include "openmc/tallies/filter_legendre.h" #include "openmc/tallies/filter_mesh.h" #include "openmc/tallies/filter_meshsurface.h" @@ -35,7 +36,6 @@ #include "xtensor/xview.hpp" #include // for max -#include #include // for size_t #include @@ -47,13 +47,13 @@ namespace openmc { namespace model { std::unordered_map tally_map; - std::vector> tallies; - std::vector active_tallies; - std::vector active_analog_tallies; - std::vector active_tracklength_tallies; - std::vector active_collision_tallies; - std::vector active_meshsurf_tallies; - std::vector active_surface_tallies; + vector> tallies; + vector active_tallies; + vector active_analog_tallies; + vector active_tracklength_tallies; + vector active_collision_tallies; + vector active_meshsurf_tallies; + vector active_surface_tallies; } namespace simulation { @@ -103,13 +103,13 @@ Tally::Tally(pugi::xml_node node) } // Determine number of filters - std::vector filter_ids; + vector filter_ids; if (check_for_node(node, "filters")) { filter_ids = get_node_array(node, "filters"); } // Allocate and store filter user ids - std::vector filters; + vector filters; for (int filter_id : filter_ids) { // Determine if filter ID is valid auto it = model::filter_map.find(filter_id); @@ -196,7 +196,7 @@ Tally::Tally(pugi::xml_node node) const auto& f = model::tally_filters[particle_filter_index].get(); auto pf = dynamic_cast(f); for (auto p : pf->particles()) { - if (p != Particle::Type::neutron) { + if (p != ParticleType::neutron) { warning(fmt::format("Particle filter other than NEUTRON used with " "photon transport turned off. All tallies for particle type {}" " will have no scores", static_cast(p))); @@ -308,7 +308,7 @@ Tally::~Tally() Tally* Tally::create(int32_t id) { - model::tallies.push_back(std::make_unique(id)); + model::tallies.push_back(make_unique(id)); return model::tallies.back().get(); } @@ -388,8 +388,7 @@ Tally::set_scores(pugi::xml_node node) set_scores(scores); } -void -Tally::set_scores(const std::vector& scores) +void Tally::set_scores(const vector& scores) { // Reset state and prepare for the new scores. scores_.clear(); @@ -541,8 +540,7 @@ Tally::set_nuclides(pugi::xml_node node) } } -void -Tally::set_nuclides(const std::vector& nuclides) +void Tally::set_nuclides(const vector& nuclides) { nuclides_.clear(); @@ -595,7 +593,7 @@ Tally::init_triggers(pugi::xml_node node) } // Read the trigger scores. - std::vector trigger_scores; + vector trigger_scores; if (check_for_node(trigger_node, "scores")) { trigger_scores = get_node_array(trigger_node, "scores"); } else { @@ -739,7 +737,7 @@ void read_tallies_xml() } for (auto node_tal : root.children("tally")) { - model::tallies.push_back(std::make_unique(node_tal)); + model::tallies.push_back(make_unique(node_tal)); } } @@ -918,7 +916,7 @@ openmc_extend_tallies(int32_t n, int32_t* index_start, int32_t* index_end) if (index_start) *index_start = model::tallies.size(); if (index_end) *index_end = model::tallies.size() + n - 1; for (int i = 0; i < n; ++i) { - model::tallies.push_back(std::make_unique(-1)); + model::tallies.push_back(make_unique(-1)); } return 0; } @@ -1108,7 +1106,7 @@ openmc_tally_set_scores(int32_t index, int n, const char** scores) return OPENMC_E_OUT_OF_BOUNDS; } - std::vector scores_str(scores, scores+n); + vector scores_str(scores, scores + n); try { model::tallies[index]->set_scores(scores_str); } catch (const std::invalid_argument& ex) { @@ -1143,8 +1141,8 @@ openmc_tally_set_nuclides(int32_t index, int n, const char** nuclides) return OPENMC_E_OUT_OF_BOUNDS; } - std::vector words(nuclides, nuclides+n); - std::vector nucs; + vector words(nuclides, nuclides + n); + vector nucs; for (auto word : words){ if (word == "total") { nucs.push_back(-1); @@ -1188,7 +1186,7 @@ openmc_tally_set_filters(int32_t index, size_t n, const int32_t* indices) // Set the filters. try { // Convert indices to filter pointers - std::vector filters; + vector filters; for (gsl::index i = 0; i < n; ++i) { int32_t i_filt = indices[i]; filters.push_back(model::tally_filters.at(i_filt).get()); diff --git a/src/tallies/tally_scoring.cpp b/src/tallies/tally_scoring.cpp index 91f10f559..5242db2e3 100644 --- a/src/tallies/tally_scoring.cpp +++ b/src/tallies/tally_scoring.cpp @@ -27,7 +27,7 @@ namespace openmc { //============================================================================== FilterBinIter::FilterBinIter(const Tally& tally, Particle& p) - : filter_matches_{p.filter_matches_}, tally_{tally} + : filter_matches_ {p.filter_matches()}, tally_ {tally} { // Find all valid bins in each relevant filter if they have not already been // found for this event. @@ -55,9 +55,9 @@ FilterBinIter::FilterBinIter(const Tally& tally, Particle& p) this->compute_index_weight(); } -FilterBinIter::FilterBinIter(const Tally& tally, bool end, - std::vector* particle_filter_matches) - : filter_matches_{*particle_filter_matches}, tally_{tally} +FilterBinIter::FilterBinIter( + const Tally& tally, bool end, vector* particle_filter_matches) + : filter_matches_ {*particle_filter_matches}, tally_ {tally} { // Handle the special case for an iterator that points to the end. if (end) { @@ -144,9 +144,8 @@ FilterBinIter::compute_index_weight() //! Helper function used to increment tallies with a delayed group filter. -void -score_fission_delayed_dg(int i_tally, int d_bin, double score, int score_index, - std::vector& filter_matches) +void score_fission_delayed_dg(int i_tally, int d_bin, double score, + int score_index, vector& filter_matches) { // Save the original delayed group bin auto& tally {*model::tallies[i_tally]}; @@ -181,11 +180,11 @@ double get_nuc_fission_q(const Nuclide& nuc, const Particle& p, int score_bin) { if (score_bin == SCORE_FISS_Q_PROMPT) { if (nuc.fission_q_prompt_) { - return (*nuc.fission_q_prompt_)(p.E_last_); + return (*nuc.fission_q_prompt_)(p.E_last()); } } else if (score_bin == SCORE_FISS_Q_RECOV) { if (nuc.fission_q_recov_) { - return (*nuc.fission_q_recov_)(p.E_last_); + return (*nuc.fission_q_recov_)(p.E_last()); } } return 0.0; @@ -200,42 +199,43 @@ double score_fission_q(const Particle& p, int score_bin, const Tally& tally, double flux, int i_nuclide, double atom_density) { if (tally.estimator_ == TallyEstimator::ANALOG) { - const Nuclide& nuc {*data::nuclides[p.event_nuclide_]}; + const Nuclide& nuc {*data::nuclides[p.event_nuclide()]}; if (settings::survival_biasing) { // No fission events occur if survival biasing is on -- need to // calculate fraction of absorptions that would have resulted in // fission scaled by the Q-value - if (p.neutron_xs_[p.event_nuclide_].absorption > 0) { - return p.wgt_absorb_ * get_nuc_fission_q(nuc, p, score_bin) - * p.neutron_xs_[p.event_nuclide_].fission * flux - / p.neutron_xs_[p.event_nuclide_].absorption; + if (p.neutron_xs(p.event_nuclide()).absorption > 0) { + return p.wgt_absorb() * get_nuc_fission_q(nuc, p, score_bin) * + p.neutron_xs(p.event_nuclide()).fission * flux / + p.neutron_xs(p.event_nuclide()).absorption; } } else { // Skip any non-absorption events - if (p.event_ == TallyEvent::SCATTER) return 0.0; + if (p.event() == TallyEvent::SCATTER) + return 0.0; // All fission events will contribute, so again we can use particle's // weight entering the collision as the estimate for the fission // reaction rate - if (p.neutron_xs_[p.event_nuclide_].absorption > 0) { - return p.wgt_last_ * get_nuc_fission_q(nuc, p, score_bin) - * p.neutron_xs_[p.event_nuclide_].fission * flux - / p.neutron_xs_[p.event_nuclide_].absorption; + if (p.neutron_xs(p.event_nuclide()).absorption > 0) { + return p.wgt_last() * get_nuc_fission_q(nuc, p, score_bin) * + p.neutron_xs(p.event_nuclide()).fission * flux / + p.neutron_xs(p.event_nuclide()).absorption; } } } else { if (i_nuclide >= 0) { const Nuclide& nuc {*data::nuclides[i_nuclide]}; - return get_nuc_fission_q(nuc, p, score_bin) * atom_density * flux - * p.neutron_xs_[i_nuclide].fission; - } else if (p.material_ != MATERIAL_VOID) { - const Material& material {*model::materials[p.material_]}; + return get_nuc_fission_q(nuc, p, score_bin) * atom_density * flux * + p.neutron_xs(i_nuclide).fission; + } else if (p.material() != MATERIAL_VOID) { + const Material& material {*model::materials[p.material()]}; double score {0.0}; for (auto i = 0; i < material.nuclide_.size(); ++i) { auto j_nuclide = material.nuclide_[i]; auto atom_density = material.atom_density_(i); const Nuclide& nuc {*data::nuclides[j_nuclide]}; - score += get_nuc_fission_q(nuc, p, score_bin) * atom_density - * p.neutron_xs_[j_nuclide].fission; + score += get_nuc_fission_q(nuc, p, score_bin) * atom_density * + p.neutron_xs(j_nuclide).fission; } return score * flux; } @@ -251,24 +251,26 @@ double get_nuclide_neutron_heating(const Particle& p, const Nuclide& nuc, size_t mt = nuc.reaction_index_[rxn_index]; if (mt == C_NONE) return 0.0; - auto i_temp = p.neutron_xs_[i_nuclide].index_temp; + auto i_temp = p.neutron_xs(i_nuclide).index_temp; if (i_temp < 0) return 0.0; // Can be true due to multipole const auto& rxn {*nuc.reactions_[mt]}; const auto& xs {rxn.xs_[i_temp]}; - auto i_grid = p.neutron_xs_[i_nuclide].index_grid; + auto i_grid = p.neutron_xs(i_nuclide).index_grid; if (i_grid < xs.threshold) return 0.0; // Determine total kerma - auto f = p.neutron_xs_[i_nuclide].interp_factor; + auto f = p.neutron_xs(i_nuclide).interp_factor; double kerma = (1.0 - f) * xs.value[i_grid-xs.threshold] + f * xs.value[i_grid-xs.threshold+1]; if (settings::run_mode == RunMode::EIGENVALUE) { // Determine kerma for fission as (EFR + EB)*sigma_f - double kerma_fission = nuc.fragments_ ? - ((*nuc.fragments_)(p.E_last_) + (*nuc.betas_)(p.E_last_)) - *p.neutron_xs_[i_nuclide].fission : 0.0; + double kerma_fission = + nuc.fragments_ + ? ((*nuc.fragments_)(p.E_last()) + (*nuc.betas_)(p.E_last())) * + p.neutron_xs(i_nuclide).fission + : 0.0; // Determine non-fission kerma as difference double kerma_non_fission = kerma - kerma_fission; @@ -294,14 +296,14 @@ double score_neutron_heating(const Particle& p, const Tally& tally, double flux, const Nuclide& nuc {*data::nuclides[i_nuclide]}; heating_xs = get_nuclide_neutron_heating(p, nuc, rxn_bin, i_nuclide); if (tally.estimator_ == TallyEstimator::ANALOG) { - heating_xs /= p.neutron_xs_[i_nuclide].total; + heating_xs /= p.neutron_xs(i_nuclide).total; } else { heating_xs *= atom_density; } } else { - if (p.material_ != MATERIAL_VOID) { + if (p.material() != MATERIAL_VOID) { heating_xs = 0.0; - const Material& material {*model::materials[p.material_]}; + const Material& material {*model::materials[p.material()]}; for (auto i = 0; i< material.nuclide_.size(); ++i) { int j_nuclide = material.nuclide_[i]; double atom_density {material.atom_density_(i)}; @@ -309,7 +311,7 @@ double score_neutron_heating(const Particle& p, const Tally& tally, double flux, heating_xs += atom_density * get_nuclide_neutron_heating(p, nuc, rxn_bin, j_nuclide); } if (tally.estimator_ == TallyEstimator::ANALOG) { - heating_xs /= p.macro_xs_.total; + heating_xs /= p.macro_xs().total; } } } @@ -320,9 +322,9 @@ double score_neutron_heating(const Particle& p, const Tally& tally, double flux, // reaction-wise heating cross section if (settings::survival_biasing) { // Account for the fact that some weight has been absorbed - score *= p.wgt_last_ + p.wgt_absorb_; + score *= p.wgt_last() + p.wgt_absorb(); } else { - score *= p.wgt_last_; + score *= p.wgt_last(); } } return score; @@ -338,8 +340,8 @@ score_fission_eout(Particle& p, int i_tally, int i_score, int score_bin) { auto& tally {*model::tallies[i_tally]}; auto i_eout_filt = tally.filters()[tally.energyout_filter_]; - auto i_bin = p.filter_matches_[i_eout_filt].i_bin_; - auto bin_energyout = p.filter_matches_[i_eout_filt].bins_[i_bin]; + auto i_bin = p.filter_matches(i_eout_filt).i_bin_; + auto bin_energyout = p.filter_matches(i_eout_filt).bins_[i_bin]; const EnergyoutFilter& eo_filt {*dynamic_cast(model::tally_filters[i_eout_filt].get())}; @@ -350,8 +352,8 @@ score_fission_eout(Particle& p, int i_tally, int i_score, int score_bin) // rate. Otherwise, the sum of all nu-fission rates would be ~1.0. // loop over number of particles banked - for (auto i = 0; i < p.n_bank_; ++i) { - const auto& bank = p.nu_bank_[i]; + for (auto i = 0; i < p.n_bank(); ++i) { + const auto& bank = p.nu_bank(i); // get the delayed group auto g = bank.delayed_group; @@ -375,7 +377,7 @@ score_fission_eout(Particle& p, int i_tally, int i_score, int score_bin) g_out = eo_filt.n_bins() - g_out - 1; // change outgoing energy bin - p.filter_matches_[i_eout_filt].bins_[i_bin] = g_out; + p.filter_matches(i_eout_filt).bins_[i_bin] = g_out; } else { @@ -392,7 +394,7 @@ score_fission_eout(Particle& p, int i_tally, int i_score, int score_bin) } else { auto i_match = lower_bound_index(eo_filt.bins().begin(), eo_filt.bins().end(), E_out); - p.filter_matches_[i_eout_filt].bins_[i_bin] = i_match; + p.filter_matches(i_eout_filt).bins_[i_bin] = i_match; } } @@ -406,7 +408,7 @@ score_fission_eout(Particle& p, int i_tally, int i_score, int score_bin) double filter_weight = 1.0; for (auto j = 0; j < tally.filters().size(); ++j) { auto i_filt = tally.filters(j); - auto& match {p.filter_matches_[i_filt]}; + auto& match {p.filter_matches(i_filt)}; auto i_bin = match.i_bin_; filter_index += match.bins_[i_bin] * tally.strides(j); filter_weight *= match.weights_[i_bin]; @@ -435,13 +437,13 @@ score_fission_eout(Particle& p, int i_tally, int i_score, int score_bin) double filter_weight = 1.; for (auto j = 0; j < tally.filters().size(); ++j) { auto i_filt = tally.filters(j); - auto& match {p.filter_matches_[i_filt]}; + auto& match {p.filter_matches(i_filt)}; auto i_bin = match.i_bin_; filter_weight *= match.weights_[i_bin]; } - score_fission_delayed_dg(i_tally, d_bin, score*filter_weight, - i_score, p.filter_matches_); + score_fission_delayed_dg(i_tally, d_bin, score * filter_weight, + i_score, p.filter_matches()); } } @@ -453,7 +455,7 @@ score_fission_eout(Particle& p, int i_tally, int i_score, int score_bin) double filter_weight = 1.; for (auto j = 0; j < tally.filters().size(); ++j) { auto i_filt = tally.filters(j); - auto& match {p.filter_matches_[i_filt]}; + auto& match {p.filter_matches(i_filt)}; auto i_bin = match.i_bin_; filter_index += match.bins_[i_bin] * tally.strides(j); filter_weight *= match.weights_[i_bin]; @@ -467,7 +469,7 @@ score_fission_eout(Particle& p, int i_tally, int i_score, int score_bin) } // Reset outgoing energy bin and score index - p.filter_matches_[i_eout_filt].bins_[i_bin] = bin_energyout; + p.filter_matches(i_eout_filt).bins_[i_bin] = bin_energyout; } double get_nuclide_xs(const Particle& p, int i_nuclide, int score_bin) { @@ -477,7 +479,7 @@ double get_nuclide_xs(const Particle& p, int i_nuclide, int score_bin) { auto m = nuc.reaction_index_[score_bin]; if (m == C_NONE) return 0.0; const auto& rxn {*nuc.reactions_[m]}; - const auto& micro {p.neutron_xs_[i_nuclide]}; + const auto& micro {p.neutron_xs(i_nuclide)}; // In the URR, the (n,gamma) cross section is sampled randomly from // probability tables. Make sure we use the sampled value (which is equal to @@ -504,10 +506,13 @@ double get_nuclide_xs(const Particle& p, int i_nuclide, int score_bin) { if (settings::run_mode == RunMode::EIGENVALUE && score_bin == HEATING_LOCAL) { // Determine kerma for fission as (EFR + EGP + EGD + EB)*sigma_f - double kerma_fission = nuc.fragments_ ? - ((*nuc.fragments_)(p.E_last_) + (*nuc.betas_)(p.E_last_) + - (*nuc.prompt_photons_)(p.E_last_) + (*nuc.delayed_photons_)(p.E_last_)) - * micro.fission : 0.0; + double kerma_fission = + nuc.fragments_ + ? ((*nuc.fragments_)(p.E_last()) + (*nuc.betas_)(p.E_last()) + + (*nuc.prompt_photons_)(p.E_last()) + + (*nuc.delayed_photons_)(p.E_last())) * + micro.fission + : 0.0; // Determine non-fission kerma as difference double kerma_non_fission = value - kerma_fission; @@ -539,9 +544,9 @@ score_general_ce(Particle& p, int i_tally, int start_index, int filter_index, Tally& tally {*model::tallies[i_tally]}; // Get the pre-collision energy of the particle. - auto E = p.E_last_; + auto E = p.E_last(); - using Type = Particle::Type; + using Type = ParticleType; for (auto i = 0; i < tally.scores_.size(); ++i) { auto score_bin = tally.scores_[i]; @@ -557,13 +562,13 @@ score_general_ce(Particle& p, int i_tally, int start_index, int filter_index, if (settings::survival_biasing) { // We need to account for the fact that some weight was already // absorbed - score = p.wgt_last_ + p.wgt_absorb_; + score = p.wgt_last() + p.wgt_absorb(); } else { - score = p.wgt_last_; + score = p.wgt_last(); } - if (p.type_ == Type::neutron || p.type_ == Type::photon) { - score *= flux / p.macro_xs_.total; + if (p.type() == Type::neutron || p.type() == Type::photon) { + score *= flux / p.macro_xs().total; } else { score = 0.; } @@ -580,27 +585,28 @@ score_general_ce(Particle& p, int i_tally, int start_index, int filter_index, if (settings::survival_biasing) { // We need to account for the fact that some weight was already // absorbed - score = (p.wgt_last_ + p.wgt_absorb_) * flux; + score = (p.wgt_last() + p.wgt_absorb()) * flux; } else { - score = p.wgt_last_ * flux; + score = p.wgt_last() * flux; } } else { if (i_nuclide >= 0) { - if (p.type_ == Type::neutron) { - score = p.neutron_xs_[i_nuclide].total * atom_density * flux; - } else if (p.type_ == Type::photon) { - score = p.photon_xs_[i_nuclide].total * atom_density * flux; + if (p.type() == Type::neutron) { + score = p.neutron_xs(i_nuclide).total * atom_density * flux; + } else if (p.type() == Type::photon) { + score = p.photon_xs(i_nuclide).total * atom_density * flux; } } else { - score = p.macro_xs_.total * flux; + score = p.macro_xs().total * flux; } } break; case SCORE_INVERSE_VELOCITY: - if (p.type_ != Type::neutron) continue; + if (p.type() != Type::neutron) + continue; if (tally.estimator_ == TallyEstimator::ANALOG) { // All events score to an inverse velocity bin. We actually use a @@ -609,11 +615,11 @@ score_general_ce(Particle& p, int i_tally, int start_index, int filter_index, if (settings::survival_biasing) { // We need to account for the fact that some weight was already // absorbed - score = p.wgt_last_ + p.wgt_absorb_; + score = p.wgt_last() + p.wgt_absorb(); } else { - score = p.wgt_last_; + score = p.wgt_last(); } - score *= flux / p.macro_xs_.total; + score *= flux / p.macro_xs().total; } else { score = flux; } @@ -623,28 +629,30 @@ score_general_ce(Particle& p, int i_tally, int start_index, int filter_index, case SCORE_SCATTER: - if (p.type_ != Type::neutron && p.type_ != Type::photon) continue; + if (p.type() != Type::neutron && p.type() != Type::photon) + continue; if (tally.estimator_ == TallyEstimator::ANALOG) { // Skip any event where the particle didn't scatter - if (p.event_ != TallyEvent::SCATTER) continue; + if (p.event() != TallyEvent::SCATTER) + continue; // Since only scattering events make it here, again we can use the // weight entering the collision as the estimator for the reaction rate - score = p.wgt_last_ * flux; + score = p.wgt_last() * flux; } else { if (i_nuclide >= 0) { - if (p.type_ == Type::neutron) { - const auto& micro = p.neutron_xs_[i_nuclide]; + if (p.type() == Type::neutron) { + const auto& micro = p.neutron_xs(i_nuclide); score = (micro.total - micro.absorption) * atom_density * flux; } else { - const auto& micro = p.photon_xs_[i_nuclide]; + const auto& micro = p.photon_xs(i_nuclide); score = (micro.coherent + micro.incoherent) * atom_density * flux; } } else { - if (p.type_ == Type::neutron) { - score = (p.macro_xs_.total - p.macro_xs_.absorption) * flux; + if (p.type() == Type::neutron) { + score = (p.macro_xs().total - p.macro_xs().absorption) * flux; } else { - score = (p.macro_xs_.coherent + p.macro_xs_.incoherent) * flux; + score = (p.macro_xs().coherent + p.macro_xs().incoherent) * flux; } } } @@ -652,56 +660,63 @@ score_general_ce(Particle& p, int i_tally, int start_index, int filter_index, case SCORE_NU_SCATTER: - if (p.type_ != Type::neutron) continue; + if (p.type() != Type::neutron) + continue; // Only analog estimators are available. // Skip any event where the particle didn't scatter - if (p.event_ != TallyEvent::SCATTER) continue; + if (p.event() != TallyEvent::SCATTER) + continue; // For scattering production, we need to use the pre-collision weight // times the yield as the estimate for the number of neutrons exiting a // reaction with neutrons in the exit channel - if (p.event_mt_ == ELASTIC || p.event_mt_ == N_LEVEL || - (p.event_mt_ >= N_N1 && p.event_mt_ <= N_NC)) { + if (p.event_mt() == ELASTIC || p.event_mt() == N_LEVEL || + (p.event_mt() >= N_N1 && p.event_mt() <= N_NC)) { // Don't waste time on very common reactions we know have // multiplicities of one. - score = p.wgt_last_ * flux; + score = p.wgt_last() * flux; } else { // Get yield and apply to score - auto m = data::nuclides[p.event_nuclide_]->reaction_index_[p.event_mt_]; - const auto& rxn {*data::nuclides[p.event_nuclide_]->reactions_[m]}; - score = p.wgt_last_ * flux * (*rxn.products_[0].yield_)(E); + auto m = + data::nuclides[p.event_nuclide()]->reaction_index_[p.event_mt()]; + const auto& rxn {*data::nuclides[p.event_nuclide()]->reactions_[m]}; + score = p.wgt_last() * flux * (*rxn.products_[0].yield_)(E); } break; case SCORE_ABSORPTION: - if (p.type_ != Type::neutron && p.type_ != Type::photon) continue; + if (p.type() != Type::neutron && p.type() != Type::photon) + continue; if (tally.estimator_ == TallyEstimator::ANALOG) { if (settings::survival_biasing) { // No absorption events actually occur if survival biasing is on -- // just use weight absorbed in survival biasing - score = p.wgt_absorb_ * flux; + score = p.wgt_absorb() * flux; } else { // Skip any event where the particle wasn't absorbed - if (p.event_ == TallyEvent::SCATTER) continue; + if (p.event() == TallyEvent::SCATTER) + continue; // All fission and absorption events will contribute here, so we // can just use the particle's weight entering the collision - score = p.wgt_last_ * flux; + score = p.wgt_last() * flux; } } else { if (i_nuclide >= 0) { - if (p.type_ == Type::neutron) { - score = p.neutron_xs_[i_nuclide].absorption * atom_density * flux; + if (p.type() == Type::neutron) { + score = p.neutron_xs(i_nuclide).absorption * atom_density * flux; } else { - const auto& xs = p.photon_xs_[i_nuclide]; + const auto& xs = p.photon_xs(i_nuclide); score = (xs.total - xs.coherent - xs.incoherent) * atom_density * flux; } } else { - if (p.type_ == Type::neutron) { - score = p.macro_xs_.absorption * flux; + if (p.type() == Type::neutron) { + score = p.macro_xs().absorption * flux; } else { - score = (p.macro_xs_.photoelectric + p.macro_xs_.pair_production) * flux; + score = + (p.macro_xs().photoelectric + p.macro_xs().pair_production) * + flux; } } } @@ -709,43 +724,44 @@ score_general_ce(Particle& p, int i_tally, int start_index, int filter_index, case SCORE_FISSION: - if (p.macro_xs_.absorption == 0) continue; + if (p.macro_xs().absorption == 0) + continue; if (tally.estimator_ == TallyEstimator::ANALOG) { if (settings::survival_biasing) { // No fission events occur if survival biasing is on -- need to // calculate fraction of absorptions that would have resulted in // fission - if (p.neutron_xs_[p.event_nuclide_].absorption > 0) { - score = p.wgt_absorb_ - * p.neutron_xs_[p.event_nuclide_].fission - / p.neutron_xs_[p.event_nuclide_].absorption * flux; + if (p.neutron_xs(p.event_nuclide()).absorption > 0) { + score = p.wgt_absorb() * p.neutron_xs(p.event_nuclide()).fission / + p.neutron_xs(p.event_nuclide()).absorption * flux; } else { score = 0.; } } else { // Skip any non-absorption events - if (p.event_ == TallyEvent::SCATTER) continue; + if (p.event() == TallyEvent::SCATTER) + continue; // All fission events will contribute, so again we can use particle's // weight entering the collision as the estimate for the fission // reaction rate - score = p.wgt_last_ - * p.neutron_xs_[p.event_nuclide_].fission - / p.neutron_xs_[p.event_nuclide_].absorption * flux; + score = p.wgt_last() * p.neutron_xs(p.event_nuclide()).fission / + p.neutron_xs(p.event_nuclide()).absorption * flux; } } else { if (i_nuclide >= 0) { - score = p.neutron_xs_[i_nuclide].fission * atom_density * flux; + score = p.neutron_xs(i_nuclide).fission * atom_density * flux; } else { - score = p.macro_xs_.fission * flux; + score = p.macro_xs().fission * flux; } } break; case SCORE_NU_FISSION: - if (p.macro_xs_.absorption == 0) continue; + if (p.macro_xs().absorption == 0) + continue; if (tally.estimator_ == TallyEstimator::ANALOG) { - if (settings::survival_biasing || p.fission_) { + if (settings::survival_biasing || p.fission()) { if (tally.energyout_filter_ != C_NONE) { // Fission has multiple outgoing neutrons so this helper function // is used to handle scoring the multiple filter bins. @@ -757,38 +773,39 @@ score_general_ce(Particle& p, int i_tally, int start_index, int filter_index, // No fission events occur if survival biasing is on -- need to // calculate fraction of absorptions that would have resulted in // nu-fission - if (p.neutron_xs_[p.event_nuclide_].absorption > 0) { - score = p.wgt_absorb_ - * p.neutron_xs_[p.event_nuclide_].nu_fission - / p.neutron_xs_[p.event_nuclide_].absorption * flux; + if (p.neutron_xs(p.event_nuclide()).absorption > 0) { + score = p.wgt_absorb() * + p.neutron_xs(p.event_nuclide()).nu_fission / + p.neutron_xs(p.event_nuclide()).absorption * flux; } else { score = 0.; } } else { // Skip any non-fission events - if (!p.fission_) continue; + if (!p.fission()) + continue; // If there is no outgoing energy filter, than we only need to score // to one bin. For the score to be 'analog', we need to score the // number of particles that were banked in the fission bank. Since // this was weighted by 1/keff, we multiply by keff to get the proper // score. - score = simulation::keff * p.wgt_bank_ * flux; + score = simulation::keff * p.wgt_bank() * flux; } } else { if (i_nuclide >= 0) { - score = p.neutron_xs_[i_nuclide].nu_fission * atom_density - * flux; + score = p.neutron_xs(i_nuclide).nu_fission * atom_density * flux; } else { - score = p.macro_xs_.nu_fission * flux; + score = p.macro_xs().nu_fission * flux; } } break; case SCORE_PROMPT_NU_FISSION: - if (p.macro_xs_.absorption == 0) continue; + if (p.macro_xs().absorption == 0) + continue; if (tally.estimator_ == TallyEstimator::ANALOG) { - if (settings::survival_biasing || p.fission_) { + if (settings::survival_biasing || p.fission()) { if (tally.energyout_filter_ != C_NONE) { // Fission has multiple outgoing neutrons so this helper function // is used to handle scoring the multiple filter bins. @@ -800,46 +817,46 @@ score_general_ce(Particle& p, int i_tally, int start_index, int filter_index, // No fission events occur if survival biasing is on -- need to // calculate fraction of absorptions that would have resulted in // prompt-nu-fission - if (p.neutron_xs_[p.event_nuclide_].absorption > 0) { - score = p.wgt_absorb_ - * p.neutron_xs_[p.event_nuclide_].fission - * data::nuclides[p.event_nuclide_] - ->nu(E, ReactionProduct::EmissionMode::prompt) - / p.neutron_xs_[p.event_nuclide_].absorption * flux; + if (p.neutron_xs(p.event_nuclide()).absorption > 0) { + score = p.wgt_absorb() * p.neutron_xs(p.event_nuclide()).fission * + data::nuclides[p.event_nuclide()]->nu( + E, ReactionProduct::EmissionMode::prompt) / + p.neutron_xs(p.event_nuclide()).absorption * flux; } else { score = 0.; } } else { // Skip any non-fission events - if (!p.fission_) continue; + if (!p.fission()) + continue; // If there is no outgoing energy filter, than we only need to score // to one bin. For the score to be 'analog', we need to score the // number of particles that were banked in the fission bank. Since // this was weighted by 1/keff, we multiply by keff to get the proper // score. - auto n_delayed = std::accumulate(p.n_delayed_bank_, - p.n_delayed_bank_+MAX_DELAYED_GROUPS, 0); - auto prompt_frac = 1. - n_delayed / static_cast(p.n_bank_); - score = simulation::keff * p.wgt_bank_ * prompt_frac * flux; + auto n_delayed = std::accumulate( + p.n_delayed_bank(), p.n_delayed_bank() + MAX_DELAYED_GROUPS, 0); + auto prompt_frac = 1. - n_delayed / static_cast(p.n_bank()); + score = simulation::keff * p.wgt_bank() * prompt_frac * flux; } } else { if (i_nuclide >= 0) { - score = p.neutron_xs_[i_nuclide].fission - * data::nuclides[i_nuclide] - ->nu(E, ReactionProduct::EmissionMode::prompt) - * atom_density * flux; + score = p.neutron_xs(i_nuclide).fission * + data::nuclides[i_nuclide]->nu( + E, ReactionProduct::EmissionMode::prompt) * + atom_density * flux; } else { score = 0.; // Add up contributions from each nuclide in the material. - if (p.material_ != MATERIAL_VOID) { - const Material& material {*model::materials[p.material_]}; + if (p.material() != MATERIAL_VOID) { + const Material& material {*model::materials[p.material()]}; for (auto i = 0; i < material.nuclide_.size(); ++i) { auto j_nuclide = material.nuclide_[i]; auto atom_density = material.atom_density_(i); - score += p.neutron_xs_[j_nuclide].fission - * data::nuclides[j_nuclide] - ->nu(E, ReactionProduct::EmissionMode::prompt) - * atom_density * flux; + score += p.neutron_xs(j_nuclide).fission * + data::nuclides[j_nuclide]->nu( + E, ReactionProduct::EmissionMode::prompt) * + atom_density * flux; } } } @@ -848,9 +865,10 @@ score_general_ce(Particle& p, int i_tally, int start_index, int filter_index, case SCORE_DELAYED_NU_FISSION: - if (p.macro_xs_.absorption == 0) continue; + if (p.macro_xs().absorption == 0) + continue; if (tally.estimator_ == TallyEstimator::ANALOG) { - if (settings::survival_biasing || p.fission_) { + if (settings::survival_biasing || p.fission()) { if (tally.energyout_filter_ != C_NONE) { // Fission has multiple outgoing neutrons so this helper function // is used to handle scoring the multiple filter bins. @@ -862,8 +880,8 @@ score_general_ce(Particle& p, int i_tally, int start_index, int filter_index, // No fission events occur if survival biasing is on -- need to // calculate fraction of absorptions that would have resulted in // delayed-nu-fission - if (p.neutron_xs_[p.event_nuclide_].absorption > 0 - && data::nuclides[p.event_nuclide_]->fissionable_) { + if (p.neutron_xs(p.event_nuclide()).absorption > 0 && + data::nuclides[p.event_nuclide()]->fissionable_) { if (tally.delayedgroup_filter_ != C_NONE) { auto i_dg_filt = tally.filters()[tally.delayedgroup_filter_]; const DelayedGroupFilter& filt @@ -872,29 +890,29 @@ score_general_ce(Particle& p, int i_tally, int start_index, int filter_index, // Tally each delayed group bin individually for (auto d_bin = 0; d_bin < filt.n_bins(); ++d_bin) { auto dg = filt.groups()[d_bin]; - auto yield = data::nuclides[p.event_nuclide_] - ->nu(E, ReactionProduct::EmissionMode::delayed, dg); - score = p.wgt_absorb_ * yield - * p.neutron_xs_[p.event_nuclide_].fission - / p.neutron_xs_[p.event_nuclide_].absorption * flux; - score_fission_delayed_dg(i_tally, d_bin, score, - score_index, p.filter_matches_); + auto yield = data::nuclides[p.event_nuclide()]->nu( + E, ReactionProduct::EmissionMode::delayed, dg); + score = p.wgt_absorb() * yield * + p.neutron_xs(p.event_nuclide()).fission / + p.neutron_xs(p.event_nuclide()).absorption * flux; + score_fission_delayed_dg( + i_tally, d_bin, score, score_index, p.filter_matches()); } continue; } else { // If the delayed group filter is not present, compute the score // by multiplying the absorbed weight by the fraction of the // delayed-nu-fission xs to the absorption xs - score = p.wgt_absorb_ - * p.neutron_xs_[p.event_nuclide_].fission - * data::nuclides[p.event_nuclide_] - ->nu(E, ReactionProduct::EmissionMode::delayed) - / p.neutron_xs_[p.event_nuclide_].absorption *flux; + score = p.wgt_absorb() * p.neutron_xs(p.event_nuclide()).fission * + data::nuclides[p.event_nuclide()]->nu( + E, ReactionProduct::EmissionMode::delayed) / + p.neutron_xs(p.event_nuclide()).absorption * flux; } } } else { // Skip any non-fission events - if (!p.fission_) continue; + if (!p.fission()) + continue; // If there is no outgoing energy filter, than we only need to score // to one bin. For the score to be 'analog', we need to score the // number of particles that were banked in the fission bank. Since @@ -910,17 +928,18 @@ score_general_ce(Particle& p, int i_tally, int start_index, int filter_index, // Tally each delayed group bin individually for (auto d_bin = 0; d_bin < filt.n_bins(); ++d_bin) { auto d = filt.groups()[d_bin]; - score = simulation::keff * p.wgt_bank_ / p.n_bank_ - * p.n_delayed_bank_[d-1] * flux; - score_fission_delayed_dg(i_tally, d_bin, score, score_index, p.filter_matches_); + score = simulation::keff * p.wgt_bank() / p.n_bank() * + p.n_delayed_bank(d - 1) * flux; + score_fission_delayed_dg( + i_tally, d_bin, score, score_index, p.filter_matches()); } continue; } else { // Add the contribution from all delayed groups - auto n_delayed = std::accumulate(p.n_delayed_bank_, - p.n_delayed_bank_+MAX_DELAYED_GROUPS, 0); - score = simulation::keff * p.wgt_bank_ / p.n_bank_ * n_delayed - * flux; + auto n_delayed = std::accumulate( + p.n_delayed_bank(), p.n_delayed_bank() + MAX_DELAYED_GROUPS, 0); + score = + simulation::keff * p.wgt_bank() / p.n_bank() * n_delayed * flux; } } } else { @@ -935,18 +954,19 @@ score_general_ce(Particle& p, int i_tally, int start_index, int filter_index, auto d = filt.groups()[d_bin]; auto yield = data::nuclides[i_nuclide] ->nu(E, ReactionProduct::EmissionMode::delayed, d); - score = p.neutron_xs_[i_nuclide].fission * yield - * atom_density * flux; - score_fission_delayed_dg(i_tally, d_bin, score, score_index, p.filter_matches_); + score = + p.neutron_xs(i_nuclide).fission * yield * atom_density * flux; + score_fission_delayed_dg( + i_tally, d_bin, score, score_index, p.filter_matches()); } continue; } else { // If the delayed group filter is not present, compute the score // by multiplying the delayed-nu-fission macro xs by the flux - score = p.neutron_xs_[i_nuclide].fission - * data::nuclides[i_nuclide] - ->nu(E, ReactionProduct::EmissionMode::delayed) - * atom_density * flux; + score = p.neutron_xs(i_nuclide).fission * + data::nuclides[i_nuclide]->nu( + E, ReactionProduct::EmissionMode::delayed) * + atom_density * flux; } } else { // Need to add up contributions for each nuclide @@ -955,8 +975,8 @@ score_general_ce(Particle& p, int i_tally, int start_index, int filter_index, const DelayedGroupFilter& filt {*dynamic_cast( model::tally_filters[i_dg_filt].get())}; - if (p.material_ != MATERIAL_VOID) { - const Material& material {*model::materials[p.material_]}; + if (p.material() != MATERIAL_VOID) { + const Material& material {*model::materials[p.material()]}; for (auto i = 0; i < material.nuclide_.size(); ++i) { auto j_nuclide = material.nuclide_[i]; auto atom_density = material.atom_density_(i); @@ -965,25 +985,25 @@ score_general_ce(Particle& p, int i_tally, int start_index, int filter_index, auto d = filt.groups()[d_bin]; auto yield = data::nuclides[j_nuclide] ->nu(E, ReactionProduct::EmissionMode::delayed, d); - score = p.neutron_xs_[j_nuclide].fission * yield - * atom_density * flux; - score_fission_delayed_dg(i_tally, d_bin, score, - score_index, p.filter_matches_); + score = p.neutron_xs(j_nuclide).fission * yield * + atom_density * flux; + score_fission_delayed_dg( + i_tally, d_bin, score, score_index, p.filter_matches()); } } } continue; } else { score = 0.; - if (p.material_ != MATERIAL_VOID) { - const Material& material {*model::materials[p.material_]}; + if (p.material() != MATERIAL_VOID) { + const Material& material {*model::materials[p.material()]}; for (auto i = 0; i < material.nuclide_.size(); ++i) { auto j_nuclide = material.nuclide_[i]; auto atom_density = material.atom_density_(i); - score += p.neutron_xs_[j_nuclide].fission - * data::nuclides[j_nuclide] - ->nu(E, ReactionProduct::EmissionMode::delayed) - * atom_density * flux; + score += p.neutron_xs(j_nuclide).fission * + data::nuclides[j_nuclide]->nu( + E, ReactionProduct::EmissionMode::delayed) * + atom_density * flux; } } } @@ -993,15 +1013,16 @@ score_general_ce(Particle& p, int i_tally, int start_index, int filter_index, case SCORE_DECAY_RATE: - if (p.macro_xs_.absorption == 0) continue; + if (p.macro_xs().absorption == 0) + continue; if (tally.estimator_ == TallyEstimator::ANALOG) { if (settings::survival_biasing) { // No fission events occur if survival biasing is on -- need to // calculate fraction of absorptions that would have resulted in // delayed-nu-fission - const auto& nuc {*data::nuclides[p.event_nuclide_]}; - if (p.neutron_xs_[p.event_nuclide_].absorption > 0 - && nuc.fissionable_) { + const auto& nuc {*data::nuclides[p.event_nuclide()]}; + if (p.neutron_xs(p.event_nuclide()).absorption > 0 && + nuc.fissionable_) { const auto& rxn {*nuc.fission_rx_[0]}; if (tally.delayedgroup_filter_ != C_NONE) { auto i_dg_filt = tally.filters()[tally.delayedgroup_filter_]; @@ -1014,12 +1035,12 @@ score_general_ce(Particle& p, int i_tally, int start_index, int filter_index, auto yield = nuc.nu(E, ReactionProduct::EmissionMode::delayed, d); auto rate = rxn.products_[d].decay_rate_; - score = p.wgt_absorb_ * yield - * p.neutron_xs_[p.event_nuclide_].fission - / p.neutron_xs_[p.event_nuclide_].absorption - * rate * flux; - score_fission_delayed_dg(i_tally, d_bin, score, - score_index, p.filter_matches_); + score = p.wgt_absorb() * yield * + p.neutron_xs(p.event_nuclide()).fission / + p.neutron_xs(p.event_nuclide()).absorption * rate * + flux; + score_fission_delayed_dg( + i_tally, d_bin, score, score_index, p.filter_matches()); } continue; } else { @@ -1037,15 +1058,16 @@ score_general_ce(Particle& p, int i_tally, int start_index, int filter_index, auto yield = nuc.nu(E, ReactionProduct::EmissionMode::delayed, d+1); auto rate = rxn.products_[d+1].decay_rate_; - score += rate * p.wgt_absorb_ - * p.neutron_xs_[p.event_nuclide_].fission * yield - / p.neutron_xs_[p.event_nuclide_].absorption * flux; + score += rate * p.wgt_absorb() * + p.neutron_xs(p.event_nuclide()).fission * yield / + p.neutron_xs(p.event_nuclide()).absorption * flux; } } } } else { // Skip any non-fission events - if (!p.fission_) continue; + if (!p.fission()) + continue; // If there is no outgoing energy filter, than we only need to score // to one bin. For the score to be 'analog', we need to score the // number of particles that were banked in the fission bank. Since @@ -1054,11 +1076,11 @@ score_general_ce(Particle& p, int i_tally, int start_index, int filter_index, // ones are delayed. If a delayed neutron is encountered, add its // contribution to the fission bank to the score. score = 0.; - for (auto i = 0; i < p.n_bank_; ++i) { - const auto& bank = p.nu_bank_[i]; + for (auto i = 0; i < p.n_bank(); ++i) { + const auto& bank = p.nu_bank(i); auto g = bank.delayed_group; if (g != 0) { - const auto& nuc {*data::nuclides[p.event_nuclide_]}; + const auto& nuc {*data::nuclides[p.event_nuclide()]}; const auto& rxn {*nuc.fission_rx_[0]}; auto rate = rxn.products_[g].decay_rate_; score += simulation::keff * bank.wgt * rate * flux; @@ -1071,8 +1093,8 @@ score_general_ce(Particle& p, int i_tally, int start_index, int filter_index, for (auto d_bin = 0; d_bin < filt.n_bins(); ++d_bin) { auto d = filt.groups()[d_bin]; if (d == g) - score_fission_delayed_dg(i_tally, d_bin, score, - score_index, p.filter_matches_); + score_fission_delayed_dg( + i_tally, d_bin, score, score_index, p.filter_matches()); } score = 0.; } @@ -1095,9 +1117,10 @@ score_general_ce(Particle& p, int i_tally, int start_index, int filter_index, auto yield = nuc.nu(E, ReactionProduct::EmissionMode::delayed, d); auto rate = rxn.products_[d].decay_rate_; - score = p.neutron_xs_[i_nuclide].fission * yield * flux - * atom_density * rate; - score_fission_delayed_dg(i_tally, d_bin, score, score_index, p.filter_matches_); + score = p.neutron_xs(i_nuclide).fission * yield * flux * + atom_density * rate; + score_fission_delayed_dg( + i_tally, d_bin, score, score_index, p.filter_matches()); } continue; } else { @@ -1111,8 +1134,8 @@ score_general_ce(Particle& p, int i_tally, int start_index, int filter_index, auto yield = nuc.nu(E, ReactionProduct::EmissionMode::delayed, d+1); auto rate = rxn.products_[d+1].decay_rate_; - score += p.neutron_xs_[i_nuclide].fission * flux - * yield * atom_density * rate; + score += p.neutron_xs(i_nuclide).fission * flux * yield * + atom_density * rate; } } } else { @@ -1121,8 +1144,8 @@ score_general_ce(Particle& p, int i_tally, int start_index, int filter_index, const DelayedGroupFilter& filt {*dynamic_cast( model::tally_filters[i_dg_filt].get())}; - if (p.material_ != MATERIAL_VOID) { - const Material& material {*model::materials[p.material_]}; + if (p.material() != MATERIAL_VOID) { + const Material& material {*model::materials[p.material()]}; for (auto i = 0; i < material.nuclide_.size(); ++i) { auto j_nuclide = material.nuclide_[i]; auto atom_density = material.atom_density_(i); @@ -1135,10 +1158,10 @@ score_general_ce(Particle& p, int i_tally, int start_index, int filter_index, auto yield = nuc.nu(E, ReactionProduct::EmissionMode::delayed, d); auto rate = rxn.products_[d].decay_rate_; - score = p.neutron_xs_[j_nuclide].fission * yield - * flux * atom_density * rate; - score_fission_delayed_dg(i_tally, d_bin, score, - score_index, p.filter_matches_); + score = p.neutron_xs(j_nuclide).fission * yield * flux * + atom_density * rate; + score_fission_delayed_dg( + i_tally, d_bin, score, score_index, p.filter_matches()); } } } @@ -1146,8 +1169,8 @@ score_general_ce(Particle& p, int i_tally, int start_index, int filter_index, continue; } else { score = 0.; - if (p.material_ != MATERIAL_VOID) { - const Material& material {*model::materials[p.material_]}; + if (p.material() != MATERIAL_VOID) { + const Material& material {*model::materials[p.material()]}; for (auto i = 0; i < material.nuclide_.size(); ++i) { auto j_nuclide = material.nuclide_[i]; auto atom_density = material.atom_density_(i); @@ -1163,8 +1186,8 @@ score_general_ce(Particle& p, int i_tally, int start_index, int filter_index, auto yield = nuc.nu(E, ReactionProduct::EmissionMode::delayed, d+1); auto rate = rxn.products_[d+1].decay_rate_; - score += p.neutron_xs_[j_nuclide].fission - * yield * atom_density * flux * rate; + score += p.neutron_xs(j_nuclide).fission * yield * + atom_density * flux * rate; } } } @@ -1176,7 +1199,8 @@ score_general_ce(Particle& p, int i_tally, int start_index, int filter_index, case SCORE_KAPPA_FISSION: - if (p.macro_xs_.absorption == 0.) continue; + if (p.macro_xs().absorption == 0.) + continue; score = 0.; // Kappa-fission values are determined from the Q-value listed for the // fission cross section. @@ -1185,27 +1209,28 @@ score_general_ce(Particle& p, int i_tally, int start_index, int filter_index, // No fission events occur if survival biasing is on -- need to // calculate fraction of absorptions that would have resulted in // fission scaled by the Q-value - const auto& nuc {*data::nuclides[p.event_nuclide_]}; - if (p.neutron_xs_[p.event_nuclide_].absorption > 0 - && nuc.fissionable_) { + const auto& nuc {*data::nuclides[p.event_nuclide()]}; + if (p.neutron_xs(p.event_nuclide()).absorption > 0 && + nuc.fissionable_) { const auto& rxn {*nuc.fission_rx_[0]}; - score = p.wgt_absorb_ * rxn.q_value_ - * p.neutron_xs_[p.event_nuclide_].fission - / p.neutron_xs_[p.event_nuclide_].absorption * flux; + score = p.wgt_absorb() * rxn.q_value_ * + p.neutron_xs(p.event_nuclide()).fission / + p.neutron_xs(p.event_nuclide()).absorption * flux; } } else { // Skip any non-absorption events - if (p.event_ == TallyEvent::SCATTER) continue; + if (p.event() == TallyEvent::SCATTER) + continue; // All fission events will contribute, so again we can use particle's // weight entering the collision as the estimate for the fission // reaction rate - const auto& nuc {*data::nuclides[p.event_nuclide_]}; - if (p.neutron_xs_[p.event_nuclide_].absorption > 0 - && nuc.fissionable_) { + const auto& nuc {*data::nuclides[p.event_nuclide()]}; + if (p.neutron_xs(p.event_nuclide()).absorption > 0 && + nuc.fissionable_) { const auto& rxn {*nuc.fission_rx_[0]}; - score = p.wgt_last_ * rxn.q_value_ - * p.neutron_xs_[p.event_nuclide_].fission - / p.neutron_xs_[p.event_nuclide_].absorption * flux; + score = p.wgt_last() * rxn.q_value_ * + p.neutron_xs(p.event_nuclide()).fission / + p.neutron_xs(p.event_nuclide()).absorption * flux; } } } else { @@ -1213,19 +1238,19 @@ score_general_ce(Particle& p, int i_tally, int start_index, int filter_index, const auto& nuc {*data::nuclides[i_nuclide]}; if (nuc.fissionable_) { const auto& rxn {*nuc.fission_rx_[0]}; - score = rxn.q_value_ * p.neutron_xs_[i_nuclide].fission - * atom_density * flux; + score = rxn.q_value_ * p.neutron_xs(i_nuclide).fission * + atom_density * flux; } - } else if (p.material_ != MATERIAL_VOID) { - const Material& material {*model::materials[p.material_]}; + } else if (p.material() != MATERIAL_VOID) { + const Material& material {*model::materials[p.material()]}; for (auto i = 0; i < material.nuclide_.size(); ++i) { auto j_nuclide = material.nuclide_[i]; auto atom_density = material.atom_density_(i); const auto& nuc {*data::nuclides[j_nuclide]}; if (nuc.fissionable_) { const auto& rxn {*nuc.fission_rx_[0]}; - score += rxn.q_value_ * p.neutron_xs_[j_nuclide].fission - * atom_density * flux; + score += rxn.q_value_ * p.neutron_xs(j_nuclide).fission * + atom_density * flux; } } } @@ -1241,28 +1266,29 @@ score_general_ce(Particle& p, int i_tally, int start_index, int filter_index, case ELASTIC: - if (p.type_ != Type::neutron) continue; + if (p.type() != Type::neutron) + continue; if (tally.estimator_ == TallyEstimator::ANALOG) { // Check if event MT matches - if (p.event_mt_ != ELASTIC) continue; - score = p.wgt_last_ * flux; + if (p.event_mt() != ELASTIC) + continue; + score = p.wgt_last() * flux; } else { if (i_nuclide >= 0) { - if (p.neutron_xs_[i_nuclide].elastic == CACHE_INVALID) + if (p.neutron_xs(i_nuclide).elastic == CACHE_INVALID) data::nuclides[i_nuclide]->calculate_elastic_xs(p); - score = p.neutron_xs_[i_nuclide].elastic * atom_density * flux; + score = p.neutron_xs(i_nuclide).elastic * atom_density * flux; } else { score = 0.; - if (p.material_ != MATERIAL_VOID) { - const Material& material {*model::materials[p.material_]}; + if (p.material() != MATERIAL_VOID) { + const Material& material {*model::materials[p.material()]}; for (auto i = 0; i < material.nuclide_.size(); ++i) { auto j_nuclide = material.nuclide_[i]; auto atom_density = material.atom_density_(i); - if (p.neutron_xs_[j_nuclide].elastic == CACHE_INVALID) + if (p.neutron_xs(j_nuclide).elastic == CACHE_INVALID) data::nuclides[j_nuclide]->calculate_elastic_xs(p); - score += p.neutron_xs_[j_nuclide].elastic * atom_density - * flux; + score += p.neutron_xs(j_nuclide).elastic * atom_density * flux; } } } @@ -1271,7 +1297,8 @@ score_general_ce(Particle& p, int i_tally, int start_index, int filter_index, case SCORE_FISS_Q_PROMPT: case SCORE_FISS_Q_RECOV: - if (p.macro_xs_.absorption == 0.) continue; + if (p.macro_xs().absorption == 0.) + continue; score = score_fission_q(p, score_bin, tally, flux, i_nuclide, atom_density); break; @@ -1287,12 +1314,14 @@ score_general_ce(Particle& p, int i_tally, int start_index, int filter_index, // which looks up cross sections if (!simulation::need_depletion_rx) goto default_case; - if (p.type_ != Type::neutron) continue; + if (p.type() != Type::neutron) + continue; if (tally.estimator_ == TallyEstimator::ANALOG) { // Check if the event MT matches - if (p.event_mt_ != score_bin) continue; - score = p.wgt_last_ * flux; + if (p.event_mt() != score_bin) + continue; + score = p.wgt_last() * flux; } else { int m; switch (score_bin) { @@ -1304,17 +1333,16 @@ score_general_ce(Particle& p, int i_tally, int start_index, int filter_index, case N_4N: m = 5; break; } if (i_nuclide >= 0) { - score = p.neutron_xs_[i_nuclide].reaction[m] * atom_density - * flux; + score = p.neutron_xs(i_nuclide).reaction[m] * atom_density * flux; } else { score = 0.; - if (p.material_ != MATERIAL_VOID) { - const Material& material {*model::materials[p.material_]}; + if (p.material() != MATERIAL_VOID) { + const Material& material {*model::materials[p.material()]}; for (auto i = 0; i < material.nuclide_.size(); ++i) { auto j_nuclide = material.nuclide_[i]; auto atom_density = material.atom_density_(i); - score += p.neutron_xs_[j_nuclide].reaction[m] - * atom_density * flux; + score += + p.neutron_xs(j_nuclide).reaction[m] * atom_density * flux; } } } @@ -1326,22 +1354,25 @@ score_general_ce(Particle& p, int i_tally, int start_index, int filter_index, case INCOHERENT: case PHOTOELECTRIC: case PAIR_PROD: - if (p.type_ != Type::photon) continue; + if (p.type() != Type::photon) + continue; if (tally.estimator_ == TallyEstimator::ANALOG) { if (score_bin == PHOTOELECTRIC) { // Photoelectric events are assigned an MT value corresponding to the // shell cross section. Also, photons below the energy cutoff are // assumed to have been absorbed via photoelectric absorption - if ((p.event_mt_ < 534 || p.event_mt_ > 572) && - p.event_mt_ != REACTION_NONE) continue; + if ((p.event_mt() < 534 || p.event_mt() > 572) && + p.event_mt() != REACTION_NONE) + continue; } else { - if (p.event_mt_ != score_bin) continue; + if (p.event_mt() != score_bin) + continue; } - score = p.wgt_last_ * flux; + score = p.wgt_last() * flux; } else { if (i_nuclide >= 0) { - const auto& micro = p.photon_xs_[i_nuclide]; + const auto& micro = p.photon_xs(i_nuclide); double xs = (score_bin == COHERENT) ? micro.coherent : (score_bin == INCOHERENT) ? micro.incoherent : @@ -1349,11 +1380,11 @@ score_general_ce(Particle& p, int i_tally, int start_index, int filter_index, micro.pair_production; score = xs * atom_density * flux; } else { - double xs = - (score_bin == COHERENT) ? p.macro_xs_.coherent : - (score_bin == INCOHERENT) ? p.macro_xs_.incoherent : - (score_bin == PHOTOELECTRIC) ? p.macro_xs_.photoelectric : - p.macro_xs_.pair_production; + double xs = (score_bin == COHERENT) ? p.macro_xs().coherent + : (score_bin == INCOHERENT) ? p.macro_xs().incoherent + : (score_bin == PHOTOELECTRIC) + ? p.macro_xs().photoelectric + : p.macro_xs().pair_production; score = xs * flux; } } @@ -1361,22 +1392,22 @@ score_general_ce(Particle& p, int i_tally, int start_index, int filter_index, case HEATING: - if (p.type_ == Type::neutron) { + if (p.type() == Type::neutron) { score = score_neutron_heating(p, tally, flux, HEATING, i_nuclide, atom_density); } else { // The energy deposited is the difference between the pre-collision and // post-collision energy... - score = E - p.E_; + score = E - p.E(); // ...less the energy of any secondary particles since they will be // transported individually later - const auto& bank = p.secondary_bank_; - for (auto it = bank.end() - p.n_bank_second_; it < bank.end(); ++it) { + const auto& bank = p.secondary_bank(); + for (auto it = bank.end() - p.n_bank_second(); it < bank.end(); ++it) { score -= it->E; } - score *= p.wgt_last_; + score *= p.wgt_last(); } break; @@ -1385,14 +1416,16 @@ score_general_ce(Particle& p, int i_tally, int start_index, int filter_index, // The default block is really only meant for redundant neutron reactions // (e.g. 444, 901) - if (p.type_ != Type::neutron) continue; + if (p.type() != Type::neutron) + continue; if (tally.estimator_ == TallyEstimator::ANALOG) { // Any other score is assumed to be a MT number. Thus, we just need // to check if it matches the MT number of the event - if (p.event_mt_ != score_bin) continue; - score = p.wgt_last_*flux; + if (p.event_mt() != score_bin) + continue; + score = p.wgt_last() * flux; } else { // Any other cross section has to be calculated on-the-fly if (score_bin < 2) fatal_error("Invalid score type on tally " @@ -1400,8 +1433,8 @@ score_general_ce(Particle& p, int i_tally, int start_index, int filter_index, score = 0.; if (i_nuclide >= 0) { score = get_nuclide_xs(p, i_nuclide, score_bin) * atom_density * flux; - } else if (p.material_ != MATERIAL_VOID) { - const Material& material {*model::materials[p.material_]}; + } else if (p.material() != MATERIAL_VOID) { + const Material& material {*model::materials[p.material()]}; for (auto i = 0; i < material.nuclide_.size(); ++i) { auto j_nuclide = material.nuclide_[i]; auto atom_density = material.atom_density_(i); @@ -1443,40 +1476,40 @@ score_general_mg(Particle& p, int i_tally, int start_index, int filter_index, // Then we either are alive and had a scatter (and so g changed), // or are dead and g did not change - if (p.alive_) { - p_u = p.u_last_; - p_g = p.g_last_; + if (p.alive()) { + p_u = p.u_last(); + p_g = p.g_last(); } else { p_u = p.u_local(); - p_g = p.g_; + p_g = p.g(); } - } else if (p.event_ == TallyEvent::SCATTER) { + } else if (p.event() == TallyEvent::SCATTER) { // Then the energy group has been changed by the scattering routine // meaning gin is now in p % last_g - p_u = p.u_last_; - p_g = p.g_last_; + p_u = p.u_last(); + p_g = p.g_last(); } else { // No scatter, no change in g. p_u = p.u_local(); - p_g = p.g_; + p_g = p.g(); } } else { // No actual collision so g has not changed. p_u = p.u_local(); - p_g = p.g_; + p_g = p.g(); } // For shorthand, assign pointers to the material and nuclide xs set auto& nuc_xs = data::mg.nuclides_[i_nuclide]; - auto& macro_xs = data::mg.macro_xs_[p.material_]; + auto& macro_xs = data::mg.macro_xs_[p.material()]; // Find the temperature and angle indices of interest macro_xs.set_angle_index(p_u); if (i_nuclide >= 0) { - nuc_xs.set_temperature_index(p.sqrtkT_); + nuc_xs.set_temperature_index(p.sqrtkT()); nuc_xs.set_angle_index(p_u); } @@ -1497,11 +1530,11 @@ score_general_mg(Particle& p, int i_tally, int start_index, int filter_index, if (settings::survival_biasing) { // We need to account for the fact that some weight was already // absorbed - score = p.wgt_last_ + p.wgt_absorb_; + score = p.wgt_last() + p.wgt_absorb(); } else { - score = p.wgt_last_; + score = p.wgt_last(); } - score *= flux / p.macro_xs_.total; + score *= flux / p.macro_xs().total; } else { score = flux; } @@ -1515,9 +1548,9 @@ score_general_mg(Particle& p, int i_tally, int start_index, int filter_index, if (settings::survival_biasing) { // We need to account for the fact that some weight was already // absorbed - score = p.wgt_last_ + p.wgt_absorb_; + score = p.wgt_last() + p.wgt_absorb(); } else { - score = p.wgt_last_; + score = p.wgt_last(); } //TODO: should flux be multiplied in above instead of below? if (i_nuclide >= 0) { @@ -1528,7 +1561,7 @@ score_general_mg(Particle& p, int i_tally, int start_index, int filter_index, if (i_nuclide >= 0) { score = atom_density * flux * nuc_xs.get_xs(MgxsType::TOTAL, p_g); } else { - score = p.macro_xs_.total * flux; + score = p.macro_xs().total * flux; } } break; @@ -1543,9 +1576,9 @@ score_general_mg(Particle& p, int i_tally, int start_index, int filter_index, if (settings::survival_biasing) { // We need to account for the fact that some weight was already // absorbed - score = p.wgt_last_ + p.wgt_absorb_; + score = p.wgt_last() + p.wgt_absorb(); } else { - score = p.wgt_last_; + score = p.wgt_last(); } if (i_nuclide >= 0) { score *= flux * nuc_xs.get_xs(MgxsType::INVERSE_VELOCITY, p_g) @@ -1567,23 +1600,26 @@ score_general_mg(Particle& p, int i_tally, int start_index, int filter_index, case SCORE_SCATTER: if (tally.estimator_ == TallyEstimator::ANALOG) { // Skip any event where the particle didn't scatter - if (p.event_ != TallyEvent::SCATTER) continue; + if (p.event() != TallyEvent::SCATTER) + continue; // Since only scattering events make it here, again we can use the // weight entering the collision as the estimator for the reaction rate - score = p.wgt_last_ * flux; + score = p.wgt_last() * flux; if (i_nuclide >= 0) { - score *= atom_density * nuc_xs.get_xs( - MgxsType::SCATTER_FMU, p.g_last_, &p.g_, &p.mu_, nullptr) - / macro_xs.get_xs( - MgxsType::SCATTER_FMU, p.g_last_, &p.g_, &p.mu_, nullptr); + score *= atom_density * + nuc_xs.get_xs(MgxsType::SCATTER_FMU, p.g_last(), &p.g(), + &p.mu(), nullptr) / + macro_xs.get_xs(MgxsType::SCATTER_FMU, p.g_last(), &p.g(), + &p.mu(), nullptr); } } else { if (i_nuclide >= 0) { - score = atom_density * flux * nuc_xs.get_xs( - MgxsType::SCATTER, p_g, nullptr, &p.mu_, nullptr); + score = + atom_density * flux * + nuc_xs.get_xs(MgxsType::SCATTER, p_g, nullptr, &p.mu(), nullptr); } else { score = flux * macro_xs.get_xs( - MgxsType::SCATTER, p_g, nullptr, &p.mu_, nullptr); + MgxsType::SCATTER, p_g, nullptr, &p.mu(), nullptr); } } break; @@ -1592,20 +1628,21 @@ score_general_mg(Particle& p, int i_tally, int start_index, int filter_index, case SCORE_NU_SCATTER: if (tally.estimator_ == TallyEstimator::ANALOG) { // Skip any event where the particle didn't scatter - if (p.event_ != TallyEvent::SCATTER) continue; + if (p.event() != TallyEvent::SCATTER) + continue; // For scattering production, we need to use the pre-collision weight // times the multiplicity as the estimate for the number of neutrons // exiting a reaction with neutrons in the exit channel - score = p.wgt_ * flux; + score = p.wgt() * flux; // Since we transport based on material data, the angle selected // was not selected from the f(mu) for the nuclide. Therefore // adjust the score by the actual probability for that nuclide. if (i_nuclide >= 0) { - score *= atom_density - * nuc_xs.get_xs(MgxsType::NU_SCATTER_FMU, p.g_last_, &p.g_, - &p.mu_, nullptr) - / macro_xs.get_xs(MgxsType::NU_SCATTER_FMU, p.g_last_, &p.g_, - &p.mu_, nullptr); + score *= atom_density * + nuc_xs.get_xs(MgxsType::NU_SCATTER_FMU, p.g_last(), &p.g(), + &p.mu(), nullptr) / + macro_xs.get_xs(MgxsType::NU_SCATTER_FMU, p.g_last(), &p.g(), + &p.mu(), nullptr); } } else { if (i_nuclide >= 0) { @@ -1622,13 +1659,14 @@ score_general_mg(Particle& p, int i_tally, int start_index, int filter_index, if (settings::survival_biasing) { // No absorption events actually occur if survival biasing is on -- // just use weight absorbed in survival biasing - score = p.wgt_absorb_ * flux; + score = p.wgt_absorb() * flux; } else { // Skip any event where the particle wasn't absorbed - if (p.event_ == TallyEvent::SCATTER) continue; + if (p.event() == TallyEvent::SCATTER) + continue; // All fission and absorption events will contribute here, so we // can just use the particle's weight entering the collision - score = p.wgt_last_ * flux; + score = p.wgt_last() * flux; } if (i_nuclide >= 0) { score *= atom_density * nuc_xs.get_xs(MgxsType::ABSORPTION, p_g) @@ -1639,7 +1677,7 @@ score_general_mg(Particle& p, int i_tally, int start_index, int filter_index, score = atom_density * flux * nuc_xs.get_xs(MgxsType::ABSORPTION, p_g); } else { - score = p.macro_xs_.absorption * flux; + score = p.macro_xs().absorption * flux; } } break; @@ -1651,14 +1689,15 @@ score_general_mg(Particle& p, int i_tally, int start_index, int filter_index, // No fission events occur if survival biasing is on -- need to // calculate fraction of absorptions that would have resulted in // fission - score = p.wgt_absorb_ * flux; + score = p.wgt_absorb() * flux; } else { // Skip any non-absorption events - if (p.event_ == TallyEvent::SCATTER) continue; + if (p.event() == TallyEvent::SCATTER) + continue; // All fission events will contribute, so again we can use particle's // weight entering the collision as the estimate for the fission // reaction rate - score = p.wgt_last_ * flux; + score = p.wgt_last() * flux; } if (i_nuclide >= 0) { score *= atom_density * nuc_xs.get_xs(MgxsType::FISSION, p_g) @@ -1679,7 +1718,7 @@ score_general_mg(Particle& p, int i_tally, int start_index, int filter_index, case SCORE_NU_FISSION: if (tally.estimator_ == TallyEstimator::ANALOG) { - if (settings::survival_biasing || p.fission_) { + if (settings::survival_biasing || p.fission()) { if (tally.energyout_filter_ != C_NONE) { // Fission has multiple outgoing neutrons so this helper function // is used to handle scoring the multiple filter bins. @@ -1691,7 +1730,7 @@ score_general_mg(Particle& p, int i_tally, int start_index, int filter_index, // No fission events occur if survival biasing is on -- need to // calculate fraction of absorptions that would have resulted in // nu-fission - score = p.wgt_absorb_ * flux; + score = p.wgt_absorb() * flux; if (i_nuclide >= 0) { score *= atom_density * nuc_xs.get_xs(MgxsType::NU_FISSION, p_g) / macro_xs.get_xs(MgxsType::ABSORPTION, p_g); @@ -1701,13 +1740,14 @@ score_general_mg(Particle& p, int i_tally, int start_index, int filter_index, } } else { // Skip any non-fission events - if (!p.fission_) continue; + if (!p.fission()) + continue; // If there is no outgoing energy filter, than we only need to score // to one bin. For the score to be 'analog', we need to score the // number of particles that were banked in the fission bank. Since // this was weighted by 1/keff, we multiply by keff to get the proper // score. - score = simulation::keff * p.wgt_bank_ * flux; + score = simulation::keff * p.wgt_bank() * flux; if (i_nuclide >= 0) { score *= atom_density * nuc_xs.get_xs(MgxsType::FISSION, p_g) / macro_xs.get_xs(MgxsType::FISSION, p_g); @@ -1726,7 +1766,7 @@ score_general_mg(Particle& p, int i_tally, int start_index, int filter_index, case SCORE_PROMPT_NU_FISSION: if (tally.estimator_ == TallyEstimator::ANALOG) { - if (settings::survival_biasing || p.fission_) { + if (settings::survival_biasing || p.fission()) { if (tally.energyout_filter_ != C_NONE) { // Fission has multiple outgoing neutrons so this helper function // is used to handle scoring the multiple filter bins. @@ -1738,7 +1778,7 @@ score_general_mg(Particle& p, int i_tally, int start_index, int filter_index, // No fission events occur if survival biasing is on -- need to // calculate fraction of absorptions that would have resulted in // prompt-nu-fission - score = p.wgt_absorb_ * flux; + score = p.wgt_absorb() * flux; if (i_nuclide >= 0) { score *= atom_density * nuc_xs.get_xs(MgxsType::PROMPT_NU_FISSION, p_g) @@ -1749,16 +1789,17 @@ score_general_mg(Particle& p, int i_tally, int start_index, int filter_index, } } else { // Skip any non-fission events - if (!p.fission_) continue; + if (!p.fission()) + continue; // If there is no outgoing energy filter, than we only need to score // to one bin. For the score to be 'analog', we need to score the // number of particles that were banked in the fission bank. Since // this was weighted by 1/keff, we multiply by keff to get the proper // score. - auto n_delayed = std::accumulate(p.n_delayed_bank_, - p.n_delayed_bank_+MAX_DELAYED_GROUPS, 0); - auto prompt_frac = 1. - n_delayed / static_cast(p.n_bank_); - score = simulation::keff * p.wgt_bank_ * prompt_frac * flux; + auto n_delayed = std::accumulate( + p.n_delayed_bank(), p.n_delayed_bank() + MAX_DELAYED_GROUPS, 0); + auto prompt_frac = 1. - n_delayed / static_cast(p.n_bank()); + score = simulation::keff * p.wgt_bank() * prompt_frac * flux; if (i_nuclide >= 0) { score *= atom_density * nuc_xs.get_xs(MgxsType::FISSION, p_g) / macro_xs.get_xs(MgxsType::FISSION, p_g); @@ -1777,7 +1818,7 @@ score_general_mg(Particle& p, int i_tally, int start_index, int filter_index, case SCORE_DELAYED_NU_FISSION: if (tally.estimator_ == TallyEstimator::ANALOG) { - if (settings::survival_biasing || p.fission_) { + if (settings::survival_biasing || p.fission()) { if (tally.energyout_filter_ != C_NONE) { // Fission has multiple outgoing neutrons so this helper function // is used to handle scoring the multiple filter bins. @@ -1799,7 +1840,7 @@ score_general_mg(Particle& p, int i_tally, int start_index, int filter_index, // Tally each delayed group bin individually for (auto d_bin = 0; d_bin < filt.n_bins(); ++d_bin) { auto d = filt.groups()[d_bin] - 1; - score = p.wgt_absorb_ * flux; + score = p.wgt_absorb() * flux; if (i_nuclide >= 0) { score *= nuc_xs.get_xs(MgxsType::DELAYED_NU_FISSION, p_g, nullptr, nullptr, &d) @@ -1809,14 +1850,15 @@ score_general_mg(Particle& p, int i_tally, int start_index, int filter_index, nullptr, nullptr, &d) / abs_xs; } - score_fission_delayed_dg(i_tally, d_bin, score, score_index, p.filter_matches_); + score_fission_delayed_dg( + i_tally, d_bin, score, score_index, p.filter_matches()); } continue; } else { // If the delayed group filter is not present, compute the score // by multiplying the absorbed weight by the fraction of the // delayed-nu-fission xs to the absorption xs - score = p.wgt_absorb_ * flux; + score = p.wgt_absorb() * flux; if (i_nuclide >= 0) { score *= nuc_xs.get_xs(MgxsType::DELAYED_NU_FISSION, p_g) / abs_xs; @@ -1828,7 +1870,8 @@ score_general_mg(Particle& p, int i_tally, int start_index, int filter_index, } } else { // Skip any non-fission events - if (!p.fission_) continue; + if (!p.fission()) + continue; // If there is no outgoing energy filter, than we only need to score // to one bin. For the score to be 'analog', we need to score the // number of particles that were banked in the fission bank. Since @@ -1844,21 +1887,22 @@ score_general_mg(Particle& p, int i_tally, int start_index, int filter_index, // Tally each delayed group bin individually for (auto d_bin = 0; d_bin < filt.n_bins(); ++d_bin) { auto d = filt.groups()[d_bin]; - score = simulation::keff * p.wgt_bank_ / p.n_bank_ - * p.n_delayed_bank_[d-1] * flux; + score = simulation::keff * p.wgt_bank() / p.n_bank() * + p.n_delayed_bank(d - 1) * flux; if (i_nuclide >= 0) { score *= atom_density * nuc_xs.get_xs(MgxsType::FISSION, p_g) / macro_xs.get_xs(MgxsType::FISSION, p_g); } - score_fission_delayed_dg(i_tally, d_bin, score, score_index, p.filter_matches_); + score_fission_delayed_dg( + i_tally, d_bin, score, score_index, p.filter_matches()); } continue; } else { // Add the contribution from all delayed groups - auto n_delayed = std::accumulate(p.n_delayed_bank_, - p.n_delayed_bank_+MAX_DELAYED_GROUPS, 0); - score = simulation::keff * p.wgt_bank_ / p.n_bank_ * n_delayed - * flux; + auto n_delayed = std::accumulate( + p.n_delayed_bank(), p.n_delayed_bank() + MAX_DELAYED_GROUPS, 0); + score = + simulation::keff * p.wgt_bank() / p.n_bank() * n_delayed * flux; if (i_nuclide >= 0) { score *= atom_density * nuc_xs.get_xs(MgxsType::FISSION, p_g) / macro_xs.get_xs(MgxsType::FISSION, p_g); @@ -1881,7 +1925,8 @@ score_general_mg(Particle& p, int i_tally, int start_index, int filter_index, score = flux * macro_xs.get_xs( MgxsType::DELAYED_NU_FISSION, p_g, nullptr, nullptr, &d); } - score_fission_delayed_dg(i_tally, d_bin, score, score_index, p.filter_matches_); + score_fission_delayed_dg( + i_tally, d_bin, score, score_index, p.filter_matches()); } continue; } else { @@ -1912,7 +1957,7 @@ score_general_mg(Particle& p, int i_tally, int start_index, int filter_index, // Tally each delayed group bin individually for (auto d_bin = 0; d_bin < filt.n_bins(); ++d_bin) { auto d = filt.groups()[d_bin] - 1; - score = p.wgt_absorb_ * flux; + score = p.wgt_absorb() * flux; if (i_nuclide >= 0) { score *= nuc_xs.get_xs(MgxsType::DECAY_RATE, p_g, nullptr, nullptr, &d) @@ -1924,7 +1969,8 @@ score_general_mg(Particle& p, int i_tally, int start_index, int filter_index, * macro_xs.get_xs(MgxsType::DELAYED_NU_FISSION, p_g, nullptr, nullptr, &d) / abs_xs; } - score_fission_delayed_dg(i_tally, d_bin, score, score_index, p.filter_matches_); + score_fission_delayed_dg( + i_tally, d_bin, score, score_index, p.filter_matches()); } continue; } else { @@ -1935,24 +1981,27 @@ score_general_mg(Particle& p, int i_tally, int start_index, int filter_index, score = 0.; for (auto d = 0; d < data::mg.num_delayed_groups_; ++d) { if (i_nuclide >= 0) { - score += p.wgt_absorb_ * flux - * nuc_xs.get_xs(MgxsType::DECAY_RATE, p_g, nullptr, - nullptr, &d) - * nuc_xs.get_xs(MgxsType::DELAYED_NU_FISSION, p_g, - nullptr, nullptr, &d) / abs_xs; + score += p.wgt_absorb() * flux * + nuc_xs.get_xs( + MgxsType::DECAY_RATE, p_g, nullptr, nullptr, &d) * + nuc_xs.get_xs(MgxsType::DELAYED_NU_FISSION, p_g, + nullptr, nullptr, &d) / + abs_xs; } else { - score += p.wgt_absorb_ * flux - * macro_xs.get_xs(MgxsType::DECAY_RATE, p_g, nullptr, - nullptr, &d) - * macro_xs.get_xs(MgxsType::DELAYED_NU_FISSION, p_g, - nullptr, nullptr, &d) / abs_xs; + score += p.wgt_absorb() * flux * + macro_xs.get_xs( + MgxsType::DECAY_RATE, p_g, nullptr, nullptr, &d) * + macro_xs.get_xs(MgxsType::DELAYED_NU_FISSION, p_g, + nullptr, nullptr, &d) / + abs_xs; } } } } } else { // Skip any non-fission events - if (!p.fission_) continue; + if (!p.fission()) + continue; // If there is no outgoing energy filter, than we only need to score // to one bin. For the score to be 'analog', we need to score the // number of particles that were banked in the fission bank. Since @@ -1961,8 +2010,8 @@ score_general_mg(Particle& p, int i_tally, int start_index, int filter_index, // ones are delayed. If a delayed neutron is encountered, add its // contribution to the fission bank to the score. score = 0.; - for (auto i = 0; i < p.n_bank_; ++i) { - const auto& bank = p.nu_bank_[i]; + for (auto i = 0; i < p.n_bank(); ++i) { + const auto& bank = p.nu_bank(i); auto d = bank.delayed_group - 1; if (d != -1) { if (i_nuclide >= 0) { @@ -1983,8 +2032,8 @@ score_general_mg(Particle& p, int i_tally, int start_index, int filter_index, for (auto d_bin = 0; d_bin < filt.n_bins(); ++d_bin) { auto dg = filt.groups()[d_bin]; if (dg == d + 1) - score_fission_delayed_dg(i_tally, d_bin, score, - score_index, p.filter_matches_); + score_fission_delayed_dg( + i_tally, d_bin, score, score_index, p.filter_matches()); } score = 0.; } @@ -2014,7 +2063,8 @@ score_general_mg(Particle& p, int i_tally, int start_index, int filter_index, * macro_xs.get_xs(MgxsType::DELAYED_NU_FISSION, p_g, nullptr, nullptr, &d); } - score_fission_delayed_dg(i_tally, d_bin, score, score_index, p.filter_matches_); + score_fission_delayed_dg( + i_tally, d_bin, score, score_index, p.filter_matches()); } continue; } else { @@ -2041,14 +2091,15 @@ score_general_mg(Particle& p, int i_tally, int start_index, int filter_index, // No fission events occur if survival biasing is on -- need to // calculate fraction of absorptions that would have resulted in // fission scaled by the Q-value - score = p.wgt_absorb_ * flux; + score = p.wgt_absorb() * flux; } else { // Skip any non-absorption events - if (p.event_ == TallyEvent::SCATTER) continue; + if (p.event() == TallyEvent::SCATTER) + continue; // All fission events will contribute, so again we can use particle's // weight entering the collision as the estimate for the fission // reaction rate - score = p.wgt_last_ * flux; + score = p.wgt_last() * flux; } if (i_nuclide >= 0) { score *= atom_density @@ -2092,7 +2143,7 @@ score_all_nuclides(Particle& p, int i_tally, double flux, int filter_index, double filter_weight) { const Tally& tally {*model::tallies[i_tally]}; - const Material& material {*model::materials[p.material_]}; + const Material& material {*model::materials[p.material()]}; // Score all individual nuclide reaction rates. for (auto i = 0; i < material.nuclide_.size(); ++i) { @@ -2129,8 +2180,9 @@ void score_analog_tally_ce(Particle& p) // Note that the heating score does NOT use the flux and will be non-zero for // electrons/positrons. double flux = - (p.type_ == Particle::Type::neutron || p.type_ == Particle::Type::photon) ? - 1.0 : 0.0; + (p.type() == ParticleType::neutron || p.type() == ParticleType::photon) + ? 1.0 + : 0.0; for (auto i_tally : model::active_analog_tallies) { const Tally& tally {*model::tallies[i_tally]}; @@ -2139,7 +2191,7 @@ void score_analog_tally_ce(Particle& p) // no valid combinations, use a continue statement to ensure we skip the // assume_separate break below. auto filter_iter = FilterBinIter(tally, p); - auto end = FilterBinIter(tally, true, &p.filter_matches_); + auto end = FilterBinIter(tally, true, &p.filter_matches()); if (filter_iter == end) continue; // Loop over filter bins. @@ -2155,7 +2207,7 @@ void score_analog_tally_ce(Particle& p) // Tally this event in the present nuclide bin if that bin represents // the event nuclide or the total material. Note that the atomic // density argument for score_general is not used for analog tallies. - if (i_nuclide == p.event_nuclide_ || i_nuclide == -1) + if (i_nuclide == p.event_nuclide() || i_nuclide == -1) score_general_ce(p, i_tally, i*tally.scores_.size(), filter_index, filter_weight, i_nuclide, -1.0, flux); } @@ -2164,7 +2216,7 @@ void score_analog_tally_ce(Particle& p) // In the case that the user has requested to tally all nuclides, we // can take advantage of the fact that we know exactly how nuclide // bins correspond to nuclide indices. First, tally the nuclide. - auto i = p.event_nuclide_; + auto i = p.event_nuclide(); score_general_ce(p, i_tally, i*tally.scores_.size(), filter_index, filter_weight, -1, -1.0, flux); @@ -2183,7 +2235,7 @@ void score_analog_tally_ce(Particle& p) } // Reset all the filter matches for the next tally event. - for (auto& match : p.filter_matches_) + for (auto& match : p.filter_matches()) match.bins_present_ = false; } @@ -2196,7 +2248,7 @@ void score_analog_tally_mg(Particle& p) // no valid combinations, use a continue statement to ensure we skip the // assume_separate break below. auto filter_iter = FilterBinIter(tally, p); - auto end = FilterBinIter(tally, true, &p.filter_matches_); + auto end = FilterBinIter(tally, true, &p.filter_matches()); if (filter_iter == end) continue; // Loop over filter bins. @@ -2210,9 +2262,10 @@ void score_analog_tally_mg(Particle& p) double atom_density = 0.; if (i_nuclide >= 0) { - auto j = model::materials[p.material_]->mat_nuclide_index_[i_nuclide]; + auto j = + model::materials[p.material()]->mat_nuclide_index_[i_nuclide]; if (j == C_NONE) continue; - atom_density = model::materials[p.material_]->atom_density_(j); + atom_density = model::materials[p.material()]->atom_density_(j); } score_general_mg(p, i_tally, i*tally.scores_.size(), filter_index, @@ -2228,7 +2281,7 @@ void score_analog_tally_mg(Particle& p) } // Reset all the filter matches for the next tally event. - for (auto& match : p.filter_matches_) + for (auto& match : p.filter_matches()) match.bins_present_ = false; } @@ -2236,7 +2289,7 @@ void score_tracklength_tally(Particle& p, double distance) { // Determine the tracklength estimate of the flux - double flux = p.wgt_ * distance; + double flux = p.wgt() * distance; for (auto i_tally : model::active_tracklength_tallies) { const Tally& tally {*model::tallies[i_tally]}; @@ -2245,7 +2298,7 @@ score_tracklength_tally(Particle& p, double distance) // no valid combinations, use a continue statement to ensure we skip the // assume_separate break below. auto filter_iter = FilterBinIter(tally, p); - auto end = FilterBinIter(tally, true, &p.filter_matches_); + auto end = FilterBinIter(tally, true, &p.filter_matches()); if (filter_iter == end) continue; // Loop over filter bins. @@ -2255,7 +2308,7 @@ score_tracklength_tally(Particle& p, double distance) // Loop over nuclide bins. if (tally.all_nuclides_) { - if (p.material_ != MATERIAL_VOID) + if (p.material() != MATERIAL_VOID) score_all_nuclides(p, i_tally, flux*filter_weight, filter_index, filter_weight); @@ -2265,10 +2318,11 @@ score_tracklength_tally(Particle& p, double distance) double atom_density = 0.; if (i_nuclide >= 0) { - if (p.material_ != MATERIAL_VOID) { - auto j = model::materials[p.material_]->mat_nuclide_index_[i_nuclide]; + if (p.material() != MATERIAL_VOID) { + auto j = + model::materials[p.material()]->mat_nuclide_index_[i_nuclide]; if (j == C_NONE) continue; - atom_density = model::materials[p.material_]->atom_density_(j); + atom_density = model::materials[p.material()]->atom_density_(j); } } @@ -2293,7 +2347,7 @@ score_tracklength_tally(Particle& p, double distance) } // Reset all the filter matches for the next tally event. - for (auto& match : p.filter_matches_) + for (auto& match : p.filter_matches()) match.bins_present_ = false; } @@ -2301,11 +2355,11 @@ void score_collision_tally(Particle& p) { // Determine the collision estimate of the flux double flux = 0.0; - if (p.type_ == Particle::Type::neutron || p.type_ == Particle::Type::photon) { + if (p.type() == ParticleType::neutron || p.type() == ParticleType::photon) { if (!settings::survival_biasing) { - flux = p.wgt_last_ / p.macro_xs_.total; + flux = p.wgt_last() / p.macro_xs().total; } else { - flux = (p.wgt_last_ + p.wgt_absorb_) / p.macro_xs_.total; + flux = (p.wgt_last() + p.wgt_absorb()) / p.macro_xs().total; } } @@ -2316,7 +2370,7 @@ void score_collision_tally(Particle& p) // no valid combinations, use a continue statement to ensure we skip the // assume_separate break below. auto filter_iter = FilterBinIter(tally, p); - auto end = FilterBinIter(tally, true, &p.filter_matches_); + auto end = FilterBinIter(tally, true, &p.filter_matches()); if (filter_iter == end) continue; // Loop over filter bins. @@ -2335,9 +2389,10 @@ void score_collision_tally(Particle& p) double atom_density = 0.; if (i_nuclide >= 0) { - auto j = model::materials[p.material_]->mat_nuclide_index_[i_nuclide]; + auto j = + model::materials[p.material()]->mat_nuclide_index_[i_nuclide]; if (j == C_NONE) continue; - atom_density = model::materials[p.material_]->atom_density_(j); + atom_density = model::materials[p.material()]->atom_density_(j); } //TODO: consider replacing this "if" with pointers or templates @@ -2360,15 +2415,14 @@ void score_collision_tally(Particle& p) } // Reset all the filter matches for the next tally event. - for (auto& match : p.filter_matches_) + for (auto& match : p.filter_matches()) match.bins_present_ = false; } -void -score_surface_tally(Particle& p, const std::vector& tallies) +void score_surface_tally(Particle& p, const vector& tallies) { // No collision, so no weight change when survival biasing - double flux = p.wgt_; + double flux = p.wgt(); for (auto i_tally : tallies) { auto& tally {*model::tallies[i_tally]}; @@ -2377,7 +2431,7 @@ score_surface_tally(Particle& p, const std::vector& tallies) // no valid combinations, use a continue statement to ensure we skip the // assume_separate break below. auto filter_iter = FilterBinIter(tally, p); - auto end = FilterBinIter(tally, true, &p.filter_matches_); + auto end = FilterBinIter(tally, true, &p.filter_matches()); if (filter_iter == end) continue; // Loop over filter bins. @@ -2404,7 +2458,7 @@ score_surface_tally(Particle& p, const std::vector& tallies) } // Reset all the filter matches for the next tally event. - for (auto& match : p.filter_matches_) + for (auto& match : p.filter_matches()) match.bins_present_ = false; } diff --git a/src/thermal.cpp b/src/thermal.cpp index 4b1561428..5e3c6d6bb 100644 --- a/src/thermal.cpp +++ b/src/thermal.cpp @@ -28,14 +28,15 @@ namespace openmc { namespace data { std::unordered_map thermal_scatt_map; -std::vector> thermal_scatt; +vector> thermal_scatt; } //============================================================================== // ThermalScattering implementation //============================================================================== -ThermalScattering::ThermalScattering(hid_t group, const std::vector& temperature) +ThermalScattering::ThermalScattering( + hid_t group, const vector& temperature) { // Get name of table from group name_ = object_name(group); @@ -65,7 +66,7 @@ ThermalScattering::ThermalScattering(hid_t group, const std::vector& tem // Determine actual temperatures to read -- start by checking whether a // temperature range was given, in which case all temperatures in the range // are loaded irrespective of what temperatures actually appear in the model - std::vector temps_to_read; + vector temps_to_read; if (settings::temperature_range[1] > 0.0) { for (const auto& T : temps_available) { if (settings::temperature_range[0] <= T && @@ -203,15 +204,14 @@ ThermalData::ThermalData(hid_t group) read_attribute(dgroup, "type", temp); if (temp == "coherent_elastic") { auto xs = dynamic_cast(elastic_.xs.get()); - elastic_.distribution = std::make_unique(*xs); + elastic_.distribution = make_unique(*xs); } else { if (temp == "incoherent_elastic") { - elastic_.distribution = std::make_unique(dgroup); + elastic_.distribution = make_unique(dgroup); } else if (temp == "incoherent_elastic_discrete") { auto xs = dynamic_cast(elastic_.xs.get()); - elastic_.distribution = std::make_unique( - dgroup, xs->x() - ); + elastic_.distribution = + make_unique(dgroup, xs->x()); } } @@ -231,12 +231,11 @@ ThermalData::ThermalData(hid_t group) std::string temp; read_attribute(dgroup, "type", temp); if (temp == "incoherent_inelastic") { - inelastic_.distribution = std::make_unique(dgroup); + inelastic_.distribution = make_unique(dgroup); } else if (temp == "incoherent_inelastic_discrete") { auto xs = dynamic_cast(inelastic_.xs.get()); - inelastic_.distribution = std::make_unique( - dgroup, xs->x() - ); + inelastic_.distribution = + make_unique(dgroup, xs->x()); } close_group(inelastic_group); diff --git a/src/track_output.cpp b/src/track_output.cpp index 314e43351..ed20b057b 100644 --- a/src/track_output.cpp +++ b/src/track_output.cpp @@ -5,13 +5,13 @@ #include "openmc/position.h" #include "openmc/settings.h" #include "openmc/simulation.h" +#include "openmc/vector.h" #include #include "xtensor/xtensor.hpp" #include // for size_t #include -#include namespace openmc { @@ -25,35 +25,35 @@ namespace openmc { void add_particle_track(Particle& p) { - p.tracks_.emplace_back(); + p.tracks().emplace_back(); } void write_particle_track(Particle& p) { - p.tracks_.back().push_back(p.r()); + p.tracks().back().push_back(p.r()); } void finalize_particle_track(Particle& p) { - std::string filename = fmt::format("{}track_{}_{}_{}.h5", - settings::path_output, simulation::current_batch, simulation::current_gen, - p.id_); + std::string filename = + fmt::format("{}track_{}_{}_{}.h5", settings::path_output, + simulation::current_batch, simulation::current_gen, p.id()); // Determine number of coordinates for each particle - std::vector n_coords; - for (auto& coords : p.tracks_) { + vector n_coords; + for (auto& coords : p.tracks()) { n_coords.push_back(coords.size()); } - #pragma omp critical (FinalizeParticleTrack) +#pragma omp critical (FinalizeParticleTrack) { hid_t file_id = file_open(filename, 'w'); write_attribute(file_id, "filetype", "track"); write_attribute(file_id, "version", VERSION_TRACK); - write_attribute(file_id, "n_particles", p.tracks_.size()); + write_attribute(file_id, "n_particles", p.tracks().size()); write_attribute(file_id, "n_coords", n_coords); - for (auto i = 1; i <= p.tracks_.size(); ++i) { - const auto& t {p.tracks_[i-1]}; + for (auto i = 1; i <= p.tracks().size(); ++i) { + const auto& t {p.tracks()[i - 1]}; size_t n = t.size(); xt::xtensor data({n,3}); for (int j = 0; j < n; ++j) { @@ -68,7 +68,7 @@ void finalize_particle_track(Particle& p) } // Clear particle tracks - p.tracks_.clear(); + p.tracks().clear(); } } // namespace openmc diff --git a/src/volume_calc.cpp b/src/volume_calc.cpp index 15096544d..33c788358 100644 --- a/src/volume_calc.cpp +++ b/src/volume_calc.cpp @@ -33,7 +33,7 @@ namespace openmc { //============================================================================== namespace model { - std::vector volume_calcs; +vector volume_calcs; } //============================================================================== @@ -94,12 +94,14 @@ VolumeCalculation::VolumeCalculation(pugi::xml_node node) } -std::vector VolumeCalculation::execute() const +vector VolumeCalculation::execute() const { // Shared data that is collected from all threads int n = domain_ids_.size(); - std::vector> master_indices(n); // List of material indices for each domain - std::vector> master_hits(n); // Number of hits for each material in each domain + vector> master_indices( + n); // List of material indices for each domain + vector> master_hits( + n); // Number of hits for each material in each domain int iterations = 0; // Divide work over MPI processes @@ -119,8 +121,8 @@ std::vector VolumeCalculation::execute() const #pragma omp parallel { // Variables that are private to each thread - std::vector> indices(n); - std::vector> hits(n); + vector> indices(n); + vector> hits(n); Particle p; // Sample locations and count hits @@ -129,7 +131,7 @@ std::vector VolumeCalculation::execute() const int64_t id = iterations * n_samples_ + i; uint64_t seed = init_seed(id, STREAM_VOLUME); - p.n_coord_ = 1; + p.n_coord() = 1; Position xi {prn(&seed), prn(&seed), prn(&seed)}; p.r() = lower_left_ + xi*(upper_right_ - lower_left_); p.u() = {0.5, 0.5, 0.5}; @@ -139,28 +141,33 @@ std::vector VolumeCalculation::execute() const continue; if (domain_type_ == TallyDomain::MATERIAL) { - if (p.material_ != MATERIAL_VOID) { + if (p.material() != MATERIAL_VOID) { for (int i_domain = 0; i_domain < n; i_domain++) { - if (model::materials[p.material_]->id_ == domain_ids_[i_domain]) { - this->check_hit(p.material_, indices[i_domain], hits[i_domain]); + if (model::materials[p.material()]->id_ == + domain_ids_[i_domain]) { + this->check_hit( + p.material(), indices[i_domain], hits[i_domain]); break; } } } } else if (domain_type_ == TallyDomain::CELL) { - for (int level = 0; level < p.n_coord_; ++level) { + for (int level = 0; level < p.n_coord(); ++level) { for (int i_domain=0; i_domain < n; i_domain++) { - if (model::cells[p.coord_[level].cell]->id_ == domain_ids_[i_domain]) { - this->check_hit(p.material_, indices[i_domain], hits[i_domain]); + if (model::cells[p.coord(level).cell]->id_ == + domain_ids_[i_domain]) { + this->check_hit( + p.material(), indices[i_domain], hits[i_domain]); break; } } } } else if (domain_type_ == TallyDomain::UNIVERSE) { - for (int level = 0; level < p.n_coord_; ++level) { + for (int level = 0; level < p.n_coord(); ++level) { for (int i_domain = 0; i_domain < n; ++i_domain) { - if (model::universes[p.coord_[level].universe]->id_ == domain_ids_[i_domain]) { - check_hit(p.material_, indices[i_domain], hits[i_domain]); + if (model::universes[p.coord(level).universe]->id_ == + domain_ids_[i_domain]) { + check_hit(p.material(), indices[i_domain], hits[i_domain]); break; } } @@ -219,7 +226,7 @@ std::vector VolumeCalculation::execute() const double trigger_val = -INFTY; // Set size for members of the Result struct - std::vector results(n); + vector results(n); for (int i_domain = 0; i_domain < n; ++i_domain) { // Get reference to result for this domain @@ -235,7 +242,7 @@ std::vector VolumeCalculation::execute() const for (int j = 1; j < mpi::n_procs; j++) { int q; MPI_Recv(&q, 1, MPI_INTEGER, j, 2*j, mpi::intracomm, MPI_STATUS_IGNORE); - std::vector buffer(2*q); + vector buffer(2 * q); MPI_Recv(buffer.data(), 2*q, MPI_INTEGER, j, 2*j + 1, mpi::intracomm, MPI_STATUS_IGNORE); for (int k = 0; k < q; ++k) { bool already_added = false; @@ -254,7 +261,7 @@ std::vector VolumeCalculation::execute() const } } else { int q = master_indices[i_domain].size(); - std::vector buffer(2*q); + vector buffer(2 * q); for (int k = 0; k < q; ++k) { buffer[2*k] = master_indices[i_domain][k]; buffer[2*k + 1] = master_hits[i_domain][k]; @@ -348,8 +355,8 @@ std::vector VolumeCalculation::execute() const } // end while } -void VolumeCalculation::to_hdf5(const std::string& filename, - const std::vector& results) const +void VolumeCalculation::to_hdf5( + const std::string& filename, const vector& results) const { // Create HDF5 file hid_t file_id = file_open(filename, 'w'); @@ -413,7 +420,7 @@ void VolumeCalculation::to_hdf5(const std::string& filename, // Create array of nuclide names from the vector auto n_nuc = result.nuclides.size(); - std::vector nucnames; + vector nucnames; for (int i_nuc : result.nuclides) { nucnames.push_back(data::nuclides[i_nuc]->name_); } @@ -433,8 +440,8 @@ void VolumeCalculation::to_hdf5(const std::string& filename, file_close(file_id); } -void VolumeCalculation::check_hit(int i_material, std::vector& indices, - std::vector& hits) const +void VolumeCalculation::check_hit( + int i_material, vector& indices, vector& hits) const { // Check if this material was previously hit and if so, increment count diff --git a/src/wmp.cpp b/src/wmp.cpp index 6a56ddd0f..4299b9400 100644 --- a/src/wmp.cpp +++ b/src/wmp.cpp @@ -105,7 +105,7 @@ WindowedMultipole::evaluate(double E, double sqrtkT) const if (sqrtkT > 0.0 && window.broaden_poly) { // Broaden the curvefit. double dopp = sqrt_awr_ / sqrtkT; - std::array broadened_polynomials; + array broadened_polynomials; broaden_wmp_polynomials(E, dopp, fit_order_ + 1, broadened_polynomials.data()); for (int i_poly = 0; i_poly < fit_order_ + 1; ++i_poly) { sig_s += curvefit_(i_window, i_poly, FIT_S) * broadened_polynomials[i_poly]; @@ -216,7 +216,7 @@ WindowedMultipole::evaluate_deriv(double E, double sqrtkT) const void check_wmp_version(hid_t file) { if (attribute_exists(file, "version")) { - std::array version; + array version; read_attribute(file, "version", version); if (version[0] != WMP_VERSION[0]) { fatal_error(fmt::format( @@ -252,7 +252,7 @@ void read_multipole_data(int i_nuclide) // Read nuclide data from HDF5 hid_t group = open_group(file, nuc->name_.c_str()); - nuc->multipole_ = std::make_unique(group); + nuc->multipole_ = make_unique(group); close_group(group); file_close(file); } diff --git a/src/xsdata.cpp b/src/xsdata.cpp index ff360c052..4cfc0b85a 100644 --- a/src/xsdata.cpp +++ b/src/xsdata.cpp @@ -37,7 +37,7 @@ XsData::XsData(bool fissionable, AngleDistributionType scatter_format, int n_pol fatal_error("Invalid scatter_format!"); } // allocate all [temperature][angle][in group] quantities - std::vector shape {n_ang, n_g_}; + vector shape {n_ang, n_g_}; total = xt::zeros(shape); absorption = xt::zeros(shape); inverse_velocity = xt::zeros(shape); @@ -509,9 +509,8 @@ XsData::scatter_from_hdf5(hid_t xsdata_grp, size_t n_ang, AngleDistributionType //============================================================================== -void -XsData::combine(const std::vector& those_xs, - const std::vector& scalars) +void XsData::combine( + const vector& those_xs, const vector& scalars) { // Combine the non-scattering data for (size_t i = 0; i < those_xs.size(); i++) { @@ -551,7 +550,7 @@ XsData::combine(const std::vector& those_xs, // Allow the ScattData object to combine itself for (size_t a = 0; a < total.shape()[0]; a++) { // Build vector of the scattering objects to incorporate - std::vector those_scatts(those_xs.size()); + vector those_scatts(those_xs.size()); for (size_t i = 0; i < those_xs.size(); i++) { those_scatts[i] = those_xs[i]->scatter[a].get(); } diff --git a/tests/regression_tests/source_dlopen/source_sampling.cpp b/tests/regression_tests/source_dlopen/source_sampling.cpp index 8eaf6265c..2c6de6d85 100644 --- a/tests/regression_tests/source_dlopen/source_sampling.cpp +++ b/tests/regression_tests/source_dlopen/source_sampling.cpp @@ -1,17 +1,17 @@ #include #include +#include "openmc/particle_data.h" #include "openmc/random_lcg.h" #include "openmc/source.h" -#include "openmc/particle.h" class CustomSource : public openmc::Source { - openmc::Particle::Bank sample(uint64_t *seed) const + openmc::SourceSite sample(uint64_t* seed) const { - openmc::Particle::Bank particle; + openmc::SourceSite particle; // wgt - particle.particle = openmc::Particle::Type::neutron; + particle.particle = openmc::ParticleType::neutron; particle.wgt = 1.0; // position diff --git a/tests/regression_tests/source_parameterized_dlopen/parameterized_source_sampling.cpp b/tests/regression_tests/source_parameterized_dlopen/parameterized_source_sampling.cpp index da7d70e37..bf49af4c3 100644 --- a/tests/regression_tests/source_parameterized_dlopen/parameterized_source_sampling.cpp +++ b/tests/regression_tests/source_parameterized_dlopen/parameterized_source_sampling.cpp @@ -1,16 +1,16 @@ +#include "openmc/particle_data.h" #include "openmc/source.h" -#include "openmc/particle.h" class CustomSource : public openmc::Source { public: CustomSource(double energy) : energy_(energy) { } // Samples from an instance of this class. - openmc::Particle::Bank sample(uint64_t* seed) const + openmc::SourceSite sample(uint64_t* seed) const { - openmc::Particle::Bank particle; + openmc::SourceSite particle; // wgt - particle.particle = openmc::Particle::Type::neutron; + particle.particle = openmc::ParticleType::neutron; particle.wgt = 1.0; // position particle.r.x = 0.0;