1
+ import numpy as np
2
+ import time
3
+ import magpylib as magpy
4
+
5
+ POS = np .array ([[1 ,2 ,3 ],[2 ,- 3 ,4 ],[- 3 ,4 ,5 ],[5 ,6 ,- 7 ],[- 3 ,- 2 ,1 ],[- 4 ,3 ,- 2 ],[5 ,- 4 ,- 3 ],[- 6 ,- 5 ,- 4 ]])
6
+
7
+ s = magpy .source .current .Circular (curr = 123 ,dim = 2 ,pos = (2 ,- 4 ,5 ),angle = 23 ,axis = (.2 ,- 5 ,3 ))
8
+ B = np .array ([s .getB (p ) for p in POS ])
9
+ Bv = s .getB (POS )
10
+ err = np .amax (np .abs (Bv - B ))
11
+ assert err < 1e-12
12
+
13
+ VERT = POS * .333
14
+ s = magpy .source .current .Line (curr = 123 ,vertices = VERT )
15
+ B = np .array ([s .getB (p ) for p in POS ])
16
+ Bv = s .getB (POS )
17
+ err = np .amax (np .abs (Bv - B ))
18
+ assert err < 1e-12
19
+
20
+ s = magpy .source .moment .Dipole (moment = (.1 ,- 5 ,5.5 ),pos = (2 ,- 4 ,5 ),angle = 33 ,axis = (.2 ,- 5 ,3 ))
21
+ B = np .array ([s .getB (p ) for p in POS ])
22
+ Bv = s .getB (POS )
23
+ err = np .amax (np .abs (Bv - B ))
24
+ assert err < 1e-12
25
+
26
+ s = magpy .source .magnet .Box (mag = (33 ,22 ,111 ),dim = (3 ,2 ,1 ),pos = (2 ,- 4 ,5 ),angle = 33 ,axis = (.2 ,- 5 ,3 ))
27
+ B = np .array ([s .getB (p ) for p in POS ])
28
+ Bv = s .getB (POS )
29
+ err = np .amax (np .abs (Bv - B ))
30
+ assert err < 1e-12
31
+
32
+ s = magpy .source .magnet .Cylinder (mag = (33 ,22 ,111 ),dim = (3 ,1 ),pos = (2 ,- 4 ,5 ),angle = 33 ,axis = (.2 ,- 5 ,3 ))
33
+ B = np .array ([s .getB (p ) for p in POS ])
34
+ Bv = s .getB (POS )
35
+ err = np .amax (np .abs (Bv - B ))
36
+ assert err < 1e-12
37
+
38
+ s = magpy .source .magnet .Sphere (mag = (33 ,22 ,111 ),dim = .123 ,pos = (2 ,- 4 ,5 ),angle = 33 ,axis = (.2 ,- 5 ,3 ))
39
+ B = np .array ([s .getB (p ) for p in POS ])
40
+ Bv = s .getB (POS )
41
+ err = np .amax (np .abs (Bv - B ))
42
+ assert err < 1e-12
0 commit comments