/*---------------------------------------------------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd. \\/ 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 2 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, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA \*---------------------------------------------------------------------------*/ #include "ensightField.H" #include "fvMesh.H" #include "volFields.H" #include "OFstream.H" #include "IOmanip.H" #include "itoa.H" #include "ensightWriteBinary.H" using namespace Foam; // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * // void writeData(const scalarField& sf, OFstream& ensightFile) { forAll(sf, i) { if (mag( sf[i] ) >= scalar(floatScalarVSMALL)) { ensightFile << setw(12) << sf[i] << nl; } else { ensightFile << setw(12) << scalar(0) << nl; } } } template scalarField map ( const Field& vf, const labelList& map, const label cmpt ) { scalarField mf(map.size()); forAll(map, i) { mf[i] = component(vf[map[i]], cmpt); } return mf; } template scalarField map ( const Field& vf, const labelList& map1, const labelList& map2, const label cmpt ) { scalarField mf(map1.size() + map2.size()); forAll(map1, i) { mf[i] = component(vf[map1[i]], cmpt); } label offset = map1.size(); forAll(map2, i) { mf[i + offset] = component(vf[map2[i]], cmpt); } return mf; } template void writeAllData ( const char* key, const Field& vf, const labelList& prims, const label nPrims, OFstream& ensightFile ) { if (nPrims) { if (Pstream::master()) { ensightFile << key << nl; for (direction cmpt=0; cmpt::nComponents; cmpt++) { writeData(map(vf, prims, cmpt), ensightFile); for (int slave=1; slave::nComponents; cmpt++) { OPstream toMaster(Pstream::scheduled, Pstream::masterNo()); toMaster<< map(vf, prims, cmpt); } } } } template void writeAllDataBinary ( const char* key, const Field& vf, const labelList& prims, const label nPrims, std::ofstream& ensightFile ) { if (nPrims) { if (Pstream::master()) { writeEnsDataBinary(key,ensightFile); for (direction cmpt=0; cmpt::nComponents; cmpt++) { writeEnsDataBinary(map(vf, prims, cmpt), ensightFile); for (int slave=1; slave::nComponents; cmpt++) { OPstream toMaster(Pstream::scheduled, Pstream::masterNo()); toMaster<< map(vf, prims, cmpt); } } } } template void writeAllFaceData ( const char* key, const labelList& prims, const label nPrims, const Field& pf, const labelList& patchProcessors, OFstream& ensightFile ) { if (nPrims) { if (Pstream::master()) { ensightFile << key << nl; for (direction cmpt=0; cmpt::nComponents; cmpt++) { writeData(map(pf, prims, cmpt), ensightFile); forAll (patchProcessors, i) { if (patchProcessors[i] != 0) { label slave = patchProcessors[i]; IPstream fromSlave(Pstream::scheduled, slave); scalarField pf(fromSlave); writeData(pf, ensightFile); } } } } else { for (direction cmpt=0; cmpt::nComponents; cmpt++) { OPstream toMaster(Pstream::scheduled, Pstream::masterNo()); toMaster<< map(pf, prims, cmpt); } } } } template void writeAllFaceDataBinary ( const char* key, const labelList& prims, const label nPrims, const Field& pf, const labelList& patchProcessors, std::ofstream& ensightFile ) { if (nPrims) { if (Pstream::master()) { writeEnsDataBinary(key,ensightFile); for (direction cmpt=0; cmpt::nComponents; cmpt++) { writeEnsDataBinary(map(pf, prims, cmpt), ensightFile); forAll (patchProcessors, i) { if (patchProcessors[i] != 0) { label slave = patchProcessors[i]; IPstream fromSlave(Pstream::scheduled, slave); scalarField pf(fromSlave); writeEnsDataBinary(pf, ensightFile); } } } } else { for (direction cmpt=0; cmpt::nComponents; cmpt++) { OPstream toMaster(Pstream::scheduled, Pstream::masterNo()); toMaster<< map(pf, prims, cmpt); } } } } template bool writePatchField ( const Foam::Field& pf, const Foam::label patchi, const Foam::label ensightPatchi, const Foam::faceSets& boundaryFaceSet, const Foam::ensightMesh::nFacePrimitives& nfp, const Foam::labelList& patchProcessors, Foam::OFstream& ensightFile ) { if (nfp.nTris || nfp.nQuads || nfp.nPolys) { if (Pstream::master()) { ensightFile << "part" << nl << setw(10) << ensightPatchi << nl; } writeAllFaceData ( "tria3", boundaryFaceSet.tris, nfp.nTris, pf, patchProcessors, ensightFile ); writeAllFaceData ( "quad4", boundaryFaceSet.quads, nfp.nQuads, pf, patchProcessors, ensightFile ); writeAllFaceData ( "nsided", boundaryFaceSet.polys, nfp.nPolys, pf, patchProcessors, ensightFile ); return true; } else { return false; } } template bool writePatchFieldBinary ( const Foam::Field& pf, const Foam::label patchi, const Foam::label ensightPatchi, const Foam::faceSets& boundaryFaceSet, const Foam::ensightMesh::nFacePrimitives& nfp, const Foam::labelList& patchProcessors, std::ofstream& ensightFile ) { if (nfp.nTris || nfp.nQuads || nfp.nPolys) { if (Pstream::master()) { writeEnsDataBinary("part",ensightFile); writeEnsDataBinary(ensightPatchi,ensightFile); } writeAllFaceDataBinary ( "tria3", boundaryFaceSet.tris, nfp.nTris, pf, patchProcessors, ensightFile ); writeAllFaceDataBinary ( "quad4", boundaryFaceSet.quads, nfp.nQuads, pf, patchProcessors, ensightFile ); writeAllFaceDataBinary ( "nsided", boundaryFaceSet.polys, nfp.nPolys, pf, patchProcessors, ensightFile ); return true; } else { return false; } } template void writePatchField ( const Foam::word& fieldName, const Foam::Field& pf, const Foam::word& patchName, const Foam::ensightMesh& eMesh, const Foam::fileName& postProcPath, const Foam::word& prepend, const Foam::label timeIndex, Foam::Ostream& ensightCaseFile ) { const Time& runTime = eMesh.mesh().time(); const List& boundaryFaceSets = eMesh.boundaryFaceSets; const HashTable& allPatchNames = eMesh.allPatchNames; const HashTable