Skip to main content

Lightning-fast magnetic fields calculations

Project description

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.

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

oersted-0.4.0.tar.gz (1.6 MB view details)

Uploaded Source

Built Distributions

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

oersted-0.4.0-cp310-abi3-win_amd64.whl (273.3 kB view details)

Uploaded CPython 3.10+Windows x86-64

oersted-0.4.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ x86-64

oersted-0.4.0-cp310-abi3-macosx_11_0_arm64.whl (353.1 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

oersted-0.4.0-cp310-abi3-macosx_10_12_x86_64.whl (369.0 kB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

Details for the file oersted-0.4.0.tar.gz.

File metadata

  • Download URL: oersted-0.4.0.tar.gz
  • Upload date:
  • Size: 1.6 MB
  • Tags: Source
  • Uploaded using 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}

File hashes

Hashes for oersted-0.4.0.tar.gz
Algorithm Hash digest
SHA256 b539ddbb55fde315d86436339309e502e9c605e7f3e742f05996a938f6e9251d
MD5 d7bbc3367e4737af3668c15960300b10
BLAKE2b-256 a6ba3178b72c18492e7b2ad2ba0ebe64e675cb21d1b895567c942ba76c1868d3

See more details on using hashes here.

File details

Details for the file oersted-0.4.0-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: oersted-0.4.0-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 273.3 kB
  • Tags: CPython 3.10+, Windows x86-64
  • Uploaded using 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}

File hashes

Hashes for oersted-0.4.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 3e04c8e3a1b472128d81008cc01e03281d7661534b6156a11654155ecb5b0fbe
MD5 9d7e28a326168adf9068cbfa0157b7dd
BLAKE2b-256 f76680a96a9a9a0e89ed9266f93f167b06edf9b13037f79336b4bd31b8c84a52

See more details on using hashes here.

File details

Details for the file oersted-0.4.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

  • Download URL: oersted-0.4.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 1.8 MB
  • Tags: CPython 3.10+, manylinux: glibc 2.17+ x86-64
  • Uploaded using 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}

File hashes

Hashes for oersted-0.4.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 dd601e4981dbdbe412896984109b84c25dc6380a278d4813319641b0784b02cb
MD5 243b8f0b0d82c383299fc90361274510
BLAKE2b-256 2d47d2bc903f143f1b662a8477506c1b33494dd101ab8118b5865b30154a19fa

See more details on using hashes here.

File details

Details for the file oersted-0.4.0-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

  • Download URL: oersted-0.4.0-cp310-abi3-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 353.1 kB
  • Tags: CPython 3.10+, macOS 11.0+ ARM64
  • Uploaded using 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}

File hashes

Hashes for oersted-0.4.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b8736f07a2b014eb93c003d9da94188f7016f6c3dea9a6f00ec43c6030ce746c
MD5 cf3c26fbacd1a7590c9e4c805d0de26d
BLAKE2b-256 678063fa7d51aa397b4d6fcb05195f5d56a8ca76450bd2337c7a8b1f9529c1ef

See more details on using hashes here.

File details

Details for the file oersted-0.4.0-cp310-abi3-macosx_10_12_x86_64.whl.

File metadata

  • Download URL: oersted-0.4.0-cp310-abi3-macosx_10_12_x86_64.whl
  • Upload date:
  • Size: 369.0 kB
  • Tags: CPython 3.10+, macOS 10.12+ x86-64
  • Uploaded using 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}

File hashes

Hashes for oersted-0.4.0-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 83fa44bfc5e185fd2cf2fdad50444e1078cae630f94399ce0604f05cb5fd0be2
MD5 b7e78dc586a6b07ab5d62d250183ba5f
BLAKE2b-256 07ed1a815bd6e55da6cf841e24516ecdb4364a7d1de3b96d30ac27d8e1e91e0f

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