I am trying to follow the magnetostatic example in the I-tutorials but I want to close the coil in on itself and still solve for the current in the coil. (And the magnetic field around the coil)
Does anyone have an idea how I achieve this? In essence I have to define the dirichlet boundary condition and current source on either side of the same surface where the two ends meet.
Hi,
a nice way is to use a mixed formulation, and search for the coil current in H(div). On the interface, you can put the integral \int U tau*n ds to the right hand side, where U is the applied voltage over the interface.
Joachim
Thank you so much for the reply! I am a complete beginner when it comes to ngsolve but tried to do something like what you describe which I have appended below. I however get that the iterations just return nan (CG iteration 1, residual = nan, CG iteration 2, residual = nan, etc)
I am not sure exactly what it is that I am missing?
Thanks again,
Hampus
import ngsolve as ngs
import netgen.occ as occ
spine = occ.Wire(occ.Circle((0,0,0), (0,0,1), 1))
circle = occ.Face(occ.Wire([occ.Circle((1,0,0), (0,1,0), 0.1)]))
circle.faces.name = "cut"
coil = occ.Glue([occ.Pipe(spine, circle), circle])
coil.solids.name = "coil"
coil.faces.name = "outer"
geometry = occ.OCCGeometry(coil)
# Mesh
mesh = ngs.Mesh(geometry.GenerateMesh())
# FEM
U = 1 # Voltage
sigma = 10 # conductivity
divfes = ngs.HDiv(mesh, order=3, dirichlet="outer")
l2fes = ngs.L2(mesh, order=2)
fes = divfes*l2fes
(ud, ul2), (vd, vl2) = fes.TnT()
a = ngs.BilinearForm((1/sigma*ud*vd + ngs.div(ud)*vl2 + ngs.div(vd)*ul2)*ngs.dx)
c = ngs.Preconditioner(a, type="bddc")
n = ngs.specialcf.normal(mesh.dim)
f = ngs.LinearForm(U*(vd.Trace()*n*ngs.ds(f"cut")))
gfm = ngs.GridFunction(fes)
with ngs.TaskManager():
a.Assemble()
f.Assemble()
ngs.solvers.CG(sol=gfm.vec, rhs=f.vec, mat=a.mat, pre=c.mat)
Is it also possible to somehow treat two sides of the same surface as different surfaces?
For instance if you wanted to solve the above problem in H1:
fes = ngs.H1(mesh, order=3, dirichlet="cut_right") # <-- one side of the cut
u, v = fes.TnT()
a = ngs.BilinearForm(sigma*grad(u)*grad(v)*ngs.dx)
f = ngs.LinearForm(J_in*v*ds("cut_left")) # <-- other side of the cut
Or if you were interested in stipulating different dirichlet conditions on either side?