Commit 27e3b6ed authored by Kenneth Leiter's avatar Kenneth Leiter

ENH: Add tests using new XdmfHDF5Writer exclusively. Modify some methods in...

ENH: Add tests using new XdmfHDF5Writer exclusively.  Modify some methods in XdmfHDF5Writer to get everything working as expected.
parent 5ed3eebe
......@@ -84,6 +84,9 @@ SWIG_SHARED_PTR_DERIVED(XdmfGeometry, XdmfItem);
SWIG_SHARED_PTR_DERIVED(XdmfGeometry, XdmfObject);
SWIG_SHARED_PTR_DERIVED(XdmfGrid, XdmfItem);
SWIG_SHARED_PTR_DERIVED(XdmfGrid, XdmfObject);
SWIG_SHARED_PTR_DERIVED(XdmfHDF5Writer, XdmfVisitor);
SWIG_SHARED_PTR_DERIVED(XdmfHDF5Writer, Loki::BaseVisitor);
SWIG_SHARED_PTR_DERIVED(XdmfHDF5Writer, XdmfObject);
SWIG_SHARED_PTR_DERIVED(XdmfItem, XdmfObject);
SWIG_SHARED_PTR_DERIVED(XdmfTopology, XdmfDataItem);
SWIG_SHARED_PTR_DERIVED(XdmfTopology, XdmfItem);
......@@ -99,6 +102,8 @@ SWIG_SHARED_PTR_DERIVED(XdmfWriter, XdmfObject);
%include XdmfItem.hpp
%include XdmfItemProperty.hpp
%include XdmfVisitor.hpp
%include XdmfHDF5Writer.hpp
%include XdmfWriter.hpp
%include XdmfDataItem.hpp
......@@ -191,4 +196,4 @@ SWIG_SHARED_PTR_DERIVED(XdmfWriter, XdmfObject);
for i in range(0, len(values)):
self.copyValueAsUInt(i+startIndex, values[i])
};
};
\ No newline at end of file
};
......@@ -15,8 +15,9 @@ class XdmfHDF5Writer::XdmfHDF5WriterImpl {
public:
XdmfHDF5WriterImpl(std::string & hdf5FilePath) :
mHDF5Handle(H5Fcreate("output.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)),
mHeavyFileName("output.h5")
mHDF5Handle(H5Fcreate(hdf5FilePath.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)),
mHeavyFileName(hdf5FilePath),
mLastWrittenDataSet("")
{
};
~XdmfHDF5WriterImpl()
......@@ -26,6 +27,7 @@ public:
std::vector<std::string> mDataHierarchy;
hid_t mHDF5Handle;
std::string mHeavyFileName;
std::string mLastWrittenDataSet;
};
class XdmfHDF5Writer::GetHDF5Type : public boost::static_visitor <hid_t> {
......@@ -145,6 +147,11 @@ std::string XdmfHDF5Writer::getHDF5GroupHandle()
return "";
}
std::string XdmfHDF5Writer::getLastWrittenDataSet() const
{
return mImpl->mLastWrittenDataSet;
}
void XdmfHDF5Writer::popDataHierarchy()
{
mImpl->mDataHierarchy.pop_back();
......@@ -164,7 +171,7 @@ void XdmfHDF5Writer::pushDataHierarchy(const XdmfItem & item)
}
}
std::string XdmfHDF5Writer::visit(XdmfArray & array, boost::shared_ptr<Loki::BaseVisitor> visitor)
void XdmfHDF5Writer::visit(XdmfArray & array, boost::shared_ptr<Loki::BaseVisitor> visitor)
{
hid_t datatype = -1;
if(array.mHaveArray)
......@@ -199,9 +206,9 @@ std::string XdmfHDF5Writer::visit(XdmfArray & array, boost::shared_ptr<Loki::Bas
std::stringstream dataSetName;
dataSetName << mImpl->mHeavyFileName << ":" << groupName << "/" << mImpl->mDataHierarchy.back();
return dataSetName.str();
mImpl->mLastWrittenDataSet = dataSetName.str();
}
return "";
mImpl->mLastWrittenDataSet = "";
}
void XdmfHDF5Writer::visit(XdmfItem & item, boost::shared_ptr<Loki::BaseVisitor> visitor)
......
......@@ -15,7 +15,7 @@ class XdmfArray;
* as the parameter.
*/
class XdmfHDF5Writer : public XdmfVisitor,
public Loki::Visitor<XdmfArray, std::string> {
public Loki::Visitor<XdmfArray> {
public:
......@@ -26,6 +26,13 @@ public:
return p;
}
/**
* Get the path to the last written data set written by this writer.
*
* @return the path to the last written data set.
*/
std::string getLastWrittenDataSet() const;
/**
* Pop a string from the data hierarchy. This should be called whenever an XdmfItem is finished
* traversal, including in light data writers that work in conjunction with this heavy data writer.
......@@ -48,10 +55,8 @@ public:
*
* @param array an XdmfArray to write to HDF5.
* @param visitor a smart pointer to this visitor --- aids in grid traversal.
*
* @return a string containing the path to the hdf5 dataset written.
*/
std::string visit(XdmfArray & array, boost::shared_ptr<Loki::BaseVisitor> visitor);
void visit(XdmfArray & array, boost::shared_ptr<Loki::BaseVisitor> visitor);
/**
* Traverse an XdmfItem structure in order to find XdmfArrays to write to HDF5.
......
......@@ -69,7 +69,8 @@ void XdmfWriter::visit(XdmfArray & array, boost::shared_ptr<Loki::BaseVisitor> v
std::stringstream xmlTextValues;
if(array.getSize() > mImpl->mLightDataLimit)
{
xmlTextValues << mImpl->mHDF5Writer->visit(array, mImpl->mHDF5Writer);
mImpl->mHDF5Writer->visit(array, mImpl->mHDF5Writer);
xmlTextValues << mImpl->mHDF5Writer->getLastWrittenDataSet();
}
else
{
......
......@@ -309,6 +309,7 @@ struct DefaultCatchAll
{ \
if (Loki::Visitor<my_class,ReturnType>* p = dynamic_cast<Loki::Visitor<my_class,ReturnType>*>(guest.get())) \
{ \
std::cout << "HERE" << std::endl; \
return p->visit(*this, guest); \
} \
else \
......
......@@ -4,6 +4,7 @@ set(XdmfCxxTests
TestXdmfDataItem
TestXdmfGeometry
TestXdmfGrid
TestXdmfHDF5Writer
TestXdmfTopology
TestXdmfVisitorValueCounter
TestXdmfWriter
......
#include "XdmfHDF5Writer.hpp"
#include "XdmfTestDataGenerator.hpp"
int main(int argc, char* argv[])
{
boost::shared_ptr<XdmfHDF5Writer> writer = XdmfHDF5Writer::New("hdf5WriterTest.h5");
boost::shared_ptr<XdmfGrid> grid = XdmfTestDataGenerator::createHexahedron();
boost::shared_ptr<XdmfDomain> domain = XdmfDomain::New();
domain->insert(grid);
domain->accept(writer);
return 0;
}
......@@ -2,6 +2,7 @@ include(UsePythonTest)
set(XdmfPythonTests
TestXdmfArray.py
TestXdmfHDF5Writer.py
TestXdmfWriter.py
)
......
from Xdmf import *
if __name__ == "__main__":
writer = XdmfHDF5Writer.New("hdf5WriterPythonTest.h5")
grid = XdmfGrid.New()
grid.setName("test")
points = [0.1, 0.1, 1.1, 1.1, 0.1, 1.1, 3.1, 0.1, 2.1, 0.1, 1.1, 1.1, 1.1, 1.1, 1.1, 3.1, 2.1, 2.1,
0.1, 0.1, -1.1, 1.1, 0.1, -1.1, 3.1, 0.1, -2.1, 0.1, 1.1, -1.1, 1.1, 1.1, -1.1, 3.1, 2.1, -2.1]
grid.getGeometry().setGeometryType(XdmfGeometryType.XYZ())
grid.getGeometry().getArray().copyValuesAsDouble(0, points)
connectivity = [0, 1, 7, 6, 3, 4, 10, 9, 1, 2, 8, 7, 4, 5, 11, 10]
grid.getTopology().setTopologyType(XdmfTopologyType.Hexahedron())
grid.getTopology().getArray().copyValuesAsInt(0, connectivity)
nodalAttribute = XdmfAttribute.New()
nodalAttribute.setName("Nodal Attribute")
nodalAttribute.setAttributeType(XdmfAttributeType.Scalar())
nodalAttribute.setAttributeCenter(XdmfAttributeCenter.Node())
nodeVals = [100, 200, 300, 300, 400, 500, 300, 400, 500, 500, 600, 700]
nodalAttribute.getArray().copyValuesAsDouble(0, nodeVals)
cellAttribute = XdmfAttribute.New()
cellAttribute.setName("Cell Attribute")
cellAttribute.setAttributeType(XdmfAttributeType.Scalar())
cellAttribute.setAttributeCenter(XdmfAttributeCenter.Cell())
cellVals = [100, 200]
cellAttribute.getArray().copyValuesAsDouble(0, cellVals)
grid.insert(nodalAttribute)
grid.insert(cellAttribute)
domain = XdmfDomain.New()
domain.insert(grid)
domain.accept(writer)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment