[cig-commits] r21804 - short/3D/PyLith/trunk/unittests/libtests/meshio
brad at geodynamics.org
brad at geodynamics.org
Wed Apr 10 14:54:36 PDT 2013
Author: brad
Date: 2013-04-10 14:54:36 -0700 (Wed, 10 Apr 2013)
New Revision: 21804
Modified:
short/3D/PyLith/trunk/unittests/libtests/meshio/TestMeshIO.cc
short/3D/PyLith/trunk/unittests/libtests/meshio/TestMeshIOAscii.cc
Log:
Fixed memory leaks. Code cleanup.
Modified: short/3D/PyLith/trunk/unittests/libtests/meshio/TestMeshIO.cc
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/meshio/TestMeshIO.cc 2013-04-10 21:16:02 UTC (rev 21803)
+++ short/3D/PyLith/trunk/unittests/libtests/meshio/TestMeshIO.cc 2013-04-10 21:54:36 UTC (rev 21804)
@@ -42,44 +42,37 @@
pylith::topology::Mesh*
pylith::meshio::TestMeshIO::_createMesh(const MeshData& data)
{ // _createMesh
+ PYLITH_METHOD_BEGIN;
+
// buildTopology() requires zero based index
CPPUNIT_ASSERT(true == data.useIndexZero);
- CPPUNIT_ASSERT(0 != data.vertices);
- CPPUNIT_ASSERT(0 != data.cells);
- CPPUNIT_ASSERT(0 != data.materialIds);
+ CPPUNIT_ASSERT(data.vertices);
+ CPPUNIT_ASSERT(data.cells);
+ CPPUNIT_ASSERT(data.materialIds);
if (data.numGroups > 0) {
- CPPUNIT_ASSERT(0 != data.groups);
- CPPUNIT_ASSERT(0 != data.groupSizes);
- CPPUNIT_ASSERT(0 != data.groupNames);
- CPPUNIT_ASSERT(0 != data.groupTypes);
+ CPPUNIT_ASSERT(data.groups);
+ CPPUNIT_ASSERT(data.groupSizes);
+ CPPUNIT_ASSERT(data.groupNames);
+ CPPUNIT_ASSERT(data.groupTypes);
} // if
- topology::Mesh* mesh = new topology::Mesh(data.cellDim);
- CPPUNIT_ASSERT(0 != mesh);
- const ALE::Obj<SieveMesh>& sieveMesh = mesh->sieveMesh();
- CPPUNIT_ASSERT(!sieveMesh.isNull());
- ALE::Obj<SieveMesh::sieve_type> sieve =
- new SieveMesh::sieve_type(mesh->comm());
- CPPUNIT_ASSERT(!sieve.isNull());
+ topology::Mesh* mesh = new topology::Mesh(data.cellDim);CPPUNIT_ASSERT(mesh);
+ const ALE::Obj<SieveMesh>& sieveMesh = mesh->sieveMesh();CPPUNIT_ASSERT(!sieveMesh.isNull());
+ ALE::Obj<SieveMesh::sieve_type> sieve = new SieveMesh::sieve_type(mesh->comm());CPPUNIT_ASSERT(!sieve.isNull());
// Cells and vertices
const bool interpolate = false;
- ALE::Obj<SieveFlexMesh::sieve_type> s =
- new SieveFlexMesh::sieve_type(sieve->comm(), sieve->debug());
-
- ALE::SieveBuilder<SieveFlexMesh>::buildTopology(s, data.cellDim, data.numCells,
- const_cast<int*>(data.cells),
- data.numVertices,
- interpolate, data.numCorners);
+ ALE::Obj<SieveFlexMesh::sieve_type> s = new SieveFlexMesh::sieve_type(sieve->comm(), sieve->debug());CPPUNIT_ASSERT(s);
+ ALE::SieveBuilder<SieveFlexMesh>::buildTopology(s, data.cellDim, data.numCells, const_cast<int*>(data.cells), data.numVertices, interpolate, data.numCorners);
std::map<SieveFlexMesh::point_type,SieveFlexMesh::point_type> renumbering;
ALE::ISieveConverter::convertSieve(*s, *sieve, renumbering);
sieveMesh->setSieve(sieve);
sieveMesh->stratify();
ALE::SieveBuilder<SieveMesh>::buildCoordinates(sieveMesh, data.spaceDim, data.vertices);
- DM dmMesh;
- PetscBool interpolateMesh = interpolate ? PETSC_TRUE : PETSC_FALSE;
+ PetscDM dmMesh = NULL;
+ PetscBool interpolateMesh = interpolate ? PETSC_TRUE : PETSC_FALSE;
PetscErrorCode err;
err = DMPlexCreateFromCellList(mesh->comm(), data.cellDim, data.numCells, data.numVertices, data.numCorners, interpolateMesh, data.cells, data.spaceDim, data.vertices, &dmMesh);CHECK_PETSC_ERROR(err);
@@ -95,11 +88,10 @@
sieveMesh->setValue(labelMaterials, *e_iter, data.materialIds[i++]);
PetscInt cStart, cEnd;
-
err = DMPlexGetHeightStratum(dmMesh, 0, &cStart, &cEnd);CHECK_PETSC_ERROR(err);
for(PetscInt c = cStart; c < cEnd; ++c) {
err = DMPlexSetLabelValue(dmMesh, "material-id", c, data.materialIds[c-cStart]);CHECK_PETSC_ERROR(err);
- }
+ } // for
// Groups
for (int iGroup=0, index=0; iGroup < data.numGroups; ++iGroup) {
@@ -116,14 +108,14 @@
for(int i=0; i < numPoints; ++i, ++index) {
groupField->setFiberDimension(data.groups[index], 1);
err = DMPlexSetLabelValue(dmMesh, data.groupNames[iGroup], data.groups[index], 1);CHECK_PETSC_ERROR(err);
- }
+ } // for
} else if (0 == strcasecmp("vertex", data.groupTypes[iGroup])) {
type = MeshIO::VERTEX;
const int numCells = sieveMesh->heightStratum(0)->size();
for(int i=0; i < numPoints; ++i, ++index) {
groupField->setFiberDimension(data.groups[index]+numCells, 1);
err = DMPlexSetLabelValue(dmMesh, data.groupNames[iGroup], data.groups[index]+numCells, 1);CHECK_PETSC_ERROR(err);
- }
+ } // for
} else
throw std::logic_error("Could not parse group type.");
sieveMesh->allocate(groupField);
@@ -137,7 +129,7 @@
mesh->coordsys(&cs);
mesh->nondimensionalize(normalizer);
- return mesh;
+ PYLITH_METHOD_RETURN(mesh);
} // _createMesh
// ----------------------------------------------------------------------
@@ -146,16 +138,16 @@
pylith::meshio::TestMeshIO::_checkVals(const topology::Mesh& mesh,
const MeshData& data)
{ // _checkVals
+ PYLITH_METHOD_BEGIN;
+
typedef SieveMesh::int_section_type::chart_type chart_type;
// Check mesh dimension
CPPUNIT_ASSERT_EQUAL(data.cellDim, mesh.dimension());
- const ALE::Obj<SieveMesh>& sieveMesh = mesh.sieveMesh();
- CPPUNIT_ASSERT(!sieveMesh.isNull());
+ const ALE::Obj<SieveMesh>& sieveMesh = mesh.sieveMesh();CPPUNIT_ASSERT(!sieveMesh.isNull());
- DM dmMesh = mesh.dmMesh();
- CPPUNIT_ASSERT(dmMesh);
+ PetscDM dmMesh = mesh.dmMesh();CPPUNIT_ASSERT(dmMesh);
// Check vertices
const ALE::Obj<SieveMesh::label_sequence>& vertices =
@@ -166,16 +158,11 @@
CPPUNIT_ASSERT(!vertices.isNull());
CPPUNIT_ASSERT(!coordsField.isNull());
CPPUNIT_ASSERT_EQUAL(data.numVertices, numVertices);
- CPPUNIT_ASSERT_EQUAL(data.spaceDim,
- coordsField->getFiberDimension(*vertices->begin()));
+ CPPUNIT_ASSERT_EQUAL(data.spaceDim, coordsField->getFiberDimension(*vertices->begin()));
int i = 0;
const int spaceDim = data.spaceDim;
- for(SieveMesh::label_sequence::iterator v_iter =
- vertices->begin();
- v_iter != vertices->end();
- ++v_iter) {
- const PylithScalar* vertexCoords = coordsField->restrictPoint(*v_iter);
- CPPUNIT_ASSERT(0 != vertexCoords);
+ for(SieveMesh::label_sequence::iterator v_iter = vertices->begin(); v_iter != vertices->end(); ++v_iter) {
+ const PylithScalar* vertexCoords = coordsField->restrictPoint(*v_iter);CPPUNIT_ASSERT(vertexCoords);
const PylithScalar tolerance = 1.0e-06;
for (int iDim=0; iDim < spaceDim; ++iDim)
if (data.vertices[i] < 1.0) {
@@ -184,18 +171,17 @@
} else {
CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, vertexCoords[iDim]/data.vertices[i++],
tolerance);
- }
+ } // if/else
} // for
- PetscSection coordSection;
- Vec coordVec;
- PetscScalar *coords;
- PetscInt vStart, vEnd;
+ PetscSection coordSection = NULL;
+ PetscVec coordVec = NULL;
+ PetscScalar *coords = NULL;
+ PetscInt vStart, vEnd;
PetscErrorCode err;
err = DMPlexGetDepthStratum(dmMesh, 0, &vStart, &vEnd);CHECK_PETSC_ERROR(err);
- err = DMPlexGetCoordinateSection(dmMesh, &coordSection);CHECK_PETSC_ERROR(err);
- err = DMGetCoordinatesLocal(dmMesh, &coordVec);CHECK_PETSC_ERROR(err);
- CPPUNIT_ASSERT(coordSection);CPPUNIT_ASSERT(coordVec);
+ err = DMPlexGetCoordinateSection(dmMesh, &coordSection);CHECK_PETSC_ERROR(err);CPPUNIT_ASSERT(coordSection);
+ err = DMGetCoordinatesLocal(dmMesh, &coordVec);CHECK_PETSC_ERROR(err);CPPUNIT_ASSERT(coordVec);
err = VecGetArray(coordVec, &coords);CHECK_PETSC_ERROR(err);
for(PetscInt v = vStart; v < vEnd; ++v) {
PetscInt dof, off;
@@ -210,9 +196,9 @@
CPPUNIT_ASSERT_DOUBLES_EQUAL(data.vertices[eoff+d], coords[off+d], tolerance);
} else {
CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, coords[off+d]/data.vertices[eoff+d], tolerance);
- }
- }
- }
+ } // if/else
+ } // for
+ } // for
err = VecRestoreArray(coordVec, &coords);CHECK_PETSC_ERROR(err);
// check cells
@@ -234,7 +220,7 @@
const SieveMesh::point_type *cone = pV.getPoints();
for(int p = 0; p < pV.getSize(); ++p, ++i) {
CPPUNIT_ASSERT_EQUAL(data.cells[i], cone[p]-offset);
- }
+ } // for
pV.clear();
} // for
PetscInt cStart, cEnd;
@@ -250,8 +236,8 @@
CPPUNIT_ASSERT_EQUAL(data.numCorners, coneSize);
for(PetscInt p = 0; p < coneSize; ++p) {
CPPUNIT_ASSERT_EQUAL(data.cells[(c-cStart)*coneSize+p], cone[p]-offset);
- }
- }
+ } // for
+ } // for
// check materials
const ALE::Obj<SieveMesh::label_type>& labelMaterials = sieveMesh->getLabel("material-id");
@@ -272,10 +258,10 @@
err = DMPlexGetLabelValue(dmMesh, "material-id", c, &matId);CHECK_PETSC_ERROR(err);
CPPUNIT_ASSERT_EQUAL(data.materialIds[c-cStart], matId);
- }
+ } // for
// Check groups
-#if 0
+#if 0 // SIEVE STUFF
const ALE::Obj<std::set<std::string> >& groupNames =
sieveMesh->getIntSections();
if (data.numGroups > 0) {
@@ -348,16 +334,19 @@
PetscInt numPoints;
err = DMPlexGetStratumSize(dmMesh, name, 1, &numPoints);CHECK_PETSC_ERROR(err);
CPPUNIT_ASSERT_EQUAL(data.groupSizes[iGroup], numPoints);
- IS pointIS;
- const PetscInt *points;
- const PetscInt offset = ("vertex" == groupType) ? numCells : 0;
+ PetscIS pointIS = NULL;
+ const PetscInt *points = NULL;
+ const PetscInt offset = ("vertex" == groupType) ? numCells : 0;
err = DMPlexGetStratumIS(dmMesh, name, 1, &pointIS);CHECK_PETSC_ERROR(err);
err = ISGetIndices(pointIS, &points);CHECK_PETSC_ERROR(err);
for(PetscInt p = 0; p < numPoints; ++p) {
CPPUNIT_ASSERT_EQUAL(data.groups[index++], points[p]-offset);
- }
+ } // for
err = ISRestoreIndices(pointIS, &points);CHECK_PETSC_ERROR(err);
- }
+ err = ISDestroy(&pointIS);CHECK_PETSC_ERROR(err);
+ } // for
+
+ PYLITH_METHOD_END;
} // _checkVals
// ----------------------------------------------------------------------
@@ -365,6 +354,8 @@
void
pylith::meshio::TestMeshIO::_testDebug(MeshIO& iohandler)
{ // _testDebug
+ PYLITH_METHOD_BEGIN;
+
bool debug = false;
iohandler.debug(debug);
CPPUNIT_ASSERT_EQUAL(debug, iohandler.debug());
@@ -372,6 +363,8 @@
debug = true;
iohandler.debug(debug);
CPPUNIT_ASSERT_EQUAL(debug, iohandler.debug());
+
+ PYLITH_METHOD_END;
} // _testDebug
// ----------------------------------------------------------------------
@@ -379,6 +372,8 @@
void
pylith::meshio::TestMeshIO::_testInterpolate(MeshIO& iohandler)
{ // _testInterpolate
+ PYLITH_METHOD_BEGIN;
+
bool interpolate = false;
iohandler.interpolate(interpolate);
CPPUNIT_ASSERT_EQUAL(interpolate, iohandler.interpolate());
@@ -386,6 +381,8 @@
interpolate = true;
iohandler.interpolate(interpolate);
CPPUNIT_ASSERT_EQUAL(interpolate, iohandler.interpolate());
+
+ PYLITH_METHOD_END;
} // _testInterpolate
Modified: short/3D/PyLith/trunk/unittests/libtests/meshio/TestMeshIOAscii.cc
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/meshio/TestMeshIOAscii.cc 2013-04-10 21:16:02 UTC (rev 21803)
+++ short/3D/PyLith/trunk/unittests/libtests/meshio/TestMeshIOAscii.cc 2013-04-10 21:54:36 UTC (rev 21804)
@@ -42,7 +42,11 @@
void
pylith::meshio::TestMeshIOAscii::testConstructor(void)
{ // testConstructor
+ PYLITH_METHOD_BEGIN;
+
MeshIOAscii iohandler;
+
+ PYLITH_METHOD_END;
} // testConstructor
// ----------------------------------------------------------------------
@@ -50,8 +54,12 @@
void
pylith::meshio::TestMeshIOAscii::testDebug(void)
{ // testDebug
+ PYLITH_METHOD_BEGIN;
+
MeshIOAscii iohandler;
_testDebug(iohandler);
+
+ PYLITH_METHOD_END;
} // testDebug
// ----------------------------------------------------------------------
@@ -59,8 +67,12 @@
void
pylith::meshio::TestMeshIOAscii::testInterpolate(void)
{ // testInterpolate
+ PYLITH_METHOD_BEGIN;
+
MeshIOAscii iohandler;
_testInterpolate(iohandler);
+
+ PYLITH_METHOD_END;
} // testInterpolate
// ----------------------------------------------------------------------
@@ -68,11 +80,15 @@
void
pylith::meshio::TestMeshIOAscii::testFilename(void)
{ // testFilename
+ PYLITH_METHOD_BEGIN;
+
MeshIOAscii iohandler;
const char* filename = "hi.txt";
iohandler.filename(filename);
CPPUNIT_ASSERT(0 == strcasecmp(filename, iohandler.filename()));
+
+ PYLITH_METHOD_END;
} // testFilename
// ----------------------------------------------------------------------
@@ -80,9 +96,13 @@
void
pylith::meshio::TestMeshIOAscii::testWriteRead1D(void)
{ // testWriteRead1D
+ PYLITH_METHOD_BEGIN;
+
MeshData1D data;
const char* filename = "mesh1D.txt";
_testWriteRead(data, filename);
+
+ PYLITH_METHOD_END;
} // testWriteRead1D
// ----------------------------------------------------------------------
@@ -90,9 +110,13 @@
void
pylith::meshio::TestMeshIOAscii::testWriteRead1Din2D(void)
{ // testWriteRead1Din2D
+ PYLITH_METHOD_BEGIN;
+
MeshData1Din2D data;
const char* filename = "mesh1Din2D.txt";
_testWriteRead(data, filename);
+
+ PYLITH_METHOD_END;
} // testWriteRead1Din2D
// ----------------------------------------------------------------------
@@ -100,9 +124,13 @@
void
pylith::meshio::TestMeshIOAscii::testWriteRead1Din3D(void)
{ // testWriteRead1Din3D
+ PYLITH_METHOD_BEGIN;
+
MeshData1Din3D data;
const char* filename = "mesh1Din3D.txt";
_testWriteRead(data, filename);
+
+ PYLITH_METHOD_END;
} // testWriteRead1Din3D
// ----------------------------------------------------------------------
@@ -110,9 +138,13 @@
void
pylith::meshio::TestMeshIOAscii::testWriteRead2D(void)
{ // testWriteRead2D
+ PYLITH_METHOD_BEGIN;
+
MeshData2D data;
const char* filename = "mesh2D.txt";
_testWriteRead(data, filename);
+
+ PYLITH_METHOD_END;
} // testWriteRead2D
// ----------------------------------------------------------------------
@@ -120,9 +152,13 @@
void
pylith::meshio::TestMeshIOAscii::testWriteRead2Din3D(void)
{ // testWriteRead2Din3D
+ PYLITH_METHOD_BEGIN;
+
MeshData2Din3D data;
const char* filename = "mesh2Din3D.txt";
_testWriteRead(data, filename);
+
+ PYLITH_METHOD_END;
} // testWriteRead2Din3D
// ----------------------------------------------------------------------
@@ -130,9 +166,13 @@
void
pylith::meshio::TestMeshIOAscii::testWriteRead3D(void)
{ // testWriteRead3D
+ PYLITH_METHOD_BEGIN;
+
MeshData3D data;
const char* filename = "mesh3D.txt";
_testWriteRead(data, filename);
+
+ PYLITH_METHOD_END;
} // testWriteRead3D
// ----------------------------------------------------------------------
@@ -140,9 +180,13 @@
void
pylith::meshio::TestMeshIOAscii::testRead3DIndexOne(void)
{ // testRead3IndexDOne
+ PYLITH_METHOD_BEGIN;
+
MeshData3DIndexOne data;
const char* filename = "data/mesh3DIndexOne.txt";
_testRead(data, filename);
+
+ PYLITH_METHOD_END;
} // testRead3DIndexOne
// ----------------------------------------------------------------------
@@ -150,9 +194,13 @@
void
pylith::meshio::TestMeshIOAscii::testReadComments(void)
{ // testWriteReadComments
+ PYLITH_METHOD_BEGIN;
+
MeshData2D data;
const char* filename = "data/mesh2D_comments.txt";
_testRead(data, filename);
+
+ PYLITH_METHOD_END;
} // testWriteReadComments
// ----------------------------------------------------------------------
@@ -161,6 +209,8 @@
pylith::meshio::TestMeshIOAscii::_testWriteRead(const MeshData& data,
const char* filename)
{ // _testWriteRead
+ PYLITH_METHOD_BEGIN;
+
topology::Mesh* meshOut = _createMesh(data);
// Write mesh
@@ -175,6 +225,8 @@
// Make sure meshIn matches data
_checkVals(meshIn, data);
+
+ PYLITH_METHOD_END;
} // _testWriteRead
// ----------------------------------------------------------------------
@@ -183,6 +235,8 @@
pylith::meshio::TestMeshIOAscii::_testRead(const MeshData& data,
const char* filename)
{ // _testWriteRead
+ PYLITH_METHOD_BEGIN;
+
// Read mesh
topology::Mesh mesh;
MeshIOAscii iohandler;
@@ -191,6 +245,8 @@
// Make sure mesh matches data
_checkVals(mesh, data);
+
+ PYLITH_METHOD_END;
} // _testRead
More information about the CIG-COMMITS
mailing list