[cig-commits] [commit] knepley/upgrade-petsc-interface: Remove Matt's temporary code. Add try/catch/throw for proper memory cleanup. (6f6cd6e)

cig_noreply at geodynamics.org cig_noreply at geodynamics.org
Mon Mar 3 14:53:11 PST 2014


Repository : ssh://geoshell/pylith

On branch  : knepley/upgrade-petsc-interface
Link       : https://github.com/geodynamics/pylith/compare/f40b3d3d5c1975b354d5915ccda6358ce5cd0dcd...896a7cf29dd1b4577c562427c001a8ae224e7eae

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

commit 6f6cd6e91924130fa110fec14ceedc46412909b6
Author: Brad Aagaard <baagaard at usgs.gov>
Date:   Mon Mar 3 13:10:59 2014 -0800

    Remove Matt's temporary code. Add try/catch/throw for proper memory cleanup.


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

6f6cd6e91924130fa110fec14ceedc46412909b6
 libsrc/pylith/faults/FaultCohesiveLagrange.cc | 79 +++++++++++++--------------
 libsrc/pylith/feassemble/CellGeometry.cc      |  2 +-
 2 files changed, 40 insertions(+), 41 deletions(-)

diff --git a/libsrc/pylith/faults/FaultCohesiveLagrange.cc b/libsrc/pylith/faults/FaultCohesiveLagrange.cc
index bca5694..4b79c59 100644
--- a/libsrc/pylith/faults/FaultCohesiveLagrange.cc
+++ b/libsrc/pylith/faults/FaultCohesiveLagrange.cc
@@ -1366,52 +1366,51 @@ pylith::faults::FaultCohesiveLagrange::_calcOrientation(const PylithScalar upDir
   // and summing across processors (complete the section) just like a
   // normal FE integration.
 
-  for(PetscInt c = cStart; c < cEnd; ++c) {
-    PetscInt *closure = NULL;
-    PetscInt closureSize, q = 0;
-
-    // Get orientations at fault cell's vertices.
-    coordsVisitor.getClosure(&coordsCell, c);
-
-    PetscErrorCode err = DMPlexGetTransitiveClosure(faultDMMesh, c, PETSC_TRUE, &closureSize, &closure);PYLITH_CHECK_ERROR(err);
-
-#define CHECKING_ORIENTATION
-#ifdef CHECKING_ORIENTATION
-    PetscInt *cl = new PetscInt[closureSize*2];
-    for(PetscInt p = 0; p < closureSize*2; ++p) {cl[p] = closure[p];}
-    err = DMPlexRestoreTransitiveClosure(faultDMMesh, c, PETSC_TRUE, &closureSize, &closure);PYLITH_CHECK_ERROR(err);
-    closure = cl;
-#endif
-    // Filter out non-vertices
-    for(PetscInt p = 0; p < closureSize*2; p += 2) {
-      if ((closure[p] >= vStart) && (closure[p] < vEnd)) {
-        closure[q*2]   = closure[p];
-        closure[q*2+1] = closure[p+1];
-        ++q;
-      } // if
-    } // for
-    closureSize = q;
+  PetscInt *closure = NULL;
+  PetscInt closureSize = 0;
+  PetscInt cell;
+  try {
+    for(cell = cStart; cell < cEnd; ++cell) {
+      
+      // Get orientations at fault cell's vertices.
+      coordsVisitor.getClosure(&coordsCell, cell);
+      
+      PetscErrorCode err = DMPlexGetTransitiveClosure(faultDMMesh, cell, PETSC_TRUE, &closureSize, &closure);PYLITH_CHECK_ERROR(err);
+      
+      // Filter out non-vertices
+      PetscInt numVertices = 0;
+      for(PetscInt p = 0; p < closureSize*2; p += 2) {
+	if ((closure[p] >= vStart) && (closure[p] < vEnd)) {
+	  closure[numVertices*2]   = closure[p];
+	  closure[numVertices*2+1] = closure[p+1];
+	  ++numVertices;
+	} // if
+      } // for
       
-    for(PetscInt v = 0; v < closureSize; ++v) {
-      // Compute Jacobian and determinant of Jacobian at vertex
-      cellGeometry.jacobian(&jacobian, &jacobianDet, &coordsCell[0], numBasis, spaceDim, &verticesRef[v*cohesiveDim], cohesiveDim);
+      for(PetscInt v = 0; v < numVertices; ++v) {
+	// Compute Jacobian and determinant of Jacobian at vertex
+	cellGeometry.jacobian(&jacobian, &jacobianDet, &coordsCell[0], numBasis, spaceDim, &verticesRef[v*cohesiveDim], cohesiveDim);
 	
-      // Compute orientation
-      cellGeometry.orientation(&orientationVertex, jacobian, jacobianDet, up);
+	// Compute orientation
+	cellGeometry.orientation(&orientationVertex, jacobian, jacobianDet, up);
 	
-      // Update orientation
-      const PetscInt ooff = orientationVisitor.sectionOffset(closure[v*2]);
+	// Update orientation
+	const PetscInt ooff = orientationVisitor.sectionOffset(closure[v*2]);
 	
-      for(PetscInt d = 0; d < orientationSize; ++d) {
-        orientationArray[ooff+d] += orientationVertex[d];
+	for(PetscInt d = 0; d < orientationSize; ++d) {
+	  orientationArray[ooff+d] += orientationVertex[d];
+	} // for
       } // for
+      err = DMPlexRestoreTransitiveClosure(faultDMMesh, cell, PETSC_TRUE, &closureSize, &closure);PYLITH_CHECK_ERROR(err);
     } // for
-#ifdef CHECKING_ORIENTATION
-    delete [] closure;
-#else
-    err = DMPlexRestoreTransitiveClosure(faultDMMesh, c, PETSC_TRUE, &closureSize, &closure);PYLITH_CHECK_ERROR(err);
-#endif
-  } // for
+  } catch (const std::exception& err) {
+    if (closure) {
+      DMPlexRestoreTransitiveClosure(faultDMMesh, cell, PETSC_TRUE, &closureSize, &closure);
+    } // if
+    throw;
+  } catch (...) {
+    throw;
+  } // try/catch
   orientationVisitor.clear();
 
   //orientation.view("ORIENTATION BEFORE COMPLETE"); // DEBUGGING
diff --git a/libsrc/pylith/feassemble/CellGeometry.cc b/libsrc/pylith/feassemble/CellGeometry.cc
index db8c336..49c8eb2 100644
--- a/libsrc/pylith/feassemble/CellGeometry.cc
+++ b/libsrc/pylith/feassemble/CellGeometry.cc
@@ -228,7 +228,7 @@ pylith::feassemble::CellGeometry::_orient2D(scalar_array* orientation,
 	<< upDir[0] << ", " << upDir[1] << ", " << upDir[2] << ") "
 	<< " cannot be parallel to the face normal ("
 	<< r0 << ", " << r1 << ", " << r2 << ").\n"
-	<< "Adjust the up_dir parameter.";
+	<< "If the face is horizontal, adjust the up_dir parameter.";
     throw std::runtime_error(msg.str());
   } // if
   p0 /= mag;



More information about the CIG-COMMITS mailing list