1
5
6 #include "moab/Core.hpp"
7 #include "moab/Range.hpp"
8 #include <iostream>
9
10 using namespace moab;
11
12 Interface* gMB = NULL;
13
14 static ErrorCode make_atomic_pillow();
15 static ErrorCode make_face_shrink();
16 static ErrorCode make_face_open_collapse();
17 static ErrorCode make_chord_push();
18 static ErrorCode make_triple_chord_push();
19 static ErrorCode make_triple_hex_push();
20
21 enum OperationType
22 {
23 ATOMIC_PILLOW = 0,
24 FACE_OPEN_COLLAPSE,
25 FACE_SHRINK,
26 CHORD_PUSH,
27 MBTRIPLE_CHORD_PUSH,
28 MBTRIPLE_HEX_PUSH,
29 UNDEFINED
30 };
31
32 const char* OperationNames[] = { "atomic_pillow", "face_open_collapse", "face_shrink", "chord_push",
33 "triple_chord_push", "triple_hex_push", "undefined" };
34
35 int main( int argc, char** argv )
36 {
37 gMB = new Core();
38 const char* extensions[] = { ".g", ".h5m", ".vtk" };
39 int file_exten = 1;
40
41 std::vector< OperationType > op_types;
42
43 if( argc < 2 )
44 {
45 std::cout << "Usage: " << argv[0] << " [-h5m] [-vtk] {-ap | -foc | -fs | -cp | -tcp | -thp}" << std::endl;
46 return 1;
47 }
48
49 int current_arg = 1;
50 while( current_arg < argc )
51 {
52 if( !strcmp( "-g", argv[current_arg] ) )
53 file_exten = 0;
54 else if( !strcmp( "-h5m", argv[current_arg] ) )
55 file_exten = 1;
56 else if( !strcmp( "-vtk", argv[current_arg] ) )
57 file_exten = 2;
58 else if( !strcmp( "-ap", argv[current_arg] ) )
59 op_types.push_back( ATOMIC_PILLOW );
60 else if( !strcmp( "-foc", argv[current_arg] ) )
61 op_types.push_back( FACE_OPEN_COLLAPSE );
62 else if( !strcmp( "-fs", argv[current_arg] ) )
63 op_types.push_back( FACE_SHRINK );
64 else if( !strcmp( "-cp", argv[current_arg] ) )
65 op_types.push_back( CHORD_PUSH );
66 else if( !strcmp( "-tcp", argv[current_arg] ) )
67 op_types.push_back( MBTRIPLE_CHORD_PUSH );
68 else if( !strcmp( "-thp", argv[current_arg] ) )
69 op_types.push_back( MBTRIPLE_HEX_PUSH );
70 current_arg++;
71 }
72
73 ErrorCode result = MB_SUCCESS, tmp_result = MB_FAILURE;
74
75 for( std::vector< OperationType >::iterator vit = op_types.begin(); vit != op_types.end(); ++vit )
76 {
77 if( *vit == ATOMIC_PILLOW )
78 {
79 tmp_result = make_atomic_pillow();
80 }
81 else if( *vit == FACE_OPEN_COLLAPSE )
82 {
83 tmp_result = make_face_open_collapse();
84 }
85 else if( *vit == CHORD_PUSH )
86 {
87 tmp_result = make_chord_push();
88 }
89 else if( *vit == MBTRIPLE_CHORD_PUSH )
90 {
91 tmp_result = make_triple_chord_push();
92 }
93
94 else if( *vit == MBTRIPLE_HEX_PUSH )
95 {
96 tmp_result = make_triple_hex_push();
97 }
98 else if( *vit == FACE_SHRINK )
99 {
100 tmp_result = make_face_shrink();
101 }
102 else
103 {
104 std::cout << "Operation undefined." << std::endl;
105 return 1;
106 }
107 if( MB_SUCCESS != tmp_result ) result = tmp_result;
108
109
110 std::string filename( OperationNames[*vit] );
111 filename.append( extensions[file_exten] );
112 tmp_result = gMB->write_mesh( filename.c_str() );
113 if( MB_SUCCESS != tmp_result ) result = tmp_result;
114 }
115
116 return ( result == MB_SUCCESS ? 0 : 1 );
117 }
118
119 ErrorCode make_atomic_pillow()
120 {
121
122
123 double vtx_coord[] = { 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0,
124 .75, .75, 1.0, .75, .25, 1.0, .25, .25, 1.0, .25, .75, 1.0 };
125
126 int connect[] = { 0, 1, 2, 3, 4, 5, 6, 7, 4, 5, 6, 7, 0, 1, 2, 3 };
127
128 ErrorCode result;
129 EntityHandle vtx_handles[8];
130
131 for( int i = 0; i < 8; i++ )
132 {
133 result = gMB->create_vertex( &vtx_coord[3 * i], vtx_handles[i] );MB_CHK_ERR( result );
134 }
135
136 EntityHandle conn[8], elems[4];
137
138
139 for( int i = 0; i < 8; i++ )
140 conn[i] = vtx_handles[connect[i]];
141 result = gMB->create_element( MBHEX, conn, 8, elems[0] );MB_CHK_ERR( result );
142
143 for( int i = 0; i < 8; i++ )
144 conn[i] = vtx_handles[connect[8 + i]];
145 result = gMB->create_element( MBHEX, conn, 8, elems[1] );MB_CHK_ERR( result );
146
147
148 for( int i = 0; i < 4; i++ )
149 conn[i] = vtx_handles[connect[i]];
150 result = gMB->create_element( MBQUAD, conn, 4, elems[2] );MB_CHK_ERR( result );
151
152 result = gMB->add_adjacencies( elems[2], elems, 1, false );MB_CHK_ERR( result );
153
154
155 result = gMB->create_element( MBQUAD, conn, 4, elems[3] );MB_CHK_ERR( result );
156
157 result = gMB->add_adjacencies( elems[3], &elems[1], 1, false );MB_CHK_ERR( result );
158
159 return MB_SUCCESS;
160 }
161
162 ErrorCode make_face_shrink()
163 {
164
165
166 double vtx_coord[] = { 1.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0,
167 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 2.0, 1.0, 0.0, 2.0, 0.0, 0.0,
168 2.0, 0.0, 1.0, 2.0, .75, .75, 1.0, .75, .25, 1.0, .25, .25, 1.0, .25, .75, 1.0 };
169
170 int connect[] = { 3, 7, 11, 15, 0, 4, 8, 12, 0, 4, 8, 12, 1, 5, 9, 13, 1, 5, 9, 13, 2, 6, 10, 14,
171 2, 6, 10, 14, 3, 7, 11, 15, 0, 3, 2, 1, 12, 15, 14, 13, 12, 15, 14, 13, 8, 11, 10, 9 };
172
173 ErrorCode result;
174 EntityHandle vtx_handles[16];
175
176 for( int i = 0; i < 16; i++ )
177 {
178 result = gMB->create_vertex( &vtx_coord[3 * i], vtx_handles[i] );MB_CHK_ERR( result );
179 }
180
181
182 EntityHandle conn[8], elems[6];
183
184 for( int j = 0; j < 6; j++ )
185 {
186 for( int i = 0; i < 8; i++ )
187 conn[i] = vtx_handles[connect[j * 8 + i]];
188
189 result = gMB->create_element( MBHEX, conn, 8, elems[j] );MB_CHK_ERR( result );
190 }
191
192 return MB_SUCCESS;
193 }
194
195 ErrorCode make_face_open_collapse()
196 {
197 return MB_FAILURE;
198 }
199
200 ErrorCode make_chord_push()
201 {
202
203
204 double vtx_coord[] = {
205 0.0, 0.0, 0.5, 0.0, 1.0, 0.0, -1.0, 0.5, 0.0, -1.0, -0.5, 0.0, 0.0, -1.0, 0.0, 1.0, -0.5,
206 0.0, 1.0, 0.5, 0.0,
207
208 0.0, 0.0, -1.5, 0.0, 1.0, -1.0, -1.0, 0.5, -1.0, -1.0, -0.5, -1.0, 0.0, -1.0, -1.0, 1.0,
209 -0.5, -1.0, 1.0, 0.5, -1.0,
210
211 0.0, -.333, 0.05, 0.0, -.667, 0.10 };
212
213 int connect[] = {
214
215 0, 2, 1, 6, 7, 9, 8, 13,
216
217 0, 4, 3, 2, 7, 11, 10, 9,
218
219 6, 5, 4, 0, 13, 12, 11, 7,
220
221 2, 0, 4, 3, 14, 6, 5, 15,
222
223 2, 14, 15, 3, 0, 6, 5, 4,
224
225 2, 0, 4, 3, 6, 5, 4, 0,
226
227 0, 4,
228
229
230 0, 4, 11, 7 };
231
232 ErrorCode result;
233 EntityHandle vtx_handles[16];
234
235 for( int i = 0; i < 16; i++ )
236 {
237 result = gMB->create_vertex( &vtx_coord[3 * i], vtx_handles[i] );MB_CHK_ERR( result );
238 }
239
240 EntityHandle conn[8], elems[12];
241
242
243 for( int i = 0; i < 5; i++ )
244 {
245 for( int j = 0; j < 8; j++ )
246 conn[j] = vtx_handles[connect[8 * i + j]];
247 result = gMB->create_element( MBHEX, conn, 8, elems[i] );MB_CHK_ERR( result );
248 }
249
250
251 for( int i = 0; i < 2; i++ )
252 {
253 for( int j = 0; j < 4; j++ )
254 conn[j] = vtx_handles[connect[40 + 4 * i + j]];
255 result = gMB->create_element( MBQUAD, conn, 4, elems[5 + i] );MB_CHK_ERR( result );
256 }
257
258
259 for( int i = 0; i < 2; i++ )
260 {
261 for( int j = 0; j < 4; j++ )
262 conn[j] = vtx_handles[connect[40 + 4 * i + j]];
263 result = gMB->create_element( MBQUAD, conn, 4, elems[7 + i] );MB_CHK_ERR( result );
264 }
265
266
267 for( int i = 0; i < 2; i++ )
268 {
269 for( int j = 0; j < 2; j++ )
270 conn[j] = vtx_handles[connect[48 + j]];
271 result = gMB->create_element( MBEDGE, conn, 2, elems[9 + i] );MB_CHK_ERR( result );
272 }
273
274
275 for( int j = 0; j < 4; j++ )
276 conn[j] = vtx_handles[connect[50 + j]];
277 result = gMB->create_element( MBQUAD, conn, 4, elems[11] );MB_CHK_ERR( result );
278
279
280
281 result = gMB->add_adjacencies( elems[9], &elems[5], 2, false );MB_CHK_ERR( result );
282 result = gMB->add_adjacencies( elems[10], &elems[7], 2, false );MB_CHK_ERR( result );
283
284
285 result = gMB->add_adjacencies( elems[10], &elems[11], 1, false );MB_CHK_ERR( result );
286
287
288 result = gMB->add_adjacencies( elems[9], &elems[3], 1, false );MB_CHK_ERR( result );
289 result = gMB->add_adjacencies( elems[10], &elems[4], 1, false );MB_CHK_ERR( result );
290
291
292 result = gMB->add_adjacencies( elems[10], &elems[1], 2, false );MB_CHK_ERR( result );
293
294
295 result = gMB->add_adjacencies( elems[5], &elems[3], 1, false );MB_CHK_ERR( result );
296 result = gMB->add_adjacencies( elems[6], &elems[3], 1, false );MB_CHK_ERR( result );
297
298
299 result = gMB->add_adjacencies( elems[7], &elems[4], 1, false );MB_CHK_ERR( result );
300 result = gMB->add_adjacencies( elems[8], &elems[4], 1, false );MB_CHK_ERR( result );
301
302
303 result = gMB->add_adjacencies( elems[7], &elems[1], 1, false );MB_CHK_ERR( result );
304 result = gMB->add_adjacencies( elems[8], &elems[2], 1, false );MB_CHK_ERR( result );
305
306 return MB_SUCCESS;
307 }
308
309 ErrorCode make_triple_chord_push()
310 {
311
312
313 double vtx_coord[] = {
314 0.0, 0.0, 0.5, 0.0, 1.0, 0.0, -1.0, 0.5, 0.0, -1.0, -0.5, 0.0, 0.0, -1.0, 0.0, 1.0, -0.5,
315 0.0, 1.0, 0.5, 0.0,
316
317 0.0, 0.0, -1.5, 0.0, 1.0, -1.0, -1.0, 0.5, -1.0, -1.0, -0.5, -1.0, 0.0, -1.0, -1.0, 1.0,
318 -0.5, -1.0, 1.0, 0.5, -1.0,
319
320 0.0, 0.0, -0.25, 0.0, 0.0, 0.0 };
321
322 int connect[] = {
323
324 14, 2, 1, 6, 7, 9, 8, 13,
325
326 14, 4, 3, 2, 7, 11, 10, 9,
327
328 6, 5, 4, 14, 13, 12, 11, 7,
329
330 0, 4, 3, 2, 6, 5, 15, 1,
331
332 2, 1, 15, 3, 14, 6, 5, 4 };
333
334 ErrorCode result;
335 EntityHandle vtx_handles[16];
336
337 for( int i = 0; i < 16; i++ )
338 {
339 result = gMB->create_vertex( &vtx_coord[3 * i], vtx_handles[i] );MB_CHK_ERR( result );
340 }
341
342 EntityHandle conn[8], elems[12];
343
344
345 for( int i = 0; i < 5; i++ )
346 {
347 for( int j = 0; j < 8; j++ )
348 conn[j] = vtx_handles[connect[8 * i + j]];
349 result = gMB->create_element( MBHEX, conn, 8, elems[i] );MB_CHK_ERR( result );
350 }
351
352 return MB_SUCCESS;
353 }
354
355 ErrorCode make_triple_hex_push()
356 {
357 return MB_FAILURE;
358 }