Skip to main content

MagnetiCalc calculates the magnetic flux density, vector potential, energy and self-inductance of arbitrary coils in vacuum, examples included. Inside a VisPy/OpenGL-accelerated PyQt5 GUI, the static magnetic flux density (B-field due to DC currents) is displayed in interactive 3D, using multiple metrics for highlighting this field's properties. Alternatively, the magnetic vector potential (A-field) may be displayed.

Project description

MagnetiCalc

License: ISC Donate API Documentation PyPI version

What does MagnetiCalc do?

MagnetiCalc calculates the magnetic flux density, vector potential, energy and self-inductance of arbitrary coils in vacuum, examples included. Inside a VisPy/OpenGL-accelerated PyQt5 GUI, the static magnetic flux density (B-field due to DC currents, in units of Tesla) is displayed in interactive 3D, using multiple metrics for highlighting the field properties. Alternatively, the magnetic vector potential (A-field, in units of Tesla-meter) may be displayed.

Who needs MagnetiCalc?

MagnetiCalc does its job for hobbyists, students, engineers and researchers of magnetic phenomena. I designed MagnetiCalc from scratch, because I didn't want to mess around with expensive and/or overly complex simulation software whenever I needed to solve a magnetostatic problem.

How does it work?

The B-field calculation is implemented using the Biot-Savart law [1], employing multiprocessing techniques; MagnetiCalc uses just-in-time compilation (JIT/Numba) to achieve high-performance calculations. Additionally, the use of easily constrainable "sampling volumes" allows for selective calculation over grids of arbitrary shape.

The shape of any wire is modeled as a 3D piecewise linear curve. Arbitrary loops of wire are sliced into differential current elements (l), each of which contributes to the total resulting field (A, B) at some fixed 3D grid point (x), summing over the positions of all current elements (x'):



Metrics

At each grid point, the field magnitude (or field angle in some plane) is displayed using colored arrows and/or dots; field color and alpha transparency are individually mapped using one of the various available metrics:

Metric Symbol Description
Magnitude Magnitude in space
Magnitude X Magnitude in X-direction
Magnitude Y Magnitude in Y-direction
Magnitude Z Magnitude in Z-direction
Magnitude XY Magnitude in XY-plane
Magnitude XZ Magnitude in XZ-plane
Magnitude YZ Magnitude in YZ-plane
Log Magnitude Logarithmic Magnitude in space
Log Magnitude X Logarithmic Magnitude in X-direction
Log Magnitude Y Logarithmic Magnitude in Y-direction
Log Magnitude Z Logarithmic Magnitude in Z-direction
Log Magnitude XY Logarithmic Magnitude in XY-plane
Log Magnitude XZ Logarithmic Magnitude in XZ-plane
Log Magnitude YZ Logarithmic Magnitude in YZ-plane
Angle XY Field angle in XY-plane
Angle XZ Field angle in XZ-plane
Angle YZ Field angle in YZ-plane

Coil energy & self-inductance

The coil's energy E [2] and self-inductance L [3] are calculated by summing the squared B-field over the entire sampling volume; ensure that the sampling volume encloses a large, non-singular portion of the field.



References

[1]: Jackson, Klassische Elektrodynamik, 5. Auflage, S. 204, (5.4).
[2]: Kraus, Electromagnetics, 4th Edition, p. 269, 6-9-1.
[3]: Jackson, Klassische Elektrodynamik, 5. Auflage, S. 252, (5.157).

Screenshot

Screenshot

(Screenshot taken from the latest GitHub release.)

Installation

Tested with Python 3.8 in Ubuntu 20.04.

If you have trouble installing MagnetiCalc, make sure to file an issue so I can help you get it up and running!

Prerequisites

The following dependency packages have to be installed first (Ubuntu 20.04):

sudo apt install python3-dev
sudo apt install libxcb-xinerama0 --reinstall

Option A: Automatic install via pip

Note: On some systems, it may be necessary to upgrade pip first:

python3 -m pip install pip --upgrade

Install (or upgrade) MagnetiCalc to the user site-packages directory and start it from there:

python3 -m pip install magneticalc --upgrade
python3 -m magneticalc

This will automatically install all dependency packages.

Note: From within a Jupyter Notebook, MagnetiCalc must be installed and run like this:

import sys
!{sys.executable} -m pip install magneticalc --upgrade
!{sys.executable} -m magneticalc

Option B: Manual download

First, manually install all dependency packages (upgrading each to the latest version):

python3 -m pip install numpy numba PyQt5 vispy qtawesome colorit si-prefix --upgrade

Clone the latest version of MagnetiCalc from GitHub and start it directly:

git clone https://github.com/shredEngineer/MagnetiCalc
cd MagnetiCalc
python3 -m magneticalc

For debugging, you may now also install (uninstall) the package in a virtual environment:

python3 -m pip install .
…
python3 -m pip uninstall magneticalc -y

ToDo

  • Add support for saving/loading configuration to/from other filenames.
  • Add installation instructions for Windows, ensure consistent PyQt5 look and feel.
  • Add support for adding, editing and removing sampling volume constraints; the SamplingVolume module already supports constraints, but the GUI currently doesn't.
  • Add support for selective display over a portion of the metric range, in order to get a kind of iso-contour display.
  • Add support for different media with arbitrary geometry and permeability.
  • Add support for multiple wires, study mutual induction.
  • Add CUDA backend for Biot-Savart implementation.

Contribute

You are invited to contribute to MagnetiCalc in any way you like! :)

If this software has been helpful to you in some way or another, please let me and others know!

License

Copyright © 2020, Paul Wilhelm, M. Sc. <anfrage@paulwilhelm.de>

ISC License

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

Video Demo

Here is a very short demo of MagnetiCalc in action:

Magnetic Field Calculation with Python (MagnetiCalc)

Links

If you want to comment on the project or see additional info, please visit my personal website: https://paulwilhelm.de/magneticalc/

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

MagnetiCalc-1.8.1.tar.gz (49.1 kB view hashes)

Uploaded Source

Built Distribution

MagnetiCalc-1.8.1-py3-none-any.whl (79.5 kB view hashes)

Uploaded Python 3

Supported by

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