26 #include "domainDecomposition.H"
54 label pointi = zoneElems[i];
56 if (elementToZone[pointi] == -1)
59 elementToZone[pointi] = zoneI;
61 else if (elementToZone[pointi] >= 0)
64 elementToZone[pointi] = -2;
76 const fileName& decompDictFile
80 facesInstancePointsPtr_
82 pointsInstance() != facesInstance()
98 decompDictFile_(decompDictFile),
103 decompositionModel::
New
107 ).
lookup(
"numberOfSubdomains")
111 cellToProc_(nCells()),
112 procPointAddressing_(nProcs_),
113 procFaceAddressing_(nProcs_),
114 procCellAddressing_(nProcs_),
115 procPatchSize_(nProcs_),
116 procPatchStartIndex_(nProcs_),
117 procNeighbourProcessors_(nProcs_),
118 procProcessorPatchSize_(nProcs_),
119 procProcessorPatchStartIndex_(nProcs_),
120 procProcessorPatchSubPatchIDs_(nProcs_),
121 procProcessorPatchSubPatchStarts_(nProcs_)
141 Info<<
"\nConstructing processor meshes" <<
endl;
154 forAll(pointZones(), zoneI)
156 mark(pointZones()[zoneI], zoneI, pointToZone);
160 labelList faceToZone(faces().size(), -1);
162 forAll(faceZones(), zoneI)
164 mark(faceZones()[zoneI], zoneI, faceToZone);
170 forAll(cellZones(), zoneI)
172 mark(cellZones()[zoneI], zoneI, cellToZone);
176 PtrList<const cellSet> cellSets;
177 PtrList<const faceSet> faceSets;
178 PtrList<const pointSet> pointSets;
182 IOobjectList objects(*
this, facesInstance(),
"polyMesh/sets");
184 IOobjectList cSets(objects.lookupClass(cellSet::typeName));
187 cellSets.append(
new cellSet(*iter()));
191 IOobjectList fSets(objects.lookupClass(faceSet::typeName));
194 faceSets.append(
new faceSet(*iter()));
198 IOobjectList pSets(objects.lookupClass(pointSet::typeName));
201 pointSets.append(
new pointSet(*iter()));
208 hexRef8Data baseMeshData
224 label maxProcCells = 0;
225 label totProcFaces = 0;
226 label maxProcPatches = 0;
227 label totProcPatches = 0;
228 label maxProcFaces = 0;
232 for (
label procI = 0; procI < nProcs_; procI++)
235 const labelList& curPointLabels = procPointAddressing_[procI];
243 forAll(curPointLabels, pointi)
245 procPoints[pointi] = meshPoints[curPointLabels[pointi]];
247 pointLookup[curPointLabels[pointi]] = pointi;
251 const labelList& curFaceLabels = procFaceAddressing_[procI];
253 const faceList& meshFaces = faces();
257 faceList procFaces(curFaceLabels.size());
259 forAll(curFaceLabels, facei)
264 label curF =
mag(curFaceLabels[facei]) - 1;
266 faceLookup[curF] = facei;
271 if (curFaceLabels[facei] >= 0)
274 origFaceLabels = meshFaces[curF];
278 origFaceLabels = meshFaces[curF].reverseFace();
282 face& procFaceLabels = procFaces[facei];
284 procFaceLabels.
setSize(origFaceLabels.size());
286 forAll(origFaceLabels, pointi)
288 procFaceLabels[pointi] = pointLookup[origFaceLabels[pointi]];
293 const labelList& curCellLabels = procCellAddressing_[procI];
297 cellList procCells(curCellLabels.size());
299 forAll(curCellLabels, celli)
301 const labelList& origCellLabels = meshCells[curCellLabels[celli]];
303 cell& curCell = procCells[celli];
305 curCell.
setSize(origCellLabels.size());
307 forAll(origCellLabels, cellFaceI)
309 curCell[cellFaceI] = faceLookup[origCellLabels[cellFaceI]];
315 fileName processorCasePath
317 time().caseName()/fileName(word(
"processor") +
Foam::name(procI))
321 mkDir(time().rootPath()/processorCasePath);
332 processorDb.setTime(time());
344 autoPtr<polyMesh> procMeshPtr;
346 if (facesInstancePointsPtr_.valid())
351 facesInstancePointsPtr_(),
389 polyMesh& procMesh = procMeshPtr();
393 const labelList& curPatchSizes = procPatchSize_[procI];
395 const labelList& curPatchStarts = procPatchStartIndex_[procI];
397 const labelList& curNeighbourProcessors =
398 procNeighbourProcessors_[procI];
400 const labelList& curProcessorPatchSizes =
401 procProcessorPatchSize_[procI];
403 const labelList& curProcessorPatchStarts =
404 procProcessorPatchStartIndex_[procI];
407 procProcessorPatchSubPatchIDs_[procI];
410 procProcessorPatchSubPatchStarts_[procI];
416 label nInterProcPatches = 0;
417 forAll(curSubPatchIDs, procPatchI)
430 nInterProcPatches += curSubPatchIDs[procPatchI].size();
442 reinterpret_cast<polyPatch*
>(0)
451 const polyPatch& meshPatch = meshPatches[
patchi];
453 fvFieldDecomposer::patchFieldDecomposer patchMapper
465 procPatches[
nPatches] = meshPatch.clone
467 procMesh.boundaryMesh(),
469 patchMapper.directAddressing(),
476 forAll(curProcessorPatchSizes, procPatchI)
478 const labelList& subPatchID = curSubPatchIDs[procPatchI];
479 const labelList& subStarts = curSubStarts[procPatchI];
481 label curStart = curProcessorPatchStarts[procPatchI];
487 i < subPatchID.size()-1
488 ? subStarts[i+1] - subStarts[i]
489 : curProcessorPatchSizes[procPatchI] - subStarts[i]
499 if (subPatchID[i] == -1)
503 new processorPolyPatch
507 +
Foam::name(curNeighbourProcessors[procPatchI]),
511 procMesh.boundaryMesh(),
513 curNeighbourProcessors[procPatchI]
518 const coupledPolyPatch& pcPatch
519 = refCast<const coupledPolyPatch>
521 boundaryMesh()[subPatchID[i]]
525 const word& referPatch = pcPatch.name();
528 new processorCyclicPolyPatch
532 +
Foam::name(curNeighbourProcessors[procPatchI])
538 procMesh.boundaryMesh(),
540 curNeighbourProcessors[procPatchI],
563 procMesh.addPatches(procPatches);
579 zonePoints[zoneI].setCapacity(pz[zoneI].size() / nProcs_);
584 forAll(curPointLabels, pointi)
586 label curPoint = curPointLabels[pointi];
588 label zoneI = pointToZone[curPoint];
593 zonePoints[zoneI].append(pointi);
595 else if (zoneI == -2)
600 label index = pz[zoneI].whichPoint(curPoint);
604 zonePoints[zoneI].append(pointi);
610 procMesh.pointZones().clearAddressing();
611 procMesh.pointZones().setSize(zonePoints.size());
614 procMesh.pointZones().set
619 procMesh.pointZones(),
621 zonePoints[zoneI].shrink()
646 label procSize = fz[zoneI].size() / nProcs_;
648 zoneFaces[zoneI].setCapacity(procSize);
649 zoneFaceFlips[zoneI].setCapacity(procSize);
655 forAll(curFaceLabels, facei)
659 label curF =
mag(curFaceLabels[facei]) - 1;
661 label zoneI = faceToZone[curF];
666 zoneFaces[zoneI].append(facei);
668 label index = fz[zoneI].whichFace(curF);
670 bool flip = fz[zoneI].flipMap()[index];
672 if (curFaceLabels[facei] < 0)
677 zoneFaceFlips[zoneI].append(flip);
679 else if (zoneI == -2)
684 label index = fz[zoneI].whichFace(curF);
688 zoneFaces[zoneI].append(facei);
690 bool flip = fz[zoneI].flipMap()[index];
692 if (curFaceLabels[facei] < 0)
697 zoneFaceFlips[zoneI].append(flip);
703 procMesh.faceZones().clearAddressing();
704 procMesh.faceZones().setSize(zoneFaces.size());
707 procMesh.faceZones().set
712 zoneFaces[zoneI].shrink(),
713 zoneFaceFlips[zoneI].shrink(),
739 zoneCells[zoneI].setCapacity(cz[zoneI].size() / nProcs_);
742 forAll(curCellLabels, celli)
744 label curCellI = curCellLabels[celli];
746 label zoneI = cellToZone[curCellI];
751 zoneCells[zoneI].append(celli);
753 else if (zoneI == -2)
758 label index = cz[zoneI].whichCell(curCellI);
762 zoneCells[zoneI].append(celli);
768 procMesh.cellZones().clearAddressing();
769 procMesh.cellZones().setSize(zoneCells.size());
772 procMesh.cellZones().set
777 zoneCells[zoneI].shrink(),
797 if (facesInstancePointsPtr_.valid())
813 pointsInstancePoints.write();
822 const cellSet& cs = cellSets[i];
823 cellSet set(procMesh, cs.name(), cs.size()/nProcs_);
826 if (cs.found(curCellLabels[i]))
835 const faceSet& cs = faceSets[i];
836 faceSet set(procMesh, cs.name(), cs.size()/nProcs_);
839 if (cs.found(
mag(curFaceLabels[i])-1))
848 const pointSet& cs = pointSets[i];
849 pointSet set(procMesh, cs.name(), cs.size()/nProcs_);
852 if (cs.found(curPointLabels[i]))
876 procCellAddressing_[procI],
877 procPointAddressing_[procI]
884 <<
"Processor " << procI <<
nl
885 <<
" Number of cells = " << procMesh.nCells()
888 maxProcCells =
max(maxProcCells, procMesh.nCells());
890 label nBoundaryFaces = 0;
891 label nProcPatches = 0;
892 label nProcFaces = 0;
896 if (isA<processorPolyPatch>(procMesh.boundaryMesh()[
patchi]))
898 const processorPolyPatch& ppp =
899 refCast<const processorPolyPatch>
901 procMesh.boundaryMesh()[
patchi]
904 Info<<
" Number of faces shared with processor "
905 << ppp.neighbProcNo() <<
" = " << ppp.size() <<
endl;
908 nProcFaces += ppp.size();
912 nBoundaryFaces += procMesh.boundaryMesh()[
patchi].size();
916 Info<<
" Number of processor patches = " << nProcPatches <<
nl
917 <<
" Number of processor faces = " << nProcFaces <<
nl
918 <<
" Number of boundary faces = " << nBoundaryFaces <<
endl;
920 totProcFaces += nProcFaces;
921 totProcPatches += nProcPatches;
922 maxProcPatches =
max(maxProcPatches, nProcPatches);
923 maxProcFaces =
max(maxProcFaces, nProcFaces);
930 "pointProcAddressing",
931 procMesh.facesInstance(),
937 procPointAddressing_[procI]
939 pointProcAddressing.write();
945 "faceProcAddressing",
946 procMesh.facesInstance(),
952 procFaceAddressing_[procI]
960 "cellProcAddressing",
961 procMesh.facesInstance(),
967 procCellAddressing_[procI]
969 cellProcAddressing.write();
973 label nMeshPatches = curPatchSizes.size();
975 procBoundaryAddressing.setSize(nMeshPatches+nProcPatches, -1);
981 "boundaryProcAddressing",
982 procMesh.facesInstance(),
988 procBoundaryAddressing
990 boundaryProcAddressing.write();
993 scalar avgProcCells = scalar(nCells())/nProcs_;
994 scalar avgProcPatches = scalar(totProcPatches)/nProcs_;
995 scalar avgProcFaces = scalar(totProcFaces)/nProcs_;
998 if (totProcPatches == 0)
1002 if (totProcFaces == 0)
1008 <<
"Number of processor faces = " << totProcFaces/2 <<
nl
1009 <<
"Max number of cells = " << maxProcCells
1010 <<
" (" << 100.0*(maxProcCells-avgProcCells)/avgProcCells
1011 <<
"% above average " << avgProcCells <<
")" <<
nl
1012 <<
"Max number of processor patches = " << maxProcPatches
1013 <<
" (" << 100.0*(maxProcPatches-avgProcPatches)/avgProcPatches
1014 <<
"% above average " << avgProcPatches <<
")" <<
nl
1015 <<
"Max number of faces between processors = " << maxProcFaces
1016 <<
" (" << 100.0*(maxProcFaces-avgProcFaces)/avgProcFaces
1017 <<
"% above average " << avgProcFaces <<
")" <<
nl