[cig-commits] [commit] knepley/fix-faults-parallel: Fix some small bugs in settings constraints in fault section. (45b56d3)

cig_noreply at geodynamics.org cig_noreply at geodynamics.org
Tue May 27 16:01:06 PDT 2014


Repository : https://github.com/geodynamics/pylith

On branch  : knepley/fix-faults-parallel
Link       : https://github.com/geodynamics/pylith/compare/a2e43ea17cb9ca3e865e9dd6fa00f622e062fcd2...45b56d3e34a63ee3945e4673470bcd39adcb1f6b

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

commit 45b56d3e34a63ee3945e4673470bcd39adcb1f6b
Author: Brad Aagaard <baagaard at usgs.gov>
Date:   Tue May 27 15:59:26 2014 -0700

    Fix some small bugs in settings constraints in fault section.


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

45b56d3e34a63ee3945e4673470bcd39adcb1f6b
 libsrc/pylith/faults/FaultCohesiveLagrange.cc | 55 ++++++++++++++-------------
 1 file changed, 29 insertions(+), 26 deletions(-)

diff --git a/libsrc/pylith/faults/FaultCohesiveLagrange.cc b/libsrc/pylith/faults/FaultCohesiveLagrange.cc
index a2f0685..3d6ee76 100644
--- a/libsrc/pylith/faults/FaultCohesiveLagrange.cc
+++ b/libsrc/pylith/faults/FaultCohesiveLagrange.cc
@@ -116,54 +116,57 @@ pylith::faults::FaultCohesiveLagrange::initialize(const topology::Mesh& mesh,
   delete _fields; _fields = new topology::Fields(*_faultMesh);assert(_fields);
 
   // Allocate dispRel field
+  const int spaceDim = cs->spaceDim();
   _fields->add("relative disp", "relative_disp");
   topology::Field& dispRel = _fields->get("relative disp");
-  dispRel.newSection(topology::FieldBase::VERTICES_FIELD, cs->spaceDim()); // :TODO: Update?
-  if (edge()) {
-    PetscDMLabel    label;
-    PetscIS         vertexIS;
-    const PetscInt *vertices;
-    PetscInt        n, i;
-    PetscErrorCode  err;
+  dispRel.newSection(topology::FieldBase::VERTICES_FIELD, spaceDim); // :TODO: Update?
+  if (strlen(edge()) > 0) {
+    PetscDMLabel label = NULL;
+    PetscIS vertexIS = NULL;
+    const PetscInt* vertices = NULL;
+    PetscInt numVertices;
+    PetscErrorCode err;
 
     err = DMPlexGetLabel(mesh.dmMesh(), edge(), &label);PYLITH_CHECK_ERROR(err);
     err = DMLabelGetStratumIS(label, 1, &vertexIS);PYLITH_CHECK_ERROR(err);
-    err = ISGetLocalSize(vertexIS, &n);PYLITH_CHECK_ERROR(err);
+    err = ISGetLocalSize(vertexIS, &numVertices);PYLITH_CHECK_ERROR(err);
     err = ISGetIndices(vertexIS, &vertices);PYLITH_CHECK_ERROR(err);
-    for (i = 0; i < n; ++i) {
+    for (int i = 0; i < numVertices; ++i) {
       PetscInt v_fault;
 
       err = PetscFindInt(vertices[i], numPoints, points, &v_fault);PYLITH_CHECK_ERROR(err);
-      err = PetscSectionSetConstraintDof(dispRel.petscSection(), v_fault, cs->spaceDim());PYLITH_CHECK_ERROR(err);
-    }
+      err = PetscSectionSetConstraintDof(dispRel.petscSection(), v_fault, spaceDim);PYLITH_CHECK_ERROR(err);
+    } // for
     err = ISRestoreIndices(vertexIS, &vertices);PYLITH_CHECK_ERROR(err);
     err = ISDestroy(&vertexIS);PYLITH_CHECK_ERROR(err);
   }
   dispRel.allocate();
-  if (edge()) {
-    PetscDMLabel    label;
-    PetscIS         vertexIS;
-    const PetscInt *vertices;
-    PetscInt       *ind, n, i;
-    PetscErrorCode  err;
-
-    PetscMalloc1(cs->spaceDim(),&ind);
-    for (i = 0; i < cs->spaceDim(); ++i) ind[i] = i;
+  if (strlen(edge()) > 0) {
+    PetscDMLabel label = NULL;
+    PetscIS vertexIS = NULL;
+    const PetscInt *vertices = NULL;
+    PetscInt numVertices;
+    PetscErrorCode err;
+
+    PetscInt* ind = (spaceDim > 0) ? new PetscInt[spaceDim] : 0;
+    for (int i = 0; i < spaceDim; ++i) { 
+      ind[i] = i;
+    } // for
 
     err = DMPlexGetLabel(mesh.dmMesh(), edge(), &label);PYLITH_CHECK_ERROR(err);
     err = DMLabelGetStratumIS(label, 1, &vertexIS);PYLITH_CHECK_ERROR(err);
-    err = ISGetLocalSize(vertexIS, &n);PYLITH_CHECK_ERROR(err);
+    err = ISGetLocalSize(vertexIS, &numVertices);PYLITH_CHECK_ERROR(err);
     err = ISGetIndices(vertexIS, &vertices);PYLITH_CHECK_ERROR(err);
-    for (i = 0; i < n; ++i) {
+    for (int i = 0; i < numVertices; ++i) {
       PetscInt v_fault;
 
       err = PetscFindInt(vertices[i], numPoints, points, &v_fault);PYLITH_CHECK_ERROR(err);
-      err = PetscSectionSetConstraintIndices(dispRel.petscSection(), points[i], ind);PYLITH_CHECK_ERROR(err);
-    }
+      err = PetscSectionSetConstraintIndices(dispRel.petscSection(), v_fault, ind);PYLITH_CHECK_ERROR(err);
+    } // for
     err = ISRestoreIndices(vertexIS, &vertices);PYLITH_CHECK_ERROR(err);
     err = ISDestroy(&vertexIS);PYLITH_CHECK_ERROR(err);
-    err = PetscFree(ind);PYLITH_CHECK_ERROR(err);
-  }
+    delete[] ind; ind = 0;
+  } // for
   dispRel.vectorFieldType(topology::FieldBase::VECTOR);
   dispRel.scale(_normalizer->lengthScale());
 



More information about the CIG-COMMITS mailing list