|
16 | 16 | #include "xtensor/xbuilder.hpp" |
17 | 17 | #include "xtensor/xoperation.hpp" |
18 | 18 | #include "xtensor/xview.hpp" |
| 19 | +#include "xtensor/xmath.hpp" |
| 20 | +#include "xtensor/xslice.hpp" |
| 21 | +#include "xtensor/xtensor_forward.hpp" |
19 | 22 |
|
20 | 23 | #include <cmath> |
21 | 24 | #include <fmt/core.h> |
@@ -125,6 +128,7 @@ PhotonInteraction::PhotonInteraction(hid_t group) |
125 | 128 | } |
126 | 129 |
|
127 | 130 | shells_.resize(n_shell); |
| 131 | + cross_sections_.resize({energy_.size(), n_shell}); |
128 | 132 |
|
129 | 133 | // Create mapping from designator to index |
130 | 134 | std::unordered_map<int, int> shell_map; |
@@ -155,13 +159,14 @@ PhotonInteraction::PhotonInteraction(hid_t group) |
155 | 159 | read_attribute(tgroup, "num_electrons", shell.n_electrons); |
156 | 160 |
|
157 | 161 | // Read subshell cross section |
| 162 | + xt::xtensor<double, 1> xs; |
158 | 163 | dset = open_dataset(tgroup, "xs"); |
159 | 164 | read_attribute(dset, "threshold_idx", shell.threshold); |
160 | 165 | close_dataset(dset); |
161 | | - read_dataset(tgroup, "xs", shell.cross_section); |
| 166 | + read_dataset(tgroup, "xs", xs); |
162 | 167 |
|
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); |
165 | 170 |
|
166 | 171 | if (object_exists(tgroup, "transitions")) { |
167 | 172 | // Determine dimensions of transitions |
@@ -565,19 +570,10 @@ void PhotonInteraction::calculate_xs(Particle& p) const |
565 | 570 | incoherent_(i_grid) + f * (incoherent_(i_grid + 1) - incoherent_(i_grid))); |
566 | 571 |
|
567 | 572 | // 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); |
574 | 575 |
|
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]; |
581 | 577 |
|
582 | 578 | // Calculate microscopic pair production cross section |
583 | 579 | xs.pair_production = std::exp( |
|
0 commit comments