diff --git a/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.C b/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.C index e1b457edd05607462c877b3c5aa1b6201e3d67d7..f66d7eb1d44737e65f2513fc809db38e90fc3fd1 100644 --- a/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.C +++ b/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2015-2023 OpenCFD Ltd. + Copyright (C) 2015-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -86,6 +86,12 @@ Foam::mappedPatchBase::offsetModeNames_ // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // +void Foam::mappedPatchBase::updateMesh(PstreamBuffers& pBufs) +{ + clearOut(); +} + + Foam::autoPtr<Foam::fileName> Foam::mappedPatchBase::readDatabase ( const dictionary& dict @@ -1569,8 +1575,9 @@ Foam::mappedPatchBase::~mappedPatchBase() void Foam::mappedPatchBase::clearOut() { mapPtr_.reset(nullptr); - surfPtr_.reset(nullptr); AMIPtr_->upToDate(false); + + //Note: no need to clear out surface since not mesh related } @@ -1674,6 +1681,76 @@ const Foam::polyPatch& Foam::mappedPatchBase::samplePolyPatch() const } +bool Foam::mappedPatchBase::upToDate() const +{ + const polyMesh& thisMesh = patch_.boundaryMesh().mesh(); + + bool thisUpToDate = thisMesh.upToDatePoints(updateMeshTime()); + bool sampleUpToDate = + ( + sameWorld() + ? sampleMesh().upToDatePoints(updateSampleMeshTime()) + : true + ); + + + // Lambda to check for points on the patch being the same + auto checkPointMovement = [] + ( + const polyMesh& mesh, + const polyPatch& patch, + regIOobject& state + ) -> bool + { + bool upToDate = true; + const auto& oldPoints = mesh.oldPoints(); + const auto& points = mesh.points(); + + for (const label pointi : patch.meshPoints()) + { + const point& oldPt = oldPoints[pointi]; + const point& currentPt = points[pointi]; + + if (mag(oldPt - currentPt) > SMALL) + { + upToDate = false; + break; + } + } + + Pstream::reduceAnd(upToDate); + + if (upToDate) + { + state.setUpToDate(); + } + + return upToDate; + }; + + + if (!thisUpToDate && thisMesh.moving()) + { + // Moving (but not topoChanging mesh) : do more accurate check: + // compare actual patch point position + + thisUpToDate = checkPointMovement(thisMesh, patch_, updateMeshTime()); + } + + if (!sampleUpToDate && sampleMesh().moving()) + { + sampleUpToDate = checkPointMovement + ( + sampleMesh(), + samplePolyPatch(), + updateSampleMeshTime() + ); + } + + return (thisUpToDate && sampleUpToDate); +} + + Foam::tmp<Foam::pointField> Foam::mappedPatchBase::samplePoints ( const pointField& fc diff --git a/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.H b/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.H index f2a90f90917877bec69a129dab6d12cad1e51472..b0d0d1fcab784ef453983c3bea67f725db2d175a 100644 --- a/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.H +++ b/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.H @@ -301,6 +301,32 @@ protected: // Protected Member Functions + // polyPatch callbacks + + //- Initialise the calculation of the patch geometry + virtual void initGeometry(PstreamBuffers&) + {} + + //- Calculate the patch geometry + virtual void calcGeometry(PstreamBuffers&) + {} + + //- Initialise the patches for moving points + virtual void initMovePoints(PstreamBuffers&, const pointField&) + {} + + //- Correct patches after moving points + virtual void movePoints(PstreamBuffers&, const pointField&) + {} + + //- Initialise the update of the patch topology + virtual void initUpdateMesh(PstreamBuffers&) + {} + + //- Update of the patch topology + virtual void updateMesh(PstreamBuffers&); + + //- Add a world-world connection bool addWorldConnection(); @@ -532,7 +558,7 @@ public: //- Sample mesh upate time inline uniformDimensionedScalarField& updateMeshTime() const; - inline bool upToDate() const; + bool upToDate() const; //- Return reference to the parallel distribution map inline const mapDistribute& map() const; diff --git a/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBaseI.H b/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBaseI.H index b2ebe51e9ff305e4eafcde389ee5046f860919aa..5c267312207a8c7a42e062827147202d080b6b6a 100644 --- a/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBaseI.H +++ b/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBaseI.H @@ -252,25 +252,6 @@ Foam::mappedPatchBase::updateMeshTime() const } -inline bool Foam::mappedPatchBase::upToDate() const -{ - const polyMesh& thisMesh = patch_.boundaryMesh().mesh(); - - if (sameWorld()) - { - return - sampleMesh().upToDatePoints(updateSampleMeshTime()) - && thisMesh.upToDatePoints(updateMeshTime()); - } - else - { - // If not the same world we do not know what the other side is doing - // so only check our local side - return thisMesh.upToDatePoints(updateMeshTime()); - } -} - - inline const Foam::mapDistribute& Foam::mappedPatchBase::map() const { if (!upToDate()) diff --git a/src/meshTools/mappedPatches/mappedPolyPatch/mappedPolyPatch.C b/src/meshTools/mappedPatches/mappedPolyPatch/mappedPolyPatch.C index 76d7f2bb827b8d7c3232b44f475bc5b785d72cb2..79ccb0a79bd465175ddb4cb7072028087df9bc0c 100644 --- a/src/meshTools/mappedPatches/mappedPolyPatch/mappedPolyPatch.C +++ b/src/meshTools/mappedPatches/mappedPolyPatch/mappedPolyPatch.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2013 OpenFOAM Foundation - Copyright (C) 2021-2023 OpenCFD Ltd. + Copyright (C) 2021-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -169,9 +169,7 @@ Foam::mappedPolyPatch::mappedPolyPatch // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // Foam::mappedPolyPatch::~mappedPolyPatch() -{ - mappedPatchBase::clearOut(); -} +{} // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // @@ -179,13 +177,14 @@ Foam::mappedPolyPatch::~mappedPolyPatch() void Foam::mappedPolyPatch::initGeometry(PstreamBuffers& pBufs) { polyPatch::initGeometry(pBufs); + mappedPatchBase::initGeometry(pBufs); } void Foam::mappedPolyPatch::calcGeometry(PstreamBuffers& pBufs) { polyPatch::calcGeometry(pBufs); - mappedPatchBase::clearOut(); + mappedPatchBase::calcGeometry(pBufs); } @@ -196,6 +195,7 @@ void Foam::mappedPolyPatch::initMovePoints ) { polyPatch::initMovePoints(pBufs, p); + mappedPatchBase::initMovePoints(pBufs, p); } @@ -206,20 +206,21 @@ void Foam::mappedPolyPatch::movePoints ) { polyPatch::movePoints(pBufs, p); - mappedPatchBase::clearOut(); + mappedPatchBase::movePoints(pBufs, p); } void Foam::mappedPolyPatch::initUpdateMesh(PstreamBuffers& pBufs) { polyPatch::initUpdateMesh(pBufs); + mappedPatchBase::initUpdateMesh(pBufs); } void Foam::mappedPolyPatch::updateMesh(PstreamBuffers& pBufs) { polyPatch::updateMesh(pBufs); - mappedPatchBase::clearOut(); + mappedPatchBase::updateMesh(pBufs); } diff --git a/src/meshTools/mappedPatches/mappedPolyPatch/mappedWallPolyPatch.C b/src/meshTools/mappedPatches/mappedPolyPatch/mappedWallPolyPatch.C index 759e07aaa13e4fcd00581a419d18f11077f87a92..223bfc0aeec7473015858a287a52a3ce44e3dd74 100644 --- a/src/meshTools/mappedPatches/mappedPolyPatch/mappedWallPolyPatch.C +++ b/src/meshTools/mappedPatches/mappedPolyPatch/mappedWallPolyPatch.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2013 OpenFOAM Foundation - Copyright (C) 2021-2023 OpenCFD Ltd. + Copyright (C) 2021-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -175,9 +175,7 @@ Foam::mappedWallPolyPatch::mappedWallPolyPatch // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // Foam::mappedWallPolyPatch::~mappedWallPolyPatch() -{ - mappedPatchBase::clearOut(); -} +{} // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // @@ -191,7 +189,7 @@ void Foam::mappedWallPolyPatch::initGeometry(PstreamBuffers& pBufs) void Foam::mappedWallPolyPatch::calcGeometry(PstreamBuffers& pBufs) { wallPolyPatch::calcGeometry(pBufs); - mappedPatchBase::clearOut(); + mappedPatchBase::calcGeometry(pBufs); } @@ -202,6 +200,7 @@ void Foam::mappedWallPolyPatch::initMovePoints ) { wallPolyPatch::initMovePoints(pBufs, p); + mappedPatchBase::initMovePoints(pBufs, p); } @@ -212,20 +211,21 @@ void Foam::mappedWallPolyPatch::movePoints ) { wallPolyPatch::movePoints(pBufs, p); - mappedPatchBase::clearOut(); + mappedPatchBase::movePoints(pBufs, p); } void Foam::mappedWallPolyPatch::initUpdateMesh(PstreamBuffers& pBufs) { wallPolyPatch::initUpdateMesh(pBufs); + mappedPatchBase::initUpdateMesh(pBufs); } void Foam::mappedWallPolyPatch::updateMesh(PstreamBuffers& pBufs) { wallPolyPatch::updateMesh(pBufs); - mappedPatchBase::clearOut(); + mappedPatchBase::updateMesh(pBufs); }