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

openmc-dev / openmc / 23084721708

14 Mar 2026 08:56AM UTC coverage: 81.599% (-0.5%) from 82.058%
23084721708

Pull #2693

github

web-flow
Merge 0ed23ee59 into bc9c31e0f
Pull Request #2693: Add reactivity control to coupled transport-depletion analyses

17575 of 25275 branches covered (69.54%)

Branch coverage included in aggregate %.

74 of 85 new or added lines in 4 files covered. (87.06%)

3755 existing lines in 99 files now uncovered.

58074 of 67433 relevant lines covered (86.12%)

47252067.37 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

82.73
/src/tallies/filter_cell_instance.cpp
1
#include "openmc/tallies/filter_cell_instance.h"
2

3
#include <cassert>
4
#include <string>
5

6
#include <fmt/core.h>
7

8
#include "openmc/capi.h"
9
#include "openmc/cell.h"
10
#include "openmc/error.h"
11
#include "openmc/geometry.h"
12
#include "openmc/tensor.h"
13
#include "openmc/xml_interface.h"
14

15
namespace openmc {
16

UNCOV
17
CellInstanceFilter::CellInstanceFilter(span<CellInstance> instances)
×
18
{
19
  this->set_cell_instances(instances);
×
UNCOV
20
}
×
21

22
void CellInstanceFilter::from_xml(pugi::xml_node node)
32✔
23
{
24
  // Get cell IDs/instances
25
  auto cells = get_node_array<int32_t>(node, "bins");
32✔
26
  assert(cells.size() % 2 == 0);
32!
27

28
  // Convert into vector of CellInstance
29
  vector<CellInstance> instances;
32✔
30
  for (int64_t i = 0; i < cells.size() / 2; ++i) {
642✔
31
    int32_t cell_id = cells[2 * i];
610!
32
    int64_t instance = cells[2 * i + 1];
610✔
33
    auto search = model::cell_map.find(cell_id);
610!
34
    if (search == model::cell_map.end()) {
610!
35
      throw std::runtime_error {fmt::format(
×
UNCOV
36
        "Could not find cell {} specified on tally filter.", cell_id)};
×
37
    }
38
    int64_t index = search->second;
610✔
39
    instances.push_back({index, instance});
610✔
40
  }
41

42
  this->set_cell_instances(instances);
32✔
43
}
32✔
44

45
void CellInstanceFilter::set_cell_instances(span<CellInstance> instances)
32✔
46
{
47
  // Clear existing cells
48
  cell_instances_.clear();
32!
49
  cell_instances_.reserve(instances.size());
32✔
50
  cells_.clear();
32✔
51
  map_.clear();
32✔
52

53
  // Update cells and mapping
54
  for (auto& x : instances) {
642✔
55
    assert(x.index_cell >= 0);
610!
56
    assert(x.index_cell < model::cells.size());
610!
57
    cell_instances_.push_back(x);
610✔
58
    cells_.insert(x.index_cell);
610✔
59
    map_[x] = cell_instances_.size() - 1;
610✔
60
  }
61

62
  n_bins_ = cell_instances_.size();
32✔
63

64
  material_cells_only_ = true;
32✔
65
  for (const auto& cell_inst : cell_instances_) {
282✔
66
    const auto& c = *model::cells[cell_inst.index_cell];
280✔
67
    if (c.type_ == Fill::MATERIAL)
280✔
68
      continue;
250✔
69
    material_cells_only_ = false;
30✔
70
    break;
30✔
71
  }
72
}
32✔
73

74
void CellInstanceFilter::get_all_bins(
7,632,068✔
75
  const Particle& p, TallyEstimator estimator, FilterMatch& match) const
76
{
77
  int64_t index_cell = p.lowest_coord().cell();
7,632,068✔
78
  int64_t instance = p.cell_instance();
7,632,068✔
79

80
  if (cells_.count(index_cell) > 0) {
7,632,068✔
81
    auto search = map_.find({index_cell, instance});
2,062,800!
82
    if (search != map_.end()) {
2,062,800!
83
      int index_bin = search->second;
2,062,800✔
84
      match.bins_.push_back(index_bin);
2,062,800✔
85
      match.weights_.push_back(1.0);
2,062,800✔
86
    }
87
  }
88

89
  if (material_cells_only_)
7,632,068✔
90
    return;
91

92
  for (int i = 0; i < p.n_coord() - 1; i++) {
17,157,734✔
93
    int64_t index_cell = p.coord(i).cell();
9,546,746✔
94
    // if this cell isn't used on the filter, move on
95
    if (cells_.count(index_cell) == 0)
9,546,746✔
96
      continue;
7,610,988✔
97

98
    // if this cell is used in the filter, check the instance as well
99
    int64_t instance = cell_instance_at_level(p, i);
1,935,758✔
100
    auto search = map_.find({index_cell, instance});
1,935,758!
101
    if (search != map_.end()) {
1,935,758!
102
      match.bins_.push_back(search->second);
1,935,758✔
103
      match.weights_.push_back(1.0);
1,935,758✔
104
    }
105
  }
106
}
107

108
void CellInstanceFilter::to_statepoint(hid_t filter_group) const
23✔
109
{
110
  Filter::to_statepoint(filter_group);
23✔
111
  size_t n = cell_instances_.size();
23✔
112
  tensor::Tensor<size_t> data({n, 2});
23✔
113
  for (int64_t i = 0; i < n; ++i) {
468✔
114
    const auto& x = cell_instances_[i];
445✔
115
    data(i, 0) = model::cells[x.index_cell]->id_;
445✔
116
    data(i, 1) = x.instance;
445✔
117
  }
118
  write_dataset(filter_group, "bins", data);
23✔
119
}
23✔
120

121
std::string CellInstanceFilter::text_label(int bin) const
445✔
122
{
123
  const auto& x = cell_instances_[bin];
445✔
124
  auto cell_id = model::cells[x.index_cell]->id_;
445✔
125
  return "Cell " + std::to_string(cell_id) + ", Instance " +
890✔
126
         std::to_string(x.instance);
1,335✔
127
}
128

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