Commit 32ae6036 authored by Kenneth Leiter's avatar Kenneth Leiter

ENH: Add Fortran updates into trunk.

parent 45377509
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!
!! AUTHOR: Kenneth Leiter (kenneth.leiter@arl.army.mil)
!!
!! Use the Xdmf Fortran Bindings to write out a simple mesh consisting of
!! two hexahedrons. Link against the XdmfFortran library to compile.
!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
PROGRAM XdmfFortranExample
IMPLICIT NONE
INTEGER*8 obj
character*256 filename
REAL*4 myPoints(3,3,4)
INTEGER myConnections(8,2)
REAL*8 myCellAttribute(2), myNodeAttribute(3,4)
filename = 'my_output'//CHAR(0)
myPoints(1,1,1) = 0
myPoints(2,1,1) = 0
myPoints(3,1,1) = 1
myPoints(1,2,1) = 1
myPoints(2,2,1) = 0
myPoints(3,2,1) = 1
myPoints(1,3,1) = 3
myPoints(2,3,1) = 0
myPoints(3,3,1) = 2
myPoints(1,1,2) = 0
myPoints(2,1,2) = 1
myPoints(3,1,2) = 1
myPoints(1,2,2) = 1
myPoints(2,2,2) = 1
myPoints(3,2,2) = 1
myPoints(1,3,2) = 3
myPoints(2,3,2) = 2
myPoints(3,3,2) = 2
myPoints(1,1,3) = 0
myPoints(2,1,3) = 0
myPoints(3,1,3) = -1
myPoints(1,2,3) = 1
myPoints(2,2,3) = 0
myPoints(3,2,3) = -1
myPoints(1,3,3) = 3
myPoints(2,3,3) = 0
myPoints(3,3,3) = -2
myPoints(1,1,4) = 0
myPoints(2,1,4) = 1
myPoints(3,1,4) = -1
myPoints(1,2,4) = 1
myPoints(2,2,4) = 1
myPoints(3,2,4) = -1
myPoints(1,3,4) = 3
myPoints(2,3,4) = 2
myPoints(3,3,4) = -2
myConnections(1,1) = 0
myConnections(2,1) = 1
myConnections(3,1) = 7
myConnections(4,1) = 6
myConnections(5,1) = 3
myConnections(6,1) = 4
myConnections(7,1) = 10
myConnections(8,1) = 9
myConnections(1,2) = 1
myConnections(2,2) = 2
myConnections(3,2) = 8
myConnections(4,2) = 7
myConnections(5,2) = 4
myConnections(6,2) = 5
myConnections(7,2) = 11
myConnections(8,2) = 10
myNodeAttribute(1,1) = 100
myNodeAttribute(1,2) = 300
myNodeAttribute(1,3) = 300
myNodeAttribute(1,4) = 500
myNodeAttribute(2,1) = 200
myNodeAttribute(2,2) = 400
myNodeAttribute(2,3) = 400
myNodeAttribute(2,4) = 600
myNodeAttribute(3,1) = 300
myNodeAttribute(3,2) = 500
myNodeAttribute(3,3) = 500
myNodeAttribute(3,4) = 700
myCellAttribute(1) = 100
myCellAttribute(2) = 200
CALL XDMFINIT(obj, filename)
! CALL XDMFSETGRIDTOPOLOGY(obj, 'Hexahedron'//CHAR(0), 2, myConnections)\
! CALL XDMFSETGEOMETRY(obj, foo, 36, XDMF_ARRAY_TYPE_FLOAT64, myPoints)
! CALL XDMFADDGRIDATTRIBUTE(obj, 'NodeValues'//CHAR(0),'XDMF_FLOAT64_TYPE'//CHAR(0), 'NODE'//CHAR(0), &
! 'SCALAR'//CHAR(0), 12, myNodeAttribute)
! CALL XDMFADDGRIDATTRIBUTE(obj, 'CellValues'//CHAR(0),'XDMF_FLOAT64_TYPE'//CHAR(0), 'CELL'//CHAR(0), &
! 'SCALAR'//CHAR(0), 2, myCellAttribute)
CALL XDMFADDGRID(obj, 'TestGrid'//CHAR(0))
! CALL XDMFWRITETOFILE(obj)
! CALL XDMFSERIALIZE(obj)
CALL XDMFCLOSE(obj)
END PROGRAM XdmfFortranExample
......@@ -2,12 +2,17 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR})
option(XDMF_BUILD_EXODUS_IO OFF)
option(XDMF_BUILD_PARTITIONER OFF)
option(XDMF_BUILD_FORTRAN OFF)
set(XdmfUtilsSources
XdmfDiff
XdmfTopologyConverter)
set(XdmfUtilsLinkLibraries Xdmf)
if(XDMF_BUILD_FORTRAN)
set(XdmfUtilsSources ${XdmfUtilsSources} XdmfFortran)
endif(XDMF_BUILD_FORTRAN)
if(XDMF_BUILD_EXODUS_IO)
set(XDMF_SWIG_FLAGS ${XDMF_SWIG_FLAGS} -DXDMF_BUILD_EXODUS_IO)
find_package(Exodus REQUIRED)
......@@ -81,6 +86,10 @@ foreach(source ${XdmfUtilsSources})
set(XdmfUtilsHeaders ${XdmfUtilsHeaders} ${source}.hpp)
endforeach(source ${XdmfUtilsSources})
if(XDMF_BUILD_FORTRAN)
set(XdmfUtilsHeaders ${XdmfUtilsHeaders} Xdmf.f)
endif(XDMF_BUILD_FORTRAN)
install(FILES ${XdmfUtilsHeaders} DESTINATION include)
install(TARGETS XdmfUtils
RUNTIME DESTINATION bin
......
! Array Type
integer XDMF_ARRAY_TYPE_INT8
integer XDMF_ARRAY_TYPE_INT16
integer XDMF_ARRAY_TYPE_INT32
integer XDMF_ARRAY_TYPE_INT64
integer XDMF_ARRAY_TYPE_UINT8
integer XDMF_ARRAY_TYPE_UINT16
integer XDMF_ARRAY_TYPE_UINT32
integer XDMF_ARRAY_TYPE_FLOAT32
integer XDMF_ARRAY_TYPE_FLOAT64
! Attribute Center
integer XDMF_ATTRIBUTE_CENTER_GRID
integer XDMF_ATTRIBUTE_CENTER_CELL
integer XDMF_ATTRIBUTE_CENTER_FACE
integer XDMF_ATTRIBUTE_CENTER_EDGE
integer XDMF_ATTRIBUTE_CENTER_NODE
! Attribute Type
integer XDMF_ATTRIBUTE_TYPE_SCALAR
integer XDMF_ATTRIBUTE_TYPE_VECTOR
integer XDMF_ATTRIBUTE_TYPE_TENSOR
integer XDMF_ATTRIBUTE_TYPE_MATRIX
integer XDMF_ATTRIBUTE_TYPE_TENSOR6
integer XDMF_ATTRIBUTE_TYPE_GLOBALID
integer XDMF_ATTRIBUTE_TYPE_NOTYPE
! Geometry Type
integer XDMF_GEOMETRY_TYPE_XYZ
integer XDMF_GEOMETRY_TYPE_XY
! Grid Collection Type
integer XDMF_GRID_COLLECTION_TYPE_SPATIAL
integer XDMF_GRID_COLLECTION_TYPE_TEMPORAL
! Topology Type
integer XDMF_TOPOLOGY_TYPE_POLYVERTEX
integer XDMF_TOPOLOGY_TYPE_POLYLINE
integer XDMF_TOPOLOGY_TYPE_POLYGON
integer XDMF_TOPOLOGY_TYPE_TRIANGLE
integer XDMF_TOPOLOGY_TYPE_QUADRILATERAL
integer XDMF_TOPOLOGY_TYPE_TETRAHEDRON
integer XDMF_TOPOLOGY_TYPE_PYRAMID
integer XDMF_TOPOLOGY_TYPE_WEDGE
integer XDMF_TOPOLOGY_TYPE_HEXAHEDRON
integer XDMF_TOPOLOGY_TYPE_EDGE_3
integer XDMF_TOPOLOGY_TYPE_TRIANGLE_6
integer XDMF_TOPOLOGY_TYPE_QUADRILATERAL_8
integer XDMF_TOPOLOGY_TYPE_QUADRILATERAL_9
integer XDMF_TOPOLOGY_TYPE_TETRAHEDRON_10
integer XDMF_TOPOLOGY_TYPE_PYRAMID_13
integer XDMF_TOPOLOGY_TYPE_WEDGE_15
integer XDMF_TOPOLOGY_TYPE_WEDGE_18
integer XDMF_TOPOLOGY_TYPE_HEXAHEDRON_20
integer XDMF_TOPOLOGY_TYPE_HEXAHEDRON_24
integer XDMF_TOPOLOGY_TYPE_HEXAHEDRON_27
integer XDMF_TOPOLOGY_TYPE_HEXAHEDRON_64
integer XDMF_TOPOLOGY_TYPE_HEXAHEDRON_125
integer XDMF_TOPOLOGY_TYPE_HEXAHEDRON_216
integer XDMF_TOPOLOGY_TYPE_HEXAHEDRON_343
integer XDMF_TOPOLOGY_TYPE_HEXAHEDRON_512
integer XDMF_TOPOLOGY_TYPE_HEXAHEDRON_729
integer XDMF_TOPOLOGY_TYPE_HEXAHEDRON_1000
integer XDMF_TOPOLOGY_TYPE_HEXAHEDRON_1331
integer XDMF_TOPOLOGY_TYPE_MIXED
!------------------------------------------------------
parameter (XDMF_ARRAY_TYPE_INT8 = 0)
parameter (XDMF_ARRAY_TYPE_INT16 = 1)
parameter (XDMF_ARRAY_TYPE_INT32 = 2)
parameter (XDMF_ARRAY_TYPE_INT64 = 3)
parameter (XDMF_ARRAY_TYPE_UINT8 = 4)
parameter (XDMF_ARRAY_TYPE_UINT16 = 5)
parameter (XDMF_ARRAY_TYPE_UINT32 = 6)
parameter (XDMF_ARRAY_TYPE_FLOAT32 = 7)
parameter (XDMF_ARRAY_TYPE_FLOAT64 = 8)
parameter (XDMF_ATTRIBUTE_CENTER_GRID = 100)
parameter (XDMF_ATTRIBUTE_CENTER_CELL = 101)
parameter (XDMF_ATTRIBUTE_CENTER_FACE = 102)
parameter (XDMF_ATTRIBUTE_CENTER_EDGE = 103)
parameter (XDMF_ATTRIBUTE_CENTER_NODE = 104)
parameter (XDMF_ATTRIBUTE_TYPE_SCALAR = 200)
parameter (XDMF_ATTRIBUTE_TYPE_VECTOR = 201)
parameter (XDMF_ATTRIBUTE_TYPE_TENSOR = 202)
parameter (XDMF_ATTRIBUTE_TYPE_MATRIX = 203)
parameter (XDMF_ATTRIBUTE_TYPE_TENSOR6 = 204)
parameter (XDMF_ATTRIBUTE_TYPE_GLOBALID = 205)
parameter (XDMF_ATTRIBUTE_TYPE_NOTYPE = 206)
parameter (XDMF_GEOMETRY_TYPE_XYZ = 301)
parameter (XDMF_GEOMETRY_TYPE_XY = 302)
parameter (XDMF_GRID_COLLECTION_TYPE_SPATIAL = 400)
parameter (XDMF_GRID_COLLECTION_TYPE_TEMPORAL = 401)
parameter (XDMF_TOPOLOGY_TYPE_POLYVERTEX = 500)
parameter (XDMF_TOPOLOGY_TYPE_POLYLINE = 501)
parameter (XDMF_TOPOLOGY_TYPE_POLYGON = 502)
parameter (XDMF_TOPOLOGY_TYPE_TRIANGLE = 503)
parameter (XDMF_TOPOLOGY_TYPE_QUADRILATERAL = 504)
parameter (XDMF_TOPOLOGY_TYPE_TETRAHEDRON = 505)
parameter (XDMF_TOPOLOGY_TYPE_PYRAMID = 506)
parameter (XDMF_TOPOLOGY_TYPE_WEDGE = 507)
parameter (XDMF_TOPOLOGY_TYPE_HEXAHEDRON = 508)
parameter (XDMF_TOPOLOGY_TYPE_EDGE_3 = 509)
parameter (XDMF_TOPOLOGY_TYPE_TRIANGLE_6 = 510)
parameter (XDMF_TOPOLOGY_TYPE_QUADRILATERAL_8 = 511)
parameter (XDMF_TOPOLOGY_TYPE_QUADRILATERAL_9 = 512)
parameter (XDMF_TOPOLOGY_TYPE_TETRAHEDRON_10 = 513)
parameter (XDMF_TOPOLOGY_TYPE_PYRAMID_13 = 514)
parameter (XDMF_TOPOLOGY_TYPE_WEDGE_15 = 515)
parameter (XDMF_TOPOLOGY_TYPE_WEDGE_18 = 516)
parameter (XDMF_TOPOLOGY_TYPE_HEXAHEDRON_20 = 517)
parameter (XDMF_TOPOLOGY_TYPE_HEXAHEDRON_24 = 518)
parameter (XDMF_TOPOLOGY_TYPE_HEXAHEDRON_27 = 519)
parameter (XDMF_TOPOLOGY_TYPE_HEXAHEDRON_64 = 520)
parameter (XDMF_TOPOLOGY_TYPE_HEXAHEDRON_125 = 521)
parameter (XDMF_TOPOLOGY_TYPE_HEXAHEDRON_216 = 522)
parameter (XDMF_TOPOLOGY_TYPE_HEXAHEDRON_343 = 523)
parameter (XDMF_TOPOLOGY_TYPE_HEXAHEDRON_512 = 524)
parameter (XDMF_TOPOLOGY_TYPE_HEXAHEDRON_729 = 525)
parameter (XDMF_TOPOLOGY_TYPE_HEXAHEDRON_1000 = 526)
parameter (XDMF_TOPOLOGY_TYPE_HEXAHEDRON_1331 = 527)
parameter (XDMF_TOPOLOGY_TYPE_MIXED = 528)
/*******************************************************************/
/* XDMF */
/* eXtensible Data Model and Format */
/* */
/* Id : Id */
/* Date : $Date$ */
/* Version : $Revision$ */
/* */
/* Author: */
/* John Vines */
/* john.m.vines@us.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 "XdmfFortran.hpp"
#include "XdmfAttribute.hpp"
#include "XdmfAttributeCenter.hpp"
#include "XdmfAttributeType.hpp"
#include "XdmfDomain.hpp"
#include "XdmfError.hpp"
#include "XdmfGeometry.hpp"
#include "XdmfGeometryType.hpp"
#include "XdmfGrid.hpp"
#include "XdmfGridCollection.hpp"
#include "XdmfGridCollectionType.hpp"
#include "XdmfInformation.hpp"
#include "XdmfReader.hpp"
#include "XdmfTime.hpp"
#include "XdmfTopology.hpp"
#include "XdmfTopologyType.hpp"
#include "XdmfUnstructuredGrid.hpp"
#include "XdmfWriter.hpp"
namespace {
template <typename T>
void
insertElements(const T grid,
std::vector<shared_ptr<XdmfAttribute> > & mAttributes,
std::vector<shared_ptr<XdmfInformation> > & mInformations,
shared_ptr<XdmfTime> mTime,
shared_ptr<XdmfDomain> mDomain,
std::stack<shared_ptr<XdmfGridCollection> > & mGridCollections)
{
for(std::vector<shared_ptr<XdmfAttribute> >::const_iterator iter =
mAttributes.begin();
iter != mAttributes.end();
++iter) {
grid->insert(*iter);
}
mAttributes.clear();
for(std::vector<shared_ptr<XdmfInformation> >::const_iterator iter =
mInformations.begin();
iter != mInformations.end();
++iter) {
grid->insert(*iter);
}
mInformations.clear();
if(mTime) {
grid->setTime(mTime);
}
if(mGridCollections.empty()) {
mDomain->insert(grid);
}
else {
mGridCollections.top()->insert(grid);
}
}
// read values from an xdmf array for a number type
void
readFromArray(shared_ptr<XdmfArray> array,
const int arrayType,
void * const values,
const unsigned int numValues,
const unsigned int startIndex,
const unsigned int arrayStride,
const unsigned int valuesStride)
{
if (!array->isInitialized()) {
array->read();
}
switch(arrayType) {
case XDMF_ARRAY_TYPE_INT8:
array->getValues(startIndex,
static_cast<char * const>(values),
numValues,
arrayStride,
valuesStride);
break;
case XDMF_ARRAY_TYPE_INT16:
array->getValues(startIndex,
static_cast<short * const>(values),
numValues,
arrayStride,
valuesStride);
break;
case XDMF_ARRAY_TYPE_INT32:
array->getValues(startIndex,
static_cast<int * const>(values),
numValues,
arrayStride,
valuesStride);
break;
case XDMF_ARRAY_TYPE_INT64:
array->getValues(startIndex,
static_cast<long * const>(values),
numValues,
arrayStride,
valuesStride);
break;
case XDMF_ARRAY_TYPE_UINT8:
array->getValues(startIndex,
static_cast<unsigned char * const>(values),
numValues,
arrayStride,
valuesStride);
break;
case XDMF_ARRAY_TYPE_UINT16:
array->getValues(startIndex,
static_cast<unsigned short * const>(values),
numValues,
arrayStride,
valuesStride);
break;
case XDMF_ARRAY_TYPE_UINT32:
array->getValues(startIndex,
static_cast<unsigned int * const>(values),
numValues,
arrayStride,
valuesStride);
break;
case XDMF_ARRAY_TYPE_FLOAT32:
array->getValues(startIndex,
static_cast<float * const>(values),
numValues,
arrayStride,
valuesStride);
break;
case XDMF_ARRAY_TYPE_FLOAT64:
array->getValues(startIndex,
static_cast<double * const>(values),
numValues,
arrayStride,
valuesStride);
break;
default:
XdmfError::message(XdmfError::FATAL, "Invalid array number type");
}
}
// write values to xdmf array for a number type
void
writeToArray(shared_ptr<XdmfArray> array,
const unsigned int numValues,
const int arrayType,
const void * const values)
{
switch(arrayType) {
case XDMF_ARRAY_TYPE_INT8:
array->insert(0,
static_cast<const char *>(values),
numValues);
break;
case XDMF_ARRAY_TYPE_INT16:
array->insert(0,
static_cast<const short *>(values),
numValues);
break;
case XDMF_ARRAY_TYPE_INT32:
array->insert(0,
static_cast<const int *>(values),
numValues);
break;
case XDMF_ARRAY_TYPE_INT64:
array->insert(0,
static_cast<const long *>(values),
numValues);
break;
case XDMF_ARRAY_TYPE_UINT8:
array->insert(0,
static_cast<const unsigned char *>(values),
numValues);
break;
case XDMF_ARRAY_TYPE_UINT16:
array->insert(0,
static_cast<const unsigned short *>(values),
numValues);
break;
case XDMF_ARRAY_TYPE_UINT32:
array->insert(0,
static_cast<const unsigned int *>(values),
numValues);
break;
case XDMF_ARRAY_TYPE_FLOAT32:
array->insert(0,
static_cast<const float *>(values),
numValues);
break;
case XDMF_ARRAY_TYPE_FLOAT64:
array->insert(0,
static_cast<const double *>(values),
numValues);
break;
default:
XdmfError::message(XdmfError::FATAL, "Invalid array type");
}
}
}
XdmfFortran::XdmfFortran() :
mDomain(XdmfDomain::New()),
mGeometry(shared_ptr<XdmfGeometry>()),
mTime(shared_ptr<XdmfTime>()),
mTopology(shared_ptr<XdmfTopology>())
{
}
XdmfFortran::~XdmfFortran()
{
}
void
XdmfFortran::addAttribute(const char * const name,
const int attributeCenter,
const int attributeType,
const unsigned int numValues,
const int arrayType,
const void * const values)
{
shared_ptr<XdmfAttribute> currAttribute = XdmfAttribute::New();
currAttribute->setName(name);
switch(attributeCenter) {
case XDMF_ATTRIBUTE_CENTER_GRID:
currAttribute->setCenter(XdmfAttributeCenter::Grid());
break;
case XDMF_ATTRIBUTE_CENTER_CELL:
currAttribute->setCenter(XdmfAttributeCenter::Cell());
break;
case XDMF_ATTRIBUTE_CENTER_FACE:
currAttribute->setCenter(XdmfAttributeCenter::Face());
break;
case XDMF_ATTRIBUTE_CENTER_EDGE:
currAttribute->setCenter(XdmfAttributeCenter::Edge());
break;
case XDMF_ATTRIBUTE_CENTER_NODE:
currAttribute->setCenter(XdmfAttributeCenter::Node());
break;
default:
XdmfError::message(XdmfError::FATAL, "Invalid attribute center");
}
switch(attributeType) {
case XDMF_ATTRIBUTE_TYPE_SCALAR:
currAttribute->setType(XdmfAttributeType::Scalar());
break;
case XDMF_ATTRIBUTE_TYPE_VECTOR:
currAttribute->setType(XdmfAttributeType::Vector());
break;
case XDMF_ATTRIBUTE_TYPE_TENSOR:
currAttribute->setType(XdmfAttributeType::Tensor());
break;
case XDMF_ATTRIBUTE_TYPE_MATRIX:
currAttribute->setType(XdmfAttributeType::Matrix());
break;
case XDMF_ATTRIBUTE_TYPE_TENSOR6:
currAttribute->setType(XdmfAttributeType::Tensor6());
break;
case XDMF_ATTRIBUTE_TYPE_GLOBALID:
currAttribute->setType(XdmfAttributeType::GlobalId());
break;
default:
XdmfError::message(XdmfError::FATAL, "Invalid attribute type");
}
// insert values into attribute
writeToArray(currAttribute,
numValues,
arrayType,
values);
mAttributes.push_back(currAttribute);
}
void
XdmfFortran::addGrid(const char * const name)
{
const shared_ptr<XdmfUnstructuredGrid> grid = XdmfUnstructuredGrid::New();
grid->setName(name);
if(mGeometry == NULL) {
XdmfError::message(XdmfError::FATAL,
"Must set geometry before adding grid.");
}
if(mTopology == NULL) {
XdmfError::message(XdmfError::FATAL,
"Must set topology before adding grid.");
}
grid->setGeometry(mGeometry);
grid->setTopology(mTopology);
insertElements(grid,
mAttributes,
mInformations,
mTime,
mDomain,
mGridCollections);
}
void
XdmfFortran::addGridCollection(const char * const name,
const int gridCollectionType)
{
const shared_ptr<XdmfGridCollection> gridCollection =
XdmfGridCollection::New();
gridCollection->setName(name);
switch(gridCollectionType) {
case XDMF_GRID_COLLECTION_TYPE_SPATIAL:
gridCollection->setType(XdmfGridCollectionType::Spatial());
break;
case XDMF_GRID_COLLECTION_TYPE_TEMPORAL:
gridCollection->setType(XdmfGridCollectionType::Temporal());
break;
default:
XdmfError::message(XdmfError::FATAL, "Invalid grid collection type");
}
insertElements(gridCollection,
mAttributes,