Force 2D tria mesh

Hi everybody,

I would like to know if there’s a way to force a 2D mesh to be made of triangles only. Referring to the NGSolve tutorial for the solution of a parabolic problem, on Colab, where I have NGSolve 6.2.2401-1-g85cf946e7, and locally, where I have version 6.2.2307, I get different meshes. Indeed, the first returns a triangular mesh, whereas the second returns a mixed mesh with both triangles and quads.
I visualize the mesh using the Draw utility of the webgui on Colab, whereas locally I necessarily have to rely on the VTKOutput utility.

PS: I have not changed the default value for quad_dominated, which is False.


You can run Split2tets on the netgen mesh :slight_smile:
We also use it in Firedrake to access anisotropic mesh refinement features.

strange, if you use the automatic mesh generator Netgen you will get triangles, as long as you do NOT set quad_dominated=True

Can you provide your input file ?


Dear Joachim,
here it is. Can you spot any mistake?

import ngsolve as ng
import netgen.occ as occ
def SetupMesh(order, path):
shape = occ.Rectangle(2,2).Face().Move((-1,-1,0))
mesh = ng.Mesh(occ.OCCGeometry(shape, dim=2).GenerateMesh(maxh=0.25))
fes = ng.H1(mesh, order=order, dirichlet=“bottom|right|left|top”)
vtk = ng.VTKOutput(ma = mesh, coefs = [0.], names = [‘mesh’],
filename = path + ‘mesh’, subdivision=1)
return [mesh, fes]

as expected, I get a triangular mesh locally.

What do you mean with:
whereas locally I necessarily have to rely on the VTKOutput utility.

You can use webgui locally, or Draw within the traditional netgen application.

By locally I mean that I am running python scripts from the terminal where I have no graphical support. In order to use the graphical interface, if I am not mistaken, you need either Conda or some kind of environment equipped with an ipython-kernel.

Do you mean that VTKOutput might give me a different result?

what do you mean with no graphical support?
for first experiments I’d recommend trying it on some local machine. Then you can for example just add

import netgen.gui

to the script to open the netgen-visualization and use Draw commands

or yes, you work with jupyter notebooks.

Hello Christopher,

first of all thanks for pointing out netgen.gui. I didn’t know it and it turned out to be very useful since it is the only one I can use from terminal. Indeed, relying on netgen.webgui, even if Draw commands execute without error using ipython, no window is opened to visualize.
I have this simple code that is a minimal setting for my inconsistent behaviour. Indeed, I obtain two different meshes in the vtk output file and through netgen.gui.
I would appreciate your feedback.
Thank you very much.

#!/usr/bin/env python                                                                                                                                  
# coding: utf-8                                                                                                                                        

import ngsolve as ng
import netgen.occ as occ
import os
path = os.getcwd()
shape = occ.Rectangle(2,2).Face().Move((-1,-1,0))
occmesh = occ.OCCGeometry(shape, dim=2).GenerateMesh(maxh=0.25)
# occmesh.Split2Tets()    ERROR from terminal                                                                                                                             
mesh = ng.Mesh(occmesh)
vtk = ng.VTKOutput(ma = mesh, coefs = [0.], names = ['mesh'],
                  filename = path + 'mesh', subdivision=1)

import netgen.gui as gui

Found my error, it is the parameter subdivision set to 1.