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

openmc-dev / openmc / 21533365354

30 Jan 2026 10:48PM UTC coverage: 81.979% (-3.2%) from 85.162%
21533365354

Pull #3453

github

web-flow
Merge de22ee16c into 7b4617aff
Pull Request #3453: Secondary energy filter

17272 of 24046 branches covered (71.83%)

Branch coverage included in aggregate %.

50 of 52 new or added lines in 8 files covered. (96.15%)

4544 existing lines in 133 files now uncovered.

55847 of 65146 relevant lines covered (85.73%)

44003337.54 hits per line

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

62.22
/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

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

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

UNCOV
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();
×
UNCOV
46
  simulation::collision_queue.clear();
×
47

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

51
void dispatch_xs_event(int64_t buffer_idx)
227,815,661✔
52
{
53
  Particle& p = simulation::particles[buffer_idx];
227,815,661✔
54
  if (p.material() == MATERIAL_VOID ||
438,516,330✔
55
      !model::materials[p.material()]->fissionable()) {
210,700,669✔
56
    simulation::calculate_nonfuel_xs_queue.thread_safe_append({p, buffer_idx});
50,423,812!
57
  } else {
58
    simulation::calculate_fuel_xs_queue.thread_safe_append({p, buffer_idx});
177,391,849!
59
  }
60
}
227,815,661✔
61

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

73
void process_calculate_xs_events(SharedArray<EventQueueItem>& queue)
786,928✔
74
{
75
  simulation::time_event_calculate_xs.start();
786,928✔
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

87
  int64_t offset = simulation::advance_particle_queue.size();
786,928✔
88

89
#pragma omp parallel for schedule(runtime)
786,928✔
90
  for (int64_t i = 0; i < queue.size(); i++) {
×
91
    Particle* p = &simulation::particles[queue[i].idx];
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.
97
    simulation::advance_particle_queue[offset + i] = queue[i];
98
  }
99

100
  simulation::advance_particle_queue.resize(offset + queue.size());
786,928✔
101

102
  queue.resize(0);
786,928✔
103

104
  simulation::time_event_calculate_xs.stop();
786,928✔
105
}
786,928✔
106

107
void process_advance_particle_events()
781,657✔
108
{
109
  simulation::time_event_advance_particle.start();
781,657✔
110

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

125
  simulation::advance_particle_queue.resize(0);
781,657✔
126

127
  simulation::time_event_advance_particle.stop();
781,657✔
128
}
781,657✔
129

130
void process_surface_crossing_events()
259,774✔
131
{
132
  simulation::time_event_surface_crossing.start();
259,774✔
133

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

144
  simulation::surface_crossing_queue.resize(0);
259,774✔
145

146
  simulation::time_event_surface_crossing.stop();
259,774✔
147
}
259,774✔
148

149
void process_collision_events()
540,389✔
150
{
151
  simulation::time_event_collision.start();
540,389✔
152

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

163
  simulation::collision_queue.resize(0);
540,389✔
164

165
  simulation::time_event_collision.stop();
540,389✔
166
}
540,389✔
167

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