🍀 Always looking for beta testers!
What does MagnetiCalc do?
MagnetiCalc calculates the static magnetic flux density, vector potential, energy, self-inductance
and magnetic dipole moment of arbitrary coils. Inside an OpenGL-accelerated GUI, the magnetic flux density
(
Experimental feature: To calculate the energy and self-inductance of permeable (i.e. ferrous) materials, different core media can be modeled as regions of variable relative permeability; however, core saturation is currently not modeled, resulting in excessive flux density values.
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
The shape of any wire is modeled as a 3D piecewise linear curve.
Arbitrary loops of wire are sliced into differential current elements
(
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.
The coil's energy
Additionally, the scalar magnetic dipole moment
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).
[4]: Jackson, Klassische Elektrodynamik, 5. Auflage, S. 216, (5.54).
(Screenshot taken from the latest GitHub release.)
Some example projects can be found in the examples/
folder.
If you feel like your project should also be included as an example, you are welcome to file an issue!
You can install MagnetiCalc either as a standard user or as a developer.
This is the recommended way to install MagnetiCalc if you just want to use it.
-
Install
pipx
pipx
is a tool that allows you to install and run Python applications in isolated environments. If you don't have it already, you can install it with:sudo apt install pipx
-
Install MagnetiCalc
pipx install magneticalc
-
Run MagnetiCalc
magneticalc
If you want to contribute to MagnetiCalc, you'll need to set up a development environment.
-
Install Poetry
Poetry is a tool for dependency management and packaging in Python. You can find the installation instructions here: https://python-poetry.org/docs/#installation
-
Clone the repository
git clone https://github.com/shredEngineer/MagnetiCalc.git cd MagnetiCalc
-
Install dependencies
poetry install
-
Run MagnetiCalc
poetry run magneticalc
Tested in Ubuntu 20.04, using the NVIDIA CUDA 10.1 driver and NVIDIA GeForce GTX 1650 GPU.
Please refer to the Numba Installation Guide which includes the steps necessary to get CUDA up and running.
Copyright © 2020–2022, 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.
You are invited to contribute to MagnetiCalc!
General feedback, Issues and Pull Requests are always welcome.
If this software has been helpful to you in some way or another, please let me and others know!
The documentation for MagnetiCalc is auto-generated from docstrings in the Python code.
If desired, MagnetiCalc can be quite verbose about everything it is doing in the terminal:
- Some modules are blacklisted in
Debug.py
, but this can easily be changed. - Some modules also provide their own debug switches to increase the level of detail.
MagnetiCalc allows the following data to be imported/exported using the GUI:
- Import/export wire points from/to TXT file.
- Export
$\mathbf{A}$ -/$\mathbf{B}$-fields, wire points and wire current to an HDF5 container for use in post-processing.
Note: You could use Panoply to open HDF5 files. (The "official" HDFView software didn't work for me.)
The API
class
(documentation)
provides basic functions for importing/exporting data programmatically.
Generate a wire shape using NumPy and export it to a TXT file:
from magneticalc import API
import numpy as np
wire = [
(np.cos(a), np.sin(a), np.sin(16 * a) / 5)
for a in np.linspace(0, 2 * np.pi, 200)
]
API.export_wire("Custom Wire.txt", wire)
Import an HDF5 file containing an
from magneticalc import API
import matplotlib.pyplot as plt
data = API.import_hdf5("examples/Custom Export.hdf5")
axes = data.get_axes()
a_field = data.get_a_field()
ax = plt.figure(figsize=(5, 5), dpi=150).add_subplot(projection="3d")
ax.quiver(*axes, *a_field, length=1e5, normalize=False, linewidth=.5)
plt.show()
The imported data is wrapped in a MagnetiCalc_Data
object
(documentation)
which provides convenience functions for accessing, transforming and reshaping the data:
Method | Description |
---|---|
.get_wire_list() |
Returns a list of all 3D points of the wire. |
.get_wire() |
Returns the raveled wire points as three arrays. |
.get_current() |
Returns the wire current. |
.get_dimension() |
Returns the sampling volume dimension as a 3-tuple. |
.get_axes_list() |
Returns a list of all 3D points of the sampling volume. |
.get_axes() |
Returns the raveled sampling volume coordinates as three arrays. |
.get_axes(reduce=True) |
Returns the axis ticks of the sampling volume. |
.get_a_field_list() .get_b_field_list()
|
Returns a list of all 3D vectors of the |
.get_a_field() .get_b_field()
|
Returns the raveled |
.get_a_field(as_3d=True) .get_b_field(as_3d=True)
|
Returns a 3D field for each component of the |
Functional
- Add a histogram for every metric.
- Add an overlay for vector metrics, like gradient or curvature
(derived from the fundamental
$\mathbf{A}$ - and$\mathbf{B}$ -fields). - Add a list of objects, for wires and permeability groups (constraints),
with a transformation pipeline for each object;
move the
Wire
widget to a dedicated dialog window instead. (Add support for multiple wires, study mutual induction.) - Interactively display superposition of fields with varying currents.
- Add (cross-)stress scalar metric: Ratio of absolute flux density contribution to actual flux density at every point.
- Highlight permeability groups with
$\mu_r \neq 0$ in the 3D view. - Add support for multiple current values and animate the resulting fields.
- Add support for modeling of core material saturation and hysteresis effects.
- Provide a means to emulate permanent magnets.
Usability
- Move variations of each wire preset (e.g. the number of turns) into an individual sub-menu; alternatively, provide a dialog for parametric generation.
- Add stationary coordinate system and ruler in the bottom left corner.
- Add support for selective display over a portion of the metric range, enabling a kind of iso-contour display.
- HDF5 container export from command line, without opening the GUI.
Known Bugs
- Fix issue where the points of a sampling volume with fractional resolution are not always spaced equidistantly for some sampling volume dimensions.
- Fix calculation of divergence right at the sampling volume boundary.
- Fix missing scaling of VisPy markers when zooming.
- Fix unnecessary shading of VisPy markers.
Performance
- Parallelize sampling volume calculation which is currently slow.
Code Quality
- Add unit tests.
A very short demo of MagnetiCalc in action:
There is also a short article about MagnetiCalc on my personal website: paulwilhelm.de/magneticalc
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 | |
Divergence |
Divergence | |
Divergence + |
Positive Divergence | |
Divergence – |
Negative Divergence | |
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 | |
Log Divergence |
Logarithmic Divergence | |
Log Divergence + |
Positive Logarithmic Divergence | |
Log Divergence – |
Negative Logarithmic Divergence | |
Angle XY |
Field angle in XY-plane | |
Angle XZ |
Field angle in XZ-plane | |
Angle YZ |
Field angle in YZ-plane |