-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathincompatible_volume_example.py
83 lines (55 loc) · 2.06 KB
/
incompatible_volume_example.py
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import gmsh
def get_rectangle(center = [0,0],length = 3.0, width = 3.0,mesh_size=0.1):
# Define the coordinates of the square
x_min = center[0] - length / 2
x_max = center[0] + length / 2
y_min = center[1] - width / 2
y_max = center[1] + width / 2
# Define the points
p1 = gmsh.model.geo.addPoint(x_min, y_min, 0 , mesh_size)
p2 = gmsh.model.geo.addPoint(x_max, y_min, 0 , mesh_size)
p3 = gmsh.model.geo.addPoint(x_max, y_max, 0 , mesh_size)
p4 = gmsh.model.geo.addPoint(x_min, y_max, 0 , mesh_size)
# Define the lines
l1 = gmsh.model.geo.addLine(p1, p2)
l2 = gmsh.model.geo.addLine(p2, p3)
l3 = gmsh.model.geo.addLine(p3, p4)
l4 = gmsh.model.geo.addLine(p4, p1)
# Define the loop
loop = gmsh.model.geo.addCurveLoop([l1, l2, l3, l4])
return loop
def get_circle(center2D = [0,0],radius = 0.5,mesh_size=0.1):
# gmsh.model.add("circle_surface")
# Add points for the inner circle
p1 = gmsh.model.geo.addPoint(radius, 0, 0, mesh_size )
p2 = gmsh.model.geo.addPoint(0, radius, 0, mesh_size )
p3 = gmsh.model.geo.addPoint(-radius, 0, 0, mesh_size)
p4 = gmsh.model.geo.addPoint(0, -radius, 0, mesh_size)
centre = gmsh.model.geo.addPoint(center2D[0], center2D[1], 0, mesh_size, 9)
# circle arcs
arc1 = gmsh.model.geo.addCircleArc(p1, centre, p2)
arc2 = gmsh.model.geo.addCircleArc(p2, centre, p3)
arc3 = gmsh.model.geo.addCircleArc(p3, centre, p4)
arc4 = gmsh.model.geo.addCircleArc(p4, centre, p1)
loop = gmsh.model.geo.addCurveLoop([arc1,arc2,arc3,arc4])
return loop
def main():
# Initialize Gmsh
gmsh.initialize()
# Create a new model
gmsh.model.add("Extrusion")
c1 = get_rectangle()
c2 = get_circle()
surface = gmsh.model.geo.addPlaneSurface([c1,c2])
height = 2
extrusion = gmsh.model.geo.extrude([(2, surface)], 0, 0, height)
# Synchronize the geometry
gmsh.model.geo.synchronize()
# generate mesh
gmsh.model.mesh.generate(2)
# Save the mesh
gmsh.write("incompatible_volume_example.msh")
# Finalize GMSH
gmsh.finalize()
if __name__== "__main__":
main()