• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

openmc-dev / openmc / 17836684803

18 Sep 2025 05:32PM UTC coverage: 85.218%. Remained the same
17836684803

Pull #3574

github

web-flow
Merge 32b14f760 into afd9d0607
Pull Request #3574: removed todos related to c++17 support

4 of 4 new or added lines in 3 files covered. (100.0%)

2 existing lines in 1 file now uncovered.

53016 of 62212 relevant lines covered (85.22%)

39245995.99 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

87.72
/src/event.cpp
1
#include "openmc/event.h"
2

3
#include "openmc/material.h"
4
#include "openmc/simulation.h"
5
#include "openmc/timer.h"
6

7
#include <execution>
8

9
namespace openmc {
10

11
//==============================================================================
12
// Global variables
13
//==============================================================================
14

15
namespace simulation {
16

17
SharedArray<EventQueueItem> calculate_fuel_xs_queue;
18
SharedArray<EventQueueItem> calculate_nonfuel_xs_queue;
19
SharedArray<EventQueueItem> advance_particle_queue;
20
SharedArray<EventQueueItem> surface_crossing_queue;
21
SharedArray<EventQueueItem> collision_queue;
22

23
vector<Particle> particles;
24

25
} // namespace simulation
26

27
//==============================================================================
28
// Non-member functions
29
//==============================================================================
30

31
void init_event_queues(int64_t n_particles)
174✔
32
{
33
  simulation::calculate_fuel_xs_queue.reserve(n_particles);
174✔
34
  simulation::calculate_nonfuel_xs_queue.reserve(n_particles);
174✔
35
  simulation::advance_particle_queue.reserve(n_particles);
174✔
36
  simulation::surface_crossing_queue.reserve(n_particles);
174✔
37
  simulation::collision_queue.reserve(n_particles);
174✔
38

39
  simulation::particles.resize(n_particles);
174✔
40
}
174✔
41

42
void free_event_queues(void)
×
43
{
44
  simulation::calculate_fuel_xs_queue.clear();
×
45
  simulation::calculate_nonfuel_xs_queue.clear();
×
46
  simulation::advance_particle_queue.clear();
×
UNCOV
47
  simulation::surface_crossing_queue.clear();
×
48
  simulation::collision_queue.clear();
×
49

UNCOV
50
  simulation::particles.clear();
×
51
}
52

53
void dispatch_xs_event(int64_t buffer_idx)
226,074,296✔
54
{
55
  Particle& p = simulation::particles[buffer_idx];
226,074,296✔
56
  if (p.material() == MATERIAL_VOID ||
435,247,095✔
57
      !model::materials[p.material()]->fissionable()) {
209,172,799✔
58
    simulation::calculate_nonfuel_xs_queue.thread_safe_append({p, buffer_idx});
49,192,931✔
59
  } else {
60
    simulation::calculate_fuel_xs_queue.thread_safe_append({p, buffer_idx});
176,881,365✔
61
  }
62
}
226,074,296✔
63

64
void process_init_events(int64_t n_particles, int64_t source_offset)
3,101✔
65
{
66
  simulation::time_event_init.start();
3,101✔
67
#pragma omp parallel for schedule(runtime)
3,101✔
68
  for (int64_t i = 0; i < n_particles; i++) {
69
    initialize_history(simulation::particles[i], source_offset + i + 1);
70
    dispatch_xs_event(i);
71
  }
72
  simulation::time_event_init.stop();
3,101✔
73
}
3,101✔
74

75
void process_calculate_xs_events(SharedArray<EventQueueItem>& queue)
782,086✔
76
{
77
  simulation::time_event_calculate_xs.start();
782,086✔
78

79
  // Perform a parallel sort of the queue
80
  // by particle type, material type, and then energy, in order to
81
  // improve cache locality and reduce thread divergence on GPU.
82
  std::sort(
782,086✔
83
    std::execution::par_unseq, queue.data(), queue.data() + queue.size());
782,086✔
84

85
  int64_t offset = simulation::advance_particle_queue.size();
782,086✔
86
  ;
87

88
#pragma omp parallel for schedule(runtime)
782,086✔
89
  for (int64_t i = 0; i < queue.size(); i++) {
90
    Particle* p = &simulation::particles[queue[i].idx];
91
    p->event_calculate_xs();
92

93
    // After executing a calculate_xs event, particles will
94
    // always require an advance event. Therefore, we don't need to use
95
    // the protected enqueuing function.
96
    simulation::advance_particle_queue[offset + i] = queue[i];
97
  }
98

99
  simulation::advance_particle_queue.resize(offset + queue.size());
782,086✔
100

101
  queue.resize(0);
782,086✔
102

103
  simulation::time_event_calculate_xs.stop();
782,086✔
104
}
782,086✔
105

106
void process_advance_particle_events()
777,048✔
107
{
108
  simulation::time_event_advance_particle.start();
777,048✔
109

110
#pragma omp parallel for schedule(runtime)
111
  for (int64_t i = 0; i < simulation::advance_particle_queue.size(); i++) {
112
    int64_t buffer_idx = simulation::advance_particle_queue[i].idx;
113
    Particle& p = simulation::particles[buffer_idx];
114
    p.event_advance();
115
    if (!p.alive())
116
      continue;
117
    if (p.collision_distance() > p.boundary().distance()) {
118
      simulation::surface_crossing_queue.thread_safe_append({p, buffer_idx});
119
    } else {
120
      simulation::collision_queue.thread_safe_append({p, buffer_idx});
121
    }
122
  }
123

124
  simulation::advance_particle_queue.resize(0);
777,048✔
125

126
  simulation::time_event_advance_particle.stop();
777,048✔
127
}
777,048✔
128

129
void process_surface_crossing_events()
261,991✔
130
{
131
  simulation::time_event_surface_crossing.start();
261,991✔
132

133
#pragma omp parallel for schedule(runtime)
134
  for (int64_t i = 0; i < simulation::surface_crossing_queue.size(); i++) {
135
    int64_t buffer_idx = simulation::surface_crossing_queue[i].idx;
136
    Particle& p = simulation::particles[buffer_idx];
137
    p.event_cross_surface();
138
    p.event_revive_from_secondary();
139
    if (p.alive())
140
      dispatch_xs_event(buffer_idx);
141
  }
142

143
  simulation::surface_crossing_queue.resize(0);
261,991✔
144

145
  simulation::time_event_surface_crossing.stop();
261,991✔
146
}
261,991✔
147

148
void process_collision_events()
533,866✔
149
{
150
  simulation::time_event_collision.start();
533,866✔
151

152
#pragma omp parallel for schedule(runtime)
153
  for (int64_t i = 0; i < simulation::collision_queue.size(); i++) {
154
    int64_t buffer_idx = simulation::collision_queue[i].idx;
155
    Particle& p = simulation::particles[buffer_idx];
156
    p.event_collide();
157
    p.event_revive_from_secondary();
158
    if (p.alive())
159
      dispatch_xs_event(buffer_idx);
160
  }
161

162
  simulation::collision_queue.resize(0);
533,866✔
163

164
  simulation::time_event_collision.stop();
533,866✔
165
}
533,866✔
166

167
void process_death_events(int64_t n_particles)
3,101✔
168
{
169
  simulation::time_event_death.start();
3,101✔
170
#pragma omp parallel for schedule(runtime)
3,101✔
171
  for (int64_t i = 0; i < n_particles; i++) {
172
    Particle& p = simulation::particles[i];
173
    p.event_death();
174
  }
175
  simulation::time_event_death.stop();
3,101✔
176
}
3,101✔
177

178
} // namespace openmc
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc