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

openmc-dev / openmc / 26675018610

30 May 2026 04:53AM UTC coverage: 81.343% (+0.006%) from 81.337%
26675018610

Pull #3915

github

web-flow
Merge b70d83d50 into 46d889613
Pull Request #3915: Allow tracklength estimator for neutron heating

18010 of 26105 branches covered (68.99%)

Branch coverage included in aggregate %.

9 of 9 new or added lines in 1 file covered. (100.0%)

1782 existing lines in 46 files now uncovered.

59130 of 68728 relevant lines covered (86.03%)

48511807.72 hits per line

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

87.29
/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)
75,403✔
25
{
26
  name_ = get_node_value(node, "name");
75,403✔
27
  if (check_for_node(node, "half_life")) {
75,403✔
28
    half_life_ = std::stod(get_node_value(node, "half_life"));
35,644✔
29
  }
30
  if (check_for_node(node, "decay_energy")) {
75,403✔
31
    decay_energy_ = std::stod(get_node_value(node, "decay_energy"));
35,600✔
32
  }
33

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

49
  for (pugi::xml_node source_node : node.children("source")) {
75,832✔
50
    auto particle = get_node_value(source_node, "particle");
34,192✔
51
    if (particle == "photon") {
34,192✔
52
      photon_energy_ = distribution_from_xml(source_node);
33,763✔
53
      break;
33,763✔
54
    }
55
  }
34,192✔
56

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

61
ChainNuclide::~ChainNuclide()
75,403✔
62
{
63
  data::chain_nuclide_map.erase(name_);
75,403✔
64
}
150,806✔
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

77
double DecayPhotonAngleEnergy::sample_energy_and_pdf(
×
78
  double E_in, double mu, double& E_out, uint64_t* seed) const
79
{
80
  E_out = photon_energy_->sample(seed).first;
×
81
  return 0.5;
×
82
}
83

84
//==============================================================================
85
// Global variables
86
//==============================================================================
87

88
namespace data {
89

90
std::unordered_map<std::string, int> chain_nuclide_map;
91
vector<unique_ptr<ChainNuclide>> chain_nuclides;
92

93
} // namespace data
94

95
//==============================================================================
96
// Non-member functions
97
//==============================================================================
98

99
void read_chain_file_xml()
8,629✔
100
{
101
  free_memory_chain();
8,629✔
102

103
  char* chain_file_path = std::getenv("OPENMC_CHAIN_FILE");
8,629✔
104
  if (!chain_file_path) {
8,629✔
105
    return;
433✔
106
  }
107

108
  write_message(5, "Reading chain file: {}...", chain_file_path);
8,196✔
109

110
  pugi::xml_document doc;
8,196✔
111
  auto result = doc.load_file(chain_file_path);
8,196✔
112
  if (!result) {
8,196!
UNCOV
113
    fatal_error(
×
UNCOV
114
      fmt::format("Error processing chain file: {}", chain_file_path));
×
115
  }
116

117
  // Get root element
118
  pugi::xml_node root = doc.document_element();
8,196✔
119

120
  for (auto node : root.children("nuclide")) {
83,599✔
121
    data::chain_nuclides.push_back(std::make_unique<ChainNuclide>(node));
150,806✔
122
  }
123
}
8,196✔
124

125
void free_memory_chain()
17,320✔
126
{
127
  data::chain_nuclides.clear();
17,320✔
128
  data::chain_nuclide_map.clear();
17,320✔
129
}
17,320✔
130

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