ENH: make some vectorTensorTransform methods inplace

- avoids intermediate allocation and re-assignment to self (#3374)

BUG: checkMesh (application) with questionable memory handling (#3374)

- move the contents of the new points instead of attempting to transfer
  the entire list

COMP: replace mapDistribute specializations with if constexpr handling

- simplify future maintenance
This commit is contained in:
Mark Olesen
2025-06-10 09:07:57 +02:00
parent a5090c37a3
commit a860d48637
12 changed files with 240 additions and 346 deletions

View File

@ -39,8 +39,7 @@ Foam::label Foam::findOppositeWedge
&& isA<wedgePolyPatch>(patches[patchi])
)
{
const wedgePolyPatch& pp =
refCast<const wedgePolyPatch>(patches[patchi]);
const auto& pp = refCast<const wedgePolyPatch>(patches[patchi]);
// Calculate (cos of) angle to wpp (not pp!) centre normal
scalar ppCosAngle = wpp.centreNormal() & pp.n();
@ -80,8 +79,7 @@ bool Foam::checkWedges
{
if (patches[patchi].size() && isA<wedgePolyPatch>(patches[patchi]))
{
const wedgePolyPatch& pp =
refCast<const wedgePolyPatch>(patches[patchi]);
const auto& pp = refCast<const wedgePolyPatch>(patches[patchi]);
scalar wedgeAngle = acos(pp.cosAngle());
@ -105,7 +103,7 @@ bool Foam::checkWedges
return true;
}
const wedgePolyPatch& opp =
const auto& opp =
refCast<const wedgePolyPatch>(patches[oppositePatchi]);
@ -275,25 +273,27 @@ namespace Foam
void operator()
(
const coupledPolyPatch& cpp,
List<pointField>& pts
UList<pointField>& pts
) const
{
// Each element of pts is all the points in the face. Convert into
// lists of size cpp to transform.
// Each element of pts is all the points in the face.
// Convert into lists of size cpp to transform.
List<pointField> newPts(pts.size());
forAll(pts, facei)
{
newPts[facei].setSize(pts[facei].size());
newPts[facei].resize(pts[facei].size());
}
pointField ptsAtIndex(pts.size());
label index = 0;
while (true)
{
label n = 0;
// Extract for every face the i'th position
pointField ptsAtIndex(pts.size(), Zero);
ptsAtIndex = Zero;
forAll(cpp, facei)
{
const pointField& facePts = pts[facei];
@ -326,7 +326,8 @@ namespace Foam
index++;
}
pts.transfer(newPts);
// Transfer newPts -> pts
std::move(newPts.begin(), newPts.end(), pts.begin());
}
};
}
@ -352,10 +353,7 @@ bool Foam::checkCoupledPoints
{
if (patches[patchi].coupled())
{
const coupledPolyPatch& cpp = refCast<const coupledPolyPatch>
(
patches[patchi]
);
const auto& cpp = refCast<const coupledPolyPatch>(patches[patchi]);
forAll(cpp, i)
{
@ -387,8 +385,7 @@ bool Foam::checkCoupledPoints
{
if (patches[patchi].coupled())
{
const coupledPolyPatch& cpp =
refCast<const coupledPolyPatch>(patches[patchi]);
const auto& cpp = refCast<const coupledPolyPatch>(patches[patchi]);
if (cpp.owner())
{
@ -1023,7 +1020,7 @@ Foam::label Foam::checkGeometry
{
if (isA<cyclicAMIPolyPatch>(pbm[patchi]))
{
const cyclicAMIPolyPatch& cpp =
const auto& cpp =
refCast<const cyclicAMIPolyPatch>(pbm[patchi]);
if (cpp.owner())
@ -1058,7 +1055,7 @@ Foam::label Foam::checkGeometry
if (isA<cyclicACMIPolyPatch>(pbm[patchi]))
{
const cyclicACMIPolyPatch& pp =
const auto& pp =
refCast<const cyclicACMIPolyPatch>(pbm[patchi]);
scalarField mergedMask;
@ -1108,8 +1105,9 @@ Foam::label Foam::checkGeometry
if (isA<cyclicACMIPolyPatch>(pbm[patchi]))
{
const cyclicACMIPolyPatch& pp =
const auto& pp =
refCast<const cyclicACMIPolyPatch>(pbm[patchi]);
scalarField mergedMask;
globalFaces().gather
(