ENH: improve memory allocations for explicit connections (issue #805)

STYLE: change access methods names in mesh wave algorithms

- nUnvisitedCells(), nUnvisitedFaces() etc instead of
  getUnsetCells(), getUnsetFaces()

- simplify some coding with range-for
This commit is contained in:
Mark Olesen
2018-04-23 10:37:24 +02:00
parent 857eed5b51
commit 591a1a0c68
9 changed files with 317 additions and 332 deletions

View File

@ -259,9 +259,9 @@ void Foam::medialAxisMeshMover::update(const dictionary& coeffDict)
);
wallDistCalc.iterate(nMedialAxisIter);
label nUnvisit = returnReduce
const label nUnvisit = returnReduce
(
wallDistCalc.getUnsetPoints(),
wallDistCalc.nUnvisitedPoints(),
sumOp<label>()
);

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -122,11 +122,11 @@ bool Foam::FaceCellWave<Type, TrackingData>::updateCell
// - changedCell_, changedCells_
// - statistics: nEvals_, nUnvisitedCells_
nEvals_++;
++nEvals_;
bool wasValid = cellInfo.valid(td_);
const bool wasValid = cellInfo.valid(td_);
bool propagate =
const bool propagate =
cellInfo.updateCell
(
mesh_,
@ -139,9 +139,8 @@ bool Foam::FaceCellWave<Type, TrackingData>::updateCell
if (propagate)
{
if (!changedCell_[celli])
if (changedCell_.set(celli))
{
changedCell_.set(celli);
changedCells_.append(celli);
}
}
@ -171,11 +170,11 @@ bool Foam::FaceCellWave<Type, TrackingData>::updateFace
// - changedFace_, changedFaces_,
// - statistics: nEvals_, nUnvisitedFaces_
nEvals_++;
++nEvals_;
bool wasValid = faceInfo.valid(td_);
const bool wasValid = faceInfo.valid(td_);
bool propagate =
const bool propagate =
faceInfo.updateFace
(
mesh_,
@ -218,11 +217,11 @@ bool Foam::FaceCellWave<Type, TrackingData>::updateFace
// - changedFace_, changedFaces_,
// - statistics: nEvals_, nUnvisitedFaces_
nEvals_++;
++nEvals_;
bool wasValid = faceInfo.valid(td_);
const bool wasValid = faceInfo.valid(td_);
bool propagate =
const bool propagate =
faceInfo.updateFace
(
mesh_,
@ -262,8 +261,8 @@ void Foam::FaceCellWave<Type, TrackingData>::checkCyclic
forAll(patch, patchFacei)
{
label i1 = patch.start() + patchFacei;
label i2 = nbrPatch.start() + patchFacei;
const label i1 = patch.start() + patchFacei;
const label i2 = nbrPatch.start() + patchFacei;
if
(
@ -299,9 +298,9 @@ template<class Type, class TrackingData>
template<class PatchType>
bool Foam::FaceCellWave<Type, TrackingData>::hasPatch() const
{
forAll(mesh_.boundaryMesh(), patchi)
for (const polyPatch& p : mesh_.boundaryMesh())
{
if (isA<PatchType>(mesh_.boundaryMesh()[patchi]))
if (isA<PatchType>(p))
{
return true;
}
@ -313,15 +312,39 @@ bool Foam::FaceCellWave<Type, TrackingData>::hasPatch() const
template<class Type, class TrackingData>
void Foam::FaceCellWave<Type, TrackingData>::setFaceInfo
(
const labelList& changedFaces,
const label facei,
const Type& faceInfo
)
{
const bool wasValid = allFaceInfo_[facei].valid(td_);
// Copy info for facei
allFaceInfo_[facei] = faceInfo;
// Maintain count of unset faces
if (!wasValid && allFaceInfo_[facei].valid(td_))
{
--nUnvisitedFaces_;
}
// Mark facei as visited and changed (both on list and on face itself)
changedFace_.set(facei);
changedFaces_.append(facei);
}
template<class Type, class TrackingData>
void Foam::FaceCellWave<Type, TrackingData>::setFaceInfo
(
const labelUList& changedFaces,
const List<Type>& changedFacesInfo
)
{
forAll(changedFaces, changedFacei)
{
label facei = changedFaces[changedFacei];
const label facei = changedFaces[changedFacei];
bool wasValid = allFaceInfo_[facei].valid(td_);
const bool wasValid = allFaceInfo_[facei].valid(td_);
// Copy info for facei
allFaceInfo_[facei] = changedFacesInfo[changedFacei];
@ -333,7 +356,6 @@ void Foam::FaceCellWave<Type, TrackingData>::setFaceInfo
}
// Mark facei as changed, both on list and on face itself.
changedFace_.set(facei);
changedFaces_.append(facei);
}
@ -345,29 +367,29 @@ void Foam::FaceCellWave<Type, TrackingData>::mergeFaceInfo
(
const polyPatch& patch,
const label nFaces,
const labelList& changedFaces,
const labelUList& changedFaces,
const List<Type>& changedFacesInfo
)
{
// Merge face information into member data
for (label changedFacei = 0; changedFacei < nFaces; changedFacei++)
for (label changedFacei = 0; changedFacei < nFaces; ++changedFacei)
{
const Type& neighbourWallInfo = changedFacesInfo[changedFacei];
label patchFacei = changedFaces[changedFacei];
const Type& newInfo = changedFacesInfo[changedFacei];
const label patchFacei = changedFaces[changedFacei];
label meshFacei = patch.start() + patchFacei;
const label meshFacei = patch.start() + patchFacei;
Type& currentWallInfo = allFaceInfo_[meshFacei];
Type& currInfo = allFaceInfo_[meshFacei];
if (!currentWallInfo.equal(neighbourWallInfo, td_))
if (!currInfo.equal(newInfo, td_))
{
updateFace
(
meshFacei,
neighbourWallInfo,
newInfo,
propagationTol_,
currentWallInfo
currInfo
);
}
}
@ -387,22 +409,22 @@ Foam::label Foam::FaceCellWave<Type, TrackingData>::getChangedPatchFaces
// Construct compact patchFace change arrays for a (slice of a) single
// patch. changedPatchFaces in local patch numbering.
// Return length of arrays.
label nChangedPatchFaces = 0;
label nChanged = 0;
for (label i = 0; i < nFaces; i++)
for (label i = 0; i < nFaces; ++i)
{
label patchFacei = i + startFacei;
label meshFacei = patch.start() + patchFacei;
const label patchFacei = i + startFacei;
const label meshFacei = patch.start() + patchFacei;
if (changedFace_.test(meshFacei))
{
changedPatchFaces[nChangedPatchFaces] = patchFacei;
changedPatchFacesInfo[nChangedPatchFaces] = allFaceInfo_[meshFacei];
nChangedPatchFaces++;
changedPatchFaces[nChanged] = patchFacei;
changedPatchFacesInfo[nChanged] = allFaceInfo_[meshFacei];
++nChanged;
}
}
return nChangedPatchFaces;
return nChanged;
}
@ -411,7 +433,7 @@ void Foam::FaceCellWave<Type, TrackingData>::leaveDomain
(
const polyPatch& patch,
const label nFaces,
const labelList& faceLabels,
const labelUList& faceLabels,
List<Type>& faceInfo
) const
{
@ -419,11 +441,11 @@ void Foam::FaceCellWave<Type, TrackingData>::leaveDomain
const vectorField& fc = mesh_.faceCentres();
for (label i = 0; i < nFaces; i++)
for (label i = 0; i < nFaces; ++i)
{
label patchFacei = faceLabels[i];
const label patchFacei = faceLabels[i];
const label meshFacei = patch.start() + patchFacei;
label meshFacei = patch.start() + patchFacei;
faceInfo[i].leaveDomain(mesh_, patch, patchFacei, fc[meshFacei], td_);
}
}
@ -434,7 +456,7 @@ void Foam::FaceCellWave<Type, TrackingData>::enterDomain
(
const polyPatch& patch,
const label nFaces,
const labelList& faceLabels,
const labelUList& faceLabels,
List<Type>& faceInfo
) const
{
@ -442,11 +464,11 @@ void Foam::FaceCellWave<Type, TrackingData>::enterDomain
const vectorField& fc = mesh_.faceCentres();
for (label i = 0; i < nFaces; i++)
for (label i = 0; i < nFaces; ++i)
{
label patchFacei = faceLabels[i];
const label patchFacei = faceLabels[i];
const label meshFacei = patch.start() + patchFacei;
label meshFacei = patch.start() + patchFacei;
faceInfo[i].enterDomain(mesh_, patch, patchFacei, fc[meshFacei], td_);
}
}
@ -466,14 +488,14 @@ void Foam::FaceCellWave<Type, TrackingData>::transform
{
const tensor& T = rotTensor[0];
for (label facei = 0; facei < nFaces; facei++)
for (label facei = 0; facei < nFaces; ++facei)
{
faceInfo[facei].transform(mesh_, T, td_);
}
}
else
{
for (label facei = 0; facei < nFaces; facei++)
for (label facei = 0; facei < nFaces; ++facei)
{
faceInfo[facei].transform(mesh_, rotTensor[facei], td_);
}
@ -490,10 +512,10 @@ void Foam::FaceCellWave<Type, TrackingData>::offset
labelList& faces
)
{
// Offset mesh face. Used for transferring from one cyclic half to the
// other.
// Offset mesh face.
// Used for transferring from one cyclic half to the other.
for (label facei = 0; facei < nFaces; facei++)
for (label facei = 0; facei < nFaces; ++facei)
{
faces[facei] += cycOffset;
}
@ -514,10 +536,8 @@ void Foam::FaceCellWave<Type, TrackingData>::handleProcPatches()
PstreamBuffers pBufs(Pstream::commsTypes::nonBlocking);
forAll(procPatches, i)
for (const label patchi : procPatches)
{
label patchi = procPatches[i];
const processorPolyPatch& procPatch =
refCast<const processorPolyPatch>(mesh_.boundaryMesh()[patchi]);
@ -564,10 +584,8 @@ void Foam::FaceCellWave<Type, TrackingData>::handleProcPatches()
// Receive all
forAll(procPatches, i)
for (const label patchi : procPatches)
{
label patchi = procPatches[i];
const processorPolyPatch& procPatch =
refCast<const processorPolyPatch>(mesh_.boundaryMesh()[patchi]);
@ -625,14 +643,14 @@ void Foam::FaceCellWave<Type, TrackingData>::handleCyclicPatches()
{
// Transfer information across cyclic halves.
forAll(mesh_.boundaryMesh(), patchi)
for (const polyPatch& patch : mesh_.boundaryMesh())
{
const polyPatch& patch = mesh_.boundaryMesh()[patchi];
if (isA<cyclicPolyPatch>(patch))
{
const cyclicPolyPatch& nbrPatch =
refCast<const cyclicPolyPatch>(patch).neighbPatch();
const cyclicPolyPatch& cycPatch =
refCast<const cyclicPolyPatch>(patch);
const cyclicPolyPatch& nbrPatch = cycPatch.neighbPatch();
// Allocate buffers
label nReceiveFaces;
@ -658,12 +676,9 @@ void Foam::FaceCellWave<Type, TrackingData>::handleCyclicPatches()
receiveFacesInfo
);
const cyclicPolyPatch& cycPatch =
refCast<const cyclicPolyPatch>(patch);
if (!cycPatch.parallel())
{
// received data from other half
// Received data from other half
transform
(
cycPatch.forwardT(),
@ -674,7 +689,8 @@ void Foam::FaceCellWave<Type, TrackingData>::handleCyclicPatches()
if (debug & 2)
{
Pout<< " Cyclic patch " << patchi << ' ' << cycPatch.name()
Pout<< " Cyclic patch "
<< cycPatch.index() << ' ' << cycPatch.name()
<< " Changed : " << nReceiveFaces
<< endl;
}
@ -711,21 +727,18 @@ void Foam::FaceCellWave<Type, TrackingData>::handleAMICyclicPatches()
{
// Transfer information across cyclicAMI halves.
forAll(mesh_.boundaryMesh(), patchi)
for (const polyPatch& patch : mesh_.boundaryMesh())
{
const polyPatch& patch = mesh_.boundaryMesh()[patchi];
if (isA<cyclicAMIPolyPatch>(patch))
{
const cyclicAMIPolyPatch& cycPatch =
refCast<const cyclicAMIPolyPatch>(patch);
const cyclicAMIPolyPatch& nbrPatch = cycPatch.neighbPatch();
List<Type> receiveInfo;
{
const cyclicAMIPolyPatch& nbrPatch =
refCast<const cyclicAMIPolyPatch>(patch).neighbPatch();
// Get nbrPatch data (so not just changed faces)
typename List<Type>::subList sendInfo
(
@ -787,22 +800,20 @@ void Foam::FaceCellWave<Type, TrackingData>::handleAMICyclicPatches()
// Merge into global storage
forAll(receiveInfo, i)
{
label meshFacei = cycPatch.start()+i;
const label meshFacei = cycPatch.start()+i;
Type& currentWallInfo = allFaceInfo_[meshFacei];
const Type& newInfo = receiveInfo[i];
if
(
receiveInfo[i].valid(td_)
&& !currentWallInfo.equal(receiveInfo[i], td_)
)
Type& currInfo = allFaceInfo_[meshFacei];
if (newInfo.valid(td_) && !currInfo.equal(newInfo, td_))
{
updateFace
(
meshFacei,
receiveInfo[i],
newInfo,
propagationTol_,
currentWallInfo
currInfo
);
}
}
@ -814,73 +825,50 @@ void Foam::FaceCellWave<Type, TrackingData>::handleAMICyclicPatches()
template<class Type, class TrackingData>
void Foam::FaceCellWave<Type, TrackingData>::handleExplicitConnections()
{
// Collect changed information
changedBaffles_.clear();
DynamicList<label> f0Baffle(explicitConnections_.size());
DynamicList<Type> f0Info(explicitConnections_.size());
DynamicList<label> f1Baffle(explicitConnections_.size());
DynamicList<Type> f1Info(explicitConnections_.size());
forAll(explicitConnections_, connI)
// Collect all/any changed information touching a baffle
for (const labelPair& baffle : explicitConnections_)
{
const labelPair& baffle = explicitConnections_[connI];
const label f0 = baffle.first();
const label f1 = baffle.second();
label f0 = baffle[0];
if (changedFace_.test(f0))
{
f0Baffle.append(connI);
f0Info.append(allFaceInfo_[f0]);
// f0 changed. Update information on f1.
changedBaffles_.append(taggedInfoType(f1, allFaceInfo_[f0]));
}
label f1 = baffle[1];
if (changedFace_.test(f1))
{
f1Baffle.append(connI);
f1Info.append(allFaceInfo_[f1]);
// f1 changed. Update information on f0.
changedBaffles_.append(taggedInfoType(f0, allFaceInfo_[f1]));
}
}
// Update other side with changed information
forAll(f1Info, index)
for (const taggedInfoType& updated : changedBaffles_)
{
const labelPair& baffle = explicitConnections_[f1Baffle[index]];
const label tgtFace = updated.first;
const Type& newInfo = updated.second;
label f0 = baffle[0];
Type& currentWallInfo = allFaceInfo_[f0];
Type& currInfo = allFaceInfo_[tgtFace];
if (!currentWallInfo.equal(f1Info[index], td_))
if (!currInfo.equal(newInfo, td_))
{
updateFace
(
f0,
f1Info[index],
tgtFace,
newInfo,
propagationTol_,
currentWallInfo
currInfo
);
}
}
forAll(f0Info, index)
{
const labelPair& baffle = explicitConnections_[f0Baffle[index]];
label f1 = baffle[1];
Type& currentWallInfo = allFaceInfo_[f1];
if (!currentWallInfo.equal(f0Info[index], td_))
{
updateFace
(
f1,
f0Info[index],
propagationTol_,
currentWallInfo
);
}
}
changedBaffles_.clear();
}
@ -896,14 +884,15 @@ Foam::FaceCellWave<Type, TrackingData>::FaceCellWave
)
:
mesh_(mesh),
explicitConnections_(0),
explicitConnections_(),
allFaceInfo_(allFaceInfo),
allCellInfo_(allCellInfo),
td_(td),
changedFace_(mesh_.nFaces(), false),
changedFaces_(mesh_.nFaces()),
changedCell_(mesh_.nCells(), false),
changedFaces_(mesh_.nFaces()),
changedCells_(mesh_.nCells()),
changedBaffles_(2*explicitConnections_.size()),
hasCyclicPatches_(hasPatch<cyclicPolyPatch>()),
hasCyclicAMIPatches_
(
@ -920,12 +909,11 @@ Foam::FaceCellWave<Type, TrackingData>::FaceCellWave
)
{
FatalErrorInFunction
<< "face and cell storage not the size of mesh faces, cells:"
<< endl
<< " allFaceInfo :" << allFaceInfo.size() << endl
<< " mesh_.nFaces():" << mesh_.nFaces() << endl
<< " allCellInfo :" << allCellInfo.size() << endl
<< " mesh_.nCells():" << mesh_.nCells()
<< "face and cell storage not the size of mesh faces, cells:" << nl
<< " allFaceInfo :" << allFaceInfo.size() << nl
<< " mesh_.nFaces():" << mesh_.nFaces() << nl
<< " allCellInfo :" << allCellInfo.size() << nl
<< " mesh_.nCells():" << mesh_.nCells() << endl
<< exit(FatalError);
}
}
@ -935,7 +923,7 @@ template<class Type, class TrackingData>
Foam::FaceCellWave<Type, TrackingData>::FaceCellWave
(
const polyMesh& mesh,
const labelList& changedFaces,
const labelUList& changedFaces,
const List<Type>& changedFacesInfo,
UList<Type>& allFaceInfo,
UList<Type>& allCellInfo,
@ -944,14 +932,15 @@ Foam::FaceCellWave<Type, TrackingData>::FaceCellWave
)
:
mesh_(mesh),
explicitConnections_(0),
explicitConnections_(),
allFaceInfo_(allFaceInfo),
allCellInfo_(allCellInfo),
td_(td),
changedFace_(mesh_.nFaces(), false),
changedFaces_(mesh_.nFaces()),
changedCell_(mesh_.nCells(), false),
changedFaces_(mesh_.nFaces()),
changedCells_(mesh_.nCells()),
changedBaffles_(2*explicitConnections_.size()),
hasCyclicPatches_(hasPatch<cyclicPolyPatch>()),
hasCyclicAMIPatches_
(
@ -968,12 +957,11 @@ Foam::FaceCellWave<Type, TrackingData>::FaceCellWave
)
{
FatalErrorInFunction
<< "face and cell storage not the size of mesh faces, cells:"
<< endl
<< " allFaceInfo :" << allFaceInfo.size() << endl
<< " mesh_.nFaces():" << mesh_.nFaces() << endl
<< " allCellInfo :" << allCellInfo.size() << endl
<< " mesh_.nCells():" << mesh_.nCells()
<< "face and cell storage not the size of mesh faces, cells:" << nl
<< " allFaceInfo :" << allFaceInfo.size() << nl
<< " mesh_.nFaces():" << mesh_.nFaces() << nl
<< " allCellInfo :" << allCellInfo.size() << nl
<< " mesh_.nCells():" << mesh_.nCells() << endl
<< exit(FatalError);
}
@ -981,14 +969,14 @@ Foam::FaceCellWave<Type, TrackingData>::FaceCellWave
setFaceInfo(changedFaces, changedFacesInfo);
// Iterate until nothing changes
label iter = iterate(maxIter);
const label iter = iterate(maxIter);
if ((maxIter > 0) && (iter >= maxIter))
{
FatalErrorInFunction
<< "Maximum number of iterations reached. Increase maxIter." << endl
<< " maxIter:" << maxIter << endl
<< " nChangedCells:" << changedCells_.size() << endl
<< "Maximum number of iterations reached. Increase maxIter." << nl
<< " maxIter:" << maxIter << nl
<< " nChangedCells:" << changedCells_.size() << nl
<< " nChangedFaces:" << changedFaces_.size() << endl
<< exit(FatalError);
}
@ -1001,7 +989,7 @@ Foam::FaceCellWave<Type, TrackingData>::FaceCellWave
const polyMesh& mesh,
const labelPairList& explicitConnections,
const bool handleCyclicAMI,
const labelList& changedFaces,
const labelUList& changedFaces,
const List<Type>& changedFacesInfo,
UList<Type>& allFaceInfo,
UList<Type>& allCellInfo,
@ -1015,9 +1003,10 @@ Foam::FaceCellWave<Type, TrackingData>::FaceCellWave
allCellInfo_(allCellInfo),
td_(td),
changedFace_(mesh_.nFaces(), false),
changedFaces_(mesh_.nFaces()),
changedCell_(mesh_.nCells(), false),
changedFaces_(mesh_.nFaces()),
changedCells_(mesh_.nCells()),
changedBaffles_(2*explicitConnections_.size()),
hasCyclicPatches_(hasPatch<cyclicPolyPatch>()),
hasCyclicAMIPatches_
(
@ -1035,12 +1024,11 @@ Foam::FaceCellWave<Type, TrackingData>::FaceCellWave
)
{
FatalErrorInFunction
<< "face and cell storage not the size of mesh faces, cells:"
<< endl
<< " allFaceInfo :" << allFaceInfo.size() << endl
<< " mesh_.nFaces():" << mesh_.nFaces() << endl
<< " allCellInfo :" << allCellInfo.size() << endl
<< " mesh_.nCells():" << mesh_.nCells()
<< "face and cell storage not the size of mesh faces, cells:" << nl
<< " allFaceInfo :" << allFaceInfo.size() << nl
<< " mesh_.nFaces():" << mesh_.nFaces() << nl
<< " allCellInfo :" << allCellInfo.size() << nl
<< " mesh_.nCells():" << mesh_.nCells() << endl
<< exit(FatalError);
}
@ -1048,14 +1036,14 @@ Foam::FaceCellWave<Type, TrackingData>::FaceCellWave
setFaceInfo(changedFaces, changedFacesInfo);
// Iterate until nothing changes
label iter = iterate(maxIter);
const label iter = iterate(maxIter);
if ((maxIter > 0) && (iter >= maxIter))
{
FatalErrorInFunction
<< "Maximum number of iterations reached. Increase maxIter." << endl
<< " maxIter:" << maxIter << endl
<< " nChangedCells:" << changedCells_.size() << endl
<< "Maximum number of iterations reached. Increase maxIter." << nl
<< " maxIter:" << maxIter << nl
<< " nChangedCells:" << changedCells_.size() << nl
<< " nChangedFaces:" << changedFaces_.size() << endl
<< exit(FatalError);
}
@ -1065,14 +1053,14 @@ Foam::FaceCellWave<Type, TrackingData>::FaceCellWave
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type, class TrackingData>
Foam::label Foam::FaceCellWave<Type, TrackingData>::getUnsetCells() const
Foam::label Foam::FaceCellWave<Type, TrackingData>::nUnvisitedCells() const
{
return nUnvisitedCells_;
}
template<class Type, class TrackingData>
Foam::label Foam::FaceCellWave<Type, TrackingData>::getUnsetFaces() const
Foam::label Foam::FaceCellWave<Type, TrackingData>::nUnvisitedFaces() const
{
return nUnvisitedFaces_;
}
@ -1085,11 +1073,10 @@ Foam::label Foam::FaceCellWave<Type, TrackingData>::faceToCell()
const labelList& owner = mesh_.faceOwner();
const labelList& neighbour = mesh_.faceNeighbour();
label nInternalFaces = mesh_.nInternalFaces();
const label nInternalFaces = mesh_.nInternalFaces();
forAll(changedFaces_, changedFacei)
for (const label facei : changedFaces_)
{
label facei = changedFaces_[changedFacei];
if (!changedFace_.test(facei))
{
FatalErrorInFunction
@ -1098,42 +1085,43 @@ Foam::label Foam::FaceCellWave<Type, TrackingData>::faceToCell()
<< abort(FatalError);
}
const Type& neighbourWallInfo = allFaceInfo_[facei];
const Type& newInfo = allFaceInfo_[facei];
// Evaluate all connected cells
// Owner
label celli = owner[facei];
Type& currentWallInfo = allCellInfo_[celli];
{
const label celli = owner[facei];
Type& currInfo = allCellInfo_[celli];
if (!currentWallInfo.equal(neighbourWallInfo, td_))
if (!currInfo.equal(newInfo, td_))
{
updateCell
(
celli,
facei,
neighbourWallInfo,
newInfo,
propagationTol_,
currentWallInfo
currInfo
);
}
}
// Neighbour.
if (facei < nInternalFaces)
{
celli = neighbour[facei];
Type& currentWallInfo2 = allCellInfo_[celli];
const label celli = neighbour[facei];
Type& currInfo = allCellInfo_[celli];
if (!currentWallInfo2.equal(neighbourWallInfo, td_))
if (!currInfo.equal(newInfo, td_))
{
updateCell
(
celli,
facei,
neighbourWallInfo,
newInfo,
propagationTol_,
currentWallInfo2
currInfo
);
}
}
@ -1150,12 +1138,8 @@ Foam::label Foam::FaceCellWave<Type, TrackingData>::faceToCell()
Pout<< " Changed cells : " << changedCells_.size() << endl;
}
// Sum changedCells over all procs
label totNChanged = changedCells_.size();
reduce(totNChanged, sumOp<label>());
return totNChanged;
// Number of changedCells over all procs
return returnReduce(changedCells_.size(), sumOp<label>());
}
@ -1166,35 +1150,33 @@ Foam::label Foam::FaceCellWave<Type, TrackingData>::cellToFace()
const cellList& cells = mesh_.cells();
forAll(changedCells_, changedCelli)
for (const label celli : changedCells_)
{
label celli = changedCells_[changedCelli];
if (!changedCell_[celli])
if (!changedCell_.test(celli))
{
FatalErrorInFunction
<< "Cell " << celli << " not marked as having been changed"
<< abort(FatalError);
}
const Type& neighbourWallInfo = allCellInfo_[celli];
const Type& newInfo = allCellInfo_[celli];
// Evaluate all connected faces
const labelList& faceLabels = cells[celli];
forAll(faceLabels, faceLabelI)
for (const label facei : faceLabels)
{
label facei = faceLabels[faceLabelI];
Type& currentWallInfo = allFaceInfo_[facei];
Type& currInfo = allFaceInfo_[facei];
if (!currentWallInfo.equal(neighbourWallInfo, td_))
if (!currInfo.equal(newInfo, td_))
{
updateFace
(
facei,
celli,
neighbourWallInfo,
newInfo,
propagationTol_,
currentWallInfo
currInfo
);
}
}
@ -1212,7 +1194,6 @@ Foam::label Foam::FaceCellWave<Type, TrackingData>::cellToFace()
if (hasCyclicPatches_)
{
// Transfer changed faces across cyclic halves
handleCyclicPatches();
}
@ -1223,7 +1204,6 @@ Foam::label Foam::FaceCellWave<Type, TrackingData>::cellToFace()
if (Pstream::parRun())
{
// Transfer changed faces from neighbouring processors.
handleProcPatches();
}
@ -1232,12 +1212,9 @@ Foam::label Foam::FaceCellWave<Type, TrackingData>::cellToFace()
Pout<< " Changed faces : " << changedFaces_.size() << endl;
}
// Sum nChangedFaces over all procs
label totNChanged = changedFaces_.size();
reduce(totNChanged, sumOp<label>());
return totNChanged;
// Number of changedFaces over all procs
return returnReduce(changedFaces_.size(), sumOp<label>());
}
@ -1245,9 +1222,13 @@ Foam::label Foam::FaceCellWave<Type, TrackingData>::cellToFace()
template<class Type, class TrackingData>
Foam::label Foam::FaceCellWave<Type, TrackingData>::iterate(const label maxIter)
{
if (maxIter < 0)
{
return 0;
}
if (hasCyclicPatches_)
{
// Transfer changed faces across cyclic halves
handleCyclicPatches();
}
@ -1258,13 +1239,12 @@ Foam::label Foam::FaceCellWave<Type, TrackingData>::iterate(const label maxIter)
if (Pstream::parRun())
{
// Transfer changed faces from neighbouring processors.
handleProcPatches();
}
label iter = 0;
while (iter < maxIter)
for (/*nil*/; iter < maxIter; ++iter)
{
if (debug)
{
@ -1272,35 +1252,23 @@ Foam::label Foam::FaceCellWave<Type, TrackingData>::iterate(const label maxIter)
}
nEvals_ = 0;
label nCells = faceToCell();
const label nCells = faceToCell();
const label nFaces = nCells ? cellToFace() : 0;
if (debug)
{
Info<< " Total changed cells : " << nCells << endl;
Info<< " Total evaluations : "
<< nEvals_ << nl
<< " Changed cells / faces : "
<< nCells << " / " << nFaces << nl
<< " Pending cells / faces : "
<< nUnvisitedCells_ << " / " << nUnvisitedFaces_ << nl;
}
if (nCells == 0)
if (!nCells || !nFaces)
{
break;
}
label nFaces = cellToFace();
if (debug)
{
Info<< " Total changed faces : " << nFaces << nl
<< " Total evaluations : " << nEvals_ << nl
<< " Remaining unvisited cells: " << nUnvisitedCells_ << nl
<< " Remaining unvisited faces: " << nUnvisitedFaces_ << endl;
}
if (nFaces == 0)
{
break;
}
++iter;
}
return iter;

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -57,7 +57,7 @@ SourceFiles
namespace Foam
{
// Forward declaration of classes
// Forward declarations
class polyMesh;
class polyPatch;
@ -79,16 +79,21 @@ class FaceCellWave
{
// Private Member Functions
//- Disallow default bitwise copy construct
FaceCellWave(const FaceCellWave&);
//- No copy construct
FaceCellWave(const FaceCellWave&) = delete;
//- Disallow default bitwise assignment
void operator=(const FaceCellWave&);
//- No copy assignment
void operator=(const FaceCellWave&) = delete;
protected:
// Protected data
//- Information tagged with a source or destination id.
// With std::pair as lightweight, moveable container.
typedef std::pair<label,Type> taggedInfoType;
// Protected Data
//- Reference to mesh
const polyMesh& mesh_;
@ -108,15 +113,18 @@ protected:
//- Has face changed
bitSet changedFace_;
//- List of changed faces
DynamicList<label> changedFaces_;
//- Has cell changed
bitSet changedCell_;
//- List of changed faces
DynamicList<label> changedFaces_;
// Cells that have changed
DynamicList<label> changedCells_;
// Information exchange for explicit baffle connections
// Max capacity = 2x number of explicit connections
DynamicList<taggedInfoType> changedBaffles_;
//- Contains cyclics
const bool hasCyclicPatches_;
@ -132,8 +140,10 @@ protected:
label nUnvisitedFaces_;
//- Updates cellInfo with information from neighbour. Updates all
// statistics.
// Protected Member Functions
//- Updates cellInfo with information from neighbour.
// Updates all statistics.
bool updateCell
(
const label celli,
@ -143,8 +153,8 @@ protected:
Type& cellInfo
);
//- Updates faceInfo with information from neighbour. Updates all
// statistics.
//- Updates faceInfo with information from neighbour.
// Updates all statistics.
bool updateFace
(
const label facei,
@ -154,8 +164,8 @@ protected:
Type& faceInfo
);
//- Updates faceInfo with information from same face. Updates all
// statistics.
//- Updates faceInfo with information from same face.
// Updates all statistics.
bool updateFace
(
const label facei,
@ -179,8 +189,8 @@ protected:
(
const polyPatch& patch,
const label nFaces,
const labelList&,
const List<Type>&
const labelUList& changedFaces,
const List<Type>& changedFacesInfo
);
//- Extract info for single patch only
@ -198,7 +208,7 @@ protected:
(
const polyPatch& patch,
const label nFaces,
const labelList& faceLabels,
const labelUList& faceLabels,
List<Type>& faceInfo
) const;
@ -207,7 +217,7 @@ protected:
(
const polyPatch& patch,
const label nFaces,
const labelList& faceLabels,
const labelUList& faceLabels,
List<Type>& faceInfo
) const;
@ -229,16 +239,18 @@ protected:
);
//- Merge data from across processor boundaries
// Transfer changed faces from neighbouring processors.
void handleProcPatches();
//- Merge data from across cyclics
// Transfer changed faces across cyclic halves
void handleCyclicPatches();
//- Merge data from across AMI cyclics
void handleAMICyclicPatches();
//- Merge data across explicitly provided local connections (usually
// baffles)
//- Merge data across explicitly provided local connections
// These are usually baffles
void handleExplicitConnections();
@ -271,11 +283,11 @@ public:
// Constructors
// Construct from mesh. Use setFaceInfo and iterate() to do actual
// calculation.
//- Construct from mesh.
//- Use setFaceInfo and iterate() to do actual calculation.
FaceCellWave
(
const polyMesh&,
const polyMesh& mesh,
UList<Type>& allFaceInfo,
UList<Type>& allCellInfo,
TrackingData& td = dummyTrackData_
@ -283,11 +295,11 @@ public:
//- Construct from mesh and list of changed faces with the Type
// for these faces. Iterates until nothing changes or maxIter reached.
// (maxIter can be 0)
// (maxIter can be 0 or negative). 0 initializes, -1 does not
FaceCellWave
(
const polyMesh&,
const labelList& initialChangedFaces,
const polyMesh& mesh,
const labelUList& initialChangedFaces,
const List<Type>& changedFacesInfo,
UList<Type>& allFaceInfo,
UList<Type>& allCellInfo,
@ -298,13 +310,13 @@ public:
//- Construct from mesh and explicitly connected boundary faces
// and list of changed faces with the Type
// for these faces. Iterates until nothing changes or maxIter reached.
// (maxIter can be 0)
// (maxIter can be 0 or negative). 0 initializes, -1 does not
FaceCellWave
(
const polyMesh&,
const polyMesh& mesh,
const labelPairList& explicitConnections,
const bool handleCyclicAMI,
const labelList& initialChangedFaces,
const labelUList& initialChangedFaces,
const List<Type>& changedFacesInfo,
UList<Type>& allFaceInfo,
UList<Type>& allCellInfo,
@ -314,8 +326,7 @@ public:
//- Destructor
virtual ~FaceCellWave()
{}
virtual ~FaceCellWave() = default;
// Member Functions
@ -346,38 +357,44 @@ public:
return mesh_;
}
//- Get number of unvisited cells, i.e. cells that were not (yet)
// reached from walking across mesh. This can happen from
//- Get number of unvisited cells,
//- i.e. cells that were not (yet) reached from walking across mesh.
// This can happen from
// - not enough iterations done
// - a disconnected mesh
// - a mesh without walls in it
label getUnsetCells() const;
label nUnvisitedCells() const;
//- Get number of unvisited faces
label getUnsetFaces() const;
label nUnvisitedFaces() const;
// Edit
//- Set single initial changed face.
// This is a noop if the face had already been visited
void setFaceInfo(const label facei, const Type& faceInfo);
//- Set initial changed faces
void setFaceInfo
(
const labelList& changedFaces,
const labelUList& changedFaces,
const List<Type>& changedFacesInfo
);
//- Propagate from face to cell. Returns total number of cells
// (over all processors) changed.
//- Propagate from face to cell.
// \return total number of cells (over all processors) changed.
virtual label faceToCell();
//- Propagate from cell to face. Returns total number of faces
// (over all processors) changed. (Faces on processorpatches are
// counted double)
//- Propagate from cell to face.
// \return total number of faces (over all processors) changed.
// Note that faces on processor patches are counted twice.
virtual label cellToFace();
//- Iterate until no changes or maxIter reached. Returns actual
// number of iterations.
//- Iterate until no changes or maxIter reached.
// \return the number of iterations taken.
virtual label iterate(const label maxIter);
};

View File

@ -141,20 +141,20 @@ public:
return calc_.iterate(maxIter);
}
//- Get number of unvisited cells, i.e. cells that were not (yet)
//- Number of unvisited cells, i.e. cells that were not (yet)
// reached from walking across mesh. This can happen from
// - not enough iterations done
// - a disconnected mesh
// - a mesh without walls in it
label getUnsetCells() const
label nUnvisitedCells() const
{
return calc_.getUnsetCells();
return calc_.nUnvisitedCells();
}
//- Get number of unvisited faces
label getUnsetFaces() const
//- Number of unvisited faces
label nUnvisitedFaces() const
{
return calc_.getUnsetFaces();
return calc_.nUnvisitedFaces();
}
};

View File

@ -420,7 +420,7 @@ template
class TrackingData
>
Foam::label Foam::PatchEdgeFaceWave<PrimitivePatchType, Type, TrackingData>::
getUnsetEdges() const
nUnvisitedEdges() const
{
return nUnvisitedEdges_;
}
@ -433,7 +433,7 @@ template
class TrackingData
>
Foam::label Foam::PatchEdgeFaceWave<PrimitivePatchType, Type, TrackingData>::
getUnsetFaces() const
nUnvisitedFaces() const
{
return nUnvisitedFaces_;
}

View File

@ -226,14 +226,14 @@ public:
return td_;
}
//- Get number of unvisited faces, i.e. faces that were not (yet)
//- Number of unvisited faces, i.e. faces that were not (yet)
// reached from walking across patch. This can happen from
// - not enough iterations done
// - a disconnected patch
// - a patch without walls in it
label getUnsetFaces() const;
label nUnvisitedFaces() const;
label getUnsetEdges() const;
label nUnvisitedEdges() const;
//- Copy initial data into allEdgeInfo_
void setEdgeInfo

View File

@ -714,14 +714,14 @@ Foam::PointEdgeWave<Type, TrackingData>::~PointEdgeWave()
template<class Type, class TrackingData>
Foam::label Foam::PointEdgeWave<Type, TrackingData>::getUnsetPoints() const
Foam::label Foam::PointEdgeWave<Type, TrackingData>::nUnvisitedPoints() const
{
return nUnvisitedPoints_;
}
template<class Type, class TrackingData>
Foam::label Foam::PointEdgeWave<Type, TrackingData>::getUnsetEdges() const
Foam::label Foam::PointEdgeWave<Type, TrackingData>::nUnvisitedEdges() const
{
return nUnvisitedEdges_;
}
@ -737,9 +737,9 @@ void Foam::PointEdgeWave<Type, TrackingData>::setPointInfo
{
forAll(changedPoints, changedPointi)
{
label pointi = changedPoints[changedPointi];
const label pointi = changedPoints[changedPointi];
bool wasValid = allPointInfo_[pointi].valid(td_);
const bool wasValid = allPointInfo_[pointi].valid(td_);
// Copy info for pointi
allPointInfo_[pointi] = changedPointsInfo[changedPointi];

View File

@ -287,14 +287,14 @@ public:
return td_;
}
//- Get number of unvisited edges, i.e. edges that were not (yet)
//- Number of unvisited edges, i.e. edges that were not (yet)
// reached from walking across mesh. This can happen from
// - not enough iterations done
// - a disconnected mesh
// - a mesh without walls in it
label getUnsetEdges() const;
label nUnvisitedEdges() const;
label getUnsetPoints() const;
label nUnvisitedPoints() const;
//- Copy initial data into allPointInfo_
void setPointInfo

View File

@ -239,7 +239,7 @@ Foam::labelList Foam::structuredRenumber::renumber
deltaCalc.iterate(nLayers_);
Info<< type() << " : did not visit "
<< deltaCalc.getUnsetCells()
<< deltaCalc.nUnvisitedCells()
<< " cells out of " << nTotalCells
<< "; using " << method_().type() << " renumbering for these" << endl;