- Thank you received: 0
Problem with GetBoundaries() after renaming boundaries (bug?)
4 years 4 days ago #3354
by rgs
Problem with GetBoundaries() after renaming boundaries (bug?) was created 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:
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:
The code that uses geometry from the STL file is:
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
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
Attachments:
- christopher
- Offline
- Administrator
Less
More
- Thank you received: 101
4 years 4 days ago #3359
by christopher
Replied by christopher on topic Problem with GetBoundaries() after renaming boundaries (bug?)
You need to first add facedescriptors for each of the boundaries:
then you can set boundary names for surfaces.
Best
Christopher
Code:
mesh.Add(Facedescriptor(surface_index, domain_in, domain_out, boundary_index))
Best
Christopher
The following user(s) said Thank You: rgs
3 years 11 months ago #3382
by rgs
Replied by rgs on topic Problem with GetBoundaries() after renaming boundaries (bug?)
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
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
- christopher
- Offline
- Administrator
Less
More
- Thank you received: 101
3 years 11 months ago #3386
by christopher
should work.
Best
Christopher
Replied by christopher on topic Problem with GetBoundaries() after renaming boundaries (bug?)
Code:
from netgen.meshing import ImportMesh
mesh = ImportMesh(filename)
Best
Christopher
The following user(s) said Thank You: rgs
Time to create page: 0.115 seconds