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

openmc-dev / openmc / 25632480981

10 May 2026 03:25PM UTC coverage: 81.003% (-0.4%) from 81.388%
25632480981

Pull #3757

github

web-flow
Merge f7b7414eb into d56cda254
Pull Request #3757: Testing point detectors

17777 of 25846 branches covered (68.78%)

Branch coverage included in aggregate %.

51 of 372 new or added lines in 25 files covered. (13.71%)

3 existing lines in 2 files now uncovered.

58790 of 68678 relevant lines covered (85.6%)

46992975.87 hits per line

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

84.43
/src/chain.cpp
1
//! \file chain.cpp
2
//! \brief Depletion chain and associated information
3

4
#include "openmc/chain.h"
5

6
#include <cstdlib> // for getenv
7
#include <memory>  // for make_unique
8
#include <string>  // for stod
9

10
#include <fmt/core.h>
11
#include <pugixml.hpp>
12

13
#include "openmc/distribution.h" // for distribution_from_xml
14
#include "openmc/error.h"
15
#include "openmc/reaction.h"
16
#include "openmc/xml_interface.h" // for get_node_value
17

18
namespace openmc {
19

20
//==============================================================================
21
// ChainNuclide implementation
22
//==============================================================================
23

24
ChainNuclide::ChainNuclide(pugi::xml_node node)
73,369✔
25
{
26
  name_ = get_node_value(node, "name");
73,369✔
27
  if (check_for_node(node, "half_life")) {
73,369✔
28
    half_life_ = std::stod(get_node_value(node, "half_life"));
34,740✔
29
  }
30
  if (check_for_node(node, "decay_energy")) {
73,369✔
31
    decay_energy_ = std::stod(get_node_value(node, "decay_energy"));
34,696✔
32
  }
33

34
  // Read reactions to store MT -> product map
35
  for (pugi::xml_node reaction_node : node.children("reaction")) {
193,375✔
36
    std::string rx_name = get_node_value(reaction_node, "type");
60,003✔
37
    if (!reaction_node.attribute("target"))
60,003✔
38
      continue;
25,021✔
39
    std::string rx_target = get_node_value(reaction_node, "target");
34,982✔
40
    double branching_ratio = 1.0;
34,982✔
41
    if (reaction_node.attribute("branching_ratio")) {
34,982!
42
      branching_ratio =
×
43
        std::stod(get_node_value(reaction_node, "branching_ratio"));
×
44
    }
45
    int mt = reaction_mt(rx_name);
34,982✔
46
    reaction_products_[mt].push_back({rx_target, branching_ratio});
34,982✔
47
  }
60,003✔
48

49
  for (pugi::xml_node source_node : node.children("source")) {
73,798✔
50
    auto particle = get_node_value(source_node, "particle");
33,288✔
51
    if (particle == "photon") {
33,288✔
52
      photon_energy_ = distribution_from_xml(source_node);
32,859✔
53
      break;
32,859✔
54
    }
55
  }
33,288✔
56

57
  // Set entry in mapping
58
  data::chain_nuclide_map[name_] = data::chain_nuclides.size();
73,369✔
59
}
73,369✔
60

61
ChainNuclide::~ChainNuclide()
73,369✔
62
{
63
  data::chain_nuclide_map.erase(name_);
73,369✔
64
}
146,738✔
65

66
//==============================================================================
67
// DecayPhotonAngleEnergy implementation
68
//==============================================================================
69

70
void DecayPhotonAngleEnergy::sample(
54,725✔
71
  double E_in, double& E_out, double& mu, uint64_t* seed) const
72
{
73
  E_out = photon_energy_->sample(seed).first;
54,725✔
74
  mu = Uniform(-1., 1.).sample(seed).first;
54,725✔
75
}
54,725✔
76

NEW
77
double DecayPhotonAngleEnergy::sample_energy_and_pdf(double E_in, double mu,
×
78
  double& E_out, uint64_t* seed, bool is_com, double awr) const
79
{
NEW
80
  if (is_com)
×
NEW
81
    fatal_error(
×
82
      "DecayPhotonAngleEnergy distribution must be in lab coordinates");
83

84
  E_out = photon_energy_->sample(seed).first;
×
85
  return 0.5;
×
86
}
87

88
//==============================================================================
89
// Global variables
90
//==============================================================================
91

92
namespace data {
93

94
std::unordered_map<std::string, int> chain_nuclide_map;
95
vector<unique_ptr<ChainNuclide>> chain_nuclides;
96

97
} // namespace data
98

99
//==============================================================================
100
// Non-member functions
101
//==============================================================================
102

103
void read_chain_file_xml()
8,406✔
104
{
105
  free_memory_chain();
8,406✔
106

107
  char* chain_file_path = std::getenv("OPENMC_CHAIN_FILE");
8,406✔
108
  if (!chain_file_path) {
8,406✔
109
    return;
436✔
110
  }
111

112
  write_message(5, "Reading chain file: {}...", chain_file_path);
7,970✔
113

114
  pugi::xml_document doc;
7,970✔
115
  auto result = doc.load_file(chain_file_path);
7,970✔
116
  if (!result) {
7,970!
117
    fatal_error(
×
118
      fmt::format("Error processing chain file: {}", chain_file_path));
×
119
  }
120

121
  // Get root element
122
  pugi::xml_node root = doc.document_element();
7,970✔
123

124
  for (auto node : root.children("nuclide")) {
81,339✔
125
    data::chain_nuclides.push_back(std::make_unique<ChainNuclide>(node));
146,738✔
126
  }
127
}
7,970✔
128

129
void free_memory_chain()
16,877✔
130
{
131
  data::chain_nuclides.clear();
16,877✔
132
  data::chain_nuclide_map.clear();
16,877✔
133
}
16,877✔
134

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