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

openmc-dev / openmc / 22110756672

17 Feb 2026 06:31PM UTC coverage: 81.831% (+0.1%) from 81.721%
22110756672

Pull #3813

github

web-flow
Merge 47dc7194f into 977ade79a
Pull Request #3813: Check for positive radii

17268 of 24298 branches covered (71.07%)

Branch coverage included in aggregate %.

16 of 16 new or added lines in 1 file covered. (100.0%)

1065 existing lines in 28 files now uncovered.

57520 of 67095 relevant lines covered (85.73%)

45595325.95 hits per line

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

86.92
/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)
30✔
23
{
24
  // Get cell IDs/instances
25
  auto cells = get_node_array<int32_t>(node, "bins");
30✔
26
  assert(cells.size() % 2 == 0);
24!
27

28
  // Convert into vector of CellInstance
29
  vector<CellInstance> instances;
30✔
30
  for (int64_t i = 0; i < cells.size() / 2; ++i) {
600✔
31
    int32_t cell_id = cells[2 * i];
570✔
32
    int64_t instance = cells[2 * i + 1];
570✔
33
    auto search = model::cell_map.find(cell_id);
570✔
34
    if (search == model::cell_map.end()) {
570!
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;
570✔
39
    instances.push_back({index, instance});
570✔
40
  }
41

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

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

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

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

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

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

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

89
  if (material_cells_only_)
6,940,160✔
90
    return;
21,080✔
91

92
  for (int i = 0; i < p.n_coord() - 1; i++) {
15,597,940✔
93
    int64_t index_cell = p.coord(i).cell();
8,678,860✔
94
    // if this cell isn't used on the filter, move on
95
    if (cells_.count(index_cell) == 0)
8,678,860✔
96
      continue;
6,919,080✔
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,759,780✔
100
    auto search = map_.find({index_cell, instance});
1,759,780✔
101
    if (search != map_.end()) {
1,759,780!
102
      match.bins_.push_back(search->second);
1,759,780✔
103
      match.weights_.push_back(1.0);
1,759,780✔
104
    }
105
  }
106
}
107

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

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