Set Meshing Options with Python?

More
4 years 3 weeks ago #3275 by mariopa
Hello,

I am new to Netget/NGSolve.

I hope you guys can help me, here the manual way I do:

I load a new Geometry into NGSolve.
After that I navigate into "Meshing options..." select "Mash granularity=very coarse" after that under "Mesh Size/Elements per curv...radius" I switch it to the value 5.

After that "Export Mesh" to a *.STL file.

that works fine, but I need to do this automaticly.

I allready wrote a little phyton file:

from netgen.NgOCC import *
from ngsolve import *

geo = LoadOCCGeometry('Part.stp')
mesh = geo.GenerateMesh()
Draw(Mesh(mesh))
# mesh.Export('Part2.stl','STL Format')


But I do not have any idea how I can set the "meshing options" first?

Anyone can help?

thanks much,
regards, mario
More
4 years 2 weeks ago #3279 by mariopa
no one any idea?
More
4 years 2 weeks ago - 4 years 2 weeks ago #3280 by matthiash
Hi Mario,

There are arguments you can pass to the GenerateMesh() function to control the meshing algorithms. For your case, try the following code
Code:
from netgen.meshing import MeshingParameters, meshsize ... mesh = geo.GenerateMesh(meshsize.very_coarse, curvaturesafety=5) Draw(Mesh(mesh))

Best,
Matthias
Last edit: 4 years 2 weeks ago by matthiash.
More
4 years 2 weeks ago #3281 by mariopa
thx much for your answer, but it does not generate a mesh:

from netgen.NgOCC import *
geo = LoadOCCGeometry('Part.stp')

from netgen.meshing import MeshingParameters, meshsize
mesh = geo.GenerateMesh(meshsize.very_coarse, curvaturesafety=5)
Draw(Mesh(mesh))

it just shows me the Part.stp in the GUI, but not the generated mesh.

what wrong with this?

regards, mario
More
4 years 2 weeks ago #3283 by mariopa
This comes from the console:

NETGEN-6.2-dev
Developed by Joachim Schoeberl at
2010-xxxx Vienna University of Technology
2006-2010 RWTH Aachen University
1996-2006 Johannes Kepler University Linz
Including OpenCascade geometry kernel
optfile ./ng.opt does not exist - using default values
togl-version : 2
OCC module loaded
loading ngsolve library
NGSolve-6.2.1905
Using Lapack
Including sparse direct solver Pardiso
Including sparse direct solver UMFPACK
Running parallel using 6 thread(s)
importing NGSolve-6.2.1905
(should) load python file 'Skript.py'
load OCC geometry Number of colours in STEP File: 1
Colour [1] = STEELBLUE3 : (0.380392,0.576471,0.752941)
Highest entry in topology hierarchy:
1 solid(s)
Traceback (most recent call last):
File "<string>", line 4, in <module>
ImportError: cannot import name 'meshsize' from 'netgen.meshing' (C:\Program Files\ngsolve-v6.2.1905\lib\site-packages\netgen\meshing.py)
Finished executing Skript.py
Preparing visualization (deflection = 0.01) ... done
More
4 years 2 weeks ago #3284 by matthiash
Seems your version of NGSolve is outdated (19.05), I suggest you download a recent version. Note that you might also need to update Python to 3.7.

Best,
Matthias
Time to create page: 0.111 seconds