Off-axis magnetic fields for coils and solenoids
Project description
rustpycoils
Python wrapper around rustycoils.
This module provides an implementation of an algorithm for finding the off-axis magnetic field of solenoidal systems of current loops.
An analytic solution to the ideal wire loop is readily available and can be computed using elliptical integrals which are also readily available in libraries such as scipy. To approximate other solenoidal magnetic field systems, such as solenoids and Helmholtz coils, this basic primitive can be duplicated however this will start to slow down as more primitives are added. Additionally provided the magnetic field is only required to be accurately known close to the central axis of symmetry a faster power series method can be employed to determine the field for any system for which the on-axis magnetic field is known.
This module impliments the primitive objects discussed in Off-axis expansion solution of Laplace's equation: Application to accurate and rapid calculation of coil magnetic fields which crucially have analytic derivatives to arbitrary powers allowing for fast and accurate higher order derivatives of the total magnetic field to be computed. Using these primitives to build up the total system allows for magnetic systems of coils to be accurately and rapidly be computed close to the axis.
Install
Can install using PyPi
pip install rustpycoils
If pipy does not contain the binaries for your system wheels can be built using maturin, which requires a Rust compiler.
git clone https://github.com/jdrtommey/rustpycoils/
cd rustpycoils
maturin build --release
Range of Applicitability
This is not a general alternative for modules such as magpylib which offer analytic expressions for magnetic fields based on primitives, and provided there is no material response, give exact solutions. It is instead useful when a magnetic field with cylindrical symmetry is being calculated, which needs to be computed fast for a region close to the central axis. This can be highlighted by comparing the speed of the algorithm against the analytical provided in magpylib for the ideal wire loop. The test uses a wire loop with a radius of 1m and a current of 1A.
Speed comparision
As can be seen inset in the left-hand figure this library can compute the magnetic field of a single position around 200 times faster (performed on 4-core 1.4Ghz Intel i5 MacBook pro). The speed then continues to scale better, particularily after around 4000 positions. The speed increase is more dramatic when more wire loops are included in the calculation, such as to model a solenoid or a pair of helmholtz coils. This is shown on the right where the magnetic field is computed at a single location at the center of the coils as the number of coils increases.
Accuracy Comparison
However, caution needs to be taken to ensure this algorithm is used correctly. Unlike the solution provided by elliptical integrals, this algorthim is not accurate everywhere. The paper from which this library is derived claims accuracies of around 0.1% can be achieved at radial positions 70% of the radius.
The agreement between the two libraries for both the axial (left) and radial (right) magnetic fields for positions which are located 70cm away from the middle of the wire loop. The agreement between the two codes saturates at around 1e-8% due to the discreprency in the definition of the vacuum permeability, where magpylib appears to be using 4π e-7 H/m, while this module uses 1.25663706212 e-6 H/m.
The agreement for a wide range of axial and radial positions is shown below:
Up to around 20% of the radius of the coil the agreement is at the level of agreement in the vacuum permiability. For radial positions approaching, and larger than, the radius the algorithm performs very poorly unless located very far away along the axial direction. These comparisons only show the accuracies for the given input parameters however they give a good idea of the range of applicability of this aproach.
Usage
The module exposes a single class
import rustycoils
#object containing primitives sharing a symmetry axis
mycoil = AxialSystem()
which defines a symmetry axis. Currently this symmetry axis can only be defined along the three cartesian axes (defaults to x). Eventually this will be arbitrary.
mycoil.transform_x()
mycoil.transform_y()
mycoil.transform_z()
Individual primitive coils can be added to the AxialSystem with a unique string identifier. The units are SI with radius,thickness,length and position in metres and current in Amperes. Positions of primitives relative to the AxialSystem are given from one end for the primitives with length, i.e., a 5m long solenoid at position 2m extends from 2m to 7m.
#define physical parameters
radius = 1.0
thickness = 0.1
current = 1.0
length = 5.0
position = 2.0 //position along the symmetry axis
mycoil.add_loop("loop1",radius,position,current)
mycoil.add_annular("foo",radius,thickness,position,current)
mycoil.add_solenoid("bar",radius,length,position,length)
mycoil.add_coil("coil1",radius,length,thickness,position,current)
The parameters controlling these primitives can be be modified by using the functions
#change radius of the current loop
mycoil.modify_radius("loop1",6.0) "loop1"
#change length of the solenoid "bar"
mycoil.modify_length("bar",3.0)
#change length of the coil "coil1"
mycoil.modify_position("coil1",3.0)
#change thickness of the annular "foo"
mycoil.modify_thickness("foo",1.0)
#change current of the annular "foo"
mycoil.modify_current("foo",1.0)
These functions accept keywords to modify multiple primitives at once. Note these keywords can not be used as identifiers for primitives.
Reserved word | Meaning |
---|---|
* | Apply to all |
LOOP | Apply to current loops |
ANNULAR | Apply to annulars |
SOLENOID | Apply to solenoids |
COIL | Apply to coils |
#changes all the current of all primitives
mycoil.modify_current("*",6.0)
#changes all the current of all current loop primitives
mycoil.modify_current("LOOP",6.0)
#changes all the radius of all annnlar primitives
mycoil.modify_radius("ANNULAR",6.0)
#changes all the length of all solenoid primitives
mycoil.modify_length("SOLENOID",6.0)
#changes all the length of all coil primitives
mycoil.modify_thickness("COIL",6.0)
The magnetic field in each of the cartesian directions can be computed using an input of a numpy array. Currently requires a 2D numpy array to work which is a little tedious for a single field value.
fields = mycoil.get_field(np.asarray([x,y,z]).reshape(3,-1),1e-18)
where 1e-18 is the tolerance to stop including additional terms in the power expansion.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file rustpycoils-0.1.0.tar.gz
.
File metadata
- Download URL: rustpycoils-0.1.0.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a491b3ada25bdfb4459dd59e5c636e0f6831c02ca261f40829345dc79efe291e |
|
MD5 | c4a5d28a8d2e662649c770f72701d52e |
|
BLAKE2b-256 | d099060e7f4879255eb6176eaf495450da4f3d6a32a8c1c6f6f8500d54160c5c |
File details
Details for the file rustpycoils-0.1.0-pp37-pypy37_pp73-manylinux2010_x86_64.whl
.
File metadata
- Download URL: rustpycoils-0.1.0-pp37-pypy37_pp73-manylinux2010_x86_64.whl
- Upload date:
- Size: 1.0 MB
- Tags: PyPy, manylinux: glibc 2.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2454f5d41970831462df58e8bc6453a9a0913602872ac235ccdc2a17e5f43750 |
|
MD5 | 2a1872f4bab2466aebf39266e25f03ac |
|
BLAKE2b-256 | 956a81a3ca63100bed13aa12356cc03b8670a3780ac6011d640da4a031eb08fe |
File details
Details for the file rustpycoils-0.1.0-pp37-pypy37_pp73-manylinux1_x86_64.whl
.
File metadata
- Download URL: rustpycoils-0.1.0-pp37-pypy37_pp73-manylinux1_x86_64.whl
- Upload date:
- Size: 1.0 MB
- Tags: PyPy
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6d6d9569acad7070732b80dec0bac5a86e5dc7ab8bac169e9c339ef6e522c60d |
|
MD5 | f7219a2ce08f855b0534c0c2ed02fb62 |
|
BLAKE2b-256 | caa1a4f7460e0e75c306b681c8a475101963c1816cf009131354186ae6420524 |
File details
Details for the file rustpycoils-0.1.0-pp37-pypy37_pp73-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: rustpycoils-0.1.0-pp37-pypy37_pp73-macosx_10_9_x86_64.whl
- Upload date:
- Size: 310.4 kB
- Tags: PyPy, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0748ae08e44be41b6240b39c78d2ae1e6f67c2c91955b44fbf1529d451b4a037 |
|
MD5 | 1b7523603c27014724d7b48367d72d7f |
|
BLAKE2b-256 | ebb5bba3de952e394e7ea3547eb009da2d7a51cde34aaa8aac049bcdbb4b88fa |
File details
Details for the file rustpycoils-0.1.0-pp36-pypy36_pp73-manylinux2010_x86_64.whl
.
File metadata
- Download URL: rustpycoils-0.1.0-pp36-pypy36_pp73-manylinux2010_x86_64.whl
- Upload date:
- Size: 1.0 MB
- Tags: PyPy, manylinux: glibc 2.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7dfd4dd7cedafd01bd5c04a5f1ac57e6382753fa119b04da6d0cd74bf89afe33 |
|
MD5 | c5bae1a667452a3da8bba02adecded77 |
|
BLAKE2b-256 | 0cab0ffe97a57cf94cbc621ad5ef4469a9940a22c1db39a329abb3b3c051eb86 |
File details
Details for the file rustpycoils-0.1.0-pp36-pypy36_pp73-manylinux1_x86_64.whl
.
File metadata
- Download URL: rustpycoils-0.1.0-pp36-pypy36_pp73-manylinux1_x86_64.whl
- Upload date:
- Size: 1.0 MB
- Tags: PyPy
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 98d31cdaa12c3888cc7e1f41df482e7f391f6efe8566c31b2e5efafea062864a |
|
MD5 | 8cbb48f2a34a1cef0207de1d68d4238b |
|
BLAKE2b-256 | 0f26b121a2bd00ee7d82ce14cd0b9461003f39bcda42e4597c450d80aaf9a11f |
File details
Details for the file rustpycoils-0.1.0-pp36-pypy36_pp73-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: rustpycoils-0.1.0-pp36-pypy36_pp73-macosx_10_9_x86_64.whl
- Upload date:
- Size: 310.4 kB
- Tags: PyPy, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | faa71328a6dc8db16385274e74e7af2afb415c9c333586cad43de78e828cbe20 |
|
MD5 | 8d16b9a4270206aff875fedb19c290a5 |
|
BLAKE2b-256 | dab763ef3204052e667d1af7579277ec5053fd3d046fb022acdd0c3fc321b11c |
File details
Details for the file rustpycoils-0.1.0-cp39-cp39-manylinux2010_x86_64.whl
.
File metadata
- Download URL: rustpycoils-0.1.0-cp39-cp39-manylinux2010_x86_64.whl
- Upload date:
- Size: 1.0 MB
- Tags: CPython 3.9, manylinux: glibc 2.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 66eeff5552c2c969e7feaaa4479d1bc451af78717d0bc156ae1f8853b74faa37 |
|
MD5 | ea3faaf572ac401fb5c87d85205f39f8 |
|
BLAKE2b-256 | ec4ac5d674ff483be5fbb9b9a3e0a512fa64ca9d5f7e4632ec51af8c6d78935d |
File details
Details for the file rustpycoils-0.1.0-cp39-cp39-manylinux1_x86_64.whl
.
File metadata
- Download URL: rustpycoils-0.1.0-cp39-cp39-manylinux1_x86_64.whl
- Upload date:
- Size: 1.0 MB
- Tags: CPython 3.9
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b48a3136d5866b423587bd9463c7ed79da80043eb059da35c4c01267a6401d08 |
|
MD5 | 70f3a3ee0c69e527c3f7f296d86c7b35 |
|
BLAKE2b-256 | 2d9bbd251bf244a963916c7d2b4d32e94011cfce0c6c6727f9df6128165feec7 |
File details
Details for the file rustpycoils-0.1.0-cp39-cp39-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: rustpycoils-0.1.0-cp39-cp39-macosx_10_9_x86_64.whl
- Upload date:
- Size: 310.4 kB
- Tags: CPython 3.9, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9561ca7c6fb7d5f2bee3fdbbb4b0857af23fb95150f1d38ec911eca32744da40 |
|
MD5 | 8ba4e5a1e5b3210374c1b42e98baa9a3 |
|
BLAKE2b-256 | 4b26883f46a7f6b2784d04a87ed3dffa7be85cdf52bd26ddfbb309ccd1176d96 |
File details
Details for the file rustpycoils-0.1.0-cp38-cp38-manylinux2010_x86_64.whl
.
File metadata
- Download URL: rustpycoils-0.1.0-cp38-cp38-manylinux2010_x86_64.whl
- Upload date:
- Size: 1.0 MB
- Tags: CPython 3.8, manylinux: glibc 2.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d5cf3282bbcb2dc37769c489f3734e32eda3911bc2cd12a22f2267bb1f2a1849 |
|
MD5 | 0ded2f181e77d90427cf72509231dfe0 |
|
BLAKE2b-256 | ddcd95374695a72537eb69f3e92974f87f5c4df3f4e5ea09d9e7e0b314b290ee |
File details
Details for the file rustpycoils-0.1.0-cp38-cp38-manylinux1_x86_64.whl
.
File metadata
- Download URL: rustpycoils-0.1.0-cp38-cp38-manylinux1_x86_64.whl
- Upload date:
- Size: 1.0 MB
- Tags: CPython 3.8
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c6d51697e0170860e8a28c1283c43d9e44848b6275982b300b2b7ce98275c8ac |
|
MD5 | 00ffdd0372ef6711752f990fdb5d0751 |
|
BLAKE2b-256 | 6daf4598aa3053d14e6a6169b9057d31f00204e43a8bf2c4ad25460e109dcc24 |
File details
Details for the file rustpycoils-0.1.0-cp38-cp38-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: rustpycoils-0.1.0-cp38-cp38-macosx_10_9_x86_64.whl
- Upload date:
- Size: 310.3 kB
- Tags: CPython 3.8, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 26afc5af5f69cd71e0dd5a9eaf9a1232a4434589031bea79707dc562388e5183 |
|
MD5 | 24899f7d3ddbdeeee4844b6ca409bba1 |
|
BLAKE2b-256 | 3b49d1bbaa0b4d09501bbf6b4ac0f83d86cd9ddae13476ba0cabdf66ffd00cf5 |
File details
Details for the file rustpycoils-0.1.0-cp37-cp37m-manylinux2010_x86_64.whl
.
File metadata
- Download URL: rustpycoils-0.1.0-cp37-cp37m-manylinux2010_x86_64.whl
- Upload date:
- Size: 1.0 MB
- Tags: CPython 3.7m, manylinux: glibc 2.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 664e86a5933a659879ab71f6ff9f597bfbb766c5187afad6f8f1f965fd4462a3 |
|
MD5 | 758b477560b6d107ddba1ee7926cabb2 |
|
BLAKE2b-256 | 89ecb8333816f60b4a3ced8882c2638ca46c18abd39dd674eda0f1c3c838e3be |
File details
Details for the file rustpycoils-0.1.0-cp37-cp37m-manylinux1_x86_64.whl
.
File metadata
- Download URL: rustpycoils-0.1.0-cp37-cp37m-manylinux1_x86_64.whl
- Upload date:
- Size: 1.0 MB
- Tags: CPython 3.7m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ab9de09da1770960200f764d5aa320dcae78f64fb214246bb25e90a340dfdd4f |
|
MD5 | f36d5b9f277058a9541280310a14c73c |
|
BLAKE2b-256 | cc28d79c861f4e30f4e007b22f9021913b9a878e156c25af97cc111702d2293b |
File details
Details for the file rustpycoils-0.1.0-cp37-cp37m-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: rustpycoils-0.1.0-cp37-cp37m-macosx_10_9_x86_64.whl
- Upload date:
- Size: 310.4 kB
- Tags: CPython 3.7m, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 66f23f47482ce38cc921713d0a68db18285aea0e8d6149fedb0dc516fa51dd87 |
|
MD5 | 73bc99ee777a80b0d0e16003eb51b89c |
|
BLAKE2b-256 | 7bf3005d6fdb20da7dc3ccdea98efd7c60617382529e97d739432a5f066a42b1 |
File details
Details for the file rustpycoils-0.1.0-cp36-cp36m-manylinux2010_x86_64.whl
.
File metadata
- Download URL: rustpycoils-0.1.0-cp36-cp36m-manylinux2010_x86_64.whl
- Upload date:
- Size: 1.0 MB
- Tags: CPython 3.6m, manylinux: glibc 2.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 01fd375d3121876a00518f19fe48ff47b75cdd63018ac73f6efe2b851359dce5 |
|
MD5 | 48fdaafe8cef38e5a78925859ef94bae |
|
BLAKE2b-256 | 7ae3ff9970edb07dee46c5a87b5eb1ce8ab2070384171dfab1baf35066511bbf |
File details
Details for the file rustpycoils-0.1.0-cp36-cp36m-manylinux1_x86_64.whl
.
File metadata
- Download URL: rustpycoils-0.1.0-cp36-cp36m-manylinux1_x86_64.whl
- Upload date:
- Size: 1.0 MB
- Tags: CPython 3.6m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 18c67d4a2ca7e3b9629cfb4f20e4a4ae22c06f237ac6d475082a105a3a6e9867 |
|
MD5 | c9e43a46b315eb566a45f756b4a2cfc5 |
|
BLAKE2b-256 | 791a7a0ab79775e7f1ea13eb239e6b8d81a5ff61fb9ea3c019704941e61b9a77 |
File details
Details for the file rustpycoils-0.1.0-cp36-cp36m-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: rustpycoils-0.1.0-cp36-cp36m-macosx_10_9_x86_64.whl
- Upload date:
- Size: 310.2 kB
- Tags: CPython 3.6m, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dd9c31417c2fea363b9dc79cf35846c074ce9d46fef01127f280c128821dca25 |
|
MD5 | 29e6e2b6ee9b392e868c62581f677454 |
|
BLAKE2b-256 | 5a29d68f4627d05570bccaf448503e84d78a7b9b3829bc1d9a8939e00228bc31 |