# Define a H(div) finite element space on a submain

Assume the domain is given as follows: How to define the H(div) finite element space on a subdomain. I define it as “V4 = HDiv(mesh, order=order, dirichlet=“gammaSD”, definedon = [2])”, I find it has more degrees of freedom. I don’t know what caused it?

geometry = SplineGeometry()

# point coordinates …

pnts = [ (0,0), (1,0), (1,0.5), (1,1), (0,1), (0, 0.5)]
pnums = [geometry.AppendPoint(*p) for p in pnts]

# start-point, end-point, boundary-condition, domain on left side, domain on right side:

(pnums[2],pnums[3],“gammaS”,1,0), (pnums[3],pnums[4],“gammaS”,1,0),
(pnums[4],pnums[5],“gammaS”,1,0),
for p1,p2,bc,left,right in lines:
geometry.Append( [“line”, p1, p2], bc=bc, leftdomain=left, rightdomain=right)
return geometry

Hi wen jing,

when using the definedon flag there seems that some dofs are marked as unused but still appear as dofs.
However, when looking at the freedofs it should have the correct number. There is the possibility to Compress the space to neglect all unused dofs.

The code

``````V1 = HDiv(mesh, order=2, dirichlet="gammaSD")
V2 = HDiv(mesh, order=2, dirichlet="gammaSD", definedon = "dom2")
V3 = Compress(V2)

print("V1 ndof = ", V1.ndof)
print("V1 fdofs = ", sum(V1.FreeDofs()))
print("V2 ndof = ", V2.ndof)
print("V2 fdofs = ", sum(V2.FreeDofs()))
print("V3 ndof = ", V3.ndof)
print("V3 fdofs = ", sum(V3.FreeDofs()))``````

gives the output

``````V1 ndof =  1845
V1 fdofs =  1815
V2 ndof =  1115
V2 fdofs =  900
V3 ndof =  930
V3 fdofs =  900``````

see also the attached code. I would highly recommend to give also regions/materials a name for better readability and avoiding errors like 0/1 based indexing.

https://ngsolve.org/media/kunena/attachments/889/hdiv_subdomain.py

Best
Michael

Attachment: hdiv_subdomain.py

Thanks for you advice and help!

Best regards,
Wen JIng

Thanks for your answer,which help me a lot! I think the number of dof of V3 is reasonable. However, should i use V2 or V3 when we’re coding?

With both spaces you should get the same result. if you explicitly need the ndofs V3 is less error prone (it might be also a bit more efficient than V2). You can simplify the notation by

``V3 = Compress(HDiv(mesh, order=2, dirichlet="gammaSD", definedon = "dom2"))``

Best
Michael