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

openmc-dev / openmc / 13948364755

19 Mar 2025 01:58PM UTC coverage: 85.123% (+0.3%) from 84.851%
13948364755

Pull #3279

github

web-flow
Merge 8633f5d3f into 18d9f9755
Pull Request #3279: Hexagonal mesh model

51566 of 60578 relevant lines covered (85.12%)

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

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

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

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

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

48
void CellFilter::get_all_bins(
91,853,926✔
49
  const Particle& p, TallyEstimator estimator, FilterMatch& match) const
50
{
51
  for (int i = 0; i < p.n_coord(); i++) {
210,473,569✔
52
    auto search = map_.find(p.coord(i).cell);
118,619,643✔
53
    if (search != map_.end()) {
118,619,643✔
54
      match.bins_.push_back(search->second);
34,977,847✔
55
      match.weights_.push_back(1.0);
34,977,847✔
56
    }
57
  }
58
}
91,853,926✔
59

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

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

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

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

84
  const auto& filt = model::tally_filters[index].get();
11✔
85
  if (filt->type() != FilterType::CELL) {
11✔
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);
11✔
91
  *cells = cell_filt->cells().data();
11✔
92
  *n = cell_filt->cells().size();
11✔
93
  return 0;
11✔
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