From c4d4becbac1ddccde73aa799f19423db39564e83 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Mon, 7 Mar 2022 15:15:21 +0100 Subject: [PATCH] ENH: -exclude-fields, -no-fields options for foamToEnsight, foamToVTK - additional verbosity option for conversions - ignore old `-finite-area` option and always convert available finiteArea mesh/fields unless `-no-finite-area` is specified (#2374) ENH: simplify point offset handling for ensight output - extend writing to include compact face/cell lists --- .../foamToEnsight/checkFieldAvailability.H | 46 +++-- .../foamToEnsight/createMeshAccounting.H | 2 + .../foamToEnsight/findCloudFields.H | 2 +- .../foamToEnsight/foamToEnsight.C | 74 +++++-- .../dataConversion/foamToEnsight/readFields.H | 17 +- .../foamToEnsight/writeAreaFields.H | 8 +- .../foamToEnsight/writeDimFields.H | 12 +- .../foamToEnsight/writePointFields.H | 8 +- .../foamToEnsight/writeVolFields.H | 8 +- .../foamToVTK/convertLagrangian.H | 3 +- .../foamToVTK/convertSurfaceFields.H | 30 +-- .../foamToVTK/convertVolumeFields.H | 16 +- .../dataConversion/foamToVTK/foamToVTK.C | 192 +++++++++++++----- .../dataConversion/foamToVTK/readFields.C | 20 +- .../dataConversion/foamToVTK/readFields.H | 12 +- src/fileFormats/ensight/mesh/ensightMesh.C | 39 +++- src/fileFormats/ensight/mesh/ensightMesh.H | 17 +- .../ensight/output/ensightOutput.C | 165 +++++++++++---- .../ensight/output/ensightOutput.H | 55 ++++- .../ensight/output/ensightOutputTemplates.C | 21 ++ .../ensight/part/cells/ensightCells.H | 16 +- .../ensight/part/cells/ensightCellsAddr.C | 4 +- .../ensight/part/cells/ensightCellsIO.C | 27 +++ .../ensight/part/faces/ensightFaces.H | 13 +- .../ensight/part/faces/ensightFacesAddr.C | 2 +- .../ensight/part/faces/ensightFacesIO.C | 32 ++- src/finiteArea/output/ensight/ensightFaMesh.C | 24 ++- src/finiteArea/output/ensight/ensightFaMesh.H | 17 +- 28 files changed, 642 insertions(+), 240 deletions(-) diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsight/checkFieldAvailability.H b/applications/utilities/postProcessing/dataConversion/foamToEnsight/checkFieldAvailability.H index b562bcdf43..0733064cd5 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToEnsight/checkFieldAvailability.H +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsight/checkFieldAvailability.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2021 OpenCFD Ltd. + Copyright (C) 2021-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM, distributed under GPL-3.0-or-later. @@ -26,27 +26,37 @@ forAll(meshes, regioni) { const auto& mesh = meshes[regioni]; - IOobjectList objects(mesh, timeDirs.last().name()); + IOobjectList objects(0); - if (!fieldPatterns.empty()) + if (doConvertFields) { - objects.filterObjects(fieldPatterns); - } + objects = IOobjectList(mesh, timeDirs.last().name()); - // Remove "*_0" restart fields - objects.prune_0(); + if (fieldSelector && !fieldSelector().empty()) + { + objects.filterObjects(fieldSelector()); + } - if (!doPointValues) - { - // Prune point fields if disabled - objects.filterClasses - ( - [](const word& clsName) - { - return fieldTypes::point.found(clsName); - }, - true // prune - ); + if (fieldSelector && !fieldSelector().empty()) + { + objects.filterObjects(fieldSelector()); + } + + // Remove "*_0" restart fields + objects.prune_0(); + + if (!doPointValues) + { + // Prune point fields if disabled + objects.filterClasses + ( + [](const word& clsName) + { + return fieldTypes::point.found(clsName); + }, + true // prune + ); + } } wordList objectNames(objects.sortedNames()); diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsight/createMeshAccounting.H b/applications/utilities/postProcessing/dataConversion/foamToEnsight/createMeshAccounting.H index 13c7a6034d..7d33588a56 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToEnsight/createMeshAccounting.H +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsight/createMeshAccounting.H @@ -55,6 +55,7 @@ PtrList ensightMeshesFa(regionNames.size()); regioni, new ensightMesh(mesh, writeOpts) ); + ensightMeshes[regioni].verbose(optVerbose); // New ensight case file, initialize header etc. ensightCases.set @@ -87,6 +88,7 @@ PtrList ensightMeshesFa(regionNames.size()); regioni, new ensightFaMesh(meshesFa[regioni]) ); + ensightMeshesFa[regioni].verbose(optVerbose); } } } diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsight/findCloudFields.H b/applications/utilities/postProcessing/dataConversion/foamToEnsight/findCloudFields.H index 600c5248e0..c50e6e2a74 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToEnsight/findCloudFields.H +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsight/findCloudFields.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2018-2021 OpenCFD Ltd. + Copyright (C) 2018-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM, distributed under GPL-3.0-or-later. diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsight/foamToEnsight.C b/applications/utilities/postProcessing/dataConversion/foamToEnsight/foamToEnsight.C index f012773424..45b816fe24 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToEnsight/foamToEnsight.C +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsight/foamToEnsight.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2016-2021 OpenCFD Ltd. + Copyright (C) 2016-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -108,11 +108,11 @@ Usage -patches '( front \".*back\" )' \endverbatim - - \par -excludePatches NAME | LIST + - \par -exclude-patches NAME | LIST Exclude single or multiple patches (name or regex) from writing. For example, \verbatim - -excludePatches '( inlet_1 inlet_2 "proc.*" )' + -exclude-patches '( inlet_1 inlet_2 "proc.*" )' \endverbatim \*---------------------------------------------------------------------------*/ @@ -170,6 +170,8 @@ int main(int argc, char *argv[]) argList::setAdvanced("decomposeParDict"); argList::setAdvanced("noFunctionObjects"); + argList::addVerboseOption("Additional verbosity"); + #include "addAllRegionOptions.H" argList::addBoolOption @@ -259,10 +261,15 @@ int main(int argc, char *argv[]) // ); argList::addBoolOption ( - "finite-area", - "Write finite area fields", + "no-finite-area", + "Suppress output of finite-area mesh/fields", true // mark as an advanced option ); + argList::ignoreOptionCompat + ( + {"finite-area", 2112}, // use -no-finite-area to disable + false // bool option, no argument + ); argList::addOption ( @@ -273,12 +280,14 @@ int main(int argc, char *argv[]) ); argList::addOption ( - "excludePatches", + "exclude-patches", "wordRes", "Exclude single or multiple patches from writing\n" "Eg, 'outlet' or '( inlet \".*Wall\" )'" , true // mark as an advanced option ); + argList::addOptionCompat("exclude-patches", {"excludePatches", 2112}); + argList::addOption ( "faceZones", @@ -293,6 +302,19 @@ int main(int argc, char *argv[]) "Specify single or multiple fields to write (all by default)\n" "Eg, 'T' or '( \"U.*\" )'" ); + argList::addOption + ( + "exclude-fields", + "wordRes", + "Exclude single or multiple fields", + true // mark as an advanced option + ); + argList::addBoolOption + ( + "no-fields", + "Suppress conversion of fields" + ); + argList::addOption ( "cellZones", @@ -315,11 +337,12 @@ int main(int argc, char *argv[]) : IOstreamOption::BINARY ); + const int optVerbose = args.verbose(); const bool doBoundary = !args.found("no-boundary"); const bool doInternal = !args.found("no-internal"); const bool doCellZones = !args.found("no-cellZones"); const bool doLagrangian = !args.found("no-lagrangian"); - const bool doFiniteArea = args.found("finite-area"); + const bool doFiniteArea = !args.found("no-finite-area"); const bool doPointValues = !args.found("no-point-data"); const bool nearCellValue = args.found("nearCellValue") && doBoundary; @@ -360,13 +383,14 @@ int main(int argc, char *argv[]) writeOpts.useInternalMesh(doInternal); writeOpts.useCellZones(doCellZones); + // Patch selection/deselection if (args.found("patches")) { writeOpts.patchSelection(args.getList("patches")); } - if (args.found("excludePatches")) + if (args.found("exclude-patches")) { - writeOpts.patchExclude(args.getList("excludePatches")); + writeOpts.patchExclude(args.getList("exclude-patches")); } if (args.found("faceZones")) @@ -381,8 +405,35 @@ int main(int argc, char *argv[]) // Report the setup writeOpts.print(Info); - wordRes fieldPatterns; - args.readListIfPresent("fields", fieldPatterns); + // Field selection/deselection + wordRes includedFields, excludedFields; + autoPtr fieldSelector(nullptr); + const bool doConvertFields = !args.found("no-fields"); + if (doConvertFields) + { + bool resetFilter = false; + if (args.readListIfPresent("fields", includedFields)) + { + resetFilter = true; + Info<< "Including fields " + << flatOutput(includedFields) << nl << endl; + } + if (args.readListIfPresent("exclude-fields", excludedFields)) + { + resetFilter = true; + Info<< "Excluding fields " + << flatOutput(excludedFields) << nl << endl; + } + if (resetFilter) + { + fieldSelector = + autoPtr::New(includedFields, excludedFields); + } + } + else if (doConvertFields) + { + Info<< "Field conversion disabled with the '-no-fields' option" << nl; + } // ------------------------------------------------------------------------ @@ -525,7 +576,6 @@ int main(int argc, char *argv[]) // Objects at this time IOobjectList objects(mesh, runTime.timeName()); - // Restrict to objects that are available for all times objects.filterObjects ( availableRegionObjectNames[regioni] diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsight/readFields.H b/applications/utilities/postProcessing/dataConversion/foamToEnsight/readFields.H index 3804b0a3a0..daa27d275e 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToEnsight/readFields.H +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsight/readFields.H @@ -81,20 +81,16 @@ tmp getField //- Convert an internal field to zero-gradient volume field template -tmp> -makeZeroGradientField +tmp> makeZeroGradientField ( - const tmp - < - typename GeometricField::Internal - >& tdf + const tmp>& tdf ) { if (tdf) { auto& df = tdf.ref(); - auto tfield = GeometricField::New + auto tfield = VolumeField::New ( df.name(), df.mesh(), @@ -119,17 +115,16 @@ makeZeroGradientField //- Convert a volume field to zero-gradient volume field template -tmp> -makeZeroGradientField +tmp> makeZeroGradientField ( - const tmp>& tdf + const tmp>& tdf ) { if (tdf) { auto& df = tdf.ref(); - auto tfield = GeometricField::New + auto tfield = VolumeField::New ( df.name(), df.mesh(), diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsight/writeAreaFields.H b/applications/utilities/postProcessing/dataConversion/foamToEnsight/writeAreaFields.H index 2e5e1d4fc2..e9abb624e9 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToEnsight/writeAreaFields.H +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsight/writeAreaFields.H @@ -34,7 +34,7 @@ bool writeAreaField ( ensightCase& ensCase, const ensightFaMesh& ensMesh, - const tmp>& tfield + const tmp>& tfield ) { if (!tfield) @@ -66,13 +66,13 @@ label writeAreaFields const IOobjectList& objects ) { - typedef GeometricField GeoField; + typedef AreaField FieldType; const faMesh& mesh = ensMesh.mesh(); label count = 0; - for (const word& fieldName : objects.sortedNames()) + for (const word& fieldName : objects.sortedNames()) { if ( @@ -80,7 +80,7 @@ label writeAreaFields ( ensCase, ensMesh, - getField(objects.findObject(fieldName), mesh) + getField(objects.findObject(fieldName), mesh) ) ) { diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsight/writeDimFields.H b/applications/utilities/postProcessing/dataConversion/foamToEnsight/writeDimFields.H index 35b47ef06a..41b110b114 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToEnsight/writeDimFields.H +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsight/writeDimFields.H @@ -33,7 +33,7 @@ bool writeDimField ( ensightCase& ensCase, const ensightMesh& ensMesh, - const tmp>& tdf + const tmp>& tdf ) { if (!tdf) @@ -63,17 +63,13 @@ label writeDimFields const IOobjectList& objects ) { - typedef typename - GeometricField - < - Type, fvPatchField, volMesh - >::Internal DimField; + typedef VolumeInternalField FieldType; const fvMesh& mesh = dynamicCast(ensMesh.mesh()); label count = 0; - for (const word& fieldName : objects.sortedNames()) + for (const word& fieldName : objects.sortedNames()) { if ( @@ -81,7 +77,7 @@ label writeDimFields ( ensCase, ensMesh, - getField(objects.findObject(fieldName), mesh) + getField(objects.findObject(fieldName), mesh) ) ) { diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsight/writePointFields.H b/applications/utilities/postProcessing/dataConversion/foamToEnsight/writePointFields.H index 714598e81d..8fb8764ad4 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToEnsight/writePointFields.H +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsight/writePointFields.H @@ -35,7 +35,7 @@ bool writePointField ( ensightCase& ensCase, const ensightMesh& ensMesh, - const tmp>& tfield + const tmp>& tfield ) { if (!tfield) @@ -68,13 +68,13 @@ label writePointFields const IOobjectList& objects ) { - typedef GeometricField GeoField; + typedef PointField FieldType; const pointMesh& ptMesh = pointMesh::New(ensMesh.mesh()); label count = 0; - for (const word& fieldName : objects.sortedNames()) + for (const word& fieldName : objects.sortedNames()) { if ( @@ -82,7 +82,7 @@ label writePointFields ( ensCase, ensMesh, - getField(ptMesh, objects, fieldName) + getField(ptMesh, objects, fieldName) ) ) { diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsight/writeVolFields.H b/applications/utilities/postProcessing/dataConversion/foamToEnsight/writeVolFields.H index fbc79a0749..cb80172b55 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToEnsight/writeVolFields.H +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsight/writeVolFields.H @@ -34,7 +34,7 @@ bool writeVolField ( ensightCase& ensCase, const ensightMesh& ensMesh, - const tmp>& tfield, + const tmp>& tfield, const bool nearCellValue = false ) { @@ -86,13 +86,13 @@ label writeVolFields const bool nearCellValue = false ) { - typedef GeometricField GeoField; + typedef VolumeField FieldType; const fvMesh& mesh = dynamicCast(ensMesh.mesh()); label count = 0; - for (const word& fieldName : objects.sortedNames()) + for (const word& fieldName : objects.sortedNames()) { if ( @@ -100,7 +100,7 @@ label writeVolFields ( ensCase, ensMesh, - getField(objects.findObject(fieldName), mesh), + getField(objects.findObject(fieldName), mesh), nearCellValue ) ) diff --git a/applications/utilities/postProcessing/dataConversion/foamToVTK/convertLagrangian.H b/applications/utilities/postProcessing/dataConversion/foamToVTK/convertLagrangian.H index aa92c3bc0a..94659d14de 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToVTK/convertLagrangian.H +++ b/applications/utilities/postProcessing/dataConversion/foamToVTK/convertLagrangian.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2018-2021 OpenCFD Ltd. + Copyright (C) 2018-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -52,7 +52,6 @@ if (doLagrangian) // Consistent order Foam::sort(cloudNames); - for (const word& cloudName : cloudNames) { IOobjectList cloudObjs(mesh, runTime.timeName(), cloudPrefix/cloudName); diff --git a/applications/utilities/postProcessing/dataConversion/foamToVTK/convertSurfaceFields.H b/applications/utilities/postProcessing/dataConversion/foamToVTK/convertSurfaceFields.H index 6803a25d74..6005ffa4a6 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToVTK/convertSurfaceFields.H +++ b/applications/utilities/postProcessing/dataConversion/foamToVTK/convertSurfaceFields.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2018-2021 OpenCFD Ltd. + Copyright (C) 2018-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -43,12 +43,7 @@ Description { if (nSurfaceScalarField == -1) { - sScalars = readFields - ( - meshProxy, - objects, - selectedFields - ); + sScalars = readFields(meshProxy, objects); reportFields::print(" surfScalar :", Info, sScalars); nSurfaceScalarField = sScalars.size(); @@ -60,12 +55,7 @@ Description if (nSurfaceVectorField == -1) { - sVectors = readFields - ( - meshProxy, - objects, - selectedFields - ); + sVectors = readFields(meshProxy, objects); reportFields::print(" surfVector :", Info, sVectors); nSurfaceVectorField = sVectors.size(); @@ -155,12 +145,7 @@ Description { if (nSurfaceScalarField == -1) { - sScalars = readFields - ( - meshProxy, - objects, - selectedFields - ); + sScalars = readFields(meshProxy, objects); nSurfaceScalarField = sScalars.size(); reportFields::print(" surfScalar :", Info, sScalars); @@ -172,12 +157,7 @@ Description if (nSurfaceVectorField == -1) { - sVectors = readFields - ( - meshProxy, - objects, - selectedFields - ); + sVectors = readFields(meshProxy, objects); nSurfaceVectorField = sVectors.size(); reportFields::print(" surfVector :", Info, sVectors); diff --git a/applications/utilities/postProcessing/dataConversion/foamToVTK/convertVolumeFields.H b/applications/utilities/postProcessing/dataConversion/foamToVTK/convertVolumeFields.H index add182f7ec..db25c78cdc 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToVTK/convertVolumeFields.H +++ b/applications/utilities/postProcessing/dataConversion/foamToVTK/convertVolumeFields.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2018-2021 OpenCFD Ltd. + Copyright (C) 2018-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -48,7 +48,7 @@ Description : 0 ); - const label nPointFields = + label nPointFields = ( doPointValues ? objects.count(stringListOps::foundOp(fieldTypes::point)) @@ -82,11 +82,6 @@ Description if (doInternal) { - if (doPointValues) - { - pInterp.reset(new volPointInterpolation(mesh)); - } - if (vtuMeshCells.empty()) { // Use the appropriate mesh (baseMesh or subMesh) @@ -119,6 +114,11 @@ Description internalWriter->writeTimeValue(mesh.time().value()); internalWriter->writeGeometry(); + + if (doPointValues) + { + pInterp.reset(new volPointInterpolation(mesh)); + } } @@ -132,7 +132,7 @@ Description labelList patchIds; if (doBoundary) { - patchIds = getSelectedPatches(patches, includePatches, excludePatches); + patchIds = getSelectedPatches(patches, patchSelector); } if (oneBoundary && patchIds.size()) diff --git a/applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK.C b/applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK.C index f2e447b5bb..9f02a529bc 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK.C +++ b/applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2016-2021 OpenCFD Ltd. + Copyright (C) 2016-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -112,11 +112,11 @@ Usage -patches '( front \".*back\" )' \endverbatim - - \par -excludePatches NAME | LIST + - \par -exclude-patches NAME | LIST Exclude single or multiple patches (name or regex) from writing. For example, \verbatim - -excludePatches '( inlet_1 inlet_2 "proc.*")' + -exclude-patches '( inlet_1 inlet_2 "proc.*")' \endverbatim Note @@ -169,22 +169,28 @@ Note labelList getSelectedPatches ( const polyBoundaryMesh& patches, - const wordRes& allow, - const wordRes& deny + const autoPtr& patchSelector ) { - // Name-based selection - labelList indices - ( - stringListOps::findMatching - ( - patches, - allow, - deny, - nameOp() - ) - ); + labelList indices; + if (patchSelector && !patchSelector().empty()) + { + // Name-based selection + indices = + ( + stringListOps::findMatching + ( + patches, + patchSelector(), + nameOp() + ) + ); + } + else + { + indices = identity(patches.size()); + } // Remove undesirable patches @@ -264,6 +270,8 @@ int main(int argc, char *argv[]) argList::setAdvanced("decomposeParDict"); argList::setAdvanced("noFunctionObjects"); + argList::addVerboseOption("Additional verbosity"); + argList::addBoolOption ( "ascii", @@ -328,7 +336,6 @@ int main(int argc, char *argv[]) "Eg, 'cells' or '( slice \"mfp-.*\" )'.", true // mark as an advanced option ); - argList::addOption ( "fields", @@ -336,6 +343,18 @@ int main(int argc, char *argv[]) "Specify single or multiple fields to write (all by default)\n" "Eg, 'T' or '(p T U \"alpha.*\")'" ); + argList::addOption + ( + "exclude-fields", + "wordRes", + "Exclude single or multiple fields", + true // mark as an advanced option + ); + argList::addBoolOption + ( + "no-fields", + "Suppress conversion of fields" + ); argList::addBoolOption ( @@ -351,11 +370,21 @@ int main(int argc, char *argv[]) ); argList::addBoolOption ( - "finite-area", - "Write finite area fields", + "no-finite-area", + "Suppress output of finite-area mesh/fields", true // mark as an advanced option ); - argList::addOptionCompat("finite-area", {"finiteAreaFields", 2012}); + argList::ignoreOptionCompat + ( + {"finite-area", 2112}, // use -no-finite-area to disable + false // bool option, no argument + ); + argList::ignoreOptionCompat + ( + {"finiteAreaFields", 2012}, // use -no-finite-area to disable + false // bool option, no argument + ); + argList::addBoolOption ( "nearCellValue", @@ -418,12 +447,14 @@ int main(int argc, char *argv[]) ); argList::addOption ( - "excludePatches", + "exclude-patches", "wordRes", "Exclude single or multiple patches from writing\n" "Eg, 'outlet' or '( inlet \".*Wall\" )'", true // mark as an advanced option ); + argList::addOptionCompat("exclude-patches", {"excludePatches", 2112}); + argList::ignoreOptionCompat ( {"noFaceZones", 1806}, // faceZones are only enabled on demand @@ -453,13 +484,13 @@ int main(int argc, char *argv[]) #include "setRootCase.H" + /// const int optVerbose = args.verbose(); const bool decomposePoly = args.found("poly-decomp"); const bool doBoundary = !args.found("no-boundary"); const bool doInternal = !args.found("no-internal"); const bool doLagrangian = !args.found("no-lagrangian"); - const bool doFiniteArea = args.found("finite-area"); + const bool doFiniteArea = !args.found("no-finite-area"); const bool doSurfaceFields = args.found("surfaceFields"); - const bool oneBoundary = args.found("one-boundary") && doBoundary; const bool nearCellValue = args.found("nearCellValue") && doBoundary; @@ -494,7 +525,7 @@ int main(int argc, char *argv[]) << nl << endl; } - const bool doPointValues = !args.found("no-point-data"); + bool doPointValues = !args.found("no-point-data"); if (!doPointValues) { Info<< "Point fields and interpolated point data" @@ -521,25 +552,74 @@ int main(int argc, char *argv[]) Info<< "Writing mesh ids (cell, patch, proc) requested" << nl; } - wordRes includePatches, excludePatches; + // Patch selection/deselection + wordRes includedPatches, excludedPatches; + autoPtr patchSelector(nullptr); if (doBoundary) { - if (args.readListIfPresent("patches", includePatches)) + bool resetFilter = false; + if (args.readListIfPresent("patches", includedPatches)) { - Info<< "Including patches " << flatOutput(includePatches) - << nl << endl; + resetFilter = true; + Info<< "Including patches " + << flatOutput(includedPatches) << nl << endl; } - if (args.readListIfPresent("excludePatches", excludePatches)) + if (args.readListIfPresent("exclude-patches", excludedPatches)) { - Info<< "Excluding patches " << flatOutput(excludePatches) - << nl << endl; + resetFilter = true; + Info<< "Excluding patches " + << flatOutput(excludedPatches) << nl << endl; + } + + if (resetFilter) + { + patchSelector = + autoPtr::New(includedPatches, excludedPatches); } } - // Can be specified as empty (ie, no fields) - wordRes selectedFields; - const bool useFieldFilter = - args.readListIfPresent("fields", selectedFields); + // Field selection/deselection + wordRes includedFields, excludedFields; + autoPtr fieldSelector(nullptr); + bool doConvertFields = !args.found("no-fields"); + if (doConvertFields) + { + bool resetFilter = false; + if (args.readListIfPresent("fields", includedFields)) + { + Info<< "Including fields " + << flatOutput(includedFields) << nl << endl; + + resetFilter = !includedFields.empty(); + + if (includedFields.empty()) + { + // Compat: Can be specified as empty (ie, no fields) + // Same as "block everything" + + doConvertFields = false; + Info<< "Field conversion disabled by '-fields ()' option" << nl + << "Should use -no-fields instead" << endl; + } + } + if (args.readListIfPresent("exclude-fields", excludedFields)) + { + resetFilter = true; + Info<< "Excluding fields " + << flatOutput(excludedFields) << nl << endl; + } + + if (resetFilter && doConvertFields) + { + fieldSelector = + autoPtr::New(includedFields, excludedFields); + } + } + else if (doConvertFields) + { + Info<< "Field conversion disabled with the '-no-fields' option" << nl; + } + // Non-mandatory const wordRes selectedFaceZones(args.getList("faceZones", false)); @@ -709,28 +789,34 @@ int main(int argc, char *argv[]) } } - // Search for list of objects for this time - IOobjectList objects(meshProxy.baseMesh(), runTime.timeName()); + IOobjectList objects(0); - if (useFieldFilter) + if (doConvertFields) { - objects.filterObjects(selectedFields); - } + // List of objects for this time + objects = + IOobjectList(meshProxy.baseMesh(), runTime.timeName()); - // Prune restart fields - objects.prune_0(); + if (fieldSelector && !fieldSelector().empty()) + { + objects.filterObjects(fieldSelector()); + } - if (!doPointValues) - { - // Prune point fields if disabled - objects.filterClasses - ( - [](const word& clsName) - { - return fieldTypes::point.found(clsName); - }, - true // prune - ); + // Remove "*_0" restart fields + objects.prune_0(); + + if (!doPointValues) + { + // Prune point fields if disabled + objects.filterClasses + ( + [](const word& clsName) + { + return fieldTypes::point.found(clsName); + }, + true // prune + ); + } } if (processorFieldsOnly) diff --git a/applications/utilities/postProcessing/dataConversion/foamToVTK/readFields.C b/applications/utilities/postProcessing/dataConversion/foamToVTK/readFields.C index 40ca84d709..3f8311b1c4 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToVTK/readFields.C +++ b/applications/utilities/postProcessing/dataConversion/foamToVTK/readFields.C @@ -94,19 +94,13 @@ template Foam::PtrList Foam::readFields ( const typename GeoField::Mesh& mesh, - const IOobjectList& objects, - const wordRes& selection + const IOobjectList& objects ) { const bool syncPar = true; // Available fields of type GeoField, sorted order - const wordList fieldNames = - ( - selection.empty() - ? objects.sortedNames() - : objects.sortedNames(selection) - ); + const wordList fieldNames(objects.sortedNames()); // Construct the fields PtrList fields(fieldNames.size()); @@ -133,19 +127,13 @@ template Foam::PtrList Foam::readFields ( const fvMeshSubsetProxy& proxy, - const IOobjectList& objects, - const wordRes& selection + const IOobjectList& objects ) { const bool syncPar = true; // Available fields of type GeoField, sorted order - const wordList fieldNames = - ( - selection.empty() - ? objects.sortedNames() - : objects.sortedNames(selection) - ); + const wordList fieldNames(objects.sortedNames()); // Construct the fields PtrList fields(fieldNames.size()); diff --git a/applications/utilities/postProcessing/dataConversion/foamToVTK/readFields.H b/applications/utilities/postProcessing/dataConversion/foamToVTK/readFields.H index 9493954449..f5f15321c5 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToVTK/readFields.H +++ b/applications/utilities/postProcessing/dataConversion/foamToVTK/readFields.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2016-2018 OpenCFD Ltd. + Copyright (C) 2016-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -35,8 +35,8 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef readFields_H -#define readFields_H +#ifndef Foam_readFields_H +#define Foam_readFields_H #include "fvMeshSubsetProxy.H" #include "IOobjectList.H" @@ -94,8 +94,7 @@ template PtrList readFields ( const typename GeoField::Mesh& mesh, - const IOobjectList& objects, - const wordRes& selection + const IOobjectList& objects ); @@ -104,8 +103,7 @@ template PtrList readFields ( const fvMeshSubsetProxy& proxy, - const IOobjectList& objects, - const wordRes& selection + const IOobjectList& objects ); diff --git a/src/fileFormats/ensight/mesh/ensightMesh.C b/src/fileFormats/ensight/mesh/ensightMesh.C index 9faae73675..7b1a28f312 100644 --- a/src/fileFormats/ensight/mesh/ensightMesh.C +++ b/src/fileFormats/ensight/mesh/ensightMesh.C @@ -110,7 +110,8 @@ Foam::ensightMesh::ensightMesh : options_(new options(opts)), mesh_(mesh), - needsUpdate_(true) + needsUpdate_(true), + verbose_(0) { if (!option().lazy()) { @@ -121,6 +122,20 @@ Foam::ensightMesh::ensightMesh // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // +int Foam::ensightMesh::verbose() const noexcept +{ + return verbose_; +} + + +int Foam::ensightMesh::verbose(const int level) noexcept +{ + int old(verbose_); + verbose_ = level; + return old; +} + + void Foam::ensightMesh::correct() { clear(); @@ -214,6 +229,10 @@ void Foam::ensightMesh::correct() // Finalize part.reduce(); + if (verbose_) + { + Info<< part.info(); + } } } @@ -235,6 +254,10 @@ void Foam::ensightMesh::correct() // Finalize part.reduce(); + if (verbose_) + { + Info<< part.info(); + } } else { @@ -253,6 +276,10 @@ void Foam::ensightMesh::correct() // Finalize part.reduce(); + if (verbose_) + { + Info<< part.info(); + } } } @@ -345,7 +372,10 @@ void Foam::ensightMesh::correct() // Finalize part.reduce(); - + if (verbose_) + { + Info<< part.info(); + } if (!part.total()) { boundaryParts_.erase(patchId); @@ -379,7 +409,10 @@ void Foam::ensightMesh::correct() // Finalize part.reduce(); - + if (verbose_) + { + Info<< part.info(); + } if (!part.total()) { faceZoneParts_.erase(zoneId); diff --git a/src/fileFormats/ensight/mesh/ensightMesh.H b/src/fileFormats/ensight/mesh/ensightMesh.H index 6c0427f977..fb61d716eb 100644 --- a/src/fileFormats/ensight/mesh/ensightMesh.H +++ b/src/fileFormats/ensight/mesh/ensightMesh.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2016-2020 OpenCFD Ltd. + Copyright (C) 2016-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -57,8 +57,8 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef ensightMesh_H -#define ensightMesh_H +#ifndef Foam_ensightMesh_H +#define Foam_ensightMesh_H #include "Map.H" #include "ensightCells.H" @@ -114,6 +114,9 @@ private: //- Track if it needs an update mutable bool needsUpdate_; + //- Output verbosity level + int verbose_; + // Private Member Functions @@ -143,6 +146,14 @@ public: // Member Functions + //- Output verbosity level + int verbose() const noexcept; + + //- Change the output verbosity level. + // \return old level + int verbose(const int level) noexcept; + + // Access //- Reference to the underlying polyMesh diff --git a/src/fileFormats/ensight/output/ensightOutput.C b/src/fileFormats/ensight/output/ensightOutput.C index 61045f2ef4..27e12cba9f 100644 --- a/src/fileFormats/ensight/output/ensightOutput.C +++ b/src/fileFormats/ensight/output/ensightOutput.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2020 OpenCFD Ltd. + Copyright (C) 2020-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -26,7 +26,6 @@ License \*---------------------------------------------------------------------------*/ #include "ensightOutput.H" - #include "cell.H" #include "cellShape.H" #include "face.H" @@ -133,20 +132,29 @@ Foam::labelList Foam::ensightOutput::Detail::getPolysNPointsPerFace } -void Foam::ensightOutput::writeFaceList +void Foam::ensightOutput::Detail::writeLabelListList ( ensightGeoFile& os, - const UList& faces + const labelUList& offsets, + const labelUList& values, + const label pointOffset ) { - for (const face& f : faces) - { - for (const label labi : f) - { - os.write(labi + 1); - } + const label off = (pointOffset + 1); // 1-based for Ensight - os.newline(); + const label nLists = (offsets.size() - 1); + + for (label i = 0; i < nLists; ++i) + { + const labelUList list + ( + values.slice(offsets[i], (offsets[i+i] - offsets[i])) + ); + for (const label pointi : list) + { + os.write(pointi + off); + } + os.newline(); // One list (cell/faces) per line (ASCII) } } @@ -154,40 +162,119 @@ void Foam::ensightOutput::writeFaceList void Foam::ensightOutput::writeFaceList ( ensightGeoFile& os, - const UIndirectList& faces + const UList& faces, + const label pointOffset ) { - for (const face& f : faces) - { - for (const label labi : f) - { - os.write(labi + 1); - } + ensightOutput::Detail::writeLabelListList(os, faces, pointOffset); +} - os.newline(); - } + +void Foam::ensightOutput::writeFaceList +( + ensightGeoFile& os, + const UIndirectList& faces, + const label pointOffset +) +{ + ensightOutput::Detail::writeLabelListList(os, faces, pointOffset); +} + + +void Foam::ensightOutput::writeFaceList +( + ensightGeoFile& os, + const CompactListList