-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfinal.py
More file actions
582 lines (525 loc) · 22.1 KB
/
final.py
File metadata and controls
582 lines (525 loc) · 22.1 KB
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
"""
A simple example of an animated plot... In 3D!
see sources in Monte function
TODO
-why is there a tendency to drift right?
-is there a way to make a sort of heatmap of flux on the surface plot?
-Make parameters enterable - Tkinter?
-writeup - include flux vs. distance, flux vs. number of particles, flux vs. isotropy factor
-write about the assumptions - uses standard monte carlo but also two-term Henyey-Greenstein phase functions
-how it differs from the 741
-real attenuation absorption scattering coeff.
"""
import numpy as np
import matplotlib.pyplot as plt
import mpl_toolkits.mplot3d.axes3d as p3
import matplotlib.animation as animation
from matplotlib import cm
from random import randint,random
from Tkinter import *
fields = ('mu_s (cm-1)', 'mu_a (cm-1)', 'Isotropy', 'Number Particles', 'World Size (cm)','Flux Width x (cm)','Flux Width y (cm)','Flux Distance z (cm)',
'Russian Roulette Factor','Initial E-Gamma (MeV)','Cutoff E-Gamma (MeV)','Flux v Distance Range (cm)','ALPHA')
def get_mu_a(e_gamma_0,mu_s):
MATCHER=[
( 1.00E-003 , 3.71E+003 ),
( 1.04E-003 , 3.39E+003 ),
( 1.07E-003 , 3.09E+003 ),
( 1.50E-003 , 1.25E+003 ),
( 2.00E-003 , 5.60E+002 ),
( 2.15E-003 , 4.58E+002 ),
( 2.30E-003 , 3.80E+002 ),
( 2.47E-003 , 3.10E+002 ),
( 2.64E-003 , 2.61E+002 ),
( 2.82E-003 , 2.16E+002 ),
( 3.00E-003 , 1.84E+002 ),
( 3.61E-003 , 1.07E+002 ),
( 4.00E-003 , 8.16E+001 ),
( 5.00E-003 , 4.22E+001 ),
( 6.00E-003 , 2.46E+001 ),
( 8.00E-003 , 1.04E+001 ),
( 1.00E-002 , 5.38E+000 ),
( 1.50E-002 , 1.70E+000 ),
( 2.00E-002 , 8.23E-001 ),
( 3.00E-002 , 3.79E-001 ),
( 4.00E-002 , 2.69E-001 ),
( 5.00E-002 , 2.26E-001 ),
( 6.00E-002 , 2.05E-001 ),
( 8.00E-002 , 1.82E-001 ),
( 1.00E-001 , 1.69E-001 ),
( 1.50E-001 , 1.49E-001 ),
( 2.00E-001 , 1.36E-001 ),
( 3.00E-001 , 1.18E-001 ),
( 4.00E-001 , 1.05E-001 ),
( 5.00E-001 , 9.60E-002 ),
( 6.00E-001 , 8.87E-002 ),
( 8.00E-001 , 7.79E-002 ),
( 1.00E+000 , 7.01E-002 ),
( 1.25E+000 , 6.27E-002 ),
( 1.50E+000 , 5.70E-002 ),
( 2.00E+000 , 4.90E-002 ),
( 3.00E+000 , 3.93E-002 ),
( 4.00E+000 , 3.37E-002 ),
( 5.00E+000 , 3.00E-002 ),
( 6.00E+000 , 2.74E-002 ),
( 8.00E+000 , 2.40E-002 ),
( 1.00E+001 , 2.19E-002 ),
( 1.50E+001 , 1.92E-002 ),
( 2.00E+001 , 1.79E-002 ),
]
for e,mu_s in MATCHER:
if e==e_gamma_0:
mu=mu_s
return mu
def runit(entries):
# period rate:
mu_s = float(entries['mu_s (cm-1)'].get())
mu_a = float(entries['mu_a (cm-1)'].get())
e_gamma_0 = float(entries['Initial E-Gamma (MeV)'].get())
mu_s=get_mu_a(e_gamma_0,mu_s)
num_particles = int(entries['Number Particles'].get())
fluxsurface_len_x = int(entries['Flux Width x (cm)'].get())
fluxsurface_len_y = int(entries['Flux Width y (cm)'].get())
flux_dist_from_src_z = float(entries['Flux Distance z (cm)'].get())
g = float(entries['Isotropy'].get())
lim = float(entries['World Size (cm)'].get())
m = float(entries['Russian Roulette Factor'].get())
lines_or_points=int(v0.get())
rand_init_dir=int(v1.get())
plot_flux_surface=int(v2.get())
sampling=v5.get()
cutoff_e = float(entries['Cutoff E-Gamma (MeV)'].get())
#alpha = float(entries['ALPHA'].get())
#print rand_init_dir,lines_or_points#mu_s,mu_a,g,num_particles,fluxsurface_len_x,fluxsurface_len_y,flux_dist_from_src_z,lim,lines_or_points
fig = plt.figure()
ax = p3.Axes3D(fig)
ax.set_xlim3d([-lim, lim])
ax.set_xlabel('X')
ax.set_ylim3d([-lim, lim])
ax.set_ylabel('Y')
ax.set_zlim3d([-lim, lim])
ax.set_zlabel('Z')
ax.set_title('3D Monte Carlo Walking')
#================
#Some I.C.s - parameters to modify
flux_surface_area = float(fluxsurface_len_x)*float(fluxsurface_len_y)
#absorption and scattering coefficients
#Following function does the bulk of the code - makes lines for the walking animation, OR determines particle flight distance and flux
def Monte(length, dims=6,g=0.0,mu_a=0.03,mu_s=0.3,e_gamma_0=5.0,rand_init_dir=False, lines_or_points=True,sampling='H'):
'''
from http://en.wikipedia.org/wiki/Monte_Carlo_method_for_photon_transport
AND
'Successive order, multiple scattering of two-term Henyey-Greenstein phase functions'
AND
Wang, Jaques MCML Monte Carlo method for light transport 1995
'''
e_gamma=e_gamma_0#MeV
mu_t = mu_a+mu_s
lineData = np.empty((dims, length))
#starting at origin
lineData[:, 0] = 0.0,0.0,0.0, 0,0,0 #x,y,z,#crossings,crossing_x,crossing_y
#INITIAL DIR
if rand_init_dir:
x_dir,y_dir,z_dir = randint(0,10),randint(0,10),randint(0,10)
mag = np.sqrt(x_dir**2+y_dir**2+z_dir**2)
#normalize
mu_x,mu_y,mu_z = x_dir/mag,y_dir/mag,z_dir/mag
else:
mu_x,mu_y,mu_z = 0.0,0.0,1.0
#START WALKING
single_p_crossing_factor=0
x_cross,y_cross=0,0
for index in range(1, length):
alpha = e_gamma/0.511
zeta1,zeta2,zeta3,zeta4=random(),random(),random(),random()
step_scalar = -np.log(zeta1)/mu_t
if (sampling == 'H') or (sampling == 'B'):
ct = (1/(2*g))*(1+g**2-((1-g**2)/(1-g+2*g*zeta2))**2) if g != 0 else 2*zeta2-1
elif sampling =='K':
while 1:#ang_diff_scat>zeta2: # if zeta2<ct, retain ct
#print ang_diff_scat
ct = -1 + 2*random()
trm1 = (1 + ct**2)/2.0
trm2 = 1.0/(1 + alpha*(1 - ct))
trm3 = 2*alpha**2*(1 - ct)**2*trm2/trm1
ang_diff_scat = trm1*trm2**2*(1 + trm3)
if ang_diff_scat<random():
break
phi = 2*np.pi*zeta3
theta = np.arccos(ct)
#print ct,theta
c = np.sqrt(1-mu_z**2)
st = np.sin(theta)
sp = np.sin(phi)
cp = np.cos(phi)
if mu_z >= 0.999:
mu_x,mu_y,mu_z = st*cp,st*sp,ct
elif mu_z <= -0.999:
mu_x,mu_y,mu_z = st*cp,-st*sp,-ct
else:
new_mu_x = (st/c)*(mu_x*mu_z*cp-mu_y*sp)+mu_x*ct
new_mu_y = (st/c)*(mu_y*mu_z*cp-mu_x*sp)+mu_y*ct
new_mu_z = -c*st*cp+mu_z*ct
mu_x,mu_y,mu_z = new_mu_x,new_mu_y,new_mu_z
#print mu_x,mu_y,mu_z,'----',mu_x**2+mu_y**2+mu_z**2 #(x and y 'directional cosines are >1, wtheck)
x,y,z = mu_x*step_scalar,mu_y*step_scalar,mu_z*step_scalar
old_z = lineData[2,index-1]
avg_x,avg_y = lineData[0,index-1]+x/2.0,lineData[1,index-1]+y/2.0
new_z = old_z+z
if ((-fluxsurface_len_x/2<avg_x<fluxsurface_len_x/2) and (-fluxsurface_len_y/2<avg_y<fluxsurface_len_y/2) and ((old_z < flux_dist_from_src_z and new_z > flux_dist_from_src_z) or (old_z > flux_dist_from_src_z and new_z < flux_dist_from_src_z))):
single_p_crossing_factor+=1*abs(1/np.dot([mu_x,mu_y,mu_z],[0,0,1])) #NOT THE ABSOLUTE VALUE, 'COMING BACK' WILL DECREASE THIS VALUE
x_cross,y_cross=lineData[0, index-1] + x,lineData[1, index-1] + y
#print old_z, new_z,'---',avg_x,avg_y,'---',mu_x,mu_y,mu_z#lineData[:, index]
step = x,y,z
#energy lost absorption
de = (mu_a/mu_t)*e_gamma
e_gamma=e_gamma-de
#PHOTON TERMINATION WITH RUSSIAN ROULETTE METHOD FOR ENDING PHOTON
#if zeta <(1/m), w=0. Else, w = initial weight
#m=40.0
if e_gamma<cutoff_e:
if zeta4 < (1.0/m):
e_gamma=m*e_gamma
#final = lineData[:, :index] #truncate the array
#print 'PHOTON DEAD', lineData[:, index]
lineData[:3, index] = lineData[:3, index-1] + step
lineData[3, index]=single_p_crossing_factor
lineData[4, index]=x_cross
lineData[5, index]=y_cross
else:
e_gamma=0#m*e_gamma
lineData[:3, index] = lineData[:3, index-1] + step
lineData[3, index]=single_p_crossing_factor
lineData[4, index]=x_cross
lineData[5, index]=y_cross
final = lineData[:, :index]
break
#final = lineData[:, :index]
#continue
else:
#e_gamma=1
lineData[:3, index] = lineData[:3, index-1] + step
lineData[3, index]=single_p_crossing_factor
lineData[4, index]=x_cross
lineData[5, index]=y_cross
final = lineData[:, :index]
#print lineData[:, index]
continue
return final if lines_or_points else final[:, -1]
#ADDING THIS MYSELF - plots stopping point (absorption points) for gamma and fluz surface===================
#total_crossing_factor_iso=0
#total_crossing_factor_aniso=0
if not lines_or_points:
total_crossing_factor=0
gx=[]
gy=[]
for j in range(num_particles):
#ptdata = [Monte(25, 6,0.33*index,mu_a,mu_s,w,False,False) for index in range(4)]#z-dir, 4 cases
#ptdata = [Monte(25, 6,0.99*index,mu_a,mu_s,w,False,False) for index in range(2)]#z-dir, 2 cases
#ptdata = [Monte(25, 6,0.33*index,mu_a,mu_s,w,False,False) for index in range(4)]#rand-dir, 4 cases
ptdata = [Monte(25, 6,g,mu_a,mu_s,e_gamma_0,rand_init_dir,lines_or_points,sampling) for index in range(1)]
for i,d in enumerate(ptdata):
total_crossing_factor = total_crossing_factor+d[3]
ax.scatter(d[0],d[1],d[2])#, c=color_dict[i])
#print 'd3 is the crossing factor',d[3]
flux = total_crossing_factor/(num_particles*flux_surface_area)
print flux, 'flux'
if plot_flux_surface:
x = np.arange(-fluxsurface_len_x/2, fluxsurface_len_x/2, 0.1)
y = np.arange(-fluxsurface_len_y/2, fluxsurface_len_y/2, 0.1)
X, Y = np.meshgrid(x, y)
zs = np.array([flux_dist_from_src_z for x,y in zip(np.ravel(X), np.ravel(Y))])
Z = zs.reshape(X.shape)
ax.plot_surface(X, Y, Z)
#The line 'walking' animation==================================
def update_lines(num, dataLines, lines) :
for line, data in zip(lines, dataLines):
# NOTE: there is no .set_data() for 3 dim data...
line.set_data(data[0:2, :num])
line.set_3d_properties(data[2,:num])
return 1
if lines_or_points:
# data for 4 'walks' (lines) of different anisotropy - 0,0.33,0.67,0.99
#data = [Monte(25, 6,0.33*index,mu_a,mu_s,w,False,True) for index in range(4)]#initial z-dir
data = [Monte(25, 6,g,mu_a,mu_s,e_gamma_0,rand_init_dir,True,sampling) for index in range(num_particles)]#rand-dir
# Creating line objects.
# NOTE: Can't pass empty arrays into 3d version of plot()
lines = [ax.plot(dat[0, 0:1], dat[1, 0:1], dat[2, 0:1])[0] for i,dat in enumerate(data)]#, label='g = %s'%(i*0.33))[0] for i,dat in enumerate(data)]
# Creating the Animation object 3rd param must match Gen_RandLine(length
#interval is how fast animation occurs
line_ani = animation.FuncAnimation(fig, update_lines, 25, fargs=(data, lines),interval=50, blit=False)
plt.legend()
plt.show()
def fluxit(entries):
# period rate:
mu_s = float(entries['mu_s (cm-1)'].get())
mu_a = float(entries['mu_a (cm-1)'].get())
e_gamma_0 = float(entries['Initial E-Gamma (MeV)'].get())
mu_s=get_mu_a(e_gamma_0,mu_s)
num_particles = int(entries['Number Particles'].get())
fluxsurface_len_x = int(entries['Flux Width x (cm)'].get())
fluxsurface_len_y = int(entries['Flux Width y (cm)'].get())
flux_dist_from_src_z = float(entries['Flux Distance z (cm)'].get())
g = float(entries['Isotropy'].get())
lim = float(entries['World Size (cm)'].get())
m = float(entries['Russian Roulette Factor'].get())
lines_or_points=int(v0.get())
rand_init_dir=int(v1.get())
plot_flux_surface=int(v2.get())
sampling=v5.get()
cutoff_e = float(entries['Cutoff E-Gamma (MeV)'].get())
#alpha = float(entries['ALPHA'].get())
fluxrange = int(entries['Flux v Distance Range (cm)'].get())
#print rand_init_dir,lines_or_points#mu_s,mu_a,g,num_particles,fluxsurface_len_x,fluxsurface_len_y,flux_dist_from_src_z,lim,lines_or_points
#fig = plt.figure()
fig, ax = plt.subplots()
'''
ax = p3.Axes3D(fig)
ax.set_xlim3d([-lim, lim])
ax.set_xlabel('X')
ax.set_ylim3d([-lim, lim])
ax.set_ylabel('Y')
ax.set_zlim3d([-lim, lim])
ax.set_zlabel('Z')
ax.set_title('Flux v D')
'''
#================
#Some I.C.s - parameters to modify
flux_surface_area = float(fluxsurface_len_x)*float(fluxsurface_len_y)
#absorption and scattering coefficients
#Following function does the bulk of the code - makes lines for the walking animation, OR determines particle flight distance and flux
def FluxMonte(length, dims=6,g=0.0,mu_a=0.03,mu_s=0.3,e_gamma_0=5.0,rand_init_dir=False, dis=1.0, sampling='H'):
'''
from http://en.wikipedia.org/wiki/Monte_Carlo_method_for_photon_transport
AND
'Successive order, multiple scattering of two-term Henyey-Greenstein phase functions'
AND
Wang, Jaques MCML Monte Carlo method for light transport 1995
'''
e_gamma=e_gamma_0#MeV
mu_t = mu_a+mu_s
lineData = np.empty((dims, length))
#starting at origin
lineData[:, 0] = 0.0,0.0,0.0, 0,0,0 #x,y,z,#crossings,crossing_x,crossing_y
#INITIAL DIR
if rand_init_dir:
x_dir,y_dir,z_dir = randint(0,10),randint(0,10),randint(0,10)
mag = np.sqrt(x_dir**2+y_dir**2+z_dir**2)
#normalize
mu_x,mu_y,mu_z = x_dir/mag,y_dir/mag,z_dir/mag
else:
mu_x,mu_y,mu_z = 0.0,0.0,1.0
#START WALKING
single_p_crossing_factor=0
x_cross,y_cross=0,0
for index in range(1, length):
alpha = e_gamma/0.511
zeta1,zeta2,zeta3,zeta4=random(),random(),random(),random()
step_scalar = -np.log(zeta1)/mu_t
if (sampling == 'H') or (sampling == 'B'):
ct = (1/(2*g))*(1+g**2-((1-g**2)/(1-g+2*g*zeta2))**2) if g != 0 else 2*zeta2-1
elif sampling =='K':
while 1:#ang_diff_scat>zeta2: # if zeta2<ct, retain ct
#print ang_diff_scat
ct = -1 + 2*random()
trm1 = (1 + ct**2)/2.0
trm2 = 1.0/(1 + alpha*(1 - ct))
trm3 = 2*alpha**2*(1 - ct)**2*trm2/trm1
ang_diff_scat = trm1*trm2**2*(1 + trm3)
if ang_diff_scat<random():
break
phi = 2*np.pi*zeta3
theta = np.arccos(ct)
#print ct,theta
c = np.sqrt(1-mu_z**2)
st = np.sin(theta)
sp = np.sin(phi)
cp = np.cos(phi)
if mu_z == 1:
mu_x,mu_y,mu_z = st*cp,st*sp,ct
elif mu_z == -1:
mu_x,mu_y,mu_z = st*cp,-st*sp,-ct
else:
new_mu_x = (st/c)*(mu_x*mu_z*cp-mu_y*sp)+mu_x*ct
new_mu_y = (st/c)*(mu_y*mu_z*cp-mu_x*sp)+mu_y*ct
new_mu_z = -c*st*cp+mu_z*ct
mu_x,mu_y,mu_z = new_mu_x,new_mu_y,new_mu_z
#print mu_x,mu_y,mu_z,'----',mu_x**2+mu_y**2+mu_z**2 #(x and y 'directional cosines are >1, wtheck)
x,y,z = mu_x*step_scalar,mu_y*step_scalar,mu_z*step_scalar
old_z = lineData[2,index-1]
avg_x,avg_y = lineData[0,index-1]+x/2.0,lineData[1,index-1]+y/2.0
new_z = old_z+z
if ((-fluxsurface_len_x/2<avg_x<fluxsurface_len_x/2) and (-fluxsurface_len_y/2<avg_y<fluxsurface_len_y/2) and ((old_z < dis and new_z > dis) or (old_z > dis and new_z < dis))):
single_p_crossing_factor+=1*abs(1/np.dot([mu_x,mu_y,mu_z],[0,0,1])) #NOT THE ABSOLUTE VALUE, 'COMING BACK' WILL DECREASE THIS VALUE
x_cross,y_cross=lineData[0, index-1] + x,lineData[1, index-1] + y
#print old_z, new_z,'---',avg_x,avg_y,'---',mu_x,mu_y,mu_z#lineData[:, index]
step = x,y,z
#energy lost absorption
de = (mu_a/mu_t)*e_gamma
e_gamma=e_gamma-de
#PHOTON TERMINATION WITH RUSSIAN ROULETTE METHOD FOR ENDING PHOTON
#if zeta <(1/m), w=0. Else, w = initial weight
#m=40.0
if e_gamma<cutoff_e:
if zeta4 < (1.0/m):
e_gamma=m*e_gamma
#final = lineData[:, :index] #truncate the array
#print 'PHOTON DEAD', lineData[:, index]
lineData[:3, index] = lineData[:3, index-1] + step
lineData[3, index]=single_p_crossing_factor
lineData[4, index]=x_cross
lineData[5, index]=y_cross
else:
e_gamma=0#m*e_gamma
lineData[:3, index] = lineData[:3, index-1] + step
lineData[3, index]=single_p_crossing_factor
lineData[4, index]=x_cross
lineData[5, index]=y_cross
final = lineData[:, :index]
break
#final = lineData[:, :index]
#continue
else:
#e_gamma=1
lineData[:3, index] = lineData[:3, index-1] + step
lineData[3, index]=single_p_crossing_factor
lineData[4, index]=x_cross
lineData[5, index]=y_cross
final = lineData[:, :index]
#print lineData[:, index]
continue
return final[:, -1]
#ADDING THIS MYSELF - plots stopping point (absorption points) for gamma and fluz surface===================
#total_crossing_factor_iso=0
#total_crossing_factor_aniso=0
to_plot=[]
if sampling == 'B':
to_plot = ['H','K']
if sampling == 'H':
to_plot = ['H']
if sampling == 'K':
to_plot = ['K']
for p in to_plot:
dis_a=[]
flux_a=[]
for dis in range(fluxrange*4):
dis = dis/4.0
total_crossing_factor=0
gx=[]
gy=[]
for j in range(num_particles):
#ptdata = [Monte(25, 6,0.33*index,mu_a,mu_s,w,False,False) for index in range(4)]#z-dir, 4 cases
#ptdata = [Monte(25, 6,0.99*index,mu_a,mu_s,w,False,False) for index in range(2)]#z-dir, 2 cases
#ptdata = [Monte(25, 6,0.33*index,mu_a,mu_s,w,False,False) for index in range(4)]#rand-dir, 4 cases
ptdata = [FluxMonte(25, 6,g,mu_a,mu_s,e_gamma_0,rand_init_dir,dis,p) for index in range(1)]
for i,d in enumerate(ptdata):
total_crossing_factor = total_crossing_factor+d[3]
#ax.scatter(d[0],d[1],d[2])#, c=color_dict[i])
#print 'd3 is the crossing factor',d[3]
flux = total_crossing_factor/(num_particles*flux_surface_area)
#print 'dis',dis,'flux', flux
dis_a.append(dis)
flux_a.append(flux)
plt.plot(dis_a,flux_a,label=p)
ax.set_xlabel('Distance (cm)')
ax.set_ylabel('Scalar Flux')
ax.set_title('Scalar Flux v Distance')
plt.legend()
plt.show()
def makeform(root, fields):
entries = {}
for field in fields:
#print field
row = Frame(root)
lab = Label(row, width=22, text=field+": ", anchor='w')
ent = Entry(row)
if field == 'mu_s (cm-1)':
ent.insert(0,"0.16")
elif field =='mu_a (cm-1)':
ent.insert(0,"0.38")
elif field == 'Number Particles':
ent.insert(0,"500")
elif field == 'Isotropy':
ent.insert(0,"0.8")
elif field == 'World Size (cm)':
ent.insert(0,"40")
elif field == 'Flux Width x (cm)':
ent.insert(0,"1")
elif field == 'Flux Width y (cm)':
ent.insert(0,"1")
elif field == 'Flux Distance z (cm)':
ent.insert(0,"4")
elif field == 'Russian Roulette Factor':
ent.insert(0,"1.4")
elif field =='Cutoff E-Gamma (MeV)':
ent.insert(0,"0.03")
elif field == 'Initial E-Gamma (MeV)':
ent.insert(0,"1.25")
elif field == 'Flux v Distance Range (cm)':
ent.insert(0,"5")
elif field == 'ALPHA':
ent.insert(0,"2.0")
row.pack(side=TOP, fill=X, padx=5, pady=5)
lab.pack(side=LEFT)
ent.pack(side=RIGHT, expand=YES, fill=X)
entries[field] = ent
return entries
if __name__ == '__main__':
root = Tk()
ents = makeform(root, fields)
#walk or flux
MODES0 = [
("Walking Animation", "1"),
("Flux Scatter Plot", "0"),
]
v0 = StringVar()
v0.set("0") # initialize
for text, mode in MODES0:
b0 = Radiobutton(root, text=text,
variable=v0, value=mode)
b0.pack(anchor=W)
#initial direction
MODES1 = [
("Random Init Dir", "1"),
("Z-Directed", "0"),
]
v1 = StringVar()
v1.set("0") # initialize
for text, mode in MODES1:
b1 = Radiobutton(root, text=text,
variable=v1, value=mode)
b1.pack(anchor=E)
#plot flux surface??
MODES2 = [
("Plot Flux Surface", "1"),
("Don't Plot Flux Surface", "0"),
]
v2 = StringVar()
v2.set("0") # initialize
for text, mode in MODES2:
b2 = Radiobutton(root, text=text,
variable=v2, value=mode)
b2.pack(anchor=W)
#plot flux surface??
MODES5 = [
("Klein Nishina", "K"),
("Henyey Greenstein", "H"),
("Both (Compare - only for flux v distance)", "B"),
]
v5 = StringVar()
v5.set("H") # initialize
for text, mode in MODES5:
b5 = Radiobutton(root, text=text,
variable=v5, value=mode)
b5.pack(anchor=E)
#root.bind('<Flux v D>', (lambda event, e=ents: fetch(e)))
root.bind('<Return>', (lambda event, e=ents: fetch(e)))
b2 = Button(root, text='3d Visual',
command=(lambda e=ents: runit(e)))
b2.pack(side=LEFT, padx=5, pady=5)
b4 = Button(root, text='Flux v Distance',
command=(lambda e=ents: fluxit(e)))
b4.pack(side=LEFT, padx=5, pady=5)
b3 = Button(root, text='Quit', command=root.quit)
b3.pack(side=LEFT, padx=5, pady=5)
#Tkinter radio buttons
root.mainloop()