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

openmc-dev / openmc / 13462313233

21 Feb 2025 05:47PM UTC coverage: 85.064% (+0.04%) from 85.02%
13462313233

push

github

web-flow
Simulation of decay photons through the D1S method (#3235)

D1S FTW!

284 of 295 new or added lines in 17 files covered. (96.27%)

3 existing lines in 2 files now uncovered.

50866 of 59797 relevant lines covered (85.06%)

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

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

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

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

61
ChainNuclide::~ChainNuclide()
22,788✔
62
{
63
  data::chain_nuclide_map.erase(name_);
22,788✔
64
}
22,788✔
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,939✔
93
{
94
  char* chain_file_path = std::getenv("OPENMC_CHAIN_FILE");
6,939✔
95
  if (!chain_file_path) {
6,939✔
96
    return;
4,423✔
97
  }
98

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

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

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

© 2025 Coveralls, Inc