Commit f1f7237c authored by Kenneth Leiter's avatar Kenneth Leiter
Browse files

ENH: Add topology setters for polyline and polyvertex.

Modify writeHDF5 to reuse previous hdf5Writer if possible.
Also modify writeHDF5 to open and close hdf5 writer before writing.
parent 26bed716
......@@ -466,7 +466,8 @@ int
XdmfFortran::setTopology(const int topologyType,
const unsigned int numValues,
const int arrayType,
const void * const connectivityValues)
const void * const connectivityValues,
const int polyNodesPerElement)
{
mTopology = XdmfTopology::New();
......@@ -475,10 +476,10 @@ XdmfFortran::setTopology(const int topologyType,
mTopology->setType(XdmfTopologyType::Polyvertex());
break;
case XDMF_TOPOLOGY_TYPE_POLYLINE:
mTopology->setType(XdmfTopologyType::Polyline(0));
mTopology->setType(XdmfTopologyType::Polyline(polyNodesPerElement));
break;
case XDMF_TOPOLOGY_TYPE_POLYGON:
mTopology->setType(XdmfTopologyType::Polygon(0));
mTopology->setType(XdmfTopologyType::Polygon(polyNodesPerElement));
break;
case XDMF_TOPOLOGY_TYPE_TRIANGLE:
mTopology->setType(XdmfTopologyType::Triangle());
......@@ -509,7 +510,8 @@ XdmfFortran::setTopology(const int topologyType,
break;
case XDMF_TOPOLOGY_TYPE_QUADRILATERAL_9:
mTopology->setType(XdmfTopologyType::Quadrilateral_9());
break; case XDMF_TOPOLOGY_TYPE_TETRAHEDRON_10:
break;
case XDMF_TOPOLOGY_TYPE_TETRAHEDRON_10:
mTopology->setType(XdmfTopologyType::Tetrahedron_10());
break;
case XDMF_TOPOLOGY_TYPE_PYRAMID_13:
......@@ -573,7 +575,8 @@ XdmfFortran::setTopology(const int topologyType,
}
void
XdmfFortran::write(const char * const xmlFilePath, const unsigned int numValues )
XdmfFortran::write(const char * const xmlFilePath,
const unsigned int numValues)
{
shared_ptr<XdmfWriter> writer = XdmfWriter::New(xmlFilePath);
writer->setLightDataLimit(numValues);
......@@ -583,9 +586,20 @@ XdmfFortran::write(const char * const xmlFilePath, const unsigned int numValues
void
XdmfFortran::writeHDF5(const char * const xmlFilePath)
{
shared_ptr<XdmfHDF5Writer> writer = XdmfHDF5Writer::New(xmlFilePath);
writer->setReleaseData( true );
shared_ptr<XdmfHDF5Writer> writer;
std::map<std::string, shared_ptr<XdmfHDF5Writer> >::iterator iter =
mPreviousWriters.find(xmlFilePath);
if(iter != mPreviousWriters.end()) {
writer = iter->second;
}
else {
writer = XdmfHDF5Writer::New(xmlFilePath);
writer->setReleaseData(true);
mPreviousWriters[xmlFilePath] = writer;
}
writer->openFile();
mDomain->accept(writer);
writer->closeFile();
}
void
......@@ -738,6 +752,36 @@ extern "C"
connectivityValues);
}
int
XdmfSetTopologyPolyline(long * pointer,
int * nodesPerElement,
int * numValues,
int * arrayType,
void * connectivityValues)
{
XdmfFortran * xdmfFortran = reinterpret_cast<XdmfFortran *>(*pointer);
return xdmfFortran->setTopology(XDMF_TOPOLOGY_TYPE_POLYLINE,
*numValues,
*arrayType,
connectivityValues,
*nodesPerElement);
}
int
XdmfSetTopologyPolyvertex(long * pointer,
int * nodesPerElement,
int * numValues,
int * arrayType,
void * connectivityValues)
{
XdmfFortran * xdmfFortran = reinterpret_cast<XdmfFortran *>(*pointer);
return xdmfFortran->setTopology(XDMF_TOPOLOGY_TYPE_POLYVERTEX,
*numValues,
*arrayType,
connectivityValues,
*nodesPerElement);
}
void
XdmfWrite(long * pointer,
char * xmlFilePath,
......@@ -750,7 +794,7 @@ extern "C"
void
XdmfWriteHDF5(long * pointer,
char * xmlFilePath )
char * xmlFilePath)
{
XdmfFortran * xdmfFortran = reinterpret_cast<XdmfFortran *>(*pointer);
xdmfFortran->writeHDF5(xmlFilePath);
......
......@@ -30,6 +30,7 @@ class XdmfAttribute;
class XdmfDomain;
class XdmfGeometry;
class XdmfGridCollection;
class XdmfHDF5Writer;
class XdmfInformation;
class XdmfTime;
class XdmfTopology;
......@@ -37,6 +38,7 @@ class XdmfUnstructuredGrid;
//Includes
#include <stack>
#include <map>
#include <vector>
#include "XdmfUtils.hpp"
#include "XdmfSharedPtr.hpp"
......@@ -136,6 +138,8 @@ class XdmfUnstructuredGrid;
#define XdmfSetPreviousTopology xdmfsetprevioustopology_
#define XdmfSetTime xdmfsettime_
#define XdmfSetTopology xdmfsettopology_
#define XdmfSetTopologyPolyline xdmfsettopologypolyline_
#define XdmfSetTopologyPolyvertex xdmfsettopologypolyvertex_
#define XdmfWrite xdmfwrite_
#define XdmfRead xdmfread_
#define XdmfWriteHDF5 xdmfwritehdf5_
......@@ -287,13 +291,16 @@ public:
* @param numValues number of connectivity values to copy.
* @param arrayType type of connectivity values.
* @param connectivityValues array of connectivity values.
* @param polyNodesPerElement for polyline and polyvertex types the
* number of nodes per element.
*
* @return int providing id to fortran if reusing.
*/
int setTopology(const int topologyType,
const unsigned int numValues,
const int arrayType,
const void * const connectivityValues);
const void * const connectivityValues,
const int polyNodesPerElement = 0);
/**
* Write constructed file to disk.
......@@ -335,7 +342,7 @@ private:
std::vector<shared_ptr<XdmfInformation> > mPreviousInformations;
std::vector<shared_ptr<XdmfTopology> > mPreviousTopologies;
std::map<std::string, shared_ptr<XdmfHDF5Writer> > mPreviousWriters;
};
......
......@@ -18,8 +18,10 @@ PROGRAM XdmfFortranExample
INTEGER myConnections(8,2)
REAL*8 myCellAttribute(2), myNodeAttribute(3,4), myTime
INTEGER nodeAttributeId, cellAttributeId, xdmfaddattribute
REAL*4 polylinePoints(3,4)
INTEGER polylineTopology(6)
filename = 'my_output'//CHAR(0)
filename = 'my_output.xmf'//CHAR(0)
myPoints(1,1,1) = 0
myPoints(2,1,1) = 0
......@@ -91,6 +93,26 @@ PROGRAM XdmfFortranExample
myCellAttribute(1) = 100
myCellAttribute(2) = 200
polylinePoints(1,1) = 0
polylinePoints(2,1) = 0
polylinePoints(3,1) = 0
polylinePoints(1,2) = 1
polylinePoints(2,2) = 1
polylinePoints(3,2) = 0
polylinePoints(1,3) = 2
polylinePoints(2,3) = 1
polylinePoints(3,3) = 0
polylinePoints(1,4) = 3
polylinePoints(2,4) = 0
polylinePoints(3,4) = 0
polylineTopology(1) = 0
polylineTopology(2) = 1
polylineTopology(3) = 1
polylineTopology(4) = 2
polylineTopology(5) = 2
polylineTopology(6) = 3
myTime = 1.0
CALL XDMFINIT(obj, filename)
......@@ -115,8 +137,15 @@ PROGRAM XdmfFortranExample
CALL XDMFSETTIME(obj, myTime)
CALL XDMFADDPREVIOUSATTRIBUTE(obj, cellAttributeId)
CALL XDMFADDGRID(obj, 'Identical'//CHAR(0))
CALL XDMFSETTOPOLOGYPOLYLINE(obj, 2, 6, XDMF_ARRAY_TYPE_INT32, &
polylineTopology)
CALL XDMFSETGEOMETRY(obj, XDMF_GEOMETRY_TYPE_XYZ, 12, &
XDMF_ARRAY_TYPE_FLOAT32, polylinePoints)
CALL XDMFADDGRID(obj, 'TestPolyline'//CHAR(0))
CALL XDMFCLOSEGRIDCOLLECTION(obj)
CALL XDMFWRITE(obj, filename)
CALL XDMFWRITE(obj, filename, 10)
CALL XDMFCLOSE(obj)
END PROGRAM XdmfFortranExample
......
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