Commit 8c4b7ddd authored by Kenneth Leiter's avatar Kenneth Leiter

ENH: Get reading of regular grids partially complete.

parent c0e846fa
...@@ -44,24 +44,12 @@ boost::shared_ptr<const XdmfGeometryType> XdmfGeometryType::VXVYVZ() ...@@ -44,24 +44,12 @@ boost::shared_ptr<const XdmfGeometryType> XdmfGeometryType::VXVYVZ()
return p; return p;
} }
boost::shared_ptr<const XdmfGeometryType> XdmfGeometryType::Origin_DXDYDZ()
{
static boost::shared_ptr<const XdmfGeometryType> p(new XdmfGeometryType("ORIGIN_DXDYDZ", 3));
return p;
}
boost::shared_ptr<const XdmfGeometryType> XdmfGeometryType::VXVY() boost::shared_ptr<const XdmfGeometryType> XdmfGeometryType::VXVY()
{ {
static boost::shared_ptr<const XdmfGeometryType> p(new XdmfGeometryType("VXVY", 2)); static boost::shared_ptr<const XdmfGeometryType> p(new XdmfGeometryType("VXVY", 2));
return p; return p;
} }
boost::shared_ptr<const XdmfGeometryType> XdmfGeometryType::Origin_DXDY()
{
static boost::shared_ptr<const XdmfGeometryType> p(new XdmfGeometryType("ORIGIN_DXDY", 2));
return p;
}
XdmfGeometryType::XdmfGeometryType(const std::string& name, const int& dimensions) : XdmfGeometryType::XdmfGeometryType(const std::string& name, const int& dimensions) :
mDimensions(dimensions), mDimensions(dimensions),
mName(name) mName(name)
...@@ -107,17 +95,15 @@ boost::shared_ptr<const XdmfGeometryType> XdmfGeometryType::New(const std::map<s ...@@ -107,17 +95,15 @@ boost::shared_ptr<const XdmfGeometryType> XdmfGeometryType::New(const std::map<s
{ {
return VXVYVZ(); return VXVYVZ();
} }
else if(typeVal.compare("ORIGIN_DXDYDZ") == 0)
{
return Origin_DXDYDZ();
}
else if(typeVal.compare("VXVY") == 0) else if(typeVal.compare("VXVY") == 0)
{ {
return VXVY(); return VXVY();
} }
else if(typeVal.compare("ORIGIN_DXDY") == 0) else if(typeVal.compare("ORIGIN_DXDY") == 0 || typeVal.compare("ORIGIN_DXDYDZ") == 0)
{ {
return Origin_DXDY(); // Special case --- Regular Grid
boost::shared_ptr<const XdmfGeometryType> p(new XdmfGeometryType("REGULAR", 0));
return p;
} }
else else
{ {
...@@ -142,6 +128,11 @@ unsigned int XdmfGeometryType::getDimensions() const ...@@ -142,6 +128,11 @@ unsigned int XdmfGeometryType::getDimensions() const
return mDimensions; return mDimensions;
} }
std::string XdmfGeometryType::getName() const
{
return mName;
}
void XdmfGeometryType::getProperties(std::map<std::string, std::string> & collectedProperties) const void XdmfGeometryType::getProperties(std::map<std::string, std::string> & collectedProperties) const
{ {
collectedProperties["Type"] = mName; collectedProperties["Type"] = mName;
......
...@@ -37,9 +37,7 @@ public: ...@@ -37,9 +37,7 @@ public:
static boost::shared_ptr<const XdmfGeometryType> X_Y_Z(); static boost::shared_ptr<const XdmfGeometryType> X_Y_Z();
static boost::shared_ptr<const XdmfGeometryType> X_Y(); static boost::shared_ptr<const XdmfGeometryType> X_Y();
static boost::shared_ptr<const XdmfGeometryType> VXVYVZ(); static boost::shared_ptr<const XdmfGeometryType> VXVYVZ();
static boost::shared_ptr<const XdmfGeometryType> Origin_DXDYDZ();
static boost::shared_ptr<const XdmfGeometryType> VXVY(); static boost::shared_ptr<const XdmfGeometryType> VXVY();
static boost::shared_ptr<const XdmfGeometryType> Origin_DXDY();
/** /**
* Get the dimensions of this geometry type - i.e. XYZ = 3. * Get the dimensions of this geometry type - i.e. XYZ = 3.
...@@ -48,6 +46,13 @@ public: ...@@ -48,6 +46,13 @@ public:
*/ */
virtual unsigned int getDimensions() const; virtual unsigned int getDimensions() const;
/**
* Get the name of this geometry type.
*
* @return the name of this geometry type.
*/
std::string getName() const;
virtual void getProperties(std::map<std::string, std::string> & collectedProperties) const; virtual void getProperties(std::map<std::string, std::string> & collectedProperties) const;
/* /*
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
* Author: kleiter * Author: kleiter
*/ */
#include <boost/tokenizer.hpp>
#include <cmath> #include <cmath>
#include "XdmfArray.hpp" #include "XdmfArray.hpp"
#include "XdmfGeometry.hpp" #include "XdmfGeometry.hpp"
...@@ -160,7 +161,7 @@ public: ...@@ -160,7 +161,7 @@ public:
unsigned int getNodesPerElement() const unsigned int getNodesPerElement() const
{ {
// 2 ^ Dimensions // 2^Dimensions
// e.g. 1D = 2 nodes per element and 2D = 4 nodes per element. // e.g. 1D = 2 nodes per element and 2D = 4 nodes per element.
return (unsigned int)std::pow(2, (double)mRegularGrid->getDimensions()->getSize()); return (unsigned int)std::pow(2, (double)mRegularGrid->getDimensions()->getSize());
} }
...@@ -295,6 +296,22 @@ boost::shared_ptr<const XdmfArray> XdmfGridRegular::getOrigin() const ...@@ -295,6 +296,22 @@ boost::shared_ptr<const XdmfArray> XdmfGridRegular::getOrigin() const
return mImpl->mOrigin; return mImpl->mOrigin;
} }
void XdmfGridRegular::populateItem(const std::map<std::string, std::string> & itemProperties, std::vector<boost::shared_ptr<XdmfItem> > & childItems, const XdmfCoreReader * const reader)
{
XdmfGrid::populateItem(itemProperties, childItems, reader);
mImpl->mOrigin->swap(this->getGeometry());
mImpl->mBrickSize->swap(this->getGeometry());
mImpl->mDimensions->clear();
std::string dimensions = this->getTopology()->getDimensions();
boost::tokenizer<> tokens(dimensions);
for(boost::tokenizer<>::const_iterator iter = tokens.begin(); iter != tokens.end(); ++iter)
{
mImpl->mDimensions->pushBack<unsigned int>(atoi((*iter).c_str()));
}
this->setGeometry(XdmfGridRegularImpl::XdmfGeometryRegular::New(this));
this->setTopology(XdmfGridRegularImpl::XdmfTopologyRegular::New(this));
}
void XdmfGridRegular::setBrickSize(const boost::shared_ptr<XdmfArray> brickSize) void XdmfGridRegular::setBrickSize(const boost::shared_ptr<XdmfArray> brickSize)
{ {
mImpl->mBrickSize = brickSize; mImpl->mBrickSize = brickSize;
......
...@@ -31,7 +31,7 @@ public: ...@@ -31,7 +31,7 @@ public:
* @return constructed structured grid. * @return constructed structured grid.
*/ */
static boost::shared_ptr<XdmfGridRegular> New(const double brickSizeX, const double brickSizeY, const unsigned int numPointsX, static boost::shared_ptr<XdmfGridRegular> New(const double brickSizeX, const double brickSizeY, const unsigned int numPointsX,
const unsigned int numPointsY, const double originX = 0, const double originY = 0); const unsigned int numPointsY, const double originX, const double originY);
/** /**
* Create a new structured grid (Three dimensional). * Create a new structured grid (Three dimensional).
...@@ -50,7 +50,7 @@ public: ...@@ -50,7 +50,7 @@ public:
*/ */
static boost::shared_ptr<XdmfGridRegular> New(const double brickSizeX, const double brickSizeY, const double brickSizeZ, static boost::shared_ptr<XdmfGridRegular> New(const double brickSizeX, const double brickSizeY, const double brickSizeZ,
const unsigned int numPointsX, const unsigned int numPointsY, const unsigned int numPointsZ, const unsigned int numPointsX, const unsigned int numPointsY, const unsigned int numPointsZ,
const double originX = 0, const double originY = 0, const double originZ = 0); const double originX, const double originY, const double originZ);
virtual ~XdmfGridRegular(); virtual ~XdmfGridRegular();
...@@ -129,7 +129,7 @@ protected: ...@@ -129,7 +129,7 @@ protected:
XdmfGridRegular(const double brickSizeX, const double brickSizeY, const double brickSizeZ, XdmfGridRegular(const double brickSizeX, const double brickSizeY, const double brickSizeZ,
const unsigned int numPointsX, const unsigned int numPointsY, const unsigned int numPointsZ, const unsigned int numPointsX, const unsigned int numPointsY, const unsigned int numPointsZ,
const double originX, const double originY, const double originZ); const double originX, const double originY, const double originZ);
//virtual void populateItem(const std::map<std::string, std::string> & itemProperties, std::vector<boost::shared_ptr<XdmfItem> > & childItems, const XdmfCoreReader * const reader); void populateItem(const std::map<std::string, std::string> & itemProperties, std::vector<boost::shared_ptr<XdmfItem> > & childItems, const XdmfCoreReader * const reader);
private: private:
......
#include "XdmfAttribute.hpp" #include "XdmfAttribute.hpp"
#include "XdmfDomain.hpp" #include "XdmfDomain.hpp"
#include "XdmfGeometry.hpp" #include "XdmfGeometry.hpp"
#include "XdmfGeometryType.hpp"
#include "XdmfGrid.hpp" #include "XdmfGrid.hpp"
#include "XdmfGridCollection.hpp" #include "XdmfGridCollection.hpp"
#include "XdmfGridRegular.hpp"
#include "XdmfInformation.hpp" #include "XdmfInformation.hpp"
#include "XdmfItemFactory.hpp" #include "XdmfItemFactory.hpp"
#include "XdmfMap.hpp" #include "XdmfMap.hpp"
...@@ -24,9 +26,9 @@ XdmfItemFactory::~XdmfItemFactory() ...@@ -24,9 +26,9 @@ XdmfItemFactory::~XdmfItemFactory()
{ {
} }
boost::shared_ptr<XdmfItem> XdmfItemFactory::createItem(const std::string & itemTag, const std::map<std::string, std::string> & itemProperties) const boost::shared_ptr<XdmfItem> XdmfItemFactory::createItem(const std::string & itemTag, const std::map<std::string, std::string> & itemProperties, const std::vector<boost::shared_ptr<XdmfItem> > & childItems) const
{ {
boost::shared_ptr<XdmfItem> newItem = XdmfCoreItemFactory::createItem(itemTag, itemProperties); boost::shared_ptr<XdmfItem> newItem = XdmfCoreItemFactory::createItem(itemTag, itemProperties, childItems);
if(newItem) if(newItem)
{ {
...@@ -35,47 +37,63 @@ boost::shared_ptr<XdmfItem> XdmfItemFactory::createItem(const std::string & item ...@@ -35,47 +37,63 @@ boost::shared_ptr<XdmfItem> XdmfItemFactory::createItem(const std::string & item
if(itemTag.compare(XdmfAttribute::ItemTag) == 0) if(itemTag.compare(XdmfAttribute::ItemTag) == 0)
{ {
newItem = XdmfAttribute::New(); return XdmfAttribute::New();
} }
else if(itemTag.compare(XdmfDomain::ItemTag) == 0) else if(itemTag.compare(XdmfDomain::ItemTag) == 0)
{ {
newItem = XdmfDomain::New(); return XdmfDomain::New();
} }
else if(itemTag.compare(XdmfGeometry::ItemTag) == 0) else if(itemTag.compare(XdmfGeometry::ItemTag) == 0)
{ {
newItem = XdmfGeometry::New(); return XdmfGeometry::New();
} }
else if(itemTag.compare(XdmfGrid::ItemTag) == 0) else if(itemTag.compare(XdmfGrid::ItemTag) == 0)
{ {
// For backwards compatibility with the old format, this tag can correspond to multiple XdmfItems.
std::map<std::string, std::string>::const_iterator gridType = itemProperties.find("GridType"); std::map<std::string, std::string>::const_iterator gridType = itemProperties.find("GridType");
if(gridType != itemProperties.end() && gridType->second.compare("Collection") == 0) if(gridType != itemProperties.end() && gridType->second.compare("Collection") == 0)
{ {
newItem = XdmfGridCollection::New(); return XdmfGridCollection::New();
} }
else else
{ {
newItem = XdmfGrid::New(); // Find out what kind of grid we have
for(std::vector<boost::shared_ptr<XdmfItem> >::const_iterator iter = childItems.begin(); iter != childItems.end(); ++iter)
{
if(boost::shared_ptr<XdmfGeometry> geometry = boost::shared_dynamic_cast<XdmfGeometry>(*iter))
{
if(geometry->getType()->getName().compare("REGULAR") == 0)
{
return XdmfGridRegular::New(0, 0, 0, 0, 0, 0);
}
else
{
break;
}
}
}
return XdmfGrid::New();
} }
} }
else if(itemTag.compare(XdmfInformation::ItemTag) == 0) else if(itemTag.compare(XdmfInformation::ItemTag) == 0)
{ {
newItem = XdmfInformation::New(); return XdmfInformation::New();
} }
else if(itemTag.compare(XdmfMap::ItemTag) == 0) else if(itemTag.compare(XdmfMap::ItemTag) == 0)
{ {
newItem = XdmfMap::New(); return XdmfMap::New();
} }
else if(itemTag.compare(XdmfSet::ItemTag) == 0) else if(itemTag.compare(XdmfSet::ItemTag) == 0)
{ {
newItem = XdmfSet::New(); return XdmfSet::New();
} }
else if(itemTag.compare(XdmfTime::ItemTag) == 0) else if(itemTag.compare(XdmfTime::ItemTag) == 0)
{ {
newItem = XdmfTime::New(); return XdmfTime::New();
} }
else if(itemTag.compare(XdmfTopology::ItemTag) == 0) else if(itemTag.compare(XdmfTopology::ItemTag) == 0)
{ {
newItem = XdmfTopology::New(); return XdmfTopology::New();
} }
return newItem; return boost::shared_ptr<XdmfItem>();
} }
...@@ -23,7 +23,7 @@ public: ...@@ -23,7 +23,7 @@ public:
virtual ~XdmfItemFactory(); virtual ~XdmfItemFactory();
virtual boost::shared_ptr<XdmfItem> createItem(const std::string & itemTag, const std::map<std::string, std::string> & itemProperties) const; virtual boost::shared_ptr<XdmfItem> createItem(const std::string & itemTag, const std::map<std::string, std::string> & itemProperties, const std::vector<boost::shared_ptr<XdmfItem> > & childItems) const;
protected: protected:
......
...@@ -16,6 +16,7 @@ boost::shared_ptr<XdmfTopology> XdmfTopology::New() ...@@ -16,6 +16,7 @@ boost::shared_ptr<XdmfTopology> XdmfTopology::New()
} }
XdmfTopology::XdmfTopology() : XdmfTopology::XdmfTopology() :
mDimensions(""),
mType(XdmfTopologyType::NoTopologyType()) mType(XdmfTopologyType::NoTopologyType())
{ {
} }
...@@ -26,6 +27,17 @@ XdmfTopology::~XdmfTopology() ...@@ -26,6 +27,17 @@ XdmfTopology::~XdmfTopology()
const std::string XdmfTopology::ItemTag = "Topology"; const std::string XdmfTopology::ItemTag = "Topology";
std::string XdmfTopology::getDimensions() const
{
if(mDimensions.compare("") == 0)
{
std::stringstream toReturn;
toReturn << this->getNumberElements();
return toReturn.str();
}
return mDimensions;
}
std::string XdmfTopology::getItemTag() const std::string XdmfTopology::getItemTag() const
{ {
return ItemTag; return ItemTag;
...@@ -62,6 +74,11 @@ void XdmfTopology::populateItem(const std::map<std::string, std::string> & itemP ...@@ -62,6 +74,11 @@ void XdmfTopology::populateItem(const std::map<std::string, std::string> & itemP
{ {
XdmfItem::populateItem(itemProperties, childItems, reader); XdmfItem::populateItem(itemProperties, childItems, reader);
mType = XdmfTopologyType::New(itemProperties); mType = XdmfTopologyType::New(itemProperties);
std::map<std::string, std::string>::const_iterator dimensions = itemProperties.find("Dimensions");
if(dimensions != itemProperties.end())
{
mDimensions = dimensions->second;
}
for(std::vector<boost::shared_ptr<XdmfItem> >::const_iterator iter = childItems.begin(); iter != childItems.end(); ++iter) for(std::vector<boost::shared_ptr<XdmfItem> >::const_iterator iter = childItems.begin(); iter != childItems.end(); ++iter)
{ {
if(boost::shared_ptr<XdmfArray> array = boost::shared_dynamic_cast<XdmfArray>(*iter)) if(boost::shared_ptr<XdmfArray> array = boost::shared_dynamic_cast<XdmfArray>(*iter))
...@@ -75,5 +92,4 @@ void XdmfTopology::populateItem(const std::map<std::string, std::string> & itemP ...@@ -75,5 +92,4 @@ void XdmfTopology::populateItem(const std::map<std::string, std::string> & itemP
void XdmfTopology::setType(const boost::shared_ptr<const XdmfTopologyType> type) void XdmfTopology::setType(const boost::shared_ptr<const XdmfTopologyType> type)
{ {
mType = type; mType = type;
} }
...@@ -30,6 +30,8 @@ public: ...@@ -30,6 +30,8 @@ public:
LOKI_DEFINE_VISITABLE(XdmfTopology, XdmfArray) LOKI_DEFINE_VISITABLE(XdmfTopology, XdmfArray)
static const std::string ItemTag; static const std::string ItemTag;
std::string getDimensions() const;
std::map<std::string, std::string> getItemProperties() const; std::map<std::string, std::string> getItemProperties() const;
std::string getItemTag() const; std::string getItemTag() const;
...@@ -65,6 +67,7 @@ private: ...@@ -65,6 +67,7 @@ private:
XdmfTopology(const XdmfTopology & topology); // Not implemented. XdmfTopology(const XdmfTopology & topology); // Not implemented.
void operator=(const XdmfTopology & topology); // Not implemented. void operator=(const XdmfTopology & topology); // Not implemented.
std::string mDimensions;
boost::shared_ptr<const XdmfTopologyType> mType; boost::shared_ptr<const XdmfTopologyType> mType;
}; };
......
...@@ -210,7 +210,7 @@ boost::shared_ptr<const XdmfTopologyType> XdmfTopologyType::ThreeDCoRectMesh() ...@@ -210,7 +210,7 @@ boost::shared_ptr<const XdmfTopologyType> XdmfTopologyType::ThreeDCoRectMesh()
return p; return p;
}*/ }*/
XdmfTopologyType::XdmfTopologyType(const int& nodesPerElement, const std::string& name, const CellType& cellType) : XdmfTopologyType::XdmfTopologyType(const unsigned int nodesPerElement, const std::string & name, const CellType cellType) :
mCellType(cellType), mCellType(cellType),
mName(name), mName(name),
mNodesPerElement(nodesPerElement) mNodesPerElement(nodesPerElement)
...@@ -322,19 +322,20 @@ boost::shared_ptr<const XdmfTopologyType> XdmfTopologyType::New(const std::map<s ...@@ -322,19 +322,20 @@ boost::shared_ptr<const XdmfTopologyType> XdmfTopologyType::New(const std::map<s
{ {
return Mixed(); return Mixed();
} }
/* /*else if(typeVal.compare("2DSMESH") == 0)
else if(typeVal.compare("2DSMESH") == 0)
{ {
return TwoDSMesh(); return TwoDSMesh();
} }
else if(typeVal.compare("2DRECTMESH") == 0) else if(typeVal.compare("2DRECTMESH") == 0)
{ {
return TwoDRectMesh(); return TwoDRectMesh();
} }*/
else if(typeVal.compare("2DCORECTMESH") == 0) else if(typeVal.compare("2DCORECTMESH") == 0 || typeVal.compare("3DCORECTMESH") == 0)
{ {
return TwoDCoRectMesh(); // Special case --- Regular Grid
} boost::shared_ptr<const XdmfTopologyType> p(new XdmfTopologyType(0, "REGULAR", Structured));
return p;
}/*
else if(typeVal.compare("3DSMESH") == 0) else if(typeVal.compare("3DSMESH") == 0)
{ {
return ThreeDSMesh(); return ThreeDSMesh();
...@@ -342,12 +343,7 @@ boost::shared_ptr<const XdmfTopologyType> XdmfTopologyType::New(const std::map<s ...@@ -342,12 +343,7 @@ boost::shared_ptr<const XdmfTopologyType> XdmfTopologyType::New(const std::map<s
else if(typeVal.compare("3DRECTMESH") == 0) else if(typeVal.compare("3DRECTMESH") == 0)
{ {
return ThreeDRectMesh(); return ThreeDRectMesh();
} }*/
else if(typeVal.compare("3DCORECTMESH") == 0)
{
return ThreeDCoRectMesh();
}
*/
else else
{ {
assert(false); assert(false);
...@@ -371,6 +367,11 @@ XdmfTopologyType::CellType XdmfTopologyType::getCellType() const ...@@ -371,6 +367,11 @@ XdmfTopologyType::CellType XdmfTopologyType::getCellType() const
return mCellType; return mCellType;
} }
std::string XdmfTopologyType::getName() const
{
return mName;
}
unsigned int XdmfTopologyType::getNodesPerElement() const unsigned int XdmfTopologyType::getNodesPerElement() const
{ {
return mNodesPerElement; return mNodesPerElement;
......
...@@ -88,12 +88,19 @@ public: ...@@ -88,12 +88,19 @@ public:
//static boost::shared_ptr<const XdmfTopologyType> ThreeDCoRectMesh(); //static boost::shared_ptr<const XdmfTopologyType> ThreeDCoRectMesh();
/** /**
* Get the cell type associated with this topology type * Get the cell type associated with this topology type.
* *
* @return a CellType containing the cell type. * @return a CellType containing the cell type.
*/ */
CellType getCellType() const; CellType getCellType() const;
/**
* Get the name of this topology type.
*
* @return the name of this topology type.
*/
std::string getName() const;
/** /**
* Get the number of nodes per element associated with this topology type. * Get the number of nodes per element associated with this topology type.
* *
...@@ -126,7 +133,7 @@ protected: ...@@ -126,7 +133,7 @@ protected:
* by Xdmf should be accessed through more specific static methods that construct XdmfTopologyType - * by Xdmf should be accessed through more specific static methods that construct XdmfTopologyType -
* i.e. XdmfTopologyType::Tetrahedron() * i.e. XdmfTopologyType::Tetrahedron()
*/ */
XdmfTopologyType(const int & nodesPerElement, const std::string & name, const CellType & cellType); XdmfTopologyType(const unsigned int nodesPerElement, const std::string & name, const CellType cellType);
private: private:
...@@ -137,7 +144,7 @@ private: ...@@ -137,7 +144,7 @@ private:
CellType mCellType; CellType mCellType;
std::string mName; std::string mName;
int mNodesPerElement; unsigned int mNodesPerElement;
}; };
#endif /* XDMFTOPOLOGYTYPE_HPP_ */ #endif /* XDMFTOPOLOGYTYPE_HPP_ */
...@@ -9,12 +9,11 @@ XdmfCoreItemFactory::~XdmfCoreItemFactory() ...@@ -9,12 +9,11 @@ XdmfCoreItemFactory::~XdmfCoreItemFactory()
{ {
} }
boost::shared_ptr<XdmfItem> XdmfCoreItemFactory::createItem(const std::string & itemTag, const std::map<std::string, std::string> &) const boost::shared_ptr<XdmfItem> XdmfCoreItemFactory::createItem(const std::string & itemTag, const std::map<std::string, std::string> &, const std::vector<boost::shared_ptr<XdmfItem> > &) const
{ {
boost::shared_ptr<XdmfItem> newItem = boost::shared_ptr<XdmfItem>();
if(itemTag.compare(XdmfArray::ItemTag) == 0) if(itemTag.compare(XdmfArray::ItemTag) == 0)
{ {
newItem = XdmfArray::New(); return XdmfArray::New();
} }
return newItem; return boost::shared_ptr<XdmfItem>();;
} }
...@@ -7,6 +7,7 @@ class XdmfItem; ...@@ -7,6 +7,7 @@ class XdmfItem;
// Includes // Includes
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
#include <map> #include <map>
#include <vector>
/** /**
* @brief Factory that constructs XdmfItems using tags and properties. * @brief Factory that constructs XdmfItems using tags and properties.
...@@ -24,9 +25,11 @@ public: ...@@ -24,9 +25,11 @@ public:
* *
* @param itemTag a string containing the tag of the XdmfItem to create. * @param itemTag a string containing the tag of the XdmfItem to create.
* @param itemProperties a map of key/value properties for the the XdmfItem. * @param itemProperties a map of key/value properties for the the XdmfItem.
* @param childItems the children of the XdmfItem to create.
*
* @return constructed XdmfItem. If no XdmfItem can be constructed, return NULL. * @return constructed XdmfItem. If no XdmfItem can be constructed, return NULL.
*/ */
virtual boost::shared_ptr<XdmfItem> createItem(const std::string & itemTag, const std::map<std::string, std::string> & itemProperties) const; virtual boost::shared_ptr<XdmfItem> createItem(const std::string & itemTag, const std::map<std::string, std::string> & itemProperties, const std::vector<boost::shared_ptr<XdmfItem> > & childItems) const;
protected: protected:
......
...@@ -129,7 +129,7 @@ public: ...@@ -129,7 +129,7 @@ public:
currAttribute = currAttribute->next; currAttribute = currAttribute->next;
} }
std::vector<boost::shared_ptr<XdmfItem> > childItems = this->read(currNode->children); std::vector<boost::shared_ptr<XdmfItem> > childItems = this->read(currNode->children);
boost::shared_ptr<XdmfItem> newItem = mItemFactory->createItem((const char *)currNode->name, itemProperties); boost::shared_ptr<XdmfItem> newItem = mItemFactory->createItem((const char *)currNode->name, itemProperties, childItems);
if(newItem == NULL) if(newItem == NULL)
{ {
assert(false); assert(false);
......
...@@ -43,6 +43,7 @@ CLEAN_CXX_TEST(TestXdmfGridCollection ...@@ -43,6 +43,7 @@ CLEAN_CXX_TEST(TestXdmfGridCollection
) )
CLEAN_CXX_TEST(TestXdmfGridRegular CLEAN_CXX_TEST(TestXdmfGridRegular
TestXdmfGridRegular1.xmf TestXdmfGridRegular1.xmf
TestXdmfGridRegular2.xmf
) )
CLEAN_CXX_TEST(TestXdmfReader CLEAN_CXX_TEST(TestXdmfReader
TestXdmfReader1.h5 TestXdmfReader1.h5
......
...@@ -12,9 +12,11 @@ int main(int, char *) ...@@ -12,9 +12,11 @@ int main(int, char *)
boost::shared_ptr<XdmfGeometry> geometry = XdmfGeometry::New(); boost::shared_ptr<XdmfGeometry> geometry = XdmfGeometry::New();
assert(geometry->getType() == XdmfGeometryType::NoGeometryType()); assert(geometry->getType() == XdmfGeometryType::NoGeometryType());
assert(geometry->getType()->getDimensions() == 0); assert(geometry->getType()->getDimensions() == 0);
assert(geometry->getType()->getName().compare("None") == 0);
geometry->setType(XdmfGeometryType::XYZ()); geometry->setType(XdmfGeometryType::XYZ());
assert(geometry->getType() == XdmfGeometryType::XYZ()); assert(geometry->getType() == XdmfGeometryType::XYZ());
assert(geometry->getType()->getDimensions() == 3); assert(geometry->getType()->getDimensions() == 3);
assert(geometry->getType()->getName().compare("XYZ") == 0);
return 0; return 0;
} }
...@@ -2,12 +2,11 @@ ...@@ -2,12 +2,11 @@
#include "XdmfGeometry.hpp" #include "XdmfGeometry.hpp"
#include "XdmfGeometryType.hpp" #include "XdmfGeometryType.hpp"
#include "XdmfGridRegular.hpp" #include "XdmfGridRegular.hpp"
#include "XdmfReader.hpp"
#include "XdmfTopology.hpp" #include "XdmfTopology.hpp"
#include "XdmfTopologyType.hpp" #include "XdmfTopologyType.hpp"
#include "XdmfWriter.hpp" #include "XdmfWriter.hpp"
#include <iostream>
int main(int, char *) int main(int, char *)
{ {
boost::shared_ptr<XdmfGridRegular> grid = XdmfGridRegular::New(1, 1, 1, 1, 1, 1, 0, 0, 0); boost::shared_ptr<XdmfGridRegular> grid = XdmfGridRegular::New(1, 1, 1, 1, 1, 1, 0, 0, 0);
...@@ -86,8 +85,13 @@ int main(int, char *) ...@@ -86,8 +85,13 @@ int main(int, char *)
// Input / Output // Input / Output
boost::shared_ptr<XdmfWriter> writer = XdmfWriter::New("TestXdmfGridRegular1.xmf"); boost::shared_ptr<XdmfWriter> writer = XdmfWriter::New("TestXdmfGridRegular1.xmf");
grid->accept(writer); grid->accept(writer);
boost::shared_ptr<XdmfReader> reader = XdmfReader::New();
boost::shared_ptr<XdmfGrid> grid2 = boost::shared_dynamic_cast<XdmfGrid>(reader->read("TestXdmfGridRegular1.xmf"));
boost::shared_ptr<XdmfWriter> writer2 = XdmfWriter::New("TestXdmfGridRegular2.xmf");
grid2->accept(writer2);
return 0; return 0;
}