MOAB: Mesh Oriented datABase  (version 5.5.0)
h5regression.cpp
Go to the documentation of this file.
1 #include "moab/Core.hpp"
2 #include "TestUtil.hpp"
3 #include "moab/Range.hpp"
4 #include "moab/ReadUtilIface.hpp"
5 #include "WriteHDF5.hpp"
6 #include "moab/FileOptions.hpp"
7 
8 #ifdef MOAB_HAVE_MPI
9 #include "moab_mpi.h"
10 #endif
11 
12 #include <algorithm>
13 #include <iostream>
14 #include <sstream>
15 #include <cstdlib>
16 #include <cmath>
17 
18 using namespace moab;
19 
20 const char filename[] = "bad.h5m";
21 
24 
25 int main( int argc, char* argv[] )
26 {
27 #ifdef MOAB_HAVE_MPI
28  int fail = MPI_Init( &argc, &argv );
29  if( fail ) return fail;
30 #else
31  argv[0] = argv[argc - argc]; // warning in serial
32 #endif
33 
34  int exitval = 0;
35  exitval += RUN_TEST( test_write_invalid_elem );
36  exitval += RUN_TEST( test_write_read_many_tags );
37 
38 #ifdef MOAB_HAVE_MPI
39  fail = MPI_Finalize();
40  if( fail ) return fail;
41 #endif
42 
43  return exitval;
44 }
45 
47 {
48  Core mbcore;
50  ReadUtilIface* readtool = 0;
51  ErrorCode rval;
52 
53  rval = moab.query_interface( readtool );CHECK_ERR( rval );
54  CHECK( readtool != 0 );
55 
56  // create two nodes
57  EntityHandle first_node;
58  std::vector< double* > coords;
59  rval = readtool->get_node_coords( 3, 2, 1, first_node, coords );CHECK_ERR( rval );
60  // Cppcheck warning (false positive): variable coords is assigned a value that is never used
61  coords[0][0] = coords[0][1] = 0.0;
62  coords[1][0] = coords[1][1] = 0.0;
63  coords[2][0] = coords[2][1] = 0.0;
64 
65  // create a triangle with an invalid node handle for its
66  // third vertex
67  EntityHandle tri;
68  EntityHandle* conn = 0;
69  rval = readtool->get_element_connect( 1, 3, MBTRI, 1, tri, conn );CHECK_ERR( rval );
70  conn[0] = first_node; // valid
71  conn[1] = first_node + 1; // valid
72  conn[2] = first_node + 2; // invalid
73 
74  // try to write the file (should fail)
75  WriteHDF5 writer( &moab );
76  FileOptions opts( 0 );
77  rval = writer.write_file( filename, true, opts, 0, 0, std::vector< std::string >() );
78  CHECK( MB_SUCCESS != rval );
79 }
80 
82 {
83  const int N = 200;
84  Core mbcore;
85  Interface& mb = mbcore;
86  ErrorCode rval;
87 
88  double coords[3] = { 0, 0, 0 };
89  EntityHandle node;
90  rval = mb.create_vertex( coords, node );CHECK_ERR( rval );
91 
92  // create a lot of tags
93  std::vector< Tag > tags;
94  for( int i = 0; i < N; ++i )
95  {
96  Tag t;
97  std::ostringstream name( "IntTag" );
98  name << i;
99  rval = mb.tag_get_handle( name.str().c_str(), 1, MB_TYPE_INTEGER, t,
100  ( i % 2 ? MB_TAG_SPARSE : MB_TAG_DENSE ) | MB_TAG_EXCL, &i );CHECK_ERR( rval );
101  tags.push_back( t );
102  }
103 
104  // write the file
105  rval = mb.write_file( filename, "MOAB" );CHECK_ERR( rval );
106 
107  // clear moab instance
108  rval = mb.delete_mesh();CHECK_ERR( rval );
109  for( int i = 0; i < N; ++i )
110  {
111  rval = mb.tag_delete( tags[i] );CHECK_ERR( rval );
112  }
113 
114  // read the file
115  rval = mb.load_file( filename );CHECK_ERR( rval );
116  remove( filename );
117 
118  // check that we have the expected tags
119  for( int i = 0; i < N; ++i )
120  {
121  Tag t;
122  std::ostringstream name( "IntTag" );
123  name << i;
124  rval = mb.tag_get_handle( name.str().c_str(), 1, MB_TYPE_INTEGER, t );CHECK_ERR( rval );
125 
126  TagType storage;
127  rval = mb.tag_get_type( t, storage );CHECK_ERR( rval );
128  CHECK_EQUAL( ( i % 2 ) ? MB_TAG_SPARSE : MB_TAG_DENSE, storage );
129 
130  DataType type;
131  rval = mb.tag_get_data_type( t, type );CHECK_ERR( rval );
132  CHECK_EQUAL( MB_TYPE_INTEGER, type );
133 
134  int size;
135  rval = mb.tag_get_length( t, size );CHECK_ERR( rval );
136  CHECK_EQUAL( 1, size );
137 
138  int def;
139  rval = mb.tag_get_default_value( t, &def );CHECK_ERR( rval );
140  CHECK_EQUAL( i, def );
141  }
142 }