Netgen python script: use default GUI parameters

More
3 years 7 months ago #3731 by mleoni
Hello everyone! I'm trying to automate a simple meshing procedure, that I follow using Netgen's GUI, into a Python script.

The GUI procedure is as follows:
1. "File -> Import Mesh" to import an STL file [a closed surface]
2. "Generate Mesh"
3. "Optimize Volume"
4. "Export Mesh"

Now, my current script looks like this:
Code:
import netgen.meshing as meshing m = meshing.ImportMesh("surfaceMesh.stl") m.GenerateVolumeMesh() m.OptimizeVolumeMesh(meshing.MeshingParameters()) m.Export("volumeMesh.gmsh", "Gmsh Format")
The problem is that the mesh generated by the steps above is different from the mesh generated by this script, and in particular the one generated by my script has much worse quality [aspect ratio].

My understanding was that, by passing a new
Code:
meshing.MeshingParameters()
instance, Netgen would use the default parameters, which I assumed were also the ones used by the GUI, but it looks like this is not the case.

Can anyone point me in the right direction? I get a very good mesh using the GUI procedure, and I want to reproduce it exactly with my script.

Thanks for any help!
Massimiliano
More
3 years 7 months ago #3733 by christopher
Hi,
you can get the default meshing parameters by using the `meshsize` object.
```
m.OptimizeVolumeMesh(meshsize.moderate)
```
There are also the other default GUI options like `meshsize.coarse`, ...

Best
Christopher
More
3 years 7 months ago #3734 by mleoni
Hello Christopher, thanks for your reply!

I tried following your advice, now my script looks like so:
Code:
import netgen.meshing as meshing m = meshing.ImportMesh("surfaceMesh.stl") m.GenerateVolumeMesh(meshing.meshsize.moderate) m.OptimizeVolumeMesh(meshing.meshsize.moderate) m.Export("volumeMesh0S.gmsh", "Gmsh Format")

I can confirm that I get the same mesh after step 2 in the GUI ["Generate Mesh"] and after calling `m.GenerateVolumeMesh(meshing.meshsize.moderate)`. However, I get two different meshes after step 3 ["Optimize Volume"] and after running `m.OptimizeVolumeMesh(meshing.meshsize.moderate)`. In particular, the script command changes the mesh only very little [removes around 300 nodes and doesn't change the quality at all] while the GUI procedure removes 18'000 nodes and significantly improves the mesh quality.
What else can I try?

Thanks a lot for your help!
Massimiliano
More
3 years 7 months ago #3738 by mleoni
To add to the information above, I compared the output I get, in the terminal, when running Netgen via GUI with the output I get when running via Python.
The two outputs are identical for the meshing part, but when the volume optimisation starts, the GUI outputs this
Code:
Volume Optimization CombineImprove 2221828 edges 126 edges with improvement 108 elements combined ImproveMesh Total badness = 2.72533e+06 Total badness = 2.72509e+06 SplitImprove 2220957 edges 4 edges with improvement 2 splits performed 0 elements split ImproveMesh Total badness = 2.72633e+06 Total badness = 2.72613e+06 SwapImprove 83805 swaps performed SwapImprove2 89 swaps performed ImproveMesh Total badness = 2.48466e+06 Total badness = 2.41983e+06 ... Lots of other text

while from the Python script I get
Code:
Volume Optimization CombineImprove 2221828 edges 126 edges with improvement 108 elements combined ImproveMesh Total badness = 2.72533e+06 Total badness = 2.72509e+06 SplitImprove 2220957 edges 4 edges with improvement 2 splits performed 0 elements split ImproveMesh Total badness = 2.72633e+06 Total badness = 2.72613e+06 SwapImprove 5 swaps performed SwapImprove2 0 swaps performed ImproveMesh Total badness = 2.72612e+06 Total badness = 2.72609e+06 ... Lots of other text

You can see that the output from the GUI says, for the SwapImprove step, `83805 swaps performed`, while the Python script gives `5 swaps performed`.

Is this any helpful? What influences that number?
Time to create page: 0.096 seconds