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

openmc-dev / openmc / 26417381072

25 May 2026 07:53PM UTC coverage: 81.098% (-0.2%) from 81.333%
26417381072

Pull #3943

github

web-flow
Merge 5708ab11a into dfb6c5699
Pull Request #3943: Fix undefined variable in openmc.mgxs.library (scatt_mgxs)

17921 of 26080 branches covered (68.72%)

Branch coverage included in aggregate %.

2 of 5 new or added lines in 1 file covered. (40.0%)

160 existing lines in 7 files now uncovered.

58952 of 68710 relevant lines covered (85.8%)

46432090.6 hits per line

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

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

3
#include "openmc/bank.h"
4
#include "openmc/error.h"
5
#include "openmc/material.h"
6
#include "openmc/settings.h"
7
#include "openmc/simulation.h"
8
#include "openmc/timer.h"
9

10
namespace openmc {
11

12
//==============================================================================
13
// Global variables
14
//==============================================================================
15

16
namespace simulation {
17

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

24
vector<Particle> particles;
25

26
} // namespace simulation
27

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

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

UNCOV
40
  simulation::particles.resize(n_particles);
×
UNCOV
41
}
×
42

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

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

UNCOV
54
void dispatch_xs_event(int64_t buffer_idx)
×
55
{
UNCOV
56
  Particle& p = simulation::particles[buffer_idx];
×
UNCOV
57
  if (p.material() == MATERIAL_VOID ||
×
UNCOV
58
      !model::materials[p.material()]->fissionable()) {
×
UNCOV
59
    simulation::calculate_nonfuel_xs_queue.thread_safe_append({p, buffer_idx});
×
60
  } else {
UNCOV
61
    simulation::calculate_fuel_xs_queue.thread_safe_append({p, buffer_idx});
×
62
  }
UNCOV
63
}
×
64

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

UNCOV
77
void process_calculate_xs_events(SharedArray<EventQueueItem>& queue)
×
78
{
UNCOV
79
  simulation::time_event_calculate_xs.start();
×
80

81
  // TODO: If using C++17, we could perform a parallel sort of the queue by
82
  // particle type, material type, and then energy, in order to improve cache
83
  // locality and reduce thread divergence on GPU. However, the parallel
84
  // algorithms typically require linking against an additional library (Intel
85
  // TBB). Prior to C++17, std::sort is a serial only operation, which in this
86
  // case makes it too slow to be practical for most test problems.
87
  //
88
  // std::sort(std::execution::par_unseq, queue.data(), queue.data() +
89
  // queue.size());
90

UNCOV
91
  int64_t offset = simulation::advance_particle_queue.size();
×
92

93
#pragma omp parallel for schedule(runtime)
94
  for (int64_t i = 0; i < queue.size(); i++) {
×
95
    Particle* p = &simulation::particles[queue[i].idx];
96
    p->event_calculate_xs();
97

98
    // After executing a calculate_xs event, particles will
99
    // always require an advance event. Therefore, we don't need to use
100
    // the protected enqueuing function.
101
    simulation::advance_particle_queue[offset + i] = queue[i];
102
  }
103

UNCOV
104
  simulation::advance_particle_queue.resize(offset + queue.size());
×
105

UNCOV
106
  queue.resize(0);
×
107

UNCOV
108
  simulation::time_event_calculate_xs.stop();
×
UNCOV
109
}
×
110

UNCOV
111
void process_advance_particle_events()
×
112
{
UNCOV
113
  simulation::time_event_advance_particle.start();
×
114

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

UNCOV
129
  simulation::advance_particle_queue.resize(0);
×
130

UNCOV
131
  simulation::time_event_advance_particle.stop();
×
UNCOV
132
}
×
133

UNCOV
134
void process_surface_crossing_events()
×
135
{
UNCOV
136
  simulation::time_event_surface_crossing.start();
×
137

138
#pragma omp parallel for schedule(runtime)
139
  for (int64_t i = 0; i < simulation::surface_crossing_queue.size(); i++) {
×
140
    int64_t buffer_idx = simulation::surface_crossing_queue[i].idx;
141
    Particle& p = simulation::particles[buffer_idx];
142
    p.event_cross_surface();
143
    p.event_check_limit_and_revive();
144
    if (p.alive())
×
145
      dispatch_xs_event(buffer_idx);
146
  }
147

UNCOV
148
  simulation::surface_crossing_queue.resize(0);
×
149

UNCOV
150
  simulation::time_event_surface_crossing.stop();
×
UNCOV
151
}
×
152

UNCOV
153
void process_collision_events()
×
154
{
UNCOV
155
  simulation::time_event_collision.start();
×
156

157
#pragma omp parallel for schedule(runtime)
158
  for (int64_t i = 0; i < simulation::collision_queue.size(); i++) {
×
159
    int64_t buffer_idx = simulation::collision_queue[i].idx;
160
    Particle& p = simulation::particles[buffer_idx];
161
    p.event_collide();
162
    p.event_check_limit_and_revive();
163
    if (p.alive())
×
164
      dispatch_xs_event(buffer_idx);
165
  }
166

UNCOV
167
  simulation::collision_queue.resize(0);
×
168

UNCOV
169
  simulation::time_event_collision.stop();
×
UNCOV
170
}
×
171

UNCOV
172
void process_death_events(int64_t n_particles)
×
173
{
UNCOV
174
  simulation::time_event_death.start();
×
175
#pragma omp parallel for schedule(runtime)
176
  for (int64_t i = 0; i < n_particles; i++) {
×
177
    Particle& p = simulation::particles[i];
178
    p.event_death();
179
  }
UNCOV
180
  simulation::time_event_death.stop();
×
UNCOV
181
}
×
182

UNCOV
183
void process_transport_events()
×
184
{
UNCOV
185
  while (true) {
×
UNCOV
186
    int64_t max = std::max({simulation::calculate_fuel_xs_queue.size(),
×
UNCOV
187
      simulation::calculate_nonfuel_xs_queue.size(),
×
UNCOV
188
      simulation::advance_particle_queue.size(),
×
UNCOV
189
      simulation::surface_crossing_queue.size(),
×
UNCOV
190
      simulation::collision_queue.size()});
×
191

UNCOV
192
    if (max == 0) {
×
193
      break;
UNCOV
194
    } else if (max == simulation::calculate_fuel_xs_queue.size()) {
×
UNCOV
195
      process_calculate_xs_events(simulation::calculate_fuel_xs_queue);
×
UNCOV
196
    } else if (max == simulation::calculate_nonfuel_xs_queue.size()) {
×
UNCOV
197
      process_calculate_xs_events(simulation::calculate_nonfuel_xs_queue);
×
UNCOV
198
    } else if (max == simulation::advance_particle_queue.size()) {
×
UNCOV
199
      process_advance_particle_events();
×
UNCOV
200
    } else if (max == simulation::surface_crossing_queue.size()) {
×
UNCOV
201
      process_surface_crossing_events();
×
UNCOV
202
    } else if (max == simulation::collision_queue.size()) {
×
UNCOV
203
      process_collision_events();
×
204
    }
205
  }
UNCOV
206
}
×
207

UNCOV
208
void process_init_secondary_events(int64_t n_particles, int64_t offset,
×
209
  const SharedArray<SourceSite>& shared_secondary_bank)
210
{
UNCOV
211
  simulation::time_event_init.start();
×
212
#pragma omp parallel for schedule(runtime)
213
  for (int64_t i = 0; i < n_particles; i++) {
×
214
    initialize_particle_track(simulation::particles[i], offset + i + 1, true);
215
    const SourceSite& site = shared_secondary_bank[offset + i];
216
    simulation::particles[i].event_revive_from_secondary(site);
217
    if (simulation::particles[i].alive()) {
×
218
      dispatch_xs_event(i);
219
    }
220
  }
UNCOV
221
  simulation::time_event_init.stop();
×
UNCOV
222
}
×
223

224
} // 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