Skip to content

Commit 78a3567

Browse files
committed
wip
1 parent f7b7414 commit 78a3567

2 files changed

Lines changed: 24 additions & 4 deletions

File tree

src/angle_energy.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#include "openmc/angle_energy.h"
22

3-
#include <cmath> // for sqrt
3+
#include <algorithm> // for clamp
4+
#include <cmath> // for sqrt
45

6+
#include "openmc/constants.h"
57
#include "openmc/random_lcg.h"
68

79
namespace openmc {
@@ -23,9 +25,16 @@ double get_jac_and_transform_impl(
2325
return 0.0;
2426
D = std::sqrt(D);
2527

26-
if (mu_lab <= 0.0 && E_cm <= E_cm)
28+
if ((mu_lab <= 0.0) && (E_cm <= E_com))
2729
return 0.0;
28-
double E_out1 = E_com * (mu_lab + D) * (mu_lab + D);
30+
31+
double E_out1;
32+
if (mu_lab > 0.0) {
33+
E_out1 = E_com * (mu_lab + D) * (mu_lab + D);
34+
} else {
35+
E_out1 = E_com * ((E_cm / E_com - 1.0) / (D - mu_lab)) *
36+
((E_cm / E_com - 1.0) / (D - mu_lab));
37+
}
2938
double mult;
3039
if (E_cm > E_com) {
3140
mult = 1.0;
@@ -39,6 +48,9 @@ double get_jac_and_transform_impl(
3948
}
4049
}
4150
mu = mu_lab * std::sqrt(E_out / E_cm) - std::sqrt(E_com / E_cm);
51+
52+
if (std::abs(mu) < 1.0 + FP_PRECISION)
53+
mu = std::clamp(mu, -1.0, 1.0);
4254
return mult * E_out / (D * std::sqrt(E_cm * E_com));
4355
}
4456

src/tallies/next_event_scoring.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "openmc/tallies/next_event_scoring.h"
22

3+
#include <algorithm> // for clamp
4+
35
#include "openmc/secondary_uncorrelated.h"
46
#include "openmc/source.h"
57

@@ -14,11 +16,13 @@ void score_point_tally_elastic(
1416

1517
// Neutron velocity in LAB
1618
Direction v_n = std::sqrt(p.E()) * p.u();
19+
auto u_n = v_n / v_n.norm();
1720

1821
// Velocity of center-of-mass
1922
Direction v_cm = (v_n + awr * v_t) / (awr + 1.0);
2023
auto u_cm = v_cm / v_cm.norm();
2124

25+
double E_in = p.E();
2226
double E_com = v_cm.dot(v_cm);
2327
double E_out = (v_n - v_cm).dot(v_n - v_cm);
2428

@@ -27,11 +31,15 @@ void score_point_tally_elastic(
2731

2832
auto pdf = [&](Direction u, double& E) {
2933
double mu = u.dot(u_cm);
34+
double mu_l = u.dot(u_n);
3035
E = E_out;
3136
double jac =
3237
get_jac_and_transform_impl(E_com, mu, E, p.current_seed(), awr);
38+
double mu_cm =
39+
1.0 + mu_l * std::sqrt(E_in * E) / E_out - (E_in + E) / (2.0 * E_out);
40+
mu_cm = std::clamp(mu_cm, -1.0, 1.0);
3341
if (!d_->angle().empty()) {
34-
return jac * d_->angle().evaluate(p.E(), mu) / (2.0 * PI);
42+
return jac * d_->angle().evaluate(p.E(), mu_cm) / (2.0 * PI);
3543
} else {
3644
return jac * 0.5 / (2.0 * PI);
3745
}

0 commit comments

Comments
 (0)