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

openmc-dev / openmc / 22500302709

27 Feb 2026 07:16PM UTC coverage: 81.512% (-0.3%) from 81.826%
22500302709

Pull #3830

github

web-flow
Merge 25fbb4266 into b3788f11e
Pull Request #3830: Parallelize sampling external sources and threadsafe rejection counters

17488 of 25193 branches covered (69.42%)

Branch coverage included in aggregate %.

59 of 66 new or added lines in 6 files covered. (89.39%)

841 existing lines in 44 files now uncovered.

57726 of 67081 relevant lines covered (86.05%)

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

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

49
  for (pugi::xml_node source_node : node.children("source")) {
68,934✔
50
    auto particle = get_node_value(source_node, "particle");
30,674✔
51
    if (particle == "photon") {
30,674✔
52
      photon_energy_ = distribution_from_xml(source_node);
30,641✔
53
      break;
30,641✔
54
    }
55
  }
30,674✔
56

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

61
ChainNuclide::~ChainNuclide()
68,901✔
62
{
63
  data::chain_nuclide_map.erase(name_);
68,901✔
64
}
137,802✔
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,077✔
93
{
94
  char* chain_file_path = std::getenv("OPENMC_CHAIN_FILE");
8,077✔
95
  if (!chain_file_path) {
8,077✔
96
    return;
436✔
97
  }
98

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

101
  pugi::xml_document doc;
7,641✔
102
  auto result = doc.load_file(chain_file_path);
7,641✔
103
  if (!result) {
7,641!
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,641✔
110

111
  for (auto node : root.children("nuclide")) {
76,542✔
112
    data::chain_nuclides.push_back(std::make_unique<ChainNuclide>(node));
137,802✔
113
  }
114
}
7,641✔
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