Mesh generation using GMSH (Python)

55 Views Asked by At

The problem is the following. I'm trying to construct the triangular mesh for the 2D region.

Area for which mesh is going to constructed: Area for which mesh is going to constructed I'm using gmsh generator on Python. Finally, I need to obtain set of all nodes, and set of triangles with information what three nodes construct this particular triangle. Ideally, sets have to be the following: [[x1, y1], [x2, y2], ..] and [[tag1, tag2, tag3], ...] respectively, where xi, yi are the coordinates of some node with tag i, and tag1, tag2, tag3 are tags of nodes for this specific triangle.

I'm using the following code. It constructs the area based on the known boundary points (12 points).

import numpy as np
import matplotlib.pyplot as plt
import gmsh
import sys

#Area characteristics 
S = 20
H = 7
#Boundary points of the area
x_b = np.array([250, 100-H, 100-H, 150-H, 150-H, 
                0, 0, 150, 150, 100, 100, 250])
y_b = np.array([-2*S - H, -2*S - H, -S, -S, -H, 
                -H, 0, 0, -S-H, -S-H, -2*S, -2*S])

#Characteristic size of the mesh
lc = 10

gmsh.initialize()
gmsh.model.add("pr2")

#Constructing of the area
points = np.empty(12, dtype = 'int')
for i in range(len(x_b)):
    points[i] = gmsh.model.geo.addPoint(x_b[i], y_b[i], 0.0, lc)
lines = np.empty(12)
for i in range(len(lines)-1):
    lines[i] = gmsh.model.geo.addLine(points[i], points[i+1])
lines[-1] = gmsh.model.geo.addLine(points[-1], points[0])
loop = gmsh.model.geo.addCurveLoop(lines)
area = gmsh.model.geo.addPlaneSurface([loop])

#Mesh generating
gmsh.model.geo.synchronize()
gmsh.model.addPhysicalGroup(1, [area], name="Area")
gmsh.model.mesh.generate(2)
gmsh.write("pr2.msh")
nodeTags, nodeCoords, parametricCoord = gmsh.model.mesh.getNodes()
if '-nopopup' not in sys.argv:
    gmsh.fltk.run()
gmsh.finalize()

However, the output file has small common with my mesh. I can obtain coordinates of the nodes from the variable nodeCoords, but I cannot get the sets of nodes for every triangle. I tried already quite everything. Do I do something wrong?

Summarizing, I construct triangular 2D mesh for some geometrically simple area. In the code, area generating and mesh constructing are performed. The problem is to obtain triples of nodes which are correlated to each triangle.

0

There are 0 best solutions below