The magnetic scalar potential $U(r\u20d7)$ has an intuitive physical interpretation, representing the electric current *I* = Δ*U*, which must be directed between any pair of isocontours along the boundary of a region, differing in potential by Δ*U*, in order to generate the corresponding magnetic intensity $H\u20d7=\u2212\u2207\u20d7U$ inside the region with no tangential component outside the boundary. This physical significance is exploited to invert the design process of hermetic (fringeless) electromagnetic coils from standard iterative techniques (calculating the magnetic field of refined current distributions) to a procedure for calculating the exact surface currents required to generate a given field configuration. A practical construction algorithm is given to produce the prescribed field in a “Target” region (constrained only by Maxwell’s equations) while confining the fringe field to a specified hermetic “Return” region. Example coils are analyzed along with a discussion of the limits of precision of the constructed field.

## I. INTRODUCTION

The practical use of magnetism often requires the design of a current-carrying collection of wires (a “coil”) that creates a specified magnetic field. Some examples are the following: (a) NMR requires a very uniform field so that a spin precesses at the same rate no matter where it may be in the experimental volume;^{1,2} searches for the electric dipole moment of the neutron^{3} require gradients smaller than 1 pT/cm.^{4,5} (b) Transporting polarized atoms or neutrons^{6} requires a holding field that varies slowly with position in a specified way so that the spin can follow the field adiabatically. (c) Active magnetic shielding can be constructed to cancel the field of a fixed source;^{7} accurate cancellation requires an accurately designed shield. (d) Guiding particle beams while maintaining stability of the trajectory and pulse duration requires a field with specified magnetic moments.^{8,9} The characteristic problem requires a magnetic field $B\u20d7(r\u20d7)$ of the specified form within a “Target” volume to a stated tolerance. Of course, the desired field will have to obey the conditions

(since it would be undesirable to have currents inside the region of study) and

where the fields $B\u20d7$ and $H\u20d7$ are related by a constitutive equation, for example, a proportionality $B\u20d7=\mu H\u20d7$. In much of what follows, it will be assumed that *μ* = *μ*_{0} everywhere, although, in general, *μ* can represent any nonlinear inhomogeneous constitutive relation, including remnant fields or hysteresis.

In general, there must be a surrounding “Return” region, since the components of the magnetic field normal to the surface of the Target cannot be canceled. It is usually desirable (but not required for this method) that the Return is a bounded region and that no field extends outside these regions (a hermetic coil), both to prevent the created field from interfering with other devices and to avoid having magnetizable objects outside the coil become part of the magnetic system (see Fig. 1). The current-carrying wires are on surfaces at the boundary between the Target and the Return, on the exterior surface of the Return, and possibly on other surfaces dividing the Target and the Return into disjoint regions.

The traditional workflow for designing coils involves starting with a basic design, calculating the magnetic field, and iterating changes to the windings to converge on the desired field configuration. Many techniques exist in the literature^{10} for streamlining this process, for example, (a) through the use of basis current loops to optimize the target field numerically,^{11–16} either solving the linear system of equations for the currents or optimizing nonlinear coil parameters. The progression from a single coil to the Helmholtz^{17,18} and Maxwell^{19} arrangements is the ancestor of this approach and has been extended to higher harmonics.^{20} Since the field and currents are related by linear equations, this method is sure to work, but the relationship between the desired field and the required coil is only as clear as one’s understanding of an integral equation involving a tensor Green function. Surface and bulk current distributions have been described as fictitious magnetization densities,^{21–24} which can take an arbitrary form in the limit of infinitesimal dipoles. Various optimization procedures include variational principles^{16,24} and linear programming.^{15} In problems with either real or fictitious magnetization density, the net pole density plays the role of electric charge in an analogous boundary value problem to that of the electric field.^{21,25–27} For real current distributions, stream functions specify the resulting discontinuity of the scalar potential,^{2,28,29} which has also been applied to eddy currents,^{30} and the analysis of fields^{31,32} showed that any volume containing surface currents can be divided into topologically simple regions in which the scalar potential is well-defined. This technique has been applied in cylindrical, spherical, and planar geometries to calculate surface current windings of coils with minimized higher order multipoles.^{9,27}

This paper describes a construction algorithm, based on a physical interpretation of the magnetic scalar potential, that can create any field $B\u20d7(r\u20d7)$ satisfying (1) and (2) within any set of Target regions and with only weak physical constraints on the boundaries and necessary Return regions derived from (1) and (2), although practical and technical considerations such as ease of construction, tolerance requirements, and power management add further constraints. These will be discussed subsequently. The particular focus is on extremely well characterized fields, with relative variation as little as 10^{−6} from the design field, with tight geometric constraints on where currents may be placed. This method inverts the process of magnet design by starting from the desired field and calculating the required windings on specified surfaces to produce this field.

Because this technique involves the design of surface current coils, it is applicable to low-field precision coils with low enough current densities that they may be formed as a single layer of conducting strips or wires, still dissipating an acceptable amount of power. This limits the field to about 100 G (although larger for superconductors), but the generalization to multiple layers is straightforward. The intuitive interpretation of the magnetic scalar potential underlying this approach simplifies visualization of general electromagnetic coils and the currents required to generate their field.

## II. THE MAGNETIC SCALAR POTENTIAL AND THE CONSTRUCTIVE ALGORITHM BASED ON IT

### A. Theory

Inside a region with no currents, Eq. (1) implies that we can construct a magnetic scalar potential *U* such that

Within the Target, the field $H\u20d7$ is completely specified (this is the starting point for the problem to be solved), and thus, we are given *U* for that region. The fields in the Return must have the same normal component of $B\u20d7$ at the interface with the Target and vanishing normal component of $B\u20d7$ at the exterior surfaces for a hermetic coil (with no exterior fringes). Other exterior constraints are possible, such as *U* being a constant in patches of the boundary where surface currents are prohibited.

In order to explain how these are connected and determine the coil windings needed to relate them, it is convenient to introduce (conceptually) a thin layer between adjacent regions and ascribe windings to the surface of each region separately. The property of this “Transition” region will be that the $H\u20d7$ field is normal to the two surfaces; there is no tangential field. Thus, the magnetic scalar potential on the Transition side of the surface does not vary as one moves along the surface and thus is a constant at the surfaces of the Target and the Return that can be set to zero by making the Transition arbitrary thin; thus, we can avoid having to make a detailed study of it. Some mechanical designs benefit from a finite width transition.^{37}

Now, consider the scalar potential within the Target. Construct a set of equipotential surfaces that correspond to values of the scalar potential that differ by multiples of a small constant amount Δ*U*. The neighboring equipotential surfaces cannot intersect, and they separate the boundary of the region into ribbons that form closed loops (Fig. 2). The magnetic field will, in general, have a component parallel to the boundary, while within the Transition region it does not by construction; thus, there is a current sheet on the ribbon. Its magnitude is determined according to the integral form of Ampere’s law,

For a path near the surface that encircles a ribbon, the part of the path inside the Target gives the difference in the magnetic scalar potential; since the field is normal to the surface in the Transition, there is no contribution. Thus, the current in the ribbon is given by^{9,28,33,34}

the difference in potential between the two edges of the ribbon.

Another route to the same relationship starts from the differential form of Ampere’s Law $\u2207\u20d7\xd7H\u20d7=J\u20d7$. This implies^{35} a surface current density $J\u20d7=\delta (n)K\u20d7$ at tangential discontinuities in $H\u20d7$: integration across the surface of the discontinuity yields

where $n\u0302$ is the outward normal to the surface and Δ represents the outward minus inward field. For discontinuities on the surface of the target, the Transition field is already normal to the surface and thus makes no contribution, so

which explicitly flows along contours of constant magnetic potential. Integration across contours on the surface yields Eq. (5). The sense of direction is as follows: while walking on the outside surface of the Target (or other region) in the direction of positive current, Δ*U* equals the right minus left equipotential (*U* increases to the right).

The flux continuity equation deriving from $\u2207\u20d7\u22c5B\u20d7=0$ includes fields in the Transition,

The general boundary conditions (6) and (8) are discrete versions of the magnetic Maxwell equations.

The fields in the Return can also be described by a magnetic scalar potential *U*′, which satisfies the Laplace equation

At the boundaries, the normal component of $B\u20d7$ is specified (Neumann boundary conditions): at the boundary with the Target, the normal component of $B\u20d7$ is given by the normal component of $B\u20d7$ in the Target from (8); at the exterior boundary, the normal component of $B\u20d7$ is zero, since there is no field outside the Return. Dirichlet boundary conditions may be substituted on a portion of either boundary to constrain a region with specified surface currents (for example, no current); however, this will result in slight modifications of the specified fields in the Target or leakage fields out of the Return. By the uniqueness and existence theorem for Laplace’s equation, this boundary value problem determines the magnetic scalar potential up to an irrelevant additive constant; it can be found numerically using commercial finite element analysis packages.^{36} As in the case of the Target, the equipotentials of *U*′ slice up the boundary of the Return into closed ribbons, which carry current *I*′ = Δ*U*′ to cancel the tangential field just outside the boundary.

The result of this construction algorithm is a coil assembly in the form of a surface current density flowing in closed loops along the equipotential lines that can create a magnetic field of an arbitrary form [consistent with the homogeneous Maxwell’s Eqs. (1) and (2)] within the Target and with no field escaping beyond the Return. The solution is unique, once the shape of the Return is chosen.

The introduction of the Transition layer separates the boundary conditions for the Target from those for the Return, allowing for a simple physical interpretation of the scalar potential, which is local to each region. The way *U* and *U*′ is defined directly determines the surface current density on the boundaries so that these prescribe the coil windings in the actual device. It should be noted that the potentials in the various regions are not continuous across the boundary and are related only by Eqs. (6) and (8). Figure 3 shows the magnetic scalar potentials that encode the fields shown in Fig. 1.

Another utility of separating the transverse boundary condition with a Transition between each region is that the branching distribution of wires at each inter-edge (junction path) of 3 or more regions is automatically handled by winding separate currents around each region. In some cases, it is advantageous to combine the Target and Return portions of current along adjacent sides of the boundary into a single set of windings calculated by discretizing the combined potential *U* − *U*′; however, in these cases, junction currents must be handed by manually splitting the currents^{37} or double-winding on a separate boundary, such as the end caps of a single-wound double-cylinder coil.^{6}

The essential point is that the magnetic scalar potential *U* has a direct physical meaning: its series of equipotential contours on the boundary of a region represents the path of source windings and the amount of current needed to generate the field $H\u20d7=\u2212\u2207\u20d7U$ within that region. In particular, the current flows along the isocontours of *U*, and the total current flowing between any two isocontours of values *U*_{1} and *U*_{2} is equal to *I* = *U*_{1} − *U*_{2}. These windings and their corresponding contours of the scalar potential form an “electric fence,” which terminates the transverse component $n\u0302\xd7H\u20d7$ at the boundary, leaving only the normal component to pass through the Transition to the next region. Fencing in the fields of all regions, which share magnetic flux lines, establishes an electromagnetic coil that not only guides the magnetic field but also generates it. However, if the windings from one region are omitted, then, the field will not be normal in its adjacent Transitions, invalidating this interpretation of the scalar potential in the surrounding regions.

In fact, this physical interpretation scalar potential extends beyond the boundary conditions of any fiducial region. If the region is separated by a membrane, the winding contours apply to both sub-regions. Since the windings cross in opposite directions on the membrane, they cancel, yielding the same net current in the combined region. Repeating this procedure, the entire equipotential surface represents a mesh of region-independent infinitesimal current loops, which reduce à la Stokes’ theorem to a current loop around the contour on the physical boundary. This completes the generalized “currents” interpretation of *U* and by extension $H\u20d7$.

The magnetic scalar potential describes the free current analog of bound surface currents, which effectively circulate around the boundary of regions of magnetic material when the magnetization field $M\u20d7(r\u20d7)$ is irrotational. This accounts for the similarities in bound and unbound design techniques: the $M\u20d7$ field represents an actual mesh of real physical current loops vs the virtual mesh represented by $H\u20d7=\u2212\u2207\u20d7U$. In either case, the curl of $H\u20d7$ or $M\u20d7$ represents the termination of partial meshes along current flux lines in the bulk instead of extending all the way to the boundary of the region so that the meshes can no longer be considered isosurfaces of a single-valued scalar potential. As an example of the parallel relationship, a Dirichlet boundary condition on the magnetic scalar potential and its corresponding surface currents can be represented by a magnetic dipole layer^{27} similar to $M\u20d7$, just as an electric dipole layer generates a discontinuity in the electric potential.

An alternative to winding surface currents along the Return is to replace the Return with a shell of ferromagnetic material (*μ* → ∞) thick enough not to become saturated, which satisfies the same condition $n\u0302\xd7H\u20d7=0$ on the outside boundary of the shell as was imposed in the Transition.^{33} Physical windings in the Return are replaced by magnetization currents of the medium, which eliminates the need for solving a boundary value problem in the Return. Inside the ferromagnetic Return, windings are only required along equipotentials of the Target region. For a uniform field, the inner contours lie on equidistant parallel planes. This explains the surprising effectiveness of the “magic box,”^{38} a rectangular shielded coil wound in this geometry. In addition, if the Target field is normal to the Return everywhere along the boundary (the Dirichlet boundary condition *U* = constant) then, the inner windings also vanish almost everywhere except between the north and south pole tips where magnetic flux reverses between entering and exiting the Target. In this case, the method reduces to the common practice of shaping pole tips along the equipotential surfaces of various field configurations, for example, pure multipoles.^{39}

A completely hermetic coil may be impractical, for example, if holes or gaps are required in the surface current coil for access to the interior. This can also be specified by the Dirichlet boundary condition *U* = constant on portions of the boundary. However, since the uniqueness and existence theorem requires exactly one boundary condition at each point on the boundary, the flux through the boundary cannot be constrained, and the coil will have fringes either in the Target or outside the Return, near this portion of the boundary.

Conversely, the Neumann “zero flux” boundary condition $n\u0302\u22c5\u2207\u20d7U=0$, where the magnetic field is parallel to the surface and is automatically satisfied by a perfect diamagnet (*μ* = 0) such as a superconductor. The magnetization or supercurrents will confine the flux inside the boundary of the region, again without the need for calculating windings.

The scalar potential method for determining the winding geometry of a coil extends naturally to regions with spatially varying magnetization, either expressed as local permeability $\mu (r\u20d7)$ and/or permanent magnetization $M\u20d7(r\u20d7)$ by replacing Laplace’s equation with

with the addition of a magnetic charge density source term $\rho M=\u2212\mu 0\u2207\u20d7\u22c5M\u20d70$, where $M\u20d70$ is the portion of magnetization not included in *μ*. This commonly used equation is the analog of electrostatic problems, with the boundary condition Eq. (8) also including the flux source term $\sigma M=\u2212n\u0302\u22c5M\u20d70$. Even with these other terms, the magnetic scalar potential *U* still represents the free currents, which must be wound along the boundary to generate the corresponding field. Modern FEA software^{36} is able to solve this equation with nonlinear permeability and even in materials exhibiting hysteresis, extending this technique for calculating the electromagnetic windings to a broad class of realistic physical situations involving ponderable media.

Interior surface currents $K\u20d7$ or discontinuities in *μ* necessitate partitioning the volume into separate regions $Ri$ with potentials *U*_{i} related by the continuity Eqs. (6) and (8). In some cases, it may be desirable or necessary to separate the Target or Return into several compartments with a current layer in between each one. This allows a larger field for the same current by avoiding surfaces where the magnetic field has a large change in the tangential component. In the case of the Target, where the internal fields are completely specified, the boundary conditions require continuity of the normal component of $B\u20d7$ and determine the bounding current $K\u20d7$ from the discontinuity in $n\u0302\xd7H\u20d7$. In the case of the Return, any current sheet on the interface between different regions of the Return is indeterminate and $K\u20d7$ must be specified in the continuity boundary conditions Eqs. (6) and (8) between the potentials of each region, which are then solved as one boundary value problem.

Finally, this technique can be used to design electromagnetic coils around pre-existing windings of current density $J\u20d7(r\u20d7)$, which do not admit the scalar potential. They can be accommodated by solving

for the vector potential $A\u20d7(r\u20d7)$ in the region containing $J\u20d7$, simultaneously solving for *U* in the remaining volume, replacing Eqs. (6) and (8) with the modified continuity equations to the surrounding scalar potential,^{40}

where $K\u20d7$ is any fixed current on the boundary and $n\u0302$ points toward the region described by *U*. The surrounding region may need to be split up to avoid it linking around current, which would make *U* multivalued. If the scalar potential completely encloses the current-carrying regions, then, the additional surface current windings are still obtained from the isocontours of the scalar potential. Otherwise, exterior boundaries of the vector potential can be wrapped by an infinitesimally thin region of scalar potential to transfer the boundary conditions to *U*, which naturally represents the winding contours on the entire surface. The surface currents can also be obtained directly from the boundary condition

### B. Practice

For a practical coil, the current will be discretized into either (a) a three-dimensional printed circuit board^{41,42} with solid ribbons of conductor between pairs of equipotential contours such that the current density in each ribbon approximates a step function, as determined by Ohm’s law, or (b) wires wound along each equipotential contour carrying all of the current assigned between it and the contour of the next wire. While traces have a smoother current density, which better approximate the continuous distribution, wire windings have a more precisely known current density (a delta function at each wire). In contrast, the exact current distribution along traces of finite width depends on the variations in the resistivity and thickness along the traces and the geometry, such as curves in the traces.

The discretization from a continuous current density $K(r\u20d7)$ to either a step function of constant valued *K* across each ribbon or a delta function of constant current *I* in each wire causes an alteration of the field inside the Target near the boundary, which falls off as one goes away from the boundary, with a scale length comparable to the wire spacing *D*. The discrete current can be represented as the sum of the current distribution it is meant to represent and a set of currents that vary on various wavelengths—for example, the Fourier representation for currents on a plane or a sum of spherical harmonics for currents on the surface of a sphere. These give fields that vary as power laws, growing most rapidly near the surface. In practice, one minimizes the residual fields by tuning the actual location of each winding about the position indicated by the uniformly spaced-equipotential rule so as to suppress the longest-wavelength variations. A possible design places the wire at the barycenter of current in each ribbon.^{43}

The coil as constructed by this algorithm consists of independent closed loops, each carrying the same current. These can be connected together in series, allowing the entire boundary to be wound with a single wire, by winding around the highest *U*-contour first, then crossing over to the next contour with a short leader, winding that contour, and so on to the end. After winding the last contour, the wire is traced back along each leader to cancel the current that is not part of the real solution.^{44} The two ends of the wire are now near the same point to be connected to the current supply power by a twisted pair or coaxial line. This process of joining the loops into a series must be done for each region of nonzero field to obtain a complete coil producing the desired field in the Target.

This strategy of following the equipotential line and joining to the next contour at a step avoids a pair of problems. Evening out the displacement (as is done in a helically wound solenoid) introduces a new surface current parallel to the magnetic field. This will give an error field in the interior, except for rotationally symmetric windings. In any case, the current has to be in a complete circuit; having wound around the Target, there has to be a connection back to the power supply. The field due to one wire circling back will depend on the wire spacing *D* and the distance *R* of the return wire from the target *δH* ≈ *I*/*R* so that *RδH*/*H* ≈ *D*/*R* ≈ 10^{−3}. Having the return current right over the steps joining the turns allows one problem to solve the other.

The cancellation of the field of the crossing leaders is only first order, replacing the *H*_{1} ≈ *I*/2*πr* field of the string of leaders by a line of dipoles with a field *H*_{2} ≈ *Iδ*/*r*^{2} where *δ* is the average separation between the leaders and the current return line (*δ* can be smaller than the average spacing *D* between wires, but is comparable to it). To put these estimates in context, the field in the Target is *H*_{0} ≈ *I*/*D*; for a coarsely wound coil, the wire spacing is of order 10^{−2} the smallest dimension of the coil so that *H*_{1} ≈ 10^{−2}*H*_{0} and *H*_{2} ≈ 10^{−4}*H*_{0}.

A different rule for designing a wound coil is discussed in a companion paper.^{45}

The following continues to describe the coil as if it were the collection of loops, while asserting that the practical implementation as a series circuit is a negligible change.

## III. SOME EXAMPLES

The technique described above is applicable to arbitrary geometries and target fields. In Secs. III A and III B, we describe standard coils with symmetric geometry and easy-to-visualize magnetic potentials as an illustration of how their winding geometry becomes immediately apparent as isocontours of the potential. Some nontrivial extensions and practical applications are described through their corresponding boundary value problems for example, active shielding in Sec. III C.

### A. Solenoid

A uniform magnetic field has regularly spaced parallel planar equipotentials. An infinite solenoid of arbitrary fixed cross section will have uniform axial field *H* = *I*/*D* if the coil is wound with current *I* around the perimeter of cross sectional slices with spacing *D* normal to the field lines. Segments of straight solenoid can be joined to produce a “bent solenoid.” Let the bend angle (change in direction) be 2*α*, then, the intersection of the two cylinders is an ellipse in the plane whose normal is tilted by the angle *α* from the field lines in either segment. At the interface, the equipotentials are parallel lines along the plane of intersection, perpendicular to the field lines on either side. The overlapping contours on the interface from both cylinder segments have current in the same direction and generate a planar current density $K=2IDsin\u2061\alpha $, which kinks the field, reversing the tangential component of $H\u20d7$ across the interface.^{41} This gives a straightforward geometric interpretation of a lengthy calculation based on Biot–Savart integration,^{46} which applies to solenoids of any cross section.

A finite solenoid with uniform field inside can be constructed by adding current-carrying end caps. The current distribution on the end caps is calculated by solving the scalar potential in the infinite region outside the solenoid with constant flux boundary conditions at each end face. The field just outside the cylindrical surface of the solenoid is in the opposite direction to the constant field inside the solenoid, and therefore, the outside windings are in the same direction as the inside ones. The equipotentials outside are closest together near the ends, indicating a higher current density at the ends to prevent fringing inside the finite-length solenoid. Circular windings are also needed on the end faces to maintain uniformity inside the solenoid.

### B. Cos-theta coil

A uniform magnetic field $x\u0302H0$ perpendicular to the axis $(z\u0302)$ of a circular cylinder of radius *A* has the potential *U* = −*H*_{0}*x* = −*H*_{0}*ρ* cos *ϕ*, giving rise to the name “cos-theta coil.” This can be created with inner longitudinal windings of equal spacing in *x* and current *I* = *H*_{0}Δ*x* along the cylinder. The field outside the cylinder is described by the potential *U*′ = *H*_{0}(*A*^{2}/*ρ*)cos *ϕ* = *H*_{0}*x*(*A*/*ρ*)^{2}. Thus, the outer windings have exactly the same current as the inside windings, resulting in double the total surface current, which can be combined into a single winding. This infinitely long design has an infinite radius Return.

For a Return in the form of a larger concentric cylinder of radius *B*, the potential *U*′ = *H*_{0}*A*^{2}(*B*^{2}/*ρ* + *ρ*)cos *ϕ*/(*B*^{2} − *A*^{2}) has zero flux escaping the outer cylinder. The uniform inner field and the return flux are shown in Fig. 4. The infinite cylinder solution is well known^{43} and can also be calculated by considering a second cos-theta coil of radius *B* with the opposite magnetic moment $HAA2=\u2212HBB2=(A\u22122\u2212B\u22122)\u22121H0$, where *H*_{A,B} are the interior fields of cos-theta coils of radii *A* and *B* with current densities *K*_{A,B} = 2*H*_{A,B} cos *ϕ* such that the total interior field is $x\u0302H0$ while the net external dipole field is canceled. However, it is the physical interpretation of the magnetic scalar potential that immediately yields the winding configuration required to truncate the double-cos-theta coil to a finite length while preserving *z*-symmetry: the cylindrical Target and Return are wound on equally spaced contours of *U* and *U*′, respectively. The windings on the end caps are illustrated in Fig. 4, and each wire on the end cap continues longitudinally down the cylinder after it reaches the inside/outside edge. Ascribing separate boundaries and windings to each region simplifies the winding patterns at edges where three or more regions meet compared to single windings in which current must be diverted in multiple directions at the junction. The design of a transverse adiabatic radio frequency spin rotator based on this finite double-cos-theta coil is described in Ref. 37.

### C. Active magnetic shield

This is the inverse of a magnetic coil in that it cancels, not creates, a magnetic field, but the technique is the same. Given a surrounding field due to external flux sources and nearby magnetic materials, an active shield can be designed as a hermetic field cancellation coil on a closed surface outside the shielded area. If the flux through this surface is nulled, then, the field will be canceled everywhere inside the shield. This can be accomplished by solving a boundary value problem for *U* in the region outside this boundary surface that either (a) includes all exterior sources and has a vanishing normal component of $B\u20d7$ at the surface or (b) for linear materials has no external sources but is given the opposite flux as that being canceled at the boundary. The external region may contain permeable materials or even current sources as discussed above. The resulting contours of constant potential on the boundary indicate how to wind the shielding coil for most effective field cancellation and efficient use of power. The coil can be wound fairly coarsely since the field penetration will rapidly decrease on the length scale given by the wire spacing. Separate coils can be calculated independently for individual sources of flux, or separate coils can be designed using the scalar potential to cancel each multipole of the background field for actively tuning the shield.

## IV. LIMITATIONS

The attainable accuracy of the resulting field in a realization is determined by the deviations from the assumptions of the theory. Here is a brief discussion of the leading concerns:

### A. Geometrical accuracy of the construction of the coil

Misplacement of a wire from its ideal position by *δx* over a span *Y* creates an error field of the dipolar form with magnitude *δH*/*H* ≈ *δxDY*/*R*^{3} at distance *R* from the wire (*D* is the spacing between wires. The extra factor *D*/*R* is the fractional contribution of one wire to the total field). Since *D* and *δx* will typically be of order 10^{−3}*R*, this might be ignorable, but a systematic displacement of a region will give coherently adding errors. For example, shifting the windings of an infinite solenoid of radius *A* by a distance *δx* in a finite region of length *L* gives an effect equivalent to an extra turn carrying current *Iδx*/*D* at the two ends of the region and gives rise to an error field of magnitude *Iδx*/*DA*. The wire form must be accurately constructed, and care be taken that the wire follows the intended path, especially at corners.

### B. Effects of the conversion of independent loops to a series-connected coil

As already noted, this gives a dipolar field of order *δH*/*H* ≈ 10^{−4}. Weaving the step and the return current lines to give alternating sign dipoles might decrease this by another factor of 10^{−2} but would not be practical in many construction techniques. Another option is to double wind the coil, spiraling up and then down again; this cancels the effects of the conversion to a helical winding in a uniform way, again at the cost of complexity.

The current has to be in a complete circuit; having wound around the Target, there has to be a connection back to the power supply. The field due to one wire circling back will depend on the wire spacing *D* and the distance *R* of the return wire from the target *δH* ≈ *I*/*R* so that *δH*/*H* ≈ *D*/*R* ≈ 10^{−3}. The schemes discussed in the previous paragraph avoid this error. An alternate scheme is discussed in Ref. 45.

### C. Discretization of the current sheet

As discussed above, this is exponentially suppressed so that the disturbance falls off as exp(−2*πz*/*D*) as one moves away from the surface. For an infinite planar array of parallel wires with spacing *D*, the error field at distance 2*D* is of order exp(−4*π*) = 3 × 10^{−6}; the exponential suppression assumes that discrete wires differ from the surface current density required by the algorithm only by a periodic correction. The discreteness becomes important where the wires are widely spaced because the scale length becomes large, or when the width varies, so that the exponential form is invalid. For example, the winding on a sphere to give a uniform field inside has the wires widely spaced toward the poles with the result that the field is inaccurately produced there.^{47}

### D. Maximum field

For normal metals, the largest attainable field is set by the limit on surface heating/area *P* ≈ *ρK*^{2}/*t* ≈ *ρH*^{2}/*t*, where *ρ* is the resistivity of the windings and *t* is the effective thickness of the winding layer. For a power density limit *P* = 1 W/cm^{2}mm, thickness *t* = 1 mm, and resistivity *ρ* ≈ 1 *μ*Ω cm, the maximum field is *H* < 400 Oe. For a superconducting winding, the limit is set by the critical field.

## V. CONCLUSION

The physical interpretation of the magnetic scalar potential is that its contours on the boundary of a region play the role of an electric fence that confines the tangential component of the field or terminates it to zero outside the region, shearing all magnetic flux lines to exit normal to the boundary. This interpretation is the basis for a general technique that gives a rational and systematic way to construct a hermetic electromagnet that provides a designed field to an accuracy limited only by the discreteness error coming from winding with wires, the accuracy of its construction, and the need to wind as a coil, rather than a collection of disconnected loops.

## ACKNOWLEDGMENTS

The author would like to thank Professor Joseph P. Straley for fruitful conversations. This work was supported, in part, by the U.S. Department of Energy, Office of Nuclear Physics, under Contract Nos. DE-SC0008107 and DE-SC0014622 and by the National Science Foundation under Award No. PHY-0855584.

## AUTHOR DECLARATIONS

### Conflict of Interest

No conflicts of interest to disclose.

## DATA AVAILABILITY

Data sharing is not applicable to this article as no new data were created or analyzed in this study.