[MOAB-dev] r3177 - in MOAB/trunk: . test

kraftche at cae.wisc.edu kraftche at cae.wisc.edu
Wed Sep 30 12:55:14 CDT 2009


Author: kraftche
Date: 2009-09-30 12:55:13 -0500 (Wed, 30 Sep 2009)
New Revision: 3177

Added:
   MOAB/trunk/gmsh_test.cc
   MOAB/trunk/test/gmsh2.msh
Modified:
   MOAB/trunk/Makefile.am
   MOAB/trunk/ReadGmsh.cpp
Log:
o Support version 2.1 of Gmsh ASCII file format
o Support reading 15-node prism and 13-node pyramid from Gmsh file
o Fix wrong MOAB type for Gmsh type 10 (bug #27)
o Add simple regression test for Gmsh reader



Modified: MOAB/trunk/Makefile.am
===================================================================
--- MOAB/trunk/Makefile.am	2009-09-30 15:17:09 UTC (rev 3176)
+++ MOAB/trunk/Makefile.am	2009-09-30 17:55:13 UTC (rev 3177)
@@ -39,6 +39,7 @@
 	mesh_set_test \
 	cub_file_test \
 	exodus_test \
+        gmsh_test \
         mbcn_test \
         bsp_tree_poly_test
 #                 merge_test \         # input files no longer exist?
@@ -367,6 +368,9 @@
 exodus_test_SOURCES = TestUtil.hpp exodus_test.cc
 exodus_test_DEPENDENCIES = $(tag_test_LDADD)
 
+gmsh_test_SOURCES = TestUtil.hpp gmsh_test.cc
+gmsh_test_DEPENDENCIES = $(tag_test_LDADD)
+
 mbcn_test_SOURCES = MBCN.hpp MBCN.cpp mbcn_test.cc
 mbcn_test_CPPFLAGS = -DSRCDIR=$(srcdir)  # define anything to work around build issue
 mbcn_test_LDADD = 

Modified: MOAB/trunk/ReadGmsh.cpp
===================================================================
--- MOAB/trunk/ReadGmsh.cpp	2009-09-30 15:17:09 UTC (rev 3176)
+++ MOAB/trunk/ReadGmsh.cpp	2009-09-30 17:55:13 UTC (rev 3177)
@@ -16,6 +16,9 @@
 /**
  * \class ReadGmsh
  * \brief Gmsh (http://www.geuz.org/gmsh) file reader
+ *
+ * See: http://geuz.org/gmsh/doc/texinfo/gmsh.html#MSH-ASCII-file-format
+ *
  * \author Jason Kraftcheck
  */
 
@@ -53,29 +56,57 @@
   }
 }
 
-// Type info indexed by type id used in file format.
+// Indexed by position in Gmsh order, containing cooresponding
+// position in MOAB order.
 const int hex_27_node_order[] =  {  
     0,  1,  2,  3,  4,  5,  6,  7,                 // corners
     8, 11, 12,  9, 13, 10, 14, 15, 16, 19, 17, 18, // edges
    24, 20, 23, 21, 22, 25,                         // faces
    26 };                                           // volume
+// Indexed by position in MOAB order, containing cooresponding
+// position in Gmsh order.
+const int pri_15_node_order[] = { 
+    0,  1,  2,  3,  4,  5,            // corners
+    6,  8,  9,  7, 10, 11, 12, 14, 13 // edges
+    };
+const int pyr_13_node_order[] = { 
+    0,  1,  2,  3,  4,                // corners
+    5,  8,  9,  6, 10,  7, 11, 12     // edges
+    };
+// Type info indexed by type id used in file format.
 const ReadGmsh::ElementType typemap[] = {
-  { MBMAXTYPE, 0, 0 },
-  { MBEDGE,    2, 0 },
-  { MBTRI,     3, 0 },
-  { MBQUAD,    4, 0 },
-  { MBTET,     4, 0 },
-  { MBHEX,     8, 0 },
-  { MBPRISM,   6, 0 },
-  { MBPYRAMID, 5, 0 },
-  { MBEDGE,    3, 0 },
-  { MBTRI,     6, 0 },
-  { MBQUAD,    8, 0 },
-  { MBTET,    10, 0 },
+  { MBMAXTYPE, 0, 0 }, 
+  { MBEDGE,    2, 0 }, // 1
+  { MBTRI,     3, 0 }, // 2
+  { MBQUAD,    4, 0 }, // 3
+  { MBTET,     4, 0 }, // 4
+  { MBHEX,     8, 0 }, // 5
+  { MBPRISM,   6, 0 }, // 6
+  { MBPYRAMID, 5, 0 }, // 7
+  { MBEDGE,    3, 0 }, // 8
+  { MBTRI,     6, 0 }, // 9
+  { MBQUAD,    9, 0 }, // 10
+  { MBTET,    10, 0 }, // 11
   { MBHEX,    27, hex_27_node_order },
-  { MBMAXTYPE,18, 0 }, // prism w/ mid-face nodes on quads but not tris
-  { MBMAXTYPE,14, 0 }, // pyramid w/ mid-face nodes on quad but not tris
-  { MBMAXTYPE, 1, 0 }  // point element (0-rad sphere element?)
+  { MBMAXTYPE,18, 0 }, // 13  prism w/ mid-face nodes on quads but not tris
+  { MBMAXTYPE,14, 0 }, // 14  pyramid w/ mid-face nodes on quad but not tris
+  { MBMAXTYPE, 1, 0 }, // 15  point element (0-rad sphere element?)
+  { MBQUAD,    8, 0 }, // 16
+  { MBHEX,    20, hex_27_node_order },
+  { MBPRISM,  15, pri_15_node_order },
+  { MBPYRAMID,13, pyr_13_node_order },
+  { MBMAXTYPE, 9, 0 }, // 20  triangle w/ 2 nodes per edge
+  { MBMAXTYPE,10, 0 }, // 21    "       " "   "    "   "   and mid-face node
+  { MBMAXTYPE,12, 0 }, // 22  triangle w/ 3 nodes per edge
+  { MBMAXTYPE,15, 0 }, // 23    "       " "   "    "   "   and 3 mid-face nodes
+  { MBMAXTYPE,15, 0 }, // 24  triangle w/ 4 nodes per edge
+  { MBMAXTYPE,21, 0 }, // 25    "       " "   "    "   "   and 6 mid-face nodes
+  { MBMAXTYPE, 4, 0 }, // 26  4-node edge
+  { MBMAXTYPE, 5, 0 }, // 27  5-node edge
+  { MBMAXTYPE, 6, 0 }, // 28  6-node edge
+  { MBMAXTYPE,20, 0 }, // 29  tet w/ 2 nodes per edge and 1 per face
+  { MBMAXTYPE,35, 0 }, // 30  tet w/ 3 nodes per edge, 3 per face, and 1 mid-voluem
+  { MBMAXTYPE,56, 0 }  // 31  tet w/ 4 nodes per edge, 6 per face, and 4 mid-voluem
 };
 const int max_type_int = sizeof(typemap) / sizeof(typemap[0]) - 1;
 
@@ -174,7 +205,7 @@
     if (!tokens.get_doubles( 1, &version ))
       return MB_FILE_WRITE_ERROR;
     
-    if (version != 2.0) {
+    if (version != 2.0 && version != 2.1) {
       readMeshIface->report_error( "%s: unknown format version: %f\n", filename, version );
       return MB_FILE_DOES_NOT_EXIST;
     }

Added: MOAB/trunk/gmsh_test.cc
===================================================================
--- MOAB/trunk/gmsh_test.cc	                        (rev 0)
+++ MOAB/trunk/gmsh_test.cc	2009-09-30 17:55:13 UTC (rev 3177)
@@ -0,0 +1,244 @@
+#include "TestUtil.hpp"
+#include "MBCore.hpp"
+#include "MBTagConventions.hpp"
+#include "MBCN.hpp"
+#include "ReadGmsh.hpp"
+#include "FileOptions.hpp"
+#include <math.h>
+#include <algorithm>
+
+/* Input test file: gmsh2.msh
+ * 
+ * Example version 2.0 ASCII input file from Gmsh 2.4 manual.
+ */
+#ifdef SRCDIR
+static const char example[] = STRINGIFY(SRCDIR) "/test/gmsh2.msh";
+#else
+static const char example[] = "test/gmsh2.msh";
+#endif
+
+void test_read_nodes();
+void test_read_quads();
+void test_read_material_set();
+void test_read_geom_set();
+
+void read_file( MBInterface& moab, const char* input_file );
+
+int main()
+{
+  int result = 0;
+  
+  result += RUN_TEST(test_read_nodes);
+  result += RUN_TEST(test_read_quads);
+  result += RUN_TEST(test_read_material_set);
+  result += RUN_TEST(test_read_geom_set);
+  
+  return result;
+}
+
+
+void read_file( MBInterface& moab, const char* input_file )
+{
+  MBErrorCode rval;
+  MBEntityHandle set;
+  ReadGmsh reader( &moab );
+  FileOptions opts("");
+  rval = reader.load_file( input_file, set, opts, 0, 0, 0 );
+  CHECK_ERR(rval);
+}
+
+void test_read_nodes()
+{
+  const double eps = 1e-100;
+  MBErrorCode rval;
+  MBCore moab;
+  MBInterface& mb = moab;
+  read_file( moab, example );
+  
+  std::vector<MBEntityHandle> nodes;
+  rval = mb.get_entities_by_type( 0, MBVERTEX, nodes );
+  CHECK_ERR(rval);
+  CHECK_EQUAL( (size_t)6, nodes.size() );
+  
+  MBTag id_tag;
+  rval = mb.tag_get_handle( GLOBAL_ID_TAG_NAME, id_tag );
+  CHECK_ERR(rval);
+  
+  std::vector<int> ids(nodes.size());
+  rval = mb.tag_get_data( id_tag, &nodes[0], nodes.size(), &ids[0] );
+  CHECK_ERR(rval);
+  
+  std::vector<int> sorted_ids( ids );
+  std::sort( sorted_ids.begin(), sorted_ids.end() );
+  
+  std::vector<double> coords(3*nodes.size());
+  rval = mb.get_coords( &nodes[0], nodes.size(), &coords[0] );
+  CHECK_ERR(rval);
+  
+  int idx, pos = 0;
+  CHECK_EQUAL( pos+1, sorted_ids[pos] );
+  idx = std::find( ids.begin(), ids.end(),pos+1 ) - ids.begin();
+  CHECK_REAL_EQUAL( coords[3*idx+0], 0.0, eps );
+  CHECK_REAL_EQUAL( coords[3*idx+1], 0.0, eps );
+  CHECK_REAL_EQUAL( coords[3*idx+2], 0.0, eps );
+  
+  ++pos;
+  CHECK_EQUAL( pos+1, sorted_ids[pos] );
+  idx = std::find( ids.begin(), ids.end(),pos+1 ) - ids.begin();
+  CHECK_REAL_EQUAL( coords[3*idx+0], 1.0, eps );
+  CHECK_REAL_EQUAL( coords[3*idx+1], 0.0, eps );
+  CHECK_REAL_EQUAL( coords[3*idx+2], 0.0, eps );
+  
+  ++pos;
+  CHECK_EQUAL( pos+1, sorted_ids[pos] );
+  idx = std::find( ids.begin(), ids.end(),pos+1 ) - ids.begin();
+  CHECK_REAL_EQUAL( coords[3*idx+0], 1.0, eps );
+  CHECK_REAL_EQUAL( coords[3*idx+1], 1.0, eps );
+  CHECK_REAL_EQUAL( coords[3*idx+2], 0.0, eps );
+  
+  ++pos;
+  CHECK_EQUAL( pos+1, sorted_ids[pos] );
+  idx = std::find( ids.begin(), ids.end(),pos+1 ) - ids.begin();
+  CHECK_REAL_EQUAL( coords[3*idx+0], 0.0, eps );
+  CHECK_REAL_EQUAL( coords[3*idx+1], 1.0, eps );
+  CHECK_REAL_EQUAL( coords[3*idx+2], 0.0, eps );
+  
+  ++pos;
+  CHECK_EQUAL( pos+1, sorted_ids[pos] );
+  idx = std::find( ids.begin(), ids.end(),pos+1 ) - ids.begin();
+  CHECK_REAL_EQUAL( coords[3*idx+0], 2.0, eps );
+  CHECK_REAL_EQUAL( coords[3*idx+1], 0.0, eps );
+  CHECK_REAL_EQUAL( coords[3*idx+2], 0.0, eps );
+  
+  ++pos;
+  CHECK_EQUAL( pos+1, sorted_ids[pos] );
+  idx = std::find( ids.begin(), ids.end(),pos+1 ) - ids.begin();
+  CHECK_REAL_EQUAL( coords[3*idx+0], 2.0, eps );
+  CHECK_REAL_EQUAL( coords[3*idx+1], 1.0, eps );
+  CHECK_REAL_EQUAL( coords[3*idx+2], 0.0, eps );
+}  
+
+
+void test_read_quads()
+{
+  MBErrorCode rval;
+  MBCore moab;
+  MBInterface& mb = moab;
+  read_file( moab, example );
+  
+  std::vector<MBEntityHandle> quads;
+  rval = mb.get_entities_by_type( 0, MBQUAD, quads );
+  CHECK_ERR(rval);
+  CHECK_EQUAL( (size_t)2, quads.size() );
+  
+  MBTag id_tag;
+  rval = mb.tag_get_handle( GLOBAL_ID_TAG_NAME, id_tag );
+  CHECK_ERR(rval);
+  
+  std::vector<int> ids(quads.size());
+  rval = mb.tag_get_data( id_tag, &quads[0], quads.size(), &ids[0] );
+  CHECK_ERR(rval);
+  
+  if (ids[0] != 1) {
+    std::swap( ids[0], ids[1] );
+    std::swap( quads[0], quads[1] );
+  }
+  
+  int vtx_ids[4];
+  const MBEntityHandle* conn;
+  int len;
+  
+  const int conn1[] = { 1, 2, 3, 4 };
+  int pos = 0;
+  CHECK_EQUAL( pos+1, ids[pos] );
+  rval = mb.get_connectivity( quads[pos], conn, len );
+  CHECK_ERR(rval);
+  CHECK_EQUAL( 4, len );
+  rval = mb.tag_get_data( id_tag, conn, len, vtx_ids );
+  CHECK_ERR(rval);
+  CHECK_ARRAYS_EQUAL( conn1, 4, vtx_ids, len );
+  
+  const int conn2[] = { 2, 5, 6, 3 };
+  ++pos;
+  CHECK_EQUAL( pos+1, ids[pos] );
+  rval = mb.get_connectivity( quads[pos], conn, len );
+  CHECK_ERR(rval);
+  CHECK_EQUAL( 4, len );
+  rval = mb.tag_get_data( id_tag, conn, len, vtx_ids );
+  CHECK_ERR(rval);
+  CHECK_ARRAYS_EQUAL( conn2, 4, vtx_ids, len );
+}  
+
+void test_read_material_set()
+{
+  MBErrorCode rval;
+  MBCore moab;
+  MBInterface& mb = moab;
+  read_file( moab, example );
+  
+  MBTag mat_tag;
+  rval = mb.tag_get_handle( MATERIAL_SET_TAG_NAME, mat_tag );
+  CHECK_ERR(rval);
+  
+  MBRange sets;
+  rval = mb.get_entities_by_type_and_tag( 0, MBENTITYSET, &mat_tag, 0, 1, sets );
+  CHECK_ERR(rval);
+  CHECK_EQUAL( 1, (int)sets.size() );
+  MBEntityHandle set = sets.front();
+  
+  int id;
+  rval = mb.tag_get_data( mat_tag, &set, 1, &id );
+  CHECK_ERR(rval);
+  CHECK_EQUAL( 99, id );
+  
+  std::vector<MBEntityHandle> quads, contents;
+  rval = mb.get_entities_by_type( 0, MBQUAD, quads );
+  CHECK_ERR(rval);
+  rval = mb.get_entities_by_handle( set, contents );
+  CHECK_ERR(rval);
+  std::sort( quads.begin(), quads.end() );
+  std::sort( contents.begin(), contents.end() );
+  CHECK_EQUAL( quads, contents );
+}
+
+
+void test_read_geom_set()
+{
+  MBErrorCode rval;
+  MBCore moab;
+  MBInterface& mb = moab;
+  read_file( moab, example );
+  
+  MBTag dim_tag, id_tag;
+  rval = mb.tag_get_handle( GEOM_DIMENSION_TAG_NAME, dim_tag );
+  CHECK_ERR(rval);
+  rval = mb.tag_get_handle( GLOBAL_ID_TAG_NAME, id_tag );
+  CHECK_ERR(rval);
+  
+  MBRange sets;
+  rval = mb.get_entities_by_type_and_tag( 0, MBENTITYSET, &dim_tag, 0, 1, sets );
+  CHECK_ERR(rval);
+  CHECK_EQUAL( 1, (int)sets.size() );
+  MBEntityHandle set = sets.front();
+  
+  int dim;
+  rval = mb.tag_get_data( dim_tag, &set, 1, &dim );
+  CHECK_ERR(rval);
+  CHECK_EQUAL( 2, dim );
+  
+  int id;
+  rval = mb.tag_get_data( id_tag, &set, 1, &id );
+  CHECK_ERR(rval);
+  CHECK_EQUAL( 3, id );
+  
+  std::vector<MBEntityHandle> quads, contents;
+  rval = mb.get_entities_by_type( 0, MBQUAD, quads );
+  CHECK_ERR(rval);
+  rval = mb.get_entities_by_handle( set, contents );
+  CHECK_ERR(rval);
+  std::sort( quads.begin(), quads.end() );
+  std::sort( contents.begin(), contents.end() );
+  CHECK_EQUAL( quads, contents );
+}
+
+

Added: MOAB/trunk/test/gmsh2.msh
===================================================================
--- MOAB/trunk/test/gmsh2.msh	                        (rev 0)
+++ MOAB/trunk/test/gmsh2.msh	2009-09-30 17:55:13 UTC (rev 3177)
@@ -0,0 +1,33 @@
+$MeshFormat
+2.1 0 8
+$EndMeshFormat
+$Nodes
+6
+1 0.0 0.0 0.0
+2 1.0 0.0 0.0
+3 1.0 1.0 0.0
+4 0.0 1.0 0.0
+5 2.0 0.0 0.0
+6 2.0 1.0 0.0
+$EndNodes
+$Elements
+2
+1 3 2 99 3 1 2 3 4
+2 3 2 99 3 2 5 6 3
+$EndElements
+$NodeData
+1
+"A scalar view"
+1
+0.0
+3
+0
+1
+6
+1 0.0
+2 0.1
+3 0.2
+4 0.0
+5 0.2
+6 0.4
+$EndNodeData



More information about the moab-dev mailing list