[cig-commits] r21556 - short/3D/PyLith/trunk/libsrc/pylith/topology

brad at geodynamics.org brad at geodynamics.org
Mon Mar 18 11:45:37 PDT 2013


Author: brad
Date: 2013-03-18 11:45:37 -0700 (Mon, 18 Mar 2013)
New Revision: 21556

Modified:
   short/3D/PyLith/trunk/libsrc/pylith/topology/Field.cc
   short/3D/PyLith/trunk/libsrc/pylith/topology/Field.hh
   short/3D/PyLith/trunk/libsrc/pylith/topology/Field.icc
Log:
Removed visitor related stuff from Field (now in Visitors).

Modified: short/3D/PyLith/trunk/libsrc/pylith/topology/Field.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/pylith/topology/Field.cc	2013-03-18 14:01:30 UTC (rev 21555)
+++ short/3D/PyLith/trunk/libsrc/pylith/topology/Field.cc	2013-03-18 18:45:37 UTC (rev 21556)
@@ -41,16 +41,16 @@
   _metadata["default"].scale = 1.0;
   _metadata["default"].dimsOkay = false;
   if (mesh.dmMesh()) {
-    DM             dm = mesh.dmMesh();
-    Vec            coordVec;
-    PetscSection   s;
+    PetscDM dm = mesh.dmMesh();
+    PetscVec coordVec = NULL;
+    PetscSection s = NULL;
     PetscErrorCode err;
 
     err = DMPlexClone(dm, &_dm);CHECK_PETSC_ERROR(err);
     err = DMGetCoordinatesLocal(dm, &coordVec);CHECK_PETSC_ERROR(err);
     if (coordVec) {
-      DM           coordDM, newCoordDM;
-      PetscSection coordSection, newCoordSection;
+      PetscDM coordDM=NULL, newCoordDM=NULL;
+      PetscSection coordSection=NULL, newCoordSection=NULL;
 
       err = DMGetCoordinateDM(dm, &coordDM);CHECK_PETSC_ERROR(err);
       err = DMGetCoordinateDM(_dm, &newCoordDM);CHECK_PETSC_ERROR(err);
@@ -62,19 +62,22 @@
     err = PetscSectionCreate(mesh.comm(), &s);CHECK_PETSC_ERROR(err);
     err = DMSetDefaultSection(_dm, s);CHECK_PETSC_ERROR(err);
   } else {
-    _dm = PETSC_NULL;
+    _dm = NULL;
   }
-  _globalVec = PETSC_NULL;
-  _localVec  = PETSC_NULL;
+  _globalVec = NULL;
+  _localVec  = NULL;
 } // constructor
 
 // ----------------------------------------------------------------------
 // Constructor with mesh, DM, and metadata
 template<typename mesh_type>
-pylith::topology::Field<mesh_type>::Field(const mesh_type& mesh, DM dm, const Metadata& metadata) :
+pylith::topology::Field<mesh_type>::Field(const mesh_type& mesh,
+					  PetscDM dm,
+					  const Metadata& metadata) :
   _mesh(mesh),
   _dm(dm)
 { // constructor
+  assert(dm);
   PetscErrorCode err;
 
   _metadata["default"] = metadata;
@@ -87,10 +90,16 @@
 // ----------------------------------------------------------------------
 // Constructor with mesh, DM, local data, and metadata
 template<typename mesh_type>
-pylith::topology::Field<mesh_type>::Field(const mesh_type& mesh, DM dm, Vec localVec, const Metadata& metadata) :
+pylith::topology::Field<mesh_type>::Field(const mesh_type& mesh,
+					  PetscDM dm,
+					  PetscVec localVec,
+					  const Metadata& metadata) :
   _mesh(mesh),
   _dm(dm)
 { // constructor
+  assert(dm);
+  assert(localVec);
+
   PetscErrorCode err;
 
   _metadata["default"] = metadata;
@@ -104,15 +113,20 @@
 // ----------------------------------------------------------------------
 // Constructor with field and subfields
 template<typename mesh_type>
-pylith::topology::Field<mesh_type>::Field(const Field& src, const int fields[], int numFields) :
+pylith::topology::Field<mesh_type>::Field(const Field& src,
+					  const int fields[],
+					  int numFields) :
   _mesh(src._mesh)
 { // constructor
-  DM             dm = mesh.dmMesh(), coordDM, newCoordDM;
-  PetscSection   coordSection, newCoordSection;
-  Vec            coordVec;
-  PetscSection   s;
+  PetscDM dm = mesh.dmMesh(), coordDM=NULL, newCoordDM=NULL;
+  PetscSection coordSection=NULL, newCoordSection=NULL;
+  PetscVec coordVec=NULL;
+  PetscSection s=NULL;
   PetscErrorCode err;
 
+  assert(dm);
+  assert(src._dm);
+
   _metadata["default"] = src._metadata["default"];
   err = DMGetDefaultSection(src._dm, &s);CHECK_PETSC_ERROR(err);
   for(PetscInt f = 0; f < numFields; ++f) {
@@ -120,8 +134,8 @@
 
     err = PetscSectionGetFieldName(s, fields[f], &name);CHECK_PETSC_ERROR(err);
     _metadata[name] = src._metadata[name];
-  }
-  err = DMCreateSubDM(dm, numFields, fields, PETSC_NULL, &_dm);CHECK_PETSC_ERROR(err);
+  } // for
+  err = DMCreateSubDM(dm, numFields, fields, NULL, &_dm);CHECK_PETSC_ERROR(err);
   err = DMGetCoordinatesLocal(dm, &coordVec);CHECK_PETSC_ERROR(err);
   if (coordVec) {
     err = DMGetCoordinateDM(dm, &coordDM);CHECK_PETSC_ERROR(err);
@@ -130,9 +144,9 @@
     err = PetscSectionClone(coordSection, &newCoordSection);CHECK_PETSC_ERROR(err);
     err = DMSetDefaultSection(newCoordDM, newCoordSection);CHECK_PETSC_ERROR(err);
     err = DMSetCoordinatesLocal(_dm, coordVec);CHECK_PETSC_ERROR(err);
-  }
-  _globalVec = PETSC_NULL;
-  _localVec  = PETSC_NULL;
+  } // if
+  _globalVec = NULL;
+  _localVec  = NULL;
 } // constructor
 
 // ----------------------------------------------------------------------
@@ -160,7 +174,9 @@
     err = DMDestroy(&s_iter->second.dm);CHECK_PETSC_ERROR(err);
     err = VecDestroy(&s_iter->second.vector);CHECK_PETSC_ERROR(err);
 
-    if (s_iter->second.scatter) {err = VecScatterDestroy(&s_iter->second.scatter);CHECK_PETSC_ERROR(err);}
+    if (s_iter->second.scatter) {
+      err = VecScatterDestroy(&s_iter->second.scatter);CHECK_PETSC_ERROR(err);
+    } // if
     err = VecDestroy(&s_iter->second.scatterVec);CHECK_PETSC_ERROR(err);
   } // for
   _scatters.clear();
@@ -207,8 +223,8 @@
 pylith::topology::Field<mesh_type>::chartSize(void) const
 { // chartSize
   assert(_dm);
-  PetscSection   s;
-  PetscInt       pStart, pEnd;
+  PetscSection s = NULL;
+  PetscInt pStart, pEnd;
   PetscErrorCode err;
 
   err = DMGetDefaultSection(_dm, &s);CHECK_PETSC_ERROR(err);
@@ -225,7 +241,7 @@
   PetscInt size = 0;
 
   if (_dm) {
-    PetscSection   s;
+    PetscSection s = NULL;
     PetscErrorCode err;
 
     err = DMGetDefaultSection(_dm, &s);CHECK_PETSC_ERROR(err);
@@ -269,26 +285,26 @@
   logger.stagePush("Field");
   const PetscInt npts = points.size();
   if (npts > 0) {
-    PetscSection s;
-    PetscInt     pointMin = 0, pointMax = 0;
+    PetscSection s = NULL;
+    PetscInt pointMin = 0, pointMax = 0;
 
     for (PetscInt i = 0; i < npts; ++i) {
       pointMin = std::min(pointMin, points[i]);
       pointMax = std::max(pointMax, points[i]);
-    }
+    } // for
     err = DMGetDefaultSection(_dm, &s);CHECK_PETSC_ERROR(err);
-    err = DMSetDefaultGlobalSection(_dm, PETSC_NULL);CHECK_PETSC_ERROR(err);
+    err = DMSetDefaultGlobalSection(_dm, NULL);CHECK_PETSC_ERROR(err);
     err = PetscSectionSetChart(s, pointMin, pointMax+1);CHECK_PETSC_ERROR(err);
     for (PetscInt i = 0; i < npts; ++i) {
       err = PetscSectionSetDof(s, points[i], fiberDim);CHECK_PETSC_ERROR(err);
-    }
+    } // for
   } else { // create empty chart
-    PetscSection s;
+    PetscSection s = NULL;
 
     err = DMGetDefaultSection(_dm, &s);CHECK_PETSC_ERROR(err);
-    err = DMSetDefaultGlobalSection(_dm, PETSC_NULL);CHECK_PETSC_ERROR(err);
+    err = DMSetDefaultGlobalSection(_dm, NULL);CHECK_PETSC_ERROR(err);
     err = PetscSectionSetChart(s, 0, 0);CHECK_PETSC_ERROR(err);
-  }
+  } // if/else
 
   logger.stagePop();
 } // newSection
@@ -316,26 +332,26 @@
   ALE::MemoryLogger& logger = ALE::MemoryLogger::singleton();
   logger.stagePush("Field");
   if (num > 0) {
-    PetscSection s;
-    PetscInt     pointMin = 0, pointMax = 0;
+    PetscSection s = NULL;
+    PetscInt pointMin = 0, pointMax = 0;
 
     for (PetscInt i = 0; i < num; ++i) {
       pointMin = std::min(pointMin, points[i]);
       pointMax = std::max(pointMax, points[i]);
-    }
+    } // for
     err = DMGetDefaultSection(_dm, &s);CHECK_PETSC_ERROR(err);
-    err = DMSetDefaultGlobalSection(_dm, PETSC_NULL);CHECK_PETSC_ERROR(err);
+    err = DMSetDefaultGlobalSection(_dm, NULL);CHECK_PETSC_ERROR(err);
     err = PetscSectionSetChart(s, pointMin, pointMax+1);CHECK_PETSC_ERROR(err);
     for (PetscInt i = 0; i < num; ++i) {
       err = PetscSectionSetDof(s, points[i], fiberDim);CHECK_PETSC_ERROR(err);
-    }
+    } // for
   } else { // create empty chart
-    PetscSection s;
+    PetscSection s = NULL;
 
     err = DMGetDefaultSection(_dm, &s);CHECK_PETSC_ERROR(err);
-    err = DMSetDefaultGlobalSection(_dm, PETSC_NULL);CHECK_PETSC_ERROR(err);
+    err = DMSetDefaultGlobalSection(_dm, NULL);CHECK_PETSC_ERROR(err);
     err = PetscSectionSetChart(s, 0, 0);CHECK_PETSC_ERROR(err);
-  }
+  } // if/else
 
   logger.stagePop();
 } // newSection
@@ -350,8 +366,8 @@
 { // newSection
   // Changing this because cells/vertices are numbered differently in the new scheme
   assert(_dm);
-  PetscSection   s;
-  PetscInt       pStart, pEnd;
+  PetscSection s = NULL;
+  PetscInt pStart, pEnd;
   PetscErrorCode err;
 
   switch(domain) {
@@ -383,11 +399,11 @@
 { // newSection
   // Changing this because cells/vertices are numbered differently in the new scheme
   assert(_dm);
-  PetscSection   s;
+  PetscSection s = NULL;
   PetscErrorCode err;
 
   err = DMGetDefaultSection(_dm, &s);CHECK_PETSC_ERROR(err);
-  err = DMSetDefaultGlobalSection(_dm, PETSC_NULL);CHECK_PETSC_ERROR(err);
+  err = DMSetDefaultGlobalSection(_dm, NULL);CHECK_PETSC_ERROR(err);
   err = PetscSectionSetChart(s, pStart, pEnd);CHECK_PETSC_ERROR(err);
 
   for(PetscInt p = pStart; p < pEnd; ++p) {
@@ -416,13 +432,13 @@
     throw std::runtime_error(msg.str());
   } // if
 
-  PetscSection   srcs, s;
-  PetscInt       pStart, pEnd;
+  PetscSection srcs=NULL, s=NULL;
+  PetscInt pStart, pEnd;
   PetscErrorCode err;
 
   err = DMGetDefaultSection(src._dm, &srcs);CHECK_PETSC_ERROR(err);
   err = DMGetDefaultSection(_dm, &s);CHECK_PETSC_ERROR(err);
-  err = DMSetDefaultGlobalSection(_dm, PETSC_NULL);CHECK_PETSC_ERROR(err);
+  err = DMSetDefaultGlobalSection(_dm, NULL);CHECK_PETSC_ERROR(err);
   err = PetscSectionGetChart(srcs, &pStart, &pEnd);CHECK_PETSC_ERROR(err);
   err = PetscSectionSetChart(s, pStart, pEnd);CHECK_PETSC_ERROR(err);
   for(PetscInt p = pStart; p < pEnd; ++p) {
@@ -449,8 +465,8 @@
   _metadata["default"] = const_cast<Field&>(src)._metadata["default"];
   label(origLabel.c_str());
 
-  PetscSection   section = src.petscSection();
-  PetscSection   newSection;
+  PetscSection section = src.petscSection();
+  PetscSection newSection = NULL;
   PetscErrorCode err;
 
   assert(_dm);
@@ -482,7 +498,7 @@
         sinfo.scatter = s_iter->second.scatter;
         err = PetscObjectReference((PetscObject) sinfo.scatter);
         CHECK_PETSC_ERROR(err);
-      }
+      } // if
       
       // Create scatter Vec
       sinfo.scatterVec = _localVec;
@@ -506,7 +522,7 @@
         sinfo.vector = _globalVec;
         err = PetscObjectReference((PetscObject) sinfo.vector);
         CHECK_PETSC_ERROR(err);
-      }
+      } // if/else
       err = PetscObjectSetName((PetscObject)sinfo.vector, _metadata["default"].label.c_str());CHECK_PETSC_ERROR(err);
 	
       _scatters[s_iter->first] = sinfo;
@@ -540,10 +556,12 @@
 { // allocate
   ALE::MemoryLogger& logger = ALE::MemoryLogger::singleton();
   logger.stagePush("Field");
-  PetscSection   s = PETSC_NULL;
+  PetscSection   s = NULL;
   PetscErrorCode err;
 
-  if (_dm) {err = DMGetDefaultSection(_dm, &s);CHECK_PETSC_ERROR(err);}
+  if (_dm) {
+    err = DMGetDefaultSection(_dm, &s);CHECK_PETSC_ERROR(err);
+  } // if
   assert(s);
 
   err = PetscSectionSetUp(s);CHECK_PETSC_ERROR(err);
@@ -562,8 +580,8 @@
 pylith::topology::Field<mesh_type>::zero(void)
 { // zero
   assert(_localVec);
-  PetscSection   section;
-  PetscInt       pStart, pEnd, maxDof = 0;
+  PetscSection section = NULL;
+  PetscInt pStart, pEnd, maxDof = 0;
   PetscErrorCode err;
 
   err = DMGetDefaultSection(_dm, &section);CHECK_PETSC_ERROR(err);    
@@ -652,17 +670,22 @@
 
 template<typename mesh_type>
 void
-pylith::topology::Field<mesh_type>::copy(PetscSection osection, PetscInt field, PetscInt component, Vec ovec)
+pylith::topology::Field<mesh_type>::copy(PetscSection osection,
+					 PetscInt field,
+					 PetscInt component,
+					 PetscVec ovec)
 { // copy
-  PetscSection   section;
-  PetscScalar   *array, *oarray;
-  PetscInt       numFields, numComp, pStart, pEnd, qStart, qEnd;
+  assert(osection);
+  assert(ovec);
+  assert(_localVec);
+
+  PetscSection section = NULL;
+  PetscScalar *array = NULL, *oarray = NULL;
+  PetscInt numFields, numComp, pStart, pEnd, qStart, qEnd;
   PetscErrorCode err;
 
   assert(_dm);
-  err = DMGetDefaultSection(_dm, &section);CHECK_PETSC_ERROR(err);
-  assert(section);assert(_localVec);
-  assert(osection);assert(ovec);
+  err = DMGetDefaultSection(_dm, &section);CHECK_PETSC_ERROR(err);assert(section);  
   err = PetscSectionGetNumFields(osection, &numFields);CHECK_PETSC_ERROR(err);
   err = PetscSectionGetChart(section, &pStart, &pEnd);CHECK_PETSC_ERROR(err);
   err = PetscSectionGetChart(osection, &qStart, &qEnd);CHECK_PETSC_ERROR(err);
@@ -691,8 +714,8 @@
       std::ostringstream msg;
       msg << "Invalid field component "<<component<<" should be in [0, "<<numComp<<")";
       throw std::runtime_error(msg.str());
-    }
-  }
+    } // if
+  } // if
   // Copy values from field
   err = VecGetArray(_localVec, &array);CHECK_PETSC_ERROR(err);
   err = VecGetArray(ovec, &oarray);CHECK_PETSC_ERROR(err);
@@ -708,16 +731,16 @@
         assert(!(odof%numComp));
         odof  = odof/numComp;
         ooff += odof*component;
-      }
+      } // if
     } else {
       err = PetscSectionGetDof(osection, p, &odof);CHECK_PETSC_ERROR(err);
       err = PetscSectionGetOffset(osection, p, &ooff);CHECK_PETSC_ERROR(err);
-    }
+    } // else
     assert(odof == dof);
     if (!odof) continue;
     for(PetscInt d = 0; d < dof; ++d) {
       array[off+d] = oarray[ooff+d];
-    }
+    } // for
   } // for
   err = VecRestoreArray(_localVec, &array);CHECK_PETSC_ERROR(err);
   err = VecRestoreArray(ovec, &oarray);CHECK_PETSC_ERROR(err);
@@ -774,9 +797,9 @@
 
   spatialdata::units::Nondimensional normalizer;
   assert(_localVec);
-  PetscSection   section;
-  PetscScalar   *array;
-  PetscInt       pStart, pEnd;
+  PetscSection section = NULL;
+  PetscScalar *array = NULL;
+  PetscInt pStart, pEnd;
   PetscErrorCode err;
 
   err = DMGetDefaultSection(_dm, &section);CHECK_PETSC_ERROR(err);
@@ -839,7 +862,7 @@
 	    << "  scale: " << const_cast<Field*>(this)->_metadata["default"].scale << "\n"
 	    << "  dimensionalize flag: " << const_cast<Field*>(this)->_metadata["default"].dimsOkay << std::endl;
   if (_dm) {
-    PetscSection   section;
+    PetscSection section = NULL;
     PetscErrorCode err;
 
     err = DMGetDefaultSection(_dm, &section);CHECK_PETSC_ERROR(err);
@@ -857,7 +880,7 @@
 template<typename scatter_mesh_type>
 void
 pylith::topology::Field<mesh_type>::createScatter(const scatter_mesh_type& mesh,
-								const char* context)
+						  const char* context)
 { // createScatter
   assert(context);
   PetscErrorCode err = 0;
@@ -896,10 +919,9 @@
 template<typename mesh_type>
 template<typename scatter_mesh_type>
 void
-pylith::topology::Field<mesh_type>::createScatter(
-      const scatter_mesh_type& mesh,
-      const typename ALE::Obj<typename SieveMesh::numbering_type> numbering,
-      const char* context)
+pylith::topology::Field<mesh_type>::createScatter(const scatter_mesh_type& mesh,
+						  const typename ALE::Obj<typename SieveMesh::numbering_type> numbering,
+						  const char* context)
 { // createScatter
   assert(!numbering.isNull());
   assert(context);
@@ -951,9 +973,8 @@
 template<typename mesh_type>
 template<typename scatter_mesh_type>
 void
-pylith::topology::Field<mesh_type>::createScatterWithBC(
-        const scatter_mesh_type& mesh,
-	const char* context)
+pylith::topology::Field<mesh_type>::createScatterWithBC(const scatter_mesh_type& mesh,
+							const char* context)
 { // createScatterWithBC
   assert(context);
   PetscErrorCode err = 0;
@@ -1000,11 +1021,10 @@
 template<typename mesh_type>
 template<typename scatter_mesh_type>
 void
-pylith::topology::Field<mesh_type>::createScatterWithBC(
-       const scatter_mesh_type& mesh,
-       const std::string& labelName,
-       PetscInt labelValue,
-       const char* context)
+pylith::topology::Field<mesh_type>::createScatterWithBC(const scatter_mesh_type& mesh,
+							const std::string& labelName,
+							PetscInt labelValue,
+							const char* context)
 { // createScatterWithBC
   assert(context);
   PetscErrorCode err = 0;
@@ -1019,20 +1039,17 @@
     return;
   } // if
 
-  ALE::MemoryLogger& logger = ALE::MemoryLogger::singleton();
-  logger.stagePush("GlobalOrder");
+  PetscDM dm = mesh.dmMesh();assert(dm);
+  PetscSection section, newSection, gsection, subSection = NULL;
+  PetscSF sf;
+  PetscDMLabel subpointMap, subpointMapF;
+  PetscInt dim, dimF, pStart, pEnd, qStart, qEnd, cEnd, cMax, vEnd, vMax;
+  err = DMPlexGetHeightStratum(_dm, 0, NULL, &cEnd);CHECK_PETSC_ERROR(err);
+  err = DMPlexGetDepthStratum(_dm, 0, NULL, &vEnd);CHECK_PETSC_ERROR(err);
+  err = DMPlexGetHybridBounds(_dm, &cMax, NULL, NULL, &vMax);CHECK_PETSC_ERROR(err);
+  PetscInt excludeRanges[4] = {cMax, cEnd, vMax, vEnd};
+  PetscInt numExcludes = (cMax >= 0 ? 1 : 0) + (vMax >= 0 ? 1 : 0);
 
-  DM           dm = mesh.dmMesh();
-  PetscSection section, newSection, gsection, subSection = PETSC_NULL;
-  PetscSF      sf;
-  DMLabel      subpointMap, subpointMapF;
-  PetscInt     dim, dimF, pStart, pEnd, qStart, qEnd, cEnd, cMax, vEnd, vMax;
-  err = DMPlexGetHeightStratum(_dm, 0, PETSC_NULL, &cEnd);CHECK_PETSC_ERROR(err);
-  err = DMPlexGetDepthStratum(_dm, 0, PETSC_NULL, &vEnd);CHECK_PETSC_ERROR(err);
-  err = DMPlexGetHybridBounds(_dm, &cMax, PETSC_NULL, PETSC_NULL, &vMax);CHECK_PETSC_ERROR(err);
-  PetscInt     excludeRanges[4] = {cMax, cEnd, vMax, vEnd};
-  PetscInt     numExcludes      = (cMax >= 0 ? 1 : 0) + (vMax >= 0 ? 1 : 0);
-
   err = DMGetDefaultSection(_dm, &section);CHECK_PETSC_ERROR(err);
   err = DMPlexGetDimension(dm,  &dim);CHECK_PETSC_ERROR(err);
   err = DMPlexGetDimension(_dm, &dimF);CHECK_PETSC_ERROR(err);
@@ -1042,8 +1059,8 @@
   err = DMPlexGetSubpointMap(_dm, &subpointMapF);CHECK_PETSC_ERROR(err);
   if (((dim != dimF) || ((pEnd-pStart) < (qEnd-qStart))) && subpointMap && !subpointMapF) {
     const PetscInt *ind;
-    IS              subpointIS;
-    PetscInt        n, q;
+    PetscIS subpointIS;
+    PetscInt n, q;
 
     err = PetscPrintf(PETSC_COMM_SELF, "Making translation PetscSection\n");CHECK_PETSC_ERROR(err);
     err = PetscSectionGetChart(section, &qStart, &qEnd);CHECK_PETSC_ERROR(err);
@@ -1062,9 +1079,9 @@
           err = PetscSectionSetDof(subSection, p, dof);CHECK_PETSC_ERROR(err);
           err = PetscSectionGetOffset(section, q, &off);CHECK_PETSC_ERROR(err);
           err = PetscSectionSetOffset(subSection, p, off);CHECK_PETSC_ERROR(err);
-        }
-      }
-    }
+        } // if
+      } // if
+    } // for
     err = ISRestoreIndices(subpointIS, &ind);CHECK_PETSC_ERROR(err);
     err = ISDestroy(&subpointIS);CHECK_PETSC_ERROR(err);
     /* No need to setup section */
@@ -1072,7 +1089,7 @@
     section = subSection;
     /* There are no excludes for surface meshes */
     numExcludes = 0;
-  }
+  } // if
 
   err = DMPlexClone(_dm, &sinfo.dm);CHECK_PETSC_ERROR(err);
   err = PetscSectionClone(section, &newSection);CHECK_PETSC_ERROR(err);
@@ -1085,10 +1102,10 @@
 
     err = DMPlexGetLabel(sinfo.dm, labelName.c_str(), &label);CHECK_PETSC_ERROR(err);
     err = PetscSectionCreateGlobalSectionLabel(section, sf, PETSC_TRUE, label, labelValue, &gsection);CHECK_PETSC_ERROR(err);
-  }
+  } // if/else
   if (((dim != dimF) || ((pEnd-pStart) < (qEnd-qStart))) && subpointMap && !subpointMapF) {
     err = PetscSectionView(gsection, PETSC_VIEWER_STDOUT_WORLD);CHECK_PETSC_ERROR(err);
-  }
+  } // if
   err = DMSetDefaultGlobalSection(sinfo.dm, gsection);CHECK_PETSC_ERROR(err);
   err = DMCreateGlobalVector(sinfo.dm, &sinfo.vector);CHECK_PETSC_ERROR(err);
   err = PetscObjectSetName((PetscObject) sinfo.vector, _metadata["default"].label.c_str());CHECK_PETSC_ERROR(err);
@@ -1113,8 +1130,6 @@
 	    << ", scatter: " << sinfo.scatter
 	    << std::endl;
 #endif
-  
-  logger.stagePop();
 } // createScatterWithBC
 
 // ----------------------------------------------------------------------
@@ -1160,13 +1175,13 @@
 template<typename mesh_type>
 void
 pylith::topology::Field<mesh_type>::scatterSectionToVector(const PetscVec vector,
-									 const char* context) const
+							   const char* context) const
 { // scatterSectionToVector
   assert(vector);
   assert(context);
   const ScatterInfo& sinfo = _getScatter(context);
-  PetscErrorCode     err   = 0;
-#if 0
+  PetscErrorCode err   = 0;
+#if 0 // OBSOLETE??
   if (!_section.isNull()) {
     err = VecScatterBegin(sinfo.scatter, sinfo.scatterVec, vector,
                           INSERT_VALUES, SCATTER_FORWARD);CHECK_PETSC_ERROR(err);
@@ -1177,7 +1192,7 @@
   if (sinfo.dm) {
     err = DMLocalToGlobalBegin(sinfo.dm, _localVec, INSERT_VALUES, vector);CHECK_PETSC_ERROR(err);
     err = DMLocalToGlobalEnd(sinfo.dm, _localVec, INSERT_VALUES, vector);CHECK_PETSC_ERROR(err);
-  }
+  } // if
 } // scatterSectionToVector
 
 // ----------------------------------------------------------------------
@@ -1204,9 +1219,9 @@
   assert(vector);
   assert(context);
   const ScatterInfo& sinfo = _getScatter(context);
-  PetscErrorCode     err   = 0;
+  PetscErrorCode err = 0;
 
-#if 0
+#if 0 // OBSOLETE??
   if (!_section.isNull()) {
     err = VecScatterBegin(sinfo.scatter, vector, sinfo.scatterVec,
                           INSERT_VALUES, SCATTER_REVERSE); CHECK_PETSC_ERROR(err);
@@ -1217,7 +1232,7 @@
   if (sinfo.dm) {
     err = DMGlobalToLocalBegin(sinfo.dm, vector, INSERT_VALUES, _localVec);CHECK_PETSC_ERROR(err);
     err = DMGlobalToLocalEnd(sinfo.dm, vector, INSERT_VALUES, _localVec);CHECK_PETSC_ERROR(err);
-  }
+  } // if
 } // scatterVectorToSection
 
 // ----------------------------------------------------------------------
@@ -1228,15 +1243,17 @@
 pylith::topology::Field<mesh_type>::_getFiberDim(void)
 { // _getFiberDim
   assert(_dm);
-  PetscSection   s;
-  PetscInt       pStart, pEnd;
-  int            fiberDimLocal, fiberDim = 0;
+
+  PetscSection s = NULL;
+  PetscInt pStart, pEnd;
+  int fiberDimLocal, fiberDim = 0;
   PetscErrorCode err;
 
   err = DMGetDefaultSection(_dm, &s);CHECK_PETSC_ERROR(err);
   err = PetscSectionGetChart(s, &pStart, &pEnd);CHECK_PETSC_ERROR(err);
   if (pEnd > pStart) {err = PetscSectionGetDof(s, pStart, &fiberDimLocal);CHECK_PETSC_ERROR(err);}
   MPI_Allreduce(&fiberDimLocal, &fiberDim, 1, MPI_INT, MPI_MAX, _mesh.comm());
+
   return fiberDim;
 } // _getFiberDim
 
@@ -1245,7 +1262,7 @@
 template<typename mesh_type>
 typename pylith::topology::Field<mesh_type>::ScatterInfo&
 pylith::topology::Field<mesh_type>::_getScatter(const char* context,
-							      const bool createOk)
+						const bool createOk)
 { // _getScatter
   assert(context);
 
@@ -1255,8 +1272,7 @@
   // leftover, reusable scatters that need to be cleared out).
   int numNewScatterLocal = (isNewScatter) ? 1 : 0;
   int numNewScatter = 0;
-  MPI_Allreduce(&numNewScatterLocal, &numNewScatter, 1, MPI_INT, MPI_MAX,
-		_mesh.comm());
+  MPI_Allreduce(&numNewScatterLocal, &numNewScatter, 1, MPI_INT, MPI_MAX, _mesh.comm());
   if (numNewScatter && !isNewScatter) {
     // remove old scatter
     ScatterInfo& sinfo = _scatters[context];
@@ -1313,33 +1329,35 @@
   return s_iter->second;
 } // _getScatter
 
+// ----------------------------------------------------------------------
 // Experimental
 template<typename mesh_type>
 void
-pylith::topology::Field<mesh_type>::addField(const char *name, int numComponents)
+pylith::topology::Field<mesh_type>::addField(const char *name,
+					     int numComponents)
 {
   // Keep track of name/components until setup
   _tmpFields[name] = numComponents;
   _metadata[name]  = _metadata["default"];
 }
 
+// ----------------------------------------------------------------------
 template<typename mesh_type>
 void
 pylith::topology::Field<mesh_type>::setupFields()
 {
   assert(_dm);
   // Keep track of name/components until setup
-  PetscSection   section;
-  PetscInt       f = 0;
-  PetscErrorCode err = DMGetDefaultSection(_dm, &section);CHECK_PETSC_ERROR(err);
-  assert(section);
+  PetscSection section;
+  PetscInt f = 0;
+  PetscErrorCode err = DMGetDefaultSection(_dm, &section);CHECK_PETSC_ERROR(err);assert(section);
   err = PetscSectionSetNumFields(section, _tmpFields.size());CHECK_PETSC_ERROR(err);
   for(std::map<std::string, int>::const_iterator f_iter = _tmpFields.begin(); f_iter != _tmpFields.end(); ++f_iter, ++f) {
     err = PetscSectionSetFieldName(section, f, f_iter->first.c_str());CHECK_PETSC_ERROR(err);
     err = PetscSectionSetFieldComponents(section, f, f_iter->second);CHECK_PETSC_ERROR(err);
-  }
+  } // for
   _tmpFields.clear();
-#if 0
+#if 0 // :MATT: What is going on here? Is this obsolete?
   // Right now, we assume that the section covers the entire chart
   PetscInt pStart, pEnd;
 
@@ -1348,12 +1366,14 @@
 #endif
 }
 
+// ----------------------------------------------------------------------
 template<typename mesh_type>
 void
-pylith::topology::Field<mesh_type>::updateDof(const char *name, const DomainEnum domain, int fiberDim)
-{
-  PetscSection   section;
-  PetscInt       pStart, pEnd, f = 0;
+pylith::topology::Field<mesh_type>::updateDof(const char *name,
+					      const DomainEnum domain,
+					      int fiberDim)
+{ // updateDof
+  PetscInt pStart, pEnd, f = 0;
   PetscErrorCode err;
 
   assert(_dm);
@@ -1374,18 +1394,18 @@
     std::cerr << "Unknown value for DomainEnum: " << domain << std::endl;
     throw std::logic_error("Bad domain enum in Field.");
   }
-  err = DMGetDefaultSection(_dm, &section);CHECK_PETSC_ERROR(err);
-  assert(section);
+  PetscSection section = NULL;
+  err = DMGetDefaultSection(_dm, &section);CHECK_PETSC_ERROR(err);assert(section);
   for(map_type::const_iterator f_iter = _metadata.begin(); f_iter != _metadata.end(); ++f_iter) {
     if (f_iter->first == name) break;
     if (f_iter->first == "default") continue;
     ++f;
-  }
+  } // for
   assert(f < _metadata.size());
   for(PetscInt p = pStart; p < pEnd; ++p) {
     //err = PetscSectionAddDof(section, p, fiberDim);CHECK_PETSC_ERROR(err);
     err = PetscSectionSetFieldDof(section, p, f, fiberDim);CHECK_PETSC_ERROR(err);
-  }
-}
+  } // for
+} // updateDof
 
 // End of file 

Modified: short/3D/PyLith/trunk/libsrc/pylith/topology/Field.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/pylith/topology/Field.hh	2013-03-18 14:01:30 UTC (rev 21555)
+++ short/3D/PyLith/trunk/libsrc/pylith/topology/Field.hh	2013-03-18 18:45:37 UTC (rev 21556)
@@ -70,16 +70,34 @@
   /** Constructor with mesh, DM, and metadata
    *
    * @param mesh Finite-element mesh.
+   * @param dm PETSc dm for field.
+   * @param meteadata Field metadata.
    */
-  Field(const mesh_type& mesh, DM dm, const Metadata& metadata);
+  Field(const mesh_type& mesh, 
+	PetscDM dm,
+	const Metadata& metadata);
 
-  /** Constructor with mesh, DM, local data, and metadata
+  /** Constructor with mesh, PETSc DM, local data, and metadata.
    *
    * @param mesh Finite-element mesh.
+   * @param dm PETSc DM for field.
+   * @param localVec PETSc Vec with local data for field.
+   * @param meteadata Field metadata.
    */
-  Field(const mesh_type& mesh, DM dm, Vec localVec, const Metadata& metadata);
+  Field(const mesh_type& mesh, 
+	PetscDM dm,
+	PetscVec localVec,
+	const Metadata& metadata);
 
-  Field(const Field& src, const int fields[], int numFields);
+  /** Constructor with field and subfield information.
+   *
+   * @param mesh Finite-element mesh.
+   * @param fields Array of indices for fields to extract.
+   * @param numFields Size of array.
+   */
+  Field(const Field& src,
+	const int fields[],
+	int numFields);
 
   /// Destructor.
   ~Field(void);
@@ -93,9 +111,9 @@
    */
   const mesh_type& mesh(void) const;
 
-  /** Get DM associated with field.
+  /** Get PETSc DM associated with field.
    *
-   * @returns DM
+   * @returns PETSc DM
    */
   PetscDM dmMesh(void) const;
 
@@ -122,7 +140,8 @@
    * @param name Field name
    * @param value Type of vector field.
    */
-  void vectorFieldType(const std::string& name, const VectorFieldEnum value);
+  void vectorFieldType(const std::string& name,
+		       const VectorFieldEnum value);
 
   /** Get vector field type
    *
@@ -185,40 +204,6 @@
    */
   PetscVec globalVector(void) const;
 
-  /** Get the local array associated with the local PETSc Vec.
-   *
-   * Must call restoryArray() afterwards.
-   * 
-   * @returns Local array.
-   */
-  PetscScalar* getLocalArray(void) const;
-
-  /** Restore local array associated with the local PETSc Vec.
-   *
-   * @preq Must be preceded by call to getLocalArray().
-   *
-   * @param a Local array.
-   */
-  void restoreLocalArray(PetscScalar** a) const;
-
-  /** Get fiber dimension for point.
-   *
-   * @preq Must call cachePetscSection().
-   *
-   * @param point Point in mesh.
-   * @returns Fiber dimension.
-   */
-  PetscInt sectionDof(const PetscInt point) const;
-
-  /** Get offset into array for point.
-   *
-   * @preq Must call cachePetscSection().
-   *
-   * @param point Point in mesh.
-   * @returns Offset.
-   */
-  PetscInt sectionOffset(const PetscInt point) const;
-
   /** Get the number of sieve points in the chart.
    *
    * @returns the chart size.
@@ -246,7 +231,9 @@
    *
    * @note Don't forget to call label(), especially if reusing a field.
    */
-  void newSection(const PetscInt pStart, const PetscInt pEnd, const int fiberDim);
+  void newSection(const PetscInt pStart,
+		  const PetscInt pEnd,
+		  const int fiberDim);
 
   /** Create sieve section and set chart and fiber dimesion for a list
    * of points.
@@ -305,11 +292,20 @@
    */
   void cloneSection(const Field& src);
 
-  void addField(const char *name, int numComponents);
+  /** :MATT: ADD DOCUMENTATION
+   */
+  void addField(const char *name,
+		int numComponents);
 
-  void setupFields();
+  /** :MATT: ADD DOCUMENTATION
+   */
+  void setupFields(void);
 
-  void updateDof(const char *name, const DomainEnum domain, const int fiberDim);
+  /** :MATT: ADD DOCUMENTATION
+   */
+  void updateDof(const char *name,
+		 const DomainEnum domain,
+		 const int fiberDim);
 
   /// Clear variables associated with section.
   void clear(void);
@@ -339,7 +335,10 @@
    * @param component Section field component or -1
    * @param ovec Values to copy.
    */
-  void copy(PetscSection osection, PetscInt field, PetscInt component, Vec ovec);
+  void copy(PetscSection osection,
+	    PetscInt field,
+	    PetscInt component,
+	    PetscVec ovec);
 
   /** Add two fields, storing the result in one of the fields.
    *

Modified: short/3D/PyLith/trunk/libsrc/pylith/topology/Field.icc
===================================================================
--- short/3D/PyLith/trunk/libsrc/pylith/topology/Field.icc	2013-03-18 14:01:30 UTC (rev 21555)
+++ short/3D/PyLith/trunk/libsrc/pylith/topology/Field.icc	2013-03-18 18:45:37 UTC (rev 21556)
@@ -30,7 +30,7 @@
   PetscSection s = PETSC_NULL;
   if (_dm) {
     PetscErrorCode err = DMGetDefaultSection(_dm, &s);CHECK_PETSC_ERROR(err);
-  }
+  } // if
   return s;
 }
 
@@ -50,53 +50,6 @@
   return _globalVec;
 }
 
-// Get the local array associated with the local PETSc Vec.
-template<typename mesh_type>
-inline
-PetscScalar*
-pylith::topology::Field<mesh_type>::getLocalArray(void) const
-{ // getLocalArray
-  PetscScalar* localArray = NULL;
-  PetscErrorCode err = VecGetArray(_localVec, &localArray);CHECK_PETSC_ERROR(err);
-  assert((_localVec && localArray) || (!_localVec && !localArray));
-
-  return localArray;
-} // getLocalArray
-
-// Restore local array associated with the local PETSc Vec.
-template<typename mesh_type>
-inline
-void
-pylith::topology::Field<mesh_type>::restoreLocalArray(PetscScalar** localArray) const
-{ // restoreLocalArray
-  PetscErrorCode err = VecRestoreArray(_localVec, localArray);CHECK_PETSC_ERROR(err);
-  assert(!(*localArray));
-} // restoreLocalArray
-
-// Get fiber dimension for point.
-template<typename mesh_type>
-inline
-PetscInt
-pylith::topology::Field<mesh_type>::sectionDof(const PetscInt point) const
-{ // sectionDof
-  PetscSection section = petscSection();assert(section);
-  PetscInt dof;
-  PetscErrorCode err = PetscSectionGetDof(section, point, &dof);CHECK_PETSC_ERROR(err);
-  return dof;
-} // sectionDof
-
-// Get offset into array for point.
-template<typename mesh_type>
-inline
-PetscInt
-pylith::topology::Field<mesh_type>::sectionOffset(const PetscInt point) const
-{ // sectionOffset
-  PetscSection section = petscSection();assert(section);
-  PetscInt offset;
-  PetscErrorCode err = PetscSectionGetOffset(section, point, &offset);CHECK_PETSC_ERROR(err);
-  return offset;
-} // sectionOffset
-
 // Get mesh associated with field.
 template<typename mesh_type>
 inline



More information about the CIG-COMMITS mailing list