42 void Foam::polyMeshAdder::append
46 DynamicList<label>& dynLst
49 dynLst.setCapacity(dynLst.size() + lst.size());
53 label newElem = map[lst[i]];
57 dynLst.append(newElem);
68 const SortableList<label>& sortedLst,
69 DynamicList<label>& dynLst
72 dynLst.setSize(dynLst.size() + lst.size());
76 label newElem = map[lst[i]];
80 dynLst.append(newElem);
87 Foam::label Foam::polyMeshAdder::patchIndex
90 DynamicList<word>& allPatchNames,
91 DynamicList<word>& allPatchTypes
96 const word& pType = p.type();
97 const word& pName = p.name();
99 label patchI =
findIndex(allPatchNames, pName);
104 allPatchNames.append(pName);
105 allPatchTypes.append(pType);
107 return allPatchNames.size() - 1;
109 else if (allPatchTypes[patchI] == pType)
120 const word& caseName = p.boundaryMesh().mesh().time().caseName();
122 allPatchNames.append(pName +
"_" + caseName);
123 allPatchTypes.append(pType);
125 Pout<<
"label patchIndex(const polyPatch& p) : "
126 <<
"Patch " << p.index() <<
" named "
127 << pName <<
" in mesh " << caseName
128 <<
" already exists, but patch types"
129 <<
" do not match.\nCreating a composite name as "
130 << allPatchNames[allPatchNames.size() - 1] <<
endl;
132 return allPatchNames.size() - 1;
138 Foam::label Foam::polyMeshAdder::zoneIndex
141 DynamicList<word>& names
153 names.append(curName);
155 return names.size() - 1;
160 void Foam::polyMeshAdder::mergePatchNames
162 const polyBoundaryMesh& patches0,
163 const polyBoundaryMesh& patches1,
165 DynamicList<word>& allPatchNames,
166 DynamicList<word>& allPatchTypes,
173 append(patches0.names(), allPatchNames);
174 append(patches0.types(), allPatchTypes);
184 from1ToAllPatches.setSize(patches1.size());
188 from1ToAllPatches[patchI] = patchIndex
195 allPatchTypes.shrink();
196 allPatchNames.shrink();
199 fromAllTo1Patches.setSize(allPatchNames.size());
200 fromAllTo1Patches = -1;
202 forAll(from1ToAllPatches, i)
204 fromAllTo1Patches[from1ToAllPatches[i]] = i;
211 const polyBoundaryMesh&
patches
217 patchStarts[patchI] = patches[patchI].start();
225 const polyBoundaryMesh& patches
231 patchSizes[patchI] = patches[patchI].size();
239 const polyMesh& mesh0,
240 const polyMesh& mesh1,
241 const polyBoundaryMesh& allBoundaryMesh,
242 const label nAllPatches,
245 const label nInternalFaces,
252 const polyBoundaryMesh& patches0 = mesh0.boundaryMesh();
253 const polyBoundaryMesh& patches1 = mesh1.boundaryMesh();
257 DynamicList<polyPatch*> allPatches(nAllPatches);
261 from0ToAllPatches.setSize(patches0.size());
262 from0ToAllPatches = -1;
264 label startFaceI = nInternalFaces;
268 for (label patchI = 0; patchI < patches0.size(); patchI++)
272 label filteredPatchI;
274 if (nFaces[patchI] == 0 && isA<processorPolyPatch>(patches0[patchI]))
282 filteredPatchI = allPatches.size();
286 patches0[patchI].clone
294 startFaceI += nFaces[patchI];
298 from0ToAllPatches[patchI] = filteredPatchI;
301 if (fromAllTo1Patches[patchI] != -1)
303 from1ToAllPatches[fromAllTo1Patches[patchI]] = filteredPatchI;
308 forAll(from1ToAllPatches, patchI)
310 label allPatchI = from1ToAllPatches[patchI];
312 if (allPatchI >= patches0.size())
316 label filteredPatchI;
320 nFaces[allPatchI] == 0
321 && isA<processorPolyPatch>(patches1[patchI])
330 filteredPatchI = allPatches.size();
334 patches1[patchI].clone
342 startFaceI += nFaces[allPatchI];
345 from1ToAllPatches[patchI] = filteredPatchI;
358 const label nInternalFaces,
366 for (label faceI = nInternalFaces; faceI < owner.size(); faceI++)
368 oldToNew[faceI] = faceI;
378 SortableList<label> nbr(cFaces.size());
382 label faceI = cFaces[i];
384 label nbrCellI = neighbour[faceI];
389 if (nbrCellI == cellI)
391 nbrCellI = owner[faceI];
394 if (cellI < nbrCellI)
418 oldToNew[cFaces[nbr.indices()[i]]] = newFaceI++;
427 if (oldToNew[faceI] == -1)
431 "polyMeshAdder::getFaceOrder"
432 "(const cellList&, const label, const labelList&"
433 ", const labelList&) const"
434 ) <<
"Did not determine new position"
435 <<
" for face " << faceI
446 void Foam::polyMeshAdder::insertVertices
449 const Map<label>& meshToMaster,
453 DynamicList<label>& workFace,
464 label v0 = masterF[fp];
465 label
v1 = masterF.nextLabel(fp);
468 workFace.append(allF[fp]);
473 if (v0Fnd != meshToMaster.end())
476 if (v1Fnd != meshToMaster.end())
481 masterToCutPoints[v0Fnd()],
482 masterToCutPoints[v1Fnd()]
487 if (iter != cutEdgeToPoints.end())
489 const edge&
e = iter.key();
493 if (e[0] == cutEdge[0])
497 workFace.append(addedPoints[i]);
504 workFace.append(addedPoints[i]);
512 if (workFace.size() != allF.size())
514 allF.transfer(workFace);
531 void Foam::polyMeshAdder::mergePrimitives
533 const polyMesh& mesh0,
534 const polyMesh& mesh1,
535 const faceCoupleInfo& coupleInfo,
537 const label nAllPatches,
548 label& nInternalFaces,
557 const polyBoundaryMesh& patches0 = mesh0.boundaryMesh();
558 const polyBoundaryMesh& patches1 = mesh1.boundaryMesh();
569 allPoints.setSize(mesh0.nPoints() + mesh1.nPoints());
572 from0ToAllPoints.setSize(mesh0.nPoints());
573 from0ToAllPoints = -1;
574 from1ToAllPoints.setSize(mesh1.nPoints());
575 from1ToAllPoints = -1;
579 const pointField& cutPoints = coupleInfo.cutPoints();
588 coupleInfo.masterToCutPoints()
599 coupleInfo.slaveToCutPoints()
605 allPoints[allPointI] = cutPoints[i];
609 const labelList& masterPoints = cutToMasterPoints[i];
613 label mesh0PointI = masterPatch.meshPoints()[masterPoints[j]];
614 from0ToAllPoints[mesh0PointI] = allPointI;
617 const labelList& slavePoints = cutToSlavePoints[i];
621 label mesh1PointI = slavePatch.meshPoints()[slavePoints[j]];
622 from1ToAllPoints[mesh1PointI] = allPointI;
629 forAll(mesh0.points(), pointI)
631 if (from0ToAllPoints[pointI] == -1)
633 allPoints[allPointI] = mesh0.points()[pointI];
634 from0ToAllPoints[pointI] = allPointI;
640 forAll(mesh1.points(), pointI)
642 if (from1ToAllPoints[pointI] == -1)
644 allPoints[allPointI] = mesh1.points()[pointI];
645 from1ToAllPoints[pointI] = allPointI;
650 allPoints.setSize(allPointI);
657 nFacesPerPatch.setSize(nAllPatches);
661 allFaces.setSize(mesh0.nFaces() + mesh1.nFaces());
662 allOwner.setSize(allFaces.size());
664 allNeighbour.setSize(allFaces.size());
668 from0ToAllFaces.setSize(mesh0.nFaces());
669 from0ToAllFaces = -1;
670 from1ToAllFaces.setSize(mesh1.nFaces());
671 from1ToAllFaces = -1;
674 for (label faceI = 0; faceI < mesh0.nInternalFaces(); faceI++)
676 allFaces[allFaceI] =
renumber(from0ToAllPoints, mesh0.faces()[faceI]);
677 allOwner[allFaceI] = mesh0.faceOwner()[faceI];
678 allNeighbour[allFaceI] = mesh0.faceNeighbour()[faceI];
679 from0ToAllFaces[faceI] = allFaceI++;
684 const labelList& cutToMasterFaces = coupleInfo.cutToMasterFaces();
685 const labelList& cutToSlaveFaces = coupleInfo.cutToSlaveFaces();
689 label masterFaceI = cutToMasterFaces[i];
691 label mesh0FaceI = masterPatch.addressing()[masterFaceI];
693 if (from0ToAllFaces[mesh0FaceI] == -1)
696 from0ToAllFaces[mesh0FaceI] = allFaceI;
699 label patch0 = patches0.whichPatch(mesh0FaceI);
700 nFacesPerPatch[patch0]--;
703 label slaveFaceI = cutToSlaveFaces[i];
705 label mesh1FaceI = slavePatch.addressing()[slaveFaceI];
707 if (from1ToAllFaces[mesh1FaceI] == -1)
709 from1ToAllFaces[mesh1FaceI] = allFaceI;
711 label patch1 = patches1.whichPatch(mesh1FaceI);
712 nFacesPerPatch[from1ToAllPatches[patch1]]--;
717 allFaces[allFaceI] = cutFaces[i];
718 allOwner[allFaceI] = mesh0.faceOwner()[mesh0FaceI];
719 allNeighbour[allFaceI] = mesh1.faceOwner()[mesh1FaceI] + mesh0.nCells();
725 for (label faceI = 0; faceI < mesh1.nInternalFaces(); faceI++)
727 allFaces[allFaceI] =
renumber(from1ToAllPoints, mesh1.faces()[faceI]);
728 allOwner[allFaceI] = mesh1.faceOwner()[faceI] + mesh0.nCells();
729 allNeighbour[allFaceI] = mesh1.faceNeighbour()[faceI] + mesh0.nCells();
730 from1ToAllFaces[faceI] = allFaceI++;
733 nInternalFaces = allFaceI;
736 for (label allPatchI = 0; allPatchI < nAllPatches; allPatchI++)
738 if (allPatchI < patches0.size())
741 const polyPatch& pp = patches0[allPatchI];
743 nFacesPerPatch[allPatchI] += pp.size();
745 label faceI = pp.start();
749 if (from0ToAllFaces[faceI] == -1)
757 allOwner[allFaceI] = mesh0.faceOwner()[faceI];
758 allNeighbour[allFaceI] = -1;
760 from0ToAllFaces[faceI] = allFaceI++;
765 if (fromAllTo1Patches[allPatchI] != -1)
768 const polyPatch& pp = patches1[fromAllTo1Patches[allPatchI]];
770 nFacesPerPatch[allPatchI] += pp.size();
772 label faceI = pp.start();
776 if (from1ToAllFaces[faceI] == -1)
785 mesh1.faceOwner()[faceI]
787 allNeighbour[allFaceI] = -1;
789 from1ToAllFaces[faceI] = allFaceI++;
795 allFaces.setSize(allFaceI);
796 allOwner.setSize(allFaceI);
797 allNeighbour.setSize(allFaceI);
812 const edgeLookup& cutEdgeToPoints = coupleInfo.cutEdgeToPoints();
817 forAll(cutToMasterFaces, i)
819 label meshFaceI = masterPatch.addressing()[cutToMasterFaces[i]];
821 masterCutFaces.insert(meshFaceI);
824 DynamicList<label> workFace(100);
826 forAll(from0ToAllFaces, face0)
828 if (!masterCutFaces.found(face0))
830 label allFaceI = from0ToAllFaces[face0];
835 masterPatch.meshPointMap(),
836 coupleInfo.masterToCutPoints(),
837 mesh0.faces()[face0],
848 forAll(cutToSlaveFaces, i)
850 label meshFaceI = slavePatch.addressing()[cutToSlaveFaces[i]];
852 slaveCutFaces.insert(meshFaceI);
855 forAll(from1ToAllFaces, face1)
857 if (!slaveCutFaces.found(face1))
859 label allFaceI = from1ToAllFaces[face1];
864 slavePatch.meshPointMap(),
865 coupleInfo.slaveToCutPoints(),
866 mesh1.faces()[face1],
881 from1ToAllCells.setSize(mesh1.nCells());
882 from1ToAllCells = -1;
886 from1ToAllCells[i] = i + mesh0.nCells();
890 nCells = mesh0.nCells() + mesh1.nCells();
892 primitiveMesh::calcCells(allCells, allOwner, allNeighbour, nCells);
914 void Foam::polyMeshAdder::mergePointZones
921 DynamicList<word>& zoneNames,
923 List<DynamicList<label> >& pzPoints
926 zoneNames.setCapacity(pz0.size() + pz1.size());
929 append(pz0.names(), zoneNames);
931 from1ToAll.setSize(pz1.size());
935 from1ToAll[zoneI] = zoneIndex(pz1[zoneI].
name(), zoneNames);
940 pzPoints.setSize(zoneNames.size());
944 append(from0ToAllPoints, pz0[zoneI], pzPoints[zoneI]);
948 PtrList<SortableList<label> > pzPointsSorted(pzPoints.size());
954 new SortableList<label>(pzPoints[zoneI])
962 label allZoneI = from1ToAll[zoneI];
968 pzPointsSorted[allZoneI],
975 pzPoints[i].shrink();
980 void Foam::polyMeshAdder::mergeFaceZones
987 DynamicList<word>& zoneNames,
989 List<DynamicList<label> >& fzFaces,
990 List<DynamicList<bool> >& fzFlips
993 zoneNames.setCapacity(fz0.size() + fz1.size());
995 append(fz0.names(), zoneNames);
997 from1ToAll.setSize(fz1.size());
1001 from1ToAll[zoneI] = zoneIndex(fz1[zoneI].
name(), zoneNames);
1007 fzFaces.setSize(zoneNames.size());
1008 fzFlips.setSize(zoneNames.size());
1011 DynamicList<label>& newZone = fzFaces[zoneI];
1012 DynamicList<bool>& newFlip = fzFlips[zoneI];
1014 newZone.setCapacity(fz0[zoneI].size());
1015 newFlip.setCapacity(newZone.size());
1017 const labelList& addressing = fz0[zoneI];
1018 const boolList& flipMap = fz0[zoneI].flipMap();
1022 label faceI = addressing[i];
1024 if (from0ToAllFaces[faceI] != -1)
1026 newZone.append(from0ToAllFaces[faceI]);
1027 newFlip.append(flipMap[i]);
1033 PtrList<SortableList<label> > fzFacesSorted(fzFaces.size());
1039 new SortableList<label>(fzFaces[zoneI])
1046 label allZoneI = from1ToAll[zoneI];
1048 DynamicList<label>& newZone = fzFaces[allZoneI];
1049 const SortableList<label>& newZoneSorted = fzFacesSorted[allZoneI];
1050 DynamicList<bool>& newFlip = fzFlips[allZoneI];
1052 newZone.setCapacity(newZone.size() + fz1[zoneI].size());
1053 newFlip.setCapacity(newZone.size());
1055 const labelList& addressing = fz1[zoneI];
1056 const boolList& flipMap = fz1[zoneI].flipMap();
1060 label faceI = addressing[i];
1061 label allFaceI = from1ToAllFaces[faceI];
1069 newZone.append(allFaceI);
1070 newFlip.append(flipMap[i]);
1077 fzFaces[i].shrink();
1078 fzFlips[i].shrink();
1083 void Foam::polyMeshAdder::mergeCellZones
1089 DynamicList<word>& zoneNames,
1091 List<DynamicList<label> >& czCells
1094 zoneNames.setCapacity(cz0.size() + cz1.size());
1096 append(cz0.names(), zoneNames);
1098 from1ToAll.setSize(cz1.size());
1101 from1ToAll[zoneI] = zoneIndex(cz1[zoneI].
name(), zoneNames);
1107 czCells.setSize(zoneNames.size());
1111 append(cz0[zoneI], czCells[zoneI]);
1118 label allZoneI = from1ToAll[zoneI];
1120 append(from1ToAllCells, cz1[zoneI], czCells[allZoneI]);
1125 czCells[i].shrink();
1130 void Foam::polyMeshAdder::mergeZones
1132 const polyMesh& mesh0,
1133 const polyMesh& mesh1,
1141 DynamicList<word>& pointZoneNames,
1142 List<DynamicList<label> >& pzPoints,
1144 DynamicList<word>& faceZoneNames,
1145 List<DynamicList<label> >& fzFaces,
1146 List<DynamicList<bool> >& fzFlips,
1148 DynamicList<word>& cellZoneNames,
1149 List<DynamicList<label> >& czCells
1193 void Foam::polyMeshAdder::addZones
1195 const DynamicList<word>& pointZoneNames,
1196 const List<DynamicList<label> >& pzPoints,
1198 const DynamicList<word>& faceZoneNames,
1199 const List<DynamicList<label> >& fzFaces,
1200 const List<DynamicList<bool> >& fzFlips,
1202 const DynamicList<word>& cellZoneNames,
1203 const List<DynamicList<label> >& czCells,
1208 List<pointZone*>
pZones(pzPoints.size());
1211 pZones[i] =
new pointZone
1220 List<faceZone*> fZones(fzFaces.size());
1223 fZones[i] =
new faceZone
1233 List<cellZone*> cZones(czCells.size());
1236 cZones[i] =
new cellZone
1279 labelList fromAllTo1Patches(allPatchNames.size(), -1);
1301 label nInternalFaces;
1309 labelList nFaces(allPatchNames.size(), 0);
1324 allPatchNames.size(),
1395 allPatchNames.
size(),
1433 getPatchSizes(patches0),
1434 getPatchStarts(patches0)
1485 const bool validBoundary
1496 labelList fromAllTo1Patches(allPatchNames.size(), -1);
1520 label nInternalFaces;
1522 labelList nFaces(allPatchNames.size(), 0);
1537 allPatchNames.size(),
1600 labelList mesh0PatchSizes(getPatchSizes(patches0));
1601 labelList mesh0PatchStarts(getPatchStarts(patches0));
1610 allPatches.
setSize(allPatchNames.size());
1612 label startFaceI = nInternalFaces;
1616 label allPatchI = 0;
1618 forAll(from0ToAllPatches, patch0)
1623 if (nFaces[patch0] == 0 && isA<processorPolyPatch>(allPatches[patch0]))
1627 from0ToAllPatches[patch0] = -1;
1629 if (fromAllTo1Patches[patch0] != -1)
1631 from1ToAllPatches[fromAllTo1Patches[patch0]] = -1;
1640 allPatches[patch0].clone
1650 from0ToAllPatches[patch0] = allPatchI;
1653 if (fromAllTo1Patches[patch0] != -1)
1655 from1ToAllPatches[fromAllTo1Patches[patch0]] = allPatchI;
1658 startFaceI += nFaces[patch0];
1665 forAll(from1ToAllPatches, patch1)
1667 label uncompactAllPatchI = from1ToAllPatches[patch1];
1669 if (uncompactAllPatchI >= from0ToAllPatches.size())
1675 nFaces[uncompactAllPatchI] == 0
1676 && isA<processorPolyPatch>(patches1[patch1])
1681 from1ToAllPatches[patch1] = -1;
1689 patches1[patch1].clone
1693 nFaces[uncompactAllPatchI],
1699 from1ToAllPatches[patch1] = allPatchI;
1701 startFaceI += nFaces[uncompactAllPatchI];
1708 allPatches.setSize(allPatchI);
1747 labelList patchSizes(getPatchSizes(allPatches));
1748 labelList patchStarts(getPatchStarts(allPatches));
1787 const scalar mergeDist
1802 label nMultiple = 0;
1804 forAll(sharedPointLabels, i)
1806 label pointI = sharedPointLabels[i];
1808 label sharedI = sharedPointAddr[i];
1812 if (iter != sharedToMesh.
end())
1818 labelList& connectedPointLabels = iter();
1820 label sz = connectedPointLabels.
size();
1823 if (
findIndex(connectedPointLabels, pointI) != -1)
1826 <<
"Duplicate point in sharedPoint addressing." <<
endl
1827 <<
"When trying to add point " << pointI <<
" on shared "
1828 << sharedI <<
" with connected points "
1829 << connectedPointLabels
1833 connectedPointLabels.
setSize(sz+1);
1834 connectedPointLabels[sz] = pointI;
1838 sharedToMesh.insert(sharedI,
labelList(1, pointI));
1850 const labelList& connectedPointLabels = iter();
1857 if (connectedPointLabels.
size() > 1)
1862 connectedPointLabels
1883 mergedPoints.
size(),
1891 const labelList& mergeSet = mergeSets[setI];
1893 if (mergeSet.
size() > 1)
1896 label masterPointI = labelMax;
1900 label pointI = connectedPointLabels[mergeSet[i]];
1902 masterPointI =
min(masterPointI, pointI);
1907 label pointI = connectedPointLabels[mergeSet[i]];
1916 pointToMaster.
insert(pointI, masterPointI);
1996 return pointToMaster;
2012 if (iter != pointToMaster.
end())
2014 if (iter() != pointI)
2027 const face&
f = faces[faceI];
2029 bool hasMerged =
false;
2033 label pointI = f[fp];
2037 if (iter != pointToMaster.
end())
2039 if (iter() != pointI)
2053 label pointI = f[fp];
2057 if (iter != pointToMaster.
end())
2064 label nei = (patchID == -1 ? mesh.
faceNeighbour()[faceI] : -1);
2066 bool zoneFlip =
false;