Commit 95079f5a authored by Kenneth Leiter's avatar Kenneth Leiter

ENH: Add XdmfDataItems to XdmfTopology and XdmfGeometry and write them out...

ENH: Add XdmfDataItems to XdmfTopology and XdmfGeometry and write them out correctly in the XdmfVisitor.  Verified to work with simple Hexahedron file.
parent 1e29d5ae
......@@ -136,6 +136,8 @@ class XdmfDataItemPtr(_object):
__swig_destroy__ = _Xdmf.delete_XdmfDataItemPtr
__del__ = lambda self : None;
def New(self): return _Xdmf.XdmfDataItemPtr_New(self)
def getNumberValues(self): return _Xdmf.XdmfDataItemPtr_getNumberValues(self)
def setNumberValues(self, *args): return _Xdmf.XdmfDataItemPtr_setNumberValues(self, *args)
def printSelf(self): return _Xdmf.XdmfDataItemPtr_printSelf(self)
def write(self, *args): return _Xdmf.XdmfDataItemPtr_write(self, *args)
XdmfDataItemPtr_swigregister = _Xdmf.XdmfDataItemPtr_swigregister
......@@ -159,6 +161,8 @@ class XdmfGeometryPtr(_object):
def setGeometryType(self, *args): return _Xdmf.XdmfGeometryPtr_setGeometryType(self, *args)
def getGeometryTypeAsString(self): return _Xdmf.XdmfGeometryPtr_getGeometryTypeAsString(self)
def getDimensions(self): return _Xdmf.XdmfGeometryPtr_getDimensions(self)
def getData(self, *args): return _Xdmf.XdmfGeometryPtr_getData(self, *args)
def setData(self, *args): return _Xdmf.XdmfGeometryPtr_setData(self, *args)
def printSelf(self): return _Xdmf.XdmfGeometryPtr_printSelf(self)
def write(self, *args): return _Xdmf.XdmfGeometryPtr_write(self, *args)
XdmfGeometryPtr_swigregister = _Xdmf.XdmfGeometryPtr_swigregister
......@@ -247,6 +251,8 @@ class XdmfTopologyPtr(_object):
def setNumberElements(self, *args): return _Xdmf.XdmfTopologyPtr_setNumberElements(self, *args)
def getTopologyTypeAsString(self): return _Xdmf.XdmfTopologyPtr_getTopologyTypeAsString(self)
def getNodesPerElement(self): return _Xdmf.XdmfTopologyPtr_getNodesPerElement(self)
def getData(self, *args): return _Xdmf.XdmfTopologyPtr_getData(self, *args)
def setData(self, *args): return _Xdmf.XdmfTopologyPtr_setData(self, *args)
def printSelf(self): return _Xdmf.XdmfTopologyPtr_printSelf(self)
def write(self, *args): return _Xdmf.XdmfTopologyPtr_write(self, *args)
XdmfTopologyPtr_swigregister = _Xdmf.XdmfTopologyPtr_swigregister
......@@ -462,6 +468,8 @@ class XdmfDataItem(XdmfItem):
__repr__ = _swig_repr
__swig_getmethods__["New"] = lambda x: _Xdmf.XdmfDataItem_New
if _newclass:New = staticmethod(_Xdmf.XdmfDataItem_New)
def getNumberValues(self): return _Xdmf.XdmfDataItem_getNumberValues(self)
def setNumberValues(self, *args): return _Xdmf.XdmfDataItem_setNumberValues(self, *args)
def printSelf(self): return _Xdmf.XdmfDataItem_printSelf(self)
def write(self, *args): return _Xdmf.XdmfDataItem_write(self, *args)
XdmfDataItem_swigregister = _Xdmf.XdmfDataItem_swigregister
......@@ -564,6 +572,8 @@ class XdmfGeometry(XdmfItem):
def setGeometryType(self, *args): return _Xdmf.XdmfGeometry_setGeometryType(self, *args)
def getGeometryTypeAsString(self): return _Xdmf.XdmfGeometry_getGeometryTypeAsString(self)
def getDimensions(self): return _Xdmf.XdmfGeometry_getDimensions(self)
def getData(self, *args): return _Xdmf.XdmfGeometry_getData(self, *args)
def setData(self, *args): return _Xdmf.XdmfGeometry_setData(self, *args)
def printSelf(self): return _Xdmf.XdmfGeometry_printSelf(self)
def write(self, *args): return _Xdmf.XdmfGeometry_write(self, *args)
XdmfGeometry_swigregister = _Xdmf.XdmfGeometry_swigregister
......@@ -692,6 +702,8 @@ class XdmfTopology(XdmfItem):
def setNumberElements(self, *args): return _Xdmf.XdmfTopology_setNumberElements(self, *args)
def getTopologyTypeAsString(self): return _Xdmf.XdmfTopology_getTopologyTypeAsString(self)
def getNodesPerElement(self): return _Xdmf.XdmfTopology_getNodesPerElement(self)
def getData(self, *args): return _Xdmf.XdmfTopology_getData(self, *args)
def setData(self, *args): return _Xdmf.XdmfTopology_setData(self, *args)
def printSelf(self): return _Xdmf.XdmfTopology_printSelf(self)
def write(self, *args): return _Xdmf.XdmfTopology_write(self, *args)
XdmfTopology_swigregister = _Xdmf.XdmfTopology_swigregister
......
......@@ -9,7 +9,8 @@
#include "XdmfVisitor.hpp"
XdmfDataItem::XdmfDataItem() :
mDataType(XdmfDataItemType::Unknown())
mDataType(XdmfDataItemType::Unknown()),
mNumberValues(0)
{
std::cout << "Created DataItem " << this << std::endl;
}
......@@ -31,6 +32,28 @@ void XdmfDataItem::setData<int>(int* dataPointer)
mDataType = XdmfDataItemType::Int32();
}
template <>
int* XdmfDataItem::getData<int>()
{
return mDataPointer;
}
template <>
const int* const XdmfDataItem::getData<int>() const
{
return mDataPointer;
}
int XdmfDataItem::getNumberValues() const
{
return mNumberValues;
}
void XdmfDataItem::setNumberValues(int numValues)
{
mNumberValues = numValues;
}
void XdmfDataItem::write(boost::shared_ptr<XdmfVisitor> visitor) const
{
visitor->visit(this);
......
......@@ -20,7 +20,13 @@ public:
template <typename T> void setData(T * dataPointer);
//int setData(int * dataPointer)
template <typename T> T* getData();
template <typename T> const T* const getData() const;
int getNumberValues() const;
void setNumberValues(int numValues);
std::string printSelf() const;
......@@ -38,6 +44,7 @@ private:
int* mDataPointer;
XdmfDataItemType mDataType;
int mNumberValues;
};
#endif /* XDMFDATAITEM_HPP_ */
......@@ -5,11 +5,13 @@
* Author: kleiter
*/
#include "XdmfDataItem.hpp"
#include "XdmfGeometry.hpp"
#include "XdmfVisitor.hpp"
XdmfGeometry::XdmfGeometry() :
mGeometryType(XdmfGeometryType::NoGeometryType())
mPointData(XdmfDataItem::New()),
mGeometryType(XdmfGeometryType::NoGeometryType())
{
std::cout << "Created Geometry " << this << std::endl;
}
......@@ -39,6 +41,21 @@ int XdmfGeometry::getDimensions() const
return mGeometryType.getDimensions();
}
boost::shared_ptr<XdmfDataItem> XdmfGeometry::getData()
{
return mPointData;
}
boost::shared_ptr<const XdmfDataItem> XdmfGeometry::getData() const
{
return mPointData;
}
void XdmfGeometry::setData(boost::shared_ptr<XdmfDataItem> pointData)
{
mPointData = pointData;
}
std::string XdmfGeometry::printSelf() const
{
return "XdmfGeometry";
......
......@@ -8,6 +8,8 @@
#ifndef XDMFGEOMETRY_HPP_
#define XDMFGEOMETRY_HPP_
class XdmfDataItem;
// Includes
#include "XdmfItem.hpp"
#include "XdmfGeometryType.hpp"
......@@ -33,19 +35,34 @@ public:
void setGeometryType(const XdmfGeometryType&);
/**
* Get the name of the GeometryType associated with this Geometry.
* Get the name of the XdmfGeometryType associated with this Geometry.
*
* @return std::string containing name of the GeometryType.
*/
std::string getGeometryTypeAsString() const;
/**
* Get the number of dimensions for this Geometry.
* Get the number of dimensions associated with this Geometry.
*
* @return int giving number of dimensions: i.e. XY = 2, XYZ = 3.
*/
int getDimensions() const;
/**
* Get the point data associated with this Geometry;
*/
boost::shared_ptr<XdmfDataItem> getData();
/**
* Get the data associated with this Geometry (const version)
*/
boost::shared_ptr<const XdmfDataItem> getData() const;
/**
* Set the point data associated with this Geometry
*/
void setData(boost::shared_ptr<XdmfDataItem> pointData);
virtual std::string printSelf() const;
virtual void write(boost::shared_ptr<XdmfVisitor> visitor) const;
......@@ -61,6 +78,7 @@ private:
void operator=(const XdmfGeometry&); // Not implemented.
XdmfGeometryType mGeometryType;
boost::shared_ptr<XdmfDataItem> mPointData;
};
......
This diff is collapsed.
......@@ -5,11 +5,13 @@
* Author: kleiter
*/
#include "XdmfDataItem.hpp"
#include "XdmfTopology.hpp"
#include "XdmfVisitor.hpp"
XdmfTopology::XdmfTopology() :
mTopologyType(XdmfTopologyType::NoTopologyType()),
mConnectivityData(XdmfDataItem::New()),
mNumberElements(0)
{
std::cout << "Created Topology " << this << std::endl;
......@@ -40,7 +42,7 @@ int XdmfTopology::getNumberElements() const
return mNumberElements;
}
void XdmfTopology::setNumberElements(int& numberElements)
void XdmfTopology::setNumberElements(int numberElements)
{
mNumberElements = numberElements;
}
......@@ -50,6 +52,21 @@ std::string XdmfTopology::getTopologyTypeAsString() const
return mTopologyType.getName();
}
boost::shared_ptr<XdmfDataItem> XdmfTopology::getData()
{
return mConnectivityData;
}
boost::shared_ptr<const XdmfDataItem> XdmfTopology::getData() const
{
return mConnectivityData;
}
void XdmfTopology::setData(boost::shared_ptr<XdmfDataItem> connectivityData)
{
mConnectivityData = connectivityData;
}
std::string XdmfTopology::printSelf() const
{
return "XdmfTopology";
......
......@@ -8,6 +8,9 @@
#ifndef XDMFTOPOLOGY_HPP_
#define XDMFTOPOLOGY_HPP_
// Forward Declarations
class XdmfDataItem;
// Includes
#include "XdmfItem.hpp"
#include "XdmfTopologyType.hpp"
......@@ -44,7 +47,7 @@ public:
*
* @param int of number elements to set.
*/
void setNumberElements(int&);
void setNumberElements(int numberElements);
/**
* Get the name of the TopologyType associated with this Topology.
......@@ -60,6 +63,21 @@ public:
*/
int getNodesPerElement() const;
/**
* Get the point data associated with this Topology;
*/
boost::shared_ptr<XdmfDataItem> getData();
/**
* Get the data associated with this Topology (const version)
*/
boost::shared_ptr<const XdmfDataItem> getData() const;
/**
* Set the point data associated with this Topology
*/
void setData(boost::shared_ptr<XdmfDataItem> connectivityData);
/**
*
*/
......@@ -79,6 +97,7 @@ private:
XdmfTopologyType mTopologyType;
int mNumberElements;
boost::shared_ptr<XdmfDataItem> mConnectivityData;
};
#endif /* XDMFTOPOLOGY_HPP_ */
......@@ -30,12 +30,30 @@ void XdmfVisitor::visit(const XdmfAttribute * const attribute)
void XdmfVisitor::visit(const XdmfDataItem * const dataItem)
{
xmlData << std::setw(mTabIndex) << "" << "<DataItem Format=\"XML\" DataType=\"Int\" Precision=\"4\" Dimensions=\"" << dataItem->getNumberValues() << "\">";
const int* const intPointer = dataItem->getData<int>();
mTabIndex++;
for (unsigned int i=0; i<dataItem->getNumberValues(); ++i)
{
if (i % 10 == 0)
{
xmlData << "\n" << std::setw(mTabIndex) << "" << intPointer[i] << " ";
}
else
{
xmlData << intPointer[i] << " ";
}
}
mTabIndex--;
xmlData << "\n" << std::setw(mTabIndex) << "" << "</DataItem>\n";
}
void XdmfVisitor::visit(const XdmfGeometry * const geometry)
{
xmlData << std::setw(mTabIndex) << "" << "<Geometry GeometryType=\"" << geometry->getGeometryTypeAsString() << "\">\n";
mTabIndex++;
visit(geometry->getData().get());
mTabIndex--;
xmlData << std::setw(mTabIndex) << "" << "</Geometry>\n";
}
......@@ -55,7 +73,10 @@ void XdmfVisitor::visit(const XdmfGrid * const grid)
void XdmfVisitor::visit(const XdmfTopology * const topology)
{
xmlData << std::setw(mTabIndex) << "" << "<Topology TopologyType=\"" << topology->getTopologyTypeAsString() << "\" NumberOfElements=" << topology->getNumberElements() << "\">\n";
xmlData << std::setw(mTabIndex) << "" << "<Topology TopologyType=\"" << topology->getTopologyTypeAsString() << "\" NumberOfElements=\"" << topology->getNumberElements() << "\">\n";
mTabIndex++;
visit(topology->getData().get());
mTabIndex--;
xmlData << std::setw(mTabIndex) << "" << "</Topology>\n";
}
......
......@@ -45,9 +45,6 @@ private:
int mTabIndex;
std::stringstream xmlData;
};
#endif /* XDMFVISITOR_HPP_ */
......@@ -3,6 +3,6 @@
int main(int argc, char* argv[])
{
boost::shared_ptr<XdmfDataItem> dataItem = XdmfDataItem::New();
int* intArray = new int[10];
int intArray[10] = {1,2,3,4,5,6,7,8,9,10};
dataItem->setData(intArray);
}
#include "XdmfAttribute.hpp"
#include "XdmfDataItem.hpp"
#include "XdmfGeometry.hpp"
#include "XdmfGrid.hpp"
#include "XdmfTopology.hpp"
......@@ -8,8 +9,23 @@ int main(int argc, char* argv[])
{
boost::shared_ptr<XdmfVisitor> visitor3 = XdmfVisitor::New();
boost::shared_ptr<XdmfGrid> grid = XdmfGrid::New();
grid->setName("test");
// Set Geometry
int points[] = { 0, 0, 1, 1, 0, 1, 3, 0, 2, 0, 1, 1, 1, 1, 1, 3, 2, 2,
0, 0, -1, 1, 0, -1, 3, 0, -2, 0, 1, -1, 1, 1, -1, 3, 2, -2};
grid->getGeometry()->setGeometryType(XdmfGeometryType::XYZ());
grid->getGeometry()->getData()->setData(points);
grid->getGeometry()->getData()->setNumberValues(36);
// Set Topology
grid->getTopology()->setTopologyType(XdmfTopologyType::Hexahedron());
grid->getTopology()->setNumberElements(2);
int connectivity[] = { 0, 1, 7, 6, 3, 4, 10, 9, 1, 2, 8, 7, 4, 5, 11, 10};
grid->getTopology()->getData()->setNumberValues(16);
grid->getTopology()->getData()->setData(connectivity);
boost::shared_ptr<XdmfAttribute> attr = XdmfAttribute::New();
attr->setName("Attr1");
attr->setAttributeType(XdmfAttributeType::Scalar());
......
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