[cig-commits] r18482 - in short/3D/PyLith/trunk: . libsrc/pylith/meshio

brad at geodynamics.org brad at geodynamics.org
Fri May 27 19:30:04 PDT 2011


Author: brad
Date: 2011-05-27 19:30:04 -0700 (Fri, 27 May 2011)
New Revision: 18482

Modified:
   short/3D/PyLith/trunk/
   short/3D/PyLith/trunk/libsrc/pylith/meshio/HDF5.cc
   short/3D/PyLith/trunk/libsrc/pylith/meshio/HDF5.hh
   short/3D/PyLith/trunk/libsrc/pylith/meshio/Xdmf.cc
   short/3D/PyLith/trunk/libsrc/pylith/meshio/Xdmf.hh
Log:
More work on Xdmf.


Property changes on: short/3D/PyLith/trunk
___________________________________________________________________
Name: buildbot:config
   - # -*- cfg -*-

[packaging]

bin_dirs =
    bin

lib_dirs =
    lib

misc_dirs =
    etc
    share

files =
    setup.sh


strip_list =
    lib/libpylith
    lib/libspatialdata

exclude =
    bin/cpp
    bin/c\+\+
    bin/gcc
    bin/gccbug
    bin/g\+\+
    bin/gcov
    bin/gfortran
    bin/.*-.*-c\+\+.*
    bin/.*-.*-g\+\+.*
    bin/.*-.*-gcc.*
    bin/.*-.*-gfortran.*
    bin/TOPSGenerator\.py
    bin/TOPSInstaller\.py
    bin/adiforfix\.py
    bin/adprocess\.py
    bin/bfort
    bin/bib2html
    bin/bsp_virtual
    bin/configVars\.py
    bin/doctext
    bin/f2py
    bin/maint/.*
    bin/matio\.py
    bin/matlab/.*
    bin/parseargs\.py
    bin/petsc_libtool
    bin/petscmpiexec
    bin/petscrun
    bin/popup
    bin/portabilitycheck\.py
    bin/processSummary\.py
    bin/pstogif
    bin/pstoxbm
    bin/task_manager
    bin/taucc\.py
    bin/tohtml
    bin/update\.py
    bin/urlget
    bin/urlget\.py
    bin/win32fe/.*
    share/man/man1/cpp\.1
    share/man/man1/g\+\+\.1
    share/man/man1/gcc\.1
    share/man/man1/gfortran\.1
    share/man/man3/.*
    share/info/.*
    share/doc/.*
    lib/.*\.a
    lib/gcc/.*-.*/.*

scripts =
    pylith
    pylithinfo
    pyconvert.py
    gensimpledb.py
    powerlaw_gendb.py

   + # -*- cfg -*-

[packaging]

bin_dirs =
    bin

lib_dirs =
    lib

misc_dirs =
    etc
    share

files =
    setup.sh


strip_list =
    lib/libpylith
    lib/libspatialdata

exclude =
    bin/cpp
    bin/c\+\+
    bin/gcc
    bin/gccbug
    bin/g\+\+
    bin/gcov
    bin/gfortran
    bin/.*-.*-c\+\+.*
    bin/.*-.*-g\+\+.*
    bin/.*-.*-gcc.*
    bin/.*-.*-gfortran.*
    bin/TOPSGenerator\.py
    bin/TOPSInstaller\.py
    bin/adiforfix\.py
    bin/adprocess\.py
    bin/2to3
    bin/bfort
    bin/bib2html
    bin/bsp_virtual
    bin/configVars\.py
    bin/doc2lt
    bin/doctext
    bin/f2py
    bin/maint/.*
    bin/matio\.py
    bin/matlab/.*
    bin/parseargs\.py
    bin/petsc_libtool
    bin/petscmpiexec
    bin/petscrun
    bin/popup
    bin/portabilitycheck\.py
    bin/processSummary\.py
    bin/pstogif
    bin/pstoxbm
    bin/task_manager
    bin/taucc\.py
    bin/tohtml
    bin/update\.py
    bin/urlget
    bin/urlget\.py
    bin/win32fe/.*
    share/man/man1/cpp\.1
    share/man/man1/g\+\+\.1
    share/man/man1/gcc\.1
    share/man/man1/gfortran\.1
    share/man/man3/.*
    share/info/.*
    share/doc/.*
    lib/.*\.a
    lib/gcc/.*-.*/.*

scripts =
    pylith
    pylithinfo
    pyconvert.py
    gensimpledb.py
    powerlaw_gendb.py



Modified: short/3D/PyLith/trunk/libsrc/pylith/meshio/HDF5.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/pylith/meshio/HDF5.cc	2011-05-28 00:34:58 UTC (rev 18481)
+++ short/3D/PyLith/trunk/libsrc/pylith/meshio/HDF5.cc	2011-05-28 02:30:04 UTC (rev 18482)
@@ -230,7 +230,7 @@
 // ----------------------------------------------------------------------
 // Get names of datasets in group.
 void
-pylith::meshio::HDF5::getGroupDatasets(std::string* names,
+pylith::meshio::HDF5::getGroupDatasets(string_vector* names,
 				       const char* group)
 { // getGroupDatasets
 } // getGroupDatasets

Modified: short/3D/PyLith/trunk/libsrc/pylith/meshio/HDF5.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/pylith/meshio/HDF5.hh	2011-05-28 00:34:58 UTC (rev 18481)
+++ short/3D/PyLith/trunk/libsrc/pylith/meshio/HDF5.hh	2011-05-28 02:30:04 UTC (rev 18482)
@@ -22,11 +22,10 @@
 // Include directives ---------------------------------------------------
 #include "meshiofwd.hh" // forward declarations
 
+#include "pylith/utils/array.hh" // USES string_vector
+
 #include <hdf5.h> // USES hid_t
 
-#include <vector> // USES std::vector
-#include <string> // USES std::string
-
 // HDF5 -----------------------------------------------------------------
 /// High-level interface for HDF5 operations.
 class pylith::meshio::HDF5
@@ -98,7 +97,7 @@
    * @param names Names of datasets.
    * @param group Name of group.
    */
-  void getGroupDatasets(std::string* names,
+  void getGroupDatasets(string_vector* names,
 			const char* group);
 
   /** Create group.

Modified: short/3D/PyLith/trunk/libsrc/pylith/meshio/Xdmf.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/pylith/meshio/Xdmf.cc	2011-05-28 00:34:58 UTC (rev 18481)
+++ short/3D/PyLith/trunk/libsrc/pylith/meshio/Xdmf.cc	2011-05-28 02:30:04 UTC (rev 18482)
@@ -61,17 +61,27 @@
 
   int ndims = 0;
   hsize_t* dims = 0;
-  
-  h5.getDatasetDims(&dims, &ndims, "/topology", "cells");
-  assert(2 == ndims);
-  numCells = dims[0];
-  numCorners = dims[1];
 
+  // Vertices
   h5.getDatasetDims(&dims, &ndims, "/geometry", "vertices");
   assert(2 == ndims);
   numVertices = dims[0];
   spaceDim = dims[1];
 
+  if (1 == spaceDim) {
+    std::cout
+      << "WARNING: Xdmf grids not defined for 1-D domains.\n"
+      << "Skipping creation of Xdmf file associated with HDF5 file '"
+      << filenameHDF5 << "'" << std::endl;
+    return;
+  } // if
+
+  // Cells
+  h5.getDatasetDims(&dims, &ndims, "/topology", "cells");
+  assert(2 == ndims);
+  numCells = dims[0];
+  numCorners = dims[1];
+
   if (1 == spaceDim && 2 == numCorners)
     cellType = "Polyline";
   else if (2 == spaceDim && 3 == numCorners)
@@ -89,32 +99,13 @@
     throw std::runtime_error(msg.str());
   } // else
 
-  // :TODO: Get time stamps
+  // Time stamps
+  _getTimeStamps(&timeStamps, h5);
 
-  // :TODO: Get fields metadata
+  // Fields metadata
+  _getFieldMetadata(&fieldsMetadata, h5);
 
-  const int numFields = fieldsMetadata.size();
-  for (int iField=0; iField < numFields; ++iField)
-    if ("vertex_field" == fieldsMetadata[iField].domain) {
-      fieldsMetadata[iField].domain = "Node";
-    } else if ("cell_field" == fieldsMetadata[iField].domain) {
-      fieldsMetadata[iField].domain = "Cell";
-    } else {
-      std::ostringstream msg;
-      msg << "Unknown field type '" << fieldsMetadata[iField].domain
-	  << "' for field '" 
-	  << fieldsMetadata[iField].domain << "'" << std::endl;
-      throw std::runtime_error(msg.str());
-    } // if/else
-
-  if (1 == spaceDim) {
-    std::cout
-      << "WARNING: Xdmf grids not defined for 1-D domains.\n"
-      << "Skipping creation of Xdmf file associated with HDF5 file '"
-      << filenameHDF5 << "'" << std::endl;
-    return;
-  } // if
-
+  // Write Xdmf file.
   _file.open(filenameXdmf);
   if (!_file.is_open() || !_file.good()) {
     std::ostringstream msg;
@@ -146,11 +137,13 @@
     _writeTimeStamps(timeStamps);
 
     const int numTimeStamps = timeStamps.size();
+    const int numFields = fieldsMetadata.size();
     for (int iTimeStep=0; iTimeStep < numTimeStamps; ++iTimeStep) {
       _file
-	<< "    <Grid Name=\"domain\" GridType=\"Uniform\">\n";
+	<< "      <Grid Name=\"domain\" GridType=\"Uniform\">\n";
       _writeGridTopology(cellType.c_str(), numCells);
       _writeGridGeometry(spaceDim);
+
       for (int iField=0; iField < numFields; ++iField) {
 	if (2 == spaceDim && 
 	    std::string("vector") == fieldsMetadata[iField].vectorFieldType) {
@@ -180,6 +173,110 @@
 } // write
 
 // ----------------------------------------------------------------------
+// Get timestamps from HDF5 file.
+void
+pylith::meshio::Xdmf::_getTimeStamps(double_array* timeStamps,
+				     HDF5& h5)
+{ // _getTimeStamps
+  assert(timeStamps);
+
+  hsize_t* dims = 0;
+  int ndims = 0;
+  double* t = 0;
+
+  if (h5.hasGroup("/vertex_fields")) {
+    h5.getDatasetDims(&dims, &ndims, "/vertex_fields", "time");
+    assert(3 == ndims);
+    const int numTimeStamps = dims[0];
+    assert(1 == dims[1]);
+    assert(1 == dims[2]);
+
+    // Dataset is in chunks of 1.
+    timeStamps->resize(numTimeStamps);
+    for (int i=0; i < numTimeStamps; ++i) {
+      h5.readDatasetChunk("/vertex_fields", "time", (char**)&t,
+			  &dims, &ndims, i, H5T_NATIVE_DOUBLE);
+      assert(3 == ndims);
+      assert(1 == dims[0]);
+      assert(1 == dims[1]);
+      assert(1 == dims[2]);
+      (*timeStamps)[i] = t[0];
+    } // for
+
+    if (h5.hasGroup("/cell_fields")) {
+      // vertify time stamps in vertex and cell fields match
+      h5.getDatasetDims(&dims, &ndims, "/cell_fields", "time");
+      assert(3 == ndims);
+      if (numTimeStamps != dims[0])
+	throw std::runtime_error("Time stamps in '/vertex_fields/time' and "
+				 "'/cell_fields/time' must be identical.");
+      assert(1 == dims[1]);
+      assert(1 == dims[2]);
+
+      // Dataset is in chunks of 1.
+      for (int i=0; i < numTimeStamps; ++i) {
+	h5.readDatasetChunk("/cell_fields", "time", (char**)&t,
+			    &dims, &ndims, i, H5T_NATIVE_DOUBLE);
+	assert(3 == ndims);
+	assert(1 == dims[0]);
+	assert(1 == dims[1]);
+	assert(1 == dims[2]);
+	if (t[0] != (*timeStamps)[i])
+	  throw std::runtime_error("Time stamps in '/vertex_fields/time' and "
+				   "'/cell_fields/time' must be identical.");
+      } // for
+    } // if
+    
+  } // if
+  if (h5.hasGroup("/cell_fields")) {
+    h5.getDatasetDims(&dims, &ndims, "/cell_fields", "time");
+    assert(3 == ndims);
+    const int numTimeStamps = dims[0];
+    assert(1 == dims[1]);
+    assert(1 == dims[2]);
+
+    // Dataset is in chunks of 1.
+    timeStamps->resize(numTimeStamps);
+    for (int i=0; i < numTimeStamps; ++i) {
+      h5.readDatasetChunk("/cell_fields", "time", (char**)&t,
+			  &dims, &ndims, i, H5T_NATIVE_DOUBLE);
+      assert(3 == ndims);
+      assert(1 == dims[0]);
+      assert(1 == dims[1]);
+      assert(1 == dims[2]);
+      (*timeStamps)[i] = t[0];
+    } // for
+  } // if
+} // _getTimeStamps
+
+// ----------------------------------------------------------------------
+// Get field metadata from HDF5 file.
+void
+pylith::meshio::Xdmf::_getFieldMetadata(std::vector<FieldMetadata>* metadata,
+					HDF5& h5)
+{ // _getFieldMetadata
+  assert(metadata);
+
+  string_vector fieldNames;
+
+  int fieldOffset = 0;
+  if (h5.hasGroup("/vertex_fields")) {
+    h5.getGroupDatasets(&fieldNames, "/vertex_fields");
+    metadata->resize(fieldOffset+fieldNames.size());
+
+    // ADD STUFF HERE
+
+    fieldOffset += fieldNames.size();
+  } // if
+  if (h5.hasGroup("/cell_fields")) {
+    h5.getGroupDatasets(&fieldNames, "/cell_fields");
+    metadata->resize(fieldOffset+fieldNames.size());
+
+    // ADD STUFF HERE
+  } // if
+} // _getFieldMetadata
+
+// ----------------------------------------------------------------------
 // Write domain cell information.
 void
 pylith::meshio::Xdmf::_writeDomainCells(const int numCells,

Modified: short/3D/PyLith/trunk/libsrc/pylith/meshio/Xdmf.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/pylith/meshio/Xdmf.hh	2011-05-28 00:34:58 UTC (rev 18481)
+++ short/3D/PyLith/trunk/libsrc/pylith/meshio/Xdmf.hh	2011-05-28 02:30:04 UTC (rev 18482)
@@ -38,7 +38,7 @@
 // Include directives ---------------------------------------------------
 #include "meshiofwd.hh" // forward declarations
 
-#include "pylith/utils/arrayfwd.hh" // USES double_array
+#include "pylith/utils/array.hh" // USES double_array, std::vector
 
 #include <vector> // USES std::vector
 #include <fstream> // HASA std::ofstream
@@ -83,6 +83,22 @@
 // PRIVATE METHODS ------------------------------------------------------
 private :
 
+  /** Get timestamps from HDF5 file.
+   *
+   * @param timeStamps Array of time stamps.
+   * @param h5 HDF5 file.
+   */
+  void _getTimeStamps(double_array* timeStamps,
+		      HDF5& h5);
+
+  /** Get field metadata from HDF5 file.
+   *
+   * @param metadata Array of field metadata.
+   * @param h5 HDF5 file.
+   */
+  void _getFieldMetadata(std::vector<FieldMetadata>* metadata,
+			 HDF5& h5);
+
   /** Write domain cell information.
    *
    * @param numCells Number of cells.



More information about the CIG-COMMITS mailing list