Skip to content

Commit c0713fb

Browse files
committed
fix3
1 parent 7a7d412 commit c0713fb

6 files changed

Lines changed: 94 additions & 95 deletions

File tree

src/photon.cpp

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,11 @@ void PhotonInteraction::compton_doppler(
503503
}
504504

505505
// Sample value on bounded cdf
506-
c = prn(seed) * c_max;
506+
if (pz_max > 0.0) {
507+
c = prn(seed) * c_max;
508+
} else {
509+
c = 1.0 + (c_max - 1.0) * prn(seed);
510+
}
507511

508512
// Determine pz corresponding to sampled cdf value
509513
tensor::View<const double> cdf_shell = profile_cdf_.slice(shell);
@@ -528,29 +532,24 @@ void PhotonInteraction::compton_doppler(
528532
double momentum_sq = std::pow((pz / FINE_STRUCTURE), 2);
529533
double f = 1.0 + alpha * (1.0 - mu);
530534
double a = momentum_sq - f * f;
531-
double b = 2.0 * E * (f - momentum_sq * mu);
532-
c = E * E * (momentum_sq - 1.0);
533-
534-
double quad = std::sqrt(b * b - 4.0 * a * c);
535-
double E_out1 = -(b + quad) / (2.0 * a);
536-
double E_out2 = -(b - quad) / (2.0 * a);
537-
538-
// Determine solution to quadratic equation that is positive
539-
if (E_out1 > 0.0) {
540-
if (E_out2 > 0.0) {
541-
// If both are positive, pick one at random
542-
*E_out = prn(seed) < 0.5 ? E_out1 : E_out2;
543-
} else {
544-
*E_out = E_out1;
545-
}
546-
} else {
547-
if (E_out2 > 0.0) {
548-
*E_out = E_out2;
549-
} else {
550-
// No positive solution -- resample
551-
continue;
552-
}
535+
double b = 2.0 * (f - momentum_sq * mu);
536+
c = (momentum_sq - 1.0);
537+
double quad = b * b - 4.0 * a * c;
538+
if (quad < 0) {
539+
write_message("Negative quad {}", quad);
540+
continue;
553541
}
542+
quad = std::sqrt(quad);
543+
double E_out1 = -(b + quad) / (2.0 * a) * E;
544+
double E_out2 = -(b - quad) / (2.0 * a) * E;
545+
// Determine solution to quadratic equation that is positive and minimal
546+
if ((E_out1 < 0.0) && (E_out2 < 0.0))
547+
continue;
548+
if ((E_out1 > 0.0) && (E_out2 > 0.0))
549+
*E_out = std::min(E_out1, E_out2);
550+
else
551+
*E_out = std::max(E_out1, E_out2);
552+
554553
if (prn(seed) * E <= *E_out)
555554
break;
556555
}
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
tally 1:
2-
1.967531E+00
3-
3.871180E+00
4-
7.966753E+04
5-
6.346915E+09
2+
1.920387E+00
3+
3.687888E+00
4+
7.854617E+04
5+
6.169501E+09
66
0.000000E+00
77
0.000000E+00
8-
9.203325E+05
9-
8.470119E+11
8+
9.214538E+05
9+
8.490772E+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.520000E-01
5-
9.063040E-01
4+
9.493000E-01
5+
9.011705E-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.337965E-01
20-
5.466081E-02
19+
2.362831E-01
20+
5.582969E-02
2121
0.000000E+00
2222
0.000000E+00
23-
2.337965E-01
24-
5.466081E-02
23+
2.362831E-01
24+
5.582969E-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.253000E-01
57-
5.076009E-02
58-
4.053867E+00
59-
1.643384E+01
56+
2.344000E-01
57+
5.494336E-02
58+
4.593008E+00
59+
2.109572E+01
6060
0.000000E+00
6161
0.000000E+00
62-
2.253000E-01
63-
5.076009E-02
64-
4.053867E+00
65-
1.643384E+01
62+
2.344000E-01
63+
5.494336E-02
64+
4.593008E+00
65+
2.109572E+01
6666
0.000000E+00
6767
0.000000E+00
6868
0.000000E+00
6969
0.000000E+00
70-
1.762738E+05
71-
3.107245E+10
70+
1.792949E+05
71+
3.214667E+10
7272
0.000000E+00
7373
0.000000E+00
7474
0.000000E+00
7575
0.000000E+00
76-
1.762738E+05
77-
3.107245E+10
76+
1.792949E+05
77+
3.214667E+10
7878
0.000000E+00
7979
0.000000E+00
8080
0.000000E+00
8181
0.000000E+00
82-
1.438891E+04
83-
2.070408E+08
82+
1.452085E+04
83+
2.108550E+08
8484
0.000000E+00
8585
0.000000E+00
8686
0.000000E+00
8787
0.000000E+00
88-
1.438891E+04
89-
2.070408E+08
88+
1.452085E+04
89+
2.108550E+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.253000E-01
106-
5.076009E-02
107-
4.053867E+00
108-
1.643384E+01
105+
2.344000E-01
106+
5.494336E-02
107+
4.593008E+00
108+
2.109572E+01
109109
0.000000E+00
110110
0.000000E+00
111-
2.253000E-01
112-
5.076009E-02
113-
4.053867E+00
114-
1.643384E+01
111+
2.344000E-01
112+
5.494336E-02
113+
4.593008E+00
114+
2.109572E+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.762738E+05
126-
3.107245E+10
125+
1.792949E+05
126+
3.214667E+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.438891E+04
138-
2.070408E+08
137+
1.452085E+04
138+
2.108550E+08
139139
0.000000E+00
140140
0.000000E+00
141141
tally 5:
Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
k-combined:
2-
2.313118E+00 2.756443E-02
2+
2.255088E+00 7.363219E-02
33
tally 1:
4-
2.710112E+00
5-
2.448973E+00
4+
2.640439E+00
5+
2.329186E+00
66
0.000000E+00
77
0.000000E+00
8-
2.710112E+00
9-
2.448973E+00
8+
2.640439E+00
9+
2.329186E+00
1010
0.000000E+00
1111
0.000000E+00
1212
0.000000E+00
@@ -18,52 +18,52 @@ tally 1:
1818
0.000000E+00
1919
0.000000E+00
2020
tally 2:
21-
2.689726E+00
22-
2.411702E+00
23-
4.310507E+08
24-
6.193986E+16
21+
2.625521E+00
22+
2.303289E+00
23+
4.210498E+08
24+
5.923082E+16
2525
0.000000E+00
2626
0.000000E+00
27-
2.689726E+00
28-
2.411702E+00
29-
4.310507E+08
30-
6.193986E+16
27+
2.625521E+00
28+
2.303289E+00
29+
4.210498E+08
30+
5.923082E+16
3131
0.000000E+00
3232
0.000000E+00
3333
0.000000E+00
3434
0.000000E+00
35-
1.698053E+05
36-
9.611469E+09
35+
1.826906E+05
36+
1.114925E+10
3737
0.000000E+00
3838
0.000000E+00
3939
0.000000E+00
4040
0.000000E+00
41-
1.698053E+05
42-
9.611469E+09
41+
1.826906E+05
42+
1.114925E+10
4343
0.000000E+00
4444
0.000000E+00
4545
tally 3:
46-
2.658739E+00
47-
2.356315E+00
48-
4.310507E+08
49-
6.193986E+16
46+
2.658439E+00
47+
2.355784E+00
48+
4.210498E+08
49+
5.923082E+16
5050
0.000000E+00
5151
0.000000E+00
52-
2.658739E+00
53-
2.356315E+00
54-
4.310507E+08
55-
6.193986E+16
52+
2.658439E+00
53+
2.355784E+00
54+
4.210498E+08
55+
5.923082E+16
5656
0.000000E+00
5757
0.000000E+00
5858
0.000000E+00
5959
0.000000E+00
60-
1.698053E+05
61-
9.611469E+09
60+
1.826906E+05
61+
1.114925E+10
6262
0.000000E+00
6363
0.000000E+00
6464
0.000000E+00
6565
0.000000E+00
66-
1.698053E+05
67-
9.611469E+09
66+
1.826906E+05
67+
1.114925E+10
6868
0.000000E+00
6969
0.000000E+00
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
tally 1:
2-
2.275725E+02
3-
5.178926E+04
2+
2.193647E+02
3+
4.812086E+04
44
0.000000E+00
55
0.000000E+00
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
c4d56d4eb3e4d10f9238d34f909f950227a99b262c04ae0afc78f9c2e0a2c07139b88461c4b4c62ed24803c59419183fecc405b6155f553c00be454d632144a2
1+
bb3b76ee105f20bc9eb763fd04753f6212ab0139197f5be03b927769ac4f45efa77dd22cdf48900062c3eaa8874f463bef11c0dd52321ba8f6da2c12c98247b7

0 commit comments

Comments
 (0)