Mesh Oriented datABase  (version 5.6.0)
An array-based unstructured mesh library
mbex3.cpp File Reference
#include "moab/Core.hpp"
#include "moab/ScdInterface.hpp"
#include <iostream>
+ Include dependency graph for mbex3.cpp:

Go to the source code of this file.

Functions

int main ()
 

Function Documentation

◆ main()

int main ( )
Examples
mbex3.cpp.

Definition at line 26 of file mbex3.cpp.

27 {
28  moab::ErrorCode rval;
29  moab::Core mbint;
30 
31  // **********************************
32  // * Create the Structured Mesh *
33  // **********************************
34 
35  // As before, we have to create an array defining the coordinate of
36  // each vertex:
37  const unsigned NUMVTX = 27;
38  const double vertex_coords[3 * NUMVTX] = {
39  0, 0, 0, 1, 0, 0, 2, 0, 0, 0, 1, 0, 1, 1, 0, 2, 1, 0, 0, 2, 0, 1, 2, 0, 2, 2, 0,
40 
41  0, 0, 1, 1, 0, 1, 2, 0, 1, 0, 1, 1, 1, 1, 1, 2, 1, 1, 0, 2, 1, 1, 2, 1, 2, 2, 1,
42 
43  0, 0, 2, 1, 0, 2, 2, 0, 2, 0, 1, 2, 1, 1, 2, 2, 1, 2, 0, 2, 2, 1, 2, 2, 2, 2, 2 };
44 
45  // moab::ScdInterface is the structured mesh interface class for
46  // MOAB.
47  moab::ScdInterface* scdint;
48 
49  // The query_interface method will create a structured mesh instance
50  // for mbcore and will point scdint to it. This is how you tell moab
51  // that our moab::Core instance is going to represent a structured
52  // mesh.
53  MB_CHK_SET_ERR( mbint.query_interface( scdint ), "mbint.query_interface failed" );
54 
55  // Structured meshes a divided into "boxes". Each box represents a
56  // little structured mesh. A single mesh, for example a
57  // block-structured mesh, can contain many individual boxes. In this
58  // example, we want to create a single, 2x2x2 box. The construct_box
59  // method will do this for us.
60  moab::ScdBox* scdbox = NULL;
61  MB_CHK_SET_ERR( scdint->construct_box( moab::HomCoord( 0, 0, 0 ), moab::HomCoord( 2, 2, 2 ), vertex_coords, NUMVTX,
62  scdbox ),
63  "scdint->construct_box failed" );
64 
65  // moab::HomCoord is a little class that is used to represent a
66  // coordinate in logical space. Above, we told MOAB that we want
67  // indexes which extend from 0,0,0 to 2,2,2 for vertexes. Since the
68  // i,j,k start/end indexes are all different, MOAB knows that our
69  // mesh consists of hexes. If we had gone from 0,0,0 to 1,1,0 then
70  // MOAB would construct a 2x2x1 mesh of quadrilaterals.
71 
72  // ***************
73  // * Inspect *
74  // ***************
75 
76  // Our mesh now exists and contains a single box! Lets loop over
77  // that box and manually print out the handle of each vertex/hex:
78  unsigned i, j, k;
79 
80  // Print out the entity handle associated with each hex:
81  for( i = 0; i < 2; ++i )
82  for( j = 0; j < 2; ++j )
83  for( k = 0; k < 2; ++k )
84  {
85  std::cout << "Hex (" << i << "," << j << "," << k << ") "
86  << "has handle: " << scdbox->get_element( i, j, k ) << std::endl;
87  }
88 
89  // Print out the entity handle associated with each vertex:
90  for( i = 0; i < 3; ++i )
91  for( j = 0; j < 3; ++j )
92  for( k = 0; k < 3; ++k )
93  {
94  std::cout << "Vertex (" << i << "," << j << "," << k << ") "
95  << "has handle: " << scdbox->get_vertex( i, j, k ) << std::endl;
96  }
97 
98  // Of course, you can still use all of the functionality defined in
99  // mbint to get coordinates, connectivity, etc...
100 
101  // ***************************
102  // * Write Mesh to Files *
103  // ***************************
104  MB_CHK_SET_ERR( mbint.write_file( "mbex3.vtk" ), "write_file(mbex3.vtk) failed" );
105 
106  return 0;
107 }

References moab::ScdInterface::construct_box(), ErrorCode, moab::ScdBox::get_element(), moab::ScdBox::get_vertex(), MB_CHK_SET_ERR, moab::Interface::query_interface(), and moab::Core::write_file().