diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsight/Make/files b/applications/utilities/postProcessing/dataConversion/foamToEnsight/Make/files new file mode 100644 index 0000000000000000000000000000000000000000..d4c28fa64c22fa63601bda7d6b73dca4956b45b3 --- /dev/null +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsight/Make/files @@ -0,0 +1,8 @@ +itoa.C +ensightMesh.C +ensightParticlePositions.C +foamToEnsight.C +ensightWriteBinary.C + +EXE = $(FOAM_APPBIN)/foamToEnsight +//EXE = $(FOAM_USER_APPBIN)/foamToEnsight diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsight/Make/options b/applications/utilities/postProcessing/dataConversion/foamToEnsight/Make/options new file mode 100644 index 0000000000000000000000000000000000000000..db2e26ca8b94e9e522bd34952181e5e0aa00d780 --- /dev/null +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsight/Make/options @@ -0,0 +1,8 @@ +EXE_INC = \ + -I$(LIB_SRC)/finiteVolume/lnInclude \ + -I$(LIB_SRC)/lagrangian/basic/lnInclude + +EXE_LIBS = \ + -lfiniteVolume \ + -llagrangian \ + diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsight/cellSets.H b/applications/utilities/postProcessing/dataConversion/foamToEnsight/cellSets.H new file mode 100644 index 0000000000000000000000000000000000000000..72859dff2b442cdb16eaf026c1a67026bdf8cbf1 --- /dev/null +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsight/cellSets.H @@ -0,0 +1,102 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2007 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 + +Class + Foam::cellSets + +Description + +\*---------------------------------------------------------------------------*/ + +#ifndef cellSets_H +#define cellSets_H + +#include "labelList.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class cellSets Declaration +\*---------------------------------------------------------------------------*/ + +class cellSets +{ + // Private Member Functions + + //- Disallow default bitwise copy construct + cellSets(const cellSets&); + + //- Disallow default bitwise assignment + void operator=(const cellSets&); + + +public: + + label nHexesWedges; + label nPrisms; + label nPyrs; + label nTets; + label nPolys; + + labelList tets; + labelList pyrs; + labelList prisms; + labelList wedges; + labelList hexes; + labelList polys; + + + // Constructors + + //- Construct given the number ov cells + cellSets(const label nCells) + : + nHexesWedges(0), + nPrisms(0), + nPyrs(0), + nTets(0), + nPolys(0), + + tets(nCells), + pyrs(nCells), + prisms(nCells), + wedges(nCells), + hexes(nCells), + polys(nCells) + {} +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsight/checkData.H b/applications/utilities/postProcessing/dataConversion/foamToEnsight/checkData.H new file mode 100644 index 0000000000000000000000000000000000000000..59be3c5dc9ffda60e2ceaae872a7054b797b68f3 --- /dev/null +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsight/checkData.H @@ -0,0 +1,18 @@ +for (int n1=startTime; n1<endTime; n1++) +{ + if (fieldName.size() > 2 && fieldName(fieldName.size() - 2, 2) == "_0") + { + variableGood = false; + break; + } + + IOobject fieldObjectHeader + ( + fieldName, + Times[n1].name(), + mesh, + IOobject::NO_READ + ); + + variableGood = variableGood && fieldObjectHeader.headerOk(); +} diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsight/checkMeshMoving.H b/applications/utilities/postProcessing/dataConversion/foamToEnsight/checkMeshMoving.H new file mode 100644 index 0000000000000000000000000000000000000000..e6e46c8f868adf8e382f53d6c36228051f44fcf0 --- /dev/null +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsight/checkMeshMoving.H @@ -0,0 +1,21 @@ +bool meshMoving = true; + +if (Times.size() > 2) +{ + for(label n2=2; n2<Times.size(); n2++) + { + IOobject tmpPoints + ( + "points", + Times[n2].name(), + polyMesh::meshSubDir, + mesh, + IOobject::NO_READ + ); + meshMoving = meshMoving && tmpPoints.headerOk(); + } +} +else +{ + meshMoving = false; +} diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsight/checkSprayData.H b/applications/utilities/postProcessing/dataConversion/foamToEnsight/checkSprayData.H new file mode 100644 index 0000000000000000000000000000000000000000..6a581184dc7d273c89b9f08a25334f8e65a488ed --- /dev/null +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsight/checkSprayData.H @@ -0,0 +1,13 @@ +forAll(Times, n1) +{ + IOobject fieldObjectHeader + ( + fieldName, + Times[n1].name(), + "lagrangian", + mesh, + IOobject::NO_READ + ); + + variableGood = variableGood && fieldObjectHeader.headerOk(); +} diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightCaseHeader.H b/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightCaseHeader.H new file mode 100644 index 0000000000000000000000000000000000000000..cc81cb465952ed52026b274d56375de627f45134 --- /dev/null +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightCaseHeader.H @@ -0,0 +1,5 @@ +if (Pstream::master()) +{ + ensightCaseFile << "FORMAT" << nl; + ensightCaseFile << "type: ensight gold" << nl << nl; +} diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightCaseTail.H b/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightCaseTail.H new file mode 100644 index 0000000000000000000000000000000000000000..43c1a3f801bcf9f3373de9bace53b32a790d66d6 --- /dev/null +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightCaseTail.H @@ -0,0 +1,33 @@ +if (Pstream::master()) +{ + ensightCaseFile << nl << "TIME" << nl + << "time set: " << 1 << nl + << "number of steps: " << nTimeSteps << nl + << "filename start number: " << 0 << nl + << "filename increment: " << 1 << nl; + + ensightCaseFile << "time values:" << nl; + + ensightCaseFile.setf(ios_base::scientific, ios_base::floatfield); + ensightCaseFile.precision(5); + + label count = 0; + scalar Tcorr = 0.0; + if (Times[0].value() < 0) + { + Tcorr = - Times[0].value(); + Info << "Correcting time values. Adding " << Tcorr << endl; + } + + for (int n=startTime; n<endTime; n++) + { + ensightCaseFile << setw(12) << Times[n].value() + Tcorr << " "; + + if (++count % 6 == 0) + { + ensightCaseFile << nl; + } + } + + ensightCaseFile << nl; +} diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightField.C b/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightField.C new file mode 100644 index 0000000000000000000000000000000000000000..4561a0b07787c36001adb15aa862a2e1c5aae8aa --- /dev/null +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightField.C @@ -0,0 +1,898 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2007 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<class Type> +scalarField map +( + const Field<Type>& vf, + const labelList& map, + const label cmpt +) +{ + scalarField mf(map.size()); + + forAll(map, i) + { + mf[i] = component(vf[map[i]], cmpt); + } + + return mf; +} + + +template<class Type> +scalarField map +( + const Field<Type>& 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<class Type> +void writeAllData +( + const char* key, + 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 +) +{ + if (nPrims) + { + if (Pstream::master()) + { + writeEnsDataBinary(key,ensightFile); + + for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; cmpt++) + { + writeEnsDataBinary(map(vf, prims, cmpt), ensightFile); + + 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++) + { + OPstream toMaster(Pstream::scheduled, Pstream::masterNo()); + toMaster<< map(vf, prims, cmpt); + } + } + } +} + + + +template<class Type> +void writeAllFaceData +( + const char* key, + const labelList& prims, + const label nPrims, + const Field<Type>& pf, + const labelList& patchProcessors, + OFstream& ensightFile +) +{ + if (nPrims) + { + if (Pstream::master()) + { + ensightFile << key << nl; + + for (direction cmpt=0; cmpt<pTraits<Type>::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<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, + const labelList& patchProcessors, + 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); + + 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<pTraits<Type>::nComponents; cmpt++) + { + OPstream toMaster(Pstream::scheduled, Pstream::masterNo()); + toMaster<< map(pf, prims, cmpt); + } + } + } +} + + +template<class Type> +bool writePatchField +( + const Foam::Field<Type>& pf, + const Foam::label patchi, + const Foam::label ensightPatchi, + const Foam::faceSets& boundaryFaceSet, + const Foam::ensightMesh::nFacePrims& 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<class Type> +bool writePatchFieldBinary +( + const Foam::Field<Type>& pf, + const Foam::label patchi, + const Foam::label ensightPatchi, + const Foam::faceSets& boundaryFaceSet, + const Foam::ensightMesh::nFacePrims& 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<class Type> +void writePatchField +( + const Foam::word& fieldName, + const Foam::Field<Type>& 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<faceSets>& boundaryFaceSets = eMesh.boundaryFaceSets; + const HashTable<labelList>& allPatchNames = eMesh.allPatchNames; + const HashTable<label>& patchIndices = eMesh.patchIndices; + const HashTable<ensightMesh::nFacePrims>& nPatchPrims = eMesh.nPatchPrims; + + label patchi = -1; + + if (patchIndices.found(patchName)) + { + patchi = patchIndices.find(patchName)(); + } + + label ensightPatchi = 2; + + for + ( + HashTable<labelList>::const_iterator iter = + allPatchNames.begin(); + iter != allPatchNames.end(); + ++iter + ) + { + if (iter.key() == patchName) break; + ensightPatchi++; + } + + + const labelList& patchProcessors = allPatchNames.find(patchName)(); + + word pfName = patchName + '.' + fieldName; + + word timeFile = prepend + itoa(timeIndex); + + OFstream *ensightFilePtr = NULL; + if (Pstream::master()) + { + if (timeIndex == 0) + { + ensightCaseFile.setf(ios_base::left); + + ensightCaseFile + << pTraits<Type>::typeName + << " per element: 1 " + << setw(15) << pfName + << (' ' + prepend + "***." + pfName).c_str() + << nl; + } + + // set the filename of the ensight file + fileName ensightFileName(timeFile + "." + pfName); + ensightFilePtr = new OFstream + ( + postProcPath/ensightFileName, + runTime.writeFormat(), + runTime.writeVersion(), + runTime.writeCompression() + ); + } + + OFstream& ensightFile = *ensightFilePtr; + + if (Pstream::master()) + { + ensightFile << pTraits<Type>::typeName << nl; + } + + if (patchi >= 0) + { + writePatchField + ( + pf, + patchi, + ensightPatchi, + boundaryFaceSets[patchi], + nPatchPrims.find(patchName)(), + patchProcessors, + ensightFile + ); + } + else + { + faceSets nullFaceSets; + + writePatchField + ( + Field<Type>(), + -1, + ensightPatchi, + nullFaceSets, + nPatchPrims.find(patchName)(), + patchProcessors, + ensightFile + ); + } + + if (Pstream::master()) + { + delete ensightFilePtr; + } +} + +template<class Type> +void ensightFieldAscii +( + const Foam::IOobject& fieldObject, + const Foam::ensightMesh& eMesh, + const Foam::fileName& postProcPath, + const Foam::word& prepend, + const Foam::label timeIndex, + Foam::Ostream& ensightCaseFile +) +{ + Info<< "Converting field " << fieldObject.name() << endl; + + word timeFile = prepend + itoa(timeIndex); + + const fvMesh& mesh = eMesh.mesh; + const Time& runTime = mesh.time(); + + const cellSets& meshCellSets = eMesh.meshCellSets; + const List<faceSets>& boundaryFaceSets = eMesh.boundaryFaceSets; + const HashTable<labelList>& allPatchNames = eMesh.allPatchNames; + const HashTable<label>& patchIndices = eMesh.patchIndices; + const wordHashSet& patchNames = eMesh.patchNames; + const HashTable<ensightMesh::nFacePrims>& nPatchPrims = eMesh.nPatchPrims; + + 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; + + OFstream *ensightFilePtr = NULL; + if (Pstream::master()) + { + // set the filename of the ensight file + fileName ensightFileName(timeFile + "." + fieldObject.name()); + ensightFilePtr = new OFstream + ( + postProcPath/ensightFileName, + runTime.writeFormat(), + runTime.writeVersion(), + runTime.writeCompression() + ); + } + + OFstream& ensightFile = *ensightFilePtr; + + GeometricField<Type, fvPatchField, volMesh> vf(fieldObject, mesh); + + if (!patchNames.size()) + { + if (Pstream::master()) + { + if (timeIndex == 0) + { + ensightCaseFile.setf(ios_base::left); + + ensightCaseFile + << pTraits<Type>::typeName + << " per element: 1 " + << setw(15) << vf.name() + << (' ' + prepend + "***." + vf.name()).c_str() + << nl; + } + + ensightFile + << pTraits<Type>::typeName << nl + << "part" << nl + << setw(10) << 1 << nl; + + ensightFile.setf(ios_base::scientific, ios_base::floatfield); + ensightFile.precision(5); + } + + if (meshCellSets.nHexesWedges) + { + if (Pstream::master()) + { + ensightFile << "hexa8" << nl; + + for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; cmpt++) + { + writeData + ( + map(vf, hexes, wedges, 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, hexes, wedges, cmpt); + } + } + } + + writeAllData("penta6", vf, prisms, meshCellSets.nPrisms, ensightFile); + writeAllData("pyramid5", vf, pyrs, meshCellSets.nPyrs, ensightFile); + writeAllData("tetra4", vf, tets, meshCellSets.nTets, ensightFile); + writeAllData("nfaced", vf, polys, meshCellSets.nPolys, ensightFile); + } + + label ensightPatchi = 2; + + for + ( + HashTable<labelList>::const_iterator iter = allPatchNames.begin(); + iter != allPatchNames.end(); + ++iter + ) + { + const word& patchName = iter.key(); + const labelList& patchProcessors = iter(); + + if (!patchNames.size() || patchNames.found(patchName)) + { + if (patchIndices.found(patchName)) + { + label patchi = patchIndices.find(patchName)(); + + if + ( + writePatchField + ( + vf.boundaryField()[patchi], + patchi, + ensightPatchi, + boundaryFaceSets[patchi], + nPatchPrims.find(patchName)(), + patchProcessors, + ensightFile + ) + ) + { + ensightPatchi++; + } + + } + else if (Pstream::master()) + { + faceSets nullFaceSet; + + if + ( + writePatchField + ( + Field<Type>(), + -1, + ensightPatchi, + nullFaceSet, + nPatchPrims.find(patchName)(), + patchProcessors, + ensightFile + ) + ) + { + ensightPatchi++; + } + } + } + } + + if (Pstream::master()) + { + delete ensightFilePtr; + } +} + + +template<class Type> +void ensightFieldBinary +( + const Foam::IOobject& fieldObject, + const Foam::ensightMesh& eMesh, + const Foam::fileName& postProcPath, + const Foam::word& prepend, + const Foam::label timeIndex, + Foam::Ostream& ensightCaseFile +) +{ + Info<< "Converting field (binary) " << fieldObject.name() << endl; + + word timeFile = prepend + itoa(timeIndex); + + const fvMesh& mesh = eMesh.mesh; + //const Time& runTime = mesh.time(); + + const cellSets& meshCellSets = eMesh.meshCellSets; + const List<faceSets>& boundaryFaceSets = eMesh.boundaryFaceSets; + const HashTable<labelList>& allPatchNames = eMesh.allPatchNames; + const HashTable<label>& patchIndices = eMesh.patchIndices; + const wordHashSet& patchNames = eMesh.patchNames; + const HashTable<ensightMesh::nFacePrims>& nPatchPrims = eMesh.nPatchPrims; + + 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; + 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? + } + + std::ofstream& ensightFile = *ensightFilePtr; + + GeometricField<Type, fvPatchField, volMesh> vf(fieldObject, mesh); + + if (!patchNames.size()) + { + if (Pstream::master()) + { + if (timeIndex == 0) + { + ensightCaseFile.setf(ios_base::left); + + ensightCaseFile + << pTraits<Type>::typeName + << " per element: 1 " + << setw(15) << vf.name() + << (' ' + prepend + "***." + vf.name()).c_str() + << nl; + } + + writeEnsDataBinary(pTraits<Type>::typeName,ensightFile); + writeEnsDataBinary("part",ensightFile); + writeEnsDataBinary(1,ensightFile); + } + + if (meshCellSets.nHexesWedges) + { + if (Pstream::master()) + { + writeEnsDataBinary("hexa8",ensightFile); + + for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; cmpt++) + { + writeEnsDataBinary + ( + map(vf, hexes, wedges, cmpt), + ensightFile + ); + + 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++) + { + OPstream toMaster(Pstream::scheduled, Pstream::masterNo()); + toMaster<< map(vf, hexes, wedges, cmpt); + } + } + } + + 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 = 2; + + for + ( + HashTable<labelList>::const_iterator iter = allPatchNames.begin(); + iter != allPatchNames.end(); + ++iter + ) + { + const word& patchName = iter.key(); + const labelList& patchProcessors = iter(); + + if (!patchNames.size() || patchNames.found(patchName)) + { + if (patchIndices.found(patchName)) + { + label patchi = patchIndices.find(patchName)(); + + if + ( + writePatchFieldBinary + ( + vf.boundaryField()[patchi], + patchi, + ensightPatchi, + boundaryFaceSets[patchi], + nPatchPrims.find(patchName)(), + patchProcessors, + ensightFile + ) + ) + { + ensightPatchi++; + } + + } + else if (Pstream::master()) + { + faceSets nullFaceSet; + + if + ( + writePatchFieldBinary + ( + Field<Type>(), + -1, + ensightPatchi, + nullFaceSet, + nPatchPrims.find(patchName)(), + patchProcessors, + ensightFile + ) + ) + { + ensightPatchi++; + } + } + } + } + + if (Pstream::master()) + { + ensightFile.close(); + } +} + +template<class Type> +void ensightField +( + const Foam::IOobject& fieldObject, + const Foam::ensightMesh& eMesh, + const Foam::fileName& postProcPath, + const Foam::word& prepend, + const Foam::label timeIndex, + const bool binary, + Foam::Ostream& ensightCaseFile +) +{ + if (binary) + { + ensightFieldBinary<Type> + ( + fieldObject, + eMesh, + postProcPath, + prepend, + timeIndex, + ensightCaseFile + ); + } + else + { + ensightFieldAscii<Type> + ( + fieldObject, + eMesh, + postProcPath, + prepend, + timeIndex, + ensightCaseFile + ); + } +} + + +// ************************************************************************* // diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightField.H b/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightField.H new file mode 100644 index 0000000000000000000000000000000000000000..2b860365ddaf3fa614959725bc81449070b072de --- /dev/null +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightField.H @@ -0,0 +1,80 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2007 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 + +InApplication + foamToEnsight + +Description + +SourceFiles + ensightField.C + +\*---------------------------------------------------------------------------*/ + +#ifndef ensightField_H +#define ensightField_H + +#include "ensightMesh.H" +#include "HashSet.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +template<class Type> +void ensightField +( + const Foam::IOobject& fieldObject, + const Foam::ensightMesh& eMesh, + const Foam::fileName& postProcPath, + const Foam::word& prepend, + const Foam::label timeIndex, + const bool binary, + Foam::Ostream& ensightCaseFile +); + + +template<class Type> +void writePatchField +( + const Foam::word& fieldName, + const Foam::Field<Type>& pf, + const Foam::word& patchName, + const Foam::ensightMesh& eMesh, + const Foam::fileName& postProcPath, + const Foam::word& prepend, + const Foam::label timeIndex, + Foam::Ostream& ensightCaseFile +); + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository +# include "ensightField.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightMesh.C b/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightMesh.C new file mode 100644 index 0000000000000000000000000000000000000000..6aad34abea22dd433b9122132cb99449994388d1 --- /dev/null +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightMesh.C @@ -0,0 +1,1533 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2007 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 "argList.H" +#include "Time.H" +#include "ensightMesh.H" +#include "fvMesh.H" +#include "PstreamCombineReduceOps.H" +#include "processorPolyPatch.H" +#include "cellModeller.H" +#include "IOmanip.H" +#include "itoa.H" +#include "ensightWriteBinary.H" +#include <fstream> + +// * * * * * * * * * * * * * Private Functions * * * * * * * * * * * * * * // + +namespace Foam +{ + +class concatPatchNames +{ + +public: + + void operator() + ( + HashTable<labelList>& x, + const HashTable<labelList>& y + ) const + { + for + ( + HashTable<labelList>::const_iterator iter = y.begin(); + iter != y.end(); + ++iter + ) + { + HashTable<labelList>::iterator xiter = x.find(iter.key()); + + if (xiter == x.end()) + { + x.insert(iter.key(), iter()); + } + else + { + labelList& xPatches = xiter(); + const labelList& yPatches = iter(); + + label offset = xPatches.size(); + xPatches.setSize(offset + yPatches.size()); + + forAll(yPatches, i) + { + xPatches[i + offset] = yPatches[i]; + } + } + } + } +}; + +} // End namespace Foam + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::ensightMesh::ensightMesh +( + const fvMesh& fMesh, + const argList& args, + const bool binary +) +: + binary_(binary), + mesh(fMesh), + meshCellSets(mesh.nCells()), + boundaryFaceSets(mesh.boundary().size()) +{ + forAll (mesh.boundaryMesh(), patchi) + { + if (typeid(mesh.boundaryMesh()[patchi]) != typeid(processorPolyPatch)) + { + if (!allPatchNames.found(mesh.boundaryMesh()[patchi].name())) + { + allPatchNames.insert + ( + mesh.boundaryMesh()[patchi].name(), + labelList(1, Pstream::myProcNo()) + ); + + patchIndices.insert + ( + mesh.boundaryMesh()[patchi].name(), + patchi + ); + } + } + } + + combineReduce(allPatchNames, concatPatchNames()); + + if (args.options().found("patches")) + { + wordList patchNameList(IStringStream(args.options()["patches"])()); + + if (!patchNameList.size()) + { + patchNameList = allPatchNames.toc(); + } + + forAll (patchNameList, i) + { + patchNames.insert(patchNameList[i]); + } + } + + const cellShapeList& cellShapes = mesh.cellShapes(); + + const cellModel& tet = *(cellModeller::lookup("tet")); + const cellModel& pyr = *(cellModeller::lookup("pyr")); + const cellModel& prism = *(cellModeller::lookup("prism")); + const cellModel& wedge = *(cellModeller::lookup("wedge")); + const cellModel& hex = *(cellModeller::lookup("hex")); + + labelList& tets = meshCellSets.tets; + labelList& pyrs = meshCellSets.pyrs; + labelList& prisms = meshCellSets.prisms; + labelList& wedges = meshCellSets.wedges; + labelList& hexes = meshCellSets.hexes; + labelList& polys = meshCellSets.polys; + + // Count the shapes + label nTets = 0; + label nPyrs = 0; + label nPrisms = 0; + label nWedges = 0; + label nHexes = 0; + label nPolys = 0; + + if (!patchNames.size()) + { + forAll(cellShapes, celli) + { + const cellShape& cellShape = cellShapes[celli]; + const cellModel& cellModel = cellShape.model(); + + if (cellModel == tet) + { + tets[nTets++] = celli; + } + else if (cellModel == pyr) + { + pyrs[nPyrs++] = celli; + } + else if (cellModel == prism) + { + prisms[nPrisms++] = celli; + } + else if (cellModel == wedge) + { + wedges[nWedges++] = celli; + } + else if (cellModel == hex) + { + hexes[nHexes++] = celli; + } + else + { + polys[nPolys++] = celli; + } + } + + tets.setSize(nTets); + pyrs.setSize(nPyrs); + prisms.setSize(nPrisms); + wedges.setSize(nWedges); + hexes.setSize(nHexes); + polys.setSize(nPolys); + + meshCellSets.nTets = nTets; + reduce(meshCellSets.nTets, sumOp<label>()); + + meshCellSets.nPyrs = nPyrs; + reduce(meshCellSets.nPyrs, sumOp<label>()); + + meshCellSets.nPrisms = nPrisms; + reduce(meshCellSets.nPrisms, sumOp<label>()); + + meshCellSets.nHexesWedges = nHexes + nWedges; + reduce(meshCellSets.nHexesWedges, sumOp<label>()); + + meshCellSets.nPolys = nPolys; + reduce(meshCellSets.nPolys, sumOp<label>()); + } + + + forAll (mesh.boundary(), patchi) + { + if (mesh.boundary()[patchi].size()) + { + const polyPatch& p = mesh.boundaryMesh()[patchi]; + + labelList& tris = boundaryFaceSets[patchi].tris; + labelList& quads = boundaryFaceSets[patchi].quads; + labelList& polys = boundaryFaceSets[patchi].polys; + + tris.setSize(p.size()); + quads.setSize(p.size()); + polys.setSize(p.size()); + + label nTris = 0; + label nQuads = 0; + label nPolys = 0; + + forAll(p, facei) + { + const face& f = p[facei]; + + if (f.size() == 3) + { + tris[nTris++] = facei; + } + else if (f.size() == 4) + { + quads[nQuads++] = facei; + } + else + { + polys[nPolys++] = facei; + } + } + + tris.setSize(nTris); + quads.setSize(nQuads); + polys.setSize(nPolys); + } + } + + for + ( + HashTable<labelList>::const_iterator iter = allPatchNames.begin(); + iter != allPatchNames.end(); + ++iter + ) + { + const word& patchName = iter.key(); + nFacePrims nfp; + + if (!patchNames.size() || patchNames.found(patchName)) + { + if (patchIndices.found(patchName)) + { + label patchi = patchIndices.find(patchName)(); + + nfp.nPoints = mesh.boundaryMesh()[patchi].localPoints().size(); + nfp.nTris = boundaryFaceSets[patchi].tris.size(); + nfp.nQuads = boundaryFaceSets[patchi].quads.size(); + nfp.nPolys = boundaryFaceSets[patchi].polys.size(); + } + } + + reduce(nfp.nPoints, sumOp<label>()); + reduce(nfp.nTris, sumOp<label>()); + reduce(nfp.nQuads, sumOp<label>()); + reduce(nfp.nPolys, sumOp<label>()); + + nPatchPrims.insert(patchName, nfp); + } +} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::ensightMesh::~ensightMesh() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +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, + const labelList& prims +) const +{ + cellShapeList mcsl(prims.size()); + + forAll(prims, i) + { + mcsl[i] = cellShapes[prims[i]]; + } + + return mcsl; +} + + +Foam::cellShapeList Foam::ensightMesh::map +( + const cellShapeList& cellShapes, + const labelList& hexes, + const labelList& wedges +) const +{ + cellShapeList mcsl(hexes.size() + wedges.size()); + + forAll(hexes, i) + { + mcsl[i] = cellShapes[hexes[i]]; + } + + label offset = hexes.size(); + + const cellModel& hex = *(cellModeller::lookup("hex")); + labelList hexLabels(8); + + forAll(wedges, i) + { + const cellShape& cellPoints = cellShapes[wedges[i]]; + + hexLabels[0] = cellPoints[0]; + hexLabels[1] = cellPoints[1]; + hexLabels[2] = cellPoints[0]; + hexLabels[3] = cellPoints[2]; + hexLabels[4] = cellPoints[3]; + hexLabels[5] = cellPoints[4]; + hexLabels[6] = cellPoints[6]; + hexLabels[7] = cellPoints[5]; + + mcsl[i + offset] = cellShape(hex, hexLabels); + } + + return mcsl; +} + + +void Foam::ensightMesh::writePrims +( + const cellShapeList& cellShapes, + const label pointOffset, + OFstream& ensightGeometryFile +) const +{ + label po = pointOffset + 1; + + forAll(cellShapes, i) + { + const cellShape& cellPoints = cellShapes[i]; + + forAll(cellPoints, pointi) + { + ensightGeometryFile<< setw(10) << cellPoints[pointi] + po; + } + ensightGeometryFile << nl; + } +} + + +void Foam::ensightMesh::writePrimsBinary +( + const cellShapeList& cellShapes, + const label pointOffset, + std::ofstream& ensightGeometryFile +) const +{ + label po = pointOffset + 1; + + // Create a temp int array + int numElem; + + numElem = cellShapes.size(); + + if (cellShapes.size() > 0) + { + // All the cellShapes have the same number of elements! + int numIntElem = cellShapes.size() * cellShapes[0].size(); + List<int> temp(numIntElem); + + int n = 0; + + forAll(cellShapes, i) + { + const cellShape& cellPoints = cellShapes[i]; + + forAll(cellPoints, pointi) + { + temp[n] = cellPoints[pointi] + po; + n++; + } + } + + ensightGeometryFile.write + ( + reinterpret_cast<char*>(temp.begin()), + numIntElem*sizeof(int) + ); + } +} + + +void Foam::ensightMesh::writePolys +( + const labelList& polys, + const cellList& cellFaces, + const faceList& faces, + const label pointOffset, + OFstream& ensightGeometryFile +) const +{ + if (polys.size()) + { + ensightGeometryFile + << "nfaced" << nl << setw(10) << polys.size() << nl; + + label po = pointOffset + 1; + + forAll(polys, i) + { + ensightGeometryFile + << setw(10) << cellFaces[polys[i]].size() << nl; + } + + forAll(polys, i) + { + const labelList& cf = cellFaces[polys[i]]; + + forAll(cf, facei) + { + ensightGeometryFile + << setw(10) << faces[cf[facei]].size() << nl; + } + } + + forAll(polys, i) + { + const labelList& cf = cellFaces[polys[i]]; + + forAll(cf, facei) + { + const face& f = faces[cf[facei]]; + + forAll(f, pointi) + { + ensightGeometryFile << setw(10) << f[pointi] + po; + } + ensightGeometryFile << nl; + } + } + } +} + + +void Foam::ensightMesh::writePolysBinary +( + const labelList& polys, + const cellList& cellFaces, + const faceList& faces, + const label pointOffset, + std::ofstream& ensightGeometryFile +) const +{ + if (polys.size()) + { + writeEnsDataBinary("nfaced",ensightGeometryFile); + writeEnsDataBinary(polys.size(),ensightGeometryFile); + + label po = pointOffset + 1; + + //TODO No buffer at the moment. To be done for speed purposes! + forAll(polys, i) + { + writeEnsDataBinary + ( + cellFaces[polys[i]].size(), + ensightGeometryFile + ); + } + + forAll(polys, i) + { + const labelList& cf = cellFaces[polys[i]]; + + forAll(cf, facei) + { + writeEnsDataBinary + ( + faces[cf[facei]].size(), + ensightGeometryFile + ); + } + } + + forAll(polys, i) + { + const labelList& cf = cellFaces[polys[i]]; + + forAll(cf, facei) + { + const face& f = faces[cf[facei]]; + + forAll(f, pointi) + { + writeEnsDataBinary(f[pointi] + po,ensightGeometryFile); + } + } + } + } +} + + +void Foam::ensightMesh::writeAllPrims +( + const char* key, + const label nPrims, + const cellShapeList& cellShapes, + const labelList& pointOffsets, + OFstream& ensightGeometryFile +) const +{ + if (nPrims) + { + if (Pstream::master()) + { + ensightGeometryFile << key << nl << setw(10) << nPrims << nl; + + writePrims(cellShapes, 0, ensightGeometryFile); + + for (int slave=1; slave<Pstream::nProcs(); slave++) + { + IPstream fromSlave(Pstream::scheduled, slave); + cellShapeList cellShapes(fromSlave); + + writePrims + ( + cellShapes, + pointOffsets[slave-1], + ensightGeometryFile + ); + } + } + else + { + OPstream toMaster(Pstream::scheduled, Pstream::masterNo()); + toMaster<< cellShapes; + } + } +} + + +void Foam::ensightMesh::writeAllPrimsBinary +( + const char* key, + const label nPrims, + const cellShapeList& cellShapes, + const labelList& pointOffsets, + std::ofstream& ensightGeometryFile +) const +{ + if (nPrims) + { + if (Pstream::master()) + { + writeEnsDataBinary(key,ensightGeometryFile); + writeEnsDataBinary(nPrims,ensightGeometryFile); + + writePrimsBinary(cellShapes, 0, ensightGeometryFile); + + for (int slave=1; slave<Pstream::nProcs(); slave++) + { + IPstream fromSlave(Pstream::scheduled, slave); + cellShapeList cellShapes(fromSlave); + + writePrimsBinary + ( + cellShapes, + pointOffsets[slave-1], + ensightGeometryFile + ); + } + } + else + { + OPstream toMaster(Pstream::scheduled, Pstream::masterNo()); + toMaster<< cellShapes; + } + } +} + + +void Foam::ensightMesh::writeFacePrims +( + const char* key, + const faceList& patchFaces, + const label pointOffset, + OFstream& ensightGeometryFile +) const +{ + if (patchFaces.size()) + { + if (word(key) == "nsided") + { + ensightGeometryFile + << key << nl << setw(10) << patchFaces.size() << nl; + + forAll(patchFaces, i) + { + ensightGeometryFile + << setw(10) << patchFaces[i].size() << nl; + } + } + + label po = pointOffset + 1; + + forAll(patchFaces, i) + { + const face& patchFace = patchFaces[i]; + + forAll(patchFace, pointi) + { + ensightGeometryFile << setw(10) << patchFace[pointi] + po; + } + ensightGeometryFile << nl; + } + } +} + + +void Foam::ensightMesh::writeFacePrimsBinary +( + const char* key, + const faceList& patchFaces, + const label pointOffset, + std::ofstream& ensightGeometryFile +) const +{ + if (patchFaces.size()) + { + //TODO No buffer at the moment. To be done for speed purposes! + if (word(key) == "nsided") + { + writeEnsDataBinary(key,ensightGeometryFile); + writeEnsDataBinary(patchFaces.size(),ensightGeometryFile); + + forAll(patchFaces, i) + { + writeEnsDataBinary + ( + patchFaces[i].size(), + ensightGeometryFile + ); + } + } + + label po = pointOffset + 1; + + forAll(patchFaces, i) + { + const face& patchFace = patchFaces[i]; + + forAll(patchFace, pointi) + { + writeEnsDataBinary + ( + patchFace[pointi] + po, + ensightGeometryFile + ); + } + } + } +} + + +Foam::faceList Foam::ensightMesh::map +( + const faceList& patchFaces, + const labelList& prims +) const +{ + faceList ppf(prims.size()); + + forAll (prims, i) + { + ppf[i] = patchFaces[prims[i]]; + } + + return ppf; +} + + +void Foam::ensightMesh::writeAllFacePrims +( + const char* key, + const labelList& prims, + const label nPrims, + const faceList& patchFaces, + const labelList& pointOffsets, + const labelList& patchProcessors, + OFstream& ensightGeometryFile +) const +{ + if (nPrims) + { + if (Pstream::master()) + { + if (word(key) != "nsided") + { + ensightGeometryFile << key << nl << setw(10) << nPrims << nl; + } + + if (&prims != NULL) + { + writeFacePrims + ( + key, + map(patchFaces, prims), + 0, + ensightGeometryFile + ); + } + + forAll (patchProcessors, i) + { + if (patchProcessors[i] != 0) + { + label slave = patchProcessors[i]; + IPstream fromSlave(Pstream::scheduled, slave); + faceList patchFaces(fromSlave); + + writeFacePrims + ( + key, + patchFaces, + pointOffsets[i], + ensightGeometryFile + ); + } + } + } + else if (&prims != NULL) + { + OPstream toMaster(Pstream::scheduled, Pstream::masterNo()); + toMaster<< map(patchFaces, prims); + } + } +} + + +void Foam::ensightMesh::writeAllFacePrimsBinary +( + const char* key, + const labelList& prims, + const label nPrims, + const faceList& patchFaces, + const labelList& pointOffsets, + const labelList& patchProcessors, + std::ofstream& ensightGeometryFile +) const +{ + if (nPrims) + { + if (Pstream::master()) + { + if (word(key) != "nsided") + { + writeEnsDataBinary(key,ensightGeometryFile); + writeEnsDataBinary(nPrims,ensightGeometryFile); + } + + if (&prims != NULL) + { + writeFacePrimsBinary + ( + key, + map(patchFaces, prims), + 0, + ensightGeometryFile + ); + } + + forAll (patchProcessors, i) + { + if (patchProcessors[i] != 0) + { + label slave = patchProcessors[i]; + IPstream fromSlave(Pstream::scheduled, slave); + faceList patchFaces(fromSlave); + + writeFacePrimsBinary + ( + key, + patchFaces, + pointOffsets[i], + ensightGeometryFile + ); + } + } + } + else if (&prims != NULL) + { + OPstream toMaster(Pstream::scheduled, Pstream::masterNo()); + toMaster<< map(patchFaces, prims); + } + } +} + + +void Foam::ensightMesh::write +( + const fileName& postProcPath, + const word& prepend, + const label timeIndex, + Ostream& ensightCaseFile +) const +{ + if (binary_) + { + writeBinary(postProcPath, prepend, timeIndex, ensightCaseFile); + } + else + { + writeAscii(postProcPath, prepend, timeIndex, ensightCaseFile); + } +} + + +void Foam::ensightMesh::writeAscii +( + const fileName& postProcPath, + const word& prepend, + const label timeIndex, + Ostream& ensightCaseFile +) const +{ + const Time& runTime = mesh.time(); + const pointField& points = mesh.points(); + const cellList& cellFaces = mesh.cells(); + const faceList& faces = mesh.faces(); + 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(), + runTime.writeCompression() + ); + } + + OFstream& ensightGeometryFile = *ensightGeometryFilePtr; + + if (Pstream::master()) + { + // Set Format + ensightGeometryFile.setf + ( + ios_base::scientific, + ios_base::floatfield + ); + ensightGeometryFile.precision(5); + + ensightGeometryFile + << "OpenFOAM Geometry File " << nl + << "OpenFOAM version " << Foam::FOAMversion << nl + << "node id assign" << nl + << "element id assign" << nl; + } + + labelList pointOffsets(Pstream::nProcs(), 0); + + if (!patchNames.size()) + { + label nPoints = points.size(); + Pstream::gather(nPoints, sumOp<label>()); + + if (Pstream::master()) + { + ensightGeometryFile + << "part" << nl + << setw(10) << 1 << nl + << "FOAM cells" << nl + << "coordinates" << nl + << setw(10) << nPoints + << endl; + + for (direction d=0; d<vector::nComponents; d++) + { + writePoints(points.component(d), ensightGeometryFile); + pointOffsets[0] = points.size(); + + for (int slave=1; slave<Pstream::nProcs(); slave++) + { + IPstream fromSlave(Pstream::scheduled, slave); + scalarField pointsComponent(fromSlave); + writePoints(pointsComponent, ensightGeometryFile); + pointOffsets[slave] = + pointOffsets[slave-1] + + pointsComponent.size(); + } + } + } + else + { + for (direction d=0; d<vector::nComponents; d++) + { + OPstream toMaster(Pstream::scheduled, Pstream::masterNo()); + toMaster<< points.component(d); + } + } + + writeAllPrims + ( + "hexa8", + meshCellSets.nHexesWedges, + map(cellShapes, meshCellSets.hexes, meshCellSets.wedges), + pointOffsets, + ensightGeometryFile + ); + + writeAllPrims + ( + "penta6", + meshCellSets.nPrisms, + map(cellShapes, meshCellSets.prisms), + pointOffsets, + ensightGeometryFile + ); + + writeAllPrims + ( + "pyramid5", + meshCellSets.nPyrs, + map(cellShapes, meshCellSets.pyrs), + pointOffsets, + ensightGeometryFile + ); + + writeAllPrims + ( + "tetra4", + meshCellSets.nTets, + map(cellShapes, meshCellSets.tets), + pointOffsets, + ensightGeometryFile + ); + + + if (meshCellSets.nPolys) + { + if (Pstream::master()) + { + /* + ensightGeometryFile + << "nfaced" << nl + << setw(10) << meshCellSets.nPolys << nl; + */ + writePolys + ( + meshCellSets.polys, + cellFaces, + faces, + 0, + ensightGeometryFile + ); + + for (int slave=1; slave<Pstream::nProcs(); slave++) + { + IPstream fromSlave(Pstream::scheduled, slave); + labelList polys(fromSlave); + cellList cellFaces(fromSlave); + faceList faces(fromSlave); + + writePolys + ( + polys, + cellFaces, + faces, + pointOffsets[slave-1], + ensightGeometryFile + ); + } + } + else + { + OPstream toMaster(Pstream::scheduled, Pstream::masterNo()); + toMaster<< meshCellSets.polys << cellFaces << faces; + } + } + } + + + label ensightPatchi = 2; + + for + ( + HashTable<labelList>::const_iterator iter = allPatchNames.begin(); + iter != allPatchNames.end(); + ++iter + ) + { + const labelList& patchProcessors = iter(); + + if (!patchNames.size() || patchNames.found(iter.key())) + { + const word& patchName = iter.key(); + const nFacePrims& nfp = nPatchPrims.find(patchName)(); + + const labelList *trisPtr = NULL; + const labelList *quadsPtr = NULL; + const labelList *polysPtr = NULL; + + const pointField *patchPointsPtr = NULL; + const faceList *patchFacesPtr = NULL; + + if (patchIndices.found(iter.key())) + { + label patchi = patchIndices.find(iter.key())(); + const polyPatch& p = mesh.boundaryMesh()[patchi]; + + trisPtr = &boundaryFaceSets[patchi].tris; + quadsPtr = &boundaryFaceSets[patchi].quads; + polysPtr = &boundaryFaceSets[patchi].polys; + + patchPointsPtr = &(p.localPoints()); + patchFacesPtr = &(p.localFaces()); + } + + const labelList& tris = *trisPtr; + const labelList& quads = *quadsPtr; + const labelList& polys = *polysPtr; + const pointField& patchPoints = *patchPointsPtr; + const faceList& patchFaces = *patchFacesPtr; + + if (nfp.nTris || nfp.nQuads || nfp.nPolys) + { + labelList patchPointOffsets(Pstream::nProcs(), 0); + + if (Pstream::master()) + { + ensightGeometryFile + << "part" << nl + << setw(10) << ensightPatchi++ << nl + << patchName << nl + << "coordinates" << nl + << setw(10) << nfp.nPoints + << endl; + + for (direction d=0; d<vector::nComponents; d++) + { + if (patchPointsPtr) + { + writePoints + ( + patchPoints.component(d), + ensightGeometryFile + ); + } + + patchPointOffsets = 0; + + forAll (patchProcessors, i) + { + if (patchProcessors[i] != 0) + { + label slave = patchProcessors[i]; + IPstream fromSlave(Pstream::scheduled, slave); + scalarField patchPointsComponent(fromSlave); + + writePoints + ( + patchPointsComponent, + ensightGeometryFile + ); + + if (i < Pstream::nProcs()-1) + { + patchPointOffsets[i+1] = + patchPointOffsets[i] + + patchPointsComponent.size(); + } + } + else + { + if (i < Pstream::nProcs()-1) + { + patchPointOffsets[i+1] = + patchPointOffsets[i] + + patchPoints.size(); + } + } + } + } + } + else if (patchPointsPtr) + { + for (direction d=0; d<vector::nComponents; d++) + { + OPstream toMaster + ( + Pstream::scheduled, + Pstream::masterNo() + ); + toMaster<< patchPoints.component(d); + } + } + + writeAllFacePrims + ( + "tria3", + tris, + nfp.nTris, + patchFaces, + patchPointOffsets, + patchProcessors, + ensightGeometryFile + ); + + writeAllFacePrims + ( + "quad4", + quads, + nfp.nQuads, + patchFaces, + patchPointOffsets, + patchProcessors, + ensightGeometryFile + ); + + writeAllFacePrims + ( + "nsided", + polys, + nfp.nPolys, + patchFaces, + patchPointOffsets, + patchProcessors, + ensightGeometryFile + ); + } + } + } + + if (Pstream::master()) + { + delete ensightGeometryFilePtr; + } +} + + +void Foam::ensightMesh::writeBinary +( + const fileName& postProcPath, + const word& prepend, + const label timeIndex, + Ostream& ensightCaseFile +) const +{ + //const Time& runTime = mesh.time(); + const pointField& points = mesh.points(); + const cellList& cellFaces = mesh.cells(); + const faceList& faces = mesh.faces(); + 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"; + + std::ofstream *ensightGeometryFilePtr = NULL; + + if (Pstream::master()) + { + ensightGeometryFilePtr = new std::ofstream((postProcPath/ensightGeometryFileName).c_str(), ios_base::out | ios_base::binary | ios_base::trunc); + // Check on file opened? + } + + std::ofstream& ensightGeometryFile = *ensightGeometryFilePtr; + + if (Pstream::master()) + { + writeEnsDataBinary("C binary",ensightGeometryFile); + writeEnsDataBinary("OpenFOAM Geometry File",ensightGeometryFile); + writeEnsDataBinary("Binary format",ensightGeometryFile); + writeEnsDataBinary("node id assign",ensightGeometryFile); + writeEnsDataBinary("element id assign",ensightGeometryFile); + } + + labelList pointOffsets(Pstream::nProcs(), 0); + + if (!patchNames.size()) + { + label nPoints = points.size(); + Pstream::gather(nPoints, sumOp<label>()); + + if (Pstream::master()) + { + writeEnsDataBinary("part",ensightGeometryFile); + writeEnsDataBinary(1,ensightGeometryFile); + writeEnsDataBinary("FOAM cells",ensightGeometryFile); + writeEnsDataBinary("coordinates",ensightGeometryFile); + writeEnsDataBinary(nPoints,ensightGeometryFile); + + for (direction d=0; d<vector::nComponents; d++) + { + //writePointsBinary(points.component(d), ensightGeometryFile); + writeEnsDataBinary(points.component(d), ensightGeometryFile); + pointOffsets[0] = points.size(); + + for (int slave=1; slave<Pstream::nProcs(); slave++) + { + IPstream fromSlave(Pstream::scheduled, slave); + scalarField pointsComponent(fromSlave); + //writePointsBinary(pointsComponent, ensightGeometryFile); + writeEnsDataBinary(pointsComponent, ensightGeometryFile); + pointOffsets[slave] = + pointOffsets[slave-1] + + pointsComponent.size(); + } + } + } + else + { + for (direction d=0; d<vector::nComponents; d++) + { + OPstream toMaster(Pstream::scheduled, Pstream::masterNo()); + toMaster<< points.component(d); + } + } + + writeAllPrimsBinary + ( + "hexa8", + meshCellSets.nHexesWedges, + map(cellShapes, meshCellSets.hexes, meshCellSets.wedges), + pointOffsets, + ensightGeometryFile + ); + + writeAllPrimsBinary + ( + "penta6", + meshCellSets.nPrisms, + map(cellShapes, meshCellSets.prisms), + pointOffsets, + ensightGeometryFile + ); + + writeAllPrimsBinary + ( + "pyramid5", + meshCellSets.nPyrs, + map(cellShapes, meshCellSets.pyrs), + pointOffsets, + ensightGeometryFile + ); + + writeAllPrimsBinary + ( + "tetra4", + meshCellSets.nTets, + map(cellShapes, meshCellSets.tets), + pointOffsets, + ensightGeometryFile + ); + + if (meshCellSets.nPolys) + { + if (Pstream::master()) + { + /* + ensightGeometryFile + << "nfaced" << nl + << setw(10) << meshCellSets.nPolys << nl; + */ + writePolysBinary + ( + meshCellSets.polys, + cellFaces, + faces, + 0, + ensightGeometryFile + ); + + for (int slave=1; slave<Pstream::nProcs(); slave++) + { + IPstream fromSlave(Pstream::scheduled, slave); + labelList polys(fromSlave); + cellList cellFaces(fromSlave); + faceList faces(fromSlave); + + writePolysBinary + ( + polys, + cellFaces, + faces, + pointOffsets[slave-1], + ensightGeometryFile + ); + } + } + else + { + OPstream toMaster(Pstream::scheduled, Pstream::masterNo()); + toMaster<< meshCellSets.polys << cellFaces << faces; + } + } + + } + + label ensightPatchi = 2; + + label iCount = 0; + + for + ( + HashTable<labelList>::const_iterator iter = allPatchNames.begin(); + iter != allPatchNames.end(); + ++iter + ) + { + iCount ++; + const labelList& patchProcessors = iter(); + + if (!patchNames.size() || patchNames.found(iter.key())) + { + const word& patchName = iter.key(); + const nFacePrims& nfp = nPatchPrims.find(patchName)(); + + const labelList *trisPtr = NULL; + const labelList *quadsPtr = NULL; + const labelList *polysPtr = NULL; + + const pointField *patchPointsPtr = NULL; + const faceList *patchFacesPtr = NULL; + + if (patchIndices.found(iter.key())) + { + label patchi = patchIndices.find(iter.key())(); + const polyPatch& p = mesh.boundaryMesh()[patchi]; + + trisPtr = &boundaryFaceSets[patchi].tris; + quadsPtr = &boundaryFaceSets[patchi].quads; + polysPtr = &boundaryFaceSets[patchi].polys; + + patchPointsPtr = &(p.localPoints()); + patchFacesPtr = &(p.localFaces()); + } + + const labelList& tris = *trisPtr; + const labelList& quads = *quadsPtr; + const labelList& polys = *polysPtr; + const pointField& patchPoints = *patchPointsPtr; + const faceList& patchFaces = *patchFacesPtr; + + if (nfp.nTris || nfp.nQuads || nfp.nPolys) + { + labelList patchPointOffsets(Pstream::nProcs(), 0); + + if (Pstream::master()) + { + writeEnsDataBinary("part",ensightGeometryFile); + writeEnsDataBinary(ensightPatchi++,ensightGeometryFile); + //writeEnsDataBinary(patchName.c_str(),ensightGeometryFile); + writeEnsDataBinary(iter.key().c_str(),ensightGeometryFile); + writeEnsDataBinary("coordinates",ensightGeometryFile); + writeEnsDataBinary(nfp.nPoints,ensightGeometryFile); + + for (direction d=0; d<vector::nComponents; d++) + { + if (patchPointsPtr) + { + //writePointsBinary + writeEnsDataBinary + ( + patchPoints.component(d), + ensightGeometryFile + ); + } + + patchPointOffsets = 0; + + + forAll (patchProcessors, i) + { + if (patchProcessors[i] != 0) + { + label slave = patchProcessors[i]; + IPstream fromSlave(Pstream::scheduled, slave); + scalarField patchPointsComponent(fromSlave); + + //writePointsBinary + writeEnsDataBinary + ( + patchPointsComponent, + ensightGeometryFile + ); + + if (i < Pstream::nProcs()-1) + { + patchPointOffsets[i+1] = + patchPointOffsets[i] + + patchPointsComponent.size(); + } + } + else + { + if (i < Pstream::nProcs()-1) + { + patchPointOffsets[i+1] = + patchPointOffsets[i] + + patchPoints.size(); + } + } + } + } + } + else if (patchPointsPtr) + { + for (direction d=0; d<vector::nComponents; d++) + { + OPstream toMaster + ( + Pstream::scheduled, + Pstream::masterNo() + ); + toMaster<< patchPoints.component(d); + } + } + + writeAllFacePrimsBinary + ( + "tria3", + tris, + nfp.nTris, + patchFaces, + patchPointOffsets, + patchProcessors, + ensightGeometryFile + ); + + writeAllFacePrimsBinary + ( + "quad4", + quads, + nfp.nQuads, + patchFaces, + patchPointOffsets, + patchProcessors, + ensightGeometryFile + ); + + writeAllFacePrimsBinary + ( + "nsided", + polys, + nfp.nPolys, + patchFaces, + patchPointOffsets, + patchProcessors, + ensightGeometryFile + ); + } + } + } + + + if (Pstream::master()) + { + delete ensightGeometryFilePtr; + } +} + +// ************************************************************************* // diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightMesh.H b/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightMesh.H new file mode 100644 index 0000000000000000000000000000000000000000..59c95bf4a7f83c380228ca764ff6ebe93495fe6e --- /dev/null +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightMesh.H @@ -0,0 +1,268 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2007 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 + +Class + Foam::ensightMesh + +Description + +SourceFiles + ensightMesh.C + +\*---------------------------------------------------------------------------*/ + +#ifndef ensightMesh_H +#define ensightMesh_H + +#include "cellSets.H" +#include "faceSets.H" +#include "HashTable.H" +#include "HashSet.H" +#include "fvMesh.H" +#include "OFstream.H" +#include <fstream> + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +class fvMesh; +class argList; + +/*---------------------------------------------------------------------------*\ + Class ensightMesh Declaration +\*---------------------------------------------------------------------------*/ + +class ensightMesh +{ + // Private data + + //- Set binary file output + bool binary_; + + + // Private Member Functions + + //- Disallow default bitwise copy construct + ensightMesh(const ensightMesh&); + + //- Disallow default bitwise assignment + void operator=(const ensightMesh&); + + void writePoints + ( + const scalarField& pointsComponent, + OFstream& ensightGeometryFile + ) const; + + cellShapeList map + ( + const cellShapeList& cellShapes, + const labelList& prims + ) const; + + cellShapeList map + ( + const cellShapeList& cellShapes, + const labelList& hexes, + const labelList& wedges + ) const; + + void writePrims + ( + const cellShapeList& cellShapes, + const label pointOffset, + OFstream& ensightGeometryFile + ) const; + + void writePolys + ( + const labelList& polys, + const cellList& cellFaces, + const faceList& faces, + const label pointOffset, + OFstream& ensightGeometryFile + ) const; + + void writeAllPrims + ( + const char* key, + const label nPrims, + const cellShapeList& cellShapes, + const labelList& pointOffsets, + OFstream& ensightGeometryFile + ) const; + + void writeFacePrims + ( + const char* key, + const faceList& patchFaces, + const label pointOffset, + OFstream& ensightGeometryFile + ) const; + + faceList map + ( + const faceList& patchFaces, + const labelList& prims + ) const; + + void writeAllFacePrims + ( + const char* key, + const labelList& prims, + const label nPrims, + const faceList& patchFaces, + const labelList& pointOffsets, + const labelList& patchProcessors, + OFstream& ensightGeometryFile + ) const; + + void writeAscii + ( + const fileName& postProcPath, + const word& prepend, + const label timeIndex, + Ostream& ensightCaseFile + ) const; + + void writeBinary + ( + const fileName& postProcPath, + const word& prepend, + const label timeIndex, + Ostream& ensightCaseFile + ) const; + + void writePrimsBinary + ( + const cellShapeList& cellShapes, + const label pointOffset, + std::ofstream& ensightGeometryFile + ) const; + + void writeAllPrimsBinary + ( + const char* key, + const label nPrims, + const cellShapeList& cellShapes, + const labelList& pointOffsets, + std::ofstream& ensightGeometryFile + ) const; + + void writePolysBinary + ( + const labelList& polys, + const cellList& cellFaces, + const faceList& faces, + const label pointOffset, + std::ofstream& ensightGeometryFile + ) const; + + void writeAllFacePrimsBinary + ( + const char* key, + const labelList& prims, + const label nPrims, + const faceList& patchFaces, + const labelList& pointOffsets, + const labelList& patchProcessors, + std::ofstream& ensightGeometryFile + ) const; + + void writeFacePrimsBinary + ( + const char* key, + const faceList& patchFaces, + const label pointOffset, + std::ofstream& ensightGeometryFile + ) const; + + +public: + + // Public data + + const fvMesh& mesh; + cellSets meshCellSets; + List<faceSets> boundaryFaceSets; + + HashTable<labelList> allPatchNames; + HashTable<label> patchIndices; + wordHashSet patchNames; + + class nFacePrims + { + public: + + label nPoints; + label nTris; + label nQuads; + label nPolys; + + nFacePrims() + : + nPoints(0), + nTris(0), + nQuads(0), + nPolys(0) + {} + }; + + HashTable<nFacePrims> nPatchPrims; + + + // Constructors + + //- Construct from fvMesh + ensightMesh(const fvMesh&, const argList& args, const bool binary); + + + // Destructor + + ~ensightMesh(); + + + // Member Functions + + void write + ( + const fileName& postProcPath, + const word& prepend, + const label timeIndex, + Ostream& ensightCaseFile + ) const; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightParticlePositions.C b/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightParticlePositions.C new file mode 100644 index 0000000000000000000000000000000000000000..5db4c0d5915c7a2e61566186343069328826ca5e --- /dev/null +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightParticlePositions.C @@ -0,0 +1,91 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2007 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 "ensightParticlePositions.H" +#include "fvMesh.H" +#include "passiveParticle.H" +#include "Cloud.H" +#include "OFstream.H" +#include "IOmanip.H" +#include "itoa.H" + +using namespace Foam; + +// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * // + +void ensightParticlePositions +( + const Foam::fvMesh& mesh, + const Foam::fileName& postProcPath, + const Foam::word& timeFile, + const Foam::word& sprayName +) +{ + const Time& runTime = mesh.time(); + + Cloud<passiveParticle> parcels(mesh); + + fileName ensightFileName(timeFile + "."+ sprayName); + OFstream ensightFile + ( + postProcPath/ensightFileName, + runTime.writeFormat(), + runTime.writeVersion(), + runTime.writeCompression() + ); + + // Output header + ensightFile + << "lagrangian " << nl + << "particle coordinates" << nl; + + // Set Format + ensightFile.setf(ios_base::scientific, ios_base::floatfield); + ensightFile.precision(5); + + ensightFile << setw(8) << parcels.size() << nl; + + label nParcels = 0; + + // Output position + for + ( + Cloud<passiveParticle>::iterator elmnt = parcels.begin(); + elmnt != parcels.end(); + ++elmnt + ) + { + const vector& p = elmnt().position(); + + ensightFile + << setw(8) << ++nParcels + << setw(12) << p.x() << setw(12) << p.y() << setw(12) << p.z() + << nl; + } +} + + +// ************************************************************************* // diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightParticlePositions.H b/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightParticlePositions.H new file mode 100644 index 0000000000000000000000000000000000000000..8382e2050a43f772cfbdf2633c6e8b10598a1cf3 --- /dev/null +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightParticlePositions.H @@ -0,0 +1,54 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2007 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 + +InApplication + foamToEnsight + +Description + +SourceFiles + ensightParticlePositions.C + +\*---------------------------------------------------------------------------*/ + +#ifndef ensightParticlePositions_H +#define ensightParticlePositions_H + +#include "fvMesh.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +void ensightParticlePositions +( + const Foam::fvMesh& mesh, + const Foam::fileName& postProcPath, + const Foam::word& timeFile, + const Foam::word& sprayName +); + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightSprayField.C b/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightSprayField.C new file mode 100644 index 0000000000000000000000000000000000000000..1b13698d68099d486d37ad4cd5f816b7e14acbf5 --- /dev/null +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightSprayField.C @@ -0,0 +1,115 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2007 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 "ensightSprayField.H" +#include "Time.H" +#include "IOField.H" +#include "OFstream.H" +#include "IOmanip.H" + +using namespace Foam; + +// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * // + +template<class Type> +void ensightSprayField +( + const Foam::IOobject& fieldObject, + const Foam::fileName& postProcPath, + const Foam::word& prepend, + const Foam::label timeIndex, + const Foam::word& sprayName, + Foam::Ostream& ensightCaseFile +) +{ + Info<< "Converting spray field " << fieldObject.name() << endl; + + word timeFile = prepend + itoa(timeIndex); + + const Time& runTime = fieldObject.time(); + + if (timeIndex == 0) + { + ensightCaseFile + << pTraits<Type>::typeName << " per measured node: 1 "; + ensightCaseFile.width(15); + ensightCaseFile.setf(ios_base::left); + ensightCaseFile + << ("s" + fieldObject.name()).c_str() + << (' ' + prepend + "***." + sprayName + + "." + fieldObject.name()).c_str() + << nl; + } + + // set the filename of the ensight file + fileName ensightFileName + ( + timeFile + "." + sprayName +"." + fieldObject.name() + ); + + OFstream ensightFile + ( + postProcPath/ensightFileName, + runTime.writeFormat(), + runTime.writeVersion(), + runTime.writeCompression() + ); + + ensightFile << pTraits<Type>::typeName << " values" << nl; + + IOField<Type> vf(fieldObject); + + ensightFile.setf(ios_base::scientific, ios_base::floatfield); + ensightFile.precision(5); + + label count = 0; + forAll(vf, i) + { + Type v = vf[i]; + + if (mag(v) < 1.0e-90) + { + v = pTraits<Type>::zero; + } + + for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; cmpt++) + { + ensightFile << setw(12) << component(v, cmpt); + if (++count % 6 == 0) + { + ensightFile << nl; + } + } + } + + if ( (count % 6 != 0) || (count==0) ) + { + ensightFile << nl; + } +} + + +// ************************************************************************* // diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightSprayField.H b/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightSprayField.H new file mode 100644 index 0000000000000000000000000000000000000000..1c6c68205549ee81893e5e93a71164b1145878f6 --- /dev/null +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightSprayField.H @@ -0,0 +1,64 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2007 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 + +InApplication + foamToEnsight + +Description + +SourceFiles + ensightSprayField.C + +\*---------------------------------------------------------------------------*/ + +#ifndef ensightSprayField_H +#define ensightSprayField_H + +#include "IOobject.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +template<class Type> +void ensightSprayField +( + const Foam::IOobject& fieldObject, + const Foam::fileName& postProcPath, + const Foam::word& prepend, + const Foam::label timeIndex, + const Foam::word& timeFile, + const Foam::word& sprayName, + Foam::Ostream& ensightCaseFile +); + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository +# include "ensightSprayField.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightWriteBinary.C b/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightWriteBinary.C new file mode 100644 index 0000000000000000000000000000000000000000..08fc02020cc1f02bfeedd68f9e1e7d59d6462c3e --- /dev/null +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightWriteBinary.C @@ -0,0 +1,79 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2007 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 "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() > 0) + { + 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 new file mode 100644 index 0000000000000000000000000000000000000000..1cd6ab30c3c5d0933a19765b7c1c2b8c1dd78721 --- /dev/null +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightWriteBinary.H @@ -0,0 +1,68 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2007 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 + +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 new file mode 100644 index 0000000000000000000000000000000000000000..c0f11b8b44b3120642c40d5bb87cf0e4c8b07628 --- /dev/null +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsight/faceSets.H @@ -0,0 +1,88 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2007 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 + +Class + Foam::faceSets + +Description + +\*---------------------------------------------------------------------------*/ + +#ifndef faceSets_H +#define faceSets_H + +#include "labelList.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class faceSets Declaration +\*---------------------------------------------------------------------------*/ + +class faceSets +{ + // Private Member Functions + + //- Disallow default bitwise copy construct + faceSets(const faceSets&); + + //- Disallow default bitwise assignment + void operator=(const faceSets&); + + +public: + + label nTris; + label nQuads; + label nPolys; + + labelList tris; + labelList quads; + labelList polys; + + + // Constructors + + //- Construct null + faceSets() + : + nTris(0), + nQuads(0), + nPolys(0) + {} +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsight/foamToEnsight.C b/applications/utilities/postProcessing/dataConversion/foamToEnsight/foamToEnsight.C new file mode 100644 index 0000000000000000000000000000000000000000..38880f63c38c1c91b65d5981cece8f7db84d16f4 --- /dev/null +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsight/foamToEnsight.C @@ -0,0 +1,396 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2007 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 + +Description + Translates FOAM data to EnSight format + +\*---------------------------------------------------------------------------*/ + +#include "argList.H" +#include "volFields.H" +#include "tensorIOField.H" +#include "IOobjectList.H" +#include "OFstream.H" +#include "IOmanip.H" +#include "scalarIOField.H" + +#include "ensightMesh.H" +#include "ensightField.H" + +#include "ensightParticlePositions.H" +#include "ensightSprayField.H" + +#include "fvc.H" + +using namespace Foam; + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +// Main program: + +int main(int argc, char *argv[]) +{ + argList::validOptions.insert("patches", "patch list"); + argList::validOptions.insert("binary", "" ); +# include "addTimeOptions.H" + + const label nTypes = 2; + const word fieldTypes[] = + { + volScalarField::typeName, + volVectorField::typeName + }; + + const label nSprayFieldTypes = 2; + const word sprayFieldTypes[] = + { + scalarIOField::typeName, + vectorIOField::typeName + }; + +# include "setRootCase.H" +# include "createTime.H" + + // get the available time-steps + instantList Times = runTime.times(); + +# include "checkTimeOptions.H" + + runTime.setTime(Times[startTime], startTime); + +# include "createMesh.H" + + const word postProcDir = "EnSight"; + const word prepend = args.globalCaseName() + '.'; + const word sprayName = "lagrangian"; + + fileName postProcPath = args.rootPath()/args.globalCaseName()/postProcDir; + + if (Pstream::master()) + { + if (dir(postProcPath)) + { + rmDir(postProcPath); + } + + mkDir(postProcPath); + } + + OFstream *ensightCaseFilePtr = NULL; + + // Check options + bool binary = false; + if (args.options().found("binary")) + { + binary = true; + } + + if (Pstream::master()) + { + // Open the Case file + fileName ensightCaseFileName = prepend + "case"; + + if (!binary) + { + ensightCaseFilePtr = new OFstream + ( + postProcPath/ensightCaseFileName, + runTime.writeFormat(), + runTime.writeVersion(), + runTime.writeCompression() + ); + } + else + { + ensightCaseFilePtr = new OFstream + ( + postProcPath/ensightCaseFileName, + runTime.writeFormat(), + runTime.writeVersion(), + IOstream::UNCOMPRESSED + ); + } + + Info<< nl << "Case file is " << ensightCaseFileName << endl; + } + + OFstream& ensightCaseFile = *ensightCaseFilePtr; + + // Construct the EnSight mesh + ensightMesh eMesh(mesh, args, binary); + + // Set Time to the last time before looking for the spray objects + runTime.setTime(Times[Times.size()-1], Times.size()-1); + + IOobjectList objects(mesh, runTime.timeName()); + IOobjectList sprayObjects(mesh, runTime.timeName(), "lagrangian"); + + bool lagrangianExist = false; + + if (!eMesh.patchNames.size()) + { + IOobject lagrangianHeader + ( + "positions", + runTime.timeName(), + "lagrangian", + mesh, + IOobject::NO_READ + ); + + if (lagrangianHeader.headerOk()) + { + lagrangianExist = true; + } + } + +# include "ensightCaseHeader.H" + +# include "checkMeshMoving.H" + + word geomCaseFileName = prepend + "000"; + if (Pstream::master()) + { + // test pre check variable if there is a moving mesh + if (meshMoving == true) geomCaseFileName = prepend + "***"; + ensightCaseFile + << "GEOMETRY" << nl + << "model: 1 " + << (geomCaseFileName + ".mesh").c_str() << nl; + } + + label nTimeSteps = 0; + for (label n=startTime; n<endTime; n++) + { + nTimeSteps++; + runTime.setTime(Times[n], n); + label timeIndex = n - startTime; + + word timeName = itoa(timeIndex); + word timeFile = prepend + timeName; + + Info << "Translating time = " << runTime.timeName() << nl; + +# include "moveMesh.H" + + if (timeIndex == 0 || mesh.moving()) + { + eMesh.write + ( + postProcPath, + prepend, + timeIndex, + ensightCaseFile + ); + } + + if (Pstream::master() && timeIndex == 0) + { + if (lagrangianExist) + { + ensightCaseFile + << ( + "measured: 1 " + + prepend + + "***." + + sprayName + ).c_str() + << nl; + } + ensightCaseFile << nl << "VARIABLE" << nl; + } + + for (label i=0; i<nTypes; i++) + { + wordList fieldNames = objects.names(fieldTypes[i]); + + for (label j=0; j<fieldNames.size(); j++) + { + word fieldName = fieldNames[j]; + + bool variableGood = true; + +# include "checkData.H" + + if (variableGood) + { + IOobject fieldObject + ( + fieldName, + mesh.time().timeName(), + mesh, + IOobject::MUST_READ, + IOobject::NO_WRITE + ); + + if (fieldTypes[i] == volScalarField::typeName) + { + ensightField<scalar> + ( + fieldObject, + eMesh, + postProcPath, + prepend, + timeIndex, + binary, + ensightCaseFile + ); + } + else if (fieldTypes[i] == volVectorField::typeName) + { + ensightField<vector> + ( + fieldObject, + eMesh, + postProcPath, + prepend, + timeIndex, + binary, + ensightCaseFile + ); + } + else if (fieldTypes[i] == volSphericalTensorField::typeName) + { + ensightField<sphericalTensor> + ( + fieldObject, + eMesh, + postProcPath, + prepend, + timeIndex, + binary, + ensightCaseFile + ); + } + else if (fieldTypes[i] == volSymmTensorField::typeName) + { + ensightField<symmTensor> + ( + fieldObject, + eMesh, + postProcPath, + prepend, + timeIndex, + binary, + ensightCaseFile + ); + } + else if (fieldTypes[i] == volTensorField::typeName) + { + ensightField<tensor> + ( + fieldObject, + eMesh, + postProcPath, + prepend, + timeIndex, + binary, + ensightCaseFile + ); + } + } + } + } + + if (lagrangianExist) + { + ensightParticlePositions + ( + mesh, + postProcPath, + timeFile, + sprayName + ); + + for (label i=0; i<nSprayFieldTypes; i++) + { + wordList fieldNames = sprayObjects.names(sprayFieldTypes[i]); + + for (label j=0; j<fieldNames.size(); j++) + { + word fieldName = fieldNames[j]; + + IOobject fieldObject + ( + fieldName, + mesh.time().timeName(), + "lagrangian", + mesh, + IOobject::MUST_READ, + IOobject::NO_WRITE + ); + + if (sprayFieldTypes[i] == scalarIOField::typeName) + { + ensightSprayField<scalar> + ( + fieldObject, + postProcPath, + prepend, + timeIndex, + sprayName, + ensightCaseFile + ); + } + else if (sprayFieldTypes[i] == vectorIOField::typeName) + { + ensightSprayField<vector> + ( + fieldObject, + postProcPath, + prepend, + timeIndex, + sprayName, + ensightCaseFile + ); + } + else if (sprayFieldTypes[i] == tensorIOField::typeName) + { + ensightSprayField<tensor> + ( + fieldObject, + postProcPath, + prepend, + timeIndex, + sprayName, + ensightCaseFile + ); + } + } + } + } + } + +# include "ensightCaseTail.H" + + if (Pstream::master()) + { + delete ensightCaseFilePtr; + } + + return 0; +} + + +// ************************************************************************* // diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsight/itoa.C b/applications/utilities/postProcessing/dataConversion/foamToEnsight/itoa.C new file mode 100644 index 0000000000000000000000000000000000000000..1539967ae332c8a4b9b35dad42dd57a62333b173 --- /dev/null +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsight/itoa.C @@ -0,0 +1,62 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2007 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 "itoa.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +word itoa(const label n) +{ + const label offset = '0'; + const label length = 3; + + char val[length + 1]; + + label leftOfN = n; + + for (label i=0; i<length; i++) + { + label j = label(leftOfN/pow(10, length - i - 1)); + leftOfN -= j*pow(10, length - i - 1); + val[i] = offset + j; + } + + val[length] = 0; + + return val; +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// ************************************************************************* // diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsight/itoa.H b/applications/utilities/postProcessing/dataConversion/foamToEnsight/itoa.H new file mode 100644 index 0000000000000000000000000000000000000000..2bed59cc5e1b12563cc3538f1b008a15fdef3384 --- /dev/null +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsight/itoa.H @@ -0,0 +1,48 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2007 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 + +InApplication + foamToEnsight + +Description + +\*---------------------------------------------------------------------------*/ + +#include "word.H" +#include "label.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +word itoa(const label n); + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// ************************************************************************* // diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsight/moveMesh.H b/applications/utilities/postProcessing/dataConversion/foamToEnsight/moveMesh.H new file mode 100644 index 0000000000000000000000000000000000000000..a0b5ac1586b0a5207d1ca88201176446cebfa8e7 --- /dev/null +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsight/moveMesh.H @@ -0,0 +1,28 @@ +{ + IOobject ioPoints + ( + "points", + runTime.timeName(), + polyMesh::meshSubDir, + mesh + ); + + if (ioPoints.headerOk()) + { + // Reading new points + pointIOField newPoints + ( + IOobject + ( + "points", + mesh.time().timeName(), + polyMesh::meshSubDir, + mesh, + IOobject::MUST_READ, + IOobject::NO_WRITE + ) + ); + + mesh.movePoints(newPoints); + } +}