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

openmc-dev / openmc / 21829370254

09 Feb 2026 02:38PM UTC coverage: 81.937% (+0.1%) from 81.817%
21829370254

Pull #3737

github

web-flow
Merge 8740453dd into d0346e94a
Pull Request #3737: Temperature feedback support in the random ray solver.

17362 of 24292 branches covered (71.47%)

Branch coverage included in aggregate %.

333 of 360 new or added lines in 11 files covered. (92.5%)

680 existing lines in 42 files now uncovered.

56324 of 65638 relevant lines covered (85.81%)

76491867.81 hits per line

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

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

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

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

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

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

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

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

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

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

88
  if (material_cells_only_)
11,091,608✔
UNCOV
89
    return;
21,080✔
90

91
  for (int i = 0; i < p.n_coord() - 1; i++) {
24,956,704✔
92
    int64_t index_cell = p.coord(i).cell();
13,886,176✔
93
    // if this cell isn't used on the filter, move on
94
    if (cells_.count(index_cell) == 0)
13,886,176✔
95
      continue;
11,070,528✔
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);
2,815,648✔
99
    auto search = map_.find({index_cell, instance});
2,815,648✔
100
    if (search != map_.end()) {
2,815,648!
101
      match.bins_.push_back(search->second);
2,815,648✔
102
      match.weights_.push_back(1.0);
2,815,648✔
103
    }
104
  }
105
}
106

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

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