Commit b17ab6e3 authored by Kenneth Leiter's avatar Kenneth Leiter

ENH: Added XdmfTopologyType to XdmfTopology to handle element types and...

ENH: Added XdmfTopologyType to XdmfTopology to handle element types and associated const data like nodesPerElement and name.  This resembles "Replace subclass with fields" implementation in Refactoring and does a nice job encapsulating element type data in an enum like way avoiding unneccesary subclassing.
parent f0246ede
......@@ -7,28 +7,32 @@ set(BUILD_SHARED_LIBS true)
find_package(Boost REQUIRED)
if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
message(${Boost_INCLUDE_DIRS})
include_directories(${Boost_INCLUDE_DIRS})
message(${Boost_INCLUDE_DIRS})
endif(Boost_FOUND)
find_package(PythonLibs REQUIRED)
if(PYTHONLIBS_FOUND)
include_directories(${PYTHON_INCLUDE_DIRS})
include_directories(${PYTHON_INCLUDE_DIRS})
endif(PYTHONLIBS_FOUND)
set(XdmfSources
XdmfGeometry
XdmfGrid
XdmfObject
XdmfTopology
XdmfGeometry
XdmfGrid
XdmfObject
XdmfTopology
)
add_library(Xdmf ${XdmfSources})
add_library(_Xdmf MODULE XdmfPython)
set_target_properties(_Xdmf PROPERTIES PREFIX "")
target_link_libraries(_Xdmf Xdmf)
configure_file(Xdmf.py Xdmf.py COPYONLY)
add_executable(XdmfTest test.cpp)
target_link_libraries(XdmfTest Xdmf)
#add_library(_Xdmf MODULE XdmfPython)
#set_target_properties(_Xdmf PROPERTIES PREFIX "")
#target_link_libraries(_Xdmf Xdmf)
#configure_file(Xdmf.py Xdmf.py COPYONLY)
option(BUILD_TESTING OFF)
if(BUILD_TESTING)
add_subdirectory(tests)
add_executable(XdmfTest test.cpp)
target_link_libraries(XdmfTest Xdmf)
endif(BUILD_TESTING)
\ No newline at end of file
/*
XdmfPython.cpp:
swig -v -c++ -make_default -python -shadow -I/share/kleiter/boost-1.41.0-install/include -o XdmfPython.cpp Xdmf.i
*/
%include std_string.i
%include std_vector.i
namespace boost {
template<class T> class shared_ptr
{
public:
T * operator-> () const;
};
}
%template(XdmfGridPtr) boost::shared_ptr<XdmfGrid>;
%module Xdmf
%{
#include <XdmfGeometry.hpp>
#include <XdmfGrid.hpp>
#include <XdmfObject.hpp>
#include <XdmfTopology.hpp>
%}
%include XdmfObject.hpp
%include XdmfGeometry.hpp
%include XdmfGrid.hpp
%include XdmfObject.hpp
%include XdmfTopology.hpp
# This file was automatically generated by SWIG (http://www.swig.org).
# Version 1.3.37
# Version 1.3.40
#
# Do not make changes to this file unless you know what you are doing--modify
# the SWIG interface file instead.
......@@ -10,12 +10,18 @@ if version_info >= (2,6,0):
def swig_import_helper():
from os.path import dirname
import imp
fp = None
try:
fp, pathname, description = imp.find_module('_Xdmf', [dirname(__file__)])
_mod = imp.load_module('_Xdmf', fp, pathname, description)
finally:
if fp is not None: fp.close()
return _mod
except ImportError:
import _Xdmf
return _Xdmf
if fp is not None:
try:
_mod = imp.load_module('_Xdmf', fp, pathname, description)
finally:
fp.close()
return _mod
_Xdmf = swig_import_helper()
del swig_import_helper
else:
......@@ -65,7 +71,7 @@ class SwigPyIterator(_object):
__setattr__ = lambda self, name, value: _swig_setattr(self, SwigPyIterator, name, value)
__swig_getmethods__ = {}
__getattr__ = lambda self, name: _swig_getattr(self, SwigPyIterator, name)
def __init__(self, *args, **kwargs): raise AttributeError("No constructor defined")
def __init__(self, *args, **kwargs): raise AttributeError("No constructor defined - class is abstract")
__repr__ = _swig_repr
__swig_destroy__ = _Xdmf.delete_SwigPyIterator
__del__ = lambda self : None;
......@@ -161,6 +167,9 @@ class XdmfTopologyPtr(_object):
__swig_destroy__ = _Xdmf.delete_XdmfTopologyPtr
__del__ = lambda self : None;
def New(self): return _Xdmf.XdmfTopologyPtr_New(self)
def getTopologyType(self): return _Xdmf.XdmfTopologyPtr_getTopologyType(self)
def setTopologyType(self, *args): return _Xdmf.XdmfTopologyPtr_setTopologyType(self, *args)
def getTopologyTypeAsString(self): return _Xdmf.XdmfTopologyPtr_getTopologyTypeAsString(self)
def printSelf(self): return _Xdmf.XdmfTopologyPtr_printSelf(self)
XdmfTopologyPtr_swigregister = _Xdmf.XdmfTopologyPtr_swigregister
XdmfTopologyPtr_swigregister(XdmfTopologyPtr)
......@@ -224,6 +233,30 @@ def XdmfGrid_New():
return _Xdmf.XdmfGrid_New()
XdmfGrid_New = _Xdmf.XdmfGrid_New
XDMF_NOTOPOLOGY = _Xdmf.XDMF_NOTOPOLOGY
XDMF_POLYVERTEX = _Xdmf.XDMF_POLYVERTEX
XDMF_POLYLINE = _Xdmf.XDMF_POLYLINE
XDMF_POLYGON = _Xdmf.XDMF_POLYGON
XDMF_TRI = _Xdmf.XDMF_TRI
XDMF_QUAD = _Xdmf.XDMF_QUAD
XDMF_TET = _Xdmf.XDMF_TET
XDMF_PYRAMID = _Xdmf.XDMF_PYRAMID
XDMF_WEDGE = _Xdmf.XDMF_WEDGE
XDMF_HEX = _Xdmf.XDMF_HEX
XDMF_EDGE_3 = _Xdmf.XDMF_EDGE_3
XDMF_TRI_6 = _Xdmf.XDMF_TRI_6
XDMF_QUAD_8 = _Xdmf.XDMF_QUAD_8
XDMF_TET_10 = _Xdmf.XDMF_TET_10
XDMF_PYRAMID_13 = _Xdmf.XDMF_PYRAMID_13
XDMF_WEDGE_15 = _Xdmf.XDMF_WEDGE_15
XDMF_HEX_20 = _Xdmf.XDMF_HEX_20
XDMF_MIXED = _Xdmf.XDMF_MIXED
XDMF_2DSMESH = _Xdmf.XDMF_2DSMESH
XDMF_2DRECTMESH = _Xdmf.XDMF_2DRECTMESH
XDMF_2DCORECTMESH = _Xdmf.XDMF_2DCORECTMESH
XDMF_3DSMESH = _Xdmf.XDMF_3DSMESH
XDMF_3DRECTMESH = _Xdmf.XDMF_3DRECTMESH
XDMF_3DCORECTMESH = _Xdmf.XDMF_3DCORECTMESH
class XdmfTopology(XdmfObject):
__swig_setmethods__ = {}
for _s in [XdmfObject]: __swig_setmethods__.update(getattr(_s,'__swig_setmethods__',{}))
......@@ -235,6 +268,9 @@ class XdmfTopology(XdmfObject):
__repr__ = _swig_repr
__swig_getmethods__["New"] = lambda x: _Xdmf.XdmfTopology_New
if _newclass:New = staticmethod(_Xdmf.XdmfTopology_New)
def getTopologyType(self): return _Xdmf.XdmfTopology_getTopologyType(self)
def setTopologyType(self, *args): return _Xdmf.XdmfTopology_setTopologyType(self, *args)
def getTopologyTypeAsString(self): return _Xdmf.XdmfTopology_getTopologyTypeAsString(self)
def printSelf(self): return _Xdmf.XdmfTopology_printSelf(self)
XdmfTopology_swigregister = _Xdmf.XdmfTopology_swigregister
XdmfTopology_swigregister(XdmfTopology)
......
......@@ -17,7 +17,7 @@ XdmfGeometry::~XdmfGeometry()
std::cout << "Deleted Geometry " << this << std::endl;
}
std::string XdmfGeometry::printSelf() const
const std::string XdmfGeometry::printSelf() const
{
return "XdmfGeometry";
}
......@@ -15,7 +15,7 @@ class XdmfGeometry : public XdmfObject {
public:
XdmfNewMacro(XdmfGeometry);
virtual std::string printSelf() const;
virtual const std::string printSelf() const;
protected:
......
......@@ -21,7 +21,7 @@ XdmfGrid::~XdmfGrid()
std::cout << "Deleted Grid " << this << std::endl;
}
std::string XdmfGrid::printSelf() const
const std::string XdmfGrid::printSelf() const
{
return "XdmfGrid containing a " + mGeometry->printSelf() + " and a " + mTopology->printSelf();
}
......@@ -31,7 +31,7 @@ public:
// Set the XdmfTopology for this grid
XdmfSetValueMacro(Topology, boost::shared_ptr<XdmfTopology>);
virtual std::string printSelf() const;
virtual const std::string printSelf() const;
protected:
......
......@@ -17,7 +17,7 @@ XdmfObject::~XdmfObject()
}
std::string XdmfObject::printSelf() const
const std::string XdmfObject::printSelf() const
{
return "XdmfObject";
}
......
......@@ -20,14 +20,14 @@ static boost::shared_ptr<type> New() \
return p; \
}
#define XdmfGetValueMacro(var,type) \
#define XdmfGetValueMacro(var, type) \
type get##var () \
{ \
return ( this->m##var ); \
}
#define XdmfSetValueMacro(var,type) \
void set##var (type _arg) \
void set##var (const type _arg) \
{ \
this->m##var = _arg; \
}
......@@ -37,7 +37,7 @@ class XdmfObject {
public:
XdmfNewMacro(XdmfObject);
virtual std::string printSelf() const;
virtual const std::string printSelf() const;
protected:
......
This diff is collapsed.
......@@ -7,7 +7,33 @@
#include "XdmfTopology.hpp"
XdmfTopology::XdmfTopology()
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)
{
std::cout << "Created Topology " << this << std::endl;
}
......@@ -17,7 +43,12 @@ XdmfTopology::~XdmfTopology()
std::cout << "Deleted Topology " << this << std::endl;
}
std::string XdmfTopology::printSelf() const
const std::string XdmfTopology::getTopologyTypeAsString() const
{
return mTopologyType->name;
}
const std::string XdmfTopology::printSelf() const
{
return "XdmfTopology";
}
......@@ -10,13 +10,83 @@
#include "XdmfObject.hpp"
class XdmfTopologyType {
public:
const int numberVertices;
const std::string name;
// Supported Xdmf Topology Type
static const XdmfTopologyType NoTopology;
static const XdmfTopologyType Polyvertex;
static const XdmfTopologyType Polyline;
static const XdmfTopologyType Polygon;
static const XdmfTopologyType Triangle;
static const XdmfTopologyType Quadrilateral;
static const XdmfTopologyType Tetrahedron;
static const XdmfTopologyType Pyramid;
static const XdmfTopologyType Wedge;
static const XdmfTopologyType Hexahedron;
static const XdmfTopologyType Edge_3;
static const XdmfTopologyType Triangle_6;
static const XdmfTopologyType Quadrilateral_8;
static const XdmfTopologyType Tetrahedron_10;
static const XdmfTopologyType Pyramid_13;
static const XdmfTopologyType Wedge_15;
static const XdmfTopologyType Hexahedron_20;
static const XdmfTopologyType Mixed;
static const XdmfTopologyType TwoDSMesh;
static const XdmfTopologyType TwoDRectMesh;
static const XdmfTopologyType TwoDCoRectMesh;
static const XdmfTopologyType ThreeDSMesh;
static const XdmfTopologyType ThreeDRectMesh;
static const XdmfTopologyType ThreeDCoRectMesh;
bool operator==(const XdmfTopologyType& top) const
{
return (this == &top) ? true : false;
}
bool operator!=(const XdmfTopologyType& top) const
{
return (this != &top) ? true : false;
}
protected:
XdmfTopologyType(const int & numberVertices, const std::string & name) :
numberVertices(numberVertices),
name(name)
{};
private:
//XdmfTopologyType(const XdmfTopologyType&); // Not implemented.
//void operator=(const XdmfTopologyType&); // Not implemented.
};
class XdmfTopology : public XdmfObject {
public:
XdmfNewMacro(XdmfTopology);
virtual std::string printSelf() const;
// 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;
}
const std::string getTopologyTypeAsString() const;
virtual const std::string printSelf() const;
protected:
......@@ -28,6 +98,7 @@ private:
XdmfTopology(const XdmfTopology&); // Not implemented.
void operator=(const XdmfTopology&); // Not implemented.
const XdmfTopologyType * mTopologyType;
};
#endif /* XDMFTOPOLOGY_HPP_ */
......@@ -21,4 +21,13 @@ int main(int argc, char* argv[])
boost::shared_ptr<XdmfTopology> top = XdmfTopology::New();
std::cout << *top << std::endl;
std::cout << top->getTopologyTypeAsString() << std::endl;
top->setTopologyType(XdmfTopologyType::Hexahedron);
std::cout << top->getTopologyTypeAsString() << std::endl;
if (top->getXdmfTopologyType() != XdmfTopologyType::Polygon)
{
top->setTopologyType(XdmfTopologyType::Polygon);
}
std::cout << top->getXdmfTopologyType().name << std::endl;
}
add_executable(TestXdmfTopologyType TestXdmfTopologyType)
target_link_libraries(TestXdmfTopologyType Xdmf)
\ No newline at end of file
#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);
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