mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: avoid list resizing when reindexing AMIInterpolation::append (#2933)
- create reindexing values as interleaved identity maps directly into the remapping lookup.
This commit is contained in:
@ -6,7 +6,7 @@
|
|||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2011-2017 OpenFOAM Foundation
|
Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||||
Copyright (C) 2015-2022 OpenCFD Ltd.
|
Copyright (C) 2015-2023 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -33,6 +33,7 @@ License
|
|||||||
#include "profiling.H"
|
#include "profiling.H"
|
||||||
#include "triangle.H"
|
#include "triangle.H"
|
||||||
#include "OFstream.H"
|
#include "OFstream.H"
|
||||||
|
#include <numeric> // For std::iota
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||||
|
|
||||||
@ -169,7 +170,7 @@ void Foam::AMIInterpolation::normaliseWeights
|
|||||||
addProfiling(ami, "AMIInterpolation::normaliseWeights");
|
addProfiling(ami, "AMIInterpolation::normaliseWeights");
|
||||||
|
|
||||||
// Normalise the weights
|
// Normalise the weights
|
||||||
wghtSum.setSize(wght.size(), 0.0);
|
wghtSum.resize_nocopy(wght.size());
|
||||||
label nLowWeight = 0;
|
label nLowWeight = 0;
|
||||||
|
|
||||||
forAll(wght, facei)
|
forAll(wght, facei)
|
||||||
@ -331,7 +332,7 @@ void Foam::AMIInterpolation::agglomerate
|
|||||||
const labelList& elemsMap =
|
const labelList& elemsMap =
|
||||||
map.constructMap()[Pstream::myProcNo()];
|
map.constructMap()[Pstream::myProcNo()];
|
||||||
labelList& newSubMap = tgtSubMap[proci];
|
labelList& newSubMap = tgtSubMap[proci];
|
||||||
newSubMap.setSize(elems.size());
|
newSubMap.resize_nocopy(elems.size());
|
||||||
|
|
||||||
labelList oldToNew(targetCoarseSize, -1);
|
labelList oldToNew(targetCoarseSize, -1);
|
||||||
label newi = 0;
|
label newi = 0;
|
||||||
@ -347,7 +348,7 @@ void Foam::AMIInterpolation::agglomerate
|
|||||||
++newi;
|
++newi;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
newSubMap.setSize(newi);
|
newSubMap.resize(newi);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -392,7 +393,7 @@ void Foam::AMIInterpolation::agglomerate
|
|||||||
const labelList& elems = map.constructMap()[proci];
|
const labelList& elems = map.constructMap()[proci];
|
||||||
|
|
||||||
labelList& newConstructMap = tgtConstructMap[proci];
|
labelList& newConstructMap = tgtConstructMap[proci];
|
||||||
newConstructMap.setSize(elems.size());
|
newConstructMap.resize_nocopy(elems.size());
|
||||||
|
|
||||||
if (elems.size())
|
if (elems.size())
|
||||||
{
|
{
|
||||||
@ -431,7 +432,7 @@ void Foam::AMIInterpolation::agglomerate
|
|||||||
tgtCompactMap[fineElem] = newConstructMap[compacti];
|
tgtCompactMap[fineElem] = newConstructMap[compacti];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
newConstructMap.setSize(newi);
|
newConstructMap.resize(newi);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -802,13 +803,13 @@ void Foam::AMIInterpolation::reset
|
|||||||
tgtWeights_.transfer(tgtWeights);
|
tgtWeights_.transfer(tgtWeights);
|
||||||
|
|
||||||
// Reset the sums of the weights
|
// Reset the sums of the weights
|
||||||
srcWeightsSum_.setSize(srcWeights_.size());
|
srcWeightsSum_.resize_nocopy(srcWeights_.size());
|
||||||
forAll(srcWeights_, facei)
|
forAll(srcWeights_, facei)
|
||||||
{
|
{
|
||||||
srcWeightsSum_[facei] = sum(srcWeights_[facei]);
|
srcWeightsSum_[facei] = sum(srcWeights_[facei]);
|
||||||
}
|
}
|
||||||
|
|
||||||
tgtWeightsSum_.setSize(tgtWeights_.size());
|
tgtWeightsSum_.resize_nocopy(tgtWeights_.size());
|
||||||
forAll(tgtWeights_, facei)
|
forAll(tgtWeights_, facei)
|
||||||
{
|
{
|
||||||
tgtWeightsSum_[facei] = sum(tgtWeights_[facei]);
|
tgtWeightsSum_[facei] = sum(tgtWeights_[facei]);
|
||||||
@ -848,121 +849,133 @@ void Foam::AMIInterpolation::append
|
|||||||
labelListList& newTgtSubMap = newPtr->tgtMapPtr_->subMap();
|
labelListList& newTgtSubMap = newPtr->tgtMapPtr_->subMap();
|
||||||
labelListList& newTgtConstructMap = newPtr->tgtMapPtr_->constructMap();
|
labelListList& newTgtConstructMap = newPtr->tgtMapPtr_->constructMap();
|
||||||
|
|
||||||
|
// Re-mapping/re-indexing - use max sizing
|
||||||
|
labelList oldMapMap
|
||||||
|
(
|
||||||
|
max
|
||||||
|
(
|
||||||
|
srcMapPtr_->constructMapTotalSize(),
|
||||||
|
tgtMapPtr_->constructMapTotalSize()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
labelList newMapMap
|
||||||
|
(
|
||||||
|
max
|
||||||
|
(
|
||||||
|
newPtr->srcMapPtr_->constructMapTotalSize(),
|
||||||
|
newPtr->tgtMapPtr_->constructMapTotalSize()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
// Re-calculate the source indices
|
// Re-calculate the source indices
|
||||||
{
|
{
|
||||||
labelList mapMap(0), newMapMap(0);
|
label total = 0;
|
||||||
forAll(srcSubMap, proci)
|
auto iter1 = oldMapMap.begin();
|
||||||
{
|
auto iter2 = newMapMap.begin();
|
||||||
mapMap.append
|
|
||||||
(
|
|
||||||
identity
|
|
||||||
(
|
|
||||||
srcConstructMap[proci].size(),
|
|
||||||
(mapMap.size() + newMapMap.size())
|
|
||||||
)
|
|
||||||
);
|
|
||||||
newMapMap.append
|
|
||||||
(
|
|
||||||
identity
|
|
||||||
(
|
|
||||||
newSrcConstructMap[proci].size(),
|
|
||||||
(mapMap.size() + newMapMap.size())
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
forAll(srcSubMap, proci)
|
forAll(srcSubMap, proci)
|
||||||
{
|
{
|
||||||
forAll(srcConstructMap[proci], srci)
|
const label len1 = srcConstructMap[proci].size();
|
||||||
|
const label len2 = newSrcConstructMap[proci].size();
|
||||||
|
|
||||||
|
std::iota(iter1, (iter1 + len1), total);
|
||||||
|
iter1 += len1;
|
||||||
|
total += len1;
|
||||||
|
|
||||||
|
std::iota(iter2, (iter2 + len2), total);
|
||||||
|
iter2 += len2;
|
||||||
|
total += len2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Renumber the source indices
|
||||||
|
{
|
||||||
|
for (labelList& list : srcConstructMap)
|
||||||
|
{
|
||||||
|
for (label& value : list)
|
||||||
{
|
{
|
||||||
srcConstructMap[proci][srci] =
|
value = oldMapMap[value];
|
||||||
mapMap[srcConstructMap[proci][srci]];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
forAll(srcSubMap, proci)
|
for (labelList& list : newSrcConstructMap)
|
||||||
{
|
{
|
||||||
forAll(newSrcConstructMap[proci], srci)
|
for (label& value : list)
|
||||||
{
|
{
|
||||||
newSrcConstructMap[proci][srci] =
|
value = newMapMap[value];
|
||||||
newMapMap[newSrcConstructMap[proci][srci]];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
forAll(tgtAddress_, tgti)
|
for (labelList& list : tgtAddress_)
|
||||||
{
|
{
|
||||||
forAll(tgtAddress_[tgti], tgtj)
|
for (label& value : list)
|
||||||
{
|
{
|
||||||
tgtAddress_[tgti][tgtj] = mapMap[tgtAddress_[tgti][tgtj]];
|
value = oldMapMap[value];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
forAll(newPtr->tgtAddress_, tgti)
|
for (labelList& list : newPtr->tgtAddress_)
|
||||||
{
|
{
|
||||||
forAll(newPtr->tgtAddress_[tgti], tgtj)
|
for (label& value : list)
|
||||||
{
|
{
|
||||||
newPtr->tgtAddress_[tgti][tgtj] =
|
value = newMapMap[value];
|
||||||
newMapMap[newPtr->tgtAddress_[tgti][tgtj]];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Re-calculate the target indices
|
// Re-calculate the target indices
|
||||||
{
|
{
|
||||||
labelList mapMap(0), newMapMap(0);
|
label total = 0;
|
||||||
forAll(srcSubMap, proci)
|
auto iter1 = oldMapMap.begin();
|
||||||
{
|
auto iter2 = newMapMap.begin();
|
||||||
mapMap.append
|
|
||||||
(
|
|
||||||
identity
|
|
||||||
(
|
|
||||||
tgtConstructMap[proci].size(),
|
|
||||||
(mapMap.size() + newMapMap.size())
|
|
||||||
)
|
|
||||||
);
|
|
||||||
newMapMap.append
|
|
||||||
(
|
|
||||||
identity
|
|
||||||
(
|
|
||||||
newTgtConstructMap[proci].size(),
|
|
||||||
(mapMap.size() + newMapMap.size())
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
forAll(srcSubMap, proci)
|
forAll(srcSubMap, proci)
|
||||||
{
|
{
|
||||||
forAll(tgtConstructMap[proci], tgti)
|
const label len1 = tgtConstructMap[proci].size();
|
||||||
|
const label len2 = newTgtConstructMap[proci].size();
|
||||||
|
|
||||||
|
std::iota(iter1, (iter1 + len1), total);
|
||||||
|
iter1 += len1;
|
||||||
|
total += len1;
|
||||||
|
|
||||||
|
std::iota(iter2, (iter2 + len2), total);
|
||||||
|
iter2 += len2;
|
||||||
|
total += len2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Renumber the target indices
|
||||||
|
{
|
||||||
|
for (labelList& list : tgtConstructMap)
|
||||||
|
{
|
||||||
|
for (label& value : list)
|
||||||
{
|
{
|
||||||
tgtConstructMap[proci][tgti] =
|
value = oldMapMap[value];
|
||||||
mapMap[tgtConstructMap[proci][tgti]];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
forAll(srcSubMap, proci)
|
for (labelList& list : newTgtConstructMap)
|
||||||
{
|
{
|
||||||
forAll(newTgtConstructMap[proci], tgti)
|
for (label& value : list)
|
||||||
{
|
{
|
||||||
newTgtConstructMap[proci][tgti] =
|
value = newMapMap[value];
|
||||||
newMapMap[newTgtConstructMap[proci][tgti]];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
forAll(srcAddress_, srci)
|
for (labelList& list : srcAddress_)
|
||||||
{
|
{
|
||||||
forAll(srcAddress_[srci], srcj)
|
for (label& value : list)
|
||||||
{
|
{
|
||||||
srcAddress_[srci][srcj] =
|
value = oldMapMap[value];
|
||||||
mapMap[srcAddress_[srci][srcj]];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
forAll(newPtr->srcAddress_, srci)
|
for (labelList& list : newPtr->srcAddress_)
|
||||||
{
|
{
|
||||||
forAll(newPtr->srcAddress_[srci], srcj)
|
for (label& value : list)
|
||||||
{
|
{
|
||||||
newPtr->srcAddress_[srci][srcj] =
|
value = newMapMap[value];
|
||||||
newMapMap[newPtr->srcAddress_[srci][srcj]];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -974,27 +987,27 @@ void Foam::AMIInterpolation::append
|
|||||||
// Combine the maps
|
// Combine the maps
|
||||||
forAll(srcSubMap, proci)
|
forAll(srcSubMap, proci)
|
||||||
{
|
{
|
||||||
srcSubMap[proci].append(newSrcSubMap[proci]);
|
srcSubMap[proci].push_back(newSrcSubMap[proci]);
|
||||||
srcConstructMap[proci].append(newSrcConstructMap[proci]);
|
srcConstructMap[proci].push_back(newSrcConstructMap[proci]);
|
||||||
|
|
||||||
tgtSubMap[proci].append(newTgtSubMap[proci]);
|
tgtSubMap[proci].push_back(newTgtSubMap[proci]);
|
||||||
tgtConstructMap[proci].append(newTgtConstructMap[proci]);
|
tgtConstructMap[proci].push_back(newTgtConstructMap[proci]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Combine new and current source data
|
// Combine new and current source data
|
||||||
forAll(srcMagSf_, srcFacei)
|
forAll(srcMagSf_, srcFacei)
|
||||||
{
|
{
|
||||||
srcAddress_[srcFacei].append(newPtr->srcAddress()[srcFacei]);
|
srcAddress_[srcFacei].push_back(newPtr->srcAddress()[srcFacei]);
|
||||||
srcWeights_[srcFacei].append(newPtr->srcWeights()[srcFacei]);
|
srcWeights_[srcFacei].push_back(newPtr->srcWeights()[srcFacei]);
|
||||||
srcWeightsSum_[srcFacei] += newPtr->srcWeightsSum()[srcFacei];
|
srcWeightsSum_[srcFacei] += newPtr->srcWeightsSum()[srcFacei];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Combine new and current target data
|
// Combine new and current target data
|
||||||
forAll(tgtMagSf_, tgtFacei)
|
forAll(tgtMagSf_, tgtFacei)
|
||||||
{
|
{
|
||||||
tgtAddress_[tgtFacei].append(newPtr->tgtAddress()[tgtFacei]);
|
tgtAddress_[tgtFacei].push_back(newPtr->tgtAddress()[tgtFacei]);
|
||||||
tgtWeights_[tgtFacei].append(newPtr->tgtWeights()[tgtFacei]);
|
tgtWeights_[tgtFacei].push_back(newPtr->tgtWeights()[tgtFacei]);
|
||||||
tgtWeightsSum_[tgtFacei] += newPtr->tgtWeightsSum()[tgtFacei];
|
tgtWeightsSum_[tgtFacei] += newPtr->tgtWeightsSum()[tgtFacei];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -42,9 +42,10 @@ Description
|
|||||||
reverse the orientation of the target patch.
|
reverse the orientation of the target patch.
|
||||||
|
|
||||||
SourceFiles
|
SourceFiles
|
||||||
|
AMIInterpolationI.H
|
||||||
AMIInterpolation.C
|
AMIInterpolation.C
|
||||||
AMIInterpolationName.C
|
AMIInterpolationNew.C
|
||||||
AMIInterpolationParallelOps.C
|
AMIInterpolationTemplates.C
|
||||||
|
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user