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

openmc-dev / openmc / 21686031975

04 Feb 2026 07:50PM UTC coverage: 81.024% (-0.7%) from 81.763%
21686031975

Pull #3755

github

web-flow
Merge 27d6053a4 into b41e22f68
Pull Request #3755: Warn users that tally heating score with photon bin but without electron and positron bins.

16378 of 22828 branches covered (71.75%)

Branch coverage included in aggregate %.

22 of 23 new or added lines in 1 file covered. (95.65%)

862 existing lines in 51 files now uncovered.

54491 of 64639 relevant lines covered (84.3%)

8259986.93 hits per line

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

84.85
/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/xml_interface.h"
13

14
namespace openmc {
15

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

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

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

41
  this->set_cell_instances(instances);
4✔
42
}
4✔
43

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

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

61
  n_bins_ = cell_instances_.size();
4✔
62

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

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

79
  if (cells_.count(index_cell) > 0) {
691,908✔
80
    auto search = map_.find({index_cell, instance});
187,226✔
81
    if (search != map_.end()) {
187,226!
82
      int index_bin = search->second;
187,226✔
83
      match.bins_.push_back(index_bin);
187,226✔
84
      match.weights_.push_back(1.0);
187,226✔
85
    }
86
  }
87

88
  if (material_cells_only_)
691,908!
UNCOV
89
    return;
×
90

91
  for (int i = 0; i < p.n_coord() - 1; i++) {
1,559,794✔
92
    int64_t index_cell = p.coord(i).cell();
867,886✔
93
    // if this cell isn't used on the filter, move on
94
    if (cells_.count(index_cell) == 0)
867,886✔
95
      continue;
691,908✔
96

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

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

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

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