35 Foam::domainDecomposition::determineCoupledFaces
37 const label masterMeshProcStart,
38 const label masterMeshProcEnd,
39 const polyMesh& masterMesh,
40 const label meshToAddProcStart,
41 const label meshToAddProcEnd,
42 const polyMesh& meshToAdd
45 const polyBoundaryMesh& masterPatches = masterMesh.boundaryMesh();
46 const polyBoundaryMesh& addPatches = meshToAdd.boundaryMesh();
48 DynamicList<label> masterFaces
50 masterMesh.nFaces() - masterMesh.nInternalFaces()
52 DynamicList<label> addFaces
54 meshToAdd.nFaces() - meshToAdd.nInternalFaces()
59 label masterProci = masterMeshProcStart;
60 masterProci < masterMeshProcEnd;
66 label addProci = meshToAddProcStart;
67 addProci < meshToAddProcEnd;
71 const word masterToAddName
73 "procBoundary" +
name(masterProci) +
"to" +
name(addProci)
75 const word addToMasterName
77 "procBoundary" +
name(addProci) +
"to" +
name(masterProci)
80 const label masterToAddID =
81 masterPatches.findIndex(masterToAddName);
82 const label addToMasterID =
83 addPatches.findIndex(addToMasterName);
85 if (masterToAddID != -1 && addToMasterID != -1)
87 const polyPatch& masterPp = masterPatches[masterToAddID];
91 masterFaces.append(masterPp.start() + i);
94 const polyPatch& addPp = addPatches[addToMasterID];
98 addFaces.append(addPp.start() + i);
102 if ((masterToAddID != -1) != (addToMasterID != -1))
104 const label foundProci =
105 masterToAddID != -1 ? masterProci : addProci;
106 const word& foundName =
107 masterToAddID != -1 ? masterToAddName : addToMasterName;
109 const label missingProci =
110 masterToAddID != -1 ? addProci : masterProci;
111 const word& missingName =
112 masterToAddID != -1 ? addToMasterName : masterToAddName;
115 <<
"Patch " << foundName <<
" found on processor "
116 << foundProci <<
" but corresponding patch "
117 << missingName <<
" missing on processor "
123 masterFaces.shrink();
126 return autoPtr<faceCoupleInfo>
139 void Foam::domainDecomposition::reconstruct()
144 PtrList<fvMesh> masterMeshes(nProcs());
147 for (
label proci=0; proci<nProcs(); proci++)
157 procMeshes()[0].facesInstance(),
159 runTimes_.completeTime()
166 fvMesh& masterMesh = masterMeshes[proci];
167 masterMesh.setPointsInstance(procMeshes()[0].pointsInstance());
170 procPointAddressing_[proci] =
172 procFaceAddressing_[proci] =
identityMap(procMeshes()[proci].nFaces());
173 procCellAddressing_[proci] =
identityMap(procMeshes()[proci].nCells());
176 autoPtr<faceCoupleInfo> couples = determineCoupledFaces
198 map().addedPointMap(),
199 procPointAddressing_[proci]
203 map().addedFaceMap(),
204 procFaceAddressing_[proci]
208 map().addedCellMap(),
209 procCellAddressing_[proci]
214 for (
label step=2; step<nProcs()*2; step*=2)
216 for (
label proci=0; proci<nProcs(); proci+=step)
218 label procj = proci + step/2;
220 if (procj >= nProcs())
continue;
223 <<
" with " << procj <<
endl;
226 autoPtr<faceCoupleInfo> couples = determineCoupledFaces
248 label mergedProci = proci;
256 procPointAddressing_[mergedProci]
261 procFaceAddressing_[mergedProci]
266 procCellAddressing_[mergedProci]
273 label addedProci = procj;
274 addedProci <
min(proci + step, nProcs());
280 map().addedPointMap(),
281 procPointAddressing_[addedProci]
285 map().addedFaceMap(),
286 procFaceAddressing_[addedProci]
290 map().addedCellMap(),
291 procCellAddressing_[addedProci]
295 masterMeshes.set(procj,
nullptr);
299 const polyBoundaryMesh&
patches = masterMeshes[0].boundaryMesh();
302 if (!
patches.findIndices<processorCyclicPolyPatch>().
empty())
305 List<DynamicList<label>> patchPatches
308 DynamicList<label>(1)
319 FixedList<label, 3>::Hash<>
320 > nbrProcessorCyclicIDs;
324 if (!isA<processorCyclicPolyPatch>(
patches[
patchi]))
continue;
326 const processorCyclicPolyPatch& pcpp =
329 const label proci = pcpp.myProcNo();
330 const label nbrProci = pcpp.neighbProcNo();
331 const label refPatchi = pcpp.referPatchIndex();
332 const label nbrRefPatchi = pcpp.referPatch().nbrPatchIndex();
334 FixedList<label, 3> key({proci, nbrProci, refPatchi});
335 FixedList<label, 3> nbrKey({nbrProci, proci, nbrRefPatchi});
337 if (nbrProcessorCyclicIDs.found(nbrKey))
339 const label nbrPatchi = nbrProcessorCyclicIDs[nbrKey];
341 patchPatches[refPatchi].append
343 patchPatches[
patchi].remove()
345 patchPatches[nbrRefPatchi].append
347 patchPatches[nbrPatchi].remove()
350 nbrProcessorCyclicIDs.erase(nbrKey);
354 nbrProcessorCyclicIDs.insert(key,
patchi);
361 labelList newToOldFace(masterMeshes[0].nFaces());
362 SubList<label>(newToOldFace, masterMeshes[0].nInternalFaces()) =
366 newPatchSizes[
patchi] = 0;
369 ? masterMeshes[0].nInternalFaces()
383 newPatchSizes[
patchi] += pp.size();
390 boolList newHasOldFace(newToOldFace.size(),
false);
391 forAll(newToOldFace, newFacei)
393 if (newHasOldFace[newToOldFace[newFacei]])
396 <<
"Face re-ordering is not valid"
399 newHasOldFace[newToOldFace[newFacei]] =
true;
404 const labelList oldToNewFace(
invert(newToOldFace.size(), newToOldFace));
405 masterMeshes[0].resetPrimitives
407 NullObjectMove<pointField>(),
408 reorder(oldToNewFace, masterMeshes[0].faces()),
409 reorder(oldToNewFace, masterMeshes[0].faceOwner()),
410 reorder(oldToNewFace, masterMeshes[0].faceNeighbour()),
417 forAll(procFaceAddressing_, proci)
422 procFaceAddressing_[proci]
429 label nNonProcPatches = 0;
439 <<
"Non-empty processor patch \""
441 <<
"\" found in reconstructed mesh"
447 nonProcPatchIds[nNonProcPatches++] =
patchi;
451 nonProcPatchIds.resize(nNonProcPatches);
453 masterMeshes[0].reorderPatches(nonProcPatchIds,
false);
457 for (
label proci=0; proci<nProcs(); proci++)
459 const fvMesh& procMesh = procMeshes_[proci];
461 forAll(procFaceAddressing_[proci], procFacei)
463 const label completeFacei = procFaceAddressing_[proci][procFacei];
467 !procMesh.isInternalFace(procFacei)
468 && masterMeshes[0].isInternalFace(completeFacei)
474 const label procOwnCelli =
475 procMesh.faceOwner()[procFacei];
476 const label completeOwnCelli =
477 masterMeshes[0].faceOwner()[completeFacei];
481 procCellAddressing_[proci][procOwnCelli]
485 procFaceAddressing_[proci][procFacei] ++;
489 procFaceAddressing_[proci][procFacei] =
490 -1 - procFaceAddressing_[proci][procFacei];
498 procFaceAddressing_[proci][procFacei] ++;
504 procFaceAddressingBf_.clear();
507 cellProc_.resize(masterMeshes[0].nCells());
508 forAll(procCellAddressing_, proci)
510 forAll(procCellAddressing_[proci], procCelli)
512 cellProc_[procCellAddressing_[proci][procCelli]] = proci;
517 completeMesh_.reset(masterMeshes.set(0,
nullptr).ptr());
518 completeMesh_->setInstance(procMeshes()[0].facesInstance());
519 completeMesh_->setPointsInstance(procMeshes()[0].pointsInstance());
528 void Foam::domainDecomposition::reconstructPoints()
530 const label pointsCompare =
533 completeMesh().pointsInstance(),
534 procMeshes_[0].pointsInstance()
537 if (pointsCompare == 1)
541 for (
label proci = 0; proci < nProcs(); proci++)
543 const fvMesh& procMesh = procMeshes_[proci];
545 completePoints.rmap(procMesh.points(), procPointAddressing_[proci]);
548 completeMesh_->setPoints(completePoints);
552 const pointZoneList& pointZones = completeMesh().pointZones();
553 const pointZoneList& pointZones0 = procMeshes_[0].pointZones();
555 const label pointZonesCompare = compareInstances
557 pointZones.instance(),
558 pointZones0.instance()
561 if (pointZonesCompare == 1)
569 boolList selected(completeMesh_->nPoints(),
false);
571 for (
label proci=0; proci<nProcs(); proci++)
574 procMeshes_[proci].pointZones()[pzi];
576 const labelList& ppa = procPointAddressing_[proci];
580 selected[ppa[pointZonei[zpi]]] =
true;
584 completeMesh_->pointZones().append
588 pointZones0[pzi].
name(),
590 completeMesh_->pointZones()
596 completeMesh_->pointZones().instance() = pointZones0.instance();
602 const cellZoneList& cellZones = completeMesh().cellZones();
603 const cellZoneList& cellZones0 = procMeshes_[0].cellZones();
605 const label cellZonesCompare = compareInstances
607 cellZones.instance(),
608 cellZones0.instance()
611 if (cellZonesCompare == 1)
619 boolList selected(completeMesh_->nCells(),
false);
621 for (
label proci=0; proci<nProcs(); proci++)
624 procMeshes_[proci].cellZones()[pzi];
626 const labelList& pca = procCellAddressing_[proci];
630 selected[pca[cellZonei[zci]]] =
true;
634 completeMesh_->cellZones().append
638 cellZones0[pzi].
name(),
640 completeMesh_->cellZones()
646 completeMesh_->cellZones().instance() = cellZones0.instance();
652 const faceZoneList& faceZones = completeMesh().faceZones();
653 const faceZoneList& faceZones0 = procMeshes_[0].faceZones();
655 const label faceZonesCompare = compareInstances
657 faceZones.instance(),
658 faceZones0.instance()
661 if (faceZonesCompare == 1)
669 boolList selectedFaces(completeMesh_->nFaces(),
false);
670 boolList flipMap(completeMesh_->nFaces(),
false);
672 const labelList& owner = completeMesh_->owner();
674 for (
label proci=0; proci<nProcs(); proci++)
677 procMeshes_[proci].faceZones()[pzi];
680 faceZones0[pzi].oriented()
681 ? procMeshes_[proci].faceZones()[pzi].flipMap()
684 const labelList& owneri = procMeshes_[proci].owner();
686 const labelList& pfa = procFaceAddressing_[proci];
687 const labelList& pca = procCellAddressing_[proci];
691 const label fi =
mag(pfa[faceZonei[zfi]]) - 1;
693 selectedFaces[fi] =
true;
697 const label ownerZfi = owner[fi];
701 const label ownerZfii = pca[owneri[faceZonei[zfi]]];
708 if (ownerZfi == ownerZfii)
710 flipMap[fi] = flipMapi[zfi];
715 flipMap[fi] = !flipMapi[zfi];
723 if (faceZones0[pzi].oriented())
725 completeMesh_->faceZones().append
729 faceZones0[pzi].
name(),
732 completeMesh_->faceZones()
738 completeMesh_->faceZones().append
742 faceZones0[pzi].
name(),
744 completeMesh_->faceZones()
751 completeMesh_->faceZones().instance() = faceZones0.instance();
#define forAll(list, i)
Loop across all elements in list.
virtual const fileName & name() const
Return the name of the stream.
static const List< bool > & null()
Return a null List.
label size() const
Return the number of elements in the UPtrList.
bool empty() const
Return true if the UPtrList is empty (ie, size() is zero)
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
static autoPtr< mapAddedPolyMesh > add(fvMesh &mesh0, const fvMesh &mesh1, const faceCoupleInfo &coupleInfo, const bool validBoundary=true)
Inplace add mesh to fvMesh. Maps all stored fields. Returns map.
static labelList indices(const boolList &selected)
Return the list of selected indices.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
const fvPatchList & patches
errorManipArg< error, int > exit(error &err, const int errNo=1)
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
List< label > labelList
A List of labels.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
List< cell > cellList
list of cells
Ostream & endl(Ostream &os)
Add newline and flush stream.
labelList invert(const label len, const labelUList &)
Invert one-to-one map. Unmapped elements will be -1.
vectorField pointField
pointField is a vectorField.
Ostream & incrIndent(Ostream &os)
Increment the indent level.
List< bool > boolList
Bool container classes.
void mag(LagrangianPatchField< scalar > &f, const LagrangianPatchField< Type > &f1)
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
ListType reorder(const label size, const typename ListType::value_type &defaultValue, const labelUList &oldToNew, const ListType &lst)
void inplaceRenumber(const labelUList &oldToNew, ListType &)
Inplace renumber the values of a list.
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
labelList identityMap(const label len)
Create identity map (map[i] == i) of given length.
Ostream & indent(Ostream &os)
Indent stream.
faceListList boundary(nPatches)