From 7aeaf61cda1e1f81506eade7b7f3c07917e5a945 Mon Sep 17 00:00:00 2001 From: Mark Olesen <Mark.Olesen@Germany> Date: Fri, 11 Nov 2016 09:42:28 +0100 Subject: [PATCH] ENH: getting foamToTecplot working again - updated code to use current API level 142. - ThirdParty build of tecio now uses CMake. --- .../dataConversion/foamToTecplot360/Allwmake | 8 +- .../foamToTecplot360/Make/options | 10 +- .../foamToTecplot360/foamToTecplot360.C | 374 ++++++------- .../foamToTecplot360/tecplotWriter.C | 507 ++++++++---------- .../foamToTecplot360/tecplotWriter.H | 132 ++++- .../foamToTecplot360/tecplotWriterTemplates.C | 111 ++-- 6 files changed, 575 insertions(+), 567 deletions(-) diff --git a/applications/utilities/postProcessing/dataConversion/foamToTecplot360/Allwmake b/applications/utilities/postProcessing/dataConversion/foamToTecplot360/Allwmake index d2cc359d9e0..0893798f67b 100755 --- a/applications/utilities/postProcessing/dataConversion/foamToTecplot360/Allwmake +++ b/applications/utilities/postProcessing/dataConversion/foamToTecplot360/Allwmake @@ -4,11 +4,13 @@ cd ${0%/*} || exit 1 # Run from this directory # Parse arguments for application compilation (at least for error control) . $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments -if [ ! -d ${WM_THIRD_PARTY_DIR}/tecio ] +export TECIO_ARCH_PATH=$WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER/tecio +if [ -f $TECIO_ARCH_PATH/TECIO.h -a -r $TECIO_ARCH_PATH/libtecio.a ] then - echo "Did not find tecio in ${WM_THIRD_PARTY_DIR}. Not building foamToTecplot360." -else + echo "Building optional tecplot conversion component." wmake $targetType +else + echo "Skipping optional tecplot conversion components (no tecio detected)." fi #------------------------------------------------------------------------------ diff --git a/applications/utilities/postProcessing/dataConversion/foamToTecplot360/Make/options b/applications/utilities/postProcessing/dataConversion/foamToTecplot360/Make/options index 5cf2518dd7c..eb87f412dfb 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToTecplot360/Make/options +++ b/applications/utilities/postProcessing/dataConversion/foamToTecplot360/Make/options @@ -1,14 +1,14 @@ +/* Tecio doesn't have many files, so they are just in a single directory */ + EXE_INC = \ - -I$(WM_THIRD_PARTY_DIR)/tecio/tecsrc/lnInclude \ + -I$(TECIO_ARCH_PATH) \ -I$(LIB_SRC)/lagrangian/basic/lnInclude \ -I$(LIB_SRC)/finiteVolume/lnInclude \ -I$(LIB_SRC)/dynamicMesh/lnInclude \ -I$(LIB_SRC)/meshTools/lnInclude - EXE_LIBS = \ + -L$(TECIO_ARCH_PATH) -ltecio \ -llagrangian \ -ldynamicMesh \ - -ldynamicMesh \ - -lgenericPatchFields \ - -L$(FOAM_EXT_LIBBIN) -ltecio + -lgenericPatchFields diff --git a/applications/utilities/postProcessing/dataConversion/foamToTecplot360/foamToTecplot360.C b/applications/utilities/postProcessing/dataConversion/foamToTecplot360/foamToTecplot360.C index 5dbe1581cad..7cc27fde20b 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToTecplot360/foamToTecplot360.C +++ b/applications/utilities/postProcessing/dataConversion/foamToTecplot360/foamToTecplot360.C @@ -43,7 +43,6 @@ Usage information as a single argument. - \par -cellSet \<name\> - - \par -faceSet \<name\> Restrict conversion to the cellSet, faceSet. @@ -81,16 +80,11 @@ Usage #include "passiveParticleCloud.H" #include "faceSet.H" #include "stringListOps.H" -#include "wordRe.H" +#include "wordReList.H" #include "meshSubsetHelper.H" #include "readFields.H" #include "tecplotWriter.H" - -#include "TECIO.h" - -// Note: needs to be after TECIO to prevent Foam::Time conflicting with -// Xlib Time. #include "fvCFD.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -243,22 +237,22 @@ int main(int argc, char *argv[]) word cellSetName; word faceSetName; - string vtkName = runTime.caseName(); + string pltName = runTime.caseName(); if (args.optionReadIfPresent("cellSet", cellSetName)) { - vtkName = cellSetName; + pltName = cellSetName; } else if (Pstream::parRun()) { // Strip off leading casename, leaving just processor_DDD ending. - vtkName = runTime.caseName(); + pltName = runTime.caseName(); - string::size_type i = vtkName.rfind("processor"); + string::size_type i = pltName.rfind("processor"); if (i != string::npos) { - vtkName = vtkName.substr(i); + pltName = pltName.substr(i); } } args.optionReadIfPresent("faceSet", faceSetName); @@ -269,9 +263,9 @@ int main(int argc, char *argv[]) // TecplotData/ directory in the case fileName fvPath(runTime.path()/"Tecplot360"); - // Directory of mesh (region0 gets filtered out) - fileName regionPrefix = ""; + // Directory of mesh (region0 gets filtered out) + fileName regionPrefix; if (regionName != polyMesh::defaultRegion) { fvPath = fvPath/regionName; @@ -293,7 +287,7 @@ int main(int argc, char *argv[]) } else { - Info<< "Deleting old VTK files in " << fvPath << nl << endl; + Info<< "Deleting old tecplot files in " << fvPath << nl << endl; rmDir(fvPath); } @@ -317,13 +311,13 @@ int main(int argc, char *argv[]) polyMesh::readUpdateState meshState = myMesh.readUpdate(); const fvMesh& mesh = myMesh.mesh(); - INTEGER4 nFaceNodes = 0; + // TotalNumFaceNodes + int32_t nFaceNodes = 0; forAll(mesh.faces(), facei) { nFaceNodes += mesh.faces()[facei].size(); } - // Read all fields on the new mesh // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -463,23 +457,23 @@ int main(int argc, char *argv[]) // ~~~~~~~~~~~~~~~ string varNames; - DynamicList<INTEGER4> varLocation; + DynamicList<int32_t> varLocation; string cellVarNames; - DynamicList<INTEGER4> cellVarLocation; + DynamicList<int32_t> cellVarLocation; // volFields tecplotWriter::getTecplotNames ( vsf, - ValueLocation_CellCentered, + tecplotWriter::CELL_CENTERED, varNames, varLocation ); tecplotWriter::getTecplotNames ( vsf, - ValueLocation_CellCentered, + tecplotWriter::CELL_CENTERED, cellVarNames, cellVarLocation ); @@ -487,14 +481,14 @@ int main(int argc, char *argv[]) tecplotWriter::getTecplotNames ( vvf, - ValueLocation_CellCentered, + tecplotWriter::CELL_CENTERED, varNames, varLocation ); tecplotWriter::getTecplotNames ( vvf, - ValueLocation_CellCentered, + tecplotWriter::CELL_CENTERED, cellVarNames, cellVarLocation ); @@ -502,14 +496,14 @@ int main(int argc, char *argv[]) tecplotWriter::getTecplotNames ( vSpheretf, - ValueLocation_CellCentered, + tecplotWriter::CELL_CENTERED, varNames, varLocation ); tecplotWriter::getTecplotNames ( vSpheretf, - ValueLocation_CellCentered, + tecplotWriter::CELL_CENTERED, cellVarNames, cellVarLocation ); @@ -517,14 +511,14 @@ int main(int argc, char *argv[]) tecplotWriter::getTecplotNames ( vSymmtf, - ValueLocation_CellCentered, + tecplotWriter::CELL_CENTERED, varNames, varLocation ); tecplotWriter::getTecplotNames ( vSymmtf, - ValueLocation_CellCentered, + tecplotWriter::CELL_CENTERED, cellVarNames, cellVarLocation ); @@ -532,25 +526,24 @@ int main(int argc, char *argv[]) tecplotWriter::getTecplotNames ( vtf, - ValueLocation_CellCentered, + tecplotWriter::CELL_CENTERED, varNames, varLocation ); tecplotWriter::getTecplotNames ( vtf, - ValueLocation_CellCentered, + tecplotWriter::CELL_CENTERED, cellVarNames, cellVarLocation ); - // pointFields tecplotWriter::getTecplotNames ( psf, - ValueLocation_Nodal, + tecplotWriter::NODE_CENTERED, varNames, varLocation ); @@ -558,44 +551,45 @@ int main(int argc, char *argv[]) tecplotWriter::getTecplotNames ( pvf, - ValueLocation_Nodal, + tecplotWriter::NODE_CENTERED, varNames, varLocation ); - // strandID (= piece id. Gets incremented for every piece of geometry - // that is output) - INTEGER4 strandID = 1; - + // strandID (= piece id). + // Gets incremented for every piece of geometry that is output. + int32_t strandID = 1; if (meshState != polyMesh::UNCHANGED) { if (doWriteInternal) { // Output mesh and fields - fileName vtkFileName + fileName pltFileName ( - fvPath/vtkName + fvPath/pltName + "_" + timeDesc + ".plt" ); - tecplotWriter writer(runTime); - - string allVarNames = string("X Y Z ") + varNames; - DynamicList<INTEGER4> allVarLocation; - allVarLocation.append(ValueLocation_Nodal); - allVarLocation.append(ValueLocation_Nodal); - allVarLocation.append(ValueLocation_Nodal); + const string allVarNames = tecplotWriter::XYZ + " " + varNames; + DynamicList<int32_t> allVarLocation + { + tecplotWriter::NODE_CENTERED, + tecplotWriter::NODE_CENTERED, + tecplotWriter::NODE_CENTERED + }; allVarLocation.append(varLocation); + + tecplotWriter writer(runTime); writer.writeInit ( runTime.caseName(), allVarNames, - vtkFileName, - DataFileType_Full + pltFileName, + tecplotWriter::FILETYPE_FULL ); writer.writePolyhedralZone @@ -607,41 +601,18 @@ int main(int argc, char *argv[]) nFaceNodes ); - // Write coordinates - writer.writeField(mesh.points().component(0)()); - writer.writeField(mesh.points().component(1)()); - writer.writeField(mesh.points().component(2)()); + // Coordinates + writer.writeField(mesh.points()); // Write all fields - forAll(vsf, i) - { - writer.writeField(vsf[i]); - } - forAll(vvf, i) - { - writer.writeField(vvf[i]); - } - forAll(vSpheretf, i) - { - writer.writeField(vSpheretf[i]); - } - forAll(vSymmtf, i) - { - writer.writeField(vSymmtf[i]); - } - forAll(vtf, i) - { - writer.writeField(vtf[i]); - } + writer.writeFields(vsf); + writer.writeFields(vvf); + writer.writeFields(vSpheretf); + writer.writeFields(vSymmtf); + writer.writeFields(vtf); - forAll(psf, i) - { - writer.writeField(psf[i]); - } - forAll(pvf, i) - { - writer.writeField(pvf[i]); - } + writer.writeFields(psf); + writer.writeFields(pvf); writer.writeConnectivity(mesh); writer.writeEnd(); @@ -654,22 +625,22 @@ int main(int argc, char *argv[]) if (timeI == 0) { // Output static mesh only - fileName vtkFileName + fileName pltFileName ( - fvPath/vtkName + fvPath/pltName + "_grid_" + timeDesc + ".plt" ); - tecplotWriter writer(runTime); + tecplotWriter writer(runTime); writer.writeInit ( runTime.caseName(), - "X Y Z", - vtkFileName, - DataFileType_Grid + tecplotWriter::XYZ, + pltFileName, + tecplotWriter::FILETYPE_GRID ); writer.writePolyhedralZone @@ -677,36 +648,33 @@ int main(int argc, char *argv[]) mesh.name(), // regionName strandID, // strandID mesh, - List<INTEGER4>(3, ValueLocation_Nodal), + List<int32_t>(3, tecplotWriter::NODE_CENTERED), nFaceNodes ); - // Write coordinates - writer.writeField(mesh.points().component(0)()); - writer.writeField(mesh.points().component(1)()); - writer.writeField(mesh.points().component(2)()); - + // Coordinates + writer.writeField(mesh.points()); writer.writeConnectivity(mesh); writer.writeEnd(); } // Output solution file - fileName vtkFileName + fileName pltFileName ( - fvPath/vtkName + fvPath/pltName + "_" + timeDesc + ".plt" ); - tecplotWriter writer(runTime); + tecplotWriter writer(runTime); writer.writeInit ( runTime.caseName(), varNames, - vtkFileName, - DataFileType_Solution + pltFileName, + tecplotWriter::FILETYPE_SOLUTION ); writer.writePolyhedralZone @@ -719,35 +687,15 @@ int main(int argc, char *argv[]) ); // Write all fields - forAll(vsf, i) - { - writer.writeField(vsf[i]); - } - forAll(vvf, i) - { - writer.writeField(vvf[i]); - } - forAll(vSpheretf, i) - { - writer.writeField(vSpheretf[i]); - } - forAll(vSymmtf, i) - { - writer.writeField(vSymmtf[i]); - } - forAll(vtf, i) - { - writer.writeField(vtf[i]); - } + writer.writeFields(vsf); + writer.writeFields(vvf); + writer.writeFields(vSpheretf); + writer.writeFields(vSymmtf); + writer.writeFields(vtf); + + writer.writeFields(psf); + writer.writeFields(pvf); - forAll(psf, i) - { - writer.writeField(psf[i]); - } - forAll(pvf, i) - { - writer.writeField(pvf[i]); - } writer.writeEnd(); } } @@ -765,11 +713,11 @@ int main(int argc, char *argv[]) labelList faceLabels(faceSet(mesh, faceSetName).toc()); // Filename as if patch with same name. - mkDir(fvPath/setName); + mkDir(fvPath/faceSetName); fileName patchFileName ( - fvPath/setName/setName + fvPath/faceSetName/faceSetName + "_" + timeDesc + ".plt" @@ -777,21 +725,23 @@ int main(int argc, char *argv[]) Info<< " FaceSet : " << patchFileName << endl; - tecplotWriter writer(runTime); - - string allVarNames = string("X Y Z ") + cellVarNames; - DynamicList<INTEGER4> allVarLocation; - allVarLocation.append(ValueLocation_Nodal); - allVarLocation.append(ValueLocation_Nodal); - allVarLocation.append(ValueLocation_Nodal); + const string allVarNames = tecplotWriter::XYZ + " " + cellVarNames; + DynamicList<int32_t> allVarLocation + { + tecplotWriter::NODE_CENTERED, + tecplotWriter::NODE_CENTERED, + tecplotWriter::NODE_CENTERED + }; allVarLocation.append(cellVarLocation); + + tecplotWriter writer(runTime); writer.writeInit ( runTime.caseName(), cellVarNames, patchFileName, - DataFileType_Full + tecplotWriter::FILETYPE_FULL ); const indirectPrimitivePatch ipp @@ -802,16 +752,14 @@ int main(int argc, char *argv[]) writer.writePolygonalZone ( - setName, + faceSetName, strandID++, ipp, allVarLocation ); - // Write coordinates - writer.writeField(ipp.localPoints().component(0)()); - writer.writeField(ipp.localPoints().component(1)()); - writer.writeField(ipp.localPoints().component(2)()); + // Coordinates + writer.writeField(ipp.localPoints()); // Write all volfields forAll(vsf, i) @@ -822,7 +770,7 @@ int main(int argc, char *argv[]) ( linearInterpolate(vsf[i])(), faceLabels - )() + ) ); } forAll(vvf, i) @@ -833,7 +781,7 @@ int main(int argc, char *argv[]) ( linearInterpolate(vvf[i])(), faceLabels - )() + ) ); } forAll(vSpheretf, i) @@ -844,7 +792,7 @@ int main(int argc, char *argv[]) ( linearInterpolate(vSpheretf[i])(), faceLabels - )() + ) ); } forAll(vSymmtf, i) @@ -855,7 +803,7 @@ int main(int argc, char *argv[]) ( linearInterpolate(vSymmtf[i])(), faceLabels - )() + ) ); } forAll(vtf, i) @@ -866,7 +814,7 @@ int main(int argc, char *argv[]) ( linearInterpolate(vtf[i])(), faceLabels - )() + ) ); } writer.writeConnectivity(ipp); @@ -908,33 +856,37 @@ int main(int argc, char *argv[]) Info<< " Combined patches : " << patchFileName << endl; - tecplotWriter writer(runTime); - - string allVarNames = string("X Y Z ") + varNames; - DynamicList<INTEGER4> allVarLocation; - allVarLocation.append(ValueLocation_Nodal); - allVarLocation.append(ValueLocation_Nodal); - allVarLocation.append(ValueLocation_Nodal); + const string allVarNames = tecplotWriter::XYZ + " " + varNames; + DynamicList<int32_t> allVarLocation + { + tecplotWriter::NODE_CENTERED, + tecplotWriter::NODE_CENTERED, + tecplotWriter::NODE_CENTERED + }; allVarLocation.append(varLocation); + + tecplotWriter writer(runTime); writer.writeInit ( runTime.caseName(), allVarNames, patchFileName, - DataFileType_Full + tecplotWriter::FILETYPE_FULL ); forAll(patchIDs, i) { label patchID = patchIDs[i]; const polyPatch& pp = patches[patchID]; - //INTEGER4 strandID = 1 + i; + // int32_t strandID = 1 + i; if (pp.size() > 0) { - Info<< " Writing patch " << patchID << "\t" << pp.name() - << "\tstrand:" << strandID << nl << endl; + Info<< " Writing patch " << patchID + << tab << pp.name() + << tab << "strand:" << strandID + << nl << endl; const indirectPrimitivePatch ipp ( @@ -950,10 +902,8 @@ int main(int argc, char *argv[]) allVarLocation ); - // Write coordinates - writer.writeField(ipp.localPoints().component(0)()); - writer.writeField(ipp.localPoints().component(1)()); - writer.writeField(ipp.localPoints().component(2)()); + // Coordinates + writer.writeField(ipp.localPoints()); // Write all fields forAll(vsf, i) @@ -965,7 +915,7 @@ int main(int argc, char *argv[]) nearCellValue, vsf[i], patchID - )() + ) ); } forAll(vvf, i) @@ -977,7 +927,7 @@ int main(int argc, char *argv[]) nearCellValue, vvf[i], patchID - )() + ) ); } forAll(vSpheretf, i) @@ -989,7 +939,7 @@ int main(int argc, char *argv[]) nearCellValue, vSpheretf[i], patchID - )() + ) ); } forAll(vSymmtf, i) @@ -1001,7 +951,7 @@ int main(int argc, char *argv[]) nearCellValue, vSymmtf[i], patchID - )() + ) ); } forAll(vtf, i) @@ -1013,7 +963,7 @@ int main(int argc, char *argv[]) nearCellValue, vtf[i], patchID - )() + ) ); } @@ -1021,14 +971,14 @@ int main(int argc, char *argv[]) { writer.writeField ( - psf[i].boundaryField()[patchID].patchInternalField()() + psf[i].boundaryField()[patchID].patchInternalField() ); } forAll(pvf, i) { writer.writeField ( - pvf[i].boundaryField()[patchID].patchInternalField()() + pvf[i].boundaryField()[patchID].patchInternalField() ); } @@ -1037,7 +987,7 @@ int main(int argc, char *argv[]) else { Info<< " Skipping zero sized patch " << patchID - << "\t" << pp.name() + << tab << pp.name() << nl << endl; } } @@ -1054,7 +1004,7 @@ int main(int argc, char *argv[]) const faceZoneMesh& zones = mesh.faceZones(); - if (doFaceZones && zones.size() > 0) + if (doFaceZones && !zones.empty()) { mkDir(fvPath/"faceZoneMesh"); @@ -1079,21 +1029,23 @@ int main(int argc, char *argv[]) Info<< " FaceZone : " << patchFileName << endl; - tecplotWriter writer(runTime); - - string allVarNames = string("X Y Z ") + cellVarNames; - DynamicList<INTEGER4> allVarLocation; - allVarLocation.append(ValueLocation_Nodal); - allVarLocation.append(ValueLocation_Nodal); - allVarLocation.append(ValueLocation_Nodal); + const string allVarNames = tecplotWriter::XYZ + " " + cellVarNames; + DynamicList<int32_t> allVarLocation + { + tecplotWriter::NODE_CENTERED, + tecplotWriter::NODE_CENTERED, + tecplotWriter::NODE_CENTERED + }; allVarLocation.append(cellVarLocation); + + tecplotWriter writer(runTime); writer.writeInit ( runTime.caseName(), allVarNames, patchFileName, - DataFileType_Full + tecplotWriter::FILETYPE_FULL ); forAll(zones, zoneI) @@ -1116,10 +1068,8 @@ int main(int argc, char *argv[]) allVarLocation ); - // Write coordinates - writer.writeField(ipp.localPoints().component(0)()); - writer.writeField(ipp.localPoints().component(1)()); - writer.writeField(ipp.localPoints().component(2)()); + // Coordinates + writer.writeField(ipp.localPoints()); // Write all volfields forAll(vsf, i) @@ -1130,7 +1080,7 @@ int main(int argc, char *argv[]) ( linearInterpolate(vsf[i])(), pp - )() + ) ); } forAll(vvf, i) @@ -1141,7 +1091,7 @@ int main(int argc, char *argv[]) ( linearInterpolate(vvf[i])(), pp - )() + ) ); } forAll(vSpheretf, i) @@ -1152,7 +1102,7 @@ int main(int argc, char *argv[]) ( linearInterpolate(vSpheretf[i])(), pp - )() + ) ); } forAll(vSymmtf, i) @@ -1163,7 +1113,7 @@ int main(int argc, char *argv[]) ( linearInterpolate(vSymmtf[i])(), pp - )() + ) ); } forAll(vtf, i) @@ -1174,7 +1124,7 @@ int main(int argc, char *argv[]) ( linearInterpolate(vtf[i])(), pp - )() + ) ); } @@ -1183,16 +1133,16 @@ int main(int argc, char *argv[]) else { Info<< " Skipping zero sized faceZone " << zoneI - << "\t" << pp.name() + << tab << pp.name() << nl << endl; } } + writer.writeEnd(); Info<< endl; } - //--------------------------------------------------------------------- // // Write lagrangian data @@ -1283,16 +1233,18 @@ int main(int argc, char *argv[]) } - string allVarNames = string("X Y Z"); - DynamicList<INTEGER4> allVarLocation; - allVarLocation.append(ValueLocation_Nodal); - allVarLocation.append(ValueLocation_Nodal); - allVarLocation.append(ValueLocation_Nodal); + string allVarNames = tecplotWriter::XYZ; + DynamicList<int32_t> allVarLocation + { + tecplotWriter::NODE_CENTERED, + tecplotWriter::NODE_CENTERED, + tecplotWriter::NODE_CENTERED + }; tecplotWriter::getTecplotNames<label> ( labelNames, - ValueLocation_Nodal, + tecplotWriter::NODE_CENTERED, allVarNames, allVarLocation ); @@ -1300,7 +1252,7 @@ int main(int argc, char *argv[]) tecplotWriter::getTecplotNames<scalar> ( scalarNames, - ValueLocation_Nodal, + tecplotWriter::NODE_CENTERED, allVarNames, allVarLocation ); @@ -1308,20 +1260,19 @@ int main(int argc, char *argv[]) tecplotWriter::getTecplotNames<vector> ( vectorNames, - ValueLocation_Nodal, + tecplotWriter::NODE_CENTERED, allVarNames, allVarLocation ); tecplotWriter writer(runTime); - writer.writeInit ( runTime.caseName(), allVarNames, lagrFileName, - DataFileType_Full + tecplotWriter::FILETYPE_FULL ); writer.writeOrderedZone @@ -1332,19 +1283,19 @@ int main(int argc, char *argv[]) allVarLocation ); - // Write coordinates - writer.writeField(positions.component(0)()); - writer.writeField(positions.component(1)()); - writer.writeField(positions.component(2)()); + // Coordinates + writer.writeField(positions); // labelFields forAll(labelNames, i) { + const word& fieldName = labelNames[i]; + IOField<label> fld ( IOobject ( - labelNames[i], + fieldName, mesh.time().timeName(), cloud::prefix/cloudDirs[cloudI], mesh, @@ -1354,21 +1305,19 @@ int main(int argc, char *argv[]) ) ); - scalarField sfld(fld.size()); - forAll(fld, j) - { - sfld[j] = scalar(fld[j]); - } - writer.writeField(sfld); + writer.writeField(fld); } + // scalarFields forAll(scalarNames, i) { + const word& fieldName = scalarNames[i]; + IOField<scalar> fld ( IOobject ( - scalarNames[i], + fieldName, mesh.time().timeName(), cloud::prefix/cloudDirs[cloudI], mesh, @@ -1377,16 +1326,20 @@ int main(int argc, char *argv[]) false ) ); + writer.writeField(fld); } + // vectorFields forAll(vectorNames, i) { + const word& fieldName = vectorNames[i]; + IOField<vector> fld ( IOobject ( - vectorNames[i], + fieldName, mesh.time().timeName(), cloud::prefix/cloudDirs[cloudI], mesh, @@ -1395,6 +1348,7 @@ int main(int argc, char *argv[]) false ) ); + writer.writeField(fld); } diff --git a/applications/utilities/postProcessing/dataConversion/foamToTecplot360/tecplotWriter.C b/applications/utilities/postProcessing/dataConversion/foamToTecplot360/tecplotWriter.C index a43c625f179..317010c0de2 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToTecplot360/tecplotWriter.C +++ b/applications/utilities/postProcessing/dataConversion/foamToTecplot360/tecplotWriter.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -25,13 +25,23 @@ License #include "tecplotWriter.H" #include "fvMesh.H" +#include "TECIO.h" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +const int32_t Foam::tecplotWriter::tecConst_0 = 0; +const int32_t Foam::tecplotWriter::tecConst_1 = 1; +const int32_t Foam::tecplotWriter::tecConst_False = 0; +const int32_t Foam::tecplotWriter::tecConst_True = 1; + +const Foam::string Foam::tecplotWriter::XYZ = "X Y Z"; + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -// Construct from components Foam::tecplotWriter::tecplotWriter(const Time& runTime) : - runTime_(runTime) + time_(runTime) {} @@ -42,35 +52,37 @@ void Foam::tecplotWriter::writeInit const word& name, const string& varNames, const fileName& fName, - INTEGER4 tecplotFileType + const dataFileType fileType ) const { -Pout<< endl - << endl - << "Name:" << name - << " varNames:" << varNames - << " to file:" << fName - << " of type:" << tecplotFileType - << endl; - - INTEGER4 IsDouble = 0; //float - INTEGER4 Debug = 0; //nodebug + const int32_t FileType = fileType; + const int32_t FileFormat = 0; // 0 = binary (plt), 1 = subzone (.szplt) + + Pout<< nl << nl + << "Name:" << name + << " varNames:" << varNames + << " to file:" << fName + << " of type:" << int(fileType) + << endl; + if ( - !TECINI112 + tecini142 ( - const_cast<char*>(name.c_str()), /* Data Set Title */ - const_cast<char*>(varNames.c_str()), /* Variable List */ - const_cast<char*>(fName.c_str()), /* File Name */ - const_cast<char*>(runTime_.path().c_str()), /* Scratch Directory */ - &tecplotFileType, - &Debug, - &IsDouble + name.c_str(), //< DataSet Title + varNames.c_str(), //< Variables List + fName.c_str(), //< FileName + time_.path().c_str(), //< ScratchDir + &FileFormat, //< FileFormat + &FileType, //< FileType + &tecConst_False, //< Debug (0: no debug, 1: debug) + &tecConst_False //< VIsDouble (0: single, 1: double) ) ) { -// FatalErrorInFunction -// << "Error in TECINI112." << exit(FatalError); + FatalErrorInFunction + << "Error in tecini142." + << exit(FatalError); } } @@ -78,78 +90,60 @@ Pout<< endl void Foam::tecplotWriter::writePolyhedralZone ( const word& zoneName, - INTEGER4 strandID, + const int32_t strandID, const fvMesh& mesh, - const List<INTEGER4>& varLocArray, - INTEGER4 nFaceNodes + const UList<int32_t>& varLocArray, + const int32_t NumFaceNodes ) const { - /* Call TECZNE112 */ - INTEGER4 NumNodes = mesh.nPoints(); /* number of unique nodes */ - INTEGER4 NumElems = mesh.nCells(); /* number of elements */ - INTEGER4 NumFaces = mesh.nFaces(); /* number of unique faces */ - - INTEGER4 ICellMax = 0; /* Not Used, set to zero */ - INTEGER4 JCellMax = 0; /* Not Used, set to zero */ - INTEGER4 KCellMax = 0; /* Not Used, set to zero */ - - double SolTime = runTime_.value(); /* solution time */ - INTEGER4 ParentZone = 0; /* no parent zone */ - - INTEGER4 IsBlock = 1; /* block format */ - - INTEGER4 NFConns = 0; /* not used for FEPolyhedron - * zones - */ - INTEGER4 FNMode = 0; /* not used for FEPolyhedron - * zones - */ -Pout<< "zoneName:" << zoneName - //<< " varLocArray:" << varLocArray - << " solTime:" << SolTime - << endl; - - - - INTEGER4 *PassiveVarArray = nullptr; - INTEGER4 *VarShareArray = nullptr; - INTEGER4 ShrConn = 0; - - INTEGER4 NumBConns = 0; /* No Boundary Connections */ - INTEGER4 NumBItems = 0; /* No Boundary Items */ - - INTEGER4 ZoneType = ZoneType_FEPolyhedron; - + const int32_t NumNodes = mesh.nPoints(); // Number of unique nodes + const int32_t NumElems = mesh.nCells(); // Number of elements + const int32_t NumFaces = mesh.nFaces(); // Number of unique faces + const double SolTime = time_.value(); // Solution time + + const int32_t ParentZone = 0; // Bool: 0 = no parent zone + const int32_t ShrConn = 0; + const int32_t NumBConns = 0; // No Boundary Connections + const int32_t NumBItems = 0; // No Boundary Items + + Pout<< "zoneName:" << zoneName + //<< " varLocArray:" << varLocArray + << " solTime:" << SolTime + << " strand:" << strandID + << endl; + + const int32_t ZoneType = ZONE_FEPOLYHEDRON; if ( - !TECZNE112 + teczne142 ( - const_cast<char*>(zoneName.c_str()), - &ZoneType, - &NumNodes, - &NumElems, - &NumFaces, - &ICellMax, - &JCellMax, - &KCellMax, - &SolTime, - &strandID, - &ParentZone, - &IsBlock, - &NFConns, - &FNMode, - &nFaceNodes, - &NumBConns, - &NumBItems, - PassiveVarArray, - const_cast<INTEGER4*>(varLocArray.begin()), - VarShareArray, - &ShrConn + zoneName.c_str(), //< ZoneTitle + &ZoneType, //< ZoneType + &NumNodes, //< IMxOrNumPts + &NumElems, //< JMxOrNumElements + &NumFaces, //< KMxOrNumFaces + &tecConst_0, //< (unused set to zero) ICellMax + &tecConst_0, //< (unused set to zero) JCellMax + &tecConst_0, //< (unused set to zero) KCellMax + &SolTime, //< SolutionTime + &strandID, //< StrandID + &ParentZone, //< ParentZone + &tecConst_True, //< IsBlock + &tecConst_0, //< (unused) NumFaceConnections + &tecConst_0, //< (unused) FaceNeighborMode + &NumFaceNodes, //< TotalNumFaceNodes + &NumBConns, //< NumConnectedBoundaryFaces + &NumBItems, //< TotalNumBoundaryConnections + nullptr, //< PassiveVarList + varLocArray.cdata(), //< ValueLocation + nullptr, //< ShareVarFromZone + &ShrConn //< ShareConnectivityFromZone ) ) { -// FatalErrorInFunction -// << "Error in TECZNE112." << exit(FatalError); + FatalErrorInFunction + << "Error in teczne142 - writing polyhedron zones." + << exit(FatalError); } } @@ -157,79 +151,61 @@ Pout<< "zoneName:" << zoneName void Foam::tecplotWriter::writePolygonalZone ( const word& zoneName, - INTEGER4 strandID, + const int32_t strandID, const indirectPrimitivePatch& pp, - const List<INTEGER4>& varLocArray + const UList<int32_t>& varLocArray ) const { - /* Call TECZNE112 */ - INTEGER4 NumNodes = pp.nPoints(); /* number of unique nodes */ - INTEGER4 NumElems = pp.size(); /* number of elements */ - INTEGER4 NumFaces = pp.nEdges(); /* number of unique faces */ - - INTEGER4 ICellMax = 0; /* Not Used, set to zero */ - INTEGER4 JCellMax = 0; /* Not Used, set to zero */ - INTEGER4 KCellMax = 0; /* Not Used, set to zero */ - - double SolTime = runTime_.value(); /* solution time */ - INTEGER4 ParentZone = 0; /* no parent zone */ - - INTEGER4 IsBlock = 1; /* block format */ - - INTEGER4 NFConns = 0; /* not used for FEPolyhedron - * zones - */ - INTEGER4 FNMode = 0; /* not used for FEPolyhedron - * zones - */ - INTEGER4 NumFaceNodes = 2*pp.nEdges(); + const int32_t NumNodes = pp.nPoints(); // Number of unique nodes + const int32_t NumElems = pp.size(); // Number of elements + const int32_t NumFaces = pp.nEdges(); // Number of unique faces + const double SolTime = time_.value(); // Solution time -Pout<< "zoneName:" << zoneName - << " strandID:" << strandID - //<< " varLocArray:" << varLocArray - << " solTime:" << SolTime - << endl; + const int32_t ParentZone = 0; // Int: 0 = no parent zone + const int32_t NumFaceNodes = 2*pp.nEdges(); + const int32_t ShrConn = 0; + const int32_t NumBConns = 0; // No Boundary Connections + const int32_t NumBItems = 0; // No Boundary Items - INTEGER4 *PassiveVarArray = nullptr; - INTEGER4 *VarShareArray = nullptr; - INTEGER4 ShrConn = 0; - - INTEGER4 NumBConns = 0; /* No Boundary Connections */ - INTEGER4 NumBItems = 0; /* No Boundary Items */ - - INTEGER4 ZoneType = ZoneType_FEPolygon; + Pout<< "zoneName:" << zoneName + << " strandID:" << strandID + //<< " varLocArray:" << varLocArray + << " solTime:" << SolTime + << endl; + const int32_t ZoneType = ZONE_FEPOLYGON; if ( - !TECZNE112 + teczne142 ( - const_cast<char*>(zoneName.c_str()), - &ZoneType, - &NumNodes, - &NumElems, - &NumFaces, - &ICellMax, - &JCellMax, - &KCellMax, - &SolTime, - &strandID, - &ParentZone, - &IsBlock, - &NFConns, - &FNMode, - &NumFaceNodes, - &NumBConns, - &NumBItems, - PassiveVarArray, - const_cast<INTEGER4*>(varLocArray.begin()), - VarShareArray, - &ShrConn + zoneName.c_str(), //< ZoneTitle + &ZoneType, //< ZoneType + &NumNodes, //< IMax or NumPts + &NumElems, //< JMax or NumElements + &NumFaces, //< KMax or NumFaces + &tecConst_0, //< (Unused set to zero) ICellMax + &tecConst_0, //< (Unused set to zero) JCellMax + &tecConst_0, //< (Unused set to zero) KCellMax + &SolTime, //< SolutionTime + &strandID, //< StrandID + &ParentZone, //< ParentZone + &tecConst_True, //< IsBlock + &tecConst_0, //< (Unused for polygon zone) NumFaceConnections + &tecConst_0, //< (Unused for polygon zone) FaceNeighborMode + &NumFaceNodes, //< TotalNumFaceNodes + &NumBConns, //< NumConnectedBoundaryFaces + &NumBItems, //< TotalNumBoundaryConnections + nullptr, //< PassiveVarList + varLocArray.cdata(), //< ValueLocation + nullptr, //< ShareVarFromZone + &ShrConn //< ShareConnectivityFromZone ) ) { -// FatalErrorInFunction -// << "Error in TECZNE112." << exit(FatalError); + FatalErrorInFunction + << "Error in teczne142 - writing polygon zones." + << exit(FatalError); } } @@ -237,120 +213,99 @@ Pout<< "zoneName:" << zoneName void Foam::tecplotWriter::writeOrderedZone ( const word& zoneName, - INTEGER4 strandID, + const int32_t strandID, const label n, - const List<INTEGER4>& varLocArray + const UList<int32_t>& varLocArray ) const { - /* Call TECZNE112 */ - INTEGER4 IMax = n; /* number of unique nodes */ - INTEGER4 JMax = 1; /* number of elements */ - INTEGER4 KMax = 1; /* number of unique faces */ - - INTEGER4 ICellMax = 0; /* Not Used, set to zero */ - INTEGER4 JCellMax = 0; /* Not Used, set to zero */ - INTEGER4 KCellMax = 0; /* Not Used, set to zero */ - - double SolTime = runTime_.value(); /* solution time */ - INTEGER4 ParentZone = 0; /* no parent zone */ - - INTEGER4 IsBlock = 1; /* block format */ - - INTEGER4 NFConns = 0; /* not used for FEPolyhedron - * zones - */ - INTEGER4 FNMode = 0; /* not used for FEPolyhedron - * zones - */ - INTEGER4 NumFaceNodes = 1; - INTEGER4 NumBConns = 1; /* No Boundary Connections */ - INTEGER4 NumBItems = 1; /* No Boundary Items */ - -Pout<< "zoneName:" << zoneName - << " strandID:" << strandID - //<< " varLocArray:" << varLocArray - << " solTime:" << SolTime - << endl; - - - INTEGER4 *PassiveVarArray = nullptr; - INTEGER4 *VarShareArray = nullptr; - INTEGER4 ShrConn = 0; - - - INTEGER4 ZoneType = ZoneType_Ordered; - + const int32_t IMax = n; // Number in I direction + const int32_t JMax = 1; // Number in J direction + const int32_t KMax = 1; // Number in K direction + const double SolTime = time_.value(); // Solution time + + const int32_t ParentZone = 0; // Bool: no parent zone + const int32_t NFConns = 0; // Unused for ordered zones + const int32_t FNMode = 0; // Unused for ordered zones + + const int32_t ShrConn = 0; + const int32_t NumFaceNodes = 1; + const int32_t NumBConns = 0; // No Boundary Connections + const int32_t NumBItems = 0; // No Boundary Items + + Pout<< "zoneName:" << zoneName + << " strandID:" << strandID + //<< " varLocArray:" << varLocArray + << " solTime:" << SolTime + << endl; + + const int32_t ZoneType = ZONE_ORDERED; if ( - !TECZNE112 + teczne142 ( - const_cast<char*>(zoneName.c_str()), - &ZoneType, - &IMax, - &JMax, - &KMax, - &ICellMax, - &JCellMax, - &KCellMax, - &SolTime, - &strandID, - &ParentZone, - &IsBlock, - &NFConns, - &FNMode, - &NumFaceNodes, - &NumBConns, - &NumBItems, - PassiveVarArray, - const_cast<INTEGER4*>(varLocArray.begin()), - VarShareArray, - &ShrConn + zoneName.c_str(), //< ZoneTitle + &ZoneType, //< ZoneType + &IMax, //< IMax or NumPts + &JMax, //< JMax or NumElements + &KMax, //< KMax or NumFaces + &tecConst_0, //< (Unused set to zero) ICellMax + &tecConst_0, //< (Unused set to zero) JCellMax + &tecConst_0, //< (Unused set to zero) KCellMax + &SolTime, //< SolutionTime + &strandID, //< StrandID + &ParentZone, //< ParentZone + &tecConst_True, //< IsBlock + &NFConns, //< NumFaceConnections + &FNMode, //< FaceNeighborMode + &NumFaceNodes, //< TotalNumFaceNodes + &NumBConns, //< NumConnectedBoundaryFaces + &NumBItems, //< TotalNumBoundaryConnections + nullptr, //< PassiveVarList + varLocArray.cdata(), //< ValueLocation + nullptr, //< ShareVarFromZone + &ShrConn //< ShareConnectivityFromZone ) ) { -// FatalErrorInFunction -// << "Error in TECZNE112." << exit(FatalError); + FatalErrorInFunction + << "Error in teczne142 - writing ordered zones." + << exit(FatalError); } } void Foam::tecplotWriter::writeConnectivity(const fvMesh& mesh) const { - List<INTEGER4> FaceNodeCounts(mesh.nFaces()); - + // first pass: get the sizes + List<int32_t> FaceNodeCounts(mesh.nFaces()); + label nFaceNodes = 0; forAll(mesh.faces(), facei) { const face& f = mesh.faces()[facei]; - FaceNodeCounts[facei] = INTEGER4(f.size()); - } - - - INTEGER4 nFaceNodes = 0; - forAll(mesh.faces(), facei) - { - nFaceNodes += mesh.faces()[facei].size(); + nFaceNodes += f.size(); + FaceNodeCounts[facei] = int32_t(f.size()); } - - List<INTEGER4> FaceNodes(nFaceNodes); + // second pass: get the nodes as a flat list + List<int32_t> FaceNodes(nFaceNodes); label nodeI = 0; forAll(mesh.faces(), facei) { const face& f = mesh.faces()[facei]; forAll(f, fp) { - FaceNodes[nodeI++] = INTEGER4(f[fp]+1); + FaceNodes[nodeI++] = int32_t(f[fp]+1); } } - List<INTEGER4> FaceLeftElems(mesh.nFaces()); + List<int32_t> FaceLeftElems(mesh.nFaces()); forAll(mesh.faceOwner(), facei) { FaceLeftElems[facei] = mesh.faceOwner()[facei]+1; } - List<INTEGER4> FaceRightElems(mesh.nFaces()); + List<int32_t> FaceRightElems(mesh.nFaces()); forAll(mesh.faceNeighbour(), facei) { FaceRightElems[facei] = mesh.faceNeighbour()[facei]+1; @@ -367,20 +322,21 @@ void Foam::tecplotWriter::writeConnectivity(const fvMesh& mesh) const if ( - !TECPOLY112 + tecpoly142 ( - FaceNodeCounts.begin(), /* The face node counts array */ - FaceNodes.begin(), /* The face nodes array */ - FaceLeftElems.begin(), /* The left elements array */ - FaceRightElems.begin(), /* The right elements array */ - nullptr, /* No boundary connection counts */ - nullptr, /* No boundary connection elements */ - nullptr /* No boundary connection zones */ + FaceNodeCounts.cdata(), // The face node counts array + FaceNodes.cdata(), // The face nodes array + FaceLeftElems.cdata(), // The left elements array + FaceRightElems.cdata(), // The right elements array + nullptr, // No face boundary connection counts + nullptr, // No face boundary connection elements + nullptr // No face boundary connection zones ) ) { -// FatalErrorInFunction -// << "Error in TECPOLY112." << exit(FatalError); + FatalErrorInFunction + << "Error in tecpoly142." + << exit(FatalError); } } @@ -389,25 +345,25 @@ void Foam::tecplotWriter::writeConnectivity const indirectPrimitivePatch& pp ) const { - INTEGER4 NumFaces = pp.nEdges(); /* number of unique faces */ - INTEGER4 NumFaceNodes = 2*pp.nEdges(); + const int32_t NumFaces = pp.nEdges(); // Number of unique faces + const int32_t NumFaceNodes = 2*NumFaces; // 2 nodes per edge // All faces (=edges) have 2 nodes - List<INTEGER4> FaceNodeCounts(NumFaces); + List<int32_t> FaceNodeCounts(NumFaces); FaceNodeCounts = 2; - List<INTEGER4> FaceNodes(NumFaceNodes); + List<int32_t> FaceNodes(NumFaceNodes); label nodeI = 0; - forAll(pp.edges(), edgeI) + forAll(pp.edges(), edgei) { - edge e = pp.edges()[edgeI]; + edge e = pp.edges()[edgei]; if (e[0] > e[1]) { e.flip(); } - FaceNodes[nodeI++] = INTEGER4(e[0]+1); - FaceNodes[nodeI++] = INTEGER4(e[1]+1); + FaceNodes[nodeI++] = int32_t(e[0]+1); + FaceNodes[nodeI++] = int32_t(e[1]+1); } /* Define the right and left elements of each face. @@ -430,22 +386,22 @@ void Foam::tecplotWriter::writeConnectivity * (element 0). */ - List<INTEGER4> FaceLeftElems(NumFaces); - List<INTEGER4> FaceRightElems(NumFaces); + List<int32_t> FaceLeftElems(NumFaces); + List<int32_t> FaceRightElems(NumFaces); const labelListList& edgeFaces = pp.edgeFaces(); - forAll(edgeFaces, edgeI) + forAll(edgeFaces, edgei) { - const labelList& eFaces = edgeFaces[edgeI]; + const labelList& eFaces = edgeFaces[edgei]; if (eFaces.size() == 1) { - FaceLeftElems[edgeI] = 0; - FaceRightElems[edgeI] = eFaces[0]+1; + FaceLeftElems[edgei] = 0; + FaceRightElems[edgei] = eFaces[0]+1; } else if (eFaces.size() == 2) { - edge e = pp.edges()[edgeI]; + edge e = pp.edges()[edgei]; if (e[0] > e[1]) { e.flip(); @@ -456,59 +412,60 @@ void Foam::tecplotWriter::writeConnectivity // The face that uses the vertices of e in increasing order // is the left face. - label fp = findIndex(f0, e[0]); - bool f0IsLeft = (f0.nextLabel(fp) == e[1]); + const label fp = findIndex(f0, e[0]); + const bool f0IsLeft = (f0.nextLabel(fp) == e[1]); if (f0IsLeft) { - FaceLeftElems[edgeI] = eFaces[0]+1; - FaceRightElems[edgeI] = eFaces[1]+1; + FaceLeftElems[edgei] = eFaces[0]+1; + FaceRightElems[edgei] = eFaces[1]+1; } else { - FaceLeftElems[edgeI] = eFaces[1]+1; - FaceRightElems[edgeI] = eFaces[0]+1; + FaceLeftElems[edgei] = eFaces[1]+1; + FaceRightElems[edgei] = eFaces[0]+1; } } else { // non-manifold. Treat as if open. - FaceLeftElems[edgeI] = 0; - FaceRightElems[edgeI] = eFaces[0]+1; + FaceLeftElems[edgei] = 0; + FaceRightElems[edgei] = eFaces[0]+1; } } - /* Write the face map (created above) using TECPOLY112. */ + // Write the face map (created above) if ( - !TECPOLY112 + tecpoly142 ( - FaceNodeCounts.begin(), /* The face node counts array */ - FaceNodes.begin(), /* The face nodes array */ - FaceLeftElems.begin(), /* The left elements array */ - FaceRightElems.begin(), /* The right elements array */ - nullptr, /* No boundary connection counts */ - nullptr, /* No boundary connection elements */ - nullptr /* No boundary connection zones */ + FaceNodeCounts.cdata(), // Face node counts array + FaceNodes.cdata(), // Face nodes array + FaceLeftElems.cdata(), // Left elements array + FaceRightElems.cdata(), // Right elements array + nullptr, // No boundary connection counts + nullptr, // No boundary connection elements + nullptr // No boundary connection zones ) ) { -// FatalErrorInFunction -// << "Error in TECPOLY112." << exit(FatalError); + FatalErrorInFunction + << "Error in tecpoly142." + << exit(FatalError); } } void Foam::tecplotWriter::writeEnd() const { -Pout<< "writeEnd" << endl; + Pout<< "writeEnd" << endl; - if (!TECEND112()) + if (tecend142()) { -// FatalErrorInFunction -// << "Error in TECEND112." << exit(FatalError); + FatalErrorInFunction + << "Error in tecend142." + << exit(FatalError); } - } diff --git a/applications/utilities/postProcessing/dataConversion/foamToTecplot360/tecplotWriter.H b/applications/utilities/postProcessing/dataConversion/foamToTecplot360/tecplotWriter.H index d00bec35579..1631545fc62 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToTecplot360/tecplotWriter.H +++ b/applications/utilities/postProcessing/dataConversion/foamToTecplot360/tecplotWriter.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -27,6 +27,11 @@ Class Description Write binary tecplot files using tecio. +Note + The tecplot API uses pass by reference for all routines. + Its standard integer is defined as INTEGER4 (ie, int32_t), + which is also used when passing boolean values. + SourceFiles tecplotWriter.C tecplotWriterTemplates.C @@ -36,14 +41,11 @@ SourceFiles #ifndef tecplotWriter_H #define tecplotWriter_H -#include "TECIO.h" #include "Time.H" #include "indirectPrimitivePatch.H" #include "volFields.H" #include "surfaceFields.H" -using namespace Foam; - // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam @@ -52,15 +54,76 @@ namespace Foam class fvMesh; /*---------------------------------------------------------------------------*\ - Class tecplotWriter Declaration + Class tecplotWriter Declaration \*---------------------------------------------------------------------------*/ class tecplotWriter { - const Time& runTime_; + //- Tecplot ZoneTypes + enum tecplotZoneType + { + ZONE_ORDERED = 0, + ZONE_FELINESEG = 1, + ZONE_FETRIANGLE = 2, + ZONE_FEQUADRILATERAL = 3, + ZONE_FETETRAHEDRON = 4, + ZONE_FEBRICK = 5, + ZONE_FEPOLYGON = 6, + ZONE_FEPOLYHEDRON = 7 + }; + + + // Static data members + + // Values commonly used internally + static const int32_t tecConst_0; + static const int32_t tecConst_1; + static const int32_t tecConst_False; + static const int32_t tecConst_True; + + + // Private data + + //- Time reference. Used for paths and the solution time. + const Time& time_; + + + // Private Member Functions + + template<class GeoField> + static wordList getNames(const PtrList<const GeoField>&); + + //- Disallow default bitwise copy construct + tecplotWriter(const tecplotWriter&) = delete; + + //- Disallow default bitwise assignment + void operator=(const tecplotWriter&) = delete; public: + //- Data location types + enum dataLocation + { + CELL_CENTERED = 0, + NODE_CENTERED = 1 + }; + + + //- Data file type + enum dataFileType + { + FILETYPE_FULL = 0, + FILETYPE_GRID = 1, + FILETYPE_SOLUTION = 2 + }; + + + // Static data members + + //- Commonly used "X Y Z" string + static const string XYZ; + + // Constructors //- Construct from components @@ -69,92 +132,103 @@ public: // Member Functions + //- Initialize writing void writeInit ( const word& name, const string& varNames, const fileName&, - INTEGER4 tecplotFileType + const dataFileType fileType ) const; //- Write mesh as polyhedral zone void writePolyhedralZone ( const word& zoneName, - const INTEGER4 strandID, + const int32_t strandID, const fvMesh& mesh, - const List<INTEGER4>& varLocArray, - INTEGER4 nFaceNodes + const UList<int32_t>& varLocArray, + const int32_t NumFaceNodes ) const; //- Write surface as polygonal zone void writePolygonalZone ( const word& zoneName, - const INTEGER4 strandID, + const int32_t strandID, const indirectPrimitivePatch& pp, - const List<INTEGER4>& varLocArray + const UList<int32_t>& varLocArray ) const; //- Write unordered data (or rather 1D ordered) void writeOrderedZone ( const word& zoneName, - INTEGER4 strandID, + const int32_t strandID, const label n, - const List<INTEGER4>& varLocArray + const UList<int32_t>& varLocArray ) const; //- Write mesh - void writeConnectivity(const fvMesh& mesh) const; + void writeConnectivity(const fvMesh&) const; //- Write surface void writeConnectivity(const indirectPrimitivePatch& pp) const; + //- Finalize writing void writeEnd() const; - //- Write generic Field + + //- Write generic Field, component-wise template<class Type> - void writeField(const Field<Type>& fld) const; + void writeField(const Field<Type>&) const; + + //- Write generic Field, component-wise + template<class Type> + void writeField(const tmp<Field<Type>>&) const; + + //- Write all fields listed + template<class GeoField> + void writeFields(const PtrList<const GeoField>&) const; //- Get either fvPatchField or patchInternalField template<class Type> - tmp<Field<Type>> getPatchField + static tmp<Field<Type>> getPatchField ( const bool nearCellValue, - const GeometricField<Type, fvPatchField, volMesh>& vfld, + const GeometricField<Type, fvPatchField, volMesh>&, const label patchi - ) const; + ); //- Get mixed field: fvsPatchField for boundary faces and // internalField for internal faces. template<class Type> - tmp<Field<Type>> getFaceField + static tmp<Field<Type>> getFaceField ( const GeometricField<Type, fvsPatchField, surfaceMesh>&, - const labelList& faceLabels - ) const; + const labelUList& faceLabels + ); - template<class GeoField> - static wordList getNames(const PtrList<GeoField>&); + //- Fill in tecplot names/locations for the given input names template<class Type> static void getTecplotNames ( const wordList& names, - const INTEGER4 loc, + const int32_t loc, string& varNames, - DynamicList<INTEGER4>& varLocation + DynamicList<int32_t>& varLocation ); + //- Fill in tecplot names/locations for the given input fields template<class GeoField> static void getTecplotNames ( const PtrList<GeoField>& flds, - const INTEGER4 loc, + const int32_t loc, string& varNames, - DynamicList<INTEGER4>& varLocation + DynamicList<int32_t>& varLocation ); }; diff --git a/applications/utilities/postProcessing/dataConversion/foamToTecplot360/tecplotWriterTemplates.C b/applications/utilities/postProcessing/dataConversion/foamToTecplot360/tecplotWriterTemplates.C index 7d8496faabd..03ad615e6a0 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToTecplot360/tecplotWriterTemplates.C +++ b/applications/utilities/postProcessing/dataConversion/foamToTecplot360/tecplotWriterTemplates.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -23,14 +23,8 @@ License \*---------------------------------------------------------------------------*/ -//extern "C" -//{ - #include "MASTER.h" - #include "GLOBAL.h" -//} - #include "tecplotWriter.H" - +#include "TECIO.h" #include "fvc.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -38,39 +32,71 @@ License template<class Type> void Foam::tecplotWriter::writeField(const Field<Type>& fld) const { - for (direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++) + typedef typename pTraits<Type>::cmptType cmptType; + + for (direction cmpt = 0; cmpt < pTraits<Type>::nComponents; ++cmpt) { - scalarField cmptFld(fld.component(cmpt)); + tmp<Field<cmptType>> tcmptFld = fld.component(cmpt); + const Field<cmptType>& cmptFld = tcmptFld(); + + const int32_t size = int32_t(cmptFld.size()); // Convert to float - Field<float> floats(cmptFld.size()); + Field<float> floats(size); forAll(cmptFld, i) { floats[i] = float(cmptFld[i]); } - INTEGER4 size = INTEGER4(floats.size()); - INTEGER4 IsDouble = 0; //float - //Pout<< "Writing component:" << cmpt << " of size:" << size // << " floats." << endl; - if (!TECDAT112(&size, floats.begin(), &IsDouble)) + if + ( + tecdat142 + ( + &size, + floats.cdata(), + &tecConst_False //< VIsDouble (0: single, 1: double) + ) + ) { -// FatalErrorInFunction -// << "Error in TECDAT112." << exit(FatalError); + FatalErrorInFunction + << "Error in tecdat142." + << exit(FatalError); } } } template<class Type> -Foam::tmp<Field<Type>> Foam::tecplotWriter::getPatchField +void Foam::tecplotWriter::writeField(const tmp<Field<Type>>& tfld) const +{ + writeField(tfld()); +} + + +template<class GeoField> +void Foam::tecplotWriter::writeFields +( + const PtrList<const GeoField>& flds +) const +{ + forAll(flds, i) + { + writeField(flds[i]); + } +} + + +template<class Type> +Foam::tmp<Foam::Field<Type>> +Foam::tecplotWriter::getPatchField ( const bool nearCellValue, const GeometricField<Type, fvPatchField, volMesh>& vfld, const label patchi -) const +) { if (nearCellValue) { @@ -84,11 +110,12 @@ Foam::tmp<Field<Type>> Foam::tecplotWriter::getPatchField template<class Type> -Foam::tmp<Field<Type>> Foam::tecplotWriter::getFaceField +Foam::tmp<Foam::Field<Type>> +Foam::tecplotWriter::getFaceField ( const GeometricField<Type, fvsPatchField, surfaceMesh>& sfld, - const labelList& faceLabels -) const + const labelUList& faceLabels +) { const polyBoundaryMesh& patches = sfld.mesh().boundaryMesh(); @@ -97,9 +124,8 @@ Foam::tmp<Field<Type>> Foam::tecplotWriter::getFaceField forAll(faceLabels, i) { - label facei = faceLabels[i]; - - label patchi = patches.whichPatch(facei); + const label facei = faceLabels[i]; + const label patchi = patches.whichPatch(facei); if (patchi == -1) { @@ -117,9 +143,10 @@ Foam::tmp<Field<Type>> Foam::tecplotWriter::getFaceField template<class GeoField> -Foam::wordList Foam::tecplotWriter::getNames +Foam::wordList +Foam::tecplotWriter::getNames ( - const PtrList<GeoField>& flds + const PtrList<const GeoField>& flds ) { wordList names(flds.size()); @@ -135,11 +162,13 @@ template<class Type> void Foam::tecplotWriter::getTecplotNames ( const wordList& names, - const INTEGER4 loc, + const int32_t loc, string& varNames, - DynamicList<INTEGER4>& varLocation + DynamicList<int32_t>& varLocation ) { + const direction nCmpts = pTraits<Type>::nComponents; + forAll(names, i) { if (!varNames.empty()) @@ -147,8 +176,6 @@ void Foam::tecplotWriter::getTecplotNames varNames += " "; } - label nCmpts = pTraits<Type>::nComponents; - if (nCmpts == 1) { varNames += names[i]; @@ -156,19 +183,13 @@ void Foam::tecplotWriter::getTecplotNames } else { - for - ( - direction cmpt = 0; - cmpt < nCmpts; - cmpt++ - ) + for (direction cmpt = 0; cmpt < nCmpts; ++cmpt) { - string fldName = - (cmpt != 0 ? " " : string::null) - + names[i] - + "_" - + pTraits<Type>::componentNames[cmpt]; - varNames += fldName; + varNames += + ( + (cmpt ? " " : string::null) + + names[i] + "_" + pTraits<Type>::componentNames[cmpt] + ); varLocation.append(loc); } } @@ -180,9 +201,9 @@ template<class GeoField> void Foam::tecplotWriter::getTecplotNames ( const PtrList<GeoField>& flds, - const INTEGER4 loc, + const int32_t loc, string& varNames, - DynamicList<INTEGER4>& varLocation + DynamicList<int32_t>& varLocation ) { getTecplotNames<typename GeoField::value_type> -- GitLab