Loading [MathJax]/extensions/tex2jax.js
Mesh Oriented datABase  (version 5.5.1)
An array-based unstructured mesh library
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TestErrorHandling.cpp
Go to the documentation of this file.
1 /** @example TestErrorHandling.cpp \n 2  * Description: This example tests MOAB's trace back error handler in serial. \n 3  * 4  * <b>To run</b>: ./TestErrorHandling <test_case_num(1 to 4)> \n 5  */ 6  7 #include "moab/Core.hpp" 8 #ifdef MOAB_HAVE_MPI 9 #include "moab_mpi.h" 10 #endif 11  12 #include <iostream> 13  14 using namespace moab; 15 using namespace std; 16  17 // In this test case, an error MB_NOT_IMPLEMENTED is returned by MOAB 18 ErrorCode TestErrorHandling_1() 19 { 20  Core moab; 21  Interface& mb = moab; 22  23  // Load a CAM-FV file and read a variable on edges (not supported yet) 24  string test_file = string( MESH_DIR ) + string( "/io/fv3x46x72.t.3.nc" ); 25  ErrorCode rval = mb.load_file( test_file.c_str(), NULL, "VARIABLE=US" );MB_CHK_ERR( rval ); 26  27  return MB_SUCCESS; 28 } 29  30 // In this test case, an error MB_TYPE_OUT_OF_RANGE is returned by MOAB 31 ErrorCode TestErrorHandling_2() 32 { 33  Core moab; 34  Interface& mb = moab; 35  36  // Load a HOMME file with an invalid GATHER_SET option 37  string test_file = string( MESH_DIR ) + string( "/io/homme3x3458.t.3.nc" ); 38  ErrorCode rval = mb.load_file( test_file.c_str(), NULL, "VARIABLE=T;GATHER_SET=0.1" );MB_CHK_ERR( rval ); 39  40  return MB_SUCCESS; 41 } 42  43 // In this test case, an error MB_FAILURE is returned by MOAB 44 ErrorCode TestErrorHandling_3() 45 { 46  Core moab; 47  Interface& mb = moab; 48  49  // Load a CAM-FV file with NOMESH option and a NULL file set 50  string test_file = string( MESH_DIR ) + string( "/io/fv3x46x72.t.3.nc" ); 51  ErrorCode rval = mb.load_file( test_file.c_str(), NULL, "NOMESH;VARIABLE=" );MB_CHK_ERR( rval ); 52  53  return MB_SUCCESS; 54 } 55  56 // In this test case, an error MB_VARIABLE_DATA_LENGTH is returned by MOAB 57 ErrorCode TestErrorHandling_4() 58 { 59  Core moab; 60  Interface& mb = moab; 61  62  // Create 100 vertices 63  const int NUM_VTX = 100; 64  vector< double > coords( 3 * NUM_VTX ); 65  Range verts; 66  ErrorCode rval = mb.create_vertices( &coords[0], NUM_VTX, verts );MB_CHK_SET_ERR( rval, "Failed to create vertices" ); 67  68  // Create a variable-length dense tag 69  Tag tag; 70  rval = mb.tag_get_handle( "var_len_den", 1, MB_TYPE_INTEGER, tag, MB_TAG_VARLEN | MB_TAG_DENSE | MB_TAG_CREAT );MB_CHK_SET_ERR( rval, "Failed to create a tag" ); 71  72  // Attempt to iterate over a variable-length tag, which will never be possible 73  void* ptr = NULL; 74  int count = 0; 75  rval = mb.tag_iterate( tag, verts.begin(), verts.end(), count, ptr );MB_CHK_SET_ERR( rval, "Failed to iterate over tag on " << NUM_VTX << " vertices" ); 76  77  return MB_SUCCESS; 78 } 79  80 int main( int argc, char** argv ) 81 { 82  if( argc < 2 ) 83  { 84  cout << "Usage: " << argv[0] << " <test_case_num(1 to 4)>" << endl; 85  return 0; 86  } 87  88 #ifdef MOAB_HAVE_MPI 89  MPI_Init( &argc, &argv ); 90 #endif 91  92  // Initialize error handler, optional for this example (using moab instances) 93  MBErrorHandler_Init(); 94  95  ErrorCode rval = MB_SUCCESS; 96  97  int test_case_num = atoi( argv[1] ); 98  switch( test_case_num ) 99  { 100  case 1: 101  rval = TestErrorHandling_1();MB_CHK_ERR( rval ); 102  break; 103  case 2: 104  rval = TestErrorHandling_2();MB_CHK_ERR( rval ); 105  break; 106  case 3: 107  rval = TestErrorHandling_3();MB_CHK_ERR( rval ); 108  break; 109  case 4: 110  rval = TestErrorHandling_4();MB_CHK_ERR( rval ); 111  break; 112  default: 113  break; 114  } 115  116  // Finalize error handler, optional for this example (using moab instances) 117  MBErrorHandler_Finalize(); 118  119 #ifdef MOAB_HAVE_MPI 120  MPI_Finalize(); 121 #endif 122  123  return 0; 124 }