Naming mesh boundaries

Hello!

Is there a way to name mesh boundaries? The tutorial pages show how to name boundaries for geometries created using CSGeometry, but I don’t see any similar options for imported geometries or meshes.

For instance, if I import an STL file with the following script:

from netgen.stl import *
#from netgen.libngpy._stl import*
geo = STLGeometry('netgenSTL_05.stl')
geo.GenerateMesh()

The function STLGeometry does not have .bc() or .Add() functions like in CSGeometry.

Another question I have is, is there a difference between the libngpy and the normal versions of the modules?

Thank you in advance!

Hi,

the Netgen mesh class has the method SetBCName to name boundaries (0-based index) after you created a mesh from the geometry.

from ngsolve import *
from netgen.geom2d import unit_square

mesh = Mesh(unit_square.GenerateMesh(maxh=0.1))
print("before: ", mesh.GetBoundaries())
mesh.ngmesh.SetBCName(0,"newname")
print("after : ", mesh.GetBoundaries())

Best,
Michael

Thank you!

I can set the boundary name for a particular boundary if I know the boundary index. Is there a way to set the names of boundaries that I do not know the indices of? I am looking for something like the bcmod argument of the Add() function in the following script:

from netgen.csg import *

sphere=Sphere(Pnt(0,0,0),0.55).bc('FSI')
pX=Plane(Pnt(0.5,0,0),Vec(1,0,0))
nX=Plane(Pnt(-0.5,0,0),Vec(-1,0,0))
pY=Plane(Pnt(0,0.5,0),Vec(0,1,0))
nY=Plane(Pnt(0,-0.5,0),Vec(0,-1,0))
pZ=Plane(Pnt(0,0,0.5),Vec(0,0,1))
nZ=Plane(Pnt(0,0,-0.5),Vec(0,0,-1))
Geom=sphere*pX*nX*pY*nY*pZ*nZ

geo=CSGeometry()
geo.Add(Geom.mat("domain"), bcmod=[(pX,"xplus"),(nX,"xminus"),(pY,"yplus"),(nY,"yminus"),(pZ,"zplus"),(nZ,"zminus")])

I would also be interested to know about any other ways we can specify which boundary we want to name.

I noticed that the ngsolve mesh class has a function Boundaries() which according to the Python documentation “Return(s) boundary mesh-region matching the given regex pattern” for the syntax “Boundaries(self: ngsolve.comp.Mesh, pattern: str)”. Can someone please give me an example of a regular expression I can use in this function? Can this be used to find the boundary index of a surface?

Edit: I am aware that one possible regex is the name of the boundary

Thank you in advance!