# Geometric Boundary Layer

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:

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

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:

``````    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=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

Yes, thank you! This was very helpful.

Just leaving a minimal working example for posterity and a different example

``````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)
``````