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

openmc-dev / openmc / 21979737004

13 Feb 2026 08:19AM UTC coverage: 81.451% (-0.4%) from 81.851%
21979737004

Pull #3801

github

web-flow
Merge a4595d510 into bcb939520
Pull Request #3801: avoid need to set particles and batches for dagmc models when calling convert_to_multigroup

16960 of 23616 branches covered (71.82%)

Branch coverage included in aggregate %.

0 of 1 new or added line in 1 file covered. (0.0%)

908 existing lines in 38 files now uncovered.

55950 of 65898 relevant lines covered (84.9%)

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

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

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

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

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

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

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

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

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

88
  if (material_cells_only_)
4,843,356!
UNCOV
89
    return;
×
90

91
  for (int i = 0; i < p.n_coord() - 1; i++) {
10,918,558✔
92
    int64_t index_cell = p.coord(i).cell();
6,075,202✔
93
    // if this cell isn't used on the filter, move on
94
    if (cells_.count(index_cell) == 0)
6,075,202✔
95
      continue;
4,843,356✔
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);
1,231,846✔
99
    auto search = map_.find({index_cell, instance});
1,231,846✔
100
    if (search != map_.end()) {
1,231,846!
101
      match.bins_.push_back(search->second);
1,231,846✔
102
      match.weights_.push_back(1.0);
1,231,846✔
103
    }
104
  }
105
}
106

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

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