Commit db5298c9 authored by Kenneth Leiter's avatar Kenneth Leiter

ENH: Add XdmfExodusReader for reading ExodusII files into Xdmf. Add ability...

ENH: Add XdmfExodusReader for reading ExodusII files into Xdmf.  Add ability for XdmfArray::initialize() to take a size value to initialize the array to.
parent 732cc4b3
#
# Find the Exodus finite element data model library from Sandia
#
# EXODUS_FOUND - System has Exodus
# EXODUS_INCLUDE_DIR - The LibXml2 include directory
# EXODUS_LIBRARIES - The libraries needed to use LibXml2
FIND_PACKAGE(NetCDF REQUIRED)
FIND_PATH(EXODUS_INCLUDE_DIR NAMES exodusII.h)
FIND_LIBRARY(EXODUS_LIBRARIES NAMES exodusii exodusIIv2c)
INCLUDE(FindPackageHandleStandardArgs)
# handle the QUIETLY and REQUIRED arguments and set EXODUS_FOUND to TRUE if
# all listed variables are TRUE
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Exodus DEFAULT_MSG EXODUS_LIBRARIES EXODUS_INCLUDE_DIR)
MARK_AS_ADVANCED(EXODUS_INCLUDE_DIR EXODUS_LIBRARIES)
#
# Find NetCDF include directories and libraries
#
# NetCDF_FOUND - System has NetCDF
# NetCDF_INCLUDE_DIR - The NetCDF include directory
# NetCDF_LIBRARIES - The libraries needed to use NetCDF
FIND_PATH(NetCDF_INCLUDE_DIR netcdf.h)
FIND_LIBRARY(NetCDF_LIBRARIES
NAMES netcdf
${NetCDF_PREFIX}
${NetCDF_PREFIX}/lib64
${NetCDF_PREFIX}/lib
/usr/local/lib64
/usr/lib64
/usr/lib64/netcdf-3
/usr/local/lib
/usr/lib
/usr/lib/netcdf-3
)
INCLUDE(FindPackageHandleStandardArgs)
# handle the QUIETLY and REQUIRED arguments and set EXODUS_FOUND to TRUE if
# all listed variables are TRUE
FIND_PACKAGE_HANDLE_STANDARD_ARGS(NetCDF DEFAULT_MSG NetCDF_INCLUDE_DIR NetCDF_LIBRARIES)
MARK_AS_ADVANCED(NetCDF_INCLUDE_DIR NetCDF_LIBRARIES)
......@@ -95,6 +95,12 @@ boost::shared_ptr<const XdmfTopologyType> XdmfTopologyType::Quadrilateral_8()
return p;
}
boost::shared_ptr<const XdmfTopologyType> XdmfTopologyType::Quadrilateral_9()
{
static boost::shared_ptr<const XdmfTopologyType> p(new XdmfTopologyType(9, "Quadrilateral_9", Quadratic));
return p;
}
boost::shared_ptr<const XdmfTopologyType> XdmfTopologyType::Tetrahedron_10()
{
static boost::shared_ptr<const XdmfTopologyType> p(new XdmfTopologyType(10, "Tetrahedron_10", Quadratic));
......@@ -113,6 +119,12 @@ boost::shared_ptr<const XdmfTopologyType> XdmfTopologyType::Wedge_15()
return p;
}
boost::shared_ptr<const XdmfTopologyType> XdmfTopologyType::Wedge_18()
{
static boost::shared_ptr<const XdmfTopologyType> p(new XdmfTopologyType(18, "Wedge_18", Quadratic));
return p;
}
boost::shared_ptr<const XdmfTopologyType> XdmfTopologyType::Hexahedron_20()
{
static boost::shared_ptr<const XdmfTopologyType> p(new XdmfTopologyType(20, "Hexahedron_20", Quadratic));
......
......@@ -23,6 +23,7 @@
* Edge_3
* Triangle_6
* Quadrilateral_8
* Quadrilateral_9
* Tetrahedron_10
* Pyramid_13
* Wedge_15
......@@ -37,7 +38,7 @@
* TwoDCoRectMesh
* ThreeDSMesh
* ThreeDRectMesh
* ThreeDCoRectMesh
* ThreeDCoRectMesh
*/
class XdmfTopologyType : public XdmfItemProperty {
......@@ -65,9 +66,11 @@ public:
static boost::shared_ptr<const XdmfTopologyType> Edge_3();
static boost::shared_ptr<const XdmfTopologyType> Triangle_6();
static boost::shared_ptr<const XdmfTopologyType> Quadrilateral_8();
static boost::shared_ptr<const XdmfTopologyType> Quadrilateral_9();
static boost::shared_ptr<const XdmfTopologyType> Tetrahedron_10();
static boost::shared_ptr<const XdmfTopologyType> Pyramid_13();
static boost::shared_ptr<const XdmfTopologyType> Wedge_15();
static boost::shared_ptr<const XdmfTopologyType> Wedge_18();
static boost::shared_ptr<const XdmfTopologyType> Hexahedron_20();
static boost::shared_ptr<const XdmfTopologyType> Hexahedron_24();
static boost::shared_ptr<const XdmfTopologyType> Hexahedron_27();
......
......@@ -471,43 +471,43 @@ std::string XdmfArray::getValuesString() const
return "";
}
void XdmfArray::initialize(const boost::shared_ptr<const XdmfArrayType> arrayType)
void XdmfArray::initialize(const boost::shared_ptr<const XdmfArrayType> arrayType, const unsigned int size)
{
if(arrayType == XdmfArrayType::Int8())
{
this->initialize<char>();
this->initialize<char>(size);
}
else if(arrayType == XdmfArrayType::Int16())
{
this->initialize<short>();
this->initialize<short>(size);
}
else if(arrayType == XdmfArrayType::Int32())
{
this->initialize<int>();
this->initialize<int>(size);
}
else if(arrayType == XdmfArrayType::Int64())
{
this->initialize<long>();
this->initialize<long>(size);
}
else if(arrayType == XdmfArrayType::Float32())
{
this->initialize<float>();
this->initialize<float>(size);
}
else if(arrayType == XdmfArrayType::Float64())
{
this->initialize<double>();
this->initialize<double>(size);
}
else if(arrayType == XdmfArrayType::UInt8())
{
this->initialize<unsigned char>();
this->initialize<unsigned char>(size);
}
else if(arrayType == XdmfArrayType::UInt16())
{
this->initialize<unsigned short>();
this->initialize<unsigned short>(size);
}
else if(arrayType == XdmfArrayType::UInt32())
{
this->initialize<unsigned int>();
this->initialize<unsigned int>(size);
}
else if(arrayType == XdmfArrayType::Uninitialized())
{
......
......@@ -187,15 +187,19 @@ public:
/**
* Initializes the array to contain an empty container of a particular type.
*
* @param size the number of values in the initialized array.
* @return a smart pointer to the internal vector of values initialized in this array.
*/
template <typename T>
boost::shared_ptr<std::vector<T> > initialize();
boost::shared_ptr<std::vector<T> > initialize(const unsigned int size = 0);
/**
* Initializes the array to contain an empty container of a particular XdmfArrayType.
*
* @param arrayType the type of array to initialize.
* @param size the number of values in the initialized array.
*/
void initialize(const boost::shared_ptr<const XdmfArrayType> arrayType);
void initialize(const boost::shared_ptr<const XdmfArrayType> arrayType, const unsigned int size = 0);
/**
* Returns whether the array is initialized (contains values in memory).
......
......@@ -198,14 +198,14 @@ void XdmfArray::getValuesCopy(const unsigned int startIndex, T * const valuesPoi
}
template <typename T>
boost::shared_ptr<std::vector<T> > XdmfArray::initialize()
boost::shared_ptr<std::vector<T> > XdmfArray::initialize(const unsigned int size)
{
if(mHaveArrayPointer)
{
releaseArrayPointer();
}
// Set type of variant to type of pointer
boost::shared_ptr<std::vector<T> > newArray(new std::vector<T>());
boost::shared_ptr<std::vector<T> > newArray(new std::vector<T>(size));
if(mTmpReserveSize > 0)
{
newArray->reserve(mTmpReserveSize);
......
......@@ -49,8 +49,7 @@ void XdmfHDF5Controller::read(XdmfArray * const array)
hssize_t numVals = H5Sget_simple_extent_npoints(dataspace);
hid_t datatype = H5Dget_type(dataset);
array->initialize(mType);
array->resize(numVals, 0);
array->initialize(mType, numVals);
H5Dread(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT, array->getValuesPointer());
herr_t status;
......
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
option(XDMF_BUILD_EXODUS_IO OFF)
option(XDMF_BUILD_PARTITIONER OFF)
set(XdmfUtilsExecutables)
......@@ -8,6 +9,15 @@ set(XdmfUtilsSources
)
set(XdmfUtilsLinkLibraries Xdmf)
if(XDMF_BUILD_EXODUS_IO)
find_package(Exodus REQUIRED)
if(EXODUS_FOUND)
include_directories(${EXODUS_INCLUDE_DIR} ${NetCDF_INCLUDE_DIR})
endif(EXODUS_FOUND)
set(XdmfUtilsSources ${XdmfUtilsSources} XdmfExodusReader)
set(XdmfUtilsLinkLibraries ${XdmfUtilsLinkLibraries} ${EXODUS_LIBRARIES} ${NetCDF_LIBRARIES})
endif(XDMF_BUILD_EXODUS_IO)
if(XDMF_BUILD_PARTITIONER)
find_package(Metis REQUIRED)
if(METIS_FOUND)
......
This diff is collapsed.
#ifndef XDMFEXODUSREADER_HPP_
#define XDMFEXODUSREADER_HPP_
// Forward Declarations
class XdmfGrid;
class XdmfTopologyType;
// Includes
#include <boost/shared_ptr.hpp>
#include <string>
/*!
* @brief XdmfExodusReader reads an ExodusII file from disk into an Xdmf structure in memory.
*/
class XdmfExodusReader {
public:
/**
* Create a new XdmfExodusReader.
*
* @return constructed XdmfExodusReader.
*/
static boost::shared_ptr<XdmfExodusReader> New();
virtual ~XdmfExodusReader();
/*!
* Read the contents of an ExodusII file from disk into an Xdmf structure in memory..
*
* @param fileName containing the path of the exodus file to read.
*
* @return XdmfGrid containing the mesh stored in the ExodusII file.
*/
boost::shared_ptr<XdmfGrid> read(const std::string & fileName) const;
protected:
XdmfExodusReader();
private:
XdmfExodusReader(const XdmfExodusReader & exodusReader); // Not implemented.
void operator=(const XdmfExodusReader & exodusReader); // Not implemented.
/**
* Convert an Exodus topology type to an XdmfTopologyType.
*
* @param exodusTopologyType a string containing the name of the exodus topology type to convert.
* @param pointsPerCell the number of points per cell for the exodus topology type to convert.
*
* @return the equivalent XdmfTopologyType.
*/
boost::shared_ptr<const XdmfTopologyType> exodusToXdmfTopologyType(std::string exodusTopologyType, const int pointsPerCell) const;
};
#endif /* XDMFEXODUSREADER_HPP_ */
......@@ -49,6 +49,12 @@ extern "C"
#include "XdmfTopology.hpp"
#include "XdmfTopologyType.hpp"
boost::shared_ptr<XdmfPartitioner> XdmfPartitioner::New()
{
boost::shared_ptr<XdmfPartitioner> p(new XdmfPartitioner());
return p;
}
XdmfPartitioner::XdmfPartitioner()
{
}
......@@ -203,8 +209,7 @@ boost::shared_ptr<XdmfGridCollection> XdmfPartitioner::partition(const boost::sh
partitioned->getGeometry()->setType(gridToPartition->getGeometry()->getType());
boost::shared_ptr<XdmfArray> geometryVals = partitioned->getGeometry();
unsigned int numDimensions = partitioned->getGeometry()->getType()->getDimensions();
geometryVals->initialize(gridToPartition->getGeometry()->getArrayType());
geometryVals->resize<unsigned int>(currNodeMap.size() * numDimensions);
geometryVals->initialize(gridToPartition->getGeometry()->getArrayType(), currNodeMap.size() * numDimensions);
for(std::map<unsigned int, unsigned int>::const_iterator iter = currNodeMap.begin(); iter != currNodeMap.end(); ++iter)
{
......@@ -220,8 +225,7 @@ 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();
topologyVals->initialize(gridToPartition->getTopology()->getArrayType());
topologyVals->resize<unsigned int>(currElemIds.size() * topologyType->getNodesPerElement());
topologyVals->initialize(gridToPartition->getTopology()->getArrayType(), currElemIds.size() * topologyType->getNodesPerElement());
unsigned int index = 0;
for(std::vector<unsigned int>::const_iterator iter = currElemIds.begin(); iter != currElemIds.end(); ++iter)
......@@ -303,8 +307,7 @@ boost::shared_ptr<XdmfGridCollection> XdmfPartitioner::partition(const boost::sh
createdAttribute->setType(currAttribute->getType());
unsigned int index = 0;
unsigned int numValsPerComponent = currAttribute->size() / gridToPartition->getTopology()->getNumberElements();
createdAttribute->initialize(currAttribute->getArrayType());
createdAttribute->resize<unsigned int>(currElemIds.size() * numValsPerComponent);
createdAttribute->initialize(currAttribute->getArrayType(), currElemIds.size() * numValsPerComponent);
for(std::vector<unsigned int>::const_iterator iter = currElemIds.begin(); iter != currElemIds.end(); ++iter)
{
createdAttribute->copyValues(index, currAttribute, *iter * numValsPerComponent, numValsPerComponent);
......@@ -317,8 +320,7 @@ boost::shared_ptr<XdmfGridCollection> XdmfPartitioner::partition(const boost::sh
createdAttribute->setName(currAttribute->getName());
createdAttribute->setCenter(currAttribute->getCenter());
createdAttribute->setType(currAttribute->getType());
createdAttribute->initialize(currAttribute->getArrayType());
createdAttribute->resize<unsigned int>(currNodeMap.size());
createdAttribute->initialize(currAttribute->getArrayType(), currNodeMap.size());
for(std::map<unsigned int, unsigned int>::const_iterator iter = currNodeMap.begin(); iter != currNodeMap.end(); ++iter)
{
createdAttribute->copyValues(iter->second, currAttribute, iter->first, 1);
......
......@@ -6,6 +6,9 @@ class XdmfGrid;
class XdmfGridCollection;
class XdmfHDF5Writer;
// Includes
#include <boost/shared_ptr.hpp>
/*!
* @brief XdmfPartitioner partitions an XdmfGrid using the metis library.
*
......@@ -20,11 +23,7 @@ public:
*
* @return constructed XdmfPartitioner.
*/
static boost::shared_ptr<XdmfPartitioner> New()
{
boost::shared_ptr<XdmfPartitioner> p(new XdmfPartitioner());
return p;
};
static boost::shared_ptr<XdmfPartitioner> New();
virtual ~XdmfPartitioner();
......
......@@ -108,8 +108,7 @@ public:
toReturn->getTopology()->setType(XdmfTopologyType::Hexahedron_64());
boost::shared_ptr<XdmfArray> newPoints = toReturn->getGeometry();
newPoints->initialize(gridToConvert->getGeometry()->getArrayType());
newPoints->resize(gridToConvert->getGeometry()->size(), 0);
newPoints->initialize(gridToConvert->getGeometry()->getArrayType(), gridToConvert->getGeometry()->size());
if(!gridToConvert->getGeometry()->isInitialized())
{
......@@ -389,8 +388,7 @@ public:
toReturn->getTopology()->setType(XdmfTopologyType::Hexahedron_125());
boost::shared_ptr<XdmfArray> newPoints = toReturn->getGeometry();
newPoints->initialize(gridToConvert->getGeometry()->getArrayType());
newPoints->resize(gridToConvert->getGeometry()->size(), 0);
newPoints->initialize(gridToConvert->getGeometry()->getArrayType(), gridToConvert->getGeometry()->size());
if(!gridToConvert->getGeometry()->isInitialized())
{
......@@ -810,8 +808,7 @@ public:
boost::shared_ptr<XdmfArray> oldConnectivity = gridToConvert->getTopology();
boost::shared_ptr<XdmfArray> newConnectivity = toReturn->getTopology();
newConnectivity->initialize(oldConnectivity->getArrayType());
newConnectivity->resize(216 * gridToConvert->getTopology()->getNumberElements(), 0);
newConnectivity->initialize(oldConnectivity->getArrayType(), 216 * gridToConvert->getTopology()->getNumberElements());
if(!oldConnectivity->isInitialized())
{
......@@ -1060,8 +1057,7 @@ public:
newAttribute->setCenter(currAttribute->getCenter());
boost::shared_ptr<XdmfArray> vals = newAttribute;
vals->initialize(currAttribute->getArrayType());
vals->resize(currAttribute->size() * 27, 0);
vals->initialize(currAttribute->getArrayType(), currAttribute->size() * 27);
for(unsigned int j=0; j<currAttribute->size(); ++j)
{
vals->copyValues(j * 27, currAttribute, j, 27, 1, 0);
......@@ -1073,6 +1069,12 @@ public:
}
};
boost::shared_ptr<XdmfTopologyConverter> XdmfTopologyConverter::New()
{
boost::shared_ptr<XdmfTopologyConverter> p(new XdmfTopologyConverter());
return p;
}
XdmfTopologyConverter::XdmfTopologyConverter()
{
}
......
......@@ -5,6 +5,9 @@
class XdmfGrid;
class XdmfTopologyType;
// Includes
#include <boost/shared_ptr.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.
......@@ -25,11 +28,7 @@ public:
*
* @return constructed XdmfTopologyConverter.
*/
static boost::shared_ptr<XdmfTopologyConverter> New()
{
boost::shared_ptr<XdmfTopologyConverter> p(new XdmfTopologyConverter());
return p;
};
static boost::shared_ptr<XdmfTopologyConverter> New();
virtual ~XdmfTopologyConverter();
......
#include <math.h>
#include "XdmfArray.hpp"
#include "XdmfArrayType.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[])
......
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