-
Notifications
You must be signed in to change notification settings - Fork 0
/
MC Plotly (Cylindrical Assembly) (While Loop).py
executable file
·915 lines (690 loc) · 31.7 KB
/
MC Plotly (Cylindrical Assembly) (While Loop).py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
from plotly.offline import init_notebook_mode
import plotly.graph_objs as go
import plotly as py
import plotly.tools as tls
import Cross_Section_Loading
import numpy as np
import pandas as pd
init_notebook_mode(connected=True)
# Wishlist (In order): Reflector, Control Rods, Source Rods, Full-Core, Concurrency
# Fission Products (Will Account for Delayed Neutrons) & Life (Will yield n(t))
# k-inf on generation > 1 needs check
def energy_lookup(data_set, inp_energy):
"""look up energy in a data set and return the nearest energy in the table
Input:
data_set: a vector of energies
inp_energy: the energy to lookup
Output:
index: the index of the nearest neighbor in the table
"""
# argmin returns the indices of the smallest members of an array
# here we’ll look for the minimum difference between the input energy and the table
index = np.argmin(np.fabs(np.array(data_set)-inp_energy))
return index
##################################################################
FUEL_PIN_RADIUS = .5
HEIGHT = 100
PITCH = 3
# assert(PITCH >= 2 * FUEL_PIN_RADIUS)
ENRICHMENT_1 = .03
ENRICHMENT_2 = .05
ENRICHMENT_3 = .07
ASSEMBLY = [[1, 1, 1, 1, 1, 1, 1, 3, 3], # Quarter Section
[1, 1, 1, 1, 1, 1, 1, 3, 3],
[1, 1, 2, 2, 2, 2, 2, 3, 3],
[1, 1, 2, 1, 1, 1, 2, 3, 3],
[1, 1, 2, 1, 1, 1, 2, 3, 3],
[1, 1, 2, 1, 1, 1, 2, 3, 3],
[1, 1, 2, 2, 2, 2, 2, 3, 3],
[3, 3, 3, 3, 3, 3, 3, 3, 3],
[3, 3, 3, 3, 3, 3, 3, 3, 3]]
# # Leakage Test
# ASSEMBLY = [[3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3], # Quarter Section
# [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],
# [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],
# [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],
# [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],
# [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],
# [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],
# [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],
# [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],
# [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],
# [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],
# [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],
# [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],
# [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]]
##################################################################
print("For 17 x 17 assembly, 9 x 9 is needed. Your shape:", np.shape(ASSEMBLY))
X_DIM = np.shape(ASSEMBLY)[1]
Y_DIM = np.shape(ASSEMBLY)[0]
X_BOUNDARY = X_DIM * PITCH
Y_BOUNDARY = Y_DIM * PITCH
centers_x = []
centers_y = []
centers_z = []
fuel_type = []
data = []
for i in range(X_DIM):
for j in range(Y_DIM):
if ASSEMBLY[j][i] != 0:
u = np.linspace(0, 2*np.pi, 50)
# Cylinders (#'s denote quadrant)
x_1 = FUEL_PIN_RADIUS * np.outer(np.ones(np.size(u)), np.cos(u)) + PITCH * i
y_1 = FUEL_PIN_RADIUS * np.outer(np.ones(np.size(u)), np.sin(u)) + PITCH * j
z_1 = np.outer(np.linspace(0, HEIGHT, np.size(u)), np.ones(np.size(u)))
x_2 = FUEL_PIN_RADIUS * np.outer(np.ones(np.size(u)), np.cos(u)) + PITCH * -i
y_2 = FUEL_PIN_RADIUS * np.outer(np.ones(np.size(u)), np.sin(u)) + PITCH * j
z_2 = np.outer(np.linspace(0, HEIGHT, np.size(u)), np.ones(np.size(u)))
x_3 = FUEL_PIN_RADIUS * np.outer(np.ones(np.size(u)), np.cos(u)) + PITCH * i
y_3 = FUEL_PIN_RADIUS * np.outer(np.ones(np.size(u)), np.sin(u)) + PITCH * -j
z_3 = np.outer(np.linspace(0, HEIGHT, np.size(u)), np.ones(np.size(u)))
x_4 = FUEL_PIN_RADIUS * np.outer(np.ones(np.size(u)), np.cos(u)) + PITCH * -i
y_4 = FUEL_PIN_RADIUS * np.outer(np.ones(np.size(u)), np.sin(u)) + PITCH * -j
z_4 = np.outer(np.linspace(0, HEIGHT, np.size(u)), np.ones(np.size(u)))
# ['Blackbody', 'Bluered', 'Blues', 'Earth', 'Electric', 'Greens', 'Greys', 'Hot', 'Jet', 'Picnic', 'Portland', 'Rainbow', 'RdBu', 'Reds', 'Viridis', 'YlGnBu', 'YlOrRd']
lateral_surface_1 = go.Surface(x=x_1,
y=y_1,
z=z_1,
colorscale='Greys',
surfacecolor=np.ones(np.size(u)),
opacity=.25,
)
lateral_surface_2 = go.Surface(x=x_2,
y=y_2,
z=z_2,
colorscale='Greys',
surfacecolor=np.ones(np.size(u)),
opacity=.25,
)
lateral_surface_3 = go.Surface(x=x_3,
y=y_3,
z=z_3,
colorscale='Greys',
surfacecolor=np.ones(np.size(u)),
opacity=.25,
)
lateral_surface_4 = go.Surface(x=x_4,
y=y_4,
z=z_4,
colorscale='Greys',
surfacecolor=np.ones(np.size(u)),
opacity=.25,
)
centers_x.append(PITCH * i)
centers_y.append(PITCH * j)
centers_z.append(HEIGHT)
fuel_type.append(ASSEMBLY[j][i])
centers_x.append(PITCH * -i)
centers_y.append(PITCH * j)
centers_z.append(HEIGHT)
fuel_type.append(ASSEMBLY[j][i])
centers_x.append(PITCH * i)
centers_y.append(PITCH * -j)
centers_z.append(HEIGHT)
fuel_type.append(ASSEMBLY[j][i])
centers_x.append(PITCH * -i)
centers_y.append(PITCH * -j)
centers_z.append(HEIGHT)
fuel_type.append(ASSEMBLY[j][i])
data.append(lateral_surface_1)
data.append(lateral_surface_2)
data.append(lateral_surface_3)
data.append(lateral_surface_4)
centers = go.Scatter3d(x=centers_x,
y=centers_y,
z=centers_z,
mode='markers',
marker=dict(
size=5,
))
# data.append(centers)
##################################################################
# Remove Duplicates
assert (len(centers_x) == len(centers_y))
pre_dup_list = []
rem_dup_list = []
for a in range(len(centers_x)):
pre_dup_list.append((centers_x[a], centers_y[a]))
for tup in pre_dup_list:
if tup not in rem_dup_list:
rem_dup_list.append(tup)
centers_x = []
centers_y = []
for tup in rem_dup_list:
centers_x.append(tup[0])
centers_y.append(tup[1])
##################################################################
def material_type(x, y):
assert(len(centers_x) == len(centers_y))
for a in range(len(centers_x)):
# Define domain of r for each pin center
r_domain = np.sqrt((x - centers_x[a])**2 + (y - centers_y[a])**2)
# See if x and y are in fuel pin
if r_domain <= FUEL_PIN_RADIUS:
return fuel_type[a]
return False
##################################################################
# Load Cross-Sections
E = Cross_Section_Loading.E
# Uranium 238 Cross-sections
U238_scattering = Cross_Section_Loading.UnionElasticU238
U238_absorption = Cross_Section_Loading.UnionGammaU238
U238_fission = Cross_Section_Loading.UnionFissionU238
U238_gamma = Cross_Section_Loading.UnionGammaU238
U238_total = Cross_Section_Loading.UnionTotalU238
U238_nu = Cross_Section_Loading.UnionNuU238
# Uranium 235 Cross-sections
U235_scattering = Cross_Section_Loading.UnionElasticU235
U235_absorption = Cross_Section_Loading.UnionGammaU235
U235_fission = Cross_Section_Loading.UnionFissionU235
U235_gamma = Cross_Section_Loading.UnionGammaU235
U235_total = Cross_Section_Loading.UnionTotalU235
U235_nu = Cross_Section_Loading.UnionNuU235
# Hydrogen & Oxygen Cross-Sections
hydrogen_scattering = Cross_Section_Loading.UnionElasticH1
hydrogen_absorption = Cross_Section_Loading.UnionGammaH1
hydrogen_gamma = Cross_Section_Loading.UnionGammaH1
hydrogen_total = Cross_Section_Loading.UnionTotalH1
oxygen_scattering = Cross_Section_Loading.UnionElasticO16
oxygen_absorption = Cross_Section_Loading.UnionGammaO16
oxygen_gamma = Cross_Section_Loading.UnionGammaO16
oxygen_total = Cross_Section_Loading.UnionTotalO16
##################################################################
A_fuel = 238 # Needs Effective Atomic Number?
DENSITY_FUEL = 10.97
A_mod = 7.42 # Effective Atomic Number
DENSITY_MOD = 1
N_mod = DENSITY_MOD / A_mod * 6.022e23 * 1e-24
N_H_mod = N_mod * 2 # Number of atoms per molecule (2)
N_O_mod = N_mod * 1 # Number of atoms per molecule (1)
alpha_fuel = (A_fuel - 1.0) ** 2 / (A_fuel + 1.0) ** 2
alpha_mod = (A_mod - 1.0) ** 2 / (A_mod + 1.0) ** 2
# Fuel Macroscopic Cross-Sections
def sigma_total_fuel(enrich):
N_U235 = enrich * DENSITY_FUEL * (6.022e23 * 1e-24)/235.0439
N_U238 = (1 - enrich) * DENSITY_FUEL * (6.022e23 * 1e-24)/238.0508
N_O16 = (N_U235 + N_U238) * 2
return N_U235 * U235_total + N_U238 * U238_total + N_O16 * oxygen_total
def sigma_scatter_fuel(enrich):
N_U235 = enrich * DENSITY_FUEL * (6.022e23 * 1e-24)/235.0439
N_U238 = (1 - enrich) * DENSITY_FUEL * (6.022e23 * 1e-24)/238.0508
N_O16 = (N_U235 + N_U238) * 2
return N_U235 * U235_scattering + N_U238 * U238_scattering + N_O16 * oxygen_scattering
def sigma_capture_fuel(enrich):
N_U235 = enrich * DENSITY_FUEL * (6.022e23 * 1e-24)/235.0439
N_U238 = (1 - enrich) * DENSITY_FUEL * (6.022e23 * 1e-24)/238.0508
N_O16 = (N_U235 + N_U238) * 2
return N_U235 * U235_gamma + N_U238 * U238_gamma + N_O16 * oxygen_gamma
def sigma_absorb_fuel(enrich):
N_U235 = enrich * DENSITY_FUEL * (6.022e23 * 1e-24)/235.0439
N_U238 = (1 - enrich) * DENSITY_FUEL * (6.022e23 * 1e-24)/238.0508
N_O16 = (N_U235 + N_U238) * 2
return N_U235 * U235_absorption + N_U238 * U238_absorption + N_O16 * oxygen_absorption
def sigma_fission_fuel(enrich):
N_U235 = enrich * DENSITY_FUEL * (6.022e23 * 1e-24)/235.0439
N_U238 = (1 - enrich) * DENSITY_FUEL * (6.022e23 * 1e-24)/238.0508
return N_U235 * U235_fission + N_U238 * U238_fission
def nu_fuel(enrich):
return enrich * U235_nu + (1 - enrich) * U238_nu
# Moderator Macroscopic Cross-Sections
sigma_total_mod = N_O_mod * oxygen_total + N_H_mod * hydrogen_total
sigma_scatter_mod = N_O_mod * oxygen_scattering + N_H_mod * hydrogen_scattering
sigma_capture_mod = N_O_mod * oxygen_gamma + N_H_mod * hydrogen_gamma
##################################################################
# get distance to interface from inside fuel pin
# Come up with alternative to Ridder function EDIT HERE
def distance_to_edge(x, y, phi):
intersect_list = []
for a in range(len(centers_x)):
# Construct Line Equation
m = np.tan(phi)
c = y - x * m
# Line-Circle Intersection is Quadratic
A = m ** 2 + 1
B = m * c - m * centers_x[a] - centers_y[a]
C = centers_y[a] ** 2 - FUEL_PIN_RADIUS ** 2 + centers_x[a] ** 2 - 2 * c * centers_y[a] + c ** 2
# Determine number of intersections and roots
# if B**2 - 4*A*C < 0:
# print("No Intersection")
# print(rem_dup_list[a])
#
# if B**2 - 4*A*C == 0:
# print("One Intersection")
# print(rem_dup_list[a])
# In this case there are two intersections
if B**2 - 4*A*C > 0:
# print("Two Intersections")
# Two quadratic results (x)
x_intersect1 = (-B + np.sqrt(B**2 - 4*A*C))/(2*A)
x_intersect2 = (-B - np.sqrt(B**2 - 4*A*C))/(2*A)
# # Two quadratic results (y)
y_intersect1 = x_intersect1*np.tan(phi) + c
y_intersect2 = x_intersect2*np.tan(phi) + c
tup1 = (x_intersect1, y_intersect1)
tup2 = (x_intersect2, y_intersect2)
# If neutron is going "up" in the x-y plane of the assembly
if phi < np.pi:
if y_intersect1 > y:
if not np.isnan(tup1[0]):
intersect_list.append(tup1)
if y_intersect2 > y:
if not np.isnan(tup2[0]):
intersect_list.append(tup2)
# If neutron is going "down" in the x-y plane of the assembly
else:
if y_intersect1 < y:
if not np.isnan(tup1[0]):
intersect_list.append(tup1)
if y_intersect2 < y:
if not np.isnan(tup2[0]):
intersect_list.append(tup2)
d_vec = []
for a in range(len(intersect_list)):
# Find distance from neutron origin to circle intersection
d = np.sqrt((x - intersect_list[a][0]) ** 2 + (y - intersect_list[a][1]) ** 2)
d_vec.append(float(d))
# Take closest distance
if len(d_vec) > 0:
# print(np.min(d_vec))
return np.min(d_vec)
if len(d_vec) == 0:
# should I return something else?
return 'no-interface'
##################################################################
def particle_func(x, y, z):
nu = 0
death_eng = 0
death_loc = 0
death_type = 0
# get initial direction
theta = np.random.uniform(0, np.pi, 1)
phi = np.random.uniform(0, 2 * np.pi, 1)
# compute energy via rejection sampling
expfiss = lambda e: 0.453 * np.exp(-1.036 * e / 1.0e6) * np.sinh(np.sqrt(2.29 * e / 1.0e6))
min_eng = np.min(E)
max_eng = np.max(E)
max_prob = np.max(expfiss(E))
thermal_boundary = 0.0253
# Energy in eV's
rejected = 1
while rejected:
a = np.random.uniform(min_eng, max_eng, 1)
b = np.random.uniform(0, max_prob, 1)
rel_prob = expfiss(a)
if b <= rel_prob:
energy = a
rejected = 0
alive = 1
# vector to keep track of positions
xvec = np.ones(1) * x
yvec = np.ones(1) * y
zvec = np.ones(1) * z
time_alive = 0
while alive:
# Get real/new cross-sections for corresponding energy
index = energy_lookup(E, energy)
interacted = 0
total_distance = 0
# Interacted may still be alive (scattering)
while interacted == 0:
###################################################
# Determine starting location for sample distance using sigma_total
material_start = material_type(x, y)
if material_start == 1:
sig_tot = sigma_total_fuel(ENRICHMENT_1)[index]
elif material_start == 2:
sig_tot = sigma_total_fuel(ENRICHMENT_2)[index]
elif material_start == 3:
sig_tot = sigma_total_fuel(ENRICHMENT_3)[index]
else:
sig_tot = sigma_total_mod[index]
###################################################
if material_start == 1 or material_start == 2 or material_start == 3: # if in fuel pin
# Get distance to edge of fuel rod (from fuel)
d = distance_to_edge(x, y, phi)
# get sample distance to collision
s = -np.log(1.0 - np.random.random(1)) / sig_tot
# Incidence on interface (denoted by code "no-interface")
if d != 'no-interface':
# Sample distance is greater than interface distance (does not account for material change)
# Must convert between 2D and 3D
if s * np.sin(theta) > d:
total_distance += d / np.sin(theta)
# Sample distance is correct and interaction occurs
else:
total_distance += s
interacted = 1
# Statement may be redundant but idk how to handle return from distance_to_rod
else:
total_distance += s
interacted = 1
else: # if in moderator
# get distance to edge of fuel rod (from moderator)
d = distance_to_edge(x, y, phi)
# get distance to collision
s = -np.log(1.0 - np.random.random(1)) / sig_tot
# Incidence on interface (denoted by code "no-interface")
if d != 'no-interface':
# Sample distance is greater than interface distance (does not account for material change)
# Must convert between 2D and 3D
if s * np.sin(theta) > d:
total_distance += d / np.sin(theta) # <- Right conversion?
# Sample distance is correct and interaction occurs
else:
total_distance += s
interacted = 1
# Statement may be redundant but idk how to handle return from distance_to_rod
else:
total_distance += s
interacted = 1
# move particle
z += total_distance * np.cos(theta)
y += total_distance * np.sin(theta) * np.sin(phi)
x += total_distance * np.sin(theta) * np.cos(phi)
# energy to velocity of neutron [eV -> J; m_neutron; meter -> cm]
velocity = np.sqrt(2*energy * 1.60218e-19/1.674929e-27) * 100
time_alive += total_distance / velocity
# material_end = material_type(x, y)
#
# if material_start != material_end:
# print("Neutron has crossed material interface(s)")
# Trace/Track particle movement
xvec = np.append(xvec, x)
yvec = np.append(yvec, y)
zvec = np.append(zvec, z)
# Get Particle Travel/Life Time
###################################################
# Leakage
if x > X_BOUNDARY or x < -X_BOUNDARY or y > Y_BOUNDARY or y < -Y_BOUNDARY or z > HEIGHT or z < 0:
alive = 0
death_type = 'leak'
if energy < thermal_boundary:
death_eng = 'thermal'
else:
death_eng = 'fast'
###################################################
# Determine Type of interaction based on energy and corresponding cross-sections
# In fuel
material = material_type(x, y)
if material == 1:
sig_scat_temp = sigma_scatter_fuel(ENRICHMENT_1)[index]
sig_abs_temp = sigma_absorb_fuel(ENRICHMENT_1)[index]
sig_fiss_temp = sigma_fission_fuel(ENRICHMENT_1)[index]
sig_tot_temp = sigma_total_fuel(ENRICHMENT_1)[index]
nu_temp = nu_fuel(ENRICHMENT_1)[index]
# Scatter
if np.random.random(1) < sig_scat_temp / sig_tot_temp:
# scatter, pick new angles & energy
theta = np.random.uniform(0, np.pi, 1)
phi = np.random.uniform(0, 2 * np.pi, 1)
energy = np.random.uniform(alpha_fuel * energy, energy, 1)
elif np.random.random(1) < sig_abs_temp / sig_tot_temp:
# Fission
if np.random.random(1) < sig_fiss_temp / sig_abs_temp:
# Determine number of neutrons produced from fission (round/int?)
nu = int(round(nu_temp))
alive = 0
death_type = 'fission'
# Randomly determine Fission Products:
# Pick FP-1 with yield as probability
# FP-2 Mass = Target - (FP-1 Mass + nu)
# U-238 target probability = N_U-238 / (N_U-235 + N_U-238) if incident neutron is fast
# [cross-sections in play?]
# Otherwise target is U-235
# No Fission
else:
alive = 0
death_type = 'absorption'
death_loc = 'fuel'
if energy < thermal_boundary:
death_eng = 'thermal'
else:
death_eng = 'fast'
#############################
elif material == 2:
sig_scat_temp = sigma_scatter_fuel(ENRICHMENT_2)[index]
sig_abs_temp = sigma_absorb_fuel(ENRICHMENT_2)[index]
sig_fiss_temp = sigma_fission_fuel(ENRICHMENT_2)[index]
sig_tot_temp = sigma_total_fuel(ENRICHMENT_2)[index]
nu_temp = nu_fuel(ENRICHMENT_2)[index]
# Scatter
if np.random.random(1) < sig_scat_temp / sig_tot_temp:
# scatter, pick new angles & energy
theta = np.random.uniform(0, np.pi, 1)
phi = np.random.uniform(0, 2 * np.pi, 1)
energy = np.random.uniform(alpha_fuel * energy, energy, 1)
elif np.random.random(1) < sig_abs_temp / sig_tot_temp:
# Fission
if np.random.random(1) < sig_fiss_temp / sig_abs_temp:
# Determine number of neutrons produced from fission (round/int?)
nu = int(round(nu_temp))
alive = 0
death_type = 'fission'
# Randomly determine Fission products according to nu
# No Fission
else:
alive = 0
death_type = 'absorption'
death_loc = 'fuel'
if energy < thermal_boundary:
death_eng = 'thermal'
else:
death_eng = 'fast'
#############################
if material == 3:
sig_scat_temp = sigma_scatter_fuel(ENRICHMENT_3)[index]
sig_abs_temp = sigma_absorb_fuel(ENRICHMENT_3)[index]
sig_fiss_temp = sigma_fission_fuel(ENRICHMENT_3)[index]
sig_tot_temp = sigma_total_fuel(ENRICHMENT_3)[index]
nu_temp = nu_fuel(ENRICHMENT_3)[index]
# Scatter
if np.random.random(1) < sig_scat_temp / sig_tot_temp:
# scatter, pick new angles & energy
theta = np.random.uniform(0, np.pi, 1)
phi = np.random.uniform(0, 2 * np.pi, 1)
energy = np.random.uniform(alpha_fuel * energy, energy, 1)
elif np.random.random(1) < sig_abs_temp / sig_tot_temp:
# Fission
if np.random.random(1) < sig_fiss_temp / sig_abs_temp:
# Determine number of neutrons produced from fission (round/int?)
nu = int(round(nu_temp))
alive = 0
death_type = 'fission'
# Randomly determine Fission products according to nu
# No Fission
else:
alive = 0
death_type = 'absorption'
death_loc = 'fuel'
if energy < thermal_boundary:
death_eng = 'thermal'
else:
death_eng = 'fast'
#############################
# In water
else:
mod_scat = sigma_scatter_mod[index]
mod_tot = sigma_total_mod[index]
# Scatter
if np.random.random(1) < mod_scat / mod_tot:
# scatter, pick new angles & energy
theta = np.random.uniform(0, np.pi, 1)
phi = np.random.uniform(0, 2 * np.pi, 1)
energy = np.random.uniform(alpha_mod * energy, energy, 1)
else:
# absorbed
alive = 0
death_type = 'absorption'
death_loc = 'mod'
###################################################
death_fate = [death_loc, death_eng, death_type, time_alive]
print('time alive:', time_alive)
return xvec, yvec, zvec, nu, death_fate
##################################################################
# for i in pyprind.prog_bar(range(N), track_time=True, monitor=True, bar_char='█', width=50,):
N = 500
while N > 0:
##########################
gen_count = 0
thermal_leaked = 0
fast_leaked = 0
thermal_absorbed_fuel = 0
fast_absorbed_fuel = 0
thermal_absorbed_mod = 0
fast_absorbed_mod = 0
thermal_fission = 0
fast_fission = 0
thermal_produced = 0
fast_produced = 0
##########################
for i in range(N):
###################################################
# Uniformly Dispersed Source (Cylinder)
# x = np.random.uniform(-X_BOUNDARY, X_BOUNDARY, 1)
# y = np.random.uniform(-Y_BOUNDARY, Y_BOUNDARY, 1)
# z = np.random.uniform(-HEIGHT, HEIGHT, 1)
# Uniformly Dispersed FUEL Source (Cylinder)
rejected = 1
while rejected:
x = np.random.uniform(-X_BOUNDARY, X_BOUNDARY, 1)
y = np.random.uniform(-Y_BOUNDARY, Y_BOUNDARY, 1)
z = np.random.uniform(-HEIGHT, HEIGHT, 1)
if material_type(x, y):
rejected = 0
###################################################
# Get normal particle info (trace)
x_vec, y_vec, z_vec, nu, fate = particle_func(x, y, z)
###############################################
gen_count += nu
if fate[2] == 'leak':
if fate[0] == 'thermal':
thermal_leaked += 1
if fate[1] == 'fast':
fast_leaked += 1
if fate[0] == 'fuel' and fate[1] == 'thermal':
thermal_absorbed_fuel += 1
if fate[2] == 'fission':
thermal_fission += 1
thermal_produced += nu
if fate[0] == 'fuel' and fate[1] == 'fast':
fast_absorbed_fuel += 1
if fate[2] == 'fission':
fast_fission += 1
fast_produced += nu
if fate[0] == 'mod' and fate[1] == 'thermal':
thermal_absorbed_mod += 1
if fate[0] == 'mod' and fate[1] == 'fast':
fast_absorbed_mod += 1
###############################################
particle_trace = go.Scatter3d(
x=x_vec,
y=y_vec,
z=z_vec,
mode='lines',
line=dict(color='rgb(173, 255, 47)')
)
data.append(particle_trace)
###################################################
nu_vec = [nu]
x_vecs = [x_vec]
y_vecs = [y_vec]
z_vecs = [z_vec]
if nu > 0:
print("{} neutrons generated for neutron {}".format(nu, i))
else:
print("No neutrons generated for neutron {}".format(i + 1))
t = 0
recent_nus = nu_vec
while np.any(recent_nus) != 0:
print(nu_vec[-t:])
tracker = 0
nu_vec_temp = []
x_vecs_temp = []
y_vecs_temp = []
z_vecs_temp = []
for a in range(len(nu_vec[-t:])):
x = x_vecs[-(a + 1)][-1]
y = y_vecs[-(a + 1)][-1]
z = z_vecs[-(a + 1)][-1]
for j in range(nu_vec[-(a + 1)]):
x_vec, y_vec, z_vec, nu, fate = particle_func(x, y, z)
###############################################
gen_count += nu
if fate[2] == 'leak':
if fate[0] == 'thermal':
thermal_leaked += 1
if fate[1] == 'fast':
fast_leaked += 1
if fate[0] == 'fuel' and fate[1] == 'thermal':
thermal_absorbed_fuel += 1
if fate[2] == 'fission':
thermal_fission += 1
thermal_produced += nu
if fate[0] == 'fuel' and fate[1] == 'fast':
fast_absorbed_fuel += 1
if fate[2] == 'fission':
fast_fission += 1
fast_produced += nu
if fate[0] == 'mod' and fate[1] == 'thermal':
thermal_absorbed_mod += 1
if fate[0] == 'mod' and fate[1] == 'fast':
fast_absorbed_mod += 1
###############################################
print("Particle {} starting coords:".format(j + 1), x_vec[0], y_vec[0], z_vec[0])
print("Particle {} ending coords:".format(j + 1), x_vec[-1], y_vec[-1], z_vec[-1])
print("Particle {} nu value".format(j + 1), nu)
nu_vec_temp.append(nu)
tracker += 1
x_vecs_temp.append(x_vec)
y_vecs_temp.append(y_vec)
z_vecs_temp.append(z_vec)
# time.sleep(1)
particle_trace = go.Scatter3d(
x=x_vec,
y=y_vec,
z=z_vec,
mode='lines',
line=dict(color='rgb(255, 0, 0)')
)
data.append(particle_trace)
print()
t = tracker
nu_vec.extend(nu_vec_temp)
x_vecs.extend(x_vecs_temp)
y_vecs.extend(y_vecs_temp)
z_vecs.extend(z_vecs_temp)
recent_nus = nu_vec_temp
print("Continuing fission:", (np.any(recent_nus) != 0))
##################################################################
Eta_T = thermal_produced / thermal_absorbed_fuel
Eta_F = fast_produced / fast_absorbed_fuel
u_F = fast_absorbed_fuel / (fast_absorbed_fuel + fast_absorbed_mod)
f_T = thermal_absorbed_fuel / (thermal_absorbed_fuel + fast_absorbed_fuel)
p = (thermal_absorbed_fuel + thermal_absorbed_mod + thermal_leaked) / (thermal_absorbed_fuel + fast_absorbed_fuel + thermal_absorbed_mod + fast_absorbed_mod + thermal_leaked)
epsilon_inf = 1 + (1-p) * u_F * Eta_F / (p * f_T * Eta_T)
k_inf = epsilon_inf * Eta_T * f_T * p
P_FNL = (fast_absorbed_fuel + fast_absorbed_mod) / (fast_absorbed_fuel + fast_absorbed_mod + fast_leaked)
P_TNL = (thermal_absorbed_fuel + thermal_absorbed_mod) / (thermal_absorbed_fuel + thermal_absorbed_mod + thermal_leaked)
k_eff = k_inf*P_FNL*P_TNL
print("\nTotal number of neutrons left in system:", N + gen_count - (thermal_leaked + fast_leaked) -
(thermal_absorbed_fuel + thermal_absorbed_mod) - (fast_absorbed_fuel + fast_absorbed_mod))
print("Total number of neutrons generated from {} neutron source: {}".format(N, gen_count))
print("Total number of leaked neutrons:", (thermal_leaked + fast_leaked))
print("Infinite Medium System Multiplication factor (4 factor):", k_inf)
print("Effective System Multiplication factor (6 factor):", k_eff)
# Cant be right (Neutrons left in system)
N = N + gen_count - (thermal_leaked + fast_leaked) - \
(thermal_absorbed_fuel + thermal_absorbed_mod) - (fast_absorbed_fuel + fast_absorbed_mod)
layout = go.Layout(
title='Monte Carlo Assembly',
autosize=True,
showlegend=False,
height=1000,
width=1000,
scene=dict(zaxis=dict(range=[-1, HEIGHT + 1]),
yaxis=dict(range=[-(Y_DIM * PITCH + 5), (Y_DIM * PITCH + 5)]),
xaxis=dict(range=[-(X_DIM * PITCH + 5), (X_DIM * PITCH + 5)])
),
)
fig = go.Figure(data=data, layout=layout)
# py.offline.plot(fig, filename='file.html')