Node IDs on a specific boundary

How to get all to the node ids which belong to specific boundary for eg.

how to get the nodes on boundary “left”. I tried to use BoundaryCF method but didn’t worked
from netgen.occ import *

from numpy import *

from ngsolve import *

d = 0.005

h = 0.002

xp = [-d/2, -d/2, 0, d/2, d/2, 0]

yp = [ h/2,-h/2, -h/2, -h/2, h/2, h/2]

face = MoveTo(xp[0], yp[0]).LineTo(xp[1], yp[1]).LineTo(xp[2], yp[2]).LineTo(xp[5], yp[5]).Close().Face()

face.faces.name = “air”

face.edges[0].name = “left”
mesh = Mesh(OCCGeometry(face,dim=2).GenerateMesh(maxh=0.005)).Curve(3)
Draw(mesh)

%%

cf=mesh.BoundaryCF({ “left” : 1e6 }, default=1)
for i, v in enumerate(mesh.vertices):
x=v.point[0]
y=v.point[1]
print(x,y)
print(cf(mesh(x,y)))

Hi @em11 ,

It’s a bit late, so perhaps you already found a way to do this. I’m leaving this here in case someone else finds it helpful. Also, perhaps not the most elegant method, but I could not find anything else.

boundary_nodes = []
for e in mesh.Elements(BND):
    if e.mat == "left":
        for v in e.vertices:
            boundary_nodes.append(mesh[v].point)
boundary_nodes = set(boundary_nodes)

set removes the duplicate points.

Best regards,
Sos

You can query the degrees of freedom of a finite element space in a region:

fes = H1(mesh,order=1)
reg = mesh.Boundaries("left")
bndnodes = fes.GetDofs(reg)
print (bndnodes)

bndnodes is a BitArray, where True stands for vertex i is on boundary left.