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

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); ...@@ -84,6 +84,9 @@ SWIG_SHARED_PTR_DERIVED(XdmfGeometry, XdmfItem);
SWIG_SHARED_PTR_DERIVED(XdmfGeometry, XdmfObject); SWIG_SHARED_PTR_DERIVED(XdmfGeometry, XdmfObject);
SWIG_SHARED_PTR_DERIVED(XdmfGrid, XdmfItem); SWIG_SHARED_PTR_DERIVED(XdmfGrid, XdmfItem);
SWIG_SHARED_PTR_DERIVED(XdmfGrid, XdmfObject); 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(XdmfItem, XdmfObject);
SWIG_SHARED_PTR_DERIVED(XdmfTopology, XdmfDataItem); SWIG_SHARED_PTR_DERIVED(XdmfTopology, XdmfDataItem);
SWIG_SHARED_PTR_DERIVED(XdmfTopology, XdmfItem); SWIG_SHARED_PTR_DERIVED(XdmfTopology, XdmfItem);
...@@ -99,6 +102,8 @@ SWIG_SHARED_PTR_DERIVED(XdmfWriter, XdmfObject); ...@@ -99,6 +102,8 @@ SWIG_SHARED_PTR_DERIVED(XdmfWriter, XdmfObject);
%include XdmfItem.hpp %include XdmfItem.hpp
%include XdmfItemProperty.hpp %include XdmfItemProperty.hpp
%include XdmfVisitor.hpp %include XdmfVisitor.hpp
%include XdmfHDF5Writer.hpp
%include XdmfWriter.hpp %include XdmfWriter.hpp
%include XdmfDataItem.hpp %include XdmfDataItem.hpp
...@@ -191,4 +196,4 @@ SWIG_SHARED_PTR_DERIVED(XdmfWriter, XdmfObject); ...@@ -191,4 +196,4 @@ SWIG_SHARED_PTR_DERIVED(XdmfWriter, XdmfObject);
for i in range(0, len(values)): for i in range(0, len(values)):
self.copyValueAsUInt(i+startIndex, values[i]) self.copyValueAsUInt(i+startIndex, values[i])
}; };
}; };
\ No newline at end of file
...@@ -15,8 +15,9 @@ class XdmfHDF5Writer::XdmfHDF5WriterImpl { ...@@ -15,8 +15,9 @@ class XdmfHDF5Writer::XdmfHDF5WriterImpl {
public: public:
XdmfHDF5WriterImpl(std::string & hdf5FilePath) : XdmfHDF5WriterImpl(std::string & hdf5FilePath) :
mHDF5Handle(H5Fcreate("output.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)), mHDF5Handle(H5Fcreate(hdf5FilePath.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)),
mHeavyFileName("output.h5") mHeavyFileName(hdf5FilePath),
mLastWrittenDataSet("")
{ {
}; };
~XdmfHDF5WriterImpl() ~XdmfHDF5WriterImpl()
...@@ -26,6 +27,7 @@ public: ...@@ -26,6 +27,7 @@ public:
std::vector<std::string> mDataHierarchy; std::vector<std::string> mDataHierarchy;
hid_t mHDF5Handle; hid_t mHDF5Handle;
std::string mHeavyFileName; std::string mHeavyFileName;
std::string mLastWrittenDataSet;
}; };
class XdmfHDF5Writer::GetHDF5Type : public boost::static_visitor <hid_t> { class XdmfHDF5Writer::GetHDF5Type : public boost::static_visitor <hid_t> {
...@@ -145,6 +147,11 @@ std::string XdmfHDF5Writer::getHDF5GroupHandle() ...@@ -145,6 +147,11 @@ std::string XdmfHDF5Writer::getHDF5GroupHandle()
return ""; return "";
} }
std::string XdmfHDF5Writer::getLastWrittenDataSet() const
{
return mImpl->mLastWrittenDataSet;
}
void XdmfHDF5Writer::popDataHierarchy() void XdmfHDF5Writer::popDataHierarchy()
{ {
mImpl->mDataHierarchy.pop_back(); mImpl->mDataHierarchy.pop_back();
...@@ -164,7 +171,7 @@ void XdmfHDF5Writer::pushDataHierarchy(const XdmfItem & item) ...@@ -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; hid_t datatype = -1;
if(array.mHaveArray) if(array.mHaveArray)
...@@ -199,9 +206,9 @@ std::string XdmfHDF5Writer::visit(XdmfArray & array, boost::shared_ptr<Loki::Bas ...@@ -199,9 +206,9 @@ std::string XdmfHDF5Writer::visit(XdmfArray & array, boost::shared_ptr<Loki::Bas
std::stringstream dataSetName; std::stringstream dataSetName;
dataSetName << mImpl->mHeavyFileName << ":" << groupName << "/" << mImpl->mDataHierarchy.back(); 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) void XdmfHDF5Writer::visit(XdmfItem & item, boost::shared_ptr<Loki::BaseVisitor> visitor)
......
...@@ -15,7 +15,7 @@ class XdmfArray; ...@@ -15,7 +15,7 @@ class XdmfArray;
* as the parameter. * as the parameter.
*/ */
class XdmfHDF5Writer : public XdmfVisitor, class XdmfHDF5Writer : public XdmfVisitor,
public Loki::Visitor<XdmfArray, std::string> { public Loki::Visitor<XdmfArray> {
public: public:
...@@ -26,6 +26,13 @@ public: ...@@ -26,6 +26,13 @@ public:
return p; 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 * 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. * traversal, including in light data writers that work in conjunction with this heavy data writer.
...@@ -48,10 +55,8 @@ public: ...@@ -48,10 +55,8 @@ public:
* *
* @param array an XdmfArray to write to HDF5. * @param array an XdmfArray to write to HDF5.
* @param visitor a smart pointer to this visitor --- aids in grid traversal. * @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. * 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 ...@@ -69,7 +69,8 @@ void XdmfWriter::visit(XdmfArray & array, boost::shared_ptr<Loki::BaseVisitor> v
std::stringstream xmlTextValues; std::stringstream xmlTextValues;
if(array.getSize() > mImpl->mLightDataLimit) if(array.getSize() > mImpl->mLightDataLimit)
{ {
xmlTextValues << mImpl->mHDF5Writer->visit(array, mImpl->mHDF5Writer); mImpl->mHDF5Writer->visit(array, mImpl->mHDF5Writer);
xmlTextValues << mImpl->mHDF5Writer->getLastWrittenDataSet();
} }
else else
{ {
......
...@@ -309,6 +309,7 @@ struct DefaultCatchAll ...@@ -309,6 +309,7 @@ struct DefaultCatchAll
{ \ { \
if (Loki::Visitor<my_class,ReturnType>* p = dynamic_cast<Loki::Visitor<my_class,ReturnType>*>(guest.get())) \ 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); \ return p->visit(*this, guest); \
} \ } \
else \ else \
......
...@@ -4,6 +4,7 @@ set(XdmfCxxTests ...@@ -4,6 +4,7 @@ set(XdmfCxxTests
TestXdmfDataItem TestXdmfDataItem
TestXdmfGeometry TestXdmfGeometry
TestXdmfGrid TestXdmfGrid
TestXdmfHDF5Writer
TestXdmfTopology TestXdmfTopology
TestXdmfVisitorValueCounter TestXdmfVisitorValueCounter
TestXdmfWriter 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) ...@@ -2,6 +2,7 @@ include(UsePythonTest)
set(XdmfPythonTests set(XdmfPythonTests
TestXdmfArray.py TestXdmfArray.py
TestXdmfHDF5Writer.py
TestXdmfWriter.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