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

openmc-dev / openmc / 22238377064

20 Feb 2026 07:37PM UTC coverage: 81.698% (-0.1%) from 81.826%
22238377064

Pull #3829

github

web-flow
Merge 351f374bf into 53ce1910f
Pull Request #3829: C++ formatting suggestions on PRs

16739 of 23313 branches covered (71.8%)

Branch coverage included in aggregate %.

56693 of 66569 relevant lines covered (85.16%)

43279756.6 hits per line

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

84.62
/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

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

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

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

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

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

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

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

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

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

80
  if (cells_.count(index_cell) > 0) {
6,227,172✔
81
    auto search = map_.find({index_cell, instance});
1,685,034✔
82
    if (search != map_.end()) {
1,685,034!
83
      int index_bin = search->second;
1,685,034✔
84
      match.bins_.push_back(index_bin);
1,685,034✔
85
      match.weights_.push_back(1.0);
1,685,034✔
86
    }
87
  }
88

89
  if (material_cells_only_)
6,227,172!
90
    return;
×
91

92
  for (int i = 0; i < p.n_coord() - 1; i++) {
14,038,146✔
93
    int64_t index_cell = p.coord(i).cell();
7,810,974✔
94
    // if this cell isn't used on the filter, move on
95
    if (cells_.count(index_cell) == 0)
7,810,974✔
96
      continue;
6,227,172✔
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,583,802✔
100
    auto search = map_.find({index_cell, instance});
1,583,802✔
101
    if (search != map_.end()) {
1,583,802!
102
      match.bins_.push_back(search->second);
1,583,802✔
103
      match.weights_.push_back(1.0);
1,583,802✔
104
    }
105
  }
106
}
107

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

121
std::string CellInstanceFilter::text_label(int bin) const
360✔
122
{
123
  const auto& x = cell_instances_[bin];
360✔
124
  auto cell_id = model::cells[x.index_cell]->id_;
360✔
125
  return "Cell " + std::to_string(cell_id) + ", Instance " +
720✔
126
         std::to_string(x.instance);
1,080✔
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