Skip to content

Commit 830b5d3

Browse files
committed
improve readme example
1 parent c827ac3 commit 830b5d3

File tree

1 file changed

+37
-8
lines changed

1 file changed

+37
-8
lines changed

README.md

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Magpylib-Force
22

3-
This package provides force and torque computation for Magpylib objects. Its work in progress and will finally be integrate into the Magpylib package.
3+
This package provides force and torque computation for Magpylib objects. It is work in progress and will finally be integrated into the Magpylib package.
4+
5+
This work is supported by a NUMFOCUS grant: SDG 2024 round 1
6+
7+
**Warning:** magpylib-force relies on magpylib version>=5.0.1
48

59
# Installation
610

@@ -13,15 +17,40 @@ import numpy as np
1317
import magpylib as magpy
1418
from magpylib_force import getFT
1519
16-
source = magpy.magnet.Sphere(diameter=1, polarization=(1,2,3))
20+
# Note: All inputs and outputs are in SI units.
21+
22+
# SOURCES: Magpylib source objects that generates the field
23+
s1 = magpy.magnet.Sphere(diameter=1, polarization=(1,2,3))
24+
s2 = magpy.magnet.Cuboid(dimension=(1,1,1), polarization=(1,2,3))
25+
26+
# TARGETS: targets that experience a force in the field of all sources
27+
cube = magpy.magnet.Cuboid(
28+
dimension=(1,1,1),
29+
polarization=(0,0,1),
30+
position=(1,2,3),
31+
)
32+
cube.meshing = (5,5,5) # regular rectangular mesh in Cuboid
1733
18-
line = magpy.current.Polyline(
34+
line = magpy.current.Line(
35+
vertices=((2,2,2), (3,3,3), (3,2,-3), (2,2,2)),
1936
current=1,
20-
vertices=((0,0,3), (-2,0,-1), (2,0,-1), (0,0,3)),
2137
)
22-
line.meshing = 10 # mesh points in each segment
38+
line.meshing = 15 # number of cells in each segment
39+
40+
# Note: use only closed current loops or be prepared to violate physics
41+
42+
sphere = magpy.magnet.Sphere(
43+
diameter=(6/np.pi)**(1/3),
44+
polarization=(0,0,1),
45+
position=(2,2,2),
46+
)
47+
sphere.meshing = 5 # grid finesse - the higher the finer
48+
49+
# COMPUTE FORCE AND TORQUE
50+
FT = getFT([s1,s2], [cube, line, sphere], anchor=(0,0,0))
51+
52+
# Note: output shape is (3,2,3) from (targets, FT, xyz)
53+
print(FT)
2354
24-
F,T = getFTcube(cube1, cube2, anchor=(0,0,0))
25-
print(F)
26-
print(T)
55+
# Note: The magnet-numbers are large because the magnets are large :)
2756
```

0 commit comments

Comments
 (0)