Coils.nb - magnetic fields from coaxial coils

Authors: Mike Gehm <mgehm@phy.duke.edu>, Michael Stenner <mstenner@phy.duke.edu>
Version: 1.3
Date: 2004-05-18

This Mathematica notebook calculates the magnetic field from sets of coils.  You must evaluate the "Definitions" section first.  See the "Description" section for help and examples.

This notebook was originally written by Mike Gehm and was modified by Michael Stenner.

Definitions

Constants

μ0 = 4 Pi* 10^-3;

Calculation Functions

These functions calculate the radial and axial field for a single coil.

Bz[r_, z_, coil_] := 
      coil[[3]] * 
        coil[[4]] *((μ0 /(2 Pi))/(Sqrt[(((coil[[1]]  +  r))^2) +  (((z - coil[[2]]))^2)])) * (EllipticK[((4 coil[[1]] r)/((((coil[[1]] + r))^2) + (((z - coil[[2]]))^2)))]  +  (((coil[[1]]^2  -  (r^2)  -  (((z - coil[[2]]))^2))/((((coil[[1]] - r))^2) + (((z - coil[[2]]))^2))))*EllipticE[((4 coil[[1]] r)/((((coil[[1]] + r))^2) + (((z - coil[[2]]))^2)))])

Br[r_, z_, coil_] := 
      coil[[3]]*
        coil[[4]]* (z - 
            coil[[2]])*((μ0 /(2 Pi r) )/(Sqrt[(((coil[[1]]  +  r))^2) +  (((z - coil[[2]]))^2)]))* (-EllipticK[((4 coil[[1]] r)/((((coil[[1]] + r))^2) + (((z - coil[[2]]))^2)))]  +  (((coil[[1]]^2  +  (r^2)  +  (((z - coil[[2]]))^2))/((((coil[[1]] - r))^2) + (((z - coil[[2]]))^2))))*
              EllipticE[((4 coil[[1]] r)/((((coil[[1]] + r))^2) + (((z - coil[[2]]))^2)))])

These functions calculate the field for all of the coils listed in "coils".

AxialField[r_, z_, coils_] := 
      Module[{}, 
        TempFunc[coil_] := Bz[r, z, coil]; 
Plus @@ 
          Map[TempFunc, coils, {1}]]

RadialField[r_, z_, coils_] := 
      Module[{}, 
        TempFunc[coil_] := Br[r, z, coil]; 
Plus @@ 
          Map[TempFunc, coils, {1}]]

This function calculates the field magnitude at any point using the previous functions.

FieldMag[r_, z_, coils_] := 
      If[r == 0, 
        AxialField[r, z, 
          coils], (Sqrt[AxialField[r, z, coils]^2 + RadialField[r, z, coils]^2])]

Tools for generating "coils" list

WithTurns[precoil_, turns_] := 
      Module[{}, 
        TempFunc[coil_] := Append[coil, turns]; 
Map[
          TempFunc, precoil, {1}]]

WithCurrent[precoil_, current_] := 
      Module[{}, 
        TempFunc[coil_] := Append[coil, current]; 
Map[
          TempFunc, precoil, {1}]]

WithTurnsAndCurrent[precoil_, turns_, current_] := 
      WithCurrent[WithTurns[precoil, turns], current]

Helmholtz[r_, z_, turns_, 
        current_] := {{r, -z, turns, current}, {r, z, turns, 
          current}}
AntiHelmholtz[r_, z_, turns_, 
        current_] := {{r, -z, turns, -current}, {r, z, turns, 
          current}}
TrueHelmholtz[z_, turns_, current_] := 
      Helmholtz[2 z, z, turns, current]
TrueAntiHelmholtz[z_, turns_, current_] := 
      AntiHelmholtz[2 z, z, turns, current]

Description

What this notebook does

This notebook calculates the magnetic field at any point in space for an arbitrary number of coils.  Each coil can have a different position, size, number of turns, and current.  The one restriction is that all coils must share the same axis.

How to use this notebook

First, you must make your "coils" list.  This is a list of lists.  You have one internal list for each coil.  Each of these internal coil (singular) lists contains the radius of the coil (in meters), the position of the coil (in meters), the number of turns, and the current (in Amperes).  The following coils list defines one coil with a radius of 10 cm, position of z = 5 cm, 100 turns, and a 1 mA current.

ExampleCoils  =  {{ .1,   .05,  100,   .001}};

Once this is defined, you can determine the axial field (parallel to z), radial field (perpendicular to z), and field magnitude at any point (r, z) with
the functions: AxialField, RadialField, and FieldMag.  each of these functions takes r, z, and your coils list.  All of these functions return the magnetic field in Gauss.  Example:

Plot[
        AxialField[0, z,  
          ExampleCoils],  {z,  - .1,   .1}];

Generating coils lists

There are several functions to help you generate coils lists.  

The function "Helmholtz" takes  the parameters for a coil list (r, z, turns, current) and returns a coils list with two identical coils.  One has the parameters you specified, and the other has a position of -z.

The function "TrueHelmholtz" takes the same parameters except that it does not take a radius.  The radius is automatically set to 2z.

The functions "AntiHelmholtz" and "TrueAntiHelmholtz" work identically except that the mirror coil has the opposite current.

ExampleCoils  =  
        AntiHelmholtz[ .4,   .15,  
          100,   .001];
Plot[
        AxialField[0, z,  
          ExampleCoils],  {z,  - .1,   .1}];

There are also functions for helping generate a list of several coils with the same current or number of turns.  To use these functions, create a "precoils" list without the current or without both current and turns.

ExamplePreCoils = {{ .1, - .1},  { .1,   .1}}

NewExamplePreCoils = WithTurns[ExamplePreCoils,  30]

ExampleCoils = WithCurrent[NewExamplePreCoils,   .4]

Or simply

ExampleCoils = 
      WithTurnsAndCurrent[ExamplePreCoils,  30,   .4]

Function Summary

coils = {{(Subscript[rad, 1]), (Subscript[z, 1]), (Subscript[turns, 1]), (Subscript[I, 1])},  {(Subscript[rad, 2]), (Subscript[z, 2]), 
          (Subscript[turns, 2]), (Subscript[I, 2])},   ... }
coils = Helmholtz[rad, z, turns, I]
coils = TrueHelmholtz[z, turns, I]
coils = AntiHelmholtz[rad, z, turns, I]
coils = TrueAntiHelmholtz[z, turns, I]
coils = WithCurrent[precoils, I]       (where precoils is a coils list with the current missing)
precoils = WithTurns[preprecoils, turns]     (where preprecoils is a coils list with both currents and turns missing)

AxialField[r, z, coils]
RadialField[r, z, coils]
FieldMag[r, z, coils]

Example

List of coils.  Each coil is a list of (coil radius, coil z position, number of turns, and current).  Distances are in meters, and current in Amperes.

coils = 
        Helmholtz[12.25* .0254, 6.125* .0254, 30, 
          1];
RadiusOfInterest =  .1;
Plot[
        AxialField[0, z, coils], {z, -RadiusOfInterest, 
          RadiusOfInterest}, 
        PlotRange -> All];
Plot[
        AxialField[r, 0, coils], {r, -RadiusOfInterest, 
          RadiusOfInterest}, PlotRange -> All];