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

openmc-dev / openmc / 15371300071

01 Jun 2025 05:04AM UTC coverage: 85.143% (+0.3%) from 84.827%
15371300071

Pull #3176

github

web-flow
Merge 4f739184a into cb95c784b
Pull Request #3176: MeshFilter rotation - solution to issue #3166

86 of 99 new or added lines in 4 files covered. (86.87%)

3707 existing lines in 117 files now uncovered.

52212 of 61323 relevant lines covered (85.14%)

42831974.38 hits per line

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

89.58
/src/tallies/filter_cell.cpp
1
#include "openmc/tallies/filter_cell.h"
2

3
#include <cassert>
4

5
#include <fmt/core.h>
6

7
#include "openmc/capi.h"
8
#include "openmc/cell.h"
9
#include "openmc/error.h"
10
#include "openmc/xml_interface.h"
11

12
namespace openmc {
13

14
void CellFilter::from_xml(pugi::xml_node node)
1,146✔
15
{
16
  // Get cell IDs and convert to indices into the global cells vector
17
  auto cells = get_node_array<int32_t>(node, "bins");
1,146✔
18
  for (auto& c : cells) {
3,922✔
19
    auto search = model::cell_map.find(c);
2,776✔
20
    if (search == model::cell_map.end()) {
2,776✔
UNCOV
21
      throw std::runtime_error {
×
UNCOV
22
        fmt::format("Could not find cell {} specified on tally filter.", c)};
×
23
    }
24
    c = search->second;
2,776✔
25
  }
26

27
  this->set_cells(cells);
1,146✔
28
}
1,146✔
29

30
void CellFilter::set_cells(span<int32_t> cells)
1,168✔
31
{
32
  // Clear existing cells
33
  cells_.clear();
1,168✔
34
  cells_.reserve(cells.size());
1,168✔
35
  map_.clear();
1,168✔
36

37
  // Update cells and mapping
38
  for (auto& index : cells) {
4,054✔
39
    assert(index >= 0);
2,495✔
40
    assert(index < model::cells.size());
2,495✔
41
    cells_.push_back(index);
2,886✔
42
    map_[index] = cells_.size() - 1;
2,886✔
43
  }
44

45
  n_bins_ = cells_.size();
1,168✔
46
}
1,168✔
47

48
void CellFilter::get_all_bins(
125,246,350✔
49
  const Particle& p, TallyEstimator estimator, FilterMatch& match) const
50
{
51
  for (int i = 0; i < p.n_coord(); i++) {
286,991,405✔
52
    auto search = map_.find(p.coord(i).cell);
161,745,055✔
53
    if (search != map_.end()) {
161,745,055✔
54
      match.bins_.push_back(search->second);
47,694,871✔
55
      match.weights_.push_back(1.0);
47,694,871✔
56
    }
57
  }
58
}
125,246,350✔
59

60
void CellFilter::to_statepoint(hid_t filter_group) const
1,070✔
61
{
62
  Filter::to_statepoint(filter_group);
1,070✔
63
  vector<int32_t> cell_ids;
1,070✔
64
  for (auto c : cells_)
3,670✔
65
    cell_ids.push_back(model::cells[c]->id_);
2,600✔
66
  write_dataset(filter_group, "bins", cell_ids);
1,070✔
67
}
1,070✔
68

69
std::string CellFilter::text_label(int bin) const
10,070✔
70
{
71
  return fmt::format("Cell {}", model::cells[cells_[bin]]->id_);
20,140✔
72
}
73

74
//==============================================================================
75
// C-API functions
76
//==============================================================================
77

78
extern "C" int openmc_cell_filter_get_bins(
15✔
79
  int32_t index, const int32_t** cells, int32_t* n)
80
{
81
  if (int err = verify_filter(index))
15✔
UNCOV
82
    return err;
×
83

84
  const auto& filt = model::tally_filters[index].get();
15✔
85
  if (filt->type() != FilterType::CELL) {
15✔
UNCOV
86
    set_errmsg("Tried to get cells from a non-cell filter.");
×
UNCOV
87
    return OPENMC_E_INVALID_TYPE;
×
88
  }
89

90
  auto cell_filt = static_cast<CellFilter*>(filt);
15✔
91
  *cells = cell_filt->cells().data();
15✔
92
  *n = cell_filt->cells().size();
15✔
93
  return 0;
15✔
94
}
95

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