An extension to the Magpylib library, providing force computation
Project description
Magpylib-Force
This package provides force and torque computation for Magpylib objects. It is work in progress and will finally be integrated into the Magpylib package.
This work is supported by a NUMFOCUS grant: SDG 2024 round 1
Warning:
- relies on magpylib version>=5.0.1
- does not work with paths
- limited target types available
Installation
pip install magpylib-force
Example code:
import numpy as np
import magpylib as magpy
from magpylib_force import getFT
# Note: All inputs and outputs are in SI units.
# SOURCES: Magpylib source objects that generates the field
s1 = magpy.magnet.Sphere(diameter=1, polarization=(1,2,3))
s2 = magpy.magnet.Cuboid(dimension=(1,1,1), polarization=(1,2,3))
# TARGETS: targets that experience a force in the field of all sources
cube = magpy.magnet.Cuboid(
dimension=(1,1,1),
polarization=(0,0,1),
position=(1,2,3),
)
cube.meshing = (5,5,5) # regular rectangular mesh in Cuboid
line = magpy.current.Line(
vertices=((2,2,2), (3,3,3), (3,2,-3), (2,2,2)),
current=1,
)
line.meshing = 15 # number of cells in each segment
# Note: use only closed current loops or be prepared to violate physics
sphere = magpy.magnet.Sphere(
diameter=(6/np.pi)**(1/3),
polarization=(0,0,1),
position=(2,2,2),
)
sphere.meshing = 5 # grid finesse - the higher the finer
# COMPUTE FORCE AND TORQUE
FT = getFT([s1,s2], [cube, line, sphere], anchor=(0,0,0))
# Note: output shape is (3,2,3) from (targets, FT, xyz)
print(FT)
# Note: The magnet-numbers are large because the magnets are large :)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
magpylib_force-0.1.8.tar.gz
(17.7 kB
view hashes)
Built Distribution
Close
Hashes for magpylib_force-0.1.8-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c36c0274ac87d1112b785794368c9b26d90a9244d0ff12a686d92c6b22b4fc11 |
|
MD5 | 50ee223422900ad20394b89851c03ccf |
|
BLAKE2b-256 | 3b3cfb92f6c898f8aa34e862fb9513a6edb2ae123d73c02979a1690f0defb1de |