Forum Message

 

 

We have moved the forum to https://forum.ngsolve.org . This is an archived version of the topics until 05/05/23. All the topics were moved to the new forum and conversations can be continued there. This forum is just kept as legacy to not invalidate old links. If you want to continue a conversation just look for the topic in the new forum.

Notice

The forum is in read only mode.

Mixed meshes

More
2 years 9 months ago - 2 years 9 months ago #3830 by armandyam
Mixed meshes was created by armandyam
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.
Last edit: 2 years 9 months ago by armandyam.
More
2 years 9 months ago #3853 by ddrake
Replied by ddrake on topic Mixed meshes
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.
Code:
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
Code:
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
The following user(s) said Thank You: armandyam
More
2 years 9 months ago #3854 by armandyam
Replied by armandyam on topic Mixed meshes
Hi,

Thank you for the reply. The quad_trig script was very helpful and it works perfectly!

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

Best regards

Ajay
More
2 years 8 months ago #3864 by arieder
Replied by arieder on topic Mixed meshes
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) mesh = geo.GenerateMesh (maxh=0.25,quad_dominated=True) return ngs.Mesh(mesh)
The following user(s) said Thank You: ddrake
More
2 years 8 months ago #3868 by ddrake
Replied by ddrake on topic Mixed meshes
Thanks arieder!

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.

Best,
Dow
Time to create page: 0.176 seconds