[cig-commits] [commit] knepley/upgrade-petsc-interface: More work on reordering unit tests. (90bb0cd)
cig_noreply at geodynamics.org
cig_noreply at geodynamics.org
Fri Oct 18 15:27:13 PDT 2013
Repository : ssh://geoshell/pylith
On branch : knepley/upgrade-petsc-interface
Link : https://github.com/geodynamics/pylith/compare/3a1c2fe5ae5b5e0c987791aa2b8eeca011b22468...885a302db65b09c5eee1ea0904b2bcee47e5d677
>---------------------------------------------------------------
commit 90bb0cd85421180345b22423a7f341603f42c286
Author: Brad Aagaard <baagaard at usgs.gov>
Date: Fri Oct 18 15:28:31 2013 -0700
More work on reordering unit tests.
>---------------------------------------------------------------
90bb0cd85421180345b22423a7f341603f42c286
.../libtests/topology/TestReverseCuthillMcKee.cc | 159 +++++++++------------
.../libtests/topology/TestReverseCuthillMcKee.hh | 14 +-
unittests/libtests/topology/data/Makefile.am | 6 +-
unittests/libtests/topology/data/reorder_hex8.mesh | 57 ++++++++
.../libtests/topology/data/reorder_quad4.mesh | 45 ++++++
unittests/libtests/topology/data/reorder_tet4.mesh | 43 ++++++
unittests/libtests/topology/data/reorder_tri3.mesh | 47 ++++++
7 files changed, 270 insertions(+), 101 deletions(-)
diff --git a/unittests/libtests/topology/TestReverseCuthillMcKee.cc b/unittests/libtests/topology/TestReverseCuthillMcKee.cc
index be77f49..c00f47e 100644
--- a/unittests/libtests/topology/TestReverseCuthillMcKee.cc
+++ b/unittests/libtests/topology/TestReverseCuthillMcKee.cc
@@ -24,21 +24,11 @@
#include "pylith/topology/Mesh.hh" // USES Mesh
#include "pylith/topology/Stratum.hh" // USES Stratum
+#include "pylith/topology/Field.hh" // USES Field
+#include "pylith/topology/Jacobian.hh" // USES Field
#include "pylith/meshio/MeshIOAscii.hh" // USES MeshIOAscii
#include "pylith/faults/FaultCohesiveKin.hh" // USES FaultCohesiveKin
-#include "data/MeshDataCohesiveTri3Level1.hh"
-#include "data/MeshDataCohesiveTri3Level1Fault1.hh"
-#include "data/MeshDataCohesiveQuad4Level1.hh"
-#include "data/MeshDataCohesiveQuad4Level1Fault1.hh"
-#include "data/MeshDataCohesiveTet4Level1.hh"
-#include "data/MeshDataCohesiveTet4Level1Fault1.hh"
-#include "data/MeshDataCohesiveHex8Level1.hh"
-#include "data/MeshDataCohesiveHex8Level1Fault1.hh"
-
-#include <strings.h> // USES strcasecmp()
-#include <stdexcept> // USES std::logic_error
-
// ----------------------------------------------------------------------
CPPUNIT_TEST_SUITE_REGISTRATION( pylith::topology::TestReverseCuthillMcKee );
@@ -49,8 +39,7 @@ pylith::topology::TestReverseCuthillMcKee::testReorderTri3(void)
{ // testReorderTri3
PYLITH_METHOD_BEGIN;
- MeshDataCohesiveTri3Level1 data;
- _testReorder(data);
+ _testReorder("data/reorder_tri3.mesh");
PYLITH_METHOD_END;
} // testReorderTri3
@@ -62,8 +51,7 @@ pylith::topology::TestReverseCuthillMcKee::testReorderTri3Fault(void)
{ // testReorderTri3Fault
PYLITH_METHOD_BEGIN;
- MeshDataCohesiveTri3Level1Fault1 data;
- _testReorder(data);
+ _testReorder("data/reorder_tri3.mesh", "fault");
PYLITH_METHOD_END;
} // testReorderTri3Fault
@@ -75,8 +63,7 @@ pylith::topology::TestReverseCuthillMcKee::testReorderQuad4(void)
{ // testReorderQuad4
PYLITH_METHOD_BEGIN;
- MeshDataCohesiveQuad4Level1 data;
- _testReorder(data);
+ _testReorder("data/reorder_quad4.mesh");
PYLITH_METHOD_END;
} // testReorderQuad4
@@ -88,8 +75,7 @@ pylith::topology::TestReverseCuthillMcKee::testReorderQuad4Fault(void)
{ // testReorderQuad4Fault
PYLITH_METHOD_BEGIN;
- MeshDataCohesiveQuad4Level1Fault1 data;
- _testReorder(data);
+ _testReorder("data/reorder_quad4.mesh", "fault");
PYLITH_METHOD_END;
} // testReorderQuad4Fault
@@ -101,8 +87,7 @@ pylith::topology::TestReverseCuthillMcKee::testReorderTet4(void)
{ // testReorderTet4
PYLITH_METHOD_BEGIN;
- MeshDataCohesiveTet4Level1 data;
- _testReorder(data);
+ _testReorder("data/reorder_tet4.mesh");
PYLITH_METHOD_END;
} // testReorderTet4
@@ -114,8 +99,7 @@ pylith::topology::TestReverseCuthillMcKee::testReorderTet4Fault(void)
{ // testReorderTet4Fault
PYLITH_METHOD_BEGIN;
- MeshDataCohesiveTet4Level1Fault1 data;
- _testReorder(data);
+ _testReorder("data/reorder_tet4.mesh", "fault");
PYLITH_METHOD_END;
} // testReorderTet4Fault
@@ -127,8 +111,7 @@ pylith::topology::TestReverseCuthillMcKee::testReorderHex8(void)
{ // testReorderHex8
PYLITH_METHOD_BEGIN;
- MeshDataCohesiveHex8Level1 data;
- _testReorder(data);
+ _testReorder("data/reorder_hex8.mesh");
PYLITH_METHOD_END;
} // testReorderHex8
@@ -140,8 +123,7 @@ pylith::topology::TestReverseCuthillMcKee::testReorderHex8Fault(void)
{ // testReorderHex8Fault
PYLITH_METHOD_BEGIN;
- MeshDataCohesiveHex8Level1Fault1 data;
- _testReorder(data);
+ _testReorder("data/reorder_hex8.mesh", "fault");
PYLITH_METHOD_END;
} // testReorderHex8Fault
@@ -149,48 +131,35 @@ pylith::topology::TestReverseCuthillMcKee::testReorderHex8Fault(void)
// ----------------------------------------------------------------------
void
pylith::topology::TestReverseCuthillMcKee::_setupMesh(Mesh* const mesh,
- const MeshDataCohesive& data)
+ const char* filename,
+ const char* faultGroup)
{ // _setupMesh
PYLITH_METHOD_BEGIN;
assert(mesh);
meshio::MeshIOAscii iohandler;
- iohandler.filename(data.filename);
+ iohandler.filename(filename);
iohandler.interpolate(true);
iohandler.read(mesh);
+ CPPUNIT_ASSERT(mesh->numCells() > 0);
+ CPPUNIT_ASSERT(mesh->numVertices() > 0);
// Adjust topology if necessary.
- if (data.faultA || data.faultB) {
+ if (faultGroup) {
int firstLagrangeVertex = 0;
int firstFaultCell = 0;
- faults::FaultCohesiveKin faultA;
- faultA.id(100);
- if (data.faultA) {
- faultA.label(data.faultA);
- const int nvertices = faultA.numVerticesNoMesh(*mesh);
- firstLagrangeVertex += nvertices;
- firstFaultCell += 2*nvertices; // shadow + Lagrange vertices
- } // if
-
- faults::FaultCohesiveKin faultB;
- faultB.id(101);
- if (data.faultB) {
- faultA.label(data.faultB);
- const int nvertices = faultB.numVerticesNoMesh(*mesh);
- firstLagrangeVertex += nvertices;
- firstFaultCell += 2*nvertices; // shadow + Lagrange vertices
- } // if
+ faults::FaultCohesiveKin fault;
+ fault.id(100);
+ fault.label(faultGroup);
+ const int nvertices = fault.numVerticesNoMesh(*mesh);
+ firstLagrangeVertex += nvertices;
+ firstFaultCell += 2*nvertices; // shadow + Lagrange vertices
int firstFaultVertex = 0;
- if (data.faultA) {
- faultA.adjustTopology(mesh, &firstFaultVertex, &firstLagrangeVertex, &firstFaultCell);
- } // if
- if (data.faultB) {
- faultB.adjustTopology(mesh, &firstFaultVertex, &firstLagrangeVertex, &firstFaultCell);
- } // if
+ fault.adjustTopology(mesh, &firstFaultVertex, &firstLagrangeVertex, &firstFaultCell);
} // if
PYLITH_METHOD_END;
@@ -199,70 +168,72 @@ pylith::topology::TestReverseCuthillMcKee::_setupMesh(Mesh* const mesh,
// ----------------------------------------------------------------------
// Test reorder().
void
-pylith::topology::TestReverseCuthillMcKee::_testReorder(const MeshDataCohesive& data)
+pylith::topology::TestReverseCuthillMcKee::_testReorder(const char* filename,
+ const char* faultGroup)
{ // _testReorder
PYLITH_METHOD_BEGIN;
- Mesh mesh(data.cellDim);
- _setupMesh(&mesh, data);
+ Mesh mesh;
+ _setupMesh(&mesh, filename, faultGroup);
+ const PetscDM dmOrig = mesh.dmMesh();
+ PetscObjectReference((PetscObject) dmOrig);
ReverseCuthillMcKee::reorder(&mesh);
- // Check mesh dimension
- CPPUNIT_ASSERT_EQUAL(data.cellDim, mesh.dimension());
-
const PetscDM& dmMesh = mesh.dmMesh();CPPUNIT_ASSERT(dmMesh);
// Check vertices (size only)
+ topology::Stratum verticesStratumE(dmOrig, topology::Stratum::DEPTH, 0);
topology::Stratum verticesStratum(dmMesh, topology::Stratum::DEPTH, 0);
- CPPUNIT_ASSERT_EQUAL(data.numVertices, verticesStratum.size());
+ CPPUNIT_ASSERT_EQUAL(verticesStratumE.size(), verticesStratum.size());
// Check cells (size only)
+ topology::Stratum cellsStratumE(dmOrig, topology::Stratum::HEIGHT, 0);
topology::Stratum cellsStratum(dmMesh, topology::Stratum::HEIGHT, 0);
const PetscInt cStart = cellsStratum.begin();
const PetscInt cEnd = cellsStratum.end();
const PetscInt numCells = cellsStratum.size();
- CPPUNIT_ASSERT_EQUAL(data.numCells+data.numCellsCohesive, numCells);
+ CPPUNIT_ASSERT_EQUAL(cellsStratumE.size(), cellsStratum.size());
// Check groups
- PetscInt numGroups, pStart, pEnd;
+ PetscInt numGroupsE, numGroups, pStart, pEnd;
PetscErrorCode err;
- err = DMPlexGetChart(dmMesh, &pStart, &pEnd);PYLITH_CHECK_ERROR(err);
+ err = DMPlexGetNumLabels(dmOrig, &numGroupsE);PYLITH_CHECK_ERROR(err);
err = DMPlexGetNumLabels(dmMesh, &numGroups);PYLITH_CHECK_ERROR(err);
- CPPUNIT_ASSERT_EQUAL(data.numGroups, numGroups-2); // Omit depth and material labels
- PetscInt index = 0;
- for(PetscInt iGroup = 0; iGroup < data.numGroups; ++iGroup) {
- // Don't know order of labels, so do brute force linear search
- bool foundLabel = false;
- int iLabel = 0;
- const char *name = NULL;
- PetscInt firstPoint = 0;
- while (iLabel < numGroups) {
- err = DMPlexGetLabelName(dmMesh, iLabel, &name);PYLITH_CHECK_ERROR(err);
- if (0 == strcmp(data.groupNames[iGroup], name)) {
- foundLabel = true;
- break;
- } else {
- ++iLabel;
- } // if/else
- } // while
- CPPUNIT_ASSERT(foundLabel);
-
- for(PetscInt p = pStart; p < pEnd; ++p) {
- PetscInt val;
- err = DMPlexGetLabelValue(dmMesh, name, p, &val);PYLITH_CHECK_ERROR(err);
- if (val >= 0) {
- firstPoint = p;
- break;
- } // if
+ { // DEBUGGING
+ PetscErrorCode err;
+ for (PetscInt iGroup = 0; iGroup < numGroupsE; ++iGroup) {
+ const char *name = NULL;
+ err = DMPlexGetLabelName(dmOrig, iGroup, &name);PYLITH_CHECK_ERROR(err);
+ std::cout << "ORIG Group["<<iGroup<<"]: " << name << std::endl;
+ } // for
+ for (PetscInt iGroup = 0; iGroup < numGroups; ++iGroup) {
+ const char *name = NULL;
+ err = DMPlexGetLabelName(dmMesh, iGroup, &name);PYLITH_CHECK_ERROR(err);
+ std::cout << "REORDER Group["<<iGroup<<"]: " << name << std::endl;
} // for
- std::string groupType = (firstPoint >= cStart && firstPoint < cEnd) ? "cell" : "vertex";
- CPPUNIT_ASSERT_EQUAL(std::string(data.groupTypes[iGroup]), groupType);
- PetscInt numPoints;
+ } // DEBUGGING
+ CPPUNIT_ASSERT_EQUAL(numGroupsE, numGroups);
+
+ for (PetscInt iGroup = 0; iGroup < numGroups; ++iGroup) {
+ const char *name = NULL;
+ err = DMPlexGetLabelName(dmMesh, iGroup, &name);PYLITH_CHECK_ERROR(err);
+
+ PetscInt numPointsE, numPoints;
+ err = DMPlexGetStratumSize(dmOrig, name, 1, &numPointsE);PYLITH_CHECK_ERROR(err);
err = DMPlexGetStratumSize(dmMesh, name, 1, &numPoints);PYLITH_CHECK_ERROR(err);
- CPPUNIT_ASSERT_EQUAL(data.groupSizes[iGroup], numPoints);
+ CPPUNIT_ASSERT_EQUAL(numPointsE, numPoints);
} // for
+ // Verify reduction in Jacobian bandwidth
+ Field field(mesh);
+ field.newSection(FieldBase::VERTICES_FIELD, mesh.dimension());
+ field.allocate();
+ field.zero();
+ Jacobian jacobian(field);
+ std::cout << "****TEST IS DISABLED. FORCING FAILURE.****" << std::endl;
+ CPPUNIT_ASSERT(false);
+
PYLITH_METHOD_END;
} // _testReorder
diff --git a/unittests/libtests/topology/TestReverseCuthillMcKee.hh b/unittests/libtests/topology/TestReverseCuthillMcKee.hh
index 491d378..d7e59dd 100644
--- a/unittests/libtests/topology/TestReverseCuthillMcKee.hh
+++ b/unittests/libtests/topology/TestReverseCuthillMcKee.hh
@@ -37,8 +37,6 @@
namespace pylith {
namespace topology {
class TestReverseCuthillMcKee;
-
- class MeshDataCohesive; // test data
} // topology
} // pylith
@@ -96,16 +94,20 @@ private :
/** Setup mesh.
*
* @mesh Mesh to setup.
- * @param data Test data.
+ * @param filename Mesh filename.
+ * @param faultGroup Name of fault group.
*/
void _setupMesh(Mesh* const mesh,
- const MeshDataCohesive& data);
+ const char* filename,
+ const char* faultGroup =0);
/** Test reorder().
*
- * @param data Test data.
+ * @param filename Mesh filename.
+ * @param faultGroup Name of fault group.
*/
- void _testReorder(const MeshDataCohesive& data);
+ void _testReorder(const char* filename,
+ const char* faultGroup =0);
}; // class TestReverseCuthillMcKee
diff --git a/unittests/libtests/topology/data/Makefile.am b/unittests/libtests/topology/data/Makefile.am
index f3698f8..6fe1bac 100644
--- a/unittests/libtests/topology/data/Makefile.am
+++ b/unittests/libtests/topology/data/Makefile.am
@@ -21,7 +21,11 @@ dist_noinst_DATA = \
fourtri3.mesh \
fourquad4.mesh \
twotet4.mesh \
- twohex8.mesh
+ twohex8.mesh \
+ reorder_tri3.mesh \
+ reorder_quad4.mesh \
+ reorder_tet4.mesh \
+ reorder_hex8.mesh
noinst_TMP =
diff --git a/unittests/libtests/topology/data/reorder_hex8.mesh b/unittests/libtests/topology/data/reorder_hex8.mesh
new file mode 100644
index 0000000..4742318
--- /dev/null
+++ b/unittests/libtests/topology/data/reorder_hex8.mesh
@@ -0,0 +1,57 @@
+mesh = {
+ dimension = 3
+ use-index-zero = true
+ vertices = {
+ dimension = 3
+ count = 18
+ coordinates = {
+ 0 +1.0 -1.0 -1.0
+ 1 -1.0 +1.0 +1.0
+ 2 -1.0 -1.0 0.0
+ 3 +1.0 +1.0 0.0
+ 4 -1.0 +1.0 -1.0
+ 5 +1.0 -1.0 +1.0
+ 6 -1.0 +1.0 0.0
+ 7 +1.0 -1.0 0.0
+ 8 -1.0 -1.0 -1.0
+ 9 +1.0 +1.0 +1.0
+ 10 -1.0 -1.0 +1.0
+ 11 +1.0 +1.0 -1.0
+ 12 0.0 -1.0 -1.0
+ 13 0.0 +1.0 +1.0
+ 14 0.0 +1.0 -1.0
+ 15 0.0 -1.0 +1.0
+ 16 0.0 -1.0 0.0
+ 17 0.0 +1.0 0.0
+ }
+ }
+ cells = {
+ count = 4
+ num-corners = 8
+ simplices = {
+ 0 2 16 17 6 10 15 13 1
+ 1 8 12 14 4 2 16 17 6
+ 2 0 11 14 12 7 3 17 16
+ 3 16 7 3 17 15 5 9 13
+ }
+ material-ids = {
+ 0 1
+ 1 1
+ 2 2
+ 3 2
+ }
+ }
+ group = {
+ name = fault
+ type = vertices
+ count = 6
+ indices = {
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ }
+ }
+}
diff --git a/unittests/libtests/topology/data/reorder_quad4.mesh b/unittests/libtests/topology/data/reorder_quad4.mesh
new file mode 100644
index 0000000..3826cc0
--- /dev/null
+++ b/unittests/libtests/topology/data/reorder_quad4.mesh
@@ -0,0 +1,45 @@
+mesh = {
+ dimension = 2
+ use-index-zero = true
+ vertices = {
+ dimension = 2
+ count = 9
+ coordinates = {
+ 0 -1.0 +1.0
+ 1 +1.0 -1.0
+ 2 -1.0 -1.0
+ 3 +1.0 +1.0
+ 4 0.0 -1.0
+ 5 0.0 +1.0
+ 6 +1.0 0.0
+ 7 -1.0 0.0
+ 8 0.0 0.0
+ }
+ }
+ cells = {
+ count = 4
+ num-corners = 4
+ simplices = {
+ 0 0 7 8 5
+ 1 2 4 8 7
+ 2 1 6 8 4
+ 3 6 3 5 8
+ }
+ material-ids = {
+ 0 1
+ 1 1
+ 2 2
+ 3 2
+ }
+ }
+ group = {
+ name = fault
+ type = vertices
+ count = 3
+ indices = {
+ 4
+ 5
+ 8
+ }
+ }
+}
diff --git a/unittests/libtests/topology/data/reorder_tet4.mesh b/unittests/libtests/topology/data/reorder_tet4.mesh
new file mode 100644
index 0000000..d67506c
--- /dev/null
+++ b/unittests/libtests/topology/data/reorder_tet4.mesh
@@ -0,0 +1,43 @@
+mesh = {
+ dimension = 3
+ use-index-zero = true
+ vertices = {
+ dimension = 3
+ count = 6
+ coordinates = {
+ 0 -1.0 0.0 0.0
+ 1 +1.0 0.0 0.0
+ 2 0.0 +1.0 0.0
+ 3 0.0 0.0 +1.0
+ 4 0.0 0.0 -1.0
+ 5 0.0 -1.0 0.0
+ }
+ }
+ cells = {
+ count = 4
+ num-corners = 4
+ simplices = {
+ 0 0 5 2 3
+ 1 4 5 2 0
+ 2 1 2 5 3
+ 3 4 1 2 5
+ }
+ material-ids = {
+ 0 1
+ 1 1
+ 2 2
+ 3 2
+ }
+ }
+ group = {
+ name = fault
+ type = vertices
+ count = 4
+ indices = {
+ 2
+ 3
+ 4
+ 5
+ }
+ }
+}
diff --git a/unittests/libtests/topology/data/reorder_tri3.mesh b/unittests/libtests/topology/data/reorder_tri3.mesh
new file mode 100644
index 0000000..cb7c2ff
--- /dev/null
+++ b/unittests/libtests/topology/data/reorder_tri3.mesh
@@ -0,0 +1,47 @@
+mesh = {
+ dimension = 2
+ use-index-zero = true
+ vertices = {
+ dimension = 2
+ count = 8
+ coordinates = {
+ 0 -1.0 +1.0
+ 1 +1.0 -1.0
+ 2 -1.0 -1.0
+ 3 +1.0 +1.0
+ 4 0.0 -1.0
+ 5 0.0 +1.0
+ 6 +1.0 0.0
+ 7 -1.0 0.0
+ }
+ }
+ cells = {
+ count = 6
+ num-corners = 3
+ simplices = {
+ 0 0 7 5
+ 1 2 4 7
+ 2 1 6 4
+ 3 6 3 5
+ 4 7 4 5
+ 5 4 6 5
+ }
+ material-ids = {
+ 0 1
+ 1 1
+ 2 2
+ 3 2
+ 4 3
+ 5 3
+ }
+ }
+ group = {
+ name = fault
+ type = vertices
+ count = 2
+ indices = {
+ 4
+ 5
+ }
+ }
+}
More information about the CIG-COMMITS
mailing list