From 2495fcb42e9697aebde36288495335b40dacca47 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Mon, 22 May 2017 16:13:53 +0200 Subject: [PATCH] ENH: replace foamToVTK routines with library-level equivalents --- .../dataConversion/foamToVTK/Allwmake | 10 - .../dataConversion/foamToVTK/Make/files | 1 + .../dataConversion/foamToVTK/Make/options | 5 +- .../dataConversion/foamToVTK/foamToVTK.C | 857 ++++++++++-------- .../foamToVTK/foamToVTK/Make/files | 13 - .../foamToVTK/foamToVTK/Make/options | 10 - .../foamToVTK/foamToVTK/internalWriter.C | 165 ---- .../foamToVTK/foamToVTK/internalWriter.H | 135 --- .../foamToVTK/internalWriterTemplates.C | 99 -- .../foamToVTK/foamToVTK/vtkMesh.H | 137 --- .../foamToVTK/foamToVTK/vtkTopo.C | 373 -------- .../foamToVTK/foamToVTK/vtkTopo.H | 139 --- .../foamToVTK/foamToVTK/writeFaceSet.C | 127 --- .../foamToVTK/foamToVTK/writeFaceSet.H | 63 -- .../foamToVTK/foamToVTK/writeFuns.C | 264 ------ .../foamToVTK/foamToVTK/writeFuns.H | 161 ---- .../foamToVTK/foamToVTK/writeFunsTemplates.C | 146 --- .../foamToVTK/foamToVTK/writePointSet.C | 103 --- .../foamToVTK/foamToVTK/writePointSet.H | 63 -- .../foamToVTK/foamToVTK/writeVTK/controlDict | 81 -- ...gianWriter.C => foamVtkLagrangianWriter.C} | 55 +- ...gianWriter.H => foamVtkLagrangianWriter.H} | 34 +- ...s.C => foamVtkLagrangianWriterTemplates.C} | 22 +- .../foamToVTK/{foamToVTK => }/readFields.C | 0 .../foamToVTK/{foamToVTK => }/readFields.H | 2 +- src/conversion/Make/files | 5 + .../vtk/output/foamVtkInternalWriter.C | 132 +++ .../vtk/output/foamVtkInternalWriter.H | 191 ++++ .../output/foamVtkInternalWriterTemplates.C | 195 ++++ .../vtk/output/foamVtkOutputFieldsTemplates.C | 1 - .../vtk/output/foamVtkPatchWriter.C | 106 ++- .../vtk/output/foamVtkPatchWriter.H | 83 +- .../vtk/output/foamVtkPatchWriterTemplates.C | 88 +- .../vtk/output/foamVtkSurfaceMeshWriter.C | 61 +- .../vtk/output/foamVtkSurfaceMeshWriter.H | 40 +- .../foamVtkSurfaceMeshWriterTemplates.C | 20 +- .../vtk/output/foamVtkWriteSurfFields.C | 67 +- .../vtk/output/foamVtkWriteSurfFields.H | 17 +- src/functionObjects/utilities/Make/files | 1 + .../utilities}/writeVTK/writeVTK.C | 53 +- .../utilities}/writeVTK/writeVTK.H | 16 +- .../utilities}/writeVTK/writeVTKTemplates.C | 0 42 files changed, 1381 insertions(+), 2760 deletions(-) delete mode 100755 applications/utilities/postProcessing/dataConversion/foamToVTK/Allwmake delete mode 100644 applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK/Make/files delete mode 100644 applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK/Make/options delete mode 100644 applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK/internalWriter.C delete mode 100644 applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK/internalWriter.H delete mode 100644 applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK/internalWriterTemplates.C delete mode 100644 applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK/vtkMesh.H delete mode 100644 applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK/vtkTopo.C delete mode 100644 applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK/vtkTopo.H delete mode 100644 applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK/writeFaceSet.C delete mode 100644 applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK/writeFaceSet.H delete mode 100644 applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK/writeFuns.C delete mode 100644 applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK/writeFuns.H delete mode 100644 applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK/writeFunsTemplates.C delete mode 100644 applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK/writePointSet.C delete mode 100644 applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK/writePointSet.H delete mode 100644 applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK/writeVTK/controlDict rename applications/utilities/postProcessing/dataConversion/foamToVTK/{foamToVTK/lagrangianWriter.C => foamVtkLagrangianWriter.C} (66%) rename applications/utilities/postProcessing/dataConversion/foamToVTK/{foamToVTK/lagrangianWriter.H => foamVtkLagrangianWriter.H} (82%) rename applications/utilities/postProcessing/dataConversion/foamToVTK/{foamToVTK/lagrangianWriterTemplates.C => foamVtkLagrangianWriterTemplates.C} (80%) rename applications/utilities/postProcessing/dataConversion/foamToVTK/{foamToVTK => }/readFields.C (100%) rename applications/utilities/postProcessing/dataConversion/foamToVTK/{foamToVTK => }/readFields.H (98%) create mode 100644 src/conversion/vtk/output/foamVtkInternalWriter.C create mode 100644 src/conversion/vtk/output/foamVtkInternalWriter.H create mode 100644 src/conversion/vtk/output/foamVtkInternalWriterTemplates.C rename applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK/patchWriter.C => src/conversion/vtk/output/foamVtkPatchWriter.C (55%) rename applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK/patchWriter.H => src/conversion/vtk/output/foamVtkPatchWriter.H (64%) rename applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK/patchWriterTemplates.C => src/conversion/vtk/output/foamVtkPatchWriterTemplates.C (51%) rename applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK/surfaceMeshWriter.C => src/conversion/vtk/output/foamVtkSurfaceMeshWriter.C (56%) rename applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK/surfaceMeshWriter.H => src/conversion/vtk/output/foamVtkSurfaceMeshWriter.H (81%) rename applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK/surfaceMeshWriterTemplates.C => src/conversion/vtk/output/foamVtkSurfaceMeshWriterTemplates.C (83%) rename applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK/writeSurfFields.C => src/conversion/vtk/output/foamVtkWriteSurfFields.C (64%) rename applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK/writeSurfFields.H => src/conversion/vtk/output/foamVtkWriteSurfFields.H (87%) rename {applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK => src/functionObjects/utilities}/writeVTK/writeVTK.C (81%) rename {applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK => src/functionObjects/utilities}/writeVTK/writeVTK.H (92%) rename {applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK => src/functionObjects/utilities}/writeVTK/writeVTKTemplates.C (100%) diff --git a/applications/utilities/postProcessing/dataConversion/foamToVTK/Allwmake b/applications/utilities/postProcessing/dataConversion/foamToVTK/Allwmake deleted file mode 100755 index 81e0196f99..0000000000 --- a/applications/utilities/postProcessing/dataConversion/foamToVTK/Allwmake +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/sh -cd ${0%/*} || exit 1 # Run from this directory - -# Parse arguments for library compilation -. $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments - -wmake $targetType foamToVTK -wmake $targetType - -#------------------------------------------------------------------------------ diff --git a/applications/utilities/postProcessing/dataConversion/foamToVTK/Make/files b/applications/utilities/postProcessing/dataConversion/foamToVTK/Make/files index f10482758a..aaec9f26ab 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToVTK/Make/files +++ b/applications/utilities/postProcessing/dataConversion/foamToVTK/Make/files @@ -1,3 +1,4 @@ +foamVtkLagrangianWriter.C foamToVTK.C EXE = $(FOAM_APPBIN)/foamToVTK diff --git a/applications/utilities/postProcessing/dataConversion/foamToVTK/Make/options b/applications/utilities/postProcessing/dataConversion/foamToVTK/Make/options index c2445fd549..541ffa86ae 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToVTK/Make/options +++ b/applications/utilities/postProcessing/dataConversion/foamToVTK/Make/options @@ -1,12 +1,13 @@ EXE_INC = \ - -IfoamToVTK/lnInclude \ + -I$(LIB_SRC)/fileFormats/lnInclude \ + -I$(LIB_SRC)/conversion/lnInclude \ -I$(LIB_SRC)/lagrangian/basic/lnInclude \ -I$(LIB_SRC)/finiteVolume/lnInclude \ -I$(LIB_SRC)/dynamicMesh/lnInclude \ -I$(LIB_SRC)/meshTools/lnInclude EXE_LIBS = \ - -lfoamToVTK \ + -lconversion \ -ldynamicMesh \ -llagrangian \ -lgenericPatchFields diff --git a/applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK.C b/applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK.C index dcf612a663..1cc6bed8ec 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK.C +++ b/applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK.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 | Copyright (C) 2016 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -103,7 +103,7 @@ Usage use the time index in the VTK file name instead of the time index Note - mesh subset is handled by vtkMesh. Slight inconsistency in + mesh subset is handled by meshSubsetHelper. Slight inconsistency in interpolation: on the internal field it interpolates the whole volField to the whole-mesh pointField and then selects only those values it needs for the subMesh (using the fvMeshSubset cellMap(), pointMap() @@ -154,25 +154,26 @@ Note #include "passiveParticle.H" #include "stringListOps.H" -#include "vtkMesh.H" +#include "meshSubsetHelper.H" #include "readFields.H" -#include "writeFuns.H" +#include "faceSet.H" +#include "pointSet.H" -#include "internalWriter.H" -#include "patchWriter.H" -#include "lagrangianWriter.H" - -#include "writeFaceSet.H" -#include "writePointSet.H" -#include "surfaceMeshWriter.H" -#include "writeSurfFields.H" +#include "foamVtkOutputOptions.H" +#include "foamVtkInternalWriter.H" +#include "foamVtkPatchWriter.H" +#include "foamVtkSurfaceMeshWriter.H" +#include "foamVtkLagrangianWriter.H" +#include "foamVtkWriteFaceSet.H" +#include "foamVtkWritePointSet.H" +#include "foamVtkWriteSurfFields.H" #include "memInfo.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // template -void print(const char* msg, Ostream& os, const PtrList& flds) +void print(const char* msg, Ostream& os, const UPtrList& flds) { if (flds.size()) { @@ -234,6 +235,56 @@ labelList getSelectedPatches } +// +// Process args for output options +// Default from foamVtkOutputOptions is inline ASCII xml +// +enum foamVtkOutput::formatType getOutputOptions(const argList& args) +{ + if (!args.optionFound("ascii")) + { + if (sizeof(floatScalar) != 4 || sizeof(label) != 4) + { + WarningInFunction + << "Using ASCII rather than binary VTK format since " + << "floatScalar and/or label are not 4 bytes in size." + << nl << endl; + } + else + { + return foamVtkOutput::formatType::LEGACY_BINARY; + } + } + + return foamVtkOutput::formatType::LEGACY_ASCII; +} + + +fileName relativeName(const fileName& parent, const fileName& file) +{ + string::size_type next = parent.size(); + if + ( + file.startsWith(parent) + && next < file.size() + && file[next] == '/' + ) + { + return file.substr(next+1); + } + else + { + return file; + } +} + + +fileName relativeName(const Time& runTime, const fileName& file) +{ + return relativeName(runTime.path(), file); +} + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // int main(int argc, char *argv[]) @@ -245,6 +296,7 @@ int main(int argc, char *argv[]) timeSelector::addOptions(); #include "addRegionOption.H" + argList::addOption ( "fields", @@ -299,7 +351,6 @@ int main(int argc, char *argv[]) "noLagrangian", "suppress writing lagrangian positions and fields" ); - argList::addBoolOption ( "noPointValues", @@ -345,22 +396,11 @@ int main(int argc, char *argv[]) const bool doWriteInternal = !args.optionFound("noInternal"); const bool doFaceZones = !args.optionFound("noFaceZones"); const bool doLinks = !args.optionFound("noLinks"); - bool binary = !args.optionFound("ascii"); const bool useTimeName = args.optionFound("useTimeName"); const bool noLagrangian = args.optionFound("noLagrangian"); - // Decomposition of polyhedral cells into tets/pyramids cells - vtkTopo::decomposePoly = decomposePoly; - - if (binary && (sizeof(floatScalar) != 4 || sizeof(label) != 4)) - { - WarningInFunction - << "Using ASCII rather than binary VTK format because " - "floatScalar and/or label are not 4 bytes in size." - << nl << endl; - binary = false; - } - + const enum foamVtkOutput::formatType fmtType = getOutputOptions(args); + const bool binary = (fmtType == foamVtkOutput::formatType::LEGACY_BINARY); const bool nearCellValue = args.optionFound("nearCellValue"); if (nearCellValue) @@ -388,11 +428,9 @@ int main(int argc, char *argv[]) Info<< "Not including patches " << excludePatches << nl << endl; } - word cellSetName; - word faceSetName; - word pointSetName; string vtkName = runTime.caseName(); + word cellSetName; if (args.optionReadIfPresent("cellSet", cellSetName)) { vtkName = cellSetName; @@ -407,9 +445,12 @@ int main(int argc, char *argv[]) vtkName = vtkName.substr(i); } } - args.optionReadIfPresent("faceSet", faceSetName); - args.optionReadIfPresent("pointSet", pointSetName); + word faceSetName; + args.optionReadIfPresent("faceSet", faceSetName); + + word pointSetName; + args.optionReadIfPresent("pointSet", pointSetName); #include "createNamedMesh.H" @@ -450,9 +491,15 @@ int main(int argc, char *argv[]) instantList timeDirs = timeSelector::select0(runTime, args); - // Mesh wrapper: does subsetting and decomposition - vtkMesh vMesh(mesh, cellSetName); + meshSubsetHelper meshRef(mesh, meshSubsetHelper::SET, cellSetName); + + // Collect decomposition information etc. + foamVtkCells foamVtkMeshCells + ( + foamVtkCells::contentType::LEGACY, + decomposePoly + ); Info<< "VTK mesh topology: " << timer.cpuTimeIncrement() << " s, " @@ -471,20 +518,19 @@ int main(int argc, char *argv[]) // Check for new polyMesh/ and update mesh, fvMeshSubset and cell // decomposition. - polyMesh::readUpdateState meshState = vMesh.readUpdate(); - - const fvMesh& mesh = vMesh.mesh(); + polyMesh::readUpdateState meshState = meshRef.readUpdate(); + const fvMesh& mesh = meshRef.mesh(); if ( meshState == polyMesh::TOPO_CHANGE || meshState == polyMesh::TOPO_PATCH_CHANGE ) { - Info<< " Read new mesh" << nl << endl; + // Trigger change for vtk cells too + foamVtkMeshCells.clear(); } - // If faceSet: write faceSet only (as polydata) if (faceSetName.size()) { @@ -501,10 +547,16 @@ int main(int argc, char *argv[]) + timeDesc + ".vtk" ); + Info<< " faceSet : " + << relativeName(runTime, outputName) << nl; - Info<< " faceSet : " << outputName << endl; - - writeFaceSet(binary, vMesh.mesh(), set, outputName); + foamVtkOutput::writeFaceSet + ( + binary, + meshRef.mesh(), + set, + outputName + ); continue; } @@ -524,10 +576,16 @@ int main(int argc, char *argv[]) + timeDesc + ".vtk" ); + Info<< " pointSet : " + << relativeName(runTime, outputName) << nl; - Info<< " pointSet : " << outputName << endl; - - writePointSet(binary, vMesh.mesh(), set, outputName); + foamVtkOutput::writePointSet + ( + binary, + meshRef.mesh(), + set, + outputName + ); continue; } @@ -544,97 +602,139 @@ int main(int argc, char *argv[]) // Construct the vol fields (on the original mesh if subsetted) - PtrList vsf; - PtrList vvf; - PtrList vSpheretf; - PtrList vSymmtf; - PtrList vtf; + PtrList vScalarFld; + PtrList vVectorFld; + PtrList vSphTensorf; + PtrList vSymTensorFld; + PtrList vTensorFld; if (!specifiedFields || selectedFields.size()) { - readFields(vMesh, vMesh.baseMesh(), objects, selectedFields, vsf); - print(" volScalarFields :", Info, vsf); - - readFields(vMesh, vMesh.baseMesh(), objects, selectedFields, vvf); - print(" volVectorFields :", Info, vvf); + readFields + ( + meshRef, + meshRef.baseMesh(), + objects, + selectedFields, + vScalarFld + ); + print(" volScalar :", Info, vScalarFld); readFields ( - vMesh, - vMesh.baseMesh(), + meshRef, + meshRef.baseMesh(), objects, selectedFields, - vSpheretf + vVectorFld ); - print(" volSphericalTensorFields :", Info, vSpheretf); + print(" volVector :", Info, vVectorFld); readFields ( - vMesh, - vMesh.baseMesh(), + meshRef, + meshRef.baseMesh(), objects, selectedFields, - vSymmtf + vSphTensorf ); - print(" volSymmTensorFields :", Info, vSymmtf); + print(" volSphericalTensor :", Info, vSphTensorf); - readFields(vMesh, vMesh.baseMesh(), objects, selectedFields, vtf); - print(" volTensorFields :", Info, vtf); + readFields + ( + meshRef, + meshRef.baseMesh(), + objects, + selectedFields, + vSymTensorFld + ); + print(" volSymmTensor :", Info, vSymTensorFld); + + readFields + ( + meshRef, + meshRef.baseMesh(), + objects, + selectedFields, + vTensorFld + ); + print(" volTensor :", Info, vTensorFld); } - label nVolFields = - vsf.size() - + vvf.size() - + vSpheretf.size() - + vSymmtf.size() - + vtf.size(); + const label nVolFields = + vScalarFld.size() + + vVectorFld.size() + + vSphTensorf.size() + + vSymTensorFld.size() + + vTensorFld.size(); // Construct dimensioned fields - PtrList dsf; - PtrList dvf; - PtrList dSpheretf; - PtrList dSymmtf; - PtrList dtf; + PtrList dScalarFld; + PtrList dVectorFld; + PtrList dSphTensorFld; + PtrList dSymTensorFld; + PtrList dTensorFld; if (!specifiedFields || selectedFields.size()) { - readFields(vMesh, vMesh.baseMesh(), objects, selectedFields, dsf); - print(" volScalarFields::Internal :", Info, dsf); - - readFields(vMesh, vMesh.baseMesh(), objects, selectedFields, dvf); - print(" volVectorFields::Internal :", Info, dvf); + readFields + ( + meshRef, + meshRef.baseMesh(), + objects, + selectedFields, + dScalarFld + ); + print(" volScalar::Internal :", Info, dScalarFld); readFields ( - vMesh, - vMesh.baseMesh(), + meshRef, + meshRef.baseMesh(), objects, selectedFields, - dSpheretf + dVectorFld ); - print(" volSphericalTensorFields::Internal :", Info, dSpheretf); + print(" volVector::Internal :", Info, dVectorFld); readFields ( - vMesh, - vMesh.baseMesh(), + meshRef, + meshRef.baseMesh(), objects, selectedFields, - dSymmtf + dSphTensorFld ); - print(" volSymmTensorFields::Internal :", Info, dSymmtf); + print(" volSphericalTensor::Internal :", Info, dSphTensorFld); - readFields(vMesh, vMesh.baseMesh(), objects, selectedFields, dtf); - print(" volTensorFields::Internal :", Info, dtf); + readFields + ( + meshRef, + meshRef.baseMesh(), + objects, + selectedFields, + dSymTensorFld + ); + print(" volSymmTensor::Internal :", Info, dSymTensorFld); + + readFields + ( + meshRef, + meshRef.baseMesh(), + objects, + selectedFields, + dTensorFld + ); + print(" volTensor::Internal :", Info, dTensorFld); } - label nDimFields = - dsf.size() - + dvf.size() - + dSpheretf.size() - + dSymmtf.size() - + dtf.size(); + const label nDimFields = + dScalarFld.size() + + dVectorFld.size() + + dSphTensorFld.size() + + dSymTensorFld.size() + + dTensorFld.size(); // Construct pointMesh only if necessary since constructs edge @@ -647,143 +747,160 @@ int main(int argc, char *argv[]) << " (\"-noPointValues\" (at your option)\n"; } - PtrList psf; - PtrList pvf; - PtrList pSpheretf; - PtrList pSymmtf; - PtrList ptf; + PtrList pScalarFld; + PtrList pVectorFld; + PtrList pSphTensorFld; + PtrList pSymTensorFld; + PtrList pTensorFld; if (!noPointValues && !(specifiedFields && selectedFields.empty())) { readFields ( - vMesh, - pointMesh::New(vMesh.baseMesh()), + meshRef, + pointMesh::New(meshRef.baseMesh()), objects, selectedFields, - psf + pScalarFld ); - print(" pointScalarFields :", Info, psf); + print(" pointScalar :", Info, pScalarFld); readFields ( - vMesh, - pointMesh::New(vMesh.baseMesh()), + meshRef, + pointMesh::New(meshRef.baseMesh()), objects, selectedFields, - pvf + pVectorFld ); - print(" pointVectorFields :", Info, pvf); + print(" pointVector :", Info, pVectorFld); readFields ( - vMesh, - pointMesh::New(vMesh.baseMesh()), + meshRef, + pointMesh::New(meshRef.baseMesh()), objects, selectedFields, - pSpheretf + pSphTensorFld ); - print(" pointSphericalTensorFields :", Info, pSpheretf); + print(" pointSphericalTensor :", Info, pSphTensorFld); readFields ( - vMesh, - pointMesh::New(vMesh.baseMesh()), + meshRef, + pointMesh::New(meshRef.baseMesh()), objects, selectedFields, - pSymmtf + pSymTensorFld ); - print(" pointSymmTensorFields :", Info, pSymmtf); + print(" pointSymmTensor :", Info, pSymTensorFld); readFields ( - vMesh, - pointMesh::New(vMesh.baseMesh()), + meshRef, + pointMesh::New(meshRef.baseMesh()), objects, selectedFields, - ptf + pTensorFld ); - print(" pointTensorFields :", Info, ptf); + print(" pointTensor :", Info, pTensorFld); } Info<< endl; - label nPointFields = - psf.size() - + pvf.size() - + pSpheretf.size() - + pSymmtf.size() - + ptf.size(); + const label nPointFields = + pScalarFld.size() + + pVectorFld.size() + + pSphTensorFld.size() + + pSymTensorFld.size() + + pTensorFld.size(); if (doWriteInternal) { + if (foamVtkMeshCells.empty()) + { + foamVtkMeshCells.reset(meshRef.mesh()); + + // Convert cellMap, addPointCellLabels to global cell ids + if (meshRef.useSubMesh()) + { + foamVtkMeshCells.renumberCells + ( + meshRef.subsetter().cellMap() + ); + } + } + // Create file and write header - fileName vtkFileName + fileName outputName ( fvPath/vtkName + "_" + timeDesc + ".vtk" ); - - Info<< " Internal : " << vtkFileName << endl; + Info<< " Internal : " + << relativeName(runTime, outputName) << endl; // Write mesh - internalWriter writer(vMesh, binary, vtkFileName); - - // VolFields + cellID - writeFuns::writeCellDataHeader + foamVtkOutput::internalWriter writer ( - writer.os(), - vMesh.nFieldCells(), - 1 + nVolFields + nDimFields + meshRef.baseMesh(), + fmtType, + foamVtkMeshCells, + outputName ); - // Write cellID field - writer.writeCellIDs(); + // CellData + { + writer.beginCellData(1 + nVolFields + nDimFields); - // Write volFields - writer.write(vsf); - writer.write(vvf); - writer.write(vSpheretf); - writer.write(vSymmtf); - writer.write(vtf); + // Write cellID field + writer.writeCellIDs(); - // Write dimensionedFields - writer.write(dsf); - writer.write(dvf); - writer.write(dSpheretf); - writer.write(dSymmtf); - writer.write(dtf); + // Write volFields + writer.write(vScalarFld); + writer.write(vVectorFld); + writer.write(vSphTensorf); + writer.write(vSymTensorFld); + writer.write(vTensorFld); + // Write dimensionedFields + writer.write(dScalarFld); + writer.write(dVectorFld); + writer.write(dSphTensorFld); + writer.write(dSymTensorFld); + writer.write(dTensorFld); + + writer.endCellData(); + } + + // PointData if (!noPointValues) { - writeFuns::writePointDataHeader - ( - writer.os(), - vMesh.nFieldPoints(), - nVolFields + nDimFields + nPointFields - ); + writer.beginPointData(nVolFields + nDimFields + nPointFields); // pointFields - writer.write(psf); - writer.write(pvf); - writer.write(pSpheretf); - writer.write(pSymmtf); - writer.write(ptf); + writer.write(pScalarFld); + writer.write(pVectorFld); + writer.write(pSphTensorFld); + writer.write(pSymTensorFld); + writer.write(pTensorFld); // Interpolated volFields volPointInterpolation pInterp(mesh); - writer.write(pInterp, vsf); - writer.write(pInterp, vvf); - writer.write(pInterp, vSpheretf); - writer.write(pInterp, vSymmtf); - writer.write(pInterp, vtf); + writer.write(pInterp, vScalarFld); + writer.write(pInterp, vVectorFld); + writer.write(pInterp, vSphTensorf); + writer.write(pInterp, vSymTensorFld); + writer.write(pInterp, vTensorFld); - writer.write(pInterp, dsf); - writer.write(pInterp, dvf); - writer.write(pInterp, dSpheretf); - writer.write(pInterp, dSymmtf); - writer.write(pInterp, dtf); + writer.write(pInterp, dScalarFld); + writer.write(pInterp, dVectorFld); + writer.write(pInterp, dSphTensorFld); + writer.write(pInterp, dSymTensorFld); + writer.write(pInterp, dTensorFld); + + writer.endPointData(); } } @@ -795,63 +912,66 @@ int main(int argc, char *argv[]) if (args.optionFound("surfaceFields")) { - PtrList ssf; + PtrList sScalarFld; readFields ( - vMesh, - vMesh.baseMesh(), + meshRef, + meshRef.baseMesh(), objects, selectedFields, - ssf + sScalarFld ); - print(" surfScalarFields :", Info, ssf); + print(" surfScalar :", Info, sScalarFld); - PtrList svf; + PtrList sVectorFld; readFields ( - vMesh, - vMesh.baseMesh(), + meshRef, + meshRef.baseMesh(), objects, selectedFields, - svf + sVectorFld ); - print(" surfVectorFields :", Info, svf); + print(" surfVector :", Info, sVectorFld); - if (ssf.size() + svf.size() > 0) + if (sScalarFld.size()) { - // Rework the scalar fields into vectorfields. - label sz = svf.size(); + // Rework the scalar fields into vector fields. + const label sz = sVectorFld.size(); - svf.setSize(sz+ssf.size()); + sVectorFld.setSize(sz + sScalarFld.size()); surfaceVectorField n(mesh.Sf()/mesh.magSf()); - forAll(ssf, i) + forAll(sScalarFld, i) { - surfaceVectorField* ssfiPtr = (ssf[i]*n).ptr(); - ssfiPtr->rename(ssf[i].name()); - svf.set(sz+i, ssfiPtr); + surfaceVectorField* ssfPtr = (sScalarFld[i]*n).ptr(); + ssfPtr->rename(sScalarFld[i].name()); + sVectorFld.set(sz+i, ssfPtr); } - ssf.clear(); + sScalarFld.clear(); + } + if (sVectorFld.size()) + { mkDir(fvPath / "surfaceFields"); - fileName surfFileName + fileName outputName ( fvPath - /"surfaceFields" - /"surfaceFields" - + "_" - + timeDesc - + ".vtk" + / "surfaceFields" + / "surfaceFields" + + "_" + + timeDesc + + ".vtk" ); - writeSurfFields + foamVtkOutput::writeSurfFields ( binary, - vMesh.mesh(), - surfFileName, - svf + meshRef.mesh(), + outputName, + sVectorFld ); } } @@ -869,72 +989,59 @@ int main(int argc, char *argv[]) { mkDir(fvPath/"allPatches"); - fileName outputName; - - if (vMesh.useSubMesh()) - { - outputName = - fvPath/"allPatches"/cellSetName - + "_" - + timeDesc - + ".vtk"; - } - else - { - outputName = - fvPath/"allPatches"/"allPatches" - + "_" - + timeDesc - + ".vtk"; - } - - Info<< " Combined patches : " << outputName << endl; - - patchWriter writer + fileName outputName ( - vMesh.mesh(), + fvPath/"allPatches" + / (meshRef.useSubMesh() ? cellSetName : "allPatches") + + "_" + + timeDesc + + ".vtk" + ); + Info<< " Combined patches : " + << relativeName(runTime, outputName) << nl; + + foamVtkOutput::patchWriter writer + ( + meshRef.mesh(), binary, nearCellValue, outputName, getSelectedPatches(patches, excludePatches) ); - // VolFields + patchID - writeFuns::writeCellDataHeader - ( - writer.os(), - writer.nFaces(), - 1+nVolFields - ); + // CellData + { + writer.beginCellData(1 + nVolFields); - // Write patchID field - writer.writePatchIDs(); + // Write patchID field + writer.writePatchIDs(); - // Write volFields - writer.write(vsf); - writer.write(vvf); - writer.write(vSpheretf); - writer.write(vSymmtf); - writer.write(vtf); + // Write volFields + writer.write(vScalarFld); + writer.write(vVectorFld); + writer.write(vSphTensorf); + writer.write(vSymTensorFld); + writer.write(vTensorFld); + writer.endCellData(); + } + + // PointData if (!noPointValues) { - writeFuns::writePointDataHeader - ( - writer.os(), - writer.nPoints(), - nPointFields - ); + writer.beginPointData(nPointFields); // Write pointFields - writer.write(psf); - writer.write(pvf); - writer.write(pSpheretf); - writer.write(pSymmtf); - writer.write(ptf); + writer.write(pScalarFld); + writer.write(pVectorFld); + writer.write(pSphTensorFld); + writer.write(pSymTensorFld); + writer.write(pTensorFld); // no interpolated volFields since I cannot be bothered to // create the patchInterpolation for all subpatches. + + writer.endPointData(); } } else @@ -943,89 +1050,75 @@ int main(int argc, char *argv[]) { const polyPatch& pp = patches[patchi]; - if (!findStrings(excludePatches, pp.name())) + if (findStrings(excludePatches, pp.name())) { - mkDir(fvPath/pp.name()); + // Skip excluded patch + continue; + } - fileName outputName; + mkDir(fvPath/pp.name()); - if (vMesh.useSubMesh()) + fileName outputName + ( + fvPath/pp.name() + / (meshRef.useSubMesh() ? cellSetName : pp.name()) + + "_" + + timeDesc + + ".vtk" + ); + Info<< " Patch : " + << relativeName(runTime, outputName) << nl; + + foamVtkOutput::patchWriter writer + ( + meshRef.mesh(), + binary, + nearCellValue, + outputName, + labelList{patchi} + ); + + if (!isA(pp)) + { + // VolFields + patchID + writer.beginCellData(1+nVolFields); + + // Write patchID field + writer.writePatchIDs(); + + // Write volFields + writer.write(vScalarFld); + writer.write(vVectorFld); + writer.write(vSphTensorf); + writer.write(vSymTensorFld); + writer.write(vTensorFld); + + writer.endCellData(); + + if (!noPointValues) { - outputName = - fvPath/pp.name()/cellSetName - + "_" - + timeDesc - + ".vtk"; - } - else - { - outputName = - fvPath/pp.name()/pp.name() - + "_" - + timeDesc - + ".vtk"; - } + writer.beginPointData(nVolFields + nPointFields); - Info<< " Patch : " << outputName << endl; + // Write pointFields + writer.write(pScalarFld); + writer.write(pVectorFld); + writer.write(pSphTensorFld); + writer.write(pSymTensorFld); + writer.write(pTensorFld); - patchWriter writer - ( - vMesh.mesh(), - binary, - nearCellValue, - outputName, - labelList{patchi} - ); - - if (!isA(pp)) - { - // VolFields + patchID - writeFuns::writeCellDataHeader + PrimitivePatchInterpolation pInter ( - writer.os(), - writer.nFaces(), - 1+nVolFields + pp ); - // Write patchID field - writer.writePatchIDs(); + // Write interpolated volFields + writer.write(pInter, vScalarFld); + writer.write(pInter, vVectorFld); + writer.write(pInter, vSphTensorf); + writer.write(pInter, vSymTensorFld); + writer.write(pInter, vTensorFld); - // Write volFields - writer.write(vsf); - writer.write(vvf); - writer.write(vSpheretf); - writer.write(vSymmtf); - writer.write(vtf); - - if (!noPointValues) - { - writeFuns::writePointDataHeader - ( - writer.os(), - writer.nPoints(), - nVolFields - + nPointFields - ); - - // Write pointFields - writer.write(psf); - writer.write(pvf); - writer.write(pSpheretf); - writer.write(pSymmtf); - writer.write(ptf); - - PrimitivePatchInterpolation pInter - ( - pp - ); - - // Write interpolated volFields - writer.write(pInter, vsf); - writer.write(pInter, vvf); - writer.write(pInter, vSpheretf); - writer.write(pInter, vSymmtf); - writer.write(pInter, vtf); - } + writer.endPointData(); } } } @@ -1039,27 +1132,27 @@ int main(int argc, char *argv[]) if (doFaceZones) { - PtrList ssf; + PtrList sScalarFld; readFields ( - vMesh, - vMesh.baseMesh(), + meshRef, + meshRef.baseMesh(), objects, selectedFields, - ssf + sScalarFld ); - print(" surfScalarFields :", Info, ssf); + print(" surfScalar :", Info, sScalarFld); - PtrList svf; + PtrList sVectorFld; readFields ( - vMesh, - vMesh.baseMesh(), + meshRef, + meshRef.baseMesh(), objects, selectedFields, - svf + sVectorFld ); - print(" surfVectorFields :", Info, svf); + print(" surfVector :", Info, sVectorFld); const faceZoneMesh& zones = mesh.faceZones(); @@ -1069,26 +1162,16 @@ int main(int argc, char *argv[]) mkDir(fvPath/fz.name()); - fileName outputName; - - if (vMesh.useSubMesh()) - { - outputName = - fvPath/fz.name()/cellSetName - + "_" - + timeDesc - + ".vtk"; - } - else - { - outputName = - fvPath/fz.name()/fz.name() - + "_" - + timeDesc - + ".vtk"; - } - - Info<< " FaceZone : " << outputName << endl; + fileName outputName = + ( + fvPath/fz.name() + / (meshRef.useSubMesh() ? cellSetName : fz.name()) + + "_" + + timeDesc + + ".vtk" + ); + Info<< " FaceZone : " + << relativeName(runTime, outputName) << nl; indirectPrimitivePatch pp ( @@ -1096,7 +1179,7 @@ int main(int argc, char *argv[]) mesh.points() ); - surfaceMeshWriter writer + foamVtkOutput::surfaceMeshWriter writer ( binary, pp, @@ -1105,20 +1188,16 @@ int main(int argc, char *argv[]) ); // Number of fields - writeFuns::writeCellDataHeader - ( - writer.os(), - pp.size(), - ssf.size()+svf.size() - ); + writer.beginCellData(sScalarFld.size() + sVectorFld.size()); - writer.write(ssf); - writer.write(svf); + writer.write(sScalarFld); + writer.write(sVectorFld); + + writer.endCellData(); } } - //--------------------------------------------------------------------- // // Write lagrangian data @@ -1137,8 +1216,8 @@ int main(int argc, char *argv[]) fvPath/cloud::prefix/cloudName/cloudName + "_" + timeDesc + ".vtk" ); - - Info<< " Lagrangian: " << outputName << endl; + Info<< " Lagrangian: " + << relativeName(runTime, outputName) << nl; IOobjectList sprayObjs ( @@ -1185,9 +1264,9 @@ int main(int argc, char *argv[]) Info<< " tensors :"; print(Info, tensorNames); - lagrangianWriter writer + foamVtkOutput::lagrangianWriter writer ( - vMesh.mesh(), + meshRef.mesh(), binary, outputName, cloudName, @@ -1195,7 +1274,7 @@ int main(int argc, char *argv[]) ); // Write number of fields - writer.writeParcelHeader + writer.beginParcelData ( labelNames.size() + scalarNames.size() @@ -1212,12 +1291,14 @@ int main(int argc, char *argv[]) writer.writeIOField(sphereNames); writer.writeIOField(symmNames); writer.writeIOField(tensorNames); + + writer.endParcelData(); } else { - lagrangianWriter writer + foamVtkOutput::lagrangianWriter writer ( - vMesh.mesh(), + meshRef.mesh(), binary, outputName, cloudName, @@ -1225,7 +1306,9 @@ int main(int argc, char *argv[]) ); // Write number of fields - writer.writeParcelHeader(0); + writer.beginParcelData(0); + + writer.endParcelData(); } } @@ -1253,8 +1336,8 @@ int main(int argc, char *argv[]) fileName procVTK ( fileName("..") - /"processor" + name(Pstream::myProcNo()) - /"VTK" + / "processor" + Foam::name(Pstream::myProcNo()) + / "VTK" ); fileNameList dirs(readDir(procVTK, fileName::DIRECTORY)); @@ -1272,17 +1355,21 @@ int main(int argc, char *argv[]) if (exists(procFile)) { - string cmd - ( - "ln -s " - + procFile - + " " - + "processor" - + name(Pstream::myProcNo()) - + "_" - + procFile.name() - ); - if (Foam::system(cmd.c_str()) == -1) + // Could likely also use Foam::ln() directly + List cmd + { + "ln", + "-s", + procFile, + ( + "processor" + + Foam::name(Pstream::myProcNo()) + + "_" + + procFile.name() + ) + }; + + if (Foam::system(cmd) == -1) { WarningInFunction << "Could not execute command " << cmd << endl; diff --git a/applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK/Make/files b/applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK/Make/files deleted file mode 100644 index 02de5b47e6..0000000000 --- a/applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK/Make/files +++ /dev/null @@ -1,13 +0,0 @@ -surfaceMeshWriter.C -internalWriter.C -lagrangianWriter.C -patchWriter.C -writeFuns.C -writeFaceSet.C -writePointSet.C -writeSurfFields.C -vtkTopo.C - -writeVTK/writeVTK.C - -LIB = $(FOAM_LIBBIN)/libfoamToVTK diff --git a/applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK/Make/options b/applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK/Make/options deleted file mode 100644 index f10e4ec1d6..0000000000 --- a/applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK/Make/options +++ /dev/null @@ -1,10 +0,0 @@ -EXE_INC = \ - -I$(LIB_SRC)/lagrangian/basic/lnInclude \ - -I$(LIB_SRC)/finiteVolume/lnInclude \ - -I$(LIB_SRC)/dynamicMesh/lnInclude \ - -I$(LIB_SRC)/meshTools/lnInclude - -LIB_LIBS = \ - -ldynamicMesh \ - -llagrangian \ - -lgenericPatchFields diff --git a/applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK/internalWriter.C b/applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK/internalWriter.C deleted file mode 100644 index 4db9f9c069..0000000000 --- a/applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK/internalWriter.C +++ /dev/null @@ -1,165 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | -------------------------------------------------------------------------------- -License - This file is part of OpenFOAM. - - OpenFOAM is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OpenFOAM is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - for more details. - - You should have received a copy of the GNU General Public License - along with OpenFOAM. If not, see . - -\*---------------------------------------------------------------------------*/ - -#include "internalWriter.H" -#include "writeFuns.H" - -// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // - -Foam::internalWriter::internalWriter -( - const vtkMesh& vMesh, - const bool binary, - const fileName& fName -) -: - vMesh_(vMesh), - binary_(binary), - fName_(fName), - os_(fName.c_str()) -{ - const fvMesh& mesh = vMesh_.mesh(); - const vtkTopo& topo = vMesh_.topo(); - - // Write header - writeFuns::writeHeader(os_, binary_, mesh.time().caseName()); - os_ << "DATASET UNSTRUCTURED_GRID" << std::endl; - - - //------------------------------------------------------------------ - // - // Write topology - // - //------------------------------------------------------------------ - - const labelList& addPointCellLabels = topo.addPointCellLabels(); - const label nTotPoints = mesh.nPoints() + addPointCellLabels.size(); - - os_ << "POINTS " << nTotPoints << " float" << std::endl; - - DynamicList ptField(3*nTotPoints); - - writeFuns::insert(mesh.points(), ptField); - - const pointField& ctrs = mesh.cellCentres(); - forAll(addPointCellLabels, api) - { - writeFuns::insert(ctrs[addPointCellLabels[api]], ptField); - } - writeFuns::write(os_, binary_, ptField); - - - // - // Write cells - // - - const labelListList& vtkVertLabels = topo.vertLabels(); - - // Count total number of vertices referenced. - label nFaceVerts = 0; - - forAll(vtkVertLabels, celli) - { - nFaceVerts += vtkVertLabels[celli].size() + 1; - } - - os_ << "CELLS " << vtkVertLabels.size() << ' ' << nFaceVerts << std::endl; - - DynamicList