[cig-commits] [commit] knepley/upgrade-petsc-interface: Added MeshOps::checkTopology(). (38bd321)

cig_noreply at geodynamics.org cig_noreply at geodynamics.org
Fri Nov 8 11:09:14 PST 2013


Repository : ssh://geoshell/pylith

On branch  : knepley/upgrade-petsc-interface
Link       : https://github.com/geodynamics/pylith/compare/1f1ab4214caab5252cb60d16b1a765e8c4dcf1b0...38bd3211afca7b7cd3c34e27e582f695f98327b9

>---------------------------------------------------------------

commit 38bd3211afca7b7cd3c34e27e582f695f98327b9
Author: Brad Aagaard <baagaard at usgs.gov>
Date:   Fri Nov 8 11:11:37 2013 -0800

    Added MeshOps::checkTopology().
    
    Added calls to checkTopology() after reading mesh, creating submesh,
    adjusting the topology (faults), and refining mesh. Removed redundant
    topology checks from unit tests.


>---------------------------------------------------------------

38bd3211afca7b7cd3c34e27e582f695f98327b9
 libsrc/pylith/faults/FaultCohesive.cc             |  7 +++++++
 libsrc/pylith/faults/FaultCohesiveLagrange.cc     |  4 ++++
 libsrc/pylith/meshio/MeshIO.cc                    |  4 ++++
 libsrc/pylith/topology/Mesh.cc                    |  5 +++++
 libsrc/pylith/topology/MeshOps.cc                 | 24 +++++++++++++++++++++++
 libsrc/pylith/topology/MeshOps.hh                 |  7 +++++++
 libsrc/pylith/topology/RefineUniform.cc           |  4 ++++
 unittests/libtests/bc/TestBoundaryMesh.cc         | 10 ----------
 unittests/libtests/faults/TestFaultCohesive.cc    | 17 ----------------
 unittests/libtests/faults/TestFaultCohesiveDyn.cc | 13 +-----------
 unittests/libtests/faults/TestFaultCohesiveKin.cc | 13 +-----------
 unittests/libtests/topology/TestRefineUniform.cc  |  6 +-----
 12 files changed, 58 insertions(+), 56 deletions(-)

diff --git a/libsrc/pylith/faults/FaultCohesive.cc b/libsrc/pylith/faults/FaultCohesive.cc
index 77a8e16..ddf568c 100644
--- a/libsrc/pylith/faults/FaultCohesive.cc
+++ b/libsrc/pylith/faults/FaultCohesive.cc
@@ -23,6 +23,7 @@
 #include "CohesiveTopology.hh" // USES CohesiveTopology
 #include "pylith/topology/Field.hh" // USES Field
 #include "pylith/topology/Fields.hh" // USES Fields
+#include "pylith/topology/MeshOps.hh" // USES MeshOps
 
 #include <cassert> // USES assert()
 #include <sstream> // USES std::ostringstream
@@ -156,6 +157,11 @@ pylith::faults::FaultCohesive::adjustTopology(topology::Mesh* const mesh,
       assert(3 == mesh->dimension());
       throw std::logic_error("Support for UCD fault files no longer implemented."); 
     } // if/else
+
+    // Check consistency of mesh.
+    topology::MeshOps::checkTopology(*mesh);
+    topology::MeshOps::checkTopology(faultMesh);
+
   } catch (const std::exception& err) {
     std::ostringstream msg;
     msg << "Error occurred while adjusting topology to create cohesive cells for fault '" << label() << "'.\n"
@@ -163,6 +169,7 @@ pylith::faults::FaultCohesive::adjustTopology(topology::Mesh* const mesh,
     throw std::runtime_error(msg.str());
   }
 
+
   PYLITH_METHOD_END;
 } // adjustTopology
 
diff --git a/libsrc/pylith/faults/FaultCohesiveLagrange.cc b/libsrc/pylith/faults/FaultCohesiveLagrange.cc
index 9c3a98b..1f7417e 100644
--- a/libsrc/pylith/faults/FaultCohesiveLagrange.cc
+++ b/libsrc/pylith/faults/FaultCohesiveLagrange.cc
@@ -25,6 +25,7 @@
 #include "pylith/feassemble/Quadrature.hh" // USES Quadrature
 #include "pylith/feassemble/CellGeometry.hh" // USES CellGeometry
 #include "pylith/topology/Mesh.hh" // USES Mesh
+#include "pylith/topology/MeshOps.hh" // USES MeshOps
 #include "pylith/topology/Field.hh" // USES Field
 #include "pylith/topology/Fields.hh" // USES Fields
 #include "pylith/topology/Jacobian.hh" // USES Jacobian
@@ -100,6 +101,9 @@ pylith::faults::FaultCohesiveLagrange::initialize(const topology::Mesh& mesh,
   const bool isSubMesh = true;
   delete _faultMesh; _faultMesh = new topology::Mesh(isSubMesh);assert(_faultMesh);
   CohesiveTopology::createFaultParallel(_faultMesh, mesh, id(), label(), _useLagrangeConstraints); // :TODO: Obsolete?
+  
+  topology::MeshOps::checkTopology(*_faultMesh);
+
   _initializeCohesiveInfo(mesh);
 
   delete _fields; _fields = new topology::Fields(*_faultMesh);assert(_fields);
diff --git a/libsrc/pylith/meshio/MeshIO.cc b/libsrc/pylith/meshio/MeshIO.cc
index 857c60e..1fde81d 100644
--- a/libsrc/pylith/meshio/MeshIO.cc
+++ b/libsrc/pylith/meshio/MeshIO.cc
@@ -21,6 +21,7 @@
 #include "MeshIO.hh" // implementation of class methods
 
 #include "pylith/topology/Mesh.hh" // USES Mesh
+#include "pylith/topology/MeshOps.hh" // USES MeshOps
 #include "pylith/topology/Stratum.hh" // USES Stratum
 
 #include "pylith/utils/array.hh" // USES scalar_array, int_array
@@ -77,6 +78,9 @@ pylith::meshio::MeshIO::read(topology::Mesh* mesh)
   _mesh->debug(_debug);
   _read();
 
+  // Check mesh consistency
+  topology::MeshOps::checkTopology(*_mesh);
+
   _mesh = 0;
 
   PYLITH_METHOD_END;
diff --git a/libsrc/pylith/topology/Mesh.cc b/libsrc/pylith/topology/Mesh.cc
index 8e6b018..859082c 100644
--- a/libsrc/pylith/topology/Mesh.cc
+++ b/libsrc/pylith/topology/Mesh.cc
@@ -21,6 +21,8 @@
 
 #include "Mesh.hh" // implementation of class methods
 
+#include "MeshOps.hh" // USES MeshOps
+
 #include "spatialdata/geocoords/CoordSys.hh" // USES CoordSys
 #include "pylith/utils/array.hh" // USES scalar_array
 #include "pylith/utils/petscfwd.h" // USES PetscVec
@@ -132,6 +134,9 @@ pylith::topology::Mesh::Mesh(const Mesh& mesh,
   err = DMPlexGetScale(dmMesh, PETSC_UNIT_LENGTH, &lengthScale);PYLITH_CHECK_ERROR(err);
   err = DMPlexSetScale(_dmMesh, PETSC_UNIT_LENGTH, lengthScale);PYLITH_CHECK_ERROR(err);
 
+  // Check topology
+  MeshOps::checkTopology(*this);
+
   PYLITH_METHOD_END;
 } // SubMesh constructor
 		     
diff --git a/libsrc/pylith/topology/MeshOps.cc b/libsrc/pylith/topology/MeshOps.cc
index 1581d79..16e1a51 100644
--- a/libsrc/pylith/topology/MeshOps.cc
+++ b/libsrc/pylith/topology/MeshOps.cc
@@ -77,6 +77,30 @@ pylith::topology::MeshOps::nondimensionalize(Mesh* const mesh,
 
 
 // ----------------------------------------------------------------------
+// Check topology of mesh.
+void
+pylith::topology::MeshOps::checkTopology(const Mesh& mesh)
+{ // checkTopology
+  PetscDM dmMesh = mesh.dmMesh();assert(dmMesh);
+
+  const int cellDim = mesh.dimension();
+  const int numCorners = mesh.numCorners();
+  PetscBool isSimplexMesh = PETSC_TRUE;
+  if ((cellDim == 2 && numCorners == 4) ||
+      (cellDim == 3 && numCorners == 8)) {
+    isSimplexMesh = PETSC_FALSE;
+  } // if
+
+  PetscErrorCode err;
+  err = DMPlexCheckSymmetry(dmMesh);PYLITH_CHECK_ERROR_MSG(err, "Error in topology of mesh associated with symmetry of adjacency information.");
+
+  if (cellDim > 1) {
+    err = DMPlexCheckSkeleton(dmMesh, isSimplexMesh);PYLITH_CHECK_ERROR_MSG(err, "Error in topology of mesh cells.");
+  } // if
+} // checkTopology
+
+
+// ----------------------------------------------------------------------
 void
 pylith::topology::MeshOps::checkMaterialIds(const Mesh& mesh,
 					    int* const materialIds,
diff --git a/libsrc/pylith/topology/MeshOps.hh b/libsrc/pylith/topology/MeshOps.hh
index 5183891..d2f9b12 100644
--- a/libsrc/pylith/topology/MeshOps.hh
+++ b/libsrc/pylith/topology/MeshOps.hh
@@ -61,6 +61,13 @@ public :
   void nondimensionalize(Mesh* const mesh,
 			 const spatialdata::units::Nondimensional& normalizer);
 
+  /** Check topology of mesh.
+   *
+   * @param mesh Finite-element mesh.
+   */
+  static
+  void checkTopology(const Mesh& mesh);
+
   /** Check to make sure material id of every cell matches the id of
    *  one of the materials.
    *
diff --git a/libsrc/pylith/topology/RefineUniform.cc b/libsrc/pylith/topology/RefineUniform.cc
index 3507399..157134d 100644
--- a/libsrc/pylith/topology/RefineUniform.cc
+++ b/libsrc/pylith/topology/RefineUniform.cc
@@ -21,6 +21,7 @@
 #include "RefineUniform.hh" // implementation of class methods
 
 #include "Mesh.hh" // USES Mesh
+#include "MeshOps.hh" // USES MeshOps
 
 #include <cassert> // USES assert()
 #include <sstream> // USES std::ostringstream
@@ -81,6 +82,9 @@ pylith::topology::RefineUniform::refine(Mesh* const newMesh,
 
   newMesh->dmMesh(dmNew);
 
+  // Check consistency
+  topology::MeshOps::checkTopology(*newMesh);
+
   //newMesh->view("REFINED_MESH", "::ascii_info_detail");
 
   PYLITH_METHOD_END;
diff --git a/unittests/libtests/bc/TestBoundaryMesh.cc b/unittests/libtests/bc/TestBoundaryMesh.cc
index a61d8e7..1b0c418 100644
--- a/unittests/libtests/bc/TestBoundaryMesh.cc
+++ b/unittests/libtests/bc/TestBoundaryMesh.cc
@@ -84,10 +84,6 @@ pylith::bc::TestBoundaryMesh::testSubmesh(void)
   topology::Mesh submesh(mesh, _data->bcLabel);
   PetscDM dmMesh = submesh.dmMesh();CPPUNIT_ASSERT(dmMesh);
 
-  // Check consistency
-  err = DMPlexCheckSymmetry(dmMesh);CPPUNIT_ASSERT(!err);
-  //err = DMPlexCheckSkeleton(dmMesh, _data->isSimplexMesh ? PETSC_TRUE : PETSC_FALSE);CPPUNIT_ASSERT(!err);
-
   // Check vertices
   topology::Stratum verticesStratum(dmMesh, topology::Stratum::DEPTH, 0);
   const PetscInt vStart = verticesStratum.begin();
@@ -158,12 +154,6 @@ pylith::bc::TestBoundaryMesh::testSubmeshFault(void)
   PetscViewerPopFormat(PETSC_VIEWER_STDOUT_WORLD);
 #endif
 
-  // Check consistency
-  err = DMPlexCheckSymmetry(dmMesh);CPPUNIT_ASSERT(!err);
-  if (submesh.dimension() > 1) {
-    //err = DMPlexCheckSkeleton(dmMesh, _data->isSimplexMesh ? PETSC_TRUE : PETSC_FALSE);CPPUNIT_ASSERT(!err);
-  } // if
-
   // Check vertices
   topology::Stratum verticesStratum(dmMesh, topology::Stratum::DEPTH, 0);
   const PetscInt vStart = verticesStratum.begin();
diff --git a/unittests/libtests/faults/TestFaultCohesive.cc b/unittests/libtests/faults/TestFaultCohesive.cc
index bdb14ba..025bb76 100644
--- a/unittests/libtests/faults/TestFaultCohesive.cc
+++ b/unittests/libtests/faults/TestFaultCohesive.cc
@@ -681,15 +681,6 @@ pylith::faults::TestFaultCohesive::_testAdjustTopology(Fault* fault,
   CPPUNIT_ASSERT_EQUAL(data.cellDim, mesh.dimension());
   dmMesh = mesh.dmMesh();CPPUNIT_ASSERT(dmMesh);
 
-  // Check consistency
-  PetscBool isSimplexMesh = PETSC_TRUE;
-  if ((data.cellDim == 2 && data.numCorners[0] == 4) ||
-      (data.cellDim == 3 && data.numCorners[0] == 8)) {
-    isSimplexMesh = PETSC_FALSE;
-  } // if
-  err = DMPlexCheckSymmetry(dmMesh);CPPUNIT_ASSERT(!err);
-  err = DMPlexCheckSkeleton(dmMesh, isSimplexMesh);CPPUNIT_ASSERT(!err);
-
   // Check vertices
   topology::Stratum verticesStratum(dmMesh, topology::Stratum::DEPTH, 0);
   const PetscInt vStart = verticesStratum.begin();
@@ -827,11 +818,6 @@ pylith::faults::TestFaultCohesive::_testAdjustTopology(Fault* faultA,
   faultA->label("faultA");
   faultA->adjustTopology(&mesh, &firstFaultVertex, &firstLagrangeVertex, &firstFaultCell);
 
-  // Check consistency of original mesh.
-  dmMesh = mesh.dmMesh();CPPUNIT_ASSERT(dmMesh);
-  err = DMPlexCheckSymmetry(dmMesh);CPPUNIT_ASSERT(!err);
-  err = DMPlexCheckSkeleton(dmMesh, isSimplexMesh);CPPUNIT_ASSERT(!err);
-
   faultB->id(2);
   faultB->label("faultB");
   faultB->adjustTopology(&mesh, &firstFaultVertex, &firstLagrangeVertex, &firstFaultCell);
@@ -841,11 +827,8 @@ pylith::faults::TestFaultCohesive::_testAdjustTopology(Fault* faultA,
   PetscViewerPopFormat(PETSC_VIEWER_STDOUT_WORLD);
 #endif
 
-  // Check consistency of mesh after adjusting topology.
   CPPUNIT_ASSERT_EQUAL(data.cellDim, mesh.dimension());
   dmMesh = mesh.dmMesh();CPPUNIT_ASSERT(dmMesh);  
-  err = DMPlexCheckSymmetry(dmMesh);CPPUNIT_ASSERT(!err);
-  err = DMPlexCheckSkeleton(dmMesh, isSimplexMesh);CPPUNIT_ASSERT(!err);
 
   // Check vertices
   topology::Stratum verticesStratum(dmMesh, topology::Stratum::DEPTH, 0);
diff --git a/unittests/libtests/faults/TestFaultCohesiveDyn.cc b/unittests/libtests/faults/TestFaultCohesiveDyn.cc
index 6ca49ef..db97d5a 100644
--- a/unittests/libtests/faults/TestFaultCohesiveDyn.cc
+++ b/unittests/libtests/faults/TestFaultCohesiveDyn.cc
@@ -159,22 +159,11 @@ pylith::faults::TestFaultCohesiveDyn::testInitialize(void)
   topology::SolutionFields fields(mesh);
   _initialize(&mesh, &fault, &fields);
 
-  // Check fault mesh consistency
-  PetscDM dmMesh = fault._faultMesh->dmMesh();CPPUNIT_ASSERT(dmMesh);
-  PetscBool isSimplexMesh = PETSC_TRUE;
-  if ((_data->cellDim == 2 && _data->numBasis == 4) ||
-      (_data->cellDim == 3 && _data->numBasis == 8)) {
-    isSimplexMesh = PETSC_FALSE;
-  } // if
-  err = DMPlexCheckSymmetry(dmMesh);CPPUNIT_ASSERT(!err);
-  if (_data->cellDim > 1) {
-    err = DMPlexCheckSkeleton(dmMesh, isSimplexMesh);CPPUNIT_ASSERT(!err);
-  } // if
-  
   topology::SubMeshIS subpointIS(*fault._faultMesh);
   const PetscInt numPoints = subpointIS.size();
   const PetscInt* points = subpointIS.points();CPPUNIT_ASSERT(points);
 
+  PetscDM dmMesh = fault._faultMesh->dmMesh();CPPUNIT_ASSERT(dmMesh);
   topology::Stratum verticesStratum(dmMesh, topology::Stratum::DEPTH, 0);
   const PetscInt vStart = verticesStratum.begin();
   const PetscInt vEnd = verticesStratum.end();
diff --git a/unittests/libtests/faults/TestFaultCohesiveKin.cc b/unittests/libtests/faults/TestFaultCohesiveKin.cc
index 3a313c7..f021e68 100644
--- a/unittests/libtests/faults/TestFaultCohesiveKin.cc
+++ b/unittests/libtests/faults/TestFaultCohesiveKin.cc
@@ -168,22 +168,11 @@ pylith::faults::TestFaultCohesiveKin::testInitialize(void)
   CPPUNIT_ASSERT_EQUAL(_data->numFaultVertices, fault.numVertices());
   CPPUNIT_ASSERT_EQUAL(_data->numCohesiveCells, fault.numCells());
 
-  // Check fault mesh consistency
-  PetscDM dmMesh = fault._faultMesh->dmMesh();CPPUNIT_ASSERT(dmMesh);
-  PetscBool isSimplexMesh = PETSC_TRUE;
-  if ((_data->cellDim == 2 && _data->numBasis == 4) ||
-      (_data->cellDim == 3 && _data->numBasis == 8)) {
-    isSimplexMesh = PETSC_FALSE;
-  } // if
-  err = DMPlexCheckSymmetry(dmMesh);CPPUNIT_ASSERT(!err);
-  if (_data->cellDim > 1) {
-    err = DMPlexCheckSkeleton(dmMesh, isSimplexMesh);CPPUNIT_ASSERT(!err);
-  } // if
-  
   topology::SubMeshIS subpointIS(*fault._faultMesh);
   const PetscInt numPoints = subpointIS.size();
   const PetscInt* points = subpointIS.points();CPPUNIT_ASSERT(points);
 
+  PetscDM dmMesh = fault._faultMesh->dmMesh();CPPUNIT_ASSERT(dmMesh);
   topology::Stratum verticesStratum(dmMesh, topology::Stratum::DEPTH, 0);
   const PetscInt vStart = verticesStratum.begin();
   const PetscInt vEnd = verticesStratum.end();
diff --git a/unittests/libtests/topology/TestRefineUniform.cc b/unittests/libtests/topology/TestRefineUniform.cc
index a5f87d6..571dbb0 100644
--- a/unittests/libtests/topology/TestRefineUniform.cc
+++ b/unittests/libtests/topology/TestRefineUniform.cc
@@ -242,11 +242,6 @@ pylith::topology::TestRefineUniform::_testRefine(const MeshDataCohesive& data,
   CPPUNIT_ASSERT_EQUAL(data.cellDim, newMesh.dimension());
 
   const PetscDM& dmMesh = newMesh.dmMesh();CPPUNIT_ASSERT(dmMesh);
-  PetscErrorCode err;
-
-  // Check consistency
-  err = DMPlexCheckSymmetry(dmMesh);CPPUNIT_ASSERT(!err);
-  err = DMPlexCheckSkeleton(dmMesh, isSimplexMesh ? PETSC_TRUE : PETSC_FALSE);CPPUNIT_ASSERT(!err);
 
   // Check vertices
   topology::Stratum verticesStratum(dmMesh, topology::Stratum::DEPTH, 0);
@@ -267,6 +262,7 @@ pylith::topology::TestRefineUniform::_testRefine(const MeshDataCohesive& data,
   const PetscInt numCells = cellsStratum.size();
 
   CPPUNIT_ASSERT_EQUAL(data.numCells+data.numCellsCohesive, numCells);
+  PetscErrorCode err;
   // Normal cells
   for(PetscInt c = cStart, index = 0; c < data.numCells; ++c) {
     PetscInt *closure = PETSC_NULL;



More information about the CIG-COMMITS mailing list