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

openmc-dev / openmc / 14515233533

17 Apr 2025 12:06PM UTC coverage: 83.16% (-2.3%) from 85.414%
14515233533

Pull #3087

github

web-flow
Merge 6ed397e9d into 47ca2916a
Pull Request #3087: wheel building with scikit build core

140769 of 169274 relevant lines covered (83.16%)

11830168.1 hits per line

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

72.92
/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)
804✔
15
{
16
  // Get cell IDs and convert to indices into the global cells vector
17
  auto cells = get_node_array<int32_t>(node, "bins");
804✔
18
  for (auto& c : cells) {
2,728✔
19
    auto search = model::cell_map.find(c);
1,924✔
20
    if (search == model::cell_map.end()) {
1,924✔
21
      throw std::runtime_error {
×
22
        fmt::format("Could not find cell {} specified on tally filter.", c)};
×
23
    }
24
    c = search->second;
1,924✔
25
  }
26

27
  this->set_cells(cells);
804✔
28
}
804✔
29

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

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

45
  n_bins_ = cells_.size();
820✔
46
}
820✔
47

48
void CellFilter::get_all_bins(
89,120,745✔
49
  const Particle& p, TallyEstimator estimator, FilterMatch& match) const
50
{
51
  for (int i = 0; i < p.n_coord(); i++) {
205,007,207✔
52
    auto search = map_.find(p.coord(i).cell);
115,886,462✔
53
    if (search != map_.end()) {
115,886,462✔
54
      match.bins_.push_back(search->second);
32,244,666✔
55
      match.weights_.push_back(1.0);
32,244,666✔
56
    }
57
  }
58
}
89,120,745✔
59

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

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

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

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

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

90
  auto cell_filt = static_cast<CellFilter*>(filt);
×
91
  *cells = cell_filt->cells().data();
×
92
  *n = cell_filt->cells().size();
×
93
  return 0;
×
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