/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2026 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see .
\*---------------------------------------------------------------------------*/
#include "FvFaceCellWave.H"
#include "processorFvPatch.H"
#include "cyclicFvPatch.H"
#include "CompactListList.H"
#include "globalMeshData.H"
#include "OPstream.H"
#include "IPstream.H"
#include "PstreamReduceOps.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
template
const Foam::scalar Foam::FvFaceCellWave::geomTol_ = 1e-6;
template
Foam::scalar Foam::FvFaceCellWave::propagationTol_ = 1e-2;
template
int Foam::FvFaceCellWave::defaultTrackingData_ = -1;
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
template
template
Foam::labelList
Foam::FvFaceCellWave::listListSizes
(
const ListList& ll
)
{
labelList s(ll.size());
forAll(ll, i)
{
s[i] = ll[i].size();
}
return s;
}
template
template
ListList Foam::FvFaceCellWave::sizesListList
(
const labelList& s,
const Value& value
)
{
ListList ll(s.size());
forAll(s, i)
{
ll[i] = typename ListList::value_type(s[i], value);
}
return ll;
}
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
template
const Type& Foam::FvFaceCellWave::faceInfo
(
const labelPair& patchAndFacei
) const
{
return
patchAndFacei.first() == -1
? internalFaceInfo_[patchAndFacei.second()]
: patchFaceInfo_[patchAndFacei.first()][patchAndFacei.second()];
}
template
Type& Foam::FvFaceCellWave::faceInfo
(
const labelPair& patchAndFacei
)
{
return
patchAndFacei.first() == -1
? internalFaceInfo_[patchAndFacei.second()]
: patchFaceInfo_[patchAndFacei.first()][patchAndFacei.second()];
}
template
bool Foam::FvFaceCellWave::faceChanged
(
const labelPair& patchAndFacei
)
const
{
return
patchAndFacei.first() == -1
? internalFaceChanged_[patchAndFacei.second()]
: patchFaceChanged_[patchAndFacei.first()][patchAndFacei.second()];
}
template
Foam::PackedBoolList::iteratorBase
Foam::FvFaceCellWave::faceChanged
(
const labelPair& patchAndFacei
)
{
return
patchAndFacei.first() == -1
? internalFaceChanged_[patchAndFacei.second()]
: patchFaceChanged_[patchAndFacei.first()][patchAndFacei.second()];
}
template
bool Foam::FvFaceCellWave::updateCell
(
const label celli,
const labelPair& neighbourPatchAndFacei,
const Type& neighbourInfo,
const scalar tol,
Type& cellInfo
)
{
bool propagate =
cellInfo.updateCell
(
mesh_,
celli,
neighbourPatchAndFacei,
neighbourInfo,
tol,
td_
);
if (propagate)
{
if (!cellChanged_[celli])
{
cellChanged_[celli] = true;
changedCells_.append(celli);
}
}
return propagate;
}
template
bool Foam::FvFaceCellWave::updateFace
(
const labelPair& patchAndFacei,
const label neighbourCelli,
const Type& neighbourInfo,
const scalar tol,
Type& faceInfo
)
{
bool propagate =
faceInfo.updateFace
(
mesh_,
patchAndFacei,
neighbourCelli,
neighbourInfo,
tol,
td_
);
if (propagate)
{
PackedBoolList::iteratorBase changed = faceChanged(patchAndFacei);
if (!changed)
{
changed = true;
changedPatchAndFaces_.append(patchAndFacei);
}
}
return propagate;
}
template
bool Foam::FvFaceCellWave::updateFace
(
const labelPair& patchAndFacei,
const Type& neighbourInfo,
const scalar tol,
Type& faceInfo
)
{
bool propagate =
faceInfo.updateFace
(
mesh_,
patchAndFacei,
neighbourInfo,
tol,
td_
);
if (propagate)
{
PackedBoolList::iteratorBase changed = faceChanged(patchAndFacei);
if (!changed)
{
changed = true;
changedPatchAndFaces_.append(patchAndFacei);
}
}
return propagate;
}
template
void Foam::FvFaceCellWave::checkCyclic
(
const fvPatch& patch
) const
{
const cyclicFvPatch& nbrPatch =
refCast(patch).nbrPatch();
forAll(patch, patchFacei)
{
const Type& info = faceInfo({patch.index(), patchFacei});
const Type& nbrInfo = faceInfo({nbrPatch.index(), patchFacei});
const bool changed = faceChanged({patch.index(), patchFacei});
const bool nbrChanged = faceChanged({nbrPatch.index(), patchFacei});
if (!info.sameGeometry(mesh_, nbrInfo, geomTol_, td_))
{
FatalErrorInFunction
<< " faceInfo:" << info
<< " otherfaceInfo:" << nbrInfo
<< abort(FatalError);
}
if (changed != nbrChanged)
{
FatalErrorInFunction
<< " faceInfo:" << info
<< " otherfaceInfo:" << nbrInfo
<< " changedFace:" << changed
<< " otherchangedFace:" << nbrChanged
<< abort(FatalError);
}
}
}
template
template
bool Foam::FvFaceCellWave::hasPatch() const
{
forAll(mesh_.boundary(), patchi)
{
if (isA(mesh_.boundary()[patchi]))
{
return true;
}
}
return false;
}
template
void Foam::FvFaceCellWave::mergeFaceInfo
(
const fvPatch& patch,
const label nFaces,
const labelList& changedPatchFaces,
const List& changedPatchFacesInfo
)
{
for (label changedFacei = 0; changedFacei < nFaces; changedFacei ++)
{
const label patchFacei = changedPatchFaces[changedFacei];
Type& info = faceInfo({patch.index(), patchFacei});
const Type& neighbourInfo = changedPatchFacesInfo[changedFacei];
if (!info.equal(neighbourInfo, td_))
{
updateFace
(
{patch.index(), patchFacei},
neighbourInfo,
propagationTol_,
info
);
}
}
}
template
Foam::label
Foam::FvFaceCellWave::getChangedPatchFaces
(
const fvPatch& patch,
labelList& changedPatchFaces,
List& changedPatchFacesInfo
) const
{
// Construct compact patchFace change arrays for a single patch.
// changedPatchFaces in local patch numbering. Return length of arrays.
label i = 0;
forAll(patch, patchFacei)
{
if (patchFaceChanged_[patch.index()][patchFacei])
{
changedPatchFaces[i] = patchFacei;
changedPatchFacesInfo[i] = faceInfo({patch.index(), patchFacei});
i ++;
}
}
return i;
}
template
void Foam::FvFaceCellWave::transform
(
const fvPatch& patch,
const label nFaces,
const labelList& patchFaces,
const transformer& transform,
List& faceInfo
)
{
for (label i = 0; i < nFaces; i++)
{
faceInfo[i].transform(patch, patchFaces[i], transform, td_);
}
}
template
void Foam::FvFaceCellWave::handleProcPatches()
{
// Transfer information to/from neighbouring processors
// Which patches are processor patches
const labelList& procPatches = mesh_.globalData().processorPatches();
// Send all
PstreamBuffers pBufs(Pstream::commsTypes::nonBlocking);
forAll(procPatches, i)
{
const label patchi = procPatches[i];
const processorFvPatch& procPatch =
refCast(mesh_.boundary()[patchi]);
// Allocate buffers
label nSendFaces;
labelList sendFaces(procPatch.size());
List sendFacesInfo(procPatch.size());
// Determine which faces changed on current patch
nSendFaces =
getChangedPatchFaces
(
procPatch,
sendFaces,
sendFacesInfo
);
if (debug & 2)
{
Pout<< " Processor patch " << patchi << ' ' << procPatch.name()
<< " communicating with " << procPatch.neighbProcNo()
<< " Sending:" << nSendFaces
<< endl;
}
// Send
UOPstream toNeighbour(procPatch.neighbProcNo(), pBufs);
toNeighbour
<< SubList