diff --git a/CMakeLists.txt b/CMakeLists.txt index 002281b2b00795bc56b414b3fc0ee3da9e86b51e..1b69311e37d35e28a6f0f92685f36a2a2461ab8d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -135,6 +135,7 @@ if(NOT XDMF_BUILD_CORE_ONLY) XdmfGrid XdmfGridCollection XdmfGridCollectionType + XdmfGridRectilinear XdmfGridRegular XdmfItemFactory XdmfMap diff --git a/XdmfGeometryType.cpp b/XdmfGeometryType.cpp index c5e3a6afc9e57eb5ac6aeac5d6e94f083bd7b65d..39b4e8ecd838f11d8b172fb94be14f09e274f378 100644 --- a/XdmfGeometryType.cpp +++ b/XdmfGeometryType.cpp @@ -99,12 +99,6 @@ boost::shared_ptr XdmfGeometryType::New(const std::map p(new XdmfGeometryType("REGULAR", 0)); - return p; - } else { assert(false); diff --git a/XdmfGeometryType.hpp b/XdmfGeometryType.hpp index 2a89e04888b2fa12be6d58544cbcfc54ebdb0ac6..ca5954c352221c521ee620afcc992d3bfcdba0c5 100644 --- a/XdmfGeometryType.hpp +++ b/XdmfGeometryType.hpp @@ -71,13 +71,13 @@ public: */ bool operator!=(const XdmfGeometryType & geometryType) const; - /** - * Compare two XdmfGeometryType for equality (for wrapping) - * - * @param geometryType a boost shared pointer to an XdmfGeometryType to compare equality to. - * @return true if the XdmfGeometryType are equal. - */ - bool IsEqual(boost::shared_ptr geometryType); + /** + * Compare two XdmfGeometryType for equality (for wrapping) + * + * @param geometryType a boost shared pointer to an XdmfGeometryType to compare equality to. + * @return true if the XdmfGeometryType are equal. + */ + bool IsEqual(boost::shared_ptr geometryType); protected: diff --git a/XdmfGridRectilinear.cpp b/XdmfGridRectilinear.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6512d9fd18919ca4b89f29188d4cc02205a205f1 --- /dev/null +++ b/XdmfGridRectilinear.cpp @@ -0,0 +1,322 @@ +/* + * XdmfGridRectilinear.cpp + * + * Created on: Jan 25, 2010 + * Author: kleiter + */ + +#include +#include "XdmfArray.hpp" +#include "XdmfGeometry.hpp" +#include "XdmfGeometryType.hpp" +#include "XdmfGridRectilinear.hpp" +#include "XdmfTopology.hpp" +#include "XdmfTopologyType.hpp" + +/** + * PIMPL + */ +class XdmfGridRectilinear::XdmfGridRectilinearImpl { + +public: + + class XdmfGeometryRectilinear : public XdmfGeometry + { + + public: + + static boost::shared_ptr New(XdmfGridRectilinear * const rectilinearGrid) + { + boost::shared_ptr p(new XdmfGeometryRectilinear(rectilinearGrid)); + return p; + } + + unsigned int getNumberPoints() const + { + const boost::shared_ptr dimensions = mRectilinearGrid->getDimensions(); + if(dimensions->getSize() == 0) + { + return 0; + } + unsigned int toReturn = 1; + for(unsigned int i=0; igetSize(); ++i) + { + toReturn *= dimensions->getValue(i); + } + return toReturn; + } + + void traverse(const boost::shared_ptr visitor) + { + const std::vector > & coordinates = mRectilinearGrid->getCoordinates(); + for(std::vector >::const_iterator iter = coordinates.begin(); iter != coordinates.end(); ++iter) + { + (*iter)->accept(visitor); + } + } + + private: + + XdmfGeometryRectilinear(XdmfGridRectilinear * const rectilinearGrid) : + mRectilinearGrid(rectilinearGrid) + { + this->setType(XdmfGeometryTypeRectilinear::New(mRectilinearGrid)); + } + + XdmfGridRectilinear * const mRectilinearGrid; + }; + + class XdmfGeometryTypeRectilinear : public XdmfGeometryType + { + + public: + + static boost::shared_ptr New(const XdmfGridRectilinear * const rectilinearGrid) + { + boost::shared_ptr p(new XdmfGeometryTypeRectilinear(rectilinearGrid)); + return p; + } + + unsigned int getDimensions() const + { + return mRectilinearGrid->getDimensions()->getSize(); + } + + void getProperties(std::map & collectedProperties) const + { + const unsigned int dimensions = this->getDimensions(); + if(dimensions == 3) + { + collectedProperties["Type"] = "ORIGIN_DXDYDZ"; + } + else if(dimensions == 2) + { + collectedProperties["Type"] = "ORIGIN_DXDY"; + } + else + { + assert(false); + } + } + + private: + + XdmfGeometryTypeRectilinear(const XdmfGridRectilinear * const rectilinearGrid) : + XdmfGeometryType("", 0), + mRectilinearGrid(mRectilinearGrid) + { + } + + const XdmfGridRectilinear * const mRectilinearGrid; + + }; + + class XdmfTopologyRectilinear : public XdmfTopology + { + + public: + + static boost::shared_ptr New(const XdmfGridRectilinear * const rectilinearGrid) + { + boost::shared_ptr p(new XdmfTopologyRectilinear(rectilinearGrid)); + return p; + } + + unsigned int getNumberElements() const + { + const boost::shared_ptr dimensions = mRectilinearGrid->getDimensions(); + if(dimensions->getSize() == 0) + { + return 0; + } + unsigned int toReturn = 1; + for(unsigned int i=0; igetSize(); ++i) + { + toReturn *= (dimensions->getValue(i) - 1); + } + return toReturn; + } + + private: + + XdmfTopologyRectilinear(const XdmfGridRectilinear * const rectilinearGrid) : + mRectilinearGrid(rectilinearGrid) + { + this->setType(XdmfTopologyTypeRectilinear::New(rectilinearGrid)); + } + + const XdmfGridRectilinear * const mRectilinearGrid; + }; + + class XdmfTopologyTypeRectilinear : public XdmfTopologyType + { + + public: + + static boost::shared_ptr New(const XdmfGridRectilinear * const rectilinearGrid) + { + boost::shared_ptr p(new XdmfTopologyTypeRectilinear(rectilinearGrid)); + return p; + } + + unsigned int getNodesPerElement() const + { + // 2^Dimensions + // e.g. 1D = 2 nodes per element and 2D = 4 nodes per element. + return (unsigned int)std::pow(2, (double)mRectilinearGrid->getDimensions()->getSize()); + } + + void getProperties(std::map & collectedProperties) const + { + boost::shared_ptr dimensions = mRectilinearGrid->getDimensions(); + if(dimensions->getSize() == 3) + { + collectedProperties["Type"] = "3DRectMesh"; + } + else if(dimensions->getSize() == 2) + { + collectedProperties["Type"] = "2DRectMesh"; + } + else + { + assert(false); + } + collectedProperties["Dimensions"] = dimensions->getValuesString(); + } + + private: + + XdmfTopologyTypeRectilinear(const XdmfGridRectilinear * const rectilinearGrid) : + XdmfTopologyType(0, "foo", XdmfTopologyType::Structured), + mRectilinearGrid(rectilinearGrid) + { + } + + const XdmfGridRectilinear * const mRectilinearGrid; + + }; + + XdmfGridRectilinearImpl(const std::vector > & coordinates) : + mCoordinates(coordinates.begin(), coordinates.end()) + { + } + + std::vector > mCoordinates; + +}; + +boost::shared_ptr XdmfGridRectilinear::New(const boost::shared_ptr xCoordinates, + const boost::shared_ptr yCoordinates) +{ + std::vector > axesCoordinates; + axesCoordinates.resize(2); + axesCoordinates[0] = xCoordinates; + axesCoordinates[1] = yCoordinates; + boost::shared_ptr p(new XdmfGridRectilinear(axesCoordinates)); + return p; +} + +boost::shared_ptr XdmfGridRectilinear::New(const boost::shared_ptr xCoordinates, + const boost::shared_ptr yCoordinates, const boost::shared_ptr zCoordinates) +{ + std::vector > axesCoordinates; + axesCoordinates.resize(3); + axesCoordinates[0] = xCoordinates; + axesCoordinates[1] = yCoordinates; + axesCoordinates[2] = zCoordinates; + boost::shared_ptr p(new XdmfGridRectilinear(axesCoordinates)); + return p; +} + +boost::shared_ptr XdmfGridRectilinear::New(const std::vector > & axesCoordinates) +{ + boost::shared_ptr p(new XdmfGridRectilinear(axesCoordinates)); + return p; +} + +XdmfGridRectilinear::XdmfGridRectilinear(const std::vector > & axesCoordinates) : + mImpl(new XdmfGridRectilinearImpl(axesCoordinates)) +{ + this->setGeometry(XdmfGridRectilinearImpl::XdmfGeometryRectilinear::New(this)); + this->setTopology(XdmfGridRectilinearImpl::XdmfTopologyRectilinear::New(this)); +} + +XdmfGridRectilinear::~XdmfGridRectilinear() +{ + delete mImpl; +} + +const std::string XdmfGridRectilinear::ItemTag = "Grid"; + +boost::shared_ptr XdmfGridRectilinear::getCoordinates(const unsigned int axisIndex) +{ + return boost::const_pointer_cast(static_cast(*this).getCoordinates(axisIndex)); +} + +boost::shared_ptr XdmfGridRectilinear::getCoordinates(const unsigned int axisIndex) const +{ + if(axisIndex < mImpl->mCoordinates.size()) + { + return mImpl->mCoordinates[axisIndex]; + } + return boost::shared_ptr(); +} + +std::vector > XdmfGridRectilinear::getCoordinates() +{ + return mImpl->mCoordinates; +} + +const std::vector > XdmfGridRectilinear::getCoordinates() const +{ + return mImpl->mCoordinates; +} + +boost::shared_ptr XdmfGridRectilinear::getDimensions() +{ + return boost::const_pointer_cast(static_cast(*this).getDimensions()); +} + +boost::shared_ptr XdmfGridRectilinear::getDimensions() const +{ + boost::shared_ptr dimensions = XdmfArray::New(); + dimensions->reserve(mImpl->mCoordinates.size()); + for(std::vector >::const_iterator iter = mImpl->mCoordinates.begin(); iter != mImpl->mCoordinates.end(); ++iter) + { + dimensions->pushBack((*iter)->getSize()); + } + return dimensions; +} + +void XdmfGridRectilinear::populateItem(const std::map & itemProperties, std::vector > & childItems, const XdmfCoreReader * const reader) +{ + XdmfGrid::populateItem(itemProperties, childItems, reader); + + for(std::vector >::const_iterator iter = childItems.begin(); iter != childItems.end(); ++iter) + { + if(boost::shared_ptr rectilinearGrid = boost::shared_dynamic_cast(*iter)) + { + this->setCoordinates(rectilinearGrid->getCoordinates()); + break; + } + } +} + +void XdmfGridRectilinear::setCoordinates(const unsigned int axisIndex, const boost::shared_ptr axisCoordinates) +{ + if(mImpl->mCoordinates.size() <= axisIndex) + { + mImpl->mCoordinates.reserve(axisIndex + 1); + unsigned int numArraysToInsert = axisIndex - mImpl->mCoordinates.size() + 1; + for(unsigned int i=0; imCoordinates.push_back(XdmfArray::New()); + } + } + mImpl->mCoordinates[axisIndex] = axisCoordinates; +} + +void XdmfGridRectilinear::setCoordinates(const std::vector > axesCoordinates) +{ + mImpl->mCoordinates = axesCoordinates; +} diff --git a/XdmfGridRectilinear.hpp b/XdmfGridRectilinear.hpp new file mode 100644 index 0000000000000000000000000000000000000000..a2e836f858fb530d51596620ff8eeb7d71d4d241 --- /dev/null +++ b/XdmfGridRectilinear.hpp @@ -0,0 +1,138 @@ +#ifndef XDMFGRIDRECTILINEAR_HPP_ +#define XDMFGRIDRECTILINEAR_HPP_ + +// Includes +#include "XdmfGrid.hpp" + +/** + * @brief A mesh consisting of cells and points arranged on a regular lattice in space. + * + * XdmfGridRectilinear represents a mesh of cells and point arranged on a regular lattice in space. + * Points are arranged along coordinate axes, but the spacing between points may vary. + * + * In order to define a rectilinear grid, the coordinates along each axis direction + * must be specified. + * + */ +class XdmfGridRectilinear : public XdmfGrid { + +public: + + /** + * Create a new rectilinear grid (Two dimensional). + * + * @param xCoordinates the coordinates of points along the x axis + * @param yCoordinates the coordinates of points along the y axis. + * + * @return constructed rectilinear grid. + */ + static boost::shared_ptr New(const boost::shared_ptr xCoordinates, const boost::shared_ptr yCoordinates); + + /** + * Create a new rectilinear grid (Three dimensional). + * + * @param xCoordinates the coordinates of points along the x axis + * @param yCoordinates the coordinates of points along the y axis. + * @param zCoordinates the coordinates of points along the z axis. + * + * @return constructed rectilinear grid. + */ + static boost::shared_ptr New(const boost::shared_ptr xCoordinates, const boost::shared_ptr yCoordinates, + const boost::shared_ptr zCoordinates); + + /** + * Create a new rectilinear grid (N dimensional). + * + * @param axesCoordinates the coordinates of points along each axis. + * + * @return constructed rectilinear grid. + */ + static boost::shared_ptr New(const std::vector > & axesCoordinates); + + virtual ~XdmfGridRectilinear(); + + LOKI_DEFINE_VISITABLE(XdmfGridRectilinear, XdmfGrid) + static const std::string ItemTag; + + /** + * Get the coordinates of the grid along a single axis. + * + * @param axisIndex the index of the axis to retrieve, (i.e. 0 for x-axis). If no array exists at the index, return NULL. + * + * @return array of coordinates along + */ + boost::shared_ptr getCoordinates(const unsigned int axisIndex); + + /** + * Get the coordinates of the grid along a single axis (const version). + * + * @param axisIndex the index of the axis to retrieve (i.e. 0 for x-axis). If no array exists at the index, return NULL. + * + * @return array of coordinates along + */ + boost::shared_ptr getCoordinates(const unsigned int axisIndex) const; + + /** + * Get the coordinates of the grid along all axes. + * + * @return vector containing an array of coordinates along each direction. + */ + std::vector > getCoordinates(); + + /** + * Get the coordinates of the grid along all axes (const version). + * + * @return vector containing an array of coordinates along each direction. + */ + const std::vector > getCoordinates() const; + + /** + * Get the dimensions of the grid, the number of points in each direction. + * + * @return XdmfArray containing dimensions of this grid. + */ + boost::shared_ptr getDimensions(); + + /** + * Get the dimensions of the grid, the number of points in each direction (const version). + * + * @return XdmfArray containing the dimensions of this grid. + */ + boost::shared_ptr getDimensions() const; + + /** + * Set the coordinates of the grid along a single axis. + * + * @param axisIndex the index of the axis to set (i.e. 0 for x-axis). + * @param axisCoordinates the coordinates of points along a single axis to set. + */ + void setCoordinates(const unsigned int axisIndex, const boost::shared_ptr axisCoordinates); + + /** + * Set the coordinates of the grid along all axes. + * + * @param axesCoordinates the coordinates of points along each axis. + */ + void setCoordinates(const std::vector > axesCoordinates); + +protected: + + XdmfGridRectilinear(const std::vector > & axesCoordinates); + + void populateItem(const std::map & itemProperties, std::vector > & childItems, const XdmfCoreReader * const reader); + +private: + + /** + * PIMPL + */ + class XdmfGridRectilinearImpl; + + XdmfGridRectilinear(const XdmfGridRectilinear & grid); // Not implemented. + void operator=(const XdmfGridRectilinear & grid); // Not implemented. + + XdmfGridRectilinearImpl * mImpl; + +}; + +#endif /* XDMFGRIDRECTILINEAR_HPP_ */ diff --git a/XdmfGridRegular.cpp b/XdmfGridRegular.cpp index 7fdc59d03dd5d9a64924d28e6eae86e1081fce10..884a101d58cfde58fa7b15760625dda08ed00cdd 100644 --- a/XdmfGridRegular.cpp +++ b/XdmfGridRegular.cpp @@ -5,7 +5,6 @@ * Author: kleiter */ -#include #include #include "XdmfArray.hpp" #include "XdmfGeometry.hpp" @@ -60,7 +59,7 @@ public: XdmfGeometryRegular(XdmfGridRegular * const regularGrid) : mRegularGrid(regularGrid) { - this->setType(XdmfGeometryTypeRegular::New(regularGrid)); + this->setType(XdmfGeometryTypeRegular::New(mRegularGrid)); } XdmfGridRegular * const mRegularGrid; @@ -84,12 +83,12 @@ public: void getProperties(std::map & collectedProperties) const { - const boost::shared_ptr dimensions = mRegularGrid->getDimensions(); - if(dimensions->getSize() == 3) + const unsigned int dimensions = this->getDimensions(); + if(dimensions == 3) { collectedProperties["Type"] = "ORIGIN_DXDYDZ"; } - else if(dimensions->getSize() == 2) + else if(dimensions == 2) { collectedProperties["Type"] = "ORIGIN_DXDY"; } @@ -196,14 +195,11 @@ public: }; - XdmfGridRegularImpl(const unsigned int dimension) : - mBrickSize(XdmfArray::New()), - mDimensions(XdmfArray::New()), - mOrigin(XdmfArray::New()) + XdmfGridRegularImpl(const boost::shared_ptr brickSize, const boost::shared_ptr numPoints, const boost::shared_ptr origin) : + mBrickSize(brickSize), + mDimensions(numPoints), + mOrigin(origin) { - mBrickSize->initialize(dimension); - mDimensions->initialize(dimension); - mOrigin->initialize(dimension); } boost::shared_ptr mBrickSize; @@ -215,7 +211,19 @@ public: boost::shared_ptr XdmfGridRegular::New(const double brickSizeX, const double brickSizeY, const unsigned int numPointsX, const unsigned int numPointsY, const double originX, const double originY) { - boost::shared_ptr p(new XdmfGridRegular(brickSizeX, brickSizeY, numPointsX, numPointsY, originX, originY)); + boost::shared_ptr brickSize = XdmfArray::New(); + brickSize->resize(2); + brickSize->insert(0, brickSizeX); + brickSize->insert(1, brickSizeY); + boost::shared_ptr numPoints = XdmfArray::New(); + numPoints->resize(2); + numPoints->insert(0, numPointsX); + numPoints->insert(1, numPointsY); + boost::shared_ptr origin = XdmfArray::New(); + origin->resize(2); + origin->insert(0, originX); + origin->insert(1, originY); + boost::shared_ptr p(new XdmfGridRegular(brickSize, numPoints, origin)); return p; } @@ -223,40 +231,38 @@ boost::shared_ptr XdmfGridRegular::New(const double brickSizeX, const unsigned int numPointsX, const unsigned int numPointsY, const unsigned int numPointsZ, const double originX, const double originY, const double originZ) { - boost::shared_ptr p(new XdmfGridRegular(brickSizeX, brickSizeY, brickSizeZ, numPointsX, numPointsY, numPointsZ, originX, originY, originZ)); + boost::shared_ptr brickSize = XdmfArray::New(); + brickSize->resize(3); + brickSize->insert(0, brickSizeX); + brickSize->insert(1, brickSizeY); + brickSize->insert(2, brickSizeZ); + boost::shared_ptr numPoints = XdmfArray::New(); + numPoints->resize(3); + numPoints->insert(0, numPointsX); + numPoints->insert(1, numPointsY); + numPoints->insert(2, numPointsZ); + boost::shared_ptr origin = XdmfArray::New(); + origin->resize(3); + origin->insert(0, originX); + origin->insert(1, originY); + origin->insert(2, originZ); + boost::shared_ptr p(new XdmfGridRegular(brickSize, numPoints, origin)); return p; } -XdmfGridRegular::XdmfGridRegular(const double brickSizeX, const double brickSizeY, const unsigned int numPointsX, - const unsigned int numPointsY, const double originX, const double originY) : - mImpl(new XdmfGridRegularImpl(2)) +boost::shared_ptr XdmfGridRegular::New(const boost::shared_ptr brickSize, const boost::shared_ptr numPoints, + const boost::shared_ptr origin) { - this->setGeometry(XdmfGridRegularImpl::XdmfGeometryRegular::New(this)); - this->setTopology(XdmfGridRegularImpl::XdmfTopologyRegular::New(this)); - mImpl->mBrickSize->insert(0, brickSizeX); - mImpl->mBrickSize->insert(1, brickSizeY); - mImpl->mDimensions->insert(0, numPointsX); - mImpl->mDimensions->insert(1, numPointsY); - mImpl->mOrigin->insert(0, originX); - mImpl->mOrigin->insert(1, originY); + boost::shared_ptr p(new XdmfGridRegular(brickSize, numPoints, origin)); + return p; } -XdmfGridRegular::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) : - mImpl(new XdmfGridRegularImpl(3)) +XdmfGridRegular::XdmfGridRegular(const boost::shared_ptr brickSize, const boost::shared_ptr numPoints, + const boost::shared_ptr origin) : + mImpl(new XdmfGridRegularImpl(brickSize, numPoints, origin)) { this->setGeometry(XdmfGridRegularImpl::XdmfGeometryRegular::New(this)); this->setTopology(XdmfGridRegularImpl::XdmfTopologyRegular::New(this)); - mImpl->mBrickSize->insert(0, brickSizeX); - mImpl->mBrickSize->insert(1, brickSizeY); - mImpl->mBrickSize->insert(2, brickSizeZ); - mImpl->mDimensions->insert(0, numPointsX); - mImpl->mDimensions->insert(1, numPointsY); - mImpl->mDimensions->insert(2, numPointsZ); - mImpl->mOrigin->insert(0, originX); - mImpl->mOrigin->insert(1, originY); - mImpl->mOrigin->insert(2, originZ); } XdmfGridRegular::~XdmfGridRegular() @@ -299,17 +305,27 @@ boost::shared_ptr XdmfGridRegular::getOrigin() const void XdmfGridRegular::populateItem(const std::map & itemProperties, std::vector > & 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) + + for(std::vector >::const_iterator iter = childItems.begin(); iter != childItems.end(); ++iter) { - mImpl->mDimensions->pushBack(atoi((*iter).c_str())); + if(boost::shared_ptr regularGrid = boost::shared_dynamic_cast(*iter)) + { + if(regularGrid->getBrickSize()) + { + mImpl->mBrickSize = regularGrid->getBrickSize(); + } + + if(regularGrid->getDimensions()) + { + mImpl->mDimensions = regularGrid->getDimensions(); + } + + if(regularGrid->getOrigin()) + { + mImpl->mOrigin = regularGrid->getOrigin(); + } + } } - this->setGeometry(XdmfGridRegularImpl::XdmfGeometryRegular::New(this)); - this->setTopology(XdmfGridRegularImpl::XdmfTopologyRegular::New(this)); } void XdmfGridRegular::setBrickSize(const boost::shared_ptr brickSize) diff --git a/XdmfGridRegular.hpp b/XdmfGridRegular.hpp index dbde0d3adff50baba62dd56d9a616e8206d964ea..10b466574f195ae02d3bc7514f2c6388cf94d349 100644 --- a/XdmfGridRegular.hpp +++ b/XdmfGridRegular.hpp @@ -52,6 +52,18 @@ public: const unsigned int numPointsX, const unsigned int numPointsY, const unsigned int numPointsZ, const double originX, const double originY, const double originZ); + /** + * Create a new structured grid (N dimensional). + * + * @param brickSize the size of the brick in each direction. + * @param numPoints the number of points in each direction. + * @param origin the coordinates of the origin. + * + * @return constructed structured grid. + */ + static boost::shared_ptr New(const boost::shared_ptr brickSize, const boost::shared_ptr numPoints, + const boost::shared_ptr origin); + virtual ~XdmfGridRegular(); LOKI_DEFINE_VISITABLE(XdmfGridRegular, XdmfGrid) @@ -79,7 +91,7 @@ public: boost::shared_ptr getDimensions(); /** - * Get the dimensions of the grid, the number of points in each direction. + * Get the dimensions of the grid, the number of points in each direction (const version). * * @return XdmfArray containing the dimensions of this grid. */ @@ -95,7 +107,7 @@ public: /** * Get the location of the origin of the grid. * - * @return XdmfArray containing the location of the origin of the grid. + * @return XdmfArray containing the location of the origin of the grid (const version). */ boost::shared_ptr getOrigin() const; @@ -124,11 +136,9 @@ public: protected: - XdmfGridRegular(const double brickSizeX, const double brickSizeY, const unsigned int numPointsX, - const unsigned int numPointsY, const double originX, const double originY); - 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); + XdmfGridRegular(const boost::shared_ptr brickSize, const boost::shared_ptr numPoints, + const boost::shared_ptr origin); + void populateItem(const std::map & itemProperties, std::vector > & childItems, const XdmfCoreReader * const reader); private: diff --git a/XdmfItemFactory.cpp b/XdmfItemFactory.cpp index a18271093c31d23e9fe942022ad0d47ca7febce8..274b5d2ace52b1eb61c215babef3a4290b45eedb 100644 --- a/XdmfItemFactory.cpp +++ b/XdmfItemFactory.cpp @@ -1,3 +1,4 @@ +#include #include "XdmfAttribute.hpp" #include "XdmfDomain.hpp" #include "XdmfGeometry.hpp" @@ -45,6 +46,41 @@ boost::shared_ptr XdmfItemFactory::createItem(const std::string & item } else if(itemTag.compare(XdmfGeometry::ItemTag) == 0) { + std::map::const_iterator type = itemProperties.find("Type"); + if(type == itemProperties.end()) + { + type = itemProperties.find("GeometryType"); + } + + if(type != itemProperties.end()) + { + const std::string typeVal = type->second; + if(typeVal.compare("ORIGIN_DXDY") == 0 || typeVal.compare("ORIGIN_DXDYDZ") == 0) + { + boost::shared_ptr origin = boost::shared_ptr(); + boost::shared_ptr brickSize = boost::shared_ptr(); + for(std::vector >::const_iterator iter = childItems.begin(); iter != childItems.end(); ++iter) + { + if(boost::shared_ptr array = boost::shared_dynamic_cast(*iter)) + { + if(!origin) + { + origin = array; + } + else if(!brickSize) + { + brickSize = array; + break; + } + } + } + if(origin && brickSize) + { + return XdmfGridRegular::New(brickSize, boost::shared_ptr(), origin); + } + return boost::shared_ptr(); + } + } return XdmfGeometry::New(); } else if(itemTag.compare(XdmfGrid::ItemTag) == 0) @@ -60,16 +96,9 @@ boost::shared_ptr XdmfItemFactory::createItem(const std::string & item // Find out what kind of grid we have for(std::vector >::const_iterator iter = childItems.begin(); iter != childItems.end(); ++iter) { - if(boost::shared_ptr geometry = boost::shared_dynamic_cast(*iter)) + if(boost::shared_ptr regularGrid = boost::shared_dynamic_cast(*iter)) { - if(geometry->getType()->getName().compare("REGULAR") == 0) - { - return XdmfGridRegular::New(0, 0, 0, 0, 0, 0); - } - else - { - break; - } + return XdmfGridRegular::New(0, 0, 0, 0, 0, 0); } } return XdmfGrid::New(); @@ -93,6 +122,33 @@ boost::shared_ptr XdmfItemFactory::createItem(const std::string & item } else if(itemTag.compare(XdmfTopology::ItemTag) == 0) { + std::map::const_iterator type = itemProperties.find("Type"); + if(type == itemProperties.end()) + { + type = itemProperties.find("TopologyType"); + } + + if(type != itemProperties.end()) + { + std::string typeVal = type->second; + std::transform(typeVal.begin(), typeVal.end(), typeVal.begin(), (int(*)(int))std::toupper); + if(typeVal.compare("2DCORECTMESH") == 0 || typeVal.compare("3DCORECTMESH") == 0) + { + boost::shared_ptr dimensionsArray = XdmfArray::New(); + std::string dimensionsString = ""; + std::map::const_iterator dimensions = itemProperties.find("Dimensions"); + if(dimensions != itemProperties.end()) + { + dimensionsString = dimensions->second; + } + boost::tokenizer<> tokens(dimensionsString); + for(boost::tokenizer<>::const_iterator iter = tokens.begin(); iter != tokens.end(); ++iter) + { + dimensionsArray->pushBack(atoi((*iter).c_str())); + } + return XdmfGridRegular::New(boost::shared_ptr(), dimensionsArray, boost::shared_ptr()); + } + } return XdmfTopology::New(); } return boost::shared_ptr(); diff --git a/XdmfTopologyType.cpp b/XdmfTopologyType.cpp index 7b3a5be67874f3a461c4bd9d38685a8ffdcb4a7b..5b3f0730697c81d101dfb3184d1b55d22537ca3f 100644 --- a/XdmfTopologyType.cpp +++ b/XdmfTopologyType.cpp @@ -5,7 +5,6 @@ * Author: kleiter */ -#include #include #include "XdmfTopologyType.hpp" @@ -329,13 +328,13 @@ boost::shared_ptr XdmfTopologyType::New(const std::map p(new XdmfTopologyType(0, "REGULAR", Structured)); return p; - }/* + } else if(typeVal.compare("3DSMESH") == 0) { return ThreeDSMesh(); @@ -373,7 +372,6 @@ bool XdmfTopologyType::IsEqual(boost::shared_ptr topologyType) return false; } - XdmfTopologyType::CellType XdmfTopologyType::getCellType() const { return mCellType; @@ -391,7 +389,7 @@ unsigned int XdmfTopologyType::getNodesPerElement() const void XdmfTopologyType::getProperties(std::map & collectedProperties) const { - collectedProperties["Type"] = mName; + collectedProperties["Type"] = this->getName(); if(mName.compare("Polygon") == 0) { std::stringstream nodesPerElement; diff --git a/XdmfTopologyType.hpp b/XdmfTopologyType.hpp index 5eaa360f4755c8533ce10a42360383ff5e8d9ef3..cb32ac72427cee1998df079de6c65982e443048a 100644 --- a/XdmfTopologyType.hpp +++ b/XdmfTopologyType.hpp @@ -99,7 +99,7 @@ public: * * @return the name of this topology type. */ - std::string getName() const; + virtual std::string getName() const; /** * Get the number of nodes per element associated with this topology type. @@ -108,7 +108,7 @@ public: */ virtual unsigned int getNodesPerElement() const; - virtual void getProperties(std::map & collectedProperties) const; + void getProperties(std::map & collectedProperties) const; /* * Compare two XdmfTopologyTypes for equality. @@ -126,14 +126,13 @@ public: */ bool operator!=(const XdmfTopologyType & topologyType) const; - /** - * Compare two XdmfTopologyType for equality (for wrapping) - * - * @param topologyType a boost shared pointer to an XdmfTopologyType to compare equality to. - * @return true if the XdmfTopologyType are equal. - */ - bool IsEqual(boost::shared_ptr topologyType); - + /** + * Compare two XdmfTopologyType for equality (for wrapping) + * + * @param topologyType a boost shared pointer to an XdmfTopologyType to compare equality to. + * @return true if the XdmfTopologyType are equal. + */ + bool IsEqual(boost::shared_ptr topologyType); protected: diff --git a/core/XdmfArrayType.cpp b/core/XdmfArrayType.cpp index 4720ac6ccdde01e35d227ad99cafd4e56385d87b..a6a2deab8ac69768a1b32dd4a3c198397314b7f0 100644 --- a/core/XdmfArrayType.cpp +++ b/core/XdmfArrayType.cpp @@ -4,7 +4,7 @@ * Created on: Jan 29, 2010 * Author: kleiter */ -#include //REMOVE + #include #include "XdmfArrayType.hpp" diff --git a/core/XdmfCoreItemFactory.cpp b/core/XdmfCoreItemFactory.cpp index 9a56eccfd4805c36b91929c797f537b60c1995f2..40ebb525c72eb5b2a5ca7f8dfd14cbc816eb116f 100644 --- a/core/XdmfCoreItemFactory.cpp +++ b/core/XdmfCoreItemFactory.cpp @@ -15,5 +15,5 @@ boost::shared_ptr XdmfCoreItemFactory::createItem(const std::string & { return XdmfArray::New(); } - return boost::shared_ptr();; + return boost::shared_ptr(); } diff --git a/tests/Cxx/TestXdmfGridCollection.cpp b/tests/Cxx/TestXdmfGridCollection.cpp index 11270fbf48dcb0a22c66142f2264cbee9f2faaad..dabb00ea4af39d40cca9571ef4006da5af0f29cd 100644 --- a/tests/Cxx/TestXdmfGridCollection.cpp +++ b/tests/Cxx/TestXdmfGridCollection.cpp @@ -60,7 +60,6 @@ int main(int, char *) writer4->setMode(XdmfWriter::DistributedHeavyData); gridCollection3->accept(writer4); - assert(XdmfTestCompareFiles::compareFiles("TestXdmfGridCollectionHDF1.xmf", "TestXdmfGridCollectionHDF2.xmf")); return 0; diff --git a/tests/Cxx/TestXdmfGridRegular.cpp b/tests/Cxx/TestXdmfGridRegular.cpp index 7d9d6fd3fb0baea3eb9a4bbd502ddb9ec807a3de..31f0b786da0d25f4d5ae552475d0bfe480e12d59 100644 --- a/tests/Cxx/TestXdmfGridRegular.cpp +++ b/tests/Cxx/TestXdmfGridRegular.cpp @@ -7,6 +7,8 @@ #include "XdmfTopologyType.hpp" #include "XdmfWriter.hpp" +#include "XdmfTestCompareFiles.hpp" + int main(int, char *) { boost::shared_ptr grid = XdmfGridRegular::New(1, 1, 1, 1, 1, 1, 0, 0, 0); @@ -88,10 +90,12 @@ int main(int, char *) grid->accept(writer); boost::shared_ptr reader = XdmfReader::New(); - boost::shared_ptr grid2 = boost::shared_dynamic_cast(reader->read("TestXdmfGridRegular1.xmf")); + boost::shared_ptr grid2 = boost::shared_dynamic_cast(reader->read("TestXdmfGridRegular1.xmf")); boost::shared_ptr writer2 = XdmfWriter::New("TestXdmfGridRegular2.xmf"); grid2->accept(writer2); + assert(XdmfTestCompareFiles::compareFiles("TestXdmfGridRegular1.xmf", "TestXdmfGridRegular2.xmf")); + return 0; }