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

openmc-dev / openmc / 18299973882

07 Oct 2025 02:14AM UTC coverage: 81.92% (-3.3%) from 85.194%
18299973882

push

github

web-flow
Switch to using coveralls github action for reporting (#3594)

16586 of 23090 branches covered (71.83%)

Branch coverage included in aggregate %.

53703 of 62712 relevant lines covered (85.63%)

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

37
  simulation::particles.resize(n_particles);
176✔
38
}
176✔
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

51
void dispatch_xs_event(int64_t buffer_idx)
226,738,719✔
52
{
53
  Particle& p = simulation::particles[buffer_idx];
226,738,719✔
54
  if (p.material() == MATERIAL_VOID ||
436,527,263✔
55
      !model::materials[p.material()]->fissionable()) {
209,788,544✔
56
    simulation::calculate_nonfuel_xs_queue.thread_safe_append({p, buffer_idx});
49,544,855!
57
  } else {
58
    simulation::calculate_fuel_xs_queue.thread_safe_append({p, buffer_idx});
177,193,864!
59
  }
60
}
226,738,719✔
61

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

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

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

102
  queue.resize(0);
778,648✔
103

104
  simulation::time_event_calculate_xs.stop();
778,648✔
105
}
778,648✔
106

107
void process_advance_particle_events()
773,508✔
108
{
109
  simulation::time_event_advance_particle.start();
773,508✔
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);
773,508✔
126

127
  simulation::time_event_advance_particle.stop();
773,508✔
128
}
773,508✔
129

130
void process_surface_crossing_events()
256,507✔
131
{
132
  simulation::time_event_surface_crossing.start();
256,507✔
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);
256,507✔
145

146
  simulation::time_event_surface_crossing.stop();
256,507✔
147
}
256,507✔
148

149
void process_collision_events()
534,984✔
150
{
151
  simulation::time_event_collision.start();
534,984✔
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);
534,984✔
164

165
  simulation::time_event_collision.stop();
534,984✔
166
}
534,984✔
167

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

© 2025 Coveralls, Inc