Commit 05106efd authored by Andrew J. Burns (Cont's avatar Andrew J. Burns (Cont

fixing type comparisons for python wrappers

parent 643784cd
......@@ -145,6 +145,65 @@ swig -v -c++ -python -o XdmfCorePython.cpp XdmfCore.i
We are doing this intentionally so suppressing the warning makes sense.*/
#pragma SWIG nowarn=509
%extend XdmfItem {
bool __eq__(const XdmfItem * item) {
return $self == item;
}
};
%extend XdmfItemProperty {
bool __eq__(const XdmfItemProperty * item) {
return $self == item;
}
};
%extend XdmfVisitor {
bool __eq__(const XdmfVisitor * item) {
return $self == item;
}
};
%extend XdmfHeavyDataWriter {
bool __eq__(const XdmfHeavyDataWriter * item) {
return $self == item;
}
};
%extend XdmfHeavyDataController {
bool __eq__(const XdmfHeavyDataController * item) {
return $self == item;
}
static shared_ptr<XdmfHDF5Controller> XdmfHDF5ControllerCast(PyObject * obj)
{
void * resultPointer = 0;
swig_type_info * returnType = SWIG_TypeQuery("_p_boost__shared_ptrT_XdmfHeavyDataController_t");
SWIG_ConvertPtr(obj, &resultPointer, returnType, 0);
shared_ptr<XdmfHeavyDataController> * returnControllerPointer =
reinterpret_cast<shared_ptr<XdmfHeavyDataController> *>(resultPointer);
shared_ptr<XdmfHeavyDataController> returnController = returnControllerPointer[0];
if (shared_ptr<XdmfHDF5Controller> returnHDF5Controller = shared_dynamic_cast<XdmfHDF5Controller>(returnController)) {
return returnHDF5Controller;
}
else {
XdmfError::message(XdmfError::FATAL, "Error: Attempting to cast a non HDF5 Controller to HDF5");
return shared_ptr<XdmfHDF5Controller>();
}
}
};
%extend XdmfCoreReader {
bool __eq__(const XdmfCoreReader * item) {
return $self == item;
}
};
%extend XdmfWriter {
bool __eq__(const XdmfWriter * item) {
return $self == item;
}
};
// Provide accessors from python lists to XdmfArrays
%extend XdmfArray {
......@@ -282,31 +341,6 @@ swig -v -c++ -python -o XdmfCorePython.cpp XdmfCore.i
}
};
%extend XdmfArrayType {
bool __eq__(const XdmfArrayType * arrayType) {
return $self == arrayType;
}
};
%extend XdmfHeavyDataController {
static shared_ptr<XdmfHDF5Controller> XdmfHDF5ControllerCast(PyObject * obj)
{
void * resultPointer = 0;
swig_type_info * returnType = SWIG_TypeQuery("_p_boost__shared_ptrT_XdmfHeavyDataController_t");
SWIG_ConvertPtr(obj, &resultPointer, returnType, 0);
shared_ptr<XdmfHeavyDataController> * returnControllerPointer =
reinterpret_cast<shared_ptr<XdmfHeavyDataController> *>(resultPointer);
shared_ptr<XdmfHeavyDataController> returnController = returnControllerPointer[0];
if (shared_ptr<XdmfHDF5Controller> returnHDF5Controller = shared_dynamic_cast<XdmfHDF5Controller>(returnController)) {
return returnHDF5Controller;
}
else {
XdmfError::message(XdmfError::FATAL, "Error: Attempting to cast a non HDF5 Controller to HDF5");
return shared_ptr<XdmfHDF5Controller>();
}
}
};
/*This causes it to avoid throwing a warning for redefining fuctions that are defined for XdmfArray.
I do this because doing so was intentional.*/
#pragma SWIG nowarn=302
......
......@@ -74,6 +74,25 @@ swig -v -c++ -python -o XdmfDSMPython.cpp XdmfDSM.i
%include <typemaps.i>
%apply int & INOUT {int & data };
%extend XdmfDSMBuffer {
bool __eq__(const XdmfDSMBuffer * item) {
return $self == item;
}
};
%extend XdmfDSMCommMPI {
bool __eq__(const XdmfDSMCommMPI * item) {
return $self == item;
}
};
%extend XdmfDSMManager {
bool __eq__(const XdmfDSMManager * item) {
return $self == item;
}
};
%extend XdmfHeavyDataController {
static shared_ptr<XdmfHDF5ControllerDSM> XdmfHDF5ControllerDSMCast(PyObject * obj)
{
......
......@@ -36,6 +36,7 @@ ADD_TEST_CXX(TestXdmfVisitorValueCounter)
ADD_TEST_CXX(TestXdmfWriter)
ADD_TEST_CXX(TestXdmfWriterHDF5ThenXML)
ADD_TEST_CXX(TestXdmfXPath)
ADD_TEST_CXX(TestXdmfXPointerReference)
#removed due to long execution time
#ADD_TEST_CXX(HugeWriteArray)
......@@ -111,6 +112,11 @@ CLEAN_TEST_CXX(TestXdmfWriterHDF5ThenXML)
CLEAN_TEST_CXX(TestXdmfXPath
XdmfXPath1.xmf
XdmfXPath2.xmf)
CLEAN_TEST_CXX(TestXdmfXPointerReference
duplicateXpointer.xmf
duplicateXpointer.h5
duplicateXpointer2.xmf
duplicateXpointer2.h5)
#removed due to long execution time
#CLEAN_TEST_CXX(HugeWriteArray
# arraydata1.h5
......
#include <iostream>
#include <XdmfDomain.hpp>
#include <XdmfGridCollection.hpp>
#include <XdmfWriter.hpp>
#include <XdmfUnstructuredGrid.hpp>
#include <XdmfTime.hpp>
#include <XdmfReader.hpp>
int main(int ac, char *av[])
{
shared_ptr<XdmfReader> reader = XdmfReader::New();
shared_ptr<XdmfDomain> domain = XdmfDomain::New();
shared_ptr<XdmfGridCollection> collection1 = XdmfGridCollection::New();
shared_ptr<XdmfGridCollection> collection2 = XdmfGridCollection::New();
shared_ptr<XdmfUnstructuredGrid> unstructuredGrid = XdmfUnstructuredGrid::New();
collection1->insert(unstructuredGrid);
collection2->insert(unstructuredGrid);
domain->insert(collection1);
domain->insert(collection2);
shared_ptr<XdmfWriter> writer = XdmfWriter::New("duplicateXpointer.xmf");
domain->accept(writer);
shared_ptr<XdmfDomain> readDomain = shared_dynamic_cast<XdmfDomain>(reader->read("duplicateXpointer.xmf"));
assert(readDomain->getGridCollection(0)->getUnstructuredGrid(0) == readDomain->getGridCollection(1)->getUnstructuredGrid(0));
assert(readDomain->getGridCollection(0)->getUnstructuredGrid(0).get() == readDomain->getGridCollection(1)->getUnstructuredGrid(0).get());
readDomain->getGridCollection(0)->getUnstructuredGrid(0)->setName("Test Grid");
shared_ptr<XdmfTime> time = XdmfTime::New(5.5);
readDomain->getGridCollection(1)->getUnstructuredGrid(0)->setTime(time);
shared_ptr<XdmfWriter> writer2 = XdmfWriter::New("duplicateXpointer2.xmf");
readDomain->accept(writer2);
shared_ptr<XdmfDomain> readDomain2 = shared_dynamic_cast<XdmfDomain>(reader->read("duplicateXpointer2.xmf"));
std::cout << readDomain2->getGridCollection(1)->getUnstructuredGrid(0)->getName() << " ?= Test Grid" << std::endl;
std::cout << readDomain2->getGridCollection(0)->getUnstructuredGrid(0)->getTime()->getValue() << " ?= " << 5.5 << std::endl;
assert(readDomain2->getGridCollection(1)->getUnstructuredGrid(0)->getName() =="Test Grid");
assert(readDomain2->getGridCollection(0)->getUnstructuredGrid(0)->getTime()->getValue() == 5.5);
return 0;
}
......@@ -21,6 +21,7 @@ ADD_TEST_PYTHON(TestXdmfHDF5Writer)
ADD_TEST_PYTHON(TestXdmfRead)
ADD_TEST_PYTHON(TestXdmfSet)
ADD_TEST_PYTHON(TestXdmfWriter)
ADD_TEST_PYTHON(TestXdmfXPointerReference)
# Add any python cleanup here:
......@@ -42,6 +43,11 @@ CLEAN_TEST_PYTHON(TestXdmfSet)
CLEAN_TEST_PYTHON(TestXdmfWriter
output.h5
output.xmf)
CLEAN_TEST_PYTHON(TestXdmfXPointerReference
duplicateXpointer.xmf
duplicateXpointer.h5
duplicateXpointer2.xmf
duplicateXpointer2.h5)
# Add a custom target for all python tests
......
from Xdmf import *
if __name__ == "__main__":
reader = XdmfReader.New()
domain = XdmfDomain.New()
collection1 = XdmfGridCollection.New()
collection2 = XdmfGridCollection.New()
unstructuredGrid = XdmfUnstructuredGrid.New()
collection1.insert(unstructuredGrid)
collection2.insert(unstructuredGrid)
domain.insert(collection1)
domain.insert(collection2)
writer = XdmfWriter.New("duplicateXpointer.xmf")
domain.accept(writer)
readDomain = reader.read("duplicateXpointer.xmf")
print str(readDomain.getGridCollection(0).getUnstructuredGrid(0)) + "\n?=\n" + str(readDomain.getGridCollection(1).getUnstructuredGrid(0))
assert(readDomain.getGridCollection(0).getUnstructuredGrid(0) == readDomain.getGridCollection(1).getUnstructuredGrid(0))
readDomain.getGridCollection(0).getUnstructuredGrid(0).setName("Test Grid")
time = XdmfTime.New(5.5)
readDomain.getGridCollection(1).getUnstructuredGrid(0).setTime(time)
writer2 = XdmfWriter.New("duplicateXpointer2.xmf")
readDomain.accept(writer2)
readDomain2 = reader.read("duplicateXpointer2.xmf")
print readDomain2.getGridCollection(1).getUnstructuredGrid(0).getName() + " ?= Test Grid"
print str(readDomain2.getGridCollection(0).getUnstructuredGrid(0).getTime().getValue()) + " ?= " + str(5.5)
assert(readDomain2.getGridCollection(1).getUnstructuredGrid(0).getName() =="Test Grid")
assert(readDomain2.getGridCollection(0).getUnstructuredGrid(0).getTime().getValue() == 5.5)
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