Coils Utilities Library (CULib) is a Python package for modeling air-core electromagnet coils and calculating their physical characteristics based on their geometry and wire informations.
Project description
CULib
Coils Utilities Library (CULib) is a Python package for modeling air-core electromagnet coils and calculating their physical characteristics based on their geometry and wire informations. It also includes functions for calculating and plotting static magnetic field in 3D or in 1D along their central axis.
CULib allows integration of "real-life" characteristics, such as :
- Coil thickness (because of an external radius and internal radius) and coil length
- Number of turns calculation based on coil geometrical dimensions for a given wire size and shape
- Wire size declaration based on standard AWG sizes, mm, or custom definition (i.e : squared section wire, foil wire... )
- Automatic recalculation of coils parameters in case of modification of geometric params or wire type (useful for wire selection and recalculation of all params based on suppliers capabilities)
- Calculation of voltage and power needed based on current injected and resistance calculation
- Temperature effect on wire resistivity and coil resistance/power
- Estimation of self-inductance and time constant
Supported coil shapes : Circular and Rectangular
Examples
import culib as cul
mycoil = cul.CircularCoil(
axis = 'x_mm', # Axis of revolution (x axis in mm)
r_in_mm = 14, # Inner coil radius (in mm)
r_out_mm = 20, # Outer coil radius (in mm)
L_mm = 32, # Coil length (in mm)
pos_mm = -8, # Position of coil center on axis (in mm) (voluntarily offsetted here)
cur_A = 3.2, # Current applied (in A)
wire = cul.RoundWire(awg=22), # Wire def. via Wire object, defined with AWG 22 (American Wire Gauge)
)
# Print all coil characteristics
print(mycoil)
# Calc and plot field in 1D
df_field = cul.init_df_field()
df_field = mycoil.calc_field(df_field)
cul.plot_field(df_field, axis='x_mm', Baxis='Bx_total_mT')
Installation
Via pip
-
Type the following in your venv
pip install culib
-
Then import in your code
import culib as cul
-
You're ready to use CULib
Requirements
CULib requires Python >= 3.11 and the packages listed below
Note : packages will be automatically installed by using pip as described on the previous step Installation
Altair and vl-convert
CULib uses Altair for plotting charts. It uses version >= 5.0 for its support for saving chart as .png easily with vl-convert. Using versions below 5.0 will work for displaying and saving as .html, but saving charts as .png might cause issues.
SciPy
Required for specific calculations on 3D fields from analytic formulas.
Numpy and Pandas
Standards for science, they are also part of requirements for SciPy and Altair.
Some specificities
Units
All parameters reprensenting a physical characteristic contain the unit at the end of its name. Drawback is that it's a bit verbose, but at least it is self-explanatory and will help avoiding stupid mistakes due to conversions.
Examples :
x_mm: position in x axis in mmBx_total_mT: Magnetic field flux density for x component in mT ("total"meaning it's the sum of every contributors to x component)mycoil.res_ohm: resistance in Ohmmycoil.temp_degC: temperature in degrees Celsiusmycoil.cur_A: coil current in Amperemycoil.wire.d_in_mm: Wire inner diameter (without insulation) in mm...
Auto recalc when changing a coil or wire parameter
At the object creation, attributes that can be deducted from the given parameters are automatically calculated. Equations have been arranged in a way that, from given inputs, outputs can be calculated without conflicts.
You can then access a coil or wire parameter via print(mycoil.res_ohm)
Updating one parameter via mycoil.r_in_mm = 12 will trigger the recalc of all parameters depending on it if mycoil.is_autorecalc is True (True by default).
Example :
>>> mycoil = cul.CircularCoil(
... axis = 'x_mm', # Axis of revolution (x axis in mm)
... r_in_mm = 14, # Inner coil radius (in mm)
... r_out_mm = 40, # Outer coil radius (in mm)
... L_mm = 32, # Coil length (in mm)
... pos_mm = 0, # Position of coil center on axis (in mm)
... cur_A = 3.2, # Current applied (in A)
... wire=cul.RoundWire(awg=22), # Wire definition via Wire object, with AWG number 22
... )
>>> print(mycoil.res_ohm)
12.792006481231436
>>> mycoil.r_out_mm = 35 # Decrease the outer radius of your coil (from 40mm to 35mm)
>>> print(mycoil.res_ohm)
9.559168241965974
References
Physics
Most equations and reasonings for characteristics calculation in this package are based on work from Jake J. Abbott :
- Jake J. Abbott; "Parametric design of tri-axial nested Helmholtz coils", Review of Scientific Instruments vol. 86 no. 5 p. 054701, May 2015, doi: 10.1063/1.4919400
Field spatial expressions are based on work from :
- David Jiles; "Introduction to Magnetism and Magnetic Materials", Section I) 1.3.4 page 24, Year 2016, CRC Press, ISBN : 978-1-4822-3887-7
- S. Hampton, R. A. Lane, R. M. Hedlof, R. E. Phillips, C. A. Ordonez; "Closed-form expressions for the magnetic fields of rectangular and circular finite-length solenoids and current loops", AIP Advances 10, 065320 (2020), June 2020, doi: 10.1063/5.0010982
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 Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file culib-0.5.1.tar.gz.
File metadata
- Download URL: culib-0.5.1.tar.gz
- Upload date:
- Size: 837.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.25 {"installer":{"name":"uv","version":"0.9.25","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ebe1b73bbf40aa5d6b202dc9f34b874095efc3a3303b9f46b1939d5bef08adef
|
|
| MD5 |
0fa0713b0b7a73b5d770a5722104471c
|
|
| BLAKE2b-256 |
1f45b6b14028bd461e56d8a37920916c221d08b0ad63d640f2c1879af6acf15e
|
File details
Details for the file culib-0.5.1-py3-none-any.whl.
File metadata
- Download URL: culib-0.5.1-py3-none-any.whl
- Upload date:
- Size: 85.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.25 {"installer":{"name":"uv","version":"0.9.25","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
134a6bc3305db8045960f0126a7f5449f61db15cf88df4ec42778f94ff52ec9a
|
|
| MD5 |
3e8abe7a31e500e376be4cf24684a771
|
|
| BLAKE2b-256 |
29a37aebec422dda3f71ff3ad354a4226a3738f514efea8394df30c82ae2eb33
|