/
ref_oct_test.c
150 lines (136 loc) · 4.58 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
/* 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_mpi.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), "search oct");
RSS(ref_mpi_free(ref_mpi), "mpi free");
RSS(ref_mpi_stop(), "stop");
return 0;
}
RXS(ref_args_find(argc, argv, "--to", &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.5;
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;
}
{ /* create */
REF_OCT ref_oct;
RSS(ref_oct_create(&ref_oct), "make oct");
RSS(ref_oct_free(ref_oct), "free oct");
}
{ /* 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");
}
{ /* 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");
}
{ /* 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");
}
RSS(ref_mpi_free(ref_mpi), "mpi free");
RSS(ref_mpi_stop(), "stop");
return 0;
}