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

openmc-dev / openmc / 12385490469

18 Dec 2024 02:58AM UTC coverage: 82.673% (-2.2%) from 84.823%
12385490469

Pull #3087

github

web-flow
Merge 3317476f5 into 775c41512
Pull Request #3087: wheel building with scikit build core

106679 of 129038 relevant lines covered (82.67%)

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

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

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

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

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

46
void CellFilter::get_all_bins(
97,080,699✔
47
  const Particle& p, TallyEstimator estimator, FilterMatch& match) const
48
{
49
  for (int i = 0; i < p.n_coord(); i++) {
223,111,530✔
50
    auto search = map_.find(p.coord(i).cell);
126,030,831✔
51
    if (search != map_.end()) {
126,030,831✔
52
      match.bins_.push_back(search->second);
35,131,416✔
53
      match.weights_.push_back(1.0);
35,131,416✔
54
    }
55
  }
56
}
97,080,699✔
57

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

67
std::string CellFilter::text_label(int bin) const
1,935✔
68
{
69
  return fmt::format("Cell {}", model::cells[cells_[bin]]->id_);
3,870✔
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