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

openmc-dev / openmc / 21240277645

22 Jan 2026 07:46AM UTC coverage: 80.906% (-1.1%) from 81.998%
21240277645

Pull #3745

github

web-flow
Merge b47b53e16 into c5df2bf62
Pull Request #3745: Add n_elements to the MeshBase protocol and deprecate num_mesh_cells

16262 of 22513 branches covered (72.23%)

Branch coverage included in aggregate %.

15 of 21 new or added lines in 2 files covered. (71.43%)

1061 existing lines in 55 files now uncovered.

53902 of 64210 relevant lines covered (83.95%)

7933045.48 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/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)
×
30
{
UNCOV
31
  simulation::calculate_fuel_xs_queue.reserve(n_particles);
×
UNCOV
32
  simulation::calculate_nonfuel_xs_queue.reserve(n_particles);
×
UNCOV
33
  simulation::advance_particle_queue.reserve(n_particles);
×
UNCOV
34
  simulation::surface_crossing_queue.reserve(n_particles);
×
UNCOV
35
  simulation::collision_queue.reserve(n_particles);
×
36

UNCOV
37
  simulation::particles.resize(n_particles);
×
UNCOV
38
}
×
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)
×
52
{
UNCOV
53
  Particle& p = simulation::particles[buffer_idx];
×
UNCOV
54
  if (p.material() == MATERIAL_VOID ||
×
UNCOV
55
      !model::materials[p.material()]->fissionable()) {
×
UNCOV
56
    simulation::calculate_nonfuel_xs_queue.thread_safe_append({p, buffer_idx});
×
57
  } else {
UNCOV
58
    simulation::calculate_fuel_xs_queue.thread_safe_append({p, buffer_idx});
×
59
  }
UNCOV
60
}
×
61

UNCOV
62
void process_init_events(int64_t n_particles, int64_t source_offset)
×
63
{
UNCOV
64
  simulation::time_event_init.start();
×
65
#pragma omp parallel for schedule(runtime)
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();
×
UNCOV
71
}
×
72

UNCOV
73
void process_calculate_xs_events(SharedArray<EventQueueItem>& queue)
×
74
{
UNCOV
75
  simulation::time_event_calculate_xs.start();
×
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();
×
88

89
#pragma omp parallel for schedule(runtime)
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());
×
101

UNCOV
102
  queue.resize(0);
×
103

UNCOV
104
  simulation::time_event_calculate_xs.stop();
×
UNCOV
105
}
×
106

UNCOV
107
void process_advance_particle_events()
×
108
{
UNCOV
109
  simulation::time_event_advance_particle.start();
×
110

111
#pragma omp parallel for schedule(runtime)
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);
×
126

UNCOV
127
  simulation::time_event_advance_particle.stop();
×
UNCOV
128
}
×
129

UNCOV
130
void process_surface_crossing_events()
×
131
{
UNCOV
132
  simulation::time_event_surface_crossing.start();
×
133

134
#pragma omp parallel for schedule(runtime)
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);
×
145

UNCOV
146
  simulation::time_event_surface_crossing.stop();
×
UNCOV
147
}
×
148

UNCOV
149
void process_collision_events()
×
150
{
UNCOV
151
  simulation::time_event_collision.start();
×
152

153
#pragma omp parallel for schedule(runtime)
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);
×
164

UNCOV
165
  simulation::time_event_collision.stop();
×
UNCOV
166
}
×
167

UNCOV
168
void process_death_events(int64_t n_particles)
×
169
{
UNCOV
170
  simulation::time_event_death.start();
×
171
#pragma omp parallel for schedule(runtime)
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();
×
UNCOV
177
}
×
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