Commit b6127226 authored by Kenneth Leiter's avatar Kenneth Leiter

ENH: Make XdmfGridCollection inherit from XdmfGrid and XdmfDomain, since it is...

ENH: Make XdmfGridCollection inherit from XdmfGrid and XdmfDomain, since it is really a unity of the two classes.  Modify some details in ItemFactory / Reader.
parent 19d96e0c
...@@ -92,10 +92,6 @@ void XdmfDomain::populateItem(const std::map<std::string, std::string> & itemPro ...@@ -92,10 +92,6 @@ void XdmfDomain::populateItem(const std::map<std::string, std::string> & itemPro
{ {
this->insert(grid); this->insert(grid);
} }
else
{
assert(false);
}
} }
} }
......
...@@ -14,7 +14,7 @@ class XdmfGridCollection; ...@@ -14,7 +14,7 @@ class XdmfGridCollection;
* XdmfDomain is the top XdmfItem in an Xdmf structure. It can store a number of grids and * XdmfDomain is the top XdmfItem in an Xdmf structure. It can store a number of grids and
* provides methods to insert, retrieve, and remove these grids. * provides methods to insert, retrieve, and remove these grids.
*/ */
class XdmfDomain : public XdmfItem { class XdmfDomain : public virtual XdmfItem {
public: public:
...@@ -58,7 +58,7 @@ public: ...@@ -58,7 +58,7 @@ public:
std::map<std::string, std::string> getItemProperties() const; std::map<std::string, std::string> getItemProperties() const;
std::string getItemTag() const; virtual std::string getItemTag() const;
/** /**
* Get the number of XdmfGrids attached to this domain. * Get the number of XdmfGrids attached to this domain.
......
...@@ -190,10 +190,6 @@ void XdmfGrid::populateItem(const std::map<std::string, std::string> & itemPrope ...@@ -190,10 +190,6 @@ void XdmfGrid::populateItem(const std::map<std::string, std::string> & itemPrope
{ {
mTopology = topology; mTopology = topology;
} }
else
{
//assert(false);
}
} }
} }
......
...@@ -19,7 +19,7 @@ class XdmfTopology; ...@@ -19,7 +19,7 @@ class XdmfTopology;
* into the XdmfGrid to specify values attached at various parts of the mesh. XdmfSets can be inserted in the XdmfGrid * into the XdmfGrid to specify values attached at various parts of the mesh. XdmfSets can be inserted in the XdmfGrid
* to specify collections of mesh elements. * to specify collections of mesh elements.
*/ */
class XdmfGrid : public XdmfItem { class XdmfGrid : public virtual XdmfItem {
public: public:
...@@ -77,7 +77,7 @@ public: ...@@ -77,7 +77,7 @@ public:
std::map<std::string, std::string> getItemProperties() const; std::map<std::string, std::string> getItemProperties() const;
std::string getItemTag() const; virtual std::string getItemTag() const;
/** /**
* Get the name of the grid. * Get the name of the grid.
......
...@@ -22,20 +22,6 @@ XdmfGridCollection::~XdmfGridCollection() ...@@ -22,20 +22,6 @@ XdmfGridCollection::~XdmfGridCollection()
const std::string XdmfGridCollection::ItemTag = "Grid"; const std::string XdmfGridCollection::ItemTag = "Grid";
boost::shared_ptr<XdmfGrid> XdmfGridCollection::getGrid(const unsigned int index)
{
return boost::const_pointer_cast<XdmfGrid>(static_cast<const XdmfGridCollection &>(*this).getGrid(index));
}
boost::shared_ptr<const XdmfGrid> XdmfGridCollection::getGrid(const unsigned int index) const
{
if(index >= mGrids.size())
{
assert(false);
}
return mGrids[index];
}
std::map<std::string, std::string> XdmfGridCollection::getItemProperties() const std::map<std::string, std::string> XdmfGridCollection::getItemProperties() const
{ {
std::map<std::string, std::string> collectionProperties; std::map<std::string, std::string> collectionProperties;
...@@ -45,9 +31,9 @@ std::map<std::string, std::string> XdmfGridCollection::getItemProperties() const ...@@ -45,9 +31,9 @@ std::map<std::string, std::string> XdmfGridCollection::getItemProperties() const
return collectionProperties; return collectionProperties;
} }
unsigned int XdmfGridCollection::getNumberOfGrids() const std::string XdmfGridCollection::getItemTag() const
{ {
return mGrids.size(); return ItemTag;
} }
boost::shared_ptr<const XdmfGridCollectionType> XdmfGridCollection::getType() const boost::shared_ptr<const XdmfGridCollectionType> XdmfGridCollection::getType() const
...@@ -55,37 +41,13 @@ boost::shared_ptr<const XdmfGridCollectionType> XdmfGridCollection::getType() co ...@@ -55,37 +41,13 @@ boost::shared_ptr<const XdmfGridCollectionType> XdmfGridCollection::getType() co
return mCollectionType; return mCollectionType;
} }
void XdmfGridCollection::insert(const boost::shared_ptr<XdmfGrid> grid)
{
mGrids.push_back(grid);
}
void XdmfGridCollection::populateItem(const std::map<std::string, std::string> & itemProperties, std::vector<boost::shared_ptr<XdmfItem> > & childItems) void XdmfGridCollection::populateItem(const std::map<std::string, std::string> & itemProperties, std::vector<boost::shared_ptr<XdmfItem> > & childItems)
{ {
mCollectionType = XdmfGridCollectionType::New(itemProperties); mCollectionType = XdmfGridCollectionType::New(itemProperties);
for(std::vector<boost::shared_ptr<XdmfItem> >::const_iterator iter = childItems.begin(); iter != childItems.end(); ++iter) XdmfDomain::populateItem(itemProperties, childItems);
{
if(boost::shared_ptr<XdmfGrid> grid = boost::shared_dynamic_cast<XdmfGrid>(*iter))
{
this->insert(grid);
}
else
{
assert(false);
}
}
XdmfGrid::populateItem(itemProperties, childItems); XdmfGrid::populateItem(itemProperties, childItems);
} }
void XdmfGridCollection::removeGrid(const unsigned int index)
{
if(index >= mGrids.size())
{
assert(false);
}
mGrids.erase(mGrids.begin() + index);
}
void XdmfGridCollection::setType(const boost::shared_ptr<const XdmfGridCollectionType> collectionType) void XdmfGridCollection::setType(const boost::shared_ptr<const XdmfGridCollectionType> collectionType)
{ {
mCollectionType = collectionType; mCollectionType = collectionType;
...@@ -93,8 +55,6 @@ void XdmfGridCollection::setType(const boost::shared_ptr<const XdmfGridCollectio ...@@ -93,8 +55,6 @@ void XdmfGridCollection::setType(const boost::shared_ptr<const XdmfGridCollectio
void XdmfGridCollection::traverse(const boost::shared_ptr<XdmfBaseVisitor> visitor) const void XdmfGridCollection::traverse(const boost::shared_ptr<XdmfBaseVisitor> visitor) const
{ {
for(std::vector<boost::shared_ptr<XdmfGrid> >::const_iterator iter = mGrids.begin(); iter != mGrids.end(); ++iter) XdmfGrid::traverse(visitor);
{ XdmfDomain::traverse(visitor);
(*iter)->accept(visitor);
}
} }
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
class XdmfGridCollectionType; class XdmfGridCollectionType;
// Includes // Includes
#include "XdmfDomain.hpp"
#include "XdmfGrid.hpp" #include "XdmfGrid.hpp"
/** /**
...@@ -15,7 +16,7 @@ class XdmfGridCollectionType; ...@@ -15,7 +16,7 @@ class XdmfGridCollectionType;
* *
* It is valid to nest collections. A spatial collection within a temporal collection is commonly used. * It is valid to nest collections. A spatial collection within a temporal collection is commonly used.
*/ */
class XdmfGridCollection : public XdmfGrid { class XdmfGridCollection : public XdmfGrid, public XdmfDomain {
public: public:
...@@ -25,30 +26,9 @@ public: ...@@ -25,30 +26,9 @@ public:
LOKI_DEFINE_VISITABLE(XdmfGridCollection, XdmfGrid) LOKI_DEFINE_VISITABLE(XdmfGridCollection, XdmfGrid)
static const std::string ItemTag; static const std::string ItemTag;
/**
* Get a grid from this collection.
*
* @param index of grid to retrieve.
* @return the requested XdmfGrid.
*/
boost::shared_ptr<XdmfGrid> getGrid(const unsigned int index);
/**
* Get a grid from this collection (const version).
*
* @param index of the grid to retrieve.
* @return the requested XdmfGrid.
*/
boost::shared_ptr<const XdmfGrid> getGrid(const unsigned int index) const;
std::map<std::string, std::string> getItemProperties() const; std::map<std::string, std::string> getItemProperties() const;
/** std::string getItemTag() const;
* Get the number of grids in this collection.
*
* @return unsigned int containing the number of XdmfGrids in this collection.
*/
unsigned int getNumberOfGrids() const;
/** /**
* Get the XdmfGridCollectionType associated with this grid collection. * Get the XdmfGridCollectionType associated with this grid collection.
...@@ -57,19 +37,8 @@ public: ...@@ -57,19 +37,8 @@ public:
*/ */
boost::shared_ptr<const XdmfGridCollectionType> getType() const; boost::shared_ptr<const XdmfGridCollectionType> getType() const;
/** using XdmfDomain::insert;
* Insert a grid into this collection. using XdmfGrid::insert;
*
* @param grid an XdmfGrid to insert into this collection.
*/
void insert(const boost::shared_ptr<XdmfGrid> grid);
/**
* Remove a grid from this collection.
*
* @param index of the XdmfGrid to remove.
*/
void removeGrid(const unsigned int index);
/** /**
* Set the XdmfGridCollectionType associated with this grid collection. * Set the XdmfGridCollectionType associated with this grid collection.
...@@ -78,7 +47,7 @@ public: ...@@ -78,7 +47,7 @@ public:
*/ */
void setType(const boost::shared_ptr<const XdmfGridCollectionType> collectionType); void setType(const boost::shared_ptr<const XdmfGridCollectionType> collectionType);
virtual void traverse(const boost::shared_ptr<XdmfBaseVisitor> visitor) const; void traverse(const boost::shared_ptr<XdmfBaseVisitor> visitor) const;
protected: protected:
...@@ -91,7 +60,6 @@ private: ...@@ -91,7 +60,6 @@ private:
void operator=(const XdmfGridCollection & collection); // Not implemented. void operator=(const XdmfGridCollection & collection); // Not implemented.
boost::shared_ptr<const XdmfGridCollectionType> mCollectionType; boost::shared_ptr<const XdmfGridCollectionType> mCollectionType;
std::vector<boost::shared_ptr<XdmfGrid> > mGrids;
}; };
#endif /* XDMFGRID_HPP_ */ #endif /* XDMFGRID_HPP_ */
#include "XdmfArray.hpp"
#include "XdmfAttribute.hpp" #include "XdmfAttribute.hpp"
#include "XdmfDomain.hpp" #include "XdmfDomain.hpp"
#include "XdmfGeometry.hpp" #include "XdmfGeometry.hpp"
...@@ -20,12 +19,14 @@ XdmfItemFactory::~XdmfItemFactory() ...@@ -20,12 +19,14 @@ 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
{ {
boost::shared_ptr<XdmfItem> newItem; boost::shared_ptr<XdmfItem> newItem = XdmfCoreItemFactory::createItem(itemTag, itemProperties);
if(itemTag.compare(XdmfArray::ItemTag) == 0)
if(newItem != NULL)
{ {
newItem = XdmfArray::New(); return newItem;
} }
else if(itemTag.compare(XdmfAttribute::ItemTag) == 0)
if(itemTag.compare(XdmfAttribute::ItemTag) == 0)
{ {
newItem = XdmfAttribute::New(); newItem = XdmfAttribute::New();
} }
...@@ -65,9 +66,5 @@ boost::shared_ptr<XdmfItem> XdmfItemFactory::createItem(const std::string & item ...@@ -65,9 +66,5 @@ boost::shared_ptr<XdmfItem> XdmfItemFactory::createItem(const std::string & item
{ {
newItem = XdmfTopology::New(); newItem = XdmfTopology::New();
} }
else
{
assert(false);
}
return newItem; return newItem;
} }
...@@ -17,12 +17,6 @@ public: ...@@ -17,12 +17,6 @@ public:
XdmfNewMacro(XdmfItemFactory); XdmfNewMacro(XdmfItemFactory);
virtual ~XdmfItemFactory(); virtual ~XdmfItemFactory();
/**
* Create a new XdmfItem.
*
* @param itemTag a string containing the tag of the XdmfItem to create.
* @param itemProperties a map of key/value properties for the the XdmfItem.
*/
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;
protected: protected:
......
#include "XdmfArray.hpp"
#include "XdmfCoreItemFactory.hpp" #include "XdmfCoreItemFactory.hpp"
XdmfCoreItemFactory::XdmfCoreItemFactory() XdmfCoreItemFactory::XdmfCoreItemFactory()
...@@ -7,3 +8,13 @@ XdmfCoreItemFactory::XdmfCoreItemFactory() ...@@ -7,3 +8,13 @@ XdmfCoreItemFactory::XdmfCoreItemFactory()
XdmfCoreItemFactory::~XdmfCoreItemFactory() XdmfCoreItemFactory::~XdmfCoreItemFactory()
{ {
} }
boost::shared_ptr<XdmfItem> XdmfCoreItemFactory::createItem(const std::string & itemTag, const std::map<std::string, std::string> & itemProperties) const
{
boost::shared_ptr<XdmfItem> newItem = boost::shared_ptr<XdmfItem>();
if(itemTag.compare(XdmfArray::ItemTag) == 0)
{
newItem = XdmfArray::New();
}
return newItem;
}
...@@ -24,8 +24,9 @@ public: ...@@ -24,8 +24,9 @@ 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.
* @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 = 0; virtual boost::shared_ptr<XdmfItem> createItem(const std::string & itemTag, const std::map<std::string, std::string> & itemProperties) const;
protected: protected:
......
...@@ -94,6 +94,10 @@ private: ...@@ -94,6 +94,10 @@ private:
} }
std::vector<boost::shared_ptr<XdmfItem> > childItems = this->read(currNode->children, xPathContext, xPathMap, xmlDir); std::vector<boost::shared_ptr<XdmfItem> > childItems = this->read(currNode->children, xPathContext, xPathMap, xmlDir);
boost::shared_ptr<XdmfItem> newItem = mItemFactory->createItem((const char *)currNode->name, itemProperties); boost::shared_ptr<XdmfItem> newItem = mItemFactory->createItem((const char *)currNode->name, itemProperties);
if(newItem == NULL)
{
assert(false);
}
newItem->populateItem(itemProperties, childItems); newItem->populateItem(itemProperties, childItems);
myItems.push_back(newItem); myItems.push_back(newItem);
xPathMap[currNode] = newItem; xPathMap[currNode] = newItem;
......
...@@ -28,16 +28,11 @@ class XdmfHDF5Writer : public XdmfVisitor, ...@@ -28,16 +28,11 @@ class XdmfHDF5Writer : public XdmfVisitor,
public: public:
virtual ~XdmfHDF5Writer();
enum Mode {
Default, Overwrite, Append
};
/** /**
* Construct XdmfHDF5Writer * Construct XdmfHDF5Writer
* *
* @param hdf5FilePath the location of the hdf5 file to output to on disk. * @param hdf5FilePath the location of the hdf5 file to output to on disk.
* @return new XdmfHDF5Writer
*/ */
static boost::shared_ptr<XdmfHDF5Writer> New(const std::string & hdf5FilePath) static boost::shared_ptr<XdmfHDF5Writer> New(const std::string & hdf5FilePath)
{ {
...@@ -45,6 +40,12 @@ public: ...@@ -45,6 +40,12 @@ public:
return p; return p;
} }
virtual ~XdmfHDF5Writer();
enum Mode {
Default, Overwrite, Append
};
/** /**
* Get the path to the hdf5 file on disk this writer is writing to. * Get the path to the hdf5 file on disk this writer is writing to.
* *
......
...@@ -23,12 +23,12 @@ int main(int argc, char* argv[]) ...@@ -23,12 +23,12 @@ int main(int argc, char* argv[])
boost::shared_ptr<XdmfGrid> childGrid1 = XdmfTestDataGenerator::createHexahedron(); boost::shared_ptr<XdmfGrid> childGrid1 = XdmfTestDataGenerator::createHexahedron();
boost::shared_ptr<XdmfGrid> childGrid2 = XdmfTestDataGenerator::createHexahedron(); boost::shared_ptr<XdmfGrid> childGrid2 = XdmfTestDataGenerator::createHexahedron();
assert(gridCollection->getNumberOfGrids() == 0); assert(gridCollection->getNumberGrids() == 0);
gridCollection->insert(childGrid1); gridCollection->insert(childGrid1);
assert(gridCollection->getNumberOfGrids() == 1); assert(gridCollection->getNumberGrids() == 1);
assert(gridCollection->getGrid(0) == childGrid1); assert(gridCollection->getGrid(0) == childGrid1);
gridCollection->removeGrid(0); gridCollection->removeGrid(0);
assert(gridCollection->getNumberOfGrids() == 0); assert(gridCollection->getNumberGrids() == 0);
gridCollection->insert(childGrid1); gridCollection->insert(childGrid1);
gridCollection->insert(childGrid2); gridCollection->insert(childGrid2);
......
...@@ -466,7 +466,7 @@ int main(int argc, char* argv[]) ...@@ -466,7 +466,7 @@ int main(int argc, char* argv[])
boost::shared_ptr<XdmfReader> reader = XdmfReader::New(); boost::shared_ptr<XdmfReader> reader = XdmfReader::New();
boost::shared_ptr<XdmfDomain> domain = boost::shared_dynamic_cast<XdmfDomain>(reader->read(argv[1])); boost::shared_ptr<XdmfDomain> domain = boost::shared_dynamic_cast<XdmfDomain>(reader->read(argv[1]));
if(domain->getNumberOfGrids() <= 0) if(domain->getNumberGrids() <= 0)
{ {
std::cout << "No grids to partition" << std::endl; std::cout << "No grids to partition" << std::endl;
return 1; return 1;
......
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