Excluding gradients in non conducting regions of a mesh


I’m interested in solving eddy current problems with ngsolve. I’ve already done some experiments with magnetostatic problems. Here I know that I can turn off the gradients in the complete domain by specifying a finite element space of the form

fes=HCurl(mesh, order=1, flags={“no grads”:True})

and adding an appropriate regularisation term to the bilinear form.

However, for eddy current problems, I have a conducting region and a non-conducting region. If I used a vector potential formulation, I know that I need to keep the gradients in the conducting region but that are not needed in the non-conducting region. To save on the number of degrees of freedom I would like to turn off the gradients in the non-conducting region. Is this possible through defining an appropriate finite element space that tags a region in the mesh? Or do I need to define two different fes and combine them in someway?

Also, in terms of the local Jacobi preconditioner, can I apply this directly to such problems?

Thanks for your help,


Yes there is a feature for that:

from netgen.csg import *
from ngsolve import *

ngsglobals.msg_level = 0

geo = CSGeometry()
block = OrthoBrick(Pnt(-1,-1,-1), Pnt(1,1,1))
sphere = Sphere(Pnt(0,0,0),0.5)


mesh = Mesh(geo.GenerateMesh())

dom_nrs_metal = [1 if mat == "metal" else 0 for mat in mesh.GetMaterials()]

order = 3
full_fes = HCurl(mesh, order=order)
nograds_fes = HCurl(mesh, order=order, nograds=True)
domainwisegrad_fes = HCurl(mesh, order=order, gradientdomains=dom_nrs_metal)

ndofs = {"air" : {}, "metal" : {}}
for el in domainwisegrad_fes.Elements(VOL):
    if len(el.dofs) not in ndofs[el.mat]:
        ndofs[el.mat][len(el.dofs)] = 1
        ndofs[el.mat][len(el.dofs)] += 1


print("ndof full = ", full_fes.ndof)
print("reduce all = ", nograds_fes.ndof)
print("gradient domains =", domainwisegrad_fes.ndof)

Results in

{'air': {41: 188, 32: 156, 29: 100, 35: 6, 50: 2}, 'metal': {60: 142}}
ndof full =  15164
reduce all =  8639
gradient domains = 11124

So you can see, that the gradients are only in the metal and on the boundary to the metal (thats why some of the air elements have some gradients as well). You can ignore the warning about the undocumented flag.