Current Loop
The magnetic field of a circular current loop is calculated using complete elliptic integrals. In local cylindrical coordinates
where
Calculate the field of a circular current loop.
julia
using Magnetostatics, StaticArrays, LinearAlgebra
using CairoMakie
# Define loop parameters
radius = 1.0
current = 10.0
center = SVector(0.0, 0.0, 0.0)
normal = SVector(0.0, 0.0, 1.0)
# Create loop object
loop = CurrentLoop(radius, current, center, normal)
# Query field
r = SVector(0.0, 0.0, 0.5)
B = getB_loop(r, loop)
println("B at (0,0,0.5): $B [T]")B at (0,0,0.5): [0.0, 0.0, 4.495881427866065e-6] [T]Visualizing the field in the xz-plane:
julia
xs = range(-2, 2, length=51)
zs = range(-2, 2, length=51)
function field_xz_loop(x, z)
B = getB_loop(SVector(x, 0.0, z), loop)
return Point2f(B[1], B[3])
end
Bmag = [norm(getB_loop(SVector(x, 0.0, z), loop)) for x in xs, z in zs]
fig = Figure(size = (700, 600), fontsize=20)
ax = Axis(fig[1, 1];
xlabel="x", ylabel="z", aspect=DataAspect(), title="Current Loop Field")
hm = heatmap!(ax, xs, zs, log10.(Bmag .+ 1e-9), colormap=:plasma)
Colorbar(fig[1, 2], hm, label="log10(|B|)")
streamplot!(ax, field_xz_loop, -2..2, -2..2;
arrow_size = 8, linewidth = 1.5, colormap = :turbo)
fig