• 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

72.16
/src/bank.cpp
1
#include "openmc/bank.h"
2
#include "openmc/capi.h"
3
#include "openmc/error.h"
4
#include "openmc/ifp.h"
5
#include "openmc/message_passing.h"
6
#include "openmc/simulation.h"
7
#include "openmc/vector.h"
8

9
#include <cstdint>
10

11
namespace openmc {
12

13
//==============================================================================
14
// Global variables
15
//==============================================================================
16

17
namespace simulation {
18

19
vector<SourceSite> source_bank;
20

21
SharedArray<SourceSite> surf_source_bank;
22

23
// The fission bank is allocated as a SharedArray, rather than a vector, as it
24
// will be shared by all threads in the simulation. It will be allocated to a
25
// fixed maximum capacity in the init_fission_bank() function. Then, Elements
26
// will be added to it by using SharedArray's special thread_safe_append()
27
// function.
28
SharedArray<SourceSite> fission_bank;
29

30
vector<vector<int>> ifp_source_delayed_group_bank;
31

32
vector<vector<double>> ifp_source_lifetime_bank;
33

34
vector<vector<int>> ifp_fission_delayed_group_bank;
35

36
vector<vector<double>> ifp_fission_lifetime_bank;
37

38
// Each entry in this vector corresponds to the number of progeny produced
39
// this generation for the particle located at that index. This vector is
40
// used to efficiently sort the fission bank after each iteration.
41
vector<int64_t> progeny_per_particle;
42

43
} // namespace simulation
44

45
//==============================================================================
46
// Non-member functions
47
//==============================================================================
48

49
void free_memory_bank()
8,104✔
50
{
51
  simulation::source_bank.clear();
8,104✔
52
  simulation::surf_source_bank.clear();
8,104✔
53
  simulation::fission_bank.clear();
8,104✔
54
  simulation::progeny_per_particle.clear();
8,104✔
55
  simulation::ifp_source_delayed_group_bank.clear();
8,104✔
56
  simulation::ifp_source_lifetime_bank.clear();
8,104✔
57
  simulation::ifp_fission_delayed_group_bank.clear();
8,104✔
58
  simulation::ifp_fission_lifetime_bank.clear();
8,104✔
59
}
8,104✔
60

61
void init_fission_bank(int64_t max)
3,756✔
62
{
63
  simulation::fission_bank.reserve(max);
3,756✔
64
  simulation::progeny_per_particle.resize(simulation::work_per_rank);
3,756✔
65
}
3,756✔
66

67
// Performs an O(n) sort on the fission bank, by leveraging
68
// the parent_id and progeny_id fields of banked particles. See the following
69
// paper for more details:
70
// "Reproducibility and Monte Carlo Eigenvalue Calculations," F.B. Brown and
71
// T.M. Sutton, 1992 ANS Annual Meeting, Transactions of the American Nuclear
72
// Society, Volume 65, Page 235.
73
void sort_fission_bank()
83,347✔
74
{
75
  // Ensure we don't read off the end of the array if we ran with 0 particles
76
  if (simulation::progeny_per_particle.size() == 0) {
83,347!
77
    return;
×
78
  }
79

80
  // Perform exclusive scan summation to determine starting indices in fission
81
  // bank for each parent particle id
82
  std::exclusive_scan(simulation::progeny_per_particle.begin(),
83,347✔
83
    simulation::progeny_per_particle.end(),
84
    simulation::progeny_per_particle.begin(), 0);
85

86
  // We need a scratch vector to make permutation of the fission bank into
87
  // sorted order easy. Under normal usage conditions, the fission bank is
88
  // over provisioned, so we can use that as scratch space.
89
  SourceSite* sorted_bank;
90
  vector<SourceSite> sorted_bank_holder;
83,347✔
91
  vector<vector<int>> sorted_ifp_delayed_group_bank;
83,347✔
92
  vector<vector<double>> sorted_ifp_lifetime_bank;
83,347✔
93

94
  // If there is not enough space, allocate a temporary vector and point to it
95
  if (simulation::fission_bank.size() >
83,347✔
96
      simulation::fission_bank.capacity() / 2) {
83,347✔
97
    sorted_bank_holder.resize(simulation::fission_bank.size());
850✔
98
    sorted_bank = sorted_bank_holder.data();
850✔
99
  } else { // otherwise, point sorted_bank to unused portion of the fission bank
100
    sorted_bank = &simulation::fission_bank[simulation::fission_bank.size()];
82,497✔
101
  }
102

103
  if (settings::ifp_on) {
83,347✔
104
    allocate_temporary_vector_ifp(
1,520✔
105
      sorted_ifp_delayed_group_bank, sorted_ifp_lifetime_bank);
106
  }
107

108
  // Use parent and progeny indices to sort fission bank
109
  for (int64_t i = 0; i < simulation::fission_bank.size(); i++) {
140,311,903✔
110
    const auto& site = simulation::fission_bank[i];
140,228,556✔
111
    int64_t offset = site.parent_id - 1 - simulation::work_index[mpi::rank];
140,228,556✔
112
    int64_t idx = simulation::progeny_per_particle[offset] + site.progeny_id;
140,228,556✔
113
    if (idx >= simulation::fission_bank.size()) {
140,228,556!
UNCOV
114
      fatal_error("Mismatch detected between sum of all particle progeny and "
×
115
                  "shared fission bank size.");
116
    }
117
    sorted_bank[idx] = site;
140,228,556✔
118
    if (settings::ifp_on) {
140,228,556✔
119
      copy_ifp_data_from_fission_banks(
1,352,626✔
120
        i, sorted_ifp_delayed_group_bank[idx], sorted_ifp_lifetime_bank[idx]);
1,352,626✔
121
    }
122
  }
123

124
  // Copy sorted bank into the fission bank
125
  std::copy(sorted_bank, sorted_bank + simulation::fission_bank.size(),
83,347✔
126
    simulation::fission_bank.data());
127
  if (settings::ifp_on) {
83,347✔
128
    copy_ifp_data_to_fission_banks(
1,520✔
129
      sorted_ifp_delayed_group_bank.data(), sorted_ifp_lifetime_bank.data());
1,520✔
130
  }
131
}
83,347✔
132

133
//==============================================================================
134
// C API
135
//==============================================================================
136

137
extern "C" int openmc_source_bank(void** ptr, int64_t* n)
12✔
138
{
139
  if (!ptr || !n) {
12!
UNCOV
140
    set_errmsg("Received null pointer.");
×
UNCOV
141
    return OPENMC_E_INVALID_ARGUMENT;
×
142
  }
143

144
  if (simulation::source_bank.size() == 0) {
12!
UNCOV
145
    set_errmsg("Source bank has not been allocated.");
×
UNCOV
146
    return OPENMC_E_ALLOCATE;
×
147
  } else {
148
    *ptr = simulation::source_bank.data();
12✔
149
    *n = simulation::source_bank.size();
12✔
150
    return 0;
12✔
151
  }
152
}
153

UNCOV
154
extern "C" int openmc_fission_bank(void** ptr, int64_t* n)
×
155
{
UNCOV
156
  if (!ptr || !n) {
×
UNCOV
157
    set_errmsg("Received null pointer.");
×
UNCOV
158
    return OPENMC_E_INVALID_ARGUMENT;
×
159
  }
160

161
  if (simulation::fission_bank.size() == 0) {
×
UNCOV
162
    set_errmsg("Fission bank has not been allocated.");
×
163
    return OPENMC_E_ALLOCATE;
×
164
  } else {
165
    *ptr = simulation::fission_bank.data();
×
UNCOV
166
    *n = simulation::fission_bank.size();
×
UNCOV
167
    return 0;
×
168
  }
169
}
170

171
} // 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