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

openmc-dev / openmc / 19102841639

05 Nov 2025 01:01PM UTC coverage: 82.019% (-3.1%) from 85.155%
19102841639

Pull #3252

github

web-flow
Merge 3c71decac into bd76fc056
Pull Request #3252: Adding vtkhdf option to write vtk data

16722 of 23233 branches covered (71.98%)

Branch coverage included in aggregate %.

61 of 66 new or added lines in 1 file covered. (92.42%)

3177 existing lines in 103 files now uncovered.

54247 of 63294 relevant lines covered (85.71%)

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

37
  simulation::particles.resize(n_particles);
177✔
38
}
177✔
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,216,384✔
52
{
53
  Particle& p = simulation::particles[buffer_idx];
227,216,384✔
54
  if (p.material() == MATERIAL_VOID ||
437,356,362✔
55
      !model::materials[p.material()]->fissionable()) {
210,139,978✔
56
    simulation::calculate_nonfuel_xs_queue.thread_safe_append({p, buffer_idx});
50,022,546!
57
  } else {
58
    simulation::calculate_fuel_xs_queue.thread_safe_append({p, buffer_idx});
177,193,838!
59
  }
60
}
227,216,384✔
61

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

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

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

102
  queue.resize(0);
779,404✔
103

104
  simulation::time_event_calculate_xs.stop();
779,404✔
105
}
779,404✔
106

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

127
  simulation::time_event_advance_particle.stop();
774,266✔
128
}
774,266✔
129

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

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

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

165
  simulation::time_event_collision.stop();
535,311✔
166
}
535,311✔
167

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