Commit 2922ad7a authored by Kenneth Leiter's avatar Kenneth Leiter

ENH: Make XdmfAttribute, XdmfTopology, XdmfGeometry inherit from XdmfDataItem....

ENH: Make XdmfAttribute, XdmfTopology, XdmfGeometry inherit from XdmfDataItem.  Instead of containing a data item, each is a dataitem of a specific type.  This makes setting data items more user friendly --- e.g. once you set the number of elements and set the topology type you don't have to set the number of elements from the dataitem again.  This still needs to be figured out for composite dataitems for things like sets.
parent 95079f5a
......@@ -61,6 +61,11 @@ void XdmfAttribute::setName(const std::string& name)
mName= name;
}
void XdmfAttribute::setNumberValues(int numValues)
{
mNumberValues = numValues;
}
void XdmfAttribute::write(boost::shared_ptr<XdmfVisitor> visitor) const
{
visitor->visit(this);
......
......@@ -8,11 +8,11 @@
#ifndef XDMFATTRIBUTE_HPP_
#define XDMFATTRIBUTE_HPP_
#include "XdmfItem.hpp"
#include "XdmfAttributeCenter.hpp"
#include "XdmfAttributeType.hpp"
#include "XdmfDataItem.hpp"
class XdmfAttribute : public XdmfItem {
class XdmfAttribute : public XdmfDataItem {
public:
......@@ -78,6 +78,8 @@ public:
virtual std::string printSelf() const;
void setNumberValues(int numValues);
protected:
XdmfAttribute();
......
......@@ -49,11 +49,6 @@ 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);
......
......@@ -26,14 +26,14 @@ public:
int getNumberValues() const;
void setNumberValues(int numValues);
std::string printSelf() const;
void write(boost::shared_ptr<XdmfVisitor> visitor) const;
protected:
int mNumberValues;
XdmfDataItem();
virtual ~XdmfDataItem();
......@@ -44,7 +44,6 @@ private:
int* mDataPointer;
XdmfDataItemType mDataType;
int mNumberValues;
};
#endif /* XDMFDATAITEM_HPP_ */
......@@ -5,13 +5,12 @@
* Author: kleiter
*/
#include "XdmfDataItem.hpp"
#include "XdmfGeometry.hpp"
#include "XdmfVisitor.hpp"
XdmfGeometry::XdmfGeometry() :
mPointData(XdmfDataItem::New()),
mGeometryType(XdmfGeometryType::NoGeometryType())
mGeometryType(XdmfGeometryType::NoGeometryType()),
mNumberPoints(0)
{
std::cout << "Created Geometry " << this << std::endl;
}
......@@ -29,6 +28,7 @@ XdmfGeometryType XdmfGeometry::getGeometryType() const
void XdmfGeometry::setGeometryType(const XdmfGeometryType& geomType)
{
mGeometryType = geomType;
mNumberValues = mNumberPoints * mGeometryType.getDimensions();
}
std::string XdmfGeometry::getGeometryTypeAsString() const
......@@ -41,19 +41,10 @@ int XdmfGeometry::getDimensions() const
return mGeometryType.getDimensions();
}
boost::shared_ptr<XdmfDataItem> XdmfGeometry::getData()
void XdmfGeometry::setNumberPoints(int numberPoints)
{
return mPointData;
}
boost::shared_ptr<const XdmfDataItem> XdmfGeometry::getData() const
{
return mPointData;
}
void XdmfGeometry::setData(boost::shared_ptr<XdmfDataItem> pointData)
{
mPointData = pointData;
mNumberPoints = numberPoints;
mNumberValues = mNumberPoints * mGeometryType.getDimensions();
}
std::string XdmfGeometry::printSelf() const
......
......@@ -8,13 +8,11 @@
#ifndef XDMFGEOMETRY_HPP_
#define XDMFGEOMETRY_HPP_
class XdmfDataItem;
// Includes
#include "XdmfItem.hpp"
#include "XdmfDataItem.hpp"
#include "XdmfGeometryType.hpp"
class XdmfGeometry : public XdmfItem {
class XdmfGeometry : public XdmfDataItem {
public:
......@@ -48,20 +46,7 @@ public:
*/
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);
void setNumberPoints(int numberPoints);
virtual std::string printSelf() const;
......@@ -78,8 +63,7 @@ private:
void operator=(const XdmfGeometry&); // Not implemented.
XdmfGeometryType mGeometryType;
boost::shared_ptr<XdmfDataItem> mPointData;
int mNumberPoints;
};
#endif /* XDMFGEOMETRY_HPP_ */
......@@ -5,13 +5,11 @@
* 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;
......@@ -30,6 +28,7 @@ XdmfTopologyType XdmfTopology::getTopologyType() const
void XdmfTopology::setTopologyType(const XdmfTopologyType& topType)
{
mTopologyType = topType;
mNumberValues = mNumberElements * mTopologyType.getNodesPerElement();
}
int XdmfTopology::getNodesPerElement() const
......@@ -45,6 +44,7 @@ int XdmfTopology::getNumberElements() const
void XdmfTopology::setNumberElements(int numberElements)
{
mNumberElements = numberElements;
mNumberValues = mNumberElements * mTopologyType.getNodesPerElement();
}
std::string XdmfTopology::getTopologyTypeAsString() const
......@@ -52,21 +52,6 @@ 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,14 +8,11 @@
#ifndef XDMFTOPOLOGY_HPP_
#define XDMFTOPOLOGY_HPP_
// Forward Declarations
class XdmfDataItem;
// Includes
#include "XdmfItem.hpp"
#include "XdmfDataItem.hpp"
#include "XdmfTopologyType.hpp"
class XdmfTopology : public XdmfItem {
class XdmfTopology : public XdmfDataItem {
public:
......@@ -63,20 +60,20 @@ 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);
void setData(boost::shared_ptr<XdmfDataItem> connectivityData);*/
/**
*
......@@ -97,7 +94,6 @@ private:
XdmfTopologyType mTopologyType;
int mNumberElements;
boost::shared_ptr<XdmfDataItem> mConnectivityData;
};
#endif /* XDMFTOPOLOGY_HPP_ */
......@@ -24,7 +24,10 @@ XdmfVisitor::~XdmfVisitor()
void XdmfVisitor::visit(const XdmfAttribute * const attribute)
{
xmlData << std::setw(mTabIndex) << "" << "<Attribute> Name=\"" << attribute->getName() << "\" AttributeType=\"" << attribute->getAttributeTypeAsString() << "\" Center=\"" << attribute->getAttributeCenterAsString() << "\">\n";
xmlData << std::setw(mTabIndex) << "" << "<Attribute Name=\"" << attribute->getName() << "\" AttributeType=\"" << attribute->getAttributeTypeAsString() << "\" Center=\"" << attribute->getAttributeCenterAsString() << "\">\n";
mTabIndex++;
visit((XdmfDataItem*)attribute);
mTabIndex--;
xmlData << std::setw(mTabIndex) << "" << "</Attribute>\n";
}
......@@ -52,7 +55,7 @@ void XdmfVisitor::visit(const XdmfGeometry * const geometry)
{
xmlData << std::setw(mTabIndex) << "" << "<Geometry GeometryType=\"" << geometry->getGeometryTypeAsString() << "\">\n";
mTabIndex++;
visit(geometry->getData().get());
visit((XdmfDataItem*)geometry);
mTabIndex--;
xmlData << std::setw(mTabIndex) << "" << "</Geometry>\n";
}
......@@ -75,7 +78,7 @@ void XdmfVisitor::visit(const XdmfTopology * const topology)
{
xmlData << std::setw(mTabIndex) << "" << "<Topology TopologyType=\"" << topology->getTopologyTypeAsString() << "\" NumberOfElements=\"" << topology->getNumberElements() << "\">\n";
mTabIndex++;
visit(topology->getData().get());
visit((XdmfDataItem*)topology);
mTabIndex--;
xmlData << std::setw(mTabIndex) << "" << "</Topology>\n";
}
......
......@@ -13,23 +13,38 @@ int main(int argc, char* argv[])
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,
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()->setNumberPoints(12);
grid->getGeometry()->setGeometryType(XdmfGeometryType::XYZ());
grid->getGeometry()->getData()->setData(points);
grid->getGeometry()->getData()->setNumberValues(36);
grid->getGeometry()->setData(points);
// Set Topology
grid->getTopology()->setTopologyType(XdmfTopologyType::Hexahedron());
int connectivity[] = {0, 1, 7, 6, 3, 4, 10, 9, 1, 2, 8, 7, 4, 5, 11, 10};
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());
grid->insert(attr);
grid->getTopology()->setTopologyType(XdmfTopologyType::Hexahedron());
grid->getTopology()->setData(connectivity);
// Add Node Attribute
boost::shared_ptr<XdmfAttribute> nodalAttribute = XdmfAttribute::New();
int nodeValues[] = {100, 200, 300, 300, 400, 500, 300, 400, 500, 500, 600, 700};
nodalAttribute->setName("Nodal Attribute");
nodalAttribute->setNumberValues(12);
nodalAttribute->setAttributeType(XdmfAttributeType::Scalar());
nodalAttribute->setAttributeCenter(XdmfAttributeCenter::Node());
nodalAttribute->setData(nodeValues);
// Add Cell Attribute
boost::shared_ptr<XdmfAttribute> cellAttribute = XdmfAttribute::New();
int cellValues[] = {100, 200};
cellAttribute->setName("Cell Attribute");
cellAttribute->setNumberValues(2);
cellAttribute->setAttributeType(XdmfAttributeType::Scalar());
cellAttribute->setAttributeCenter(XdmfAttributeCenter::Cell());
cellAttribute->setData(cellValues);
grid->insert(nodalAttribute);
grid->insert(cellAttribute);
grid->write(visitor3);
std::cout << visitor3->printSelf() << std::endl;
......
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