Commit bdaca3a6 authored by mattijs's avatar mattijs
Browse files

ENH: Store additional information to handle split cyclics (still not correct though)

parent d807c167
......@@ -30,6 +30,9 @@ License
#include "faceCoupleInfo.H"
#include "processorFvPatchField.H"
#include "processorFvsPatchField.H"
#include "processorCyclicPolyPatch.H"
#include "processorCyclicFvPatchField.H"
#include "processorCyclicFvsPatchField.H"
#include "polyTopoChange.H"
#include "removeCells.H"
#include "polyModifyFace.H"
......@@ -129,6 +132,7 @@ void Foam::fvMeshDistribute::printMeshInfo(const fvMesh& mesh)
{
Pout<< "Primitives:" << nl
<< " points :" << mesh.nPoints() << nl
<< " bb :" << boundBox(mesh.points(), false) << nl
<< " internalFaces:" << mesh.nInternalFaces() << nl
<< " faces :" << mesh.nFaces() << nl
<< " cells :" << mesh.nCells() << nl;
......@@ -188,7 +192,8 @@ void Foam::fvMeshDistribute::printCoupleInfo
const primitiveMesh& mesh,
const labelList& sourceFace,
const labelList& sourceProc,
const labelList& sourceNewProc
const labelList& sourcePatch,
const labelList& sourceNewNbrProc
)
{
Pout<< nl
......@@ -203,7 +208,7 @@ void Foam::fvMeshDistribute::printCoupleInfo
<< " fc:" << mesh.faceCentres()[meshFaceI]
<< " connects to proc:" << sourceProc[bFaceI]
<< "/face:" << sourceFace[bFaceI]
<< " which will move to proc:" << sourceNewProc[bFaceI]
<< " which will move to proc:" << sourceNewNbrProc[bFaceI]
<< endl;
}
}
......@@ -271,32 +276,87 @@ Foam::label Foam::fvMeshDistribute::findNonEmptyPatch() const
}
// Appends processorPolyPatch. Returns patchID.
Foam::label Foam::fvMeshDistribute::addProcPatch
(
const word& patchName,
const label nbrProc
)
//// Appends processorPolyPatch. Returns patchID.
//Foam::label Foam::fvMeshDistribute::addProcPatch
//(
// const word& patchName,
// const label nbrProc
//)
//{
// // Clear local fields and e.g. polyMesh globalMeshData.
// mesh_.clearOut();
//
//
// polyBoundaryMesh& polyPatches =
// const_cast<polyBoundaryMesh&>(mesh_.boundaryMesh());
// fvBoundaryMesh& fvPatches = const_cast<fvBoundaryMesh&>(mesh_.boundary());
//
// if (polyPatches.findPatchID(patchName) != -1)
// {
// FatalErrorIn("fvMeshDistribute::addProcPatch(const word&, const label)")
// << "Cannot create patch " << patchName << " since already exists."
// << nl
// << "Current patch names:" << polyPatches.names()
// << exit(FatalError);
// }
//
//
//
// // Add the patch
// // ~~~~~~~~~~~~~
//
// label sz = polyPatches.size();
//
// // Add polyPatch
// polyPatches.setSize(sz+1);
// polyPatches.set
// (
// sz,
// new processorPolyPatch
// (
// patchName,
// 0, // size
// mesh_.nFaces(),
// sz,
// mesh_.boundaryMesh(),
// Pstream::myProcNo(),
// nbrProc
// )
// );
// fvPatches.setSize(sz+1);
// fvPatches.set
// (
// sz,
// fvPatch::New
// (
// polyPatches[sz], // point to newly added polyPatch
// mesh_.boundary()
// )
// );
//
// return sz;
//}
// Appends polyPatch. Returns patchID.
Foam::label Foam::fvMeshDistribute::addPatch(polyPatch* patchPtr)
{
// Clear local fields and e.g. polyMesh globalMeshData.
mesh_.clearOut();
polyBoundaryMesh& polyPatches =
const_cast<polyBoundaryMesh&>(mesh_.boundaryMesh());
fvBoundaryMesh& fvPatches = const_cast<fvBoundaryMesh&>(mesh_.boundary());
if (polyPatches.findPatchID(patchName) != -1)
if (polyPatches.findPatchID(patchPtr->name()) != -1)
{
FatalErrorIn("fvMeshDistribute::addProcPatch(const word&, const label)")
<< "Cannot create patch " << patchName << " since already exists."
<< nl
<< "Current patch names:" << polyPatches.names()
<< exit(FatalError);
FatalErrorIn("fvMeshDistribute::addPatch(polyPatch*)")
<< "Cannot create patch " << patchPtr->name()
<< " since already exists." << nl
<< "Current patch names:" << polyPatches.names() << exit(FatalError);
}
// Add the patch
// ~~~~~~~~~~~~~
......@@ -304,20 +364,7 @@ Foam::label Foam::fvMeshDistribute::addProcPatch
// Add polyPatch
polyPatches.setSize(sz+1);
polyPatches.set
(
sz,
new processorPolyPatch
(
patchName,
0, // size
mesh_.nFaces(),
sz,
mesh_.boundaryMesh(),
Pstream::myProcNo(),
nbrProc
)
);
polyPatches.set(sz, patchPtr);
fvPatches.setSize(sz+1);
fvPatches.set
(
......@@ -625,25 +672,27 @@ void Foam::fvMeshDistribute::getNeighbourData
const labelList& distribution,
labelList& sourceFace,
labelList& sourceProc,
labelList& sourceNewProc
labelList& sourcePatch,
labelList& sourceNewNbrProc
) const
{
label nBnd = mesh_.nFaces() - mesh_.nInternalFaces();
sourceFace.setSize(nBnd);
sourceProc.setSize(nBnd);
sourceNewProc.setSize(nBnd);
sourcePatch.setSize(nBnd);
sourceNewNbrProc.setSize(nBnd);
const polyBoundaryMesh& patches = mesh_.boundaryMesh();
// Get neighbouring meshFace labels and new processor of coupled boundaries.
labelList nbrFaces(nBnd, -1);
labelList nbrNewProc(nBnd, -1);
labelList nbrNewNbrProc(nBnd, -1);
forAll(patches, patchI)
{
const polyPatch& pp = patches[patchI];
if (isA<processorPolyPatch>(pp))
if (pp.coupled())
{
label offset = pp.start() - mesh_.nInternalFaces();
......@@ -655,7 +704,7 @@ void Foam::fvMeshDistribute::getNeighbourData
}
// Which processor they will end up on
SubList<label>(nbrNewProc, pp.size(), offset).assign
SubList<label>(nbrNewNbrProc, pp.size(), offset).assign
(
UIndirectList<label>(distribution, pp.faceCells())()
);
......@@ -665,7 +714,7 @@ void Foam::fvMeshDistribute::getNeighbourData
// Exchange the boundary data
syncTools::swapBoundaryFaceList(mesh_, nbrFaces);
syncTools::swapBoundaryFaceList(mesh_, nbrNewProc);
syncTools::swapBoundaryFaceList(mesh_, nbrNewNbrProc);
forAll(patches, patchI)
......@@ -680,7 +729,7 @@ void Foam::fvMeshDistribute::getNeighbourData
// Check which of the two faces we store.
if (Pstream::myProcNo() < procPatch.neighbProcNo())
if (procPatch.owner())
{
// Use my local face labels
forAll(pp, i)
......@@ -688,7 +737,7 @@ void Foam::fvMeshDistribute::getNeighbourData
label bndI = offset + i;
sourceFace[bndI] = pp.start()+i;
sourceProc[bndI] = Pstream::myProcNo();
sourceNewProc[bndI] = nbrNewProc[bndI];
sourceNewNbrProc[bndI] = nbrNewNbrProc[bndI];
}
}
else
......@@ -699,7 +748,50 @@ void Foam::fvMeshDistribute::getNeighbourData
label bndI = offset + i;
sourceFace[bndI] = nbrFaces[bndI];
sourceProc[bndI] = procPatch.neighbProcNo();
sourceNewProc[bndI] = nbrNewProc[bndI];
sourceNewNbrProc[bndI] = nbrNewNbrProc[bndI];
}
}
label patchI = -1;
if (isA<processorCyclicPolyPatch>(pp))
{
patchI = refCast<const processorCyclicPolyPatch>
(
pp
).referPatchID();
}
forAll(pp, i)
{
label bndI = offset + i;
sourcePatch[bndI] = patchI;
}
}
else if (isA<cyclicPolyPatch>(pp))
{
const cyclicPolyPatch& cpp = refCast<const cyclicPolyPatch>(pp);
if (cpp.owner())
{
forAll(pp, i)
{
label bndI = offset + i;
sourceFace[bndI] = pp.start()+i;
sourceProc[bndI] = Pstream::myProcNo();
sourcePatch[bndI] = patchI;
sourceNewNbrProc[bndI] = nbrNewNbrProc[bndI];
}
}
else
{
forAll(pp, i)
{
label bndI = offset + i;
sourceFace[bndI] = nbrFaces[bndI];
sourceProc[bndI] = Pstream::myProcNo();
sourcePatch[bndI] = patchI;
sourceNewNbrProc[bndI] = nbrNewNbrProc[bndI];
}
}
}
......@@ -709,9 +801,10 @@ void Foam::fvMeshDistribute::getNeighbourData
forAll(pp, i)
{
label bndI = offset + i;
sourceFace[bndI] = patchI;
sourceFace[bndI] = -1;
sourceProc[bndI] = -1;
sourceNewProc[bndI] = -1;
sourcePatch[bndI] = patchI;
sourceNewNbrProc[bndI] = -1;
}
}
}
......@@ -732,16 +825,19 @@ void Foam::fvMeshDistribute::subsetBoundaryData
const labelList& sourceFace,
const labelList& sourceProc,
const labelList& sourceNewProc,
const labelList& sourcePatch,
const labelList& sourceNewNbrProc,
labelList& subFace,
labelList& subProc,
labelList& subNewProc
labelList& subPatch,
labelList& subNewNbrProc
)
{
subFace.setSize(mesh.nFaces() - mesh.nInternalFaces());
subProc.setSize(mesh.nFaces() - mesh.nInternalFaces());
subNewProc.setSize(mesh.nFaces() - mesh.nInternalFaces());
subPatch.setSize(mesh.nFaces() - mesh.nInternalFaces());
subNewNbrProc.setSize(mesh.nFaces() - mesh.nInternalFaces());
forAll(subFace, newBFaceI)
{
......@@ -754,6 +850,7 @@ void Foam::fvMeshDistribute::subsetBoundaryData
{
subFace[newBFaceI] = oldFaceI;
subProc[newBFaceI] = Pstream::myProcNo();
subPatch[newBFaceI] = -1;
label oldOwn = oldFaceOwner[oldFaceI];
label oldNei = oldFaceNeighbour[oldFaceI];
......@@ -761,12 +858,12 @@ void Foam::fvMeshDistribute::subsetBoundaryData
if (oldOwn == cellMap[mesh.faceOwner()[newFaceI]])
{
// We kept the owner side. Where does the neighbour move to?
subNewProc[newBFaceI] = oldDistribution[oldNei];
subNewNbrProc[newBFaceI] = oldDistribution[oldNei];
}
else
{
// We kept the neighbour side.
subNewProc[newBFaceI] = oldDistribution[oldOwn];
subNewNbrProc[newBFaceI] = oldDistribution[oldOwn];
}
}
else
......@@ -776,7 +873,8 @@ void Foam::fvMeshDistribute::subsetBoundaryData
subFace[newBFaceI] = sourceFace[oldBFaceI];
subProc[newBFaceI] = sourceProc[oldBFaceI];
subNewProc[newBFaceI] = sourceNewProc[oldBFaceI];
subPatch[newBFaceI] = sourcePatch[oldBFaceI];
subNewNbrProc[newBFaceI] = sourceNewNbrProc[oldBFaceI];
}
}
}
......@@ -789,11 +887,13 @@ void Foam::fvMeshDistribute::findCouples
const primitiveMesh& mesh,
const labelList& sourceFace,
const labelList& sourceProc,
const labelList& sourcePatch,
const label domain,
const primitiveMesh& domainMesh,
const labelList& domainFace,
const labelList& domainProc,
const labelList& domainPatch,
labelList& masterCoupledFaces,
labelList& slaveCoupledFaces
......@@ -803,9 +903,16 @@ void Foam::fvMeshDistribute::findCouples
// with same face+proc.
HashTable<label, labelPair, labelPair::Hash<> > map(domainFace.size());
forAll(domainFace, bFaceI)
forAll(domainProc, bFaceI)
{
map.insert(labelPair(domainFace[bFaceI], domainProc[bFaceI]), bFaceI);
if (domainProc[bFaceI] != -1 && domainPatch[bFaceI] == -1)
{
map.insert
(
labelPair(domainFace[bFaceI], domainProc[bFaceI]),
bFaceI
);
}
}
......@@ -817,7 +924,7 @@ void Foam::fvMeshDistribute::findCouples
forAll(sourceFace, bFaceI)
{
if (sourceProc[bFaceI] != -1)
if (sourceProc[bFaceI] != -1 && sourcePatch[bFaceI] == -1)
{
labelPair myData(sourceFace[bFaceI], sourceProc[bFaceI]);
......@@ -935,105 +1042,202 @@ Foam::autoPtr<Foam::mapPolyMesh> Foam::fvMeshDistribute::doRemoveCells
// the processor patchID.
void Foam::fvMeshDistribute::addProcPatches
(
const labelList& neighbourNewProc, // processor that neighbour is on
labelList& procPatchID
const labelList& nbrProc, // processor that neighbour is now on
const labelList& referPatchID, // patchID (or -1) I originated from
List<Map<label> >& procPatchID
)
{
// Now use the neighbourFace/Proc to repatch the mesh. These two lists
// Now use the neighbourFace/Proc to repatch the mesh. These lists
// contain for all current boundary faces the global patchID (for non-proc
// patch) or the processor.
labelList procPatchSizes(Pstream::nProcs(), 0);
forAll(neighbourNewProc, bFaceI)
{
if (neighbourNewProc[bFaceI] != -1)
{
procPatchSizes[neighbourNewProc[bFaceI]]++;
}
}
// Per neighbour processor the label of the processor patch
procPatchID.setSize(Pstream::nProcs());
forAll(procPatchSizes, procI)
forAll(nbrProc, bFaceI)
{
if (procPatchSizes[procI] > 0)
{
const word patchName =
"procBoundary"
+ name(Pstream::myProcNo())
+ "to"
+ name(procI);
label procI = nbrProc[bFaceI];
procPatchID[procI] = addProcPatch(patchName, procI);
addPatchFields<volScalarField>
(
processorFvPatchField<scalar>::typeName
);
addPatchFields<volVectorField>
(
processorFvPatchField<vector>::typeName
);
addPatchFields<volSphericalTensorField>
(
processorFvPatchField<sphericalTensor>::typeName
);
addPatchFields<volSymmTensorField>
(
processorFvPatchField<symmTensor>::typeName
);
addPatchFields<volTensorField>
(
processorFvPatchField<tensor>::typeName
);
addPatchFields<surfaceScalarField>
(
processorFvPatchField<scalar>::typeName
);
addPatchFields<surfaceVectorField>
(
processorFvPatchField<vector>::typeName
);
addPatchFields<surfaceSphericalTensorField>
(
processorFvPatchField<sphericalTensor>::typeName
);
addPatchFields<surfaceSymmTensorField>
(
processorFvPatchField<symmTensor>::typeName
);
addPatchFields<surfaceTensorField>
(
processorFvPatchField<tensor>::typeName
);
}
else
if (procI != -1 && procI != Pstream::myProcNo())
{
procPatchID[procI] = -1;
if (!procPatchID[procI].found(referPatchID[bFaceI]))
{
// No patch for neighbour yet. Is either a normal processor
// patch or a processorCyclic patch.
if (referPatchID[bFaceI] == -1)
{
// Ordinary processor boundary
const word patchName =
"procBoundary"
+ name(Pstream::myProcNo())
+ "to"
+ name(procI);
procPatchID[procI].insert
(
referPatchID[bFaceI],
addPatch
(
new processorPolyPatch
(
patchName,
0, // size
mesh_.nFaces(),
mesh_.boundaryMesh().size(),
mesh_.boundaryMesh(),
Pstream::myProcNo(),
nbrProc[bFaceI]
)
)
);
addPatchFields<volScalarField>
(
processorFvPatchField<scalar>::typeName
);
addPatchFields<volVectorField>
(
processorFvPatchField<vector>::typeName
);
addPatchFields<volSphericalTensorField>
(
processorFvPatchField<sphericalTensor>::typeName
);
addPatchFields<volSymmTensorField>
(
processorFvPatchField<symmTensor>::typeName
);
addPatchFields<volTensorField>
(
processorFvPatchField<tensor>::typeName
);
addPatchFields<surfaceScalarField>
(
processorFvPatchField<scalar>::typeName
);
addPatchFields<surfaceVectorField>
(
processorFvPatchField<vector>::typeName
);
addPatchFields<surfaceSphericalTensorField>
(
processorFvPatchField<sphericalTensor>::typeName
);
addPatchFields<surfaceSymmTensorField>
(
processorFvPatchField<symmTensor>::typeName
);
addPatchFields<surfaceTensorField>
(
processorFvPatchField<tensor>::typeName
);
}
else
{
// Processor boundary originating from cyclic
const word& cycName = mesh_.boundaryMesh()
[
referPatchID[bFaceI]
].name();
const word patchName =
"procBoundary"
+ name(Pstream::myProcNo())
+ "to"
+ name(procI)
+ "through"
+ cycName;
procPatchID[procI].insert
(
referPatchID[bFaceI],
addPatch
(
new processorCyclicPolyPatch
(
patchName,
0, // size
mesh_.nFaces(),
mesh_.boundaryMesh().size(),
mesh_.boundaryMesh(),
Pstream::myProcNo(),
nbrProc[bFaceI],
cycName
)
)
);
addPatchFields<volScalarField>
(
processorCyclicFvPatchField<scalar>::typeName
);
addPatchFields<volVectorField>
(
processorCyclicFvPatchField<vector>::typeName
);
addPatchFields<volSphericalTensorField>
(
processorCyclicFvPatchField<sphericalTensor>::typeName
);
addPatchFields<volSymmTensorField>
(
processorCyclicFvPatchField<symmTensor>::typeName
);
addPatchFields<volTensorField>
(
processorCyclicFvPatchField<tensor>::typeName
);
addPatchFields<surfaceScalarField>
(
processorCyclicFvPatchField<scalar>::typeName
);
addPatchFields<surfaceVectorField>
(
processorCyclicFvPatchField<vector>::typeName
);
addPatchFields<surfaceSphericalTensorField>