Commit ab806f9f authored by Ken Leiter (Civ's avatar Ken Leiter (Civ

ENH: Allow XdmfGrids to insert XdmfAttribute elements. Add this to the...

ENH: Allow XdmfGrids to insert XdmfAttribute elements.  Add this to the visitor logic to write to xml.
parent 4acdd29e
......@@ -156,6 +156,9 @@ class XdmfGridPtr(_object):
def setTopology(self, *args): return _Xdmf.XdmfGridPtr_setTopology(self, *args)
def getName(self): return _Xdmf.XdmfGridPtr_getName(self)
def setName(self, *args): return _Xdmf.XdmfGridPtr_setName(self, *args)
def insert(self, *args): return _Xdmf.XdmfGridPtr_insert(self, *args)
def getAttribute(self, *args): return _Xdmf.XdmfGridPtr_getAttribute(self, *args)
def getNumberOfAttribute(self): return _Xdmf.XdmfGridPtr_getNumberOfAttribute(self)
def printSelf(self): return _Xdmf.XdmfGridPtr_printSelf(self)
def write(self, *args): return _Xdmf.XdmfGridPtr_write(self, *args)
XdmfGridPtr_swigregister = _Xdmf.XdmfGridPtr_swigregister
......@@ -483,6 +486,9 @@ class XdmfGrid(XdmfItem):
def setTopology(self, *args): return _Xdmf.XdmfGrid_setTopology(self, *args)
def getName(self): return _Xdmf.XdmfGrid_getName(self)
def setName(self, *args): return _Xdmf.XdmfGrid_setName(self, *args)
def insert(self, *args): return _Xdmf.XdmfGrid_insert(self, *args)
def getAttribute(self, *args): return _Xdmf.XdmfGrid_getAttribute(self, *args)
def getNumberOfAttribute(self): return _Xdmf.XdmfGrid_getNumberOfAttribute(self)
def printSelf(self): return _Xdmf.XdmfGrid_printSelf(self)
def write(self, *args): return _Xdmf.XdmfGrid_write(self, *args)
XdmfGrid_swigregister = _Xdmf.XdmfGrid_swigregister
......
......@@ -73,6 +73,36 @@ void XdmfGrid::setName(const std::string& name)
mName= name;
}
void XdmfGrid::insert(boost::shared_ptr<XdmfAttribute> attribute)
{
mAttributes.push_back(attribute);
}
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];
}
boost::shared_ptr<const XdmfAttribute> XdmfGrid::getAttribute(unsigned int index) const
{
if(index >= mAttributes.size())
{
assert(false);
// Out of range --- should we throw exceptions?
}
return mAttributes[index];
}
unsigned int XdmfGrid::getNumberOfAttribute() const
{
return mAttributes.size();
}
const std::string XdmfGrid::printSelf() const
{
return "XdmfGrid containing a " + mGeometry->printSelf() + " and a " + mTopology->printSelf();
......
......@@ -75,6 +75,32 @@ public:
*/
void setName(const std::string&);
/**
* Insert an attribute into the grid
*/
void insert(boost::shared_ptr<XdmfAttribute>);
/**
* Get an attribute attached to this grid.
*
* @param index of the attribute to retrieve
* @return pointer to the attribute attached to this grid
*/
boost::shared_ptr<XdmfAttribute> getAttribute(unsigned int index);
/**
* Get an attribute attached to this grid (const version).
*
* @param index of the attribute to retrieve
* @return pointer to the attribute attached to this grid
*/
boost::shared_ptr<const XdmfAttribute> getAttribute(unsigned int index) const;
/**
* Get the number of attributes attached to this grid
*/
unsigned int getNumberOfAttribute() const;
virtual const std::string printSelf() const;
virtual void write(boost::shared_ptr<XdmfVisitor> visitor) const;
......
This diff is collapsed.
......@@ -39,6 +39,10 @@ void XdmfVisitor::visit(const XdmfGrid * const grid)
mTabIndex++;
visit(grid->getGeometry().get());
visit(grid->getTopology().get());
for(unsigned int i=0; i<grid->getNumberOfAttribute(); i++)
{
visit(grid->getAttribute(i).get());
}
mTabIndex--;
xmlData << std::setw(mTabIndex) << "" << "</Grid>\n";
}
......
set(XdmfTests
TestXdmfAttribute
TestXdmfGeometry
TestXdmfGrid
TestXdmfTopology
......
#include "XdmfAttribute.hpp"
int main(int argc, char* argv[])
{
// Test != and == operators
assert(XdmfAttributeType::Scalar == XdmfAttributeType::Scalar);
assert(XdmfAttributeType::Scalar == XdmfAttributeType::Vector == false);
assert(XdmfAttributeType::Scalar != XdmfAttributeType::Scalar == false);
assert(XdmfAttributeType::Scalar != XdmfAttributeType::Vector);
// Test copy constructor and assigment operators
XdmfAttributeType type = XdmfAttributeType::Scalar();
assert(type.getName().compare("Scalar") == 0);
XdmfAttributeType type2(type); // Copy Constructor
assert(type2.getName().compare("Scalar") == 0);
XdmfAttributeType type3 = XdmfAttributeType::Vector();
assert(type3.getName().compare("Vector") == 0);
type2 = type3;
assert(type2.getName().compare("Vector") == 0);
boost::shared_ptr<XdmfAttribute> attribute = XdmfAttribute::New();
assert(attribute->getAttributeType() == XdmfAttributeType::NoAttributeType());
assert(attribute->getAttributeType().getName().compare("None") == 0);
attribute->setAttributeType(XdmfAttributeType::Scalar());
assert(attribute->getAttributeType() == XdmfAttributeType::Scalar());
assert(attribute->getAttributeTypeAsString().compare("Scalar") == 0);
return 0;
}
......@@ -3,10 +3,10 @@
int main(int argc, char* argv[])
{
// Test != and == operators
assert(XdmfGeometryType::XYZ == XdmfGeometryType::XYZ);
assert(XdmfGeometryType::XYZ == XdmfGeometryType::XY == false);
assert(XdmfGeometryType::XYZ != XdmfGeometryType::XYZ == false);
assert(XdmfGeometryType::XYZ != XdmfGeometryType::XY);
assert(XdmfGeometryType::XYZ() == XdmfGeometryType::XYZ());
assert(XdmfGeometryType::XYZ() == XdmfGeometryType::XY() == false);
assert(XdmfGeometryType::XYZ() != XdmfGeometryType::XYZ() == false);
assert(XdmfGeometryType::XYZ() != XdmfGeometryType::XY());
boost::shared_ptr<XdmfGeometry> geom = XdmfGeometry::New();
assert(geom->getGeometryType() == XdmfGeometryType::NoGeometryType());
......
#include "XdmfAttribute.hpp"
#include "XdmfGrid.hpp"
int main(int argc, char* argv[])
......@@ -9,5 +10,12 @@ int main(int argc, char* argv[])
assert(grid->getName().compare(gridName) == 0);
std::cout << grid->getName() << std::endl;
boost::shared_ptr<XdmfAttribute> attr = XdmfAttribute::New();
attr->setName("Attr1");
assert(grid->getNumberOfAttribute() == 0);
grid->insert(attr);
assert(grid->getNumberOfAttribute() == 1);
assert(grid->getAttribute(0) == attr);
return 0;
}
#include "XdmfAttribute.hpp"
#include "XdmfGeometry.hpp"
#include "XdmfGrid.hpp"
#include "XdmfTopology.hpp"
......@@ -19,6 +20,10 @@ int main(int argc, char* argv[])
boost::shared_ptr<XdmfGrid> grid = XdmfGrid::New();
grid->setName("test");
grid->getTopology()->setTopologyType(XdmfTopologyType::Hexahedron());
boost::shared_ptr<XdmfAttribute> attr = XdmfAttribute::New();
attr->setName("Attr1");
attr->setAttributeType(XdmfAttributeType::Scalar());
grid->insert(attr);
grid->write(visitor3);
std::cout << visitor3->printSelf() << std::endl;
......
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