diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsight/Make/files b/applications/utilities/postProcessing/dataConversion/foamToEnsight/Make/files index 78e39e9df6b48603ae717147a52c6dbff0f34959..44c513a079bdb9707167566ccc85a334e91d4078 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToEnsight/Make/files +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsight/Make/files @@ -2,6 +2,5 @@ itoa.C ensightMesh.C ensightParticlePositions.C foamToEnsight.C -ensightWriteBinary.C EXE = $(FOAM_APPBIN)/foamToEnsight diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsight/cellSets.H b/applications/utilities/postProcessing/dataConversion/foamToEnsight/cellSets.H index 2c9755ef436014b387f35237ec7bdee8f7e12b37..a4447108ab75857adfc042210e86181dd882e8b7 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToEnsight/cellSets.H +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsight/cellSets.H @@ -44,15 +44,6 @@ namespace Foam class cellSets { - // Private Member Functions - - //- Disallow default bitwise copy construct - cellSets(const cellSets&); - - //- Disallow default bitwise assignment - void operator=(const cellSets&); - - public: label nHexesWedges; diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightAsciiStream.H b/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightAsciiStream.H new file mode 100644 index 0000000000000000000000000000000000000000..2230b75b24bb0db43f511290b337dec7000efe39 --- /dev/null +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightAsciiStream.H @@ -0,0 +1,156 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2010-2010 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 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/>. + +Class + Foam::ensightAsciiStream + +Description + +SourceFiles + ensightAsciiStream.C + +\*---------------------------------------------------------------------------*/ + +#ifndef ensightAsciiStream_H +#define ensightAsciiStream_H + +#include "ensightStream.H" +#include "OFstream.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class ensightAsciiStream Declaration +\*---------------------------------------------------------------------------*/ + +class ensightAsciiStream +: + public ensightStream +{ + // Private data + + //- Description of data_ + OFstream str_; + + + // Private Member Functions + + //- Disallow default bitwise copy construct + ensightAsciiStream(const ensightAsciiStream&); + + //- Disallow default bitwise assignment + void operator=(const ensightAsciiStream&); + + +public: + + // Constructors + + //- Construct from components + ensightAsciiStream(const fileName& f, const Time& runTime) + : + ensightStream(f), + str_ + ( + f, + runTime.writeFormat(), + runTime.writeVersion(), + IOstream::UNCOMPRESSED + ) + { + + str_.setf(ios_base::scientific, ios_base::floatfield); + str_.precision(5); + } + + + //- Destructor + virtual ~ensightAsciiStream() + {} + + + // Member Functions + + virtual void write(const char* c) + { + str_ << c << nl; + } + + virtual void write(const int v) + { + str_ << setw(10) << v << nl; + } + + virtual void write(const scalarField& sf) + { + forAll(sf, i) + { + if (mag(sf[i]) >= scalar(floatScalarVSMALL)) + { + str_ << setw(12) << sf[i] << nl; + } + else + { + str_ << setw(12) << scalar(0) << nl; + } + } + } + + virtual void write(const List<int>& sf) + { + forAll(sf, i) + { + str_ << setw(10) << sf[i]; + } + str_<< nl; + } + + virtual void writePartHeader(const label partI) + { + str_<< "part" << nl + << setw(10) << partI << nl; + } + + // Member Operators + + // Friend Functions + + // Friend Operators + + // IOstream Operators + +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightBinaryStream.H b/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightBinaryStream.H new file mode 100644 index 0000000000000000000000000000000000000000..b4f1421e4aff778f7926a6e1f348890c8637b8f4 --- /dev/null +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightBinaryStream.H @@ -0,0 +1,158 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2010-2010 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 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/>. + +Class + Foam::ensightBinaryStream + +Description + +SourceFiles + ensightBinaryStream.C + +\*---------------------------------------------------------------------------*/ + +#ifndef ensightBinaryStream_H +#define ensightBinaryStream_H + +#include "ensightStream.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class ensightBinaryStream Declaration +\*---------------------------------------------------------------------------*/ + +class ensightBinaryStream +: + public ensightStream +{ + // Private data + + //- Description of data_ + autoPtr<std::ofstream> str_; + + + // Private Member Functions + + //- Disallow default bitwise copy construct + ensightBinaryStream(const ensightBinaryStream&); + + //- Disallow default bitwise assignment + void operator=(const ensightBinaryStream&); + + +public: + + // Constructors + + //- Construct from components + ensightBinaryStream(const fileName& f, const Time&) + : + ensightStream(f), + str_ + ( + new std::ofstream + ( + f.c_str(), + ios_base::out | ios_base::binary | ios_base::trunc + ) + ) + {} + + + //- Destructor + virtual ~ensightBinaryStream() + {} + + + // Member Functions + + virtual void write(const char* val) + { + char buffer[80] = {0}; + strcpy(buffer, val); + str_().write(buffer, 80*sizeof(char)); + } + + virtual void write(const int val) + { + str_().write(reinterpret_cast<const char*>(&val), sizeof(int)); + } + + virtual void write(const scalarField& sf) + { + if (sf.size()) + { + List<float> temp(sf.size()); + + forAll(sf, i) + { + temp[i] = float(sf[i]); + } + + str_().write + ( + reinterpret_cast<const char*>(temp.begin()), + sf.size()*sizeof(float) + ); + } + } + + virtual void write(const List<int>& sf) + { + str_().write + ( + reinterpret_cast<const char*>(sf.begin()), + sf.size()*sizeof(int) + ); + } + + virtual void writePartHeader(const label partI) + { + write("part"); + write(partI); + } + + // Member Operators + + // Friend Functions + + // Friend Operators + + // IOstream Operators + +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightField.C b/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightField.C index 680d5ff89499649d64c4232c673e6fa49aab9b04..8a366d1a223892b41cc272f2361b6197308c3bd4 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightField.C +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightField.C @@ -29,28 +29,14 @@ License #include "OFstream.H" #include "IOmanip.H" #include "itoa.H" -#include "ensightWriteBinary.H" +#include "volPointInterpolation.H" +#include "ensightBinaryStream.H" +#include "ensightAsciiStream.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<class Type> scalarField map ( @@ -104,64 +90,25 @@ void writeAllData const Field<Type>& vf, const labelList& prims, const label nPrims, - OFstream& ensightFile -) -{ - if (nPrims) - { - if (Pstream::master()) - { - ensightFile << key << nl; - - for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; cmpt++) - { - writeData(map(vf, prims, cmpt), ensightFile); - - for (int slave=1; slave<Pstream::nProcs(); slave++) - { - IPstream fromSlave(Pstream::scheduled, slave); - scalarField data(fromSlave); - writeData(data, ensightFile); - } - } - } - else - { - for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; cmpt++) - { - OPstream toMaster(Pstream::scheduled, Pstream::masterNo()); - toMaster<< map(vf, prims, cmpt); - } - } - } -} - - -template<class Type> -void writeAllDataBinary -( - const char* key, - const Field<Type>& vf, - const labelList& prims, - const label nPrims, - std::ofstream& ensightFile + ensightStream& ensightFile ) { if (nPrims) { if (Pstream::master()) { - writeEnsDataBinary(key,ensightFile); + ensightFile.write(key); for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; cmpt++) { - writeEnsDataBinary(map(vf, prims, cmpt), ensightFile); + scalarField masterData(map(vf, prims, cmpt)); + ensightFile.write(masterData); for (int slave=1; slave<Pstream::nProcs(); slave++) { IPstream fromSlave(Pstream::scheduled, slave); - scalarField data(fromSlave); - writeEnsDataBinary(data, ensightFile); + scalarField slaveData(fromSlave); + ensightFile.write(slaveData); } } } @@ -184,66 +131,25 @@ void writeAllFaceData const labelList& prims, const label nPrims, const Field<Type>& pf, - OFstream& ensightFile + ensightStream& ensightFile ) { if (nPrims) { if (Pstream::master()) { - ensightFile << key << nl; + ensightFile.write(key); for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; cmpt++) { - writeData(map(pf, prims, cmpt), ensightFile); + ensightFile.write(map(pf, prims, cmpt)); for (int slave=1; slave<Pstream::nProcs(); slave++) { IPstream fromSlave(Pstream::scheduled, slave); scalarField pf(fromSlave); - writeData(pf, ensightFile); - } - } - } - else - { - for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; cmpt++) - { - OPstream toMaster(Pstream::scheduled, Pstream::masterNo()); - toMaster<< map(pf, prims, cmpt); - } - } - } -} - - -template<class Type> -void writeAllFaceDataBinary -( - const char* key, - const labelList& prims, - const label nPrims, - const Field<Type>& pf, - std::ofstream& ensightFile -) -{ - if (nPrims) - { - if (Pstream::master()) - { - writeEnsDataBinary(key,ensightFile); - - for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; cmpt++) - { - writeEnsDataBinary(map(pf, prims, cmpt), ensightFile); - - for (int slave=1; slave<Pstream::nProcs(); slave++) - { - IPstream fromSlave(Pstream::scheduled, slave); - scalarField pf(fromSlave); - - writeEnsDataBinary(pf, ensightFile); + ensightFile.write(pf); } } } @@ -267,16 +173,14 @@ bool writePatchField const Foam::label ensightPatchI, const Foam::faceSets& boundaryFaceSet, const Foam::ensightMesh::nFacePrimitives& nfp, - Foam::OFstream& ensightFile + ensightStream& ensightFile ) { if (nfp.nTris || nfp.nQuads || nfp.nPolys) { if (Pstream::master()) { - ensightFile - << "part" << nl - << setw(10) << ensightPatchI << nl; + ensightFile.writePartHeader(ensightPatchI); } writeAllFaceData @@ -315,61 +219,6 @@ bool writePatchField } -template<class Type> -bool writePatchFieldBinary -( - const Foam::Field<Type>& pf, - const Foam::label patchi, - const Foam::label ensightPatchI, - const Foam::faceSets& boundaryFaceSet, - const Foam::ensightMesh::nFacePrimitives& nfp, - 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, - ensightFile - ); - - writeAllFaceDataBinary - ( - "quad4", - boundaryFaceSet.quads, - nfp.nQuads, - pf, - ensightFile - ); - - writeAllFaceDataBinary - ( - "nsided", - boundaryFaceSet.polys, - nfp.nPolys, - pf, - ensightFile - ); - - return true; - } - else - { - return false; - } -} - - template<class Type> void writePatchField ( @@ -380,6 +229,7 @@ void writePatchField const Foam::fileName& postProcPath, const Foam::word& prepend, const Foam::label timeIndex, + const bool binary, Foam::Ostream& ensightCaseFile ) { @@ -409,7 +259,7 @@ void writePatchField word timeFile = prepend + itoa(timeIndex); - OFstream *ensightFilePtr = NULL; + autoPtr<ensightStream> ensightFilePtr; if (Pstream::master()) { if (timeIndex == 0) @@ -426,20 +276,36 @@ void writePatchField // set the filename of the ensight file fileName ensightFileName(timeFile + "." + pfName); - ensightFilePtr = new OFstream - ( - postProcPath/ensightFileName, - runTime.writeFormat(), - runTime.writeVersion(), - runTime.writeCompression() - ); + + if (binary) + { + ensightFilePtr.reset + ( + new ensightBinaryStream + ( + postProcPath/ensightFileName, + runTime + ) + ); + } + else + { + ensightFilePtr.reset + ( + new ensightAsciiStream + ( + postProcPath/ensightFileName, + runTime + ) + ); + } } - OFstream& ensightFile = *ensightFilePtr; + ensightStream& ensightFile = ensightFilePtr(); if (Pstream::master()) { - ensightFile << pTraits<Type>::typeName << nl; + ensightFile.write(pTraits<Type>::typeName); } if (patchi >= 0) @@ -468,26 +334,22 @@ void writePatchField ensightFile ); } - - if (Pstream::master()) - { - delete ensightFilePtr; - } } template<class Type> -void ensightFieldAscii +void ensightField ( - const Foam::IOobject& fieldObject, + const GeometricField<Type, fvPatchField, volMesh>& vf, const Foam::ensightMesh& eMesh, const Foam::fileName& postProcPath, const Foam::word& prepend, const Foam::label timeIndex, + const bool binary, Foam::Ostream& ensightCaseFile ) { - Info<< "Converting field " << fieldObject.name() << endl; + Info<< "Converting field " << vf.name() << endl; word timeFile = prepend + itoa(timeIndex); @@ -512,23 +374,37 @@ void ensightFieldAscii const labelList& hexes = meshCellSets.hexes; const labelList& polys = meshCellSets.polys; - OFstream *ensightFilePtr = NULL; + autoPtr<ensightStream> ensightFilePtr; if (Pstream::master()) { // set the filename of the ensight file - fileName ensightFileName(timeFile + "." + fieldObject.name()); - ensightFilePtr = new OFstream - ( - postProcPath/ensightFileName, - runTime.writeFormat(), - runTime.writeVersion(), - IOstream::UNCOMPRESSED - ); - } + fileName ensightFileName(timeFile + "." + vf.name()); - OFstream& ensightFile = *ensightFilePtr; + if (binary) + { + ensightFilePtr.reset + ( + new ensightBinaryStream + ( + postProcPath/ensightFileName, + runTime + ) + ); + } + else + { + ensightFilePtr.reset + ( + new ensightAsciiStream + ( + postProcPath/ensightFileName, + runTime + ) + ); + } + } - GeometricField<Type, fvPatchField, volMesh> vf(fieldObject, mesh); + ensightStream& ensightFile = ensightFilePtr(); if (patchNames.empty()) { @@ -548,34 +424,26 @@ void ensightFieldAscii << nl; } - ensightFile - << pTraits<Type>::typeName << nl - << "part" << nl - << setw(10) << 1 << nl; - - ensightFile.setf(ios_base::scientific, ios_base::floatfield); - ensightFile.precision(5); + ensightFile.write(pTraits<Type>::typeName); + ensightFile.writePartHeader(1); } if (meshCellSets.nHexesWedges) { if (Pstream::master()) { - ensightFile << "hexa8" << nl; + ensightFile.write("hexa8"); for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; cmpt++) { - writeData - ( - map(vf, hexes, wedges, cmpt), - ensightFile - ); + scalarField masterData(map(vf, hexes, wedges, cmpt)); + ensightFile.write(masterData); for (int slave=1; slave<Pstream::nProcs(); slave++) { IPstream fromSlave(Pstream::scheduled, slave); scalarField data(fromSlave); - writeData(data, ensightFile); + ensightFile.write(data); } } } @@ -727,68 +595,61 @@ void ensightFieldAscii } } } - - if (Pstream::master()) - { - delete ensightFilePtr; - } } template<class Type> -void ensightFieldBinary +void ensightPointField ( - const Foam::IOobject& fieldObject, + const GeometricField<Type, pointPatchField, pointMesh>& pf, const Foam::ensightMesh& eMesh, const Foam::fileName& postProcPath, const Foam::word& prepend, const Foam::label timeIndex, + const bool binary, Foam::Ostream& ensightCaseFile ) { - Info<< "Converting field (binary) " << fieldObject.name() << endl; + Info<< "Converting field " << pf.name() << endl; word timeFile = prepend + itoa(timeIndex); - const fvMesh& mesh = eMesh.mesh(); + //const fvMesh& mesh = eMesh.mesh(); //const Time& runTime = mesh.time(); - const cellSets& meshCellSets = eMesh.meshCellSets(); - const List<faceSets>& boundaryFaceSets = eMesh.boundaryFaceSets(); - const wordList& allPatchNames = eMesh.allPatchNames(); - const wordHashSet& patchNames = eMesh.patchNames(); - const HashTable<ensightMesh::nFacePrimitives>& - nPatchPrims = eMesh.nPatchPrims(); - const List<faceSets>& faceZoneFaceSets = eMesh.faceZoneFaceSets(); - const wordHashSet& faceZoneNames = eMesh.faceZoneNames(); - const HashTable<ensightMesh::nFacePrimitives>& - nFaceZonePrims = eMesh.nFaceZonePrims(); - - const labelList& tets = meshCellSets.tets; - const labelList& pyrs = meshCellSets.pyrs; - const labelList& prisms = meshCellSets.prisms; - const labelList& wedges = meshCellSets.wedges; - const labelList& hexes = meshCellSets.hexes; - const labelList& polys = meshCellSets.polys; - - std::ofstream *ensightFilePtr = NULL; + autoPtr<ensightStream> ensightFilePtr; if (Pstream::master()) { // set the filename of the ensight file - fileName ensightFileName(timeFile + "." + fieldObject.name()); - ensightFilePtr = new std::ofstream - ( - (postProcPath/ensightFileName).c_str(), - ios_base::out | ios_base::binary | ios_base::trunc - ); - // Check on file opened? - } + fileName ensightFileName(timeFile + "." + pf.name()); - std::ofstream& ensightFile = *ensightFilePtr; + if (binary) + { + ensightFilePtr.reset + ( + new ensightBinaryStream + ( + postProcPath/ensightFileName, + eMesh.mesh().time() + ) + ); + } + else + { + ensightFilePtr.reset + ( + new ensightAsciiStream + ( + postProcPath/ensightFileName, + eMesh.mesh().time() + ) + ); + } + } - GeometricField<Type, fvPatchField, volMesh> vf(fieldObject, mesh); + ensightStream& ensightFile = ensightFilePtr(); - if (patchNames.empty()) + if (eMesh.patchNames().empty()) { eMesh.barrier(); @@ -800,193 +661,45 @@ void ensightFieldBinary ensightCaseFile << pTraits<Type>::typeName - << " per element: 1 " - << setw(15) << vf.name() - << (' ' + prepend + "***." + vf.name()).c_str() + << " per node: 1 " + << setw(15) << pf.name() + << (' ' + prepend + "***." + pf.name()).c_str() << nl; } - writeEnsDataBinary(pTraits<Type>::typeName,ensightFile); - writeEnsDataBinary("part",ensightFile); - writeEnsDataBinary(1,ensightFile); + ensightFile.write(pTraits<Type>::typeName); + ensightFile.write("part"); + ensightFile.write(1); } - if (meshCellSets.nHexesWedges) + if (Pstream::master()) { - if (Pstream::master()) - { - writeEnsDataBinary("hexa8",ensightFile); + ensightFile.write("coordinates"); - for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; cmpt++) - { - writeEnsDataBinary - ( - map(vf, hexes, wedges, cmpt), - ensightFile - ); + Field<Type> uniqueFld(pf.internalField(), eMesh.uniquePointMap()); - for (int slave=1; slave<Pstream::nProcs(); slave++) - { - IPstream fromSlave(Pstream::scheduled, slave); - scalarField data(fromSlave); - writeEnsDataBinary(data, ensightFile); - } - } - } - else + for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; cmpt++) { - for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; cmpt++) + ensightFile.write(uniqueFld.component(cmpt)); + + for (int slave=1; slave<Pstream::nProcs(); slave++) { - OPstream toMaster(Pstream::scheduled, Pstream::masterNo()); - toMaster<< map(vf, hexes, wedges, cmpt); + IPstream fromSlave(Pstream::scheduled, slave); + scalarField data(fromSlave); + ensightFile.write(data); } } } - - writeAllDataBinary - ( - "penta6", - vf, - prisms, - meshCellSets.nPrisms, - ensightFile - ); - - writeAllDataBinary - ( - "pyramid5", - vf, - pyrs, - meshCellSets.nPyrs, - ensightFile - ); - - writeAllDataBinary - ( - "tetra4", - vf, - tets, - meshCellSets.nTets, - ensightFile - ); - - writeAllDataBinary - ( - "nfaced", - vf, - polys, - meshCellSets.nPolys, - ensightFile - ); - } - - label ensightPatchI = eMesh.patchPartOffset(); - - forAll(allPatchNames, patchi) - { - const word& patchName = allPatchNames[patchi]; - - eMesh.barrier(); - - if (patchNames.empty() || patchNames.found(patchName)) - { - if - ( - writePatchFieldBinary - ( - vf.boundaryField()[patchi], - patchi, - ensightPatchI, - boundaryFaceSets[patchi], - nPatchPrims.find(patchName)(), - ensightFile - ) - ) - { - ensightPatchI++; - } - } - - } - - // write faceZones, if requested - if (faceZoneNames.size()) - { - // Interpolates cell values to faces - needed only when exporting - // faceZones... - GeometricField<Type, fvsPatchField, surfaceMesh> sf - ( - linearInterpolate(vf) - ); - - forAllConstIter(wordHashSet, faceZoneNames, iter) + else { - const word& faceZoneName = iter.key(); - - eMesh.barrier(); - - label zoneID = mesh.faceZones().findZoneID(faceZoneName); - - const faceZone& fz = mesh.faceZones()[zoneID]; - - // Prepare data to write - label nIncluded = 0; - forAll(fz, i) - { - if (eMesh.faceToBeIncluded(fz[i])) - { - ++nIncluded; - } - } - - Field<Type> values(nIncluded); - - // Loop on the faceZone and store the needed field values - label j = 0; - forAll(fz, i) - { - label faceI = fz[i]; - if (mesh.isInternalFace(faceI)) - { - values[j] = sf[faceI]; - ++j; - } - else - { - if (eMesh.faceToBeIncluded(faceI)) - { - label patchI = mesh.boundaryMesh().whichPatch(faceI); - const polyPatch& pp = mesh.boundaryMesh()[patchI]; - label patchFaceI = pp.whichFace(faceI); - Type value = sf.boundaryField()[patchI][patchFaceI]; - values[j] = value; - ++j; - } - } - } - - if - ( - writePatchFieldBinary - ( - values, - zoneID, - ensightPatchI, - faceZoneFaceSets[zoneID], - nFaceZonePrims.find(faceZoneName)(), - ensightFile - ) - ) + Field<Type> uniqueFld(pf.internalField(), eMesh.uniquePointMap()); + for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; cmpt++) { - ensightPatchI++; + OPstream toMaster(Pstream::scheduled, Pstream::masterNo()); + toMaster<< uniqueFld.component(cmpt); } } } - - if (Pstream::master()) - { - ensightFile.close(); - } } @@ -999,30 +712,42 @@ void ensightField const Foam::word& prepend, const Foam::label timeIndex, const bool binary, + const bool nodeValues, Foam::Ostream& ensightCaseFile ) { - if (binary) + // Read field + GeometricField<Type, fvPatchField, volMesh> vf(fieldObject, eMesh.mesh()); + + if (nodeValues) { - ensightFieldBinary<Type> + tmp<GeometricField<Type, pointPatchField, pointMesh> > pfld ( - fieldObject, + volPointInterpolation::New(eMesh.mesh()).interpolate(vf) + ); + pfld().rename(vf.name()); + + ensightPointField<Type> + ( + pfld, eMesh, postProcPath, prepend, timeIndex, + binary, ensightCaseFile ); } else { - ensightFieldAscii<Type> + ensightField<Type> ( - fieldObject, + vf, eMesh, postProcPath, prepend, timeIndex, + binary, ensightCaseFile ); } diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightMesh.C b/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightMesh.C index 00c733890aa4d0c6f7740b821e55a3224c837de1..c1d36da21086e9770cc800946bc4f3919a1ce1a2 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightMesh.C +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightMesh.C @@ -23,9 +23,9 @@ License \*---------------------------------------------------------------------------*/ +#include "ensightMesh.H" #include "argList.H" #include "Time.H" -#include "ensightMesh.H" #include "fvMesh.H" #include "globalMeshData.H" #include "PstreamCombineReduceOps.H" @@ -33,38 +33,31 @@ License #include "cellModeller.H" #include "IOmanip.H" #include "itoa.H" -#include "ensightWriteBinary.H" #include "globalIndex.H" #include "mapDistribute.H" #include "stringListOps.H" +#include "ensightBinaryStream.H" +#include "ensightAsciiStream.H" + #include <fstream> // * * * * * * * * * * * * * Private Functions * * * * * * * * * * * * * * // -// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // - -Foam::ensightMesh::ensightMesh -( - const fvMesh& mesh, - const argList& args, - const bool binary -) -: - mesh_(mesh), - binary_(binary), - patchPartOffset_(2), - meshCellSets_(mesh_.nCells()), - boundaryFaceSets_(mesh_.boundary().size()), - allPatchNames_(0), - patchNames_(0), - nPatchPrims_(0), - faceZoneFaceSets_(mesh_.faceZones().size()), - faceZoneNames_(0), - nFaceZonePrims_(0), - boundaryFaceToBeIncluded_(0) +void Foam::ensightMesh::correct() { - const cellShapeList& cellShapes = mesh.cellShapes(); + patchPartOffset_ = 2; + meshCellSets_ = mesh_.nCells(); + boundaryFaceSets_.setSize(mesh_.boundary().size()); + allPatchNames_.clear(); + patchNames_.clear(); + nPatchPrims_ = 0; + faceZoneFaceSets_.setSize(mesh_.faceZones().size()); + faceZoneNames_.clear(); + nFaceZonePrims_ = 0; + boundaryFaceToBeIncluded_.clear(); + + const cellShapeList& cellShapes = mesh_.cellShapes(); const cellModel& tet = *(cellModeller::lookup("tet")); const cellModel& pyr = *(cellModeller::lookup("pyr")); @@ -72,7 +65,7 @@ Foam::ensightMesh::ensightMesh const cellModel& wedge = *(cellModeller::lookup("wedge")); const cellModel& hex = *(cellModeller::lookup("hex")); - if (!args.optionFound("noPatches")) + if (!noPatches_) { // Patches are output. Check that they're synced. mesh_.boundaryMesh().checkParallelSync(true); @@ -84,11 +77,9 @@ Foam::ensightMesh::ensightMesh - mesh_.globalData().processorPatches().size() ); - if (args.optionFound("patches")) + if (patches_) { - wordReList patterns(args.optionLookup("patches")()); - - if (patterns.empty()) + if (patchPatterns_.empty()) { forAll(allPatchNames_, nameI) { @@ -101,7 +92,7 @@ Foam::ensightMesh::ensightMesh forAll(allPatchNames_, nameI) { const word& patchName = allPatchNames_[nameI]; - if (findStrings(patterns, patchName)) + if (findStrings(patchPatterns_, patchName)) { patchNames_.insert(patchName); } @@ -184,15 +175,23 @@ Foam::ensightMesh::ensightMesh meshCellSets_.nPolys = nPolys; reduce(meshCellSets_.nPolys, sumOp<label>()); + + + // Determine parallel shared points + globalPointsPtr_ = mesh_.globalData().mergePoints + ( + pointToGlobal_, + uniquePointMap_ + ); } - if (!args.optionFound("noPatches")) + if (!noPatches_) { - forAll(mesh.boundary(), patchi) + forAll(mesh_.boundary(), patchi) { - if (mesh.boundary()[patchi].size()) + if (mesh_.boundary()[patchi].size()) { - const polyPatch& p = mesh.boundaryMesh()[patchi]; + const polyPatch& p = mesh_.boundaryMesh()[patchi]; labelList& tris = boundaryFaceSets_[patchi].tris; labelList& quads = boundaryFaceSets_[patchi].quads; @@ -238,7 +237,7 @@ Foam::ensightMesh::ensightMesh if (patchNames_.empty() || patchNames_.found(patchName)) { - if (mesh.boundary()[patchi].size()) + if (mesh_.boundary()[patchi].size()) { nfp.nTris = boundaryFaceSets_[patchi].tris.size(); nfp.nQuads = boundaryFaceSets_[patchi].quads.size(); @@ -254,17 +253,15 @@ Foam::ensightMesh::ensightMesh } // faceZones - if (args.optionFound("faceZones")) + if (faceZones_) { - wordReList patterns(args.optionLookup("faceZones")()); - const wordList faceZoneNamesAll = mesh_.faceZones().names(); // Find faceZone names which match that requested at command-line forAll(faceZoneNamesAll, nameI) { const word& zoneName = faceZoneNamesAll[nameI]; - if (findStrings(patterns, zoneName)) + if (findStrings(faceZonePatterns_, zoneName)) { faceZoneNames_.insert(zoneName); } @@ -300,7 +297,7 @@ Foam::ensightMesh::ensightMesh { //const word& zoneName = faceZoneNamesAll[zoneI]; - const faceZone& fz = mesh.faceZones()[zoneI]; + const faceZone& fz = mesh_.faceZones()[zoneI]; if (fz.size()) { @@ -380,6 +377,35 @@ Foam::ensightMesh::ensightMesh } +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::ensightMesh::ensightMesh +( + const fvMesh& mesh, + const bool noPatches, + + const bool patches, + const wordReList& patchPatterns, + + const bool faceZones, + const wordReList& faceZonePatterns, + + const bool binary +) +: + mesh_(mesh), + noPatches_(noPatches), + patches_(patches), + patchPatterns_(patchPatterns), + faceZones_(faceZones), + faceZonePatterns_(faceZonePatterns), + binary_(binary), + meshCellSets_(mesh.nCells()) +{ + correct(); +} + + // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // Foam::ensightMesh::~ensightMesh() @@ -412,19 +438,6 @@ void Foam::ensightMesh::barrier() } -void Foam::ensightMesh::writePoints -( - const scalarField& pointsComponent, - OFstream& ensightGeometryFile -) const -{ - forAll(pointsComponent, pointI) - { - ensightGeometryFile<< setw(12) << float(pointsComponent[pointI]) << nl; - } -} - - Foam::cellShapeList Foam::ensightMesh::map ( const cellShapeList& cellShapes, @@ -489,35 +502,10 @@ Foam::cellShapeList Foam::ensightMesh::map void Foam::ensightMesh::writePrims ( const cellShapeList& cellShapes, - OFstream& ensightGeometryFile -) const -{ - forAll(cellShapes, i) - { - const cellShape& cellPoints = cellShapes[i]; - - forAll(cellPoints, pointI) - { - ensightGeometryFile - << setw(10) - << cellPoints[pointI] + 1; - } - ensightGeometryFile << nl; - } -} - - -void Foam::ensightMesh::writePrimsBinary -( - const cellShapeList& cellShapes, - std::ofstream& ensightGeometryFile + ensightStream& ensightGeometryFile ) const { // Create a temp int array - int numElem; - - numElem = cellShapes.size(); - if (cellShapes.size()) { // All the cellShapes have the same number of elements! @@ -536,12 +524,7 @@ void Foam::ensightMesh::writePrimsBinary n++; } } - - ensightGeometryFile.write - ( - reinterpret_cast<char*>(temp.begin()), - numIntElem*sizeof(int) - ); + ensightGeometryFile.write(temp); } } @@ -550,13 +533,12 @@ void Foam::ensightMesh::writePolysNFaces ( const labelList& polys, const cellList& cellFaces, - OFstream& ensightGeometryFile + ensightStream& ensightGeometryFile ) const { forAll(polys, i) { - ensightGeometryFile - << setw(10) << cellFaces[polys[i]].size() << nl; + ensightGeometryFile.write(cellFaces[polys[i]].size()); } } @@ -566,7 +548,7 @@ void Foam::ensightMesh::writePolysNPointsPerFace const labelList& polys, const cellList& cellFaces, const faceList& faces, - OFstream& ensightGeometryFile + ensightStream& ensightGeometryFile ) const { forAll(polys, i) @@ -575,8 +557,7 @@ void Foam::ensightMesh::writePolysNPointsPerFace forAll(cf, faceI) { - ensightGeometryFile - << setw(10) << faces[cf[faceI]].size() << nl; + ensightGeometryFile.write(faces[cf[faceI]].size()); } } } @@ -587,7 +568,7 @@ void Foam::ensightMesh::writePolysPoints const labelList& polys, const cellList& cellFaces, const faceList& faces, - OFstream& ensightGeometryFile + ensightStream& ensightGeometryFile ) const { forAll(polys, i) @@ -598,11 +579,12 @@ void Foam::ensightMesh::writePolysPoints { const face& f = faces[cf[faceI]]; + List<int> temp(f.size()); forAll(f, pointI) { - ensightGeometryFile << setw(10) << f[pointI] + 1; + temp[pointI] = f[pointI] + 1; } - ensightGeometryFile << nl; + ensightGeometryFile.write(temp); } } } @@ -611,7 +593,7 @@ void Foam::ensightMesh::writePolysPoints void Foam::ensightMesh::writeAllPolys ( const labelList& pointToGlobal, - OFstream& ensightGeometryFile + ensightStream& ensightGeometryFile ) const { if (meshCellSets_.nPolys) @@ -626,8 +608,8 @@ void Foam::ensightMesh::writeAllPolys if (Pstream::master()) { - ensightGeometryFile - << "nfaced" << nl << setw(10) << meshCellSets_.nPolys << nl; + ensightGeometryFile.write("nfaced"); + ensightGeometryFile.write(meshCellSets_.nPolys); } // Number of faces for each poly cell @@ -735,150 +717,156 @@ void Foam::ensightMesh::writeAllPolys } -void Foam::ensightMesh::writePolysNFacesBinary +void Foam::ensightMesh::writeAllPrims ( - const labelList& polys, - const cellList& cellFaces, - std::ofstream& ensightGeometryFile + const char* key, + const label nPrims, + const cellShapeList& cellShapes, + ensightStream& ensightGeometryFile ) const { - forAll(polys, i) + if (nPrims) { - writeEnsDataBinary - ( - cellFaces[polys[i]].size(), - ensightGeometryFile - ); - } -} + if (Pstream::master()) + { + ensightGeometryFile.write(key); + ensightGeometryFile.write(nPrims); + writePrims(cellShapes, ensightGeometryFile); -void Foam::ensightMesh::writePolysNPointsPerFaceBinary -( - const labelList& polys, - const cellList& cellFaces, - const faceList& faces, - std::ofstream& ensightGeometryFile -) const -{ - forAll(polys, i) - { - const labelList& cf = cellFaces[polys[i]]; + for (int slave=1; slave<Pstream::nProcs(); slave++) + { + IPstream fromSlave(Pstream::scheduled, slave); + cellShapeList cellShapes(fromSlave); - forAll(cf, faceI) + writePrims(cellShapes, ensightGeometryFile); + } + } + else { - writeEnsDataBinary - ( - faces[cf[faceI]].size(), - ensightGeometryFile - ); + OPstream toMaster(Pstream::scheduled, Pstream::masterNo()); + toMaster<< cellShapes; } } } -void Foam::ensightMesh::writePolysPointsBinary +void Foam::ensightMesh::writeFacePrims ( - const labelList& polys, - const cellList& cellFaces, - const faceList& faces, - std::ofstream& ensightGeometryFile + const faceList& patchFaces, + ensightStream& ensightGeometryFile ) const { - forAll(polys, i) + forAll(patchFaces, i) { - const labelList& cf = cellFaces[polys[i]]; + const face& patchFace = patchFaces[i]; - forAll(cf, faceI) + List<int> temp(patchFace.size()); + forAll(patchFace, pointI) { - const face& f = faces[cf[faceI]]; - - forAll(f, pointI) - { - writeEnsDataBinary(f[pointI] + 1,ensightGeometryFile); - } + temp[pointI] = patchFace[pointI] + 1; } + + ensightGeometryFile.write(temp); } } -void Foam::ensightMesh::writeAllPolysBinary +void Foam::ensightMesh::writeAllFacePrims ( - const labelList& pointToGlobal, - std::ofstream& ensightGeometryFile + const char* key, + const labelList& prims, + const label nPrims, + const faceList& patchFaces, + ensightStream& ensightGeometryFile ) const { - if (meshCellSets_.nPolys) + if (nPrims) { - const cellList& cellFaces = mesh_.cells(); - // Renumber faces to use global point numbers - faceList faces(mesh_.faces()); - forAll(faces, i) - { - inplaceRenumber(pointToGlobal, faces[i]); - } - if (Pstream::master()) { - writeEnsDataBinary("nfaced",ensightGeometryFile); - writeEnsDataBinary(meshCellSets_.nPolys,ensightGeometryFile); - } + ensightGeometryFile.write(key); + ensightGeometryFile.write(nPrims); - // Number of faces for each poly cell - if (Pstream::master()) - { - // Master - writePolysNFacesBinary + writeFacePrims ( - meshCellSets_.polys, - cellFaces, + UIndirectList<face>(patchFaces, prims)(), ensightGeometryFile ); - // Slaves + for (int slave=1; slave<Pstream::nProcs(); slave++) { IPstream fromSlave(Pstream::scheduled, slave); - labelList polys(fromSlave); - cellList cellFaces(fromSlave); + faceList patchFaces(fromSlave); - writePolysNFacesBinary - ( - polys, - cellFaces, - ensightGeometryFile - ); + writeFacePrims(patchFaces, ensightGeometryFile); } } else { OPstream toMaster(Pstream::scheduled, Pstream::masterNo()); - toMaster<< meshCellSets_.polys << cellFaces; + toMaster<< UIndirectList<face>(patchFaces, prims); } + } +} - // Number of points for each face of the above list + +void Foam::ensightMesh::writeNSidedNPointsPerFace +( + const faceList& patchFaces, + ensightStream& ensightGeometryFile +) const +{ + forAll(patchFaces, i) + { + ensightGeometryFile.write(patchFaces[i].size()); + } +} + + +void Foam::ensightMesh::writeNSidedPoints +( + const faceList& patchFaces, + ensightStream& ensightGeometryFile +) const +{ + writeFacePrims(patchFaces, ensightGeometryFile); +} + + +void Foam::ensightMesh::writeAllNSided +( + const labelList& prims, + const label nPrims, + const faceList& patchFaces, + ensightStream& ensightGeometryFile +) const +{ + if (nPrims) + { if (Pstream::master()) { - // Master - writePolysNPointsPerFaceBinary + ensightGeometryFile.write("nsided"); + ensightGeometryFile.write(nPrims); + } + + // Number of points for each face + if (Pstream::master()) + { + writeNSidedNPointsPerFace ( - meshCellSets_.polys, - cellFaces, - faces, + UIndirectList<face>(patchFaces, prims)(), ensightGeometryFile ); - // Slaves + for (int slave=1; slave<Pstream::nProcs(); slave++) { IPstream fromSlave(Pstream::scheduled, slave); - labelList polys(fromSlave); - cellList cellFaces(fromSlave); - faceList faces(fromSlave); + faceList patchFaces(fromSlave); - writePolysNPointsPerFaceBinary + writeNSidedNPointsPerFace ( - polys, - cellFaces, - faces, + patchFaces, ensightGeometryFile ); } @@ -886,977 +874,130 @@ void Foam::ensightMesh::writeAllPolysBinary else { OPstream toMaster(Pstream::scheduled, Pstream::masterNo()); - toMaster<< meshCellSets_.polys << cellFaces << faces; + toMaster<< UIndirectList<face>(patchFaces, prims); } - // List of points id for each face of the above list + // List of points id for each face if (Pstream::master()) { - // Master - writePolysPointsBinary + writeNSidedPoints ( - meshCellSets_.polys, - cellFaces, - faces, + UIndirectList<face>(patchFaces, prims)(), ensightGeometryFile ); - // Slaves + for (int slave=1; slave<Pstream::nProcs(); slave++) { IPstream fromSlave(Pstream::scheduled, slave); - labelList polys(fromSlave); - cellList cellFaces(fromSlave); - faceList faces(fromSlave); + faceList patchFaces(fromSlave); - writePolysPointsBinary - ( - polys, - cellFaces, - faces, - ensightGeometryFile - ); + writeNSidedPoints(patchFaces, ensightGeometryFile); } } else { OPstream toMaster(Pstream::scheduled, Pstream::masterNo()); - toMaster<< meshCellSets_.polys << cellFaces << faces; + toMaster<< UIndirectList<face>(patchFaces, prims); } } } -void Foam::ensightMesh::writeAllPrims +void Foam::ensightMesh::writeAllInternalPoints ( - const char* key, - const label nPrims, - const cellShapeList& cellShapes, - OFstream& ensightGeometryFile + const pointField& uniquePoints, + const label nPoints, + ensightStream& ensightGeometryFile ) const { - if (nPrims) + barrier(); + + if (Pstream::master()) { - if (Pstream::master()) + ensightGeometryFile.writePartHeader(1); + ensightGeometryFile.write("internalMesh"); + ensightGeometryFile.write("coordinates"); + ensightGeometryFile.write(nPoints); + + for (direction d=0; d<vector::nComponents; d++) { - ensightGeometryFile << key << nl << setw(10) << nPrims << nl; + ensightGeometryFile.write(uniquePoints.component(d)); - writePrims(cellShapes, ensightGeometryFile); - - for (int slave=1; slave<Pstream::nProcs(); slave++) - { - IPstream fromSlave(Pstream::scheduled, slave); - cellShapeList cellShapes(fromSlave); - - writePrims(cellShapes, ensightGeometryFile); - } - } - else - { - OPstream toMaster(Pstream::scheduled, Pstream::masterNo()); - toMaster<< cellShapes; - } - } -} - - -void Foam::ensightMesh::writeAllPrimsBinary -( - const char* key, - const label nPrims, - const cellShapeList& cellShapes, - std::ofstream& ensightGeometryFile -) const -{ - if (nPrims) - { - if (Pstream::master()) - { - writeEnsDataBinary(key,ensightGeometryFile); - writeEnsDataBinary(nPrims,ensightGeometryFile); - - writePrimsBinary(cellShapes, ensightGeometryFile); - - for (int slave=1; slave<Pstream::nProcs(); slave++) - { - IPstream fromSlave(Pstream::scheduled, slave); - cellShapeList cellShapes(fromSlave); - - writePrimsBinary(cellShapes, ensightGeometryFile); - } - } - else - { - OPstream toMaster(Pstream::scheduled, Pstream::masterNo()); - toMaster<< cellShapes; - } - } -} - - -void Foam::ensightMesh::writeFacePrims -( - const faceList& patchFaces, - OFstream& ensightGeometryFile -) const -{ - forAll(patchFaces, i) - { - const face& patchFace = patchFaces[i]; - - forAll(patchFace, pointI) - { - ensightGeometryFile << setw(10) << patchFace[pointI] + 1; - } - ensightGeometryFile << nl; - } -} - - -void Foam::ensightMesh::writeFacePrimsBinary -( - const faceList& patchFaces, - std::ofstream& ensightGeometryFile -) const -{ - forAll(patchFaces, i) - { - const face& patchFace = patchFaces[i]; - - forAll(patchFace, pointI) - { - writeEnsDataBinary(patchFace[pointI] + 1, ensightGeometryFile); - } - } -} - - -void Foam::ensightMesh::writeAllFacePrims -( - const char* key, - const labelList& prims, - const label nPrims, - const faceList& patchFaces, - OFstream& ensightGeometryFile -) const -{ - if (nPrims) - { - if (Pstream::master()) - { - ensightGeometryFile << key << nl << setw(10) << nPrims << nl; - - writeFacePrims - ( - UIndirectList<face>(patchFaces, prims)(), - ensightGeometryFile - ); - - for (int slave=1; slave<Pstream::nProcs(); slave++) - { - IPstream fromSlave(Pstream::scheduled, slave); - faceList patchFaces(fromSlave); - - writeFacePrims(patchFaces, ensightGeometryFile); - } - } - else - { - OPstream toMaster(Pstream::scheduled, Pstream::masterNo()); - toMaster<< UIndirectList<face>(patchFaces, prims); - } - } -} - - -void Foam::ensightMesh::writeNSidedNPointsPerFace -( - const faceList& patchFaces, - OFstream& ensightGeometryFile -) const -{ - forAll(patchFaces, i) - { - ensightGeometryFile << setw(10) << patchFaces[i].size() << nl; - } -} - - -void Foam::ensightMesh::writeNSidedPoints -( - const faceList& patchFaces, - OFstream& ensightGeometryFile -) const -{ - writeFacePrims(patchFaces, ensightGeometryFile); -} - - -void Foam::ensightMesh::writeAllNSided -( - const labelList& prims, - const label nPrims, - const faceList& patchFaces, - OFstream& ensightGeometryFile -) const -{ - if (nPrims) - { - if (Pstream::master()) - { - ensightGeometryFile - << "nsided" << nl << setw(10) << nPrims << nl; - } - - // Number of points for each face - if (Pstream::master()) - { - writeNSidedNPointsPerFace - ( - UIndirectList<face>(patchFaces, prims)(), - ensightGeometryFile - ); - - for (int slave=1; slave<Pstream::nProcs(); slave++) - { - IPstream fromSlave(Pstream::scheduled, slave); - faceList patchFaces(fromSlave); - - writeNSidedNPointsPerFace - ( - patchFaces, - ensightGeometryFile - ); - } - } - else - { - OPstream toMaster(Pstream::scheduled, Pstream::masterNo()); - toMaster<< UIndirectList<face>(patchFaces, prims); - } - - // List of points id for each face - if (Pstream::master()) - { - writeNSidedPoints - ( - UIndirectList<face>(patchFaces, prims)(), - ensightGeometryFile - ); - - for (int slave=1; slave<Pstream::nProcs(); slave++) - { - IPstream fromSlave(Pstream::scheduled, slave); - faceList patchFaces(fromSlave); - - writeNSidedPoints(patchFaces, ensightGeometryFile); - } - } - else - { - OPstream toMaster(Pstream::scheduled, Pstream::masterNo()); - toMaster<< UIndirectList<face>(patchFaces, prims); - } - } -} - - -void Foam::ensightMesh::writeNSidedPointsBinary -( - const faceList& patchFaces, - std::ofstream& ensightGeometryFile -) const -{ - writeFacePrimsBinary(patchFaces, ensightGeometryFile); -} - - -void Foam::ensightMesh::writeNSidedNPointsPerFaceBinary -( - const faceList& patchFaces, - std::ofstream& ensightGeometryFile -) const -{ - forAll(patchFaces, i) - { - writeEnsDataBinary(patchFaces[i].size(), ensightGeometryFile); - } -} - - -void Foam::ensightMesh::writeAllNSidedBinary -( - const labelList& prims, - const label nPrims, - const faceList& patchFaces, - std::ofstream& ensightGeometryFile -) const -{ - if (nPrims) - { - if (Pstream::master()) - { - writeEnsDataBinary("nsided",ensightGeometryFile); - writeEnsDataBinary(nPrims,ensightGeometryFile); - } - - // Number of points for each face - if (Pstream::master()) - { - writeNSidedNPointsPerFaceBinary - ( - UIndirectList<face>(patchFaces, prims)(), - ensightGeometryFile - ); - - for (int slave=1; slave<Pstream::nProcs(); slave++) - { - IPstream fromSlave(Pstream::scheduled, slave); - faceList patchFaces(fromSlave); - - writeNSidedNPointsPerFaceBinary - ( - patchFaces, - ensightGeometryFile - ); - } - } - else - { - OPstream toMaster(Pstream::scheduled, Pstream::masterNo()); - toMaster<< UIndirectList<face>(patchFaces, prims); - } - - // List of points id for each face - if (Pstream::master()) - { - writeNSidedPointsBinary - ( - UIndirectList<face>(patchFaces, prims)(), - ensightGeometryFile - ); - - for (int slave=1; slave<Pstream::nProcs(); slave++) - { - IPstream fromSlave(Pstream::scheduled, slave); - faceList patchFaces(fromSlave); - - writeNSidedPointsBinary(patchFaces, ensightGeometryFile); - } - } - else - { - OPstream toMaster(Pstream::scheduled, Pstream::masterNo()); - toMaster<< UIndirectList<face>(patchFaces, prims); - } - } -} - - -void Foam::ensightMesh::writeAllFacePrimsBinary -( - const char* key, - const labelList& prims, - const label nPrims, - const faceList& patchFaces, - std::ofstream& ensightGeometryFile -) const -{ - if (nPrims) - { - if (Pstream::master()) - { - writeEnsDataBinary(key,ensightGeometryFile); - writeEnsDataBinary(nPrims,ensightGeometryFile); - - writeFacePrimsBinary - ( - UIndirectList<face>(patchFaces, prims)(), - ensightGeometryFile - ); - - for (int slave=1; slave<Pstream::nProcs(); slave++) - { - IPstream fromSlave(Pstream::scheduled, slave); - faceList patchFaces(fromSlave); - - writeFacePrimsBinary(patchFaces, ensightGeometryFile); - } - } - else - { - OPstream toMaster(Pstream::scheduled, Pstream::masterNo()); - toMaster<< UIndirectList<face>(patchFaces, prims); - } - } -} - - -void Foam::ensightMesh::write -( - const fileName& postProcPath, - const word& prepend, - const label timeIndex, - Ostream& ensightCaseFile -) const -{ - // Find global point numbering - labelList pointToGlobal; - labelList uniquePointMap; - autoPtr<globalIndex> globalPoints = mesh_.globalData().mergePoints - ( - pointToGlobal, - uniquePointMap - ); - - const pointField uniquePoints(mesh_.points(), uniquePointMap); - - if (binary_) - { - writeBinary - ( - postProcPath, - prepend, - timeIndex, - ensightCaseFile, - pointToGlobal, - uniquePoints, - globalPoints() - ); - } - else - { - writeAscii - ( - postProcPath, - prepend, - timeIndex, - ensightCaseFile, - pointToGlobal, - uniquePoints, - globalPoints() - ); - } -} - -void Foam::ensightMesh::writeAllInternalPoints -( - const pointField& uniquePoints, - const label nPoints, - OFstream& ensightGeometryFile -) const -{ - barrier(); - - if (Pstream::master()) - { - ensightGeometryFile - << "part" << nl - << setw(10) << 1 << nl - << "internalMesh" << nl - << "coordinates" << nl - << setw(10) << nPoints - << endl; - - for (direction d=0; d<vector::nComponents; d++) - { - writePoints(uniquePoints.component(d), ensightGeometryFile); - - for (int slave=1; slave<Pstream::nProcs(); slave++) - { - IPstream fromSlave(Pstream::scheduled, slave); - scalarField pointsComponent(fromSlave); - writePoints(pointsComponent, ensightGeometryFile); - } - } - } - else - { - for (direction d=0; d<vector::nComponents; d++) - { - OPstream toMaster(Pstream::scheduled, Pstream::masterNo()); - toMaster<< uniquePoints.component(d); - } - } -} - -void Foam::ensightMesh::writeAllInternalPointsBinary -( - const pointField& uniquePoints, - const label nPoints, - std::ofstream& ensightGeometryFile -) const -{ - barrier(); - - if (Pstream::master()) - { - writeEnsDataBinary("part",ensightGeometryFile); - writeEnsDataBinary(1,ensightGeometryFile); - writeEnsDataBinary("internalMesh",ensightGeometryFile); - writeEnsDataBinary("coordinates",ensightGeometryFile); - writeEnsDataBinary(nPoints,ensightGeometryFile); - - for (direction d=0; d<vector::nComponents; d++) - { - writeEnsDataBinary - ( - uniquePoints.component(d), - ensightGeometryFile - ); - - for (int slave=1; slave<Pstream::nProcs(); slave++) - { - IPstream fromSlave(Pstream::scheduled, slave); - scalarField pointsComponent(fromSlave); - writeEnsDataBinary(pointsComponent, ensightGeometryFile); - } - } - } - else - { - for (direction d=0; d<vector::nComponents; d++) - { - OPstream toMaster(Pstream::scheduled, Pstream::masterNo()); - toMaster<< uniquePoints.component(d); - } - } -} - -void Foam::ensightMesh::writeAllPatchPoints -( - const label ensightPatchI, - const word& patchName, - const pointField& uniquePoints, - const label nPoints, - OFstream& ensightGeometryFile -) const -{ - barrier(); - - if (Pstream::master()) - { - ensightGeometryFile - << "part" << nl - << setw(10) << ensightPatchI << nl - << patchName << nl - << "coordinates" << nl - << setw(10) << nPoints // globalPointsPtr().size() - << endl; - - for (direction d=0; d<vector::nComponents; d++) - { - writePoints - ( - uniquePoints.component(d), - ensightGeometryFile - ); - - for (int slave=1; slave<Pstream::nProcs(); slave++) - { - IPstream fromSlave(Pstream::scheduled, slave); - scalarField patchPointsComponent(fromSlave); - - writePoints - ( - patchPointsComponent, - ensightGeometryFile - ); - } - } - } - else - { - for (direction d=0; d<vector::nComponents; d++) - { - OPstream toMaster - ( - Pstream::scheduled, - Pstream::masterNo() - ); - toMaster<< uniquePoints.component(d); - } - } -} - -void Foam::ensightMesh::writeAllPatchPointsBinary -( - const label ensightPatchI, - const word& patchName, - const pointField& uniquePoints, - const label nPoints, - std::ofstream& ensightGeometryFile -) const -{ - barrier(); - - if (Pstream::master()) - { - writeEnsDataBinary("part",ensightGeometryFile); - writeEnsDataBinary(ensightPatchI,ensightGeometryFile); - //writeEnsDataBinary(patchName.c_str(),ensightGeometryFile); - writeEnsDataBinary(patchName.c_str(),ensightGeometryFile); - writeEnsDataBinary("coordinates",ensightGeometryFile); - writeEnsDataBinary - ( - nPoints, //globalPointsPtr().size(), - ensightGeometryFile - ); - - for (direction d=0; d<vector::nComponents; d++) - { - //writePointsBinary - writeEnsDataBinary - ( - uniquePoints.component(d), - ensightGeometryFile - ); - - for (int slave=1; slave<Pstream::nProcs(); slave++) - { - IPstream fromSlave(Pstream::scheduled, slave); - scalarField patchPointsComponent(fromSlave); - - //writePointsBinary - writeEnsDataBinary - ( - patchPointsComponent, - ensightGeometryFile - ); - } - } - } - else - { - for (direction d=0; d<vector::nComponents; d++) - { - OPstream toMaster - ( - Pstream::scheduled, - Pstream::masterNo() - ); - toMaster<< uniquePoints.component(d); - } - } -} - -void Foam::ensightMesh::writeAscii -( - const fileName& postProcPath, - const word& prepend, - const label timeIndex, - Ostream& ensightCaseFile, - const labelList& pointToGlobal, - const pointField& uniquePoints, - const globalIndex& globalPoints -) const -{ - const Time& runTime = mesh_.time(); - //const pointField& points = mesh_.points(); - const cellShapeList& cellShapes = mesh_.cellShapes(); - - - word timeFile = prepend; - - if (timeIndex == 0) - { - timeFile += "000."; - } - else if (mesh_.moving()) - { - timeFile += itoa(timeIndex) + '.'; - } - - // set the filename of the ensight file - fileName ensightGeometryFileName = timeFile + "mesh"; - - OFstream *ensightGeometryFilePtr = NULL; - if (Pstream::master()) - { - ensightGeometryFilePtr = new OFstream - ( - postProcPath/ensightGeometryFileName, - runTime.writeFormat(), - runTime.writeVersion(), - IOstream::UNCOMPRESSED - ); - } - - OFstream& ensightGeometryFile = *ensightGeometryFilePtr; - - if (Pstream::master()) - { - // Set Format - ensightGeometryFile.setf - ( - ios_base::scientific, - ios_base::floatfield - ); - ensightGeometryFile.precision(5); - - ensightGeometryFile - << "EnSight Geometry File" << nl - << "written by OpenFOAM-" << Foam::FOAMversion << nl - << "node id assign" << nl - << "element id assign" << nl; - } - - if (patchNames_.empty()) - { - label nPoints = globalPoints.size(); - - writeAllInternalPoints - ( - uniquePoints, - nPoints, - ensightGeometryFile - ); - - writeAllPrims - ( - "hexa8", - meshCellSets_.nHexesWedges, - map // Rewrite cellShapes to global numbering - ( - cellShapes, - meshCellSets_.hexes, - meshCellSets_.wedges, - pointToGlobal - ), - ensightGeometryFile - ); - - writeAllPrims - ( - "penta6", - meshCellSets_.nPrisms, - map(cellShapes, meshCellSets_.prisms, pointToGlobal), - ensightGeometryFile - ); - - writeAllPrims - ( - "pyramid5", - meshCellSets_.nPyrs, - map(cellShapes, meshCellSets_.pyrs, pointToGlobal), - ensightGeometryFile - ); - - writeAllPrims - ( - "tetra4", - meshCellSets_.nTets, - map(cellShapes, meshCellSets_.tets, pointToGlobal), - ensightGeometryFile - ); - - writeAllPolys - ( - pointToGlobal, - ensightGeometryFile - ); + for (int slave=1; slave<Pstream::nProcs(); slave++) + { + IPstream fromSlave(Pstream::scheduled, slave); + scalarField pointsComponent(fromSlave); + ensightGeometryFile.write(pointsComponent); + } + } + } + else + { + for (direction d=0; d<vector::nComponents; d++) + { + OPstream toMaster(Pstream::scheduled, Pstream::masterNo()); + toMaster<< uniquePoints.component(d); + } } +} - label ensightPatchI = patchPartOffset_; +void Foam::ensightMesh::writeAllPatchPoints +( + const label ensightPatchI, + const word& patchName, + const pointField& uniquePoints, + const label nPoints, + ensightStream& ensightGeometryFile +) const +{ + barrier(); - forAll(allPatchNames_, patchi) + if (Pstream::master()) { - const word& patchName = allPatchNames_[patchi]; + ensightGeometryFile.writePartHeader(ensightPatchI); + ensightGeometryFile.write(patchName.c_str()); + ensightGeometryFile.write("coordinates"); + ensightGeometryFile.write(nPoints); - if (patchNames_.empty() || patchNames_.found(patchName)) + for (direction d=0; d<vector::nComponents; d++) { - const nFacePrimitives& nfp = nPatchPrims_[patchName]; - - if (nfp.nTris || nfp.nQuads || nfp.nPolys) + ensightGeometryFile.write(uniquePoints.component(d)); + for (int slave=1; slave<Pstream::nProcs(); slave++) { - const polyPatch& p = mesh_.boundaryMesh()[patchi]; - const labelList& tris = boundaryFaceSets_[patchi].tris; - const labelList& quads = boundaryFaceSets_[patchi].quads; - const labelList& polys = boundaryFaceSets_[patchi].polys; - - // Renumber the patch points/faces into unique points - labelList pointToGlobal; - labelList uniqueMeshPointLabels; - autoPtr<globalIndex> globalPointsPtr = - mesh_.globalData().mergePoints - ( - p.meshPoints(), - p.meshPointMap(), - pointToGlobal, - uniqueMeshPointLabels - ); - - pointField uniquePoints(mesh_.points(), uniqueMeshPointLabels); - // Renumber the patch faces - faceList patchFaces(p.localFaces()); - forAll(patchFaces, i) - { - inplaceRenumber(pointToGlobal, patchFaces[i]); - } - - writeAllPatchPoints - ( - ensightPatchI++, - patchName, - uniquePoints, - globalPointsPtr().size(), - ensightGeometryFile - ); - - writeAllFacePrims - ( - "tria3", - tris, - nfp.nTris, - patchFaces, - ensightGeometryFile - ); - - writeAllFacePrims - ( - "quad4", - quads, - nfp.nQuads, - patchFaces, - ensightGeometryFile - ); - - writeAllNSided - ( - polys, - nfp.nPolys, - patchFaces, - ensightGeometryFile - ); + IPstream fromSlave(Pstream::scheduled, slave); + scalarField patchPointsComponent(fromSlave); + ensightGeometryFile.write(patchPointsComponent); } } } - - // write faceZones, if requested - forAllConstIter(wordHashSet, faceZoneNames_, iter) + else { - const word& faceZoneName = iter.key(); - - label faceID = mesh_.faceZones().findZoneID(faceZoneName); - - const faceZone& fz = mesh_.faceZones()[faceID]; - - const nFacePrimitives& nfp = nFaceZonePrims_[faceZoneName]; - - if (nfp.nTris || nfp.nQuads || nfp.nPolys) + for (direction d=0; d<vector::nComponents; d++) { - const labelList& tris = faceZoneFaceSets_[faceID].tris; - const labelList& quads = faceZoneFaceSets_[faceID].quads; - const labelList& polys = faceZoneFaceSets_[faceID].polys; - - // Renumber the faceZone points/faces into unique points - labelList pointToGlobal; - labelList uniqueMeshPointLabels; - autoPtr<globalIndex> globalPointsPtr = - mesh_.globalData().mergePoints - ( - fz().meshPoints(), - fz().meshPointMap(), - pointToGlobal, - uniqueMeshPointLabels - ); - - pointField uniquePoints(mesh_.points(), uniqueMeshPointLabels); - - // Find the list of master faces belonging to the faceZone, - // in loacal numbering - faceList faceZoneFaces(fz().localFaces()); - - // Count how many master faces belong to the faceZone. Is there - // a better way of doing this? - label nMasterFaces = 0; - - forAll(fz, faceI) - { - if (faceToBeIncluded(fz[faceI])) - { - ++nMasterFaces; - } - } - - // Create the faceList for the master faces only and fill it. - faceList faceZoneMasterFaces(nMasterFaces); - - label currentFace = 0; - - forAll(fz, faceI) - { - if (faceToBeIncluded(fz[faceI])) - { - faceZoneMasterFaces[currentFace] = faceZoneFaces[faceI]; - ++currentFace; - } - } - - // Renumber the faceZone master faces - forAll(faceZoneMasterFaces, i) - { - inplaceRenumber(pointToGlobal, faceZoneMasterFaces[i]); - } - - writeAllPatchPoints - ( - ensightPatchI++, - faceZoneName, - uniquePoints, - globalPointsPtr().size(), - ensightGeometryFile - ); - - writeAllFacePrims - ( - "tria3", - tris, - nfp.nTris, - faceZoneMasterFaces, - ensightGeometryFile - ); - - writeAllFacePrims - ( - "quad4", - quads, - nfp.nQuads, - faceZoneMasterFaces, - ensightGeometryFile - ); - - writeAllNSided + OPstream toMaster ( - polys, - nfp.nPolys, - faceZoneMasterFaces, - ensightGeometryFile + Pstream::scheduled, + Pstream::masterNo() ); + toMaster<< uniquePoints.component(d); } } - - - if (Pstream::master()) - { - delete ensightGeometryFilePtr; - } } -void Foam::ensightMesh::writeBinary +void Foam::ensightMesh::write ( const fileName& postProcPath, const word& prepend, const label timeIndex, - Ostream& ensightCaseFile, - const labelList& pointToGlobal, - const pointField& uniquePoints, - const globalIndex& globalPoints + Ostream& ensightCaseFile ) const { + const Time& runTime = mesh_.time(); const cellShapeList& cellShapes = mesh_.cellShapes(); + word timeFile = prepend; if (timeIndex == 0) @@ -1871,43 +1012,60 @@ void Foam::ensightMesh::writeBinary // set the filename of the ensight file fileName ensightGeometryFileName = timeFile + "mesh"; - std::ofstream *ensightGeometryFilePtr = NULL; - + autoPtr<ensightStream> ensightGeometryFilePtr; if (Pstream::master()) { - ensightGeometryFilePtr = new std::ofstream - ( - (postProcPath/ensightGeometryFileName).c_str(), - ios_base::out | ios_base::binary | ios_base::trunc - ); - // Check on file opened? + if (binary_) + { + ensightGeometryFilePtr.reset + ( + new ensightBinaryStream + ( + postProcPath/ensightGeometryFileName, + runTime + ) + ); + ensightGeometryFilePtr().write("C binary"); + } + else + { + ensightGeometryFilePtr.reset + ( + new ensightAsciiStream + ( + postProcPath/ensightGeometryFileName, + runTime + ) + ); + } } - std::ofstream& ensightGeometryFile = *ensightGeometryFilePtr; + ensightStream& ensightGeometryFile = ensightGeometryFilePtr(); if (Pstream::master()) { - string description = string("written by OpenFOAM-") + Foam::FOAMversion; - writeEnsDataBinary("C binary", ensightGeometryFile); - writeEnsDataBinary("EnSight Geometry File", ensightGeometryFile); - writeEnsDataBinary(description.c_str(), ensightGeometryFile); - writeEnsDataBinary("node id assign", ensightGeometryFile); - writeEnsDataBinary("element id assign", ensightGeometryFile); - } + string desc = string("written by OpenFOAM-") + Foam::FOAMversion; + ensightGeometryFile.write("EnSight Geometry File"); + ensightGeometryFile.write(desc.c_str()); + ensightGeometryFile.write("node id assign"); + ensightGeometryFile.write("element id assign"); + } if (patchNames_.empty()) { - label nPoints = globalPoints.size(); + label nPoints = globalPoints().size(); - writeAllInternalPointsBinary + const pointField uniquePoints(mesh_.points(), uniquePointMap_); + + writeAllInternalPoints ( uniquePoints, nPoints, ensightGeometryFile ); - writeAllPrimsBinary + writeAllPrims ( "hexa8", meshCellSets_.nHexesWedges, @@ -1916,53 +1074,52 @@ void Foam::ensightMesh::writeBinary cellShapes, meshCellSets_.hexes, meshCellSets_.wedges, - pointToGlobal + pointToGlobal_ ), ensightGeometryFile ); - writeAllPrimsBinary + writeAllPrims ( "penta6", meshCellSets_.nPrisms, - map(cellShapes, meshCellSets_.prisms, pointToGlobal), + map(cellShapes, meshCellSets_.prisms, pointToGlobal_), ensightGeometryFile ); - writeAllPrimsBinary + writeAllPrims ( "pyramid5", meshCellSets_.nPyrs, - map(cellShapes, meshCellSets_.pyrs, pointToGlobal), + map(cellShapes, meshCellSets_.pyrs, pointToGlobal_), ensightGeometryFile ); - writeAllPrimsBinary + writeAllPrims ( "tetra4", meshCellSets_.nTets, - map(cellShapes, meshCellSets_.tets, pointToGlobal), + map(cellShapes, meshCellSets_.tets, pointToGlobal_), ensightGeometryFile ); - writeAllPolysBinary + writeAllPolys ( - pointToGlobal, + pointToGlobal_, ensightGeometryFile ); } + label ensightPatchI = patchPartOffset_; - label iCount = 0; forAll(allPatchNames_, patchi) { - iCount ++; const word& patchName = allPatchNames_[patchi]; if (patchNames_.empty() || patchNames_.found(patchName)) { - const nFacePrimitives& nfp = nPatchPrims_.find(patchName)(); + const nFacePrimitives& nfp = nPatchPrims_[patchName]; if (nfp.nTris || nfp.nQuads || nfp.nPolys) { @@ -1982,6 +1139,7 @@ void Foam::ensightMesh::writeBinary pointToGlobal, uniqueMeshPointLabels ); + pointField uniquePoints(mesh_.points(), uniqueMeshPointLabels); // Renumber the patch faces faceList patchFaces(p.localFaces()); @@ -1990,7 +1148,7 @@ void Foam::ensightMesh::writeBinary inplaceRenumber(pointToGlobal, patchFaces[i]); } - writeAllPatchPointsBinary + writeAllPatchPoints ( ensightPatchI++, patchName, @@ -1999,7 +1157,7 @@ void Foam::ensightMesh::writeBinary ensightGeometryFile ); - writeAllFacePrimsBinary + writeAllFacePrims ( "tria3", tris, @@ -2008,7 +1166,7 @@ void Foam::ensightMesh::writeBinary ensightGeometryFile ); - writeAllFacePrimsBinary + writeAllFacePrims ( "quad4", quads, @@ -2017,7 +1175,7 @@ void Foam::ensightMesh::writeBinary ensightGeometryFile ); - writeAllNSidedBinary + writeAllNSided ( polys, nfp.nPolys, @@ -2090,13 +1248,12 @@ void Foam::ensightMesh::writeBinary } // Renumber the faceZone master faces - forAll(faceZoneMasterFaces, i) { inplaceRenumber(pointToGlobal, faceZoneMasterFaces[i]); } - writeAllPatchPointsBinary + writeAllPatchPoints ( ensightPatchI++, faceZoneName, @@ -2105,7 +1262,7 @@ void Foam::ensightMesh::writeBinary ensightGeometryFile ); - writeAllFacePrimsBinary + writeAllFacePrims ( "tria3", tris, @@ -2114,7 +1271,7 @@ void Foam::ensightMesh::writeBinary ensightGeometryFile ); - writeAllFacePrimsBinary + writeAllFacePrims ( "quad4", quads, @@ -2123,7 +1280,7 @@ void Foam::ensightMesh::writeBinary ensightGeometryFile ); - writeAllNSidedBinary + writeAllNSided ( polys, nfp.nPolys, @@ -2132,12 +1289,6 @@ void Foam::ensightMesh::writeBinary ); } } - - - if (Pstream::master()) - { - delete ensightGeometryFilePtr; - } } diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightMesh.H b/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightMesh.H index 46442efc59992983a7d02a26750a31268a10d95c..f7db81bbc13ca4dfbe05741a21a46d1580cb169a 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightMesh.H +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightMesh.H @@ -38,10 +38,13 @@ SourceFiles #include "faceSets.H" #include "HashTable.H" #include "HashSet.H" -#include "fvMesh.H" -#include "OFstream.H" -#include <fstream> #include "PackedBoolList.H" +#include "wordReList.H" +#include "scalarField.H" +#include "cellShapeList.H" +#include "cellList.H" + +#include <fstream> // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -51,6 +54,7 @@ namespace Foam class fvMesh; class argList; class globalIndex; +class ensightStream; /*---------------------------------------------------------------------------*\ Class ensightMesh Declaration @@ -82,8 +86,19 @@ private: //- Reference to the OpenFOAM mesh const fvMesh& mesh_; + //- Suppress patches + const bool noPatches_; + + //- Output selected patches only + const bool patches_; + const wordReList patchPatterns_; + + //- Output selected faceZones + const bool faceZones_; + const wordReList faceZonePatterns_; + //- Set binary file output - bool binary_; + const bool binary_; //- The ensight part id for the first patch label patchPartOffset_; @@ -109,6 +124,19 @@ private: PackedBoolList boundaryFaceToBeIncluded_; + // Parallel merged points + + //- Global numbering for merged points + autoPtr<globalIndex> globalPointsPtr_; + + //- From mesh point to global merged point + labelList pointToGlobal_; + + //- Local points that are unique + labelList uniquePointMap_; + + + // Private Member Functions //- Disallow default bitwise copy construct @@ -120,7 +148,7 @@ private: void writePoints ( const scalarField& pointsComponent, - OFstream& ensightGeometryFile + ensightStream& ensightGeometryFile ) const; cellShapeList map @@ -141,14 +169,14 @@ private: void writePrims ( const cellShapeList& cellShapes, - OFstream& ensightGeometryFile + ensightStream& ensightGeometryFile ) const; void writePolysNFaces ( const labelList& polys, const cellList& cellFaces, - OFstream& ensightGeometryFile + ensightStream& ensightGeometryFile ) const; void writePolysNPointsPerFace @@ -156,7 +184,7 @@ private: const labelList& polys, const cellList& cellFaces, const faceList& faces, - OFstream& ensightGeometryFile + ensightStream& ensightGeometryFile ) const; void writePolysPoints @@ -164,13 +192,13 @@ private: const labelList& polys, const cellList& cellFaces, const faceList& faces, - OFstream& ensightGeometryFile + ensightStream& ensightGeometryFile ) const; void writeAllPolys ( const labelList& pointToGlobal, - OFstream& ensightGeometryFile + ensightStream& ensightGeometryFile ) const; void writeAllPrims @@ -178,13 +206,13 @@ private: const char* key, const label nPrims, const cellShapeList& cellShapes, - OFstream& ensightGeometryFile + ensightStream& ensightGeometryFile ) const; void writeFacePrims ( const faceList& patchFaces, - OFstream& ensightGeometryFile + ensightStream& ensightGeometryFile ) const; void writeAllFacePrims @@ -193,19 +221,19 @@ private: const labelList& prims, const label nPrims, const faceList& patchFaces, - OFstream& ensightGeometryFile + ensightStream& ensightGeometryFile ) const; void writeNSidedNPointsPerFace ( const faceList& patchFaces, - OFstream& ensightGeometryFile + ensightStream& ensightGeometryFile ) const; void writeNSidedPoints ( const faceList& patchFaces, - OFstream& ensightGeometryFile + ensightStream& ensightGeometryFile ) const; void writeAllNSided @@ -213,14 +241,14 @@ private: const labelList& prims, const label nPrims, const faceList& patchFaces, - OFstream& ensightGeometryFile + ensightStream& ensightGeometryFile ) const; void writeAllInternalPoints ( const pointField& uniquePoints, const label nPoints, - OFstream& ensightGeometryFile + ensightStream& ensightGeometryFile ) const; void writeAllPatchPoints @@ -229,123 +257,7 @@ private: const word& patchName, const pointField& uniquePoints, const label nPoints, - OFstream& ensightGeometryFile - ) const; - - void writeAllInternalPointsBinary - ( - const pointField& uniquePoints, - const label nPoints, - std::ofstream& ensightGeometryFile - ) const; - - void writeAllPatchPointsBinary - ( - label ensightPatchI, - const word& patchName, - const pointField& uniquePoints, - const label nPoints, - std::ofstream& ensightGeometryFile - ) const; - - void writeAscii - ( - const fileName& postProcPath, - const word& prepend, - const label timeIndex, - Ostream& ensightCaseFile, - const labelList& pointToGlobal, - const pointField& uniquePoints, - const globalIndex& globalPoints - ) const; - - void writeBinary - ( - const fileName& postProcPath, - const word& prepend, - const label timeIndex, - Ostream& ensightCaseFile, - const labelList& pointToGlobal, - const pointField& uniquePoints, - const globalIndex& globalPoints - ) const; - - void writePrimsBinary - ( - const cellShapeList& cellShapes, - std::ofstream& ensightGeometryFile - ) const; - - void writeAllPrimsBinary - ( - const char* key, - const label nPrims, - const cellShapeList& cellShapes, - std::ofstream& ensightGeometryFile - ) const; - - void writePolysNFacesBinary - ( - const labelList& polys, - const cellList& cellFaces, - std::ofstream& ensightGeometryFile - ) const; - - void writePolysNPointsPerFaceBinary - ( - const labelList& polys, - const cellList& cellFaces, - const faceList& faces, - std::ofstream& ensightGeometryFile - ) const; - - void writePolysPointsBinary - ( - const labelList& polys, - const cellList& cellFaces, - const faceList& faces, - std::ofstream& ensightGeometryFile - ) const; - - void writeAllPolysBinary - ( - const labelList& pointToGlobal, - std::ofstream& ensightGeometryFile - ) const; - - void writeAllFacePrimsBinary - ( - const char* key, - const labelList& prims, - const label nPrims, - const faceList& patchFaces, - std::ofstream& ensightGeometryFile - ) const; - - void writeFacePrimsBinary - ( - const faceList& patchFaces, - std::ofstream& ensightGeometryFile - ) const; - - void writeNSidedPointsBinary - ( - const faceList& patchFaces, - std::ofstream& ensightGeometryFile - ) const; - - void writeNSidedNPointsPerFaceBinary - ( - const faceList& patchFaces, - std::ofstream& ensightGeometryFile - ) const; - - void writeAllNSidedBinary - ( - const labelList& prims, - const label nPrims, - const faceList& patchFaces, - std::ofstream& ensightGeometryFile + ensightStream& ensightGeometryFile ) const; public: @@ -355,8 +267,12 @@ public: //- Construct from fvMesh ensightMesh ( - const fvMesh&, - const argList& args, + const fvMesh& mesh, + const bool noPatches, + const bool patches, + const wordReList& patchPatterns, + const bool faceZones, + const wordReList& faceZonePatterns, const bool binary ); @@ -420,8 +336,35 @@ public: return patchPartOffset_; } + + // Parallel point merging + + //- Global numbering for merged points + const globalIndex& globalPoints() const + { + return globalPointsPtr_(); + } + + //- From mesh point to global merged point + const labelList& pointToGlobal() const + { + return pointToGlobal_; + } + + //- Local points that are unique + const labelList& uniquePointMap() const + { + return uniquePointMap_; + } + + + + // Other + //- Update for new mesh + void correct(); + //- When exporting faceZones, check if a given face has to be included // or not (i.e. faces on processor boundaries) bool faceToBeIncluded(const label faceI) const; diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightStream.H b/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightStream.H new file mode 100644 index 0000000000000000000000000000000000000000..60be47dcdab822895eb6356e478f0a72e427aa63 --- /dev/null +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightStream.H @@ -0,0 +1,112 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2010-2010 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 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/>. + +Class + Foam::ensightStream + +Description + Abstract base class for writing Ensight data + +SourceFiles + ensightStream.C + +\*---------------------------------------------------------------------------*/ + +#ifndef ensightStream_H +#define ensightStream_H + +#include "fileName.H" +#include "scalarField.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + + +/*---------------------------------------------------------------------------*\ + Class ensightStream Declaration +\*---------------------------------------------------------------------------*/ + +class ensightStream +{ + // Private data + + const fileName name_; + + // Private Member Functions + + //- Disallow default bitwise copy construct + ensightStream(const ensightStream&); + + //- Disallow default bitwise assignment + void operator=(const ensightStream&); + + +public: + + // Constructors + + //- Construct from components + ensightStream(const fileName& f) + : + name_(f) + {} + + + //- Destructor + virtual ~ensightStream() + {} + + + // Member Functions + + const fileName& name() const + { + return name_; + } + + virtual void write(const char*) = 0; + + virtual void write(const int) = 0; + + virtual void write(const scalarField&) = 0; + + virtual void write(const List<int>&) = 0; + + virtual void writePartHeader(const label) = 0; + + + +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightWriteBinary.C b/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightWriteBinary.C deleted file mode 100644 index bd3c2342fadb96575d71506ab540fd6adbed375f..0000000000000000000000000000000000000000 --- a/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightWriteBinary.C +++ /dev/null @@ -1,78 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 1991-2010 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 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 "ensightWriteBinary.H" -#include <fstream> - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -void writeEnsDataBinary -( - const char* val, - std::ofstream& ensFile -) -{ - char buffer[80] = {0}; - strcpy(buffer, val); - ensFile.write(buffer, 80*sizeof(char)); -} - - -void writeEnsDataBinary -( - const int val, - std::ofstream& ensFile -) -{ - ensFile.write(reinterpret_cast<const char*>(&val), sizeof(int)); -} - - -void writeEnsDataBinary -( - const scalarField& sf, - std::ofstream& ensightFile -) -{ - if (sf.size()) - { - List<float> temp(sf.size()); - - forAll(sf, i) - { - temp[i] = float(sf[i]); - } - - ensightFile.write - ( - reinterpret_cast<char*>(temp.begin()), - sf.size()*sizeof(float) - ); - } -} - - -// ************************************************************************* // - diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightWriteBinary.H b/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightWriteBinary.H deleted file mode 100644 index e29a823e15927489e6b799fafb25d2e54b04f2b1..0000000000000000000000000000000000000000 --- a/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightWriteBinary.H +++ /dev/null @@ -1,67 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 1991-2010 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 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/>. - -InApplication - foamToEnsight - -Description - Collection of functions for binary write in EnSight files - -SourceFiles - ensightWriteBinary.C - -\*---------------------------------------------------------------------------*/ - -#ifndef ensightWriteBinary_H -#define ensightWriteBinary_H - -#include "ensightMesh.H" - -using namespace Foam; - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -void writeEnsDataBinary -( - const char* val, - std::ofstream& ensFile -); - -void writeEnsDataBinary -( - const int val, - std::ofstream& ensFile -); - - -void writeEnsDataBinary -( - const scalarField& sf, - std::ofstream& ensightFile -); - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -#endif - -// ************************************************************************* // diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsight/faceSets.H b/applications/utilities/postProcessing/dataConversion/foamToEnsight/faceSets.H index edf25fa34df1242f2f5495b1619c4087989997cd..f5d396b86eb0d78a992b2a39f2a90feb89bdd8fb 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToEnsight/faceSets.H +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsight/faceSets.H @@ -44,15 +44,6 @@ namespace Foam class faceSets { - // Private Member Functions - - //- Disallow default bitwise copy construct - faceSets(const faceSets&); - - //- Disallow default bitwise assignment - void operator=(const faceSets&); - - public: label nTris; diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsight/foamToEnsight.C b/applications/utilities/postProcessing/dataConversion/foamToEnsight/foamToEnsight.C index dff5d8b8c8e7902a787ba2fcfd857e9944e65a5a..ba2bfccf9af6ab31ff67bfe0bd3e54136c709791 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToEnsight/foamToEnsight.C +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsight/foamToEnsight.C @@ -104,6 +104,11 @@ int main(int argc, char *argv[]) "write in ASCII format instead of 'C Binary'" ); argList::addBoolOption + ( + "nodeValues", + "write values in nodes" + ); + argList::addBoolOption ( "noPatches", "suppress writing any patches" @@ -126,6 +131,7 @@ int main(int argc, char *argv[]) // Check options const bool binary = !args.optionFound("ascii"); + const bool nodeValues = args.optionFound("nodeValues"); # include "createTime.H" @@ -191,7 +197,29 @@ int main(int argc, char *argv[]) OFstream& ensightCaseFile = *ensightCaseFilePtr; // Construct the EnSight mesh - ensightMesh eMesh(mesh, args, binary); + const bool selectedPatches = args.optionFound("patches"); + wordReList patchPatterns; + if (selectedPatches) + { + patchPatterns = wordReList(args.optionLookup("patches")()); + } + const bool selectedZones = args.optionFound("faceZones"); + wordReList zonePatterns; + if (selectedZones) + { + zonePatterns = wordReList(args.optionLookup("faceZones")()); + } + + ensightMesh eMesh + ( + mesh, + args.optionFound("noPatches"), + selectedPatches, + patchPatterns, + selectedZones, + zonePatterns, + binary + ); // Set Time to the last time before looking for the lagrangian objects runTime.setTime(Times.last(), Times.size()-1); @@ -313,6 +341,11 @@ int main(int argc, char *argv[]) polyMesh::readUpdateState meshState = mesh.readUpdate(); + if (meshState != polyMesh::UNCHANGED) + { + eMesh.correct(); + } + if (timeIndex == 0 || (meshState != polyMesh::UNCHANGED)) { eMesh.write @@ -371,6 +404,7 @@ int main(int argc, char *argv[]) prepend, timeIndex, binary, + nodeValues, ensightCaseFile ); } @@ -384,6 +418,7 @@ int main(int argc, char *argv[]) prepend, timeIndex, binary, + nodeValues, ensightCaseFile ); } @@ -397,6 +432,7 @@ int main(int argc, char *argv[]) prepend, timeIndex, binary, + nodeValues, ensightCaseFile ); } @@ -410,6 +446,7 @@ int main(int argc, char *argv[]) prepend, timeIndex, binary, + nodeValues, ensightCaseFile ); } @@ -423,6 +460,7 @@ int main(int argc, char *argv[]) prepend, timeIndex, binary, + nodeValues, ensightCaseFile ); }