Commit 2726b577 authored by mattijs's avatar mattijs
Browse files

topological point merging

parent 03f50a8b
......@@ -1737,85 +1737,218 @@ Foam::autoPtr<Foam::mapAddedPolyMesh> Foam::polyMeshAdder::add
Foam::Map<Foam::label> Foam::polyMeshAdder::findSharedPoints
(
const polyMesh& mesh,
const scalar mergeTol
const scalar mergeDist
)
{
const labelList& sharedPointLabels = mesh.globalData().sharedPointLabels();
const labelList& sharedPointAddr = mesh.globalData().sharedPointAddr();
labelList sharedToMerged;
pointField mergedPoints;
bool hasMerged = Foam::mergePoints
(
pointField
(
IndirectList<point>
(
mesh.points(),
sharedPointLabels
)()
),
mergeTol,
false,
sharedToMerged,
mergedPoints
);
// Because of adding the missing pieces e.g. when redistributing a mesh
// it can be that there are multiple points on the same processor that
// refer to the same shared point.
// Invert point-to-shared addressing
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Find out which sets of points get merged and create a map from
// mesh point to unique point.
Map<labelList> sharedToMesh(sharedPointLabels.size());
Map<label> pointToMaster(10*sharedToMerged.size());
label nMultiple = 0;
if (hasMerged)
forAll(sharedPointLabels, i)
{
labelListList mergeSets
(
invertOneToMany
(
sharedToMerged.size(),
sharedToMerged
)
);
label pointI = sharedPointLabels[i];
label nMergeSets = 0;
label sharedI = sharedPointAddr[i];
forAll(mergeSets, setI)
Map<labelList>::iterator iter = sharedToMesh.find(sharedI);
if (iter != sharedToMesh.end())
{
const labelList& mergeSet = mergeSets[setI];
// sharedI already used by other point. Add this one.
nMultiple++;
labelList& connectedPointLabels = iter();
if (mergeSet.size() > 1)
label sz = connectedPointLabels.size();
// Check just to make sure.
if (findIndex(connectedPointLabels, pointI) != -1)
{
// Take as master the shared point with the lowest mesh
// point label. (rather arbitrarily - could use max or any other
// one of the points)
FatalErrorIn("polyMeshAdder::findSharedPoints(..)")
<< "Duplicate point in sharedPoint addressing." << endl
<< "When trying to add point " << pointI << " on shared "
<< sharedI << " with connected points "
<< connectedPointLabels
<< abort(FatalError);
}
nMergeSets++;
connectedPointLabels.setSize(sz+1);
connectedPointLabels[sz] = pointI;
}
else
{
sharedToMesh.insert(sharedI, labelList(1, pointI));
}
}
label masterI = labelMax;
// Assign single master for every shared with multiple geometric points
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
forAll(mergeSet, i)
{
label sharedI = mergeSet[i];
Map<label> pointToMaster(nMultiple);
masterI = min(masterI, sharedPointLabels[sharedI]);
}
forAllConstIter(Map<labelList>, sharedToMesh, iter)
{
const labelList& connectedPointLabels = iter();
//Pout<< "For shared:" << iter.key()
// << " found points:" << connectedPointLabels
// << " at coords:"
// << pointField(mesh.points(), connectedPointLabels) << endl;
forAll(mergeSet, i)
if (connectedPointLabels.size() > 1)
{
const pointField connectedPoints
(
mesh.points(),
connectedPointLabels
);
labelList toMergedPoints;
pointField mergedPoints;
bool hasMerged = Foam::mergePoints
(
connectedPoints,
mergeDist,
false,
toMergedPoints,
mergedPoints
);
if (hasMerged)
{
// Invert toMergedPoints
const labelListList mergeSets
(
invertOneToMany
(
mergedPoints.size(),
toMergedPoints
)
);
// Find master for valid merges
forAll(mergeSets, setI)
{
label sharedI = mergeSet[i];
const labelList& mergeSet = mergeSets[setI];
pointToMaster.insert(sharedPointLabels[sharedI], masterI);
if (mergeSet.size() > 1)
{
// Pick lowest numbered point
label masterPointI = labelMax;
forAll(mergeSet, i)
{
label pointI = connectedPointLabels[mergeSet[i]];
masterPointI = min(masterPointI, pointI);
}
forAll(mergeSet, i)
{
label pointI = connectedPointLabels[mergeSet[i]];
//Pout<< "Merging point " << pointI
// << " at " << mesh.points()[pointI]
// << " into master point "
// << masterPointI
// << " at " << mesh.points()[masterPointI]
// << endl;
pointToMaster.insert(pointI, masterPointI);
}
}
}
}
}
//if (debug)
//{
// Pout<< "polyMeshAdder : merging:"
// << pointToMaster.size() << " into " << nMergeSets << " sets."
// << endl;
//}
}
//- Old: geometric merging. Causes problems for two close shared points.
//labelList sharedToMerged;
//pointField mergedPoints;
//bool hasMerged = Foam::mergePoints
//(
// pointField
// (
// IndirectList<point>
// (
// mesh.points(),
// sharedPointLabels
// )()
// ),
// mergeDist,
// false,
// sharedToMerged,
// mergedPoints
//);
//
//// Find out which sets of points get merged and create a map from
//// mesh point to unique point.
//
//Map<label> pointToMaster(10*sharedToMerged.size());
//
//if (hasMerged)
//{
// labelListList mergeSets
// (
// invertOneToMany
// (
// sharedToMerged.size(),
// sharedToMerged
// )
// );
//
// label nMergeSets = 0;
//
// forAll(mergeSets, setI)
// {
// const labelList& mergeSet = mergeSets[setI];
//
// if (mergeSet.size() > 1)
// {
// // Take as master the shared point with the lowest mesh
// // point label. (rather arbitrarily - could use max or
// // any other one of the points)
//
// nMergeSets++;
//
// label masterI = labelMax;
//
// forAll(mergeSet, i)
// {
// label sharedI = mergeSet[i];
//
// masterI = min(masterI, sharedPointLabels[sharedI]);
// }
//
// forAll(mergeSet, i)
// {
// label sharedI = mergeSet[i];
//
// pointToMaster.insert(sharedPointLabels[sharedI], masterI);
// }
// }
// }
//
// //if (debug)
// //{
// // Pout<< "polyMeshAdder : merging:"
// // << pointToMaster.size() << " into " << nMergeSets
// // << " sets." << endl;
// //}
//}
return pointToMaster;
}
......@@ -1836,8 +1969,7 @@ void Foam::polyMeshAdder::mergePoints
{
if (iter() != pointI)
{
//1.4.1: meshMod.removePoint(pointI, iter());
meshMod.setAction(polyRemovePoint(pointI));
meshMod.removePoint(pointI, iter());
}
}
}
......
Markdown is supported
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