-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.py
224 lines (164 loc) · 7.8 KB
/
functions.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
# functions.py: supplies several functions for integration, including the dipole,
# the Hopf fibration field, and their isotrope fields
#
#
#
#
import numpy as np
def Dipole(xx, m = np.array([0,0,1])):
"""
Returns the vector field of a dipole in arbitrary direction
"""
xxn = xx/np.sqrt(np.sum(xx**2)) #xxnormalized Careful around Zero!
vf = (3*xxn * np.dot(xxn, m) - m)/np.sqrt(np.sum(xx**2))**3 # Vector Field!
return vf
def Dipole_guide(xx, m = np.array([0,0,1]), d=np.array([0,0,-.5]),strength = 0.5):
"""
Returns the vector field of a dipole in arbirary direction plus a guide field in another
arbitrary direction.
Args:
*xx**:
position where the field is to be evaluated.
**m**
Direction of the dipole.
**d**:
The constant guide field.
"""
xxn = xx/np.sqrt(np.sum(xx**2)) #xxnormalized Careful around Zero!
vf = (3*xxn * np.dot(xxn, m) - m)/np.sqrt(np.sum(xx**2))**3 # Vector Field!
guidefield = (d/np.sqrt(np.sum(d**2)))*strength
return np.array(vf+guidefield)
def Dipole_isotropes(xx):
"""
Returns the isotropes.
Note: corresponds with the dipole where m=(0,0,1)!!!
"""
isotropes= np.zeros(3)
isotropes[0] = (-9*xx[0]*xx[2]*(xx[0]**2 + xx[1]**2 + 2*xx[2]**2))/((xx[0]**2 + xx[1]**2 + xx[2]**2)*(xx[0]**2 + xx[1]**2 + 4*xx[2]**2))**1.5
isotropes[1] = (-9*xx[1]*xx[2]*(xx[0]**2 + xx[1]**2 + 2*xx[2]**2))/((xx[0]**2 + xx[1]**2 + xx[2]**2)*(xx[0]**2 + xx[1]**2 + 4*xx[2]**2))**1.5
isotropes[2] = (-9*xx[2]**2*(xx[0]**2 + xx[1]**2 + 2*xx[2]**2))/((xx[0]**2 + xx[1]**2 + xx[2]**2)*(xx[0]**2 + xx[1]**2 + 4*xx[2]**2))**1.5
return isotropes
def Dipole_nulls(strength, direction):
"""
Returns the positions of the null points in the dipole field in a constant guide
field of magnitude given by strength and direction given by the (cartesian) vector direction.
Expressions explained in paper/poster.
"""
nullpos = np.zeros(3)
R = strength
#translate the direction vector to shperical coordinates:
Phi = np.arctan2(np.sqrt(direction[0]**2+direction[1]**2), -direction[2])
Theta = np.arctan2(-1* direction[1], -1* direction[2])
nullpos[0] = ((9 + np.cos(2*Phi) + np.sqrt(2)*np.cos(Phi)*np.sqrt(17 +\
np.cos(2*Phi)))**0.16666666666666666*np.cos(Theta)*np.sin(np.arccos((-1 +\
np.cos(2*Phi) + np.sqrt(2)*np.cos(Phi)*np.sqrt(17 + np.cos(2*Phi)))/6.)/2.))/\
(2**0.3333333333333333*R**0.3333333333333333)
nullpos[1] = ((9 + np.cos(2*Phi) + np.sqrt(2)*np.cos(Phi)*np.sqrt(17 +\
np.cos(2*Phi)))**0.16666666666666666*np.sin(Theta)* np.sin(np.arccos((-1 +\
np.cos(2*Phi) + np.sqrt(2)*np.cos(Phi)*np.sqrt(17 +\
np.cos(2*Phi)))/6.)/2.))/(2**0.3333333333333333*R**0.3333333333333333)
nullpos[2] = ((9 + np.cos(2*Phi) + np.sqrt(2)*np.cos(Phi)*np.sqrt(17 +\
np.cos(2*Phi)))**0.16666666666666666*np.cos(np.arccos((-1 + np.cos(2*Phi) +\
np.sqrt(2)*np.cos(Phi)*np.sqrt(17 +\
np.cos(2*Phi)))/6.)/2.))/(2**0.3333333333333333*R**0.3333333333333333)
return [nullpos, -1*nullpos]
def Hopf_isotropes(xx):
"""
returns the vector field that is in the direction of the isotropes of the Hopf fibration.
This means the vectors in the direction that the direction of the Hopf field stays constant.
"""
x = (4*(xx[1] - xx[0]*xx[2]))/((1 + xx[0]**2 + xx[1]**2 + xx[2]**2)**2*abs(-1 + xx[0]**2 + xx[1]**2 - xx[2]**2))
y = (-4*(xx[0] + xx[1]*xx[2]))/((1 + xx[0]**2 + xx[1]**2 + xx[2]**2)**2*abs(-1 + xx[0]**2 + xx[1]**2 - xx[2]**2))
z = (-4*(1 + xx[2]**2))/((1 + xx[0]**2 + xx[1]**2 + xx[2]**2)**2*abs(-1 + xx[0]**2 + xx[1]**2 - xx[2]**2))
return np.array((x,y,z))
def ZeroField(xx, strength=.1, index=1):
"""
Returns the magnetic field around a magnetic null. This is equal to the
linearized field of square vacuum null.
The null is at the origin and the spine is along the z-axis
Keyword arguments:
*xx*
Position where the field is to be evaulated
*strength*
Scales the field strength
*index*
Index of the null (is the z-axis in- or out?) only \pm 1 allowed
"""
factor= {True:-1, False:1}[index>0]
field=factor*np.array([.5*xx[0], .5*xx[1], -xx[2]])
return strength*field
def BHopf_guide(xx, strength=0.01, direction=np.array([0,0,1]), **kwargs):
"""
Function that returns the field of the Hopf field with a guide field in a certain direction
Keyword arguments:
*xx*
Position where the field is to be evaluated
*strength*
amplitude of the magnetic field strength
*direction*
vector in R3 of unit length that gives the direction of the guide field. If it is not unit length, it is made so.
other keyword arguments are passed directly on to the Bfield function
"""
direction= direction/ np.sqrt(np.sum(direction**2))
hopfField = BHopf(xx, **kwargs)
return hopfField + (direction*strength)
def BHopf_guide_RPT(xx, R=0.01, Phi=.001, Theta=0, **kwargs):
"""
Function that returns the field of the Hopf field with a guide field, where the guide field is
given in R(magnitude), in MINUS the Phi and Theta spherical direction.
Keyword arguments:
*xx*
Position where the field is to be evaluated
*R*
amplitude of the magnetic field strength
*Phi*
other angle of the direction of the guide field
*Theta*
Azimuthal angle of the direction of the guide field
other keyword arguments are passed directly on to the Bfield function
"""
direction= np.array( (np.cos(Theta)*np.sin(Phi),
np.sin(Theta)*np.sin(Phi),
np.cos(Phi)))
hopfField = BHopf(xx, **kwargs)
return hopfField - (direction*R)
def BHopf(xx, w1=1, w2=1, r0=1 ):
"""
Function that returns the magnetic field of the Hopf map at x,y,z coordinates
given by xx.
Functional form to be found in Smiet et al. (2015): 'Self-organizing knotted structures
in Plasma'
Call signature:
BHopf(xx, w1=1, w1=2, r0=1):
Keyword arguments:
*xx*
Position where the field is to be evaluated
*w1*
omega1, the poloidal winding number
*w2*
omega2, the toroidal winding number
*r0*
Scaling factor that increases the size. Equals the radius of the degenerate torus
"""
bfield=np.zeros(3)
r2=(np.sum(xx**2)) #
prefactor = r0**4/((r0**2 + r2)**3)
bfield[0]=2*(w2*r0*xx[1] - w1*xx[0]*xx[2]) #remember python arrays start at zero!
bfield[1]=-2*(w2*r0*xx[0] + w1*xx[1]*xx[2])
bfield[2]= w1*(-1*r0**2 + xx[0]**2 +xx[1]**2 -xx[2]**2)
return -1* prefactor*bfield
def Hopf_nulls(R, Phi, Theta):
"""
returns the location of the nulls of the Hopf field with a guide field that
has magnitude R, and angles Phi (azimuthal) and Theta in spherical coordinates.
DUE TO REASONS PHI=0 GIVES NANS. USE PHI=0.00000000001 TO AVOID
"""
null1 = np.zeros(3)
null2 = np.zeros(3)
null1[0] = ((-1 + np.cos(Phi))*np.sqrt(1 - 2*np.sqrt(R) + np.cos(Phi))*np.cos(Theta)*(1/np.sin(Phi)))/(np.sqrt(2)*R**0.25) + np.sin(Theta)*np.tan(Phi/2.)
null1[1] = ((-1 + np.cos(Phi))*np.sqrt(1 - 2*np.sqrt(R) + np.cos(Phi))*(1/np.sin(Phi))*np.sin(Theta))/(np.sqrt(2)*R**0.25) - np.cos(Theta)*np.tan(Phi/2.)
null1[2] = -(np.sqrt(1 - 2*np.sqrt(R) + np.cos(Phi))/(np.sqrt(2)*R**0.25))
null2[0] = (((np.sqrt(2)*np.sqrt(1 - 2*np.sqrt(R) + np.cos(Phi))*np.cos(Theta))/R**0.25 + 2*np.sin(Theta))*np.tan(Phi/2.))/2.
null2[1] = ((-2*np.cos(Theta) + (np.sqrt(2)*np.sqrt(1 - 2*np.sqrt(R) + np.cos(Phi))*np.sin(Theta))/R**0.25)*np.tan(Phi/2.))/2.
null2[2] = np.sqrt(1 - 2*np.sqrt(R) + np.cos(Phi))/(np.sqrt(2)*R**0.25)
return null1, null2