From e5f48bfca6c17f769a5ba83e6b1e74035ebe91a3 Mon Sep 17 00:00:00 2001 From: Henry Weller Date: Mon, 15 Apr 2024 14:18:50 +0100 Subject: [PATCH] functionObjects: Added single patch option to functionObjects that operate on patches functionObjects layerAverage, nearWallFields, wallHeatFlux, wallHeatTransferCoeff, wallShearStress and forcesBase now support both the 'patches' option for which a list of regular expressions to select the patches is specified and the new simple 'patch' option for which a single patch name is specified. --- .../fvMeshFunctionObject.C | 46 ++++++++++++++++++- .../fvMeshFunctionObject.H | 13 +++++- .../field/layerAverage/layerAverage.C | 6 +-- .../field/layerAverage/layerAverage.H | 3 +- .../field/nearWallFields/nearWallFields.C | 5 +- .../field/nearWallFields/nearWallFields.H | 7 +-- .../field/wallHeatFlux/wallHeatFlux.C | 8 +--- .../field/wallHeatFlux/wallHeatFlux.H | 3 +- .../wallHeatTransferCoeff.C | 8 +--- .../field/wallShearStress/wallShearStress.C | 10 ++-- .../field/wallShearStress/wallShearStress.H | 3 +- .../forces/forcesBase/forcesBase.C | 2 +- 12 files changed, 78 insertions(+), 36 deletions(-) diff --git a/src/finiteVolume/functionObjects/fvMeshFunctionObject/fvMeshFunctionObject.C b/src/finiteVolume/functionObjects/fvMeshFunctionObject/fvMeshFunctionObject.C index 2321577d2a..699ddb00c6 100644 --- a/src/finiteVolume/functionObjects/fvMeshFunctionObject/fvMeshFunctionObject.C +++ b/src/finiteVolume/functionObjects/fvMeshFunctionObject/fvMeshFunctionObject.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2016-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2016-2024 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -38,6 +38,50 @@ namespace functionObjects } +// * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * // + +Foam::labelHashSet Foam::functionObjects::fvMeshFunctionObject::patchSet +( + const dictionary& dict, + const bool optional +) const +{ + if (dict.found("patch")) + { + const word patchName(dict.lookup("patch")); + const label patchIndex = mesh_.boundaryMesh().findIndex(patchName); + + if (patchIndex >= 0) + { + return labelHashSet(FixedList(patchIndex)); + } + else + { + FatalIOErrorInFunction(dict) + << "Unable to find patch " << patchName << exit(FatalIOError); + } + } + else if (dict.found("patches")) + { + return mesh_.boundaryMesh().patchSet + ( + dict.lookup("patches") + ); + } + else + { + if (!optional) + { + FatalIOErrorInFunction(dict) + << "Neither 'patch' or 'patches' specified" + << exit(FatalIOError); + } + } + + return labelHashSet(); +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::functionObjects::fvMeshFunctionObject::fvMeshFunctionObject diff --git a/src/finiteVolume/functionObjects/fvMeshFunctionObject/fvMeshFunctionObject.H b/src/finiteVolume/functionObjects/fvMeshFunctionObject/fvMeshFunctionObject.H index 93399753a0..93d40f2ebb 100644 --- a/src/finiteVolume/functionObjects/fvMeshFunctionObject/fvMeshFunctionObject.H +++ b/src/finiteVolume/functionObjects/fvMeshFunctionObject/fvMeshFunctionObject.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2016-2021 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2016-2024 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -73,6 +73,17 @@ protected: const fvMesh& mesh_; + // Protected member functions + + //- Return the patch set corresponding to the patch selection entries + // in the given dictionary + labelHashSet patchSet + ( + const dictionary&, + const bool optional = false + ) const; + + public: //- Runtime type information diff --git a/src/functionObjects/field/layerAverage/layerAverage.C b/src/functionObjects/field/layerAverage/layerAverage.C index 8842cea01a..f226a148ea 100644 --- a/src/functionObjects/field/layerAverage/layerAverage.C +++ b/src/functionObjects/field/layerAverage/layerAverage.C @@ -240,11 +240,7 @@ bool Foam::functionObjects::layerAverage::read(const dictionary& dict) { Info<< type() << " " << name() << ":" << nl; - patchIndices_ = - mesh_.boundaryMesh().patchSet - ( - dict.lookupOrDefault("patches", wordReList()) - ).toc(); + patchIndices_ = patchSet(dict, true).toc(); zoneIndices_ = findStrings diff --git a/src/functionObjects/field/layerAverage/layerAverage.H b/src/functionObjects/field/layerAverage/layerAverage.H index 666004fa4e..d2c91bbf15 100644 --- a/src/functionObjects/field/layerAverage/layerAverage.H +++ b/src/functionObjects/field/layerAverage/layerAverage.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2024 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -54,6 +54,7 @@ Usage Property | Description | Required | Default value type | Type name: layerAverage | yes | setFormat | Output plotting format | yes | + patch | Patch that layers extrude from | no | patches | Patches that layers extrude from | no | () zones | Face zones that the layers extrude from | no | () axis | Component of the position to plot against | yes | diff --git a/src/functionObjects/field/nearWallFields/nearWallFields.C b/src/functionObjects/field/nearWallFields/nearWallFields.C index f5a2add237..f92177db4f 100644 --- a/src/functionObjects/field/nearWallFields/nearWallFields.C +++ b/src/functionObjects/field/nearWallFields/nearWallFields.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2024 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -214,8 +214,7 @@ bool Foam::functionObjects::nearWallFields::read(const dictionary& dict) fvMeshFunctionObject::read(dict); dict.lookup("fields") >> fieldSet_; - patchSet_ = - mesh_.boundaryMesh().patchSet(wordReList(dict.lookup("patches"))); + patchSet_ = patchSet(dict); distance_ = dict.lookup("distance"); diff --git a/src/functionObjects/field/nearWallFields/nearWallFields.H b/src/functionObjects/field/nearWallFields/nearWallFields.H index ff911668e2..78f0209470 100644 --- a/src/functionObjects/field/nearWallFields/nearWallFields.H +++ b/src/functionObjects/field/nearWallFields/nearWallFields.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2024 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -50,7 +50,7 @@ Description (U UNear) ); - patches (movingWall); + patch movingWall; distance 0.13; } @@ -61,7 +61,8 @@ Usage Property | Description | Required | Default value type | type name: nearWallFields | yes | fields | list of fields with corresponding output field names | yes | - patches | list of patches to sample | yes | + patch | patch to sample | no | + patches | list of patches to sample | no | distance | distance from patch to sample | yes | \endtable diff --git a/src/functionObjects/field/wallHeatFlux/wallHeatFlux.C b/src/functionObjects/field/wallHeatFlux/wallHeatFlux.C index 8c5f840242..2e18452e6f 100644 --- a/src/functionObjects/field/wallHeatFlux/wallHeatFlux.C +++ b/src/functionObjects/field/wallHeatFlux/wallHeatFlux.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2016-2023 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2016-2024 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -141,11 +141,7 @@ bool Foam::functionObjects::wallHeatFlux::read(const dictionary& dict) const polyBoundaryMesh& pbm = mesh_.boundaryMesh(); - patchSet_ = - mesh_.boundaryMesh().patchSet - ( - wordReList(dict.lookupOrDefault("patches", wordReList())) - ); + patchSet_ = patchSet(dict, true); Info<< type() << " " << name() << ":" << nl; diff --git a/src/functionObjects/field/wallHeatFlux/wallHeatFlux.H b/src/functionObjects/field/wallHeatFlux/wallHeatFlux.H index e59c135110..4cc311dc45 100644 --- a/src/functionObjects/field/wallHeatFlux/wallHeatFlux.H +++ b/src/functionObjects/field/wallHeatFlux/wallHeatFlux.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2016-2022 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2016-2024 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -47,6 +47,7 @@ Usage \table Property | Description | Required | Default value type | type name: wallHeatFlux | yes | + patch | patch to process | no | patches | list of patches to process | no | all wall patches region | region to be evaluated | no | default region \endtable diff --git a/src/functionObjects/field/wallHeatTransferCoeff/wallHeatTransferCoeff.C b/src/functionObjects/field/wallHeatTransferCoeff/wallHeatTransferCoeff.C index 60cbd80b6e..d599798d09 100644 --- a/src/functionObjects/field/wallHeatTransferCoeff/wallHeatTransferCoeff.C +++ b/src/functionObjects/field/wallHeatTransferCoeff/wallHeatTransferCoeff.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2020-2023 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2020-2024 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -109,11 +109,7 @@ bool Foam::functionObjects::wallHeatTransferCoeff::read(const dictionary& dict) const polyBoundaryMesh& pbm = mesh_.boundaryMesh(); - patchSet_ = - pbm.patchSet - ( - wordReList(dict.lookupOrDefault("patches", wordReList())) - ); + patchSet_ = patchSet(dict, true); Info<< type() << ":" << nl; diff --git a/src/functionObjects/field/wallShearStress/wallShearStress.C b/src/functionObjects/field/wallShearStress/wallShearStress.C index ac673dc302..4d7ee45b06 100644 --- a/src/functionObjects/field/wallShearStress/wallShearStress.C +++ b/src/functionObjects/field/wallShearStress/wallShearStress.C @@ -125,16 +125,12 @@ bool Foam::functionObjects::wallShearStress::read(const dictionary& dict) phaseName_ = dict.lookupOrDefault("phase", word::null); - const polyBoundaryMesh& pbm = mesh_.boundaryMesh(); - - patchSet_ = - mesh_.boundaryMesh().patchSet - ( - wordReList(dict.lookupOrDefault("patches", wordReList())) - ); + patchSet_ = patchSet(dict, true); Info<< type() << " " << name() << ":" << nl; + const polyBoundaryMesh& pbm = mesh_.boundaryMesh(); + if (patchSet_.empty()) { forAll(pbm, patchi) diff --git a/src/functionObjects/field/wallShearStress/wallShearStress.H b/src/functionObjects/field/wallShearStress/wallShearStress.H index 43f1cc90e1..e6341b7ef6 100644 --- a/src/functionObjects/field/wallShearStress/wallShearStress.H +++ b/src/functionObjects/field/wallShearStress/wallShearStress.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2013-2022 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2013-2024 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -57,6 +57,7 @@ Usage \table Property | Description | Required | Default value type | type name: wallShearStress | yes | + patch | patch to process | no | patches | list of patches to process | no | all wall patches phase | phase name | no | \endtable diff --git a/src/functionObjects/forces/forcesBase/forcesBase.C b/src/functionObjects/forces/forcesBase/forcesBase.C index df981fcc8d..ed3ca0a659 100644 --- a/src/functionObjects/forces/forcesBase/forcesBase.C +++ b/src/functionObjects/forces/forcesBase/forcesBase.C @@ -662,7 +662,7 @@ bool Foam::functionObjects::forcesBase::read(const dictionary& dict) const polyBoundaryMesh& pbm = mesh_.boundaryMesh(); - patchSet_ = pbm.patchSet(wordReList(dict.lookup("patches"))); + patchSet_ = patchSet(dict); if (directForceDensity_) {