-
Notifications
You must be signed in to change notification settings - Fork 1
/
Solenoid.py
216 lines (199 loc) · 5.86 KB
/
Solenoid.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
import math
import numpy
from scipy.integrate import odeint
from scipy.special import ellipk, ellipe
from matplotlib.pyplot import *
class Spire:
def __init__(self,a,zs,i):
self.a = a
self.a2 = a*a
self.a4 = self.a2*self.a2
self.zs = zs
self.i = i
def champB(self,x,z):
if abs(x) < 1e-8:
x=0
if x>0:
sx = 1
x = -x
else:
sx = -1
z = z-self.zs
x2 = x*x
z2 = z*z
r2 = x2+z2
b1 = self.a2+ r2
b2 = 2*x*self.a
b3 = b1+b2
b4 = b1-b2
b5 = -2*b2/b4
b6 = math.sqrt(b3/b4)*self.i
rb3 = math.sqrt(b3)
b7 = self.a*b3*rb3
b8 = self.a4-self.a2*(x2-2*z2)+z2*(x2+z2)
b9 = (self.a2+z2)*b3
e = ellipe(b5)
k = ellipk(b5)
bz = b6*((self.a2-r2)*e+b3*k)/b7
if x==0:
bx = 0.0
Atheta = 0.0
Adx = bz/2
else:
bx = -sx*z/x*b6*(b1*e-b3*k)/b7
Atheta = -sx*b6/x*(-b4*e+(self.a2+r2)*k)/(self.a*rb3)
Adx = b6/x2*(b8*e-b9*k)/b7
return [bx,bz,Atheta,Adx]
class SystemeSpires:
def __init__(self,xmin,xmax,zmin,zmax):
self.xmin = xmin
self.xmax = xmax
self.zmin = zmin
self.zmax = zmax
self.spires = []
self.n = 0
def bornes(self,xmin,xmax,zmin,zmax):
self.xmin = xmin
self.xmax = xmax
self.zmin = zmin
self.zmax = zmax
def ajouter(self,spire):
self.spires.append(spire)
self.n += 1
def champB(self,x,z):
bx = 0.0
bz = 0.0
A = 0.0
Adx = 0.0
for spire in self.spires:
b = spire.champB(x,z)
bx += b[0]
bz += b[1]
A += b[2]
Adx += b[3]
return [bx,bz,A,Adx]
def Bz_z(self,x,z):
nz = len(z)
bz = numpy.zeros(nz)
for k in range(nz):
b = self.champB(x,z[k])
bz[k] = b[1]
return bz
def Bz_x(self,x,z):
nx = len(x)
bz = numpy.zeros(nx)
for k in range(nx):
b = self.champB(x[k],z)
bz[k] = b[1]
return bz
def Bx_z(self,x,z):
nz = len(z)
bx = numpy.zeros(nz)
for k in range(nz):
b = self.champB(x,z[k])
bx[k] = b[0]
return bx
def Bx_x(self,x,z):
nx = len(x)
bx = numpy.zeros(nx)
for k in range(nx):
b = self.champB(x[k],z)
bx[k] = b[0]
return bx
def A_x(self,x,z):
nx = len(x)
A = numpy.zeros(nx)
for k in range(nx):
b = self.champB(x[k],z)
A[k] = b[2]
return A
def Adx_x(self,x,z):
nx = len(x)
Adx = numpy.zeros(nx)
for k in range(nx):
b = self.champB(x[k],z)
Adx[k] = b[3]
return Adx
def B(self,x,z):
nx = len(x)
nz = len(z)
bx = numpy.zeros((nx,nz))
bz = numpy.zeros((nx,nz))
A = numpy.zeros((nx,nz))
for i in range(nz):
for j in range(nx):
b = self.champB(x[j],z[i])
bx[j][i] = b[0]
bz[j][i] = b[1]
A[j][i] = b[2]
return [bx,bz,A]
def ligneB(self,x0,z0,sens):
def equation(y,t):
b = self.champB(y[0],y[1])
nb = math.sqrt(b[0]*b[0]+b[1]*b[1])
return [sens*b[0]/nb,sens*b[1]/nb]
tmax = (self.xmax-self.xmin)
te = 1.0*tmax/100
xarray = numpy.array([x0])
zarray = numpy.array([z0])
x=x0
z=z0
t = 0.0
while t < tmax:
y = odeint(equation,[x,z],[0,te],rtol=1e-5,atol=1e-5)
x = y[1][0]
z = y[1][1]
if x<self.xmin or x>self.xmax or z<self.zmin or z>self.zmax:
break
xarray = numpy.append(xarray,x)
zarray = numpy.append(zarray,z)
t += te
return [xarray,zarray]
def ligneE(self,x0,z0,sens):
def equation(y,t):
b = self.champB(y[0],y[1])
nb = math.sqrt(b[0]*b[0]+b[1]*b[1])
return [sens*b[1]/nb, -sens*b[0]/nb]
tmax = (self.xmax-self.xmin)
te = 1.0*tmax/500
xarray = numpy.array([x0])
zarray = numpy.array([z0])
x = x0
z = z0
t = 0.0
while t < tmax:
y = odeint(equation, [x,z], [0,te], rtol=1e-5, atol=1e-5)
x = y[1][0]
z = y[1][1]
if x<self.xmin or x>self.xmax or z<self.zmin or z>self.zmax:
break
xarray = numpy.append(xarray, x)
zarray = numpy.append(zarray, z)
t += te
return [xarray,zarray]
def plot_lignesB(self,points,style):
for p in points:
[x,z] = self.ligneB(p[0],p[1],1)
plot(z,x,style)
[x,z] = self.ligneB(p[0],p[1],-1)
plot(z,x,style)
[x,z] = self.ligneB(-p[0],p[1],1)
plot(z,x,style)
[x,z] = self.ligneB(-p[0],p[1],-1)
plot(z,x,style)
for s in self.spires:
plot([s.zs,s.zs],[-s.a,s.a],linestyle=" ",marker="o",markersize=4,color="black")
def plot_lignesE(self,points,style):
for p in points:
[x,z] = self.ligneE(p[0],p[1],1)
plot(z,x,style)
[x,z] = self.ligneE(p[0],p[1],-1)
plot(z,x,style)
def lignesE(self,points):
res = []
for p in points:
calc = self.ligneE(p[0],p[1],1)
x = calc[1][numpy.logical_not(numpy.isnan(calc[1]))]
y = calc[0][numpy.logical_not(numpy.isnan(calc[0]))]
res += [[list(x), list(y)]]
return res