38 DynamicList<word>& allPatchNames,
39 DynamicList<word>& allPatchTypes
44 const word& pType =
p.type();
45 const word& pName =
p.name();
52 allPatchNames.append(pName);
53 allPatchTypes.append(pType);
55 return allPatchNames.size() - 1;
57 else if (allPatchTypes[
patchi] == pType)
68 const word& caseName =
p.boundaryMesh().mesh().time().caseName();
70 allPatchNames.append(pName +
"_" + caseName);
71 allPatchTypes.append(pType);
73 Pout<<
"label patchIndex(const polyPatch& p) : "
74 <<
"Patch " <<
p.index() <<
" named "
75 << pName <<
" in mesh " << caseName
76 <<
" already exists, but patch types"
77 <<
" do not match.\nCreating a composite name as "
78 << allPatchNames.last() <<
endl;
80 return allPatchNames.size() - 1;
89 DynamicList<word>& names
101 names.append(curName);
103 return names.size() - 1;
108 void Foam::polyMeshAdder::mergePatchNames
110 const polyBoundaryMesh& patches0,
111 const polyBoundaryMesh& patches1,
113 DynamicList<word>& allPatchNames,
114 DynamicList<word>& allPatchTypes,
121 allPatchNames.append(patches0.names());
122 allPatchTypes.append(patches0.types());
132 from1ToAllPatches.setSize(patches1.size());
136 from1ToAllPatches[
patchi] = patchIndex
143 allPatchTypes.shrink();
144 allPatchNames.shrink();
147 fromAllTo1Patches.setSize(allPatchNames.size());
148 fromAllTo1Patches = -1;
150 forAll(from1ToAllPatches, i)
152 fromAllTo1Patches[from1ToAllPatches[i]] = i;
159 const polyBoundaryMesh&
patches
173 const polyBoundaryMesh&
patches
188 const label nInternalFaces,
196 for (
label facei = nInternalFaces; facei < owner.size(); ++facei)
198 oldToNew[facei] = facei;
208 SortableList<label> nbr(cFaces.size());
212 label facei = cFaces[i];
214 label nbrCelli = neighbour[facei];
219 if (nbrCelli == celli)
221 nbrCelli = owner[facei];
224 if (celli < nbrCelli)
248 oldToNew[cFaces[nbr.indices()[i]]] = newFacei++;
257 if (oldToNew[facei] == -1)
260 <<
"Did not determine new position"
261 <<
" for face " << facei
282 void Foam::polyMeshAdder::mergePrimitives
284 const polyMesh& mesh0,
285 const polyMesh& mesh1,
286 const faceCoupleInfo& coupleInfo,
288 const label nAllPatches,
299 label& nInternalFaces,
308 const polyBoundaryMesh& patches0 = mesh0.boundaryMesh();
309 const polyBoundaryMesh& patches1 = mesh1.boundaryMesh();
319 allPoints.setSize(mesh0.nPoints() + mesh1.nPoints());
322 from0ToAllPoints.setSize(mesh0.nPoints());
323 from0ToAllPoints = -1;
324 from1ToAllPoints.setSize(mesh1.nPoints());
325 from1ToAllPoints = -1;
331 coupleInfo.coupleToMasterPoints()
335 coupleInfo.coupleToSlavePoints()
338 forAll(coupleToMasterPoints, couplePointi)
340 const labelList& masterPoints = coupleToMasterPoints[couplePointi];
344 label mesh0Pointi = masterPatch.meshPoints()[masterPoints[j]];
345 from0ToAllPoints[mesh0Pointi] = allPointi;
346 allPoints[allPointi] = mesh0.points()[mesh0Pointi];
349 const labelList& slavePoints = coupleToSlavePoints[couplePointi];
353 label mesh1Pointi = slavePatch.meshPoints()[slavePoints[j]];
354 from1ToAllPoints[mesh1Pointi] = allPointi;
355 allPoints[allPointi] = mesh1.points()[mesh1Pointi];
363 forAll(mesh0.points(), pointi)
365 if (from0ToAllPoints[pointi] == -1)
367 allPoints[allPointi] = mesh0.points()[pointi];
368 from0ToAllPoints[pointi] = allPointi;
374 forAll(mesh1.points(), pointi)
376 if (from1ToAllPoints[pointi] == -1)
378 allPoints[allPointi] = mesh1.points()[pointi];
379 from1ToAllPoints[pointi] = allPointi;
384 allPoints.setSize(allPointi);
391 nFacesPerPatch.setSize(nAllPatches);
395 allFaces.setSize(mesh0.nFaces() + mesh1.nFaces());
396 allOwner.setSize(allFaces.size());
398 allNeighbour.setSize(allFaces.size());
402 from0ToAllFaces.setSize(mesh0.nFaces());
403 from0ToAllFaces = -1;
404 from1ToAllFaces.setSize(mesh1.nFaces());
405 from1ToAllFaces = -1;
408 for (
label facei = 0; facei < mesh0.nInternalFaces(); facei++)
410 allFaces[allFacei] =
renumber(from0ToAllPoints, mesh0.faces()[facei]);
411 allOwner[allFacei] = mesh0.faceOwner()[facei];
412 allNeighbour[allFacei] = mesh0.faceNeighbour()[facei];
413 from0ToAllFaces[facei] = allFacei++;
418 forAll(masterPatch, coupleFacei)
420 const label mesh0Facei = masterPatch.addressing()[coupleFacei];
422 if (from0ToAllFaces[mesh0Facei] == -1)
425 from0ToAllFaces[mesh0Facei] = allFacei;
428 label patch0 = patches0.whichPatch(mesh0Facei);
429 nFacesPerPatch[patch0]--;
432 const label mesh1Facei = slavePatch.addressing()[coupleFacei];
434 if (from1ToAllFaces[mesh1Facei] == -1)
436 from1ToAllFaces[mesh1Facei] = allFacei;
438 label patch1 = patches1.whichPatch(mesh1Facei);
439 nFacesPerPatch[from1ToAllPatches[patch1]]--;
444 allFaces[allFacei] = coupleInfo.coupleFace(coupleFacei);
445 allOwner[allFacei] = mesh0.faceOwner()[mesh0Facei];
446 allNeighbour[allFacei] = mesh1.faceOwner()[mesh1Facei] + mesh0.nCells();
452 for (
label facei = 0; facei < mesh1.nInternalFaces(); facei++)
454 allFaces[allFacei] =
renumber(from1ToAllPoints, mesh1.faces()[facei]);
455 allOwner[allFacei] = mesh1.faceOwner()[facei] + mesh0.nCells();
456 allNeighbour[allFacei] = mesh1.faceNeighbour()[facei] + mesh0.nCells();
457 from1ToAllFaces[facei] = allFacei++;
460 nInternalFaces = allFacei;
463 for (
label allPatchi = 0; allPatchi < nAllPatches; allPatchi++)
465 if (allPatchi < patches0.size())
468 const polyPatch& pp = patches0[allPatchi];
470 nFacesPerPatch[allPatchi] += pp.size();
472 label facei = pp.start();
476 if (from0ToAllFaces[facei] == -1)
484 allOwner[allFacei] = mesh0.faceOwner()[facei];
485 allNeighbour[allFacei] = -1;
487 from0ToAllFaces[facei] = allFacei++;
492 if (fromAllTo1Patches[allPatchi] != -1)
495 const polyPatch& pp = patches1[fromAllTo1Patches[allPatchi]];
497 nFacesPerPatch[allPatchi] += pp.size();
499 label facei = pp.start();
503 if (from1ToAllFaces[facei] == -1)
512 mesh1.faceOwner()[facei]
514 allNeighbour[allFacei] = -1;
516 from1ToAllFaces[facei] = allFacei++;
522 allFaces.setSize(allFacei);
523 allOwner.setSize(allFacei);
524 allNeighbour.setSize(allFacei);
529 from1ToAllCells.setSize(mesh1.nCells());
530 from1ToAllCells = -1;
534 from1ToAllCells[i] = i + mesh0.nCells();
538 nCells = mesh0.nCells() + mesh1.nCells();
540 primitiveMesh::calcCells(allCells, allOwner, allNeighbour, nCells);
562 void Foam::polyMeshAdder::mergePointZones
564 const label nAllPoints,
570 DynamicList<word>& zoneNames,
572 List<DynamicList<label>>& pzPoints
575 zoneNames.setCapacity(pz0.size() + pz1.size());
576 zoneNames.append(pz0.names());
578 from1ToAll.setSize(pz1.size());
582 from1ToAll[zoneI] = zoneIndex(pz1[zoneI].
name(), zoneNames);
598 const pointZone& pz = pz0[zoneI];
602 label point0 = pz[i];
603 label allPointi = from0ToAllPoints[point0];
605 if (pointToZone[allPointi] == -1)
607 pointToZone[allPointi] = zoneI;
609 else if (pointToZone[allPointi] != zoneI)
623 const pointZone& pz = pz1[zoneI];
624 const label allZoneI = from1ToAll[zoneI];
628 label point1 = pz[i];
629 label allPointi = from1ToAllPoints[point1];
631 if (pointToZone[allPointi] == -1)
633 pointToZone[allPointi] = allZoneI;
635 else if (pointToZone[allPointi] != allZoneI)
650 forAll(pointToZone, allPointi)
652 label zoneI = pointToZone[allPointi];
658 forAll(addPointToZones, allPointi)
668 pzPoints.setSize(zoneNames.size());
671 pzPoints[zoneI].setCapacity(
nPoints[zoneI]);
673 forAll(pointToZone, allPointi)
675 label zoneI = pointToZone[allPointi];
678 pzPoints[zoneI].append(allPointi);
681 forAll(addPointToZones, allPointi)
686 pzPoints[
pZones[i]].append(allPointi);
691 pzPoints[i].shrink();
697 void Foam::polyMeshAdder::mergeFaceZones
701 const polyMesh& mesh0,
702 const polyMesh& mesh1,
709 DynamicList<word>& zoneNames,
711 List<DynamicList<label>>& fzFaces,
712 List<DynamicList<bool>>& fzFlips
716 const labelList& owner0 = mesh0.faceOwner();
718 const labelList& owner1 = mesh1.faceOwner();
721 zoneNames.setCapacity(fz0.size() + fz1.size());
722 zoneNames.
append(fz0.names());
724 from1ToAll.setSize(fz1.size());
728 from1ToAll[zoneI] = zoneIndex(fz1[zoneI].
name(), zoneNames);
734 labelList faceToZone(allOwner.size(), -1);
736 boolList faceToFlip(allOwner.size(),
false);
742 const labelList& addressing = fz0[zoneI];
743 const boolList& flipMap = fz0[zoneI].flipMap();
747 label face0 = addressing[i];
748 bool flip0 = flipMap[i];
750 label allFacei = from0ToAllFaces[face0];
754 label allCell0 = owner0[face0];
755 if (allOwner[allFacei] != allCell0)
760 if (faceToZone[allFacei] == -1)
762 faceToZone[allFacei] = zoneI;
763 faceToFlip[allFacei] = flip0;
765 else if (faceToZone[allFacei] != zoneI)
767 labelList& fZones = addFaceToZones[allFacei];
768 boolList& flipZones = addFaceToFlips[allFacei];
773 flipZones.append(flip0);
783 const labelList& addressing = fz1[zoneI];
784 const boolList& flipMap = fz1[zoneI].flipMap();
786 const label allZoneI = from1ToAll[zoneI];
790 label face1 = addressing[i];
791 bool flip1 = flipMap[i];
793 label allFacei = from1ToAllFaces[face1];
797 label allCell1 = from1ToAllCells[owner1[face1]];
798 if (allOwner[allFacei] != allCell1)
803 if (faceToZone[allFacei] == -1)
805 faceToZone[allFacei] = allZoneI;
806 faceToFlip[allFacei] = flip1;
808 else if (faceToZone[allFacei] != allZoneI)
810 labelList& fZones = addFaceToZones[allFacei];
811 boolList& flipZones = addFaceToFlips[allFacei];
816 flipZones.append(flip1);
828 forAll(faceToZone, allFacei)
830 label zoneI = faceToZone[allFacei];
836 forAll(addFaceToZones, allFacei)
838 const labelList& fZones = addFaceToZones[allFacei];
846 fzFaces.setSize(zoneNames.size());
847 fzFlips.setSize(zoneNames.size());
850 fzFaces[zoneI].setCapacity(nFaces[zoneI]);
851 fzFlips[zoneI].setCapacity(nFaces[zoneI]);
853 forAll(faceToZone, allFacei)
855 label zoneI = faceToZone[allFacei];
856 bool flip = faceToFlip[allFacei];
859 fzFaces[zoneI].append(allFacei);
860 fzFlips[zoneI].append(flip);
863 forAll(addFaceToZones, allFacei)
865 const labelList& fZones = addFaceToZones[allFacei];
866 const boolList& flipZones = addFaceToFlips[allFacei];
870 label zoneI = fZones[i];
871 fzFaces[zoneI].append(allFacei);
872 fzFlips[zoneI].append(flipZones[i]);
883 fzFaces[i] = UIndirectList<label>(fzFaces[i],
order)();
884 fzFlips[i] = UIndirectList<bool>(fzFlips[i],
order)();
889 void Foam::polyMeshAdder::mergeCellZones
891 const label nAllCells,
897 DynamicList<word>& zoneNames,
899 List<DynamicList<label>>& czCells
902 zoneNames.setCapacity(cz0.size() + cz1.size());
903 zoneNames.append(cz0.names());
905 from1ToAll.setSize(cz1.size());
908 from1ToAll[zoneI] = zoneIndex(cz1[zoneI].
name(), zoneNames);
923 const cellZone& cz = cz0[zoneI];
928 if (cellToZone[cell0] == -1)
930 cellToZone[cell0] = zoneI;
932 else if (cellToZone[cell0] != zoneI)
934 labelList& cZones = addCellToZones[cell0];
946 const cellZone& cz = cz1[zoneI];
947 const label allZoneI = from1ToAll[zoneI];
951 label allCelli = from1ToAllCells[cell1];
953 if (cellToZone[allCelli] == -1)
955 cellToZone[allCelli] = allZoneI;
957 else if (cellToZone[allCelli] != allZoneI)
959 labelList& cZones = addCellToZones[allCelli];
972 forAll(cellToZone, allCelli)
974 label zoneI = cellToZone[allCelli];
980 forAll(addCellToZones, allCelli)
982 const labelList& cZones = addCellToZones[allCelli];
990 czCells.setSize(zoneNames.size());
993 czCells[zoneI].setCapacity(nCells[zoneI]);
995 forAll(cellToZone, allCelli)
997 label zoneI = cellToZone[allCelli];
1000 czCells[zoneI].append(allCelli);
1003 forAll(addCellToZones, allCelli)
1005 const labelList& cZones = addCellToZones[allCelli];
1008 czCells[cZones[i]].append(allCelli);
1013 czCells[i].shrink();
1019 void Foam::polyMeshAdder::mergeZones
1021 const label nAllPoints,
1023 const label nAllCells,
1025 const polyMesh& mesh0,
1026 const polyMesh& mesh1,
1034 DynamicList<word>& pointZoneNames,
1035 List<DynamicList<label>>& pzPoints,
1037 DynamicList<word>& faceZoneNames,
1038 List<DynamicList<label>>& fzFaces,
1039 List<DynamicList<bool>>& fzFlips,
1041 DynamicList<word>& cellZoneNames,
1042 List<DynamicList<label>>& czCells
1090 void Foam::polyMeshAdder::addZones
1092 const DynamicList<word>& pointZoneNames,
1093 const List<DynamicList<label>>& pzPoints,
1095 const DynamicList<word>& faceZoneNames,
1096 const List<DynamicList<label>>& fzFaces,
1097 const List<DynamicList<bool>>& fzFlips,
1099 const DynamicList<word>& cellZoneNames,
1100 const List<DynamicList<label>>& czCells,
1105 List<pointZone*>
pZones(pzPoints.size());
1108 pZones[i] =
new pointZone
1117 List<faceZone*> fZones(fzFaces.size());
1120 fZones[i] =
new faceZone
1130 List<cellZone*> cZones(czCells.size());
1133 cZones[i] =
new cellZone
1158 const bool validBoundary
1193 label nInternalFaces;
1210 allPatchNames.
size(),
1277 labelList mesh0PatchSizes(getPatchSizes(patches0));
1278 labelList mesh0PatchStarts(getPatchStarts(patches0));
1288 label startFacei = nInternalFaces;
1292 label allPatchi = 0;
1294 forAll(from0ToAllPatches, patch0)
1299 if (nFaces[patch0] == 0 && isA<processorPolyPatch>(patches0[patch0]))
1304 from0ToAllPatches[patch0] = -1;
1307 if (fromAllTo1Patches[patch0] != -1)
1309 from1ToAllPatches[fromAllTo1Patches[patch0]] = -1;
1314 patchSizes[allPatchi] = nFaces[patch0];
1315 patchStarts[allPatchi] = startFacei;
1318 from0ToAllPatches[patch0] = allPatchi;
1321 if (fromAllTo1Patches[patch0] != -1)
1323 from1ToAllPatches[fromAllTo1Patches[patch0]] = allPatchi;
1326 startFacei += nFaces[patch0];
1334 const label sz0 = from0ToAllPatches.
size();
1339 if (from0ToAllPatches[
patchi] != -1)
1341 newToOld[nNew++] =
patchi;
1349 forAll(from1ToAllPatches, patch1)
1351 label uncompactAllPatchi = from1ToAllPatches[patch1];
1353 if (uncompactAllPatchi >= from0ToAllPatches.
size())
1359 nFaces[uncompactAllPatchi] == 0
1360 && isA<processorPolyPatch>(patches1[patch1])
1365 from1ToAllPatches[patch1] = -1;
1369 patchSizes[allPatchi] = nFaces[uncompactAllPatchi];
1370 patchStarts[allPatchi] = startFacei;
1385 from1ToAllPatches[patch1] = allPatchi;
1387 startFacei += nFaces[uncompactAllPatchi];
1393 patchSizes.
setSize(allPatchi);
1394 patchStarts.
setSize(allPatchi);
#define forAll(list, i)
Loop across all elements in list.
void append(const T &)
Append an element at the end of the list.
void size(const label)
Override size to be inconsistent with allocated storage.
void setSize(const label)
Reset size of List.
void clear()
Clear the zones.
void append(T *)
Append an element at the end of the list.
label size() const
Return the number of elements in the UPtrList.
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
A list of keyword definitions, which are a keyword followed by any number of values (e....
Container for information needed to couple to meshes. When constructed from two meshes and a list of ...
Class containing mesh-to-mesh mapping information after a mesh addition where we add a mesh ('added m...
static autoPtr< mapAddedPolyMesh > add(polyMesh &mesh0, const polyMesh &mesh1, const faceCoupleInfo &coupleInfo, const bool validBoundary=true)
Inplace add mesh to polyMesh. Returns map construct.
Mesh consisting of general polyhedral cells.
const meshFaceZones & faceZones() const
Return face zones.
virtual void addPatch(const label insertPatchi, const polyPatch &patch, const dictionary &patchFieldDict, const word &defaultPatchFieldType, const bool validBoundary)
Add/insert single patch. If validBoundary the new situation.
void resetPrimitives(pointField &&points, faceList &&faces, labelList &&owner, labelList &&neighbour, const labelList &patchSizes, const labelList &patchStarts, const bool validBoundary=true)
Reset mesh primitive data. Assumes all patch info correct.
const meshPointZones & pointZones() const
Return point zones.
void resetMotion() const
Reset motion.
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
virtual void reorderPatches(const labelUList &newToOld, const bool validBoundary)
Reorder and trim existing patches. If validBoundary the new.
const meshCellZones & cellZones() const
Return cell zones.
IOporosityModelList pZones(mesh)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
const fvPatchList & patches
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.
word name(const bool)
Return a word representation of a bool.
int order(const scalar s)
errorManip< error > abort(error &err)
MeshZones< cellZone, polyMesh > meshCellZones
A MeshZones with the type cellZone.
ListType renumber(const labelUList &oldToNew, const ListType &)
Renumber the values (not the indices) of a list.
vectorField pointField
pointField is a vectorField.
List< bool > boolList
Bool container classes.
MeshZones< pointZone, polyMesh > meshPointZones
A MeshZones with the type pointZone.
List< labelList > labelListList
A List of labelList.
List< List< bool > > boolListList
void inplaceRenumber(const labelUList &oldToNew, ListType &)
Inplace renumber the values of a list.
prefixOSstream Pout(cout, "Pout")
label findIndex(const ListType &, typename ListType::const_reference, const label start=0)
Find first occurrence of given element and return index,.
void stableSort(UList< T > &)
MeshZones< faceZone, polyMesh > meshFaceZones
A MeshZones with the type faceZone.
labelList identityMap(const label len)
Create identity map (map[i] == i) of given length.
void sortedOrder(const UList< T > &, labelList &order)
Generate the (stable) sort order for the list.
PrimitivePatch< IndirectList< face >, const pointField & > indirectPrimitivePatch
Foam::indirectPrimitivePatch.
void inplaceReorder(const labelUList &oldToNew, ListType &)
Inplace reorder the elements of a list.