forked from lmengel422/FVCOM-Grid-Generation
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic_mesh_example.py
More file actions
43 lines (32 loc) · 916 Bytes
/
basic_mesh_example.py
File metadata and controls
43 lines (32 loc) · 916 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import gmsh
import sys
# Initialize Gmsh
gmsh.initialize()
# Create a new model
gmsh.model.add("simple_mesh")
# Add a rectangle (2D geometry)
# lc = characteristic length (controls mesh size)
lc = 0.1
gmsh.model.geo.addPoint(0, 0, 0, lc, 1)
gmsh.model.geo.addPoint(1, 0, 0, lc, 2)
gmsh.model.geo.addPoint(1, 1, 0, lc, 3)
gmsh.model.geo.addPoint(0, 1, 0, lc, 4)
# Add lines connecting the points
gmsh.model.geo.addLine(1, 2, 1)
gmsh.model.geo.addLine(2, 3, 2)
gmsh.model.geo.addLine(3, 4, 3)
gmsh.model.geo.addLine(4, 1, 4)
# Add a surface (closed loop)
gmsh.model.geo.addCurveLoop([1, 2, 3, 4], 1)
gmsh.model.geo.addPlaneSurface([1], 1)
# Synchronize geometry
gmsh.model.geo.synchronize()
# Generate 2D mesh
gmsh.model.mesh.generate(2)
# Save the mesh
gmsh.write("rectangle_mesh.msh")
# View it (optional - opens GUI)
gmsh.fltk.run()
# Finalize
gmsh.finalize()
print("Mesh generated: rectangle_mesh.msh")