Commit f9139aa0 authored by mattijs's avatar mattijs
Browse files

ENH: decomposePar: added logic for preserving baffles

parent 431fea98
......@@ -33,6 +33,11 @@ numberOfSubdomains 2;
//singleProcessorFaceSets ((f0 -1));
//- Keep owner and neighbour of baffles on same processor (i.e. keep it
// detectable as a baffle). Baffles are two boundary face sharing the
// same points.
//preserveBaffles true;
//- Use the volScalarField named here as a weight for each cell in the
// decomposition. For example, use a particle population field to decompose
// for a balanced number of particles in a lagrangian simulation.
......
......@@ -1209,18 +1209,19 @@ Foam::autoPtr<Foam::mapDistributePolyMesh> Foam::meshRefinement::balance
PtrList<labelList> specifiedProcessorFaces;
labelList specifiedProcessor;
// Pairs of baffles
List<labelPair> couples;
// Constraints from decomposeParDict
decomposer.setConstraints
(
mesh_,
blockedFace,
specifiedProcessorFaces,
specifiedProcessor
specifiedProcessor,
couples
);
// Pairs of baffles
List<labelPair> couples;
if (keepZoneFaces || keepBaffles)
{
......@@ -1314,12 +1315,43 @@ Foam::autoPtr<Foam::mapDistributePolyMesh> Foam::meshRefinement::balance
if (keepBaffles)
{
// Get boundary baffles that need to stay together.
couples = getDuplicateFaces // all baffles
(
identity(mesh_.nFaces()-mesh_.nInternalFaces())
+mesh_.nInternalFaces()
);
label nBnd = mesh_.nFaces()-mesh_.nInternalFaces();
labelList coupledFace(mesh_.nFaces(), -1);
{
// Get boundary baffles that need to stay together
List<labelPair> allCouples = getDuplicateFaces
(
identity(nBnd)
+mesh_.nInternalFaces()
);
// Merge with any couples from
// decompositionMethod::setConstraints
forAll(couples, i)
{
const labelPair& baffle = couples[i];
coupledFace[baffle.first()] = baffle.second();
coupledFace[baffle.second()] = baffle.first();
}
forAll(allCouples, i)
{
const labelPair& baffle = allCouples[i];
coupledFace[baffle.first()] = baffle.second();
coupledFace[baffle.second()] = baffle.first();
}
}
couples.setSize(nBnd);
label nCpl = 0;
forAll(coupledFace, faceI)
{
if (coupledFace[faceI] != -1 && faceI < coupledFace[faceI])
{
couples[nCpl++] = labelPair(faceI, coupledFace[faceI]);
}
}
couples.setSize(nCpl);
}
label nCouples = returnReduce(couples.size(), sumOp<label>());
......
EXE_INC = \
-I$(LIB_SRC)/meshTools/lnInclude \
-I$(LIB_SRC)/dynamicMesh/lnInclude \
-I$(LIB_SRC)/finiteVolume/lnInclude
LIB_LIBS = \
-lmeshTools \
-ldynamicMesh \
-lfiniteVolume
......@@ -32,6 +32,7 @@ InClass
#include "Tuple2.H"
#include "faceSet.H"
#include "regionSplit.H"
#include "localPointRegion.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
......@@ -984,15 +985,16 @@ void Foam::decompositionMethod::setConstraints
const polyMesh& mesh,
boolList& blockedFace,
PtrList<labelList>& specifiedProcessorFaces,
labelList& specifiedProcessor
labelList& specifiedProcessor,
List<labelPair>& explicitConnections
)
{
blockedFace.setSize(mesh.nFaces());
blockedFace = true;
label nUnblocked = 0;
//label nUnblocked = 0;
specifiedProcessorFaces.clear();
specifiedProcessor.setSize(0);
explicitConnections.clear();
if (decompositionDict_.found("preservePatches"))
......@@ -1024,7 +1026,7 @@ void Foam::decompositionMethod::setConstraints
if (blockedFace[pp.start() + i])
{
blockedFace[pp.start() + i] = false;
nUnblocked++;
//nUnblocked++;
}
}
}
......@@ -1058,20 +1060,103 @@ void Foam::decompositionMethod::setConstraints
if (blockedFace[fz[i]])
{
blockedFace[fz[i]] = false;
nUnblocked++;
//nUnblocked++;
}
}
}
}
bool preserveBaffles = decompositionDict_.lookupOrDefault
(
"preserveBaffles",
false
);
if (preserveBaffles)
{
Info<< nl
<< "Keeping owner of faces in baffles "
<< " on same processor." << endl;
// Faces to test: all boundary faces
labelList testFaces
(
identity(mesh.nFaces()-mesh.nInternalFaces())
+ mesh.nInternalFaces()
);
// Find correspondencing baffle face (or -1)
labelList duplicateFace
(
localPointRegion::findDuplicateFaces
(
mesh,
testFaces
)
);
const polyBoundaryMesh& patches = mesh.boundaryMesh();
// Convert into list of coupled face pairs (mesh face labels).
explicitConnections.setSize(testFaces.size());
label dupI = 0;
forAll(duplicateFace, i)
{
label otherFaceI = duplicateFace[i];
if (otherFaceI != -1 && i < otherFaceI)
{
label meshFace0 = testFaces[i];
label patch0 = patches.whichPatch(meshFace0);
label meshFace1 = testFaces[otherFaceI];
label patch1 = patches.whichPatch(meshFace1);
// Check for illegal topology. Should normally not happen!
if
(
(patch0 != -1 && isA<processorPolyPatch>(patches[patch0]))
|| (patch1 != -1 && isA<processorPolyPatch>(patches[patch1]))
)
{
FatalErrorIn
(
"decompositionMethod::decompose(const polyMesh&)"
) << "One of two duplicate faces is on"
<< " processorPolyPatch."
<< "This is not allowed." << nl
<< "Face:" << meshFace0
<< " is on patch:" << patches[patch0].name()
<< nl
<< "Face:" << meshFace1
<< " is on patch:" << patches[patch1].name()
<< abort(FatalError);
}
explicitConnections[dupI++] = labelPair(meshFace0, meshFace1);
if (blockedFace[meshFace0])
{
blockedFace[meshFace0] = false;
//nUnblocked++;
}
if (blockedFace[meshFace1])
{
blockedFace[meshFace1] = false;
//nUnblocked++;
}
}
}
explicitConnections.setSize(dupI);
}
if
(
decompositionDict_.found("preservePatches")
|| decompositionDict_.found("preserveFaceZones")
|| preserveBaffles
)
{
syncTools::syncFaceList(mesh, blockedFace, andEqOp<bool>());
reduce(nUnblocked, sumOp<label>());
//reduce(nUnblocked, sumOp<label>());
}
......@@ -1303,12 +1388,14 @@ Foam::labelList Foam::decompositionMethod::decompose
boolList blockedFace;
PtrList<labelList> specifiedProcessorFaces;
labelList specifiedProcessor;
List<labelPair> explicitConnections;
setConstraints
(
mesh,
blockedFace,
specifiedProcessorFaces,
specifiedProcessor
specifiedProcessor,
explicitConnections
);
......@@ -1322,7 +1409,7 @@ Foam::labelList Foam::decompositionMethod::decompose
blockedFace, // any cells to be combined
specifiedProcessorFaces,// any whole cluster of cells to be kept
specifiedProcessor,
List<labelPair>() // no baffles
explicitConnections // baffles
);
return finalDecomp;
......
......@@ -256,13 +256,19 @@ public:
//);
//- Helper: extract constraints
//- Helper: extract constraints:
// blockedface: existing faces where owner and neighbour on same
// proc
// explicitConnections: sets of boundary faces ,, ,,
// specifiedProcessorFaces: groups of faces with all cells on
// same processor.
void setConstraints
(
const polyMesh& mesh,
boolList& blockedFace,
PtrList<labelList>& specifiedProcessorFaces,
labelList& specifiedProcessor
labelList& specifiedProcessor,
List<labelPair>& explicitConnections
);
// Decompose a mesh with constraints:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment