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

openmc-dev / openmc / 13114782272

03 Feb 2025 01:38PM UTC coverage: 82.603% (-2.3%) from 84.867%
13114782272

Pull #3087

github

web-flow
Merge 258841139 into 59c398be8
Pull Request #3087: wheel building with scikit build core

107121 of 129682 relevant lines covered (82.6%)

12608592.69 hits per line

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

59.65
/src/tallies/filter_material.cpp
1
#include "openmc/tallies/filter_material.h"
2

3
#include <fmt/core.h>
4

5
#include "openmc/capi.h"
6
#include "openmc/material.h"
7
#include "openmc/xml_interface.h"
8

9
namespace openmc {
10

11
void MaterialFilter::from_xml(pugi::xml_node node)
1,330✔
12
{
13
  // Get material IDs and convert to indices in the global materials vector
14
  auto mats = get_node_array<int32_t>(node, "bins");
1,330✔
15
  for (auto& m : mats) {
2,851✔
16
    auto search = model::material_map.find(m);
1,521✔
17
    if (search == model::material_map.end()) {
1,521✔
18
      throw std::runtime_error {fmt::format(
×
19
        "Could not find material {} specified on tally filter.", m)};
×
20
    }
21
    m = search->second;
1,521✔
22
  }
23

24
  this->set_materials(mats);
1,330✔
25
}
1,330✔
26

27
void MaterialFilter::set_materials(gsl::span<const int32_t> materials)
1,330✔
28
{
29
  // Clear existing materials
30
  materials_.clear();
1,330✔
31
  materials_.reserve(materials.size());
1,330✔
32
  map_.clear();
1,330✔
33

34
  // Update materials and mapping
35
  for (auto& index : materials) {
2,851✔
36
    Expects(index >= 0);
1,521✔
37
    Expects(index < model::materials.size());
1,521✔
38
    materials_.push_back(index);
1,521✔
39
    map_[index] = materials_.size() - 1;
1,521✔
40
  }
41

42
  n_bins_ = materials_.size();
1,330✔
43
}
1,330✔
44

45
void MaterialFilter::get_all_bins(
325,769,040✔
46
  const Particle& p, TallyEstimator estimator, FilterMatch& match) const
47
{
48
  auto search = map_.find(p.material());
325,769,040✔
49
  if (search != map_.end()) {
325,769,040✔
50
    match.bins_.push_back(search->second);
180,544,944✔
51
    match.weights_.push_back(1.0);
180,544,944✔
52
  }
53
}
325,769,040✔
54

55
void MaterialFilter::to_statepoint(hid_t filter_group) const
1,032✔
56
{
57
  Filter::to_statepoint(filter_group);
1,032✔
58
  vector<int32_t> material_ids;
1,032✔
59
  for (auto c : materials_)
2,244✔
60
    material_ids.push_back(model::materials[c]->id_);
1,212✔
61
  write_dataset(filter_group, "bins", material_ids);
1,032✔
62
}
1,032✔
63

64
std::string MaterialFilter::text_label(int bin) const
10,632✔
65
{
66
  return fmt::format("Material {}", model::materials[materials_[bin]]->id_);
21,264✔
67
}
68

69
//==============================================================================
70
// C-API functions
71
//==============================================================================
72

73
extern "C" int openmc_material_filter_get_bins(
×
74
  int32_t index, const int32_t** bins, size_t* n)
75
{
76
  // Make sure this is a valid index to an allocated filter.
77
  if (int err = verify_filter(index))
×
78
    return err;
×
79

80
  // Get a pointer to the filter and downcast.
81
  const auto& filt_base = model::tally_filters[index].get();
×
82
  auto* filt = dynamic_cast<MaterialFilter*>(filt_base);
×
83

84
  // Check the filter type.
85
  if (!filt) {
×
86
    set_errmsg("Tried to get material filter bins on a non-material filter.");
×
87
    return OPENMC_E_INVALID_TYPE;
×
88
  }
89

90
  // Output the bins.
91
  *bins = filt->materials().data();
×
92
  *n = filt->materials().size();
×
93
  return 0;
×
94
}
95

96
extern "C" int openmc_material_filter_set_bins(
×
97
  int32_t index, size_t n, const int32_t* bins)
98
{
99
  // Make sure this is a valid index to an allocated filter.
100
  if (int err = verify_filter(index))
×
101
    return err;
×
102

103
  // Get a pointer to the filter and downcast.
104
  const auto& filt_base = model::tally_filters[index].get();
×
105
  auto* filt = dynamic_cast<MaterialFilter*>(filt_base);
×
106

107
  // Check the filter type.
108
  if (!filt) {
×
109
    set_errmsg("Tried to set material filter bins on a non-material filter.");
×
110
    return OPENMC_E_INVALID_TYPE;
×
111
  }
112

113
  // Update the filter.
114
  filt->set_materials({bins, n});
×
115
  return 0;
×
116
}
117

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