Commit cd0f247f authored by Kenneth Leiter's avatar Kenneth Leiter

ENH: Add XdmfSet. Remove getName() method from ItemProperties.

parent 955bbcf2
......@@ -48,6 +48,8 @@ set(XdmfSources
XdmfItemProperty
XdmfObject
XdmfReader
XdmfSet
XdmfSetType
XdmfTopology
XdmfTopologyType
XdmfVisitor
......
......@@ -20,6 +20,8 @@ swig -v -c++ -python -o XdmfPython.cpp Xdmf.i
#include <XdmfItemProperty.hpp>
#include <XdmfObject.hpp>
#include <XdmfReader.hpp>
#include <XdmfSet.hpp>
#include <XdmfSetType.hpp>
#include <XdmfTopology.hpp>
#include <XdmfTopologyType.hpp>
#include <XdmfVisitor.hpp>
......@@ -60,6 +62,7 @@ namespace boost {
%template(XdmfItemPtr) boost::shared_ptr<XdmfItem>;
%template(XdmfObjPtr) boost::shared_ptr<XdmfObject>;
%template(XdmfReaderPtr) boost::shared_ptr<XdmfReader>;
%template(XdmfSetPtr) boost::shared_ptr<XdmfSet>;
%template(XdmfTopologyPtr) boost::shared_ptr<XdmfTopology>;
%template(XdmfVisitorPtr) boost::shared_ptr<XdmfVisitor>;
%template(XdmfWriterPtr) boost::shared_ptr<XdmfWriter>;
......@@ -94,6 +97,9 @@ SWIG_SHARED_PTR_DERIVED(XdmfHDF5Writer, Loki::BaseVisitor);
SWIG_SHARED_PTR_DERIVED(XdmfHDF5Writer, XdmfObject);
SWIG_SHARED_PTR_DERIVED(XdmfItem, XdmfObject);
SWIG_SHARED_PTR_DERIVED(XdmfReader, XdmfObject);
SWIG_SHARED_PTR_DERIVED(XdmfSet, XdmfDataItem);
SWIG_SHARED_PTR_DERIVED(XdmfSet, XdmfItem);
SWIG_SHARED_PTR_DERIVED(XdmfSet, XdmfObject);
SWIG_SHARED_PTR_DERIVED(XdmfTopology, XdmfDataItem);
SWIG_SHARED_PTR_DERIVED(XdmfTopology, XdmfItem);
SWIG_SHARED_PTR_DERIVED(XdmfTopology, XdmfObject);
......@@ -123,6 +129,8 @@ SWIG_SHARED_PTR_DERIVED(XdmfWriter, XdmfObject);
%include XdmfGeometry.hpp
%include XdmfGeometryType.hpp
%include XdmfGrid.hpp
%include XdmfSet.hpp
%include XdmfSetType.hpp
%include XdmfTopology.hpp
%include XdmfTopologyType.hpp
......
......@@ -558,6 +558,11 @@ void XdmfArray::initialize(const std::string & type, const unsigned int precisio
}
}
bool XdmfArray::isInitialized()
{
return mHaveArray || mHaveArrayPointer;
}
void XdmfArray::internalizeArrayPointer()
{
if(mHaveArrayPointer)
......
......@@ -179,6 +179,11 @@ public:
template <typename T>
boost::shared_ptr<std::vector<T> > initialize();
/**
* Returns whether the array is initialized (contains values in memory).
*/
bool isInitialized();
/**
* Copy a value to the back of this array
*/
......
......@@ -77,7 +77,7 @@ XdmfAttributeCenter XdmfAttributeCenter::New(const std::map<std::string, std::st
assert(false);
}
XdmfAttributeCenter& XdmfAttributeCenter::operator=(const XdmfAttributeCenter & attributeCenter)
XdmfAttributeCenter & XdmfAttributeCenter::operator=(const XdmfAttributeCenter & attributeCenter)
{
if(this != &attributeCenter)
{
......@@ -96,11 +96,6 @@ bool XdmfAttributeCenter::operator!=(const XdmfAttributeCenter & attributeCenter
return !this->operator==(attributeCenter);
}
std::string XdmfAttributeCenter::getName() const
{
return mName;
}
void XdmfAttributeCenter::getProperties(std::map<std::string, std::string> & collectedProperties) const
{
collectedProperties["Center"] = mName;
......
......@@ -32,13 +32,6 @@ public:
static XdmfAttributeCenter Edge();
static XdmfAttributeCenter Node();
/**
* Get the name of this attribute center.
*
* @return a string containing the name.
*/
std::string getName() const;
void getProperties(std::map<std::string, std::string> & collectedProperties) const;
/**
......@@ -58,7 +51,7 @@ public:
bool operator!=(const XdmfAttributeCenter & attributeCenter) const;
XdmfAttributeCenter(const XdmfAttributeCenter & attributeCenter);
XdmfAttributeCenter& operator=(const XdmfAttributeCenter & attributeCenter);
XdmfAttributeCenter & operator=(const XdmfAttributeCenter & attributeCenter);
protected:
......
......@@ -95,7 +95,7 @@ XdmfAttributeType XdmfAttributeType::New(const std::map<std::string, std::string
assert(false);
}
XdmfAttributeType& XdmfAttributeType::operator=(const XdmfAttributeType & attributeType)
XdmfAttributeType & XdmfAttributeType::operator=(const XdmfAttributeType & attributeType)
{
if(this != &attributeType)
{
......@@ -114,11 +114,6 @@ bool XdmfAttributeType::operator!=(const XdmfAttributeType & attributeType) cons
return !this->operator==(attributeType);
}
std::string XdmfAttributeType::getName() const
{
return mName;
}
void XdmfAttributeType::getProperties(std::map<std::string, std::string> & collectedProperties) const
{
collectedProperties["AttributeType"] = mName;
......
......@@ -36,13 +36,6 @@ public:
static XdmfAttributeType Tensor6();
static XdmfAttributeType GlobalId();
/**
* Get the name of this attribute type
*
* @return a string containing the name.
*/
std::string getName() const;
void getProperties(std::map<std::string, std::string> & collectedProperties) const;
/*
......@@ -62,7 +55,7 @@ public:
bool operator!=(const XdmfAttributeType & attributeType) const;
XdmfAttributeType(const XdmfAttributeType & attributeType);
XdmfAttributeType& operator=(const XdmfAttributeType & attributeType);
XdmfAttributeType & operator=(const XdmfAttributeType & attributeType);
protected:
......
......@@ -116,7 +116,7 @@ XdmfGeometryType XdmfGeometryType::New(const std::map<std::string, std::string>
assert(false);
}
XdmfGeometryType& XdmfGeometryType::operator=(const XdmfGeometryType& geometryType)
XdmfGeometryType & XdmfGeometryType::operator=(const XdmfGeometryType& geometryType)
{
if(this != &geometryType)
{
......@@ -141,11 +141,6 @@ 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["GeometryType"] = this->mName;
......
......@@ -47,17 +47,10 @@ public:
*/
int getDimensions() const;
/**
* Get the name of this geometry type
*
* @return a string containing the name.
*/
std::string getName() const;
void getProperties(std::map<std::string, std::string> & collectedProperties) const;
/*
* Compare two XdmfGeometry types for equality.
* Compare two XdmfGeometryTypes for equality.
*
* @param geometryType a XdmfGeometryType to compare equality to.
* @return true if the XdmfGeometryTypes are equal.
......@@ -65,7 +58,7 @@ public:
bool operator==(const XdmfGeometryType & geometryType) const;
/**
* Compare two XdmfGeometry types for inequality.
* Compare two XdmfGeometryTypes for inequality.
*
* @param geometryType a XdmfGeometryType to compare inequality to.
* @return true if the XdmfGeometryTypes are not equal.
......@@ -73,7 +66,7 @@ public:
bool operator!=(const XdmfGeometryType & geometryType) const;
XdmfGeometryType(const XdmfGeometryType & geometryType);
XdmfGeometryType& operator=(const XdmfGeometryType & geometryType);
XdmfGeometryType & operator=(const XdmfGeometryType & geometryType);
protected:
......
......@@ -8,6 +8,7 @@
#include "XdmfAttribute.hpp"
#include "XdmfGrid.hpp"
#include "XdmfGeometry.hpp"
#include "XdmfSet.hpp"
#include "XdmfTopology.hpp"
XdmfGrid::XdmfGrid() :
......@@ -30,7 +31,6 @@ boost::shared_ptr<XdmfAttribute> XdmfGrid::getAttribute(unsigned int index)
if(index >= mAttributes.size())
{
assert(false);
// Out of range --- should we throw exceptions?
}
return mAttributes[index];
}
......@@ -40,7 +40,6 @@ boost::shared_ptr<const XdmfAttribute> XdmfGrid::getAttribute(unsigned int index
if(index >= mAttributes.size())
{
assert(false);
// Out of range --- should we throw exceptions?
}
return mAttributes[index];
}
......@@ -77,6 +76,29 @@ unsigned int XdmfGrid::getNumberOfAttributes() const
return mAttributes.size();
}
unsigned int XdmfGrid::getNumberOfSets() const
{
return mSets.size();
}
boost::shared_ptr<XdmfSet> XdmfGrid::getSet(unsigned int index)
{
if(index >= mSets.size())
{
assert(false);
}
return mSets[index];
}
boost::shared_ptr<const XdmfSet> XdmfGrid::getSet(unsigned int index) const
{
if(index >= mSets.size())
{
assert(false);
}
return mSets[index];
}
boost::shared_ptr<XdmfTopology> XdmfGrid::getTopology()
{
return mTopology;
......@@ -92,6 +114,11 @@ void XdmfGrid::insert(boost::shared_ptr<XdmfAttribute> attribute)
mAttributes.push_back(attribute);
}
void XdmfGrid::insert(boost::shared_ptr<XdmfSet> set)
{
mSets.push_back(set);
}
void XdmfGrid::populateItem(const std::map<std::string, std::string> & itemProperties, std::vector<boost::shared_ptr<XdmfItem> > & childItems)
{
std::map<std::string, std::string>::const_iterator name = itemProperties.find("Name");
......@@ -113,6 +140,10 @@ void XdmfGrid::populateItem(const std::map<std::string, std::string> & itemPrope
{
mGeometry = geometry;
}
if(boost::shared_ptr<XdmfSet> set = boost::shared_dynamic_cast<XdmfSet>(*iter))
{
this->insert(set);
}
else if(boost::shared_ptr<XdmfTopology> topology = boost::shared_dynamic_cast<XdmfTopology>(*iter))
{
mTopology = topology;
......@@ -143,4 +174,8 @@ void XdmfGrid::traverse(boost::shared_ptr<Loki::BaseVisitor> visitor)
{
(*iter)->accept(visitor);
}
for(std::vector<boost::shared_ptr<XdmfSet> >::const_iterator iter = mSets.begin(); iter != mSets.end(); ++iter)
{
(*iter)->accept(visitor);
}
}
......@@ -4,6 +4,7 @@
// Forward Declarations
class XdmfAttribute;
class XdmfGeometry;
class XdmfSet;
class XdmfTopology;
// Includes
......@@ -15,7 +16,8 @@ class XdmfTopology;
*
* XdmfGrid represents a mesh. It is required to contain two other Xdmf data structures, an XdmfGeometry
* that stores point locations and an XdmfTopology that store connectivity information. XdmfAttributes can be inserted
* into the XdmfGrid to specify values attached at various parts of the mesh.
* 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 {
......@@ -73,6 +75,29 @@ public:
*/
unsigned int getNumberOfAttributes() const;
/**
* Get the number of XdmfSets attached to this grid.
*
* @return an unsigned int containing the number of XdmfSets attached to this grid.
*/
unsigned int getNumberOfSets() const;
/**
* Get an XdmfSet attached to this grid.
*
* @param index of the XdmfSet to retrieve.
* @return pointer to the XdmfSet attached to this grid.
*/
boost::shared_ptr<XdmfSet> getSet(unsigned int index);
/**
* Get an XdmfSet attached to this grid (const version).
*
* @param index of the XdmfSet to retrieve.
* @return pointer to the XdmfSet attached to this grid.
*/
boost::shared_ptr<const XdmfSet> getSet(unsigned int index) const;
/**
* Get the XdmfTopology associated with this grid.
*
......@@ -90,21 +115,28 @@ public:
/**
* Insert an XdmfAttribute into the grid.
*
* @param attribute a smart pointer to the XdmfAttribute to attach to this grid.
* @param attribute an XdmfAttribute to attach to this grid.
*/
void insert(boost::shared_ptr<XdmfAttribute> attribute);
/**
* Insert an XdmfSet into the grid.
*
* @param set an XdmfSet to attach to this grid.
*/
void insert(boost::shared_ptr<XdmfSet> set);
/**
* Set the XdmfGeometry associated with this grid.
*
* @param geometry a smart pointer to the XdmfGeometry to attach to this grid.
* @param geometry an XdmfGeometry to attach to this grid.
*/
void setGeometry(boost::shared_ptr<XdmfGeometry> geometry);
/**
* Set the XdmfTopology associated with this grid.
*
* @param topology a smart pointer to the XdmfTopology to attach to this grid.
* @param topology an XdmfTopology to attach to this grid.
*/
void setTopology(boost::shared_ptr<XdmfTopology> topology);
......@@ -130,6 +162,7 @@ private:
std::vector<boost::shared_ptr<XdmfAttribute> > mAttributes;
boost::shared_ptr<XdmfGeometry> mGeometry;
std::vector<boost::shared_ptr<XdmfSet> > mSets;
boost::shared_ptr<XdmfTopology> mTopology;
std::string mName;
};
......
......@@ -6,6 +6,7 @@
#include "XdmfDomain.hpp"
#include "XdmfGeometry.hpp"
#include "XdmfGrid.hpp"
#include "XdmfSet.hpp"
#include "XdmfTopology.hpp"
......@@ -51,6 +52,10 @@ public:
{
newItem = XdmfGrid::New();
}
else if(itemTag.compare(XdmfSet::ItemTag) == 0)
{
newItem = XdmfSet::New();
}
else if(itemTag.compare(XdmfTopology::ItemTag) == 0)
{
newItem = XdmfTopology::New();
......
/*
* XdmfSet.cpp
*
* Created on: Jan 29, 2010
* Author: kleiter
*/
#include "XdmfSet.hpp"
XdmfSet::XdmfSet() :
mSetType(XdmfSetType::NoSetType()),
mName("")
{
std::cout << "Created Set " << this << std::endl;
}
XdmfSet::~XdmfSet()
{
std::cout << "Deleted Set " << this << std::endl;
}
std::string XdmfSet::ItemTag = "Set";
std::string XdmfSet::getName() const
{
return mName;
}
XdmfSetType XdmfSet::getSetType() const
{
return mSetType;
}
std::map<std::string, std::string> XdmfSet::getItemProperties() const
{
std::map<std::string, std::string> setProperties;
setProperties["Name"] = mName;
mSetType.getProperties(setProperties);
return setProperties;
}
std::string XdmfSet::getItemTag() const
{
return ItemTag;
}
void XdmfSet::populateItem(const std::map<std::string, std::string> & itemProperties, std::vector<boost::shared_ptr<XdmfItem> > & childItems)
{
std::map<std::string, std::string>::const_iterator name = itemProperties.find("Name");
if(name != itemProperties.end())
{
mName = name->second;
}
else
{
assert(false);
}
mSetType = XdmfSetType::New(itemProperties);
XdmfDataItem::populateItem(itemProperties, childItems);
}
void XdmfSet::setName(const std::string & name)
{
mName= name;
}
void XdmfSet::setSetType(const XdmfSetType & setType)
{
mSetType = setType;
}
#ifndef XDMFSET_HPP_
#define XDMFSET_HPP_
// Includes
#include "XdmfDataItem.hpp"
#include "XdmfSetType.hpp"
/**
* @brief Holds a collection of individual nodes, cells, faces, or edges that are part of an XdmfGrid.
*
* An XdmfSet holds a collection of nodes, cells, faces, or edges that are part of an XdmfGrid. For instance,
* a simulation may want to record a set of nodes along a boundary. The individual elements making up the
* set are determined by their id. An XdmfSet can have XdmfAttributes attached that give extra values
* attached to the components of the set.
*/
class XdmfSet : public XdmfDataItem {
public:
XdmfNewMacro(XdmfSet);
LOKI_DEFINE_VISITABLE(XdmfSet, XdmfDataItem)
static std::string ItemTag;
/**
* Get the XdmfSetType associated with this set.
*
* @return XdmfSetType of this set.
*/
XdmfSetType getSetType() const;
std::map<std::string, std::string> getItemProperties() const;
std::string getItemTag() const;
/**
* Get the name of the set.
*
* @return a string containing the name of the set.
*/
std::string getName() const;
/**
* Set the name of the set.
*
* @param name a string containing the name to set.
*/
void setName(const std::string & name);
/**
* Set the XdmfSetType associated with this set.
*
* @param setType the XdmfSetType to set.
*/
void setSetType(const XdmfSetType & setType);
protected:
XdmfSet();
virtual ~XdmfSet();
virtual void populateItem(const std::map<std::string, std::string> & itemProperties, std::vector<boost::shared_ptr<XdmfItem> > & childItems);
private:
XdmfSet(const XdmfSet & set); // Not implemented.
void operator=(const XdmfSet & set); // Not implemented.
std::string mName;
XdmfSetType mSetType;
};
#endif /* XDMFSET_HPP_ */
/*
* XdmfSetType.cpp
*
* Created on: Jan 29, 2010
* Author: kleiter
*/
#include "XdmfSetType.hpp"
// Supported XdmfSetTypes
XdmfSetType XdmfSetType::NoSetType()
{
return XdmfSetType("None");
}
XdmfSetType XdmfSetType::Node()
{
return XdmfSetType("Node");
}
XdmfSetType XdmfSetType::Cell()
{
return XdmfSetType("Cell");
}
XdmfSetType XdmfSetType::Face()
{
return XdmfSetType("Face");
}
XdmfSetType XdmfSetType::Edge()
{
return XdmfSetType("Edge");
}
XdmfSetType::XdmfSetType(const XdmfSetType & setType):
mName(setType.mName)
{
}
XdmfSetType::XdmfSetType(const std::string & name) :
mName(name)
{
}
XdmfSetType XdmfSetType::New(const std::map<std::string, std::string> & itemProperties)
{
std::map<std::string, std::string>::const_iterator type = itemProperties.find("SetType");
if(type != itemProperties.end())
{
const std::string typeVal = type->second;
if(typeVal.compare("None") == 0)
{
return NoSetType();
}
else if(typeVal.compare("Node") == 0)
{
return Node();
}
else if(typeVal.compare("Cell") == 0)
{
return Cell();
}
else if(typeVal.compare("Face") == 0)
{
return Face();
}
else if(typeVal.compare("Edge") == 0)
{
return Edge();
}
else
{
assert(false);
}
}
assert(false);
}
XdmfSetType & XdmfSetType::operator=(const XdmfSetType & setType)
{
if(this != &setType)
{
mName = setType.mName;
}
return *this;
}
bool XdmfSetType::operator==(const XdmfSetType & setType) const
{
return mName.compare(setType.mName) == 0;
}
bool XdmfSetType::operator!=(const XdmfSetType & setType) const
{
return !this->operator==(setType);
}
void XdmfSetType::getProperties(std::map<std::string, std::string> & collectedProperties) const
{
collectedProperties["SetType"] = this->mName;
}
#ifndef XDMFSETTYPE_HPP_
#define XDMFSETTYPE_HPP_
// Includes
#include <string>
#include "XdmfItemProperty.hpp"
/**
* @brief Property describing the type of an XdmfSet.
*
* An XdmfSet consist of a collection of nodes, cells, faces, or edges that are part of an XdmfGrid. This
* property indicates which element type the set contains.
*
* Xdmf supports the following set types:
* NoSetType
* Node
* Cell
* Face
* Edge
*/
class XdmfSetType : public XdmfItemProperty {
public:
friend class XdmfSet;
// Supported Xdmf Set Types
static XdmfSetType NoSetType();
static XdmfSetType Node();
static XdmfSetType Cell();
static XdmfSetType Face();
static XdmfSetType Edge();
void getProperties(std::map<std::string, std::string> & collectedProperties) const;
/*
* Compare two XdmfSetTypes for equality.
*
* @param setType a XdmfSetType to compare equality to.
* @return true if the XdmfSetTypes are equal.
*/
bool operator==(const XdmfSetType & setType) const;
/**
* Compare two XdmfSetTypes for inequality.
*
* @param setType a XdmfSetType to compare inequality to.
* @return true if the XdmfSetTypes are not equal.
*/
bool operator!=(const XdmfSetType & setType) const;
XdmfSetType(const XdmfSetType & setType);
XdmfSetType & operator=(const XdmfSetType & setType);
protected:
/**
* Protected constructor for XdmfSetType. The constructor is protected because all set types supported
* by Xdmf should be accessed through more specific static methods that construct XdmfSetTypes -
* i.e. XdmfSetType::Node().
*
* @param name a std::string containing the name of the XdmfSetType.
*/
XdmfSetType(const std::string & name);
private:
static XdmfSetType New(const std::map<std::string, std::string> & itemProperties);
std::string mName;
};
#endif /* XDMFGEOMETRYTYPE_HPP_ */
......@@ -51,7 +51,6 @@ protected:
virtual ~XdmfTopology();
virtual void populateItem(const std::map<std::string, std::string> & itemProperties, std::vector<boost::shared_ptr<XdmfItem> > & childItems);
private:
XdmfTopology(const XdmfTopology & topology); // Not implemented.
......
......@@ -257,7 +257,7 @@ XdmfTopologyType XdmfTopologyType::New(const std::map<std::string, std::string>
assert(false);
}
XdmfTopologyType& XdmfTopologyType::operator=(const XdmfTopologyType& topologyType)
XdmfTopologyType & XdmfTopologyType::operator=(const XdmfTopologyType& topologyType)
{
if(this != &topologyType)
{
......@@ -283,11 +283,6 @@ XdmfTopologyType::CellType XdmfTopologyType::getCellType() const
return mCellType;
}
std::string XdmfTopologyType::getName() const
{
return mName;
}
unsigned int XdmfTopologyType::getNodesPerElement() const
{
return mNodesPerElement;
......
......@@ -79,13 +79,6 @@ public:
*/
CellType getCellType() const;
<