-
Notifications
You must be signed in to change notification settings - Fork 9
/
examples.jl
214 lines (169 loc) · 5.7 KB
/
examples.jl
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
using TetGen
using LinearAlgebra
"""
random_delaunay(;npoints=20)
Create a Delaunay tetrahedralization from a random set of points.
This is a tetrahedralization of the convex hull of the points.
If the points are in general position (which we assume here),
it is unique.
"""
function random_delaunay(;npoints=20)
input=TetGen.RawTetGenIO{Cdouble}(pointlist=rand(3,npoints))
tetrahedralize(input, "Q")
end
"""
cube(;vol=1)
Tetrahedralization of cube witn maximum tetrahedron volume.
"""
function cube(;vol=1)
input=TetGen.RawTetGenIO{Cdouble}()
input.pointlist=[0 0 0;
1 0 0;
1 1 0;
0 1 0;
0 0 1;
1 0 1;
1 1 1;
0 1 1]'
TetGen.facetlist!(input,[1 2 3 4;
5 6 7 8;
1 2 6 5;
2 3 7 6;
3 4 8 7;
4 1 5 8]')
tetrahedralize(input, "pQa$(vol)")
end
"""
cubewithhole(;vol=1)
Tetrahedralization of cube witn maximum tetrahedron volume.
"""
function cubewithhole(;vol=1)
input=TetGen.RawTetGenIO{Cdouble}()
outerpoints=[-1 -1 -1;
1 -1 -1;
1 1 -1;
-1 1 -1;
-1 -1 1;
1 -1 1;
1 1 1;
-1 1 1;]'
input.pointlist=hcat(outerpoints,outerpoints/2)
outerfacets=[1 2 3 4;
5 6 7 8;
1 2 6 5;
2 3 7 6;
3 4 8 7;
4 1 5 8;
]'
input.holelist=[0 0 0;]'
TetGen.facetlist!(input,hcat(outerfacets,outerfacets.+8))
tetrahedralize(input, "pQa$(vol)")
end
"""
cube_localref()
Tetrahedralization of cube with local refinement callback
"""
function cube_localref()
tetunsuitable() do pa,pb,pc,pd
vol=det(hcat(pb-pa,pc-pa,pd-pa))/6
center=0.25*(pa+pb+pc+pd)-[0.5,0.5,0.5]
vol> 0.05*norm(center)^2.5
end
input=TetGen.RawTetGenIO{Cdouble}()
input.pointlist=[0 0 0;
1 0 0;
1 1 0;
0 1 0;
0 0 1;
1 0 1;
1 1 1;
0 1 1]'
TetGen.facetlist!(input,[1 2 3 4;
5 6 7 8;
1 2 6 5;
2 3 7 6;
3 4 8 7;
4 1 5 8]')
tetrahedralize(input, "pQa")
end
"""
prism(;vol=1)
Tetrahedralization of a prism with maximum tetrahedron volume.
"""
function prism(vol=2)
input=TetGen.RawTetGenIO{Cdouble}()
input.pointlist=[0 0 0;
1 0 0;
0 1 0;
0 0 1;
1 0 1;
0 1 1]'
TetGen.facetlist!(input,[[1,2,3],
[4,5,6],
[1,2,5,4],
[2,3,6,5],
[3,1,4,6]])
tetrahedralize(input, "pQa$(vol)")
end
"""
prism(;vol1=0.01, vol2=0.2)
Tetrahedralization of a prism with two regions with different tet volumes
"""
function material_prism(;vol1=0.01, vol2=0.1)
input=TetGen.RawTetGenIO{Cdouble}()
input.pointlist=[0 0 0;
1 0 0;
0 1 0;
0 0 1;
1 0 1;
0 1 1;
0 0 2;
1 0 2;
0 1 2]'
TetGen.facetlist!(input,[[1,2,3],
[7,8,9],
[1,2,5,4],
[2,3,6,5],
[3,1,4,6],
[1,2,5,4].+3,
[2,3,6,5].+3,
[3,1,4,6].+3])
input.facetmarkerlist=[1,2,3,3,3,3,3,3]
input.regionlist=[0.1 0.1 0.5 1 vol1;
0.1 0.1 1.5 2 vol2]'
tetrahedralize(input, "paAqQ")
end
"""
cutprism(;vol=0.05)
Tetrahedralization of a prism with a prism cut out in the middle.
This tests the use of facet holes.
"""
function cutprism(;vol=0.05)
input=TetGen.RawTetGenIO{Cdouble}()
input.pointlist=[0 0 0;
1 0 0;
0 1 0;
0 0 10;
1 0 10;
0 1 10;
-1 -1 0; # 7
2 -1 0;
2 2 0;
-1 2 0;
-1 -1 10; # 11
2 -1 10;
2 2 10;
-1 2 10]'
push!(input.facetlist,RawFacet([Cint[1, 2, 3],Cint[7, 8, 9, 10]], [0.1 0.1 0.0;]))
push!(input.facetlist,RawFacet([Cint[4, 5, 6],Cint[11,12,13,14]], [0.1 0.1 1.0;]))
push!(input.facetlist,RawFacet([Cint[1, 2, 5, 4 ]], Array{Cdouble,2}(undef,0,0)))
push!(input.facetlist,RawFacet([Cint[2, 3, 6, 5 ]], Array{Cdouble,2}(undef,0,0)))
push!(input.facetlist,RawFacet([Cint[3, 1, 4, 6 ]], Array{Cdouble,2}(undef,0,0)))
push!(input.facetlist,RawFacet([Cint[7, 8, 12,11]], Array{Cdouble,2}(undef,0,0)))
push!(input.facetlist,RawFacet([Cint[8, 9, 13,12]], Array{Cdouble,2}(undef,0,0)))
push!(input.facetlist,RawFacet([Cint[9, 10,14,13]], Array{Cdouble,2}(undef,0,0)))
push!(input.facetlist,RawFacet([Cint[10,7, 11,14]], Array{Cdouble,2}(undef,0,0)))
input.facetmarkerlist=[1,2,3,3,3,4,5,6,7]
input.regionlist=[ -0.1 -0.1 0.1 1 vol;]'
tetrahedralize(input, "paqAQ")
end