I am working on mesh adaptation and use a C++ solver built upon NGSolve. In this regard, I have two questions
About generating/importing mixed meshes with both triangles and quads. I wanted to know if NGsolve supports this and if so how to import them from a .vol file. . I tried to generate such a mesh by hand and I get a segmentation fault when I import it into NGSolve.
If there are some tutorials about using import NGSolve in C++ with MPI support. The C++ code we have uses NGSolve libraries (mesh interface, basis functions, quadrature etc) and I wanted to parallelize this code.
Mixed meshes seem to be possible. This tutorial shows how to make a quad mesh by hand.
Here’s a snippet that creates a mesh with 2 elements – one quad and one trig.
import netgen.meshing as nm
ngmesh = nm.Mesh(dim=2)
pnums = [ngmesh.Add(nm.MeshPoint(nm.Pnt(*pt, 0)))
for pt in [(0,0),(1,0),(1.5, .5),(1,1),(0,1)]]
idx_dom = ngmesh.AddRegion("mat", dim=2)
ngmesh.Add(nm.Element2D(idx_dom, [pnums[0], pnums[1], pnums[3], pnums[4]]))
ngmesh.Add(nm.Element2D(idx_dom, [pnums[1], pnums[2], pnums[3]]))
ngmesh.Add(nm.Element1D([pnums[0], pnums[1]], index=1))
ngmesh.Add(nm.Element1D([pnums[1], pnums[2]], index=1))
ngmesh.Add(nm.Element1D([pnums[2], pnums[3]], index=1))
ngmesh.Add(nm.Element1D([pnums[3], pnums[4]], index=1))
ngmesh.Add(nm.Element1D([pnums[4], pnums[0]], index=1))
ngmesh.Save('quad_trig.vol')
The saved mesh file ‘quad_trig.vol’ seems to load correctly if we do
from ngsolve import Mesh
mesh = Mesh('quad_trig.vol')
But I believe that NGSolve cannot currently generate a mesh containing quads automatically from a geometry.
For your second question, I don’t know of any C++ tutorials for MPI, but you could look at the Python tutorials, and work backwards from the Pybind bindings (python_*.cpp) in the source tree.
just a small note: netgen/ngsolve is indeed able to generate quad meshes automatically. You just have to pass the flag quad_dominated=True to the Generate Mesh function.
For example, I use the following code to generate a 2d quad mesh for a hp method on the square:
I’ve seen that quad_dominated flag at some point, but never tried using it, and forgot all about it. I just did a little testing with it on a non-rectangular geometry and it generated a mesh with a mix of quads and trigs so that may be a better solution for the original problem.