A simple, user friendly Python 3 toolbox for calculating magnetic fields from permanent magnets and current distributions.
Project description
magpylib - A simple and user friendly magnetic toolbox for Python 3
What is magpylib ?
- Python package for calculating magnetic fields of magnets, currents and moments (sources).
- It provides convenient methods to generate, geometrically manipulate, group and vizualize assemblies of sources.
- The magnetic fields are determined from underlying (semi-analytical) solutions which results in fast computation times (sub-millisecond) and requires little computation power.
Dependencies:
Python3.6+, Numpy, Matplotlib
Guides & Installation:
Please check out our documentation for getting started and more info!
(Installation methods are still WIP.)
Installing this project using pip:
- run the following in your Python environment terminal:
pip install magpylib
Installing this project locally:
- Clone this repository to your machine.
- In the directory, run
pip install .in your conda terminal.
Example:
- Two permanent magnets with axial magnetization are created and geometrically manipulated. They are grouped in a single collection and the system geometry is displayed using a supplied method.
- The total magnetic field that is generated by the collection is calculated on a grid in the xz-plane and is displayed using matplotlib.
Program output:
Code:
# imports
import numpy as np
import matplotlib.pyplot as plt
import magpylib as magpy
# create magnets
magnet1 = magpy.source.magnet.Box(mag=[0,0,600],dim=[3,3,3],pos=[-4,0,3])
magnet2 = magpy.source.magnet.Cylinder(mag=[0,0,500], dim=[3,5], pos=[0,0,0])
# manipulate magnets
magnet1.rotate(45,[0,1,0],anchor=[0,0,0])
magnet2.move([5,0,-4])
# collect magnets
pmc = magpy.Collection(magnet1,magnet2)
# display system geometry
pmc.displaySystem()
# calculate B-fields on a grid
xs = np.linspace(-10,10,20)
zs = np.linspace(-10,10,20)
Bs = np.array([[pmc.getB([x,0,z]) for x in xs] for z in zs])
# display fields using matplotlib
fig, ax = plt.subplots()
X,Y = np.meshgrid(xs,zs)
U,V = Bs[:,:,0], Bs[:,:,2]
ax.streamplot(X, Y, U, V, color=np.log(U**2+V**2), density=1.5)
plt.show()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file magpylib-1.0.2b0.tar.gz.
File metadata
- Download URL: magpylib-1.0.2b0.tar.gz
- Upload date:
- Size: 45.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.7.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fde2f8641a265461a9eb50259c5fccdf82822b57a441e3eae7a99f2861f3022e
|
|
| MD5 |
e90265fd138dfd843d4d50047492d8e0
|
|
| BLAKE2b-256 |
d2bcf09f9ae0fac48ba19b0ab891a6f9dec2400dc3ab5ac35ee867f1232c6ea1
|
File details
Details for the file magpylib-1.0.2b0-py3-none-any.whl.
File metadata
- Download URL: magpylib-1.0.2b0-py3-none-any.whl
- Upload date:
- Size: 67.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.7.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6bf826ce6d5a74c3701d02d121697616e2e04792c11368789fc6ac0d65fc4085
|
|
| MD5 |
0834b9cad935a538048aaeee4c5065ff
|
|
| BLAKE2b-256 |
3632eaaef25ded1c3c44c9f6c5ff2dba6ad84dc0fcdffcf93e0487fb93a8d0f9
|