/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "h5Write.H"
#include "Time.H"
#include "SortableList.H"
#include "OFstream.H"
#include "string.H"
#include "stringOps.H"
#define H5DATA_MESH_FILE_NAME "h5Data/h5DataMesh.h5"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
/*
const Foam::label Foam::h5Write::foamToXDMFFaceAddr[4][6] =
{
{ 4, 5, 2, 3, 0, 1 }, // 11 = pro-STAR hex
{ 0, 1, 4, 5, 2, -1 }, // 12 = pro-STAR prism
{ 5, 4, 2, 0, -1, -1 }, // 13 = pro-STAR tetra
{ 0, 4, 3, 5, 2, -1 } // 14 = pro-STAR pyramid
};
*/
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::h5Write::meshInit()
{
Info<< "h5Write::meshInit" << endl << endl;
// Set up file access property list with parallel I/O access
meshPlistID_ = H5Pcreate(H5P_FILE_ACCESS);
H5Pset_fapl_mpio(meshPlistID_, MPI_COMM_WORLD, MPI_INFO_NULL);
// Create a new file collectively.
meshFileID_ = H5Fcreate
(
H5DATA_MESH_FILE_NAME,
H5F_ACC_TRUNC,
H5P_DEFAULT,
meshPlistID_
);
// Close the property list
H5Pclose(meshPlistID_);
}
void Foam::h5Write::meshClose()
{
Info<< "h5Write::meshClose" << endl << endl;
// Close the file.
H5Fclose(meshFileID_);
}
void Foam::h5Write::meshWrite()
{
meshWritePoints();
meshWriteCells();
}
void Foam::h5Write::meshWritePoints()
{
const pointField& points = mesh_.points();
// Create the dataspace for the dataset
hsize_t dimsf[] = {points.size(), 3};
hid_t fileSpace = H5Screate_simple(2, dimsf, NULL);
// Construct dataset name
char datasetName[80];
sprintf(datasetName, "/%f/points/processor%i", mesh_.time().value(),
Pstream::myProcNo());
//if (debug)
{
Pout<< "Dataset name: "<< datasetName << endl;
}
// Create the dataset with default properties
hid_t dsetID = H5Dcreate2
(
meshFileID_,
datasetName,
H5T_SCALAR,
fileSpace,
H5P_DEFAULT,
H5P_DEFAULT,
H5P_DEFAULT
);
// Create property list for collective dataset write.
meshPlistID_ = H5Pcreate(H5P_DATASET_XFER);
H5Pset_dxpl_mpio(meshPlistID_, H5FD_MPIO_COLLECTIVE);
//if (debug)
{
Pout<< "Writing " << points.size() << " points" << endl;
}
// Create a simple array of points (to pass on to H5Dwrite)
scalar pointList[points.size()][3];
// Fill the array
forAll(points, ptI)
{
pointList[ptI][0] = points[ptI].x();
pointList[ptI][1] = points[ptI].y();
pointList[ptI][2] = points[ptI].z();
}
// Do the actual write
meshStatus_ = H5Dwrite
(
dsetID,
H5T_SCALAR,
H5S_ALL,
H5S_ALL,
meshPlistID_,
pointList
);
// Close/release resources.
H5Dclose(dsetID);
H5Sclose(fileSpace);
H5Pclose(meshPlistID_);
}
void Foam::h5Write::meshWriteCells()
{
}
// ************************************************************************* //