Commit 6632e999 authored by Kenneth Leiter's avatar Kenneth Leiter

ENH: Add XdmfGeometryType to XdmfGeometry in a similar implementation as...

ENH: Add XdmfGeometryType to XdmfGeometry in a similar implementation as XdmfTopologyType.  Add tests for XdmfGeometry.  Add XdmfItem, an abstract class that is able to be traversed by an XdmfVisitor to write out its information to XML and HDF5 or other heavy data formats.  Modify XdmfGeometry, XdmfGrid, XdmfTopology, and XdmfAttribute to inherit from XdmfItem.
parent ac19e9d4
......@@ -11,26 +11,33 @@ if(Boost_FOUND)
message(${Boost_INCLUDE_DIRS})
endif(Boost_FOUND)
find_package(PythonLibs REQUIRED)
if(PYTHONLIBS_FOUND)
include_directories(${PYTHON_INCLUDE_DIRS})
endif(PYTHONLIBS_FOUND)
option(XDMF_WRAP_PYTHON ON)
if(XDMF_WRAP_PYTHON)
find_package(PythonLibs REQUIRED)
if(PYTHONLIBS_FOUND)
include_directories(${PYTHON_INCLUDE_DIRS})
endif(PYTHONLIBS_FOUND)
endif(XDMF_WRAP_PYTHON)
set(XdmfSources
XdmfGeometry
XdmfGrid
XdmfItem
XdmfObject
XdmfTopology
XdmfVisitor
)
add_library(Xdmf ${XdmfSources})
add_library(_Xdmf MODULE XdmfPython)
set_target_properties(_Xdmf PROPERTIES PREFIX "")
target_link_libraries(_Xdmf Xdmf)
if(WIN32 OR APPLE)
target_link_libraries(_Xdmf ${PYTHON_LIBRARY})
endif(WIN32 OR APPLE)
if(XDMF_WRAP_PYTHON)
add_library(_Xdmf MODULE XdmfPython)
set_target_properties(_Xdmf PROPERTIES PREFIX "")
target_link_libraries(_Xdmf Xdmf)
if(WIN32 OR APPLE)
target_link_libraries(_Xdmf ${PYTHON_LIBRARY})
endif(WIN32 OR APPLE)
endif(XDMF_WRAP_PYTHON)
configure_file(Xdmf.py Xdmf.py COPYONLY)
......
......@@ -7,28 +7,35 @@ swig -v -c++ -python -o XdmfPython.cpp Xdmf.i
%include std_vector.i
namespace boost {
template<class T> class shared_ptr
{
public:
T * operator-> () const;
};
template<class T> class shared_ptr
{
public:
T * operator-> () const;
};
}
%template(XdmfGeometryPtr) boost::shared_ptr<XdmfGeometry>;
%template(XdmfGridPtr) boost::shared_ptr<XdmfGrid>;
%template(XdmfItemPtr) boost::shared_ptr<XdmfItem>;
%template(XdmfObjPtr) boost::shared_ptr<XdmfObject>;
%template(XdmfTopologyPtr) boost::shared_ptr<XdmfTopology>;
%template(XdmfVisitorPtr) boost::shared_ptr<XdmfVisitor>;
%module Xdmf
%{
#include <XdmfGeometry.hpp>
#include <XdmfGrid.hpp>
#include <XdmfObject.hpp>
#include <XdmfTopology.hpp>
#include <XdmfGeometry.hpp>
#include <XdmfGrid.hpp>
#include <XdmfItem.hpp>
#include <XdmfObject.hpp>
#include <XdmfTopology.hpp>
#include <XdmfVisitor.hpp>
%}
%include XdmfObject.hpp
%include XdmfItem.hpp
%include XdmfVisitor.hpp
%include XdmfGeometry.hpp
%include XdmfGrid.hpp
%include XdmfTopology.hpp
This diff is collapsed.
......@@ -8,9 +8,9 @@
#ifndef XDMFATTRIBUTE_HPP_
#define XDMFATTRIBUTE_HPP_
#include "XdmfObject.hpp"
#include "XdmfItem.hpp"
class XdmfAttribute : public XdmfObject {
class XdmfAttribute : public XdmfItem {
XdmfNewMacro(XdmfAttribute);
......
......@@ -7,7 +7,19 @@
#include "XdmfGeometry.hpp"
XdmfGeometry::XdmfGeometry()
// Supported XdmfGeometryTypes
const XdmfGeometryType XdmfGeometryType::NoGeometry("NONE", 0);
const XdmfGeometryType XdmfGeometryType::XYZ("XYZ", 3);
const XdmfGeometryType XdmfGeometryType::XY("XY", 2);
const XdmfGeometryType XdmfGeometryType::X_Y_Z("X_Y_Z", 3);
const XdmfGeometryType XdmfGeometryType::X_Y("X_Y", 2);
const XdmfGeometryType XdmfGeometryType::VXVYVZ("VXVYVZ", 3);
const XdmfGeometryType XdmfGeometryType::Origin_DXDYDZ("ORIGIN_DXDYDZ", 3);
const XdmfGeometryType XdmfGeometryType::VXVY("VXVY", 2);
const XdmfGeometryType XdmfGeometryType::Origin_DXDY("ORIGIN_DXDY", 2);
XdmfGeometry::XdmfGeometry() :
mGeometryType(&XdmfGeometryType::NoGeometry)
{
std::cout << "Created Geometry " << this << std::endl;
}
......@@ -17,6 +29,27 @@ XdmfGeometry::~XdmfGeometry()
std::cout << "Deleted Geometry " << this << std::endl;
}
const XdmfGeometryType& XdmfGeometry::getGeometryType() const
{
return *mGeometryType;
}
void XdmfGeometry::setGeometryType(const XdmfGeometryType& geomType)
{
mGeometryType = &geomType;
return;
}
const std::string XdmfGeometry::getGeometryTypeAsString() const
{
return mGeometryType->name;
}
const int XdmfGeometry::getDimensions() const
{
return mGeometryType->dimensions;
}
const std::string XdmfGeometry::printSelf() const
{
return "XdmfGeometry";
......
......@@ -8,13 +8,102 @@
#ifndef XDMFGEOMETRY_HPP_
#define XDMFGEOMETRY_HPP_
#include "XdmfObject.hpp"
#include "XdmfItem.hpp"
class XdmfGeometry : public XdmfObject {
class XdmfGeometryType {
public:
const int dimensions;
const std::string name;
// Supported Xdmf Geometry Types
static const XdmfGeometryType NoGeometry;
static const XdmfGeometryType XYZ;
static const XdmfGeometryType XY;
static const XdmfGeometryType X_Y_Z;
static const XdmfGeometryType X_Y;
static const XdmfGeometryType VXVYVZ;
static const XdmfGeometryType Origin_DXDYDZ;
static const XdmfGeometryType VXVY;
static const XdmfGeometryType Origin_DXDY;
/*
* Compare two XdmfGeometry types for equality. Each geometry type has a single static instance meaning that
* equality can be determined by determining if they have the same pointer value.
*
* @param an XdmfGeometryType to compare equality to.
* @return true iff the XdmfGeometryTypes are equal.
*/
bool operator==(const XdmfGeometryType& top) const
{
return (this == &top) ? true : false;
}
/**
* Compare two XdmfGeometry types for inequality. Each geometry type has a single static instance meaning that
* equality can be determined by determining if they have the same pointer value.
*
* @param XdmfGeometryType to compare inequality to.
* @return true iff the XdmfGeometryTypes are not equal.
*/
bool operator!=(const XdmfGeometryType& top) const
{
return (this != &top) ? true : false;
}
protected:
/**
* Protected constructor for XdmfGeometryType. The constructor is protected because all geometry types supported
* by Xdmf should be accessed through static public instances of XdmfGeometryType - i.e. XdmfGeometryType::XYZ.
*/
XdmfGeometryType(const std::string& name, const int& dimensions) :
name(name),
dimensions(dimensions)
{};
private:
//XdmfTopologyType(const XdmfTopologyType&); // Not implemented.
//void operator=(const XdmfTopologyType&); // Not implemented.
};
class XdmfGeometry : public XdmfItem {
public:
XdmfNewMacro(XdmfGeometry);
/**
* Get the XdmfGeometryType associated with this Geometry.
*
* @return XdmfGeometryType.
*/
const XdmfGeometryType& getGeometryType() const;
/**
* Set the XdmfGeometryType associated with this Geometry.
*
* @param XdmfGeometryType to set.
*/
void setGeometryType(const XdmfGeometryType&);
/**
* Get the name of the GeometryType associated with this Geometry.
*
* @return std::string containing name of the GeometryType.
*/
const std::string getGeometryTypeAsString() const;
/**
* Get the number of dimensions for this Geometry.
*
* @return int giving number of dimensions: i.e. XY = 2, XYZ = 3.
*/
const int getDimensions() const;
virtual const std::string printSelf() const;
protected:
......@@ -24,15 +113,11 @@ protected:
private:
class Delete
{
public:
void operator()(XdmfGeometry * p) { delete p; }
};
XdmfGeometry(const XdmfGeometry&); // Not implemented.
void operator=(const XdmfGeometry&); // Not implemented.
const XdmfGeometryType * mGeometryType;
};
#endif /* XDMFGEOMETRY_HPP_ */
......@@ -9,11 +9,11 @@
#include "XdmfGeometry.hpp"
#include "XdmfTopology.hpp"
XdmfGrid::XdmfGrid()
XdmfGrid::XdmfGrid() :
mGeometry(XdmfGeometry::New()),
mTopology(XdmfTopology::New())
{
std::cout << "Created Grid " << this << std::endl;
mGeometry = XdmfGeometry::New();
mTopology = XdmfTopology::New();
}
XdmfGrid::~XdmfGrid()
......
......@@ -6,16 +6,15 @@
// Forward Declarations
class XdmfAttribute;
class XdmfAttributeVector;
class XdmfGeometry;
class XdmfTopology;
class XdmfVisitor;
// Includes
#include "XdmfObject.hpp"
#include "XdmfItem.hpp"
#include <vector>
class XdmfGrid : public XdmfObject {
class XdmfGrid : public XdmfItem {
public:
......@@ -31,6 +30,8 @@ public:
// Set the XdmfTopology for this grid
XdmfSetValueMacro(Topology, boost::shared_ptr<XdmfTopology>);
//virtual void write(XdmfVisitor&) const;
virtual const std::string printSelf() const;
protected:
......
#include "XdmfItem.hpp"
XdmfItem::XdmfItem()
{
}
XdmfItem::~XdmfItem()
{
}
/**
* An XdmfItem replaces the XdmfElement class in the previous version of Xdmf. An XdmfElement represents and item that can be
* visited by an XdmfLightDataVisitor and have it's contents added to an XdmfFile. These include XdmfGrids, XdmfSets,
* XdmfTopologies, etc.
*
* This is an abstract base class.
*/
#ifndef XDMFITEM_HPP_
#define XDMFITEM_HPP_
class XdmfVisitor;
// Includes
#include "XdmfObject.hpp"
class XdmfItem : public XdmfObject {
public:
//virtual const std::string printSelf() const = 0;
//virtual void write(XdmfVisitor&) const = 0;
protected:
XdmfItem();
virtual ~XdmfItem();
private:
//XdmfItem(const XdmfItem&); // Not implemented.
//void operator=(const XdmfItem&); // Not implemented.
};
#endif /* XDMFITEM_HPP_ */
......@@ -36,8 +36,7 @@ class XdmfObject {
public:
XdmfNewMacro(XdmfObject);
virtual const std::string printSelf() const;
virtual const std::string printSelf() const = 0;
protected:
......
This diff is collapsed.
......@@ -7,33 +7,33 @@
#include "XdmfTopology.hpp"
const XdmfTopologyType XdmfTopologyType::NoTopology(0, "NoTopology");
const XdmfTopologyType XdmfTopologyType::Polyvertex(1, "Polyvertex");
const XdmfTopologyType XdmfTopologyType::Polyline(1, "Polyline");
const XdmfTopologyType XdmfTopologyType::Polygon(1, "Polygon");
const XdmfTopologyType XdmfTopologyType::Triangle(3, "Triangle");
const XdmfTopologyType XdmfTopologyType::Quadrilateral(4, "Quadrilateral");
const XdmfTopologyType XdmfTopologyType::Tetrahedron(4, "Tetrahedron");
const XdmfTopologyType XdmfTopologyType::Pyramid(5, "Pyramid");
const XdmfTopologyType XdmfTopologyType::Wedge(6, "Wedge");
const XdmfTopologyType XdmfTopologyType::Hexahedron(8, "Hexahedron");
const XdmfTopologyType XdmfTopologyType::Edge_3(3, "Edge_3");
const XdmfTopologyType XdmfTopologyType::Triangle_6(6, "Triangle_6");
const XdmfTopologyType XdmfTopologyType::Quadrilateral_8(8, "Quadrilateral_8");
const XdmfTopologyType XdmfTopologyType::Tetrahedron_10(10, "Tetrahedron_10");
const XdmfTopologyType XdmfTopologyType::Pyramid_13(13, "Pyramid_13");
const XdmfTopologyType XdmfTopologyType::Wedge_15(15, "Wedge_15");
const XdmfTopologyType XdmfTopologyType::Hexahedron_20(20, "Hexahedron_20");
const XdmfTopologyType XdmfTopologyType::Mixed(0, "Mixed");
const XdmfTopologyType XdmfTopologyType::TwoDSMesh(1, "2DSMesh");
const XdmfTopologyType XdmfTopologyType::TwoDRectMesh(1, "2DRectMesh");
const XdmfTopologyType XdmfTopologyType::TwoDCoRectMesh(1, "2DCoRectMesh");
const XdmfTopologyType XdmfTopologyType::ThreeDSMesh(1, "3DSMesh");
const XdmfTopologyType XdmfTopologyType::ThreeDRectMesh(1, "3DRectMesh");
const XdmfTopologyType XdmfTopologyType::ThreeDCoRectMesh(1, "3DCoRectMesh");
XdmfTopology::XdmfTopology():
mTopologyType(&XdmfTopologyType::Tetrahedron)
const XdmfTopologyType XdmfTopologyType::NoTopology(0, "NoTopology", NoCellType);
const XdmfTopologyType XdmfTopologyType::Polyvertex(1, "Polyvertex", Linear);
const XdmfTopologyType XdmfTopologyType::Polyline(1, "Polyline", Linear);
const XdmfTopologyType XdmfTopologyType::Polygon(1, "Polygon", Linear);
const XdmfTopologyType XdmfTopologyType::Triangle(3, "Triangle", Linear);
const XdmfTopologyType XdmfTopologyType::Quadrilateral(4, "Quadrilateral", Linear);
const XdmfTopologyType XdmfTopologyType::Tetrahedron(4, "Tetrahedron", Linear);
const XdmfTopologyType XdmfTopologyType::Pyramid(5, "Pyramid", Linear);
const XdmfTopologyType XdmfTopologyType::Wedge(6, "Wedge", Linear);
const XdmfTopologyType XdmfTopologyType::Hexahedron(8, "Hexahedron", Linear);
const XdmfTopologyType XdmfTopologyType::Edge_3(3, "Edge_3", Quadratic);
const XdmfTopologyType XdmfTopologyType::Triangle_6(6, "Triangle_6", Quadratic);
const XdmfTopologyType XdmfTopologyType::Quadrilateral_8(8, "Quadrilateral_8", Quadratic);
const XdmfTopologyType XdmfTopologyType::Tetrahedron_10(10, "Tetrahedron_10", Quadratic);
const XdmfTopologyType XdmfTopologyType::Pyramid_13(13, "Pyramid_13", Quadratic);
const XdmfTopologyType XdmfTopologyType::Wedge_15(15, "Wedge_15", Quadratic);
const XdmfTopologyType XdmfTopologyType::Hexahedron_20(20, "Hexahedron_20", Quadratic);
const XdmfTopologyType XdmfTopologyType::Mixed(0, "Mixed", Arbitrary);
const XdmfTopologyType XdmfTopologyType::TwoDSMesh(1, "2DSMesh", Structured);
const XdmfTopologyType XdmfTopologyType::TwoDRectMesh(1, "2DRectMesh", Structured);
const XdmfTopologyType XdmfTopologyType::TwoDCoRectMesh(1, "2DCoRectMesh", Structured);
const XdmfTopologyType XdmfTopologyType::ThreeDSMesh(1, "3DSMesh", Structured);
const XdmfTopologyType XdmfTopologyType::ThreeDRectMesh(1, "3DRectMesh", Structured);
const XdmfTopologyType XdmfTopologyType::ThreeDCoRectMesh(1, "3DCoRectMesh", Structured);
XdmfTopology::XdmfTopology() :
mTopologyType(&XdmfTopologyType::NoTopology)
{
std::cout << "Created Topology " << this << std::endl;
}
......@@ -43,6 +43,22 @@ XdmfTopology::~XdmfTopology()
std::cout << "Deleted Topology " << this << std::endl;
}
const XdmfTopologyType & XdmfTopology::getTopologyType() const
{
return *mTopologyType;
}
void XdmfTopology::setTopologyType(const XdmfTopologyType& topType)
{
mTopologyType = &topType;
return;
}
const int XdmfTopology::getNodesPerElement() const
{
return mTopologyType->nodesPerElement;
}
const std::string XdmfTopology::getTopologyTypeAsString() const
{
return mTopologyType->name;
......
......@@ -8,16 +8,22 @@
#ifndef XDMFTOPOLOGY_HPP_
#define XDMFTOPOLOGY_HPP_
#include "XdmfObject.hpp"
#include "XdmfItem.hpp"
class XdmfTopologyType {
public:
const int numberVertices;
enum CellType {
NoCellType, Linear, Quadratic, Arbitrary, Structured
};
const int nodesPerElement;
const std::string name;
const CellType cellType;
// Supported Xdmf Topology Type
// TODO: How do we deal with Polygon datatypes and others that can have variable nodesPerElement?
static const XdmfTopologyType NoTopology;
static const XdmfTopologyType Polyvertex;
static const XdmfTopologyType Polyline;
......@@ -43,11 +49,25 @@ public:
static const XdmfTopologyType ThreeDRectMesh;
static const XdmfTopologyType ThreeDCoRectMesh;
/*
* Compare two XdmfTopology types for equality. Each topology type has a single static instance meaning that
* equality can be determined by determining if they have the same pointer value.
*
* @param an XdmfTopologyType to compare equality to.
* @return true iff the XdmfTopologyTypes are equal.
*/
bool operator==(const XdmfTopologyType& top) const
{
return (this == &top) ? true : false;
}
/**
* Compare two XdmfTopology types for inequality. Each topology type has a single static instance meaning that
* equality can be determined by determining if they have the same pointer value.
*
* @param XdmfTopologyType to compare inequality to.
* @return true iff the XdmfTopologyTypes are not equal.
*/
bool operator!=(const XdmfTopologyType& top) const
{
return (this != &top) ? true : false;
......@@ -55,9 +75,14 @@ public:
protected:
XdmfTopologyType(const int & numberVertices, const std::string & name) :
numberVertices(numberVertices),
name(name)
/**
* Protected constructor for XdmfTopologyType. The constructor is protected because all topology types supported
* by Xdmf should be accessed through static public instances of XdmfTopologyType - i.e. XdmfTopologyType::Tetrahedron.
*/
XdmfTopologyType(const int& nodesPerElement, const std::string& name, const CellType& cellType) :
nodesPerElement(nodesPerElement),
name(name),
cellType(cellType)
{};
private:
......@@ -67,25 +92,43 @@ private:
};
class XdmfTopology : public XdmfObject {
class XdmfTopology : public XdmfItem {
public:
XdmfNewMacro(XdmfTopology);
// Get the topology type for this topology
const XdmfTopologyType & getXdmfTopologyType() const
{
return *mTopologyType;
}
// Set the topology type for this topology
void setTopologyType(const XdmfTopologyType & topType)
{
mTopologyType = &topType;
}
/**
* Get the XdmfTopologyType associated with this Topology.
*
* @return XdmfTopologyType.
*/
const XdmfTopologyType& getTopologyType() const;
/**
* Set the XdmfTopologyType associated with this Topology.
*
* @param XdmfTopologyType to set.
*/
void setTopologyType(const XdmfTopologyType&);
/**
* Get the name of the TopologyType associated with this Topology.
*
* @return std::string containing name of the TopologyType.
*/
const std::string getTopologyTypeAsString() const;
/**
* Get the number of nodes per element for this Topology.
*
* @return int of number of nodes per element.
*/
const int getNodesPerElement() const;
/**
*
*/
virtual const std::string printSelf() const;
protected:
......
// Kenneth Leiter
// Xdmf Smart Pointer Test
#include "XdmfVisitor.hpp"
XdmfVisitor::XdmfVisitor()
{
}
XdmfVisitor::~XdmfVisitor()
{
}
const std::string XdmfVisitor::printSelf() const
{
return "XdmfVisitor";
}
// Kenneth Leiter
// Xdmf Smart Pointer Test
#ifndef XDMFVISITOR_HPP_
#define XDMFVISITOR_HPP_
// Forward Declarations
// Includes
#include "XdmfObject.hpp"
class XdmfVisitor : public XdmfObject {
public:
XdmfNewMacro(XdmfVisitor);
//virtual void visit(boost::shared_ptr<XdmfItem>);
const std::string printSelf() const;
protected:
XdmfVisitor();
virtual ~XdmfVisitor();
private:
XdmfVisitor(const XdmfVisitor&); // Not implemented.
void operator=(const XdmfVisitor&); // Not implemented.
};
#endif /* XDMFVISITOR_HPP_ */
......@@ -25,9 +25,9 @@ int main(int argc, char* argv[])
top->setTopologyType(XdmfTopologyType::Hexahedron);
std::cout << top->getTopologyTypeAsString() << std::endl;
if (top->getXdmfTopologyType() != XdmfTopologyType::Polygon)
if (top->getTopologyType() != XdmfTopologyType::Polygon)
{
top->setTopologyType(XdmfTopologyType::Polygon);
}
std::cout << top->getXdmfTopologyType().name << std::endl;
std::cout << top->getTopologyType().name << std::endl;
}
add_executable(TestXdmfTopologyType TestXdmfTopologyType)
target_link_libraries(TestXdmfTopologyType Xdmf)
\ No newline at end of file
add_executable(TestXdmfTopology TestXdmfTopology)
target_link_libraries(TestXdmfTopology Xdmf)
add_executable(TestXdmfGeometry TestXdmfGeometry)
target_link_libraries(TestXdmfGeometry Xdmf)
\ No newline at end of file
#include "XdmfGeometry.hpp"
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);
boost::shared_ptr<XdmfGeometry> geom = XdmfGeometry::New();
assert(geom->getGeometryType() == XdmfGeometryType::NoGeometry);
assert(geom->getGeometryType().name.compare("NONE") == 0);
assert(geom->getGeometryType().dimensions == 0);
geom->setGeometryType(XdmfGeometryType::XYZ);
assert(geom->getGeometryType() == XdmfGeometryType::XYZ);
assert(geom->getGeometryTypeAsString().compare("XYZ") == 0);
assert(geom->getDimensions() == 3);
return 0;
}
#include "XdmfTopology.hpp"
int main(int argc, char* argv[])
{
// Test != and == operators
assert(XdmfTopologyType::Hexahedron == XdmfTopologyType::Hexahedron);
assert(XdmfTopologyType::Hexahedron == XdmfTopologyType::Tetrahedron == false);
assert(XdmfTopologyType::Hexahedron != XdmfTopologyType::Hexahedron == false);
assert(XdmfTopologyType::Hexahedron != XdmfTopologyType::Tetrahedron);
boost::shared_ptr<XdmfTopology> top = XdmfTopology::New();
assert(top->getTopologyType() == XdmfTopologyType::NoTopology);
assert(top->getTopologyType().name.compare("NoTopology") == 0);
assert(top->getTopologyType().nodesPerElement == 0);
top->setTopologyType(XdmfTopologyType::Hexahedron);
assert(top->getTopologyType() == XdmfTopologyType::Hexahedron);
assert(top->getTopologyTypeAsString().compare("Hexahedron") == 0);
assert(top->getNodesPerElement() == 8);
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