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

openmc-dev / openmc / 17707962129

14 Sep 2025 07:15AM UTC coverage: 85.074% (-0.1%) from 85.218%
17707962129

Pull #3547

github

web-flow
Merge 07e1f2aef into afd9d0607
Pull Request #3547: Tally spectrum of secondary particles

23 of 58 new or added lines in 8 files covered. (39.66%)

31 existing lines in 2 files now uncovered.

52790 of 62052 relevant lines covered (85.07%)

38251650.85 hits per line

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

57.97
/src/tallies/filter_particle.cpp
1
#include "openmc/tallies/filter_particle.h"
2

3
#include <fmt/core.h>
4

5
#include "openmc/xml_interface.h"
6

7
namespace openmc {
8

9
//==============================================================================
10
// ParticleFilter implementation
11
//==============================================================================
12

13
void ParticleFilter::from_xml(pugi::xml_node node)
294✔
14
{
15
  auto particles = get_node_array<std::string>(node, "bins");
294✔
16

17
  // Convert to vector of ParticleType
18
  vector<ParticleType> types;
294✔
19
  for (auto& p : particles) {
908✔
20
    types.push_back(str_to_particle_type(p));
614✔
21
  }
22
  this->set_particles(types);
294✔
23
}
294✔
24

25
void ParticleFilter::set_particles(span<ParticleType> particles)
376✔
26
{
27
  // Clear existing particles
28
  particles_.clear();
376✔
29
  particles_.reserve(particles.size());
376✔
30

31
  // Set particles and number of bins
32
  for (auto p : particles) {
1,072✔
33
    particles_.push_back(p);
696✔
34
  }
35
  n_bins_ = particles_.size();
376✔
36
}
376✔
37

38
void ParticleFilter::get_all_bins(
161,785,983✔
39
  const Particle& p, TallyEstimator estimator, FilterMatch& match) const
40
{
41
  // Get the pre-collision type of the particle.
42
  auto type = p.type_last();
161,785,983✔
43

44
  for (auto i = 0; i < particles_.size(); i++) {
440,667,115✔
45
    if (particles_[i] == type) {
278,881,132✔
46
      match.bins_.push_back(i);
91,756,894✔
47
      match.weights_.push_back(1.0);
91,756,894✔
48
    }
49
  }
50
}
161,785,983✔
51

52
void ParticleFilter::to_statepoint(hid_t filter_group) const
437✔
53
{
54
  Filter::to_statepoint(filter_group);
437✔
55
  vector<std::string> particles;
437✔
56
  for (auto p : particles_) {
1,221✔
57
    particles.push_back(particle_type_to_str(p));
784✔
58
  }
59
  write_dataset(filter_group, "bins", particles);
437✔
60
}
437✔
61

62
std::string ParticleFilter::text_label(int bin) const
3,257,849✔
63
{
64
  const auto& p = particles_.at(bin);
3,257,849✔
65
  return fmt::format("Particle: {}", particle_type_to_str(p));
6,515,698✔
66
}
67

68
//==============================================================================
69
// ParticleOutFilter implementation
70
//==============================================================================
71

NEW
72
void ParticleOutFilter::from_xml(pugi::xml_node node)
×
73
{
NEW
74
  auto particles = get_node_array<std::string>(node, "bins");
×
75

76
  // Convert to vector of ParticleType
NEW
77
  vector<ParticleType> types;
×
NEW
78
  for (auto& p : particles) {
×
NEW
79
    types.push_back(str_to_particle_type(p));
×
80
  }
NEW
81
  this->set_particles(types);
×
82
}
83

NEW
84
void ParticleOutFilter::set_particles(span<ParticleType> particles)
×
85
{
86
  // Clear existing particles
NEW
87
  particles_.clear();
×
NEW
88
  particles_.reserve(particles.size());
×
89

90
  // Set particles and number of bins
NEW
91
  for (auto p : particles) {
×
NEW
92
    particles_.push_back(p);
×
93
  }
NEW
94
  n_bins_ = particles_.size();
×
95
}
96

NEW
97
void ParticleOutFilter::get_all_bins(
×
98
  const Particle& p, TallyEstimator estimator, FilterMatch& match) const
99
{
NEW
100
  for (auto i = 0; i < particles_.size(); i++) {
×
NEW
101
    if (particles_[i] == p.type()) {
×
NEW
102
      match.bins_.push_back(i);
×
NEW
103
      match.weights_.push_back(1.0);
×
104
    }
105
  }
106
}
107

NEW
108
void ParticleOutFilter::to_statepoint(hid_t filter_group) const
×
109
{
NEW
110
  Filter::to_statepoint(filter_group);
×
NEW
111
  vector<std::string> particles;
×
NEW
112
  for (auto p : particles_) {
×
NEW
113
    particles.push_back(particle_type_to_str(p));
×
114
  }
NEW
115
  write_dataset(filter_group, "bins", particles);
×
116
}
117

NEW
118
std::string ParticleOutFilter::text_label(int bin) const
×
119
{
NEW
120
  const auto& p = particles_.at(bin);
×
NEW
121
  return fmt::format("ParticleOut: {}", particle_type_to_str(p));
×
122
}
123

124
//==============================================================================
125
// C-API functions
126
//==============================================================================
127

128
extern "C" int openmc_particle_filter_get_bins(int32_t idx, int bins[])
144✔
129
{
130
  if (int err = verify_filter(idx))
144✔
131
    return err;
×
132

133
  const auto& f = model::tally_filters[idx];
144✔
134
  auto pf = dynamic_cast<ParticleFilter*>(f.get());
144✔
135
  if (pf) {
144✔
136
    const auto& particles = pf->particles();
144✔
137
    for (int i = 0; i < particles.size(); i++) {
432✔
138
      bins[i] = static_cast<int>(particles[i]);
288✔
139
    }
140
  } else {
141
    set_errmsg("The filter at the specified index is not a ParticleFilter");
×
142
    return OPENMC_E_INVALID_ARGUMENT;
×
143
  }
144
  return 0;
144✔
145
}
146

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