Skip to main content

User Friendly Magnetic Field Calculations

Project description

Pymagnet

User friendly magnetic field calculations in Python

License: MPL 2.0 License: CC BY-SA 4.0 DOI Anaconda-Server Badge

Getting Started

Installing pymagnet can be done using

python -m pip install pymagnet 

or

conda install -c pdunne pymagnet

Pymagnet is a collection of routines to calculate and plot the magnetic field due to arbitrary 2D and 3D objects, like cubes or cylinders, as well as complex non-convex structures stored in STL files.

The approach assumes the magnets are uniformly magnetised, and fully transparent to magnetic fields. There are some drawbacks to this compared to Finite Element Methods (FEM), but with the advantage of significantly faster calculations.

The current version is written in Python with some speed up using Numpy and Numba, but the backend is being ported to Rust for improved performance.

Documentation

Full documentation can be found here: https://pdunne.github.io/pymagnet/

Examples

Examples can be found in the repository.

You can test out the libraries on Binder, but performance is poor on the free service:

Binder

Features

This code uses analytical expressions to calculate the magnetic field due to various magnets, and forces and torques on a magnet due to all other magnets.

These include simple objects such as:

  • 3D: cubes, prisms (cuboids), cylinders, spheres
Cylinder Plots
  • 2D: rectangles, squares, circles
2D contour plot and streamplot of a long bipolar rod

and complex compound objects:

  • 3D: Polyhedra stored as STL meshes
  • 2D: Polygons constructed from collections of line elements

There are helper functions to plot the data as line, contour, slice, and volume plots, but the underlying data is also accessible.

Prerequisites

Ensure you have Python version >= 3.6 (to use f-strings), and the following packages:

  • numpy
  • numpy-stl
  • numba
  • matplotlib
  • plotly

Usage

Forms of this library have been used in a number of projects including Liquid flow and control without solid walls, Nature 2020.

Licensing

Source code licensed under the Mozilla Public License Version 2.0

Documentation is licensed under a Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

This is a human-readable summary of (and not a substitute for) the license, adapted from CS50x. Official translations of this license are available in other languages.

You are free to:

  • Share — copy and redistribute the material in any medium or format.
  • Adapt — remix, transform, and build upon the material.

Under the following terms:

  • Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
  • ShareAlike — If you remix, transform, or build upon the material, you must distribute your contributions under the same license as the original
  • No additional restrictions — You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you shall be licensed as above, without any additional terms or conditions.

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

pymagnet-0.3.0.tar.gz (50.9 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pymagnet-0.3.0-py3-none-any.whl (79.6 kB view details)

Uploaded Python 3

File details

Details for the file pymagnet-0.3.0.tar.gz.

File metadata

  • Download URL: pymagnet-0.3.0.tar.gz
  • Upload date:
  • Size: 50.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0.post20210125 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.8

File hashes

Hashes for pymagnet-0.3.0.tar.gz
Algorithm Hash digest
SHA256 a23a5bbd484966c2156551483f96a273216b68dde3cfb6ec364e205359f4d2e0
MD5 b62a022e1f1b1d5878fdce73b54a7419
BLAKE2b-256 2072771d37088d7b460d85f4476a0375d2f02248a18a21a1ea075f2a6dfae543

See more details on using hashes here.

File details

Details for the file pymagnet-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: pymagnet-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 79.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0.post20210125 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.8

File hashes

Hashes for pymagnet-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8ff0ec49e18aaba829fd7d950f6a4a92153e0aeda469b3eba9ed33483715ff55
MD5 017f88bdea9efade3282ecb6f164d515
BLAKE2b-256 9ad044d36916b9aa197454d2546f9f82137fc37fd94dbd7a7d7009d7d49b0b1b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page