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

openmc-dev / openmc / 21043561037

15 Jan 2026 07:23PM UTC coverage: 81.388% (-0.7%) from 82.044%
21043561037

Pull #3734

github

web-flow
Merge 5e79b7b6f into 179048b80
Pull Request #3734: Specify temperature from a field (structured mesh only)

16703 of 22995 branches covered (72.64%)

Branch coverage included in aggregate %.

156 of 179 new or added lines in 12 files covered. (87.15%)

843 existing lines in 36 files now uncovered.

54487 of 64475 relevant lines covered (84.51%)

27592585.27 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)
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
  }
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)
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

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)
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

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)
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

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)
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

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)
172
  for (int64_t i = 0; i < n_particles; i++) {
×
173
    Particle& p = simulation::particles[i];
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