# Mixed meshes

Hi,

I am working on mesh adaptation and use a C++ solver built upon NGSolve. In this regard, I have two questions

1. 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.
2. 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.

Thank you.

Hi,

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, pnums, pnums, pnums])) ngmesh.Add(nm.Element2D(idx_dom, [pnums, pnums, pnums])) ngmesh.Add(nm.Element1D([pnums, pnums], index=1)) ngmesh.Add(nm.Element1D([pnums, pnums], index=1)) ngmesh.Add(nm.Element1D([pnums, pnums], index=1)) ngmesh.Add(nm.Element1D([pnums, pnums], index=1)) ngmesh.Add(nm.Element1D([pnums, pnums], 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.

Best,
Dow

Hi,

Thank you also for the pointers for the MPI tutorial. I will take a look at them.

Best regards

Ajay

Hi,

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:

[code]def square_mesh():
import netgen.geom2d as geom2d;
geo = geom2d.SplineGeometry()
p1 = geo.AppendPoint (0,0,hpref=1)
p2 = geo.AppendPoint (1,0,hpref=1)
p3 = geo.AppendPoint (1,1,hpref=1)
p4 = geo.AppendPoint (0,1,hpref=1)

``````geo.Append (["line", p1, p2], bc=1,hpref=1)
geo.Append (["line", p2, p3], bc=1,hpref=1)
geo.Append (["line", p3, p4], bc=1,hpref=1)
geo.Append (["line", p4, p1], bc=1,hpref=1)