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.

Geometric Boundary Layer

More
3 years 2 months ago #3533 by runiteking1
Hi all,

I want to solve reaction-diffusion equations using geometric boundary meshes. For a simple domain like a square, I can easily construct the layers by hand, but I'm wondering if it's possible for Netgen to automatically create these types of meshes for me?

In particular, in the paper:
arxiv.org/pdf/2004.10517.pdf
the authors specified that they used NGSolve/Netgen to (automatically) create the geometrically refined meshes in Figure 4, but I lack the technical knowledge of the software to produce these meshes without explicitly specifying points/layers. I'm hoping someone can point me to an appropriate function call to generate them.

Thank you!

Marshall
More
3 years 2 months ago #3534 by arieder
Replied by arieder on topic Geometric Boundary Layer
Hi,

you can indeed use ngsolve to generate geometric refinements towards (parts of) the boundary.
To do so, you have to mark the faces/edges/vertices towards which you want refinement and then use RefineHp().
For a simple square, I use the following code:
Code:
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) ng_mesh = geo.GenerateMesh (maxh=0.25,quad_dominated=True) mesh=ngs.Mesh(mesh) mesh.RefineHP(L,sigma);
where L is the number of Layers and sigma is the grading factor. One thing to remember that has caused me some headaches, is that if you mark adjacent edges, you also have to mark the vertex contained in both, otherwise you may get weird segfaults.

hope this helps,
Alex
More
3 years 1 month ago #3537 by runiteking1
Yes, thank you! This was very helpful.

Just leaving a minimal working example for posterity and a different example
Code:
from ngsolve import * import netgen.geom2d as geom2d geo = geom2d.SplineGeometry() p1 = geo.AppendPoint(1, 0, hpref=1) p2 = geo.AppendPoint(0, 0, hpref=1) p3 = geo.AppendPoint(0, -1, hpref=1) p4 = geo.AppendPoint(-1, -1, hpref=1) p5 = geo.AppendPoint(-1, 0, hpref=1) p6 = geo.AppendPoint(-1, 1, hpref=1) p7 = geo.AppendPoint(0, 1, hpref=1) p8 = geo.AppendPoint(1, 1, hpref=1) # Seems sensitive to direction/order of splines; this configuration works geo.Append (["line", p2, p1], hpref=1, bc=1) geo.Append (["spline3", p1, p8, p7], hpref=1, bc=1) geo.Append (["spline3", p7, p6, p5], hpref=1, bc=1) geo.Append (["spline3", p5, p4, p3], hpref=1, bc=1) geo.Append (["line", p3, p2], hpref=1, bc=1) ng_mesh = geo.GenerateMesh (maxh=.125) mesh=Mesh(ng_mesh) # mesh.Curve(2) # Curved elements mesh.RefineHP(2,.25) Draw(mesh)
Time to create page: 0.144 seconds