45 void Foam::domainDecomposition::mark
54 label pointi = zoneElems[i];
56 if (elementToZone[pointi] == -1)
59 elementToZone[pointi] = zoneI;
61 else if (elementToZone[pointi] >= 0)
64 elementToZone[pointi] = -2;
75 facesInstancePointsPtr_
97 decompositionModel::
New 100 ).
lookup(
"numberOfSubdomains")
105 procPointAddressing_(nProcs_),
106 procFaceAddressing_(nProcs_),
107 procCellAddressing_(nProcs_),
108 procPatchSize_(nProcs_),
109 procPatchStartIndex_(nProcs_),
110 procNeighbourProcessors_(nProcs_),
111 procProcessorPatchSize_(nProcs_),
112 procProcessorPatchStartIndex_(nProcs_),
113 procProcessorPatchSubPatchIDs_(nProcs_),
114 procProcessorPatchSubPatchStarts_(nProcs_)
133 Info<<
"\nConstructing processor meshes" <<
endl;
146 forAll(pointZones(), zoneI)
148 mark(pointZones()[zoneI], zoneI, pointToZone);
152 labelList faceToZone(faces().size(), -1);
154 forAll(faceZones(), zoneI)
156 mark(faceZones()[zoneI], zoneI, faceToZone);
162 forAll(cellZones(), zoneI)
164 mark(cellZones()[zoneI], zoneI, cellToZone);
168 PtrList<const cellSet> cellSets;
169 PtrList<const faceSet> faceSets;
170 PtrList<const pointSet> pointSets;
174 IOobjectList objects(*
this, facesInstance(),
"polyMesh/sets");
176 IOobjectList cSets(objects.lookupClass(cellSet::typeName));
179 cellSets.append(
new cellSet(*iter()));
183 IOobjectList fSets(objects.lookupClass(faceSet::typeName));
186 faceSets.append(
new faceSet(*iter()));
190 IOobjectList pSets(objects.lookupClass(pointSet::typeName));
193 pointSets.append(
new pointSet(*iter()));
200 hexRef8Data baseMeshData
216 label maxProcCells = 0;
217 label totProcFaces = 0;
218 label maxProcPatches = 0;
219 label totProcPatches = 0;
220 label maxProcFaces = 0;
224 for (
label proci = 0; proci < nProcs_; proci++)
227 const labelList& curPointLabels = procPointAddressing_[proci];
235 forAll(curPointLabels, pointi)
237 procPoints[pointi] = meshPoints[curPointLabels[pointi]];
239 pointLookup[curPointLabels[pointi]] = pointi;
243 const labelList& curFaceLabels = procFaceAddressing_[proci];
245 const faceList& meshFaces = faces();
249 faceList procFaces(curFaceLabels.size());
251 forAll(curFaceLabels, facei)
256 label curF =
mag(curFaceLabels[facei]) - 1;
258 faceLookup[curF] = facei;
263 if (curFaceLabels[facei] >= 0)
266 origFaceLabels = meshFaces[curF];
270 origFaceLabels = meshFaces[curF].reverseFace();
274 face& procFaceLabels = procFaces[facei];
276 procFaceLabels.
setSize(origFaceLabels.size());
278 forAll(origFaceLabels, pointi)
280 procFaceLabels[pointi] = pointLookup[origFaceLabels[pointi]];
285 const labelList& curCellLabels = procCellAddressing_[proci];
289 cellList procCells(curCellLabels.size());
291 forAll(curCellLabels, celli)
293 const labelList& origCellLabels = meshCells[curCellLabels[celli]];
295 cell& curCell = procCells[celli];
297 curCell.
setSize(origCellLabels.size());
299 forAll(origCellLabels, cellFacei)
301 curCell[cellFacei] = faceLookup[origCellLabels[cellFacei]];
307 fileName processorCasePath
309 time().caseName()/fileName(word(
"processor") +
Foam::name(proci))
313 mkDir(time().rootPath()/processorCasePath);
324 processorDb.setTime(time());
336 autoPtr<polyMesh> procMeshPtr;
338 if (facesInstancePointsPtr_.valid())
343 facesInstancePointsPtr_(),
381 polyMesh& procMesh = procMeshPtr();
385 const labelList& curPatchSizes = procPatchSize_[proci];
387 const labelList& curPatchStarts = procPatchStartIndex_[proci];
389 const labelList& curNeighbourProcessors =
390 procNeighbourProcessors_[proci];
392 const labelList& curProcessorPatchSizes =
393 procProcessorPatchSize_[proci];
395 const labelList& curProcessorPatchStarts =
396 procProcessorPatchStartIndex_[proci];
399 procProcessorPatchSubPatchIDs_[proci];
402 procProcessorPatchSubPatchStarts_[proci];
408 label nInterProcPatches = 0;
409 forAll(curSubPatchIDs, procPatchi)
411 nInterProcPatches += curSubPatchIDs[procPatchi].size();
414 List<polyPatch*> procPatches
416 curPatchSizes.size() + nInterProcPatches,
417 reinterpret_cast<polyPatch*
>(0)
422 forAll(curPatchSizes, patchi)
426 const polyPatch& meshPatch = meshPatches[
patchi];
428 fvFieldDecomposer::patchFieldDecomposer patchMapper
433 curPatchSizes[patchi],
434 curPatchStarts[patchi]
440 procPatches[
nPatches] = meshPatch.clone
442 procMesh.boundaryMesh(),
444 patchMapper.directAddressing(),
451 forAll(curProcessorPatchSizes, procPatchi)
453 const labelList& subPatchID = curSubPatchIDs[procPatchi];
454 const labelList& subStarts = curSubStarts[procPatchi];
456 label curStart = curProcessorPatchStarts[procPatchi];
462 i < subPatchID.size()-1
463 ? subStarts[i+1] - subStarts[i]
464 : curProcessorPatchSizes[procPatchi] - subStarts[i]
467 if (subPatchID[i] == -1)
471 new processorPolyPatch
476 procMesh.boundaryMesh(),
478 curNeighbourProcessors[procPatchi]
483 const coupledPolyPatch& pcPatch
484 = refCast<const coupledPolyPatch>
486 boundaryMesh()[subPatchID[i]]
490 new processorCyclicPolyPatch
495 procMesh.boundaryMesh(),
497 curNeighbourProcessors[procPatchi],
510 procMesh.addPatches(procPatches);
521 List<DynamicList<label>> zonePoints(pz.size());
526 zonePoints[zoneI].setCapacity(pz[zoneI].size() / nProcs_);
531 forAll(curPointLabels, pointi)
533 label curPoint = curPointLabels[pointi];
535 label zoneI = pointToZone[curPoint];
540 zonePoints[zoneI].append(pointi);
542 else if (zoneI == -2)
547 label index = pz[zoneI].whichPoint(curPoint);
551 zonePoints[zoneI].append(pointi);
557 procMesh.pointZones().clearAddressing();
558 procMesh.pointZones().setSize(zonePoints.size());
561 procMesh.pointZones().set
566 procMesh.pointZones(),
568 zonePoints[zoneI].shrink()
587 List<DynamicList<label>> zoneFaces(fz.size());
588 List<DynamicList<bool>> zoneFaceFlips(fz.size());
593 label procSize = fz[zoneI].size() / nProcs_;
595 zoneFaces[zoneI].setCapacity(procSize);
596 zoneFaceFlips[zoneI].setCapacity(procSize);
602 forAll(curFaceLabels, facei)
606 label curF =
mag(curFaceLabels[facei]) - 1;
608 label zoneI = faceToZone[curF];
613 zoneFaces[zoneI].append(facei);
615 label index = fz[zoneI].whichFace(curF);
617 bool flip = fz[zoneI].flipMap()[index];
619 if (curFaceLabels[facei] < 0)
624 zoneFaceFlips[zoneI].append(flip);
626 else if (zoneI == -2)
631 label index = fz[zoneI].whichFace(curF);
635 zoneFaces[zoneI].append(facei);
637 bool flip = fz[zoneI].flipMap()[index];
639 if (curFaceLabels[facei] < 0)
644 zoneFaceFlips[zoneI].append(flip);
650 procMesh.faceZones().clearAddressing();
651 procMesh.faceZones().setSize(zoneFaces.size());
654 procMesh.faceZones().set
659 zoneFaces[zoneI].shrink(),
660 zoneFaceFlips[zoneI].shrink(),
681 List<DynamicList<label>> zoneCells(cz.size());
686 zoneCells[zoneI].setCapacity(cz[zoneI].size() / nProcs_);
689 forAll(curCellLabels, celli)
691 label curCelli = curCellLabels[celli];
693 label zoneI = cellToZone[curCelli];
698 zoneCells[zoneI].append(celli);
700 else if (zoneI == -2)
705 label index = cz[zoneI].whichCell(curCelli);
709 zoneCells[zoneI].append(celli);
715 procMesh.cellZones().clearAddressing();
716 procMesh.cellZones().setSize(zoneCells.size());
719 procMesh.cellZones().set
724 zoneCells[zoneI].shrink(),
744 if (facesInstancePointsPtr_.valid())
760 pointsInstancePoints.write();
769 const cellSet& cs = cellSets[i];
770 cellSet
set(procMesh, cs.name(), cs.size()/nProcs_);
773 if (cs.found(curCellLabels[i]))
782 const faceSet& cs = faceSets[i];
783 faceSet
set(procMesh, cs.name(), cs.size()/nProcs_);
786 if (cs.found(
mag(curFaceLabels[i])-1))
795 const pointSet& cs = pointSets[i];
796 pointSet
set(procMesh, cs.name(), cs.size()/nProcs_);
799 if (cs.found(curPointLabels[i]))
823 procCellAddressing_[proci],
824 procPointAddressing_[proci]
831 <<
"Processor " << proci <<
nl 832 <<
" Number of cells = " << procMesh.nCells()
835 maxProcCells =
max(maxProcCells, procMesh.nCells());
837 label nBoundaryFaces = 0;
838 label nProcPatches = 0;
839 label nProcFaces = 0;
843 if (isA<processorPolyPatch>(procMesh.boundaryMesh()[
patchi]))
845 const processorPolyPatch& ppp =
846 refCast<const processorPolyPatch>
848 procMesh.boundaryMesh()[
patchi]
851 Info<<
" Number of faces shared with processor " 852 << ppp.neighbProcNo() <<
" = " << ppp.size() <<
endl;
855 nProcFaces += ppp.size();
859 nBoundaryFaces += procMesh.boundaryMesh()[
patchi].size();
863 Info<<
" Number of processor patches = " << nProcPatches <<
nl 864 <<
" Number of processor faces = " << nProcFaces <<
nl 865 <<
" Number of boundary faces = " << nBoundaryFaces <<
endl;
867 totProcFaces += nProcFaces;
868 totProcPatches += nProcPatches;
869 maxProcPatches =
max(maxProcPatches, nProcPatches);
870 maxProcFaces =
max(maxProcFaces, nProcFaces);
877 "pointProcAddressing",
878 procMesh.facesInstance(),
884 procPointAddressing_[proci]
886 pointProcAddressing.write();
892 "faceProcAddressing",
893 procMesh.facesInstance(),
899 procFaceAddressing_[proci]
907 "cellProcAddressing",
908 procMesh.facesInstance(),
914 procCellAddressing_[proci]
916 cellProcAddressing.write();
920 label nMeshPatches = curPatchSizes.size();
922 procBoundaryAddressing.setSize(nMeshPatches+nProcPatches, -1);
928 "boundaryProcAddressing",
929 procMesh.facesInstance(),
935 procBoundaryAddressing
937 boundaryProcAddressing.write();
940 scalar avgProcCells = scalar(nCells())/nProcs_;
941 scalar avgProcPatches = scalar(totProcPatches)/nProcs_;
942 scalar avgProcFaces = scalar(totProcFaces)/nProcs_;
945 if (totProcPatches == 0)
949 if (totProcFaces == 0)
955 <<
"Number of processor faces = " << totProcFaces/2 <<
nl 956 <<
"Max number of cells = " << maxProcCells
957 <<
" (" << 100.0*(maxProcCells-avgProcCells)/avgProcCells
958 <<
"% above average " << avgProcCells <<
")" <<
nl 959 <<
"Max number of processor patches = " << maxProcPatches
960 <<
" (" << 100.0*(maxProcPatches-avgProcPatches)/avgProcPatches
961 <<
"% above average " << avgProcPatches <<
")" <<
nl 962 <<
"Max number of faces between processors = " << maxProcFaces
963 <<
" (" << 100.0*(maxProcFaces-avgProcFaces)/avgProcFaces
964 <<
"% above average " << avgProcFaces <<
")" <<
nl
PtrList< polyPatch > polyPatchList
container classes for polyPatch
List< labelList > labelListList
A List of labelList.
bool writeDecomposition(const bool decomposeSets)
Write decomposition.
ZoneMesh< faceZone, polyMesh > faceZoneMesh
A ZoneMesh with the type faceZone.
#define forAll(list, i)
Loop across all elements in list.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
static const decompositionModel & New(const polyMesh &mesh, const fileName &decompDictFile="")
Read (optionallly from absolute path) & register on mesh.
const fileName & facesInstance() const
Return the current instance directory for faces.
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
vectorIOField pointIOField
pointIOField is a vectorIOField.
PtrList< labelIOList > & faceProcAddressing
static word meshSubDir
Return the mesh sub-directory name (usually "polyMesh")
static unsigned int defaultPrecision()
Return the default precision.
IOobject(const word &name, const fileName &instance, const objectRegistry ®istry, readOption r=NO_READ, writeOption w=NO_WRITE, bool registerObject=true)
Construct from name, instance, registry, io options.
Ostream & endl(Ostream &os)
Add newline and flush stream.
domainDecomposition(const IOobject &io)
Construct from IOobject.
labelList identity(const label len)
Create identity map (map[i] == i) of given length.
~domainDecomposition()
Destructor.
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
vectorField pointField
pointField is a vectorField.
Xfer< T > xferMove(T &)
Construct by transferring the contents of the arg.
bool readIfPresent(const word &, T &, bool recursive=false, bool patternMatch=true) const
Find an entry if present, and assign to T.
List< label > labelList
A List of labels.
ZoneMesh< pointZone, polyMesh > pointZoneMesh
A ZoneMesh with the type pointZone.
static word controlDictName
The default control dictionary name (normally "controlDict")
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
static autoPtr< dictionary > New(Istream &)
Construct top-level dictionary on freestore from Istream.
bool mkDir(const fileName &, mode_t=0777)
Make a directory and return an error if it could not be created.
word name(const complex &)
Return a string representation of a complex.
fvMesh(const IOobject &io)
Construct from IOobject.
void setSize(const label)
Reset size of List.
const fileName & pointsInstance() const
Return the current instance directory for points.
dimensioned< scalar > mag(const dimensioned< Type > &)
List< cell > cellList
list of cells
ZoneMesh< cellZone, polyMesh > cellZoneMesh
A ZoneMesh with the type cellZone.
const word & name() const
Return name.
IOList< label > labelIOList
Label container classes.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
polyMesh(const IOobject &io)
Construct from IOobject.