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

openmc-dev / openmc / 14455467353

14 Apr 2025 08:49PM UTC coverage: 85.176% (-0.2%) from 85.414%
14455467353

Pull #3345

github

web-flow
Merge 25138d8a5 into 47ca2916a
Pull Request #3345: Filter weight implementation

30 of 31 new or added lines in 5 files covered. (96.77%)

115 existing lines in 20 files now uncovered.

52040 of 61097 relevant lines covered (85.18%)

37018357.61 hits per line

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

96.0
/src/tallies/filter_weight.cpp
1
#include "openmc/tallies/filter_weight.h"
2

3
#include <algorithm> // for is_sorted
4
#include <stdexcept> // for runtime_error
5

6
#include <fmt/core.h>
7

8
#include "openmc/search.h"
9
#include "openmc/xml_interface.h"
10

11
namespace openmc {
12

13
//==============================================================================
14
// WeightFilter implementation
15
//==============================================================================
16

17
void WeightFilter::from_xml(pugi::xml_node node)
11✔
18
{
19
  auto bins = get_node_array<double>(node, "bins");
11✔
20
  this->set_bins(bins);
11✔
21
}
11✔
22

23
void WeightFilter::set_bins(span<const double> bins)
11✔
24
{
25
  if (!std::is_sorted(bins.begin(), bins.end())) {
11✔
NEW
26
    throw std::runtime_error {"Weight bins must be monotonically increasing."};
×
27
  }
28

29
  // Clear existing bins
30
  bins_.clear();
11✔
31
  bins_.reserve(bins.size());
11✔
32

33
  // Copy bins
34
  bins_.insert(bins_.end(), bins.begin(), bins.end());
11✔
35
  n_bins_ = bins_.size() - 1;
11✔
36
}
11✔
37

38
void WeightFilter::get_all_bins(
322,322✔
39
  const Particle& p, TallyEstimator estimator, FilterMatch& match) const
40
{
41
  // Get particle weight
42
  double wgt = p.wgt_last();
322,322✔
43

44
  // Bin the weight
45
  if (wgt >= bins_.front() && wgt <= bins_.back()) {
322,322✔
46
    auto bin = lower_bound_index(bins_.begin(), bins_.end(), wgt);
322,322✔
47
    match.bins_.push_back(bin);
322,322✔
48
    match.weights_.push_back(1.0);
322,322✔
49
  }
50
}
322,322✔
51

52
void WeightFilter::to_statepoint(hid_t filter_group) const
11✔
53
{
54
  Filter::to_statepoint(filter_group);
11✔
55
  write_dataset(filter_group, "bins", bins_);
11✔
56
}
11✔
57

58
std::string WeightFilter::text_label(int bin) const
4,224✔
59
{
60
  return fmt::format("Weight [{}, {}]", bins_[bin], bins_[bin + 1]);
8,448✔
61
}
62

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