[cig-commits] r8024 - in short/3D/PyLith/trunk: libsrc/meshio
unittests/libtests/meshio unittests/libtests/meshio/data
brad at geodynamics.org
brad at geodynamics.org
Tue Sep 25 10:49:49 PDT 2007
Author: brad
Date: 2007-09-25 10:49:48 -0700 (Tue, 25 Sep 2007)
New Revision: 8024
Added:
short/3D/PyLith/trunk/unittests/libtests/meshio/data/MeshData3DIndexOne.cc
short/3D/PyLith/trunk/unittests/libtests/meshio/data/MeshData3DIndexOne.hh
short/3D/PyLith/trunk/unittests/libtests/meshio/data/mesh3DIndexOne.txt
Modified:
short/3D/PyLith/trunk/libsrc/meshio/MeshIO.cc
short/3D/PyLith/trunk/libsrc/meshio/MeshIO.hh
short/3D/PyLith/trunk/libsrc/meshio/MeshIO.icc
short/3D/PyLith/trunk/libsrc/meshio/MeshIOAscii.cc
short/3D/PyLith/trunk/libsrc/meshio/MeshIOAscii.hh
short/3D/PyLith/trunk/unittests/libtests/meshio/Makefile.am
short/3D/PyLith/trunk/unittests/libtests/meshio/TestMeshIO.cc
short/3D/PyLith/trunk/unittests/libtests/meshio/TestMeshIOAscii.cc
short/3D/PyLith/trunk/unittests/libtests/meshio/TestMeshIOAscii.hh
short/3D/PyLith/trunk/unittests/libtests/meshio/data/Makefile.am
Log:
Fixed zero indexing for MeshIOAscii. Removed zero indexing stuff from MeshIO (all transformations to/from zero indexing and one indexing are done in the read/write implementation objects).
Modified: short/3D/PyLith/trunk/libsrc/meshio/MeshIO.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/MeshIO.cc 2007-09-25 17:19:45 UTC (rev 8023)
+++ short/3D/PyLith/trunk/libsrc/meshio/MeshIO.cc 2007-09-25 17:49:48 UTC (rev 8024)
@@ -25,7 +25,6 @@
// ----------------------------------------------------------------------
// Constructor
pylith::meshio::MeshIO::MeshIO(void) :
- _useIndexZero(true),
_debug(false),
_interpolate(false),
_mesh(0)
@@ -180,7 +179,6 @@
const int size = (*numCells) * (*numCorners);
cells->resize(size);
- const int offset = (useIndexZero()) ? 0 : 1;
int i = 0;
for(Mesh::label_sequence::iterator e_iter = meshCells->begin();
e_iter != meshCells->end();
@@ -190,7 +188,7 @@
for(sieve_type::traits::coneSequence::iterator c_iter = cone->begin();
c_iter != cone->end();
++c_iter)
- (*cells)[i++] = vNumbering->getIndex(*c_iter) + offset;
+ (*cells)[i++] = vNumbering->getIndex(*c_iter);
} // for
} // _getCells
@@ -254,7 +252,7 @@
} // _getMaterials
// ----------------------------------------------------------------------
-// Build a point group as an int sectio
+// Build a point group as an int section.
void
pylith::meshio::MeshIO::_setGroup(const std::string& name,
const GroupPtType type,
@@ -273,7 +271,7 @@
else if (VERTEX == type) {
const int numCells = (*_mesh)->heightStratum(0)->size();
for(int i=0; i < numPoints; ++i)
- groupField->setFiberDimension(points[i]+numCells, 1);
+ groupField->setFiberDimension(numCells+points[i], 1);
} // if/else
(*_mesh)->allocate(groupField);
} // _setGroup
@@ -346,7 +344,7 @@
pylith::meshio::MeshIO::_getGroup(int_array* points,
GroupPtType* type,
const char *name) const
-{ // _getMaterials
+{ // _getGroup
assert(0 != points);
assert(0 != type);
assert(0 != _mesh);
@@ -376,7 +374,7 @@
assert(!numbering.isNull());
(*points)[i++] = numbering->getIndex(*c_iter);
} // for
-} // _getMaterials
+} // _getGroup
// End of file
Modified: short/3D/PyLith/trunk/libsrc/meshio/MeshIO.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/MeshIO.hh 2007-09-25 17:19:45 UTC (rev 8023)
+++ short/3D/PyLith/trunk/libsrc/meshio/MeshIO.hh 2007-09-25 17:49:48 UTC (rev 8024)
@@ -90,18 +90,6 @@
virtual
void _read(void) = 0;
- /** Get flag indicating whether indices start at 0 (True) or 1 (False).
- *
- * @returns True if indices start at 0, false if 1.
- */
- bool useIndexZero(void) const;
-
- /** Set flag indicating whether indices start at 0 (True) or 1 (False).
- *
- * @param flag True if indices start at 0, false if 1.
- */
- void useIndexZero(const bool flag);
-
/** Get spatial dimension of mesh.
*
* @returns Spatial dimension of mesh
@@ -110,6 +98,9 @@
/** Build mesh topology and set vertex coordinates.
*
+ * All mesh information must use zero based indices. In other words,
+ * the lowest index MUST be 0 not 1.
+ *
* @param coordinates Array of coordinates of vertices
* @param numVertices Number of vertices
* @param spaceDim Dimension of vector space for vertex coordinates
@@ -140,6 +131,10 @@
/** Get information about cells in mesh.
*
+ * The indices of the vertices will be returned using zero based
+ * indices. In other words, the first vertex will be referred to
+ * using an index of 0.
+ *
* Method caller is responsible for memory management.
*
* @param cells Pointer to array of indicates of vertices in each cell
@@ -166,6 +161,9 @@
/** Build a point group
*
+ * The indices in the points array must use zero based indices. In
+ * other words, the lowest index MUST be 0 not 1.
+ *
* @param name The group name
* @param type The point type, e.g. VERTEX, CELL
* @param points An array of the points in the group.
@@ -182,6 +180,10 @@
/** Return a point group
*
+ * The indices of the vertices will be returned using zero based
+ * indices. In other words, the first vertex will be referred to
+ * using an index of 0.
+ *
* @param points An array of the points in the group
* @param type The point type, e.g. VERTEX, CELL
* @param name The group name
@@ -197,7 +199,6 @@
// PRIVATE MEMBERS //////////////////////////////////////////////////////
private :
- bool _useIndexZero; ///< Flag indicating if indicates start at 0 (T) or 1 (F)
bool _debug; ///< True to turn of mesh debugging output
bool _interpolate; ///< True if building intermediate topology elements
Modified: short/3D/PyLith/trunk/libsrc/meshio/MeshIO.icc
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/MeshIO.icc 2007-09-25 17:19:45 UTC (rev 8023)
+++ short/3D/PyLith/trunk/libsrc/meshio/MeshIO.icc 2007-09-25 17:49:48 UTC (rev 8024)
@@ -14,20 +14,6 @@
#error "MeshIO.icc must be included only from MeshIO.hh"
#else
-// Get flag indicating whether indices start at 0 (True) or 1 (False).
-inline
-bool
-pylith::meshio::MeshIO::useIndexZero(void) const {
- return _useIndexZero;
-}
-
-// Set flag indicating whether indices start at 0 (True) or 1 (False).
-inline
-void
-pylith::meshio::MeshIO::useIndexZero(const bool flag) {
- _useIndexZero = flag;
-}
-
// Set debug flag for mesh.
inline
void
Modified: short/3D/PyLith/trunk/libsrc/meshio/MeshIOAscii.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/MeshIOAscii.cc 2007-09-25 17:19:45 UTC (rev 8023)
+++ short/3D/PyLith/trunk/libsrc/meshio/MeshIOAscii.cc 2007-09-25 17:49:48 UTC (rev 8024)
@@ -34,7 +34,8 @@
// ----------------------------------------------------------------------
// Constructor
pylith::meshio::MeshIOAscii::MeshIOAscii(void) :
- _filename("")
+ _filename(""),
+ _useIndexZero(true)
{ // constructor
} // constructor
@@ -104,9 +105,9 @@
std::string flag = "";
buffer >> flag;
if (0 == strcasecmp(flag.c_str(), "true"))
- useIndexZero(true);
+ _useIndexZero = true;
else
- useIndexZero(false);
+ _useIndexZero = false;
} else if (0 == strcasecmp(token.c_str(), "vertices")) {
_readVertices(parser, &coordinates, &numVertices, &spaceDim);
readVertices = true;
@@ -182,7 +183,7 @@
fileout
<< "mesh = {\n"
<< " dimension = " << getMeshDim() << "\n"
- << " use-index-zero = " << (useIndexZero() ? "true" : "false") << "\n";
+ << " use-index-zero = " << (_useIndexZero ? "true" : "false") << "\n";
_writeVertices(fileout);
_writeCells(fileout);
@@ -327,7 +328,7 @@
for (int iCorner=0; iCorner < *numCorners; ++iCorner)
buffer >> (*cells)[i++];
} // for
- if (!useIndexZero()) {
+ if (!_useIndexZero) {
// if files begins with index 1, then decrement to index 0
// for compatibility with Sieve
for (int i=0; i < size; ++i)
@@ -484,6 +485,9 @@
msg << "I/O error while parsing group '" << *name << "'.";
throw std::runtime_error(msg.str());
} // if
+
+ if (!_useIndexZero)
+ *points -= 1;
} // _readGroup
// ----------------------------------------------------------------------
@@ -496,6 +500,8 @@
GroupPtType type;
_getGroup(&points, &type, name);
+ const int offset = _useIndexZero ? 0 : 1;
+
const int numPoints = points.size();
fileout
<< " group = {\n"
@@ -504,7 +510,7 @@
<< " count = " << numPoints << "\n"
<< " indices = {\n";
for(int i=0; i < numPoints; ++i)
- fileout << " " << points[i] << "\n";
+ fileout << " " << points[i]+offset << "\n";
fileout
<< " }\n"
Modified: short/3D/PyLith/trunk/libsrc/meshio/MeshIOAscii.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/MeshIOAscii.hh 2007-09-25 17:19:45 UTC (rev 8023)
+++ short/3D/PyLith/trunk/libsrc/meshio/MeshIOAscii.hh 2007-09-25 17:49:48 UTC (rev 8024)
@@ -130,6 +130,7 @@
private :
std::string _filename; ///< Name of file
+ bool _useIndexZero; ///< Flag indicating if indicates start at 0 (T) or 1 (F)
}; // MeshIOAscii
Modified: short/3D/PyLith/trunk/unittests/libtests/meshio/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/meshio/Makefile.am 2007-09-25 17:19:45 UTC (rev 8023)
+++ short/3D/PyLith/trunk/unittests/libtests/meshio/Makefile.am 2007-09-25 17:49:48 UTC (rev 8024)
@@ -40,6 +40,7 @@
data/MeshData2D.cc \
data/MeshData2Din3D.cc \
data/MeshData3D.cc \
+ data/MeshData3DIndexOne.cc \
data/MeshDataCubitTri.cc \
data/MeshDataCubitQuad.cc \
data/MeshDataCubitTet.cc \
@@ -54,6 +55,7 @@
data/MeshData2D.hh \
data/MeshData2Din3D.hh \
data/MeshData3D.hh \
+ data/MeshData3DIndexOne.hh \
data/MeshDataCubitTri.hh \
data/MeshDataCubitQuad.hh \
data/MeshDataCubitTet.hh \
Modified: short/3D/PyLith/trunk/unittests/libtests/meshio/TestMeshIO.cc
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/meshio/TestMeshIO.cc 2007-09-25 17:19:45 UTC (rev 8023)
+++ short/3D/PyLith/trunk/unittests/libtests/meshio/TestMeshIO.cc 2007-09-25 17:49:48 UTC (rev 8024)
@@ -145,7 +145,7 @@
mesh->depth())->size();
CPPUNIT_ASSERT_EQUAL(data.numCorners, numCorners);
- const int offset = (data.useIndexZero) ? numCells : numCells-1;
+ const int offset = numCells;
i = 0;
for(Mesh::label_sequence::iterator e_iter = cells->begin();
e_iter != cells->end();
Modified: short/3D/PyLith/trunk/unittests/libtests/meshio/TestMeshIOAscii.cc
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/meshio/TestMeshIOAscii.cc 2007-09-25 17:19:45 UTC (rev 8023)
+++ short/3D/PyLith/trunk/unittests/libtests/meshio/TestMeshIOAscii.cc 2007-09-25 17:49:48 UTC (rev 8024)
@@ -24,6 +24,7 @@
#include "data/MeshData2D.hh"
#include "data/MeshData2Din3D.hh"
#include "data/MeshData3D.hh"
+#include "data/MeshData3DIndexOne.hh"
// ----------------------------------------------------------------------
CPPUNIT_TEST_SUITE_REGISTRATION( pylith::meshio::TestMeshIOAscii );
@@ -127,6 +128,16 @@
} // testWriteRead3D
// ----------------------------------------------------------------------
+// Test read() for 3D mesh with 1 based indexing.
+void
+pylith::meshio::TestMeshIOAscii::testRead3DIndexOne(void)
+{ // testRead3IndexDOne
+ MeshData3DIndexOne data;
+ const char* filename = "data/mesh3DIndexOne.txt";
+ _testRead(data, filename);
+} // testRead3DIndexOne
+
+// ----------------------------------------------------------------------
// Test write() and read() for 2D mesh in 2D space with comments.
void
pylith::meshio::TestMeshIOAscii::testReadComments(void)
Modified: short/3D/PyLith/trunk/unittests/libtests/meshio/TestMeshIOAscii.hh
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/meshio/TestMeshIOAscii.hh 2007-09-25 17:19:45 UTC (rev 8023)
+++ short/3D/PyLith/trunk/unittests/libtests/meshio/TestMeshIOAscii.hh 2007-09-25 17:49:48 UTC (rev 8024)
@@ -48,6 +48,7 @@
CPPUNIT_TEST( testWriteRead2D );
CPPUNIT_TEST( testWriteRead2Din3D );
CPPUNIT_TEST( testWriteRead3D );
+ CPPUNIT_TEST( testRead3DIndexOne );
CPPUNIT_TEST( testReadComments );
CPPUNIT_TEST_SUITE_END();
@@ -85,6 +86,9 @@
/// Test write() and read() for 3D mesh in 3D space.
void testWriteRead3D(void);
+ /// Test read() for 3D mesh with one based indexing.
+ void testRead3DIndexOne(void);
+
/// Test and read() for 2D mesh in 2D space with comments.
void testReadComments(void);
Modified: short/3D/PyLith/trunk/unittests/libtests/meshio/data/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/meshio/data/Makefile.am 2007-09-25 17:19:45 UTC (rev 8023)
+++ short/3D/PyLith/trunk/unittests/libtests/meshio/data/Makefile.am 2007-09-25 17:49:48 UTC (rev 8024)
@@ -15,6 +15,7 @@
cube2_ascii.pset \
cube2_binary.gmv \
cube2_binary.pset \
+ mesh3DIndexOne.txt \
twotri3.exo \
twoquad4.exo \
twotet4.exo \
Added: short/3D/PyLith/trunk/unittests/libtests/meshio/data/MeshData3DIndexOne.cc
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/meshio/data/MeshData3DIndexOne.cc 2007-09-25 17:19:45 UTC (rev 8023)
+++ short/3D/PyLith/trunk/unittests/libtests/meshio/data/MeshData3DIndexOne.cc 2007-09-25 17:49:48 UTC (rev 8024)
@@ -0,0 +1,93 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+// Brad T. Aagaard
+// U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+#include "MeshData3DIndexOne.hh"
+
+const int pylith::meshio::MeshData3DIndexOne::_numVertices = 14;
+
+const int pylith::meshio::MeshData3DIndexOne::_spaceDim = 3;
+
+const int pylith::meshio::MeshData3DIndexOne::_numCells = 2;
+
+const int pylith::meshio::MeshData3DIndexOne::_cellDim = 3;
+
+const int pylith::meshio::MeshData3DIndexOne::_numCorners = 8;
+
+const double pylith::meshio::MeshData3DIndexOne::_vertices[] = {
+ -3.0, -1.0, 0.2,
+ -3.0, -1.0, 1.3,
+ -1.0, -1.2, 0.1,
+ -1.0, -1.2, 1.2,
+ -3.0, 5.0, 1.3,
+ -3.0, 5.0, 0.1,
+ -0.5, 4.8, 0.2,
+ -0.5, 4.8, 1.4,
+ 0.5, 7.0, 1.2,
+ 1.0, 3.1, 1.3,
+ 3.0, 4.1, 1.4,
+ 0.5, 7.0, -0.1,
+ 1.0, 3.0, -0.2,
+ 3.0, 4.2, 0.1
+};
+
+const int pylith::meshio::MeshData3DIndexOne::_cells[] = {
+ 6, 12, 13, 11, 7, 9, 10, 8,
+ 0, 2, 6, 5, 1, 3, 7, 4
+};
+const int pylith::meshio::MeshData3DIndexOne::_materialIds[] = {
+ 2, 1
+};
+
+const int pylith::meshio::MeshData3DIndexOne::_numGroups = 2;
+
+const int pylith::meshio::MeshData3DIndexOne::_groupSizes[] =
+ { 5, 2, 4 };
+
+const int pylith::meshio::MeshData3DIndexOne::_groups[] = {
+ 0, 4, 6, 7, 10,
+ 0, 1,
+ 0, 4, 12, 13
+};
+
+const char* pylith::meshio::MeshData3DIndexOne::_groupNames[] = {
+ "group A", "group B", "group C"
+};
+
+const char* pylith::meshio::MeshData3DIndexOne::_groupTypes[] = {
+ "vertex", "cell", "vertex"
+};
+
+const bool pylith::meshio::MeshData3DIndexOne::_useIndexZero = false;
+
+pylith::meshio::MeshData3DIndexOne::MeshData3DIndexOne(void)
+{ // constructor
+ numVertices = _numVertices;
+ spaceDim = _spaceDim;
+ numCells = _numCells;
+ cellDim = _cellDim;
+ numCorners = _numCorners;
+ vertices = const_cast<double*>(_vertices);
+ cells = const_cast<int*>(_cells);
+ materialIds = const_cast<int*>(_materialIds);
+ groups = const_cast<int*>(_groups);
+ groupSizes = const_cast<int*>(_groupSizes);
+ groupNames = const_cast<char**>(_groupNames);
+ groupTypes = const_cast<char**>(_groupTypes);
+ numGroups = _numGroups;
+ useIndexZero = _useIndexZero;
+} // constructor
+
+pylith::meshio::MeshData3DIndexOne::~MeshData3DIndexOne(void)
+{}
+
+
+// End of file
Added: short/3D/PyLith/trunk/unittests/libtests/meshio/data/MeshData3DIndexOne.hh
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/meshio/data/MeshData3DIndexOne.hh 2007-09-25 17:19:45 UTC (rev 8023)
+++ short/3D/PyLith/trunk/unittests/libtests/meshio/data/MeshData3DIndexOne.hh 2007-09-25 17:49:48 UTC (rev 8024)
@@ -0,0 +1,61 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+// Brad T. Aagaard
+// U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+#if !defined(pylith_meshio_meshdata3dindexone_hh)
+#define pylith_meshio_meshdata3dindexone_hh
+
+#include "MeshData.hh"
+
+namespace pylith {
+ namespace meshio {
+ class MeshData3DIndexOne;
+ } // pylith
+} // meshio
+
+class pylith::meshio::MeshData3DIndexOne : public MeshData
+{
+
+// PUBLIC METHODS ///////////////////////////////////////////////////////
+public:
+
+ /// Constructor
+ MeshData3DIndexOne(void);
+
+ /// Destructor
+ ~MeshData3DIndexOne(void);
+
+// PRIVATE MEMBERS //////////////////////////////////////////////////////
+private:
+
+ static const int _numVertices; ///< Number of vertices
+ static const int _spaceDim; ///< Number of dimensions in vertex coordinates
+ static const int _numCells; ///< Number of cells
+ static const int _cellDim; ///< Number of dimensions associated with cell
+ static const int _numCorners; ///< Number of vertices in cell
+
+ static const double _vertices[]; ///< Pointer to coordinates of vertices
+ static const int _cells[]; ///< Pointer to indices of vertices in cells
+ static const int _materialIds[]; ///< Pointer to cell material identifiers
+
+ static const int _groups[]; ///< Groups of points
+ static const int _groupSizes[]; ///< Sizes of groups
+ static const char* _groupNames[]; ///< Array of group names
+ static const char* _groupTypes[]; ///< Array of group types
+ static const int _numGroups; ///< Number of groups
+
+ static const bool _useIndexZero; ///< First vertex is 0 if true, 1 if false
+
+};
+
+#endif // pylith_meshio_meshdata3dindexone_hh
+
+// End of file
Added: short/3D/PyLith/trunk/unittests/libtests/meshio/data/mesh3DIndexOne.txt
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/meshio/data/mesh3DIndexOne.txt 2007-09-25 17:19:45 UTC (rev 8023)
+++ short/3D/PyLith/trunk/unittests/libtests/meshio/data/mesh3DIndexOne.txt 2007-09-25 17:49:48 UTC (rev 8024)
@@ -0,0 +1,57 @@
+mesh = {
+ dimension = 3
+ use-index-zero = false
+ vertices = {
+ dimension = 3
+ count = 14
+ coordinates = {
+ 1 -3.000000e+00 -1.000000e+00 2.000000e-01
+ 2 -3.000000e+00 -1.000000e+00 1.300000e+00
+ 3 -1.000000e+00 -1.200000e+00 1.000000e-01
+ 4 -1.000000e+00 -1.200000e+00 1.200000e+00
+ 5 -3.000000e+00 5.000000e+00 1.300000e+00
+ 6 -3.000000e+00 5.000000e+00 1.000000e-01
+ 7 -5.000000e-01 4.800000e+00 2.000000e-01
+ 8 -5.000000e-01 4.800000e+00 1.400000e+00
+ 9 5.000000e-01 7.000000e+00 1.200000e+00
+ 10 1.000000e+00 3.100000e+00 1.300000e+00
+ 11 3.000000e+00 4.100000e+00 1.400000e+00
+ 12 5.000000e-01 7.000000e+00 -1.000000e-01
+ 13 1.000000e+00 3.000000e+00 -2.000000e-01
+ 14 3.000000e+00 4.200000e+00 1.000000e-01
+ }
+ }
+ cells = {
+ count = 2
+ num-corners = 8
+ simplices = {
+ 1 7 13 14 12 8 10 11 9
+ 2 1 3 7 6 2 4 8 5
+ }
+ material-ids = {
+ 1 2
+ 2 1
+ }
+ }
+ group = {
+ name = group A
+ type = vertices
+ count = 5
+ indices = {
+ 1
+ 5
+ 7
+ 8
+ 11
+ }
+ }
+ group = {
+ name = group B
+ type = cells
+ count = 2
+ indices = {
+ 1
+ 2
+ }
+ }
+}
More information about the cig-commits
mailing list