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

openmc-dev / openmc / 13443476914

20 Feb 2025 07:49PM UTC coverage: 85.022% (+0.05%) from 84.969%
13443476914

Pull #3140

github

web-flow
Merge 8ddcb065a into 7638661fa
Pull Request #3140: Add Versioning Support from `version.txt`

8 of 8 new or added lines in 2 files covered. (100.0%)

1242 existing lines in 42 files now uncovered.

50634 of 59554 relevant lines covered (85.02%)

35434881.25 hits per line

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

94.44
/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

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

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

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

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

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

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

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

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

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

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

88
  if (material_cells_only_)
8,444,983✔
89
    return;
21,031✔
90

91
  for (int i = 0; i < p.n_coord() - 1; i++) {
18,903,600✔
92
    int64_t index_cell = p.coord(i).cell;
10,479,648✔
93
    // if this cell isn't used on the filter, move on
94
    if (cells_.count(index_cell) == 0)
10,479,648✔
95
      continue;
8,423,952✔
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,055,696✔
99
    auto search = map_.find({index_cell, instance});
2,055,696✔
100
    if (search != map_.end()) {
2,055,696✔
101
      match.bins_.push_back(search->second);
2,055,696✔
102
      match.weights_.push_back(1.0);
2,055,696✔
103
    }
104
  }
105
}
106

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

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

© 2025 Coveralls, Inc