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

openmc-dev / openmc / 23084721708

14 Mar 2026 08:56AM UTC coverage: 81.599% (-0.5%) from 82.058%
23084721708

Pull #2693

github

web-flow
Merge 0ed23ee59 into bc9c31e0f
Pull Request #2693: Add reactivity control to coupled transport-depletion analyses

17575 of 25275 branches covered (69.54%)

Branch coverage included in aggregate %.

74 of 85 new or added lines in 4 files covered. (87.06%)

3755 existing lines in 99 files now uncovered.

58074 of 67433 relevant lines covered (86.12%)

47252067.37 hits per line

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

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

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

49
  for (pugi::xml_node source_node : node.children("source")) {
70,158✔
50
    auto particle = get_node_value(source_node, "particle");
31,218✔
51
    if (particle == "photon") {
31,218✔
52
      photon_energy_ = distribution_from_xml(source_node);
31,185✔
53
      break;
31,185✔
54
    }
55
  }
31,218✔
56

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

61
ChainNuclide::~ChainNuclide()
70,125✔
62
{
63
  data::chain_nuclide_map.erase(name_);
70,125✔
64
}
140,250✔
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
//==============================================================================
78
// Global variables
79
//==============================================================================
80

81
namespace data {
82

83
std::unordered_map<std::string, int> chain_nuclide_map;
84
vector<unique_ptr<ChainNuclide>> chain_nuclides;
85

86
} // namespace data
87

88
//==============================================================================
89
// Non-member functions
90
//==============================================================================
91

92
void read_chain_file_xml()
8,213✔
93
{
94
  char* chain_file_path = std::getenv("OPENMC_CHAIN_FILE");
8,213✔
95
  if (!chain_file_path) {
8,213✔
96
    return;
436✔
97
  }
98

99
  write_message(5, "Reading chain file: {}...", chain_file_path);
7,777✔
100

101
  pugi::xml_document doc;
7,777✔
102
  auto result = doc.load_file(chain_file_path);
7,777✔
103
  if (!result) {
7,777!
104
    fatal_error(
×
105
      fmt::format("Error processing chain file: {}", chain_file_path));
×
106
  }
107

108
  // Get root element
109
  pugi::xml_node root = doc.document_element();
7,777✔
110

111
  for (auto node : root.children("nuclide")) {
77,902✔
112
    data::chain_nuclides.push_back(std::make_unique<ChainNuclide>(node));
140,250✔
113
  }
114
}
7,777✔
115

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