Skip to main content

oersted

Lightning-fast magnetic fields calculations

Documentation | Rust API

This library contains highly-optimised routines for solving magnetic fields calculations, using both analytic and approximate volume integral methods. Included is a Barnes-Hut solver with multipole expansion at octree nodes, which dramatically reduces solver speed at acceptable error levels:

Timing Results

The Barnes-Hut solver exhibits excellent scaling performance, solving a 4.6M element (21.2e12 interaction) problem in ~20 seconds on a consumer-grade workstation:

Octree times

Installation

oersted can be installed via pypi:

pip install oersted

or from crates.io:

cargo add oersted

Example

import oersted 

# Mesh the part 
mesh_size = 10e-3 # (m)
mesh = oersted.Mesh.from_step("my_part.stp", mesh_size)

# Compute the current density on the part 
jdensity: NDArray[float64] = ... 

# Compute self-fields using the 'fast' solver
settings = oersted.SolverSettings(method="octree", theta=0.5)
B = oersted.b_field(mesh, mesh.centroids, jdensity=jdensity, settings=settings)

# Compute forces from self-fields 
F = oersted.lorentz_forces(mesh, jdensity, B)

Features

This library provides Barnes-Hut-accelerated volume integral methods for computing magnetic fields generated by current-carrying solid conductors and magnetic materials:

  • Methods for meshing STEP files (via gmsh)
  • Analytic Biot-Savart integrals for current-carrying and magnetized tetrahedrons
  • A 'point' fields source, which is orders of magnitude faster and highly accurate for far-field and force calculations
  • Barnes-Hut/octree methods for reducing the time complexity of Biot-Savart law integration from O(N^2) to near-linear, allowing the solution of multi-million element models in seconds on a laptop
  • A basic iterative solver for isotropic linear materials (mu_r < 20.0)
  • Force calculations using the Maxwell stress tensor (surface-based), Kelvin, or Lorentz (volumetric) formulations

Roadmap

This project is under active development and will be changing quite a bit on its way to a stable 1.0.0 release:

  • v0.1.0
    • Octree acceleration for both analytic and point approximations of finite element sources
  • v0.2.0
    • Dramatic simplification of the library and internal/external API's
    • Tetrahedra meshing and force calculations
  • v0.3.0
    • Solid angle calculations to replace the edge-integral formulations for fields from 3D elements (2-4x speed improvement)
  • v0.4.0
    • Convert octree methods from recursive to interaction lists (2-5x speed improvement)
    • Refactor library for ease of use and maintainability
  • v0.5.0
    • GMRES solver for high-permeability materials
    • Eddy current solver for low-frequency time domain problems
  • v0.6.0
    • Symmetry boundary conditions
    • Multi-material meshes
    • BH curves for nonlinear magnetic materials
  • v0.7.0
    • Steady-state conduction solver
  • v0.8.0
    • Eddy current solver for frequency-domain problems
  • v0.9.0
    • 3D GUI (e.g. integrated with ONELAB)

Background

The Biot-Savart Law is widely used to calculate the magnetic fields of electromagnets by summing the contributions of many small magnetic field sources at a large number of target points. This calculation, in its simplest form, has time complexity of O(M x N), where M is the number of source points and N is the number of target points.

Barnes-Hut Algorithm

This code applies the Barnes Hut algorithm for large-N interaction problems to achieve linear time complexity of the same calculation while maintaining reasonable (<1%) error relative to the full ("direct") calculation.

This library uses an octree, which is a tree structure that divides the problem space recursively into 8 octants. Each octant hosts a collection of source points, which are summed together at each node. If the distance between the node and a target point is far enough away such that treating the many source points within the node as one large "super source", the node is 'accepted' and an approximate calculation is performed. If the node is too close, then it is recursively subdivided and the same acceptance criteria is applied again. In practice, an acceptance criteria of phi = node_size/distance = 0.5 has been found to be effective for self-fields problems.

See https://jheer.github.io/barnes-hut/ for an excellent demo of the algorithm applied to gravitational problems.

Intended Problems

The intended problem for this code is a finite element mesh of a solenoidal collection of current-carrying 3D bodies. The magnetic field generated by these currents can either be computed on the bodies themselves (self-field) or at a collection of points not on the bodies. Each element is treated as a component of a finite sum approximation to the Biot Savart integral.

Problem sizes typically solved on a workstation computer (i.e. finite element meshes of <10M elements) are considered for testing of this code.

Contributing

Please contact the author prior to making a pull request.

License

MIT or Apache 2.0, at your option.

Release files for oersted 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for oersted 0.4.0
File Size Uploaded
oersted-0.4.0.tar.gz 1.6 MB Details

Built distributions (wheels)

Table of built distributions (wheels) for oersted 0.4.0
File
oersted-0.4.0-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details
oersted-0.4.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.10 abi3 Linux glibc 2.17+ x86-64 Details
oersted-0.4.0-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details
oersted-0.4.0-cp310-abi3-macosx_10_12_x86_64.whl CPython 3.10 abi3 macOS 10.12+ x86-64 Details

Total release size: 4.4 MB

Release files / oersted-0.4.0.tar.gz

Download URL oersted-0.4.0.tar.gz
Size 1.6 MB
Tags Source
SHA-256 checksum
How to use checksums
b539ddbb55fde315d86436339309e502e9c605e7f3e742f05996a938f6e9251d
BLAKE2b-256 checksum
How to use checksums
a6ba3178b72c18492e7b2ad2ba0ebe64e675cb21d1b895567c942ba76c1868d3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.30 {"installer":{"name":"uv","version":"0.11.30","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / oersted-0.4.0-cp310-abi3-win_amd64.whl

Download URL oersted-0.4.0-cp310-abi3-win_amd64.whl
Size 273.3 kB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
3e04c8e3a1b472128d81008cc01e03281d7661534b6156a11654155ecb5b0fbe
BLAKE2b-256 checksum
How to use checksums
f76680a96a9a9a0e89ed9266f93f167b06edf9b13037f79336b4bd31b8c84a52
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.30 {"installer":{"name":"uv","version":"0.11.30","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / oersted-0.4.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL oersted-0.4.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.8 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
dd601e4981dbdbe412896984109b84c25dc6380a278d4813319641b0784b02cb
BLAKE2b-256 checksum
How to use checksums
2d47d2bc903f143f1b662a8477506c1b33494dd101ab8118b5865b30154a19fa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.30 {"installer":{"name":"uv","version":"0.11.30","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / oersted-0.4.0-cp310-abi3-macosx_11_0_arm64.whl

Download URL oersted-0.4.0-cp310-abi3-macosx_11_0_arm64.whl
Size 353.1 kB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
b8736f07a2b014eb93c003d9da94188f7016f6c3dea9a6f00ec43c6030ce746c
BLAKE2b-256 checksum
How to use checksums
678063fa7d51aa397b4d6fcb05195f5d56a8ca76450bd2337c7a8b1f9529c1ef
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.30 {"installer":{"name":"uv","version":"0.11.30","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / oersted-0.4.0-cp310-abi3-macosx_10_12_x86_64.whl

Download URL oersted-0.4.0-cp310-abi3-macosx_10_12_x86_64.whl
Size 369.0 kB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
83fa44bfc5e185fd2cf2fdad50444e1078cae630f94399ce0604f05cb5fd0be2
BLAKE2b-256 checksum
How to use checksums
07ed1a815bd6e55da6cf841e24516ecdb4364a7d1de3b96d30ac27d8e1e91e0f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.30 {"installer":{"name":"uv","version":"0.11.30","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

This release

0.4.0 This release

5 release files

0.3.0

5 release files

0.2.0

5 release files

0.1.0

5 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page