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.1.0.tar.gz (339.9 kB view details)

Uploaded Source

Built Distributions

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

oersted-0.1.0-cp310-abi3-win_amd64.whl (279.1 kB view details)

Uploaded CPython 3.10+Windows x86-64

oersted-0.1.0-cp310-abi3-macosx_11_0_arm64.whl (348.5 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

oersted-0.1.0-cp310-abi3-macosx_10_12_x86_64.whl (365.7 kB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

oersted-0.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (393.8 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

File details

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

File metadata

  • Download URL: oersted-0.1.0.tar.gz
  • Upload date:
  • Size: 339.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","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.1.0.tar.gz
Algorithm Hash digest
SHA256 acda823f3d2b6d28df678d5d530e1169f7380a917f51692a15d69f3e0c4f5b59
MD5 de4cca40deeed134d2e32255b6c1ba55
BLAKE2b-256 9160aa9361a981621a617db8c385268b6e4a6106089a3a64ce989a5ada68b436

See more details on using hashes here.

File details

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

File metadata

  • Download URL: oersted-0.1.0-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 279.1 kB
  • Tags: CPython 3.10+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","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.1.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 f710e11745264f36df3627ac0b6401a325264482010846c02eb02c94a7163006
MD5 9ef11d236e1cda9c50dba413e939e025
BLAKE2b-256 b224ec9d0175c611b02f28d099c32c3fa5d641f89a285ce4e87a38373ae2ef6c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: oersted-0.1.0-cp310-abi3-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 348.5 kB
  • Tags: CPython 3.10+, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","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.1.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0b741400c022f13169409f22194d8f3c0f05690c669ec8617405f3dda26e3ce7
MD5 ceb3f69f46492f9d1157dc6ed4fa6c35
BLAKE2b-256 4a2d81d018eccaf866511443584c65933578ca977fe5a3b12995e6139df16fe2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: oersted-0.1.0-cp310-abi3-macosx_10_12_x86_64.whl
  • Upload date:
  • Size: 365.7 kB
  • Tags: CPython 3.10+, macOS 10.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","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.1.0-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 71c35a162d2a4fa2570e32e694beb14fa26278bfefb667e83dd8028075b4d5ef
MD5 dd868d1cf2b5f92ab64eaa862a73a203
BLAKE2b-256 a75020d4a3119fe2074b439655dfd63de1d7dbf0ca503d18dd7b11f114888c9c

See more details on using hashes here.

File details

Details for the file oersted-0.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

  • Download URL: oersted-0.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 393.8 kB
  • Tags: CPython 3.8, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","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.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e5c26b244d4b70636332781f3365a25990fd135f9034533e666723b08074bec0
MD5 93c57be8ef54b67f2b9ebcf2e61270fa
BLAKE2b-256 b2f4d8db100d84401aaffa24d4245058803fdf852413ef17c5cf4796b6ddcf0b

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