Can not change Mesh size.

I load my geometry using LoadOCCGeometry and when I am trying to mesh it I have the same number of elements for different values of maxh parameter.

from netgen.NgOCC import * geo = LoadOCCGeometry("brick.step") mp = MeshingParameters(maxh=1, grading=0.3) ngmesh = geo.GenerateMesh(mp=mp)
Output: 17 elements were created

from netgen.NgOCC import * geo = LoadOCCGeometry("brick.step") mp = MeshingParameters(maxh=0.1, grading=0.3) ngmesh = geo.GenerateMesh(mp=mp)
Output: 17 elements were created

ngmesh = geo.GenerateMesh(maxh=0.1, segmentsperedge=20)

Tried with segments meshing - > 17 elements were created.

Do you have experience with this? Is it a bug of python interface?

you are right, the meshing parameters from Python were ignored for the occ geometry. This is fixed in the upcoming nightly release. We have included some further changes/improvements/syntactic sugar:

The occ module should now be included using netgen.occ, geometries constructed by the constructor taking the filename as argument.

from netgen.occ import *
geo = OCCGeometry("brick.step")

This constructor now understands .brep, .iges, .step and .stp files.
One can now use meshing parameters as given in the gui, by the helper variable meshsize:


you can give additional meshsize parameters as kwargs as well:

geo.GenerateMesh(meshsize.coarse, maxh=0.2)

There is a docstring about available meshing and optimization parameters if you query GenerateMesh for its help:


Hope that helps and let us know if you run into problems.


Thanks a lot, now it works good :slight_smile:
Could you, please, tell me if netgen has MPI support. Can I create mesh in parallel?

no, you cannot generate a mesh mpi-parallel. But you can distribute a mesh for parallel computations, and also refine a mesh in parallel.

Here is a simple example for that::

from ngsolve import *
from netgen.csg import unit_cube
import netgen.meshing

if mpi_world.rank == 0:
    ngmesh = unit_cube.GenerateMesh(maxh=0.2).Distribute(mpi_world)
    ngmesh = netgen.meshing.Mesh.Receive(mpi_world)

for l in range(2):

mesh = Mesh(ngmesh)
fes = H1(mesh, order=3)
print ("ndof-local =", fes.ndof, "ndof-global =", fes.ndofglobal)


Hello joachim,
Could you please tell me if RestrictH() method works with occ geometries?
I try to run the code like this(Cube properties 10x10x10, starting point (0,0,0) ):

from netgen.occ import * from netgen.meshing import MeshingParameters mp = MeshingParameters() n = 100 for i in range(n+1): loc_h = 10/n mp.RestrictH(x=0,y=i*loc_h,z=0,h=loc_h) geo = OCCGeometry("cube.step") mesh = geo.GenerateMesh(mp=mp) mesh.Export("output.msh", "Gmsh2 Format")

But it does not mesh my edge. When I use CS Geometry it works good.
Could you please help me?

Fixed in restricth for occ and stl geometries · NGSolve/netgen@13c17ad · GitHub
Will be in coming nightly release
Thanks for reporting