[cig-commits] r22187 - in short/3D/PyLith/trunk/libsrc/pylith: faults topology

knepley at geodynamics.org knepley at geodynamics.org
Fri Jun 7 16:03:23 PDT 2013


Author: knepley
Date: 2013-06-07 16:03:23 -0700 (Fri, 07 Jun 2013)
New Revision: 22187

Modified:
   short/3D/PyLith/trunk/libsrc/pylith/faults/CohesiveTopology.cc
   short/3D/PyLith/trunk/libsrc/pylith/faults/FaultCohesive.cc
   short/3D/PyLith/trunk/libsrc/pylith/topology/Stratum.icc
Log:
Fixes for empty meshes in parallel

Modified: short/3D/PyLith/trunk/libsrc/pylith/faults/CohesiveTopology.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/pylith/faults/CohesiveTopology.cc	2013-06-07 22:11:17 UTC (rev 22186)
+++ short/3D/PyLith/trunk/libsrc/pylith/faults/CohesiveTopology.cc	2013-06-07 23:03:23 UTC (rev 22187)
@@ -38,7 +38,6 @@
   PYLITH_METHOD_BEGIN;
 
   assert(faultMesh);
-  assert(groupField);
   PetscErrorCode err;
 
   faultMesh->coordsys(mesh.coordsys());
@@ -52,9 +51,9 @@
   if (depth == dim) {
     PetscDM subdm = NULL;
     PetscDMLabel label = NULL;
-    const char *groupName = NULL, *labelName = "boundary";
+    const char *groupName = "", *labelName = "boundary";
 
-    err = DMLabelGetName(groupField, &groupName);PYLITH_CHECK_ERROR(err);
+    if (groupField) {err = DMLabelGetName(groupField, &groupName);PYLITH_CHECK_ERROR(err);}
     err = DMPlexCreateSubmesh(dmMesh, groupName, 1, &subdm);PYLITH_CHECK_ERROR(err);
     err = DMPlexCreateLabel(subdm, labelName);PYLITH_CHECK_ERROR(err);
     err = DMPlexGetLabel(subdm, labelName, &label);PYLITH_CHECK_ERROR(err);
@@ -67,10 +66,10 @@
     PetscDMLabel subpointMapTmp = NULL, subpointMap = NULL;
     PetscIS pointIS = NULL;
     const PetscInt *points = NULL;
-    PetscInt depth, newDepth, h, numPoints, p;
-    const char *groupName = NULL;
+    PetscInt depth, newDepth, h, numPoints = 0, p;
+    const char *groupName = "";
 
-    err = DMLabelGetName(groupField, &groupName);PYLITH_CHECK_ERROR(err);
+    if (groupField) {err = DMLabelGetName(groupField, &groupName);PYLITH_CHECK_ERROR(err);}
     err = DMPlexCreateSubmesh(dmMesh, groupName, 1, &faultDMMeshTmp);PYLITH_CHECK_ERROR(err);
     err = DMPlexInterpolate(faultDMMeshTmp, &faultDMMesh);PYLITH_CHECK_ERROR(err);
     err = DMPlexGetVTKCellHeight(faultDMMeshTmp, &h);PYLITH_CHECK_ERROR(err);
@@ -80,22 +79,26 @@
     err = DMPlexGetSubpointMap(faultDMMeshTmp, &subpointMapTmp);PYLITH_CHECK_ERROR(err);
     err = DMLabelCreate("subpoint_map", &subpointMap);PYLITH_CHECK_ERROR(err);
     err = DMLabelGetStratumIS(subpointMapTmp, 0, &pointIS);PYLITH_CHECK_ERROR(err);
-    err = ISGetLocalSize(pointIS, &numPoints);PYLITH_CHECK_ERROR(err);
-    err = ISGetIndices(pointIS, &points);PYLITH_CHECK_ERROR(err);
+    if (pointIS) {
+      err = ISGetLocalSize(pointIS, &numPoints);PYLITH_CHECK_ERROR(err);
+      err = ISGetIndices(pointIS, &points);PYLITH_CHECK_ERROR(err);
+    }
     for (p = 0; p < numPoints; ++p) {
       err = DMLabelSetValue(subpointMap, points[p], 0);PYLITH_CHECK_ERROR(err);
     }
-    err = ISRestoreIndices(pointIS, &points);PYLITH_CHECK_ERROR(err);
+    if (pointIS) {err = ISRestoreIndices(pointIS, &points);PYLITH_CHECK_ERROR(err);}
     err = ISDestroy(&pointIS);PYLITH_CHECK_ERROR(err);
     err = DMPlexGetDepth(faultDMMeshTmp, &depth);PYLITH_CHECK_ERROR(err);
     err = DMPlexGetDepth(faultDMMesh, &newDepth);PYLITH_CHECK_ERROR(err);
     err = DMLabelGetStratumIS(subpointMapTmp, depth, &pointIS);PYLITH_CHECK_ERROR(err);
-    err = ISGetLocalSize(pointIS, &numPoints);PYLITH_CHECK_ERROR(err);
-    err = ISGetIndices(pointIS, &points);PYLITH_CHECK_ERROR(err);
+    if (pointIS) {
+      err = ISGetLocalSize(pointIS, &numPoints);PYLITH_CHECK_ERROR(err);
+      err = ISGetIndices(pointIS, &points);PYLITH_CHECK_ERROR(err);
+    }
     for (p = 0; p < numPoints; ++p) {
       err = DMLabelSetValue(subpointMap, points[p], newDepth);PYLITH_CHECK_ERROR(err);
     }
-    err = ISRestoreIndices(pointIS, &points);PYLITH_CHECK_ERROR(err);
+    if (pointIS) {err = ISRestoreIndices(pointIS, &points);PYLITH_CHECK_ERROR(err);}
     err = ISDestroy(&pointIS);PYLITH_CHECK_ERROR(err);
     err = DMPlexSetSubpointMap(faultDMMesh, subpointMap);PYLITH_CHECK_ERROR(err);
     err = DMLabelDestroy(&subpointMap);PYLITH_CHECK_ERROR(err);
@@ -157,14 +160,13 @@
   PYLITH_METHOD_BEGIN;
 
   assert(mesh);
-  assert(groupField);
 
-  const char    *groupName;
+  const char    *groupName = NULL;
   PetscMPIInt    rank;
   PetscErrorCode err;
 
   err = MPI_Comm_rank(mesh->comm(), &rank);PYLITH_CHECK_ERROR(err);
-  err = DMLabelGetName(groupField, &groupName);PYLITH_CHECK_ERROR(err);
+  if (groupField) {err = DMLabelGetName(groupField, &groupName);PYLITH_CHECK_ERROR(err);}
 
   /* DMPlex */
   DM complexMesh = mesh->dmMesh();
@@ -200,13 +202,15 @@
   }
 
   // Add new shadow vertices and possibly Lagrange multipler vertices
-  IS              fVertexIS;
-  const PetscInt *fVerticesDM;
-  PetscInt        numFaultVerticesDM, vStart, vEnd;
+  IS              fVertexIS   = NULL;
+  const PetscInt *fVerticesDM = NULL;
+  PetscInt        numFaultVerticesDM = 0, vStart, vEnd;
 
-  err = DMLabelGetStratumIS(groupField, 1, &fVertexIS);PYLITH_CHECK_ERROR(err);
-  err = ISGetLocalSize(fVertexIS, &numFaultVerticesDM);PYLITH_CHECK_ERROR(err);
-  err = ISGetIndices(fVertexIS, &fVerticesDM);PYLITH_CHECK_ERROR(err);
+  if (groupField) {
+    err = DMLabelGetStratumIS(groupField, 1, &fVertexIS);PYLITH_CHECK_ERROR(err);
+    err = ISGetLocalSize(fVertexIS, &numFaultVerticesDM);PYLITH_CHECK_ERROR(err);
+    err = ISGetIndices(fVertexIS, &fVerticesDM);PYLITH_CHECK_ERROR(err);
+  }
   err = DMPlexGetDepthStratum(complexMesh, 0, &vStart, &vEnd);PYLITH_CHECK_ERROR(err);
   std::map<point_type,point_type> vertexRenumber;
   std::map<point_type,point_type> vertexLagrangeRenumber;
@@ -366,10 +370,10 @@
   TopologyOps::PointSet replaceVerticesDM;
   PetscInt       *cohesiveCone;
   IS              subpointIS;
-  const PetscInt *subpointMap;
+  const PetscInt *subpointMap = NULL;
 
   err = DMPlexCreateSubpointIS(faultDMMesh, &subpointIS);PYLITH_CHECK_ERROR(err);
-  err = ISGetIndices(subpointIS, &subpointMap);PYLITH_CHECK_ERROR(err);
+  if (subpointIS) {err = ISGetIndices(subpointIS, &subpointMap);PYLITH_CHECK_ERROR(err);}
   err = PetscMalloc3(faceSizeDM,PetscInt,&origVerticesDM,faceSizeDM,PetscInt,&faceVerticesDM,faceSizeDM*3,PetscInt,&cohesiveCone);PYLITH_CHECK_ERROR(err);
   for (PetscInt faceDM = ffStart; faceDM < ffEnd; ++faceDM, ++firstFaultCell, ++firstFaultCellDM) {
     if (debug) std::cout << "Considering fault face " << faceDM << std::endl;
@@ -476,13 +480,13 @@
   assert(faultBoundary);
   err = DMPlexGetDepthStratum(faultBoundary, 0, &bfvStart, &bfvEnd);PYLITH_CHECK_ERROR(err);
   err = DMPlexCreateSubpointIS(faultBoundary, &bdSubpointIS);PYLITH_CHECK_ERROR(err);
-  err = ISGetIndices(bdSubpointIS, &points);PYLITH_CHECK_ERROR(err);
+  if (bdSubpointIS) {err = ISGetIndices(bdSubpointIS, &points);PYLITH_CHECK_ERROR(err);}
   for (PetscInt v = bfvStart; v < bfvEnd; ++v) {
     faultBdVertices.insert(subpointMap[points[v]]);
   }
-  err = ISRestoreIndices(bdSubpointIS, &points);PYLITH_CHECK_ERROR(err);
+  if (bdSubpointIS) {err = ISRestoreIndices(bdSubpointIS, &points);PYLITH_CHECK_ERROR(err);}
   err = ISDestroy(&bdSubpointIS);PYLITH_CHECK_ERROR(err);
-  err = ISRestoreIndices(subpointIS, &subpointMap);PYLITH_CHECK_ERROR(err);
+  if (subpointIS) {err = ISRestoreIndices(subpointIS, &subpointMap);PYLITH_CHECK_ERROR(err);}
   err = ISDestroy(&subpointIS);PYLITH_CHECK_ERROR(err);
   // Classify cells by side of the fault
   TopologyOps::PointSet::const_iterator rVerticesEnd = replaceVerticesDM.end();
@@ -538,12 +542,12 @@
   PetscSection coordSection, newCoordSection;
   Vec          coordinatesVec, newCoordinatesVec;
   PetscScalar *coords, *newCoords;
-  PetscInt     numComp, coordSize;
+  PetscInt     numComp = 0, coordSize = 0;
  
   err = DMPlexGetCoordinateSection(complexMesh, &coordSection);PYLITH_CHECK_ERROR(err);
   err = DMPlexGetCoordinateSection(newMesh,     &newCoordSection);PYLITH_CHECK_ERROR(err);
   err = PetscSectionSetNumFields(newCoordSection, 1);PYLITH_CHECK_ERROR(err);
-  err = PetscSectionGetDof(coordSection, vStart, &numComp);PYLITH_CHECK_ERROR(err);
+  if (vEnd > vStart) {err = PetscSectionGetDof(coordSection, vStart, &numComp);PYLITH_CHECK_ERROR(err);}
   err = PetscSectionSetFieldComponents(newCoordSection, 0, numComp);PYLITH_CHECK_ERROR(err);
   err = DMGetCoordinatesLocal(complexMesh, &coordinatesVec);PYLITH_CHECK_ERROR(err);
   err = PetscSectionSetChart(newCoordSection, vStart+extraCells, vEnd+extraCells+extraVertices);PYLITH_CHECK_ERROR(err);
@@ -567,7 +571,6 @@
       err = PetscSectionSetFieldDof(newCoordSection, vertexLagrangeRenumberDM[vnew], 0, dof);PYLITH_CHECK_ERROR(err);
     }
   } // for
-
   err = PetscSectionSetUp(newCoordSection);PYLITH_CHECK_ERROR(err);
   err = PetscSectionGetStorageSize(newCoordSection, &coordSize);PYLITH_CHECK_ERROR(err);
   err = VecCreate(mesh->comm(), &newCoordinatesVec);PYLITH_CHECK_ERROR(err);
@@ -610,7 +613,7 @@
   err = DMSetCoordinatesLocal(newMesh, newCoordinatesVec);PYLITH_CHECK_ERROR(err);
   err = VecDestroy(&newCoordinatesVec);PYLITH_CHECK_ERROR(err);
 
-  err = ISRestoreIndices(fVertexIS, &fVerticesDM);PYLITH_CHECK_ERROR(err);
+  if (fVertexIS) {err = ISRestoreIndices(fVertexIS, &fVerticesDM);PYLITH_CHECK_ERROR(err);}
   err = ISDestroy(&fVertexIS);PYLITH_CHECK_ERROR(err);
 
   PetscReal lengthScale = 1.0;

Modified: short/3D/PyLith/trunk/libsrc/pylith/faults/FaultCohesive.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/pylith/faults/FaultCohesive.cc	2013-06-07 22:11:17 UTC (rev 22186)
+++ short/3D/PyLith/trunk/libsrc/pylith/faults/FaultCohesive.cc	2013-06-07 23:03:23 UTC (rev 22187)
@@ -81,11 +81,14 @@
     // Get group of vertices associated with fault
     PetscDM dmMesh = mesh.dmMesh();assert(dmMesh);
     PetscBool hasLabel = PETSC_FALSE;
+    PetscMPIInt rank;
     PetscErrorCode err;
 
     assert(std::string("") != label());
+    // We do not have labels on all ranks until after distribution
+    err = MPI_Comm_rank(PetscObjectComm((PetscObject) dmMesh), &rank);PYLITH_CHECK_ERROR(err);
     err = DMPlexHasLabel(dmMesh, label(), &hasLabel);PYLITH_CHECK_ERROR(err);
-    if (!hasLabel) {
+    if (!hasLabel && !rank) {
       std::ostringstream msg;
       msg << "Mesh missing group of vertices '" << label()
           << "' for fault interface condition.";
@@ -126,9 +129,12 @@
 
       PetscDMLabel groupField;
       PetscBool hasLabel;
+      PetscMPIInt rank;
       PetscErrorCode err;
+      // We do not have labels on all ranks until after distribution
+      err = MPI_Comm_rank(PetscObjectComm((PetscObject) dmMesh), &rank);PYLITH_CHECK_ERROR(err);
       err = DMPlexHasLabel(dmMesh, charlabel, &hasLabel);PYLITH_CHECK_ERROR(err);
-      if (!hasLabel) {
+      if (!hasLabel && !rank) {
         std::ostringstream msg;
         msg << "Mesh missing group of vertices '" << label()
             << "' for fault interface condition.";

Modified: short/3D/PyLith/trunk/libsrc/pylith/topology/Stratum.icc
===================================================================
--- short/3D/PyLith/trunk/libsrc/pylith/topology/Stratum.icc	2013-06-07 22:11:17 UTC (rev 22186)
+++ short/3D/PyLith/trunk/libsrc/pylith/topology/Stratum.icc	2013-06-07 23:03:23 UTC (rev 22187)
@@ -93,7 +93,7 @@
   PetscErrorCode err;
   err = DMPlexGetStratumIS(dmMesh, label, id, &_indexSet);PYLITH_CHECK_ERROR(err);assert(_indexSet);
   err = ISGetSize(_indexSet, &_size);PYLITH_CHECK_ERROR(err);assert(_size >= 0);
-  err = ISGetIndices(_indexSet, &_points);PYLITH_CHECK_ERROR(err);
+  err = ISGetIndices(_indexSet, &_points);PYLITH_CHECK_ERROR(err);assert(!_size || _points);
 } // constructor
 
 // ----------------------------------------------------------------------



More information about the CIG-COMMITS mailing list