Wolfram Language Paclet Repository
Community-contributed installable additions to the Wolfram Language
Create simple, discrete coils using current-carrying loops, saddles or ellipses to generate magnetic fields
Contributed by: Noah Hardwicke, Peter J. Hobson, Michael Packer
Create simple coils made from cylindrical loop, saddle, or ellipse-based primitives, optimised to generate a target magnetic field harmonic. Visualise and examine the coils and the magnetic fields they generate.
CreateCoil implements the theoretical model derived in Designing optimal loop, saddle, and ellipse-based magnetic coils by spherical harmonic mapping.
We will soon be adding the ability to export coil data and field data, so check back for updates!
To install this paclet in your Wolfram Language environment,
evaluate this code:
PacletInstall["NoahH/CreateCoil"]
To load the code after installation, evaluate this code:
Needs["NoahH`CreateCoil`"]
Compare the uniform axial Bz field (encoded as the B1,0 field harmonic) generated by a Helmholtz pair, and by three optimised pairs of loops covering the same axial extent:
| In[1]:= | ![]() |
| Out[1]= |
| In[2]:= | ![]() |
| Out[3]= | ![]() |
Optimise a saddle coil and an ellipse coil to generate the uniform transverse Bx field (encoded as the B1,1 field harmonic):
| In[4]:= | ![]() |
| Out[4]= | ![]() |
Visualise the coils as 2D schematics:
| In[5]:= | ![]() |
| Out[5]= | ![]() |
Visualise the coils as 3D plots. Colour each ellipse primitive differently to distinguish them more easily:
| In[6]:= | ![]() |
| Out[6]= | ![]() |
Plot the Bx field component generated by each coil in the xz-plane:
| In[7]:= | ![]() |
| Out[7]= | ![]() |
The search domain can be constrained to account for physical constraints. Optimise a loop coil of three pairs to generate the B2,0 field harmonic, with axial separations constrained between 0.5 and 1 times the coil radius:
| In[8]:= |
| Out[8]= | ![]() |
| In[9]:= |
| Out[9]= | ![]() |
When the mouse hovers over a wire in a 2D or 3D coil plot, all other wires belonging to the same coil primitive are highlighted, and a tooltip shows the parameters describing that primitive:

By default, FindLoopCoil, FindSaddleCoil, and FindEllipseCoil null one fewer leading-order error field harmonics than there are coil parameters, meaning that solutions lie on a 1D contour embedded in a solution space whose dimensionality is equal to the number of coil parameters. Points are found on the solution contour by searching over a coarse mesh of search seeds. These points are interpolated to produce a fine mesh of search seeds, which yield the final set of solutions:
| In[10]:= |
| In[11]:= |
| Out[11]= | ![]() |
The solutions are then ranked by the ratio of the desired-to-leading-order error field harmonic magnitudes.
Specifying fewer field harmonics to be nulled results in a solution contour of higher dimensionality. Use three saddle primitives to null only one field harmonic, and the solution contour is a 2D surface embedded in a 3D space:
| In[12]:= |
| In[13]:= |
| Out[13]= | ![]() |
Although the interpolation algorithm works for arbitrary solution contour and search space dimensions, it is currently only optimised for a 1D solution contour (the default and most useful case).
Wolfram Language Version 13.0
Creative Commons Attribution Non Commercial 3.0 Unported