diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsight/checkFieldAvailability.H b/applications/utilities/postProcessing/dataConversion/foamToEnsight/checkFieldAvailability.H index b9adb4990a..de638671d4 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-2023 OpenCFD Ltd. + Copyright (C) 2021-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM, distributed under GPL-3.0-or-later. @@ -44,10 +44,10 @@ forAll(meshes, regioni) IOobjectOption::NO_REGISTER ); - if (fieldSelector && !fieldSelector().empty()) + if (fieldSelector) { - objects.filterObjects(fieldSelector()); - faObjects.filterObjects(fieldSelector()); + objects.filterObjects(fieldSelector); + faObjects.filterObjects(fieldSelector); } // Remove "*_0" restart fields diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsight/foamToEnsight.C b/applications/utilities/postProcessing/dataConversion/foamToEnsight/foamToEnsight.C index 48a1261315..d9b66824cf 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-2022 OpenCFD Ltd. + Copyright (C) 2016-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -406,34 +406,27 @@ int main(int argc, char *argv[]) // 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) + else { Info<< "Field conversion disabled with the '-no-fields' option" << nl; } + const wordRes::filter fieldSelector(includedFields, excludedFields); + // ------------------------------------------------------------------------ #include "createTime.H" diff --git a/applications/utilities/postProcessing/dataConversion/foamToVTK/convertVolumeFields.H b/applications/utilities/postProcessing/dataConversion/foamToVTK/convertVolumeFields.H index 629ca24911..d663efe1ab 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-2023 OpenCFD Ltd. + Copyright (C) 2018-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM, distributed under GPL-3.0-or-later. @@ -136,7 +136,7 @@ Description labelList patchIds; if (doBoundary) { - patchIds = getSelectedPatches(patches, patchSelector); + patchIds = patchSelector.indices(patches); } if (oneBoundary && patchIds.size()) diff --git a/applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK.C b/applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK.C index 6fbc12edfa..c8edc8fabf 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK.C +++ b/applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK.C @@ -166,56 +166,54 @@ Note // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -labelList getSelectedPatches -( - const polyBoundaryMesh& patches, - const autoPtr& patchSelector -) +namespace Foam { - labelList indices; - if (patchSelector && !patchSelector().empty()) +// Simple wrapper for polyBoundaryMesh::indices() with some additional logic +struct polyBoundaryPatchSelector +{ + wordRes allow_; + wordRes deny_; + + void clear() { - // Name-based selection - indices = - ( - stringListOps::findMatching - ( - patches, - patchSelector(), - nameOp() - ) - ); - } - else - { - indices = identity(patches.size()); + allow_.clear(); + deny_.clear(); } - // Remove undesirable patches - - label count = 0; - for (const label patchi : indices) + //- Forward to polyBoundaryMesh::indices() with additional handling. + // Prune emptyPolyPatch (always) and processorPolyPatch (in parallel) + labelList indices(const polyBoundaryMesh& pbm) const { - const polyPatch& pp = patches[patchi]; + labelList ids = pbm.indices(allow_, deny_); - if (isType(pp)) + const bool excludeProcPatches = UPstream::parRun(); + + // Prune undesirable patches + label count = 0; + for (const label patchi : ids) { - continue; - } - else if (UPstream::parRun() && bool(isA(pp))) - { - break; // No processor patches for parallel output + const auto& pp = pbm[patchi]; + + if (isType(pp)) + { + continue; + } + else if (excludeProcPatches && bool(isA(pp))) + { + break; // No processor patches for parallel output + } + + ids[count] = patchi; + ++count; } - indices[count] = patchi; - ++count; + ids.resize(count); + return ids; } +}; - indices.resize(count); - - return indices; -} +} // End namespace Foam // @@ -552,45 +550,38 @@ int main(int argc, char *argv[]) } // Patch selection/deselection - wordRes includedPatches, excludedPatches; - autoPtr patchSelector(nullptr); + polyBoundaryPatchSelector patchSelector; + if (doBoundary) { - bool resetFilter = false; - if (args.readListIfPresent("patches", includedPatches)) + if + ( + auto& slot = patchSelector.allow_; + args.readListIfPresent("patches", slot) + ) { - resetFilter = true; - Info<< "Including patches " - << flatOutput(includedPatches) << nl << endl; + Info<< "Including patches " << flatOutput(slot) << nl << endl; } - if (args.readListIfPresent("exclude-patches", excludedPatches)) + if + ( + auto& slot = patchSelector.deny_; + args.readListIfPresent("exclude-patches", slot) + ) { - resetFilter = true; - Info<< "Excluding patches " - << flatOutput(excludedPatches) << nl << endl; - } - - if (resetFilter) - { - patchSelector = - autoPtr::New(includedPatches, excludedPatches); + Info<< "Excluding patches " << flatOutput(slot) << nl << endl; } } // 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) @@ -603,22 +594,22 @@ int main(int argc, char *argv[]) } if (args.readListIfPresent("exclude-fields", excludedFields)) { - resetFilter = true; Info<< "Excluding fields " << flatOutput(excludedFields) << nl << endl; } - if (resetFilter && doConvertFields) + if (!doConvertFields) { - fieldSelector = - autoPtr::New(includedFields, excludedFields); + includedFields.clear(); + excludedFields.clear(); } } - else if (doConvertFields) + else { Info<< "Field conversion disabled with the '-no-fields' option" << nl; } + const wordRes::filter fieldSelector(includedFields, excludedFields); // Non-mandatory const wordRes selectedFaceZones(args.getList("faceZones", false)); @@ -799,10 +790,10 @@ int main(int argc, char *argv[]) IOobjectOption::NO_REGISTER ); - if (fieldSelector && !fieldSelector().empty()) + if (fieldSelector) { - objects.filterObjects(fieldSelector()); - faObjects.filterObjects(fieldSelector()); + objects.filterObjects(fieldSelector); + faObjects.filterObjects(fieldSelector); } // Remove "*_0" restart fields diff --git a/applications/utilities/surface/surfaceMeshExtract/surfaceMeshExtract.C b/applications/utilities/surface/surfaceMeshExtract/surfaceMeshExtract.C index fcd551ab61..31eef2f6ee 100644 --- a/applications/utilities/surface/surfaceMeshExtract/surfaceMeshExtract.C +++ b/applications/utilities/surface/surfaceMeshExtract/surfaceMeshExtract.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2017-2024 OpenCFD Ltd. + Copyright (C) 2017-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -155,50 +155,39 @@ void writeOBJ } } - +// Simple wrapper for polyBoundaryMesh::indices() with some additional logic +// - prune emptyPolyPatch (always) and (maybe) processorPolyPatch labelList getSelectedPatches ( - const polyBoundaryMesh& patches, + const polyBoundaryMesh& pbm, const wordRes& allow, - const wordRes& deny + const wordRes& deny, + const bool excludeProcPatches ) { - // Name-based selection - labelList indices - ( - stringListOps::findMatching - ( - patches, - allow, - deny, - nameOp() - ) - ); - + labelList ids = pbm.indices(allow, deny); // Remove undesirable patches - label count = 0; - for (const label patchi : indices) + for (const label patchi : ids) { - const polyPatch& pp = patches[patchi]; + const polyPatch& pp = pbm[patchi]; if (isType(pp)) { continue; } - else if (Pstream::parRun() && bool(isA(pp))) + else if (excludeProcPatches && bool(isA(pp))) { - break; // No processor patches for parallel output + break; // No processor patches for parallel output } - indices[count] = patchi; + ids[count] = patchi; ++count; } - indices.resize(count); - - return indices; + ids.resize(count); + return ids; } @@ -668,11 +657,14 @@ int main(int argc, char *argv[]) const labelList patchIds = ( - (includePatches.size() || excludePatches.size()) - ? getSelectedPatches(bMesh, includePatches, excludePatches) - : includeProcPatches - ? identity(bMesh.size()) - : identity(bMesh.nNonProcessor()) + getSelectedPatches + ( + bMesh, + includePatches, + excludePatches, + // No processor patches? (parallel output or excluded) + (UPstream::parRun() || !includeProcPatches) + ) ); labelList faceZoneIds; diff --git a/src/functionObjects/utilities/vtkWrite/vtkWriteUpdate.C b/src/functionObjects/utilities/vtkWrite/vtkWriteUpdate.C index 57c67cc186..a5803470d1 100644 --- a/src/functionObjects/utilities/vtkWrite/vtkWriteUpdate.C +++ b/src/functionObjects/utilities/vtkWrite/vtkWriteUpdate.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2018-2023 OpenCFD Ltd. + Copyright (C) 2018-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -27,6 +27,7 @@ License #include "vtkWrite.H" #include "cellBitSet.H" +#include "emptyPolyPatch.H" #include "processorPolyPatch.H" // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // @@ -54,31 +55,32 @@ bool Foam::functionObjects::vtkWrite::updateSubset Foam::labelList Foam::functionObjects::vtkWrite::getSelectedPatches ( - const polyBoundaryMesh& patches + const polyBoundaryMesh& pbm ) const { - DynamicList