[cig-commits] r18481 - in short/3D/PyLith/trunk: . libsrc/pylith/meshio tests/2d/frictionslide unittests/libtests/meshio
brad at geodynamics.org
brad at geodynamics.org
Fri May 27 17:34:58 PDT 2011
Author: brad
Date: 2011-05-27 17:34:58 -0700 (Fri, 27 May 2011)
New Revision: 18481
Added:
short/3D/PyLith/trunk/tests/2d/frictionslide/velocitysteps.timedb
Modified:
short/3D/PyLith/trunk/TODO
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
short/3D/PyLith/trunk/unittests/libtests/meshio/TestDataWriterHDF5.cc
Log:
More work on Xdmf.
Modified: short/3D/PyLith/trunk/TODO
===================================================================
--- short/3D/PyLith/trunk/TODO 2011-05-27 19:57:36 UTC (rev 18480)
+++ short/3D/PyLith/trunk/TODO 2011-05-28 00:34:58 UTC (rev 18481)
@@ -14,10 +14,6 @@
rate and state friction - sliding test
predictor/corrector scheme?
-* CUBIT 12.2 versus 13.0 file format
-
- Get coordinates from coord_x, coord_y, and coord_z rather than coord in 13.0
-
* Unform global refinement
Check refinement in parallel thoroughly.
@@ -38,6 +34,11 @@
* Output to HDF5 files. [BRAD]
+ Unit tests
+ HDF5::getDatasetDims()
+ HDF5::getGroupDatasets()
+ Xdmf
+
(2) Add creation of .xmf metadata file for ParaView/Visit.
* Field split.
Modified: short/3D/PyLith/trunk/libsrc/pylith/meshio/HDF5.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/pylith/meshio/HDF5.cc 2011-05-27 19:57:36 UTC (rev 18480)
+++ short/3D/PyLith/trunk/libsrc/pylith/meshio/HDF5.cc 2011-05-28 00:34:58 UTC (rev 18481)
@@ -166,26 +166,74 @@
// ----------------------------------------------------------------------
// Get topology metadata.
void
-pylith::meshio::HDF5::getTopologyMetadata(int* numCells,
- int* numCorners,
- std::string* cellType)
-{ // getTopologyMetadata
-} // getTopologyMetadata
+pylith::meshio::HDF5::getDatasetDims(hsize_t** dims,
+ int* ndims,
+ const char* parent,
+ const char* name)
+{ // getDatasetDims
+ assert(dims);
+ assert(ndims);
-// ----------------------------------------------------------------------
-// Get geometry metadata.
-void
-pylith::meshio::HDF5::getGeometryMetadata(int* numVertices,
- int* spaceDim)
-{ // getGeometryMetadata
-} // getGeometryMetadata
+ try {
+ // Open group
+#if defined(PYLITH_HDF5_USE_API_18)
+ hid_t group = H5Gopen2(_file, parent, H5P_DEFAULT);
+#else
+ hid_t group = H5Gopen(_file, parent);
+#endif
+ if (group < 0)
+ throw std::runtime_error("Could not open group.");
+
+ // Open the dataset
+#if defined(PYLITH_HDF5_USE_API_18)
+ hid_t dataset = H5Dopen2(group, name, H5P_DEFAULT);
+#else
+ hid_t dataset = H5Dopen(group, name);
+#endif
+ if (dataset < 0)
+ throw std::runtime_error("Could not open dataset.");
+
+ hid_t dataspace = H5Dget_space(dataset);
+ if (dataspace < 0)
+ throw std::runtime_error("Could not get dataspace.");
+ *ndims = H5Sget_simple_extent_ndims(dataspace);
+ delete[] *dims; *dims = (*ndims > 0) ? new hsize_t[*ndims] : 0;
+ H5Sget_simple_extent_dims(dataspace, *dims, 0);
+
+ herr_t err = H5Sclose(dataspace);
+ if (err < 0)
+ throw std::runtime_error("Could not close dataspace.");
+
+ err = H5Dclose(dataset);
+ if (err < 0)
+ throw std::runtime_error("Could not close dataset.");
+
+ err = H5Gclose(group);
+ if (err < 0)
+ throw std::runtime_error("Could not close group.");
+
+ } catch (const std::exception& err) {
+ std::ostringstream msg;
+ msg << "Error occurred while reading dataset '"
+ << parent << "/" << name << "':\n"
+ << err.what();
+ throw std::runtime_error(msg.str());
+ } catch (...) {
+ std::ostringstream msg;
+ msg << "Unknown occurred while reading dataset '"
+ << parent << "/" << name << "'.";
+ throw std::runtime_error(msg.str());
+ } // try/catch
+} // getDatasetDims
+
// ----------------------------------------------------------------------
-// Get metadata for fields.
+// Get names of datasets in group.
void
-pylith::meshio::HDF5::getFieldsMetadata(std::vector<FieldMetadata>* metadata)
-{ // getFieldsMetadata
-} // getFieldsMetadata
+pylith::meshio::HDF5::getGroupDatasets(std::string* names,
+ const char* group)
+{ // getGroupDatasets
+} // getGroupDatasets
// ----------------------------------------------------------------------
// Create group.
Modified: short/3D/PyLith/trunk/libsrc/pylith/meshio/HDF5.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/pylith/meshio/HDF5.hh 2011-05-27 19:57:36 UTC (rev 18480)
+++ short/3D/PyLith/trunk/libsrc/pylith/meshio/HDF5.hh 2011-05-28 00:34:58 UTC (rev 18481)
@@ -33,19 +33,6 @@
{ // HDF5
friend class TestHDF5; // Unit testing
-// PUBLIC STRUCTS -------------------------------------------------------
-public :
-
- /// Metadata associated with fields.
- struct FieldMetadata {
- std::string name; ///< Name of field.
- std::string vectorFieldType; ///< Type of field.
- std::string domain; ///< Domain over which field is given.
- int numPoints; ///< Number of points in field.
- int fiberDim; ///< Number of values in field at each point, time.
- int numTimeSteps; ///< Number of time steps for field.
- }; // FieldMetadata
-
// PUBLIC METHODS -------------------------------------------------------
public :
@@ -94,30 +81,26 @@
*/
bool hasDataset(const char* name);
- /** Get topology metadata.
+ /** Get dimensions of dataset.
*
- * @param numCells Number of cells [output]
- * @param numCorners Number of corners [output]
- * @param cellType Type of cell [output]
+ * @param dims Array of dimensions. [output]
+ * @param ndims Number of dimensions. [output]
+ * @param parent Full path of parent dataset for attribute.
+ * @param name Name of attribute.
*/
- void getTopologyMetadata(int* numCells,
- int* numCorners,
- std::string* cellType);
+ void getDatasetDims(hsize_t** dims,
+ int* ndims,
+ const char* parent,
+ const char* name);
- /** Get geometry metadata.
+ /** Get names of datasets in group.
*
- * @param numVertices Number of vertices [output].
- * @param spaceDim Spatial dimension [output].
+ * @param names Names of datasets.
+ * @param group Name of group.
*/
- void getGeometryMetadata(int* numVertices,
- int* spaceDim);
+ void getGroupDatasets(std::string* names,
+ const char* group);
- /** Get metadata for fields.
- *
- * @param metadata Array of metadata for fields.
- */
- void getFieldsMetadata(std::vector<FieldMetadata>* metadata);
-
/** Create group.
*
* Create group and leave group open for further operations.
Modified: short/3D/PyLith/trunk/libsrc/pylith/meshio/Xdmf.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/pylith/meshio/Xdmf.cc 2011-05-27 19:57:36 UTC (rev 18480)
+++ short/3D/PyLith/trunk/libsrc/pylith/meshio/Xdmf.cc 2011-05-28 00:34:58 UTC (rev 18481)
@@ -18,8 +18,10 @@
#include "Xdmf.hh" // implementation of class methods
-#include "pylith/utils/array.hh" // USES int_array, string_vector
+#include "HDF5.hh" // USES HDF5
+#include "pylith/utils/array.hh" // USES double_array
+
#include <string> // USES std::string
#include <stdexcept> // USES std::runtime_error
#include <iostream> // USES std::cout
@@ -52,14 +54,45 @@
std::string cellType;
int numVertices = 0;
int spaceDim = 0;
- int numTimeSteps = 0;
- double* timeStamps = 0;
- std::vector<HDF5::FieldMetadata> fieldsMetadata;
+ double_array timeStamps;
+ std::vector<FieldMetadata> fieldsMetadata;
HDF5 h5(filenameHDF5, H5F_ACC_RDONLY);
- h5.getTopologyMetadata(&numCells, &numCorners, &cellType);
- h5.getGeometryMetadata(&numVertices, &spaceDim);
- h5.getFieldsMetadata(&fieldsMetadata);
+
+ int ndims = 0;
+ hsize_t* dims = 0;
+
+ h5.getDatasetDims(&dims, &ndims, "/topology", "cells");
+ assert(2 == ndims);
+ numCells = dims[0];
+ numCorners = dims[1];
+
+ h5.getDatasetDims(&dims, &ndims, "/geometry", "vertices");
+ assert(2 == ndims);
+ numVertices = dims[0];
+ spaceDim = dims[1];
+
+ if (1 == spaceDim && 2 == numCorners)
+ cellType = "Polyline";
+ else if (2 == spaceDim && 3 == numCorners)
+ cellType = "Triangle";
+ else if (2 == spaceDim && 4 == numCorners)
+ cellType = "Quadrilateral";
+ else if (3 == spaceDim && 4 == numCorners)
+ cellType = "Tetrahedron";
+ else if (3 == spaceDim && 8 == numCorners)
+ cellType = "Hexahedron";
+ else {
+ std::ostringstream msg;
+ msg << "Unknown cell type with " << numCorners
+ << " vertices for dimension " << spaceDim << ".";
+ throw std::runtime_error(msg.str());
+ } // else
+
+ // :TODO: Get time stamps
+
+ // :TODO: Get fields metadata
+
const int numFields = fieldsMetadata.size();
for (int iField=0; iField < numFields; ++iField)
if ("vertex_field" == fieldsMetadata[iField].domain) {
@@ -104,31 +137,43 @@
_writeDomainVertices(numVertices, spaceDim);
_file
- << "<!-- ============================================================ -->\n";
+ << " <!-- ============================================================ -->\n";
- _writeTimeStamps(timeStamps, numTimeSteps);
+ if (timeStamps.size() > 0) {
+ _file << " <Grid Name=\"TimeSeries\" GridType=\"Collection\" "
+ << "CollectionType=\"Temporal\">\n";
- _file
- << " <Grid Name=\"domain\" GridType=\"Uniform\">\n";
- for (int iTimeStep=0; iTimeStep < numTimeSteps; ++iTimeStep) {
+ _writeTimeStamps(timeStamps);
+
+ const int numTimeStamps = timeStamps.size();
+ for (int iTimeStep=0; iTimeStep < numTimeStamps; ++iTimeStep) {
+ _file
+ << " <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) {
+ for (int component=0; component < spaceDim; ++component)
+ _writeGridAttributeComponent(fieldsMetadata[iField],
+ iTimeStep, component);
+ } else {
+ _writeGridAttribute(fieldsMetadata[iField],
+ iTimeStep);
+ } // if/else
+ } // for
+ _file << " </Grid>\n";
+ } // for
+ _file << " </Grid>\n";
+ } else {
+ // No time steps or fields (just the mesh).
+ _file << " <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) {
- for (int component=0; component < spaceDim; ++component)
- _writeGridAttributeComponent(fieldsMetadata[iField],
- iTimeStep, component);
- } else {
- _writeGridAttribute(fieldsMetadata[iField],
- iTimeStep);
- } // if/else
- } // for
- _file << " </Grid>\n";
- } // for
+ _file << " </Grid>\n";
+ } // if
_file
- << " </Grid>\n"
<< " </Domain>\n"
<< "</Xdmf>\n";
_file.close();
@@ -171,14 +216,22 @@
// ----------------------------------------------------------------------
// Write time stamps.
void
-pylith::meshio::Xdmf::_writeTimeStamps(const double* timeStamps,
- const int numTimeSteps)
+pylith::meshio::Xdmf::_writeTimeStamps(const double_array& timeStamps)
{ // _writeTimeStamps
assert(_file.is_open() && _file.good());
- if (numTimeSteps > 0) {
- assert(timeStamps);
- } // if
+ const int numTimeStamps = timeStamps.size();
+ _file
+ << " <Time TimeType=\"List\">\n"
+ << " <DataItem Format=\"XML\" NumberType=\"Float\" "
+ << "Dimensions=\"" << numTimeStamps << "\">\n"
+ << " ";
+ for (int i=0; i < numTimeStamps; ++i)
+ _file << " " << timeStamps[i];
+ _file
+ << "\n"
+ << " </DataItem>\n"
+ << " </Time>\n";
} // _writeTimeStamps
// ----------------------------------------------------------------------
@@ -220,7 +273,7 @@
// ----------------------------------------------------------------------
// Write grid attribute.
void
-pylith::meshio::Xdmf::_writeGridAttribute(const HDF5::FieldMetadata& metadata,
+pylith::meshio::Xdmf::_writeGridAttribute(const FieldMetadata& metadata,
const int iTime)
{ // _writeGridAttribute
assert(_file.is_open() && _file.good());
@@ -268,7 +321,7 @@
// ----------------------------------------------------------------------
// Write grid attribute.
void
-pylith::meshio::Xdmf::_writeGridAttributeComponent(const HDF5::FieldMetadata& metadata,
+pylith::meshio::Xdmf::_writeGridAttributeComponent(const FieldMetadata& metadata,
const int iTime,
const int component)
{ // _writeGridAttribute
Modified: short/3D/PyLith/trunk/libsrc/pylith/meshio/Xdmf.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/pylith/meshio/Xdmf.hh 2011-05-27 19:57:36 UTC (rev 18480)
+++ short/3D/PyLith/trunk/libsrc/pylith/meshio/Xdmf.hh 2011-05-28 00:34:58 UTC (rev 18481)
@@ -38,7 +38,7 @@
// Include directives ---------------------------------------------------
#include "meshiofwd.hh" // forward declarations
-#include "HDF5.hh" // USES HDF5::FieldMetadata
+#include "pylith/utils/arrayfwd.hh" // USES double_array
#include <vector> // USES std::vector
#include <fstream> // HASA std::ofstream
@@ -67,6 +67,19 @@
void write(const char* filenameXdmf,
const char* filenameHDF5);
+// PRIVATE STRUCTS ------------------------------------------------------
+public :
+
+ /// Metadata associated with fields.
+ struct FieldMetadata {
+ std::string name; ///< Name of field.
+ std::string vectorFieldType; ///< Type of field.
+ std::string domain; ///< Domain over which field is given.
+ int numPoints; ///< Number of points in field.
+ int fiberDim; ///< Number of values in field at each point, time.
+ int numTimeSteps; ///< Number of time steps for field.
+ }; // FieldMetadata
+
// PRIVATE METHODS ------------------------------------------------------
private :
@@ -89,10 +102,8 @@
/** Write time stamps associated with fields.
*
* @param timeStamps Array of time stamps.
- * @param numTimeStamps Number of time stamps.
*/
- void _writeTimeStamps(const double* timeStamps,
- const int numTimeSteps);
+ void _writeTimeStamps(const double_array& timeStamps);
/** Write grid topology information.
*
@@ -113,7 +124,7 @@
* @param metadata Metadata for field.
* @param iTime Index of time step.
*/
- void _writeGridAttribute(const HDF5::FieldMetadata& metadata,
+ void _writeGridAttribute(const FieldMetadata& metadata,
const int iTime);
/** Write grid attribute as single component (for 2-D vector).
@@ -122,7 +133,7 @@
* @param iTime Index of time step.
* @param component Index of component.
*/
- void _writeGridAttributeComponent(const HDF5::FieldMetadata& metadata,
+ void _writeGridAttributeComponent(const FieldMetadata& metadata,
const int iTime,
const int component);
Added: short/3D/PyLith/trunk/tests/2d/frictionslide/velocitysteps.timedb
===================================================================
--- short/3D/PyLith/trunk/tests/2d/frictionslide/velocitysteps.timedb (rev 0)
+++ short/3D/PyLith/trunk/tests/2d/frictionslide/velocitysteps.timedb 2011-05-28 00:34:58 UTC (rev 18481)
@@ -0,0 +1,10 @@
+#TIME HISTORY ascii
+TimeHistory {
+ num-points = 5
+ time-units = second
+}
+ 0.0 0.0
+ 2.0 2.0e-06
+ 4.0 2.2e-05
+ 6.0 2.4e-05
+ 8.0 2.4e-05
Modified: short/3D/PyLith/trunk/unittests/libtests/meshio/TestDataWriterHDF5.cc
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/meshio/TestDataWriterHDF5.cc 2011-05-27 19:57:36 UTC (rev 18480)
+++ short/3D/PyLith/trunk/unittests/libtests/meshio/TestDataWriterHDF5.cc 2011-05-28 00:34:58 UTC (rev 18481)
@@ -27,25 +27,11 @@
#endif
// ----------------------------------------------------------------------
-#if 0
-namespace pylith {
- namespace meshio {
- namespace _TestDataWriterHDF5 {
-#endif
- herr_t checkObject(hid_t id,
- const char* name,
- H5O_info_t* info,
- void* data);
-#if 0
- } // _TestDataWriterHDF5
- } // meshio
-} // pylith
-#endif
herr_t
-checkObject(hid_t id,
- const char* name,
- const H5O_info_t* info,
- void* data)
+pylith_meshio_TestDataWriterHDF5_checkObject(hid_t id,
+ const char* name,
+ const H5O_info_t* info,
+ void* data)
{ // checkObject
CPPUNIT_ASSERT(info);
CPPUNIT_ASSERT(data);
@@ -155,7 +141,8 @@
#if defined(PYLITH_HDF5_USE_API_18)
// Traverse recursively file with expected values.
- err = H5Ovisit(fileE, H5_INDEX_NAME, H5_ITER_NATIVE, checkObject, (void*) &file);
+ err = H5Ovisit(fileE, H5_INDEX_NAME, H5_ITER_NATIVE,
+ pylith_meshio_TestDataWriterHDF5_checkObject, (void*) &file);
CPPUNIT_ASSERT(err >= 0);
#else
More information about the CIG-COMMITS
mailing list