Sitelet https://github.com/openmsr/openmc/commit/687d43b0ab6e3e3ddfe867767c210f0a1cfb38a7
Skip to content

Commit 687d43b

Browse files
committed
added external xtensor within PhotonInteraction for all shell photoelectric xs to utilize contiguous memory in calculate_xs
1 parent 1be02f9 commit 687d43b

3 files changed

Lines changed: 15 additions & 19 deletions

File tree

‎include/openmc/photon.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ class ElectronSubshell {
3636
int threshold;
3737
double n_electrons;
3838
double binding_energy;
39-
xt::xtensor<double, 1> cross_section;
4039
vector<Transition> transitions;
4140
};
4241

@@ -82,6 +81,7 @@ class PhotonInteraction {
8281

8382
// Photoionization and atomic relaxation data
8483
vector<ElectronSubshell> shells_;
84+
xt::xtensor<double, 2> cross_sections_;
8585

8686
// Compton profile data
8787
xt::xtensor<double, 2> profile_pdf_;

‎src/photon.cpp‎

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
#include "xtensor/xbuilder.hpp"
1717
#include "xtensor/xoperation.hpp"
1818
#include "xtensor/xview.hpp"
19+
#include "xtensor/xmath.hpp"
20+
#include "xtensor/xslice.hpp"
21+
#include "xtensor/xtensor_forward.hpp"
1922

2023
#include <cmath>
2124
#include <fmt/core.h>
@@ -125,6 +128,7 @@ PhotonInteraction::PhotonInteraction(hid_t group)
125128
}
126129

127130
shells_.resize(n_shell);
131+
cross_sections_.resize({energy_.size(), n_shell});
128132

129133
// Create mapping from designator to index
130134
std::unordered_map<int, int> shell_map;
@@ -155,13 +159,14 @@ PhotonInteraction::PhotonInteraction(hid_t group)
155159
read_attribute(tgroup, "num_electrons", shell.n_electrons);
156160

157161
// Read subshell cross section
162+
xt::xtensor<double, 1> xs;
158163
dset = open_dataset(tgroup, "xs");
159164
read_attribute(dset, "threshold_idx", shell.threshold);
160165
close_dataset(dset);
161-
read_dataset(tgroup, "xs", shell.cross_section);
166+
read_dataset(tgroup, "xs", xs);
162167

163-
auto& xs = shell.cross_section;
164-
xs = xt::where(xs > 0.0, xt::log(xs), -500.0);
168+
auto cross_section = xt::view(cross_sections_, xt::range(shell.threshold, shell.threshold + xs.size()), i);
169+
cross_section = xt::where(xs > 0.0, xt::log(xs), -500.0);
165170

166171
if (object_exists(tgroup, "transitions")) {
167172
// Determine dimensions of transitions
@@ -565,19 +570,10 @@ void PhotonInteraction::calculate_xs(Particle& p) const
565570
incoherent_(i_grid) + f * (incoherent_(i_grid + 1) - incoherent_(i_grid)));
566571

567572
// Calculate microscopic photoelectric cross section
568-
xs.photoelectric = 0.0;
569-
for (const auto& shell : shells_) {
570-
// Check threshold of reaction
571-
int i_start = shell.threshold;
572-
if (i_grid < i_start)
573-
continue;
573+
const auto& xs_upper = xt::row(cross_sections_, i_grid);
574+
const auto& xs_lower = xt::row(cross_sections_, i_grid + 1);
574575

575-
// Evaluation subshell photoionization cross section
576-
xs.photoelectric +=
577-
std::exp(shell.cross_section(i_grid - i_start) +
578-
f * (shell.cross_section(i_grid + 1 - i_start) -
579-
shell.cross_section(i_grid - i_start)));
580-
}
576+
xs.photoelectric = xt::sum(xt::exp(xs_upper + f * (xs_upper - xs_lower)))[0];
581577

582578
// Calculate microscopic pair production cross section
583579
xs.pair_production = std::exp(

‎src/physics.cpp‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,9 +358,9 @@ void sample_photon_reaction(Particle& p)
358358
continue;
359359

360360
// Evaluation subshell photoionization cross section
361-
double xs = std::exp(shell.cross_section(i_grid - i_start) +
362-
f * (shell.cross_section(i_grid + 1 - i_start) -
363-
shell.cross_section(i_grid - i_start)));
361+
double xs = std::exp(element.cross_sections_(i_grid - i_start) +
362+
f * (element.cross_sections_(i_grid + 1 - i_start) -
363+
element.cross_sections_(i_grid - i_start)));
364364

365365
prob += xs;
366366
if (prob > cutoff) {

0 commit comments

Comments
 (0)