Commit ab73bf69 authored by Kenneth Leiter's avatar Kenneth Leiter

ENH: Add XdmfExodusWriter to utils.

parent 906019df
......@@ -8,6 +8,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/CMake ${CMAKE_CURRENT_SOURCE_D
add_subdirectory(core)
include_directories(${XdmfCore_INCLUDE_DIRS})
include_directories(tests/Cxx)
set(XdmfSources
XdmfAttribute
......
......@@ -282,19 +282,19 @@ void XdmfGrid::setTopology(const boost::shared_ptr<XdmfTopology> topology)
void XdmfGrid::traverse(const boost::shared_ptr<XdmfBaseVisitor> visitor)
{
if(mTime != NULL)
if(mTime)
{
mTime->accept(visitor);
}
if(mGeometry != NULL)
if(mGeometry)
{
mGeometry->accept(visitor);
}
if(mTopology != NULL)
if(mTopology)
{
mTopology->accept(visitor);
}
if(mMap != NULL)
if(mMap)
{
mMap->accept(visitor);
}
......
......@@ -265,7 +265,9 @@ protected:
XdmfGrid();
virtual void populateItem(const std::map<std::string, std::string> & itemProperties, std::vector<boost::shared_ptr<XdmfItem> > & childItems);
boost::shared_ptr<XdmfGeometry> mGeometry;
std::string mName;
boost::shared_ptr<XdmfTopology> mTopology;
private:
......@@ -273,11 +275,9 @@ private:
void operator=(const XdmfGrid & grid); // Not implemented.
std::vector<boost::shared_ptr<XdmfAttribute> > mAttributes;
boost::shared_ptr<XdmfGeometry> mGeometry;
boost::shared_ptr<XdmfMap> mMap;
std::vector<boost::shared_ptr<XdmfSet> > mSets;
boost::shared_ptr<XdmfTime> mTime;
boost::shared_ptr<XdmfTopology> mTopology;
};
#endif /* XDMFGRID_HPP_ */
......@@ -15,9 +15,12 @@ boost::shared_ptr<XdmfGridCollection> XdmfGridCollection::New()
};
XdmfGridCollection::XdmfGridCollection() :
XdmfGrid(),
mCollectionType(XdmfGridCollectionType::NoCollectionType())
{
mGeometry = boost::shared_ptr<XdmfGeometry>();
mName = "Collection";
mTopology = boost::shared_ptr<XdmfTopology>();
}
XdmfGridCollection::~XdmfGridCollection()
......
......@@ -28,7 +28,7 @@ boost::shared_ptr<XdmfItem> XdmfItemFactory::createItem(const std::string & item
{
boost::shared_ptr<XdmfItem> newItem = XdmfCoreItemFactory::createItem(itemTag, itemProperties);
if(newItem != NULL)
if(newItem)
{
return newItem;
}
......
......@@ -189,7 +189,7 @@ void XdmfMap::populateItem(const std::map<std::string, std::string> & itemProper
void XdmfMap::read()
{
if(mImpl->mLocalNodeIdsHDF5Controller != NULL && mImpl->mRemoteTaskIdsHDF5Controller != NULL && mImpl->mRemoteLocalNodeIdsHDF5Controller != NULL)
if(mImpl->mLocalNodeIdsHDF5Controller && mImpl->mRemoteTaskIdsHDF5Controller && mImpl->mRemoteLocalNodeIdsHDF5Controller)
{
assert(mImpl->mLocalNodeIdsHDF5Controller->size() == mImpl->mRemoteTaskIdsHDF5Controller->size() && mImpl->mLocalNodeIdsHDF5Controller->size() == mImpl->mRemoteLocalNodeIdsHDF5Controller->size());
boost::shared_ptr<XdmfArray> globalNodeIds = XdmfArray::New();
......
......@@ -164,7 +164,7 @@ boost::shared_ptr<std::vector<T> > XdmfArray::getValues()
boost::shared_ptr<std::vector<T> > currArray = boost::get<boost::shared_ptr<std::vector<T> > >(mArray);
return currArray;
}
catch(const boost::bad_get& exception)
catch(const boost::bad_get & exception)
{
return boost::shared_ptr<std::vector<T> >();
}
......
......@@ -14,7 +14,7 @@ if(XDMF_BUILD_EXODUS_IO)
if(EXODUS_FOUND)
include_directories(${EXODUS_INCLUDE_DIR} ${NetCDF_INCLUDE_DIR})
endif(EXODUS_FOUND)
set(XdmfUtilsSources ${XdmfUtilsSources} XdmfExodusReader)
set(XdmfUtilsSources ${XdmfUtilsSources} XdmfExodusReader XdmfExodusWriter)
set(XdmfUtilsLinkLibraries ${XdmfUtilsLinkLibraries} ${EXODUS_LIBRARIES} ${NetCDF_LIBRARIES})
endif(XDMF_BUILD_EXODUS_IO)
......
/*******************************************************************/
/* XDMF */
/* eXtensible Data Model and Format */
/* */
/* Id : Id */
/* Date : $Date$ */
/* Version : $Revision$ */
/* */
/* Author: */
/* Kenneth Leiter */
/* kenneth.leiter@arl.army.mil */
/* US Army Research Laboratory */
/* Aberdeen Proving Ground, MD */
/* */
/* Copyright @ 2009 US Army Research Laboratory */
/* All Rights Reserved */
/* See Copyright.txt or http://www.arl.hpc.mil/ice for details */
/* */
/* This software is distributed WITHOUT ANY WARRANTY; without */
/* even the implied warranty of MERCHANTABILITY or FITNESS */
/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
/* for more information. */
/* */
/*******************************************************************/
#include <exodusII.h>
#include "XdmfArrayType.hpp"
#include "XdmfAttribute.hpp"
......@@ -71,6 +46,7 @@ boost::shared_ptr<XdmfGrid> XdmfExodusReader::read(const std::string & fileName,
char * title = new char[MAX_LINE_LENGTH+1];
int num_dim, num_nodes, num_elem, num_elem_blk, num_node_sets, num_side_sets;
ex_get_init (exodusHandle, title, &num_dim, &num_nodes, &num_elem, &num_elem_blk, &num_node_sets, &num_side_sets);
toReturn->setName(title);
delete [] title;
/*
......@@ -180,7 +156,7 @@ boost::shared_ptr<XdmfGrid> XdmfExodusReader::read(const std::string & fileName,
int elemIndex = 0;
for(unsigned int i=0; i<num_elem_blk; ++i)
{
ex_get_elem_conn(exodusHandle, blockIds[i], &connectivityPointer[elemIndex]);
ex_get_elem_conn(exodusHandle, blockIds[i], connectivityPointer + elemIndex);
elemIndex += numElemsInBlock[i] * numNodesPerElemInBlock[i];
}
......@@ -447,8 +423,8 @@ boost::shared_ptr<XdmfGrid> XdmfExodusReader::read(const std::string & fileName,
elemIndex = 0;
for (unsigned int j=0; j<num_elem_blk; ++j)
{
ex_get_elem_var(exodusHandle, 1, i+1, blockIds[j], numElemsInBlock[i], &((double*)attribute->getValuesPointer())[elemIndex]);
elemIndex = elemIndex + numElemsInBlock[i];
ex_get_elem_var(exodusHandle, 1, i+1, blockIds[j], numElemsInBlock[j], (double*)attribute->getValuesPointer() + elemIndex);
elemIndex += numElemsInBlock[j];
}
toReturn->insert(attribute);
if(heavyDataWriter)
......
This diff is collapsed.
#ifndef XDMFEXODUSWRITER_HPP_
#define XDMFEXODUSWRITER_HPP_
// Forward Declarations
class XdmfGrid;
class XdmfTopologyType;
// Includes
#include <boost/shared_ptr.hpp>
#include <string>
/*!
* @brief XdmfExodusWriter writes an Xdmf structure in memory to an ExodusII file on disk.
*/
class XdmfExodusWriter {
public:
/**
* Create a new XdmfExodusReader.
*
* @return constructed XdmfExodusReader.
*/
static boost::shared_ptr<XdmfExodusWriter> New();
virtual ~XdmfExodusWriter();
/*!
* Write an XdmfGrid to an ExodusII file.
*
* @param path of the ExodusII file to writer.
* @param gridToWrite an XdmfGrid to write to ExodusII file format.
*/
void write(const std::string & filePath, const boost::shared_ptr<XdmfGrid> gridToWrite) const;
protected:
XdmfExodusWriter();
private:
/**
* PIMPL
*/
class XdmfExodusWriterImpl;
XdmfExodusWriter(const XdmfExodusWriter & exodusWriter); // Not implemented.
void operator=(const XdmfExodusWriter & exodusWriter); // Not implemented.
/**
* Convert an Xdmf topology type to an exodus topology type.
*
* @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.
*/
std::string xdmfToExodusTopologyType(boost::shared_ptr<const XdmfTopologyType> topologyType) const;
XdmfExodusWriterImpl * mImpl;
};
#endif /* XDMFEXODUSWRITER_HPP_ */
/*******************************************************************/
/* XDMF */
/* eXtensible Data Model and Format */
/* */
/* Id : Id */
/* Date : $Date$ */
/* Version : $Revision$ */
/* */
/* Author: */
/* Kenneth Leiter */
/* kenneth.leiter@arl.army.mil */
/* US Army Research Laboratory */
/* Aberdeen Proving Ground, MD */
/* */
/* Copyright @ 2010 US Army Research Laboratory */
/* All Rights Reserved */
/* See Copyright.txt or http://www.arl.hpc.mil/ice for details */
/* */
/* This software is distributed WITHOUT ANY WARRANTY; without */
/* even the implied warranty of MERCHANTABILITY or FITNESS */
/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
/* for more information. */
/* */
/*******************************************************************/
#ifndef BUILD_EXE
extern "C"
......@@ -65,6 +40,9 @@ XdmfPartitioner::~XdmfPartitioner()
boost::shared_ptr<XdmfGridCollection> XdmfPartitioner::partition(const boost::shared_ptr<XdmfGrid> gridToPartition, const unsigned int numberOfPartitions,
const boost::shared_ptr<XdmfHDF5Writer> heavyDataWriter) const
{
// Make sure geometry and topology are non null
assert(gridToPartition->getGeometry() && gridToPartition->getTopology());
int metisElementType;
int nodesPerElement;
......@@ -107,7 +85,7 @@ boost::shared_ptr<XdmfGridCollection> XdmfPartitioner::partition(const boost::sh
idxtype * metisConnectivity = new idxtype[nodesPerElement * numElements];
for(unsigned int i=0; i<numElements; ++i)
{
gridToPartition->getTopology()->getValuesCopy(i*topologyType->getNodesPerElement(), &metisConnectivity[i*nodesPerElement], nodesPerElement);
gridToPartition->getTopology()->getValuesCopy(i*topologyType->getNodesPerElement(), metisConnectivity + i * nodesPerElement, nodesPerElement);
}
int numNodes = gridToPartition->getGeometry()->getNumberPoints();
......@@ -332,7 +310,7 @@ boost::shared_ptr<XdmfGridCollection> XdmfPartitioner::partition(const boost::sh
createdAttribute->copyValues(iter->second, currAttribute, iter->first, 1);
}
}
if(createdAttribute != NULL)
if(createdAttribute)
{
partitioned->insert(createdAttribute);
if(heavyDataWriter)
......
......@@ -1129,7 +1129,7 @@ public:
currAttribute->release();
}
}
if(createdAttribute != NULL)
if(createdAttribute)
{
toReturn->insert(createdAttribute);
if(heavyDataWriter)
......@@ -1164,6 +1164,9 @@ XdmfTopologyConverter::~XdmfTopologyConverter()
boost::shared_ptr<XdmfGrid> XdmfTopologyConverter::convert(const boost::shared_ptr<XdmfGrid> gridToConvert, const boost::shared_ptr<const XdmfTopologyType> topologyType,
const boost::shared_ptr<XdmfHDF5Writer> heavyDataWriter) const
{
// Make sure geometry and topology are non null
assert(gridToConvert->getGeometry() && gridToConvert->getTopology());
boost::shared_ptr<const XdmfTopologyType> topologyTypeToConvert = gridToConvert->getTopology()->getType();
if(topologyTypeToConvert == topologyType)
{
......
......@@ -39,8 +39,13 @@ swig -v -c++ -python -o XdmfUtilsPython.cpp XdmfUtils.i
#include <XdmfTopologyType.hpp>
// XdmfUtils Includes
#include <XdmfExodusReader.hpp>
//#include <XdmfPartitioner.hpp>
#ifdef XDMF_BUILD_EXODUS_IO
#include <XdmfExodusReader.hpp>
#include <XdmfExodusWriter.hpp>
#endif
#ifdef XDMF_BUILD_PARTITIONER
#include <XdmfPartitioner.hpp>
#endif
#include <XdmfTopologyConverter.hpp>
%}
......@@ -51,10 +56,20 @@ swig -v -c++ -python -o XdmfUtilsPython.cpp XdmfUtils.i
//}
// Shared Pointer Templates
%shared_ptr(XdmfExodusReader)
//%shared_ptr(XdmfPartitioner)
#ifdef XDMF_BUILD_EXODUS_IO
%shared_ptr(XdmfExodusReader)
%shared_ptr(XdmfExodusWriter)
#endif
#ifdef XDMF_BUILD_PARTITIONER
%shared_ptr(XdmfPartitioner)
#endif
%shared_ptr(XdmfTopologyConverter)
%include XdmfExodusReader.hpp
//%include XdmfPartitioner.hpp
#ifdef XDMF_BUILD_EXODUS_IO
%include XdmfExodusReader.hpp
%include XdmfExodusWriter.hpp
#endif
#ifdef XDMF_BUILD_PARTITIONER
%include XdmfPartitioner.hpp
#endif
%include XdmfTopologyConverter.hpp
set(XdmfUtilsCxxTests
TestXdmfExodusReader
TestXdmfTopologyConverter
)
if(XDMF_BUILD_EXODUS_IO)
set(XdmfUtilsCxxTests ${XdmfUtilsCxxTests} TestXdmfExodusIO)
endif(XDMF_BUILD_EXODUS_IO)
foreach(test ${XdmfUtilsCxxTests})
add_executable(${test} ${test})
target_link_libraries(${test} XdmfUtils)
......
#include "XdmfDomain.hpp"
#include "XdmfExodusReader.hpp"
#include "XdmfExodusWriter.hpp"
#include "XdmfHDF5Writer.hpp"
#include "XdmfWriter.hpp"
#include "XdmfTestDataGenerator.hpp"
int main(int argc, char* argv[])
{
boost::shared_ptr<XdmfExodusWriter> exodusWriter = XdmfExodusWriter::New();
boost::shared_ptr<XdmfGrid> hexahedron = XdmfTestDataGenerator::createHexahedron();
exodusWriter->write("TestXdmfExodusIO.exo", hexahedron);
boost::shared_ptr<XdmfExodusReader> reader = XdmfExodusReader::New();
boost::shared_ptr<XdmfGrid> grid = reader->read("TestXdmfExodusIO.exo");
assert(grid->getName() == hexahedron->getName());
assert(grid->getGeometry()->getType() == hexahedron->getGeometry()->getType());
assert(grid->getGeometry()->getNumberPoints() == hexahedron->getGeometry()->getNumberPoints());
for(unsigned int i=0; i<grid->getGeometry()->size(); ++i)
{
assert(grid->getGeometry()->getValueCopy<double>(i) == hexahedron->getGeometry()->getValueCopy<double>(i));
}
assert(grid->getTopology()->getType() == hexahedron->getTopology()->getType());
assert(grid->getTopology()->getNumberElements() == hexahedron->getTopology()->getNumberElements());
for(unsigned int i=0; i<grid->getTopology()->size(); ++i)
{
assert(grid->getTopology()->getValueCopy<double>(i) == hexahedron->getTopology()->getValueCopy<double>(i));
}
assert(hexahedron->getNumberAttributes() + 1 == grid->getNumberAttributes());
for(unsigned int i=0; i<hexahedron->getNumberAttributes(); ++i)
{
boost::shared_ptr<XdmfAttribute> attribute1 = hexahedron->getAttribute(i);
boost::shared_ptr<XdmfAttribute> attribute2 = grid->getAttribute(attribute1->getName());
assert(attribute1->getCenter() == attribute2->getCenter());
assert(attribute1->getType() == attribute2->getType());
assert(attribute1->size() == attribute2->size());
for(unsigned int j=0; j<attribute1->size(); ++j)
{
assert(attribute1->getValueCopy<double>(i) == attribute2->getValueCopy<double>(i));
}
}
}
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