[cig-commits] r7495 - in short/3D/PyLith/trunk: examples/3d/hex8 libsrc/bc libsrc/meshio pylith/topology

knepley at geodynamics.org knepley at geodynamics.org
Tue Jun 26 09:19:59 PDT 2007


Author: knepley
Date: 2007-06-26 09:19:58 -0700 (Tue, 26 Jun 2007)
New Revision: 7495

Modified:
   short/3D/PyLith/trunk/examples/3d/hex8/pylithapp.cfg
   short/3D/PyLith/trunk/libsrc/bc/Dirichlet.cc
   short/3D/PyLith/trunk/libsrc/meshio/MeshIOCubit.cc
   short/3D/PyLith/trunk/libsrc/meshio/MeshIOHDF5.cc
   short/3D/PyLith/trunk/libsrc/meshio/MeshIOLagrit.cc
   short/3D/PyLith/trunk/pylith/topology/MeshImporter.py
Log:
Fixed parallel reading of other mesh formats


Modified: short/3D/PyLith/trunk/examples/3d/hex8/pylithapp.cfg
===================================================================
--- short/3D/PyLith/trunk/examples/3d/hex8/pylithapp.cfg	2007-06-26 15:50:31 UTC (rev 7494)
+++ short/3D/PyLith/trunk/examples/3d/hex8/pylithapp.cfg	2007-06-26 16:19:58 UTC (rev 7495)
@@ -13,6 +13,7 @@
 meshiocubit = 1
 implicitelasticity = 1
 faultcohesivekin = 1
+meshimporter = 1
 #quadrature3d = 1
 #fiatlagrange = 1
 

Modified: short/3D/PyLith/trunk/libsrc/bc/Dirichlet.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/bc/Dirichlet.cc	2007-06-26 15:50:31 UTC (rev 7494)
+++ short/3D/PyLith/trunk/libsrc/bc/Dirichlet.cc	2007-06-26 16:19:58 UTC (rev 7495)
@@ -61,8 +61,9 @@
   int i = 0;
   for(int_section_type::chart_type::iterator c_iter = chart.begin();
       c_iter != chart.end();
-      ++c_iter)
+      ++c_iter) {
     _points[i++] = *c_iter;
+  }
 
   // Get values for degrees of freedom
   char** valueNames = (numFixedDOF > 0) ? new char*[numFixedDOF] : 0;

Modified: short/3D/PyLith/trunk/libsrc/meshio/MeshIOCubit.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/MeshIOCubit.cc	2007-06-26 15:50:31 UTC (rev 7494)
+++ short/3D/PyLith/trunk/libsrc/meshio/MeshIOCubit.cc	2007-06-26 16:19:58 UTC (rev 7495)
@@ -18,6 +18,8 @@
 
 #include "journal/info.h" // USES journal::info_t
 
+#include <petsc.h> // USES MPI_Comm
+
 #include <netcdfcpp.h> // USES netcdf
 
 #include <assert.h> // USES assert()
@@ -42,48 +44,59 @@
 void
 pylith::meshio::MeshIOCubit::_read(void)
 { // _read
-  try {
-    NcFile ncfile(_filename.c_str());
-    if (!ncfile.is_valid()) {
-      std::ostringstream msg;
-      msg << "Could not open Cubit Exodus file '" << _filename
-	  << "' for reading.\n";
-      throw std::runtime_error(msg.str());
-    } // if
+  MPI_Comm comm = PETSC_COMM_WORLD;
+  int rank;
+  int meshDim = 0;
+  int spaceDim = 0;
+  int numVertices = 0;
+  int numCells = 0;
+  int numCorners = 0;
+  double_array coordinates;
+  int_array cells;
+  int_array materialIds;
 
-    int meshDim = 0;
-    int spaceDim = 0;
-    int numVertices = 0;
-    int numCells = 0;
-    int numCorners = 0;
-    double_array coordinates;
-    int_array cells;
-    int_array materialIds;
+  MPI_Comm_rank(comm, &rank);
+  if (!rank) {
+    try {
+      NcFile ncfile(_filename.c_str());
+      if (!ncfile.is_valid()) {
+        std::ostringstream msg;
+        msg << "Could not open Cubit Exodus file '" << _filename
+            << "' for reading.\n";
+        throw std::runtime_error(msg.str());
+      } // if
 
-    NcDim* num_dim = ncfile.get_dim("num_dim");
-    if (0 == num_dim)
-      throw std::runtime_error("Could not get dimension 'num_dim'.");
-    meshDim = num_dim->size();
 
-    _readVertices(ncfile, &coordinates, &numVertices, &spaceDim);
-    _readCells(ncfile, &cells, &materialIds, &numCells, &numCorners);
-    _orientCells(&cells, numCells, numCorners, meshDim);
+      NcDim* num_dim = ncfile.get_dim("num_dim");
+      if (0 == num_dim)
+        throw std::runtime_error("Could not get dimension 'num_dim'.");
+      meshDim = num_dim->size();
+
+      _readVertices(ncfile, &coordinates, &numVertices, &spaceDim);
+      _readCells(ncfile, &cells, &materialIds, &numCells, &numCorners);
+      _orientCells(&cells, numCells, numCorners, meshDim);
+      _buildMesh(coordinates, numVertices, spaceDim,
+                 cells, numCells, numCorners, meshDim);
+      _setMaterials(materialIds);
+
+      _readGroups(ncfile);
+    } catch (std::exception& err) {
+      std::ostringstream msg;
+      msg << "Error while reading Cubit Exodus file '" << _filename << "'.\n"
+          << err.what();
+      throw std::runtime_error(msg.str());
+    } catch (...) {
+      std::ostringstream msg;
+      msg << "Unknown error while reading Cubit Exodus file '" << _filename
+          << "'.";
+      throw std::runtime_error(msg.str());
+    } // try/catch
+  } else {
     _buildMesh(coordinates, numVertices, spaceDim,
-	       cells, numCells, numCorners, meshDim);
+               cells, numCells, numCorners, meshDim);
     _setMaterials(materialIds);
-
-    _readGroups(ncfile);
-  } catch (std::exception& err) {
-    std::ostringstream msg;
-    msg << "Error while reading Cubit Exodus file '" << _filename << "'.\n"
-	<< err.what();
-    throw std::runtime_error(msg.str());
-  } catch (...) {
-    std::ostringstream msg;
-    msg << "Unknown error while reading Cubit Exodus file '" << _filename
-	<< "'.";
-    throw std::runtime_error(msg.str());
-  } // try/catch
+  }
+  _distributeGroups();
 } // read
 
 // ----------------------------------------------------------------------

Modified: short/3D/PyLith/trunk/libsrc/meshio/MeshIOHDF5.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/MeshIOHDF5.cc	2007-06-26 15:50:31 UTC (rev 7494)
+++ short/3D/PyLith/trunk/libsrc/meshio/MeshIOHDF5.cc	2007-06-26 16:19:58 UTC (rev 7495)
@@ -41,9 +41,8 @@
 MeshIOHDF5::read(ALE::Obj<ALE::PetscMesh>* pMesh)
 { // read
   assert(0 != pMesh);
-
-  
-
+  MPI_Comm comm = PETSC_COMM_WORLD;
+  int rank;
   int meshDim = 0;
   int numDims = 0;
   int numVertices = 0;
@@ -52,44 +51,39 @@
   double* coordinates = 0;
   int* elements = 0;
 
-  hid_t filein = H5Fopen(_filename.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT);
-  if (filein < 0) {
-    std::ostringstream msg;
-    msg << "Could not open HDF5 mesh file '" << _filename
-	<< "' for reading.\n";
-    throw std::runtime_error(msg.str());
-  } // if
+  MPI_Comm_rank(comm, &rank);
+  if (!rank) {
+    hid_t filein = H5Fopen(_filename.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT);
+    if (filein < 0) {
+      std::ostringstream msg;
+      msg << "Could not open HDF5 mesh file '" << _filename
+          << "' for reading.\n";
+      throw std::runtime_error(msg.str());
+    } // if
 
-  _readMeshInfo(filein, pMesh);
-  _readVertices(filein, &coordinates, &numVertices, &numDims);
-  _readElements(filein, &elements, &numElements, &numCorners);
+    _readMeshInfo(filein, pMesh);
+    _readVertices(filein, &coordinates, &numVertices, &numDims);
+    _readElements(filein, &elements, &numElements, &numCorners);
   
-  *pMesh = ALE::PetscMesh(PETSC_COMM_WORLD, meshDim);
-  (*pMesh)->debug = true;
-  bool interpolate = false;
+    *pMesh = ALE::PetscMesh(PETSC_COMM_WORLD, meshDim);
+    (*pMesh)->debug = true;
+    bool interpolate = false;
 
-#if 1
-  // allow mesh to have different dimension than coordinates
-  ALE::Obj<ALE::PetscMesh::sieve_type> topology = (*pMesh)->getTopology();
-  topology->setStratification(false);
-  (*pMesh)->buildTopology(numElements, elements, numVertices, 
-			  interpolate, numCorners);
-  topology->stratify();
-  topology->setStratification(true);
-  (*pMesh)->createVertexBundle(numElements, elements, 0, numCorners);
-  (*pMesh)->createSerialCoordinates(numDims, numElements, coordinates);
-#else
-  // require mesh to have same dimension as coordinates
-  (*pMesh)->populate(numElements, elements, numVertices, coordinates, 
-		     interpolate, numCorners);
-#endif
-  delete[] coordinates; coordinates = 0;
-  delete[] elements; elements = 0;
+    _buildMesh(coordinates, numVertices, spaceDim,
+               cells, numCells, numCorners, meshDim);
+    delete[] coordinates; coordinates = 0;
+    delete[] elements; elements = 0;
 
-  // loop over charts
-  // _readChart();
+    // loop over charts
+    // _readChart();
 
-  H5Fclose(filein);
+    H5Fclose(filein);
+  } else {
+    _buildMesh(coordinates, numVertices, spaceDim,
+               cells, numCells, numCorners, meshDim);
+  }
+  //_setMaterials(materialIds);
+  //_distributeGroups();
 } // read
 
 // ----------------------------------------------------------------------

Modified: short/3D/PyLith/trunk/libsrc/meshio/MeshIOLagrit.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/MeshIOLagrit.cc	2007-06-26 15:50:31 UTC (rev 7494)
+++ short/3D/PyLith/trunk/libsrc/meshio/MeshIOLagrit.cc	2007-06-26 16:19:58 UTC (rev 7495)
@@ -21,6 +21,8 @@
 
 #include "pylith/utils/array.hh" // USES double_array, int_array
 
+#include <petsc.h> // USES MPI_Comm
+
 #include <assert.h> // USES assert()
 #include <stdexcept> // TEMPORARY
 
@@ -44,6 +46,8 @@
 void
 pylith::meshio::MeshIOLagrit::_read(void)
 { // _read
+  MPI_Comm comm = PETSC_COMM_WORLD;
+  int rank;
   int meshDim = 0;
   int spaceDim = 0;
   int numVertices = 0;
@@ -53,33 +57,39 @@
   int_array cells;
   int_array materialIds;
 
-  if (GMVFile::isAscii(_filenameGmv.c_str())) {
-    GMVFileAscii filein(_filenameGmv.c_str());
-    filein.read(&coordinates, &cells, &materialIds, 
-		&meshDim, &spaceDim, &numVertices, &numCells, &numCorners);
-    _orientCellsAscii(&cells, numCells, numCorners, meshDim);
-  } else {
-    GMVFileBinary filein(_filenameGmv.c_str(), _flipEndian);
-    filein.read(&coordinates, &cells, &materialIds, 
-		&meshDim, &spaceDim, &numVertices, &numCells, &numCorners);
-    _orientCellsBinary(&cells, numCells, numCorners, meshDim);
-  } // if/else
+  MPI_Comm_rank(comm, &rank);
+  if (!rank) {
+    if (GMVFile::isAscii(_filenameGmv.c_str())) {
+      GMVFileAscii filein(_filenameGmv.c_str());
+      filein.read(&coordinates, &cells, &materialIds, 
+                  &meshDim, &spaceDim, &numVertices, &numCells, &numCorners);
+      _orientCellsAscii(&cells, numCells, numCorners, meshDim);
+    } else {
+      GMVFileBinary filein(_filenameGmv.c_str(), _flipEndian);
+      filein.read(&coordinates, &cells, &materialIds, 
+                  &meshDim, &spaceDim, &numVertices, &numCells, &numCorners);
+      _orientCellsBinary(&cells, numCells, numCorners, meshDim);
+    } // if/else
+  }
   _buildMesh(coordinates, numVertices, spaceDim,
-	     cells, numCells, numCorners, meshDim);
+             cells, numCells, numCorners, meshDim);
   _setMaterials(materialIds);
 
-  std::vector<PsetFile::Pset> groups;
-  if (PsetFile::isAscii(_filenamePset.c_str())) {
-    PsetFileAscii filein(_filenamePset.c_str());
-    filein.read(&groups);
-  } else {
-    PsetFileBinary filein(_filenamePset.c_str(), _flipEndian);
-    filein.read(&groups);
-  } // if/else
-  GroupPtType type = VERTEX;
-  const int numGroups = groups.size();
-  for (int iGroup=0; iGroup < numGroups; ++iGroup)
-    _setGroup(groups[iGroup].name, type, groups[iGroup].points);
+  if (!rank) {
+    std::vector<PsetFile::Pset> groups;
+    if (PsetFile::isAscii(_filenamePset.c_str())) {
+      PsetFileAscii filein(_filenamePset.c_str());
+      filein.read(&groups);
+    } else {
+      PsetFileBinary filein(_filenamePset.c_str(), _flipEndian);
+      filein.read(&groups);
+    } // if/else
+    GroupPtType type = VERTEX;
+    const int numGroups = groups.size();
+    for (int iGroup=0; iGroup < numGroups; ++iGroup)
+      _setGroup(groups[iGroup].name, type, groups[iGroup].points);
+  }
+  _distributeGroups();
 } // _read
 
 // ----------------------------------------------------------------------

Modified: short/3D/PyLith/trunk/pylith/topology/MeshImporter.py
===================================================================
--- short/3D/PyLith/trunk/pylith/topology/MeshImporter.py	2007-06-26 15:50:31 UTC (rev 7494)
+++ short/3D/PyLith/trunk/pylith/topology/MeshImporter.py	2007-06-26 16:19:58 UTC (rev 7495)
@@ -72,8 +72,11 @@
     Hook for creating mesh.
     """
     mesh = self.importer.read(self.debug, self.interpolate)
+    self._info.log("Adjusting topology.")
     self._adjustTopology(mesh, faults)
+    self._info.log("Distributing mesh.")
     mesh = self.distributor.distribute(mesh)
+    mesh.view()
     return mesh
 
 



More information about the cig-commits mailing list