2 import matplotlib.pyplot
as plt
12 for i
in range(len(tem)):
13 if tem[i]<0: tem[i]+=2*np.pi
17 if author ==
'WomersleySym':
18 if not glob.glob(
'PointDistFiles/sphdesigns/WomersleySym/ss%03d.*'%t):
20 coord = np.loadtxt(glob.glob(
'PointDistFiles/sphdesigns/WomersleySym/ss%03d.*'%t)[0])
21 elif author ==
'WomersleyNonSym':
22 if not glob.glob(
'PointDistFiles/sphdesigns/WomersleyNonSym/sf%03d.*'%t):
24 coord = np.loadtxt(glob.glob(
'PointDistFiles/sphdesigns/WomersleyNonSym/sf%03d.*'%t)[0])
26 if not glob.glob(
'PointDistFiles/sphdesigns/HardinSloane/hs%03.*.txt'%t):
28 coord = np.loadtxt(sorted(glob.glob(
'PointDistFiles/sphdesigns/HardinSloane/hs%03d.txt'%t))[0])
29 xx = coord[:,0]; yy = coord[:,1]; zz = coord[:,2]
34 for (i,x)
in enumerate(phi):
35 I += func(theta[i],phi[i],**kwargs)
40 (x_sample, w) = np.polynomial.legendre.leggauss(N)
42 x_sample = (x_up-x_low)*x_sample/2 + (x_up + x_low)/2
44 for (i,x)
in enumerate(x_sample):
45 I += w[i]*func(x, **kwargs)
46 I = (x_up-x_low)/2 * I
51 x_sample = np.linspace(x_low,x_up,N)
53 for (i,x)
in enumerate(x_sample):
54 f[i] = func(x, **kwargs)
55 I = np.trapz(f,x_sample)
61 def func_sphere(phi,theta,**kwargs):
return func(phi,theta,**kwargs)*np.sin(phi)
64 N=M,x_low=0,x_up=2*pi)
69 with open(fname)
as f:
70 for i, l
in enumerate(f):
80 if scheme==
"Gauss_Legendre":
82 elif scheme==
"t-design":
86 print(
"Scheme: "+scheme+
" datafile: "+file_name)
95 tem=list(map(float,line.split(
', ')))
103 print(
"timesteps: "+
str(tstep))
110 tem=list(map(float,line.split(
', ')))
111 if (
not tem[1]==ID1)
or (
not tem[2]==ID2)
and (
not tem[6]==0):
112 ID1=tem[1]; ID2=tem[2]
114 coor=[tem[3],tem[4],tem[5]]
117 coors=np.array(coors)
118 print(
"valid tracers: "+
str(len(coors)))
121 data_set=np.zeros((N_tracer,tstep,7))
127 tem=list(map(float,line.split(
', ')))
128 if (tem[1]==ID1)
and (tem[2]==ID2):
129 data_set[N_count][t_count][0]=tem[0];
130 data_set[N_count][t_count][1]=tem[3]; data_set[N_count][t_count][2]=tem[4]; data_set[N_count][t_count][3]=tem[5]
131 data_set[N_count][t_count][4]=tem[6]; data_set[N_count][t_count][5]=tem[7]
134 ID1=tem[1]; ID2=tem[2]
137 data_set[N_count][t_count][0]=tem[0];
138 data_set[N_count][t_count][1]=tem[3]; data_set[N_count][t_count][2]=tem[4]; data_set[N_count][t_count][3]=tem[5]
139 data_set[N_count][t_count][4]=tem[6]; data_set[N_count][t_count][5]=tem[7]
145 if scheme==
"Gauss_Legendre":
146 (thetas,ws)= np.polynomial.legendre.leggauss(20)
147 zs=np.cos(np.pi*thetas/2 + np.pi/2)*0.4
148 zip_iterator=zip(zs,ws)
149 w_dict=dict(zip_iterator)
153 for n
in range(N_tracer):
155 if abs(data_set[n][0][3]-z)<1e-4:
156 data_set[n,:,6]=w_dict[z]
160 elif scheme==
"t-design":
161 for n
in range(N_tracer):
170 for t
in range(tstep):
171 for n
in range(N_tracer):
172 x=data_set[n][t][1]; y=data_set[n][t][2]; z=data_set[n][t][3];
173 p4re=data_set[n][t][4]; p4im=data_set[n][t][5]
175 sintheta=(x**2+y**2)**0.5/(x**2+y**2+z**2)**0.5; costheta=z/(x**2+y**2+z**2)**0.5;
176 if x**2+y**2==0: x+=1e-6;
177 sinphi=y/(x**2+y**2)**0.5; cosphi=x/(x**2+y**2)**0.5
178 cos2phi=2*cosphi**2-1; sin2phi=2*sinphi*cosphi
180 if l_mode==2
and m_mode==2:
181 data_set[n][t][4]=(p4re*cos2phi-p4im*sin2phi)*(1+costheta)**2*(5/64/np.pi)**0.5
182 data_set[n][t][5]=(p4re*sin2phi-p4im*cos2phi)*(1+costheta)**2*(5/64/np.pi)**0.5
184 if scheme==
"Gauss_Legendre":
185 data_set[n][t][4]*=sintheta;
186 data_set[n][t][5]*=sintheta;
190 ModeRe=np.zeros(tstep)
191 ModeIm=np.zeros(tstep)
192 if scheme==
"Gauss_Legendre":
193 for t
in range(tstep):
194 for n
in range(N_tracer):
195 w=(1.0/40)*(2*np.pi)*data_set[n][t][6]*(np.pi/2.0)
196 x=data_set[n][t][1]; y=data_set[n][t][2]; z=data_set[n][t][3];
197 ModeRe[t]+=w*data_set[n][t][4]
200 ModeIm[t]+=w*data_set[n][t][5]
201 elif scheme==
"t-design":
202 for t
in range(tstep):
203 for n
in range(N_tracer):
204 w=(1.0/N_tracer)*(4*np.pi)
205 ModeRe[t]+=w*data_set[n][t][4]
208 ModeIm[t]+=w*data_set[n][t][5]
212 print(ModeRe/4/np.pi)
213 print(ModeIm/4/np.pi)
224 print("z coors number: "+str(len(zz))+" "+str(zz))
227 print(z3,len(z[z==z3]))
231 plt.figure(figsize=(10,10),dpi=80)
234 plt.plot(p[0],p[1],'o',color='blue')
241 t_list=np.array(range(tnum))
249 #(I,N)=sph_design(f,21,author='WomersleySym')
253 for (i,t) in enumerate(t_list):
254 (I_num[i],N_num[i])=sph_design(f,t,author='WomersleySym')
256 I_num=I_num[~np.isnan(N_num)]
257 N_num=N_num[~np.isnan(N_num)]
258 #print(arctan2_2pi([1,1,-1,-1],[1,-1,-1,1])/np.pi)
262 #plt.plot(N_num,abs(I_num-I_exa)/I_exa)
266 print(prod_quad(f,10,20)*4*pi-I_exa)
def trapezoidal(func, N=40, x_low=0, x_up=pi, **kwargs)
Gauss 1D integration.
def gauss_legendre(func, N=40, x_low=0, x_up=pi, **kwargs)
Gauss-Legendre 1D integration.
def prod_quad(func, N=20, M=40, **kwargs)
Gaussian product quadrature using Trapezoidal for azimuthal direction and Gauss-Legendre for polar an...
def sph_design(func, t=5, author='Hardin', **kwargs)