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

brad at geodynamics.org brad at geodynamics.org
Tue Mar 19 14:15:28 PDT 2013


Author: brad
Date: 2013-03-19 14:15:27 -0700 (Tue, 19 Mar 2013)
New Revision: 21572

Modified:
   short/3D/PyLith/trunk/libsrc/pylith/topology/Mesh.cc
   short/3D/PyLith/trunk/libsrc/pylith/topology/Mesh.hh
   short/3D/PyLith/trunk/libsrc/pylith/topology/MeshOps.cc
   short/3D/PyLith/trunk/libsrc/pylith/topology/MeshOps.hh
   short/3D/PyLith/trunk/modulesrc/topology/Mesh.i
Log:
Code cleanup. More removal of Sieve stuff.

Modified: short/3D/PyLith/trunk/libsrc/pylith/topology/Mesh.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/pylith/topology/Mesh.cc	2013-03-19 20:42:21 UTC (rev 21571)
+++ short/3D/PyLith/trunk/libsrc/pylith/topology/Mesh.cc	2013-03-19 21:15:27 UTC (rev 21572)
@@ -116,39 +116,25 @@
 // Return the names of all vertex groups.
 void
 pylith::topology::Mesh::groups(int* numNames, 
-			       char*** names) const
+			       const char*** names) const
 { // groups
-  if (!_mesh.isNull()) {
-    assert(!_mesh.isNull());
-    const ALE::Obj<std::set<std::string> >& sectionNames =  
-      _mesh->getIntSections();
-    assert(!sectionNames.isNull());
-    
-    *numNames = sectionNames->size();
-    *names = new char*[sectionNames->size()];
-    assert(*names);
-    
-    const std::set<std::string>::const_iterator namesEnd = sectionNames->end();
-    int i = 0;
-    for (std::set<std::string>::const_iterator n_iter=sectionNames->begin(); 
-	 n_iter != namesEnd;
-	 ++n_iter) {
-      const char len = n_iter->length();
-      char* newName = 0;
-      if (len > 0) {
-	newName = new char[len+1];
-	strncpy(newName, n_iter->c_str(), len+1);
-      } else {
-	newName = new char[1];
-	newName[0] ='\0';
-      } // if/else
-      (*names)[i++] = newName;
-    } // for
+  assert(numNames);
+  assert(names);
+  *numNames = 0;
+  *names = 0;
 
-  } else {
-    *numNames = 0;
-    *names = 0;
-  } // if/else
+  if (_newMesh) {
+    PetscErrorCode err = 0;
+
+    PetscInt numLabels = 0;
+    err = DMPlexGetNumLabels(_newMesh, &numLabels);CHECK_PETSC_ERROR(err);
+
+    *numNames = numLabels;
+    *names = new const char*[numLabels];
+    for (int iLabel=0; iLabel < numLabels; ++iLabel) {
+      err = DMPlexGetLabelName(_newMesh, iLabel, &(*names)[iLabel]);CHECK_PETSC_ERROR(err);
+    } // for
+  } // if
 } // groups
 
 // ----------------------------------------------------------------------
@@ -156,25 +142,22 @@
 int
 pylith::topology::Mesh::groupSize(const char *name)
 { // groupSize
-  if (!_mesh->hasIntSection(name)) {
+  assert(_newMesh);
+
+  PetscErrorCode err = 0;
+
+  PetscBool hasLabel = PETSC_FALSE;
+  err = DMPlexHasLabel(_newMesh, name, &hasLabel);CHECK_PETSC_ERROR(err);
+  if (!hasLabel) {
     std::ostringstream msg;
     msg << "Cannot get size of group '" << name
 	<< "'. Group missing from mesh.";
     throw std::runtime_error(msg.str());
   } // if
 
-  const ALE::Obj<IntSection>&            group    = _mesh->getIntSection(name);
-  const IntSection::chart_type&          chart    = group->getChart();
-  IntSection::chart_type::const_iterator chartEnd = chart.end();
-  int                                    size     = 0;
+  PetscInt size = 0;
+  err = DMPlexGetLabelSize(_newMesh, name, &size);CHECK_PETSC_ERROR(err);
 
-  for(IntSection::chart_type::const_iterator c_iter = chart.begin();
-      c_iter != chartEnd;
-      ++c_iter) {
-    if (group->getFiberDimension(*c_iter))
-      size++;
-  } // for
-
   return size;
 } // groupSize
 
@@ -188,6 +171,7 @@
   const PylithScalar lengthScale = normalizer.lengthScale();
   PetscErrorCode err;
 
+#if 1 // :TODO: REMOVE SIEVE STUFF
   // Get coordinates (currently dimensioned).
   if (!_mesh.isNull()) {
     const ALE::Obj<RealSection>& coordsSection = _mesh->getRealSection("coordinates");
@@ -230,10 +214,10 @@
       coordsSection->updatePoint(*v_iter, coordsVertex);
     } // for
   }
+#endif
 
   assert(_newMesh);
-  err = DMGetCoordinatesLocal(_newMesh, &coordVec);CHECK_PETSC_ERROR(err);
-  assert(coordVec);
+  err = DMGetCoordinatesLocal(_newMesh, &coordVec);CHECK_PETSC_ERROR(err);assert(coordVec);
   // There does not seem to be an advantage to calling nondimensionalize()
   err = VecScale(coordVec, 1.0/lengthScale);CHECK_PETSC_ERROR(err);
   err = DMPlexSetScale(_newMesh, PETSC_UNIT_LENGTH, lengthScale);CHECK_PETSC_ERROR(err);

Modified: short/3D/PyLith/trunk/libsrc/pylith/topology/Mesh.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/pylith/topology/Mesh.hh	2013-03-19 20:42:21 UTC (rev 21571)
+++ short/3D/PyLith/trunk/libsrc/pylith/topology/Mesh.hh	2013-03-19 21:15:27 UTC (rev 21572)
@@ -226,7 +226,7 @@
    * @param names Names of fields.
    */
   void groups(int* numNames, 
-	      char*** names) const;
+	      const char*** names) const;
 
   /** Return the size of a group.
    *

Modified: short/3D/PyLith/trunk/libsrc/pylith/topology/MeshOps.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/pylith/topology/MeshOps.cc	2013-03-19 20:42:21 UTC (rev 21571)
+++ short/3D/PyLith/trunk/libsrc/pylith/topology/MeshOps.cc	2013-03-19 21:15:27 UTC (rev 21572)
@@ -21,6 +21,7 @@
 #include "MeshOps.hh" // implementation of class methods
 
 #include "pylith/topology/Mesh.hh" // USES Mesh
+#include "pylith/topology/Stratum.hh" // USES Stratum
 #include "pylith/utils/array.hh" // USES int_array
 
 #include <stdexcept> // USES std::runtime_error
@@ -32,20 +33,6 @@
 
 
 // ----------------------------------------------------------------------
-int
-pylith::topology::MeshOps::numMaterialCells(const Mesh& mesh,
-					    int materialId)
-{ // numMaterialCells
-  PetscInt ncells = 0;
-
-  DM dmMesh = mesh.dmMesh();
-  assert(dmMesh);
-  PetscErrorCode err = DMPlexGetStratumSize(dmMesh, "material-id", materialId, &ncells);CHECK_PETSC_ERROR(err);
-  return ncells;
-} // numMaterialCells
-
-
-// ----------------------------------------------------------------------
 void
 pylith::topology::MeshOps::checkMaterialIds(const Mesh& mesh,
 					    int* const materialIds,
@@ -56,23 +43,23 @@
 
   // Create map with indices for each material
   std::map<int, int> materialIndex;
-  for (int i=0; i < numMaterials; ++i)
+  for (int i=0; i < numMaterials; ++i) {
     materialIndex[materialIds[i]] = i;
+  } // for
 
   int_array matCellCounts(numMaterials);
   matCellCounts = 0;
 
-  DM       dmMesh = mesh.dmMesh();
-  PetscInt cStart, cEnd;
+  PetscDM dmMesh = mesh.dmMesh();assert(dmMesh);
+  Stratum heightStratum(dmMesh, Stratum::HEIGHT, 0);
+  const PetscInt cStart = heightStratum.begin();
+  const PetscInt cEnd = heightStratum.end();
 
-  assert(dmMesh);
-  err = DMPlexGetHeightStratum(dmMesh, 0, &cStart, &cEnd);CHECK_PETSC_ERROR(err);
-  DMLabel materialsLabel;
-  err = DMPlexGetLabel(dmMesh, "material-id", &materialsLabel);CHECK_PETSC_ERROR(err);
-  assert(materialsLabel);
+  PetscDMLabel materialsLabel = NULL;
+  err = DMPlexGetLabel(dmMesh, "material-id", &materialsLabel);CHECK_PETSC_ERROR(err);assert(materialsLabel);
 
   int *matBegin = materialIds;
-  int *matEnd   = materialIds + numMaterials;
+  int *matEnd = materialIds + numMaterials;
   std::sort(matBegin, matEnd);
 
   for (PetscInt c = cStart; c < cEnd; ++c) {
@@ -92,12 +79,12 @@
     ++matCellCounts[matIndex];
   } // for
 
-  // Make sure each material has 
+  // Make sure each material has cells.
   int_array matCellCountsAll(matCellCounts.size());
   err = MPI_Allreduce(&matCellCounts[0], &matCellCountsAll[0],
                       matCellCounts.size(), MPI_INT, MPI_SUM, mesh.comm());CHECK_PETSC_ERROR(err);
   for (int i=0; i < numMaterials; ++i) {
-    const int matId    = materialIds[i];
+    const int matId = materialIds[i];
     const int matIndex = materialIndex[matId];
     assert(0 <= matIndex && matIndex < numMaterials);
     if (matCellCountsAll[matIndex] <= 0) {
@@ -111,4 +98,17 @@
 } // checkMaterialIds
 
 
+// ----------------------------------------------------------------------
+int
+pylith::topology::MeshOps::numMaterialCells(const Mesh& mesh,
+					    int materialId)
+{ // numMaterialCells
+  PetscInt ncells = 0;
+
+  PetscDM dmMesh = mesh.dmMesh();assert(dmMesh);
+  PetscErrorCode err = DMPlexGetStratumSize(dmMesh, "material-id", materialId, &ncells);CHECK_PETSC_ERROR(err);
+  return ncells;
+} // numMaterialCells
+
+
 // End of file 

Modified: short/3D/PyLith/trunk/libsrc/pylith/topology/MeshOps.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/pylith/topology/MeshOps.hh	2013-03-19 20:42:21 UTC (rev 21571)
+++ short/3D/PyLith/trunk/libsrc/pylith/topology/MeshOps.hh	2013-03-19 21:15:27 UTC (rev 21572)
@@ -50,10 +50,17 @@
 			int* const materialIds,
 			const int numMaterials);
 
+  /** Get number of cells associated with material.
+   *
+   * @param mesh Finite-element mesh.
+   * @param materialId Id of material.
+   * @returns Number of cells.
+   */
   static
-  int numMaterialCells(const Mesh& mesh, int materialId);
+  int numMaterialCells(const Mesh& mesh,
+		       int materialId);
+  
 
-
 // NOT IMPLEMENTED //////////////////////////////////////////////////////
 private :
 

Modified: short/3D/PyLith/trunk/modulesrc/topology/Mesh.i
===================================================================
--- short/3D/PyLith/trunk/modulesrc/topology/Mesh.i	2013-03-19 20:42:21 UTC (rev 21571)
+++ short/3D/PyLith/trunk/modulesrc/topology/Mesh.i	2013-03-19 21:15:27 UTC (rev 21572)
@@ -134,7 +134,7 @@
        * @param values Values of field values [output].
        */
       void groups(int* numValues, 
-		  char*** values) const;
+		  const char*** values) const;
 
       /** Return the size of a group.
        *



More information about the CIG-COMMITS mailing list