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/env python
# -*- coding: utf-8 -*-
#script for the creation of the plasma position animation. Intensity of the poloidal magnetics field around plasma is plotted.
#Autor: Tomas Odstrcil
from numpy import *
from matplotlib.pyplot import *
import time
from numpy.linalg import norm
from scipy.signal import fftconvolve
from MagFieldCalc import *
import matplotlib.animation as manimation
matplotlib.rcParams['xtick.direction'] = 'out'
matplotlib.rcParams['ytick.direction'] = 'out'
global mu_0,a,R_0
a = 0.085 #[m]
R_0 = 0.4 #[m]
mu_0 = 4*pi*1e-7
def PlotProfile(tvec,I_p,pos_p,name, I_coils = (), pos_coils = ()):
# time vector, plasma current, plasma position, list of the coils currents, list of their positions
n = 100
r = linspace(-a*2+R_0,a*2+R_0,n)
z = linspace(-a*2,2*a,n)
R, Z = np.meshgrid(r,z)
phi = linspace(0,2*pi, 100)
c = cos(phi)
s = sin(phi)
FFMpegWriter = manimation.writers['ffmpeg']
metadata = dict(title='Movie Test', artist='Matplotlib',
comment='Movie support!')
writer = FFMpegWriter(fps=10, metadata=metadata,codec='mpeg4',bitrate=2000 )
fig = figure(figsize=(5,5))
ax = fig.add_subplot(111)
#external coils
B_coil = ()
for coordin_coil in pos_coils:
B_coil.append(Bloop_analytic(R,Z,coordin_coil[0],coordin_coil[1]))
plot(a*c+R_0, a*s, 'r--')
plasma_edge_plot, = plot([], [], 'g--')
mag_img = imshow(zeros((n/2,n/2)), extent=[-a+R_0,a+R_0,-a,a])
CS = contour(R,R,R,colors='k')
cl = clabel(CS, inline=1, fontsize=10)
#B = Bloop_analytic(R,Z,R_0,0)
#norm = sqrt(B[...,1]**2+B[...,0]**2)
with writer.saving(fig, "video/animation.wmv", len(tvec)):
for i in range(len(tvec)):
t = time.time()
ax.set_title('Pol. Mag. field [mT]; time %1.2f ms'%(1e3*tvec[i]))
#calculate profile of the current loop
B = Bloop_analytic(R,Z,pos_p[i,0],pos_p[i,1])
#external coils
for B_ext, I_ext in zip(B_coil,I_coils) :
B+= B_ext*I_ext
norm = sqrt(B[...,1]**2+B[...,0]**2)
j,ao = CurrentProfile(R,Z,pos_p[i,0],pos_p[i,1],I_p[i], 0.2,centered = True)
#pcolor(j) #kreslenà použitého proudového profilu
#show()
#calculate profile of the current loop
#B = Bloop_analytic(R,Z,R_0,0)
#BUG bude to dÄlat chybu s externÃmi cÃvkami
normconv = fftconvolve(norm,j,mode='same')*(r[1]-r[0])*(z[1]-z[0]) # neplatà to zcela pÅesnÄ!! ale je to rychlé
plasma_edge_plot.set_data(c*ao+pos_p[i,0],s*ao+pos_p[i,1])
normconv*=1e3 # convert testa to mili tesla
mag_img.set_data(normconv[-n/4:n/4:-1,n/4:-n/4 ])
ax.autoscale_view(tight=True)
mag_img.autoscale()
#remove CS + clabels
for coll in CS.collections:
ax.collections.remove(coll)
for text in CS.labelTexts:
text.remove()
CS = contour(R[n/4:-n/4,n/4:-n/4],Z[n/4:-n/4,n/4:-n/4],normconv[n/4:-n/4,n/4:-n/4], colors='k') # kvůli okrajovým efektům
cl = CS.clabel( inline=1, fontsize=10)
#quiver(R,Z,B[:,:,0]/norm,B[:,:,1]/norm ) #vykresà to Å¡ipeÄky
ax.relim() #to update the axes limits if desired.
writer.grab_frame()
if i == len(tvec)/2:
fig.savefig('icon.png',bbox_inches='tight',figsize=(4,3),dpi=40)
fig.savefig('large_icon.png',bbox_inches='tight',figsize=(5,5),dpi=40)
#print time.time()-t
|