From 9175fb13fd134c652989a122bf71a2464cf41ae4 Mon Sep 17 00:00:00 2001 From: Will Bainbridge Date: Wed, 15 Feb 2023 15:51:34 +0000 Subject: [PATCH] meshToMesh: Stabilisation Stabilisation has been added to the mapping of fields between consistent meshes. This means that if part of the target mesh is found not to connect with the source mesh, then its values will be set by propagating a value from the closest part of the target mesh did successfully connect to the source. This propagation is achieved by means of a mesh wave. This stabilisation applies to both cell and patch fields, and any and all ancillary fields that may be being stored by the patch boundary conditions. It applies to the mapping performed by both mapFieldsPar and the run-time mapping meshToMesh topology changer. This fixes the previous situation in mapping between consistent meshes in which target elements which did not connect to the source would be given an undefined value, which would cause either a floating point error, or (worse) incorrect operation. --- src/OpenFOAM/primitives/remote/remote.H | 12 +- src/OpenFOAM/primitives/remote/remoteI.H | 18 +- src/finiteVolume/Make/files | 2 - .../fvMeshToFvMesh/fvMeshToFvMeshTemplates.C | 41 ++- .../patchToPatchFvPatchFieldMapper.C | 14 + .../patchToPatchFvPatchFieldMapper.H | 169 ++++++++---- .../patchToPatchFvPatchFieldMapperTemplates.C | 52 ++++ ...PatchLeftOverFvPatchFieldMapperTemplates.C | 53 ---- ...tchNormalisedFvPatchFieldMapperTemplates.C | 53 ---- src/meshTools/Make/files | 4 + .../PatchEdgeFacePointDataI.H | 2 +- .../cellsToCells/cellsToCells/cellsToCells.C | 22 ++ .../cellsToCells/cellsToCells/cellsToCells.H | 6 + .../cellsToCellsStabilisation.C | 240 ++++++++++++++++++ .../cellsToCellsStabilisation.H} | 73 +++--- .../cellsToCellsStabilisationTemplates.C} | 24 +- src/meshTools/meshToMesh/meshToMesh.C | 61 +++-- src/meshTools/meshToMesh/meshToMesh.H | 72 ++++-- src/meshTools/meshToMesh/meshToMeshI.H | 91 ++++++- .../patchToPatch/patchToPatch/patchToPatch.C | 52 +++- .../patchToPatch/patchToPatch/patchToPatch.H | 10 +- .../patchToPatch/patchToPatch/patchToPatchI.H | 30 +-- .../patchToPatchStabilisation.C | 207 +++++++++++++++ .../patchToPatchStabilisation.H} | 73 +++--- .../patchToPatchStabilisationTemplates.C} | 24 +- 25 files changed, 1060 insertions(+), 345 deletions(-) delete mode 100644 src/finiteVolume/fvMeshToFvMesh/patchToPatchLeftOverFvPatchFieldMapperTemplates.C delete mode 100644 src/finiteVolume/fvMeshToFvMesh/patchToPatchNormalisedFvPatchFieldMapperTemplates.C create mode 100644 src/meshTools/cellsToCells/cellsToCellsStabilisation/cellsToCellsStabilisation.C rename src/{finiteVolume/fvMeshToFvMesh/patchToPatchLeftOverFvPatchFieldMapper.H => meshTools/cellsToCells/cellsToCellsStabilisation/cellsToCellsStabilisation.H} (57%) rename src/{finiteVolume/fvMeshToFvMesh/patchToPatchLeftOverFvPatchFieldMapper.C => meshTools/cellsToCells/cellsToCellsStabilisation/cellsToCellsStabilisationTemplates.C} (72%) create mode 100644 src/meshTools/patchToPatch/patchToPatchStabilisation/patchToPatchStabilisation.C rename src/{finiteVolume/fvMeshToFvMesh/patchToPatchNormalisedFvPatchFieldMapper.H => meshTools/patchToPatch/patchToPatchStabilisation/patchToPatchStabilisation.H} (57%) rename src/{finiteVolume/fvMeshToFvMesh/patchToPatchNormalisedFvPatchFieldMapper.C => meshTools/patchToPatch/patchToPatchStabilisation/patchToPatchStabilisationTemplates.C} (72%) diff --git a/src/OpenFOAM/primitives/remote/remote.H b/src/OpenFOAM/primitives/remote/remote.H index 8c568c28ff..fd802ee14d 100644 --- a/src/OpenFOAM/primitives/remote/remote.H +++ b/src/OpenFOAM/primitives/remote/remote.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2022 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2022-2023 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -98,6 +98,16 @@ public: }; +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +template<> +class pTraits +{ +public: + typedef remote cmptType; +}; + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace Foam diff --git a/src/OpenFOAM/primitives/remote/remoteI.H b/src/OpenFOAM/primitives/remote/remoteI.H index b5ba9f1ac3..6c7abe37fc 100644 --- a/src/OpenFOAM/primitives/remote/remoteI.H +++ b/src/OpenFOAM/primitives/remote/remoteI.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2022 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2022-2023 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -75,4 +75,20 @@ inline Foam::Istream& Foam::operator>>(Istream& is, remote& p) } +// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * // + +namespace Foam +{ + +template +class Tensor; + +inline remote transform(const Tensor&, const remote& p) +{ + return p; +} + +} + + // ************************************************************************* // diff --git a/src/finiteVolume/Make/files b/src/finiteVolume/Make/files index 47bbcbe6be..4e299686aa 100644 --- a/src/finiteVolume/Make/files +++ b/src/finiteVolume/Make/files @@ -517,7 +517,5 @@ solver/solverNew.C fvMeshToFvMesh/fvMeshToFvMesh.C fvMeshToFvMesh/patchToPatchFvPatchFieldMapper.C -fvMeshToFvMesh/patchToPatchLeftOverFvPatchFieldMapper.C -fvMeshToFvMesh/patchToPatchNormalisedFvPatchFieldMapper.C LIB = $(FOAM_LIBBIN)/libfiniteVolume diff --git a/src/finiteVolume/fvMeshToFvMesh/fvMeshToFvMeshTemplates.C b/src/finiteVolume/fvMeshToFvMesh/fvMeshToFvMeshTemplates.C index 109ea25ec9..a2f89f263b 100644 --- a/src/finiteVolume/fvMeshToFvMesh/fvMeshToFvMeshTemplates.C +++ b/src/finiteVolume/fvMeshToFvMesh/fvMeshToFvMeshTemplates.C @@ -26,8 +26,7 @@ License #include "fvMeshToFvMesh.H" #include "directFvPatchFieldMapper.H" #include "identityFvPatchFieldMapper.H" -#include "patchToPatchNormalisedFvPatchFieldMapper.H" -#include "patchToPatchLeftOverFvPatchFieldMapper.H" +#include "patchToPatchFvPatchFieldMapper.H" // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // @@ -125,10 +124,10 @@ Foam::tmp> Foam::fvMeshToFvMesh::srcToTgt // Construct target patch fields as copies of source patch fields, but do // not map values yet PtrList> tgtPatchFields(tgtMesh.boundary().size()); - forAll(srcToTgtPatchIDs(), i) + forAll(patchIDs(), i) { - const label srcPatchi = srcToTgtPatchIDs()[i].first(); - const label tgtPatchi = srcToTgtPatchIDs()[i].second(); + const label srcPatchi = patchIDs()[i].first(); + const label tgtPatchi = patchIDs()[i].second(); if (!tgtPatchFields.set(tgtPatchi)) { @@ -188,18 +187,18 @@ Foam::tmp> Foam::fvMeshToFvMesh::srcToTgt ttgtFld.ref().boundaryFieldRef(); // Mapped patches - forAll(srcToTgtPatchIDs(), i) + forAll(patchIDs(), i) { - const label srcPatchi = srcToTgtPatchIDs()[i].first(); - const label tgtPatchi = srcToTgtPatchIDs()[i].second(); + const label srcPatchi = patchIDs()[i].first(); + const label tgtPatchi = patchIDs()[i].second(); tgtBfld[tgtPatchi].map ( srcFld.boundaryField()[srcPatchi], patchToPatchNormalisedFvPatchFieldMapper ( - srcToTgtPatchToPatches()[i], - true + patchInterpolation(i), + tgtPatchStabilisation(i) ) ); } @@ -241,10 +240,10 @@ Foam::tmp> Foam::fvMeshToFvMesh::srcToTgt ttgtFld.ref().boundaryFieldRef(); // Mapped patches - forAll(srcToTgtPatchIDs(), i) + forAll(patchIDs(), i) { - const label srcPatchi = srcToTgtPatchIDs()[i].first(); - const label tgtPatchi = srcToTgtPatchIDs()[i].second(); + const label srcPatchi = patchIDs()[i].first(); + const label tgtPatchi = patchIDs()[i].second(); tgtBfld[tgtPatchi].map ( @@ -254,11 +253,7 @@ Foam::tmp> Foam::fvMeshToFvMesh::srcToTgt tgtBfld[tgtPatchi].map ( srcFld.boundaryField()[srcPatchi], - patchToPatchLeftOverFvPatchFieldMapper - ( - srcToTgtPatchToPatches()[i], - true - ) + patchToPatchLeftOverFvPatchFieldMapper(patchInterpolation(i)) ); } @@ -283,14 +278,18 @@ Foam::tmp> Foam::fvMeshToFvMesh::srcToTgt const VolInternalField& srcFld ) const { - return + tmp> ttgtFld = VolInternalField::New ( typedName("interpolate(" + srcFld.name() + ")"), static_cast(meshToMesh::tgtMesh()), srcFld.dimensions(), - srcToTgtCellsToCells().srcToTgt(srcFld) + cellsInterpolation().srcToTgt(srcFld) ); + + tgtCellsStabilisation().stabilise(ttgtFld.ref()); + + return ttgtFld; } @@ -307,7 +306,7 @@ Foam::tmp> Foam::fvMeshToFvMesh::srcToTgt typedName("interpolate(" + srcFld.name() + ")"), static_cast(meshToMesh::tgtMesh()), leftOverTgtFld.dimensions(), - srcToTgtCellsToCells().srcToTgt(srcFld, leftOverTgtFld) + cellsInterpolation().srcToTgt(srcFld, leftOverTgtFld) ); } diff --git a/src/finiteVolume/fvMeshToFvMesh/patchToPatchFvPatchFieldMapper.C b/src/finiteVolume/fvMeshToFvMesh/patchToPatchFvPatchFieldMapper.C index 53fcea895d..d369946497 100644 --- a/src/finiteVolume/fvMeshToFvMesh/patchToPatchFvPatchFieldMapper.C +++ b/src/finiteVolume/fvMeshToFvMesh/patchToPatchFvPatchFieldMapper.C @@ -48,4 +48,18 @@ Foam::patchToPatchFvPatchFieldMapper::operator() } +FOR_ALL_FIELD_TYPES +( + IMPLEMENT_FIELD_MAPPER_OPERATOR, + patchToPatchLeftOverFvPatchFieldMapper +) + + +FOR_ALL_FIELD_TYPES +( + IMPLEMENT_FIELD_MAPPER_OPERATOR, + patchToPatchNormalisedFvPatchFieldMapper +) + + // ************************************************************************* // diff --git a/src/finiteVolume/fvMeshToFvMesh/patchToPatchFvPatchFieldMapper.H b/src/finiteVolume/fvMeshToFvMesh/patchToPatchFvPatchFieldMapper.H index 8885f384a6..6092773866 100644 --- a/src/finiteVolume/fvMeshToFvMesh/patchToPatchFvPatchFieldMapper.H +++ b/src/finiteVolume/fvMeshToFvMesh/patchToPatchFvPatchFieldMapper.H @@ -36,6 +36,8 @@ Description #include "fvPatchFieldMapper.H" #include "patchToPatch.H" +#include "patchToPatchStabilisation.H" +#include "ListOps.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -43,7 +45,7 @@ namespace Foam { /*---------------------------------------------------------------------------*\ - Class patchToPatchFvPatchFieldMapper Declaration + Class patchToPatchFvPatchFieldMapper Declaration \*---------------------------------------------------------------------------*/ class patchToPatchFvPatchFieldMapper @@ -54,49 +56,20 @@ protected: // Protected Data - //- Patch-to-patch mapping engine + //- Patch-to-patch interpolation engine const patchToPatch& pToP_; - //- Mapping direction - const bool forward_; - - //- Size of the mapped field - label size_; - - //- Does the mapping engine leave anything unmapped? - bool hasUnmapped_; - public: // Constructors - //- Construct given a patch-to-patch and a mapping direction - patchToPatchFvPatchFieldMapper - ( - const patchToPatch& pToP, - const bool forward - ) + //- Construct given a patch-to-patch interpolation + patchToPatchFvPatchFieldMapper(const patchToPatch& pToP) : fvPatchFieldMapper(), - pToP_(pToP), - forward_(forward), - size_(-1), - hasUnmapped_(false) - { - const List> procFaces = - forward_ ? pToP_.tgtSrcProcFaces() : pToP_.srcTgtProcFaces(); - - size_ = procFaces.size(); - - forAll(procFaces, i) - { - if (procFaces[i].size() == 0) - { - hasUnmapped_ = true; - } - } - } + pToP_(pToP) + {} //- Destructor @@ -104,18 +77,9 @@ public: {} - // Member Functions - - //- Return whether or not all faces receive a mapped value - virtual bool hasUnmapped() const - { - return hasUnmapped_; - } - - // Member Operators - //- Map a label field + //- Map a label field (not implemented) DEFINE_FIELD_MAPPER_OPERATOR(label, ); //- Map a temporary field @@ -128,6 +92,121 @@ public: }; +/*---------------------------------------------------------------------------*\ + Class patchToPatchLeftOverFvPatchFieldMapper Declaration +\*---------------------------------------------------------------------------*/ + +class patchToPatchLeftOverFvPatchFieldMapper +: + public patchToPatchFvPatchFieldMapper +{ + // Private Member Functions + + //- Map from one field to another + template + void map(Field& f, const Field& mapF) const; + + //- Map a field and return the result as tmp + template + tmp> map(const Field& mapF) const; + + +public: + + // Constructors + + //- Inherit base class constructor + using patchToPatchFvPatchFieldMapper::patchToPatchFvPatchFieldMapper; + + + //- Destructor + virtual ~patchToPatchLeftOverFvPatchFieldMapper() + {} + + + // Member Functions + + //- Return whether or not all faces receive a mapped value + virtual bool hasUnmapped() const + { + FatalErrorInFunction + << "Not a valid query for this mapper, which should only be " + << "used for modifying an existing, valid, field" + << exit(FatalError); + return false; + } + + + // Member Operators + + //- Map a field + FOR_ALL_FIELD_TYPES(DEFINE_FIELD_MAPPER_OPERATOR, ); +}; + + +/*---------------------------------------------------------------------------*\ + Class patchToPatchNormalisedFvPatchFieldMapper Declaration +\*---------------------------------------------------------------------------*/ + +class patchToPatchNormalisedFvPatchFieldMapper +: + public patchToPatchFvPatchFieldMapper +{ + // Private Data + + //- Patch stabilisation engine + const patchToPatchStabilisation& pS_; + + + // Private Member Functions + + //- Map from one field to another + template + void map(Field& f, const Field& mapF) const; + + //- Map a field and return the result as tmp + template + tmp> map(const Field& mapF) const; + + +public: + + // Constructors + + //- Construct given a patch-to-patch interpolation and stabilisation + patchToPatchNormalisedFvPatchFieldMapper + ( + const patchToPatch& pToP, + const patchToPatchStabilisation& pS + ) + : + patchToPatchFvPatchFieldMapper(pToP), + pS_(pS) + {} + + + //- Destructor + virtual ~patchToPatchNormalisedFvPatchFieldMapper() + {} + + + // Member Functions + + //- Return whether or not all faces receive a mapped value + virtual bool hasUnmapped() const + { + return false; + } + + + // Member Operators + + //- Map a field + FOR_ALL_FIELD_TYPES(DEFINE_FIELD_MAPPER_OPERATOR, ); +}; + + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace Foam diff --git a/src/finiteVolume/fvMeshToFvMesh/patchToPatchFvPatchFieldMapperTemplates.C b/src/finiteVolume/fvMeshToFvMesh/patchToPatchFvPatchFieldMapperTemplates.C index 12ee688159..8077051433 100644 --- a/src/finiteVolume/fvMeshToFvMesh/patchToPatchFvPatchFieldMapperTemplates.C +++ b/src/finiteVolume/fvMeshToFvMesh/patchToPatchFvPatchFieldMapperTemplates.C @@ -52,4 +52,56 @@ Foam::patchToPatchFvPatchFieldMapper::operator() } +template +void Foam::patchToPatchLeftOverFvPatchFieldMapper::map +( + Field& f, + const Field& mapF +) const +{ + f = pToP_.srcToTgt(mapF, f); +} + + +template +Foam::tmp> +Foam::patchToPatchLeftOverFvPatchFieldMapper::map +( + const Field& mapF +) const +{ + FatalErrorInFunction + << "Not a valid operation for this mapper, which should only be " + << "used for modifying an existing, valid, field" + << exit(FatalError); + return tmp>(nullptr); +} + + +template +void Foam::patchToPatchNormalisedFvPatchFieldMapper::map +( + Field& f, + const Field& mapF +) const +{ + f = pToP_.srcToTgt(mapF); + + pS_.stabilise(f); +} + + +template +Foam::tmp> +Foam::patchToPatchNormalisedFvPatchFieldMapper::map +( + const Field& mapF +) const +{ + tmp> tf(new Field()); + map(tf.ref(), mapF); + return tf; +} + + // ************************************************************************* // diff --git a/src/finiteVolume/fvMeshToFvMesh/patchToPatchLeftOverFvPatchFieldMapperTemplates.C b/src/finiteVolume/fvMeshToFvMesh/patchToPatchLeftOverFvPatchFieldMapperTemplates.C deleted file mode 100644 index d887518024..0000000000 --- a/src/finiteVolume/fvMeshToFvMesh/patchToPatchLeftOverFvPatchFieldMapperTemplates.C +++ /dev/null @@ -1,53 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2022-2023 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 "patchToPatchLeftOverFvPatchFieldMapper.H" - -// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // - -template -void Foam::patchToPatchLeftOverFvPatchFieldMapper::map -( - Field& f, - const Field& mapF -) const -{ - f = forward_ ? pToP_.srcToTgt(mapF, f) : pToP_.tgtToSrc(mapF, f); -} - - -template -Foam::tmp> -Foam::patchToPatchLeftOverFvPatchFieldMapper::map -( - const Field& mapF -) const -{ - NotImplemented; - return tmp>(nullptr); -} - - -// ************************************************************************* // diff --git a/src/finiteVolume/fvMeshToFvMesh/patchToPatchNormalisedFvPatchFieldMapperTemplates.C b/src/finiteVolume/fvMeshToFvMesh/patchToPatchNormalisedFvPatchFieldMapperTemplates.C deleted file mode 100644 index 7792df95aa..0000000000 --- a/src/finiteVolume/fvMeshToFvMesh/patchToPatchNormalisedFvPatchFieldMapperTemplates.C +++ /dev/null @@ -1,53 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2022-2023 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 "patchToPatchNormalisedFvPatchFieldMapper.H" - -// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // - -template -void Foam::patchToPatchNormalisedFvPatchFieldMapper::map -( - Field& f, - const Field& mapF -) const -{ - f = forward_ ? pToP_.srcToTgt(mapF) : pToP_.tgtToSrc(mapF); -} - - -template -Foam::tmp> Foam::patchToPatchNormalisedFvPatchFieldMapper::map -( - const Field& mapF -) const -{ - tmp> tf(new Field(size_)); - map(tf.ref(), mapF); - return tf; -} - - -// ************************************************************************* // diff --git a/src/meshTools/Make/files b/src/meshTools/Make/files index 500021e1f3..9b483128df 100644 --- a/src/meshTools/Make/files +++ b/src/meshTools/Make/files @@ -215,12 +215,16 @@ patchToPatch/inverseDistance/inverseDistancePatchToPatch.C patchToPatch/intersection/intersectionPatchToPatch.C patchToPatch/rays/raysPatchToPatch.C +patchToPatch/patchToPatchStabilisation/patchToPatchStabilisation.C + cellsToCells/cellsToCells/cellsToCells.C cellsToCells/cellsToCells/cellsToCellsParallelOps.C cellsToCells/matching/matchingCellsToCells.C cellsToCells/nearest/nearestCellsToCells.C cellsToCells/intersection/intersectionCellsToCells.C +cellsToCells/cellsToCellsStabilisation/cellsToCellsStabilisation.C + meshToMesh/meshToMesh.C mappedPatches/mappedPatchBase/mappedPatchBase.C diff --git a/src/meshTools/algorithms/PatchEdgeFaceWave/PatchEdgeFacePointDataI.H b/src/meshTools/algorithms/PatchEdgeFaceWave/PatchEdgeFacePointDataI.H index fa953125b0..ae13a7c45f 100644 --- a/src/meshTools/algorithms/PatchEdgeFaceWave/PatchEdgeFacePointDataI.H +++ b/src/meshTools/algorithms/PatchEdgeFaceWave/PatchEdgeFacePointDataI.H @@ -176,8 +176,8 @@ inline bool Foam::PatchEdgeFacePointData::updateFace ( mesh, patch, - edgei, facei, + edgei, edgeInfo, tol, td diff --git a/src/meshTools/cellsToCells/cellsToCells/cellsToCells.C b/src/meshTools/cellsToCells/cellsToCells/cellsToCells.C index 50d3f2e244..57a7a20d26 100644 --- a/src/meshTools/cellsToCells/cellsToCells/cellsToCells.C +++ b/src/meshTools/cellsToCells/cellsToCells/cellsToCells.C @@ -183,6 +183,28 @@ Foam::autoPtr Foam::cellsToCells::New // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // +Foam::PackedBoolList Foam::cellsToCells::srcCoupled() const +{ + PackedBoolList result(srcLocalTgtCells_.size()); + forAll(srcLocalTgtCells_, srcCelli) + { + result[srcCelli] = !srcLocalTgtCells_[srcCelli].empty(); + } + return result; +} + + +Foam::PackedBoolList Foam::cellsToCells::tgtCoupled() const +{ + PackedBoolList result(tgtLocalSrcCells_.size()); + forAll(tgtLocalSrcCells_, tgtCelli) + { + result[tgtCelli] = !tgtLocalSrcCells_[tgtCelli].empty(); + } + return result; +} + + Foam::remote Foam::cellsToCells::srcToTgtPoint ( const polyMesh& tgtMesh, diff --git a/src/meshTools/cellsToCells/cellsToCells/cellsToCells.H b/src/meshTools/cellsToCells/cellsToCells/cellsToCells.H index 7a63fb6906..8bab2f71fd 100644 --- a/src/meshTools/cellsToCells/cellsToCells/cellsToCells.H +++ b/src/meshTools/cellsToCells/cellsToCells/cellsToCells.H @@ -209,6 +209,12 @@ public: //- Is this intersection on a single process? inline bool isSingleProcess() const; + //- Return a list indicating which source cells are coupled + PackedBoolList srcCoupled() const; + + //- Return a list indicating which target cells are coupled + PackedBoolList tgtCoupled() const; + // Interpolation diff --git a/src/meshTools/cellsToCells/cellsToCellsStabilisation/cellsToCellsStabilisation.C b/src/meshTools/cellsToCells/cellsToCellsStabilisation/cellsToCellsStabilisation.C new file mode 100644 index 0000000000..64b3be855e --- /dev/null +++ b/src/meshTools/cellsToCells/cellsToCellsStabilisation/cellsToCellsStabilisation.C @@ -0,0 +1,240 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2023 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 "cellsToCellsStabilisation.H" +#include "syncTools.H" +#include "wallPoint.H" +#include "WallLocationData.H" +#include "WallInfo.H" +#include "FaceCellWave.H" +#include "globalIndex.H" +#include "OBJstream.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + defineTypeNameAndDebug(cellsToCellsStabilisation, 0); +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::cellsToCellsStabilisation::cellsToCellsStabilisation() +: + stabilisation_(false), + localStabilisationCells_(), + stabilisationMapPtr_(nullptr) +{} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::cellsToCellsStabilisation::~cellsToCellsStabilisation() +{} + + +// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // + +void Foam::cellsToCellsStabilisation::update +( + const polyMesh& mesh, + const PackedBoolList& cellCoupleds +) +{ + // Determine whether or not stabilisation is necessary + stabilisation_ = false; + forAll(cellCoupleds, celli) + { + if (!cellCoupleds[celli]) + { + stabilisation_ = true; + break; + } + } + reduce(stabilisation_, orOp()); + + // Quick return if nothing is to be done + if (!stabilisation_) return; + + // Get some information regarding the cells on the other side of couplings + List bFaceNbrProcCells(mesh.nFaces() - mesh.nInternalFaces()); + boolList bFaceNbrIsCoupled(mesh.nFaces() - mesh.nInternalFaces()); + forAll(bFaceNbrIsCoupled, bFacei) + { + const label owni = mesh.faceOwner()[bFacei + mesh.nInternalFaces()]; + bFaceNbrProcCells[bFacei] = remote(Pstream::myProcNo(), owni); + bFaceNbrIsCoupled[bFacei] = cellCoupleds[owni]; + } + syncTools::swapBoundaryFaceList(mesh, bFaceNbrProcCells); + syncTools::swapBoundaryFaceList(mesh, bFaceNbrIsCoupled); + + // Determine the "cut" faces that separate coupled and un-coupled cellS + typedef WallInfo> info; + DynamicList