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()
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()
{
static boost::shared_ptr<const XdmfGeometryType> p(new XdmfGeometryType("VXVY", 2));
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) :
mDimensions(dimensions),
mName(name)
......@@ -107,17 +95,15 @@ boost::shared_ptr<const XdmfGeometryType> XdmfGeometryType::New(const std::map<s
{
return VXVYVZ();
}
else if(typeVal.compare("ORIGIN_DXDYDZ") == 0)
{
return Origin_DXDYDZ();
}
else if(typeVal.compare("VXVY") == 0)
{
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
{
......@@ -142,6 +128,11 @@ unsigned int XdmfGeometryType::getDimensions() const
return mDimensions;
}
std::string XdmfGeometryType::getName() const
{
return mName;
}
void XdmfGeometryType::getProperties(std::map<std::string, std::string> & collectedProperties) const
{
collectedProperties["Type"] = mName;
......
......@@ -37,9 +37,7 @@ public:
static boost::shared_ptr<const XdmfGeometryType> X_Y_Z();
static boost::shared_ptr<const XdmfGeometryType> X_Y();
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> Origin_DXDY();
/**
* Get the dimensions of this geometry type - i.e. XYZ = 3.
......@@ -48,6 +46,13 @@ public:
*/
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;
/*
......
......@@ -5,6 +5,7 @@
* Author: kleiter
*/
#include <boost/tokenizer.hpp>
#include <cmath>
#include "XdmfArray.hpp"
#include "XdmfGeometry.hpp"
......@@ -160,7 +161,7 @@ public:
unsigned int getNodesPerElement() const
{
// 2 ^ Dimensions
// 2^Dimensions
// e.g. 1D = 2 nodes per element and 2D = 4 nodes per element.
return (unsigned int)std::pow(2, (double)mRegularGrid->getDimensions()->getSize());
}
......@@ -295,6 +296,22 @@ boost::shared_ptr<const XdmfArray> XdmfGridRegular::getOrigin() const
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)
{
mImpl->mBrickSize = brickSize;
......
......@@ -31,7 +31,7 @@ public:
* @return constructed structured grid.
*/
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).
......@@ -50,7 +50,7 @@ public:
*/
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 double originX = 0, const double originY = 0, const double originZ = 0);
const double originX, const double originY, const double originZ);
virtual ~XdmfGridRegular();
......@@ -129,7 +129,7 @@ protected:
XdmfGridRegular(const double brickSizeX, const double brickSizeY, const double brickSizeZ,
const unsigned int numPointsX, const unsigned int numPointsY, const unsigned int numPointsZ,
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:
......
#include "XdmfAttribute.hpp"
#include "XdmfDomain.hpp"
#include "XdmfGeometry.hpp"
#include "XdmfGeometryType.hpp"
#include "XdmfGrid.hpp"
#include "XdmfGridCollection.hpp"
#include "XdmfGridRegular.hpp"
#include "XdmfInformation.hpp"
#include "XdmfItemFactory.hpp"
#include "XdmfMap.hpp"
......@@ -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)
{
......@@ -35,47 +37,63 @@ boost::shared_ptr<XdmfItem> XdmfItemFactory::createItem(const std::string & item
if(itemTag.compare(XdmfAttribute::ItemTag) == 0)
{
newItem = XdmfAttribute::New();
return XdmfAttribute::New();
}
else if(itemTag.compare(XdmfDomain::ItemTag) == 0)
{
newItem = XdmfDomain::New();
return XdmfDomain::New();
}
else if(itemTag.compare(XdmfGeometry::ItemTag) == 0)
{
newItem = XdmfGeometry::New();
return XdmfGeometry::New();
}
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");
if(gridType != itemProperties.end() && gridType->second.compare("Collection") == 0)
{
newItem = XdmfGridCollection::New();
return XdmfGridCollection::New();
}
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)
{
newItem = XdmfInformation::New();
return XdmfInformation::New();
}
else if(itemTag.compare(XdmfMap::ItemTag) == 0)
{
newItem = XdmfMap::New();
return XdmfMap::New();
}
else if(itemTag.compare(XdmfSet::ItemTag) == 0)
{
newItem = XdmfSet::New();
return XdmfSet::New();
}
else if(itemTag.compare(XdmfTime::ItemTag) == 0)
{
newItem = XdmfTime::New();
return XdmfTime::New();
}
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:
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:
......
......@@ -16,6 +16,7 @@ boost::shared_ptr<XdmfTopology> XdmfTopology::New()
}
XdmfTopology::XdmfTopology() :
mDimensions(""),
mType(XdmfTopologyType::NoTopologyType())
{
}
......@@ -26,6 +27,17 @@ XdmfTopology::~XdmfTopology()
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
{
return ItemTag;
......@@ -62,6 +74,11 @@ void XdmfTopology::populateItem(const std::map<std::string, std::string> & itemP
{
XdmfItem::populateItem(itemProperties, childItems, reader);
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)
{
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
void XdmfTopology::setType(const boost::shared_ptr<const XdmfTopologyType> type)
{
mType = type;
}
......@@ -30,6 +30,8 @@ public:
LOKI_DEFINE_VISITABLE(XdmfTopology, XdmfArray)
static const std::string ItemTag;
std::string getDimensions() const;
std::map<std::string, std::string> getItemProperties() const;
std::string getItemTag() const;
......@@ -65,6 +67,7 @@ private:
XdmfTopology(const XdmfTopology & topology); // Not implemented.
void operator=(const XdmfTopology & topology); // Not implemented.
std::string mDimensions;
boost::shared_ptr<const XdmfTopologyType> mType;
};
......
......@@ -210,7 +210,7 @@ boost::shared_ptr<const XdmfTopologyType> XdmfTopologyType::ThreeDCoRectMesh()
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),
mName(name),
mNodesPerElement(nodesPerElement)
......@@ -322,19 +322,20 @@ boost::shared_ptr<const XdmfTopologyType> XdmfTopologyType::New(const std::map<s
{
return Mixed();
}
/*
else if(typeVal.compare("2DSMESH") == 0)
/*else if(typeVal.compare("2DSMESH") == 0)
{
return TwoDSMesh();
}
else if(typeVal.compare("2DRECTMESH") == 0)
{
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)
{
return ThreeDSMesh();
......@@ -342,12 +343,7 @@ boost::shared_ptr<const XdmfTopologyType> XdmfTopologyType::New(const std::map<s
else if(typeVal.compare("3DRECTMESH") == 0)
{
return ThreeDRectMesh();
}
else if(typeVal.compare("3DCORECTMESH") == 0)
{
return ThreeDCoRectMesh();
}
*/
}*/
else
{
assert(false);
......@@ -371,6 +367,11 @@ XdmfTopologyType::CellType XdmfTopologyType::getCellType() const
return mCellType;
}
std::string XdmfTopologyType::getName() const
{
return mName;
}
unsigned int XdmfTopologyType::getNodesPerElement() const
{
return mNodesPerElement;
......
......@@ -88,12 +88,19 @@ public:
//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.
*/
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.
*
......@@ -126,7 +133,7 @@ protected:
* by Xdmf should be accessed through more specific static methods that construct XdmfTopologyType -
* 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:
......@@ -137,7 +144,7 @@ private:
CellType mCellType;
std::string mName;
int mNodesPerElement;
unsigned int mNodesPerElement;
};
#endif /* XDMFTOPOLOGYTYPE_HPP_ */
......@@ -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)
{
newItem = XdmfArray::New();
return XdmfArray::New();
}
return newItem;
return boost::shared_ptr<XdmfItem>();;
}
......@@ -7,6 +7,7 @@ class XdmfItem;
// Includes
#include <boost/shared_ptr.hpp>
#include <map>
#include <vector>
/**
* @brief Factory that constructs XdmfItems using tags and properties.
......@@ -24,9 +25,11 @@ 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.
* @param childItems the children of the XdmfItem to create.
*
* @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:
......
......@@ -129,7 +129,7 @@ public:
currAttribute = currAttribute->next;
}
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)
{
assert(false);
......
......@@ -43,6 +43,7 @@ CLEAN_CXX_TEST(TestXdmfGridCollection
)
CLEAN_CXX_TEST(TestXdmfGridRegular
TestXdmfGridRegular1.xmf
TestXdmfGridRegular2.xmf
)
CLEAN_CXX_TEST(TestXdmfReader
TestXdmfReader1.h5
......
......@@ -12,9 +12,11 @@ int main(int, char *)
boost::shared_ptr<XdmfGeometry> geometry = XdmfGeometry::New();
assert(geometry->getType() == XdmfGeometryType::NoGeometryType());
assert(geometry->getType()->getDimensions() == 0);
assert(geometry->getType()->getName().compare("None") == 0);
geometry->setType(XdmfGeometryType::XYZ());
assert(geometry->getType() == XdmfGeometryType::XYZ());
assert(geometry->getType()->getDimensions() == 3);
assert(geometry->getType()->getName().compare("XYZ") == 0);
return 0;
}
......@@ -2,12 +2,11 @@
#include "XdmfGeometry.hpp"
#include "XdmfGeometryType.hpp"
#include "XdmfGridRegular.hpp"
#include "XdmfReader.hpp"
#include "XdmfTopology.hpp"
#include "XdmfTopologyType.hpp"
#include "XdmfWriter.hpp"
#include <iostream>
int main(int, char *)
{
boost::shared_ptr<XdmfGridRegular> grid = XdmfGridRegular::New(1, 1, 1, 1, 1, 1, 0, 0, 0);
......@@ -86,8 +85,13 @@ int main(int, char *)
// Input / Output
boost::shared_ptr<XdmfWriter> writer = XdmfWriter::New("TestXdmfGridRegular1.xmf");
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;
}
......@@ -17,10 +17,12 @@ int main(int, char *)
boost::shared_ptr<XdmfTopology> top = XdmfTopology::New();
assert(top->getType() == XdmfTopologyType::NoTopologyType());
assert(top->getType()->getNodesPerElement() == 0);
assert(top->getType()->getName().compare("NoTopology") == 0);
top->setType(XdmfTopologyType::Hexahedron());
assert(top->getType() == XdmfTopologyType::Hexahedron());
assert(top->getType()->getNodesPerElement() == 8);
assert(top->getType()->getName().compare("Hexahedron") == 0);
boost::shared_ptr<const XdmfTopologyType> polygon = XdmfTopologyType::Polygon(6);
boost::shared_ptr<const XdmfTopologyType> polygon6 = XdmfTopologyType::Polygon(6);
......
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