Two domain mesh

Hi, after following the tutorial instructions and executing


I had no error, but when I am trying to Draw it with Draw(mesh1), I see the error
[color=purple]File “”, line 13
IndentationError: unexpected indent[/color]

similar error if I try another example using mesh.Points():

for p in mesh.Points(): x,y,z =p.p print ("x= ", x, "y= ", y) for el in mesh.Elemends2D(): print (el.vertices)
I see
[color=purple]File “”, line 22
for el in mesh.Elemends2D():
IndentationError: unexpected indent[/color]

I checked if the appropriate libraries are imported and I can not find the mistake. Could help me please? Do I miss something?

best wishes



Hi Makis,

regarding your first question (I’m not working on ngsxfem):
You have to be aware of the type of your python object!

mesh = Mesh(geo.GenerateMesh(maxh=0.5))

Let’s say we have the mesh with two domains (as in the tutorial you linked, full code is attached). If you want to work with material/domains of you mesh, you have the use the NGSolve mesh. You can check the type with:

type(mesh)[/code] and the output is[code]<class 'ngsolve.comp.Mesh'>

Also use the python help function to find out which functions and members are available for your python object. This can be done by


If you want to use one of your subdomains, you can use the “Material(…)” function. But this function does not return a mesh! It returns a “Region”, which can be used the define a finite element space on a subdomain. Again


tells you the type of the object and python help shows details about this object.

For the second part of your first question you have to use the Netgen mesh. This is available as member of the NGSolve mesh.



<class 'netgen.libngpy._meshing.Mesh'>

If you now check the help of “mesh.ngmesh” you see the functions to get the points and elements you wanted to use.

for p in mesh.ngmesh.Points():
    x,y,z =p.p
    print ("x= ", x, "y= ", y)
for el in mesh.ngmesh.Elements2D():
    print (el.vertices)

Best regards,


Dear Christoph,
thank you for the detailed instructions!
with Kindest Regards