Skip to content

Commit d943dca

Browse files
committed
fix
1 parent 02277b5 commit d943dca

7 files changed

Lines changed: 108 additions & 123 deletions

File tree

include/openmc/photon.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class PhotonInteraction {
8787
tensor::Tensor<double> profile_pdf_;
8888
tensor::Tensor<double> profile_cdf_;
8989
tensor::Tensor<double> binding_energy_;
90-
tensor::Tensor<double> electron_cdf_;
90+
tensor::Tensor<double> electron_pdf_;
9191

9292
// Map subshells from Compton profile data obtained from Biggs et al,
9393
// "Hartree-Fock Compton profiles for the elements" to ENDF/B atomic

src/photon.cpp

Lines changed: 35 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -214,13 +214,8 @@ PhotonInteraction::PhotonInteraction(hid_t group)
214214
rgroup = open_group(group, "compton_profiles");
215215

216216
// Read electron shell PDF and binding energies
217-
tensor::Tensor<double> electron_pdf;
218-
read_dataset(rgroup, "num_electrons", electron_pdf);
219-
electron_pdf /= electron_pdf.sum();
220-
electron_cdf_ = tensor::Tensor<double>(electron_pdf.shape());
221-
electron_cdf_(0) = electron_pdf(0);
222-
for (int i = 1; i < electron_pdf.shape()[0]; ++i)
223-
electron_cdf_(i) = electron_cdf_(i - 1) + electron_pdf(i);
217+
read_dataset(rgroup, "num_electrons", electron_pdf_);
218+
electron_pdf_ /= electron_pdf_.sum();
224219
read_dataset(rgroup, "binding_energy", binding_energy_);
225220

226221
// Read Compton profiles
@@ -428,25 +423,13 @@ void PhotonInteraction::compton_scatter(double alpha, bool doppler,
428423
int last_shell = binding_energy_.shape()[0] - 1;
429424
double E_b = binding_energy_(last_shell);
430425
double E = alpha * MASS_ELECTRON_EV;
431-
double mu_max = 1 - E_b / (alpha * (E - E_b));
426+
if (E < E_b)
427+
fatal_error("Cannot eject any electron");
432428

433429
while (true) {
434430
// Sample Klein-Nishina distribution for trial energy and angle
435431
std::tie(*alpha_out, *mu) = klein_nishina(alpha, seed);
436432

437-
// If in every angle we cannot eject an electron
438-
// Exit with no shell
439-
if (mu_max < -1) {
440-
*i_shell = -1;
441-
return;
442-
}
443-
444-
if (doppler) {
445-
// Reject angles that cannot eject the most loosely bound electron
446-
if (*mu > mu_max)
447-
continue;
448-
}
449-
450433
// Note that the parameter used here does not correspond exactly to the
451434
// momentum transfer q in ENDF-102 Eq. (27.2). Rather, this is the
452435
// parameter as defined by Hubbell, where the actual data comes from
@@ -478,42 +461,37 @@ void PhotonInteraction::compton_doppler(
478461
double alpha, double mu, double* E_out, int* i_shell, uint64_t* seed) const
479462
{
480463
auto n = data::compton_profile_pz.size();
481-
double E = alpha * MASS_ELECTRON_EV;
482-
int j_shell = 0;
483-
for (double E_b : binding_energy_) {
484-
if ((E_b - (E - E_b) * alpha * (1.0 - mu)) < 0.0)
485-
break;
486-
++j_shell;
487-
}
488-
489-
double offset = 0.0;
490-
if (j_shell > 0)
491-
offset = electron_cdf_(j_shell - 1);
492464

493465
int shell; // index for shell
494466
while (true) {
495467
// Sample electron shell
496-
double rn = offset + prn(seed) * (1.0 - offset);
497-
double c;
498-
for (shell = j_shell; shell < electron_cdf_.size(); ++shell) {
499-
c = electron_cdf_(shell);
468+
double rn = prn(seed);
469+
double c = 0.0;
470+
for (shell = 0; shell < electron_pdf_.size(); ++shell) {
471+
c += electron_pdf_(shell);
500472
if (rn < c)
501473
break;
502474
}
475+
double E = alpha * MASS_ELECTRON_EV;
503476

504477
// Determine binding energy of shell
505478
double E_b = binding_energy_(shell);
506479

507-
// Determine p_z,max
480+
// Resample if photon energy insufficient
481+
if (E < E_b)
482+
continue;
483+
508484
double pz_max = -FINE_STRUCTURE * (E_b - (E - E_b) * alpha * (1.0 - mu)) /
509485
std::sqrt(2.0 * E * (E - E_b) * (1.0 - mu) + E_b * E_b);
486+
510487
// Determine profile cdf value corresponding to p_z,max
511488
double c_max;
512-
if (pz_max > data::compton_profile_pz(n - 1)) {
489+
if (std::abs(pz_max) > data::compton_profile_pz(n - 1)) {
490+
// TODO: handle linear extrapolation in lin-log scales
513491
c_max = profile_cdf_(shell, n - 1);
514492
} else {
515493
int i = lower_bound_index(data::compton_profile_pz.cbegin(),
516-
data::compton_profile_pz.cend(), pz_max);
494+
data::compton_profile_pz.cend(), std::abs(pz_max));
517495
double pz_l = data::compton_profile_pz(i);
518496
double pz_r = data::compton_profile_pz(i + 1);
519497
double p_l = profile_pdf_(shell, i);
@@ -522,10 +500,11 @@ void PhotonInteraction::compton_doppler(
522500
if (pz_l == pz_r) {
523501
c_max = c_l;
524502
} else if (p_l == p_r) {
525-
c_max = c_l + (pz_max - pz_l) * p_l;
503+
c_max = c_l + (std::abs(pz_max) - pz_l) * p_l;
526504
} else {
527505
double m = (p_l - p_r) / (pz_l - pz_r);
528-
c_max = c_l + (std::pow((m * (pz_max - pz_l) + p_l), 2) - p_l * p_l) /
506+
c_max = c_l + (std::pow((m * (std::abs(pz_max) - pz_l) + p_l), 2) -
507+
p_l * p_l) /
529508
(2.0 * m);
530509
}
531510
}
@@ -561,22 +540,28 @@ void PhotonInteraction::compton_doppler(
561540

562541
double quad = b * b - 4.0 * a * c;
563542
if (quad < 0)
564-
continue;
543+
fatal_error("Cannot doppler broaden.");
565544
quad = std::sqrt(quad);
566545
double E_out1 = -(b + quad) / (2.0 * a);
567546
double E_out2 = -(b - quad) / (2.0 * a);
568547

569-
// If no positive solution -- resample
570-
if (std::max(E_out1, E_out2) < 0)
571-
continue;
572-
573548
// Determine solution to quadratic equation that is positive
574-
if ((E_out1 > 0.0) && (E_out2 > 0.0)) {
575-
*E_out = prn(seed) < 0.5 ? E_out1 : E_out2;
549+
if (E_out1 > 0.0) {
550+
if (E_out2 > 0.0) {
551+
// If both are positive, pick one at random
552+
*E_out = prn(seed) < 0.5 ? E_out1 : E_out2;
553+
} else {
554+
*E_out = E_out1;
555+
}
576556
} else {
577-
*E_out = std::max(E_out1, E_out2);
557+
if (E_out2 > 0.0) {
558+
*E_out = E_out2;
559+
} else {
560+
// No positive solution -- resample
561+
continue;
562+
}
578563
}
579-
if (*E_out < E - E_b)
564+
if (prn(seed) * E <= *E_out)
580565
break;
581566
}
582567

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
tally 1:
2-
1.955720E+00
3-
3.824843E+00
4-
7.895341E+04
5-
6.233641E+09
2+
1.967531E+00
3+
3.871180E+00
4+
7.966753E+04
5+
6.346915E+09
66
0.000000E+00
77
0.000000E+00
8-
9.210466E+05
9-
8.483268E+11
8+
9.203325E+05
9+
8.470119E+11

tests/regression_tests/photon_production/results_true.dat

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
tally 1:
22
8.610000E-01
33
7.413210E-01
4-
9.489000E-01
5-
9.004112E-01
4+
9.520000E-01
5+
9.063040E-01
66
0.000000E+00
77
0.000000E+00
88
0.000000E+00
@@ -16,12 +16,12 @@ tally 2:
1616
1.573004E+00
1717
4.296434E-04
1818
1.845934E-07
19-
2.342279E-01
20-
5.486270E-02
19+
2.337965E-01
20+
5.466081E-02
2121
0.000000E+00
2222
0.000000E+00
23-
2.342279E-01
24-
5.486270E-02
23+
2.337965E-01
24+
5.466081E-02
2525
0.000000E+00
2626
0.000000E+00
2727
0.000000E+00
@@ -53,40 +53,40 @@ tally 3:
5353
4.104374E+12
5454
4.296582E-04
5555
1.846062E-07
56-
2.294000E-01
57-
5.262436E-02
58-
4.488894E+00
59-
2.015017E+01
56+
2.253000E-01
57+
5.076009E-02
58+
4.053867E+00
59+
1.643384E+01
6060
0.000000E+00
6161
0.000000E+00
62-
2.294000E-01
63-
5.262436E-02
64-
4.488894E+00
65-
2.015017E+01
62+
2.253000E-01
63+
5.076009E-02
64+
4.053867E+00
65+
1.643384E+01
6666
0.000000E+00
6767
0.000000E+00
6868
0.000000E+00
6969
0.000000E+00
70-
1.774550E+05
71-
3.149027E+10
70+
1.762738E+05
71+
3.107245E+10
7272
0.000000E+00
7373
0.000000E+00
7474
0.000000E+00
7575
0.000000E+00
76-
1.774550E+05
77-
3.149027E+10
76+
1.762738E+05
77+
3.107245E+10
7878
0.000000E+00
7979
0.000000E+00
8080
0.000000E+00
8181
0.000000E+00
82-
1.474427E+04
83-
2.173936E+08
82+
1.438891E+04
83+
2.070408E+08
8484
0.000000E+00
8585
0.000000E+00
8686
0.000000E+00
8787
0.000000E+00
88-
1.474427E+04
89-
2.173936E+08
88+
1.438891E+04
89+
2.070408E+08
9090
0.000000E+00
9191
0.000000E+00
9292
tally 4:
@@ -102,16 +102,16 @@ tally 4:
102102
4.104374E+12
103103
0.000000E+00
104104
0.000000E+00
105-
2.294000E-01
106-
5.262436E-02
107-
4.488894E+00
108-
2.015017E+01
105+
2.253000E-01
106+
5.076009E-02
107+
4.053867E+00
108+
1.643384E+01
109109
0.000000E+00
110110
0.000000E+00
111-
2.294000E-01
112-
5.262436E-02
113-
4.488894E+00
114-
2.015017E+01
111+
2.253000E-01
112+
5.076009E-02
113+
4.053867E+00
114+
1.643384E+01
115115
0.000000E+00
116116
0.000000E+00
117117
0.000000E+00
@@ -122,8 +122,8 @@ tally 4:
122122
0.000000E+00
123123
0.000000E+00
124124
0.000000E+00
125-
1.774550E+05
126-
3.149027E+10
125+
1.762738E+05
126+
3.107245E+10
127127
0.000000E+00
128128
0.000000E+00
129129
0.000000E+00
@@ -134,8 +134,8 @@ tally 4:
134134
0.000000E+00
135135
0.000000E+00
136136
0.000000E+00
137-
1.474427E+04
138-
2.173936E+08
137+
1.438891E+04
138+
2.070408E+08
139139
0.000000E+00
140140
0.000000E+00
141141
tally 5:

0 commit comments

Comments
 (0)