-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmyMagnetic.py
92 lines (67 loc) · 2.8 KB
/
myMagnetic.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
import numpy as np
class magneticlass():
def __init__(self,N):
self.N = N
self.B = None
self.FIELD_X=0
self.FIELD_Y=1
self.FIELD_Z=2
self.dirfield=0 # x y o z
self.Bmaxmag=1000.
self.B =None # magnetuic filed N*N*N*3
# list with two 3d vectors for draw main arrow
# (first position and second dir vector )
self.mainArrow=[]
self.btext=""
def clear(self):
self.btext=""
self.mainArrow=[]
self.B =None
def load_npyFile(self, sfilepath):
self.mainArrow=[]
self.btext="magpy"
self.B = np.load(sfilepath)
def _makeMainArrow(self):
if self.dirfield == self.FIELD_X:
vpos=np.array([0,0, self.N*0.72])
vdir=np.array([-1.,0.,0.])
elif self.dirfield == self.FIELD_Y:
vpos=np.array([ self.N*0.8,0,0])
vdir=np.array([0,-1,0])
elif self.dirfield == self.FIELD_Z:
vpos=np.array([ -self.N*0.8,0,0])
vdir=np.array([0,0,-1])
self.mainArrow.append(vpos)
self.mainArrow.append(vdir)
def makeB(self,dirfield,Bmaxmag):
self.btext=""
self.B = np.zeros((self.N,self.N,self.N,3))
self.dirfield=dirfield
self.Bmaxmag=Bmaxmag
vmag=-Bmaxmag
incmag=2.0 * Bmaxmag/self.N
if dirfield == self.FIELD_X:
vdir=np.array([1.,0.,0.])
for x in range (self.N):
vmag+=incmag
vv = vdir*vmag
for y in range(self.N):
for z in range(self.N):
self.B[x][y][z]= vv
elif dirfield == self.FIELD_Y:
vdir=np.array([0.,1.,0.])
for y in range (self.N):
vmag+=incmag
vv = vdir*vmag
for x in range(self.N):
for z in range(self.N):
self.B[x][y][z]= vv
elif dirfield == self.FIELD_Z:
vdir=np.array([0.,0.,1])
for z in range (self.N):
vmag+=incmag
vv = vdir*vmag
for x in range(self.N):
for y in range(self.N):
self.B[x][y][z]= vv
self._makeMainArrow()