[MOAB-dev] r3310 - MOAB/trunk
kraftche at cae.wisc.edu
kraftche at cae.wisc.edu
Mon Nov 9 14:26:45 CST 2009
Author: kraftche
Date: 2009-11-09 14:26:45 -0600 (Mon, 09 Nov 2009)
New Revision: 3310
Modified:
MOAB/trunk/VtkTest.cpp
MOAB/trunk/VtkUtil.cpp
Log:
add support for reading/writing additional element types tofrom VTK files: Quad9, Pri15, Pyr13, Hex27
Modified: MOAB/trunk/VtkTest.cpp
===================================================================
--- MOAB/trunk/VtkTest.cpp 2009-11-09 18:26:00 UTC (rev 3309)
+++ MOAB/trunk/VtkTest.cpp 2009-11-09 20:26:45 UTC (rev 3310)
@@ -33,13 +33,17 @@
DECLARE_TEST(tri6)
DECLARE_TEST(quad4)
DECLARE_TEST(quad8)
+DECLARE_TEST(quad9)
DECLARE_TEST(polygon)
DECLARE_TEST(tet4)
DECLARE_TEST(tet10)
DECLARE_TEST(hex8)
DECLARE_TEST(hex20)
+DECLARE_TEST(hex27)
DECLARE_TEST(wedge)
+DECLARE_TEST(wedge15)
DECLARE_TEST(pyramid)
+DECLARE_TEST(pyramid13)
DECLARE_TEST(structured_points_2d)
DECLARE_TEST(structured_grid_2d)
@@ -325,6 +329,32 @@
return test_read_write_element( coords, 13, conn, conn, 16, 2, 23, MBQUAD );
}
+bool test_quad9()
+{
+ const double coords[] =
+ { 0, 0, 0,
+ 0, 2, 0,
+ 0, 4, 0,
+ 0, 0, 4,
+ 0, 2, 4,
+ 0, 4, 4,
+ 4, 0, 0,
+ 4, 2, 0,
+ 4, 4, 0,
+ 2, 0, 0,
+ 2, 2, 0,
+ 2, 4, 0,
+ 0, 0, 2,
+ 0, 2, 2,
+ 0, 4, 2
+ };
+ const int conn[] =
+ { 0, 2, 5, 3, 1, 14, 4, 12, 12,
+ 2, 0, 6, 8, 1, 9, 7, 11, 10 };
+
+ return test_read_write_element( coords, 15, conn, conn, 18, 2, 28, MBQUAD );
+}
+
bool test_polygon()
{
const double coords[] =
@@ -458,20 +488,42 @@
{
const int vtk_conn[] =
{ 0, 2, 8, 6,
- 18, 20, 26, 25,
- 1, 5, 7, 13,
+ 18, 20, 26, 24,
+ 1, 5, 7, 3,
19, 23, 25, 21,
9, 11, 17, 15 };
const int exo_conn[] =
{ 0, 2, 8, 6,
- 18, 20, 26, 25,
- 1, 5, 7, 13,
+ 18, 20, 26, 24,
+ 1, 5, 7, 3,
9, 11, 17, 15,
19, 23, 25, 21 };
return test_read_write_element( grid_2x2x2, 27, vtk_conn, exo_conn, 20, 1, 25, MBHEX );
}
+bool test_hex27()
+{
+ const int vtk_conn[] =
+ { 0, 2, 8, 6,
+ 18, 20, 26, 24,
+ 1, 5, 7, 3,
+ 19, 23, 25, 21,
+ 9, 11, 17, 15,
+ 10, 16, 14, 12,
+ 4, 22, 13 };
+ const int moab_conn[] =
+ { 0, 2, 8, 6,
+ 18, 20, 26, 24,
+ 1, 5, 7, 3,
+ 9, 11, 17, 15,
+ 19, 23, 25, 21,
+ 14, 16, 12, 10,
+ 4, 22, 13 };
+
+ return test_read_write_element( grid_2x2x2, 27, vtk_conn, moab_conn, 27, 1, 29, MBHEX );
+}
+
bool test_wedge()
{
const double coords[] =
@@ -492,6 +544,40 @@
return test_read_write_element( coords, 8, vtk_conn, exo_conn, 12, 2, 13, MBPRISM );
}
+bool test_wedge15()
+{
+ const double coords[] =
+ { 2, 0, 0,
+ 2, 2, 0,
+ 0, 2, 0,
+ 0, 0, 0,
+ 2, 0, 2,
+ 2, 2, 2,
+ 0, 2, 2,
+ 0, 0, 2,
+ 2, 1, 0,
+ 1, 2, 0,
+ 0, 1, 0,
+ 1, 0, 0,
+ 1, 1, 0,
+ 2, 1, 2,
+ 1, 2, 2,
+ 0, 1, 2,
+ 1, 0, 2,
+ 1, 1, 2,
+ 2, 0, 1,
+ 2, 2, 1,
+ 0, 2, 1,
+ 0, 0, 1 };
+ const int exo_conn[] =
+ { 0, 1, 3, 4, 5, 7, 8, 12, 11, 18, 19, 21, 13, 17, 16,
+ 1, 2, 3, 5, 6, 7, 9, 10, 12, 19, 20, 21, 14, 15, 17 };
+ const int vtk_conn[] =
+ { 0, 3, 1, 4, 7, 5, 11, 12, 8, 16, 17, 13, 18, 21, 19,
+ 1, 3, 2, 5, 7, 6, 12, 10, 9, 17, 15, 14, 19, 21, 20 };
+ return test_read_write_element( coords, 22, vtk_conn, exo_conn, 30, 2, 26, MBPRISM );
+}
+
bool test_pyramid()
{
const double coords[] =
@@ -508,6 +594,34 @@
return test_read_write_element( coords, 6, conn, conn, 10, 2, 14, MBPYRAMID );
}
+bool test_pyramid13()
+{
+ const double coords[] =
+ { 2, -2, 0,
+ 2, 2, 0,
+ -2, 2, 0,
+ -2, -2, 0,
+ 0, 0, -2,
+ 0, 0, 2,
+ 2, 0, 0,
+ 0, 2, 0,
+ -2, 0, 0,
+ 0, -2, 0,
+ 1, -1, -1,
+ 1, 1, -1,
+ -1, 1, -1,
+ -1, -1, -1,
+ 1, -1, 1,
+ 1, 1, 1,
+ -1, 1, 1,
+ -1, -1, 1 };
+ const int conn[] =
+ { 0, 1, 2, 3, 5, 6, 7, 8, 9, 14, 15, 16, 17,
+ 3, 2, 1, 0, 4, 8, 7, 6, 9, 13, 12, 11, 10 };
+
+ return test_read_write_element( coords, 18, conn, conn, 26, 2, 27, MBPYRAMID );
+}
+
bool test_structured_2d( const char* file );
bool test_structured_3d( const char* file );
Modified: MOAB/trunk/VtkUtil.cpp
===================================================================
--- MOAB/trunk/VtkUtil.cpp 2009-11-09 18:26:00 UTC (rev 3309)
+++ MOAB/trunk/VtkUtil.cpp 2009-11-09 20:26:45 UTC (rev 3310)
@@ -35,72 +35,92 @@
*/
// Define node ordering for those types for which
-// the VTK and MOAB ordering doesn't match.
+// the VTK and MOAB ordering doesn't match. The values
+// contained in the array are MOAB connectivity indices,
+// and the values used to index the arrays are VTK
+// connectivity indices.
const unsigned pixel[] = { 0, 1, 3, 2 };
const unsigned voxel[] = { 0, 1, 3, 2, 4, 5, 7, 6 };
-const unsigned wedge[] = { 0, 2, 1, 3, 5, 4 };
-const unsigned qhex[] = { 0, 1, 2, 3,
+const unsigned wedge[] = { 0, 2, 1, // bottom corners
+ 3, 5, 4, // top corners
+ 8, 7, 6, // bottom edges
+ 14,13,12, // top edges
+ 9,11,10, // lateral edges
+ 17,16,15 }; // quadrilateral faces
+const unsigned qhex[] = { 0, 1, 2, 3, // corners (same)
4, 5, 6, 7,
- 8, 9, 10, 11,
+ 8, 9, 10, 11, // mid-edge (top before lateral)
16, 17, 18, 19,
- 12, 13, 14, 15 };
+ 12, 13, 14, 15,
+ 23, 21, 20, 22, // mid-face (mixed up) & mid-region (same)
+ 24, 25, 26 };
// List of VtkElemType structs, indexed by the VTK type number.
const VtkElemType VtkUtil::vtkElemTypes[] = {
- { 0, 0, MBMAXTYPE, 0, 0 },
- { "vertex", 1, MBMAXTYPE, 1, 0 },
- { "polyvertex", 2, MBMAXTYPE, 0, 0 },
- { "line", 3, MBEDGE, 2, 0 },
- { "polyline", 4, MBMAXTYPE, 0, 0 },
- { "triangle", 5, MBTRI, 3, 0 },
- { "triangle strip", 6, MBMAXTYPE, 0, 0 },
- { "polygon", 7, MBPOLYGON, 0, 0 },
- { "pixel", 8, MBQUAD, 4, pixel },
- { "quadrilateral", 9, MBQUAD, 4, 0 },
- { "tetrahedron", 10, MBTET, 4, 0 },
- { "voxel", 11, MBHEX, 8, voxel },
- { "hexahedron", 12, MBHEX, 8, 0 },
- { "wedge", 13, MBPRISM, 6, wedge },
- { "pyramid", 14, MBPYRAMID, 5, 0 },
- { 0, 15, MBMAXTYPE, 0, 0 },
- { 0, 16, MBMAXTYPE, 0, 0 },
- { 0, 17, MBMAXTYPE, 0, 0 },
- { 0, 18, MBMAXTYPE, 0, 0 },
- { 0, 19, MBMAXTYPE, 0, 0 },
- { 0, 20, MBMAXTYPE, 0, 0 },
- { "quadratic edge",21, MBEDGE, 3, 0 },
- { "quadratic tri", 22, MBTRI, 6, 0 },
- { "quadratic quad",23, MBQUAD, 8, 0 },
- { "quadratic tet", 24, MBTET, 10, 0 },
- { "quadratic hex", 25, MBHEX, 20, qhex } ,
- { 0, 26, MBMAXTYPE, 0, 0 }
+ { 0, 0, MBMAXTYPE, 0, 0 },
+ { "vertex", 1, MBMAXTYPE, 1, 0 },
+ { "polyvertex", 2, MBMAXTYPE, 0, 0 },
+ { "line", 3, MBEDGE, 2, 0 },
+ { "polyline", 4, MBMAXTYPE, 0, 0 },
+ { "triangle", 5, MBTRI, 3, 0 },
+ { "triangle strip", 6, MBMAXTYPE, 0, 0 },
+ { "polygon", 7, MBPOLYGON, 0, 0 },
+ { "pixel", 8, MBQUAD, 4, pixel },
+ { "quadrilateral", 9, MBQUAD, 4, 0 },
+ { "tetrahedron", 10, MBTET, 4, 0 },
+ { "voxel", 11, MBHEX, 8, voxel },
+ { "hexahedron", 12, MBHEX, 8, 0 },
+ { "wedge", 13, MBPRISM, 6, wedge },
+ { "pyramid", 14, MBPYRAMID, 5, 0 },
+ { "pentagonal prism", 15, MBMAXTYPE,10, 0 }, // not supported
+ { "hexagonal prism", 16, MBMAXTYPE,12, 0 }, // not supported
+ { 0, 17, MBMAXTYPE, 0, 0 },
+ { 0, 18, MBMAXTYPE, 0, 0 },
+ { 0, 19, MBMAXTYPE, 0, 0 },
+ { 0, 20, MBMAXTYPE, 0, 0 },
+ { "quadratic edge", 21, MBEDGE, 3, 0 },
+ { "quadratic tri", 22, MBTRI, 6, 0 },
+ { "quadratic quad", 23, MBQUAD, 8, 0 },
+ { "quadratic tet", 24, MBTET, 10, 0 },
+ { "quadratic hex", 25, MBHEX, 20, qhex },
+ { "quadratic wedge", 26, MBPRISM, 15, wedge },
+ { "quadratic pyramid", 27, MBPYRAMID,13, 0 },
+ { "bi-quadratic quad", 28, MBQUAD, 9, 0 },
+ { "tri-quadratic hex", 29, MBHEX, 27, qhex },
+ { "quadratic-linear quad", 30, MBMAXTYPE, 6, 0 }, // not supported
+ { "quadratic-linear wedge", 31, MBMAXTYPE,12, wedge }, // not supported
+ { "bi-quadratic wedge", 32, MBMAXTYPE,18, wedge }, // not supported
+ { "bi-quadratic hex", 33, MBMAXTYPE,24, qhex }, // not supported
+ { 0, 34, MBMAXTYPE, 0, 0 }
};
const unsigned VtkUtil::numVtkElemType = sizeof(VtkUtil::vtkElemTypes) / sizeof(VtkUtil::vtkElemTypes[0]);
// Define an array, indexed by MBEntityType containing the corresponding
-// VTK element type numbers for the linear and quadratic (mid-edge) elements.
+// VTK element type numbers for the linear, quadratic (mid-edge),
+// and full (mid-face & mid-region node) elements.
// Zero is used to indicate an invalid type (not supported by VTK.) The
// VTK element type number may be used as an index into vtkElemTypes[].
-const int mb_to_vtk_type[][2] = {
- { 1, 0 }, // MBVERTEX
- { 3, 21 }, // MBEDGE
- { 5, 22 }, // MBTRI
- { 9, 23 }, // MBQUAD
- { 7, 0 }, // MBPOLYGON
- { 10, 24 }, // MBTET
- { 14, 0 }, // MBPYRAMID
- { 13, 0 }, // MBWEDGE
- { 0, 0 }, // MBKNIFE
- { 12, 25 }, // MBHEX
- { 0, 0 }, // MBPOLYHEDRON
- { 0, 0 }, // MBENTITYSET
- { 0, 0 } };// MBMAXTYPE
+const int mb_to_vtk_type[][3] = {
+ { 1, 0, 0 }, // MBVERTEX
+ { 3, 21, 0 }, // MBEDGE
+ { 5, 22, 0 }, // MBTRI
+ { 9, 23, 28 }, // MBQUAD
+ { 7, 0, 0 }, // MBPOLYGON
+ { 10, 24, 0 }, // MBTET
+ { 14, 27, 0 }, // MBPYRAMID
+ { 13, 26, 0 }, // MBWEDGE
+ { 0, 0, 0 }, // MBKNIFE
+ { 12, 25, 29 }, // MBHEX
+ { 0, 0, 0 }, // MBPOLYHEDRON
+ { 0, 0, 0 }, // MBENTITYSET
+ { 0, 0, 0 } };// MBMAXTYPE
const VtkElemType* VtkUtil::get_vtk_type( MBEntityType type, unsigned num_nodes )
{
const int i = mb_to_vtk_type[type][0]; // Index for linear type
const int j = mb_to_vtk_type[type][1]; // Index for quadratic type
+ const int k = mb_to_vtk_type[type][2]; // Index for full quadratic type
if (i) // If element type is supported at all (if not linear then not quadratic either)
{
// If the linear type is requested (all polygons are linear
@@ -111,6 +131,10 @@
// nodes specified corresponds to the quadratic type, return that.
else if (j && vtkElemTypes[j].num_nodes == num_nodes)
return vtkElemTypes + j;
+ // Otherwise if there is a full quadratic type and the number of
+ // nodes specified corresponds to the quadratic type, return that.
+ else if (k && vtkElemTypes[k].num_nodes == num_nodes)
+ return vtkElemTypes + k;
}
return 0;
More information about the moab-dev
mailing list