Planar Conductors#

Many practical current-carrying structures, such as those found in PCBs (Printed Circuit Boards), are planar conductors—traces confined to a flat layer. These conductors are common in power electronics, RF systems, and magnetic sensors, where the geometry of the current path directly influences the magnetic field distribution and system performance.

Planar layouts are especially useful for creating compact coils, inductors, or loops within a single layer of copper. Understanding the magnetic fields generated by these structures is essential for optimizing electromagnetic behavior and minimizing interference.

In the following example, we construct a planar spiral coil using the TriangleStrip class.

Hide code cell source

import numpy as np
import magpylib as magpy

# Parameters
depth = 0.1      # z-offset for leads
width = 0.1      # trace width
n_turns = 5      # number of turns in the spiral
n_points = 100   # total discretization number
scale = 1e-3     # convert to mm

# Spiral angles
ang = np.linspace(-np.pi, (2 * n_turns - 1) * np.pi, n_points)
sin_t, cos_t = np.sin(ang), np.cos(ang)

# Radii for inner and outer edges of the trace
r1 = 1 + ang * width / np.pi
r2 = r1 + width

# Create spiral vertices alternating between inner and outer edge
spiral = np.empty((2 * n_points, 3))
spiral[::2] = np.stack((r1 * sin_t, r1 * cos_t, np.zeros_like(ang)), axis=1)
spiral[1::2] = np.stack((r2 * sin_t, r2 * cos_t, np.zeros_like(ang)), axis=1)

# Define connection legs
spiral[1] -= np.array([width, 0, 0.0])
leg1 = [
    spiral[0] + np.array([0.0, -2, -depth]),
    spiral[1] + np.array([0.0, -2+width, -depth]),
    spiral[0] + np.array([0.0, 0, -depth]),
    spiral[1] + np.array([0.0, 0, -depth]),
]
spiral[-1] += np.array([2*width, 0, 0])
spiral[-2] += np.array([width, 0, 0])
leg2 = [
    spiral[-2] + np.array([0.0, -1, 0.0]),
    spiral[-1] + np.array([0.0, -1+width, 0.0]),
]

# Combine all segments and convert to mm
vertices = np.concatenate((leg1, spiral, leg2), axis=0) * scale

# Create TriangleStrip object
planar_coil = magpy.current.TriangleStrip(current=0.1, vertices=vertices)
planar_coil.show(backend="plotly", style_direction_color='r')

The following code computes and visualizes the z-component of the magnetic field generated by the planar coil in a plane slightly above its surface. A relatively low spatial resolution is used to reduce the computational load (~100 triangles + 2500 observers = 250000 instances), ensuring fast and lightweight execution in the documentation environment.

Hide code cell source

import matplotlib.pyplot as plt

# Create observer grid in the xy-plane, slightly above the coil
n = 50 # discretization number
z_obs = 0.01e-3  # observation height in (m)
xs = np.linspace(-2.1e-3, 2.1e-3, n)
ys = np.linspace(-3.1e-3, 2.1e-3, n)
X, Y = np.meshgrid(xs, ys)
Z = np.full_like(X, z_obs)
grid = np.stack((X, Y, Z), axis=-1)

# Compute magnetic field H at each grid point
H = planar_coil.getH(grid)
Hz = H[..., 2]

# Plot Hz field using contourf
fig, ax = plt.subplots(figsize=(6, 5))
cp = ax.contourf(X * 1e3, Y * 1e3, Hz, levels=50, cmap='viridis')  # convert to mm for display
cb = fig.colorbar(cp, ax=ax, label="Hz [A/m]")

# Plot styling
ax.set(
    title="Magnetic Field $H_z$ of Planar Spiral Coil",
    xlabel="x [mm]",
    ylabel="y [mm]",
    aspect='equal'
)
plt.tight_layout()
plt.show()
../../../_images/4d4647df3a592baa0a7e61d92e734c24ee67d00cb598fbdc8c0b437f32a417ba.png

Note that planar coil structures are often combined with a shielding layer or a highly permeable back-sheet (e.g., ferrite) to reduce electromagnetic interference or enhance inductance. While Magpylib does not simulate induced magnetization or solve for current density distributions in materials, in such cases the Method of Images can be applied.

Keep in mind that real current distributions are typically non-uniform, especially near corners, sharp bends, or under high-frequency (AC) conditions where eddy currents become relevant. However, if the AC penetration depth is significantly larger than the conductor dimensions, eddy current effects are minimal, and the static field models provided by Magpylib can still offer reasonable approximations.