Mesh Oriented datABase  (version 5.6.0)
An array-based unstructured mesh library
makeops.cpp
Go to the documentation of this file.
1 /*
2  * Program to make hex modification operation meshes
3  *
4  */
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 
17 static ErrorCode make_chord_push();
20 
22 {
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  // now write to a file
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 
120 {
121  // make atomic pillow configuration
122  // make all vertices
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] );
134  MB_CHK_ERR( result );
135  }
136 
137  EntityHandle conn[8], elems[4];
138 
139  // make the two hexes
140  for( int i = 0; i < 8; i++ )
141  conn[i] = vtx_handles[connect[i]];
142  result = gMB->create_element( MBHEX, conn, 8, elems[0] );
143  MB_CHK_ERR( result );
144 
145  for( int i = 0; i < 8; i++ )
146  conn[i] = vtx_handles[connect[8 + i]];
147  result = gMB->create_element( MBHEX, conn, 8, elems[1] );
148  MB_CHK_ERR( result );
149 
150  // make one of the end quads explicitly and bind to the first hex
151  for( int i = 0; i < 4; i++ )
152  conn[i] = vtx_handles[connect[i]];
153  result = gMB->create_element( MBQUAD, conn, 4, elems[2] );
154  MB_CHK_ERR( result );
155 
156  result = gMB->add_adjacencies( elems[2], elems, 1, false );
157  MB_CHK_ERR( result );
158 
159  // now the other one
160  result = gMB->create_element( MBQUAD, conn, 4, elems[3] );
161  MB_CHK_ERR( result );
162 
163  result = gMB->add_adjacencies( elems[3], &elems[1], 1, false );
164  MB_CHK_ERR( result );
165 
166  return MB_SUCCESS;
167 }
168 
170 {
171  // make face shrink configuration
172  // make all vertices
173  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,
174  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,
175  2.0, 0.0, 1.0, 2.0, .75, .75, 1.0, .75, .25, 1.0, .25, .25, 1.0, .25, .75, 1.0 };
176 
177  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,
178  2, 6, 10, 14, 3, 7, 11, 15, 0, 3, 2, 1, 12, 15, 14, 13, 12, 15, 14, 13, 8, 11, 10, 9 };
179 
180  ErrorCode result;
181  EntityHandle vtx_handles[16];
182 
183  for( int i = 0; i < 16; i++ )
184  {
185  result = gMB->create_vertex( &vtx_coord[3 * i], vtx_handles[i] );
186  MB_CHK_ERR( result );
187  }
188 
189  // make all elements at once
190  EntityHandle conn[8], elems[6];
191 
192  for( int j = 0; j < 6; j++ )
193  {
194  for( int i = 0; i < 8; i++ )
195  conn[i] = vtx_handles[connect[j * 8 + i]];
196 
197  result = gMB->create_element( MBHEX, conn, 8, elems[j] );
198  MB_CHK_ERR( result );
199  }
200 
201  return MB_SUCCESS;
202 }
203 
205 {
206  return MB_FAILURE;
207 }
208 
210 {
211  // make chord push configuration
212  // make all vertices
213  double vtx_coord[] = { // first layer
214  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,
215  0.0, 1.0, 0.5, 0.0,
216  // second layer
217  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,
218  -0.5, -1.0, 1.0, 0.5, -1.0,
219  // 2 extra vertices for chord push
220  0.0, -.333, 0.05, 0.0, -.667, 0.10 };
221 
222  int connect[] = { // 3 "normal" hexes first
223  // top hex
224  0, 2, 1, 6, 7, 9, 8, 13,
225  // bottom left
226  0, 4, 3, 2, 7, 11, 10, 9,
227  // bottom right
228  6, 5, 4, 0, 13, 12, 11, 7,
229  // front chord push hex
230  2, 0, 4, 3, 14, 6, 5, 15,
231  // back chord push hex
232  2, 14, 15, 3, 0, 6, 5, 4,
233  // front/rear quads a, b
234  2, 0, 4, 3, 6, 5, 4, 0,
235  // duplicate edges from chord push
236  0, 4,
237  // face between bottom 2 normal hexes (needed for explicit
238  // adjacency)
239  0, 4, 11, 7 };
240 
241  ErrorCode result;
242  EntityHandle vtx_handles[16];
243 
244  for( int i = 0; i < 16; i++ )
245  {
246  result = gMB->create_vertex( &vtx_coord[3 * i], vtx_handles[i] );
247  MB_CHK_ERR( result );
248  }
249 
250  EntityHandle conn[8], elems[12];
251 
252  // make the five hexes
253  for( int i = 0; i < 5; i++ )
254  {
255  for( int j = 0; j < 8; j++ )
256  conn[j] = vtx_handles[connect[8 * i + j]];
257  result = gMB->create_element( MBHEX, conn, 8, elems[i] );
258  MB_CHK_ERR( result );
259  }
260 
261  // make the frontmost pair of quads and bind to the front degen hex
262  for( int i = 0; i < 2; i++ )
263  {
264  for( int j = 0; j < 4; j++ )
265  conn[j] = vtx_handles[connect[40 + 4 * i + j]];
266  result = gMB->create_element( MBQUAD, conn, 4, elems[5 + i] );
267  MB_CHK_ERR( result );
268  }
269 
270  // now the back pair
271  for( int i = 0; i < 2; i++ )
272  {
273  for( int j = 0; j < 4; j++ )
274  conn[j] = vtx_handles[connect[40 + 4 * i + j]];
275  result = gMB->create_element( MBQUAD, conn, 4, elems[7 + i] );
276  MB_CHK_ERR( result );
277  }
278 
279  // make the duplicated edges explicitly too
280  for( int i = 0; i < 2; i++ )
281  {
282  for( int j = 0; j < 2; j++ )
283  conn[j] = vtx_handles[connect[48 + j]];
284  result = gMB->create_element( MBEDGE, conn, 2, elems[9 + i] );
285  MB_CHK_ERR( result );
286  }
287 
288  // now the quad between the lower pair of hexes
289  for( int j = 0; j < 4; j++ )
290  conn[j] = vtx_handles[connect[50 + j]];
291  result = gMB->create_element( MBQUAD, conn, 4, elems[11] );
292  MB_CHK_ERR( result );
293 
294  // now set adjacencies explicitly
295  // front/rear duplicated edge to front/rear pair of quads
296  result = gMB->add_adjacencies( elems[9], &elems[5], 2, false );
297  MB_CHK_ERR( result );
298  result = gMB->add_adjacencies( elems[10], &elems[7], 2, false );
299  MB_CHK_ERR( result );
300 
301  // rear duplicated edge to quad between lower pair of normal hexes
302  result = gMB->add_adjacencies( elems[10], &elems[11], 1, false );
303  MB_CHK_ERR( result );
304 
305  // front/rear duplicated edge to front/rear degen hex
306  result = gMB->add_adjacencies( elems[9], &elems[3], 1, false );
307  MB_CHK_ERR( result );
308  result = gMB->add_adjacencies( elems[10], &elems[4], 1, false );
309  MB_CHK_ERR( result );
310 
311  // rear duplicated edge to normal hexes behind it
312  result = gMB->add_adjacencies( elems[10], &elems[1], 2, false );
313  MB_CHK_ERR( result );
314 
315  // front pair of quads to front degen hex
316  result = gMB->add_adjacencies( elems[5], &elems[3], 1, false );
317  MB_CHK_ERR( result );
318  result = gMB->add_adjacencies( elems[6], &elems[3], 1, false );
319  MB_CHK_ERR( result );
320 
321  // rear pair of quads to rear degen hex
322  result = gMB->add_adjacencies( elems[7], &elems[4], 1, false );
323  MB_CHK_ERR( result );
324  result = gMB->add_adjacencies( elems[8], &elems[4], 1, false );
325  MB_CHK_ERR( result );
326 
327  // rear pair of quads to normal hexes behind them
328  result = gMB->add_adjacencies( elems[7], &elems[1], 1, false );
329  MB_CHK_ERR( result );
330  result = gMB->add_adjacencies( elems[8], &elems[2], 1, false );
331  MB_CHK_ERR( result );
332 
333  return MB_SUCCESS;
334 }
335 
337 {
338  // make chord push configuration
339  // make all vertices
340  double vtx_coord[] = { // first layer
341  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,
342  0.0, 1.0, 0.5, 0.0,
343  // second layer
344  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,
345  -0.5, -1.0, 1.0, 0.5, -1.0,
346  // 2 extra vertices in middle
347  0.0, 0.0, -0.25, 0.0, 0.0, 0.0 };
348 
349  int connect[] = { // 3 "normal" hexes first
350  // top hex
351  14, 2, 1, 6, 7, 9, 8, 13,
352  // bottom left
353  14, 4, 3, 2, 7, 11, 10, 9,
354  // bottom right
355  6, 5, 4, 14, 13, 12, 11, 7,
356  // front triple chord push hex
357  0, 4, 3, 2, 6, 5, 15, 1,
358  // back triple chord push hex
359  2, 1, 15, 3, 14, 6, 5, 4 };
360 
361  ErrorCode result;
362  EntityHandle vtx_handles[16];
363 
364  for( int i = 0; i < 16; i++ )
365  {
366  result = gMB->create_vertex( &vtx_coord[3 * i], vtx_handles[i] );
367  MB_CHK_ERR( result );
368  }
369 
370  EntityHandle conn[8], elems[12];
371 
372  // make the five hexes
373  for( int i = 0; i < 5; i++ )
374  {
375  for( int j = 0; j < 8; j++ )
376  conn[j] = vtx_handles[connect[8 * i + j]];
377  result = gMB->create_element( MBHEX, conn, 8, elems[i] );
378  MB_CHK_ERR( result );
379  }
380 
381  return MB_SUCCESS;
382 }
383 
385 {
386  return MB_FAILURE;
387 }