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

openmc-dev / openmc / 21043587909

15 Jan 2026 07:25PM UTC coverage: 81.332% (-0.7%) from 82.044%
21043587909

Pull #3734

github

web-flow
Merge 0c6701672 into 179048b80
Pull Request #3734: Specify temperature from a field (structured mesh only)

16365 of 22657 branches covered (72.23%)

Branch coverage included in aggregate %.

157 of 180 new or added lines in 12 files covered. (87.22%)

681 existing lines in 43 files now uncovered.

54412 of 64365 relevant lines covered (84.54%)

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

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

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

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

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

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

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

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

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

88
  if (material_cells_only_)
2,767,632!
UNCOV
89
    return;
×
90

91
  for (int i = 0; i < p.n_coord() - 1; i++) {
6,239,176✔
92
    int64_t index_cell = p.coord(i).cell();
3,471,544✔
93
    // if this cell isn't used on the filter, move on
94
    if (cells_.count(index_cell) == 0)
3,471,544✔
95
      continue;
2,767,632✔
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);
703,912✔
99
    auto search = map_.find({index_cell, instance});
703,912✔
100
    if (search != map_.end()) {
703,912!
101
      match.bins_.push_back(search->second);
703,912✔
102
      match.weights_.push_back(1.0);
703,912✔
103
    }
104
  }
105
}
106

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

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