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

openmc-dev / openmc / 13461947318

21 Feb 2025 05:24PM UTC coverage: 85.019% (+0.05%) from 84.969%
13461947318

Pull #3140

github

web-flow
Merge ece247ada into 2b788ea6e
Pull Request #3140: Add Versioning Support from `version.txt`

8 of 8 new or added lines in 2 files covered. (100.0%)

1293 existing lines in 43 files now uncovered.

50627 of 59548 relevant lines covered (85.02%)

35584918.67 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)
879✔
15
{
16
  // Get cell IDs and convert to indices into the global cells vector
17
  auto cells = get_node_array<int32_t>(node, "bins");
879✔
18
  for (auto& c : cells) {
3,020✔
19
    auto search = model::cell_map.find(c);
2,141✔
20
    if (search == model::cell_map.end()) {
2,141✔
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,141✔
25
  }
26

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

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

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

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

48
void CellFilter::get_all_bins(
100,202,032✔
49
  const Particle& p, TallyEstimator estimator, FilterMatch& match) const
50
{
51
  for (int i = 0; i < p.n_coord(); i++) {
229,603,028✔
52
    auto search = map_.find(p.coord(i).cell);
129,400,996✔
53
    if (search != map_.end()) {
129,400,996✔
54
      match.bins_.push_back(search->second);
38,157,103✔
55
      match.weights_.push_back(1.0);
38,157,103✔
56
    }
57
  }
58
}
100,202,032✔
59

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

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

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

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

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