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

openmc-dev / openmc / 25897159321

15 May 2026 02:35AM UTC coverage: 81.399% (+0.01%) from 81.388%
25897159321

Pull #3938

github

web-flow
Merge e2f98f01d into d56cda254
Pull Request #3938: Do not count zero energy pulse heights

17770 of 25664 branches covered (69.24%)

Branch coverage included in aggregate %.

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

688 existing lines in 41 files now uncovered.

58752 of 68344 relevant lines covered (85.97%)

62484189.48 hits per line

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

67.82
/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
namespace openmc {
8

9
//==============================================================================
10
// Global variables
11
//==============================================================================
12

13
namespace simulation {
14

15
SharedArray<EventQueueItem> calculate_fuel_xs_queue;
16
SharedArray<EventQueueItem> calculate_nonfuel_xs_queue;
17
SharedArray<EventQueueItem> advance_particle_queue;
18
SharedArray<EventQueueItem> surface_crossing_queue;
19
SharedArray<EventQueueItem> collision_queue;
20

21
vector<Particle> particles;
22

23
} // namespace simulation
24

25
//==============================================================================
26
// Non-member functions
27
//==============================================================================
28

UNCOV
29
void init_event_queues(int64_t n_particles)
211✔
30
{
UNCOV
31
  simulation::calculate_fuel_xs_queue.reserve(n_particles);
211✔
UNCOV
32
  simulation::calculate_nonfuel_xs_queue.reserve(n_particles);
211✔
UNCOV
33
  simulation::advance_particle_queue.reserve(n_particles);
211✔
UNCOV
34
  simulation::surface_crossing_queue.reserve(n_particles);
211✔
UNCOV
35
  simulation::collision_queue.reserve(n_particles);
211✔
36

UNCOV
37
  simulation::particles.resize(n_particles);
211✔
UNCOV
38
}
211✔
39

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

48
  simulation::particles.clear();
×
49
}
×
50

UNCOV
51
void dispatch_xs_event(int64_t buffer_idx)
228,566,540✔
52
{
UNCOV
53
  Particle& p = simulation::particles[buffer_idx];
228,566,540✔
UNCOV
54
  if (p.material() == MATERIAL_VOID ||
228,566,540✔
UNCOV
55
      !model::materials[p.material()]->fissionable()) {
211,299,509✔
UNCOV
56
    simulation::calculate_nonfuel_xs_queue.thread_safe_append({p, buffer_idx});
51,150,675✔
57
  } else {
UNCOV
58
    simulation::calculate_fuel_xs_queue.thread_safe_append({p, buffer_idx});
177,415,865✔
59
  }
UNCOV
60
}
228,566,540✔
61

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

UNCOV
73
void process_calculate_xs_events(SharedArray<EventQueueItem>& queue)
939,600✔
74
{
UNCOV
75
  simulation::time_event_calculate_xs.start();
939,600✔
76

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

UNCOV
87
  int64_t offset = simulation::advance_particle_queue.size();
939,600✔
88

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

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

UNCOV
100
  simulation::advance_particle_queue.resize(offset + queue.size());
939,600✔
101

UNCOV
102
  queue.resize(0);
939,600✔
103

UNCOV
104
  simulation::time_event_calculate_xs.stop();
939,600✔
UNCOV
105
}
939,600✔
106

UNCOV
107
void process_advance_particle_events()
934,326✔
108
{
UNCOV
109
  simulation::time_event_advance_particle.start();
934,326✔
110

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

UNCOV
125
  simulation::advance_particle_queue.resize(0);
934,326✔
126

UNCOV
127
  simulation::time_event_advance_particle.stop();
934,326✔
UNCOV
128
}
934,326✔
129

UNCOV
130
void process_surface_crossing_events()
262,403✔
131
{
UNCOV
132
  simulation::time_event_surface_crossing.start();
262,403✔
133

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

UNCOV
144
  simulation::surface_crossing_queue.resize(0);
262,403✔
145

UNCOV
146
  simulation::time_event_surface_crossing.stop();
262,403✔
UNCOV
147
}
262,403✔
148

UNCOV
149
void process_collision_events()
690,431✔
150
{
UNCOV
151
  simulation::time_event_collision.start();
690,431✔
152

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

UNCOV
163
  simulation::collision_queue.resize(0);
690,431✔
164

UNCOV
165
  simulation::time_event_collision.stop();
690,431✔
UNCOV
166
}
690,431✔
167

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

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