Forum Message

 

 

We have moved the forum to https://forum.ngsolve.org . This is an archived version of the topics until 05/05/23. All the topics were moved to the new forum and conversations can be continued there. This forum is just kept as legacy to not invalidate old links. If you want to continue a conversation just look for the topic in the new forum.

Notice

The forum is in read only mode.

Problem with GetBoundaries() after renaming boundaries (bug?)

More
3 years 5 months ago #3354 by rgs
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:
Code:
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:
Code:
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:
Code:
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
More
3 years 5 months ago #3359 by christopher
You need to first add facedescriptors for each of the boundaries:
Code:
mesh.Add(Facedescriptor(surface_index, domain_in, domain_out, boundary_index))
then you can set boundary names for surfaces.
Best
Christopher
The following user(s) said Thank You: rgs
More
3 years 5 months ago #3382 by rgs
Hello Christopher,

thank you, I can set names for the boundary conditions after adding facedescriptors.

The generated mesh currently does not correctly resolve the edges in the geometry. I think this is because the stl data is imported as a geometry and not as a mesh. I see that I can import STL files as either geometries or surface meshes using the GUI. Is there a way to import an stl file as a surface mesh using the python interface?

Thanks in advance!

Cheers,
Rohit
More
3 years 5 months ago #3386 by christopher
Code:
from netgen.meshing import ImportMesh mesh = ImportMesh(filename)
should work.
Best
Christopher
The following user(s) said Thank You: rgs
Time to create page: 0.185 seconds