BUG: avoid excessive recalculation of map for moving meshes

This commit is contained in:
Andrew Heather
2022-11-18 16:46:25 +00:00
committed by mattijs
parent 013f3cccc4
commit 945405c32d
3 changed files with 97 additions and 10 deletions

View File

@ -724,6 +724,8 @@ void Foam::mappedPatchBase::findSamples
void Foam::mappedPatchBase::calcMapping() const void Foam::mappedPatchBase::calcMapping() const
{ {
DebugInFunction;
static bool hasWarned = false; static bool hasWarned = false;
if (mapPtr_) if (mapPtr_)
{ {
@ -1051,6 +1053,9 @@ void Foam::mappedPatchBase::calcMapping() const
} }
} }
} }
updateMeshTime().setUpToDate();
updateSampleMeshTime().setUpToDate();
} }

View File

@ -96,6 +96,7 @@ SourceFiles
#include "pointIndexHit.H" #include "pointIndexHit.H"
#include "AMIPatchToPatchInterpolation.H" #include "AMIPatchToPatchInterpolation.H"
#include "coupleGroupIdentifier.H" #include "coupleGroupIdentifier.H"
#include "uniformDimensionedFields.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -288,6 +289,16 @@ protected:
dictionary surfDict_; dictionary surfDict_;
// Mesh update IOobjects
//- Local mesh update time
mutable autoPtr<uniformDimensionedScalarField> updateMeshTimePtr_;
//- Sample mesh update time
mutable autoPtr<uniformDimensionedScalarField>
updateSampleMeshTimePtr_;
// Protected Member Functions // Protected Member Functions
//- Add a world-world connection //- Add a world-world connection
@ -515,6 +526,14 @@ public:
//- Cached sampleRegion != mesh.name() //- Cached sampleRegion != mesh.name()
inline bool sameRegion() const noexcept; inline bool sameRegion() const noexcept;
//- Local mesh update time
inline uniformDimensionedScalarField& updateSampleMeshTime() const;
//- Sample mesh upate time
inline uniformDimensionedScalarField& updateMeshTime() const;
inline bool upToDate() const;
//- Return reference to the parallel distribution map //- Return reference to the parallel distribution map
inline const mapDistribute& map() const; inline const mapDistribute& map() const;

View File

@ -196,16 +196,78 @@ inline bool Foam::mappedPatchBase::sameRegion() const noexcept
} }
inline const Foam::mapDistribute& Foam::mappedPatchBase::map() const inline Foam::uniformDimensionedScalarField&
Foam::mappedPatchBase::updateSampleMeshTime() const
{
if (!updateSampleMeshTimePtr_)
{
const auto& mesh = sampleMesh();
updateSampleMeshTimePtr_ =
autoPtr<uniformDimensionedScalarField>::New
(
IOobject
(
"updateSampleMeshTime",
mesh.pointsInstance(),
mesh,
IOobject::NO_READ,
IOobject::NO_WRITE,
false
)
);
}
return updateSampleMeshTimePtr_();
}
inline Foam::uniformDimensionedScalarField&
Foam::mappedPatchBase::updateMeshTime() const
{
if (!updateMeshTimePtr_)
{
const auto& mesh = patch_.boundaryMesh().mesh();
updateMeshTimePtr_ =
autoPtr<uniformDimensionedScalarField>::New
(
IOobject
(
"updateMeshTime",
mesh.pointsInstance(),
mesh,
IOobject::NO_READ,
IOobject::NO_WRITE,
false
)
);
}
return updateMeshTimePtr_();
}
inline bool Foam::mappedPatchBase::upToDate() const
{ {
const polyMesh& thisMesh = patch_.boundaryMesh().mesh(); const polyMesh& thisMesh = patch_.boundaryMesh().mesh();
bool topoChange =
(sameWorld() && sampleMesh().topoChanging())
|| thisMesh.topoChanging();
if (topoChange) return
(sameWorld() && sampleMesh().upToDatePoints(updateSampleMeshTime()))
&& thisMesh.upToDatePoints(updateMeshTime());
}
inline const Foam::mapDistribute& Foam::mappedPatchBase::map() const
{
if (!upToDate())
{ {
mapPtr_.reset(nullptr); mapPtr_.reset(nullptr);
if (AMIPtr_)
{
AMIPtr_->upToDate() = false;
}
} }
if (!mapPtr_) if (!mapPtr_)
@ -222,12 +284,13 @@ inline const Foam::AMIPatchToPatchInterpolation& Foam::mappedPatchBase::AMI
bool forceUpdate bool forceUpdate
) const ) const
{ {
const polyMesh& thisMesh = patch_.boundaryMesh().mesh(); if (!upToDate())
bool topoChange = {
(sameWorld() && sampleMesh().topoChanging()) mapPtr_.reset(nullptr);
|| thisMesh.topoChanging(); AMIPtr_->upToDate() = false;
}
if (topoChange || forceUpdate) if (forceUpdate)
{ {
AMIPtr_->upToDate() = false; AMIPtr_->upToDate() = false;
} }