Commit cb1fe3d8 authored by Kenneth Leiter's avatar Kenneth Leiter

ENH: Get Utils, Python Wrapping, and Tests working for new changes.

parent 996d9c05
......@@ -85,68 +85,54 @@ private:
const unsigned int mIndex;
};
class XdmfArray::GetCapacity : public boost::static_visitor<unsigned int> {
class XdmfArray::GetArrayType : public boost::static_visitor<boost::shared_ptr<const XdmfArrayType> > {
public:
GetCapacity()
GetArrayType()
{
}
template<typename T>
unsigned int operator()(const boost::shared_ptr<std::vector<T> > & array) const
{
return array->capacity();
}
};
class XdmfArray::GetType : public boost::static_visitor<boost::shared_ptr<const XdmfArrayType> > {
public:
GetType()
{
}
boost::shared_ptr<const XdmfArrayType> getType(const char * const) const
boost::shared_ptr<const XdmfArrayType> getArrayType(const char * const) const
{
return XdmfArrayType::Int8();
}
boost::shared_ptr<const XdmfArrayType> getType(const short * const) const
boost::shared_ptr<const XdmfArrayType> getArrayType(const short * const) const
{
return XdmfArrayType::Int16();
}
boost::shared_ptr<const XdmfArrayType> getType(const int * const) const
boost::shared_ptr<const XdmfArrayType> getArrayType(const int * const) const
{
return XdmfArrayType::Int32();
}
boost::shared_ptr<const XdmfArrayType> getType(const long * const) const
boost::shared_ptr<const XdmfArrayType> getArrayType(const long * const) const
{
return XdmfArrayType::Int64();
}
boost::shared_ptr<const XdmfArrayType> getType(const float * const) const
boost::shared_ptr<const XdmfArrayType> getArrayType(const float * const) const
{
return XdmfArrayType::Float32();
}
boost::shared_ptr<const XdmfArrayType> getType(const double * const) const
boost::shared_ptr<const XdmfArrayType> getArrayType(const double * const) const
{
return XdmfArrayType::Float64();
}
boost::shared_ptr<const XdmfArrayType> getType(const unsigned char * const) const
boost::shared_ptr<const XdmfArrayType> getArrayType(const unsigned char * const) const
{
return XdmfArrayType::UInt8();
}
boost::shared_ptr<const XdmfArrayType> getType(const unsigned short * const) const
boost::shared_ptr<const XdmfArrayType> getArrayType(const unsigned short * const) const
{
return XdmfArrayType::UInt16();
}
boost::shared_ptr<const XdmfArrayType> getType(const unsigned int * const) const
boost::shared_ptr<const XdmfArrayType> getArrayType(const unsigned int * const) const
{
return XdmfArrayType::UInt32();
}
......@@ -154,13 +140,27 @@ public:
template<typename T>
boost::shared_ptr<const XdmfArrayType> operator()(const boost::shared_ptr<std::vector<T> > & array) const
{
return this->getType(&(array.get()->operator[](0)));
return this->getArrayType(&(array.get()->operator[](0)));
}
template<typename T>
boost::shared_ptr<const XdmfArrayType> operator()(const boost::shared_array<const T> & array) const
{
return this->getType(array.get());
return this->getArrayType(array.get());
}
};
class XdmfArray::GetCapacity : public boost::static_visitor<unsigned int> {
public:
GetCapacity()
{
}
template<typename T>
unsigned int operator()(const boost::shared_ptr<std::vector<T> > & array) const
{
return array->capacity();
}
};
......@@ -370,6 +370,24 @@ void XdmfArray::erase(const unsigned int index)
}
}
boost::shared_ptr<const XdmfArrayType> XdmfArray::getArrayType() const
{
if(mHaveArray)
{
return boost::apply_visitor(GetArrayType(), mArray);
}
else if(mHaveArrayPointer)
{
return boost::apply_visitor(GetArrayType(), mArrayPointer);
}
else if(mHDF5Controller)
{
return mHDF5Controller->getType();
}
return XdmfArrayType::Uninitialized();
}
unsigned int XdmfArray::getCapacity() const
{
if(mHaveArray)
......@@ -407,7 +425,7 @@ std::map<std::string, std::string> XdmfArray::getItemProperties() const
{
arrayProperties["Name"] = mName;
}
boost::shared_ptr<const XdmfArrayType> type = this->getType();
boost::shared_ptr<const XdmfArrayType> type = this->getArrayType();
type->getProperties(arrayProperties);
return arrayProperties;
}
......@@ -422,23 +440,6 @@ std::string XdmfArray::getName() const
return mName;
}
boost::shared_ptr<const XdmfArrayType> XdmfArray::getType() const
{
if(mHaveArray)
{
return boost::apply_visitor(GetType(), mArray);
}
else if(mHaveArrayPointer)
{
return boost::apply_visitor(GetType(), mArrayPointer);
}
else if(mHDF5Controller)
{
return mHDF5Controller->getType();
}
return XdmfArrayType::Uninitialized();
}
void * XdmfArray::getValuesPointer()
{
return const_cast<void *>(static_cast<const XdmfArray &>(*this).getValuesPointer());
......
......@@ -95,6 +95,14 @@ public:
*/
void erase(const unsigned int index);
/**
* Get the data type of this array.
*
* @return a string containing the Xdmf data type for the array, this is one of
* Char, Short, Int, Float, UChar, UShort, UInt.
*/
boost::shared_ptr<const XdmfArrayType> getArrayType() const;
/**
* Get the capacity of this array (the number of values this array can store without reallocation).
*
......@@ -127,14 +135,6 @@ public:
*/
std::string getName() const;
/**
* Get the data type of this array.
*
* @return a string containing the Xdmf data type for the array, this is one of
* Char, Short, Int, Float, UChar, UShort, UInt.
*/
boost::shared_ptr<const XdmfArrayType> getType() const;
/**
* Get a copy of a single value stored in this array.
*
......@@ -335,9 +335,9 @@ private:
class CopyValues;
class Erase;
class GetArrayType;
class GetCapacity;
class GetHDF5Type;
class GetType;
template <typename T>
class GetValuesCopy;
......
......@@ -7,16 +7,16 @@ swig -v -c++ -python -o XdmfCorePython.cpp XdmfCore.i
%{
#include <XdmfArray.hpp>
#include <XdmfArrayType.hpp>
#include <XdmfCoreHDF5Writer.hpp>
#include <XdmfCoreItemFactory.hpp>
#include <XdmfCoreReader.hpp>
#include <XdmfCoreWriter.hpp>
#include <XdmfHDF5Controller.hpp>
#include <XdmfHDF5Writer.hpp>
#include <XdmfInformation.hpp>
#include <XdmfItem.hpp>
#include <XdmfItemProperty.hpp>
#include <XdmfSystemUtils.hpp>
#include <XdmfVisitor.hpp>
#include <XdmfWriter.hpp>
%}
%include boost_shared_ptr.i
......@@ -24,36 +24,35 @@ swig -v -c++ -python -o XdmfCorePython.cpp XdmfCore.i
%include std_vector.i
%include loki/Visitor.h
// Abstract Base Classes
%template() Loki::BaseVisitable<void>;
%template() Loki::Visitor<XdmfArray>;
%template() Loki::Visitor<XdmfItem>;
// Shared Pointer Templates
%shared_ptr(XdmfArray)
%shared_ptr(XdmfArrayType)
%shared_ptr(XdmfBaseVisitor)
%shared_ptr(XdmfCoreItemFactory)
%shared_ptr(XdmfCoreReader)
%shared_ptr(XdmfCoreWriter)
%shared_ptr(XdmfHDF5Controller)
%shared_ptr(XdmfHDF5Writer)
%shared_ptr(XdmfInformation)
%shared_ptr(XdmfItem)
%shared_ptr(XdmfItemProperty)
%shared_ptr(XdmfVisitor)
%shared_ptr(XdmfWriter)
// Abstract Base Classes
%template() Loki::BaseVisitable<void>;
%template() Loki::Visitor<XdmfArray>;
%template() Loki::Visitor<XdmfItem>;
%include XdmfItem.hpp
%include XdmfDataItem.hpp
%include XdmfItemProperty.hpp
%include XdmfVisitor.hpp
%include XdmfCoreItemFactory.hpp
%include XdmfCoreReader.hpp
%include XdmfCoreWriter.hpp
%include XdmfInformation.hpp
%include XdmfHDF5Controller.hpp
%include XdmfHDF5Writer.hpp
%include XdmfWriter.hpp
%include XdmfArray.hpp
%include XdmfArrayType.hpp
......
......@@ -66,39 +66,39 @@ void XdmfHDF5Writer::visit(XdmfArray & array, const boost::shared_ptr<XdmfBaseVi
if(array.isInitialized())
{
if(array.getType() == XdmfArrayType::Int8())
if(array.getArrayType() == XdmfArrayType::Int8())
{
datatype = H5T_NATIVE_CHAR;
}
else if(array.getType() == XdmfArrayType::Int16())
else if(array.getArrayType() == XdmfArrayType::Int16())
{
datatype = H5T_NATIVE_SHORT;
}
else if(array.getType() == XdmfArrayType::Int32())
else if(array.getArrayType() == XdmfArrayType::Int32())
{
datatype = H5T_NATIVE_INT;
}
else if(array.getType() == XdmfArrayType::Int64())
else if(array.getArrayType() == XdmfArrayType::Int64())
{
datatype = H5T_NATIVE_LONG;
}
else if(array.getType() == XdmfArrayType::Float32())
else if(array.getArrayType() == XdmfArrayType::Float32())
{
datatype = H5T_NATIVE_FLOAT;
}
else if(array.getType() == XdmfArrayType::Float64())
else if(array.getArrayType() == XdmfArrayType::Float64())
{
datatype = H5T_NATIVE_DOUBLE;
}
else if(array.getType() == XdmfArrayType::UInt8())
else if(array.getArrayType() == XdmfArrayType::UInt8())
{
datatype = H5T_NATIVE_UCHAR;
}
else if(array.getType() == XdmfArrayType::UInt16())
else if(array.getArrayType() == XdmfArrayType::UInt16())
{
datatype = H5T_NATIVE_USHORT;
}
else if(array.getType() == XdmfArrayType::UInt32())
else if(array.getArrayType() == XdmfArrayType::UInt32())
{
datatype = H5T_NATIVE_UINT;
}
......@@ -201,7 +201,7 @@ void XdmfHDF5Writer::visit(XdmfArray & array, const boost::shared_ptr<XdmfBaseVi
// Attach a new controller to the array if needed.
if(mImpl->mMode == Default || !array.getHDF5Controller())
{
boost::shared_ptr<XdmfHDF5Controller> newDataSetController = XdmfHDF5Controller::New(hdf5FilePath, dataSetPath.str(), array.size(), array.getType());
boost::shared_ptr<XdmfHDF5Controller> newDataSetController = XdmfHDF5Controller::New(hdf5FilePath, dataSetPath.str(), array.size(), array.getArrayType());
array.setHDF5Controller(newDataSetController);
mImpl->mDataSetId++;
}
......
......@@ -19,6 +19,7 @@ public:
XdmfWriterImpl(const std::string & xmlFilePath, const boost::shared_ptr<XdmfHDF5Writer> hdf5Writer) :
mHDF5Writer(hdf5Writer),
mLastXPathed(false),
mLightDataLimit(100),
mMode(Default),
mWriteXPaths(true),
......@@ -52,6 +53,7 @@ public:
}
boost::shared_ptr<XdmfHDF5Writer> mHDF5Writer;
bool mLastXPathed;
unsigned int mLightDataLimit;
Mode mMode;
bool mWriteXPaths;
......@@ -155,7 +157,7 @@ void XdmfWriter::visit(XdmfArray & array, const boost::shared_ptr<XdmfBaseVisito
this->visit(dynamic_cast<XdmfItem &>(array), visitor);
}
if(array.size() > 0)
if(array.size() > 0 && !mImpl->mLastXPathed)
{
std::stringstream xmlTextValues;
......@@ -230,6 +232,7 @@ void XdmfWriter::visit(XdmfItem & item, const boost::shared_ptr<XdmfBaseVisitor>
// Inserted before --- just xpath location of previously written node
mImpl->mXMLCurrentNode = xmlNewChild(mImpl->mXMLCurrentNode, NULL, (xmlChar*)"xi:include", NULL);
xmlNewProp(mImpl->mXMLCurrentNode, (xmlChar*)"xpointer", (xmlChar*)iter->second.c_str());
mImpl->mLastXPathed = true;
}
else
{
......@@ -247,6 +250,7 @@ void XdmfWriter::visit(XdmfItem & item, const boost::shared_ptr<XdmfBaseVisitor>
mImpl->mXPathCount = 0;
item.traverse(visitor);
mImpl->mXPathCount = parentCount;
mImpl->mLastXPathed = false;
}
mImpl->mXPathString = parentXPathString;
......
......@@ -15,12 +15,12 @@ int main(int argc, char* argv[])
*/
boost::shared_ptr<XdmfArray> array = XdmfArray::New();
assert(array->size() == 0);
assert(array->getType() == XdmfArrayType::Uninitialized());
assert(array->getArrayType() == XdmfArrayType::Uninitialized());
assert(array->getValuesString() == "");
assert(array->getValuesPointer() == NULL);
array->copyValues(0, &values[0], 4, 1, 1);
assert(array->size() == 4);
assert(array->getType() == XdmfArrayType::Int32());
assert(array->getArrayType() == XdmfArrayType::Int32());
assert(array->getValuesString().compare("1 2 3 4 ") == 0);
const int * const arrayPointer = (const int * const)array->getValuesPointer();
assert(arrayPointer[0] == 1);
......@@ -47,7 +47,7 @@ int main(int argc, char* argv[])
boost::shared_ptr<XdmfArray> array2 = XdmfArray::New();
array2->copyValues(0, &values[0], 2, 2, 1);
assert(array2->size() == 3);
assert(array2->getType() == XdmfArrayType::Int32());
assert(array2->getArrayType() == XdmfArrayType::Int32());
assert(array2->getValuesString().compare("1 0 2 ") == 0);
storedValues = array2->getValues<int>();
assert((*storedValues)[0] == 1);
......@@ -60,7 +60,7 @@ int main(int argc, char* argv[])
boost::shared_ptr<XdmfArray> array3 = XdmfArray::New();
array3->copyValues(0, &values[0], 2, 1, 2);
assert(array3->size() == 2);
assert(array3->getType() == XdmfArrayType::Int32());
assert(array3->getArrayType() == XdmfArrayType::Int32());
assert(array3->getValuesString().compare("1 3 ") == 0);
storedValues = array3->getValues<int>();
assert((*storedValues)[0] == 1);
......@@ -106,7 +106,7 @@ int main(int argc, char* argv[])
*/
array5->setValues(values, 2, 0);
assert(array5->size() == 2);
assert(array5->getType() == XdmfArrayType::Int32());
assert(array5->getArrayType() == XdmfArrayType::Int32());
assert(array5->getValuesString().compare("1 2 ") == 0);
const int * const array5Pointer = (const int * const)array5->getValuesPointer();
assert(array5Pointer[0] == 1);
......@@ -135,7 +135,7 @@ int main(int argc, char* argv[])
doubleValues[2] = 10.1;
array5->setValues(doubleValues, 3, 1);
assert(array5->size() == 3);
assert(array5->getType() == XdmfArrayType::Float64());
assert(array5->getArrayType() == XdmfArrayType::Float64());
assert(array5->getValuesString().compare("0 1.1 10.1 ") == 0);
//
......@@ -154,7 +154,7 @@ int main(int argc, char* argv[])
boost::shared_ptr<XdmfArray> array6 = XdmfArray::New();
array6->setValues(values2);
assert(array6->size() == 5);
assert(array6->getType() == XdmfArrayType::Int8());
assert(array6->getArrayType() == XdmfArrayType::Int8());
assert(array6->getValuesString().compare("-2 -1 0 1 2 ") == 0);
// Assert we have the same values!
boost::shared_ptr<std::vector<char> > storedValues2 = array6->getValues<char>();
......@@ -192,7 +192,7 @@ int main(int argc, char* argv[])
array7->swap(values3);
assert(values3.size() == 0);
assert(array7->size() == 3);
assert(array7->getType() == XdmfArrayType::Int16());
assert(array7->getArrayType() == XdmfArrayType::Int16());
boost::shared_ptr<std::vector<short> > storedValues3 = array7->getValues<short>();
assert((*storedValues3)[0] == -1);
assert((*storedValues3)[1] == 0);
......@@ -205,7 +205,7 @@ int main(int argc, char* argv[])
array7->swap(values2);
assert(storedValues2->size() == 0);
assert(array7->size() == 6);
assert(array7->getType() == XdmfArrayType::Int8());
assert(array7->getArrayType() == XdmfArrayType::Int8());
/**
* Swap values from an XdmfArray (with copy)
......
......@@ -6,46 +6,46 @@ if __name__ == "__main__":
array1 = XdmfArray.New()
array1.copyValuesAsInt8(0, values1)
print array1.getValuesString()
assert array1.getType() == XdmfArrayType.Int8()
assert array1.getArrayType() == XdmfArrayType.Int8()
array2 = XdmfArray.New()
array2.copyValuesAsInt16(0, values1)
print array2.getValuesString()
assert array2.getType() == XdmfArrayType.Int16()
assert array2.getArrayType() == XdmfArrayType.Int16()
array3 = XdmfArray.New()
array3.copyValuesAsInt32(0, values1[2:4])
print array3.getValuesString()
assert array3.getType() == XdmfArrayType.Int32()
assert array3.getArrayType() == XdmfArrayType.Int32()
# Stride
array4 = XdmfArray.New()
array4.copyValuesAsInt64(0, values1[0:4:2])
print array4.getValuesString()
assert array4.getType() == XdmfArrayType.Int64()
assert array4.getArrayType() == XdmfArrayType.Int64()
# Reverse
array5 = XdmfArray.New()
array5.copyValuesAsFloat32(0, values1[::-1])
print array5.getValuesString()
assert array5.getType() == XdmfArrayType.Float32()
assert array5.getArrayType() == XdmfArrayType.Float32()
array6 = XdmfArray.New()
array6.copyValuesAsFloat64(0, values1)
print array6.getValuesString()
assert array6.getType() == XdmfArrayType.Float64()
assert array6.getArrayType() == XdmfArrayType.Float64()
array7 = XdmfArray.New()
array7.copyValuesAsUInt8(0, values1)
print array7.getValuesString()
assert array7.getType() == XdmfArrayType.UInt8()
assert array7.getArrayType() == XdmfArrayType.UInt8()
array8 = XdmfArray.New()
array8.copyValuesAsUInt16(0, values1)
print array8.getValuesString()
assert array8.getType() == XdmfArrayType.UInt16()
assert array8.getArrayType() == XdmfArrayType.UInt16()
array9 = XdmfArray.New()
array9.copyValuesAsUInt32(0, values1)
print array9.getValuesString()
assert array9.getType() == XdmfArrayType.UInt32()
assert array9.getArrayType() == XdmfArrayType.UInt32()
......@@ -10,25 +10,25 @@ if __name__ == "__main__":
0.1, 0.1, -1.1, 1.1, 0.1, -1.1, 3.1, 0.1, -2.1, 0.1, 1.1, -1.1, 1.1, 1.1, -1.1, 3.1, 2.1, -2.1]
grid.getGeometry().setType(XdmfGeometryType.XYZ())
grid.getGeometry().getArray().copyValuesAsFloat64(0, points)
grid.getGeometry().copyValuesAsFloat64(0, points)
connectivity = [0, 1, 7, 6, 3, 4, 10, 9, 1, 2, 8, 7, 4, 5, 11, 10]
grid.getTopology().setType(XdmfTopologyType.Hexahedron())
grid.getTopology().getArray().copyValuesAsInt32(0, connectivity)
grid.getTopology().copyValuesAsInt32(0, connectivity)
nodalAttribute = XdmfAttribute.New()
nodalAttribute.setName("Nodal Attribute")
nodalAttribute.setType(XdmfAttributeType.Scalar())
nodalAttribute.setCenter(XdmfAttributeCenter.Node())
nodeVals = [100, 200, 300, 300, 400, 500, 300, 400, 500, 500, 600, 700]
nodalAttribute.getArray().copyValuesAsFloat64(0, nodeVals)
nodalAttribute.copyValuesAsFloat64(0, nodeVals)
cellAttribute = XdmfAttribute.New()
cellAttribute.setName("Cell Attribute")
cellAttribute.setType(XdmfAttributeType.Scalar())
cellAttribute.setCenter(XdmfAttributeCenter.Cell())
cellVals = [100, 200]
cellAttribute.getArray().copyValuesAsFloat64(0, cellVals)
cellAttribute.copyValuesAsFloat64(0, cellVals)
grid.insert(nodalAttribute)
grid.insert(cellAttribute)
......
......@@ -11,25 +11,25 @@ if __name__ == "__main__":
0.1, 0.1, -1.1, 1.1, 0.1, -1.1, 3.1, 0.1, -2.1, 0.1, 1.1, -1.1, 1.1, 1.1, -1.1, 3.1, 2.1, -2.1]
grid.getGeometry().setType(XdmfGeometryType.XYZ())
grid.getGeometry().getArray().copyValuesAsFloat64(0, points)
grid.getGeometry().copyValuesAsFloat64(0, points)
connectivity = [0, 1, 7, 6, 3, 4, 10, 9, 1, 2, 8, 7, 4, 5, 11, 10]
grid.getTopology().setType(XdmfTopologyType.Hexahedron())
grid.getTopology().getArray().copyValuesAsInt32(0, connectivity)
grid.getTopology().copyValuesAsInt32(0, connectivity)
nodalAttribute = XdmfAttribute.New()
nodalAttribute.setName("Nodal Attribute")
nodalAttribute.setType(XdmfAttributeType.Scalar())
nodalAttribute.setCenter(XdmfAttributeCenter.Node())
nodeVals = [100, 200, 300, 300, 400, 500, 300, 400, 500, 500, 600, 700]
nodalAttribute.getArray().copyValuesAsFloat64(0, nodeVals)
nodalAttribute.copyValuesAsFloat64(0, nodeVals)
cellAttribute = XdmfAttribute.New()
cellAttribute.setName("Cell Attribute")
cellAttribute.setType(XdmfAttributeType.Scalar())
cellAttribute.setCenter(XdmfAttributeCenter.Cell())
cellVals = [100, 200]
cellAttribute.getArray().copyValuesAsFloat64(0, cellVals)
cellAttribute.copyValuesAsFloat64(0, cellVals)
grid.insert(nodalAttribute)
grid.insert(cellAttribute)
......
......@@ -90,16 +90,16 @@ boost::shared_ptr<XdmfGridCollection> XdmfPartitioner::partition(const boost::sh
assert(false);
}
if(!gridToPartition->getTopology()->getArray()->isInitialized())
if(!gridToPartition->getTopology()->isInitialized())
{
gridToPartition->getTopology()->getArray()->read();
gridToPartition->getTopology()->read();
}
int numElements = gridToPartition->getTopology()->getNumberElements();
idxtype * metisConnectivity = new idxtype[numNodesPerElement * numElements];
for(unsigned int i=0; i<numElements; ++i)
{
gridToPartition->getTopology()->getArray()->getValuesCopy(i*topologyType->getNodesPerElement(), &metisConnectivity[i*numNodesPerElement], numNodesPerElement);
gridToPartition->getTopology()->getValuesCopy(i*topologyType->getNodesPerElement(), &metisConnectivity[i*numNodesPerElement], numNodesPerElement);
}
int numNodes = gridToPartition->getGeometry()->getNumberPoints();
......@@ -160,7 +160,7 @@ boost::shared_ptr<XdmfGridCollection> XdmfPartitioner::partition(const boost::sh
unsigned int partitionId = elementsPartition[i];
for (unsigned int j=0; j<topologyType->getNodesPerElement(); ++j)
{
unsigned int globalNodeId = gridToPartition->getTopology()->getArray()->getValueCopy<unsigned int>(totalIndex);
unsigned int globalNodeId = gridToPartition->getTopology()->getValueCopy<unsigned int>(totalIndex);
if (globalToLocalNodeIdMap[partitionId].count(globalNodeId) == 0)
{
// Have not seen this node, need to add to map
......@@ -179,9 +179,9 @@ boost::shared_ptr<XdmfGridCollection> XdmfPartitioner::partition(const boost::sh
boost::shared_ptr<XdmfGridCollection> partitionedGrids = XdmfGridCollection::New();
partitionedGrids->setType(XdmfGridCollectionType::Spatial());
if(!gridToPartition->getGeometry()->getArray()->isInitialized())
if(!gridToPartition->getGeometry()->isInitialized())
{
gridToPartition->getGeometry()->getArray()->read();
gridToPartition->getGeometry()->read();
}
// Split geometry and topology into proper partitions
......@@ -201,14 +201,14 @@ boost::shared_ptr<XdmfGridCollection> XdmfPartitioner::partition(const boost::sh
// Fill in geometry for this partition
partitioned->getGeometry()->setType(gridToPartition->getGeometry()->getType());
boost::shared_ptr<XdmfArray> geometryVals = partitioned->getGeometry()->getArray();
boost::shared_ptr<XdmfArray> geometryVals = partitioned->getGeometry();
unsigned int numDimensions = partitioned->getGeometry()->getType()->getDimensions();
geometryVals->initialize(gridToPartition->getGeometry()->getArray()->getType());
geometryVals->initialize(gridToPartition->getGeometry()->getArrayType());
geometryVals->resize<unsigned int>(currNodeMap.size() * numDimensions);
for(std::map<unsigned int, unsigned int>::const_iterator iter = currNodeMap.begin(); iter != currNodeMap.end(); ++iter)
{
geometryVals->copyValues(iter->second * numDimensions, gridToPartition->getGeometry()->getArray(), iter->first * numDimensions, numDimensions);
geometryVals->copyValues(iter->second * numDimensions, gridToPartition->getGeometry(), iter->first * numDimensions, numDimensions);
}
if(heavyDataWriter)
......@@ -219,8 +219,8 @@ boost::shared_ptr<XdmfGridCollection> XdmfPartitioner::partition(const boost::sh
// Fill in topology for this partition
partitioned->getTopology()->setType(gridToPartition->getTopology()->getType());
boost::shared_ptr<XdmfArray> topologyVals = partitioned->getTopology()->getArray();
topologyVals->initialize(gridToPartition->getTopology()->getArray()->getType());
boost::shared_ptr<XdmfArray> topologyVals = partitioned->getTopology();
topologyVals->initialize(gridToPartition->getTopology()->getArrayType());
topologyVals->resize<unsigned int>(currElemIds.size() * topologyType->getNodesPerElement());
unsigned int index = 0;
......@@ -229,7 +229,7 @@ boost::shared_ptr<XdmfGridCollection> XdmfPartitioner::partition(const boost::sh
// Translate these global node ids to local node ids
for(unsigned int j=0; j<topologyType->getNodesPerElement(); ++j)
{
unsigned int globalNodeId = currNodeMap[gridToPartition->getTopology()->getArray()->getValueCopy<unsigned int>(*iter * topologyType->getNodesPerElement() + j)];
unsigned int globalNodeId = currNodeMap[gridToPartition->getTopology()->getValueCopy<unsigned int>(*iter * topologyType->getNodesPerElement() + j)];
topologyVals->copyValues(index, &globalNodeId, 1);
index++;
}
......@@ -248,7 +248,7 @@ boost::shared_ptr<XdmfGridCollection> XdmfPartitioner::partition(const boost::sh
globalNodeIds->setType(XdmfAttributeType::GlobalId());
globalNodeIds->setCenter(XdmfAttributeCenter::Node());
boost::shared_ptr<XdmfArray> globalNodeIdsVals = globalNodeIds->getArray();
boost::shared_ptr<XdmfArray> globalNodeIdsVals = globalNodeIds;
globalNodeIdsVals->resize<unsigned int>(currNodeMap.size());
for (std::map<unsigned int, unsigned int>::const_iterator iter = currNodeMap.begin(); iter != currNodeMap.end(); ++iter)
{
......@@ -265,16 +265,16 @@ boost::shared_ptr<XdmfGridCollection> XdmfPartitioner::partition(const boost::sh
}
}
gridToPartition->getGeometry()->getArray()->release();
gridToPartition->getTopology()->getArray()->release();
gridToPartition->getGeometry()->release();
gridToPartition->getTopology()->release();
// Split attributes into proper partitions
for(unsigned int i=0; i<gridToPartition->getNumberAttributes(); ++i)
{
boost::shared_ptr<XdmfAttribute> currAttribute = gridToPartition->getAttribute(i);
if(!currAttribute->getArray()->isInitialized())
if(!currAttribute->isInitialized())
{
currAttribute->getArray()->read();
currAttribute->read();
}
unsigned int partitionId = 0;
for(unsigned int j=0; j<numberOfPartitions; ++j)
......@@ -302,12 +302,12 @@ boost::shared_ptr<XdmfGridCollection> XdmfPartitioner::partition(const boost::sh
createdAttribute->setCenter(currAttribute->getCenter());
createdAttribute->setType(currAttribute->getType());
unsigned int index = 0;
unsigned int numValsPerComponent = currAttribute->getArray()->size() / gridToPartition->getTopology()->getNumberElements();
createdAttribute->getArray()->initialize(currAttribute->getArray()->getType());
createdAttribute->getArray()->resize<unsigned int>(currElemIds.size() * numValsPerComponent);
unsigned int numValsPerComponent = currAttribute->size() / gridToPartition->getTopology()->getNumberElements();
createdAttribute->initialize(currAttribute->getArrayType());
createdAttribute->resize<unsigned int>(currElemIds.size() * numValsPerComponent);
for(std::vector<unsigned int>::const_iterator iter = currElemIds.begin(); iter != currElemIds.end(); ++iter)
{
createdAttribute->getArray()->copyValues(index, currAttribute->getArray(), *iter * numValsPerComponent, numValsPerComponent);
createdAttribute->copyValues(index, currAttribute, *iter * numValsPerComponent, numValsPerComponent);
index += numValsPerComponent;
}
}
......@@ -317,11 +317,11 @@ boost::shared_ptr<XdmfGridCollection> XdmfPartitioner::partition(const boost::sh
createdAttribute->setName(currAttribute->getName());
createdAttribute->setCenter(currAttribute->getCenter());
createdAttribute->setType(currAttribute->getType());
createdAttribute->getArray()->initialize(currAttribute->getArray()->getType());
createdAttribute->getArray()->resize<unsigned int>(currNodeMap.size());
createdAttribute->initialize(currAttribute->getArrayType());
createdAttribute->resize<unsigned int>(currNodeMap.size());
for(std::map<unsigned int, unsigned int>::const_iterator iter = currNodeMap.begin(); iter != currNodeMap.end(); ++iter)
{
createdAttribute->getArray()->copyValues(iter->second, currAttribute->getArray(), iter->first, 1);
createdAttribute->copyValues(iter->second, currAttribute, iter->first, 1);
}
}
if(createdAttribute != NULL)
......@@ -329,20 +329,20 @@ boost::shared_ptr<XdmfGridCollection> XdmfPartitioner::partition(const boost::sh
partitioned->insert(createdAttribute);
if(heavyDataWriter)
{
createdAttribute->getArray()->accept(heavyDataWriter);
createdAttribute->getArray()->release();
createdAttribute->accept(heavyDataWriter);
createdAttribute->release();
}
}
}
}
currAttribute->getArray()->release();
currAttribute->release();