Commit cb10378a authored by Kenneth Leiter's avatar Kenneth Leiter

ENH: Add skeleton for XdmfTopologyConverter Util

parent 3d1e70fb
option(XDMF_BUILD_PARTITIONER OFF)
set(XdmfUtilsExectutables)
set(XdmfUtilsSources)
set(XdmfUtilsExecutables)
set(XdmfUtilsSources
XdmfTopologyConverter
)
set(XdmfUtilsLinkLibraries Xdmf)
if(XDMF_BUILD_PARTITIONER)
......@@ -9,7 +11,7 @@ if(XDMF_BUILD_PARTITIONER)
if(METIS_FOUND)
include_directories(${METIS_INCLUDE_DIR})
endif(METIS_FOUND)
set(XdmfUtilsExectutables ${XdmfUtilsExectutables} XdmfPartitioner)
set(XdmfUtilsExecutables ${XdmfUtilsExecutables} XdmfPartitioner)
set(XdmfUtilsSources ${XdmfUtilsSources} XdmfPartitioner)
set(XdmfUtilsLinkLibraries ${XdmfUtilsLinkLibraries} ${METIS_LIBRARIES})
endif(XDMF_BUILD_PARTITIONER)
......@@ -17,8 +19,8 @@ endif(XDMF_BUILD_PARTITIONER)
add_library(XdmfUtils ${XdmfUtilsSources})
target_link_libraries(XdmfUtils ${XdmfUtilsLinkLibraries})
foreach(executable ${XdmfUtilsExectutables})
foreach(executable ${XdmfUtilsExecutables})
add_executable(${executable} ${executable})
set_target_properties(${executable} PROPERTIES COMPILE_FLAGS -DBUILD_EXE)
target_link_libraries(${executable} XdmfUtils)
endforeach(executable ${XdmfUtilsExectutables})
endforeach(executable ${XdmfUtilsExecutables})
......@@ -56,7 +56,7 @@ XdmfPartitioner::~XdmfPartitioner()
{
}
boost::shared_ptr<XdmfGridCollection> XdmfPartitioner::partition(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)
{
int metisElementType;
......@@ -108,7 +108,7 @@ boost::shared_ptr<XdmfGridCollection> XdmfPartitioner::partition(boost::shared_p
std::map<idxtype, idxtype> xdmfIdToMetisId;
if(numNodesPerElement != topologyType->getNodesPerElement())
{
int index = 0;
unsigned int index = 0;
for (unsigned int i=0; i<numElements * numNodesPerElement; ++i)
{
std::map<idxtype, idxtype>::const_iterator val = xdmfIdToMetisId.find(metisConnectivity[i]);
......@@ -164,17 +164,17 @@ boost::shared_ptr<XdmfGridCollection> XdmfPartitioner::partition(boost::shared_p
if (globalToLocalNodeIdMap[partitionId].count(globalNodeId) == 0)
{
// Have not seen this node, need to add to map
int size = globalToLocalNodeIdMap[partitionId].size();
unsigned int size = globalToLocalNodeIdMap[partitionId].size();
globalToLocalNodeIdMap[partitionId][globalNodeId] = size;
}
totalIndex++;
}
globalElementIds[partitionId].push_back(i);
}
delete[] elementsPartition;
delete [] elementsPartition;
boost::shared_ptr<XdmfAttribute> globalNodeIds = gridToPartition->getAttribute("GlobalNodeId");
bool generateGlobalNodeIds = (globalNodeIds == NULL);
bool generateGlobalNodeIds = !globalNodeIds;
boost::shared_ptr<XdmfGridCollection> partitionedGrids = XdmfGridCollection::New();
partitionedGrids->setGridCollectionType(XdmfGridCollectionType::Spatial());
......@@ -203,7 +203,8 @@ boost::shared_ptr<XdmfGridCollection> XdmfPartitioner::partition(boost::shared_p
partitioned->getGeometry()->setGeometryType(gridToPartition->getGeometry()->getGeometryType());
boost::shared_ptr<XdmfArray> geometryVals = partitioned->getGeometry()->getArray();
unsigned int numDimensions = partitioned->getGeometry()->getGeometryType()->getDimensions();
geometryVals->reserve(currNodeMap.size() * numDimensions);
geometryVals->initialize(gridToPartition->getGeometry()->getArray()->getType());
geometryVals->resize<unsigned int>(currNodeMap.size() * numDimensions);
for(std::map<unsigned int, unsigned int>::const_iterator iter = currNodeMap.begin(); iter != currNodeMap.end(); ++iter)
{
......@@ -219,7 +220,8 @@ boost::shared_ptr<XdmfGridCollection> XdmfPartitioner::partition(boost::shared_p
// Fill in topology for this partition
partitioned->getTopology()->setTopologyType(gridToPartition->getTopology()->getTopologyType());
boost::shared_ptr<XdmfArray> topologyVals = partitioned->getTopology()->getArray();
topologyVals->reserve(currElemIds.size() * topologyType->getNodesPerElement());
topologyVals->initialize(gridToPartition->getTopology()->getArray()->getType());
topologyVals->resize<unsigned int>(currElemIds.size() * topologyType->getNodesPerElement());
unsigned int index = 0;
for(std::vector<unsigned int>::const_iterator iter = currElemIds.begin(); iter != currElemIds.end(); ++iter)
......@@ -247,7 +249,7 @@ boost::shared_ptr<XdmfGridCollection> XdmfPartitioner::partition(boost::shared_p
globalNodeIds->setAttributeCenter(XdmfAttributeCenter::Node());
boost::shared_ptr<XdmfArray> globalNodeIdsVals = globalNodeIds->getArray();
globalNodeIdsVals->reserve(currNodeMap.size());
globalNodeIdsVals->resize<unsigned int>(currNodeMap.size());
for (std::map<unsigned int, unsigned int>::const_iterator iter = currNodeMap.begin(); iter != currNodeMap.end(); ++iter)
{
globalNodeIdsVals->copyValues(iter->second, &iter->first, 1);
......
......@@ -19,6 +19,7 @@ class XdmfPartitioner : public XdmfObject {
public:
XdmfNewMacro(XdmfPartitioner);
virtual ~XdmfPartitioner();
/**
* Partitions an XdmfGrid using the metis library. Currently supported topology types are:
......@@ -41,17 +42,21 @@ public:
*
* @param gridToPartition an XdmfGrid to partition.
* @param numberOfPartitions the number of pieces to partition the grid into.
* @param heavyDataWriter an XdmfHDF5Writer to write the partitioned mesh to.
* @param heavyDataWriter an XdmfHDF5Writer to write the partitioned mesh to. If no heavyDataWriter is specified, all partitioned data will remain in memory.
*
* @return a spatial collection containing partitioned grids.
*/
boost::shared_ptr<XdmfGridCollection> partition(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);
protected:
XdmfPartitioner();
virtual ~XdmfPartitioner();
private:
XdmfPartitioner(const XdmfPartitioner & partitioner); // Not implemented.
void operator=(const XdmfPartitioner & partitioner); // Not implemented.
};
#endif /* XDMFPARTITIONER_HPP_ */
#include "XdmfTopologyConverter.hpp"
#include "XdmfGrid.hpp"
#include "XdmfTopologyType.hpp"
XdmfTopologyConverter::XdmfTopologyConverter()
{
}
XdmfTopologyConverter::~XdmfTopologyConverter()
{
}
boost::shared_ptr<XdmfGrid> XdmfTopologyConverter::convert(const boost::shared_ptr<const XdmfGrid> gridToConvert, const boost::shared_ptr<const XdmfTopologyType> topologyType) const
{
}
#ifndef XDMFTOPOLOGYCONVERTER_HPP_
#define XDMFTOPOLOGYCONVERTER_HPP_
// Forward Declarations
class XdmfGrid;
class XdmfTopologyType;
// Includes
#include "XdmfObject.hpp"
/*!
* @brief XdmfTopologyConverter converts an XdmfGrid to different topology types. XdmfAttributes and XdmfSets attached to the XdmfGrid
* are adjusted to remain valid for the new topology type.
*
* When converting from a lower order topology to a higher order topology type (e.g. Hexahedron to Hexahedron_64) additional points are added to the mesh, no additional elements are added.
* When converting from a higher order topology to a lower order topology type (e.h. Hexahedron_64 to Hexahedron) elements are tesselated to form the new topology, no additional points are added.
*
* Currently supported conversions:
* Hexahedron to Hexahedron_64
*/
class XdmfTopologyConverter : public XdmfObject {
public:
XdmfNewMacro(XdmfTopologyConverter);
virtual ~XdmfTopologyConverter();
/**
* Converts an XdmfGrid to a different topology type
*
* @param gridToConvert the XdmfGrid to convert to a different topology
* @param topologyType the XdmfTopologyType to convert to.
*
* @return the converted XdmfGrid.
*/
boost::shared_ptr<XdmfGrid> convert(const boost::shared_ptr<const XdmfGrid> gridToConvert, const boost::shared_ptr<const XdmfTopologyType> topologyType) const;
protected:
XdmfTopologyConverter();
private:
XdmfTopologyConverter(const XdmfTopologyConverter & converter); // Not implemented.
void operator=(const XdmfTopologyConverter & converter); // Not implemented.
};
#endif /* XDMFPARTITIONER_HPP_ */
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