polyTopoChange.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
6  \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "polyTopoChange.H"
27 #include "SortableList.H"
28 #include "polyMesh.H"
29 #include "polyAddPoint.H"
30 #include "polyModifyPoint.H"
31 #include "polyRemovePoint.H"
32 #include "polyAddFace.H"
33 #include "polyModifyFace.H"
34 #include "polyRemoveFace.H"
35 #include "polyAddCell.H"
36 #include "polyModifyCell.H"
37 #include "polyRemoveCell.H"
38 #include "objectMap.H"
39 #include "processorPolyPatch.H"
40 #include "fvMesh.H"
41 #include "CompactListList.H"
42 #include "ListOps.H"
43 
44 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
45 
46 namespace Foam
47 {
48  defineTypeNameAndDebug(polyTopoChange, 0);
49 }
50 
51 
52 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
53 
54 // Renumber with special handling for merged items (marked with <-1)
56 (
57  const labelList& map,
58  DynamicList<label>& elems
59 )
60 {
61  forAll(elems, elemI)
62  {
63  label val = elems[elemI];
64 
65  if (val >= 0)
66  {
67  elems[elemI] = map[val];
68  }
69  else if (val < -1)
70  {
71  label mergedVal = -val-2;
72  elems[elemI] = -map[mergedVal]-2;
73  }
74  }
75 }
76 
77 
79 (
80  const labelList& map,
81  labelHashSet& elems
82 )
83 {
84  labelHashSet newElems(elems.size());
85 
86  forAllConstIter(labelHashSet, elems, iter)
87  {
88  label newElem = map[iter.key()];
89 
90  if (newElem >= 0)
91  {
92  newElems.insert(newElem);
93  }
94  }
95 
96  elems.transfer(newElems);
97 }
98 
99 
100 // Renumber and remove -1 elements.
102 (
103  const labelList& map,
104  labelList& elems
105 )
106 {
107  label newElemI = 0;
108 
109  forAll(elems, elemI)
110  {
111  label newVal = map[elems[elemI]];
112 
113  if (newVal != -1)
114  {
115  elems[newElemI++] = newVal;
116  }
117  }
118  elems.setSize(newElemI);
119 }
120 
121 
123 (
124  const labelList& map,
125  const labelList& reverseMap,
126  label& nAdd,
127  label& nInflate,
128  label& nMerge,
129  label& nRemove
130 )
131 {
132  nAdd = 0;
133  nInflate = 0;
134  nMerge = 0;
135  nRemove = 0;
136 
137  forAll(map, newCellI)
138  {
139  label oldCellI = map[newCellI];
140 
141  if (oldCellI >= 0)
142  {
143  if (reverseMap[oldCellI] == newCellI)
144  {
145  // unchanged
146  }
147  else
148  {
149  // Added (from another cell v.s. inflated from face/point)
150  nAdd++;
151  }
152  }
153  else if (oldCellI == -1)
154  {
155  // Created from nothing
156  nInflate++;
157  }
158  else
159  {
161  << " new:" << newCellI << abort(FatalError);
162  }
163  }
164 
165  forAll(reverseMap, oldCellI)
166  {
167  label newCellI = reverseMap[oldCellI];
168 
169  if (newCellI >= 0)
170  {
171  // unchanged
172  }
173  else if (newCellI == -1)
174  {
175  // removed
176  nRemove++;
177  }
178  else
179  {
180  // merged into -newCellI-2
181  nMerge++;
182  }
183  }
184 }
185 
186 
188 (
189  const PackedBoolList& lst
190 )
191 {
192  labelHashSet values(lst.count());
193  forAll(lst, i)
194  {
195  if (lst[i])
196  {
197  values.insert(i);
198  }
199  }
200  return values;
201 }
202 
203 
205 {
206  const polyBoundaryMesh& patches = mesh.boundaryMesh();
207 
208  labelList patchSizes(patches.size());
209  labelList patchStarts(patches.size());
210  forAll(patches, patchI)
211  {
212  patchSizes[patchI] = patches[patchI].size();
213  patchStarts[patchI] = patches[patchI].start();
214  }
215 
216  os << " Points : " << mesh.nPoints() << nl
217  << " Faces : " << mesh.nFaces() << nl
218  << " Cells : " << mesh.nCells() << nl
219  << " PatchSizes : " << patchSizes << nl
220  << " PatchStarts : " << patchStarts << nl
221  << endl;
222 }
223 
224 
226 (
227  const labelList& reverseCellMap,
228  const labelList& cellMap,
229  List<objectMap>& cellsFromCells
230 )
231 {
232  // Per new cell the number of old cells that have been merged into it
233  labelList nMerged(cellMap.size(), 1);
234 
235  forAll(reverseCellMap, oldCellI)
236  {
237  label newCellI = reverseCellMap[oldCellI];
238 
239  if (newCellI < -1)
240  {
241  label mergeCellI = -newCellI-2;
242 
243  nMerged[mergeCellI]++;
244  }
245  }
246 
247  // From merged cell to set index
248  labelList cellToMergeSet(cellMap.size(), -1);
249 
250  label nSets = 0;
251 
252  forAll(nMerged, cellI)
253  {
254  if (nMerged[cellI] > 1)
255  {
256  cellToMergeSet[cellI] = nSets++;
257  }
258  }
259 
260  // Collect cell labels.
261  // Each objectMap will have
262  // - index : new mesh cell label
263  // - masterObjects : list of old cells that have been merged. Element 0
264  // will be the original destination cell label.
265 
266  cellsFromCells.setSize(nSets);
267 
268  forAll(reverseCellMap, oldCellI)
269  {
270  label newCellI = reverseCellMap[oldCellI];
271 
272  if (newCellI < -1)
273  {
274  label mergeCellI = -newCellI-2;
275 
276  // oldCellI was merged into mergeCellI
277 
278  label setI = cellToMergeSet[mergeCellI];
279 
280  objectMap& mergeSet = cellsFromCells[setI];
281 
282  if (mergeSet.masterObjects().empty())
283  {
284  // First occurrence of master cell mergeCellI
285 
286  mergeSet.index() = mergeCellI;
287  mergeSet.masterObjects().setSize(nMerged[mergeCellI]);
288 
289  // old master label
290  mergeSet.masterObjects()[0] = cellMap[mergeCellI];
291 
292  // old slave label
293  mergeSet.masterObjects()[1] = oldCellI;
294 
295  nMerged[mergeCellI] = 2;
296  }
297  else
298  {
299  mergeSet.masterObjects()[nMerged[mergeCellI]++] = oldCellI;
300  }
301  }
302  }
303 }
304 
305 
307 {
308  forAll(f, fp)
309  {
310  if (f[fp] < 0 || f[fp] >= points_.size())
311  {
312  return false;
313  }
314  }
315  return true;
316 }
317 
318 
320 {
321  pointField points(f.size());
322  forAll(f, fp)
323  {
324  if (f[fp] < 0 && f[fp] >= points_.size())
325  {
327  << "Problem." << abort(FatalError);
328  }
329  points[fp] = points_[f[fp]];
330  }
331  return points;
332 }
333 
334 
336 (
337  const face& f,
338  const label faceI,
339  const label own,
340  const label nei,
341  const label patchI,
342  const label zoneI
343 ) const
344 {
345  if (nei == -1)
346  {
347  if (own == -1 && zoneI != -1)
348  {
349  // retired face
350  }
351  else if (patchI == -1 || patchI >= nPatches_)
352  {
354  << "Face has no neighbour (so external) but does not have"
355  << " a valid patch" << nl
356  << "f:" << f
357  << " faceI(-1 if added face):" << faceI
358  << " own:" << own << " nei:" << nei
359  << " patchI:" << patchI << nl;
360  if (hasValidPoints(f))
361  {
362  FatalError
363  << "points (removed points marked with "
364  << vector::max << ") " << facePoints(f);
365  }
367  }
368  }
369  else
370  {
371  if (patchI != -1)
372  {
374  << "Cannot both have valid patchI and neighbour" << nl
375  << "f:" << f
376  << " faceI(-1 if added face):" << faceI
377  << " own:" << own << " nei:" << nei
378  << " patchI:" << patchI << nl;
379  if (hasValidPoints(f))
380  {
381  FatalError
382  << "points (removed points marked with "
383  << vector::max << ") : " << facePoints(f);
384  }
386  }
387 
388  if (nei <= own)
389  {
391  << "Owner cell label should be less than neighbour cell label"
392  << nl
393  << "f:" << f
394  << " faceI(-1 if added face):" << faceI
395  << " own:" << own << " nei:" << nei
396  << " patchI:" << patchI << nl;
397  if (hasValidPoints(f))
398  {
399  FatalError
400  << "points (removed points marked with "
401  << vector::max << ") : " << facePoints(f);
402  }
404  }
405  }
406 
407  if (f.size() < 3 || findIndex(f, -1) != -1)
408  {
410  << "Illegal vertices in face"
411  << nl
412  << "f:" << f
413  << " faceI(-1 if added face):" << faceI
414  << " own:" << own << " nei:" << nei
415  << " patchI:" << patchI << nl;
416  if (hasValidPoints(f))
417  {
418  FatalError
419  << "points (removed points marked with "
420  << vector::max << ") : " << facePoints(f);
421  }
423  }
424  if (faceI >= 0 && faceI < faces_.size() && faceRemoved(faceI))
425  {
427  << "Face already marked for removal"
428  << nl
429  << "f:" << f
430  << " faceI(-1 if added face):" << faceI
431  << " own:" << own << " nei:" << nei
432  << " patchI:" << patchI << nl;
433  if (hasValidPoints(f))
434  {
435  FatalError
436  << "points (removed points marked with "
437  << vector::max << ") : " << facePoints(f);
438  }
440  }
441  forAll(f, fp)
442  {
443  if (f[fp] < points_.size() && pointRemoved(f[fp]))
444  {
446  << "Face uses removed vertices"
447  << nl
448  << "f:" << f
449  << " faceI(-1 if added face):" << faceI
450  << " own:" << own << " nei:" << nei
451  << " patchI:" << patchI << nl;
452  if (hasValidPoints(f))
453  {
454  FatalError
455  << "points (removed points marked with "
456  << vector::max << ") : " << facePoints(f);
457  }
459  }
460  }
461 }
462 
463 
465 (
466  const label nActiveFaces,
467  labelList& cellFaces,
468  labelList& cellFaceOffsets
469 ) const
470 {
471  cellFaces.setSize(2*nActiveFaces);
472  cellFaceOffsets.setSize(cellMap_.size() + 1);
473 
474  // Faces per cell
475  labelList nNbrs(cellMap_.size(), 0);
476 
477  // 1. Count faces per cell
478 
479  for (label faceI = 0; faceI < nActiveFaces; faceI++)
480  {
481  if (faceOwner_[faceI] < 0)
482  {
483  pointField newPoints;
484  if (faceI < faces_.size())
485  {
486  const face& f = faces_[faceI];
487  newPoints.setSize(f.size(), vector::max);
488  forAll(f, fp)
489  {
490  if (f[fp] < points_.size())
491  {
492  newPoints[fp] = points_[f[fp]];
493  }
494  }
495  }
496 
497 
499  << "Face " << faceI << " is active but its owner has"
500  << " been deleted. This is usually due to deleting cells"
501  << " without modifying exposed faces to be boundary faces."
502  << exit(FatalError);
503  }
504  nNbrs[faceOwner_[faceI]]++;
505  }
506  for (label faceI = 0; faceI < nActiveFaces; faceI++)
507  {
508  if (faceNeighbour_[faceI] >= 0)
509  {
510  nNbrs[faceNeighbour_[faceI]]++;
511  }
512  }
513 
514  // 2. Calculate offsets
515 
516  cellFaceOffsets[0] = 0;
517  forAll(nNbrs, cellI)
518  {
519  cellFaceOffsets[cellI+1] = cellFaceOffsets[cellI] + nNbrs[cellI];
520  }
521 
522  // 3. Fill faces per cell
523 
524  // reset the whole list to use as counter
525  nNbrs = 0;
526 
527  for (label faceI = 0; faceI < nActiveFaces; faceI++)
528  {
529  label cellI = faceOwner_[faceI];
530 
531  cellFaces[cellFaceOffsets[cellI] + nNbrs[cellI]++] = faceI;
532  }
533 
534  for (label faceI = 0; faceI < nActiveFaces; faceI++)
535  {
536  label cellI = faceNeighbour_[faceI];
537 
538  if (cellI >= 0)
539  {
540  cellFaces[cellFaceOffsets[cellI] + nNbrs[cellI]++] = faceI;
541  }
542  }
543 
544  // Last offset points to beyond end of cellFaces.
545  cellFaces.setSize(cellFaceOffsets[cellMap_.size()]);
546 }
547 
548 
549 // Create cell-cell addressing. Called after compaction (but before ordering)
550 // of faces
552 (
553  const label nActiveFaces,
554  CompactListList<label>& cellCells
555 ) const
556 {
557  // Neighbours per cell
558  labelList nNbrs(cellMap_.size(), 0);
559 
560  // 1. Count neighbours (through internal faces) per cell
561 
562  for (label faceI = 0; faceI < nActiveFaces; faceI++)
563  {
564  if (faceNeighbour_[faceI] >= 0)
565  {
566  nNbrs[faceOwner_[faceI]]++;
567  nNbrs[faceNeighbour_[faceI]]++;
568  }
569  }
570 
571  // 2. Construct csr
572  cellCells.setSize(nNbrs);
573 
574 
575  // 3. Fill faces per cell
576 
577  // reset the whole list to use as counter
578  nNbrs = 0;
579 
580  for (label faceI = 0; faceI < nActiveFaces; faceI++)
581  {
582  label nei = faceNeighbour_[faceI];
583 
584  if (nei >= 0)
585  {
586  label own = faceOwner_[faceI];
587  cellCells.m()[cellCells.index(own, nNbrs[own]++)] = nei;
588  cellCells.m()[cellCells.index(nei, nNbrs[nei]++)] = own;
589  }
590  }
591 }
592 
593 
594 // Cell ordering (based on bandCompression).
595 // Handles removed cells. Returns number of remaining cells.
597 (
598  const CompactListList<label>& cellCellAddressing,
599  labelList& oldToNew
600 ) const
601 {
602  labelList newOrder(cellCellAddressing.size());
603 
604  // Fifo buffer for string of cells
605  SLList<label> nextCell;
606 
607  // Whether cell has been done already
608  PackedBoolList visited(cellCellAddressing.size());
609 
610  label cellInOrder = 0;
611 
612 
613  // Work arrays. Kept outside of loop to minimise allocations.
614  // - neighbour cells
615  DynamicList<label> nbrs;
616  // - corresponding weights
617  DynamicList<label> weights;
618 
619  // - ordering
620  labelList order;
621 
622 
623  while (true)
624  {
625  // For a disconnected region find the lowest connected cell.
626 
627  label currentCell = -1;
628  label minWeight = labelMax;
629 
630  forAll(visited, cellI)
631  {
632  // find the lowest connected cell that has not been visited yet
633  if (!cellRemoved(cellI) && !visited[cellI])
634  {
635  if (cellCellAddressing[cellI].size() < minWeight)
636  {
637  minWeight = cellCellAddressing[cellI].size();
638  currentCell = cellI;
639  }
640  }
641  }
642 
643 
644  if (currentCell == -1)
645  {
646  break;
647  }
648 
649 
650  // Starting from currentCell walk breadth-first
651 
652 
653  // use this cell as a start
654  nextCell.append(currentCell);
655 
656  // loop through the nextCell list. Add the first cell into the
657  // cell order if it has not already been visited and ask for its
658  // neighbours. If the neighbour in question has not been visited,
659  // add it to the end of the nextCell list
660 
661  while (nextCell.size())
662  {
663  currentCell = nextCell.removeHead();
664 
665  if (!visited[currentCell])
666  {
667  visited[currentCell] = 1;
668 
669  // add into cellOrder
670  newOrder[cellInOrder] = currentCell;
671  cellInOrder++;
672 
673  // find if the neighbours have been visited
674  const labelUList neighbours = cellCellAddressing[currentCell];
675 
676  // Add in increasing order of connectivity
677 
678  // 1. Count neighbours of unvisited neighbours
679  nbrs.clear();
680  weights.clear();
681 
682  forAll(neighbours, nI)
683  {
684  label nbr = neighbours[nI];
685  if (!cellRemoved(nbr) && !visited[nbr])
686  {
687  // not visited, add to the list
688  nbrs.append(nbr);
689  weights.append(cellCellAddressing[nbr].size());
690  }
691  }
692  // 2. Sort
693  sortedOrder(weights, order);
694  // 3. Add in sorted order
695  forAll(order, i)
696  {
697  nextCell.append(nbrs[i]);
698  }
699  }
700  }
701  }
702 
703  // Now we have new-to-old in newOrder.
704  newOrder.setSize(cellInOrder);
705 
706  // Invert to get old-to-new. Make sure removed (i.e. unmapped) cells are -1.
707  oldToNew = invert(cellCellAddressing.size(), newOrder);
708 
709  return cellInOrder;
710 }
711 
712 
713 // Determine order for faces:
714 // - upper-triangular order for internal faces
715 // - external faces after internal faces and in patch order.
717 (
718  const label nActiveFaces,
719  const labelList& cellFaces,
720  const labelList& cellFaceOffsets,
721 
722  labelList& oldToNew,
723  labelList& patchSizes,
724  labelList& patchStarts
725 ) const
726 {
727  oldToNew.setSize(faceOwner_.size());
728  oldToNew = -1;
729 
730  // First unassigned face
731  label newFaceI = 0;
732 
733  labelList nbr;
734  labelList order;
735 
736  forAll(cellMap_, cellI)
737  {
738  label startOfCell = cellFaceOffsets[cellI];
739  label nFaces = cellFaceOffsets[cellI+1] - startOfCell;
740 
741  // Neighbouring cells
742  //SortableList<label> nbr(nFaces);
743  nbr.setSize(nFaces);
744 
745  for (label i = 0; i < nFaces; i++)
746  {
747  label faceI = cellFaces[startOfCell + i];
748 
749  label nbrCellI = faceNeighbour_[faceI];
750 
751  if (faceI >= nActiveFaces)
752  {
753  // Retired face.
754  nbr[i] = -1;
755  }
756  else if (nbrCellI != -1)
757  {
758  // Internal face. Get cell on other side.
759  if (nbrCellI == cellI)
760  {
761  nbrCellI = faceOwner_[faceI];
762  }
763 
764  if (cellI < nbrCellI)
765  {
766  // CellI is master
767  nbr[i] = nbrCellI;
768  }
769  else
770  {
771  // nbrCell is master. Let it handle this face.
772  nbr[i] = -1;
773  }
774  }
775  else
776  {
777  // External face. Do later.
778  nbr[i] = -1;
779  }
780  }
781 
782  //nbr.sort();
783  order.setSize(nFaces);
784  sortedOrder(nbr, order);
785 
786  //forAll(nbr, i)
787  //{
788  // if (nbr[i] != -1)
789  // {
790  // oldToNew[cellFaces[startOfCell + nbr.indices()[i]]] =
791  // newFaceI++;
792  // }
793  //}
794  forAll(order, i)
795  {
796  label index = order[i];
797  if (nbr[index] != -1)
798  {
799  oldToNew[cellFaces[startOfCell + index]] = newFaceI++;
800  }
801  }
802  }
803 
804 
805  // Pick up all patch faces in patch face order.
806  patchStarts.setSize(nPatches_);
807  patchStarts = 0;
808  patchSizes.setSize(nPatches_);
809  patchSizes = 0;
810 
811  if (nPatches_ > 0)
812  {
813  patchStarts[0] = newFaceI;
814 
815  for (label faceI = 0; faceI < nActiveFaces; faceI++)
816  {
817  if (region_[faceI] >= 0)
818  {
819  patchSizes[region_[faceI]]++;
820  }
821  }
822 
823  label faceI = patchStarts[0];
824 
825  forAll(patchStarts, patchI)
826  {
827  patchStarts[patchI] = faceI;
828  faceI += patchSizes[patchI];
829  }
830  }
831 
832  //if (debug)
833  //{
834  // Pout<< "patchSizes:" << patchSizes << nl
835  // << "patchStarts:" << patchStarts << endl;
836  //}
837 
838  labelList workPatchStarts(patchStarts);
839 
840  for (label faceI = 0; faceI < nActiveFaces; faceI++)
841  {
842  if (region_[faceI] >= 0)
843  {
844  oldToNew[faceI] = workPatchStarts[region_[faceI]]++;
845  }
846  }
847 
848  // Retired faces.
849  for (label faceI = nActiveFaces; faceI < oldToNew.size(); faceI++)
850  {
851  oldToNew[faceI] = faceI;
852  }
853 
854  // Check done all faces.
855  forAll(oldToNew, faceI)
856  {
857  if (oldToNew[faceI] == -1)
858  {
860  << "Did not determine new position"
861  << " for face " << faceI
862  << " owner " << faceOwner_[faceI]
863  << " neighbour " << faceNeighbour_[faceI]
864  << " region " << region_[faceI] << endl
865  << "This is usually caused by not specifying a patch for"
866  << " a boundary face." << nl
867  << "Switch on the polyTopoChange::debug flag to catch"
868  << " this error earlier." << nl;
869  if (hasValidPoints(faces_[faceI]))
870  {
871  FatalError
872  << "points (removed points marked with "
873  << vector::max << ") " << facePoints(faces_[faceI]);
874  }
876  }
877  }
878 }
879 
880 
881 // Reorder and compact faces according to map.
883 (
884  const label newSize,
885  const labelList& oldToNew
886 )
887 {
888  reorder(oldToNew, faces_);
889  faces_.setCapacity(newSize);
890 
891  reorder(oldToNew, region_);
892  region_.setCapacity(newSize);
893 
894  reorder(oldToNew, faceOwner_);
895  faceOwner_.setCapacity(newSize);
896 
897  reorder(oldToNew, faceNeighbour_);
898  faceNeighbour_.setCapacity(newSize);
899 
900  // Update faceMaps.
901  reorder(oldToNew, faceMap_);
902  faceMap_.setCapacity(newSize);
903 
904  renumberReverseMap(oldToNew, reverseFaceMap_);
905 
906  renumberKey(oldToNew, faceFromPoint_);
907  renumberKey(oldToNew, faceFromEdge_);
908  inplaceReorder(oldToNew, flipFaceFlux_);
909  flipFaceFlux_.setCapacity(newSize);
910  renumberKey(oldToNew, faceZone_);
911  inplaceReorder(oldToNew, faceZoneFlip_);
912  faceZoneFlip_.setCapacity(newSize);
913 }
914 
915 
916 // Compact all and orders points and faces:
917 // - points into internal followed by external points
918 // - internalfaces upper-triangular
919 // - externalfaces after internal ones.
921 (
922  const bool orderCells,
923  const bool orderPoints,
924  label& nInternalPoints,
925  labelList& patchSizes,
926  labelList& patchStarts
927 )
928 {
929  points_.shrink();
930  pointMap_.shrink();
931  reversePointMap_.shrink();
932 
933  faces_.shrink();
934  region_.shrink();
935  faceOwner_.shrink();
936  faceNeighbour_.shrink();
937  faceMap_.shrink();
938  reverseFaceMap_.shrink();
939 
940  cellMap_.shrink();
941  reverseCellMap_.shrink();
942  cellZone_.shrink();
943 
944 
945  // Compact points
946  label nActivePoints = 0;
947  {
948  labelList localPointMap(points_.size(), -1);
949  label newPointI = 0;
950 
951  if (!orderPoints)
952  {
953  nInternalPoints = -1;
954 
955  forAll(points_, pointI)
956  {
957  if (!pointRemoved(pointI) && !retiredPoints_.found(pointI))
958  {
959  localPointMap[pointI] = newPointI++;
960  }
961  }
962  nActivePoints = newPointI;
963  }
964  else
965  {
966  forAll(points_, pointI)
967  {
968  if (!pointRemoved(pointI) && !retiredPoints_.found(pointI))
969  {
970  nActivePoints++;
971  }
972  }
973 
974  // Mark boundary points
975  forAll(faceOwner_, faceI)
976  {
977  if
978  (
979  !faceRemoved(faceI)
980  && faceOwner_[faceI] >= 0
981  && faceNeighbour_[faceI] < 0
982  )
983  {
984  // Valid boundary face
985  const face& f = faces_[faceI];
986 
987  forAll(f, fp)
988  {
989  label pointI = f[fp];
990 
991  if (localPointMap[pointI] == -1)
992  {
993  if
994  (
995  pointRemoved(pointI)
996  || retiredPoints_.found(pointI)
997  )
998  {
1000  << "Removed or retired point " << pointI
1001  << " in face " << f
1002  << " at position " << faceI << endl
1003  << "Probably face has not been adapted for"
1004  << " removed points." << abort(FatalError);
1005  }
1006  localPointMap[pointI] = newPointI++;
1007  }
1008  }
1009  }
1010  }
1011 
1012  label nBoundaryPoints = newPointI;
1013  nInternalPoints = nActivePoints - nBoundaryPoints;
1014 
1015  // Move the boundary addressing up
1016  forAll(localPointMap, pointI)
1017  {
1018  if (localPointMap[pointI] != -1)
1019  {
1020  localPointMap[pointI] += nInternalPoints;
1021  }
1022  }
1023 
1024  newPointI = 0;
1025 
1026  // Mark internal points
1027  forAll(faceOwner_, faceI)
1028  {
1029  if
1030  (
1031  !faceRemoved(faceI)
1032  && faceOwner_[faceI] >= 0
1033  && faceNeighbour_[faceI] >= 0
1034  )
1035  {
1036  // Valid internal face
1037  const face& f = faces_[faceI];
1038 
1039  forAll(f, fp)
1040  {
1041  label pointI = f[fp];
1042 
1043  if (localPointMap[pointI] == -1)
1044  {
1045  if
1046  (
1047  pointRemoved(pointI)
1048  || retiredPoints_.found(pointI)
1049  )
1050  {
1052  << "Removed or retired point " << pointI
1053  << " in face " << f
1054  << " at position " << faceI << endl
1055  << "Probably face has not been adapted for"
1056  << " removed points." << abort(FatalError);
1057  }
1058  localPointMap[pointI] = newPointI++;
1059  }
1060  }
1061  }
1062  }
1063 
1064  if (newPointI != nInternalPoints)
1065  {
1067  << "Problem." << abort(FatalError);
1068  }
1069  newPointI = nActivePoints;
1070  }
1071 
1072  forAllConstIter(labelHashSet, retiredPoints_, iter)
1073  {
1074  localPointMap[iter.key()] = newPointI++;
1075  }
1076 
1077 
1078  if (debug)
1079  {
1080  Pout<< "Points : active:" << nActivePoints
1081  << " removed:" << points_.size()-newPointI << endl;
1082  }
1083 
1084  reorder(localPointMap, points_);
1085  points_.setCapacity(newPointI);
1086 
1087  // Update pointMaps
1088  reorder(localPointMap, pointMap_);
1089  pointMap_.setCapacity(newPointI);
1090  renumberReverseMap(localPointMap, reversePointMap_);
1091 
1092  renumberKey(localPointMap, pointZone_);
1093  renumber(localPointMap, retiredPoints_);
1094 
1095  // Use map to relabel face vertices
1096  forAll(faces_, faceI)
1097  {
1098  face& f = faces_[faceI];
1099 
1100  //labelList oldF(f);
1101  renumberCompact(localPointMap, f);
1102 
1103  if (!faceRemoved(faceI) && f.size() < 3)
1104  {
1106  << "Created illegal face " << f
1107  //<< " from face " << oldF
1108  << " at position:" << faceI
1109  << " when filtering removed points"
1110  << abort(FatalError);
1111  }
1112  }
1113  }
1114 
1115 
1116  // Compact faces.
1117  {
1118  labelList localFaceMap(faces_.size(), -1);
1119  label newFaceI = 0;
1120 
1121  forAll(faces_, faceI)
1122  {
1123  if (!faceRemoved(faceI) && faceOwner_[faceI] >= 0)
1124  {
1125  localFaceMap[faceI] = newFaceI++;
1126  }
1127  }
1128  nActiveFaces_ = newFaceI;
1129 
1130  forAll(faces_, faceI)
1131  {
1132  if (!faceRemoved(faceI) && faceOwner_[faceI] < 0)
1133  {
1134  // Retired face
1135  localFaceMap[faceI] = newFaceI++;
1136  }
1137  }
1138 
1139  if (debug)
1140  {
1141  Pout<< "Faces : active:" << nActiveFaces_
1142  << " removed:" << faces_.size()-newFaceI << endl;
1143  }
1144 
1145  // Reorder faces.
1146  reorderCompactFaces(newFaceI, localFaceMap);
1147  }
1148 
1149  // Compact cells.
1150  {
1151  labelList localCellMap;
1152  label newCellI;
1153 
1154  if (orderCells)
1155  {
1156  // Construct cellCell addressing
1157  CompactListList<label> cellCells;
1158  makeCellCells(nActiveFaces_, cellCells);
1159 
1160  // Cell ordering (based on bandCompression). Handles removed cells.
1161  newCellI = getCellOrder(cellCells, localCellMap);
1162  }
1163  else
1164  {
1165  // Compact out removed cells
1166  localCellMap.setSize(cellMap_.size());
1167  localCellMap = -1;
1168 
1169  newCellI = 0;
1170  forAll(cellMap_, cellI)
1171  {
1172  if (!cellRemoved(cellI))
1173  {
1174  localCellMap[cellI] = newCellI++;
1175  }
1176  }
1177  }
1178 
1179  if (debug)
1180  {
1181  Pout<< "Cells : active:" << newCellI
1182  << " removed:" << cellMap_.size()-newCellI << endl;
1183  }
1184 
1185  // Renumber -if cells reordered or -if cells removed
1186  if (orderCells || (newCellI != cellMap_.size()))
1187  {
1188  reorder(localCellMap, cellMap_);
1189  cellMap_.setCapacity(newCellI);
1190  renumberReverseMap(localCellMap, reverseCellMap_);
1191 
1192  reorder(localCellMap, cellZone_);
1193  cellZone_.setCapacity(newCellI);
1194 
1195  renumberKey(localCellMap, cellFromPoint_);
1196  renumberKey(localCellMap, cellFromEdge_);
1197  renumberKey(localCellMap, cellFromFace_);
1198 
1199  // Renumber owner/neighbour. Take into account if neighbour suddenly
1200  // gets lower cell than owner.
1201  forAll(faceOwner_, faceI)
1202  {
1203  label own = faceOwner_[faceI];
1204  label nei = faceNeighbour_[faceI];
1205 
1206  if (own >= 0)
1207  {
1208  // Update owner
1209  faceOwner_[faceI] = localCellMap[own];
1210 
1211  if (nei >= 0)
1212  {
1213  // Update neighbour.
1214  faceNeighbour_[faceI] = localCellMap[nei];
1215 
1216  // Check if face needs reversing.
1217  if
1218  (
1219  faceNeighbour_[faceI] >= 0
1220  && faceNeighbour_[faceI] < faceOwner_[faceI]
1221  )
1222  {
1223  faces_[faceI].flip();
1224  Swap(faceOwner_[faceI], faceNeighbour_[faceI]);
1225  flipFaceFlux_[faceI] =
1226  (
1227  flipFaceFlux_[faceI]
1228  ? 0
1229  : 1
1230  );
1231  faceZoneFlip_[faceI] =
1232  (
1233  faceZoneFlip_[faceI]
1234  ? 0
1235  : 1
1236  );
1237  }
1238  }
1239  }
1240  else if (nei >= 0)
1241  {
1242  // Update neighbour.
1243  faceNeighbour_[faceI] = localCellMap[nei];
1244  }
1245  }
1246  }
1247  }
1248 
1249  // Reorder faces into upper-triangular and patch ordering
1250  {
1251  // Create cells (packed storage)
1252  labelList cellFaces;
1253  labelList cellFaceOffsets;
1254  makeCells(nActiveFaces_, cellFaces, cellFaceOffsets);
1255 
1256  // Do upper triangular order and patch sorting
1257  labelList localFaceMap;
1258  getFaceOrder
1259  (
1260  nActiveFaces_,
1261  cellFaces,
1262  cellFaceOffsets,
1263 
1264  localFaceMap,
1265  patchSizes,
1266  patchStarts
1267  );
1268 
1269  // Reorder faces.
1270  reorderCompactFaces(localFaceMap.size(), localFaceMap);
1271  }
1272 }
1273 
1274 
1275 // Find faces to interpolate to create value for new face. Only used if
1276 // face was inflated from edge or point. Internal faces should only be
1277 // created from internal faces, external faces only from external faces
1278 // (and ideally the same patch)
1279 // Is bit problematic if there are no faces to select, i.e. in polyDualMesh
1280 // an internal face can be created from a boundary edge with no internal
1281 // faces connected to it.
1284  const primitiveMesh& mesh,
1285  const labelList& faceLabels,
1286  const bool internalFacesOnly
1287 )
1288 {
1289  label nFaces = 0;
1290 
1291  forAll(faceLabels, i)
1292  {
1293  label faceI = faceLabels[i];
1294 
1295  if (internalFacesOnly == mesh.isInternalFace(faceI))
1296  {
1297  nFaces++;
1298  }
1299  }
1300 
1301  labelList collectedFaces;
1302 
1303  if (nFaces == 0)
1304  {
1305  // Did not find any faces of the correct type so just use any old
1306  // face.
1307  collectedFaces = faceLabels;
1308  }
1309  else
1310  {
1311  collectedFaces.setSize(nFaces);
1312 
1313  nFaces = 0;
1314 
1315  forAll(faceLabels, i)
1316  {
1317  label faceI = faceLabels[i];
1318 
1319  if (internalFacesOnly == mesh.isInternalFace(faceI))
1320  {
1321  collectedFaces[nFaces++] = faceI;
1322  }
1323  }
1324  }
1325 
1326  return collectedFaces;
1327 }
1328 
1329 
1330 // Calculate pointMap per patch (so from patch point label to old patch point
1331 // label)
1334  const List<Map<label> >& oldPatchMeshPointMaps,
1335  const polyBoundaryMesh& boundary,
1336  labelListList& patchPointMap
1337 ) const
1338 {
1339  patchPointMap.setSize(boundary.size());
1340 
1341  forAll(boundary, patchI)
1342  {
1343  const labelList& meshPoints = boundary[patchI].meshPoints();
1344 
1345  const Map<label>& oldMeshPointMap = oldPatchMeshPointMaps[patchI];
1346 
1347  labelList& curPatchPointRnb = patchPointMap[patchI];
1348 
1349  curPatchPointRnb.setSize(meshPoints.size());
1350 
1351  forAll(meshPoints, i)
1352  {
1353  if (meshPoints[i] < pointMap_.size())
1354  {
1355  // Check if old point was part of same patch
1356  Map<label>::const_iterator ozmpmIter = oldMeshPointMap.find
1357  (
1358  pointMap_[meshPoints[i]]
1359  );
1360 
1361  if (ozmpmIter != oldMeshPointMap.end())
1362  {
1363  curPatchPointRnb[i] = ozmpmIter();
1364  }
1365  else
1366  {
1367  curPatchPointRnb[i] = -1;
1368  }
1369  }
1370  else
1371  {
1372  curPatchPointRnb[i] = -1;
1373  }
1374  }
1375  }
1376 }
1377 
1378 
1381  const polyMesh& mesh,
1382  List<objectMap>& facesFromPoints,
1383  List<objectMap>& facesFromEdges,
1384  List<objectMap>& facesFromFaces
1385 ) const
1386 {
1387  // Faces inflated from points
1388  // ~~~~~~~~~~~~~~~~~~~~~~~~~~
1389 
1390  facesFromPoints.setSize(faceFromPoint_.size());
1391 
1392  if (faceFromPoint_.size())
1393  {
1394  label nFacesFromPoints = 0;
1395 
1396  // Collect all still existing faces connected to this point.
1397  forAllConstIter(Map<label>, faceFromPoint_, iter)
1398  {
1399  label newFaceI = iter.key();
1400 
1401  if (region_[newFaceI] == -1)
1402  {
1403  // Get internal faces using point on old mesh
1404  facesFromPoints[nFacesFromPoints++] = objectMap
1405  (
1406  newFaceI,
1407  selectFaces
1408  (
1409  mesh,
1410  mesh.pointFaces()[iter()],
1411  true
1412  )
1413  );
1414  }
1415  else
1416  {
1417  // Get patch faces using point on old mesh
1418  facesFromPoints[nFacesFromPoints++] = objectMap
1419  (
1420  newFaceI,
1421  selectFaces
1422  (
1423  mesh,
1424  mesh.pointFaces()[iter()],
1425  false
1426  )
1427  );
1428  }
1429  }
1430  }
1431 
1432 
1433  // Faces inflated from edges
1434  // ~~~~~~~~~~~~~~~~~~~~~~~~~
1435 
1436  facesFromEdges.setSize(faceFromEdge_.size());
1437 
1438  if (faceFromEdge_.size())
1439  {
1440  label nFacesFromEdges = 0;
1441 
1442  // Collect all still existing faces connected to this edge.
1443  forAllConstIter(Map<label>, faceFromEdge_, iter)
1444  {
1445  label newFaceI = iter.key();
1446 
1447  if (region_[newFaceI] == -1)
1448  {
1449  // Get internal faces using edge on old mesh
1450  facesFromEdges[nFacesFromEdges++] = objectMap
1451  (
1452  newFaceI,
1453  selectFaces
1454  (
1455  mesh,
1456  mesh.edgeFaces(iter()),
1457  true
1458  )
1459  );
1460  }
1461  else
1462  {
1463  // Get patch faces using edge on old mesh
1464  facesFromEdges[nFacesFromEdges++] = objectMap
1465  (
1466  newFaceI,
1467  selectFaces
1468  (
1469  mesh,
1470  mesh.edgeFaces(iter()),
1471  false
1472  )
1473  );
1474  }
1475  }
1476  }
1477 
1478 
1479  // Faces from face merging
1480  // ~~~~~~~~~~~~~~~~~~~~~~~
1481 
1482  getMergeSets
1483  (
1484  reverseFaceMap_,
1485  faceMap_,
1486  facesFromFaces
1487  );
1488 }
1489 
1490 
1493  const polyMesh& mesh,
1494  List<objectMap>& cellsFromPoints,
1495  List<objectMap>& cellsFromEdges,
1496  List<objectMap>& cellsFromFaces,
1497  List<objectMap>& cellsFromCells
1498 ) const
1499 {
1500  cellsFromPoints.setSize(cellFromPoint_.size());
1501 
1502  if (cellFromPoint_.size())
1503  {
1504  label nCellsFromPoints = 0;
1505 
1506  // Collect all still existing faces connected to this point.
1507  forAllConstIter(Map<label>, cellFromPoint_, iter)
1508  {
1509  cellsFromPoints[nCellsFromPoints++] = objectMap
1510  (
1511  iter.key(),
1512  mesh.pointCells()[iter()]
1513  );
1514  }
1515  }
1516 
1517 
1518  cellsFromEdges.setSize(cellFromEdge_.size());
1519 
1520  if (cellFromEdge_.size())
1521  {
1522  label nCellsFromEdges = 0;
1523 
1524  // Collect all still existing faces connected to this point.
1525  forAllConstIter(Map<label>, cellFromEdge_, iter)
1526  {
1527  cellsFromEdges[nCellsFromEdges++] = objectMap
1528  (
1529  iter.key(),
1530  mesh.edgeCells()[iter()]
1531  );
1532  }
1533  }
1534 
1535 
1536  cellsFromFaces.setSize(cellFromFace_.size());
1537 
1538  if (cellFromFace_.size())
1539  {
1540  label nCellsFromFaces = 0;
1541 
1542  labelList twoCells(2);
1543 
1544  // Collect all still existing faces connected to this point.
1545  forAllConstIter(Map<label>, cellFromFace_, iter)
1546  {
1547  label oldFaceI = iter();
1548 
1549  if (mesh.isInternalFace(oldFaceI))
1550  {
1551  twoCells[0] = mesh.faceOwner()[oldFaceI];
1552  twoCells[1] = mesh.faceNeighbour()[oldFaceI];
1553  cellsFromFaces[nCellsFromFaces++] = objectMap
1554  (
1555  iter.key(),
1556  twoCells
1557  );
1558  }
1559  else
1560  {
1561  cellsFromFaces[nCellsFromFaces++] = objectMap
1562  (
1563  iter.key(),
1564  labelList(1, mesh.faceOwner()[oldFaceI])
1565  );
1566  }
1567  }
1568  }
1569 
1570 
1571  // Cells from cell merging
1572  // ~~~~~~~~~~~~~~~~~~~~~~~
1573 
1574  getMergeSets
1575  (
1576  reverseCellMap_,
1577  cellMap_,
1578  cellsFromCells
1579  );
1580 }
1581 
1582 
1585  const polyMesh& mesh,
1586  polyMesh& newMesh,
1587  labelListList& pointZoneMap,
1588  labelListList& faceZoneFaceMap,
1589  labelListList& cellZoneMap
1590 ) const
1591 {
1592  // pointZones
1593  // ~~~~~~~~~~
1594 
1595  pointZoneMap.setSize(mesh.pointZones().size());
1596  {
1597  const pointZoneMesh& pointZones = mesh.pointZones();
1598 
1599  // Count points per zone
1600 
1601  labelList nPoints(pointZones.size(), 0);
1602 
1603  forAllConstIter(Map<label>, pointZone_, iter)
1604  {
1605  label zoneI = iter();
1606 
1607  if (zoneI < 0 || zoneI >= pointZones.size())
1608  {
1610  << "Illegal zoneID " << zoneI << " for point "
1611  << iter.key() << " coord " << mesh.points()[iter.key()]
1612  << abort(FatalError);
1613  }
1614  nPoints[zoneI]++;
1615  }
1616 
1617  // Distribute points per zone
1618 
1619  labelListList addressing(pointZones.size());
1620  forAll(addressing, zoneI)
1621  {
1622  addressing[zoneI].setSize(nPoints[zoneI]);
1623  }
1624  nPoints = 0;
1625 
1626  forAllConstIter(Map<label>, pointZone_, iter)
1627  {
1628  label zoneI = iter();
1629 
1630  addressing[zoneI][nPoints[zoneI]++] = iter.key();
1631  }
1632  // Sort the addressing
1633  forAll(addressing, zoneI)
1634  {
1635  stableSort(addressing[zoneI]);
1636  }
1637 
1638  // So now we both have old zones and the new addressing.
1639  // Invert the addressing to get pointZoneMap.
1640  forAll(addressing, zoneI)
1641  {
1642  const pointZone& oldZone = pointZones[zoneI];
1643  const labelList& newZoneAddr = addressing[zoneI];
1644 
1645  labelList& curPzRnb = pointZoneMap[zoneI];
1646  curPzRnb.setSize(newZoneAddr.size());
1647 
1648  forAll(newZoneAddr, i)
1649  {
1650  if (newZoneAddr[i] < pointMap_.size())
1651  {
1652  curPzRnb[i] = oldZone.whichPoint(pointMap_[newZoneAddr[i]]);
1653  }
1654  else
1655  {
1656  curPzRnb[i] = -1;
1657  }
1658  }
1659  }
1660 
1661  // Reset the addresing on the zone
1662  newMesh.pointZones().clearAddressing();
1663  forAll(newMesh.pointZones(), zoneI)
1664  {
1665  if (debug)
1666  {
1667  Pout<< "pointZone:" << zoneI
1668  << " name:" << newMesh.pointZones()[zoneI].name()
1669  << " size:" << addressing[zoneI].size()
1670  << endl;
1671  }
1672 
1673  newMesh.pointZones()[zoneI] = addressing[zoneI];
1674  }
1675  }
1676 
1677 
1678  // faceZones
1679  // ~~~~~~~~~
1680 
1681  faceZoneFaceMap.setSize(mesh.faceZones().size());
1682  {
1683  const faceZoneMesh& faceZones = mesh.faceZones();
1684 
1685  labelList nFaces(faceZones.size(), 0);
1686 
1687  forAllConstIter(Map<label>, faceZone_, iter)
1688  {
1689  label zoneI = iter();
1690 
1691  if (zoneI < 0 || zoneI >= faceZones.size())
1692  {
1694  << "Illegal zoneID " << zoneI << " for face "
1695  << iter.key()
1696  << abort(FatalError);
1697  }
1698  nFaces[zoneI]++;
1699  }
1700 
1701  labelListList addressing(faceZones.size());
1702  boolListList flipMode(faceZones.size());
1703 
1704  forAll(addressing, zoneI)
1705  {
1706  addressing[zoneI].setSize(nFaces[zoneI]);
1707  flipMode[zoneI].setSize(nFaces[zoneI]);
1708  }
1709  nFaces = 0;
1710 
1711  forAllConstIter(Map<label>, faceZone_, iter)
1712  {
1713  label zoneI = iter();
1714  label faceI = iter.key();
1715 
1716  label index = nFaces[zoneI]++;
1717 
1718  addressing[zoneI][index] = faceI;
1719  flipMode[zoneI][index] = faceZoneFlip_[faceI];
1720  }
1721  // Sort the addressing
1722  forAll(addressing, zoneI)
1723  {
1724  labelList newToOld;
1725  sortedOrder(addressing[zoneI], newToOld);
1726  {
1727  labelList newAddressing(addressing[zoneI].size());
1728  forAll(newAddressing, i)
1729  {
1730  newAddressing[i] = addressing[zoneI][newToOld[i]];
1731  }
1732  addressing[zoneI].transfer(newAddressing);
1733  }
1734  {
1735  boolList newFlipMode(flipMode[zoneI].size());
1736  forAll(newFlipMode, i)
1737  {
1738  newFlipMode[i] = flipMode[zoneI][newToOld[i]];
1739  }
1740  flipMode[zoneI].transfer(newFlipMode);
1741  }
1742  }
1743 
1744  // So now we both have old zones and the new addressing.
1745  // Invert the addressing to get faceZoneFaceMap.
1746  forAll(addressing, zoneI)
1747  {
1748  const faceZone& oldZone = faceZones[zoneI];
1749  const labelList& newZoneAddr = addressing[zoneI];
1750 
1751  labelList& curFzFaceRnb = faceZoneFaceMap[zoneI];
1752 
1753  curFzFaceRnb.setSize(newZoneAddr.size());
1754 
1755  forAll(newZoneAddr, i)
1756  {
1757  if (newZoneAddr[i] < faceMap_.size())
1758  {
1759  curFzFaceRnb[i] =
1760  oldZone.whichFace(faceMap_[newZoneAddr[i]]);
1761  }
1762  else
1763  {
1764  curFzFaceRnb[i] = -1;
1765  }
1766  }
1767  }
1768 
1769 
1770  // Reset the addresing on the zone
1771  newMesh.faceZones().clearAddressing();
1772  forAll(newMesh.faceZones(), zoneI)
1773  {
1774  if (debug)
1775  {
1776  Pout<< "faceZone:" << zoneI
1777  << " name:" << newMesh.faceZones()[zoneI].name()
1778  << " size:" << addressing[zoneI].size()
1779  << endl;
1780  }
1781 
1782  newMesh.faceZones()[zoneI].resetAddressing
1783  (
1784  addressing[zoneI],
1785  flipMode[zoneI]
1786  );
1787  }
1788  }
1789 
1790 
1791  // cellZones
1792  // ~~~~~~~~~
1793 
1794  cellZoneMap.setSize(mesh.cellZones().size());
1795  {
1796  const cellZoneMesh& cellZones = mesh.cellZones();
1797 
1798  labelList nCells(cellZones.size(), 0);
1799 
1800  forAll(cellZone_, cellI)
1801  {
1802  label zoneI = cellZone_[cellI];
1803 
1804  if (zoneI >= cellZones.size())
1805  {
1807  << "Illegal zoneID " << zoneI << " for cell "
1808  << cellI << abort(FatalError);
1809  }
1810 
1811  if (zoneI >= 0)
1812  {
1813  nCells[zoneI]++;
1814  }
1815  }
1816 
1817  labelListList addressing(cellZones.size());
1818  forAll(addressing, zoneI)
1819  {
1820  addressing[zoneI].setSize(nCells[zoneI]);
1821  }
1822  nCells = 0;
1823 
1824  forAll(cellZone_, cellI)
1825  {
1826  label zoneI = cellZone_[cellI];
1827 
1828  if (zoneI >= 0)
1829  {
1830  addressing[zoneI][nCells[zoneI]++] = cellI;
1831  }
1832  }
1833  // Sort the addressing
1834  forAll(addressing, zoneI)
1835  {
1836  stableSort(addressing[zoneI]);
1837  }
1838 
1839  // So now we both have old zones and the new addressing.
1840  // Invert the addressing to get cellZoneMap.
1841  forAll(addressing, zoneI)
1842  {
1843  const cellZone& oldZone = cellZones[zoneI];
1844  const labelList& newZoneAddr = addressing[zoneI];
1845 
1846  labelList& curCellRnb = cellZoneMap[zoneI];
1847 
1848  curCellRnb.setSize(newZoneAddr.size());
1849 
1850  forAll(newZoneAddr, i)
1851  {
1852  if (newZoneAddr[i] < cellMap_.size())
1853  {
1854  curCellRnb[i] =
1855  oldZone.whichCell(cellMap_[newZoneAddr[i]]);
1856  }
1857  else
1858  {
1859  curCellRnb[i] = -1;
1860  }
1861  }
1862  }
1863 
1864  // Reset the addresing on the zone
1865  newMesh.cellZones().clearAddressing();
1866  forAll(newMesh.cellZones(), zoneI)
1867  {
1868  if (debug)
1869  {
1870  Pout<< "cellZone:" << zoneI
1871  << " name:" << newMesh.cellZones()[zoneI].name()
1872  << " size:" << addressing[zoneI].size()
1873  << endl;
1874  }
1875 
1876  newMesh.cellZones()[zoneI] = addressing[zoneI];
1877  }
1878  }
1879 }
1880 
1881 
1884  const polyMesh& mesh,
1885  const List<Map<label> >& oldFaceZoneMeshPointMaps,
1886  labelListList& faceZonePointMap
1887 ) const
1888 {
1889  const faceZoneMesh& faceZones = mesh.faceZones();
1890 
1891  faceZonePointMap.setSize(faceZones.size());
1892 
1893  forAll(faceZones, zoneI)
1894  {
1895  const faceZone& newZone = faceZones[zoneI];
1896 
1897  const labelList& newZoneMeshPoints = newZone().meshPoints();
1898 
1899  const Map<label>& oldZoneMeshPointMap = oldFaceZoneMeshPointMaps[zoneI];
1900 
1901  labelList& curFzPointRnb = faceZonePointMap[zoneI];
1902 
1903  curFzPointRnb.setSize(newZoneMeshPoints.size());
1904 
1905  forAll(newZoneMeshPoints, pointI)
1906  {
1907  if (newZoneMeshPoints[pointI] < pointMap_.size())
1908  {
1909  Map<label>::const_iterator ozmpmIter =
1910  oldZoneMeshPointMap.find
1911  (
1912  pointMap_[newZoneMeshPoints[pointI]]
1913  );
1914 
1915  if (ozmpmIter != oldZoneMeshPointMap.end())
1916  {
1917  curFzPointRnb[pointI] = ozmpmIter();
1918  }
1919  else
1920  {
1921  curFzPointRnb[pointI] = -1;
1922  }
1923  }
1924  else
1925  {
1926  curFzPointRnb[pointI] = -1;
1927  }
1928  }
1929  }
1930 }
1931 
1932 
1935  const bool syncParallel,
1936  const polyBoundaryMesh& boundary,
1937  const labelList& patchStarts,
1938  const labelList& patchSizes,
1939  const pointField& points
1940 )
1941 {
1942  // Mapping for faces (old to new). Extends over all mesh faces for
1943  // convenience (could be just the external faces)
1944  labelList oldToNew(identity(faces_.size()));
1945 
1946  // Rotation on new faces.
1947  labelList rotation(faces_.size(), 0);
1948 
1950 
1951  // Send ordering
1952  forAll(boundary, patchI)
1953  {
1954  if (syncParallel || !isA<processorPolyPatch>(boundary[patchI]))
1955  {
1956  boundary[patchI].initOrder
1957  (
1958  pBufs,
1960  (
1962  (
1963  faces_,
1964  patchSizes[patchI],
1965  patchStarts[patchI]
1966  ),
1967  points
1968  )
1969  );
1970  }
1971  }
1972 
1973  if (syncParallel)
1974  {
1975  pBufs.finishedSends();
1976  }
1977 
1978  // Receive and calculate ordering
1979 
1980  bool anyChanged = false;
1981 
1982  forAll(boundary, patchI)
1983  {
1984  if (syncParallel || !isA<processorPolyPatch>(boundary[patchI]))
1985  {
1986  labelList patchFaceMap(patchSizes[patchI], -1);
1987  labelList patchFaceRotation(patchSizes[patchI], 0);
1988 
1989  bool changed = boundary[patchI].order
1990  (
1991  pBufs,
1993  (
1995  (
1996  faces_,
1997  patchSizes[patchI],
1998  patchStarts[patchI]
1999  ),
2000  points
2001  ),
2002  patchFaceMap,
2003  patchFaceRotation
2004  );
2005 
2006  if (changed)
2007  {
2008  // Merge patch face reordering into mesh face reordering table
2009  label start = patchStarts[patchI];
2010 
2011  forAll(patchFaceMap, patchFaceI)
2012  {
2013  oldToNew[patchFaceI + start] =
2014  start + patchFaceMap[patchFaceI];
2015  }
2016 
2017  forAll(patchFaceRotation, patchFaceI)
2018  {
2019  rotation[patchFaceI + start] =
2020  patchFaceRotation[patchFaceI];
2021  }
2022 
2023  anyChanged = true;
2024  }
2025  }
2026  }
2027 
2028  if (syncParallel)
2029  {
2030  reduce(anyChanged, orOp<bool>());
2031  }
2032 
2033  if (anyChanged)
2034  {
2035  // Reorder faces according to oldToNew.
2036  reorderCompactFaces(oldToNew.size(), oldToNew);
2037 
2038  // Rotate faces (rotation is already in new face indices).
2039  forAll(rotation, faceI)
2040  {
2041  if (rotation[faceI] != 0)
2042  {
2043  inplaceRotateList<List, label>(faces_[faceI], rotation[faceI]);
2044  }
2045  }
2046  }
2047 }
2048 
2049 
2052  const polyMesh& mesh,
2053  const bool syncParallel,
2054  const bool orderCells,
2055  const bool orderPoints,
2056 
2057  label& nInternalPoints,
2058  pointField& newPoints,
2059  labelList& patchSizes,
2060  labelList& patchStarts,
2061  List<objectMap>& pointsFromPoints,
2062  List<objectMap>& facesFromPoints,
2063  List<objectMap>& facesFromEdges,
2064  List<objectMap>& facesFromFaces,
2065  List<objectMap>& cellsFromPoints,
2066  List<objectMap>& cellsFromEdges,
2067  List<objectMap>& cellsFromFaces,
2068  List<objectMap>& cellsFromCells,
2069  List<Map<label> >& oldPatchMeshPointMaps,
2070  labelList& oldPatchNMeshPoints,
2071  labelList& oldPatchStarts,
2072  List<Map<label> >& oldFaceZoneMeshPointMaps
2073 )
2074 {
2075  if (mesh.boundaryMesh().size() != nPatches_)
2076  {
2078  << "polyTopoChange was constructed with a mesh with "
2079  << nPatches_ << " patches." << endl
2080  << "The mesh now provided has a different number of patches "
2081  << mesh.boundaryMesh().size()
2082  << " which is illegal" << endl
2083  << abort(FatalError);
2084  }
2085 
2086  // Remove any holes from points/faces/cells and sort faces.
2087  // Sets nActiveFaces_.
2088  compact(orderCells, orderPoints, nInternalPoints, patchSizes, patchStarts);
2089 
2090  // Transfer points to pointField. points_ are now cleared!
2091  // Only done since e.g. reorderCoupledFaces requires pointField.
2092  newPoints.transfer(points_);
2093 
2094  // Reorder any coupled faces
2095  reorderCoupledFaces
2096  (
2097  syncParallel,
2098  mesh.boundaryMesh(),
2099  patchStarts,
2100  patchSizes,
2101  newPoints
2102  );
2103 
2104 
2105  // Calculate inflation/merging maps
2106  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2107  // These are for the new face(/point/cell) the old faces whose value
2108  // needs to be
2109  // averaged/summed to get the new value. These old faces come either from
2110  // merged old faces (face remove into other face),
2111  // the old edgeFaces (inflate from edge) or the old pointFaces (inflate
2112  // from point). As an additional complexity will use only internal faces
2113  // to create new value for internal face and vice versa only patch
2114  // faces to to create patch face value.
2115 
2116  // For point only point merging
2117  getMergeSets
2118  (
2119  reversePointMap_,
2120  pointMap_,
2121  pointsFromPoints
2122  );
2123 
2124  calcFaceInflationMaps
2125  (
2126  mesh,
2127  facesFromPoints,
2128  facesFromEdges,
2129  facesFromFaces
2130  );
2131 
2132  calcCellInflationMaps
2133  (
2134  mesh,
2135  cellsFromPoints,
2136  cellsFromEdges,
2137  cellsFromFaces,
2138  cellsFromCells
2139  );
2140 
2141  // Clear inflation info
2142  {
2143  faceFromPoint_.clearStorage();
2144  faceFromEdge_.clearStorage();
2145 
2146  cellFromPoint_.clearStorage();
2147  cellFromEdge_.clearStorage();
2148  cellFromFace_.clearStorage();
2149  }
2150 
2151 
2153 
2154  // Grab patch mesh point maps
2155  oldPatchMeshPointMaps.setSize(boundary.size());
2156  oldPatchNMeshPoints.setSize(boundary.size());
2157  oldPatchStarts.setSize(boundary.size());
2158 
2159  forAll(boundary, patchI)
2160  {
2161  // Copy old face zone mesh point maps
2162  oldPatchMeshPointMaps[patchI] = boundary[patchI].meshPointMap();
2163  oldPatchNMeshPoints[patchI] = boundary[patchI].meshPoints().size();
2164  oldPatchStarts[patchI] = boundary[patchI].start();
2165  }
2166 
2167  // Grab old face zone mesh point maps.
2168  // These need to be saved before resetting the mesh and are used
2169  // later on to calculate the faceZone pointMaps.
2170  oldFaceZoneMeshPointMaps.setSize(mesh.faceZones().size());
2171 
2172  forAll(mesh.faceZones(), zoneI)
2173  {
2174  const faceZone& oldZone = mesh.faceZones()[zoneI];
2175 
2176  oldFaceZoneMeshPointMaps[zoneI] = oldZone().meshPointMap();
2177  }
2178 }
2179 
2180 
2181 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
2182 
2183 // Construct from components
2185 :
2186  strict_(strict),
2187  nPatches_(nPatches),
2188  points_(0),
2189  pointMap_(0),
2190  reversePointMap_(0),
2191  pointZone_(0),
2192  retiredPoints_(0),
2193  faces_(0),
2194  region_(0),
2195  faceOwner_(0),
2196  faceNeighbour_(0),
2197  faceMap_(0),
2198  reverseFaceMap_(0),
2199  faceFromPoint_(0),
2200  faceFromEdge_(0),
2201  flipFaceFlux_(0),
2202  faceZone_(0),
2203  faceZoneFlip_(0),
2204  nActiveFaces_(0),
2205  cellMap_(0),
2206  reverseCellMap_(0),
2207  cellFromPoint_(0),
2208  cellFromEdge_(0),
2209  cellFromFace_(0),
2210  cellZone_(0)
2211 {}
2212 
2213 
2214 // Construct from components
2217  const polyMesh& mesh,
2218  const bool strict
2219 )
2220 :
2221  strict_(strict),
2222  nPatches_(0),
2223  points_(0),
2224  pointMap_(0),
2225  reversePointMap_(0),
2226  pointZone_(0),
2227  retiredPoints_(0),
2228  faces_(0),
2229  region_(0),
2230  faceOwner_(0),
2231  faceNeighbour_(0),
2232  faceMap_(0),
2233  reverseFaceMap_(0),
2234  faceFromPoint_(0),
2235  faceFromEdge_(0),
2236  flipFaceFlux_(0),
2237  faceZone_(0),
2238  faceZoneFlip_(0),
2239  nActiveFaces_(0),
2240  cellMap_(0),
2241  reverseCellMap_(0),
2242  cellFromPoint_(0),
2243  cellFromEdge_(0),
2244  cellFromFace_(0),
2245  cellZone_(0)
2246 {
2247  addMesh
2248  (
2249  mesh,
2251  identity(mesh.pointZones().size()),
2252  identity(mesh.faceZones().size()),
2253  identity(mesh.cellZones().size())
2254  );
2255 }
2256 
2257 
2258 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
2259 
2261 {
2262  points_.clearStorage();
2263  pointMap_.clearStorage();
2264  reversePointMap_.clearStorage();
2265  pointZone_.clearStorage();
2266  retiredPoints_.clearStorage();
2267 
2268  faces_.clearStorage();
2269  region_.clearStorage();
2270  faceOwner_.clearStorage();
2271  faceNeighbour_.clearStorage();
2272  faceMap_.clearStorage();
2273  reverseFaceMap_.clearStorage();
2274  faceFromPoint_.clearStorage();
2275  faceFromEdge_.clearStorage();
2276  flipFaceFlux_.clearStorage();
2277  faceZone_.clearStorage();
2278  faceZoneFlip_.clearStorage();
2279  nActiveFaces_ = 0;
2280 
2281  cellMap_.clearStorage();
2282  reverseCellMap_.clearStorage();
2283  cellZone_.clearStorage();
2284  cellFromPoint_.clearStorage();
2285  cellFromEdge_.clearStorage();
2286  cellFromFace_.clearStorage();
2287 }
2288 
2289 
2292  const polyMesh& mesh,
2293  const labelList& patchMap,
2294  const labelList& pointZoneMap,
2295  const labelList& faceZoneMap,
2296  const labelList& cellZoneMap
2297 )
2298 {
2299  label maxRegion = nPatches_ - 1;
2300  forAll(patchMap, i)
2301  {
2302  maxRegion = max(maxRegion, patchMap[i]);
2303  }
2304  nPatches_ = maxRegion + 1;
2305 
2306 
2307  // Add points
2308  {
2309  const pointField& points = mesh.points();
2310  const pointZoneMesh& pointZones = mesh.pointZones();
2311 
2312  // Extend
2313  points_.setCapacity(points_.size() + points.size());
2314  pointMap_.setCapacity(pointMap_.size() + points.size());
2315  reversePointMap_.setCapacity(reversePointMap_.size() + points.size());
2316  pointZone_.resize(pointZone_.size() + points.size()/100);
2317 
2318  // Precalc offset zones
2319  labelList newZoneID(points.size(), -1);
2320 
2321  forAll(pointZones, zoneI)
2322  {
2323  const labelList& pointLabels = pointZones[zoneI];
2324 
2325  forAll(pointLabels, j)
2326  {
2327  newZoneID[pointLabels[j]] = pointZoneMap[zoneI];
2328  }
2329  }
2330 
2331  // Add points in mesh order
2332  for (label pointI = 0; pointI < mesh.nPoints(); pointI++)
2333  {
2334  addPoint
2335  (
2336  points[pointI],
2337  pointI,
2338  newZoneID[pointI],
2339  true
2340  );
2341  }
2342  }
2343 
2344  // Add cells
2345  {
2346  const cellZoneMesh& cellZones = mesh.cellZones();
2347 
2348  // Resize
2349 
2350  // Note: polyMesh does not allow retired cells anymore. So allCells
2351  // always equals nCells
2352  label nAllCells = mesh.nCells();
2353 
2354  cellMap_.setCapacity(cellMap_.size() + nAllCells);
2355  reverseCellMap_.setCapacity(reverseCellMap_.size() + nAllCells);
2356  cellFromPoint_.resize(cellFromPoint_.size() + nAllCells/100);
2357  cellFromEdge_.resize(cellFromEdge_.size() + nAllCells/100);
2358  cellFromFace_.resize(cellFromFace_.size() + nAllCells/100);
2359  cellZone_.setCapacity(cellZone_.size() + nAllCells);
2360 
2361 
2362  // Precalc offset zones
2363  labelList newZoneID(nAllCells, -1);
2364 
2365  forAll(cellZones, zoneI)
2366  {
2367  const labelList& cellLabels = cellZones[zoneI];
2368 
2369  forAll(cellLabels, j)
2370  {
2371  label cellI = cellLabels[j];
2372 
2373  if (newZoneID[cellI] != -1)
2374  {
2376  << "Cell:" << cellI
2377  << " centre:" << mesh.cellCentres()[cellI]
2378  << " is in two zones:"
2379  << cellZones[newZoneID[cellI]].name()
2380  << " and " << cellZones[zoneI].name() << endl
2381  << " This is not supported."
2382  << " Continuing with first zone only." << endl;
2383  }
2384  else
2385  {
2386  newZoneID[cellI] = cellZoneMap[zoneI];
2387  }
2388  }
2389  }
2390 
2391  // Add cells in mesh order
2392  for (label cellI = 0; cellI < nAllCells; cellI++)
2393  {
2394  // Add cell from cell
2395  addCell(-1, -1, -1, cellI, newZoneID[cellI]);
2396  }
2397  }
2398 
2399  // Add faces
2400  {
2402  const faceList& faces = mesh.faces();
2403  const labelList& faceOwner = mesh.faceOwner();
2404  const labelList& faceNeighbour = mesh.faceNeighbour();
2405  const faceZoneMesh& faceZones = mesh.faceZones();
2406 
2407  // Resize
2408  label nAllFaces = mesh.faces().size();
2409 
2410  faces_.setCapacity(faces_.size() + nAllFaces);
2411  region_.setCapacity(region_.size() + nAllFaces);
2412  faceOwner_.setCapacity(faceOwner_.size() + nAllFaces);
2413  faceNeighbour_.setCapacity(faceNeighbour_.size() + nAllFaces);
2414  faceMap_.setCapacity(faceMap_.size() + nAllFaces);
2415  reverseFaceMap_.setCapacity(reverseFaceMap_.size() + nAllFaces);
2416  faceFromPoint_.resize(faceFromPoint_.size() + nAllFaces/100);
2417  faceFromEdge_.resize(faceFromEdge_.size() + nAllFaces/100);
2418  flipFaceFlux_.setCapacity(faces_.size() + nAllFaces);
2419  faceZone_.resize(faceZone_.size() + nAllFaces/100);
2420  faceZoneFlip_.setCapacity(faces_.size() + nAllFaces);
2421 
2422 
2423  // Precalc offset zones
2424  labelList newZoneID(nAllFaces, -1);
2425  boolList zoneFlip(nAllFaces, false);
2426 
2427  forAll(faceZones, zoneI)
2428  {
2429  const labelList& faceLabels = faceZones[zoneI];
2430  const boolList& flipMap = faceZones[zoneI].flipMap();
2431 
2432  forAll(faceLabels, j)
2433  {
2434  newZoneID[faceLabels[j]] = faceZoneMap[zoneI];
2435  zoneFlip[faceLabels[j]] = flipMap[j];
2436  }
2437  }
2438 
2439  // Add faces in mesh order
2440 
2441  // 1. Internal faces
2442  for (label faceI = 0; faceI < mesh.nInternalFaces(); faceI++)
2443  {
2444  addFace
2445  (
2446  faces[faceI],
2447  faceOwner[faceI],
2448  faceNeighbour[faceI],
2449  -1, // masterPointID
2450  -1, // masterEdgeID
2451  faceI, // masterFaceID
2452  false, // flipFaceFlux
2453  -1, // patchID
2454  newZoneID[faceI], // zoneID
2455  zoneFlip[faceI] // zoneFlip
2456  );
2457  }
2458 
2459  // 2. Patch faces
2460  forAll(patches, patchI)
2461  {
2462  const polyPatch& pp = patches[patchI];
2463 
2464  if (pp.start() != faces_.size())
2465  {
2467  << "Problem : "
2468  << "Patch " << pp.name() << " starts at " << pp.start()
2469  << endl
2470  << "Current face counter at " << faces_.size() << endl
2471  << "Are patches in incremental order?"
2472  << abort(FatalError);
2473  }
2474  forAll(pp, patchFaceI)
2475  {
2476  label faceI = pp.start() + patchFaceI;
2477 
2478  addFace
2479  (
2480  faces[faceI],
2481  faceOwner[faceI],
2482  -1, // neighbour
2483  -1, // masterPointID
2484  -1, // masterEdgeID
2485  faceI, // masterFaceID
2486  false, // flipFaceFlux
2487  patchMap[patchI], // patchID
2488  newZoneID[faceI], // zoneID
2489  zoneFlip[faceI] // zoneFlip
2490  );
2491  }
2492  }
2493  }
2494 }
2495 
2496 
2499  const label nPoints,
2500  const label nFaces,
2501  const label nCells
2502 )
2503 {
2504  points_.setCapacity(nPoints);
2505  pointMap_.setCapacity(nPoints);
2506  reversePointMap_.setCapacity(nPoints);
2507  pointZone_.resize(pointZone_.size() + nPoints/100);
2508 
2509  faces_.setCapacity(nFaces);
2510  region_.setCapacity(nFaces);
2511  faceOwner_.setCapacity(nFaces);
2512  faceNeighbour_.setCapacity(nFaces);
2513  faceMap_.setCapacity(nFaces);
2514  reverseFaceMap_.setCapacity(nFaces);
2515  faceFromPoint_.resize(faceFromPoint_.size() + nFaces/100);
2516  faceFromEdge_.resize(faceFromEdge_.size() + nFaces/100);
2517  flipFaceFlux_.setCapacity(nFaces);
2518  faceZone_.resize(faceZone_.size() + nFaces/100);
2519  faceZoneFlip_.setCapacity(nFaces);
2520 
2521  cellMap_.setCapacity(nCells);
2522  reverseCellMap_.setCapacity(nCells);
2523  cellFromPoint_.resize(cellFromPoint_.size() + nCells/100);
2524  cellFromEdge_.resize(cellFromEdge_.size() + nCells/100);
2525  cellFromFace_.resize(cellFromFace_.size() + nCells/100);
2526  cellZone_.setCapacity(nCells);
2527 }
2528 
2529 
2531 {
2532  if (isType<polyAddPoint>(action))
2533  {
2534  const polyAddPoint& pap = refCast<const polyAddPoint>(action);
2535 
2536  return addPoint
2537  (
2538  pap.newPoint(),
2539  pap.masterPointID(),
2540  pap.zoneID(),
2541  pap.inCell()
2542  );
2543  }
2544  else if (isType<polyModifyPoint>(action))
2545  {
2546  const polyModifyPoint& pmp = refCast<const polyModifyPoint>(action);
2547 
2548  modifyPoint
2549  (
2550  pmp.pointID(),
2551  pmp.newPoint(),
2552  pmp.zoneID(),
2553  pmp.inCell()
2554  );
2555 
2556  return -1;
2557  }
2558  else if (isType<polyRemovePoint>(action))
2559  {
2560  const polyRemovePoint& prp = refCast<const polyRemovePoint>(action);
2561 
2562  removePoint(prp.pointID(), prp.mergePointID());
2563 
2564  return -1;
2565  }
2566  else if (isType<polyAddFace>(action))
2567  {
2568  const polyAddFace& paf = refCast<const polyAddFace>(action);
2569 
2570  return addFace
2571  (
2572  paf.newFace(),
2573  paf.owner(),
2574  paf.neighbour(),
2575  paf.masterPointID(),
2576  paf.masterEdgeID(),
2577  paf.masterFaceID(),
2578  paf.flipFaceFlux(),
2579  paf.patchID(),
2580  paf.zoneID(),
2581  paf.zoneFlip()
2582  );
2583  }
2584  else if (isType<polyModifyFace>(action))
2585  {
2586  const polyModifyFace& pmf = refCast<const polyModifyFace>(action);
2587 
2588  modifyFace
2589  (
2590  pmf.newFace(),
2591  pmf.faceID(),
2592  pmf.owner(),
2593  pmf.neighbour(),
2594  pmf.flipFaceFlux(),
2595  pmf.patchID(),
2596  pmf.zoneID(),
2597  pmf.zoneFlip()
2598  );
2599 
2600  return -1;
2601  }
2602  else if (isType<polyRemoveFace>(action))
2603  {
2604  const polyRemoveFace& prf = refCast<const polyRemoveFace>(action);
2605 
2606  removeFace(prf.faceID(), prf.mergeFaceID());
2607 
2608  return -1;
2609  }
2610  else if (isType<polyAddCell>(action))
2611  {
2612  const polyAddCell& pac = refCast<const polyAddCell>(action);
2613 
2614  return addCell
2615  (
2616  pac.masterPointID(),
2617  pac.masterEdgeID(),
2618  pac.masterFaceID(),
2619  pac.masterCellID(),
2620  pac.zoneID()
2621  );
2622  }
2623  else if (isType<polyModifyCell>(action))
2624  {
2625  const polyModifyCell& pmc = refCast<const polyModifyCell>(action);
2626 
2627  if (pmc.removeFromZone())
2628  {
2629  modifyCell(pmc.cellID(), -1);
2630  }
2631  else
2632  {
2633  modifyCell(pmc.cellID(), pmc.zoneID());
2634  }
2635 
2636  return -1;
2637  }
2638  else if (isType<polyRemoveCell>(action))
2639  {
2640  const polyRemoveCell& prc = refCast<const polyRemoveCell>(action);
2641 
2642  removeCell(prc.cellID(), prc.mergeCellID());
2643 
2644  return -1;
2645  }
2646  else
2647  {
2649  << "Unknown type of topoChange: " << action.type()
2650  << abort(FatalError);
2651 
2652  // Dummy return to keep compiler happy
2653  return -1;
2654  }
2655 }
2656 
2657 
2660  const point& pt,
2661  const label masterPointID,
2662  const label zoneID,
2663  const bool inCell
2664 )
2665 {
2666  label pointI = points_.size();
2667 
2668  points_.append(pt);
2669  pointMap_.append(masterPointID);
2670  reversePointMap_.append(pointI);
2671 
2672  if (zoneID >= 0)
2673  {
2674  pointZone_.insert(pointI, zoneID);
2675  }
2676 
2677  if (!inCell)
2678  {
2679  retiredPoints_.insert(pointI);
2680  }
2681 
2682  return pointI;
2683 }
2684 
2685 
2688  const label pointI,
2689  const point& pt,
2690  const label newZoneID,
2691  const bool inCell
2692 )
2693 {
2694  if (pointI < 0 || pointI >= points_.size())
2695  {
2697  << "illegal point label " << pointI << endl
2698  << "Valid point labels are 0 .. " << points_.size()-1
2699  << abort(FatalError);
2700  }
2701  if (pointRemoved(pointI) || pointMap_[pointI] == -1)
2702  {
2704  << "point " << pointI << " already marked for removal"
2705  << abort(FatalError);
2706  }
2707  points_[pointI] = pt;
2708 
2709  Map<label>::iterator pointFnd = pointZone_.find(pointI);
2710 
2711  if (pointFnd != pointZone_.end())
2712  {
2713  if (newZoneID >= 0)
2714  {
2715  pointFnd() = newZoneID;
2716  }
2717  else
2718  {
2719  pointZone_.erase(pointFnd);
2720  }
2721  }
2722  else if (newZoneID >= 0)
2723  {
2724  pointZone_.insert(pointI, newZoneID);
2725  }
2726 
2727  if (inCell)
2728  {
2729  retiredPoints_.erase(pointI);
2730  }
2731  else
2732  {
2733  retiredPoints_.insert(pointI);
2734  }
2735 }
2736 
2737 
2739 {
2740  if (newPoints.size() != points_.size())
2741  {
2743  << "illegal pointField size." << endl
2744  << "Size:" << newPoints.size() << endl
2745  << "Points in mesh:" << points_.size()
2746  << abort(FatalError);
2747  }
2748 
2749  forAll(points_, pointI)
2750  {
2751  points_[pointI] = newPoints[pointI];
2752  }
2753 }
2754 
2755 
2758  const label pointI,
2759  const label mergePointI
2760 )
2761 {
2762  if (pointI < 0 || pointI >= points_.size())
2763  {
2765  << "illegal point label " << pointI << endl
2766  << "Valid point labels are 0 .. " << points_.size()-1
2767  << abort(FatalError);
2768  }
2769 
2770  if
2771  (
2772  strict_
2773  && (pointRemoved(pointI) || pointMap_[pointI] == -1)
2774  )
2775  {
2777  << "point " << pointI << " already marked for removal" << nl
2778  << "Point:" << points_[pointI] << " pointMap:" << pointMap_[pointI]
2779  << abort(FatalError);
2780  }
2781 
2782  if (pointI == mergePointI)
2783  {
2785  << "Cannot remove/merge point " << pointI << " onto itself."
2786  << abort(FatalError);
2787  }
2788 
2789  points_[pointI] = point::max;
2790  pointMap_[pointI] = -1;
2791  if (mergePointI >= 0)
2792  {
2793  reversePointMap_[pointI] = -mergePointI-2;
2794  }
2795  else
2796  {
2797  reversePointMap_[pointI] = -1;
2798  }
2799  pointZone_.erase(pointI);
2800  retiredPoints_.erase(pointI);
2801 }
2802 
2803 
2806  const face& f,
2807  const label own,
2808  const label nei,
2809  const label masterPointID,
2810  const label masterEdgeID,
2811  const label masterFaceID,
2812  const bool flipFaceFlux,
2813  const label patchID,
2814  const label zoneID,
2815  const bool zoneFlip
2816 )
2817 {
2818  // Check validity
2819  if (debug)
2820  {
2821  checkFace(f, -1, own, nei, patchID, zoneID);
2822  }
2823 
2824  label faceI = faces_.size();
2825 
2826  faces_.append(f);
2827  region_.append(patchID);
2828  faceOwner_.append(own);
2829  faceNeighbour_.append(nei);
2830 
2831  if (masterPointID >= 0)
2832  {
2833  faceMap_.append(-1);
2834  faceFromPoint_.insert(faceI, masterPointID);
2835  }
2836  else if (masterEdgeID >= 0)
2837  {
2838  faceMap_.append(-1);
2839  faceFromEdge_.insert(faceI, masterEdgeID);
2840  }
2841  else if (masterFaceID >= 0)
2842  {
2843  faceMap_.append(masterFaceID);
2844  }
2845  else
2846  {
2847  // Allow inflate-from-nothing?
2848  //FatalErrorInFunction
2849  // << "Need to specify a master point, edge or face"
2850  // << "face:" << f << " own:" << own << " nei:" << nei
2851  // << abort(FatalError);
2852  faceMap_.append(-1);
2853  }
2854  reverseFaceMap_.append(faceI);
2855 
2856  flipFaceFlux_[faceI] = (flipFaceFlux ? 1 : 0);
2857 
2858  if (zoneID >= 0)
2859  {
2860  faceZone_.insert(faceI, zoneID);
2861  }
2862  faceZoneFlip_[faceI] = (zoneFlip ? 1 : 0);
2863 
2864  return faceI;
2865 }
2866 
2867 
2870  const face& f,
2871  const label faceI,
2872  const label own,
2873  const label nei,
2874  const bool flipFaceFlux,
2875  const label patchID,
2876  const label zoneID,
2877  const bool zoneFlip
2878 )
2879 {
2880  // Check validity
2881  if (debug)
2882  {
2883  checkFace(f, faceI, own, nei, patchID, zoneID);
2884  }
2885 
2886  faces_[faceI] = f;
2887  faceOwner_[faceI] = own;
2888  faceNeighbour_[faceI] = nei;
2889  region_[faceI] = patchID;
2890 
2891  flipFaceFlux_[faceI] = (flipFaceFlux ? 1 : 0);
2892 
2893  Map<label>::iterator faceFnd = faceZone_.find(faceI);
2894 
2895  if (faceFnd != faceZone_.end())
2896  {
2897  if (zoneID >= 0)
2898  {
2899  faceFnd() = zoneID;
2900  }
2901  else
2902  {
2903  faceZone_.erase(faceFnd);
2904  }
2905  }
2906  else if (zoneID >= 0)
2907  {
2908  faceZone_.insert(faceI, zoneID);
2909  }
2910  faceZoneFlip_[faceI] = (zoneFlip ? 1 : 0);
2911 }
2912 
2913 
2914 void Foam::polyTopoChange::removeFace(const label faceI, const label mergeFaceI)
2915 {
2916  if (faceI < 0 || faceI >= faces_.size())
2917  {
2919  << "illegal face label " << faceI << endl
2920  << "Valid face labels are 0 .. " << faces_.size()-1
2921  << abort(FatalError);
2922  }
2923 
2924  if
2925  (
2926  strict_
2927  && (faceRemoved(faceI) || faceMap_[faceI] == -1)
2928  )
2929  {
2931  << "face " << faceI
2932  << " already marked for removal"
2933  << abort(FatalError);
2934  }
2935 
2936  faces_[faceI].setSize(0);
2937  region_[faceI] = -1;
2938  faceOwner_[faceI] = -1;
2939  faceNeighbour_[faceI] = -1;
2940  faceMap_[faceI] = -1;
2941  if (mergeFaceI >= 0)
2942  {
2943  reverseFaceMap_[faceI] = -mergeFaceI-2;
2944  }
2945  else
2946  {
2947  reverseFaceMap_[faceI] = -1;
2948  }
2949  faceFromEdge_.erase(faceI);
2950  faceFromPoint_.erase(faceI);
2951  flipFaceFlux_[faceI] = 0;
2952  faceZone_.erase(faceI);
2953  faceZoneFlip_[faceI] = 0;
2954 }
2955 
2956 
2959  const label masterPointID,
2960  const label masterEdgeID,
2961  const label masterFaceID,
2962  const label masterCellID,
2963  const label zoneID
2964 )
2965 {
2966  label cellI = cellMap_.size();
2967 
2968  if (masterPointID >= 0)
2969  {
2970  cellMap_.append(-1);
2971  cellFromPoint_.insert(cellI, masterPointID);
2972  }
2973  else if (masterEdgeID >= 0)
2974  {
2975  cellMap_.append(-1);
2976  cellFromEdge_.insert(cellI, masterEdgeID);
2977  }
2978  else if (masterFaceID >= 0)
2979  {
2980  cellMap_.append(-1);
2981  cellFromFace_.insert(cellI, masterFaceID);
2982  }
2983  else
2984  {
2985  cellMap_.append(masterCellID);
2986  }
2987  reverseCellMap_.append(cellI);
2988  cellZone_.append(zoneID);
2989 
2990  return cellI;
2991 }
2992 
2993 
2996  const label cellI,
2997  const label zoneID
2998 )
2999 {
3000  cellZone_[cellI] = zoneID;
3001 }
3002 
3003 
3004 void Foam::polyTopoChange::removeCell(const label cellI, const label mergeCellI)
3005 {
3006  if (cellI < 0 || cellI >= cellMap_.size())
3007  {
3009  << "illegal cell label " << cellI << endl
3010  << "Valid cell labels are 0 .. " << cellMap_.size()-1
3011  << abort(FatalError);
3012  }
3013 
3014  if (strict_ && cellMap_[cellI] == -2)
3015  {
3017  << "cell " << cellI
3018  << " already marked for removal"
3019  << abort(FatalError);
3020  }
3021 
3022  cellMap_[cellI] = -2;
3023  if (mergeCellI >= 0)
3024  {
3025  reverseCellMap_[cellI] = -mergeCellI-2;
3026  }
3027  else
3028  {
3029  reverseCellMap_[cellI] = -1;
3030  }
3031  cellFromPoint_.erase(cellI);
3032  cellFromEdge_.erase(cellI);
3033  cellFromFace_.erase(cellI);
3034  cellZone_[cellI] = -1;
3035 }
3036 
3037 
3040  polyMesh& mesh,
3041  const bool inflate,
3042  const bool syncParallel,
3043  const bool orderCells,
3044  const bool orderPoints
3045 )
3046 {
3047  if (debug)
3048  {
3049  Pout<< "polyTopoChange::changeMesh"
3050  << "(polyMesh&, const bool, const bool, const bool, const bool)"
3051  << endl;
3052  }
3053 
3054  if (debug)
3055  {
3056  Pout<< "Old mesh:" << nl;
3057  writeMeshStats(mesh, Pout);
3058  }
3059 
3060  // new mesh points
3061  pointField newPoints;
3062  // number of internal points
3063  label nInternalPoints;
3064  // patch slicing
3065  labelList patchSizes;
3066  labelList patchStarts;
3067  // inflate maps
3068  List<objectMap> pointsFromPoints;
3069  List<objectMap> facesFromPoints;
3070  List<objectMap> facesFromEdges;
3071  List<objectMap> facesFromFaces;
3072  List<objectMap> cellsFromPoints;
3073  List<objectMap> cellsFromEdges;
3074  List<objectMap> cellsFromFaces;
3075  List<objectMap> cellsFromCells;
3076  // old mesh info
3077  List<Map<label> > oldPatchMeshPointMaps;
3078  labelList oldPatchNMeshPoints;
3079  labelList oldPatchStarts;
3080  List<Map<label> > oldFaceZoneMeshPointMaps;
3081 
3082  // Compact, reorder patch faces and calculate mesh/patch maps.
3083  compactAndReorder
3084  (
3085  mesh,
3086  syncParallel,
3087  orderCells,
3088  orderPoints,
3089 
3090  nInternalPoints,
3091  newPoints,
3092  patchSizes,
3093  patchStarts,
3094  pointsFromPoints,
3095  facesFromPoints,
3096  facesFromEdges,
3097  facesFromFaces,
3098  cellsFromPoints,
3099  cellsFromEdges,
3100  cellsFromFaces,
3101  cellsFromCells,
3102  oldPatchMeshPointMaps,
3103  oldPatchNMeshPoints,
3104  oldPatchStarts,
3105  oldFaceZoneMeshPointMaps
3106  );
3107 
3108  const label nOldPoints(mesh.nPoints());
3109  const label nOldFaces(mesh.nFaces());
3110  const label nOldCells(mesh.nCells());
3111  autoPtr<scalarField> oldCellVolumes(new scalarField(mesh.cellVolumes()));
3112 
3113 
3114  // Change the mesh
3115  // ~~~~~~~~~~~~~~~
3116  // This will invalidate any addressing so better make sure you have
3117  // all the information you need!!!
3118 
3119  if (inflate)
3120  {
3121  // Keep (renumbered) mesh points, store new points in map for inflation
3122  // (appended points (i.e. from nowhere) get value zero)
3123  pointField renumberedMeshPoints(newPoints.size());
3124 
3125  forAll(pointMap_, newPointI)
3126  {
3127  label oldPointI = pointMap_[newPointI];
3128 
3129  if (oldPointI >= 0)
3130  {
3131  renumberedMeshPoints[newPointI] = mesh.points()[oldPointI];
3132  }
3133  else
3134  {
3135  renumberedMeshPoints[newPointI] = vector::zero;
3136  }
3137  }
3138 
3140  (
3141  xferMove(renumberedMeshPoints),
3142  faces_.xfer(),
3143  faceOwner_.xfer(),
3144  faceNeighbour_.xfer(),
3145  patchSizes,
3146  patchStarts,
3147  syncParallel
3148  );
3149 
3150  mesh.topoChanging(true);
3151  // Note: could already set moving flag as well
3152  // mesh.moving(true);
3153  }
3154  else
3155  {
3156  // Set new points.
3158  (
3159  xferMove(newPoints),
3160  faces_.xfer(),
3161  faceOwner_.xfer(),
3162  faceNeighbour_.xfer(),
3163  patchSizes,
3164  patchStarts,
3165  syncParallel
3166  );
3167  mesh.topoChanging(true);
3168  }
3169 
3170  // Clear out primitives
3171  {
3172  retiredPoints_.clearStorage();
3173  region_.clearStorage();
3174  }
3175 
3176 
3177  if (debug)
3178  {
3179  // Some stats on changes
3180  label nAdd, nInflate, nMerge, nRemove;
3181  countMap(pointMap_, reversePointMap_, nAdd, nInflate, nMerge, nRemove);
3182  Pout<< "Points:"
3183  << " added(from point):" << nAdd
3184  << " added(from nothing):" << nInflate
3185  << " merged(into other point):" << nMerge
3186  << " removed:" << nRemove
3187  << nl;
3188 
3189  countMap(faceMap_, reverseFaceMap_, nAdd, nInflate, nMerge, nRemove);
3190  Pout<< "Faces:"
3191  << " added(from face):" << nAdd
3192  << " added(inflated):" << nInflate
3193  << " merged(into other face):" << nMerge
3194  << " removed:" << nRemove
3195  << nl;
3196 
3197  countMap(cellMap_, reverseCellMap_, nAdd, nInflate, nMerge, nRemove);
3198  Pout<< "Cells:"
3199  << " added(from cell):" << nAdd
3200  << " added(inflated):" << nInflate
3201  << " merged(into other cell):" << nMerge
3202  << " removed:" << nRemove
3203  << nl
3204  << endl;
3205  }
3206 
3207  if (debug)
3208  {
3209  Pout<< "New mesh:" << nl;
3210  writeMeshStats(mesh, Pout);
3211  }
3212 
3213 
3214  // Zones
3215  // ~~~~~
3216 
3217  // Inverse of point/face/cell zone addressing.
3218  // For every preserved point/face/cells in zone give the old position.
3219  // For added points, the index is set to -1
3220  labelListList pointZoneMap(mesh.pointZones().size());
3221  labelListList faceZoneFaceMap(mesh.faceZones().size());
3222  labelListList cellZoneMap(mesh.cellZones().size());
3223 
3224  resetZones(mesh, mesh, pointZoneMap, faceZoneFaceMap, cellZoneMap);
3225 
3226  // Clear zone info
3227  {
3228  pointZone_.clearStorage();
3229  faceZone_.clearStorage();
3230  faceZoneFlip_.clearStorage();
3231  cellZone_.clearStorage();
3232  }
3233 
3234 
3235  // Patch point renumbering
3236  // For every preserved point on a patch give the old position.
3237  // For added points, the index is set to -1
3238  labelListList patchPointMap(mesh.boundaryMesh().size());
3239  calcPatchPointMap
3240  (
3241  oldPatchMeshPointMaps,
3242  mesh.boundaryMesh(),
3243  patchPointMap
3244  );
3245 
3246  // Create the face zone mesh point renumbering
3247  labelListList faceZonePointMap(mesh.faceZones().size());
3248  calcFaceZonePointMap(mesh, oldFaceZoneMeshPointMaps, faceZonePointMap);
3249 
3250  labelHashSet flipFaceFluxSet(getSetIndices(flipFaceFlux_));
3251 
3252  return autoPtr<mapPolyMesh>
3253  (
3254  new mapPolyMesh
3255  (
3256  mesh,
3257  nOldPoints,
3258  nOldFaces,
3259  nOldCells,
3260 
3261  pointMap_,
3262  pointsFromPoints,
3263 
3264  faceMap_,
3265  facesFromPoints,
3266  facesFromEdges,
3267  facesFromFaces,
3268 
3269  cellMap_,
3270  cellsFromPoints,
3271  cellsFromEdges,
3272  cellsFromFaces,
3273  cellsFromCells,
3274 
3275  reversePointMap_,
3276  reverseFaceMap_,
3277  reverseCellMap_,
3278 
3279  flipFaceFluxSet,
3280 
3281  patchPointMap,
3282 
3283  pointZoneMap,
3284 
3285  faceZonePointMap,
3286  faceZoneFaceMap,
3287  cellZoneMap,
3288 
3289  newPoints, // if empty signals no inflation.
3290  oldPatchStarts,
3291  oldPatchNMeshPoints,
3292 
3293  oldCellVolumes,
3294 
3295  true // steal storage.
3296  )
3297  );
3298 
3299  // At this point all member DynamicList (pointMap_, cellMap_ etc.) will
3300  // be invalid.
3301 }
3302 
3303 
3306  autoPtr<fvMesh>& newMeshPtr,
3307  const IOobject& io,
3308  const polyMesh& mesh,
3309  const bool syncParallel,
3310  const bool orderCells,
3311  const bool orderPoints
3312 )
3313 {
3314  if (debug)
3315  {
3316  Pout<< "polyTopoChange::changeMesh"
3317  << "(autoPtr<fvMesh>&, const IOobject&, const fvMesh&"
3318  << ", const bool, const bool, const bool)"
3319  << endl;
3320  }
3321 
3322  if (debug)
3323  {
3324  Pout<< "Old mesh:" << nl;
3325  writeMeshStats(mesh, Pout);
3326  }
3327 
3328  // new mesh points
3329  pointField newPoints;
3330  // number of internal points
3331  label nInternalPoints;
3332  // patch slicing
3333  labelList patchSizes;
3334  labelList patchStarts;
3335  // inflate maps
3336  List<objectMap> pointsFromPoints;
3337  List<objectMap> facesFromPoints;
3338  List<objectMap> facesFromEdges;
3339  List<objectMap> facesFromFaces;
3340  List<objectMap> cellsFromPoints;
3341  List<objectMap> cellsFromEdges;
3342  List<objectMap> cellsFromFaces;
3343  List<objectMap> cellsFromCells;
3344 
3345  // old mesh info
3346  List<Map<label> > oldPatchMeshPointMaps;
3347  labelList oldPatchNMeshPoints;
3348  labelList oldPatchStarts;
3349  List<Map<label> > oldFaceZoneMeshPointMaps;
3350 
3351  // Compact, reorder patch faces and calculate mesh/patch maps.
3352  compactAndReorder
3353  (
3354  mesh,
3355  syncParallel,
3356  orderCells,
3357  orderPoints,
3358 
3359  nInternalPoints,
3360  newPoints,
3361  patchSizes,
3362  patchStarts,
3363  pointsFromPoints,
3364  facesFromPoints,
3365  facesFromEdges,
3366  facesFromFaces,
3367  cellsFromPoints,
3368  cellsFromEdges,
3369  cellsFromFaces,
3370  cellsFromCells,
3371  oldPatchMeshPointMaps,
3372  oldPatchNMeshPoints,
3373  oldPatchStarts,
3374  oldFaceZoneMeshPointMaps
3375  );
3376 
3377  const label nOldPoints(mesh.nPoints());
3378  const label nOldFaces(mesh.nFaces());
3379  const label nOldCells(mesh.nCells());
3380  autoPtr<scalarField> oldCellVolumes(new scalarField(mesh.cellVolumes()));
3381 
3382 
3383  // Create the mesh
3384  // ~~~~~~~~~~~~~~~
3385 
3386  IOobject noReadIO(io);
3387  noReadIO.readOpt() = IOobject::NO_READ;
3388  newMeshPtr.reset
3389  (
3390  new fvMesh
3391  (
3392  noReadIO,
3393  xferMove(newPoints),
3394  faces_.xfer(),
3395  faceOwner_.xfer(),
3396  faceNeighbour_.xfer()
3397  )
3398  );
3399  fvMesh& newMesh = newMeshPtr();
3400 
3401  // Clear out primitives
3402  {
3403  retiredPoints_.clearStorage();
3404  region_.clearStorage();
3405  }
3406 
3407 
3408  if (debug)
3409  {
3410  // Some stats on changes
3411  label nAdd, nInflate, nMerge, nRemove;
3412  countMap(pointMap_, reversePointMap_, nAdd, nInflate, nMerge, nRemove);
3413  Pout<< "Points:"
3414  << " added(from point):" << nAdd
3415  << " added(from nothing):" << nInflate
3416  << " merged(into other point):" << nMerge
3417  << " removed:" << nRemove
3418  << nl;
3419 
3420  countMap(faceMap_, reverseFaceMap_, nAdd, nInflate, nMerge, nRemove);
3421  Pout<< "Faces:"
3422  << " added(from face):" << nAdd
3423  << " added(inflated):" << nInflate
3424  << " merged(into other face):" << nMerge
3425  << " removed:" << nRemove
3426  << nl;
3427 
3428  countMap(cellMap_, reverseCellMap_, nAdd, nInflate, nMerge, nRemove);
3429  Pout<< "Cells:"
3430  << " added(from cell):" << nAdd
3431  << " added(inflated):" << nInflate
3432  << " merged(into other cell):" << nMerge
3433  << " removed:" << nRemove
3434  << nl
3435  << endl;
3436  }
3437 
3438 
3439  {
3440  const polyBoundaryMesh& oldPatches = mesh.boundaryMesh();
3441 
3442  List<polyPatch*> newBoundary(oldPatches.size());
3443 
3444  forAll(oldPatches, patchI)
3445  {
3446  newBoundary[patchI] = oldPatches[patchI].clone
3447  (
3448  newMesh.boundaryMesh(),
3449  patchI,
3450  patchSizes[patchI],
3451  patchStarts[patchI]
3452  ).ptr();
3453  }
3454  newMesh.addFvPatches(newBoundary);
3455  }
3456 
3457 
3458  // Zones
3459  // ~~~~~
3460 
3461  // Start off from empty zones.
3462  const pointZoneMesh& oldPointZones = mesh.pointZones();
3463  List<pointZone*> pZonePtrs(oldPointZones.size());
3464  {
3465  forAll(oldPointZones, i)
3466  {
3467  pZonePtrs[i] = new pointZone
3468  (
3469  oldPointZones[i].name(),
3470  labelList(0),
3471  i,
3472  newMesh.pointZones()
3473  );
3474  }
3475  }
3476 
3477  const faceZoneMesh& oldFaceZones = mesh.faceZones();
3478  List<faceZone*> fZonePtrs(oldFaceZones.size());
3479  {
3480  forAll(oldFaceZones, i)
3481  {
3482  fZonePtrs[i] = new faceZone
3483  (
3484  oldFaceZones[i].name(),
3485  labelList(0),
3486  boolList(0),
3487  i,
3488  newMesh.faceZones()
3489  );
3490  }
3491  }
3492 
3493  const cellZoneMesh& oldCellZones = mesh.cellZones();
3494  List<cellZone*> cZonePtrs(oldCellZones.size());
3495  {
3496  forAll(oldCellZones, i)
3497  {
3498  cZonePtrs[i] = new cellZone
3499  (
3500  oldCellZones[i].name(),
3501  labelList(0),
3502  i,
3503  newMesh.cellZones()
3504  );
3505  }
3506  }
3507 
3508  newMesh.addZones(pZonePtrs, fZonePtrs, cZonePtrs);
3509 
3510  // Inverse of point/face/cell zone addressing.
3511  // For every preserved point/face/cells in zone give the old position.
3512  // For added points, the index is set to -1
3513  labelListList pointZoneMap(mesh.pointZones().size());
3514  labelListList faceZoneFaceMap(mesh.faceZones().size());
3515  labelListList cellZoneMap(mesh.cellZones().size());
3516 
3517  resetZones(mesh, newMesh, pointZoneMap, faceZoneFaceMap, cellZoneMap);
3518 
3519  // Clear zone info
3520  {
3521  pointZone_.clearStorage();
3522  faceZone_.clearStorage();
3523  faceZoneFlip_.clearStorage();
3524  cellZone_.clearStorage();
3525  }
3526 
3527  // Patch point renumbering
3528  // For every preserved point on a patch give the old position.
3529  // For added points, the index is set to -1
3530  labelListList patchPointMap(newMesh.boundaryMesh().size());
3531  calcPatchPointMap
3532  (
3533  oldPatchMeshPointMaps,
3534  newMesh.boundaryMesh(),
3535  patchPointMap
3536  );
3537 
3538  // Create the face zone mesh point renumbering
3539  labelListList faceZonePointMap(newMesh.faceZones().size());
3540  calcFaceZonePointMap(newMesh, oldFaceZoneMeshPointMaps, faceZonePointMap);
3541 
3542  if (debug)
3543  {
3544  Pout<< "New mesh:" << nl;
3545  writeMeshStats(mesh, Pout);
3546  }
3547 
3548  labelHashSet flipFaceFluxSet(getSetIndices(flipFaceFlux_));
3549 
3550  return autoPtr<mapPolyMesh>
3551  (
3552  new mapPolyMesh
3553  (
3554  newMesh,
3555  nOldPoints,
3556  nOldFaces,
3557  nOldCells,
3558 
3559  pointMap_,
3560  pointsFromPoints,
3561 
3562  faceMap_,
3563  facesFromPoints,
3564  facesFromEdges,
3565  facesFromFaces,
3566 
3567  cellMap_,
3568  cellsFromPoints,
3569  cellsFromEdges,
3570  cellsFromFaces,
3571  cellsFromCells,
3572 
3573  reversePointMap_,
3574  reverseFaceMap_,
3575  reverseCellMap_,
3576 
3577  flipFaceFluxSet,
3578 
3579  patchPointMap,
3580 
3581  pointZoneMap,
3582 
3583  faceZonePointMap,
3584  faceZoneFaceMap,
3585  cellZoneMap,
3586 
3587  newPoints, // if empty signals no inflation.
3588  oldPatchStarts,
3589  oldPatchNMeshPoints,
3590  oldCellVolumes,
3591  true // steal storage.
3592  )
3593  );
3594 
3595  // At this point all member DynamicList (pointMap_, cellMap_ etc.) will
3596  // be invalid.
3597 }
3598 
3599 
3600 // ************************************************************************* //
Foam::polyModifyCell::zoneID
label zoneID() const
Cell zone ID.
Definition: polyModifyCell.H:122
Foam::polyModifyPoint::pointID
label pointID() const
Point ID.
Definition: polyModifyPoint.H:118
Foam::polyTopoChange::addCell
label addCell(const label masterPointID, const label masterEdgeID, const label masterFaceID, const label masterCellID, const label zoneID)
Add cell. Return new cell label.
Definition: polyTopoChange.C:2958
Foam::polyAddPoint::inCell
bool inCell() const
Does the point support a cell.
Definition: polyAddPoint.H:154
Foam::polyModifyFace::zoneFlip
label zoneFlip() const
Face zone flip.
Definition: polyModifyFace.H:263
Foam::polyModifyFace::flipFaceFlux
bool flipFaceFlux() const
Does the face flux need to be flipped.
Definition: polyModifyFace.H:222
Foam::polyMesh::points
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:979
Foam::CompactListList::m
const List< T > & m() const
Return the packed matrix of data.
Definition: CompactListListI.H:116
Foam::scalarField
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Definition: primitiveFieldsFwd.H:48
Foam::polyMesh::topoChanging
bool topoChanging() const
Is mesh topology changing.
Definition: polyMesh.H:507
Foam::IOobject
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
Foam::polyTopoChange::getCellOrder
label getCellOrder(const CompactListList< label, labelList > &, labelList &) const
Cell ordering (bandCompression). Returns number of remaining cells.
Definition: polyTopoChange.C:597
Foam::polyAddFace::masterFaceID
label masterFaceID() const
Return master face ID.
Definition: polyAddFace.H:292
Foam::objectMap::index
label & index()
Return object index.
Definition: objectMapI.H:68
Foam::PackedBoolList
A bit-packed bool list.
Definition: PackedBoolList.H:63
Foam::polyTopoChange::reorderCompactFaces
void reorderCompactFaces(const label newSize, const labelList &oldToNew)
Compact and reorder faces according to map.
Definition: polyTopoChange.C:883
Foam::polyModifyCell::cellID
label cellID() const
Cell ID.
Definition: polyModifyCell.H:105
Foam::Vector< scalar >::zero
static const Vector zero
Definition: Vector.H:80
Foam::polyRemoveCell::cellID
label cellID() const
Return cell ID.
Definition: polyRemoveCell.H:95
polyRemovePoint.H
Foam::polyAddFace::owner
label owner() const
Return owner cell.
Definition: polyAddFace.H:244
Foam::LList::append
void append(const T &a)
Add at tail of list.
Definition: LList.H:166
Foam::polyTopoChange::clear
void clear()
Clear all storage.
Definition: polyTopoChange.C:2260
Foam::labelList
List< label > labelList
A List of labels.
Definition: labelList.H:56
Foam::reorder
ListType reorder(const labelUList &oldToNew, const ListType &)
Reorder the elements (indices, not values) of a list.
Definition: ListOpsTemplates.C:74
Foam::polyBoundaryMesh
Foam::polyBoundaryMesh.
Definition: polyBoundaryMesh.H:60
Foam::polyRemovePoint
Class containing data for point removal.
Definition: polyRemovePoint.H:46
Foam::SLList< label >
nPatches
label nPatches
Definition: readKivaGrid.H:402
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::HashTable::transfer
void transfer(HashTable< T, Key, Hash > &)
Transfer the contents of the argument table into this table.
Definition: HashTable.C:518
Foam::polyAddCell::masterCellID
label masterCellID() const
Return master cell ID.
Definition: polyAddCell.H:168
Foam::findIndex
label findIndex(const ListType &, typename ListType::const_reference, const label start=0)
Find first occurence of given element and return index,.
Foam::polyTopoChange::changeMesh
autoPtr< mapPolyMesh > changeMesh(polyMesh &mesh, const bool inflate, const bool syncParallel=true, const bool orderCells=false, const bool orderPoints=false)
Inplace changes mesh without change of patches.
Definition: polyTopoChange.C:3039
Foam::DynamicList< label >
Foam::polyRemoveFace::mergeFaceID
label mergeFaceID() const
Return merge face ID.
Definition: polyRemoveFace.H:101
Foam::fvMesh::addFvPatches
void addFvPatches(const List< polyPatch * > &, const bool validBoundary=true)
Add boundary patches. Constructor helper.
Definition: fvMesh.C:462
polyAddFace.H
Foam::polyTopoChange::modifyCell
void modifyCell(const label, const label zoneID)
Modify zone of cell.
Definition: polyTopoChange.C:2995
Foam::polyTopoChange::modifyPoint
void modifyPoint(const label, const point &, const label newZoneID, const bool inCell)
Modify coordinate.
Definition: polyTopoChange.C:2687
Foam::primitiveMesh::edgeFaces
const labelListList & edgeFaces() const
Definition: primitiveMeshEdgeFaces.C:31
Foam::SubList
A List obtained as a section of another List.
Definition: SubList.H:53
Foam::CompactListList
A packed storage unstructured matrix of objects of type <T> using an offset table for access.
Definition: polyTopoChange.H:91
polyRemoveFace.H
Foam::labelMax
static const label labelMax
Definition: label.H:62
Foam::polyRemovePoint::mergePointID
label mergePointID() const
Definition: polyRemovePoint.H:101
Foam::pointZone
A subset of mesh points. The labels of points in the zone can be obtained from the addressing() list.
Definition: pointZone.H:62
Foam::polyTopoChange::addFace
label addFace(const face &f, const label own, const label nei, const label masterPointID, const label masterEdgeID, const label masterFaceID, const bool flipFaceFlux, const label patchID, const label zoneID, const bool zoneFlip)
Add face to cells. Return new face label.
Definition: polyTopoChange.C:2805
Foam::polyAddFace::flipFaceFlux
bool flipFaceFlux() const
Does the face flux need to be flipped.
Definition: polyAddFace.H:298
Foam::Vector< scalar >::max
static const Vector max
Definition: Vector.H:82
Foam::PstreamBuffers
Buffers for inter-processor communications streams (UOPstream, UIPstream).
Definition: PstreamBuffers.H:85
Foam::polyTopoChange::modifyFace
void modifyFace(const face &f, const label faceI, const label own, const label nei, const bool flipFaceFlux, const label patchID, const label zoneID, const bool zoneFlip)
Modify vertices or cell of face.
Definition: polyTopoChange.C:2869
polyTopoChange.H
Foam::primitiveMesh::pointFaces
const labelListList & pointFaces() const
Definition: primitiveMeshPointFaces.C:32
boundary
faceListList boundary(nPatches)
Foam::polyAddCell::masterPointID
label masterPointID() const
Return master point ID.
Definition: polyAddCell.H:150
Foam::polyTopoChange::removeCell
void removeCell(const label, const label)
Remove/merge cell.
Definition: polyTopoChange.C:3004
Foam::List::transfer
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
Foam::polyTopoChange::writeMeshStats
static void writeMeshStats(const polyMesh &mesh, Ostream &)
Print some stats about mesh.
Definition: polyTopoChange.C:204
Foam::polyMesh::cellZones
const cellZoneMesh & cellZones() const
Return cell zone mesh.
Definition: polyMesh.H:469
Foam::Map< label >
Foam::polyAddCell::masterEdgeID
label masterEdgeID() const
Return master edge ID.
Definition: polyAddCell.H:156
Foam::polyTopoChange::addMesh
void addMesh(const polyMesh &, const labelList &patchMap, const labelList &pointZoneMap, const labelList &faceZoneMap, const labelList &cellZoneMap)
Add all points/faces/cells of mesh. Additional offset for patch.
Definition: polyTopoChange.C:2291
Foam::polyModifyFace
Class describing modification of a face.
Definition: polyModifyFace.H:48
Foam::polyModifyPoint
Class describing modification of a point.
Definition: polyModifyPoint.H:47
Foam::polyMesh::boundaryMesh
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:421
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::polyTopoChange::calcPatchPointMap
void calcPatchPointMap(const List< Map< label > > &, const polyBoundaryMesh &, labelListList &) const
Calculate mapping for patchpoints only.
Definition: polyTopoChange.C:1333
Foam::polyAddFace::masterEdgeID
label masterEdgeID() const
Return master edge ID.
Definition: polyAddFace.H:286
getFaceOrder
labelList getFaceOrder(const primitiveMesh &mesh, const labelList &cellOrder)
Definition: renumberMesh.C:165
polyMesh.H
Foam::HashSet< label, Hash< label > >
Foam::polyTopoChange::calcFaceInflationMaps
void calcFaceInflationMaps(const polyMesh &, List< objectMap > &, List< objectMap > &, List< objectMap > &) const
Definition: polyTopoChange.C:1380
Foam::polyTopoChange::addPoint
label addPoint(const point &, const label masterPointID, const label zoneID, const bool inCell)
Add point. Return new point label.
Definition: polyTopoChange.C:2659
Foam::polyAddFace::patchID
label patchID() const
Boundary patch ID.
Definition: polyAddFace.H:310
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Foam::polyAddPoint::newPoint
const point & newPoint() const
Point location.
Definition: polyAddPoint.H:124
Foam::cellZone
A subset of mesh cells.
Definition: cellZone.H:61
forAllConstIter
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:39
Foam::polyMesh::faceZones
const faceZoneMesh & faceZones() const
Return face zone mesh.
Definition: polyMesh.H:463
Foam::polyTopoChange::setCapacity
void setCapacity(const label nPoints, const label nFaces, const label nCells)
Explicitly pre-size the dynamic storage for expected mesh.
Definition: polyTopoChange.C:2498
Foam::polyTopoChange::getMergeSets
static void getMergeSets(const labelList &reverseCellMap, const labelList &cellMap, List< objectMap > &cellsFromCells)
Calculate object maps. Requires reverseMap to have destination.
Definition: polyTopoChange.C:226
nPoints
label nPoints
Definition: gmvOutputHeader.H:2
Foam::renumber
ListType renumber(const labelUList &oldToNew, const ListType &)
Renumber the values (not the indices) of a list.
Definition: ListOpsTemplates.C:32
Foam::primitiveMesh::nCells
label nCells() const
Definition: primitiveMeshI.H:64
SortableList.H
Foam::sortedOrder
void sortedOrder(const UList< T > &, labelList &order)
Generate the (stable) sort order for the list.
Definition: ListOpsTemplates.C:179
Foam::polyTopoChange::renumberCompact
static void renumberCompact(const labelList &, labelList &)
Renumber & compact elements of list according to map.
Definition: polyTopoChange.C:102
Foam::polyTopoChange::polyTopoChange
polyTopoChange(const label nPatches, const bool strict=true)
Construct without mesh. Either specify nPatches or use.
Definition: polyTopoChange.C:2184
Foam::primitiveMesh::nPoints
label nPoints() const
Definition: primitiveMeshI.H:35
Foam::reduce
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
Definition: PstreamReduceOps.H:43
Foam::stableSort
void stableSort(UList< T > &)
Definition: UList.C:121
Foam::polyRemoveCell
Class containing data for cell removal.
Definition: polyRemoveCell.H:46
Foam::UPstream::nonBlocking
@ nonBlocking
Definition: UPstream.H:68
Foam::inplaceReorder
void inplaceReorder(const labelUList &oldToNew, ListType &)
Inplace reorder the elements of a list.
Definition: ListOpsTemplates.C:102
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Foam::polyAddFace::neighbour
label neighbour() const
Return neighour cell.
Definition: polyAddFace.H:250
polyModifyPoint.H
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::IOobject::readOpt
readOption readOpt() const
Definition: IOobject.H:317
Foam::faceZone
A subset of mesh faces organised as a primitive patch.
Definition: faceZone.H:64
Foam::orOp
Definition: ops.H:178
Foam::IOobject::NO_READ
@ NO_READ
Definition: IOobject.H:111
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::polyTopoChange::checkFace
void checkFace(const face &, const label faceI, const label own, const label nei, const label patchI, const label zoneI) const
Check inputs to modFace or addFace.
Definition: polyTopoChange.C:336
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
Foam::polyTopoChange::selectFaces
static labelList selectFaces(const primitiveMesh &, const labelList &faceLabels, const bool internalFacesOnly)
Select either internal or external faces out of faceLabels.
Definition: polyTopoChange.C:1283
Foam::polyMesh::pointZones
const pointZoneMesh & pointZones() const
Return point zone mesh.
Definition: polyMesh.H:457
Foam::cellZone::whichCell
label whichCell(const label globalCellID) const
Helper function to re-direct to zone::localID(...)
Definition: cellZone.C:119
Foam::polyTopoChange::getFaceOrder
void getFaceOrder(const label nActiveFaces, const labelList &cellFaces, const labelList &cellFaceOffsets, labelList &oldToNew, labelList &patchSizes, labelList &patchStarts) const
Do upper-triangular ordering and patch ordering.
Definition: polyTopoChange.C:717
Foam::polyTopoChange::makeMesh
autoPtr< mapPolyMesh > makeMesh(autoPtr< fvMesh > &newMesh, const IOobject &io, const polyMesh &mesh, const bool syncParallel=true, const bool orderCells=false, const bool orderPoints=false)
Create new mesh with old mesh patches.
Definition: polyTopoChange.C:3305
Foam::polyTopoChange::makeCells
void makeCells(const label nActiveFaces, labelList &cellFaces, labelList &cellFaceOffsets) const
Construct cells (in packed storage)
Definition: polyTopoChange.C:465
Foam::DynamicList::clear
void clear()
Clear the addressed list, i.e. set the size to zero.
Definition: DynamicListI.H:242
Foam::polyMesh::faceOwner
virtual const labelList & faceOwner() const
Return face owner.
Definition: polyMesh.C:1017
Foam::ZoneMesh
A list of mesh zones.
Definition: cellZoneMeshFwd.H:39
Foam::PackedList::count
unsigned int count() const
Count number of bits set, O(log(n))
Definition: PackedList.C:55
polyAddPoint.H
Foam::polyRemoveFace::faceID
label faceID() const
Return face ID.
Definition: polyRemoveFace.H:95
Foam::polyAddFace::zoneID
label zoneID() const
Face zone ID.
Definition: polyAddFace.H:328
Foam::polyModifyPoint::zoneID
label zoneID() const
Point zone ID.
Definition: polyModifyPoint.H:142
Foam::polyModifyFace::newFace
const face & newFace() const
Return face.
Definition: polyModifyFace.H:198
Foam::polyTopoChange::removePoint
void removePoint(const label, const label)
Remove/merge point.
Definition: polyTopoChange.C:2757
Foam::PstreamBuffers::finishedSends
void finishedSends(const bool block=true)
Mark all sends as having been done. This will start receives.
Definition: PstreamBuffers.C:82
Foam::polyModifyFace::neighbour
label neighbour() const
Return owner cell ID.
Definition: polyModifyFace.H:216
Foam::identity
labelList identity(const label len)
Create identity map (map[i] == i) of given length.
Definition: ListOps.C:104
Foam::polyTopoChange::removeFace
void removeFace(const label, const label)
Remove/merge face.
Definition: polyTopoChange.C:2914
Foam::primitiveMesh::edgeCells
const labelListList & edgeCells() const
Definition: primitiveMeshEdgeCells.C:32
Foam::FatalError
error FatalError
processorPolyPatch.H
Foam::HashTable::size
label size() const
Return number of elements in table.
Definition: HashTableI.H:65
Foam::polyMesh::resetPrimitives
void resetPrimitives(const Xfer< pointField > &points, const Xfer< faceList > &faces, const Xfer< labelList > &owner, const Xfer< labelList > &neighbour, const labelList &patchSizes, const labelList &patchStarts, const bool validBoundary=true)
Reset mesh primitive data. Assumes all patch info correct.
Definition: polyMesh.C:642
Foam::primitiveMesh::nInternalFaces
label nInternalFaces() const
Definition: primitiveMeshI.H:52
Foam::objectMap
An objectMap is a pair of labels defining the mapping of an object from another object,...
Definition: objectMap.H:58
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
polyRemoveCell.H
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
fvMesh.H
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::polyModifyFace::faceID
label faceID() const
Return master face ID.
Definition: polyModifyFace.H:204
Foam::faceZone::whichFace
label whichFace(const label globalCellID) const
Helper function to re-direct to zone::localID(...)
Definition: faceZone.C:314
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:131
Foam::primitiveMesh::cellVolumes
const scalarField & cellVolumes() const
Definition: primitiveMeshCellCentresAndVols.C:222
Foam::CompactListList::index
label index(const label row, const label col) const
Return index into m.
Definition: CompactListListI.H:132
Foam::polyAddCell
Class containing data for cell addition.
Definition: polyAddCell.H:46
Foam::boolList
List< bool > boolList
Bool container classes.
Definition: boolList.H:50
Foam::polyPatch::start
label start() const
Return start label of this patch in the polyMesh face list.
Definition: polyPatch.H:312
polyModifyFace.H
Foam::polyTopoChange::resetZones
void resetZones(const polyMesh &, polyMesh &, labelListList &, labelListList &, labelListList &) const
Definition: polyTopoChange.C:1584
Foam::CompactListList::setSize
void setSize(const label nRows)
Reset size of CompactListList.
Definition: CompactListList.C:128
Foam::polyTopoChange::getSetIndices
static labelHashSet getSetIndices(const PackedBoolList &)
Get all set elements as a labelHashSet.
Definition: polyTopoChange.C:188
Foam::DynamicList::append
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Foam::polyTopoChange::makeCellCells
void makeCellCells(const label nActiveFaces, CompactListList< label, labelList > &cellCells) const
Construct cellCells (in packed storage)
Definition: polyTopoChange.C:552
Foam::polyRemovePoint::pointID
label pointID() const
Return point ID.
Definition: polyRemovePoint.H:96
Foam::max
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
polyAddCell.H
Foam::polyModifyFace::owner
label owner() const
Return owner cell ID.
Definition: polyModifyFace.H:210
Foam::List::setSize
void setSize(const label)
Reset size of List.
Foam::autoPtr
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:117
Foam::primitiveMesh::cellCentres
const vectorField & cellCentres() const
Definition: primitiveMeshCellCentresAndVols.C:211
Foam::polyModifyCell
Class describing modification of a cell.
Definition: polyModifyCell.H:46
Foam::polyTopoChange::reorderCoupledFaces
void reorderCoupledFaces(const bool syncParallel, const polyBoundaryMesh &, const labelList &patchStarts, const labelList &patchSizes, const pointField &points)
Do all coupled patch face reordering.
Definition: polyTopoChange.C:1934
Foam::pointZone::whichPoint
label whichPoint(const label globalPointID) const
Helper function to re-direct to zone::localID(...)
Definition: pointZone.C:126
Foam::polyMesh::faces
virtual const faceList & faces() const
Return raw faces.
Definition: polyMesh.C:1004
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
Foam::xferMove
Xfer< T > xferMove(T &)
Construct by transferring the contents of the arg.
Foam::polyTopoChange::setAction
label setAction(const topoAction &action)
For compatibility with polyTopoChange: set topological action.
Definition: polyTopoChange.C:2530
Foam::primitiveMesh::nFaces
label nFaces() const
Definition: primitiveMeshI.H:58
Foam::polyModifyFace::patchID
label patchID() const
Boundary patch ID.
Definition: polyModifyFace.H:234
Foam::polyTopoChange::compactAndReorder
void compactAndReorder(const polyMesh &, const bool syncParallel, const bool orderCells, const bool orderPoints, label &nInternalPoints, pointField &newPoints, labelList &patchSizes, labelList &patchStarts, List< objectMap > &pointsFromPoints, List< objectMap > &facesFromPoints, List< objectMap > &facesFromEdges, List< objectMap > &facesFromFaces, List< objectMap > &cellsFromPoints, List< objectMap > &cellsFromEdges, List< objectMap > &cellsFromFaces, List< objectMap > &cellsFromCells, List< Map< label > > &oldPatchMeshPointMaps, labelList &oldPatchNMeshPoints, labelList &oldPatchStarts, List< Map< label > > &oldFaceZoneMeshPointMaps)
Definition: polyTopoChange.C:2051
Foam::Pout
prefixOSstream Pout(cout, "Pout")
Definition: IOstreams.H:53
f
labelList f(nPoints)
Foam::polyTopoChange::facePoints
pointField facePoints(const face &f) const
Return face points.
Definition: polyTopoChange.C:319
Foam::Vector< scalar >
Foam::polyRemoveFace
Class containing data for face removal.
Definition: polyRemoveFace.H:46
Foam::polyModifyPoint::inCell
bool inCell() const
Does the point support a cell.
Definition: polyModifyPoint.H:148
Foam::polyTopoChange::renumber
static void renumber(const labelList &, labelHashSet &)
Renumber elements of container according to map.
Definition: polyTopoChange.C:79
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::IOobject::clone
Foam::autoPtr< IOobject > clone() const
Clone.
Definition: IOobject.H:252
Foam::primitiveMesh::isInternalFace
bool isInternalFace(const label faceIndex) const
Return true if given face label is internal to the mesh.
Definition: primitiveMeshI.H:70
Foam::polyTopoChange::renumberReverseMap
static void renumberReverseMap(const labelList &, DynamicList< label > &)
Special handling of reverse maps which have <-1 in them.
Definition: polyTopoChange.C:56
Foam::polyTopoChange::calcFaceZonePointMap
void calcFaceZonePointMap(const polyMesh &, const List< Map< label > > &, labelListList &) const
Definition: polyTopoChange.C:1883
Foam::UList
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:60
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::polyRemoveCell::mergeCellID
label mergeCellID() const
Return cell ID.
Definition: polyRemoveCell.H:101
Foam::PtrList::size
label size() const
Return the number of elements in the PtrList.
Definition: PtrListI.H:32
Foam::polyModifyCell::removeFromZone
bool removeFromZone() const
Definition: polyModifyCell.H:116
Foam::CompactListList::size
label size() const
Return the primary size, i.e. the number of rows.
Definition: CompactListListI.H:87
Foam::primitiveMesh::pointCells
const labelListList & pointCells() const
Definition: primitiveMeshPointCells.C:108
Foam::HashSet::insert
bool insert(const Key &key)
Insert a new entry.
Definition: HashSet.H:116
Foam::PtrList::setSize
void setSize(const label)
Reset size of PtrList. If extending the PtrList, new entries are.
Definition: PtrList.C:142
Foam::polyAddFace::masterPointID
label masterPointID() const
Return master point ID.
Definition: polyAddFace.H:280
Foam::polyAddPoint::zoneID
label zoneID() const
Point zone ID.
Definition: polyAddPoint.H:148
Foam::objectMap::masterObjects
labelList & masterObjects()
Return master object index.
Definition: objectMapI.H:80
Foam::polyAddPoint
Class containing data for point addition.
Definition: polyAddPoint.H:47
Foam::polyModifyFace::zoneID
label zoneID() const
Face zone ID.
Definition: polyModifyFace.H:257
Foam::mapPolyMesh
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:158
Foam::autoPtr::reset
void reset(T *=0)
If object pointer already set, delete object and set to given.
Definition: autoPtrI.H:114
Foam::polyAddFace
A face addition data class. A face can be inflated either from a point or from another face and can e...
Definition: polyAddFace.H:51
Foam::invert
labelList invert(const label len, const labelUList &)
Invert one-to-one map. Unmapped elements will be -1.
Definition: ListOps.C:37
Foam::polyAddCell::masterFaceID
label masterFaceID() const
Return master face ID.
Definition: polyAddCell.H:162
patches
patches[0]
Definition: createSingleCellMesh.H:36
Foam::topoAction
A virtual base class for topological actions.
Definition: topoAction.H:48
Foam::face
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
ListOps.H
Various functions to operate on Lists.
CompactListList.H
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
Foam::polyTopoChange::compact
void compact(const bool orderCells, const bool orderPoints, label &nInternalPoints, labelList &patchSizes, labelList &patchStarts)
Remove all unused/removed points/faces/cells and update.
Definition: polyTopoChange.C:921
Foam::ZoneMesh::clearAddressing
void clearAddressing()
Clear addressing.
Definition: ZoneMesh.C:394
Foam::Swap
void Swap(T &a, T &b)
Definition: Swap.H:43
Foam::polyAddPoint::masterPointID
label masterPointID() const
Master point label.
Definition: polyAddPoint.H:130
Foam::polyAddFace::zoneFlip
label zoneFlip() const
Face zone flip.
Definition: polyAddFace.H:334
Foam::polyTopoChange::calcCellInflationMaps
void calcCellInflationMaps(const polyMesh &, List< objectMap > &, List< objectMap > &, List< objectMap > &, List< objectMap > &) const
Definition: polyTopoChange.C:1492
Foam::polyModifyPoint::newPoint
const point & newPoint() const
New point location.
Definition: polyModifyPoint.H:124
objectMap.H
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::polyAddCell::zoneID
label zoneID() const
Cell zone ID.
Definition: polyAddCell.H:180
Foam::patchIdentifier::name
const word & name() const
Return name.
Definition: patchIdentifier.H:109
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:259
Foam::polyMesh::addZones
void addZones(const List< pointZone * > &pz, const List< faceZone * > &fz, const List< cellZone * > &cz)
Add mesh zones.
Definition: polyMesh.C:922
pointLabels
labelList pointLabels(nPoints, -1)
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
Foam::polyMesh::faceNeighbour
virtual const labelList & faceNeighbour() const
Return face neighbour.
Definition: polyMesh.C:1023
Foam::LList::removeHead
T removeHead()
Remove and return head.
Definition: LList.H:172
Foam::polyTopoChange::movePoints
void movePoints(const pointField &newPoints)
Move all points. Incompatible with other topology changes.
Definition: polyTopoChange.C:2738
polyModifyCell.H
Foam::polyTopoChange::hasValidPoints
bool hasValidPoints(const face &) const
Are all face vertices valid.
Definition: polyTopoChange.C:306
Foam::PrimitivePatch
A list of faces which address into the list of points.
Definition: PrimitivePatchTemplate.H:88
Foam::polyTopoChange::countMap
static void countMap(const labelList &map, const labelList &reverseMap, label &nAdd, label &nInflate, label &nMerge, label &nRemove)
Count number of added and removed quantities from maps.
Definition: polyTopoChange.C:123
Foam::polyAddFace::newFace
const face & newFace() const
Return face.
Definition: polyAddFace.H:238
Foam::primitiveMesh
Cell-face mesh analysis engine.
Definition: primitiveMesh.H:79