Mesh Oriented datABase  (version 5.5.1)
An array-based unstructured mesh library
honodes.cpp
Go to the documentation of this file.
1 #include <iostream>
2 #include <moab/Core.hpp>
3 #include "moab/ProgOptions.hpp"
4 
5 using namespace moab;
6 using namespace std;
7 const char BRIEF_DESC[] = "Add higher order nodes to existing mesh, eg. hex8 to hex27 (default). "
8  "Use available options as desired.";
9 std::ostringstream LONG_DESC;
10 
11 int main( int argc, char* argv[] )
12 {
13  moab::Core* mb = new moab::Core();
14  moab::ErrorCode rval;
15  bool edge = false;
16  bool face = false;
17  bool volume = false;
18 
19  LONG_DESC << "mbhonodes tool reads a mesh file and adds higher order nodes." << std::endl
20  << "Options to add higher order nodes on all volume or face or edge elements of the mesh "
21  "are supported"
22  << std::endl
23  << "Example1: Use the following command to create hex mid volume nodes, in.h5m is a hex8 "
24  "mesh"
25  << std::endl
26  << " -> mbhonodes -i in.h5m -o o.h5m -f -e" << std::endl
27  << "Example2: Use the following command to create hex27 mesh o2.h5m, in.h5m is a hex8 mesh" << std::endl
28  << " -> mbhonodes -i in.h5m -o o2.h5m" << std::endl;
29 
30  ProgOptions opts( LONG_DESC.str(), BRIEF_DESC );
31  string inFileName = "";
32  opts.addRequiredArg< string >( "inFile,i", "Specify the output file name string", &inFileName );
33 #ifdef MOAB_HAVE_HDF5
34  string outFileName = "outfile.h5m";
35 #else
36  string outFileName = "outfile.vtk";
37 #endif
38  opts.addOpt< string >( "outFile,o", "Specify the output file name string (default outfile.h5m)", &outFileName );
39  opts.addOpt< void >( "edge,e", "DO NOT create mid nodes along edge (default=true)", &edge );
40  opts.addOpt< void >( "face,f", "DO NOT create face mid nodes (default=true)", &face );
41  opts.addOpt< void >( "volume,v", "DO NOT create volume mid nodes (default=true)", &volume );
42 
43  opts.parseCommandLine( argc, argv );
44 
45  // load the input file
46  rval = mb->load_mesh( inFileName.c_str() );MB_CHK_SET_ERR( rval, "Failed to write the mesh file" );
47  std::cout << "Read input mesh file: " << inFileName << std::endl;
49  moab::EntityHandle meshset;
50 
51  rval = mb->get_entities_by_type( 0, MBHEX, entities );MB_CHK_SET_ERR( rval, "Failed to get hex entities" );
52  rval = mb->create_meshset( MESHSET_SET, meshset );MB_CHK_SET_ERR( rval, "Failed to create meshset" );
53  rval = mb->add_entities( meshset, entities );MB_CHK_SET_ERR( rval, "Failed to add entitites to meshset" );
54 
55  rval = mb->convert_entities( meshset, !edge, !face, !volume );MB_CHK_SET_ERR( rval, "Failed to convert to higher dimension entities" );
56 
57  rval = mb->write_mesh( outFileName.c_str() );MB_CHK_SET_ERR( rval, "Failed to write the mesh file" );
58  std::cout << "Wrote mesh file: " << outFileName << std::endl;
59  delete mb;
60 }