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

openmc-dev / openmc / 12736621629

12 Jan 2025 07:58PM UTC coverage: 84.911% (+0.04%) from 84.868%
12736621629

Pull #3235

github

web-flow
Merge a15dc3072 into d2edf0ce4
Pull Request #3235: Simulation of decay photons through the D1S method

276 of 287 new or added lines in 15 files covered. (96.17%)

3 existing lines in 2 files now uncovered.

50309 of 59249 relevant lines covered (84.91%)

34373326.96 hits per line

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

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

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

49
  for (pugi::xml_node source_node : node.children("source")) {
22,383✔
50
    auto particle = get_node_value(source_node, "particle");
9,988✔
51
    if (particle == "photon") {
9,988✔
52
      photon_energy_ = distribution_from_xml(source_node);
9,952✔
53
      break;
9,952✔
54
    }
55
  }
9,988✔
56

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

61
ChainNuclide::~ChainNuclide()
22,347✔
62
{
63
  data::chain_nuclide_map.erase(name_);
22,347✔
64
}
22,347✔
65

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

70
void DecayPhotonAngleEnergy::sample(
59,700✔
71
  double E_in, double& E_out, double& mu, uint64_t* seed) const
72
{
73
  E_out = photon_energy_->sample(seed);
59,700✔
74
  mu = Uniform(-1., 1.).sample(seed);
59,700✔
75
}
59,700✔
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()
6,868✔
93
{
94
  char* chain_file_path = std::getenv("OPENMC_CHAIN_FILE");
6,868✔
95
  if (!chain_file_path) {
6,868✔
96
    return;
4,401✔
97
  }
98

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

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

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

111
  for (auto node : root.children("nuclide")) {
24,814✔
112
    data::chain_nuclides.push_back(std::make_unique<ChainNuclide>(node));
22,347✔
113
  }
114
}
2,467✔
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