/
ref_oct_test.c
386 lines (356 loc) · 12.2 KB
/
ref_oct_test.c
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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
/* Copyright 2006, 2014, 2021 United States Government as represented
* by the Administrator of the National Aeronautics and Space
* Administration. No copyright is claimed in the United States under
* Title 17, U.S. Code. All Other Rights Reserved.
*
* The refine version 3 unstructured grid adaptation platform is
* licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
#include "ref_oct.h"
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include "ref_args.h"
#include "ref_cell.h"
#include "ref_export.h"
#include "ref_grid.h"
#include "ref_import.h"
#include "ref_mpi.h"
#include "ref_node.h"
int main(int argc, char *argv[]) {
REF_INT pos;
REF_MPI ref_mpi;
RSS(ref_mpi_start(argc, argv), "start");
RSS(ref_mpi_create(&ref_mpi), "make mpi");
RXS(ref_args_find(argc, argv, "--tec", &pos), REF_NOT_FOUND, "arg search");
if (pos != REF_EMPTY && pos + 1 < argc) {
REF_OCT ref_oct;
RSS(ref_oct_create(&ref_oct), "make oct");
RSS(ref_oct_split(ref_oct, 0), "split root");
RSS(ref_oct_split(ref_oct, 1), "split first child");
RSS(ref_oct_split(ref_oct, 9), "split second gen");
RSS(ref_oct_tec(ref_oct, argv[pos + 1]), "tec");
RSS(ref_oct_free(ref_oct), "free oct");
RSS(ref_mpi_free(ref_mpi), "mpi free");
RSS(ref_mpi_stop(), "stop");
return 0;
}
RXS(ref_args_find(argc, argv, "--box", &pos), REF_NOT_FOUND, "arg search");
if (pos != REF_EMPTY && pos + 1 < argc) {
REF_GRID ref_grid;
REF_OCT ref_oct;
REF_DBL h = 0.05;
RSS(ref_grid_create(&ref_grid, ref_mpi), "make grid");
RSS(ref_oct_create(&ref_oct), "make oct");
RSS(ref_oct_split_touching(ref_oct, ref_oct->bbox, h), "split");
RSS(ref_oct_export(ref_oct, ref_grid), "export");
RSS(ref_export_by_extension(ref_grid, argv[pos + 1]), "export");
RSS(ref_oct_free(ref_oct), "free oct");
RSS(ref_grid_free(ref_grid), "free grid");
RSS(ref_mpi_free(ref_mpi), "mpi free");
RSS(ref_mpi_stop(), "stop");
return 0;
}
RXS(ref_args_find(argc, argv, "--point", &pos), REF_NOT_FOUND, "arg search");
if (pos != REF_EMPTY && pos + 1 < argc) {
REF_OCT ref_oct;
REF_DBL xyz[3], h;
RSS(ref_oct_create(&ref_oct), "make oct");
xyz[0] = 0.3;
xyz[1] = 0.4;
xyz[2] = 0.49;
h = 0.01;
RSS(ref_oct_split_at(ref_oct, xyz, h), "split xyz h");
RSS(ref_oct_tec(ref_oct, argv[pos + 1]), "tec");
RSS(ref_oct_free(ref_oct), "search oct");
RSS(ref_mpi_free(ref_mpi), "mpi free");
RSS(ref_mpi_stop(), "stop");
return 0;
}
RXS(ref_args_find(argc, argv, "--surf", &pos), REF_NOT_FOUND, "arg search");
if (pos != REF_EMPTY && pos + 2 < argc) {
REF_OCT ref_oct;
char orig[1024];
REF_INT nleaf;
RSS(ref_oct_create(&ref_oct), "make oct");
{
REF_GRID ref_grid;
REF_CELL ref_cell;
REF_NODE ref_node;
REF_INT cell, nodes[REF_CELL_MAX_SIZE_PER];
RSS(ref_import_by_extension(&ref_grid, ref_mpi, argv[pos + 1]), "import");
ref_node = ref_grid_node(ref_grid);
ref_cell = ref_grid_tri(ref_grid);
each_ref_cell_valid_cell_with_nodes(ref_cell, cell, nodes) {
REF_DBL xyz[3], h, area;
REF_INT i, j;
RSS(ref_node_tri_area(ref_node, nodes, &area), "tri area");
h = sqrt(area);
for (j = 0; j < 3; j++) {
xyz[j] = 0;
for (i = 0; i < 3; i++) {
xyz[j] += ref_node_xyz(ref_node, j, nodes[i]) / 3.0;
}
}
RSS(ref_oct_split_at(ref_oct, xyz, h), "split xyz h");
}
RSS(ref_grid_free(ref_grid), "free grid");
}
snprintf(orig, 1024, "%s-raw.tec", argv[pos + 2]);
RSS(ref_oct_nleaf(ref_oct, &nleaf), "count leaves");
printf("writing %d vox to %s from %s\n", nleaf, orig, argv[pos + 1]);
RSS(ref_oct_tec(ref_oct, orig), "tec");
RSS(ref_oct_gradation(ref_oct), "grad");
RSS(ref_oct_nleaf(ref_oct, &nleaf), "count leaves");
printf("writing %d vox to %s from %s\n", nleaf, argv[pos + 2],
argv[pos + 1]);
RSS(ref_oct_tec(ref_oct, argv[pos + 2]), "tec");
RSS(ref_oct_free(ref_oct), "search oct");
RSS(ref_mpi_free(ref_mpi), "mpi free");
RSS(ref_mpi_stop(), "stop");
return 0;
}
{ /* create */
REF_OCT ref_oct;
RSS(ref_oct_create(&ref_oct), "make oct");
RSS(ref_oct_free(ref_oct), "free oct");
}
{ /* child's bbox */
REF_DBL parent_bbox[6], child_bbox[6];
REF_INT child_index = 0;
REF_DBL tol = -1.0;
parent_bbox[0] = 0.0;
parent_bbox[1] = 1.0;
parent_bbox[2] = 0.0;
parent_bbox[3] = 1.0;
parent_bbox[4] = 0.0;
parent_bbox[5] = 1.0;
RSS(ref_oct_child_bbox(parent_bbox, child_index, child_bbox), "bbox");
RWDS(0.0, child_bbox[0], tol, "not zero");
}
{ /* bbox diag */
REF_DBL bbox[6];
REF_DBL diag, tol = -1.0;
bbox[0] = 0.0;
bbox[1] = 0.5;
bbox[2] = 0.5;
bbox[3] = 1.0;
bbox[4] = 0.2;
bbox[5] = 0.7;
RSS(ref_oct_bbox_diag(bbox, &diag), "bbox diag");
RWDS(sqrt(0.75), diag, tol, "wrong size");
}
{ /* split root */
REF_OCT ref_oct;
RSS(ref_oct_create(&ref_oct), "make oct");
RSS(ref_oct_split(ref_oct, 0), "split oct");
RSS(ref_oct_free(ref_oct), "free oct");
}
{ /* one refinment, matching bbox */
REF_OCT ref_oct;
REF_DBL bbox[6], h;
bbox[0] = 0.0;
bbox[1] = 1.0;
bbox[2] = 0.0;
bbox[3] = 1.0;
bbox[4] = 0.0;
bbox[5] = 1.0;
h = 0.9 * sqrt(3.0);
RSS(ref_oct_create(&ref_oct), "make oct");
RSS(ref_oct_split_touching(ref_oct, bbox, h), "split main");
REIS(9, ref_oct_n(ref_oct), "expect one refinement, match")
RSS(ref_oct_free(ref_oct), "free oct");
}
{ /* two refinment, matching corner bbox */
REF_OCT ref_oct;
REF_DBL bbox[6], h;
bbox[0] = 0.0;
bbox[1] = 0.2;
bbox[2] = 0.0;
bbox[3] = 0.2;
bbox[4] = 0.0;
bbox[5] = 0.2;
h = 0.45 * sqrt(3.0);
RSS(ref_oct_create(&ref_oct), "make oct");
RSS(ref_oct_split_touching(ref_oct, bbox, h), "split main");
REIS(17, ref_oct_n(ref_oct), "expect one refinement, match")
RSS(ref_oct_free(ref_oct), "free oct");
}
{ /* gradation of spot refinement */
REF_OCT ref_oct;
RSS(ref_oct_create(&ref_oct), "make oct");
RSS(ref_oct_split(ref_oct, 0), "split root");
RSS(ref_oct_split(ref_oct, 1), "split first child");
RSS(ref_oct_split(ref_oct, 14), "split second gen");
RSS(ref_oct_gradation(ref_oct), "gradation");
RSS(ref_oct_free(ref_oct), "free oct");
}
{ /* root unique nodes */
REF_NODE ref_node;
REF_OCT ref_oct;
RSS(ref_node_create(&ref_node, ref_mpi), "make node");
RSS(ref_oct_create(&ref_oct), "make oct");
RSS(ref_oct_unique_nodes(ref_oct, ref_node), "make nodes");
REIS(8, ref_oct_nnode(ref_oct), "expects 8 node hex");
REIS(8, ref_node_n(ref_node), "ref_node n");
REIS(8, ref_node_n_global(ref_node), "ref_node global n");
RSS(ref_oct_free(ref_oct), "free oct");
RSS(ref_node_free(ref_node), "free node");
}
{ /* one split unique nodes */
REF_NODE ref_node;
REF_OCT ref_oct;
RSS(ref_node_create(&ref_node, ref_mpi), "make node");
RSS(ref_oct_create(&ref_oct), "make oct");
RSS(ref_oct_split(ref_oct, 0), "split root");
RSS(ref_oct_unique_nodes(ref_oct, ref_node), "make nodes");
REIS(27, ref_oct_nnode(ref_oct), "expects 8 node hex");
REIS(27, ref_node_n(ref_node), "ref_node n");
REIS(27, ref_node_n_global(ref_node), "ref_node global n");
RSS(ref_oct_free(ref_oct), "free oct");
RSS(ref_node_free(ref_node), "free node");
}
{ /* root export ref_grid */
REF_GRID ref_grid;
REF_OCT ref_oct;
RSS(ref_grid_create(&ref_grid, ref_mpi), "make grid");
RSS(ref_oct_create(&ref_oct), "make oct");
RSS(ref_oct_export(ref_oct, ref_grid), "export");
REIS(1, ref_cell_n(ref_grid_hex(ref_grid)), "hex");
REIS(6, ref_cell_n(ref_grid_qua(ref_grid)), "qua");
RSS(ref_oct_free(ref_oct), "free oct");
RSS(ref_grid_free(ref_grid), "free grid");
}
{ /* one export ref_grid */
REF_GRID ref_grid;
REF_OCT ref_oct;
RSS(ref_grid_create(&ref_grid, ref_mpi), "make grid");
RSS(ref_oct_create(&ref_oct), "make oct");
RSS(ref_oct_split(ref_oct, 0), "split root");
RSS(ref_oct_export(ref_oct, ref_grid), "export");
REIS(8, ref_cell_n(ref_grid_hex(ref_grid)), "hex");
REIS(24, ref_cell_n(ref_grid_qua(ref_grid)), "qua");
RSS(ref_oct_free(ref_oct), "free oct");
RSS(ref_grid_free(ref_grid), "free grid");
}
{ /* spot export ref_grid */
REF_GRID ref_grid;
REF_OCT ref_oct;
RSS(ref_grid_create(&ref_grid, ref_mpi), "make grid");
RSS(ref_oct_create(&ref_oct), "make oct");
RSS(ref_oct_split(ref_oct, 0), "split root");
RSS(ref_oct_split(ref_oct, 1), "split first");
RSS(ref_oct_export(ref_oct, ref_grid), "export");
RSS(ref_oct_free(ref_oct), "free oct");
RSS(ref_grid_free(ref_grid), "free grid");
}
{ /* contains root */
REF_OCT ref_oct;
REF_DBL xyz[] = {0.1, 0.1, 0.1};
REF_DBL bbox[6];
REF_INT node;
RSS(ref_oct_create(&ref_oct), "make oct");
RSS(ref_oct_contains(ref_oct, xyz, &node, bbox), "contains oct");
REIS(0, node, "expects root");
xyz[0] = 100.0;
RSS(ref_oct_contains(ref_oct, xyz, &node, bbox), "contains oct");
REIS(REF_EMPTY, node, "expects empty outside root");
RSS(ref_oct_free(ref_oct), "free oct");
}
{ /* contains child */
REF_OCT ref_oct;
REF_DBL xyz[] = {0.1, 0.1, 0.1};
REF_DBL bbox[6];
REF_INT node;
RSS(ref_oct_create(&ref_oct), "make oct");
RSS(ref_oct_split(ref_oct, 0), "split oct");
RSS(ref_oct_contains(ref_oct, xyz, &node, bbox), "contains oct");
REIS(1, node, "expects first child");
xyz[0] = 0.9;
xyz[1] = 0.1;
xyz[2] = 0.1;
RSS(ref_oct_contains(ref_oct, xyz, &node, bbox), "contains oct");
REIS(2, node, "expects last child");
xyz[0] = 0.1;
xyz[1] = 0.9;
xyz[2] = 0.1;
RSS(ref_oct_contains(ref_oct, xyz, &node, bbox), "contains oct");
REIS(4, node, "expects last child");
xyz[0] = 0.9;
xyz[1] = 0.9;
xyz[2] = 0.9;
RSS(ref_oct_contains(ref_oct, xyz, &node, bbox), "contains oct");
REIS(7, node, "expects last child");
RSS(ref_oct_free(ref_oct), "free oct");
}
{
REF_OCT ref_oct;
REF_DBL xyz[] = {0.01, 0.01, 0.01};
REF_DBL bbox[6];
REF_INT node;
RSS(ref_oct_create(&ref_oct), "make oct");
RSS(ref_oct_split(ref_oct, 0), "split root");
RSS(ref_oct_split(ref_oct, 1), "split first child");
RSS(ref_oct_split(ref_oct, 9), "split second gen");
RSS(ref_oct_contains(ref_oct, xyz, &node, bbox), "contains oct");
REIS(17, node, "expects third level");
RSS(ref_oct_free(ref_oct), "free oct");
}
{
REF_DBL bbox0[6], bbox1[6];
REF_BOOL overlap;
bbox0[0] = 0.0;
bbox0[1] = 1.0;
bbox0[2] = 0.0;
bbox0[3] = 1.0;
bbox0[4] = 0.0;
bbox0[5] = 1.0;
bbox1[0] = 0.1;
bbox1[1] = 0.2;
bbox1[2] = 0.1;
bbox1[3] = 0.2;
bbox1[4] = 0.1;
bbox1[5] = 0.2;
RSS(ref_oct_bbox_overlap(bbox0, bbox1, &overlap), "overlap");
REIS(REF_TRUE, overlap, "expect overlap");
bbox1[0] = 1.1;
bbox1[1] = 1.2;
bbox1[2] = 0.1;
bbox1[3] = 0.2;
bbox1[4] = 0.1;
bbox1[5] = 0.2;
RSS(ref_oct_bbox_overlap(bbox0, bbox1, &overlap), "overlap");
REIS(REF_FALSE, overlap, "did expect overlap");
}
{
REF_DBL bbox0[6], bbox1[6];
REF_DBL factor;
REF_DBL tol = -1.0;
bbox0[0] = 0.0;
bbox0[1] = 1.0;
bbox0[2] = 0.0;
bbox0[3] = 2.0;
bbox0[4] = 0.0;
bbox0[5] = 4.0;
factor = 1.1;
RSS(ref_oct_bbox_scale(bbox0, factor, bbox1), "scale");
RWDS(-0.05, bbox1[0], tol, "xmin");
RWDS(1.05, bbox1[1], tol, "xmax");
RWDS(-0.1, bbox1[2], tol, "ymin");
RWDS(2.1, bbox1[3], tol, "ymax");
RWDS(-0.2, bbox1[4], tol, "zmin");
RWDS(4.2, bbox1[5], tol, "zmax");
}
RSS(ref_mpi_free(ref_mpi), "mpi free");
RSS(ref_mpi_stop(), "stop");
return 0;
}