[cig-commits] r18396 - short/3D/PyLith/trunk/libsrc/meshio
brad at geodynamics.org
brad at geodynamics.org
Fri May 20 07:59:41 PDT 2011
Author: brad
Date: 2011-05-20 07:59:41 -0700 (Fri, 20 May 2011)
New Revision: 18396
Modified:
short/3D/PyLith/trunk/libsrc/meshio/Xdmf.cc
short/3D/PyLith/trunk/libsrc/meshio/Xdmf.hh
Log:
More work on Xdmf.
Modified: short/3D/PyLith/trunk/libsrc/meshio/Xdmf.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/Xdmf.cc 2011-05-19 23:14:38 UTC (rev 18395)
+++ short/3D/PyLith/trunk/libsrc/meshio/Xdmf.cc 2011-05-20 14:59:41 UTC (rev 18396)
@@ -18,7 +18,11 @@
#include "Xdmf.hh" // implementation of class methods
+#include "pylith/utils/array.hh" // USES int_array, string_vector
+
+#include <string> // USES std::string
#include <stdexcept> // USES std::runtime_error
+#include <iostream> // USES std::cout
#include <sstream> // USES std::ostringstream
#include <cassert> // USES assert()
@@ -40,14 +44,93 @@
pylith::meshio::Xdmf::write(const char* filenameXdfm,
const char* filenameHDF5)
{ // write
+ std::string cellType = 0;
+ int numCells = 0;
+ int numCorners = 0;
+ int numVertices = 0;
+ int spaceDim = 0;
+ int numTimeSteps = 0;
+ double* timeStamps = 0;
+ int numFields = 0;
+ string_vector fieldName;
+ string_vector fieldVectorFieldType;
+ string_vector fieldType;
+ int_array fieldNumPoints;
+ int_array fieldFiberDim;
+
+ if (spaceDim == 1) {
+ 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
+
+ _file
+ << "<?xml version=\"1.0\" ?>\n"
+ << "<!DOCTYPE Xdmf SYSTEM \"Xdmf.dtd\" [\n"
+ << "<!ENTITY HeavyData \"" << filenameHDF5 << "\">\n"
+ << "]>\n"
+ << "\n"
+ << "<Xdmf>\n"
+ << " <Domain Name=\"domain\">\n";
+
+ _writeDomainCells(numCells, numCorners);
+ _writeDomainVertices(numVertices, spaceDim);
+
+ _file
+ << "<!-- ============================================================ -->\n";
+
+ _writeTimeStamps(timeStamps, numTimeSteps);
+
+ _file
+ << "<Grid Name=\"domain\" GridType=\"Uniform\">\n";
+ for (int iTimeStep=0; iTimeStep < numTimeSteps; ++iTimeStep) {
+ _writeGridTopology(cellType.c_str(), numCells);
+ _writeGridGeometry(spaceDim);
+ for (int iField=0; iField < numFields; ++iField) {
+ if (2 == spaceDim &&
+ std::string("vector") == fieldVectorFieldType[iField]) {
+ for (int component=0; component < spaceDim; ++component)
+ _writeGridAttributeComponent(fieldName[iField].c_str(),
+ fieldVectorFieldType[iField].c_str(),
+ fieldType[iField].c_str(),
+ numTimeSteps, fieldNumPoints[iField],
+ fieldFiberDim[iField],
+ iTimeStep, component);
+ } else {
+ _writeGridAttribute(fieldName[iField].c_str(),
+ fieldVectorFieldType[iField].c_str(),
+ fieldType[iField].c_str(), numTimeSteps,
+ fieldNumPoints[iField], fieldFiberDim[iField],
+ iTimeStep);
+ } // if/else
+ } // for
+ } // for
+
+ _file
+ << " </Grid>\n"
+ << " </Grid>\n"
+ << " </Domain>\n"
+ << "</Xdmf>\n";
+ _file.close();
} // write
// ----------------------------------------------------------------------
// Write domain cell information.
void
-pylith::meshio::Xdmf::_writeDomainCells(const int numcells,
+pylith::meshio::Xdmf::_writeDomainCells(const int numCells,
const int numCorners)
{ // _writeDomainCells
+ _file
+ << " <DataItem Name=\"cells\"\n"
+ << " ItemType=\"Uniform\"\n"
+ << " Format=\"HDF\"\n"
+ << " NumberType=\"Float\" Precision=\"8\"\n"
+ << " Dimensions=\"" << numCells << " " << numCorners << "\">\n"
+ << " &HeavyData;:/topology/cells\n"
+ << " </DataItem>\n";
+
} // _writeDomainCells
// ----------------------------------------------------------------------
@@ -56,14 +139,39 @@
pylith::meshio::Xdmf::_writeDomainVertices(const int numVertices,
const int spaceDim)
{ // _writeDomainVertices
+ _file
+ << " <DataItem Name=\"vertices\"\n"
+ << " Format=\"HDF\"\n"
+ << " Dimensions=\"" << numVertices << " " << spaceDim << "\">\n"
+ << " &HeavyData;:/geometry/vertices\n"
+ << " </DataItem>\n";
} // _writeDomainVertices
// ----------------------------------------------------------------------
+// Write time stamps.
+void
+pylith::meshio::Xdmf::_writeTimeStamps(const double* timeStamps,
+ const int numTimeSteps)
+{ // _writeTimeStamps
+ if (numTimeSteps > 0) {
+ assert(timeStamps);
+ } // if
+} // _writeTimeStamps
+
+// ----------------------------------------------------------------------
// Write grid topology information.
void
pylith::meshio::Xdmf::_writeGridTopology(const char* cellType,
- const int numells)
+ const int numCells)
{ // _writeGridTopology
+ _file
+ << " <Topology\n"
+ << " TopologyType=\"Triangle\"\n"
+ << " NumberOfElements=\"" << numCells << "\">\n"
+ << " <DataItem Reference=\"XML\">\n"
+ << " /Xdmf/Domain/DataItem[@Name=\"cells\"]\n"
+ << " </DataItem>\n"
+ << " </Topology>\n";
} // _writeGridTopology
// ----------------------------------------------------------------------
@@ -71,18 +179,111 @@
void
pylith::meshio::Xdmf::_writeGridGeometry(const int spaceDim)
{ // _writeGridGeometry
+ assert(2 == spaceDim || 3 == spaceDim);
+
+ const char* geomType = (spaceDim == 3) ? "XYZ" : "XY";
+
+ _file
+ << " <Geometry GeometryType=\"" << geomType << "\">\n"
+ << " <DataItem Reference=\"XML\">\n"
+ << " /Xdmf/Domain/DataItem[@Name=\"vertices\"]\n"
+ << " </DataItem>\n"
+ << " </Geometry>\n";
} // _writeGridGeometry
// ----------------------------------------------------------------------
// Write grid attribute.
void
+pylith::meshio::Xdmf::_writeGridAttributeComponent(const char* name,
+ const char* vectorFieldType,
+ const char* center,
+ const int numTimeSteps,
+ const int numPoints,
+ const int fiberDim,
+ const int iTime,
+ const int component)
+{ // _writeGridAttribute
+ std::string componentName = "unknown";
+ switch (component) {
+ case 0:
+ componentName = std::string("x-") + std::string(name);
+ break;
+ case 1:
+ componentName = std::string("y-") + std::string(name);
+ break;
+ case 2:
+ componentName = std::string("z-") + std::string(name);
+ break;
+ default:
+ { // default
+ std::ostringstream msg;
+ msg << "Unknown component " << component << " while writing Xdmf file.";
+ std::cerr << msg.str() << std::endl;
+ assert(0);
+ throw std::logic_error(msg.str());
+ } // default
+ } // switch
+ _file
+ << " <Attribute\n"
+ << " Name=\"" << componentName << "\"\n"
+ << " Type=\""<< vectorFieldType << "\"\n"
+ << " Center=\"" << center << "\">\n"
+ << " <DataItem ItemType=\"HyperSlab\"\n"
+ << " Dimensions=\"1 " << numPoints << " 1\"\n"
+ << " Type=\"HyperSlab\">\n"
+ << " <DataItem\n"
+ << " Dimensions=\"3 3\"\n"
+ << " Format=\"XML\">\n"
+ << " 0 0 "<< component << "\n"
+ << " 1 1 1\n"
+ << " 1 " << numPoints << " 1\n"
+ << " </DataItem>\n"
+ << " <DataItem\n"
+ << " DataType=\"Float\" Precision=\"8\"\n"
+ << " Dimensions=\""
+ << numTimeSteps << " " << numPoints << " " << fiberDim << "\"\n"
+ << " Format=\"HDF\">\n"
+ << " &HeavyData;:/vertex_fields/" << name << "\n"
+ << " </DataItem>\n"
+ << " </DataItem>\n"
+ << " </Attribute>\n";
+} // _writeGridAttribute
+
+// ----------------------------------------------------------------------
+// Write grid attribute.
+void
pylith::meshio::Xdmf::_writeGridAttribute(const char* name,
+ const char* vectorFieldType,
const char* center,
const int numTimeSteps,
const int numPoints,
const int fiberDim,
const int iTime)
{ // _writeGridAttribute
+ _file
+ << " <Attribute\n"
+ << " Name=\"" << name << "\"\n"
+ << " Type=\"" << vectorFieldType << "\"\n"
+ << " Center=\"" << center << "\">\n"
+ << " <DataItem ItemType=\"HyperSlab\"\n"
+ << " Dimensions=\"1 " << numPoints << " 1\"\n"
+ << " Type=\"HyperSlab\">\n"
+ << " <DataItem\n"
+ << " Dimensions=\"3 3\"\n"
+ << " Format=\"XML\">\n"
+ << " 0 0 0\n"
+ << " 1 1 1\n"
+ << " 1 " << numPoints << " 1\n"
+ << " </DataItem>\n"
+ << " <DataItem\n"
+ << " DataType=\"Float\" Precision=\"8\"\n"
+ << " Dimensions=\""
+ << numTimeSteps << " " << numPoints << " " << fiberDim << "\"\n"
+ << " Format=\"HDF\">\n"
+ << " &HeavyData;:/vertex_fields/" << name << "\n"
+ << " </DataItem>\n"
+ << " </DataItem>\n"
+ << " </Attribute>\n";
} // _writeGridAttribute
Modified: short/3D/PyLith/trunk/libsrc/meshio/Xdmf.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/Xdmf.hh 2011-05-19 23:14:38 UTC (rev 18395)
+++ short/3D/PyLith/trunk/libsrc/meshio/Xdmf.hh 2011-05-20 14:59:41 UTC (rev 18396)
@@ -72,7 +72,7 @@
* @param numCells Number of cells.
* @param numCorners Number of vertices in a cell.
*/
- void _writeDomainCells(const int numcells,
+ void _writeDomainCells(const int numCells,
const int numCorners);
/** Write domain vertices information.
@@ -83,13 +83,21 @@
void _writeDomainVertices(const int numVertices,
const int spaceDim);
+ /** 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);
+
/** Write grid topology information.
*
* @param cellType Name for cell type.
* @param numCells Number of cells.
*/
void _writeGridTopology(const char* cellType,
- const int numells);
+ const int numCells);
/** Write Grid geometry.
*
@@ -100,6 +108,7 @@
/** Write grid attribute.
*
* @param name Name of attribute.
+ * @param vectorFieldType Type of vector field.
* @param center Vertex/Cell center.
* @param numTimeSteps Number of time steps.
* @param numPoints Number of vertices or cells.
@@ -107,12 +116,33 @@
* @param iTime Index of time step.
*/
void _writeGridAttribute(const char* name,
+ const char* vectorFieldType,
const char* center,
const int numTimeSteps,
const int numPoints,
const int fiberDim,
const int iTime);
+ /** Write grid attribute as single component (for 2-D vector).
+ *
+ * @param name Name of attribute.
+ * @param vectorFieldType Type of vector field.
+ * @param center Vertex/Cell center.
+ * @param numTimeSteps Number of time steps.
+ * @param numPoints Number of vertices or cells.
+ * @param fiberDim Fiber dimension for attribute.
+ * @param iTime Index of time step.
+ * @param component Index of component.
+ */
+ void _writeGridAttributeComponent(const char* name,
+ const char* vectorFieldType,
+ const char* center,
+ const int numTimeSteps,
+ const int numPoints,
+ const int fiberDim,
+ const int iTime,
+ const int component);
+
// PRIVATE MEMBERS ------------------------------------------------------
private :
More information about the CIG-COMMITS
mailing list