Skip to main content

Lightning-fast magnetic fields calculations

Project description

oersted

Approximate Biot-Savart Law integration to calculate magnetic fields in near-linear time using octrees and the Barnes Hut algorithm.

Documentation | Rust API

Timing Results

Installation

oersted can be installed via pypi:

pip install oersted

Example

import oersted 

# Assume the following NumPy arrays are already defined: 
# centroids: Nx3 element centroid locations
# vol: N-length, volume of each element 
# jdensity: Nx3 elemental current-density vectors 
# targets: Nx3 target point locations in 3D space 

theta = 0.25        # B-H accuracy parameter

# Compute the magnetic flux density at each target
b = oersted.bfield_octree(
    centroids, vol, jdensity, targets, theta=theta
)

Background

This is a prototype code and not meant for production applications.

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.

Effectively, the program 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.

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.2.0.tar.gz (1.5 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.2.0-cp310-abi3-win_amd64.whl (320.5 kB view details)

Uploaded CPython 3.10+Windows x86-64

oersted-0.2.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (442.3 kB view details)

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

oersted-0.2.0-cp310-abi3-macosx_11_0_arm64.whl (384.4 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

oersted-0.2.0-cp310-abi3-macosx_10_12_x86_64.whl (408.0 kB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: oersted-0.2.0.tar.gz
  • Upload date:
  • Size: 1.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","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.2.0.tar.gz
Algorithm Hash digest
SHA256 1ab1f0424e357ccaa4403523dc83c2a3f8a53082c6113af65c4a6fb3a766a41b
MD5 fa3bc48c13f340828158db84398b3e5d
BLAKE2b-256 89e64bedfe5695c1a2e6d6a4365165bd21a3929b859c878904c5246791a818d9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: oersted-0.2.0-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 320.5 kB
  • Tags: CPython 3.10+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","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.2.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 07cd52ee20fd20830e92b914a9bcddc269652159577b686f24b5d6998f815095
MD5 a87cb7d452411f408b64d8a2bcae459d
BLAKE2b-256 225403c226fc9dfbed233a237cbafe601218a577f8c78734341b8948e330dc13

See more details on using hashes here.

File details

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

File metadata

  • Download URL: oersted-0.2.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 442.3 kB
  • Tags: CPython 3.10+, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","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.2.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b6be184cb1ac5f2942c3bdc8940b0cd9591631ed529393995d711db534426e6b
MD5 86ae0231ef73777cd0232a09692640d9
BLAKE2b-256 73af823f6785a41da76bda9e700e73beb9c1c8ad9803278cc0aff18e0e84cf5b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: oersted-0.2.0-cp310-abi3-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 384.4 kB
  • Tags: CPython 3.10+, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","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.2.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0a5eceec42ef46667d57675e017e0158ac14c125aa78b20d48db86c7458c5dac
MD5 d61b5e19395c2d7f02420f1914f33279
BLAKE2b-256 f8c6ca7c1394b73d05f38fb60af1f211f1d398c6ca183a300b067d2a20d1355f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: oersted-0.2.0-cp310-abi3-macosx_10_12_x86_64.whl
  • Upload date:
  • Size: 408.0 kB
  • Tags: CPython 3.10+, macOS 10.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","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.2.0-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 f7e28857a34746e4fd62923ff1f09af14d1f0c66fe3d8a7efbfdd85a71803457
MD5 17cc916100e23975cb9b119192d9760a
BLAKE2b-256 a029d2c20da18f020f821545db29d7ea784effc50ab123dfbda02a407feafbec

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