Skip to content

Commit e260366

Browse files
committed
doku
1 parent 4e86ecd commit e260366

File tree

5 files changed

+18
-82
lines changed

5 files changed

+18
-82
lines changed

docs/_pages/0_documentation.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,8 +396,6 @@ The following example code shows how to use `displaySystem()`:
396396

397397
**Figure:** Several magnet and sensor object are created and manipulated. Using `displaySystem()` they are displayed in a 3D plot together with some markers which allows one to quickly check if the system geometry is ok.
398398

399-
:download:`displaySys.py <../pyplots/doku/displaySys.py>`
400-
401399

402400
Math Package
403401
###############

docs/_pages/2_guideExamples.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ The superposition principle allows us to calculate complex magnet shapes by 'add
110110
:download:`04_ComplexShape.py <../pyplots/examples/04_ComplexShape.py>`
111111

112112

113-
Using vectorized code with rotations
113+
Vectorized vs Classical Code
114114
######################################
115115

116116
Description coming up tomorrow :)

docs/pyplots/doku/thorsHammerSensor.py

Lines changed: 0 additions & 35 deletions
This file was deleted.

docs/pyplots/examples/04_ComplexShape.py

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,37 @@
33
from magpylib.source.magnet import Cylinder
44
import magpylib as magpy
55

6-
#create collection of four magnets
6+
# create collection of two magnets
77
s1 = Cylinder(mag=[0,0,1000], dim=[5,5])
88
s2 = Cylinder(mag=[0,0,-1000], dim=[2,6])
99
c = magpy.Collection(s1,s2)
1010

11-
#create positions
11+
# create positions
1212
xs = np.linspace(-8,8,100)
1313
zs = np.linspace(-6,6,100)
1414
posis = [[x,0,z] for z in zs for x in xs]
1515

16-
#calculate fields
17-
#Bs = c.getBsweep(posis)
16+
# calculate field and amplitude
17+
B = [c.getB(pos) for pos in posis]
18+
Bs = np.array(B).reshape([100,100,3]) #reshape
19+
Bamp = np.linalg.norm(Bs,axis=2)
1820

19-
#reshape array and calculate amplitude
20-
#Bs = np.array(Bs).reshape([100,100,3])
21-
#Bamp = np.linalg.norm(Bs,axis=2)
22-
23-
##define figure with 2d and 3d axes
21+
# define figure with a 2d and a 3d axis
2422
fig = plt.figure(figsize=(8,4))
2523
ax1 = fig.add_subplot(121,projection='3d')
2624
ax2 = fig.add_subplot(122)
2725

28-
#add displaySystem on ax1
26+
# add displaySystem on ax1
2927
magpy.displaySystem(c,subplotAx=ax1,suppress=True)
3028
ax1.view_init(elev=75)
3129

32-
##amplitude plot on ax2
33-
#X,Z = np.meshgrid(xs,zs)
34-
#ax2.pcolor(xs,zs,Bamp,cmap='jet',vmin=-200)
30+
# amplitude plot on ax2
31+
X,Z = np.meshgrid(xs,zs)
32+
ax2.pcolor(xs,zs,Bamp,cmap='jet',vmin=-200)
3533

36-
#plot field lines on ax2
37-
#U,V = Bs[:,:,0], Bs[:,:,2]
38-
#ax2.streamplot(X,Z,U,V,color='k',density=2)
34+
# plot field lines on ax2
35+
U,V = Bs[:,:,0], Bs[:,:,2]
36+
ax2.streamplot(X,Z,U,V,color='k',density=2)
3937

4038
#display
4139
plt.show()
Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import magpylib as magpy
22
import numpy as np
33
import matplotlib.pyplot as plt
4-
import time
54

65
# vector size: we calculate the field N times with different inputs
76
N = 10000
@@ -17,27 +16,6 @@
1716
# different angles for each evaluation
1817
angs = np.linspace(-20,20,N)
1918

20-
21-
# magpylib classic ---------------------------
22-
T0 = time.perf_counter()
23-
24-
B = []
25-
for a in angs:
26-
s = magpy.source.magnet.Box(mag,dim,posm)
27-
s.rotate(a,axis,anch)
28-
B += [s.getB(poso)]
29-
Bc = np.array(B)
30-
31-
T1 = time.perf_counter()
32-
print('Evaluation time (classic): ' + str(T1-T0))
33-
34-
plt.plot(Bc[:,0])
35-
plt.plot(Bc[:,1])
36-
plt.plot(Bc[:,2])
37-
38-
# magpylib vector ---------------------------
39-
T0 = time.perf_counter()
40-
4119
# Vectorizing input using numpy native instead of python loops
4220
MAG = np.tile(mag,(N,1))
4321
DIM = np.tile(dim,(N,1))
@@ -49,11 +27,8 @@
4927
# N-times evalulation of the field with different inputs
5028
Bv = magpy.vector.getBv_magnet('box',MAG,DIM,POSo,POSm,[angs],[AXIS],[ANCH])
5129

52-
T1 = time.perf_counter()
53-
print('Evaluation time (vector): ' + str(T1-T0))
54-
55-
plt.plot(Bv[:,0],ls='--')
56-
plt.plot(Bv[:,1],ls='--')
57-
plt.plot(Bv[:,2],ls='--')
30+
plt.plot(Bv[:,0])
31+
plt.plot(Bv[:,1])
32+
plt.plot(Bv[:,2])
5833

5934
plt.show()

0 commit comments

Comments
 (0)