Extension of the H5Fed API and adding a dump program to test the API.
This commit is contained in:
@@ -5,6 +5,8 @@
|
||||
/GNUmakefile.orig -text
|
||||
H5Fed/applications/gmsh2h5fed.cc -text
|
||||
H5Fed/applications/gmsh2h5fed.hh -text
|
||||
H5Fed/applications/h5feddump.cc -text
|
||||
H5Fed/applications/h5feddump.hh -text
|
||||
H5Fed/applications/makefile.am -text
|
||||
H5Fed/autogen.sh -text
|
||||
H5Fed/configure.ac -text
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
// modified - 2006 jun 26, creation, patrick leidenberger
|
||||
// modified - 2006 aug 25, extend, patrick leidenberger
|
||||
// modified - 2006 aug 26, pl, integrate automatic index mapping.
|
||||
// modified - 2006 sep 22, pl, addaped to h5fed api changes.
|
||||
//
|
||||
// feature - Implements the a mesh preprocessor.
|
||||
// feature - It will read gmsh's mesh files of version 2.0 and write the mesh
|
||||
@@ -159,12 +160,12 @@ int main(int argc, char **argv)
|
||||
|
||||
// The gmsh node index has gaps and is not consecutive.
|
||||
// So we activate the automatic index mapping from the h5fed api.
|
||||
h5fedFile.beginIndexMapping(&gmshNodesIndex);
|
||||
h5fedFile.beginIndexMapping(gmshNodesIndex);
|
||||
|
||||
// Get a vector with all node coordinates from the gmsh file.
|
||||
gmshNodes = gmshInFile.gmshNode();
|
||||
// Write the nodes to the h5fed file.
|
||||
h5fedFile.coord3d(&gmshNodes);
|
||||
h5fedFile.wCoord3d(gmshNodes);
|
||||
// Every node in h5fed file, so we can save memory.
|
||||
gmshNodes.clear();
|
||||
|
||||
@@ -174,8 +175,10 @@ int main(int argc, char **argv)
|
||||
{
|
||||
// rDebug("Elem: %d Nodes: %d; %d; %d; %d", varI, gmshTetrahedron[varI][0], gmshTetrahedron[varI][1], gmshTetrahedron[varI][2], gmshTetrahedron[varI][3]);
|
||||
}
|
||||
std::vector<unsigned int> gmshTetrahedronMatIndex;
|
||||
gmshTetrahedronMatIndex.resize(0,gmshTetrahedron.size());
|
||||
// Write the tetrahedrons to the h5fed file on the respective level.
|
||||
h5fedFile.tetrahedron(0,&gmshTetrahedron);
|
||||
h5fedFile.wTetrahedron(0,gmshTetrahedron, gmshTetrahedronMatIndex);
|
||||
// Every terahedron in h5fed file, so we can save memory.
|
||||
gmshTetrahedron.clear();
|
||||
|
||||
|
||||
@@ -0,0 +1,142 @@
|
||||
// rights - 2006-, copyright patrick leidenberger and benedikt oswald,
|
||||
// all rights reserved
|
||||
// project - h5feddump
|
||||
// file name - h5feddump.cc
|
||||
// file type - c++ implementaton file
|
||||
// objective - main file h5fed dump program
|
||||
// modified - 2006 sep 21, creation, patrick leidenberger.
|
||||
// modified - 2006 sep 22, pl, add dump for coordinates.
|
||||
//
|
||||
// feature - Implements the a dump tool for h5fed files.
|
||||
// feature - It will read hf5ed file and write the data to the standard
|
||||
// feature - output.
|
||||
// feature - There are different options on command line what to dump.
|
||||
// required software - rlog library, boost library
|
||||
|
||||
#include <h5feddump.hh>
|
||||
|
||||
using namespace rlog;
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
//=================//
|
||||
// Initialize RLog //
|
||||
//=================//
|
||||
// Make a instance of the class for RLog.
|
||||
StdioNode stdLog;
|
||||
|
||||
/** Subscchar* inFile_;ribe output channels.
|
||||
* Compile with -DRLOG_DEBUG to get the debug output.
|
||||
**/
|
||||
#ifdef USE_RLOG_DEBUG_CHANNEL
|
||||
stdLog.subscribeTo(GetGlobalChannel("debug"));
|
||||
#endif //USE_RLOG_DEBUG_CHANNEL
|
||||
#ifdef USE_RLOG_ERROR_CHANNEL
|
||||
stdLog.subscribeTo(GetGlobalChannel("error"));
|
||||
#endif //USE_RLOG_ERROR_CHANNEL
|
||||
#ifdef USE_RLOG_INFO_CHANNEL
|
||||
stdLog.subscribeTo(GetGlobalChannel("info"));
|
||||
#endif //USE_RLOG_INFO_CHANNEL
|
||||
#ifdef USE_RLOG_WARNING_CHANNEL
|
||||
stdLog.subscribeTo(GetGlobalChannel("warning"));
|
||||
#endif //USE_RLOG_WARNING_CHANNEL
|
||||
|
||||
// Define variables that hold the command line parameters.
|
||||
string hdf5fedFile;
|
||||
|
||||
//==================================================//
|
||||
// Parse the comand line options //
|
||||
// with the program_options from the boost library. //
|
||||
//==================================================//
|
||||
try
|
||||
{
|
||||
// Define and instance of the program_options class and name it.
|
||||
boost::program_options::options_description
|
||||
desc("Allowed program options");
|
||||
// Define the command line options parsing rules.
|
||||
desc.add_options()
|
||||
("help", "produce this help")
|
||||
("input-file", boost::program_options::value<string>(),
|
||||
"hdf5fed file to dump");
|
||||
// Parse the command line.
|
||||
boost::program_options::variables_map varMap;
|
||||
boost::program_options::store
|
||||
(boost::program_options::parse_command_line(argc, argv, desc),
|
||||
varMap);
|
||||
boost::program_options::notify(varMap);
|
||||
// Action in relation to the command line options.
|
||||
if (varMap.count("help"))
|
||||
{
|
||||
cout << desc << "\n";
|
||||
return ERRORCODE;
|
||||
}
|
||||
else if (varMap.count("input-file"))
|
||||
{
|
||||
hdf5fedFile = varMap["input-file"].as<string>();
|
||||
rInfo("Input filename: %s",
|
||||
hdf5fedFile.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
rError("You have insert wrong options.");
|
||||
rError("For details use: --help.");
|
||||
return ERRORCODE;
|
||||
}
|
||||
}
|
||||
catch(exception& error)
|
||||
{
|
||||
rError("Error: %d",error.what());
|
||||
return ERRORCODE;
|
||||
}
|
||||
|
||||
//==========================//
|
||||
// Start with the main work //
|
||||
//==========================//
|
||||
|
||||
// Put all H5Fed funktions in here.
|
||||
#ifdef HAVE_HDF5
|
||||
// Create H5Fed class instance.
|
||||
H5Fed::H5Fed h5fedFile;
|
||||
|
||||
// Open H5Fed file for reading. Filename comes from
|
||||
// command line parameters.
|
||||
h5fedFile.open(hdf5fedFile,FILE_READ);
|
||||
|
||||
// Vector for the tetrahedorn nodes and the material tag.
|
||||
std::vector< std::vector<unsigned int> > elem;
|
||||
std::vector<unsigned int> materialIndex;
|
||||
|
||||
|
||||
// Read the tetrahedrons of the h5fed file an print them.
|
||||
h5fedFile.rTetrahedron((unsigned int)0, elem, materialIndex);
|
||||
for(int varI = 0; varI<elem.size(); varI++)
|
||||
{
|
||||
rDebug("Tet number: %d; nodes: %d %d; %d %d; material index: %d",
|
||||
varI,
|
||||
elem[varI][0],
|
||||
elem[varI][1],
|
||||
elem[varI][2],
|
||||
elem[varI][3],
|
||||
materialIndex[varI]);
|
||||
}
|
||||
|
||||
|
||||
// Read the 3d coordinates of the h5fed file an print them.
|
||||
std::vector<std::vector< double> > coord;
|
||||
h5fedFile.rCoord3d(coord);
|
||||
for(int varI = 0; varI<coord.size(); varI++)
|
||||
{
|
||||
rDebug("Coor Number %d; Coord3d: %f; %f; %f",
|
||||
varI,
|
||||
coord[varI][0],
|
||||
coord[varI][1],
|
||||
coord[varI][2]);
|
||||
}
|
||||
// Close H5Fed file.
|
||||
h5fedFile.close();
|
||||
|
||||
#endif // HAVE_HDF5
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
// rights - 2006-, copyright by
|
||||
// benedikt oswald and patrick leidenberger,
|
||||
// all rights reserved
|
||||
// project - h5feddump
|
||||
// file name - h5feddump.hh
|
||||
// file type - c++ header file
|
||||
// objective - header file for the h5feddump
|
||||
// modified - 2006 sep 21, creation, Patrick Leidenberger
|
||||
// modified - 2006 sep 22, pl, add dump for coordinates.
|
||||
|
||||
#ifndef H5FEDDUMP_H_
|
||||
#define H5FEDDUMP_H_
|
||||
|
||||
/* include standard header files */
|
||||
#include <cmath>
|
||||
#include <complex>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
#include <math.h>
|
||||
|
||||
/* Include the files for rlog. */
|
||||
#include <rlog/rlog.h>
|
||||
#include <rlog/rloglocation.h>
|
||||
#include <rlog/Error.h>
|
||||
#include <rlog/RLogChannel.h>
|
||||
#include <rlog/StdioNode.h>
|
||||
// Include this if you want to log the time.
|
||||
#include <rlog/RLogTime.h>
|
||||
|
||||
// Include the boost program program_options to parse the comand line
|
||||
// options.
|
||||
#include <boost/program_options.hpp>
|
||||
|
||||
|
||||
/* include standard proprietary header files */
|
||||
#include <nonsciconst.h>
|
||||
#include <physicomath.h>
|
||||
|
||||
// Include the Hdf5FiniteElementData API.
|
||||
#ifdef HAVE_HDF5
|
||||
// Include the Hdf5FiniteElementData API.
|
||||
#include <h5fed.hh>
|
||||
// Include h5fed specific constants.
|
||||
#include <h5fedconst.hh>
|
||||
#else
|
||||
#warning No hdf5 lib found!!
|
||||
#endif
|
||||
|
||||
using namespace physicomath;
|
||||
using namespace nonsciconst;
|
||||
using namespace H5Fed;
|
||||
//using namespace gmshtohdf5fed;
|
||||
|
||||
#endif /*PHIDIAS3D_H_*/
|
||||
@@ -4,11 +4,12 @@
|
||||
## modified - 2006 aug 21, patrick leidenberger, creation
|
||||
## modified - 2006 aug 23, pl, adaped to changed directory structure.
|
||||
## modified - 2006 aug 25, pl, adaped to changed directory structure.
|
||||
## modified - 2006 sep 21, pl, add the h5feddump application.
|
||||
#
|
||||
## objective - automake input file for the gmsh directory
|
||||
## project - gmsh2h5fed
|
||||
|
||||
noinst_PROGRAMS = gmsh2h5fed
|
||||
noinst_PROGRAMS = gmsh2h5fed h5feddump
|
||||
|
||||
gmsh2h5fed_SOURCES = gmsh2h5fed.cc
|
||||
gmsh2h5fed_DEPENDENCIES = ../libsrc/stdincl/nonsciconst.h \
|
||||
@@ -23,4 +24,14 @@ gmsh2h5fed_DEPENDENCIES = ../libsrc/stdincl/nonsciconst.h \
|
||||
|
||||
gmsh2h5fed_LDADD = @GMSH2H5FED_LIBS@
|
||||
|
||||
|
||||
h5feddump_SOURCES = h5feddump.cc
|
||||
h5feddump_DEPENDENCIES = ../libsrc/stdincl/nonsciconst.h \
|
||||
../libsrc/stdincl/physicomath.h \
|
||||
../libsrc/h5fed/h5fed.hh \
|
||||
../libsrc/h5fed/h5fed.cc
|
||||
|
||||
h5feddump_LDADD = @H5FEDDUMP_LIBS@
|
||||
|
||||
|
||||
#AM_CPPFLAGS = @AM_CPPFLAGS@
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
## author - benedikt oswald and patrick leidenberger
|
||||
## modified - 2006 aug 21, pl, creation.
|
||||
## modified - 2006 aug 24, pl, add h5fed path.
|
||||
## modified - 2006 sep 21, pl, add h5feddump libs.
|
||||
##
|
||||
## to do : The rlog lib needs a -DRLOG_COMPONENT="some name", I don't know
|
||||
## how tho do this so that the quotation marks are in the output
|
||||
@@ -33,6 +34,7 @@ CXXFLAGS=""
|
||||
# provide include directories
|
||||
AC_SUBST([AM_CPPFLAGS], '-I$(top_srcdir)/libsrc/stdincl -I$(top_srcdir)/libsrc/gmsh -I$(top_srcdir)/libsrc/h5fed')
|
||||
AC_SUBST([GMSH2H5FED_LIBS],'$(top_srcdir)/libsrc/gmsh/libgmsh.la $(top_srcdir)/libsrc/h5fed/libh5fed.la')
|
||||
AC_SUBST([H5FEDDUMP_LIBS],'$(top_srcdir)/libsrc/h5fed/libh5fed.la')
|
||||
|
||||
# Make available external libraries
|
||||
AC_ARG_WITH(boost,
|
||||
|
||||
+336
-35
@@ -5,6 +5,7 @@
|
||||
// objective - declare class for HDF5/ELECTROMAGNETIC file format access
|
||||
// modified - 2006 jun 26, creation, benedikt oswald
|
||||
// modified - 2006 aug 26, pl, integrate automatic index mapping.
|
||||
// modified - 2006 sep 22, pl, add output functions for tets and coordinates.
|
||||
// inheritance -
|
||||
// feature - declares the base class for HDF5/ELECTROMAGNETIC file format access;
|
||||
// feature - this class is completely self contained, i.e. it does not need anything
|
||||
@@ -163,7 +164,7 @@ public:
|
||||
// and consecutive index set for the hdf5fed file.
|
||||
// The indexVec holdes the numbers of the nodes in the same way, as the
|
||||
// nodes are in the node vector.
|
||||
int beginIndexMapping(std::vector<unsigned int>* indexVec)
|
||||
int beginIndexMapping(std::vector<unsigned int>& indexVec)
|
||||
{
|
||||
rDebug("Begin automatic index mapping.");
|
||||
doIndexMapping_ = true;
|
||||
@@ -171,9 +172,9 @@ public:
|
||||
positionMap_.clear();
|
||||
|
||||
// Copy the old index to the map as map-key.
|
||||
for(unsigned int varI = 0; varI < indexVec->size(); varI++)
|
||||
for(unsigned int varI = 0; varI < indexVec.size(); varI++)
|
||||
{
|
||||
indexMap_.insert(make_pair((*indexVec)[varI],0));
|
||||
indexMap_.insert(make_pair(indexVec[varI],0));
|
||||
}
|
||||
// Number all elements in the map consecutive, starting with zero, that
|
||||
// is the new index set.
|
||||
@@ -187,10 +188,10 @@ public:
|
||||
}
|
||||
// The first column contains the new index, the second the old position
|
||||
// of the coordinate in the vector.
|
||||
for(unsigned int varI = 0; varI < indexVec->size(); varI++)
|
||||
for(unsigned int varI = 0; varI < indexVec.size(); varI++)
|
||||
{
|
||||
positionMap_.insert(make_pair(
|
||||
(indexMap_.find((*indexVec)[varI]))->second,varI));
|
||||
(indexMap_.find(indexVec[varI]))->second,varI));
|
||||
}
|
||||
return OKCODE;
|
||||
};
|
||||
@@ -206,7 +207,7 @@ public:
|
||||
};
|
||||
|
||||
// Write 3dim coordinates to h5fed file.
|
||||
int coord3d (std::vector<std::vector<double> >* coord)
|
||||
int wCoord3d (std::vector<std::vector<double> >& coord)
|
||||
{
|
||||
// All these operations are only allowed, if there is a valid file
|
||||
// identifier.
|
||||
@@ -224,7 +225,7 @@ public:
|
||||
// Number of rows: as much as coordinates.
|
||||
// Number of colums: 3, one for each dimension.
|
||||
hsize_t dim[2];
|
||||
dim[0] = coord->size();
|
||||
dim[0] = coord.size();
|
||||
dim[1] = 3;
|
||||
|
||||
// We copy the coordinates from coord in an standart array, so that
|
||||
@@ -263,7 +264,8 @@ public:
|
||||
|
||||
// Create dataset of full size.
|
||||
hdf5DatasetId = H5Dcreate(hdf5FileIdent_, H5FED_D_COORD3D.c_str(),
|
||||
H5T_IEEE_F64LE, hdf5DataspaceId, H5P_DEFAULT);
|
||||
H5FED_COORD_DATATYPE,
|
||||
hdf5DataspaceId, H5P_DEFAULT);
|
||||
|
||||
|
||||
|
||||
@@ -286,9 +288,9 @@ public:
|
||||
// Do not copy the next in the input vector, copy the coord
|
||||
// with the next following number.
|
||||
if (doIndexMapping_ == true)
|
||||
coordinate[varJ] = (*coord)[iter->second][varJ];
|
||||
coordinate[varJ] = coord[iter->second][varJ];
|
||||
else
|
||||
coordinate[varJ] = (*coord)[varI][varJ];
|
||||
coordinate[varJ] = coord[varI][varJ];
|
||||
}
|
||||
|
||||
// Select hyperslab ('region') in file dataspace.
|
||||
@@ -329,21 +331,160 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
// Read and return tetrahedron on of the given level.
|
||||
std::vector<std::vector<unsigned int> > tetrahedron(unsigned int level)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Write 3dim coordinates to h5fed file.
|
||||
int rCoord3d (std::vector<std::vector<double> >& coord)
|
||||
{
|
||||
rError("The function: tetrahedron(unsigned int level) is not implemented.");
|
||||
// All these operations are only allowed, if there is a valid file
|
||||
// identifier.
|
||||
if (hdf5FileIdent_ >= 0)
|
||||
{
|
||||
// The name of the dataset.
|
||||
std::string datasetName = H5FED_D_COORD3D;
|
||||
// Define the rank of the different dataspaces.
|
||||
const int rank = 2;
|
||||
// Hdf5 error handling variable for Hdf5 actions.
|
||||
herr_t hdf5Status;
|
||||
// Hdf5 dataspace identifier.
|
||||
hid_t hdf5DataspaceId;
|
||||
// Hdf5 dataset identifier.
|
||||
hid_t hdf5DatasetId;
|
||||
// Open the hdf5 dataset.
|
||||
hdf5DatasetId = H5Dopen(hdf5FileIdent_, datasetName.c_str());
|
||||
// Get the dataspace from the dataset.
|
||||
hdf5DataspaceId = H5Dget_space(hdf5DatasetId);
|
||||
// Read the dimension of the file dataspace.
|
||||
hsize_t dim_out[rank];
|
||||
hdf5Status = H5Sget_simple_extent_dims(hdf5DataspaceId, dim_out,
|
||||
H5P_DEFAULT);
|
||||
|
||||
// Get the datatype of the datas we want to read.
|
||||
hid_t dataType;
|
||||
dataType = H5Dget_type(hdf5DatasetId);
|
||||
|
||||
// Resize the element and material index vector to dataspace size.
|
||||
coord.clear();
|
||||
coord.resize(dim_out[0]);
|
||||
for (unsigned int varI = 0; varI < coord.size(); varI++)
|
||||
{
|
||||
coord[varI].resize(dim_out[1]);
|
||||
}
|
||||
|
||||
rDebug("dim_out[0]: %d",dim_out[0]);
|
||||
rDebug("dim_out[1]: %d",dim_out[1]);
|
||||
|
||||
// We copy the coordinates from coord in an standart array, so that
|
||||
// hdf5 can handle it.
|
||||
// We do this in portions, so we save memory.
|
||||
|
||||
// Subdimension of hyperslab in memory: 1 line, 3 columns.
|
||||
hsize_t dim_sub_mem[2];
|
||||
dim_sub_mem[0] = 1;
|
||||
dim_sub_mem[1] = dim_out[1];
|
||||
// Subdimension of hyperslab in file: 1 line, 3 columns.
|
||||
hsize_t dim_sub_file[2];
|
||||
dim_sub_file[0] = 1;
|
||||
dim_sub_file[1] = dim_out[1];
|
||||
// Define the offset for reading the file.
|
||||
hsize_t offset_file[2];
|
||||
offset_file[0] = 0; // Row only at the beginning. We iterate over it.
|
||||
offset_file[1] = 0; // We have no offset respective to the column.
|
||||
// Define the offset for writing into the memory.
|
||||
// Always fixed.
|
||||
hsize_t offset_mem[2];
|
||||
offset_mem[0] = 0;
|
||||
offset_mem[1] = 0;
|
||||
|
||||
// Array for x, y and z component of one coordinate.
|
||||
double coordinate[dim_out[1]];
|
||||
|
||||
// Loop over all rows of the dataset (file) and copy the coord vector
|
||||
// element wise.
|
||||
for (unsigned int varI = 0; varI < dim_out[0]; varI++)
|
||||
{
|
||||
// Iterate over the rows in file dataspace.
|
||||
offset_file[0] = varI;
|
||||
|
||||
// Select hyperslab ('region') in file dataspace.
|
||||
hdf5Status = H5Sselect_hyperslab(hdf5DataspaceId, H5S_SELECT_SET,
|
||||
offset_file, H5P_DEFAULT,
|
||||
dim_sub_file, H5P_DEFAULT);
|
||||
|
||||
// Define memory Dataspace.
|
||||
hid_t hdf5MemspaceId;
|
||||
hdf5MemspaceId = H5Screate_simple(rank, dim_sub_mem, H5P_DEFAULT);
|
||||
// Select hyperslab ('region') in memory.
|
||||
hdf5Status = H5Sselect_hyperslab(hdf5MemspaceId, H5S_SELECT_SET,
|
||||
offset_mem, H5P_DEFAULT,
|
||||
dim_sub_mem, H5P_DEFAULT);
|
||||
|
||||
// Copy dataset to dataset from memory to file.
|
||||
hdf5Status = H5Dread(hdf5DatasetId, dataType,
|
||||
hdf5MemspaceId, hdf5DataspaceId,
|
||||
H5P_DEFAULT, coordinate);
|
||||
H5Sclose(hdf5MemspaceId);
|
||||
|
||||
// Copy every element of a coordinate.
|
||||
for (unsigned int varJ = 0; varJ < dim_out[1]; varJ++)
|
||||
{
|
||||
coord[varI][varJ]=coordinate[varJ];
|
||||
}
|
||||
}
|
||||
|
||||
// Close hdf5 identifier.
|
||||
hdf5Status = H5Dclose(hdf5DatasetId);
|
||||
hdf5Status = H5Sclose(hdf5DataspaceId);
|
||||
|
||||
return OKCODE;
|
||||
}
|
||||
else
|
||||
{
|
||||
rError("You cannot operate to dataset %s.",H5FED_D_COORD3D.c_str());
|
||||
rError("There is no valid file identifier.");
|
||||
return ERRORCODE;
|
||||
}
|
||||
};
|
||||
// Copy the tetrahedon elements to the h5fed file.
|
||||
int tetrahedron(unsigned int level,
|
||||
std::vector< std::vector<unsigned int> >* elem)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Read and return tetrahedrons and respective material index of the
|
||||
// given level.
|
||||
int rTetrahedron(unsigned int level,
|
||||
std::vector<std::vector<unsigned int> >& elem,
|
||||
std::vector<unsigned int>& materialIndex)
|
||||
{
|
||||
// Set the name of the dataset, we want to read.
|
||||
string datasetName = H5FED_D_TETMESH;
|
||||
rElement_(datasetName, level, elem, materialIndex);
|
||||
return OKCODE;
|
||||
};
|
||||
|
||||
// Copy the tetrahedon elements to the h5fed filse.
|
||||
int wTetrahedron(unsigned int level,
|
||||
std::vector< std::vector<unsigned int> >& elem,
|
||||
std::vector<unsigned int>& materialIndex)
|
||||
{
|
||||
// Set dimension of an elements vector.
|
||||
unsigned int elemDim = H5FED_TET_N_NODE;
|
||||
// Set the name of the dataset, we want to operate.
|
||||
string datasetName = H5FED_D_TETMESH;
|
||||
// Select the data type in which the elements should be stored.
|
||||
hid_t dataType = H5FED_MESH_ELEM_DATATYPE;
|
||||
// This function does the real work for all elements.
|
||||
element_(level, elem, datasetName, elemDim);
|
||||
wElement_(datasetName, level, elemDim, elem, materialIndex, dataType);
|
||||
return OKCODE;
|
||||
|
||||
}
|
||||
@@ -351,10 +492,21 @@ public:
|
||||
// This function gets some attributes of the element, it should insert and
|
||||
// insert it to the given dataset.
|
||||
// Here we do the index mapping.
|
||||
int element_(unsigned int level,
|
||||
std::vector< std::vector<unsigned int> >* elem,
|
||||
std::string datasetNameBlank,
|
||||
unsigned int elemDim )
|
||||
// datasetNameBlank: the name of the elements dataset without the level!
|
||||
// (example: ../TETMESH_L)
|
||||
// level: the hierarchy level of the elements.
|
||||
// elemDim: the number of nodes a single element has (tet = 4, line = 2, ..)
|
||||
// elem: the outer vector contains all elements,
|
||||
// the inner vector contains the elements node numbers
|
||||
// materialIndex: the material index to an element.
|
||||
// elementType: this is the element type we use to store the elements and
|
||||
// the material index in the file.
|
||||
int wElement_(std::string datasetNameBlank,
|
||||
unsigned int level,
|
||||
unsigned int elemDim,
|
||||
std::vector< std::vector<unsigned int> >& elem,
|
||||
std::vector<unsigned int>& materialIndex,
|
||||
hid_t dataType)
|
||||
{
|
||||
// All these operations are only allowed, if there is a valid file
|
||||
// identifier.
|
||||
@@ -372,11 +524,13 @@ public:
|
||||
{
|
||||
rError("Dataspace %s already exists!", datasetName.c_str());
|
||||
rError("You cannot insert it twice.");
|
||||
rError("Exit.");
|
||||
exit(ERRORCODE);
|
||||
}
|
||||
else
|
||||
{
|
||||
// INSERT COMMENT HERE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
// We need no check for level 0.
|
||||
// If the level is higher than zero, check if levle-1 exists.
|
||||
if (level > 0)
|
||||
{
|
||||
if (!(existsDataspace(datasetNameBlank + stringify(level-1))))
|
||||
@@ -384,7 +538,7 @@ public:
|
||||
rError("You insert level %d while level %d does not exists.",
|
||||
level, level-1);
|
||||
rError("So the %s levels will be not consective.",
|
||||
datasetNameBlank);
|
||||
datasetNameBlank.c_str());
|
||||
rError("Exit.");
|
||||
exit(ERRORCODE);
|
||||
}
|
||||
@@ -401,9 +555,10 @@ public:
|
||||
// Define the dimension of the data array.
|
||||
hsize_t dim[2];
|
||||
// Number of rows: as much as elements.
|
||||
dim[0] = elem->size();
|
||||
// Number of colums: dimenstion of an elements vector.
|
||||
dim[1] = elemDim;
|
||||
dim[0] = elem.size();
|
||||
// Number of colums: dimenstion of an elements vector + 1.
|
||||
// We need the extra column as index in the material list!
|
||||
dim[1] = elemDim + 1;
|
||||
|
||||
// We copy the element nodes from a element in an standart array,
|
||||
// so that hdf5 can handle it.
|
||||
@@ -412,11 +567,11 @@ public:
|
||||
// Subdimension of hyperslab in memory: 1 line, elemDim columns.
|
||||
hsize_t dim_sub_mem[2];
|
||||
dim_sub_mem[0] = 1;
|
||||
dim_sub_mem[1] = elemDim;
|
||||
dim_sub_mem[1] = dim[1];
|
||||
// Subdimension of hyperslab in file: 1 line, elemDim columns.
|
||||
hsize_t dim_sub_file[2];
|
||||
dim_sub_file[0] = 1;
|
||||
dim_sub_file[1] = elemDim;
|
||||
dim_sub_file[1] = dim[1];
|
||||
// Define the offset for reading from the memory.
|
||||
// Always fixed, because memory has exactly the same size.
|
||||
hsize_t offset_mem[2];
|
||||
@@ -428,33 +583,33 @@ public:
|
||||
offset_file[1] = 0; // We have no offset respective to the column.
|
||||
|
||||
// Array for single elements of an element vector.
|
||||
unsigned int element[elemDim];
|
||||
unsigned int element[dim[1]];
|
||||
|
||||
// Dimesion and datatype of the file dataset, read out form file.
|
||||
// This is not the fastest, but the most robust way.
|
||||
hsize_t dim_out[2];
|
||||
hid_t dataType;
|
||||
|
||||
// Create dataspace of full size.
|
||||
hdf5DataspaceId = H5Screate_simple(rank, dim, H5P_DEFAULT);
|
||||
|
||||
// Create dataset of full size.
|
||||
hdf5DatasetId = H5Dcreate(hdf5FileIdent_, datasetName.c_str(),
|
||||
H5T_STD_U32LE, hdf5DataspaceId, H5P_DEFAULT);
|
||||
dataType, hdf5DataspaceId, H5P_DEFAULT);
|
||||
|
||||
// Loop over all rows of the dataset (file) and copy the elem vector
|
||||
// row wise.
|
||||
hdf5Status = H5Sget_simple_extent_dims(hdf5DataspaceId, dim_out,
|
||||
H5P_DEFAULT);
|
||||
// Get the datatype of the datas we want to write.
|
||||
dataType = H5Dget_type(hdf5DatasetId);
|
||||
// dataType = H5Dget_type(hdf5DatasetId);
|
||||
for (unsigned int varI = 0; varI < dim_out[0]; varI++)
|
||||
{
|
||||
// Iterate over the rows in file dataspace.
|
||||
offset_file[0] = varI;
|
||||
|
||||
// Copy every element of a coordinate.
|
||||
for (unsigned int varJ = 0; varJ < dim_out[1]; varJ++)
|
||||
// Remember: the last column is an index in the material list!
|
||||
for (unsigned int varJ = 0; varJ < dim_out[1] - 1; varJ++)
|
||||
{
|
||||
// Here is the only special case for automated mapping:
|
||||
// Do not copy the next in the input vector, copy the coord
|
||||
@@ -462,12 +617,17 @@ public:
|
||||
if (doIndexMapping_ == true)
|
||||
{
|
||||
std::map<unsigned int, unsigned int>::iterator iter;
|
||||
iter = indexMap_.find((*elem)[varI][varJ]);
|
||||
iter = indexMap_.find((elem)[varI][varJ]);
|
||||
element[varJ] = iter->second;
|
||||
}
|
||||
else
|
||||
element[varJ] = (*elem)[varI][varJ];
|
||||
element[varJ] = (elem)[varI][varJ];
|
||||
}
|
||||
|
||||
// Set the appropriate material list!
|
||||
// ===> This is not implementes yet! <===
|
||||
// See warning above.
|
||||
element[dim_out[1]-1] = 0;
|
||||
|
||||
// Select hyperslab ('region') in file dataspace.
|
||||
hdf5Status = H5Sselect_hyperslab(hdf5DataspaceId, H5S_SELECT_SET,
|
||||
@@ -499,11 +659,152 @@ public:
|
||||
{
|
||||
rError("You cannot operate to a dataset.");
|
||||
rError("There is no valid file identifier.");
|
||||
rError("Exit.");
|
||||
exit(ERRORCODE);
|
||||
}
|
||||
};
|
||||
|
||||
// This function gets the level and name of an element in
|
||||
// a H5Fed file and returns the element nodes and material tag as a
|
||||
// vetor of vectors and a vector.
|
||||
// datasetNameBlank: the name of the elements dataset without the level!
|
||||
// (example: ../TETMESH_L)
|
||||
// level: the hierarchy level of the elements.
|
||||
// elem: the outer vector gets all elements,
|
||||
// the inner vectors get the elements node numbers.
|
||||
// materialIndex: the material index to an elemen.
|
||||
int rElement_(std::string datasetNameBlank,
|
||||
unsigned int level,
|
||||
std::vector< std::vector<unsigned int> >& elem,
|
||||
std::vector<unsigned int>& materialIndex)
|
||||
{
|
||||
// All these operations are only allowed, if there is a valid file
|
||||
// identifier.
|
||||
if (hdf5FileIdent_ >= 0)
|
||||
{
|
||||
// Make datasetName with the datasetNameBlank and the level.
|
||||
string datasetName = datasetNameBlank + stringify(level);
|
||||
|
||||
// Check if the dataset with the given datasetName exists:
|
||||
// if it does not return errorcode, else continue.
|
||||
if (!(existsDataspace(datasetName)))
|
||||
{
|
||||
rDebug("Dataspace %s does not exists!", datasetName.c_str());
|
||||
rDebug("So you cannot read.");
|
||||
return ERRORCODE;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Define the rank of the different dataspaces.
|
||||
const int rank = 2;
|
||||
// Hdf5 error handling variable for Hdf5 actions.
|
||||
herr_t hdf5Status;
|
||||
|
||||
// Hdf5 dataspace identifier.
|
||||
hid_t hdf5DataspaceId;
|
||||
|
||||
// Hdf5 dataset identifier.
|
||||
hid_t hdf5DatasetId;
|
||||
// Open the hdf5 dataset.
|
||||
hdf5DatasetId = H5Dopen(hdf5FileIdent_, datasetName.c_str());
|
||||
|
||||
// Get the dataspace from the dataset.
|
||||
hdf5DataspaceId = H5Dget_space(hdf5DatasetId);
|
||||
|
||||
// Read the dimension of the file dataspace.
|
||||
hsize_t dim_out[2];
|
||||
hdf5Status = H5Sget_simple_extent_dims(hdf5DataspaceId, dim_out,
|
||||
H5P_DEFAULT);
|
||||
|
||||
// Get the datatype of the datas we want to read.
|
||||
hid_t dataType;
|
||||
dataType = H5Dget_type(hdf5DatasetId);
|
||||
|
||||
// Resize the element and material index vector to dataspace size.
|
||||
elem.clear();
|
||||
elem.resize(dim_out[0]);
|
||||
for (unsigned int varI = 0; varI < elem.size(); varI++)
|
||||
{
|
||||
elem[varI].resize(dim_out[1]);
|
||||
}
|
||||
materialIndex.clear();
|
||||
materialIndex.resize(dim_out[0]);
|
||||
|
||||
// We copy a line from file to a standart array, and the array to a
|
||||
// stl::vector of vector so that hdf5 can handle it.
|
||||
// We do this for every element separate, so we save memory.
|
||||
|
||||
// Subdimension of hyperslab in memory: 1 line, elemDim columns.
|
||||
hsize_t dim_sub_mem[2];
|
||||
dim_sub_mem[0] = 1;
|
||||
dim_sub_mem[1] = dim_out[1];
|
||||
// Subdimension of hyperslab in file: 1 line, elemDim columns.
|
||||
hsize_t dim_sub_file[2];
|
||||
dim_sub_file[0] = 1;
|
||||
dim_sub_file[1] = dim_out[1];
|
||||
// Define the offset for reading into the file.
|
||||
hsize_t offset_file[2];
|
||||
offset_file[0] = 0; // Row ofsett zero only at the beginning.
|
||||
offset_file[1] = 0; // We have no offset respective to the column.
|
||||
// Define the offset for writing to the memory.
|
||||
// Always fixed, because memory has exactly the same size.
|
||||
hsize_t offset_mem[2];
|
||||
offset_mem[0] = 0;
|
||||
offset_mem[1] = 0;
|
||||
|
||||
// Array for single elements in memory.
|
||||
unsigned int element[dim_out[1]];
|
||||
|
||||
// Loop over all rows of the dataset (file) and copy the elem vector
|
||||
// row wise.
|
||||
for (unsigned int varI = 0; varI < dim_out[0]; varI++)
|
||||
{
|
||||
// Iterate over the rows in file dataspace.
|
||||
offset_file[0] = varI;
|
||||
|
||||
// Select hyperslab ('region') in file dataspace.
|
||||
hdf5Status = H5Sselect_hyperslab(hdf5DataspaceId, H5S_SELECT_SET,
|
||||
offset_file, H5P_DEFAULT,
|
||||
dim_sub_file, H5P_DEFAULT);
|
||||
// Define memory Dataspace.
|
||||
hid_t hdf5MemspaceId;
|
||||
hdf5MemspaceId = H5Screate_simple(rank, dim_sub_mem, H5P_DEFAULT);
|
||||
// Select hyperslab ('region') in memory.
|
||||
hdf5Status = H5Sselect_hyperslab(hdf5MemspaceId, H5S_SELECT_SET,
|
||||
offset_mem, H5P_DEFAULT,
|
||||
dim_sub_mem, H5P_DEFAULT);
|
||||
// Copy dataset to dataset from file to memory.
|
||||
hdf5Status = H5Dread(hdf5DatasetId, dataType,
|
||||
hdf5MemspaceId, hdf5DataspaceId,
|
||||
H5P_DEFAULT, element);
|
||||
// Close the memory space identifier.
|
||||
H5Sclose(hdf5MemspaceId);
|
||||
|
||||
// Copy every element of a coordinate.
|
||||
// Remember: the last column is an index in the material list!
|
||||
for (unsigned int varJ = 0; varJ < dim_out[1]-1; varJ++)
|
||||
{
|
||||
elem[varI][varJ] = element[varJ];
|
||||
}
|
||||
// Copy the material index in the appropriate vector.
|
||||
materialIndex[varI] = element[dim_out[1]-1];
|
||||
}
|
||||
|
||||
// Close hdf5 identifier.
|
||||
hdf5Status = H5Sclose(hdf5DataspaceId);
|
||||
hdf5Status = H5Dclose(hdf5DatasetId);
|
||||
|
||||
return OKCODE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
rError("You cannot operate to a dataset.");
|
||||
rError("There is no valid file identifier.");
|
||||
rError("Exit.");
|
||||
exit(ERRORCODE);
|
||||
}
|
||||
};
|
||||
|
||||
// Write 3dim coordinates to h5fed file.
|
||||
bool existsDataspace (std::string dataspaceName)
|
||||
|
||||
@@ -2,6 +2,10 @@
|
||||
#define H5FEDCONST_HH_
|
||||
|
||||
#include<string>
|
||||
|
||||
// Include HDF5 headers.
|
||||
#include <hdf5.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
//! Hdf5 specific file access:
|
||||
@@ -46,5 +50,10 @@ const unsigned short int H5FED_PYRAMID_N_NODE = 5;
|
||||
const unsigned short int H5FED_TRIANGLE_N_NODE = 3;
|
||||
const unsigned short int H5FED_QUADRANGLE_N_NODE = 4;
|
||||
|
||||
// In which format should a single element of a mesh entity and the
|
||||
// index to the material list be stored.
|
||||
const hid_t H5FED_MESH_ELEM_DATATYPE = H5T_STD_U32LE;
|
||||
const hid_t H5FED_COORD_DATATYPE = H5T_IEEE_F64LE;
|
||||
|
||||
|
||||
#endif /*H5FEDCONST_HH_*/
|
||||
|
||||
Reference in New Issue
Block a user