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
{
this->insert(grid);
}
else
{
assert(false);
}
}
}
......
......@@ -14,7 +14,7 @@ class XdmfGridCollection;
* 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.
*/
class XdmfDomain : public XdmfItem {
class XdmfDomain : public virtual XdmfItem {
public:
......@@ -58,7 +58,7 @@ public:
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.
......
......@@ -190,10 +190,6 @@ void XdmfGrid::populateItem(const std::map<std::string, std::string> & itemPrope
{
mTopology = topology;
}
else
{
//assert(false);
}
}
}
......
......@@ -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
* to specify collections of mesh elements.
*/
class XdmfGrid : public XdmfItem {
class XdmfGrid : public virtual XdmfItem {
public:
......@@ -77,7 +77,7 @@ public:
std::map<std::string, std::string> getItemProperties() const;
std::string getItemTag() const;
virtual std::string getItemTag() const;
/**
* Get the name of the grid.
......
......@@ -22,20 +22,6 @@ XdmfGridCollection::~XdmfGridCollection()
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> collectionProperties;
......@@ -45,9 +31,9 @@ std::map<std::string, std::string> XdmfGridCollection::getItemProperties() const
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
......@@ -55,37 +41,13 @@ boost::shared_ptr<const XdmfGridCollectionType> XdmfGridCollection::getType() co
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)
{
mCollectionType = XdmfGridCollectionType::New(itemProperties);
for(std::vector<boost::shared_ptr<XdmfItem> >::const_iterator iter = childItems.begin(); iter != childItems.end(); ++iter)
{
if(boost::shared_ptr<XdmfGrid> grid = boost::shared_dynamic_cast<XdmfGrid>(*iter))
{
this->insert(grid);
}
else
{
assert(false);
}
}
XdmfDomain::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)
{
mCollectionType = collectionType;
......@@ -93,8 +55,6 @@ void XdmfGridCollection::setType(const boost::shared_ptr<const XdmfGridCollectio
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)
{
(*iter)->accept(visitor);
}
XdmfGrid::traverse(visitor);
XdmfDomain::traverse(visitor);
}
......@@ -5,6 +5,7 @@
class XdmfGridCollectionType;
// Includes
#include "XdmfDomain.hpp"
#include "XdmfGrid.hpp"
/**
......@@ -15,7 +16,7 @@ class XdmfGridCollectionType;
*
* 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:
......@@ -25,30 +26,9 @@ public:
LOKI_DEFINE_VISITABLE(XdmfGridCollection, XdmfGrid)
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;
/**
* Get the number of grids in this collection.
*
* @return unsigned int containing the number of XdmfGrids in this collection.
*/
unsigned int getNumberOfGrids() const;
std::string getItemTag() const;
/**
* Get the XdmfGridCollectionType associated with this grid collection.
......@@ -57,19 +37,8 @@ public:
*/
boost::shared_ptr<const XdmfGridCollectionType> getType() const;
/**
* Insert a grid into this collection.
*
* @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);
using XdmfDomain::insert;
using XdmfGrid::insert;
/**
* Set the XdmfGridCollectionType associated with this grid collection.
......@@ -78,7 +47,7 @@ public:
*/
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:
......@@ -91,7 +60,6 @@ private:
void operator=(const XdmfGridCollection & collection); // Not implemented.
boost::shared_ptr<const XdmfGridCollectionType> mCollectionType;
std::vector<boost::shared_ptr<XdmfGrid> > mGrids;
};
#endif /* XDMFGRID_HPP_ */
#include "XdmfArray.hpp"
#include "XdmfAttribute.hpp"
#include "XdmfDomain.hpp"
#include "XdmfGeometry.hpp"
......@@ -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> newItem;
if(itemTag.compare(XdmfArray::ItemTag) == 0)
boost::shared_ptr<XdmfItem> newItem = XdmfCoreItemFactory::createItem(itemTag, itemProperties);
if(newItem != NULL)
{
newItem = XdmfArray::New();
return newItem;
}
else if(itemTag.compare(XdmfAttribute::ItemTag) == 0)
if(itemTag.compare(XdmfAttribute::ItemTag) == 0)
{
newItem = XdmfAttribute::New();
}
......@@ -65,9 +66,5 @@ boost::shared_ptr<XdmfItem> XdmfItemFactory::createItem(const std::string & item
{
newItem = XdmfTopology::New();
}
else
{
assert(false);
}
return newItem;
}
......@@ -17,12 +17,6 @@ public:
XdmfNewMacro(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;
protected:
......
#include "XdmfArray.hpp"
#include "XdmfCoreItemFactory.hpp"
XdmfCoreItemFactory::XdmfCoreItemFactory()
......@@ -7,3 +8,13 @@ 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:
*
* @param itemTag a string containing the tag of the XdmfItem to create.
* @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:
......
......@@ -94,6 +94,10 @@ private:
}
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);
if(newItem == NULL)
{
assert(false);
}
newItem->populateItem(itemProperties, childItems);
myItems.push_back(newItem);
xPathMap[currNode] = newItem;
......
......@@ -28,16 +28,11 @@ class XdmfHDF5Writer : public XdmfVisitor,
public:
virtual ~XdmfHDF5Writer();
enum Mode {
Default, Overwrite, Append
};
/**
* Construct XdmfHDF5Writer
*
* @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)
{
......@@ -45,6 +40,12 @@ public:
return p;
}
virtual ~XdmfHDF5Writer();
enum Mode {
Default, Overwrite, Append
};
/**
* Get the path to the hdf5 file on disk this writer is writing to.
*
......
......@@ -23,12 +23,12 @@ int main(int argc, char* argv[])
boost::shared_ptr<XdmfGrid> childGrid1 = XdmfTestDataGenerator::createHexahedron();
boost::shared_ptr<XdmfGrid> childGrid2 = XdmfTestDataGenerator::createHexahedron();
assert(gridCollection->getNumberOfGrids() == 0);
assert(gridCollection->getNumberGrids() == 0);
gridCollection->insert(childGrid1);
assert(gridCollection->getNumberOfGrids() == 1);
assert(gridCollection->getNumberGrids() == 1);
assert(gridCollection->getGrid(0) == childGrid1);
gridCollection->removeGrid(0);
assert(gridCollection->getNumberOfGrids() == 0);
assert(gridCollection->getNumberGrids() == 0);
gridCollection->insert(childGrid1);
gridCollection->insert(childGrid2);
......
......@@ -466,7 +466,7 @@ int main(int argc, char* argv[])
boost::shared_ptr<XdmfReader> reader = XdmfReader::New();
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;
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