This page was generated from wta/coil.ipynb.

Magnetostatics

[1]:
from netgen.occ import *
from ngsolve import *
from ngsolve.webgui import Draw
from netgen.webgui import Draw as DrawGeo
import math

model of the coil:

[2]:
cyl = Cylinder((0,0,0), Z, r=0.01, h=0.03).faces[0]
heli = Edge(Segment((0,0), (12*math.pi, 0.03)), cyl)
ps = heli.start
vs = heli.start_tangent
pe = heli.end
ve = heli.end_tangent

e1 = Segment((0,0,-0.03), (0,0,-0.01))
c1 = BezierCurve( [(0,0,-0.01), (0,0,0), ps-vs, ps])
e2 = Segment((0,0,0.04), (0,0,0.06))
c2 = BezierCurve( [pe, pe+ve, (0,0,0.03), (0,0,0.04)])
spiral = Wire([e1, c1, heli, c2, e2])
circ = Face(Wire([Circle((0,0,-0.03), Z, 0.001)]))
coil = Pipe(spiral, circ)

coil.faces.maxh=0.2
coil.faces.name="coilbnd"
coil.faces.Max(Z).name="in"
coil.faces.Min(Z).name="out"
coil.mat("coil")
crosssection = coil.faces.Max(Z).mass
[3]:
DrawGeo (coil);
[4]:
box = Box((-0.04,-0.04,-0.03), (0.04,0.04,0.06))
box.faces.name = "outer"
air = box-coil
air.mat("air");

mesh-geneation of coil and air-box:

[5]:
geo = OCCGeometry(Glue([coil,air]))
with TaskManager():
    mesh = Mesh(geo.GenerateMesh(meshsize.coarse, maxh=0.01)).Curve(3)


Draw (mesh, clipping={"y":1, "z":0, "dist":0.012});

checking mesh data materials and boundaries:

[6]:
mesh.ne, mesh.nv, mesh.GetMaterials(), mesh.GetBoundaries()
[6]:
(146196,
 24979,
 ('coil', 'air'),
 ('out',
  'coilbnd',
  'coilbnd',
  'coilbnd',
  'coilbnd',
  'coilbnd',
  'in',
  'outer',
  'outer',
  'outer',
  'outer',
  'outer',
  'outer'))

Solve a potential problem to determine current density in wire:

[7]:
fespot = H1(mesh, order=3, definedon="coil", dirichlet="out")
upot,vpot = fespot.TnT()
amat = BilinearForm(grad(upot)*grad(vpot)*dx).Assemble().mat
inv = amat.Inverse(freedofs=fespot.FreeDofs(), inverse="sparsecholesky")
fvec = LinearForm(1/crosssection*vpot*ds("in")).Assemble().vec
gfpot = GridFunction(fespot)
gfpot.vec.data = inv * fvec
[8]:
Draw (gfpot, draw_vol=False, clipping={"y":1, "z":0, "dist":0.012});

Solve magnetostatic problem:

\[\int \mu^{-1} \operatorname{curl} u \cdot \operatorname{curl} v \, dx = \int j \cdot v \, dx\]
[9]:
fes = HCurl(mesh, order=2, nograds=True)
u,v = fes.TnT()
mu = 4*math.pi*1e-7
a = BilinearForm(1/mu*curl(u)*curl(v)*dx+1e-6/mu*u*v*dx)
pre = Preconditioner(a, "bddc")
f = LinearForm(grad(gfpot)*v*dx("coil"))
with TaskManager():
    a.Assemble()
    f.Assemble()
[10]:
inv = CGSolver(a.mat, pre)
gfu = GridFunction(fes)
with TaskManager():
    gfu.vec.data = inv * f.vec
[11]:
Draw (curl(gfu), mesh, draw_surf=False, \
      min=0, max=3e-4, clipping = { "y":1, "z" : 0, "function":False}, vectors = { "grid_size":100});
[ ]: