diff --git a/include/openmc/particle.h b/include/openmc/particle.h index 43503bd22..f753cb119 100644 --- a/include/openmc/particle.h +++ b/include/openmc/particle.h @@ -59,27 +59,30 @@ public: neutron, photon, electron, positron }; - int64_t id_; //!< Unique ID - Type type_; //!< Particle type (n, p, e, etc.) + // Constructors + Particle(); - int n_coord_; //!< number of current coordinate levels + 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 LocalCoord coord_[MAX_COORD]; //!< coordinates for all levels // Particle coordinates before crossing a surface - int last_n_coord_; //!< number of current coordinates + int last_n_coord_ {1}; //!< number of current coordinates int last_cell_[MAX_COORD]; //!< coordinates for all levels // Energy data double E_; //!< post-collision energy in eV double last_E_; //!< pre-collision energy in eV - int g_; //!< post-collision energy group (MG only) + int g_ {0}; //!< post-collision energy group (MG only) int last_g_; //!< pre-collision energy group (MG only) // Other physical data - double wgt_; //!< particle weight + double wgt_ {1.0}; //!< particle weight double mu_; //!< angle of scatter - bool alive_; //!< is particle alive? + bool alive_ {true}; //!< is particle alive? // Other physical data double last_xyz_current_[3]; //!< coordinates of the last collision or @@ -87,36 +90,36 @@ public: //!< current tallies double last_xyz_[3]; //!< previous coordinates double last_uvw_[3]; //!< previous direction coordinates - double last_wgt_; //!< pre-collision particle weight - double absorb_wgt_; //!< weight absorbed for survival biasing + double last_wgt_ {1.0}; //!< pre-collision particle weight + double absorb_wgt_ {0.0}; //!< weight absorbed for survival biasing // What event took place - bool fission_; //!< did particle cause implicit fission + bool fission_ {false}; //!< did particle cause implicit fission int event_; //!< scatter, absorption int event_nuclide_; //!< index in nuclides array int event_mt_; //!< reaction MT - int delayed_group_; //!< delayed group + int delayed_group_ {0}; //!< delayed group // Post-collision physical data - int n_bank_; //!< number of fission sites banked - double wgt_bank_; //!< weight of fission sites banked + int n_bank_ {0}; //!< number of fission sites 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_; //!< index for surface particle is on - int cell_born_; //!< index for cell particle was born in - int material_; //!< index for current material - int last_material_; //!< index for last material + 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 last_material_ {-1}; //!< index for last material // Temperature of current cell - double sqrtkT_; //!< sqrt(k_Boltzmann * temperature) in eV - double last_sqrtkT_; //!< last temperature + double sqrtkT_ {-1.0}; //!< sqrt(k_Boltzmann * temperature) in eV + double last_sqrtkT_ {0.0}; //!< last temperature // Statistical data - int n_collision_; //!< number of collisions + int n_collision_ {0}; //!< number of collisions -// Track output + // Track output bool write_track_ {false}; // Secondary particles created @@ -136,9 +139,6 @@ public: //! \param run_CE Whether continuous-energy data is being used void create_secondary(const double* uvw, double E, Type type, bool run_CE); - //! sets default attributes for a particle - void initialize(); - //! initialize from a source site // //! initializes a particle from data stored in a source site. The source diff --git a/src/geometry.cpp b/src/geometry.cpp index 3598f8d5b..feaf6c00f 100644 --- a/src/geometry.cpp +++ b/src/geometry.cpp @@ -466,7 +466,6 @@ extern "C" int openmc_find_cell(const double* xyz, int32_t* index, int32_t* instance) { Particle p; - p.initialize(); std::copy(xyz, xyz + 3, p.coord_[0].xyz); p.coord_[0].uvw[0] = 0.0; diff --git a/src/particle.cpp b/src/particle.cpp index 4ff749ea9..287fef576 100644 --- a/src/particle.cpp +++ b/src/particle.cpp @@ -47,11 +47,22 @@ LocalCoord::reset() // Particle implementation //============================================================================== +Particle::Particle() +{ + // Clear coordinate lists + clear(); + + for (int& n : n_delayed_bank_) { + n = 0; + } +} + void Particle::clear() { // reset any coordinate levels - for (int i=0; iclear(); + alive_ = true; + surface_ = 0; + cell_born_ = C_NONE; + material_ = C_NONE; + n_collision_ = 0; + fission_ = false; // copy attributes from source bank site type_ = static_cast(src->particle); diff --git a/src/particle_restart.cpp b/src/particle_restart.cpp index 887c2d91f..7c0772879 100644 --- a/src/particle_restart.cpp +++ b/src/particle_restart.cpp @@ -83,7 +83,6 @@ void run_particle_restart() // Initialize the particle to be tracked Particle p; - p.initialize(); // Read in the restart information int previous_run_mode; diff --git a/src/plot.cpp b/src/plot.cpp index a1d24c938..c3456b3ae 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -136,7 +136,6 @@ void create_ppm(Plot pl) #pragma omp parallel { Particle p; - p.initialize(); std::copy(xyz, xyz+3, p.coord_[0].xyz); std::copy(dir, dir+3, p.coord_[0].uvw); p.coord_[0].universe = model::root_universe; @@ -854,7 +853,6 @@ void create_voxel(Plot pl) // allocate and initialize particle double dir[3] = {0.5, 0.5, 0.5}; Particle p; - p.initialize(); std::copy(ll.begin(), ll.begin()+ll.size(), p.coord_[0].xyz); std::copy(dir, dir+3, p.coord_[0].uvw); p.coord_[0].universe = model::root_universe; diff --git a/src/volume_calc.cpp b/src/volume_calc.cpp index 5ffae4b20..a23481539 100644 --- a/src/volume_calc.cpp +++ b/src/volume_calc.cpp @@ -96,7 +96,6 @@ std::vector VolumeCalculation::execute() const std::vector> indices(n); std::vector> hits(n); Particle p; - p.initialize(); prn_set_stream(STREAM_VOLUME);