Commit 3d1e70fb authored by Kenneth Leiter's avatar Kenneth Leiter

ENH: Move XdmfCore into its own subdirectory. Move XdmfCore specific tests...

ENH: Move XdmfCore into its own subdirectory.  Move XdmfCore specific tests into core subdirectory and modify
swig wrapping to create two separate libraries (Xdmf and XdmfCore).
parent fcfd3891
project(Xdmf2)
project(Xdmf)
cmake_minimum_required(VERSION 2.6)
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/CMake ${CMAKE_MODULE_PATH})
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
set(BUILD_SHARED_LIBS true)
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/CMake ${CMAKE_CURRENT_SOURCE_DIR}/core/CMake)
find_package(Boost REQUIRED)
if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
endif(Boost_FOUND)
find_package(HDF5 REQUIRED)
if(HDF5_FOUND)
include_directories(${HDF5_INCLUDE_DIR})
endif(HDF5_FOUND)
find_package(LibXml2 REQUIRED)
if(LIBXML2_FOUND)
include_directories(${LIBXML2_INCLUDE_DIR})
endif(LIBXML2_FOUND)
option(XDMF_WRAP_PYTHON OFF)
if(XDMF_WRAP_PYTHON)
find_package(SWIG REQUIRED)
include(${SWIG_USE_FILE})
find_package(PythonLibs REQUIRED)
include_directories(${PYTHON_INCLUDE_DIRS})
set_source_files_properties(Xdmf.i PROPERTIES CPLUSPLUS ON)
swig_add_module(Xdmf python Xdmf.i)
swig_link_libraries(Xdmf Xdmf ${PYTHON_LIBRARIES})
endif(XDMF_WRAP_PYTHON)
set(XdmfCoreSources
XdmfArray
XdmfArrayType
XdmfCoreItemFactory
XdmfCoreReader
XdmfDataItem
XdmfHDF5Controller
XdmfHDF5Writer
XdmfItem
XdmfItemProperty
XdmfObject
XdmfVisitor
XdmfWriter
)
add_subdirectory(core)
include_directories(${XdmfCore_INCLUDE_DIRS})
set(XdmfSources
XdmfAttribute
......@@ -65,8 +27,6 @@ set(XdmfSources
XdmfTopologyType
)
add_library(XdmfCore ${XdmfCoreSources})
target_link_libraries(XdmfCore ${HDF5_LIBRARIES} ${LIBXML2_LIBRARIES})
add_library(Xdmf ${XdmfSources})
target_link_libraries(Xdmf XdmfCore)
......@@ -75,14 +35,20 @@ if(XDMF_BUILD_DOCUMENTATION)
add_subdirectory(doc)
endif(XDMF_BUILD_DOCUMENTATION)
option(XDMF_BUILD_TESTING OFF)
if(XDMF_BUILD_TESTING)
enable_testing()
include(CTest)
add_subdirectory(tests)
endif(XDMF_BUILD_TESTING)
option(XDMF_BUILD_UTILS OFF)
if(XDMF_BUILD_UTILS)
add_subdirectory(utils)
add_subdirectory(utils)
endif(XDMF_BUILD_UTILS)
if(XDMF_WRAP_PYTHON)
find_package(SWIG REQUIRED)
include(${SWIG_USE_FILE})
set_source_files_properties(Xdmf.i PROPERTIES CPLUSPLUS ON)
swig_add_module(Xdmf python Xdmf.i)
swig_link_libraries(Xdmf Xdmf ${PYTHON_LIBRARIES})
endif(XDMF_WRAP_PYTHON)
......@@ -5,209 +5,80 @@ swig -v -c++ -python -o XdmfPython.cpp Xdmf.i
%module Xdmf
%{
// XdmfCore Includes
#include <XdmfArray.hpp>
#include <XdmfArrayType.hpp>
#include <XdmfCoreItemFactory.hpp>
#include <XdmfCoreReader.hpp>
#include <XdmfDataItem.hpp>
#include <XdmfHDF5Controller.hpp>
#include <XdmfHDF5Writer.hpp>
#include <XdmfItem.hpp>
#include <XdmfItemProperty.hpp>
#include <XdmfObject.hpp>
#include <XdmfVisitor.hpp>
#include <XdmfWriter.hpp>
// Xdmf Includes
#include <XdmfAttribute.hpp>
#include <XdmfAttributeCenter.hpp>
#include <XdmfAttributeType.hpp>
#include <XdmfDataItem.hpp>
#include <XdmfDomain.hpp>
#include <XdmfGeometry.hpp>
#include <XdmfGeometryType.hpp>
#include <XdmfGrid.hpp>
#include <XdmfGridCollection.hpp>
#include <XdmfGridCollectionType.hpp>
#include <XdmfHDF5Controller.hpp>
#include <XdmfHDF5Writer.hpp>
#include <XdmfItem.hpp>
#include <XdmfItemProperty.hpp>
#include <XdmfObject.hpp>
#include <XdmfItemFactory.hpp>
#include <XdmfReader.hpp>
#include <XdmfSet.hpp>
#include <XdmfSetType.hpp>
#include <XdmfTopology.hpp>
#include <XdmfTopologyType.hpp>
#include <XdmfVisitor.hpp>
#include <XdmfWriter.hpp>
%}
%include boost_shared_ptr.i
%include std_string.i
%include std_vector.i
%include loki/Visitor.h
%import XdmfCore.i
%pythoncode {
from XdmfCore import *
}
// Shared Pointer Templates
%shared_ptr(XdmfArray)
%shared_ptr(XdmfAttribute)
%shared_ptr(XdmfBaseVisitor)
%shared_ptr(XdmfDataItem)
%shared_ptr(XdmfAttributeCenter)
%shared_ptr(XdmfAttributeType)
%shared_ptr(XdmfDomain)
%shared_ptr(XdmfGeometry)
%shared_ptr(XdmfGeometryType)
%shared_ptr(XdmfGrid)
%shared_ptr(XdmfGridCollection)
%shared_ptr(XdmfHDF5Controller)
%shared_ptr(XdmfHDF5Writer)
%shared_ptr(XdmfItem)
%shared_ptr(XdmfItemProperty)
%shared_ptr(XdmfObject)
%shared_ptr(XdmfGridCollectionType)
%shared_ptr(XdmfItemFactory)
%shared_ptr(XdmfReader)
%shared_ptr(XdmfSet)
%shared_ptr(XdmfTopology)
%shared_ptr(XdmfVisitor)
%shared_ptr(XdmfWriter)
%shared_ptr(XdmfArrayType)
%shared_ptr(XdmfAttributeCenter)
%shared_ptr(XdmfAttributeType)
%shared_ptr(XdmfGeometryType)
%shared_ptr(XdmfGridCollectionType)
%shared_ptr(XdmfSetType)
%shared_ptr(XdmfTopology)
%shared_ptr(XdmfTopologyType)
// Abstract Base Classes
%template() Loki::BaseVisitable<void>;
%template() Loki::Visitor<XdmfArray>;
%template() Loki::Visitor<XdmfAttribute>;
%template() Loki::Visitor<XdmfDomain>;
%template() Loki::Visitor<XdmfGeometry>;
%template() Loki::Visitor<XdmfGrid>;
%template() Loki::Visitor<XdmfItem>;
%template() Loki::Visitor<XdmfTopology>;
%include XdmfObject.hpp
%include XdmfItem.hpp
%include XdmfDataItem.hpp
%include XdmfItemProperty.hpp
%include XdmfVisitor.hpp
%include XdmfHDF5Controller.hpp
%include XdmfHDF5Writer.hpp
%include XdmfReader.hpp
%include XdmfWriter.hpp
%include XdmfAttribute.hpp
%include XdmfAttributeCenter.hpp
%include XdmfAttributeType.hpp
%include XdmfArray.hpp
%include XdmfArrayType.hpp
%include XdmfDomain.hpp
%include XdmfGeometry.hpp
%include XdmfGeometryType.hpp
%include XdmfGrid.hpp
%include XdmfGridCollection.hpp
%include XdmfGridCollectionType.hpp
%include XdmfItemFactory.hpp
%include XdmfReader.hpp
%include XdmfSet.hpp
%include XdmfSetType.hpp
%include XdmfTopology.hpp
%include XdmfTopologyType.hpp
%include XdmfGridCollection.hpp
%include XdmfGridCollectionType.hpp
%template(getValueCopyAsInt8) XdmfArray::getValueCopy<char>;
%template(getValueCopyAsInt16) XdmfArray::getValueCopy<short>;
%template(getValueCopyAsInt32) XdmfArray::getValueCopy<int>;
%template(getValueCopyAsInt64) XdmfArray::getValueCopy<long>;
%template(getValueCopyAsFloat32) XdmfArray::getValueCopy<float>;
%template(getValueCopyAsFloat64) XdmfArray::getValueCopy<double>;
%template(getValueCopyAsUInt8) XdmfArray::getValueCopy<unsigned char>;
%template(getValueCopyAsUInt16) XdmfArray::getValueCopy<unsigned short>;
%template(getValueCopyAsUInt32) XdmfArray::getValueCopy<unsigned int>;
%template(pushBackAsInt8) XdmfArray::pushBack<char>;
%template(pushBackAsInt16) XdmfArray::pushBack<short>;
%template(pushBackAsInt32) XdmfArray::pushBack<int>;
%template(pushBackAsInt64) XdmfArray::pushBack<long>;
%template(pushBackAsFloat32) XdmfArray::pushBack<float>;
%template(pushBackAsFloat64) XdmfArray::pushBack<double>;
%template(pushBackAsUInt8) XdmfArray::pushBack<unsigned char>;
%template(pushBackAsUInt16) XdmfArray::pushBack<unsigned short>;
%template(pushBackAsUInt32) XdmfArray::pushBack<unsigned int>;
%template(resizeAsInt8) XdmfArray::resize<char>;
%template(resizeAsInt16) XdmfArray::resize<short>;
%template(resizeAsInt32) XdmfArray::resize<int>;
%template(resizeAsInt64) XdmfArray::resize<long>;
%template(resizeAsFloat32) XdmfArray::resize<float>;
%template(resizeAsFloat64) XdmfArray::resize<double>;
%template(resizeAsUInt8) XdmfArray::resize<unsigned char>;
%template(resizeAsUInt16) XdmfArray::resize<unsigned short>;
%template(resizeAsUInt32) XdmfArray::resize<unsigned int>;
// Provide accessors from python lists to XdmfArrays
%extend XdmfArray {
void copyValueAsInt8(int index, char value) {
$self->copyValues(index, &value);
}
void copyValueAsInt16(int index, short value) {
$self->copyValues(index, &value);
}
void copyValueAsInt32(int index, int value) {
$self->copyValues(index, &value);
}
void copyValueAsInt64(int index, long value) {
$self->copyValues(index, &value);
}
void copyValueAsFloat32(int index, float value) {
$self->copyValues(index, &value);
}
void copyValueAsFloat64(int index, double value) {
$self->copyValues(index, &value);
}
void copyValueAsUInt8(int index, unsigned char value) {
$self->copyValues(index, &value);
}
void copyValueAsUInt16(int index, unsigned short value) {
$self->copyValues(index, &value);
}
void copyValueAsUInt32(int index, unsigned int value) {
$self->copyValues(index, &value);
}
};
%extend XdmfArray {
%pythoncode {
def copyValuesAsInt8(self, startIndex, values):
for i in range(0, len(values)):
self.copyValueAsInt8(i+startIndex, values[i])
def copyValuesAsInt16(self, startIndex, values):
for i in range(0, len(values)):
self.copyValueAsInt16(i+startIndex, values[i])
def copyValuesAsInt32(self, startIndex, values):
for i in range(0, len(values)):
self.copyValueAsInt32(i+startIndex, values[i])
def copyValuesAsInt64(self, startIndex, values):
for i in range(0, len(values)):
self.copyValueAsInt64(i+startIndex, values[i])
def copyValuesAsFloat32(self, startIndex, values):
for i in range(0, len(values)):
self.copyValueAsFloat32(i+startIndex, values[i])
def copyValuesAsFloat64(self, startIndex, values):
for i in range(0, len(values)):
self.copyValueAsFloat64(i+startIndex, values[i])
def copyValuesAsUInt8(self, startIndex, values):
for i in range(0, len(values)):
self.copyValueAsUInt8(i+startIndex, values[i])
def copyValuesAsUInt16(self, startIndex, values):
for i in range(0, len(values)):
self.copyValueAsUInt16(i+startIndex, values[i])
def copyValuesAsUInt32(self, startIndex, values):
for i in range(0, len(values)):
self.copyValueAsUInt32(i+startIndex, values[i])
};
};
project(XdmfCore)
cmake_minimum_required(VERSION 2.6)
set(BUILD_SHARED_LIBS true)
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/CMake)
find_package(Boost REQUIRED)
if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
endif(Boost_FOUND)
find_package(HDF5 REQUIRED)
if(HDF5_FOUND)
include_directories(${HDF5_INCLUDE_DIR})
endif(HDF5_FOUND)
find_package(LibXml2 REQUIRED)
if(LIBXML2_FOUND)
include_directories(${LIBXML2_INCLUDE_DIR})
endif(LIBXML2_FOUND)
set(XdmfCoreSources
XdmfArray
XdmfArrayType
XdmfCoreItemFactory
XdmfCoreReader
XdmfDataItem
XdmfHDF5Controller
XdmfHDF5Writer
XdmfItem
XdmfItemProperty
XdmfObject
XdmfVisitor
XdmfWriter
)
add_library(XdmfCore ${XdmfCoreSources})
target_link_libraries(XdmfCore ${HDF5_LIBRARIES} ${LIBXML2_LIBRARIES})
option(XDMF_BUILD_TESTING OFF)
if(XDMF_BUILD_TESTING)
enable_testing()
include(CTest)
add_subdirectory(tests)
endif(XDMF_BUILD_TESTING)
option(XDMF_WRAP_PYTHON OFF)
if(XDMF_WRAP_PYTHON)
find_package(SWIG REQUIRED)
include(${SWIG_USE_FILE})
find_package(PythonLibs REQUIRED)
include_directories(${PYTHON_INCLUDE_DIRS})
set_source_files_properties(XdmfCore.i PROPERTIES CPLUSPLUS ON)
swig_add_module(XdmfCore python XdmfCore.i)
swig_link_libraries(XdmfCore XdmfCore ${PYTHON_LIBRARIES})
endif(XDMF_WRAP_PYTHON)
set(XdmfCore_INCLUDE_DIRS ${Boost_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR} ${HDF5_INCLUDE_DIR} ${LIBXML2_INCLUDE_DIR} ${PYTHON_INCLUDE_DIRS} CACHE INTERNAL "")
\ No newline at end of file
/*
XdmfCorePython.cpp:
swig -v -c++ -python -o XdmfCorePython.cpp XdmfCore.i
*/
%module XdmfCore
%{
#include <XdmfArray.hpp>
#include <XdmfArrayType.hpp>
#include <XdmfCoreItemFactory.hpp>
#include <XdmfCoreReader.hpp>
#include <XdmfDataItem.hpp>
#include <XdmfHDF5Controller.hpp>
#include <XdmfHDF5Writer.hpp>
#include <XdmfItem.hpp>
#include <XdmfItemProperty.hpp>
#include <XdmfObject.hpp>
#include <XdmfVisitor.hpp>
#include <XdmfWriter.hpp>
%}
%include boost_shared_ptr.i
%include std_string.i
%include std_vector.i
%include loki/Visitor.h
// Shared Pointer Templates
%shared_ptr(XdmfArray)
%shared_ptr(XdmfArrayType)
%shared_ptr(XdmfBaseVisitor)
%shared_ptr(XdmfCoreItemFactory)
%shared_ptr(XdmfCoreReader)
%shared_ptr(XdmfDataItem)
%shared_ptr(XdmfHDF5Controller)
%shared_ptr(XdmfHDF5Writer)
%shared_ptr(XdmfItem)
%shared_ptr(XdmfItemProperty)
%shared_ptr(XdmfObject)
%shared_ptr(XdmfVisitor)
%shared_ptr(XdmfWriter)
// Abstract Base Classes
%template() Loki::BaseVisitable<void>;
%template() Loki::Visitor<XdmfArray>;
%template() Loki::Visitor<XdmfItem>;
%include XdmfObject.hpp
%include XdmfItem.hpp
%include XdmfDataItem.hpp
%include XdmfItemProperty.hpp
%include XdmfVisitor.hpp
%include XdmfCoreItemFactory.hpp
%include XdmfCoreReader.hpp
%include XdmfHDF5Controller.hpp
%include XdmfHDF5Writer.hpp
%include XdmfWriter.hpp
%include XdmfArray.hpp
%include XdmfArrayType.hpp
%template(getValueCopyAsInt8) XdmfArray::getValueCopy<char>;
%template(getValueCopyAsInt16) XdmfArray::getValueCopy<short>;
%template(getValueCopyAsInt32) XdmfArray::getValueCopy<int>;
%template(getValueCopyAsInt64) XdmfArray::getValueCopy<long>;
%template(getValueCopyAsFloat32) XdmfArray::getValueCopy<float>;
%template(getValueCopyAsFloat64) XdmfArray::getValueCopy<double>;
%template(getValueCopyAsUInt8) XdmfArray::getValueCopy<unsigned char>;
%template(getValueCopyAsUInt16) XdmfArray::getValueCopy<unsigned short>;
%template(getValueCopyAsUInt32) XdmfArray::getValueCopy<unsigned int>;
%template(pushBackAsInt8) XdmfArray::pushBack<char>;
%template(pushBackAsInt16) XdmfArray::pushBack<short>;
%template(pushBackAsInt32) XdmfArray::pushBack<int>;
%template(pushBackAsInt64) XdmfArray::pushBack<long>;
%template(pushBackAsFloat32) XdmfArray::pushBack<float>;
%template(pushBackAsFloat64) XdmfArray::pushBack<double>;
%template(pushBackAsUInt8) XdmfArray::pushBack<unsigned char>;
%template(pushBackAsUInt16) XdmfArray::pushBack<unsigned short>;
%template(pushBackAsUInt32) XdmfArray::pushBack<unsigned int>;
%template(resizeAsInt8) XdmfArray::resize<char>;
%template(resizeAsInt16) XdmfArray::resize<short>;
%template(resizeAsInt32) XdmfArray::resize<int>;
%template(resizeAsInt64) XdmfArray::resize<long>;
%template(resizeAsFloat32) XdmfArray::resize<float>;
%template(resizeAsFloat64) XdmfArray::resize<double>;
%template(resizeAsUInt8) XdmfArray::resize<unsigned char>;
%template(resizeAsUInt16) XdmfArray::resize<unsigned short>;
%template(resizeAsUInt32) XdmfArray::resize<unsigned int>;
// Provide accessors from python lists to XdmfArrays
%extend XdmfArray {
void copyValueAsInt8(int index, char value) {
$self->copyValues(index, &value);
}
void copyValueAsInt16(int index, short value) {
$self->copyValues(index, &value);
}
void copyValueAsInt32(int index, int value) {
$self->copyValues(index, &value);
}
void copyValueAsInt64(int index, long value) {
$self->copyValues(index, &value);
}
void copyValueAsFloat32(int index, float value) {
$self->copyValues(index, &value);
}
void copyValueAsFloat64(int index, double value) {
$self->copyValues(index, &value);
}
void copyValueAsUInt8(int index, unsigned char value) {
$self->copyValues(index, &value);
}
void copyValueAsUInt16(int index, unsigned short value) {
$self->copyValues(index, &value);
}
void copyValueAsUInt32(int index, unsigned int value) {
$self->copyValues(index, &value);
}
};
%extend XdmfArray {
%pythoncode {
def copyValuesAsInt8(self, startIndex, values):
for i in range(0, len(values)):
self.copyValueAsInt8(i+startIndex, values[i])
def copyValuesAsInt16(self, startIndex, values):
for i in range(0, len(values)):
self.copyValueAsInt16(i+startIndex, values[i])
def copyValuesAsInt32(self, startIndex, values):
for i in range(0, len(values)):
self.copyValueAsInt32(i+startIndex, values[i])
def copyValuesAsInt64(self, startIndex, values):
for i in range(0, len(values)):
self.copyValueAsInt64(i+startIndex, values[i])
def copyValuesAsFloat32(self, startIndex, values):
for i in range(0, len(values)):
self.copyValueAsFloat32(i+startIndex, values[i])
def copyValuesAsFloat64(self, startIndex, values):
for i in range(0, len(values)):
self.copyValueAsFloat64(i+startIndex, values[i])
def copyValuesAsUInt8(self, startIndex, values):
for i in range(0, len(values)):
self.copyValueAsUInt8(i+startIndex, values[i])
def copyValuesAsUInt16(self, startIndex, values):
for i in range(0, len(values)):
self.copyValueAsUInt16(i+startIndex, values[i])
def copyValuesAsUInt32(self, startIndex, values):
for i in range(0, len(values)):
self.copyValueAsUInt32(i+startIndex, values[i])
};
};
......@@ -9,7 +9,7 @@ class XdmfItem;
#include "XdmfObject.hpp"
/**
* @brief Factory for constructing XdmfItems from their ItemTag and ItemProperties
* @brief Factory that constructs XdmfItems using tags and properties.
*
* XdmfCoreItemFactory is an abstract base class.
*/
......
......@@ -92,5 +92,3 @@ boost::shared_ptr<XdmfItem> XdmfCoreReader::read(const std::string & filePath) c
return toReturn[0];
}
......@@ -20,10 +20,21 @@ public:
virtual ~XdmfCoreReader();
/**
* Read an Xdmf file from disk into memory.
*
* @param fileName the path on disk to the Xdmf file to read in.
* @return an XdmfItem at the root of the Xdmf tree.
*/
virtual boost::shared_ptr<XdmfItem> read(const std::string & fileName) const;
protected:
/**
* Constructor
*
* @param itemFactory an XdmfCoreItemFactory to construct XdmfItems for a specific Xdmf language.
*/
XdmfCoreReader(const boost::shared_ptr<XdmfCoreItemFactory> itemFactory);
private:
......
add_subdirectory(Cxx)
if(XDMF_WRAP_PYTHON)
add_subdirectory(Python)
endif(XDMF_WRAP_PYTHON)
set(XdmfCoreCxxTests
TestXdmfArray
TestXdmfArrayWriteRead
TestXdmfDataItem
TestXdmfHDF5Writer
)
foreach(test ${XdmfCoreCxxTests})
add_executable(${test} ${test})
target_link_libraries(${test} XdmfCore)
add_test(${test} ${test})
endforeach(test ${XdmfCoreCxxTests})
include(UsePythonTest)
set(XdmfCorePythonTests
TestXdmfArray.py
)
foreach(test ${XdmfCorePythonTests})
set_source_files_properties(${test} PROPERTIES PYTHONPATH "${CMAKE_BINARY_DIR}")
add_python_test(${test} ${test})
endforeach(test ${XdmfCorePythonTests})
from Xdmf import *
from XdmfCore import *
if __name__ == "__main__":
......
set(XdmfCoreCxxTests
TestXdmfArray
TestXdmfArrayWriteRead
TestXdmfDataItem
TestXdmfHDF5Writer
)
set(XdmfCxxTests
TestXdmfAttribute
TestXdmfGeometry
......@@ -18,12 +11,6 @@ set(XdmfCxxTests
TestXdmfWriterHDF5ThenXML
)
foreach(test ${XdmfCoreCxxTests})
add_executable(${test} ${test})
target_link_libraries(${test} XdmfCore)
add_test(${test} ${test})
endforeach(test ${XdmfCoreCxxTests})
foreach(test ${XdmfCxxTests})
add_executable(${test} ${test})
target_link_libraries(${test} Xdmf)
......
include(UsePythonTest)
set(XdmfPythonTests
TestXdmfArray.py
TestXdmfHDF5Writer.py
TestXdmfWriter.py
)