Commit 5c280140 authored by Kenneth Leiter's avatar Kenneth Leiter

ENH: Add XdmfDomain.

parent 195746b2
......@@ -25,6 +25,7 @@ set(XdmfSources
XdmfAttributeType
XdmfDataItem
XdmfDataItemType
XdmfDomain
XdmfGeometry
XdmfGeometryType
XdmfGrid
......
......@@ -16,6 +16,7 @@ namespace boost {
%template(XdmfAttributePtr) boost::shared_ptr<XdmfAttribute>;
%template(XdmfDataItemPtr) boost::shared_ptr<XdmfDataItem>;
%template(XdmfDomainPtr) boost::shared_ptr<XdmfDomain>;
%template(XdmfGeometryPtr) boost::shared_ptr<XdmfGeometry>;
%template(XdmfGridPtr) boost::shared_ptr<XdmfGrid>;
%template(XdmfItemPtr) boost::shared_ptr<XdmfItem>;
......@@ -30,6 +31,7 @@ namespace boost {
#include <XdmfAttributeType.hpp>
#include <XdmfDataItem.hpp>
#include <XdmfDataItemType.hpp>
#include <XdmfDomain.hpp>
#include <XdmfGeometry.hpp>
#include <XdmfGeometryType.hpp>
#include <XdmfGrid.hpp>
......@@ -51,6 +53,7 @@ namespace boost {
%include XdmfAttribute.hpp
%include XdmfAttributeCenter.hpp
%include XdmfAttributeType.hpp
%include XdmfDomain.hpp
%include XdmfGeometry.hpp
%include XdmfGeometryType.hpp
%include XdmfGrid.hpp
......
......@@ -144,6 +144,28 @@ class XdmfDataItemPtr(_object):
XdmfDataItemPtr_swigregister = _Xdmf.XdmfDataItemPtr_swigregister
XdmfDataItemPtr_swigregister(XdmfDataItemPtr)
class XdmfDomainPtr(_object):
__swig_setmethods__ = {}
__setattr__ = lambda self, name, value: _swig_setattr(self, XdmfDomainPtr, name, value)
__swig_getmethods__ = {}
__getattr__ = lambda self, name: _swig_getattr(self, XdmfDomainPtr, name)
__repr__ = _swig_repr
def __deref__(self): return _Xdmf.XdmfDomainPtr___deref__(self)
def __init__(self):
this = _Xdmf.new_XdmfDomainPtr()
try: self.this.append(this)
except: self.this = this
__swig_destroy__ = _Xdmf.delete_XdmfDomainPtr
__del__ = lambda self : None;
def New(self): return _Xdmf.XdmfDomainPtr_New(self)
def insert(self, *args): return _Xdmf.XdmfDomainPtr_insert(self, *args)
def getGrid(self, *args): return _Xdmf.XdmfDomainPtr_getGrid(self, *args)
def getNumberOfGrids(self): return _Xdmf.XdmfDomainPtr_getNumberOfGrids(self)
def printSelf(self): return _Xdmf.XdmfDomainPtr_printSelf(self)
def write(self, *args): return _Xdmf.XdmfDomainPtr_write(self, *args)
XdmfDomainPtr_swigregister = _Xdmf.XdmfDomainPtr_swigregister
XdmfDomainPtr_swigregister(XdmfDomainPtr)
class XdmfGeometryPtr(_object):
__swig_setmethods__ = {}
__setattr__ = lambda self, name, value: _swig_setattr(self, XdmfGeometryPtr, name, value)
......@@ -191,7 +213,7 @@ class XdmfGridPtr(_object):
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 getNumberOfAttributes(self): return _Xdmf.XdmfGridPtr_getNumberOfAttributes(self)
def printSelf(self): return _Xdmf.XdmfGridPtr_printSelf(self)
def write(self, *args): return _Xdmf.XdmfGridPtr_write(self, *args)
XdmfGridPtr_swigregister = _Xdmf.XdmfGridPtr_swigregister
......@@ -557,6 +579,29 @@ def XdmfAttributeType_GlobalId():
return _Xdmf.XdmfAttributeType_GlobalId()
XdmfAttributeType_GlobalId = _Xdmf.XdmfAttributeType_GlobalId
class XdmfDomain(XdmfItem):
__swig_setmethods__ = {}
for _s in [XdmfItem]: __swig_setmethods__.update(getattr(_s,'__swig_setmethods__',{}))
__setattr__ = lambda self, name, value: _swig_setattr(self, XdmfDomain, name, value)
__swig_getmethods__ = {}
for _s in [XdmfItem]: __swig_getmethods__.update(getattr(_s,'__swig_getmethods__',{}))
__getattr__ = lambda self, name: _swig_getattr(self, XdmfDomain, name)
def __init__(self, *args, **kwargs): raise AttributeError("No constructor defined")
__repr__ = _swig_repr
__swig_getmethods__["New"] = lambda x: _Xdmf.XdmfDomain_New
if _newclass:New = staticmethod(_Xdmf.XdmfDomain_New)
def insert(self, *args): return _Xdmf.XdmfDomain_insert(self, *args)
def getGrid(self, *args): return _Xdmf.XdmfDomain_getGrid(self, *args)
def getNumberOfGrids(self): return _Xdmf.XdmfDomain_getNumberOfGrids(self)
def printSelf(self): return _Xdmf.XdmfDomain_printSelf(self)
def write(self, *args): return _Xdmf.XdmfDomain_write(self, *args)
XdmfDomain_swigregister = _Xdmf.XdmfDomain_swigregister
XdmfDomain_swigregister(XdmfDomain)
def XdmfDomain_New():
return _Xdmf.XdmfDomain_New()
XdmfDomain_New = _Xdmf.XdmfDomain_New
class XdmfGeometry(XdmfDataItem):
__swig_setmethods__ = {}
for _s in [XdmfDataItem]: __swig_setmethods__.update(getattr(_s,'__swig_setmethods__',{}))
......@@ -674,7 +719,7 @@ class XdmfGrid(XdmfItem):
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 getNumberOfAttributes(self): return _Xdmf.XdmfGrid_getNumberOfAttributes(self)
def printSelf(self): return _Xdmf.XdmfGrid_printSelf(self)
def write(self, *args): return _Xdmf.XdmfGrid_write(self, *args)
XdmfGrid_swigregister = _Xdmf.XdmfGrid_swigregister
......
......@@ -68,7 +68,7 @@ public:
void setAttributeCenter(const XdmfAttributeCenter& attributeCenter);
/**
* Get the name of the AttributeCenter associated with this Attribute.
* Get the name of the XdmfAttributeCenter associated with this Attribute.
*
* @return std::string containing name of the AttributeCenter.
*/
......
/*
* XdmfGrid.cpp
*
* Created on: Jan 25, 2010
* Author: kleiter
*/
#include "XdmfDomain.hpp"
#include "XdmfVisitor.hpp"
XdmfDomain::XdmfDomain()
{
std::cout << "Created Domain " << this << std::endl;
}
XdmfDomain::~XdmfDomain()
{
std::cout << "Deleted Domain " << this << std::endl;
}
void XdmfDomain::insert(boost::shared_ptr<XdmfGrid> grid)
{
mGrids.push_back(grid);
}
boost::shared_ptr<XdmfGrid> XdmfDomain::getGrid(unsigned int index)
{
if(index >= mGrids.size())
{
assert(false);
// Out of range --- should we throw exceptions?
}
return mGrids[index];
}
boost::shared_ptr<const XdmfGrid> XdmfDomain::getGrid(unsigned int index) const
{
if(index >= mGrids.size())
{
assert(false);
// Out of range --- should we throw exceptions?
}
return mGrids[index];
}
unsigned int XdmfDomain::getNumberOfGrids() const
{
return mGrids.size();
}
std::string XdmfDomain::printSelf() const
{
return "XdmfDomain";
}
void XdmfDomain::write(boost::shared_ptr<XdmfVisitor> visitor) const
{
visitor->visit(this);
}
// Kenneth Leiter
// Xdmf Smart Pointer Test
#ifndef XDMFDOMAIN_HPP_
#define XDMFDOMAIN_HPP_
// Forward Declarations
class XdmfGrid;
// Includes
#include "XdmfItem.hpp"
#include <vector>
class XdmfDomain : public XdmfItem {
public:
XdmfNewMacro(XdmfDomain);
/**
* Insert a grid into the domain.
*/
void insert(boost::shared_ptr<XdmfGrid>);
/**
* Get a grid attached to this domain.
*
* @param index of the grid to retrieve.
* @return pointer to the grid attached to this domain.
*/
boost::shared_ptr<XdmfGrid> getGrid(unsigned int index);
/**
* Get a grid attached to this domain (const version).
*
* @param index of the grid to retrieve.
* @return pointer to the grid attached to this domain.
*/
boost::shared_ptr<const XdmfGrid> getGrid(unsigned int index) const;
/**
* Get the number of grids attached to this domain
*/
unsigned int getNumberOfGrids() const;
virtual std::string printSelf() const;
virtual void write(boost::shared_ptr<XdmfVisitor> visitor) const;
protected:
XdmfDomain();
virtual ~XdmfDomain();
private:
XdmfDomain(const XdmfDomain&); // Not implemented.
void operator=(const XdmfDomain&); // Not implemented.
std::vector<boost::shared_ptr<XdmfGrid> > mGrids;
};
#endif /* XDMFDOMAIN_HPP_ */
......@@ -98,7 +98,7 @@ boost::shared_ptr<const XdmfAttribute> XdmfGrid::getAttribute(unsigned int index
return mAttributes[index];
}
unsigned int XdmfGrid::getNumberOfAttribute() const
unsigned int XdmfGrid::getNumberOfAttributes() const
{
return mAttributes.size();
}
......
......@@ -99,7 +99,7 @@ public:
/**
* Get the number of attributes attached to this grid
*/
unsigned int getNumberOfAttribute() const;
unsigned int getNumberOfAttributes() const;
virtual std::string printSelf() const;
......
This diff is collapsed.
......@@ -60,21 +60,6 @@ public:
*/
int getNodesPerElement() const;
/* *
* Get the point data associated with this Topology;
boost::shared_ptr<XdmfDataItem> getData();
*
* Get the data associated with this Topology (const version)
boost::shared_ptr<const XdmfDataItem> getData() const;
*
* Set the point data associated with this Topology
void setData(boost::shared_ptr<XdmfDataItem> connectivityData);*/
/**
*
*/
......
......@@ -3,6 +3,7 @@
#include "XdmfAttribute.hpp"
#include "XdmfDataItem.hpp"
#include "XdmfDomain.hpp"
#include "XdmfGeometry.hpp"
#include "XdmfGrid.hpp"
#include "XdmfTopology.hpp"
......@@ -51,6 +52,18 @@ void XdmfVisitor::visit(const XdmfDataItem * const dataItem)
xmlData << "\n" << std::setw(mTabIndex) << "" << "</DataItem>\n";
}
void XdmfVisitor::visit(const XdmfDomain * const domain)
{
xmlData << std::setw(mTabIndex) << "" << "<Domain>\n";
mTabIndex++;
for(unsigned int i=0; i<domain->getNumberOfGrids(); ++i)
{
visit(domain->getGrid(i).get());
}
mTabIndex--;
xmlData << std::setw(mTabIndex) << "" << "</Domain>\n";
}
void XdmfVisitor::visit(const XdmfGeometry * const geometry)
{
xmlData << std::setw(mTabIndex) << "" << "<Geometry GeometryType=\"" << geometry->getGeometryTypeAsString() << "\">\n";
......@@ -66,7 +79,7 @@ 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++)
for(unsigned int i=0; i<grid->getNumberOfAttributes(); i++)
{
visit(grid->getAttribute(i).get());
}
......
......@@ -7,6 +7,7 @@
// Forward Declarations
class XdmfAttribute;
class XdmfDataItem;
class XdmfDomain;
class XdmfGeometry;
class XdmfGrid;
class XdmfTopology;
......@@ -25,6 +26,8 @@ public:
virtual void visit(const XdmfDataItem * const geometry);
virtual void visit(const XdmfDomain * const domain);
virtual void visit(const XdmfGeometry * const geometry);
virtual void visit(const XdmfGrid * const grid);
......
......@@ -12,9 +12,9 @@ int main(int argc, char* argv[])
boost::shared_ptr<XdmfAttribute> attr = XdmfAttribute::New();
attr->setName("Attr1");
assert(grid->getNumberOfAttribute() == 0);
assert(grid->getNumberOfAttributes() == 0);
grid->insert(attr);
assert(grid->getNumberOfAttribute() == 1);
assert(grid->getNumberOfAttributes() == 1);
assert(grid->getAttribute(0) == attr);
return 0;
......
#include "XdmfAttribute.hpp"
#include "XdmfDataItem.hpp"
#include "XdmfDomain.hpp"
#include "XdmfGeometry.hpp"
#include "XdmfGrid.hpp"
#include "XdmfTopology.hpp"
......@@ -45,7 +46,11 @@ int main(int argc, char* argv[])
grid->insert(nodalAttribute);
grid->insert(cellAttribute);
grid->write(visitor3);
boost::shared_ptr<XdmfDomain> domain = XdmfDomain::New();
domain->insert(grid);
domain->write(visitor3);
std::cout << visitor3->printSelf() << std::endl;
return 0;
......
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