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,
565 const pointZoneList& pz0,
566 const pointZoneList& pz1,
570 DynamicList<word>& zoneNames,
572 List<DynamicList<label>>& pzPoints
575 zoneNames.setCapacity(pz0.size() + pz1.size());
576 zoneNames.append(pz0.toc());
578 from1ToAll.setSize(pz1.size());
582 from1ToAll[zi] = zoneIndex(pz1[zi].
name(), zoneNames);
598 const pointZone& pz = pz0[zi];
602 label point0 = pz[i];
603 label allPointi = from0ToAllPoints[point0];
605 if (pointToZone[allPointi] == -1)
607 pointToZone[allPointi] = zi;
609 else if (pointToZone[allPointi] != zi)
623 const pointZone& pz = pz1[zi];
624 const label allZoneI = from1ToAll[zi];
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 zi = pointToZone[allPointi];
658 forAll(addPointToZones, allPointi)
668 pzPoints.setSize(zoneNames.size());
671 pzPoints[zi].setCapacity(
nPoints[zi]);
673 forAll(pointToZone, allPointi)
675 label zi = pointToZone[allPointi];
678 pzPoints[zi].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,
713 List<DynamicList<bool>>& fzFlips
716 const faceZoneList& fz0 = mesh0.faceZones();
717 const labelList& owner0 = mesh0.faceOwner();
718 const faceZoneList& fz1 = mesh1.faceZones();
719 const labelList& owner1 = mesh1.faceOwner();
722 zoneNames.setCapacity(fz0.size() + fz1.size());
723 zoneNames.
append(fz0.toc());
725 from1ToAll.setSize(fz1.size());
729 from1ToAll[zi] = zoneIndex(fz1[zi].
name(), zoneNames);
733 fzOrientations.setSize(zoneNames.size(),
false);
736 labelList faceToZone(allOwner.size(), -1);
738 boolList faceToFlip(allOwner.size(),
false);
746 fzOrientations[zi] = fz0[zi].oriented();
748 if (fz0[zi].oriented())
750 const boolList& flipMap = fz0[zi].flipMap();
754 const label face0 = addressing[i];
755 bool flip0 = flipMap[i];
756 const label allFacei = from0ToAllFaces[face0];
761 const label allCell0 = owner0[face0];
762 if (allOwner[allFacei] != allCell0)
767 if (faceToZone[allFacei] == -1)
769 faceToZone[allFacei] = zi;
770 faceToFlip[allFacei] = flip0;
772 else if (faceToZone[allFacei] != zi)
774 labelList& fZones = addFaceToZones[allFacei];
775 boolList& flipZones = addFaceToFlips[allFacei];
780 flipZones.append(flip0);
790 const label face0 = addressing[i];
791 const label allFacei = from0ToAllFaces[face0];
795 if (faceToZone[allFacei] == -1)
797 faceToZone[allFacei] = zi;
799 else if (faceToZone[allFacei] != zi)
801 labelList& fZones = addFaceToZones[allFacei];
817 const boolList& flipMap = fz1[zi].flipMap();
819 const label allZoneI = from1ToAll[zi];
821 fzOrientations[allZoneI] = fz1[zi].oriented();
823 if (fz1[zi].oriented())
827 const label face1 = addressing[i];
828 bool flip1 = flipMap[i];
829 const label allFacei = from1ToAllFaces[face1];
834 const label allCell1 = from1ToAllCells[owner1[face1]];
835 if (allOwner[allFacei] != allCell1)
840 if (faceToZone[allFacei] == -1)
842 faceToZone[allFacei] = allZoneI;
843 faceToFlip[allFacei] = flip1;
845 else if (faceToZone[allFacei] != allZoneI)
847 labelList& fZones = addFaceToZones[allFacei];
848 boolList& flipZones = addFaceToFlips[allFacei];
853 flipZones.append(flip1);
863 const label face1 = addressing[i];
864 const label allFacei = from1ToAllFaces[face1];
868 if (faceToZone[allFacei] == -1)
870 faceToZone[allFacei] = allZoneI;
872 else if (faceToZone[allFacei] != allZoneI)
874 labelList& fZones = addFaceToZones[allFacei];
891 forAll(faceToZone, allFacei)
893 label zi = faceToZone[allFacei];
899 forAll(addFaceToZones, allFacei)
901 const labelList& fZones = addFaceToZones[allFacei];
909 fzFaces.setSize(zoneNames.size());
910 fzFlips.setSize(zoneNames.size());
914 fzFaces[zi].setCapacity(nFaces[zi]);
916 if (fzOrientations[zi])
918 fzFlips[zi].setCapacity(nFaces[zi]);
922 forAll(faceToZone, allFacei)
924 label zi = faceToZone[allFacei];
925 bool flip = faceToFlip[allFacei];
928 fzFaces[zi].append(allFacei);
930 if (fzOrientations[zi])
932 fzFlips[zi].append(flip);
936 forAll(addFaceToZones, allFacei)
938 const labelList& fZones = addFaceToZones[allFacei];
939 const boolList& flipZones = addFaceToFlips[allFacei];
943 label zi = fZones[i];
944 fzFaces[zi].append(allFacei);
945 if (fzOrientations[zi])
947 fzFlips[zi].append(flipZones[i]);
954 fzFaces[zi].shrink();
955 fzFlips[zi].shrink();
959 fzFaces[zi] = UIndirectList<label>(fzFaces[zi],
order)();
960 fzFlips[zi] = UIndirectList<bool>(fzFlips[zi],
order)();
965 void Foam::polyMeshAdder::mergeCellZones
967 const label nAllCells,
969 const cellZoneList& cz0,
970 const cellZoneList& cz1,
973 DynamicList<word>& zoneNames,
975 List<DynamicList<label>>& czCells
978 zoneNames.setCapacity(cz0.size() + cz1.size());
979 zoneNames.append(cz0.toc());
981 from1ToAll.setSize(cz1.size());
984 from1ToAll[zi] = zoneIndex(cz1[zi].
name(), zoneNames);
999 const cellZone& cz = cz0[zi];
1002 label cell0 = cz[i];
1004 if (cellToZone[cell0] == -1)
1006 cellToZone[cell0] = zi;
1008 else if (cellToZone[cell0] != zi)
1010 labelList& cZones = addCellToZones[cell0];
1022 const cellZone& cz = cz1[zi];
1023 const label allZoneI = from1ToAll[zi];
1026 label cell1 = cz[i];
1027 label allCelli = from1ToAllCells[cell1];
1029 if (cellToZone[allCelli] == -1)
1031 cellToZone[allCelli] = allZoneI;
1033 else if (cellToZone[allCelli] != allZoneI)
1035 labelList& cZones = addCellToZones[allCelli];
1048 forAll(cellToZone, allCelli)
1050 label zi = cellToZone[allCelli];
1056 forAll(addCellToZones, allCelli)
1058 const labelList& cZones = addCellToZones[allCelli];
1061 nCells[cZones[i]]++;
1066 czCells.setSize(zoneNames.size());
1069 czCells[zi].setCapacity(nCells[zi]);
1071 forAll(cellToZone, allCelli)
1073 label zi = cellToZone[allCelli];
1076 czCells[zi].append(allCelli);
1079 forAll(addCellToZones, allCelli)
1081 const labelList& cZones = addCellToZones[allCelli];
1084 czCells[cZones[i]].append(allCelli);
1089 czCells[i].shrink();
1095 void Foam::polyMeshAdder::mergeZones
1097 const label nAllPoints,
1099 const label nAllCells,
1101 const polyMesh& mesh0,
1102 const polyMesh& mesh1,
1110 DynamicList<word>& pointZoneNames,
1111 List<DynamicList<label>>& pzPoints,
1113 DynamicList<word>& faceZoneNames,
1114 List<DynamicList<label>>& fzFaces,
1116 List<DynamicList<bool>>& fzFlips,
1118 DynamicList<word>& cellZoneNames,
1119 List<DynamicList<label>>& czCells
1168 void Foam::polyMeshAdder::addZones
1170 const DynamicList<word>& pointZoneNames,
1171 const List<DynamicList<label>>& pzPoints,
1173 const DynamicList<word>& faceZoneNames,
1174 const List<DynamicList<label>>& fzFaces,
1176 const List<DynamicList<bool>>& fzFlips,
1178 const DynamicList<word>& cellZoneNames,
1179 const List<DynamicList<label>>& czCells,
1184 List<pointZone*>
pZones(pzPoints.size());
1187 pZones[i] =
new pointZone
1195 List<faceZone*> fZones(fzFaces.size());
1198 if (fzOrientations[i])
1200 fZones[i] =
new faceZone
1210 fZones[i] =
new faceZone
1219 List<cellZone*> cZones(czCells.size());
1222 cZones[i] =
new cellZone
1246 const bool validBoundary
1281 label nInternalFaces;
1298 allPatchNames.
size(),
1367 labelList mesh0PatchSizes(getPatchSizes(patches0));
1368 labelList mesh0PatchStarts(getPatchStarts(patches0));
1378 label startFacei = nInternalFaces;
1382 label allPatchi = 0;
1384 forAll(from0ToAllPatches, patch0)
1389 if (nFaces[patch0] == 0 && isA<processorPolyPatch>(patches0[patch0]))
1394 from0ToAllPatches[patch0] = -1;
1397 if (fromAllTo1Patches[patch0] != -1)
1399 from1ToAllPatches[fromAllTo1Patches[patch0]] = -1;
1404 patchSizes[allPatchi] = nFaces[patch0];
1405 patchStarts[allPatchi] = startFacei;
1408 from0ToAllPatches[patch0] = allPatchi;
1411 if (fromAllTo1Patches[patch0] != -1)
1413 from1ToAllPatches[fromAllTo1Patches[patch0]] = allPatchi;
1416 startFacei += nFaces[patch0];
1424 const label sz0 = from0ToAllPatches.
size();
1429 if (from0ToAllPatches[
patchi] != -1)
1431 newToOld[nNew++] =
patchi;
1439 forAll(from1ToAllPatches, patch1)
1441 label uncompactAllPatchi = from1ToAllPatches[patch1];
1443 if (uncompactAllPatchi >= from0ToAllPatches.
size())
1449 nFaces[uncompactAllPatchi] == 0
1450 && isA<processorPolyPatch>(patches1[patch1])
1455 from1ToAllPatches[patch1] = -1;
1459 patchSizes[allPatchi] = nFaces[uncompactAllPatchi];
1460 patchStarts[allPatchi] = startFacei;
1465 mesh0.
addPatch(allPatchi, patches1[patch1]);
1468 from1ToAllPatches[patch1] = allPatchi;
1470 startFacei += nFaces[uncompactAllPatchi];
1476 patchSizes.
setSize(allPatchi);
1477 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 append(T *)
Append an element at the end of the list.
label size() const
Return the number of elements in the UPtrList.
void clear()
Clear the zones.
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
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 pointZoneList & pointZones() const
Return point zones.
const cellZoneList & cellZones() const
Return cell zones.
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.
void resetMotion() const
Reset motion.
const faceZoneList & faceZones() const
Return face zones.
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
void addZones(const List< pointZone * > &pz, const List< faceZone * > &fz, const List< cellZone * > &cz)
Add mesh zones.
virtual void reorderPatches(const labelUList &newToOld, const bool validBoundary)
Reorder and trim existing patches. If validBoundary the new.
virtual void addPatch(const label insertPatchi, const polyPatch &patch)
Add/insert single patch.
IOporosityModelList pZones(mesh)
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
#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.
int order(const scalar s)
errorManip< error > abort(error &err)
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.
List< labelList > labelListList
A List of labelList.
List< List< bool > > boolListList
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.
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 > &)
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.