fvMeshDistribute: uses topological rather than geometric point merging

Patch contributed by Mattijs Janssens
This commit is contained in:
Henry Weller
2018-03-23 17:02:18 +00:00
parent a59351c64f
commit 5d4c8f5d5f
2 changed files with 200 additions and 41 deletions

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -41,6 +41,7 @@ License
#include "CompactListList.H"
#include "fvMeshTools.H"
#include "ListOps.H"
#include "globalIndex.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -582,25 +583,54 @@ Foam::autoPtr<Foam::mapPolyMesh> Foam::fvMeshDistribute::repatch
// merge those points.
Foam::autoPtr<Foam::mapPolyMesh> Foam::fvMeshDistribute::mergeSharedPoints
(
const labelList& pointToGlobalMaster,
labelListList& constructPointMap
)
{
// Find out which sets of points get merged and create a map from
// mesh point to unique point.
Map<label> pointToMaster
(
fvMeshAdder::findSharedPoints
(
mesh_,
mergeTol_
)
);
label nShared = 0;
forAll(pointToGlobalMaster, pointi)
{
if (pointToGlobalMaster[pointi] != -1)
{
nShared++;
}
}
Map<label> globalMasterToLocalMaster(2*nShared);
Map<label> pointToMaster(2*nShared);
forAll(pointToGlobalMaster, pointi)
{
label globali = pointToGlobalMaster[pointi];
if (globali != -1)
{
Map<label>::const_iterator iter = globalMasterToLocalMaster.find
(
globali
);
if (iter == globalMasterToLocalMaster.end())
{
// Found first point. Designate as master
globalMasterToLocalMaster.insert(globali, pointi);
pointToMaster.insert(pointi, pointi);
}
else
{
pointToMaster.insert(pointi, iter());
}
}
}
if (returnReduce(pointToMaster.size(), sumOp<label>()) == 0)
{
return autoPtr<mapPolyMesh>(nullptr);
}
polyTopoChange meshMod(mesh_);
fvMeshAdder::mergePoints(mesh_, pointToMaster, meshMod);
@ -642,16 +672,19 @@ Foam::autoPtr<Foam::mapPolyMesh> Foam::fvMeshDistribute::mergeSharedPoints
}
// Construct the local environment of all boundary faces.
void Foam::fvMeshDistribute::getNeighbourData
void Foam::fvMeshDistribute::getCouplingData
(
const labelList& distribution,
labelList& sourceFace,
labelList& sourceProc,
labelList& sourcePatch,
labelList& sourceNewNbrProc
labelList& sourceNewNbrProc,
labelList& sourcePointMaster
) const
{
// Construct the coupling information for all (boundary) faces and
// points
label nBnd = mesh_.nFaces() - mesh_.nInternalFaces();
sourceFace.setSize(nBnd);
sourceProc.setSize(nBnd);
@ -782,13 +815,62 @@ void Foam::fvMeshDistribute::getNeighbourData
}
}
}
// Collect coupled (collocated) points
sourcePointMaster.setSize(mesh_.nPoints());
sourcePointMaster = -1;
{
// Assign global master point
const globalIndex globalPoints(mesh_.nPoints());
const globalMeshData& gmd = mesh_.globalData();
const indirectPrimitivePatch& cpp = gmd.coupledPatch();
const labelList& meshPoints = cpp.meshPoints();
const mapDistribute& slavesMap = gmd.globalCoPointSlavesMap();
const labelListList& slaves = gmd.globalCoPointSlaves();
labelList elems(slavesMap.constructSize(), -1);
forAll(meshPoints, pointi)
{
const labelList& slots = slaves[pointi];
if (slots.size())
{
// pointi is a master. Assign a unique label.
label globalPointi = globalPoints.toGlobal(meshPoints[pointi]);
elems[pointi] = globalPointi;
forAll(slots, i)
{
label sloti = slots[i];
if (sloti >= meshPoints.size())
{
// Filter out local collocated points. We don't want
// to merge these
elems[slots[i]] = globalPointi;
}
}
}
}
// Push slave-slot data back to slaves
slavesMap.reverseDistribute(elems.size(), elems, false);
// Extract back onto mesh
forAll(meshPoints, pointi)
{
sourcePointMaster[meshPoints[pointi]] = elems[pointi];
}
}
}
// Subset the neighbourCell/neighbourProc fields
void Foam::fvMeshDistribute::subsetBoundaryData
void Foam::fvMeshDistribute::subsetCouplingData
(
const fvMesh& mesh,
const labelList& pointMap,
const labelList& faceMap,
const labelList& cellMap,
@ -801,11 +883,13 @@ void Foam::fvMeshDistribute::subsetBoundaryData
const labelList& sourceProc,
const labelList& sourcePatch,
const labelList& sourceNewNbrProc,
const labelList& sourcePointMaster,
labelList& subFace,
labelList& subProc,
labelList& subPatch,
labelList& subNewNbrProc
labelList& subNewNbrProc,
labelList& subPointMaster
)
{
subFace.setSize(mesh.nFaces() - mesh.nInternalFaces());
@ -851,6 +935,9 @@ void Foam::fvMeshDistribute::subsetBoundaryData
subNewNbrProc[newBFacei] = sourceNewNbrProc[oldBFacei];
}
}
subPointMaster = UIndirectList<label>(sourcePointMaster, pointMap);
}
@ -935,9 +1022,9 @@ Foam::labelList Foam::fvMeshDistribute::mapBoundaryData
(
const primitiveMesh& mesh, // mesh after adding
const mapAddedPolyMesh& map,
const labelList& boundaryData0, // mesh before adding
const labelList& boundaryData0, // on mesh before adding
const label nInternalFaces1,
const labelList& boundaryData1 // added mesh
const labelList& boundaryData1 // on added mesh
)
{
labelList newBoundaryData(mesh.nFaces() - mesh.nInternalFaces());
@ -969,6 +1056,41 @@ Foam::labelList Foam::fvMeshDistribute::mapBoundaryData
}
Foam::labelList Foam::fvMeshDistribute::mapPointData
(
const primitiveMesh& mesh, // mesh after adding
const mapAddedPolyMesh& map,
const labelList& boundaryData0, // on mesh before adding
const labelList& boundaryData1 // on added mesh
)
{
labelList newBoundaryData(mesh.nPoints());
forAll(boundaryData0, oldPointi)
{
label newPointi = map.oldPointMap()[oldPointi];
// Point still exists (is necessary?)
if (newPointi >= 0)
{
newBoundaryData[newPointi] = boundaryData0[oldPointi];
}
}
forAll(boundaryData1, addedPointi)
{
label newPointi = map.addedPointMap()[addedPointi];
if (newPointi >= 0)
{
newBoundaryData[newPointi] = boundaryData1[addedPointi];
}
}
return newBoundaryData;
}
// Remove cells. Add all exposed faces to patch oldInternalPatchi
Foam::autoPtr<Foam::mapPolyMesh> Foam::fvMeshDistribute::doRemoveCells
(
@ -1189,6 +1311,7 @@ void Foam::fvMeshDistribute::sendMesh
const labelList& sourceProc,
const labelList& sourcePatch,
const labelList& sourceNewNbrProc,
const labelList& sourcePointMaster,
Ostream& toDomain
)
{
@ -1325,7 +1448,8 @@ void Foam::fvMeshDistribute::sendMesh
<< sourceFace
<< sourceProc
<< sourcePatch
<< sourceNewNbrProc;
<< sourceNewNbrProc
<< sourcePointMaster;
if (debug)
@ -1348,6 +1472,7 @@ Foam::autoPtr<Foam::fvMesh> Foam::fvMeshDistribute::receiveMesh
labelList& domainSourceProc,
labelList& domainSourcePatch,
labelList& domainSourceNewNbrProc,
labelList& domainSourcePointMaster,
Istream& fromNbr
)
{
@ -1366,7 +1491,8 @@ Foam::autoPtr<Foam::fvMesh> Foam::fvMeshDistribute::receiveMesh
>> domainSourceFace
>> domainSourceProc
>> domainSourcePatch
>> domainSourceNewNbrProc;
>> domainSourceNewNbrProc
>> domainSourcePointMaster;
// Construct fvMesh
autoPtr<fvMesh> domainMeshPtr
@ -1607,13 +1733,15 @@ Foam::autoPtr<Foam::mapDistributePolyMesh> Foam::fvMeshDistribute::distribute
labelList sourceFace;
labelList sourceProc;
labelList sourceNewNbrProc;
getNeighbourData
labelList sourcePointMaster;
getCouplingData
(
distribution,
sourceFace,
sourceProc,
sourcePatch,
sourceNewNbrProc
sourceNewNbrProc,
sourcePointMaster
);
@ -1825,11 +1953,13 @@ Foam::autoPtr<Foam::mapDistributePolyMesh> Foam::fvMeshDistribute::distribute
labelList procSourceProc;
labelList procSourcePatch;
labelList procSourceNewNbrProc;
labelList procSourcePointMaster;
subsetBoundaryData
subsetCouplingData
(
subsetter.subMesh(),
subsetter.faceMap(), // from subMesh to mesh
subsetter.pointMap(), // from subMesh to mesh
subsetter.faceMap(), // ,, ,,
subsetter.cellMap(), // ,, ,,
distribution, // old mesh distribution
@ -1841,15 +1971,16 @@ Foam::autoPtr<Foam::mapDistributePolyMesh> Foam::fvMeshDistribute::distribute
sourceProc,
sourcePatch,
sourceNewNbrProc,
sourcePointMaster,
procSourceFace,
procSourceProc,
procSourcePatch,
procSourceNewNbrProc
procSourceNewNbrProc,
procSourcePointMaster
);
// Send to neighbour
sendMesh
(
@ -1864,6 +1995,8 @@ Foam::autoPtr<Foam::mapDistributePolyMesh> Foam::fvMeshDistribute::distribute
procSourceProc,
procSourcePatch,
procSourceNewNbrProc,
procSourcePointMaster,
str
);
@ -2023,10 +2156,12 @@ Foam::autoPtr<Foam::mapDistributePolyMesh> Foam::fvMeshDistribute::distribute
labelList domainSourceProc;
labelList domainSourcePatch;
labelList domainSourceNewNbrProc;
labelList domainSourcePointMaster;
subsetBoundaryData
subsetCouplingData
(
mesh_, // new mesh
subMap().pointMap(), // from new to original mesh
subMap().faceMap(), // from new to original mesh
subMap().cellMap(),
@ -2039,17 +2174,20 @@ Foam::autoPtr<Foam::mapDistributePolyMesh> Foam::fvMeshDistribute::distribute
sourceProc,
sourcePatch,
sourceNewNbrProc,
sourcePointMaster,
domainSourceFace,
domainSourceProc,
domainSourcePatch,
domainSourceNewNbrProc
domainSourceNewNbrProc,
domainSourcePointMaster
);
sourceFace.transfer(domainSourceFace);
sourceProc.transfer(domainSourceProc);
sourcePatch.transfer(domainSourcePatch);
sourceNewNbrProc.transfer(domainSourceNewNbrProc);
sourcePointMaster.transfer(domainSourcePointMaster);
}
@ -2107,6 +2245,7 @@ Foam::autoPtr<Foam::mapDistributePolyMesh> Foam::fvMeshDistribute::distribute
labelList domainSourceProc;
labelList domainSourcePatch;
labelList domainSourceNewNbrProc;
labelList domainSourcePointMaster;
autoPtr<fvMesh> domainMeshPtr;
@ -2143,6 +2282,7 @@ Foam::autoPtr<Foam::mapDistributePolyMesh> Foam::fvMeshDistribute::distribute
domainSourceProc,
domainSourcePatch,
domainSourceNewNbrProc,
domainSourcePointMaster,
str
);
fvMesh& domainMesh = domainMeshPtr();
@ -2410,6 +2550,15 @@ Foam::autoPtr<Foam::mapDistributePolyMesh> Foam::fvMeshDistribute::distribute
domainMesh.nInternalFaces(),
domainSourceNewNbrProc
);
// Update pointMaster data
sourcePointMaster = mapPointData
(
mesh_,
map(),
sourcePointMaster,
domainSourcePointMaster
);
// Update all addressing so xxProcAddressing points to correct
// item in masterMesh.
@ -2524,6 +2673,10 @@ Foam::autoPtr<Foam::mapDistributePolyMesh> Foam::fvMeshDistribute::distribute
}
// See if any originally shared points need to be merged. Note: does
// parallel comms. After this points and edges should again be consistent.
mergeSharedPoints(sourcePointMaster, constructPointMap);
// Add processorPatches
// ~~~~~~~~~~~~~~~~~~~~
@ -2553,16 +2706,8 @@ Foam::autoPtr<Foam::mapDistributePolyMesh> Foam::fvMeshDistribute::distribute
// Change patches. Since this might change ordering of coupled faces
// we also need to adapt our constructMaps.
// NOTE: there is one very particular problem with this structure.
// We first create the processor patches and use these to merge out
// shared points (see mergeSharedPoints below). So temporarily points
// and edges do not match!
repatch(newPatchID, constructFaceMap);
// See if any geometrically shared points need to be merged. Note: does
// parallel comms. After this points and edges should again be consistent.
mergeSharedPoints(constructPointMap);
// Bit of hack: processorFvPatchField does not get reset since created
// from nothing so explicitly reset.
initPatchFields<volScalarField, processorFvPatchField<scalar>>

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -163,11 +163,11 @@ class fvMeshDistribute
labelListList& constructFaceMap
);
//- Merge any shared points that are geometrically shared. Needs
// parallel valid mesh - uses globalMeshData.
//- Merge any local points that were remotely coupled.
// constructPointMap is adapted for the new point labels.
autoPtr<mapPolyMesh> mergeSharedPoints
(
const labelList& pointToGlobalMaster,
labelListList& constructPointMap
);
@ -175,19 +175,21 @@ class fvMeshDistribute
// Coupling information
//- Construct the local environment of all boundary faces.
void getNeighbourData
void getCouplingData
(
const labelList& distribution,
labelList& sourceFace,
labelList& sourceProc,
labelList& sourcePatch,
labelList& sourceNewProc
labelList& sourceNewProc,
labelList& sourcePointMaster
) const;
// Subset the neighbourCell/neighbourProc fields
static void subsetBoundaryData
static void subsetCouplingData
(
const fvMesh& mesh,
const labelList& pointMap,
const labelList& faceMap,
const labelList& cellMap,
@ -200,11 +202,13 @@ class fvMeshDistribute
const labelList& sourceProc,
const labelList& sourcePatch,
const labelList& sourceNewProc,
const labelList& sourcePointMaster,
labelList& subFace,
labelList& subProc,
labelList& subPatch,
labelList& subNewProc
labelList& subNewProc,
labelList& subPointMaster
);
//- Find cells on mesh whose faceID/procID match the neighbour
@ -237,6 +241,14 @@ class fvMeshDistribute
const labelList& boundaryData1 // added mesh
);
//- Map point data to new mesh (resulting from adding two meshes)
static labelList mapPointData
(
const primitiveMesh& mesh, // mesh after adding
const mapAddedPolyMesh& map,
const labelList& boundaryData0, // on mesh before adding
const labelList& boundaryData1 // on added mesh
);
// Other
@ -276,6 +288,7 @@ class fvMeshDistribute
const labelList& sourceProc,
const labelList& sourcePatch,
const labelList& sourceNewProc,
const labelList& sourcePointMaster,
Ostream& toDomain
);
//- Send subset of fields
@ -300,6 +313,7 @@ class fvMeshDistribute
labelList& domainSourceProc,
labelList& domainSourcePatch,
labelList& domainSourceNewProc,
labelList& domainSourcePointMaster,
Istream& fromNbr
);