Skip to content

Commit d5d2072

Browse files
committed
change particle to using accessor methods
1 parent 711c60e commit d5d2072

38 files changed

Lines changed: 1234 additions & 1031 deletions

‎include/openmc/event.h‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ struct EventQueueItem{
3131

3232
// Constructors
3333
EventQueueItem() = default;
34-
EventQueueItem(const Particle& p, int64_t buffer_idx) :
35-
idx(buffer_idx), type(p.type_), material(p.material_), E(p.E_) {}
34+
EventQueueItem(const Particle& p, int64_t buffer_idx)
35+
: idx(buffer_idx), type(p.type()), material(p.material()), E(p.E())
36+
{}
3637

3738
// Compare by particle type, then by material type (4.5% fuel/7.0% fuel/cladding/etc),
3839
// then by energy.

‎include/openmc/particle.h‎

Lines changed: 141 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -187,25 +187,6 @@ class Particle {
187187

188188
Particle();
189189

190-
//==========================================================================
191-
// Methods and accessors
192-
193-
// Accessors for position in global coordinates
194-
Position& r() { return coord_[0].r; }
195-
const Position& r() const { return coord_[0].r; }
196-
197-
// Accessors for position in local coordinates
198-
Position& r_local() { return coord_[n_coord_ - 1].r; }
199-
const Position& r_local() const { return coord_[n_coord_ - 1].r; }
200-
201-
// Accessors for direction in global coordinates
202-
Direction& u() { return coord_[0].u; }
203-
const Direction& u() const { return coord_[0].u; }
204-
205-
// Accessors for direction in local coordinates
206-
Direction& u_local() { return coord_[n_coord_ - 1].u; }
207-
const Direction& u_local() const { return coord_[n_coord_ - 1].u; }
208-
209190
//! resets all coordinate levels for the particle
210191
void clear();
211192

@@ -279,8 +260,16 @@ class Particle {
279260
uint64_t* current_seed() {return seeds_ + stream_;}
280261
const uint64_t* current_seed() const {return seeds_ + stream_;}
281262

263+
//! Force recalculation of neutron xs by setting last energy to zero
264+
void invalidate_neutron_xs()
265+
{
266+
for (auto& micro : neutron_xs_)
267+
micro.last_E = 0.0;
268+
}
269+
270+
private:
282271
//==========================================================================
283-
// Data members
272+
// Data members (accessor methods are below)
284273

285274
// Cross section caches
286275
std::vector<NuclideMicroXS> neutron_xs_; //!< Microscopic neutron cross sections
@@ -387,6 +376,138 @@ class Particle {
387376
#endif
388377

389378
int64_t n_progeny_ {0}; // Number of progeny produced by this particle
379+
380+
public:
381+
//==========================================================================
382+
// Methods and accessors
383+
384+
NuclideMicroXS& neutron_xs(const int& i) { return neutron_xs_[i]; }
385+
const NuclideMicroXS& neutron_xs(const int& i) const
386+
{
387+
return neutron_xs_[i];
388+
}
389+
ElementMicroXS& photon_xs(const int& i) { return photon_xs_[i]; }
390+
MacroXS& macro_xs() { return macro_xs_; }
391+
const MacroXS& macro_xs() const { return macro_xs_; }
392+
393+
int64_t& id() { return id_; }
394+
Type& type() { return type_; }
395+
const Type& type() const { return type_; }
396+
397+
int& n_coord() { return n_coord_; }
398+
const int& n_coord() const { return n_coord_; }
399+
int& cell_instance() { return cell_instance_; }
400+
const int& cell_instance() const { return cell_instance_; }
401+
LocalCoord& coord(const int& i) { return coord_[i]; }
402+
const LocalCoord& coord(const int& i) const { return coord_[i]; }
403+
404+
int& n_coord_last() { return n_coord_last_; }
405+
const int& n_coord_last() const { return n_coord_last_; }
406+
int& cell_last(const int& i) { return cell_last_[i]; }
407+
const int& cell_last(const int& i) const { return cell_last_[i]; }
408+
409+
double& E() { return E_; }
410+
const double& E() const { return E_; }
411+
double& E_last() { return E_last_; }
412+
const double& E_last() const { return E_last_; }
413+
int& g() { return g_; }
414+
const int& g() const { return g_; }
415+
int& g_last() { return g_last_; }
416+
const int& g_last() const { return g_last_; }
417+
418+
double& wgt() { return wgt_; }
419+
double& mu() { return mu_; }
420+
const double& mu() const { return mu_; }
421+
bool& alive() { return alive_; }
422+
423+
Position& r_last_current() { return r_last_current_; }
424+
const Position& r_last_current() const { return r_last_current_; }
425+
Position& r_last() { return r_last_; }
426+
const Position& r_last() const { return r_last_; }
427+
Position& u_last() { return u_last_; }
428+
const Position& u_last() const { return u_last_; }
429+
double& wgt_last() { return wgt_last_; }
430+
const double& wgt_last() const { return wgt_last_; }
431+
double& wgt_absorb() { return wgt_absorb_; }
432+
const double& wgt_absorb() const { return wgt_absorb_; }
433+
434+
bool& fission() { return fission_; }
435+
TallyEvent& event() { return event_; }
436+
const TallyEvent& event() const { return event_; }
437+
int& event_nuclide() { return event_nuclide_; }
438+
const int& event_nuclide() const { return event_nuclide_; }
439+
int& event_mt() { return event_mt_; }
440+
int& delayed_group() { return delayed_group_; }
441+
442+
int& n_bank() { return n_bank_; }
443+
int& n_bank_second() { return n_bank_second_; }
444+
double& wgt_bank() { return wgt_bank_; }
445+
int* n_delayed_bank() { return n_delayed_bank_; }
446+
int& n_delayed_bank(const int& i) { return n_delayed_bank_[i]; }
447+
448+
int& surface() { return surface_; }
449+
const int& surface() const { return surface_; }
450+
int& cell_born() { return cell_born_; }
451+
const int& cell_born() const { return cell_born_; }
452+
int& material() { return material_; }
453+
const int& material() const { return material_; }
454+
int& material_last() { return material_last_; }
455+
456+
BoundaryInfo& boundary() { return boundary_; }
457+
458+
double& sqrtkT() { return sqrtkT_; }
459+
const double& sqrtkT() const { return sqrtkT_; }
460+
double& sqrtkT_last() { return sqrtkT_last_; }
461+
462+
int& n_collision() { return n_collision_; }
463+
464+
bool& write_track() { return write_track_; }
465+
uint64_t& seeds(const int& i) { return seeds_[i]; }
466+
uint64_t* seeds() { return seeds_; }
467+
int& stream() { return stream_; }
468+
469+
Particle::Bank& secondary_bank(const int& i) { return secondary_bank_[i]; }
470+
decltype(secondary_bank_)& secondary_bank() { return secondary_bank_; }
471+
int64_t& current_work() { return current_work_; }
472+
decltype(flux_derivs_)& flux_derivs() { return flux_derivs_; }
473+
const decltype(flux_derivs_)& flux_derivs() const { return flux_derivs_; }
474+
decltype(filter_matches_)& filter_matches() { return filter_matches_; }
475+
FilterMatch& filter_matches(const int& i) { return filter_matches_[i]; }
476+
decltype(tracks_)& tracks() { return tracks_; }
477+
decltype(nu_bank_)& nu_bank() { return nu_bank_; }
478+
NuBank& nu_bank(const int& i) { return nu_bank_[i]; }
479+
480+
double& keff_tally_absorption() { return keff_tally_absorption_; }
481+
double& keff_tally_collision() { return keff_tally_collision_; }
482+
double& keff_tally_tracklength() { return keff_tally_tracklength_; }
483+
double& keff_tally_leakage() { return keff_tally_leakage_; }
484+
485+
bool& trace() { return trace_; }
486+
double& collision_distance() { return collision_distance_; }
487+
int& n_event() { return n_event_; }
488+
489+
#ifdef DAGMC
490+
moab::DagMC::RayHistory& rayhistory() { return history_; }
491+
Direction& last_dir() { return last_dir_; }
492+
#endif
493+
494+
int64_t& n_progeny() { return n_progeny_; }
495+
496+
// Accessors for position in global coordinates
497+
Position& r() { return coord_[0].r; }
498+
const Position& r() const { return coord_[0].r; }
499+
500+
// Accessors for position in local coordinates
501+
Position& r_local() { return coord_[n_coord_ - 1].r; }
502+
const Position& r_local() const { return coord_[n_coord_ - 1].r; }
503+
504+
// Accessors for direction in global coordinates
505+
Direction& u() { return coord_[0].u; }
506+
const Direction& u() const { return coord_[0].u; }
507+
508+
// Accessors for direction in local coordinates
509+
Direction& u_local() { return coord_[n_coord_ - 1].u; }
510+
const Direction& u_local() const { return coord_[n_coord_ - 1].u; }
390511
};
391512

392513
//============================================================================

‎include/openmc/plot.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ T PlotBase::get_map() const {
171171
Particle p;
172172
p.r() = xyz;
173173
p.u() = dir;
174-
p.coord_[0].universe = model::root_universe;
174+
p.coord(0).universe = model::root_universe;
175175
int level = level_;
176176
int j{};
177177

@@ -180,10 +180,10 @@ T PlotBase::get_map() const {
180180
p.r()[out_i] = xyz[out_i] - out_pixel * y;
181181
for (int x = 0; x < width; x++) {
182182
p.r()[in_i] = xyz[in_i] + in_pixel * x;
183-
p.n_coord_ = 1;
183+
p.n_coord() = 1;
184184
// local variables
185185
bool found_cell = exhaustive_find_cell(p);
186-
j = p.n_coord_ - 1;
186+
j = p.n_coord() - 1;
187187
if (level >= 0) { j = level; }
188188
if (found_cell) {
189189
data.set_value(y, x, p, j);

‎src/boundary_condition.cpp‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,18 +113,18 @@ void
113113
TranslationalPeriodicBC::handle_particle(Particle& p, const Surface& surf) const
114114
{
115115
// TODO: off-by-one on surface indices throughout this function.
116-
int i_particle_surf = std::abs(p.surface_) - 1;
116+
int i_particle_surf = std::abs(p.surface()) - 1;
117117

118118
// Figure out which of the two BC surfaces were struck then find the
119119
// particle's new location and surface.
120120
Position new_r;
121121
int new_surface;
122122
if (i_particle_surf == i_surf_) {
123123
new_r = p.r() + translation_;
124-
new_surface = p.surface_ > 0 ? j_surf_ + 1 : -(j_surf_ + 1);
124+
new_surface = p.surface() > 0 ? j_surf_ + 1 : -(j_surf_ + 1);
125125
} else if (i_particle_surf == j_surf_) {
126126
new_r = p.r() - translation_;
127-
new_surface = p.surface_ > 0 ? i_surf_ + 1 : -(i_surf_ + 1);
127+
new_surface = p.surface() > 0 ? i_surf_ + 1 : -(i_surf_ + 1);
128128
} else {
129129
throw std::runtime_error("Called BoundaryCondition::handle_particle after "
130130
"hitting a surface, but that surface is not recognized by the BC.");
@@ -222,7 +222,7 @@ void
222222
RotationalPeriodicBC::handle_particle(Particle& p, const Surface& surf) const
223223
{
224224
// TODO: off-by-one on surface indices throughout this function.
225-
int i_particle_surf = std::abs(p.surface_) - 1;
225+
int i_particle_surf = std::abs(p.surface()) - 1;
226226

227227
// Figure out which of the two BC surfaces were struck to figure out if a
228228
// forward or backward rotation is required. Specify the other surface as
@@ -231,10 +231,10 @@ RotationalPeriodicBC::handle_particle(Particle& p, const Surface& surf) const
231231
int new_surface;
232232
if (i_particle_surf == i_surf_) {
233233
theta = angle_;
234-
new_surface = p.surface_ > 0 ? -(j_surf_ + 1) : j_surf_ + 1;
234+
new_surface = p.surface() > 0 ? -(j_surf_ + 1) : j_surf_ + 1;
235235
} else if (i_particle_surf == j_surf_) {
236236
theta = -angle_;
237-
new_surface = p.surface_ > 0 ? -(i_surf_ + 1) : i_surf_ + 1;
237+
new_surface = p.surface() > 0 ? -(i_surf_ + 1) : i_surf_ + 1;
238238
} else {
239239
throw std::runtime_error("Called BoundaryCondition::handle_particle after "
240240
"hitting a surface, but that surface is not recognized by the BC.");

‎src/bremsstrahlung.cpp‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,22 @@ std::vector<Bremsstrahlung> ttb;
2828

2929
void thick_target_bremsstrahlung(Particle& p, double* E_lost)
3030
{
31-
if (p.material_ == MATERIAL_VOID) return;
31+
if (p.material() == MATERIAL_VOID)
32+
return;
3233

3334
int photon = static_cast<int>(Particle::Type::photon);
34-
if (p.E_ < settings::energy_cutoff[photon]) return;
35+
if (p.E() < settings::energy_cutoff[photon])
36+
return;
3537

3638
// Get bremsstrahlung data for this material and particle type
3739
BremsstrahlungData* mat;
38-
if (p.type_ == Particle::Type::positron) {
39-
mat = &model::materials[p.material_]->ttb_->positron;
40+
if (p.type() == Particle::Type::positron) {
41+
mat = &model::materials[p.material()]->ttb_->positron;
4042
} else {
41-
mat = &model::materials[p.material_]->ttb_->electron;
43+
mat = &model::materials[p.material()]->ttb_->electron;
4244
}
4345

44-
double e = std::log(p.E_);
46+
double e = std::log(p.E());
4547
auto n_e = data::ttb_e_grid.size();
4648

4749
// Find the lower bounding index of the incident electron energy
@@ -108,7 +110,7 @@ void thick_target_bremsstrahlung(Particle& p, double* E_lost)
108110

109111
if (w > settings::energy_cutoff[photon]) {
110112
// Create secondary photon
111-
p.create_secondary(p.wgt_, p.u(), w, Particle::Type::photon);
113+
p.create_secondary(p.wgt(), p.u(), w, Particle::Type::photon);
112114
*E_lost += w;
113115
}
114116
}

‎src/event.cpp‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ void free_event_queues(void)
5050
void dispatch_xs_event(int64_t buffer_idx)
5151
{
5252
Particle& p = simulation::particles[buffer_idx];
53-
if (p.material_ == MATERIAL_VOID || !model::materials[p.material_]->fissionable_) {
53+
if (p.material() == MATERIAL_VOID ||
54+
!model::materials[p.material()]->fissionable_) {
5455
simulation::calculate_nonfuel_xs_queue.thread_safe_append({p, buffer_idx});
5556
} else {
5657
simulation::calculate_fuel_xs_queue.thread_safe_append({p, buffer_idx});
@@ -109,7 +110,7 @@ void process_advance_particle_events()
109110
int64_t buffer_idx = simulation::advance_particle_queue[i].idx;
110111
Particle& p = simulation::particles[buffer_idx];
111112
p.event_advance();
112-
if (p.collision_distance_ > p.boundary_.distance) {
113+
if (p.collision_distance() > p.boundary().distance) {
113114
simulation::surface_crossing_queue.thread_safe_append({p, buffer_idx});
114115
} else {
115116
simulation::collision_queue.thread_safe_append({p, buffer_idx});
@@ -131,7 +132,7 @@ void process_surface_crossing_events()
131132
Particle& p = simulation::particles[buffer_idx];
132133
p.event_cross_surface();
133134
p.event_revive_from_secondary();
134-
if (p.alive_)
135+
if (p.alive())
135136
dispatch_xs_event(buffer_idx);
136137
}
137138

@@ -150,7 +151,7 @@ void process_collision_events()
150151
Particle& p = simulation::particles[buffer_idx];
151152
p.event_collide();
152153
p.event_revive_from_secondary();
153-
if (p.alive_)
154+
if (p.alive())
154155
dispatch_xs_event(buffer_idx);
155156
}
156157

0 commit comments

Comments
 (0)