-
Notifications
You must be signed in to change notification settings - Fork 0
/
HI_radia_equation_numsolving1.py
470 lines (375 loc) · 20.1 KB
/
HI_radia_equation_numsolving1.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
# 程序名:有限差分法解hosing+radiation耦合方程组2.0版本,加上额外项
# 作者:刘玉龙
# 时间:2022.9.13 20:50
# 地点:高能所
# ----------------------------------------------------------------------------------------------------------
# Numerical sovinghosing of HI coupled equation:
# ∂ξ^2(Xc)+CrCψω0^2(Xc)=ω0^2(Xb)
# ∂s^2(Xb)+f/gamma∂s(Xb)+k^2/gamma(Xb)=k^2/gamma(Xc)
# ∂s(gamma)=f-2/3regamma^2k^4(xb-xc)^2
# Three variables, Xc(ξ,s), Xb(ξ,s), gamma(ξ,s)
'''
#Xb[i, j] = (fds/gamma[i, j-1]+1 - ((fds/gamma[i, j-1]+1)**2 + 4*(k2ds2/gamma[i, j-1]*(Xb[i, j-1]-Xc[i, j-1])/hs)**2 + 4*k2/gamma[i, j-1]*(Xb[i, j-1]-Xc[i, j-1])*(Xb[i, j-2]-Xb[i, j-1]))**(1/2))/(2*k2ds2*(Xb[i, j-1]-Xc[i, j-1])/gamma[i, j-1]/hs/hs) + Xb[i, j-1] #forward -b(+/-)sqrt(b2-4ac), the first blank
#Xb[i, j] = k2ds2*(Xc[i, j-1]-Xb[i, j-1])/gamma[i, j-1] + (2-fds/gamma[i, j-1])*Xb[i, j-1] - (1-fds/gamma[i, j-1])*Xb[i, j-2] + k2ds2/gamma[i, j-1]*(Xc[i, j-1]-Xb[i, j-1])*((Xb[i, j-1]-Xb[i, j-2])/hs)**2 #backward
Xb[i, j] = (fds/gamma[i, j-1]+1 - ((fds/gamma[i, j-1]+1)**2 + (k2ds2/gamma[i, j-1]*(Xb[i, j-1]-Xc[i, j-1])/hs)**2 + 2*k2/gamma[i, j-1]*(Xb[i, j-1]-Xc[i, j-1])*(Xb[i, j-2]-Xb[i, j-1]))**(1/2))/(k2*(Xb[i, j-1]-Xc[i, j-1])/gamma[i, j-1]/2) + Xb[i, j-1] #center -b(+/-)sqrt(b2-4ac), the first blank
Xc[i, j] = CrCphiW0dxi2*Xb[i-1, j] + (2-CrCphiW0dxi2)*Xc[i-1, j] - Xc[i-2, j]
#gamma[i, j] = fds - co_rek4ds*(gamma[i, j-1]*(Xb[i, j-1]-Xc[i, j-1]))**2 + gamma[i, j-1] - k2*(Xb[i, j]-Xb[i, j-1])*(Xb[i, j-1]-Xc[i, j-1]) #forward
#gamma[i, j] = fds - co_rek4ds*(gamma[i, j-1]*(Xb[i, j-1]-Xc[i, j-1]))**2 + gamma[i, j-1] - k2*(Xb[i, j-1]-Xb[i, j-2])*(Xb[i, j-1]-Xc[i, j-1]) #backward
gamma[i, j] = 2*fds - 2*co_rek4ds*(gamma[i, j-1]*(Xb[i, j-1]-Xc[i, j-1]))**2 + gamma[i, j-1] - k2*(Xb[i, j]-Xb[i, j-2])*(Xb[i, j-1]-Xc[i, j-1]) #center
'''
import numpy as np
import matplotlib.pyplot as plt
##################### Global variables ####################
lam = 0.
k2 = 0.5
w02 = 0.5
Cr = 1.
Cphi = 1.
re = 0.
f = 0.
##################### define function #####################
def numsolve_fore(nxi, ns, k2ds2, fds, CrCphiW0dxi2, co_rek4ds, omegabeta_ds):
'''
forward
calculate all Xb[:, :], Xc[:, :], gamma[:, :]
Parameters
----------
:param nxi, ns: the number of meshes of ξ and S in [0, max]
:param hxi, hs: the step of ξ and S
:param Ximax, Smax: the maximum value of ξ and S,from the beginning of 0
:param XbI, XcI, gamma0: value at initial time, that is Xb[:, 1], Xc[1,:], gamma[:, 1]
:param a: k^2*delts^2
:param b: f*delts
:param c: CrCphi*w0*deltxi^2
:param d: 2/3*re*k^4*delts
:return:Xb[i, j+1], Xc[i+1, j], gamma[i, j+1]
----------
'''
#define variables
Xb = np.zeros((nxi, ns), dtype=float) # define dtype for less running time
Xc = np.zeros((nxi, ns), dtype=float)
gamma = np.zeros((nxi, ns), dtype=float)
gamma[:, 1] = gamma0
gamma[:, 0] = gamma0
for i in range(0, nxi):
Xb[i, 0] = -omegabeta_ds*XbI[i]
#Xb[i, 1] = XbI[i]
for i in range(0, 2):
for j in range(2, ns):
Xb[i, j] = (k2ds2*(Xc[i, j-1]-Xb[i, j-1])/gamma[i, j-1] - Xb[i, j-2] + (fds/gamma[i, j-1]+2.)*Xb[i, j-1])/(1.+fds/gamma[i, j-1])
gamma[i, j] = fds - co_rek4ds*(gamma[i, j-1]*(Xb[i, j-1]-Xc[i, j-1]))**2 + gamma[i, j-1]
for i in range(2, nxi):
for j in range(2, ns):
Xb[i, j] = (k2ds2*(Xc[i, j-1]-Xb[i, j-1])/gamma[i, j-1] - Xb[i, j-2] + (fds/gamma[i, j-1]+2.)*Xb[i, j-1])/(1.+fds/gamma[i, j-1])
Xc[i, j] = CrCphiW0dxi2*Xb[i-1, j] + (2-CrCphiW0dxi2)*Xc[i-1, j] - Xc[i-2, j]
gamma[i, j] = fds - co_rek4ds*(gamma[i, j-1]*(Xb[i, j-1]-Xc[i, j-1]))**2 + gamma[i, j-1]
return Xb, gamma
def numsolve_back(nxi, ns, k2ds2, fds, CrCphiW0dxi2, co_rek4ds, omegabeta_ds):
'''
forward
calculate all Xb[:, :], Xc[:, :], gamma[:, :]
Parameters
----------
:param nxi, ns: the number of meshes of ξ and S in [0, max]
:param hxi, hs: the step of ξ and S
:param Ximax, Smax: the maximum value of ξ and S,from the beginning of 0
:param XbI, XcI, gamma0: value at initial time, that is Xb[:, 1], Xc[1,:], gamma[:, 1]
:param a: k^2*delts^2
:param b: f*delts
:param c: CrCphi*w0*deltxi^2
:param d: 2/3*re*k^4*delts
:return:Xb[i, j+1], Xc[i+1, j], gamma[i, j+1]
----------
'''
#define variables
Xb = np.zeros((nxi, ns), dtype=float) # define dtype for less running time
Xc = np.zeros((nxi, ns), dtype=float)
gamma = np.zeros((nxi, ns), dtype=float)
gamma[:, 1] = gamma0
gamma[:, 0] = gamma0
for i in range(0, nxi):
Xb[i, 0] = -omegabeta_ds*XbI[i]
#Xb[i, 1] = XbI[i]
for i in range(0, 2):
for j in range(2, ns):
Xb[i, j] = (k2ds2*(Xc[i, j-1]-Xb[i, j-1])/gamma[i, j-1] - (fds/gamma[i, j-1]-2.)*Xb[i, j-1] + (fds/gamma[i, j-1]-1.)*Xb[i, j-2])
gamma[i, j] = fds - co_rek4ds*(gamma[i, j-1]*(Xb[i, j-1]-Xc[i, j-1]))**2 + gamma[i, j-1]
for i in range(2, nxi):
for j in range(2, ns):
Xb[i, j] = (k2ds2*(Xc[i, j-1]-Xb[i, j-1])/gamma[i, j-1] - (fds/gamma[i, j-1]-2.)*Xb[i, j-1] + (fds/gamma[i, j-1]-1.)*Xb[i, j-2])
Xc[i, j] = CrCphiW0dxi2*Xb[i-1, j] + (2-CrCphiW0dxi2)*Xc[i-1, j] - Xc[i-2, j]
gamma[i, j] = fds - co_rek4ds*(gamma[i, j-1]*(Xb[i, j-1]-Xc[i, j-1]))**2 + gamma[i, j-1]
return Xb, gamma
def numsolve_cent(nxi, ns, k2ds2, fds, CrCphiW0dxi2, co_rek4ds, omegabeta_ds):
'''
forward
calculate all Xb[:, :], Xc[:, :], gamma[:, :]
Parameters
----------
:param nxi, ns: the number of meshes of ξ and S in [0, max]
:param hxi, hs: the step of ξ and S
:param Ximax, Smax: the maximum value of ξ and S,from the beginning of 0
:param XbI, XcI, gamma0: value at initial time, that is Xb[:, 1], Xc[1,:], gamma[:, 1]
:param a: k^2*delts^2
:param b: f*delts
:param c: CrCphi*w0*deltxi^2
:param d: 2/3*re*k^4*delts
:return:Xb[i, j+1], Xc[i+1, j], gamma[i, j+1]
----------
'''
#define variables
Xb = np.zeros((nxi, ns), dtype=float) # define dtype for less running time
Xc = np.zeros((nxi, ns), dtype=float)
gamma = np.zeros((nxi, ns), dtype=float)
gamma[:, 1] = gamma0
gamma[:, 0] = gamma0
for i in range(0, nxi):
Xb[i, 0] = -omegabeta_ds*XbI[i]
#Xb[i, 1] = XbI[i]
for i in range(0, 2):
for j in range(2, ns):
Xb[i, j] = (k2ds2*(Xc[i, j-1]-Xb[i, j-1])/gamma[i, j-1] + 2*Xb[i, j-1] + (fds/gamma[i, j-1]/2.-1.)*Xb[i, j-2])/(1+fds/gamma[i, j-1]/2.)
gamma[i, j] = 2*fds - 2*co_rek4ds*(gamma[i, j-1]*(Xb[i, j-1]-Xc[i, j-1]))**2 + gamma[i, j-2]
for i in range(2, nxi):
for j in range(2, ns):
Xb[i, j] = (k2ds2*(Xc[i, j-1]-Xb[i, j-1])/gamma[i, j-1] + 2*Xb[i, j-1] + (fds/gamma[i, j-1]/2.-1.)*Xb[i, j-2])/(1+fds/gamma[i, j-1]/2.)
Xc[i, j] = CrCphiW0dxi2*Xb[i-1, j] + (2-CrCphiW0dxi2)*Xc[i-1, j] - Xc[i-2, j]
gamma[i, j] = 2*fds - 2*co_rek4ds*(gamma[i, j-1]*(Xb[i, j-1]-Xc[i, j-1]))**2 + gamma[i, j-2]
return Xb, gamma
def numsolve1_fore(nxi, ns, k2ds2, fds, CrCphiW0dxi2, co_rek4ds, omegabeta_ds):
'''
calculate all Xb[:, :], Xc[:, :], gamma[:, :]
Parameters
----------
:param nxi, ns: the number of meshes of ξ and S in [0, max]
:param hxi, hs: the step of ξ and S
:param Ximax, Smax: the maximum value of ξ and S,from the beginning of 0
:param XbI, XcI, gamma0: value at initial time, that is Xb[:, 1], Xc[1,:], gamma[:, 1]
:param a: k^2*delts^2
:param b: f*delts
:param c: CrCphi*w0*deltxi^2
:param d: 2/3*re*k^4*delts
:return:Xb[i, j+1], Xc[i+1, j], gamma[i, j+1]
----------
'''
#define variables
Xb = np.zeros((nxi, ns), dtype=float) # define dtype for less running time
Xc = np.zeros((nxi, ns), dtype=float)
gamma = np.zeros((nxi, ns), dtype=float)
gamma[:, 1] = gamma0
gamma[:, 0] = gamma0
for i in range(0, nxi):
Xb[i, 0] = -omegabeta_ds*XbI[i]
#Xb[i, 1] = XbI[i]
for i in range(0, 2):
for j in range(2, ns):
A = (k2*0.5-lam*0.25)/gamma[i, j-2]*(Xb[i, j-2]-Xc[i, j-2])*(Xb[i, j-1]-Xb[i, j-2])**2
Xb[i, j] = (k2ds2*(Xc[i, j-1]-Xb[i, j-1])/gamma[i, j-1] - Xb[i, j-2] + (fds/gamma[i, j-1]+2.)*Xb[i, j-1] + A)/(1+fds/gamma[i, j-1])
gamma[i, j] = fds - co_rek4ds*(gamma[i, j-1]*(Xb[i, j-1]-Xc[i, j-1]))**2 + gamma[i, j-1] - (k2*0.5-lam*0.25)*(Xb[i, j-1]-Xc[i, j-1])*(Xb[i, j]-Xb[i, j-1])
for i in range(2, nxi):
for j in range(2, ns):
A = (k2*0.5-lam*0.25)/gamma[i, j-2]*(Xb[i, j-2]-Xc[i, j-2])*(Xb[i, j-1]-Xb[i, j-2])**2
Xb[i, j] = (k2ds2*(Xc[i, j-1]-Xb[i, j-1])/gamma[i, j-1] - Xb[i, j-2] + (fds/gamma[i, j-1]+2.)*Xb[i, j-1] + A)/(1+fds/gamma[i, j-1]) #forward -b(+/-)sqrt(b2-4ac), the first blank
a = 0
for k in range(3):
if abs(Xb[i, j]-a) < 1.e-10 :
break
else:
if k==2:
print('Warning: Iteration 3 times still does not converge!')
A = (k2*0.5-lam*0.25)/gamma[i, j-1]*(Xb[i, j-1]-Xc[i, j-1])*(Xb[i, j]-Xb[i, j-1])**2
a = Xb[i, j]
Xb[i, j] = (k2ds2*(Xc[i, j-1]-Xb[i, j-1])/gamma[i, j-1] - Xb[i, j-2] + (fds/gamma[i, j-1]+2.)*Xb[i, j-1] + A)/(1+fds/gamma[i, j-1]) #forward -b(+/-)sqrt(b2-4ac), the first blank
Xc[i, j] = CrCphiW0dxi2*Xb[i-1, j] + (2-CrCphiW0dxi2)*Xc[i-1, j] - Xc[i-2, j]
gamma[i, j] = fds - co_rek4ds*(gamma[i, j-1]*(Xb[i, j-1]-Xc[i, j-1]))**2 + gamma[i, j-1] - (k2*0.5-lam*0.25)*(Xb[i, j-1]-Xc[i, j-1])*(Xb[i, j]-Xb[i, j-1]) #forward
return Xb, gamma
def numsolve1_back(nxi, ns, k2ds2, fds, CrCphiW0dxi2, co_rek4ds, omegabeta_ds):
'''
calculate all Xb[:, :], Xc[:, :], gamma[:, :]
Parameters
----------
:param nxi, ns: the number of meshes of ξ and S in [0, max]
:param hxi, hs: the step of ξ and S
:param Ximax, Smax: the maximum value of ξ and S,from the beginning of 0
:param XbI, XcI, gamma0: value at initial time, that is Xb[:, 1], Xc[1,:], gamma[:, 1]
:param a: k^2*delts^2
:param b: f*delts
:param c: CrCphi*w0*deltxi^2
:param d: 2/3*re*k^4*delts
:return:Xb[i, j+1], Xc[i+1, j], gamma[i, j+1]
----------
'''
#define variables
Xb = np.zeros((nxi, ns), dtype=float) # define dtype for less running time
Xc = np.zeros((nxi, ns), dtype=float)
gamma = np.zeros((nxi, ns), dtype=float)
gamma[:, 1] = gamma0
gamma[:, 0] = gamma0
for i in range(0, nxi):
Xb[i, 0] = -omegabeta_ds*XbI[i]
#Xb[i, 1] = XbI[i]
for i in range(0, 2):
for j in range(2, ns):
Xb[i, j] = k2ds2*(Xc[i, j-1]-Xb[i, j-1])/gamma[i, j-1] + (2.-fds/gamma[i, j-1])*Xb[i, j-1] - (1.-fds/gamma[i, j-1])*Xb[i, j-2] + (k2*0.5-lam*0.25)/gamma[i, j-1]*(Xb[i, j-1]-Xc[i, j-1])*(Xb[i, j-1]-Xb[i, j-2])**2
gamma[i, j] = fds - co_rek4ds*(gamma[i, j-1]*(Xb[i, j-1]-Xc[i, j-1]))**2 + gamma[i, j-1] - (k2*0.5-lam*0.25)*(Xb[i, j-1]-Xb[i, j-2])*(Xb[i, j-1]-Xc[i, j-1])
for i in range(2, nxi):
for j in range(2, ns):
Xb[i, j] = k2ds2*(Xc[i, j-1]-Xb[i, j-1])/gamma[i, j-1] + (2.-fds/gamma[i, j-1])*Xb[i, j-1] - (1.-fds/gamma[i, j-1])*Xb[i, j-2] + (k2*0.5-lam*0.25)/gamma[i, j-1]*(Xb[i, j-1]-Xc[i, j-1])*(Xb[i, j-1]-Xb[i, j-2])**2 #backward
Xc[i, j] = CrCphiW0dxi2*Xb[i-1, j] + (2-CrCphiW0dxi2)*Xc[i-1, j] - Xc[i-2, j]
gamma[i, j] = fds - co_rek4ds*(gamma[i, j-1]*(Xb[i, j-1]-Xc[i, j-1]))**2 + gamma[i, j-1] - (k2*0.5-lam*0.25)*(Xb[i, j-1]-Xb[i, j-2])*(Xb[i, j-1]-Xc[i, j-1]) #backward
return Xb, gamma
def numsolve1_cent(nxi, ns, k2ds2, fds, CrCphiW0dxi2, co_rek4ds, omegabeta_ds):
'''
calculate all Xb[:, :], Xc[:, :], gamma[:, :]
Parameters
----------
:param nxi, ns: the number of meshes of ξ and S in [0, max]
:param hxi, hs: the step of ξ and S
:param Ximax, Smax: the maximum value of ξ and S,from the beginning of 0
:param XbI, XcI, gamma0: value at initial time, that is Xb[:, 1], Xc[1,:], gamma[:, 1]
:param a: k^2*delts^2
:param b: f*delts
:param c: CrCphi*w0*deltxi^2
:param d: 2/3*re*k^4*delts
:return:Xb[i, j+1], Xc[i+1, j], gamma[i, j+1]
----------
'''
#define variables
Xb = np.zeros((nxi, ns), dtype=float) # define dtype for less running time
Xc = np.zeros((nxi, ns), dtype=float)
gamma = np.zeros((nxi, ns), dtype=float)
gamma[:, 1] = gamma0
gamma[:, 0] = gamma0
for i in range(0, nxi):
Xb[i, 0] = -omegabeta_ds*XbI[i]
Xb[i, 2] = (k2ds2*(Xc[i, 1]-Xb[i, 1])/gamma[i, 1] + 2*Xb[i, 1] + (fds/gamma[i, 1]/2.-1.)*Xb[i, 0])/(1+fds/gamma[i, 1]/2.) #center -b(+/-)sqrt(b2-4ac), the first blank
gamma[i, 2] = 2*fds - 2*co_rek4ds*(gamma[i, 1]*(Xb[i, 1]-Xc[i, 1]))**2 + gamma[i, 0] - (k2*0.5-lam*0.25)*(Xb[i, 1]-Xc[i, 1])*(Xb[i, 2]-Xb[i, 0]) #center
#Xb[i, 1] = XbI[i]
for i in range(0, 2):
for j in range(3, ns):
A = (k2*0.5-lam*0.25)/gamma[i, j-2]*(Xb[i, j-2]-Xc[i, j-2])*(Xb[i, j-1]-Xb[i, j-3])**2/4.
Xb[i, j] = (k2ds2*(Xc[i, j-1]-Xb[i, j-1])/gamma[i, j-1] + 2*Xb[i, j-1] + (fds/gamma[i, j-1]/2.-1.)*Xb[i, j-2] + A)/(1+fds/gamma[i, j-1]/2.)
gamma[i, j] = 2*fds - 2*co_rek4ds*(gamma[i, j-1]*(Xb[i, j-1]-Xc[i, j-1]))**2 + gamma[i, j-2] - (k2*0.5-lam*0.25)*(Xb[i, j-1]-Xc[i, j-1])*(Xb[i, j]-Xb[i, j-2])
for i in range(2, nxi):
Xc[i, 2] = CrCphiW0dxi2*Xb[i-1, 2] + (2-CrCphiW0dxi2)*Xc[i-1, 2] - Xc[i-2, 2]
for i in range(2, nxi):
for j in range(3, ns):
A = (k2*0.5-lam*0.25)/gamma[i, j-2]*(Xb[i, j-2]-Xc[i, j-2])*(Xb[i, j-1]-Xb[i, j-3])**2/4.
Xb[i, j] = (k2ds2*(Xc[i, j-1]-Xb[i, j-1])/gamma[i, j-1] + 2*Xb[i, j-1] + (fds/gamma[i, j-1]/2.-1.)*Xb[i, j-2] + A)/(1+fds/gamma[i, j-1]/2.) #center -b(+/-)sqrt(b2-4ac), the first blank
a = 0
for k in range(3):
if abs(Xb[i, j]-a) < 1.e-10 :
break
else:
if k==2:
print('Warning: Iteration 3 times still does not converge!')
A = (k2*0.5-lam*0.25)/gamma[i, j-1]*(Xb[i, j-1]-Xc[i, j-1])*(Xb[i, j]-Xb[i, j-2])**2/4.
a = Xb[i, j]
Xb[i, j] = (k2ds2*(Xc[i, j-1]-Xb[i, j-1])/gamma[i, j-1] + 2*Xb[i, j-1] + (fds/gamma[i, j-1]/2.-1.)*Xb[i, j-2] + A)/(1+fds/gamma[i, j-1]/2.) #center -b(+/-)sqrt(b2-4ac), the first blank
Xc[i, j] = CrCphiW0dxi2*Xb[i-1, j] + (2-CrCphiW0dxi2)*Xc[i-1, j] - Xc[i-2, j]
gamma[i, j] = 2*fds - 2*co_rek4ds*(gamma[i, j-1]*(Xb[i, j-1]-Xc[i, j-1]))**2 + gamma[i, j-2] - (k2*0.5-lam*0.25)*(Xb[i, j-1]-Xc[i, j-1])*(Xb[i, j]-Xb[i, j-2]) #center
return Xb, gamma
def draw_3d(Y, ximin, ximax, smin, smax, label):
plt.imshow(Y, origin='lower', extent=[ximin, ximax, smin, smax],aspect='auto')
plt.title(label='{}'.format(label), fontsize=19)
cbar = plt.colorbar()
cbar.set_label(label)
plt.ylabel('$k_p S$', fontsize=19)
plt.xlabel('$k_p \\xi$', fontsize=19)
plt.tight_layout()
plt.legend()
if __name__ == "__main__":
#set some variabilities
Ximax = 1.
nxi = 512 #total grids
gamma0 = 1.e5 #for bigger co_rek4dsgamma2
Smax = 1.e4
ns = 1024
Xb0 = 1.e-3
XbI = np.linspace(0., Xb0, nxi) #XbI are one-dimensional transverse
#constant with xi(i=Ixi) while varying s; constant with s(j=Js) while varying xi;
Ixi = -1 #i=257, ξ = (i-1)*hxi
Js = -1
#Generally, at least, one period(lambda_beta) has twenty grids(hs=300/20=15)
L_hosing = np.power(2, 15/4)*np.power(gamma0, 1/2)*np.power(3, -9/4)*np.power(XbI[Ixi], -1/2)
lambda_beta = 2.*np.pi*np.power(2.*gamma0, 1/2) #the period of S roughly = 0.4*sqrt(gamma0)
L_radiation = 16./(re*gamma0*XbI[Ixi]*XbI[Ixi])
print('XbI[Ixi]', XbI[Ixi])
print('Lb_hosing', L_hosing)
print('Lb_radiation', L_radiation)
xi_spread = np.linspace(0., Ximax, nxi)
s_spread = np.linspace(0., Smax, ns)
hs = s_spread[1]-s_spread[0]
hxi = xi_spread[1]-xi_spread[0]
#define some coefficients
k2ds2 = k2*hs*hs #k^2*delts^2, a
fds = f*hs #f*delts, b
#dxi need samll, ds need big
#CrCphiW0dxi2 = 0
CrCphiW0dxi2 = Cr*Cphi*w02*hxi*hxi #CrCphi*w0*deltxi^2, c
co_rek4ds = 2./3.*re*k2*k2*hs #2/3*re*k^4*delts, co represent 2./3., d
omegabeta_ds=(k2/gamma0)**0.5*hs
print(k2ds2, fds, CrCphiW0dxi2, co_rek4ds)
#at here, get all the value of Xb, xi, s
Xb_fore, Gamma_fore = numsolve_fore(nxi, ns, k2ds2, fds, CrCphiW0dxi2, co_rek4ds, omegabeta_ds)
Xb_back, Gamma_back = numsolve_back(nxi, ns, k2ds2, fds, CrCphiW0dxi2, co_rek4ds, omegabeta_ds)
Xb_cent, Gamma_cent = numsolve_cent(nxi, ns, k2ds2, fds, CrCphiW0dxi2, co_rek4ds, omegabeta_ds)
Xb1_fore, Gamma1_fore = numsolve1_fore(nxi, ns, k2ds2, fds, CrCphiW0dxi2, co_rek4ds, omegabeta_ds)
Xb1_back, Gamma1_back = numsolve1_back(nxi, ns, k2ds2, fds, CrCphiW0dxi2, co_rek4ds, omegabeta_ds)
Xb1_cent, Gamma1_cent = numsolve1_cent(nxi, ns, k2ds2, fds, CrCphiW0dxi2, co_rek4ds, omegabeta_ds)
#draw plot
plt.figure(figsize=[12,8])
plt.subplot(321)
plt.plot(s_spread, Xb_fore[Ixi, :], 'r-', label='Xb-s')
plt.plot(s_spread, Xb1_fore[Ixi, :], 'g:', label='Xb1_fore-s')
plt.plot(s_spread, Xb1_back[Ixi, :], 'y-.', label='Xb1_back-s')
plt.plot(s_spread, Xb1_cent[Ixi, :], 'b--', label='Xb1_cent-s')
plt.title(label='$\\xi$={}'.format(xi_spread[Ixi]))
plt.ylabel('Xb')
plt.xlabel('s')
plt.legend()
plt.subplot(322)
plt.plot(s_spread, Gamma_fore[Ixi, :], 'r-', label='$\\gamma$-s')
plt.plot(s_spread, Gamma1_fore[Ixi, :], 'g:', label='$\\gamma$1_fore-s')
plt.plot(s_spread, Gamma1_back[Ixi, :], 'y-.', label='$\\gamma$1_back-s')
plt.plot(s_spread, Gamma1_cent[Ixi, :], 'b--', label='$\\gamma$1_cent-s')
plt.title(label='$\\xi$={}'.format(xi_spread[Ixi]))
plt.ylabel('$\\gamma$')
plt.xlabel('s')
plt.legend()
plt.subplot(323)
plt.plot(xi_spread, Xb_fore[:, Js], 'r-', label='Xb-$\\xi$')
plt.plot(xi_spread, Xb1_fore[:, Js], 'g:', label='Xb1_fore-$\\xi$')
plt.plot(xi_spread, Xb1_back[:, Js], 'y-.', label='Xb1_back-$\\xi$')
plt.plot(xi_spread, Xb1_cent[:, Js], 'b--', label='Xb1_cent-$\\xi$')
plt.title(label='s={}'.format(s_spread[Js]))
plt.ylabel('Xb')
plt.xlabel('$\\xi$')
plt.legend()
plt.subplot(324)
plt.plot(xi_spread, Gamma_fore[:, Js], 'r-', label='$\\gamma-\\xi$')
plt.plot(xi_spread, Gamma1_fore[:, Js], 'g:', label='$\\gamma$1_fore-$\\xi$')
plt.plot(xi_spread, Gamma1_back[:, Js], 'y-.', label='$\\gamma$1_back-$\\xi$')
plt.plot(xi_spread, Gamma1_cent[:, Js], 'b--', label='$\\gamma$1_cent-$\\xi$')
plt.title(label='s={}'.format(s_spread[Js]))
plt.ylabel('$\\gamma$')
plt.xlabel('$\\xi$')
plt.legend()
plt.subplot(325)
draw_3d(Xb_fore, 0, Ximax, 0, Smax, 'Xb')
plt.subplot(326)
draw_3d(Gamma_fore, 0, Ximax, 0, Smax, '$\\gamma$')
plt.figure(figsize=[12,8])
plt.subplot(121)
plt.plot(s_spread, Xb_fore[Ixi, :]-Xb1_fore[Ixi, :], 'g-', label='Xb_fore-Xb1_fore-s')
plt.plot(s_spread, Xb_back[Ixi, :]-Xb1_back[Ixi, :], 'y-', label='Xb_back-Xb1_back-s')
plt.plot(s_spread, Xb_cent[Ixi, :]-Xb1_cent[Ixi, :], 'b-', label='Xb_cent-Xb1_cent-s')
plt.legend()
plt.subplot(122)
plt.plot(s_spread, Xb1_fore[Ixi, :]**2*(k2*0.5-lam*0.25)*0.5, 'r-', label='theory')
plt.plot(s_spread, Gamma_fore[Ixi, :]-Gamma1_fore[Ixi, :], 'g-', label='$\\gamma$_fore-$\\gamma$1_fore-s')
plt.plot(s_spread, Gamma_back[Ixi, :]-Gamma1_back[Ixi, :], 'y-', label='$\\gamma$_back-$\\gamma$1_back-s')
plt.plot(s_spread, Gamma_cent[Ixi, :]-Gamma1_cent[Ixi, :], 'b-', label='$\\gamma$_cent-$\\gamma$1_cent-s')
plt.legend()
plt.tight_layout()
plt.show()