-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmem_check_tetgen_build.rs
240 lines (227 loc) · 7.45 KB
/
mem_check_tetgen_build.rs
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
use std::thread;
use tritet::{StrError, Tetgen};
fn main() {
println!("Running Mem Check on Tetgen\n");
let mut handles = Vec::new();
for i in 0..20 {
let handle = thread::spawn(move || {
println!("..{}..", i);
run_all().unwrap();
});
handles.push(handle);
}
for handle in handles {
handle.join().unwrap();
}
println!("\nDone\n");
}
fn run_all() -> Result<(), StrError> {
let _tet = Tetgen::new(4, Some(vec![3, 3, 3, 3]), Some(1), Some(1))?;
new_captures_some_errors();
set_point_captures_some_errors()?;
set_facet_point_captures_some_errors()?;
set_region_captures_some_errors()?;
set_hole_captures_some_errors()?;
generate_methods_capture_some_errors()?;
generate_delaunay_works()?;
generate_mesh_works_1()?;
Ok(())
}
fn new_captures_some_errors() {
assert_eq!(Tetgen::new(3, None, None, None).err(), Some("npoint must be ≥ 4"));
assert_eq!(
Tetgen::new(4, Some(vec![3, 3, 3]), None, None).err(),
Some("nfacet must be ≥ 4")
);
assert_eq!(
Tetgen::new(4, Some(vec![3, 3, 3, 2]), None, None).err(),
Some("facet npoint must be ≥ 3")
);
}
fn set_point_captures_some_errors() -> Result<(), StrError> {
let mut tetgen = Tetgen::new(4, None, None, None)?;
assert_eq!(
tetgen.set_point(5, 0, 0.0, 0.0, 0.0).err(),
Some("index of point is out of bounds")
);
Ok(())
}
fn set_facet_point_captures_some_errors() -> Result<(), StrError> {
let mut tetgen = Tetgen::new(4, None, None, None)?;
assert_eq!(
tetgen.set_facet_point(0, 0, 0).err(),
Some("cannot set facet point because facet_npoint is None")
);
let mut tetgen = Tetgen::new(4, Some(vec![3, 3, 3, 3]), None, None)?;
assert_eq!(
tetgen.set_facet_point(5, 0, 0).err(),
Some("index of facet is out of bounds")
);
assert_eq!(
tetgen.set_facet_point(0, 4, 0).err(),
Some("index of facet point is out of bounds")
);
assert_eq!(
tetgen.set_facet_point(0, 0, 5).err(),
Some("id of facet point is out of bounds")
);
Ok(())
}
fn set_region_captures_some_errors() -> Result<(), StrError> {
let mut tetgen = Tetgen::new(4, None, None, None)?;
assert_eq!(
tetgen.set_region(0, 1, 0.33, 0.33, 0.33, Some(0.1)).err(),
Some("cannot set region because the number of regions is None")
);
let mut tetgen = Tetgen::new(4, Some(vec![3, 3, 3, 3]), Some(1), None)?;
assert_eq!(
tetgen.set_region(1, 1, 0.33, 0.33, 0.33, Some(0.1)).err(),
Some("index of region is out of bounds")
);
Ok(())
}
fn set_hole_captures_some_errors() -> Result<(), StrError> {
let mut tetgen = Tetgen::new(4, None, None, None)?;
assert_eq!(
tetgen.set_hole(0, 0.33, 0.33, 0.33).err(),
Some("cannot set hole because the number of holes is None")
);
let mut tetgen = Tetgen::new(4, Some(vec![3, 3, 3, 3]), Some(1), Some(1))?;
assert_eq!(
tetgen.set_hole(1, 0.33, 0.33, 0.33).err(),
Some("index of hole is out of bounds")
);
Ok(())
}
fn generate_methods_capture_some_errors() -> Result<(), StrError> {
let mut tetgen = Tetgen::new(4, Some(vec![3, 3, 3, 3]), None, None)?;
assert_eq!(
tetgen.generate_delaunay(false).err(),
Some("cannot generate Delaunay tetrahedralization because not all points are set")
);
assert_eq!(
tetgen.generate_mesh(false, false, None, None).err(),
Some("cannot generate mesh of tetrahedra because not all points are set")
);
tetgen
.set_point(0, 0, 0.0, 0.0, 0.0)?
.set_point(1, 0, 1.0, 0.0, 0.0)?
.set_point(2, 0, 0.0, 1.0, 0.0)?
.set_point(3, 0, 0.0, 0.0, 1.0)?;
assert_eq!(
tetgen.generate_mesh(false, false, None, None).err(),
Some("cannot generate mesh of tetrahedra because not all facets are set")
);
Ok(())
}
fn generate_delaunay_works() -> Result<(), StrError> {
let mut tetgen = Tetgen::new(4, None, None, None)?;
tetgen
.set_point(0, 0, 0.0, 0.0, 0.0)?
.set_point(1, 0, 1.0, 0.0, 0.0)?
.set_point(2, 0, 0.0, 1.0, 0.0)?
.set_point(3, 0, 0.0, 0.0, 1.0)?;
tetgen.generate_delaunay(false)?;
assert_eq!(tetgen.out_ncell(), 1);
assert_eq!(tetgen.out_npoint(), 4);
Ok(())
}
fn generate_mesh_works_1() -> Result<(), StrError> {
let mut tetgen = Tetgen::new(
16,
Some(vec![
4, 4, 4, 4, 4, 4, // inner cube
4, 4, 4, 4, 4, 4, // outer cube
]),
Some(1),
Some(1),
)?;
// inner cube
tetgen
.set_point(0, 0, 0.0, 0.0, 0.0)?
.set_point(1, 0, 1.0, 0.0, 0.0)?
.set_point(2, 0, 1.0, 1.0, 0.0)?
.set_point(3, 0, 0.0, 1.0, 0.0)?
.set_point(4, 0, 0.0, 0.0, 1.0)?
.set_point(5, 0, 1.0, 0.0, 1.0)?
.set_point(6, 0, 1.0, 1.0, 1.0)?
.set_point(7, 0, 0.0, 1.0, 1.0)?;
// outer cube
tetgen
.set_point(8, 0, -1.0, -1.0, -1.0)?
.set_point(9, 0, 2.0, -1.0, -1.0)?
.set_point(10, 0, 2.0, 2.0, -1.0)?
.set_point(11, 0, -1.0, 2.0, -1.0)?
.set_point(12, 0, -1.0, -1.0, 2.0)?
.set_point(13, 0, 2.0, -1.0, 2.0)?
.set_point(14, 0, 2.0, 2.0, 2.0)?
.set_point(15, 0, -1.0, 2.0, 2.0)?;
// inner cube
tetgen
.set_facet_point(0, 0, 0)?
.set_facet_point(0, 1, 4)?
.set_facet_point(0, 2, 7)?
.set_facet_point(0, 3, 3)?;
tetgen
.set_facet_point(1, 0, 1)?
.set_facet_point(1, 1, 2)?
.set_facet_point(1, 2, 6)?
.set_facet_point(1, 3, 5)?;
tetgen
.set_facet_point(2, 0, 0)?
.set_facet_point(2, 1, 1)?
.set_facet_point(2, 2, 5)?
.set_facet_point(2, 3, 4)?;
tetgen
.set_facet_point(3, 0, 2)?
.set_facet_point(3, 1, 3)?
.set_facet_point(3, 2, 7)?
.set_facet_point(3, 3, 6)?;
tetgen
.set_facet_point(4, 0, 0)?
.set_facet_point(4, 1, 3)?
.set_facet_point(4, 2, 2)?
.set_facet_point(4, 3, 1)?;
tetgen
.set_facet_point(5, 0, 4)?
.set_facet_point(5, 1, 5)?
.set_facet_point(5, 2, 6)?
.set_facet_point(5, 3, 7)?;
// outer cube
tetgen
.set_facet_point(6, 0, 8 + 0)?
.set_facet_point(6, 1, 8 + 4)?
.set_facet_point(6, 2, 8 + 7)?
.set_facet_point(6, 3, 8 + 3)?;
tetgen
.set_facet_point(7, 0, 8 + 1)?
.set_facet_point(7, 1, 8 + 2)?
.set_facet_point(7, 2, 8 + 6)?
.set_facet_point(7, 3, 8 + 5)?;
tetgen
.set_facet_point(8, 0, 8 + 0)?
.set_facet_point(8, 1, 8 + 1)?
.set_facet_point(8, 2, 8 + 5)?
.set_facet_point(8, 3, 8 + 4)?;
tetgen
.set_facet_point(9, 0, 8 + 2)?
.set_facet_point(9, 1, 8 + 3)?
.set_facet_point(9, 2, 8 + 7)?
.set_facet_point(9, 3, 8 + 6)?;
tetgen
.set_facet_point(10, 0, 8 + 0)?
.set_facet_point(10, 1, 8 + 3)?
.set_facet_point(10, 2, 8 + 2)?
.set_facet_point(10, 3, 8 + 1)?;
tetgen
.set_facet_point(11, 0, 8 + 4)?
.set_facet_point(11, 1, 8 + 5)?
.set_facet_point(11, 2, 8 + 6)?
.set_facet_point(11, 3, 8 + 7)?;
tetgen.set_region(0, 1, -0.9, -0.9, -0.9, None)?;
tetgen.set_hole(0, 0.5, 0.5, 0.5)?;
tetgen.generate_mesh(false, false, None, None)?;
assert_eq!(tetgen.out_ncell(), 60);
assert_eq!(tetgen.out_npoint(), 22);
Ok(())
}