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
|
#!/usr/bin/python3
#ADD COMMENT
#ADD COMMENT
#ADD COMMENT
import sys
import glob
import os
import numpy as np
import matplotlib.pyplot as plt
import yt
#Physical parameters
um = 1.e-6
fs = 1.e-15
c = 299792458
#Parameters of the gaussian beam
wavelength = 1.*um
w0 = 6.*um
tt = 10.*fs
x_c = 0.*um
t_c = 20.*fs
foc_dist = 10*um
E_max = 1e12
#Parameters of the tx grid
x_l = -12.0*um
x_r = 12.0*um
x_points = 480
t_l = 0.0*fs
t_r = 40.0*fs
t_points = 400
tcoords = np.linspace(t_l, t_r, t_points)
xcoords = np.linspace(x_l, x_r, x_points)
def gauss(T,X,Y,opt):
k0 = 2.0*np.pi/wavelength
inv_tau2 = 1./tt/tt
osc_phase = k0*c*(T-t_c)
diff_factor = 1.0 + 1.0j* foc_dist * 2/(k0*w0*w0)
inv_w_2 = 1.0/(w0*w0*diff_factor)
pre_fact = np.exp(1.0j * osc_phase)
if opt == '3d':
pre_fact = pre_fact/diff_factor
else:
pre_fact = pre_fact/np.sqrt(diff_factor)
exp_arg = - (X*X + Y*Y)*inv_w_2 - inv_tau2 * (T-t_c)*(T-t_c)
return np.real(pre_fact * np.exp(exp_arg))
def write_file(fname, x, y, t, E):
with open(fname, 'wb') as file:
flag_unif = 0
file.write(flag_unif.to_bytes(1, byteorder='little'))
file.write((len(t)).to_bytes(4, byteorder='little', signed=False))
file.write((len(x)).to_bytes(4, byteorder='little', signed=False))
file.write((len(y)).to_bytes(4, byteorder='little', signed=False))
file.write(t.tobytes())
file.write(x.tobytes())
file.write(y.tobytes())
file.write(E.tobytes())
def write_file_unf(fname, x, y, t, E):
with open(fname, 'wb') as file:
flag_unif = 1
file.write(flag_unif.to_bytes(1, byteorder='little'))
file.write((len(t)).to_bytes(4, byteorder='little', signed=False))
file.write((len(x)).to_bytes(4, byteorder='little', signed=False))
file.write((len(y)).to_bytes(4, byteorder='little', signed=False))
file.write(t[0].tobytes())
file.write(t[-1].tobytes())
file.write(x[0].tobytes())
file.write(x[-1].tobytes())
file.write(y[0].tobytes())
file.write(y[-1].tobytes())
file.write(E.tobytes())
def create_gaussian_2d():
T, X, Y = np.meshgrid(tcoords, xcoords, np.array([0.0]), indexing='ij')
E_t = gauss(T,X,Y,'2d')
write_file("gauss_2d.txye", xcoords, np.array([0.0]), tcoords, E_t)
write_file_unf("gauss_2d_unf.txye", xcoords, np.array([0.0]), tcoords, E_t)
def do_analysis(fname):
data_set_end = yt.load(fname)
sim_time = data_set_end.current_time.to_value()
ray0 = data_set_end.ray((0*um,0*um,0), (15*um, 15*um,0))
xx0 = np.array(ray0["t"])*np.sqrt(2)*15*um
EE0 = np.array(ray0["Ey"])/E_max
expected0 = [-gauss((sim_time)-x/c , 0, 0, '2d') for x in xx0]
#DEBUG
plt.plot(xx0,EE0,'bo')
plt.plot(xx0,expected0,'ro')
plt.savefig('graph.png')
#__DEBUG__
return True
def launch_analysis(executable):
create_gaussian_2d()
os.system("./" + executable + " inputs.2d_test_txye")
assert(do_analysis("diags/plotfiles/plt00507/"))
os.system("sed -i 's/gauss_2d_unf.txye/gauss_2d.txye/g' inputs.2d_test_txye")
os.system("./" + executable + " inputs.2d_test_txye")
assert(do_analysis("diags/plotfiles/plt00507/"))
def main() :
executables = glob.glob("main2d*")
if len(executables) == 1 :
launch_analysis(executables[0])
else :
assert(False)
if __name__ == "__main__":
main()
|