ENH: 2 or 8 procs. pointFile only inserts on one proc.

This commit is contained in:
graham
2011-04-04 17:19:45 +01:00
parent 5fcd183b8b
commit f37e7ff7d9
6 changed files with 324 additions and 113 deletions

View File

@ -563,123 +563,206 @@ void Foam::conformalVoronoiMesh::buildParallelInterface
return; return;
} }
{
// Update the bounds of the domain
Info<< "USING SINGLE PROCESSOR PER DOMAIN" << endl;
DynamicList<Foam::point> parallelAllPoints;
DynamicList<label> targetProcessor;
DynamicList<label> parallelAllIndices;
Foam::point minPt(VGREAT, VGREAT, VGREAT);
Foam::point maxPt(-VGREAT, -VGREAT, -VGREAT);
for
(
Delaunay::Finite_vertices_iterator vit = finite_vertices_begin();
vit != finite_vertices_end();
vit++
)
{
if (vit->real())
{
Foam::point v = topoint(vit->point());
minPt = Foam::min(minPt, v);
maxPt = Foam::max(maxPt, v);
}
}
Pout<< "Before processorDomains update"
<< geometryToConformTo_.processorDomains()[Pstream::myProcNo()]
<< endl;
geometryToConformTo_.processorDomains()[Pstream::myProcNo()][0] =
treeBoundBox(minPt, maxPt);
Pout<< "After processorDomains update"
<< geometryToConformTo_.processorDomains()[Pstream::myProcNo()]
<< endl;
{
OFstream str
(
runTime_.path()
/"procDomainUpdated_"
+ name(Pstream::myProcNo())
+ "_bounds.obj"
);
Pout<< "Writing " << str.name() << endl;
pointField bbPoints
(
geometryToConformTo_.processorDomains()
[
Pstream::myProcNo()
][0].points()
);
forAll(bbPoints, i)
{
meshTools::writeOBJ(str, bbPoints[i]);
}
forAll(treeBoundBox::faces, i)
{
const face& f = treeBoundBox::faces[i];
str << "f"
<< ' ' << f[0] + 1
<< ' ' << f[1] + 1
<< ' ' << f[2] + 1
<< ' ' << f[3] + 1
<< nl;
}
}
Pstream::gatherList(geometryToConformTo_.processorDomains());
Pstream::scatterList(geometryToConformTo_.processorDomains());
}
boolList sendToProc(Pstream::nProcs(), false); boolList sendToProc(Pstream::nProcs(), false);
// { bool allPointReferral = false;
// // Refer all points to all processors
// DynamicList<Foam::point> parallelAllPoints; if (allPointReferral)
// DynamicList<label> targetProcessor; {
// DynamicList<label> parallelAllIndices; // Refer all points to all processors
// for DynamicList<Foam::point> parallelAllPoints;
// ( DynamicList<label> targetProcessor;
// Delaunay::Finite_vertices_iterator vit = finite_vertices_begin(); DynamicList<label> parallelAllIndices;
// vit != finite_vertices_end();
// vit++
// )
// {
// if (!vit->farPoint())
// {
// sendToProc = true;
// sendToProc[Pstream::myProcNo()] = false; for
(
Delaunay::Finite_vertices_iterator vit = finite_vertices_begin();
vit != finite_vertices_end();
vit++
)
{
if (!vit->farPoint())
{
sendToProc = true;
// forAll(sendToProc, procI) sendToProc[Pstream::myProcNo()] = false;
// {
// if (sendToProc[procI])
// {
// label vIndex = vit->index();
// // Using the hashSet to ensure that each vertex is forAll(sendToProc, procI)
// // only referred once to each processor {
// if (!referralVertices[procI].found(vIndex)) if (sendToProc[procI])
// { {
// referralVertices[procI].insert(vIndex); label vIndex = vit->index();
// parallelAllPoints.append // Using the hashSet to ensure that each vertex is
// ( // only referred once to each processor
// topoint(vit->point()) if (!referralVertices[procI].found(vIndex))
// ); {
referralVertices[procI].insert(vIndex);
// targetProcessor.append(procI); parallelAllPoints.append
(
topoint(vit->point())
);
// if (vit->internalOrBoundaryPoint()) targetProcessor.append(procI);
// {
// parallelAllIndices.append(vIndex);
// }
// else
// {
// parallelAllIndices.append(-vIndex);
// }
// }
// }
// }
// }
// }
// if (cvMeshControls().objOutput()) if (vit->internalOrBoundaryPoint())
// { {
// writePoints parallelAllIndices.append(vIndex);
// ( }
// "parallelAllPointsToSend.obj", else
// parallelAllPoints {
// ); parallelAllIndices.append(-vIndex);
// } }
}
}
}
}
}
// mapDistribute pointMap = buildReferringMap(targetProcessor); if (cvMeshControls().objOutput())
{
writePoints
(
"parallelAllPointsToSend.obj",
parallelAllPoints
);
}
// label totalAllVertices = parallelAllPoints.size(); mapDistribute pointMap = buildReferringMap(targetProcessor);
// reduce(totalAllVertices, sumOp<label>()); label totalAllVertices = parallelAllPoints.size();
// pointMap.distribute(parallelAllPoints); reduce(totalAllVertices, sumOp<label>());
// pointMap.distribute(parallelAllIndices); pointMap.distribute(parallelAllPoints);
// if (cvMeshControls().objOutput()) pointMap.distribute(parallelAllIndices);
// {
// writePoints
// (
// "parallelAllPointsReceived_" + outputName + ".obj",
// parallelAllPoints
// );
// }
// for (label procI = 0; procI < Pstream::nProcs(); procI++) if (cvMeshControls().objOutput())
// { {
// const labelList& constructMap = pointMap.constructMap()[procI]; writePoints
(
"parallelAllPointsReceived_" + outputName + ".obj",
parallelAllPoints
);
}
// if (constructMap.size()) for (label procI = 0; procI < Pstream::nProcs(); procI++)
// { {
// forAll(constructMap, i) const labelList& constructMap = pointMap.constructMap()[procI];
// {
// label origIndex =
// parallelAllIndices[constructMap[i]];
// if (!receivedVertices[procI].found(origIndex)) if (constructMap.size())
// { {
// // For the initial referred vertices, the original forAll(constructMap, i)
// // processor is the one that is sending it. {
// label encodedProcI = -(procI + 1); label origIndex =
parallelAllIndices[constructMap[i]];
// insertPoint if (!receivedVertices[procI].found(origIndex))
// ( {
// parallelAllPoints[constructMap[i]], // For the initial referred vertices, the original
// origIndex, // processor is the one that is sending it.
// encodedProcI label encodedProcI = -(procI + 1);
// );
// receivedVertices[procI].insert(origIndex); insertPoint
// } (
// } parallelAllPoints[constructMap[i]],
// } origIndex,
// } encodedProcI
);
// Info<< "totalAllVertices " receivedVertices[procI].insert(origIndex);
// << totalAllVertices << endl; }
// } }
}
}
Info<< "totalAllVertices "
<< totalAllVertices << endl;
}
if (initialEdgeReferrral) if (initialEdgeReferrral)
{ {
@ -779,6 +862,12 @@ void Foam::conformalVoronoiMesh::buildParallelInterface
// processor is the one that is sending it. // processor is the one that is sending it.
label encodedProcI = -(procI + 1); label encodedProcI = -(procI + 1);
// Pout<< "Insert "
// << parallelIntersectionPoints[constructMap[i]]
// << " " << origIndex
// << " " << procI
// << endl;
insertPoint insertPoint
( (
parallelIntersectionPoints[constructMap[i]], parallelIntersectionPoints[constructMap[i]],
@ -893,6 +982,12 @@ void Foam::conformalVoronoiMesh::buildParallelInterface
// processor is the one that is sending it. // processor is the one that is sending it.
label encodedProcI = -(procI + 1); label encodedProcI = -(procI + 1);
// Pout<< "Insert "
// << parallelInfluencePoints[constructMap[i]]
// << " " << origIndex
// << " " << procI
// << endl;
insertPoint insertPoint
( (
parallelInfluencePoints[constructMap[i]], parallelInfluencePoints[constructMap[i]],
@ -1112,14 +1207,8 @@ void Foam::conformalVoronoiMesh::parallelInterfaceInfluence
); );
// Pout<< nl << "# circumradius " << sqrt(circumradiusSqr) << endl; // Pout<< nl << "# circumradius " << sqrt(circumradiusSqr) << endl;
// drawDelaunayCell(Pout, cit); // drawDelaunayCell(Pout, cit);
// meshTools::writeOBJ(Pout, topoint(cit->vertex(0)->point()));
// meshTools::writeOBJ(Pout, circumcentre);
// Pout<< "l cr0 cr1" << endl;
forAll(geometryToConformTo_.processorDomains(), procI) forAll(geometryToConformTo_.processorDomains(), procI)
{ {
if (procI == Pstream::myProcNo()) if (procI == Pstream::myProcNo())

View File

@ -85,10 +85,14 @@ void Foam::conformalVoronoiMesh::drawDelaunayCell
const Delaunay::Finite_cells_iterator& cit const Delaunay::Finite_cells_iterator& cit
) const ) const
{ {
meshTools::writeOBJ(os, topoint(cit->vertex(0)->point())); for (int i = 0; i < 4; i++)
meshTools::writeOBJ(os, topoint(cit->vertex(1)->point())); {
meshTools::writeOBJ(os, topoint(cit->vertex(2)->point())); os << "# index type: "
meshTools::writeOBJ(os, topoint(cit->vertex(3)->point())); << label(cit->vertex(i)->index()) << " "
<< label(cit->vertex(i)->type()) << endl;
meshTools::writeOBJ(os, topoint(cit->vertex(i)->point()));
}
os << "f 1 3 2" << nl os << "f 1 3 2" << nl
<< "f 2 3 4" << nl << "f 2 3 4" << nl

View File

@ -246,9 +246,45 @@ Foam::conformationSurfaces::conformationSurfaces
if (Pstream::parRun()) if (Pstream::parRun())
{ {
label procLimit = 8; processorDomains_.setSize(Pstream::nProcs());
if (Pstream::nProcs() != procLimit) if (Pstream::nProcs() == 2)
{
processorDomains_[Pstream::myProcNo()] = treeBoundBoxList(4);
forAll(processorDomains_[Pstream::myProcNo()], pDI)
{
processorDomains_[Pstream::myProcNo()][pDI] =
globalBounds_.subBbox
(
direction(Pstream::myProcNo()*4 + pDI)
);
}
DynamicList<Foam::point> allBbPoints;
forAll(processorDomains_[Pstream::myProcNo()], pDI)
{
allBbPoints.append
(
processorDomains_[Pstream::myProcNo()][pDI].points()
);
}
bounds_ = treeBoundBox(allBbPoints);
// Replace 4 bound boxes with one
processorDomains_[Pstream::myProcNo()] =
treeBoundBoxList(1, bounds_);
}
else if (Pstream::nProcs() == 8)
{
bounds_ = globalBounds_.subBbox(direction(Pstream::myProcNo()));
processorDomains_[Pstream::myProcNo()] =
treeBoundBoxList(1, bounds_);
}
else
{ {
FatalErrorIn FatalErrorIn
( (
@ -259,16 +295,10 @@ Foam::conformationSurfaces::conformationSurfaces
"const dictionary& surfaceConformationDict" "const dictionary& surfaceConformationDict"
")" ")"
) )
<< "Hard coded to " << procLimit << " << procs" << "Hard coded to " << "2 or 8" << " procs"
<< exit(FatalError); << exit(FatalError);
} }
bounds_ = globalBounds_.subBbox(direction(Pstream::myProcNo()));
processorDomains_.setSize(Pstream::nProcs());
processorDomains_[Pstream::myProcNo()] = treeBoundBoxList(1, bounds_);
Pstream::gatherList(processorDomains_); Pstream::gatherList(processorDomains_);
Pstream::scatterList(processorDomains_); Pstream::scatterList(processorDomains_);
@ -379,9 +409,29 @@ bool Foam::conformationSurfaces::positionOnThisProc(const point& pt) const
// This is likely to give problems when a point is on the boundary between // This is likely to give problems when a point is on the boundary between
// two processors. // two processors.
if (Pstream::parRun())
{
const treeBoundBoxList& procBbs =
processorDomains_[Pstream::myProcNo()];
forAll(procBbs, pBI)
{
const treeBoundBox& procBb = procBbs[pBI];
if (procBb.contains(pt))
{
return true;
}
}
}
else
{
return bounds_.contains(pt); return bounds_.contains(pt);
} }
return false;
}
Foam::Field<bool> Foam::conformationSurfaces::inside Foam::Field<bool> Foam::conformationSurfaces::inside
( (

View File

@ -166,6 +166,9 @@ public:
//- Return spanSqr //- Return spanSqr
inline scalar spanMagSqr() const; inline scalar spanMagSqr() const;
//- Return non-const access to the processorDomains
inline List<treeBoundBoxList>& processorDomains();
//- Return the processorDomains //- Return the processorDomains
inline const List<treeBoundBoxList>& processorDomains() const; inline const List<treeBoundBoxList>& processorDomains() const;

View File

@ -74,6 +74,13 @@ inline Foam::scalar Foam::conformationSurfaces::spanMagSqr() const
} }
inline Foam::List<Foam::treeBoundBoxList>&
Foam::conformationSurfaces::processorDomains()
{
return processorDomains_;
}
inline const Foam::List<Foam::treeBoundBoxList>& inline const Foam::List<Foam::treeBoundBoxList>&
Foam::conformationSurfaces::processorDomains() const Foam::conformationSurfaces::processorDomains() const
{ {

View File

@ -85,6 +85,64 @@ std::vector<Vb::Point> pointFile::initialPoints() const
); );
} }
if (Pstream::parRun())
{
List<boolList> allProcPt(Pstream::nProcs());
allProcPt[Pstream::myProcNo()] = procPt;
Pstream::gatherList(allProcPt);
Pstream::scatterList(allProcPt);
// forAll(procPt, ptI)
// {
// label nProcsTrue = 0;
// forAll(allProcPt, procI)
// {
// if (allProcPt[procI][ptI])
// {
// nProcsTrue++;
// }
// }
// if (nProcsTrue != 1)
// {
// Info<< points[ptI] << " " << nProcsTrue << " true" << endl;
// if (nProcsTrue > 1)
// {
// forAll(allProcPt, procI)
// {
// allProcPt[procI][ptI] = false;
// }
// }
// }
// }
forAll(procPt, ptI)
{
bool foundAlready = false;
forAll(allProcPt, procI)
{
// If a processor with a lower index has found this point to
// insert already, defer to it and don't insert.
if (foundAlready)
{
allProcPt[procI][ptI] = false;
}
else if (allProcPt[procI][ptI])
{
foundAlready = true;
}
}
}
procPt = allProcPt[Pstream::myProcNo()];
}
inplaceSubset(procPt, points); inplaceSubset(procPt, points);
std::vector<Vb::Point> initialPoints; std::vector<Vb::Point> initialPoints;