Commit 9cf33fdc authored by Kenneth Leiter's avatar Kenneth Leiter
Browse files

ENH: Begin implementing XdmfTopologyConverter. Fix typo in XdmfArray that...

ENH: Begin implementing XdmfTopologyConverter.  Fix typo in XdmfArray that incorrectly initialized UInt32() type.
parent 305ffbca
...@@ -496,7 +496,7 @@ void XdmfArray::initialize(const boost::shared_ptr<const XdmfArrayType> arrayTyp ...@@ -496,7 +496,7 @@ void XdmfArray::initialize(const boost::shared_ptr<const XdmfArrayType> arrayTyp
{ {
this->initialize<unsigned short>(); this->initialize<unsigned short>();
} }
else if(arrayType == XdmfArrayType::Int32()) else if(arrayType == XdmfArrayType::UInt32())
{ {
this->initialize<unsigned int>(); this->initialize<unsigned int>();
} }
......
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
option(XDMF_BUILD_PARTITIONER OFF) option(XDMF_BUILD_PARTITIONER OFF)
set(XdmfUtilsExecutables) set(XdmfUtilsExecutables)
...@@ -24,3 +26,7 @@ foreach(executable ${XdmfUtilsExecutables}) ...@@ -24,3 +26,7 @@ foreach(executable ${XdmfUtilsExecutables})
set_target_properties(${executable} PROPERTIES COMPILE_FLAGS -DBUILD_EXE) set_target_properties(${executable} PROPERTIES COMPILE_FLAGS -DBUILD_EXE)
target_link_libraries(${executable} XdmfUtils) target_link_libraries(${executable} XdmfUtils)
endforeach(executable ${XdmfUtilsExecutables}) endforeach(executable ${XdmfUtilsExecutables})
if(XDMF_BUILD_TESTING)
add_subdirectory(tests)
endif(XDMF_BUILD_TESTING)
...@@ -23,8 +23,6 @@ ...@@ -23,8 +23,6 @@
/* */ /* */
/*******************************************************************/ /*******************************************************************/
#include "XdmfPartitioner.hpp"
#ifndef BUILD_EXE #ifndef BUILD_EXE
extern "C" extern "C"
...@@ -43,6 +41,7 @@ extern "C" ...@@ -43,6 +41,7 @@ extern "C"
#include "XdmfGridCollection.hpp" #include "XdmfGridCollection.hpp"
#include "XdmfGridCollectionType.hpp" #include "XdmfGridCollectionType.hpp"
#include "XdmfHDF5Writer.hpp" #include "XdmfHDF5Writer.hpp"
#include "XdmfPartitioner.hpp"
#include "XdmfSet.hpp" #include "XdmfSet.hpp"
#include "XdmfSetType.hpp" #include "XdmfSetType.hpp"
#include "XdmfTopology.hpp" #include "XdmfTopology.hpp"
...@@ -57,7 +56,7 @@ XdmfPartitioner::~XdmfPartitioner() ...@@ -57,7 +56,7 @@ XdmfPartitioner::~XdmfPartitioner()
} }
boost::shared_ptr<XdmfGridCollection> XdmfPartitioner::partition(const boost::shared_ptr<XdmfGrid> gridToPartition, const unsigned int numberOfPartitions, boost::shared_ptr<XdmfGridCollection> XdmfPartitioner::partition(const boost::shared_ptr<XdmfGrid> gridToPartition, const unsigned int numberOfPartitions,
boost::shared_ptr<XdmfHDF5Writer> heavyDataWriter) boost::shared_ptr<XdmfHDF5Writer> heavyDataWriter) const
{ {
int metisElementType; int metisElementType;
int numNodesPerElement; int numNodesPerElement;
...@@ -303,7 +302,8 @@ boost::shared_ptr<XdmfGridCollection> XdmfPartitioner::partition(const boost::sh ...@@ -303,7 +302,8 @@ boost::shared_ptr<XdmfGridCollection> XdmfPartitioner::partition(const boost::sh
createdAttribute->setAttributeType(currAttribute->getAttributeType()); createdAttribute->setAttributeType(currAttribute->getAttributeType());
unsigned int index = 0; unsigned int index = 0;
unsigned int numValsPerComponent = currAttribute->getArray()->getSize() / gridToPartition->getTopology()->getNumberElements(); unsigned int numValsPerComponent = currAttribute->getArray()->getSize() / gridToPartition->getTopology()->getNumberElements();
createdAttribute->getArray()->reserve(currElemIds.size() * numValsPerComponent); createdAttribute->getArray()->initialize(currAttribute->getArray()->getType());
createdAttribute->getArray()->resize<unsigned int>(currElemIds.size() * numValsPerComponent);
for(std::vector<unsigned int>::const_iterator iter = currElemIds.begin(); iter != currElemIds.end(); ++iter) for(std::vector<unsigned int>::const_iterator iter = currElemIds.begin(); iter != currElemIds.end(); ++iter)
{ {
createdAttribute->getArray()->copyValues(index, currAttribute->getArray(), *iter * numValsPerComponent, numValsPerComponent); createdAttribute->getArray()->copyValues(index, currAttribute->getArray(), *iter * numValsPerComponent, numValsPerComponent);
...@@ -316,7 +316,8 @@ boost::shared_ptr<XdmfGridCollection> XdmfPartitioner::partition(const boost::sh ...@@ -316,7 +316,8 @@ boost::shared_ptr<XdmfGridCollection> XdmfPartitioner::partition(const boost::sh
createdAttribute->setName(currAttribute->getName()); createdAttribute->setName(currAttribute->getName());
createdAttribute->setAttributeCenter(currAttribute->getAttributeCenter()); createdAttribute->setAttributeCenter(currAttribute->getAttributeCenter());
createdAttribute->setAttributeType(currAttribute->getAttributeType()); createdAttribute->setAttributeType(currAttribute->getAttributeType());
createdAttribute->getArray()->reserve(currNodeMap.size()); createdAttribute->getArray()->initialize(currAttribute->getArray()->getType());
createdAttribute->getArray()->resize<unsigned int>(currNodeMap.size());
for(std::map<unsigned int, unsigned int>::const_iterator iter = currNodeMap.begin(); iter != currNodeMap.end(); ++iter) 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->getArray()->copyValues(iter->second, currAttribute->getArray(), iter->first, 1);
...@@ -403,6 +404,7 @@ boost::shared_ptr<XdmfGridCollection> XdmfPartitioner::partition(const boost::sh ...@@ -403,6 +404,7 @@ boost::shared_ptr<XdmfGridCollection> XdmfPartitioner::partition(const boost::sh
#include "XdmfDomain.hpp" #include "XdmfDomain.hpp"
#include "XdmfGridCollection.hpp" #include "XdmfGridCollection.hpp"
#include "XdmfHDF5Writer.hpp" #include "XdmfHDF5Writer.hpp"
#include "XdmfPartitioner.hpp"
#include "XdmfReader.hpp" #include "XdmfReader.hpp"
#include "XdmfWriter.hpp" #include "XdmfWriter.hpp"
...@@ -417,7 +419,6 @@ boost::shared_ptr<XdmfGridCollection> XdmfPartitioner::partition(const boost::sh ...@@ -417,7 +419,6 @@ boost::shared_ptr<XdmfGridCollection> XdmfPartitioner::partition(const boost::sh
*/ */
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
std::string usage = "Partitions an Xdmf grid using the metis library: \n \n Usage: \n \n XdmfPartitioner <path-of-file-to-partition> <num-partitions> (Optional: <path-to-output-file>)"; std::string usage = "Partitions an Xdmf grid using the metis library: \n \n Usage: \n \n XdmfPartitioner <path-of-file-to-partition> <num-partitions> (Optional: <path-to-output-file>)";
std::string meshName = ""; std::string meshName = "";
......
...@@ -38,7 +38,7 @@ public: ...@@ -38,7 +38,7 @@ public:
* *
* The partitioner splits the XdmfGrid and all attached XdmfAttributes and XdmfSets into their proper partition. * The partitioner splits the XdmfGrid and all attached XdmfAttributes and XdmfSets into their proper partition.
* An XdmfAttribute named "GlobalNodeId" is added to each partitioned grid to map partitioned node ids to their * An XdmfAttribute named "GlobalNodeId" is added to each partitioned grid to map partitioned node ids to their
* original unpartitioned id. This could allow grids to be recombined. * original unpartitioned id. All arrays attached to the passed gridToPartition are read from disk if not initialized.
* *
* @param gridToPartition an XdmfGrid to partition. * @param gridToPartition an XdmfGrid to partition.
* @param numberOfPartitions the number of pieces to partition the grid into. * @param numberOfPartitions the number of pieces to partition the grid into.
...@@ -47,7 +47,7 @@ public: ...@@ -47,7 +47,7 @@ public:
* @return a spatial collection containing partitioned grids. * @return a spatial collection containing partitioned grids.
*/ */
boost::shared_ptr<XdmfGridCollection> partition(const boost::shared_ptr<XdmfGrid> gridToPartition, const unsigned int numberOfPartitions, boost::shared_ptr<XdmfGridCollection> partition(const boost::shared_ptr<XdmfGrid> gridToPartition, const unsigned int numberOfPartitions,
boost::shared_ptr<XdmfHDF5Writer> heavyDataWriter); boost::shared_ptr<XdmfHDF5Writer> heavyDataWriter) const;
protected: protected:
......
#include "XdmfTopologyConverter.hpp"
#include <math.h>
#include "XdmfArray.hpp"
#include "XdmfGeometry.hpp"
#include "XdmfGeometryType.hpp"
#include "XdmfGrid.hpp" #include "XdmfGrid.hpp"
#include "XdmfTopology.hpp"
#include "XdmfTopologyConverter.hpp"
#include "XdmfTopologyType.hpp" #include "XdmfTopologyType.hpp"
XdmfTopologyConverter::XdmfTopologyConverter() XdmfTopologyConverter::XdmfTopologyConverter()
...@@ -11,8 +16,327 @@ XdmfTopologyConverter::~XdmfTopologyConverter() ...@@ -11,8 +16,327 @@ XdmfTopologyConverter::~XdmfTopologyConverter()
{ {
} }
boost::shared_ptr<XdmfGrid> XdmfTopologyConverter::convert(const boost::shared_ptr<const XdmfGrid> gridToConvert, const boost::shared_ptr<const XdmfTopologyType> topologyType) const struct XdmfTopologyConverter::PointComparison {
bool operator()(const std::vector<double> & point1, const std::vector<double> & point2) const
{
double epsilon = 1e-6;
for(unsigned int i=0; i<3; ++i)
{
if(fabs(point1[i] - point2[i]) > epsilon)
{
return point1[i] < point2[i];
}
}
return false;
}
};
class XdmfTopologyConverter::HexahedronToHexahedron64 {
public:
HexahedronToHexahedron64()
{
}
inline void computeInteriorPoints(std::vector<double> & leftPoint, std::vector<double> & rightPoint, std::vector<double> & point1, std::vector<double> & point2) const
{
leftPoint[0] = (1.0/3.0)*(point2[0] + 2*point1[0]);
leftPoint[1] = (1.0/3.0)*(point2[1] + 2*point1[1]);
leftPoint[2] = (1.0/3.0)*(point2[2] + 2*point1[2]);
rightPoint[0] = (1.0/3.0)*(2*point2[0] + point1[0]);
rightPoint[1] = (1.0/3.0)*(2*point2[1] + point1[1]);
rightPoint[2] = (1.0/3.0)*(2*point2[2] + point1[2]);
}
inline void computeLeftPoint(std::vector<double> & leftPoint, std::vector<double> & point1, std::vector<double> & point2) const
{
leftPoint[0] = (1.0/3.0)*(point2[0] + 2*point1[0]);
leftPoint[1] = (1.0/3.0)*(point2[1] + 2*point1[1]);
leftPoint[2] = (1.0/3.0)*(point2[2] + 2*point1[2]);
}
inline void computeRightPoint(std::vector<double> & rightPoint, std::vector<double> & point1, std::vector<double> & point2) const
{
rightPoint[0] = (1.0/3.0)*(2*point2[0] + point1[0]);
rightPoint[1] = (1.0/3.0)*(2*point2[1] + point1[1]);
rightPoint[2] = (1.0/3.0)*(2*point2[2] + point1[2]);
}
inline void insertPointWithoutCheck(std::vector<double> & newPoint, std::map<std::vector<double>, unsigned int, PointComparison> & coordToIdMap, const boost::shared_ptr<XdmfArray> newConnectivity, const boost::shared_ptr<XdmfArray> newPoints) const
{
unsigned int newId = newPoints->getSize() / 3;
newConnectivity->pushBack(newId);
newPoints->pushBack(newPoint[0]);
newPoints->pushBack(newPoint[1]);
newPoints->pushBack(newPoint[2]);
}
inline void insertPointWithCheck(std::vector<double> & newPoint, std::map<std::vector<double>, unsigned int, PointComparison> & coordToIdMap, const boost::shared_ptr<XdmfArray> newConnectivity, const boost::shared_ptr<XdmfArray> newPoints) const
{
std::map<std::vector<double>, unsigned int>::const_iterator iter = coordToIdMap.find(newPoint);
if(iter == coordToIdMap.end())
{
// Not inserted before
unsigned int newId = newPoints->getSize() / 3;
coordToIdMap[newPoint] = newId;
insertPointWithoutCheck(newPoint, coordToIdMap, newConnectivity, newPoints);
}
else
{
newConnectivity->pushBack(iter->second);
}
}
boost::shared_ptr<XdmfGrid> convert(const boost::shared_ptr<XdmfGrid> gridToConvert) const
{
boost::shared_ptr<XdmfGrid> toReturn = XdmfGrid::New();
toReturn->setName(gridToConvert->getName());
toReturn->getGeometry()->setGeometryType(gridToConvert->getGeometry()->getGeometryType());
toReturn->getTopology()->setTopologyType(XdmfTopologyType::Hexahedron_64());
boost::shared_ptr<XdmfArray> newPoints = toReturn->getGeometry()->getArray();
newPoints->initialize(gridToConvert->getGeometry()->getArray()->getType());
newPoints->resize(gridToConvert->getGeometry()->getArray()->getSize(), 0);
// Copy all geometry values from old grid into new grid because we are keeping all old points.
newPoints->copyValues(0, gridToConvert->getGeometry()->getArray(), 0, gridToConvert->getGeometry()->getArray()->getSize());
boost::shared_ptr<XdmfArray> newConnectivity = toReturn->getTopology()->getArray();
newConnectivity->initialize(gridToConvert->getTopology()->getArray()->getType());
newConnectivity->reserve(64 * gridToConvert->getTopology()->getNumberElements());
std::vector<double> leftPoint(3);
std::vector<double> rightPoint(3);
std::map<std::vector<double>, unsigned int, PointComparison> coordToIdMap;
for(unsigned int i=0; i<gridToConvert->getTopology()->getNumberElements(); ++i)
{
// Fill localNodes with original coordinate information.
std::vector<std::vector<double> > localNodes(8, std::vector<double>(3));
localNodes.reserve(44);
for(int j=0; j<8; ++j)
{
gridToConvert->getGeometry()->getArray()->getValuesCopy((8 * i + j) * 3, &localNodes[j][0], 3);
}
// Add old connectivity information to newConnectivity.
newConnectivity->resize(newConnectivity->getSize() + 8, 0);
newConnectivity->copyValues(64*i, gridToConvert->getTopology()->getArray(), 8*i, 8);
// Case 0
this->computeInteriorPoints(leftPoint, rightPoint, localNodes[0], localNodes[1]);
localNodes.push_back(leftPoint);
localNodes.push_back(rightPoint);
this->insertPointWithCheck(leftPoint, coordToIdMap, newConnectivity, newPoints);
this->insertPointWithCheck(rightPoint, coordToIdMap, newConnectivity, newPoints);
// Case 1
this->computeInteriorPoints(leftPoint, rightPoint, localNodes[1], localNodes[2]);
localNodes.push_back(leftPoint);
localNodes.push_back(rightPoint);
this->insertPointWithCheck(leftPoint, coordToIdMap, newConnectivity, newPoints);
this->insertPointWithCheck(rightPoint, coordToIdMap, newConnectivity, newPoints);
// Case 2
this->computeInteriorPoints(leftPoint, rightPoint, localNodes[2], localNodes[3]);
localNodes.push_back(leftPoint);
localNodes.push_back(rightPoint);
this->insertPointWithCheck(leftPoint, coordToIdMap, newConnectivity, newPoints);
this->insertPointWithCheck(rightPoint, coordToIdMap, newConnectivity, newPoints);
// Case 3
this->computeInteriorPoints(leftPoint, rightPoint, localNodes[3], localNodes[0]);
localNodes.push_back(leftPoint);
localNodes.push_back(rightPoint);
this->insertPointWithCheck(leftPoint, coordToIdMap, newConnectivity, newPoints);
this->insertPointWithCheck(rightPoint, coordToIdMap, newConnectivity, newPoints);
// Case 4
this->computeInteriorPoints(leftPoint, rightPoint, localNodes[4], localNodes[5]);
localNodes.push_back(leftPoint);
localNodes.push_back(rightPoint);
this->insertPointWithCheck(leftPoint, coordToIdMap, newConnectivity, newPoints);
this->insertPointWithCheck(rightPoint, coordToIdMap, newConnectivity, newPoints);
// Case 5
this->computeInteriorPoints(leftPoint, rightPoint, localNodes[5], localNodes[6]);
localNodes.push_back(leftPoint);
localNodes.push_back(rightPoint);
this->insertPointWithCheck(leftPoint, coordToIdMap, newConnectivity, newPoints);
this->insertPointWithCheck(rightPoint, coordToIdMap, newConnectivity, newPoints);
// Case 6
this->computeInteriorPoints(leftPoint, rightPoint, localNodes[6], localNodes[7]);
localNodes.push_back(leftPoint);
localNodes.push_back(rightPoint);
this->insertPointWithCheck(leftPoint, coordToIdMap, newConnectivity, newPoints);
this->insertPointWithCheck(rightPoint, coordToIdMap, newConnectivity, newPoints);
// Case 7
this->computeInteriorPoints(leftPoint, rightPoint, localNodes[7], localNodes[4]);
localNodes.push_back(leftPoint);
localNodes.push_back(rightPoint);
this->insertPointWithCheck(leftPoint, coordToIdMap, newConnectivity, newPoints);
this->insertPointWithCheck(rightPoint, coordToIdMap, newConnectivity, newPoints);
// Case 8
computeLeftPoint(leftPoint, localNodes[0], localNodes[4]);
localNodes.push_back(leftPoint);
insertPointWithCheck(leftPoint, coordToIdMap, newConnectivity, newPoints);
// Case 9
this->computeLeftPoint(leftPoint, localNodes[1], localNodes[5]);
localNodes.push_back(leftPoint);
this->insertPointWithCheck(leftPoint, coordToIdMap, newConnectivity, newPoints);
// Case 10
this->computeLeftPoint(leftPoint, localNodes[2], localNodes[6]);
localNodes.push_back(leftPoint);
this->insertPointWithCheck(leftPoint, coordToIdMap, newConnectivity, newPoints);
// Case 11
this->computeLeftPoint(leftPoint, localNodes[3], localNodes[7]);
localNodes.push_back(leftPoint);
this->insertPointWithCheck(leftPoint, coordToIdMap, newConnectivity, newPoints);
// Case 12
this->computeRightPoint(leftPoint, localNodes[0], localNodes[4]);
localNodes.push_back(leftPoint);
this->insertPointWithCheck(leftPoint, coordToIdMap, newConnectivity, newPoints);
// Case 13
this->computeRightPoint(leftPoint, localNodes[1], localNodes[5]);
localNodes.push_back(leftPoint);
this->insertPointWithCheck(leftPoint, coordToIdMap, newConnectivity, newPoints);
// Case 14
this->computeRightPoint(leftPoint, localNodes[2], localNodes[6]);
localNodes.push_back(leftPoint);
this->insertPointWithCheck(leftPoint, coordToIdMap, newConnectivity, newPoints);
// Case 15
this->computeRightPoint(leftPoint, localNodes[3], localNodes[7]);
localNodes.push_back(leftPoint);
this->insertPointWithCheck(leftPoint, coordToIdMap, newConnectivity, newPoints);
// Case 16
this->computeInteriorPoints(leftPoint, rightPoint, localNodes[27], localNodes[24]);
localNodes.push_back(leftPoint);
localNodes.push_back(rightPoint);
this->insertPointWithCheck(leftPoint, coordToIdMap, newConnectivity, newPoints);
this->insertPointWithCheck(rightPoint, coordToIdMap, newConnectivity, newPoints);
// Case 17
this->computeInteriorPoints(leftPoint, rightPoint, localNodes[25], localNodes[26]);
localNodes.push_back(leftPoint);
localNodes.push_back(rightPoint);
this->insertPointWithCheck(leftPoint, coordToIdMap, newConnectivity, newPoints);
this->insertPointWithCheck(rightPoint, coordToIdMap, newConnectivity, newPoints);
// Case 18
this->computeInteriorPoints(leftPoint, rightPoint, localNodes[24], localNodes[25]);
localNodes.push_back(leftPoint);
localNodes.push_back(rightPoint);
this->insertPointWithCheck(leftPoint, coordToIdMap, newConnectivity, newPoints);
this->insertPointWithCheck(rightPoint, coordToIdMap, newConnectivity, newPoints);
// Case 19
this->computeInteriorPoints(leftPoint, rightPoint, localNodes[26], localNodes[27]);
localNodes.push_back(leftPoint);
localNodes.push_back(rightPoint);
this->insertPointWithCheck(leftPoint, coordToIdMap, newConnectivity, newPoints);
this->insertPointWithCheck(rightPoint, coordToIdMap, newConnectivity, newPoints);
// Case 20
this->computeInteriorPoints(leftPoint, rightPoint, localNodes[31], localNodes[28]);
localNodes.push_back(leftPoint);
localNodes.push_back(rightPoint);
this->insertPointWithCheck(leftPoint, coordToIdMap, newConnectivity, newPoints);
this->insertPointWithCheck(rightPoint, coordToIdMap, newConnectivity, newPoints);
// Case 21
this->computeInteriorPoints(leftPoint, rightPoint, localNodes[29], localNodes[30]);
localNodes.push_back(leftPoint);
localNodes.push_back(rightPoint);
this->insertPointWithCheck(leftPoint, coordToIdMap, newConnectivity, newPoints);
this->insertPointWithCheck(rightPoint, coordToIdMap, newConnectivity, newPoints);
// Case 22
this->computeInteriorPoints(leftPoint, rightPoint, localNodes[28], localNodes[29]);
this->insertPointWithCheck(leftPoint, coordToIdMap, newConnectivity, newPoints);
this->insertPointWithCheck(rightPoint, coordToIdMap, newConnectivity, newPoints);
// Case 23
this->computeInteriorPoints(leftPoint, rightPoint, localNodes[30], localNodes[31]);
this->insertPointWithCheck(leftPoint, coordToIdMap, newConnectivity, newPoints);
this->insertPointWithCheck(rightPoint, coordToIdMap, newConnectivity, newPoints);
// Case 24
this->computeInteriorPoints(leftPoint, rightPoint, localNodes[15], localNodes[10]);
this->insertPointWithCheck(leftPoint, coordToIdMap, newConnectivity, newPoints);
this->insertPointWithCheck(rightPoint, coordToIdMap, newConnectivity, newPoints);
// Case 25
this->computeInteriorPoints(leftPoint, rightPoint, localNodes[11], localNodes[14]);
this->insertPointWithCheck(leftPoint, coordToIdMap, newConnectivity, newPoints);
this->insertPointWithCheck(rightPoint, coordToIdMap, newConnectivity, newPoints);
// Case 26
this->computeInteriorPoints(leftPoint, rightPoint, localNodes[23], localNodes[18]);
this->insertPointWithCheck(leftPoint, coordToIdMap, newConnectivity, newPoints);
this->insertPointWithCheck(rightPoint, coordToIdMap, newConnectivity, newPoints);
// Case 27
this->computeInteriorPoints(leftPoint, rightPoint, localNodes[19], localNodes[22]);
this->insertPointWithCheck(leftPoint, coordToIdMap, newConnectivity, newPoints);
this->insertPointWithCheck(rightPoint, coordToIdMap, newConnectivity, newPoints);
// Case 28
this->computeInteriorPoints(leftPoint, rightPoint, localNodes[33], localNodes[34]);
this->insertPointWithoutCheck(leftPoint, coordToIdMap, newConnectivity, newPoints);
this->insertPointWithoutCheck(rightPoint, coordToIdMap, newConnectivity, newPoints);
// Case 29
this->computeInteriorPoints(leftPoint, rightPoint, localNodes[35], localNodes[32]);
this->insertPointWithoutCheck(leftPoint, coordToIdMap, newConnectivity, newPoints);
this->insertPointWithoutCheck(rightPoint, coordToIdMap, newConnectivity, newPoints);
// Case 30
this->computeInteriorPoints(leftPoint, rightPoint, localNodes[41], localNodes[42]);
this->insertPointWithoutCheck(leftPoint, coordToIdMap, newConnectivity, newPoints);
this->insertPointWithoutCheck(rightPoint, coordToIdMap, newConnectivity, newPoints);
// Case 31
this->computeInteriorPoints(leftPoint, rightPoint, localNodes[43], localNodes[40]);
this->insertPointWithoutCheck(leftPoint, coordToIdMap, newConnectivity, newPoints);
this->insertPointWithoutCheck(rightPoint, coordToIdMap, newConnectivity, newPoints);
}
return toReturn;
}
};
boost::shared_ptr<XdmfGrid> XdmfTopologyConverter::convert(const boost::shared_ptr<XdmfGrid> gridToConvert, const boost::shared_ptr<const XdmfTopologyType> topologyType) const
{ {
boost::shared_ptr<const XdmfTopologyType> topologyTypeToConvert = gridToConvert->getTopology()->getTopologyType();
if(topologyTypeToConvert == topologyType)
{
// No conversion necessary
return gridToConvert;
}
} if(gridToConvert->getGeometry()->getGeometryType() != XdmfGeometryType::XYZ())
{
assert(false);
}
if(topologyTypeToConvert == XdmfTopologyType::Hexahedron())
{
if(topologyType == XdmfTopologyType::Hexahedron_64())
{
HexahedronToHexahedron64 converter;
return converter.convert(gridToConvert);
}
}
assert(false);
}
...@@ -33,7 +33,7 @@ public: ...@@ -33,7 +33,7 @@ public:
* *
* @return the converted XdmfGrid. * @return the converted XdmfGrid.
*/ */
boost::shared_ptr<XdmfGrid> convert(const boost::shared_ptr<const XdmfGrid> gridToConvert, const boost::shared_ptr<const XdmfTopologyType> topologyType) const; boost::shared_ptr<XdmfGrid> convert(const boost::shared_ptr<XdmfGrid> gridToConvert, const boost::shared_ptr<const XdmfTopologyType> topologyType) const;
protected: protected:
...@@ -43,6 +43,12 @@ private: ...@@ -43,6 +43,12 @@ private:
XdmfTopologyConverter(const XdmfTopologyConverter & converter); // Not implemented. XdmfTopologyConverter(const XdmfTopologyConverter & converter); // Not implemented.
void operator=(const XdmfTopologyConverter & converter); // Not implemented. void operator=(const XdmfTopologyConverter & converter); // Not implemented.
// Specific Topology Converters
class HexahedronToHexahedron64;
// Point comparator
class PointComparison;
}; };
#endif /* XDMFPARTITIONER_HPP_ */ #endif /* XDMFPARTITIONER_HPP_ */
add_subdirectory(Cxx)
set(XdmfUtilsCxxTests
TestXdmfTopologyConverter
)
foreach(test ${XdmfUtilsCxxTests})
add_executable(${test} ${test})
target_link_libraries(${test} XdmfUtils)
add_test(${test} ${test})
endforeach(test ${XdmfUtilsCxxTests})
#include <math.h>
#include "XdmfArray.hpp"
#include "XdmfGeometry.hpp"
#include "XdmfGeometryType.hpp"
#include "XdmfGrid.hpp"
#include "XdmfTopology.hpp"
#include "XdmfTopologyConverter.hpp"
#include "XdmfTopologyType.hpp"
#include "XdmfArrayType.hpp"
#include "XdmfWriter.hpp"
int main(int argc, char* argv[])
{
const double epsilon = 1e-6;
boost::shared_ptr<XdmfTopologyConverter> converter = XdmfTopologyConverter::New();
// Create Hexahedron Grid
boost::shared_ptr<XdmfGrid> hexGrid = XdmfGrid::New();
double hexPoints[24] = {0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1};
hexGrid->getGeometry()->setGeometryType(XdmfGeometryType::XYZ());
hexGrid->getGeometry()->getArray()->resize<double>(24, 0);
hexGrid->getGeometry()->getArray()->copyValues(0, hexPoints, 24);
unsigned int hexConn[8] = {0, 1, 2, 3, 4, 5, 6, 7};
hexGrid->getTopology()->setTopologyType(XdmfTopologyType::Hexahedron());
hexGrid->getTopology()->getArray()->resize<unsigned int>(8, 0);
hexGrid->getTopology()->getArray()->copyValues(0, hexConn, 8);
/*
* Hexahedron to Hexahedron_64
*/
boost::shared_ptr<XdmfGrid> hex64Grid = converter->convert(hexGrid, XdmfTopologyType::Hexahedron_64());
boost::shared_ptr<XdmfWriter> writer = XdmfWriter::New("hex64.xmf");
hex64Grid->accept(writer);
assert(hex64Grid->getGeometry()->getGeometryType() == XdmfGeometryType::XYZ());
assert(hex64Grid->getGeometry()->getNumberPoints() == 64);
double expectedPoints[192] = {0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0.333333333333333, 0, 0, 0.666666666666667, 0, 0, 1, 0.333333333333333,
0, 1, 0.666666666666667, 0, 0.666666666666667, 1, 0, 0.333333333333333, 1, 0, 0, 0.666666666666667, 0, 0, 0.333333333333333, 0,
0.333333333333333, 0,