Hello,
I am trying to write a script that can import geometry from an STL file, mesh it and give names to some of the boundaries after the mesh is generated. In order to name the boundaries, I use the SetBCName() function in the netgen mesh class. Naming boundaries and then printing the names of the boundaries using GetBoundaries() (from the ngsolve mesh class) works when I generate the geometry being meshed with CSG. However, if the geometry is from an STL file, I get an error when I call GetBoundaries() after calling SetBCName(). I do not get any warning or error when I call SetBCName(). GetBoundaries() works for STL geometries if SetBCName() is not called before it. I have tried this with 3 STL files generated using 3 different programs, one of which is Netgen, and I always get the error:
netgen.libngpy._meshing.NgException: Illegal bc number : index 1 out of range [0,1)
I don’t understand this error message, and I don’t know why there would be an error in the first place. Since I am using functions that are defined in the netgen and ngsolve mesh classes, the functions shouldn’t be affected by whether the geometry was generated in Netgen or imported from an STL file. Could someone please help me fix this problem or understand what is going on? Is this a bug?
The code that uses geometry generated using CSG is:
from netgen.csg import *
# Defining solid
sphere = Sphere(Pnt(0, 0, 0), 0.55)
pX = Plane(Pnt(0.5, 0, 0), Vec(1, 0, 0))
nX = Plane(Pnt(0, 0, 0), Vec(-1, 0, 0))
pY = Plane(Pnt(0, 0.5, 0), Vec(0, 1, 0))
nY = Plane(Pnt(0, 0, 0), Vec(0, -1, 0))
pZ = Plane(Pnt(0, 0, 0.5), Vec(0, 0, 1))
nZ = Plane(Pnt(0, 0, 0), Vec(0, 0, -1))
bbox = pX*nX*pY*nY*pZ*nZ
Zielinski = sphere*bbox
# Making geometry from solid
geo=CSGeometry()
geo.Add(Zielinski)
# Meshing
from ngsolve.comp import Mesh
netgenMesh = geo.GenerateMesh(maxh=0.05)
netgenMesh.SetBCName(0, "test")
mesh = Mesh(netgenMesh)
print(mesh.GetBoundaries())
Draw(mesh)
The code that uses geometry from the STL file is:
from netgen.stl import *
from ngsolve.comp import Mesh
geo = STLGeometry('geo.stl')
from ngsolve.comp import Mesh
netgenMesh = geo.GenerateMesh(maxh=0.05)
netgenMesh.SetBCName(0, "test")
mesh = Mesh(netgenMesh)
print(mesh.GetBoundaries())
Draw(mesh)
I am attaching both scripts and a sample STL file exported using Netgen.
I have tried this in the latest stable version of NGSolve and also the nightly build NGSolve-6.2.2009-24-g53c262fa
Thanks in advance.
Cheers!
Rohit
Attachment: CSG_2020-11-19.py
Attachment: STL_2020-11-19.py
Attachment: geo_2020-11-19.stl