In some cases, the modelling domain may require flexibility in one region and equidistant structure in another. In this short example, we demonstrate how to accomplish this for a two-dimensional mesh consisting of a region with regularly spaced quadrilaterals and a region with unstructured triangles. We start by importing numpy, matplotlib and pygimli with its required components.
We continue by building a regular grid and assign the marker 2 to all cells.
Mesh: Nodes: 1326 Cells: 1250 Boundaries: 2575
Next, we build an unstructured region on top by creating the polygon and calling triangle via pygimli’s TriangleWrapper.
poly = pg.Mesh(2) # empty 2d mesh nStart = poly.createNode(xmin, zmax, 0.0) nA = nStart for x in xreg[1:]: nB = poly.createNode(x, zmax, 0.0) poly.createEdge(nA, nB) nA = nB z2 = 0. nA = poly.createNode(xmax, z2, 0.0) poly.createEdge(nB, nA) nB = poly.createNode(xmin, z2, 0.0) poly.createEdge(nA, nB) poly.createEdge(nB, nStart) tri = pg.TriangleWrapper(poly) tri.setSwitches('-pzeAfaq31')
For more information on the triangle switches and the corresponding settings, the reader is referred to the triangle website.
Now we can generate the unstructured mesh.
mesh2 = pg.Mesh(2) tri.generate(mesh2) for cell in mesh2.cells(): cell.setMarker(1)
Finally, the grid and the unstructured mesh can be merged to single mesh for further modelling.
mesh3 = merge2Meshes(mesh1, mesh2)
Of course, you can treat the hybrid mesh like any other mesh and append a
triangle boundary for example with the function
mesh = appendTriangleBoundary(mesh3, -100., 100., quality=31, smooth=True, marker=3, isSubSurface=True) pg.show(mesh, markers=True, showMesh=True) pg.wait()