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

openmc-dev / openmc / 13183778412

06 Feb 2025 04:50PM UTC coverage: 82.601% (-2.3%) from 84.867%
13183778412

Pull #3087

github

web-flow
Merge f09af412b into 6e0f156d3
Pull Request #3087: wheel building with scikit build core

107123 of 129687 relevant lines covered (82.6%)

12608225.33 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 <fmt/core.h>
4

5
#include "openmc/capi.h"
6
#include "openmc/cell.h"
7
#include "openmc/error.h"
8
#include "openmc/xml_interface.h"
9

10
namespace openmc {
11

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

25
  this->set_cells(cells);
740✔
26
}
740✔
27

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

35
  // Update cells and mapping
36
  for (auto& index : cells) {
2,772✔
37
    Expects(index >= 0);
2,015✔
38
    Expects(index < model::cells.size());
2,015✔
39
    cells_.push_back(index);
2,015✔
40
    map_[index] = cells_.size() - 1;
2,015✔
41
  }
42

43
  n_bins_ = cells_.size();
757✔
44
}
757✔
45

46
void CellFilter::get_all_bins(
97,095,964✔
47
  const Particle& p, TallyEstimator estimator, FilterMatch& match) const
48
{
49
  for (int i = 0; i < p.n_coord(); i++) {
223,142,060✔
50
    auto search = map_.find(p.coord(i).cell);
126,046,096✔
51
    if (search != map_.end()) {
126,046,096✔
52
      match.bins_.push_back(search->second);
35,133,979✔
53
      match.weights_.push_back(1.0);
35,133,979✔
54
    }
55
  }
56
}
97,095,964✔
57

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

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

72
//==============================================================================
73
// C-API functions
74
//==============================================================================
75

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

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

88
  auto cell_filt = static_cast<CellFilter*>(filt);
×
89
  *cells = cell_filt->cells().data();
×
90
  *n = cell_filt->cells().size();
×
91
  return 0;
×
92
}
93

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