diff --git a/src/finiteVolume/fvMesh/wallDist/nearWallDist/nearWallDist.C b/src/finiteVolume/fvMesh/wallDist/nearWallDist/nearWallDist.C index bf5462f2c6ecbd059c9996984f89aa7f70011141..f7d7644037e495a3fde221fd5ef85b8cbd628668 100644 --- a/src/finiteVolume/fvMesh/wallDist/nearWallDist/nearWallDist.C +++ b/src/finiteVolume/fvMesh/wallDist/nearWallDist/nearWallDist.C @@ -36,74 +36,128 @@ void Foam::nearWallDist::calculate() { const cellDistFuncs wallUtils(mesh_); - // Collect indices of wall patches + const volVectorField& cellCentres = mesh_.C(); - DynamicList<label> wallPatchIDs(mesh_.boundary().size()); - label nWalls = 0; - forAll(mesh_.boundary(), patchi) + if (cellDistFuncs::useCombinedWallPatch) { - if (isA<wallFvPatch>(mesh_.boundary()[patchi])) - { - wallPatchIDs.append(patchi); - nWalls += mesh_.boundary()[patchi].size(); - } - else + // Collect indices of wall patches + + DynamicList<label> wallPatchIDs(mesh_.boundary().size()); + label nWalls = 0; + + forAll(mesh_.boundary(), patchi) { - // Set distance to 0 - operator[](patchi) = 0.0; + if (isA<wallFvPatch>(mesh_.boundary()[patchi])) + { + wallPatchIDs.append(patchi); + nWalls += mesh_.boundary()[patchi].size(); + } + else + { + // Set distance to 0 + operator[](patchi) = 0.0; + } } - } - // Collect all mesh faces of wall patches + // Collect all mesh faces of wall patches - DynamicList<label> faceLabels(nWalls); + DynamicList<label> faceLabels(nWalls); - for (const label patchi : wallPatchIDs) - { - const fvPatch& patch = mesh_.boundary()[patchi]; - const auto& pp = patch.patch(); - - forAll(patch, i) + for (const label patchi : wallPatchIDs) { - faceLabels.append(pp.start()+i); + const fvPatch& patch = mesh_.boundary()[patchi]; + const auto& pp = patch.patch(); + + forAll(patch, i) + { + faceLabels.append(pp.start()+i); + } } - } - const uindirectPrimitivePatch wallPatch - ( - UIndirectList<face>(mesh_.faces(), faceLabels), - mesh_.points() - ); + const uindirectPrimitivePatch wallPatch + ( + UIndirectList<face>(mesh_.faces(), faceLabels), + mesh_.points() + ); - const volVectorField& cellCentres = mesh_.C(); + DynamicList<label> neighbours; + + nWalls = 0; + for (const label patchi : wallPatchIDs) + { + const fvPatch& patch = mesh_.boundary()[patchi]; + const labelUList& faceCells = patch.patch().faceCells(); - DynamicList<label> neighbours; + fvPatchScalarField& ypatch = operator[](patchi); - nWalls = 0; - for (const label patchi : wallPatchIDs) + forAll(patch, patchFacei) + { + // Get point connected neighbours (in wallPatch indices!) + wallUtils.getPointNeighbours(wallPatch, nWalls, neighbours); + + label minFacei = -1; + ypatch[patchFacei] = wallUtils.smallestDist + ( + cellCentres[faceCells[patchFacei]], + wallPatch, + neighbours, + minFacei + ); + + nWalls++; + } + } + } + else { - const fvPatch& patch = mesh_.boundary()[patchi]; - const labelUList& faceCells = patch.patch().faceCells(); + // Get patch ids of walls + const labelHashSet wallPatchIDs(wallUtils.getPatchIDs<wallPolyPatch>()); - fvPatchScalarField& ypatch = operator[](patchi); + // Size neighbours array for maximum possible + DynamicList<label> neighbours(wallUtils.maxPatchSize(wallPatchIDs)); - forAll(patch, patchFacei) - { - // Get point connected neighbours (in wallPatch indices!) - wallUtils.getPointNeighbours(wallPatch, nWalls, neighbours); - label minFacei = -1; - ypatch[patchFacei] = wallUtils.smallestDist - ( - cellCentres[faceCells[patchFacei]], - wallPatch, - neighbours, - minFacei - ); + // Correct all cells with face on wall - nWalls++; + forAll(mesh_.boundary(), patchi) + { + fvPatchScalarField& ypatch = operator[](patchi); + + const fvPatch& patch = mesh_.boundary()[patchi]; + + if (isA<wallFvPatch>(patch)) + { + const polyPatch& pPatch = patch.patch(); + + const labelUList& faceCells = patch.faceCells(); + + // Check cells with face on wall + forAll(patch, patchFacei) + { + wallUtils.getPointNeighbours + ( + pPatch, + patchFacei, + neighbours + ); + + label minFacei = -1; + + ypatch[patchFacei] = wallUtils.smallestDist + ( + cellCentres[faceCells[patchFacei]], + pPatch, + neighbours, + minFacei + ); + } + } + else + { + ypatch = 0.0; + } } } } diff --git a/src/finiteVolume/fvMesh/wallDist/wallDistAddressing/wallDistAddressing.C b/src/finiteVolume/fvMesh/wallDist/wallDistAddressing/wallDistAddressing.C index 4f2189723cc630c868cec3b6bb57a5584a6986f2..e8111bc20f0de604b5b58692396bcabce4885834 100644 --- a/src/finiteVolume/fvMesh/wallDist/wallDistAddressing/wallDistAddressing.C +++ b/src/finiteVolume/fvMesh/wallDist/wallDistAddressing/wallDistAddressing.C @@ -235,27 +235,33 @@ void Foam::wallDistAddressing::correct(volScalarField& y) { cellToWallFace.reserve(nWalls); - //correctBoundaryFaceCells - //( - // patchSet, - // y, - // cellToWallFace - //); - //correctBoundaryPointCells - //( - // patchSet, - // y, - // cellToWallFace - //); - - // Correct across multiple patches - correctBoundaryCells - ( - patchIDs_, - true, // do point-connected cells as well - y, - cellToWallFace - ); + if (cellDistFuncs::useCombinedWallPatch) + { + // Correct across multiple patches + correctBoundaryCells + ( + patchIDs_, + true, // do point-connected cells as well + y, + cellToWallFace + ); + } + else + { + // Optional backwards compatibility + correctBoundaryFaceCells + ( + patchSet, + y, + cellToWallFace + ); + correctBoundaryPointCells + ( + patchSet, + y, + cellToWallFace + ); + } } // Make sure boundary values are up to date diff --git a/src/meshTools/cellDist/cellDistFuncs.C b/src/meshTools/cellDist/cellDistFuncs.C index 15f276ce846514cb3332d579c6a113c361a2aa31..aa9e0cd5963d113a36e03224b3618d80383a4ac2 100644 --- a/src/meshTools/cellDist/cellDistFuncs.C +++ b/src/meshTools/cellDist/cellDistFuncs.C @@ -30,6 +30,7 @@ License #include "polyMesh.H" #include "polyBoundaryMesh.H" #include "uindirectPrimitivePatch.H" +#include "registerSwitch.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -38,6 +39,16 @@ namespace Foam defineTypeNameAndDebug(cellDistFuncs, 0); } +bool Foam::cellDistFuncs::useCombinedWallPatch = true; + +registerInfoSwitch +( + "useCombinedWallPatch", + bool, + Foam::cellDistFuncs::useCombinedWallPatch +); + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::cellDistFuncs::cellDistFuncs(const polyMesh& mesh) diff --git a/src/meshTools/cellDist/cellDistFuncs.H b/src/meshTools/cellDist/cellDistFuncs.H index 2c9955a88b26ef0d618082267b6a40802bd949b9..19defde509fbdc3ad37715ecbb3af17477bac1a5 100644 --- a/src/meshTools/cellDist/cellDistFuncs.H +++ b/src/meshTools/cellDist/cellDistFuncs.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2020 OpenCFD Ltd. + Copyright (C) 2020,2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -79,8 +79,16 @@ class cellDistFuncs public: + // Static Data Members + ClassName("cellDistFuncs"); + + //- Use combined-wall-patches wall distance v.s. v2406 per-patch + //- distance. Default is true + static bool useCombinedWallPatch; + + // Constructors //- Construct from mesh diff --git a/src/meshTools/cellDist/patchWave/patchDataWave.C b/src/meshTools/cellDist/patchWave/patchDataWave.C index 2c9070995cacbcf2c0fee17eaefe7b57d2d37149..3e33b3ae7fad8d6ad907f8232b18b371694e5e42 100644 --- a/src/meshTools/cellDist/patchWave/patchDataWave.C +++ b/src/meshTools/cellDist/patchWave/patchDataWave.C @@ -263,29 +263,35 @@ void Foam::patchDataWave<TransferType, TrackingData>::correct() { Map<label> nearestFace(2 * nWalls); - // Get distance and indices of nearest face - //correctBoundaryFaceCells - //( - // patchIDs_, - // distance_, - // nearestFace - //); - - //correctBoundaryPointCells - //( - // patchIDs_, - // distance_, - // nearestFace - //); - - // Correct across multiple patches - correctBoundaryCells - ( - patchIDs_.sortedToc(), - true, // do point-connected cells as well - distance_, - nearestFace - ); + if (cellDistFuncs::useCombinedWallPatch) + { + // Correct across multiple patches + correctBoundaryCells + ( + patchIDs_.sortedToc(), + true, // do point-connected cells as well + distance_, + nearestFace + ); + } + else + { + // Get distance and indices of nearest face + correctBoundaryFaceCells + ( + patchIDs_, + distance_, + nearestFace + ); + + correctBoundaryPointCells + ( + patchIDs_, + distance_, + nearestFace + ); + } + // Transfer data from nearest face to cell const List<TransferType>& faceInfo = waveInfo.allFaceInfo(); diff --git a/src/meshTools/cellDist/patchWave/patchWave.C b/src/meshTools/cellDist/patchWave/patchWave.C index c5b5e89b109e7dc397503e09217c1eae0c036678..3adcc15da07b52f4cad624225980b048feb6babe 100644 --- a/src/meshTools/cellDist/patchWave/patchWave.C +++ b/src/meshTools/cellDist/patchWave/patchWave.C @@ -204,28 +204,34 @@ void Foam::patchWave::correct() { Map<label> nearestFace(2*nPatch); - //correctBoundaryFaceCells - //( - // patchIDs_, - // distance_, - // nearestFace - //); - - //correctBoundaryPointCells - //( - // patchIDs_, - // distance_, - // nearestFace - //); - - // Correct across multiple patches - correctBoundaryCells - ( - patchIDs_.sortedToc(), - true, // do point-connected cells as well - distance_, - nearestFace - ); + if (cellDistFuncs::useCombinedWallPatch) + { + // Correct across multiple patches + correctBoundaryCells + ( + patchIDs_.sortedToc(), + true, // do point-connected cells as well + distance_, + nearestFace + ); + } + else + { + // Backwards compatible + correctBoundaryFaceCells + ( + patchIDs_, + distance_, + nearestFace + ); + + correctBoundaryPointCells + ( + patchIDs_, + distance_, + nearestFace + ); + } } }