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

openmc-dev / openmc / 19910382579

03 Dec 2025 10:06PM UTC coverage: 81.805% (-0.1%) from 81.942%
19910382579

Pull #3550

github

web-flow
Merge 481901eb4 into ad5a876be
Pull Request #3550: [Point Detector] Add distribution get_pdf functionality

16991 of 23680 branches covered (71.75%)

Branch coverage included in aggregate %.

59 of 222 new or added lines in 14 files covered. (26.58%)

5 existing lines in 3 files now uncovered.

54911 of 64214 relevant lines covered (85.51%)

43378737.03 hits per line

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

88.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)
63,942✔
25
{
26
  name_ = get_node_value(node, "name");
63,942✔
27
  if (check_for_node(node, "half_life")) {
63,942✔
28
    half_life_ = std::stod(get_node_value(node, "half_life"));
14,290✔
29
  }
30
  if (check_for_node(node, "decay_energy")) {
63,942✔
31
    decay_energy_ = std::stod(get_node_value(node, "decay_energy"));
14,290✔
32
  }
33

34
  // Read reactions to store MT -> product map
35
  for (pugi::xml_node reaction_node : node.children("reaction")) {
113,902✔
36
    std::string rx_name = get_node_value(reaction_node, "type");
49,960✔
37
    if (!reaction_node.attribute("target"))
49,960✔
38
      continue;
21,358✔
39
    std::string rx_target = get_node_value(reaction_node, "target");
28,602✔
40
    double branching_ratio = 1.0;
28,602✔
41
    if (reaction_node.attribute("branching_ratio")) {
28,602!
42
      branching_ratio =
43
        std::stod(get_node_value(reaction_node, "branching_ratio"));
×
44
    }
45
    int mt = reaction_type(rx_name);
28,602✔
46
    reaction_products_[mt].push_back({rx_target, branching_ratio});
28,602✔
47
  }
49,960✔
48

49
  for (pugi::xml_node source_node : node.children("source")) {
63,975✔
50
    auto particle = get_node_value(source_node, "particle");
28,470✔
51
    if (particle == "photon") {
28,470✔
52
      photon_energy_ = distribution_from_xml(source_node);
28,437✔
53
      break;
28,437✔
54
    }
55
  }
28,470✔
56

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

61
ChainNuclide::~ChainNuclide()
63,942✔
62
{
63
  data::chain_nuclide_map.erase(name_);
63,942✔
64
}
63,942✔
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);
54,725✔
74
  mu = Uniform(-1., 1.).sample(seed);
54,725✔
75
}
54,725✔
76

NEW
77
double DecayPhotonAngleEnergy::sample_energy_and_pdf(
×
78
  double E_in, double mu, double& E_out, uint64_t* seed) const
79
{
NEW
80
  E_out = photon_energy_->sample(seed);
×
NEW
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()
7,524✔
100
{
101
  char* chain_file_path = std::getenv("OPENMC_CHAIN_FILE");
7,524✔
102
  if (!chain_file_path) {
7,524✔
103
    return;
434✔
104
  }
105

106
  write_message(5, "Reading chain file: {}...", chain_file_path);
7,090✔
107

108
  pugi::xml_document doc;
7,090✔
109
  auto result = doc.load_file(chain_file_path);
7,090✔
110
  if (!result) {
7,090!
111
    fatal_error(
×
112
      fmt::format("Error processing chain file: {}", chain_file_path));
×
113
  }
114

115
  // Get root element
116
  pugi::xml_node root = doc.document_element();
7,090✔
117

118
  for (auto node : root.children("nuclide")) {
71,032✔
119
    data::chain_nuclides.push_back(std::make_unique<ChainNuclide>(node));
63,942✔
120
  }
121
}
7,090✔
122

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

© 2025 Coveralls, Inc