meshRefinement.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2017 OpenFOAM Foundation
9  Copyright (C) 2015-2023 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::meshRefinement
29 
30 Description
31  Helper class which maintains intersections of (changing) mesh with
32  (static) surfaces.
33 
34  Maintains
35  - per face any intersections of the cc-cc segment with any of the surfaces
36 
37 SourceFiles
38  meshRefinement.C
39  meshRefinementBaffles.C
40  meshRefinementGapRefine.C
41  meshRefinementMerge.C
42  meshRefinementProblemCells.C
43  meshRefinementRefine.C
44 
45 \*---------------------------------------------------------------------------*/
46 
47 #ifndef Foam_meshRefinement_H
48 #define Foam_meshRefinement_H
49 
50 #include "hexRef8.H"
51 #include "mapPolyMesh.H"
52 #include "autoPtr.H"
53 #include "labelPairHashes.H"
54 #include "indirectPrimitivePatch.H"
55 #include "pointFieldsFwd.H"
56 #include "Tuple2.H"
57 #include "pointIndexHit.H"
58 #include "wordPairHashes.H"
59 #include "surfaceZonesInfo.H"
60 #include "volumeType.H"
61 #include "DynamicField.H"
62 #include "coordSetWriter.H"
63 #include "surfaceWriter.H"
64 
65 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
66 
67 namespace Foam
68 {
69 
70 // Forward Declarations
71 class fvMesh;
72 class mapDistributePolyMesh;
73 class mapDistribute;
74 class decompositionMethod;
75 class refinementSurfaces;
76 class refinementFeatures;
77 class shellSurfaces;
78 class removeCells;
79 class fvMeshDistribute;
80 class removePoints;
81 class localPointRegion;
82 class snapParameters;
83 
84 /*---------------------------------------------------------------------------*\
85  Class meshRefinement Declaration
86 \*---------------------------------------------------------------------------*/
87 
88 class meshRefinement
89 {
90 public:
91 
92  // Public Data Types
93 
94  //- Enumeration for what to debug. Used as a bit-pattern.
95  enum debugType
96  {
97  MESH = (1 << 0),
98  OBJINTERSECTIONS = (1 << 1),
99  FEATURESEEDS = (1 << 2),
100  ATTRACTION = (1 << 3),
101  LAYERINFO = (1 << 4)
102  };
103 
104  static const Enum<debugType> debugTypeNames;
105 
107  //enum outputType
108  //{
109  // OUTPUTLAYERINFO = (1 << 0)
110  //};
111  //
112  //static const Enum<outputType> outputTypeNames;
113 
114  //- Enumeration for what to write. Used as a bit-pattern.
115  enum writeType
116  {
117  WRITEMESH = (1 << 0),
118  NOWRITEREFINEMENT = (1 << 1),
119  WRITELEVELS = (1 << 2),
120  WRITELAYERSETS = (1 << 3),
121  WRITELAYERFIELDS = (1 << 4)
122  };
124  static const Enum<writeType> writeTypeNames;
125 
126  //- Enumeration for how userdata is to be mapped upon refinement.
127  enum mapType
128  {
129  MASTERONLY = 1,
130  KEEPALL = 2,
131  REMOVE = 4
132  };
133 
134  //- Enumeration for what to do with co-planar patch faces on a single
135  // cell
136  enum FaceMergeType
137  {
138  NONE, // no merging
139  GEOMETRIC, // use feature angle
140  IGNOREPATCH // use feature angle, allow merging of different
141  // patches
142  };
145 private:
146 
147  // Static Data Members
148 
149  //- Control of writing level
150  static writeType writeLevel_;
151 
153  //static outputType outputLevel_;
154 
155 
156  // Private Data
157 
158  //- Reference to mesh
159  fvMesh& mesh_;
160 
161  //- Tolerance used for sorting coordinates (used in 'less' routine)
162  const scalar mergeDistance_;
163 
164  //- Overwrite the mesh?
165  const bool overwrite_;
166 
167  //- Instance of mesh upon construction. Used when in overwrite_ mode.
168  const word oldInstance_;
169 
170  //- All surface-intersection interaction
171  const refinementSurfaces& surfaces_;
172 
173  //- All feature-edge interaction
174  const refinementFeatures& features_;
175 
176  //- All shell-refinement interaction
177  const shellSurfaces& shells_;
178 
179  //- All limit-refinement interaction
180  const shellSurfaces& limitShells_;
181 
182  //- Are we operating in test mode?
183  const bool dryRun_;
184 
185  //- Refinement engine
186  hexRef8 meshCutter_;
187 
188  //- Per cc-cc vector the index of the surface hit
189  labelIOList surfaceIndex_;
190 
191 
192  // For baffle merging
193 
194  //- Original patch for baffle faces that used to be on
195  // coupled patches
196  Map<label> faceToCoupledPatch_;
197 
198 
199  //- User supplied face based data.
200  List<Tuple2<mapType, labelList>> userFaceData_;
201 
202  //- Meshed patches - are treated differently. Stored as wordList since
203  // order changes.
204  wordList meshedPatches_;
205 
206  //- FaceZone to master patch name
207  HashTable<word> faceZoneToMasterPatch_;
208 
209  //- FaceZone to slave patch name
210  HashTable<word> faceZoneToSlavePatch_;
211 
212  //- FaceZone to method to handle faces
214 
215 
216  // Private Member Functions
217 
218  //- Add patchfield of given type to all fields on mesh
219  template<class GeoField>
220  static void addPatchFields(fvMesh&, const word& patchFieldType);
221 
222  //- Reorder patchfields of all fields on mesh
223  template<class GeoField>
224  static void reorderPatchFields(fvMesh&, const labelList& oldToNew);
225 
226  //- Find out which faces have changed given cells (old mesh labels)
227  // that were marked for refinement.
228  static labelList getChangedFaces
229  (
230  const mapPolyMesh&,
231  const labelList& oldCellsToRefine
232  );
233 
234  // Debug: count number of master-faces (and do some checking
235  // for consistency)
236  label globalFaceCount(const labelList& elems) const;
237 
238  //- Calculate coupled boundary end vector and refinement level
239  void calcNeighbourData(labelList& neiLevel, pointField& neiCc) const;
240 
241  //- Calculate rays from cell-centre to cell-centre and corresponding
242  // min cell refinement level
243  void calcCellCellRays
244  (
245  const pointField& neiCc,
246  const labelList& neiLevel,
247  const labelList& testFaces,
248  pointField& start,
249  pointField& end,
250  labelList& minLevel
251  ) const;
252 
253  //- Get cells which are inside any closed surface. Note that
254  // all closed surfaces
255  // will have already been oriented to have keepPoint outside.
256  labelList getInsideCells(const word&) const;
257 
258  //- Do all to remove inside cells
259  autoPtr<mapPolyMesh> removeInsideCells
260  (
261  const string& msg,
262  const label exposedPatchi
263  );
264 
265 
266  // Refinement candidate selection
267 
268  //- Mark cell for refinement (if not already marked). Return false
269  // if refinelimit hit. Keeps running count (in nRefine) of cells
270  // marked for refinement
271  static bool markForRefine
272  (
273  const label markValue,
274  const label nAllowRefine,
275  label& cellValue,
276  label& nRefine
277  );
278 
279  //- Mark every cell with level of feature passing through it
280  // (or -1 if not passed through). Uses tracking.
281  void markFeatureCellLevel
282  (
283  const pointField& keepPoints,
284  labelList& maxFeatureLevel
285  ) const;
286 
287  //- Calculate list of cells to refine based on intersection of
288  // features.
289  label markFeatureRefinement
290  (
291  const pointField& keepPoints,
292  const label nAllowRefine,
293 
295  label& nRefine
296  ) const;
297 
298  //- Mark cells for distance-to-feature based refinement.
299  label markInternalDistanceToFeatureRefinement
300  (
301  const label nAllowRefine,
303  label& nRefine
304  ) const;
305 
306  //- Mark cells for refinement-shells based refinement.
307  label markInternalRefinement
308  (
309  const label nAllowRefine,
311  label& nRefine
312  ) const;
313 
314  //- Unmark cells for refinement based on limit-shells. Return number
315  // of limited cells.
316  label unmarkInternalRefinement
317  (
319  label& nRefine
320  ) const;
321 
322  //- Collect faces that are intersected and whose neighbours aren't
323  // yet marked for refinement.
324  labelList getRefineCandidateFaces
325  (
326  const labelList& refineCell
327  ) const;
328 
329  //- Mark cells for surface intersection based refinement.
330  label markSurfaceRefinement
331  (
332  const label nAllowRefine,
333  const labelList& neiLevel,
334  const pointField& neiCc,
336  label& nRefine
337  ) const;
338 
339  //- Collect cells intersected by the surface that are candidates
340  // for gap checking. Used inside markSurfaceGapRefinement
341  void collectGapCandidates
342  (
343  const shellSurfaces& shells,
344  const labelList& testFaces,
345  const labelList& neiLevel,
346  const pointField& neiCc,
347  labelList& cellToCompact,
348  labelList& bFaceToCompact,
349  List<FixedList<label, 3>>& shellGapInfo,
350  List<volumeType>& shellGapMode
351  ) const;
352  void collectGapCells
353  (
354  const scalar planarCos,
355 
356  const List<FixedList<label, 3>>& extendedGapLevel,
357  const List<volumeType>& extendedGapMode,
358  const labelList& testFaces,
359  const pointField& start,
360  const pointField& end,
361 
362  const labelList& cellToCompact,
363  const labelList& bFaceToCompact,
364  const List<FixedList<label, 3>>& shellGapInfo,
365  const List<volumeType>& shellGapMode,
366 
367  const label nAllowRefine,
368  const labelList& neiLevel,
369  const pointField& neiCc,
370 
372  label& nRefine
373  ) const;
374 
375 
376  //- Mark cells intersected by the surface if they are inside
377  // close gaps
378  label markSurfaceGapRefinement
379  (
380  const scalar planarCos,
381  const label nAllowRefine,
382  const labelList& neiLevel,
383  const pointField& neiCc,
384 
386  label& nRefine
387  ) const;
388 
389  //- Generate single ray from nearPoint in direction of nearNormal
390  label generateRays
391  (
392  const point& nearPoint,
393  const vector& nearNormal,
394  const FixedList<label, 3>& gapInfo,
395  const volumeType& mode,
396 
397  const label cLevel,
398 
399  DynamicField<point>& start,
401  ) const;
402 
403  //- Generate pairs of rays through cell centre
404  // Each ray pair has start, end, and expected gap size
405  label generateRays
406  (
407  const bool useSurfaceNormal,
408 
409  const point& nearPoint,
410  const vector& nearNormal,
411  const FixedList<label, 3>& gapInfo,
412  const volumeType& mode,
413 
414  const point& cc,
415  const label cLevel,
416 
417  DynamicField<point>& start,
419  DynamicField<scalar>& gapSize,
420 
421  DynamicField<point>& start2,
422  DynamicField<point>& end2,
423  DynamicField<scalar>& gapSize2
424  ) const;
425 
426  //- Select candidate cells (cells inside a shell with gapLevel
427  // specified)
428  void selectGapCandidates
429  (
430  const labelList& refineCell,
431  const label nRefine,
432 
433  labelList& cellMap,
434  labelList& gapShell,
435  List<FixedList<label, 3>>& shellGapInfo,
436  List<volumeType>& shellGapMode
437  ) const;
438 
439  //- Merge gap information coming from shell and from surface
440  // (surface wins)
441  void mergeGapInfo
442  (
443  const FixedList<label, 3>& shellGapInfo,
444  const volumeType shellGapMode,
445  const FixedList<label, 3>& surfGapInfo,
446  const volumeType surfGapMode,
447  FixedList<label, 3>& gapInfo,
448  volumeType& gapMode
449  ) const;
450 
451  //- Mark cells for non-surface intersection based gap refinement
452  label markInternalGapRefinement
453  (
454  const scalar planarCos,
455  const bool spreadGapSize,
456  const label nAllowRefine,
458  label& nRefine,
459  labelList& numGapCells,
460  scalarField& gapSize
461  ) const;
462 
463  //- Refine cells containing small gaps
464  label markSmallFeatureRefinement
465  (
466  const scalar planarCos,
467  const label nAllowRefine,
468  const labelList& neiLevel,
469  const pointField& neiCc,
470 
472  label& nRefine
473  ) const;
474 
475  //- Refine cells containing triangles with high refinement level
476  // (currently due to high curvature or being inside shell with
477  // high level)
478  label markSurfaceFieldRefinement
479  (
480  const label nAllowRefine,
481  const labelList& neiLevel,
482  const pointField& neiCc,
483 
485  label& nRefine
486  ) const;
487 
488  //- Helper: count number of normals1 that are in normals2
489  label countMatches
490  (
491  const List<point>& normals1,
492  const List<point>& normals2,
493  const scalar tol = 1e-6
494  ) const;
495 
496  //- Detect if two intersection points are high curvature (w.r.t.
497  // lengthscale
498  bool highCurvature
499  (
500  const scalar minCosAngle,
501  const scalar lengthScale,
502  const point& p0,
503  const vector& n0,
504  const point& p1,
505  const vector& n1
506  ) const;
507 
508  //- Mark cells for surface curvature based refinement. Marks if
509  // local curvature > curvature or if on different regions
510  // (markDifferingRegions)
511  label markSurfaceCurvatureRefinement
512  (
513  const scalar curvature,
514  const label nAllowRefine,
515  const labelList& neiLevel,
516  const pointField& neiCc,
518  label& nRefine
519  ) const;
520 
521  //- Mark cell if local a gap topology or
522  bool checkProximity
523  (
524  const scalar planarCos,
525  const label nAllowRefine,
526 
527  const label surfaceLevel,
528  const vector& surfaceLocation,
529  const vector& surfaceNormal,
530 
531  const label celli,
532 
533  label& cellMaxLevel,
534  vector& cellMaxLocation,
535  vector& cellMaxNormal,
536 
538  label& nRefine
539  ) const;
540 
541  //- Mark cells for surface proximity based refinement.
542  label markProximityRefinement
543  (
544  const scalar curvature,
545 
546  // Per region the min and max cell level
547  const labelList& surfaceMinLevel,
548  const labelList& surfaceMaxLevel,
549 
550  const label nAllowRefine,
551  const labelList& neiLevel,
552  const pointField& neiCc,
553 
555  label& nRefine
556  ) const;
557 
558  //- Mark cells for surface proximity based refinement.
559  label markProximityRefinementWave
560  (
561  const scalar planarCos,
562  const labelList& blockedSurfaces,
563  const label nAllowRefine,
564  const labelList& neiLevel,
565  const pointField& neiCc,
566 
568  label& nRefine
569  ) const;
570 
571 
572  // Baffle handling
573 
574  //- Get faces to repatch. Returns map from face to patch.
575  Map<labelPair> getZoneBafflePatches
576  (
577  const bool allowBoundary,
578  const labelList& globalToMasterPatch,
579  const labelList& globalToSlavePatch
580  ) const;
581 
582  //- Calculate intersections. Return per face -1 or the global
583  // surface region
584  void getIntersections
585  (
586  const labelList& surfacesToTest,
587  const pointField& neiCc,
588  const labelList& testFaces,
589 
590  labelList& globalRegion1,
591  labelList& globalRegion2
592  ) const;
593 
594  //- Calculate intersections on zoned faces. Return per face -1
595  // or the global region of the surface and the orientation
596  // w.r.t. surface
597  void getIntersections
598  (
599  const labelList& surfacesToTest,
600  const pointField& neiCc,
601  const labelList& testFaces,
602 
603  labelList& namedSurfaceRegion,
604  bitSet& posOrientation
605  ) const;
606 
607  //- Determine patches for baffles
608  void getBafflePatches
609  (
610  const label nErodeCellZones,
611  const labelList& globalToMasterPatch,
612  const pointField& locationsInMesh,
613  const wordList& regionsInMesh,
614  const pointField& locationsOutsideMesh,
615  const bool exitIfLeakPath,
616  const refPtr<coordSetWriter>& leakPathFormatter,
617  refPtr<surfaceWriter>& surfFormatter,
618 
619  const labelList& neiLevel,
620  const pointField& neiCc,
621  labelList& ownPatch,
622  labelList& neiPatch
623  ) const;
624 
625  autoPtr<mapPolyMesh> splitMesh
626  (
627  const label nBufferLayers,
628  const labelList& globalToMasterPatch,
629  const labelList& globalToSlavePatch,
630  labelList& cellRegion,
631  labelList& ownPatch,
632  labelList& neiPatch
633  );
634 
635  //- Repatches external face or creates baffle for internal face
636  // with user specified patches (might be different for both sides).
637  // Returns label of added face.
638  label createBaffle
639  (
640  const label facei,
641  const label ownPatch,
642  const label neiPatch,
643  polyTopoChange& meshMod
644  ) const;
645 
646  //- Write leak path
647  static fileName writeLeakPath
648  (
649  const polyMesh& mesh,
650  const pointField& locationsInMesh,
651  const pointField& locationsOutsideMesh,
652  const boolList& blockedFace,
653  coordSetWriter& leakPathWriter
654  );
655 
656 
657  // Problem cell handling
658 
659  //- Helper function to mark face as being on 'boundary'. Used by
660  // markFacesOnProblemCells
661  void markBoundaryFace
662  (
663  const label facei,
664  boolList& isBoundaryFace,
665  boolList& isBoundaryEdge,
666  boolList& isBoundaryPoint
667  ) const;
668 
669  void findNearest
670  (
671  const labelList& meshFaces,
672  List<pointIndexHit>& nearestInfo,
673  labelList& nearestSurface,
674  labelList& nearestRegion,
675  vectorField& nearestNormal
676  ) const;
677 
678  Map<label> findEdgeConnectedProblemCells
679  (
680  const scalarField& perpendicularAngle,
681  const labelList&
682  ) const;
683 
684  bool isCollapsedFace
685  (
686  const pointField&,
687  const pointField& neiCc,
688  const scalar minFaceArea,
689  const scalar maxNonOrtho,
690  const label facei
691  ) const;
692 
693  bool isCollapsedCell
694  (
695  const pointField&,
696  const scalar volFraction,
697  const label celli
698  ) const;
699 
700  //- Returns list with for every internal face -1 or the patch
701  // they should be baffled into. If removeEdgeConnectedCells is set
702  // removes cells based on perpendicularAngle.
703  void markFacesOnProblemCells
704  (
705  const dictionary& motionDict,
706  const bool removeEdgeConnectedCells,
707  const scalarField& perpendicularAngle,
708  const labelList& globalToMasterPatch,
709 
710  labelList& facePatch,
712  ) const;
713 
714  //- Calculates for every face the nearest 'start' face. Any
715  // unreached face does not get set (faceToStart[facei] = -1)
716  void nearestFace
717  (
718  const labelUList& startFaces,
719  const bitSet& isBlockedFace,
720 
721  autoPtr<mapDistribute>& mapPtr,
722  labelList& faceToStart,
723  const label nIter = labelMax
724  ) const;
725 
726  //- Calculates for every face the label of the nearest
727  // patch its zone. Any unreached face (disconnected mesh?) becomes
728  // adaptPatchIDs[0]
729  void nearestPatch
730  (
731  const labelList& adaptPatchIDs,
732  labelList& nearestPatch,
733  labelList& nearestZone
734  ) const;
735 
736  //- Returns list with for every face the label of the nearest
737  // patch. Any unreached face (disconnected mesh?) becomes
738  // adaptPatchIDs[0]
739  labelList nearestPatch(const labelList& adaptPatchIDs) const;
740 
741  //- Returns list with for every face the label of the nearest
742  // (global) region. Any unreached face (disconnected mesh?) becomes
743  // defaultRegion
744  labelList nearestIntersection
745  (
746  const labelList& surfacesToTest,
747  const label defaultRegion
748  ) const;
749 
750  //- Returns list with for every internal face -1 or the patch
751  // they should be baffled into.
752  void markFacesOnProblemCellsGeometric
753  (
754  const snapParameters& snapParams,
755  const dictionary& motionDict,
756  const labelList& globalToMasterPatch,
757  const labelList& globalToSlavePatch,
758 
759  labelList& facePatch,
761  ) const;
762 
763 
764  // Baffle merging
765 
766  //- Extract those baffles (duplicate) faces that are on the edge
767  // of a baffle region. These are candidates for merging.
768  List<labelPair> freeStandingBaffles
769  (
770  const List<labelPair>&,
771  const scalar freeStandingAngle
772  ) const;
773 
774 
775  // Zone handling
776 
777  //- Finds zone per cell for cells inside closed named surfaces.
778  // (uses geometric test for insideness)
779  // Adapts namedSurfaceRegion so all faces on boundary of cellZone
780  // have corresponding faceZone.
781  void findCellZoneGeometric
782  (
783  const pointField& neiCc,
784  const labelList& closedNamedSurfaces,
785  labelList& namedSurfaceRegion,
786  const labelList& surfaceToCellZone,
787  labelList& cellToZone
788  ) const;
789 
790  //- Finds zone per cell for cells inside region for which name
791  // is specified.
792  void findCellZoneInsideWalk
793  (
794  const pointField& locationsInMesh,
795  const labelList& zonesInMesh,
796  const labelList& blockedFace, // per face -1 or some index >= 0
797  labelList& cellToZone
798  ) const;
799 
800  //- Finds zone per cell for cells inside region for which name
801  // is specified.
802  void findCellZoneInsideWalk
803  (
804  const pointField& locationsInMesh,
805  const wordList& zoneNamesInMesh,
806  const labelList& faceToZone, // per face -1 or some index >= 0
807  labelList& cellToZone
808  ) const;
809 
810  //- Determines cell zone from cell region information.
811  bool calcRegionToZone
812  (
813  const label backgroundZoneID,
814  const label surfZoneI,
815  const label ownRegion,
816  const label neiRegion,
817 
818  labelList& regionToCellZone
819  ) const;
820 
821  //- Finds zone per cell. Uses topological walk with all faces
822  // marked in unnamedSurfaceRegion (intersections with unnamed
823  // surfaces) and namedSurfaceRegion (intersections with named
824  // surfaces) regarded as blocked.
825  void findCellZoneTopo
826  (
827  const label backgroundZoneID,
828  const pointField& locationsInMesh,
829  const labelList& unnamedSurfaceRegion,
830  const labelList& namedSurfaceRegion,
831  const labelList& surfaceToCellZone,
832  labelList& cellToZone
833  ) const;
834 
835  //- Opposite of findCellTopo: finds assigned cell connected to
836  // an unassigned one and puts it in the background zone.
837  void erodeCellZone
838  (
839  const label nErodeCellZones,
840  const label backgroundZoneID,
841  const labelList& unnamedSurfaceRegion,
842  const labelList& namedSurfaceRegion,
843  labelList& cellToZone
844  ) const;
845 
846  //- Variation of findCellZoneTopo: walks from cellZones but ignores
847  // face intersections (unnamedSurfaceRegion). WIP
848  void growCellZone
849  (
850  const label nGrowCellZones,
851  const label backgroundZoneID,
852  labelList& unnamedSurfaceRegion1,
853  labelList& unnamedSurfaceRegion2,
854  labelList& namedSurfaceRegion,
855  labelList& cellToZone
856  ) const;
857 
858  //- Make namedSurfaceRegion consistent with cellToZone
859  // - clear out any blocked faces inbetween same cell zone.
860  void makeConsistentFaceIndex
861  (
862  const labelList& zoneToNamedSurface,
863  const labelList& cellToZone,
864  labelList& namedSurfaceRegion
865  ) const;
866 
867  //- Calculate cellZone allocation
868  void zonify
869  (
870  const bool allowFreeStandingZoneFaces,
871  const label nErodeCellZones,
872  const label backgroundZoneID,
873  const pointField& locationsInMesh,
874  const wordList& zonesInMesh,
875  const pointField& locationsOutsideMesh,
876  const bool exitIfLeakPath,
877  const refPtr<coordSetWriter>& leakPathFormatter,
878  refPtr<surfaceWriter>& surfFormatter,
879 
880  labelList& cellToZone,
881  labelList& unnamedRegion1,
882  labelList& unnamedRegion2,
883  labelList& namedSurfaceRegion,
884  bitSet& posOrientation
885  ) const;
886 
887  //- Put cells into cellZone, faces into faceZone
888  void zonify
889  (
890  const bitSet& isMasterFace,
891  const labelList& cellToZone,
892  const labelList& neiCellZone,
893  const labelList& faceToZone,
894  const bitSet& meshFlipMap,
895  polyTopoChange& meshMod
896  ) const;
897 
898  //- Allocate faceZoneName
899  void allocateInterRegionFaceZone
900  (
901  const label ownZone,
902  const label neiZone,
903  wordPairHashTable& zonesToFaceZone,
904  LabelPairMap<word>& zoneIDsToFaceZone
905  ) const;
906 
907  //- Remove any loose standing cells
908  void handleSnapProblems
909  (
910  const snapParameters& snapParams,
911  const bool useTopologicalSnapDetection,
912  const bool removeEdgeConnectedCells,
913  const scalarField& perpendicularAngle,
914  const dictionary& motionDict,
915  Time& runTime,
916  const labelList& globalToMasterPatch,
917  const labelList& globalToSlavePatch
918  );
919 
920 
921  // Some patch utilities
922 
923  //- Get all faces in faceToZone that have no cellZone on
924  // either side.
925  labelList freeStandingBaffleFaces
926  (
927  const labelList& faceToZone,
928  const labelList& cellToZone,
929  const labelList& neiCellZone
930  ) const;
931 
932  //- Determine per patch edge the number of master faces. Used
933  // to detect non-manifold situations.
934  void calcPatchNumMasterFaces
935  (
936  const bitSet& isMasterFace,
938  labelList& nMasterFaces
939  ) const;
940 
941  //- Determine per patch face the (singly-) connected zone it
942  // is in. Return overall number of zones.
943  label markPatchZones
944  (
946  const labelList& nMasterFaces,
947  labelList& faceToZone
948  ) const;
949 
950  //- Make faces consistent.
951  void consistentOrientation
952  (
953  const bitSet& isMasterFace,
955  const labelList& nMasterFaces,
956  const labelList& faceToZone,
957  const Map<label>& zoneToOrientation,
958  bitSet& meshFlipMap
959  ) const;
960 
961 
962  //- No copy construct
963  meshRefinement(const meshRefinement&) = delete;
964 
965  //- No copy assignment
966  void operator=(const meshRefinement&) = delete;
967 
968 public:
969 
970  //- Runtime type information
971  ClassName("meshRefinement");
972 
973 
974  // Constructors
975 
976  //- Construct from components
978  (
979  fvMesh& mesh,
980  const scalar mergeDistance,
981  const bool overwrite,
982  const refinementSurfaces&,
983  const refinementFeatures&,
984  const shellSurfaces&, // omnidirectional refinement
985  const shellSurfaces&, // limit refinement
986  const labelUList& checkFaces, // initial faces to check
987  const bool dryRun
988  );
989 
990 
991  // Member Functions
992 
993  // Access
994 
995  //- Reference to mesh
996  const fvMesh& mesh() const
997  {
998  return mesh_;
999  }
1000  fvMesh& mesh()
1001  {
1002  return mesh_;
1003  }
1004 
1005  scalar mergeDistance() const
1006  {
1007  return mergeDistance_;
1008  }
1009 
1010  //- Overwrite the mesh?
1011  bool overwrite() const
1012  {
1013  return overwrite_;
1014  }
1015 
1016  //- (points)instance of mesh upon construction
1017  const word& oldInstance() const
1018  {
1019  return oldInstance_;
1020  }
1021 
1022  //- Reference to surface search engines
1023  const refinementSurfaces& surfaces() const
1024  {
1025  return surfaces_;
1026  }
1027 
1028  //- Reference to feature edge mesh
1029  const refinementFeatures& features() const
1030  {
1031  return features_;
1032  }
1033 
1034  //- Reference to refinement shells (regions)
1035  const shellSurfaces& shells() const
1036  {
1037  return shells_;
1038  }
1039 
1040  //- Reference to limit shells (regions)
1041  const shellSurfaces& limitShells() const
1042  {
1043  return limitShells_;
1044  }
1045 
1046  //- Reference to meshcutting engine
1047  const hexRef8& meshCutter() const
1048  {
1049  return meshCutter_;
1050  }
1051 
1052  //- Per start-end edge the index of the surface hit
1053  const labelList& surfaceIndex() const;
1054 
1056 
1057  //- For faces originating from processor faces store the original
1058  // patch
1059  const Map<label>& faceToCoupledPatch() const
1060  {
1061  return faceToCoupledPatch_;
1062  }
1063 
1064  //- Additional face data that is maintained across
1065  // topo changes. Every entry is a list over all faces.
1066  // Bit of a hack. Additional flag to say whether to maintain master
1067  // only (false) or increase set to account for face-from-face.
1068  const List<Tuple2<mapType, labelList>>& userFaceData() const
1069  {
1070  return userFaceData_;
1071  }
1072 
1073  List<Tuple2<mapType, labelList>>& userFaceData()
1074  {
1075  return userFaceData_;
1076  }
1077 
1078 
1079  // Other
1080 
1081  //- Count number of intersections (local)
1082  label countHits() const;
1083 
1084  //- Redecompose according to cell count
1085  // keepZoneFaces : find all faceZones from zoned surfaces and keep
1086  // owner and neighbour together
1087  // keepBaffles : find all baffles and keep them together
1088  autoPtr<mapDistributePolyMesh> balance
1089  (
1090  const bool keepZoneFaces,
1091  const bool keepBaffles,
1092  const scalarField& cellWeights,
1093  decompositionMethod& decomposer,
1094  fvMeshDistribute& distributor
1095  );
1096 
1097  //- Get faces with intersection.
1098  labelList intersectedFaces() const;
1099 
1100  //- Get points on surfaces with intersection and boundary faces.
1101  labelList intersectedPoints() const;
1102 
1103  //- Create patch from set of patches
1104  static autoPtr<indirectPrimitivePatch> makePatch
1105  (
1106  const polyMesh&,
1107  const labelList&
1108  );
1109 
1110  //- Helper function to make a pointVectorField with correct
1111  // bcs for mesh movement:
1112  // - adaptPatchIDs : fixedValue
1113  // - processor : calculated (so free to move)
1114  // - cyclic/wedge/symmetry : slip
1115  // - other : slip
1116  static tmp<pointVectorField> makeDisplacementField
1117  (
1118  const pointMesh& pMesh,
1119  const labelList& adaptPatchIDs
1120  );
1121 
1122  //- Helper function: check that face zones are synced
1123  static void checkCoupledFaceZones(const polyMesh&);
1124 
1125  //- Helper: calculate edge weights (1/length)
1126  static void calculateEdgeWeights
1127  (
1128  const polyMesh& mesh,
1129  const bitSet& isMasterEdge,
1130  const labelList& meshPoints,
1131  const edgeList& edges,
1132  scalarField& edgeWeights,
1133  scalarField& invSumWeight
1134  );
1135 
1136  //- Helper: weighted sum (over all subset of mesh points) by
1137  // summing contribution from (master) edges
1138  template<class Type>
1139  static void weightedSum
1140  (
1141  const polyMesh& mesh,
1142  const bitSet& isMasterEdge,
1143  const labelList& meshPoints,
1144  const edgeList& edges,
1145  const scalarField& edgeWeights,
1146  const Field<Type>& data,
1147  Field<Type>& sum
1148  );
1149 
1150 
1151  // Refinement
1152 
1153  //- Is local topology a small gap?
1154  bool isGap
1155  (
1156  const scalar,
1157  const vector&,
1158  const vector&,
1159  const vector&,
1160  const vector&
1161  ) const;
1162 
1163  //- Is local topology a small gap normal to the test vector
1164  bool isNormalGap
1165  (
1166  const scalar planarCos,
1167  const label level0,
1168  const vector& point0,
1169  const vector& normal0,
1170  const label level1,
1171  const vector& point1,
1172  const vector& normal1
1173  ) const;
1174 
1175  //- Calculate list of cells to refine.
1177  (
1178  const pointField& keepPoints,
1179  const scalar curvature,
1180  const scalar planarAngle,
1181 
1182  const bool featureRefinement,
1183  const bool featureDistanceRefinement,
1184  const bool internalRefinement,
1185  const bool surfaceRefinement,
1186  const bool curvatureRefinement,
1187  const bool smallFeatureRefinement,
1188  const bool gapRefinement,
1189  const bool bigGapRefinement,
1190  const bool spreadGapSize,
1191  const label maxGlobalCells,
1192  const label maxLocalCells
1193  ) const;
1194 
1195 
1196  // Blocking cells
1197 
1198  //- Mark faces on interface between set and rest
1199  // (and same cell level)
1200  void markOutsideFaces
1201  (
1202  const labelList& cellLevel,
1203  const labelList& neiLevel,
1204  const labelList& refineCell,
1205  bitSet& isOutsideFace
1206  ) const;
1207 
1208  //- Count number of faces on cell that are in set
1210  (
1211  const bitSet& isOutsideFace,
1212  const label celli
1213  ) const;
1215  //- Add one layer of cells to set
1216  void growSet
1217  (
1218  const labelList& neiLevel,
1219  const bitSet& isOutsideFace,
1221  label& nRefine
1222  ) const;
1223 
1224  //- Detect gapRefinement cells and remove them
1226  (
1227  const scalar planarAngle,
1228  const labelList& minSurfaceLevel,
1229  const labelList& globalToMasterPatch,
1230  const label growIter
1231  );
1232 
1233  // Blocking leaks (by blocking cells)
1234 
1235  //- Faces currently on boundary or intersected by surface
1237  (
1239  boolList& isBlockedFace
1240  ) const;
1241 
1242  //- Return list of cells to block by walking from the seedCells
1243  // until reaching a leak face
1245  (
1246  const boolList& isBlockedFace,
1247  const labelList& leakFaces,
1248  const labelList& seedCells
1249  ) const;
1250 
1251  //- Remove minimum amount of cells to break any leak from
1252  // inside to outside
1254  (
1255  const labelList& globalToMasterPatch,
1256  const labelList& globalToSlavePatch,
1257  const pointField& locationsInMesh,
1258  const pointField& locationsOutsideMesh,
1259  const labelList& selectedSurfaces
1260  );
1261 
1262  //- Baffle faces to break any leak from inside to outside
1264  (
1265  const labelList& globalToMasterPatch,
1266  const labelList& globalToSlavePatch,
1267  const pointField& locationsInMesh,
1268  const wordList& zonesInMesh,
1269  const pointField& locationsOutsideMesh,
1270  const labelList& selectedSurfaces
1271  );
1272 
1273 
1274  //- Refine some cells
1275  autoPtr<mapPolyMesh> refine(const labelList& cellsToRefine);
1276 
1277  //- Balance the mesh
1279  (
1280  const string& msg,
1281  decompositionMethod& decomposer,
1282  fvMeshDistribute& distributor,
1283  labelList& cellsToRefine,
1284  const scalar maxLoadUnbalance,
1285  const label maxCellUnbalance
1286  );
1288  //- Refine some cells and rebalance
1290  (
1291  const string& msg,
1292  decompositionMethod& decomposer,
1293  fvMeshDistribute& distributor,
1294  const labelList& cellsToRefine,
1295  const scalar maxLoadUnbalance,
1296  const label maxCellUnbalance
1297  );
1298 
1299  //- Balance before refining some cells
1301  (
1302  const string& msg,
1303  decompositionMethod& decomposer,
1304  fvMeshDistribute& distributor,
1305  const labelList& cellsToRefine,
1306  const scalar maxLoadUnbalance,
1307  const label maxCellUnbalance
1308  );
1309 
1310  //- Calculate list of cells to directionally refine
1312  (
1313  const label maxGlobalCells,
1314  const label maxLocalCells,
1315  const labelList& currentLevel,
1316  const direction dir
1317  ) const;
1318 
1319  //- Directionally refine in direction cmpt
1321  (
1322  const string& msg,
1323  const direction cmpt,
1324  const labelList& cellsToRefine
1325  );
1326 
1327 
1328  // Baffle handling
1329 
1330  //- Split off unreachable areas of mesh.
1331  void baffleAndSplitMesh
1332  (
1333  const bool handleSnapProblems,
1334 
1335  // How to remove problem snaps
1336  const snapParameters& snapParams,
1337  const bool useTopologicalSnapDetection,
1338  const bool removeEdgeConnectedCells,
1339  const scalarField& perpendicularAngle,
1340  const label nErodeCellZones,
1341  const dictionary& motionDict,
1342  Time& runTime,
1343  const labelList& globalToMasterPatch,
1344  const labelList& globalToSlavePatch,
1345  const pointField& locationsInMesh,
1346  const wordList& regionsInMesh,
1347  const pointField& locationsOutsideMesh,
1348  const bool exitIfLeakPath,
1349  const refPtr<coordSetWriter>& leakPathFormatter,
1350  refPtr<surfaceWriter>& surfFormatter
1351  );
1352 
1353  //- Merge free-standing baffles
1355  (
1356  const snapParameters& snapParams,
1357  const bool useTopologicalSnapDetection,
1358  const bool removeEdgeConnectedCells,
1359  const scalarField& perpendicularAngle,
1360  const scalar planarAngle,
1361  const dictionary& motionDict,
1362  Time& runTime,
1363  const labelList& globalToMasterPatch,
1364  const labelList& globalToSlavePatch,
1365  const pointField& locationsInMesh,
1366  const pointField& locationsOutsideMesh
1367  );
1368 
1369  //- Split off (with optional buffer layers) unreachable areas
1370  // of mesh. Does not introduce baffles.
1371  autoPtr<mapPolyMesh> splitMesh
1372  (
1373  const label nBufferLayers,
1374  const label nErodeCellZones,
1375  const labelList& globalToMasterPatch,
1376  const labelList& globalToSlavePatch,
1377 
1378  const pointField& locationsInMesh,
1379  const wordList& regionsInMesh,
1380  const pointField& locationsOutsideMesh,
1381  const bool exitIfLeakPath,
1382  const refPtr<coordSetWriter>& leakPathFormatter,
1383  refPtr<surfaceWriter>& surfFormatter
1384  );
1385 
1386  //- Remove cells from limitRegions if level -1
1388  (
1389  const label nBufferLayers,
1390  const label nErodeCellZones,
1391  const labelList& globalToMasterPatch,
1392  const labelList& globalToSlavePatch,
1393  const pointField& locationsInMesh,
1394  const wordList& regionsInMesh,
1395  const pointField& locationsOutsideMesh
1396  );
1397 
1398  //- Find boundary points that connect to more than one cell
1399  // region and split them.
1401 
1402  //- Find boundary points that connect to more than one cell
1403  // region and split them.
1405 
1406  //- Find boundary points that are on faceZones of type boundary
1407  // and duplicate them
1409 
1410  //- Merge duplicate points
1412  (
1413  const labelList& pointToDuplicate
1414  );
1415 
1416  //- Create baffle for every internal face where ownPatch != -1.
1417  // External faces get repatched according to ownPatch (neiPatch
1418  // should be -1 for these)
1420  (
1421  const labelList& ownPatch,
1422  const labelList& neiPatch
1423  );
1424 
1425  //- Get zones of given type
1427  (
1429  ) const;
1430 
1431  //- Subset baffles according to zones
1433  (
1434  const polyMesh& mesh,
1435  const labelList& zoneIDs,
1436  const List<labelPair>& baffles
1437  );
1438 
1439  //- Get per-face information (faceZone, master/slave patch)
1440  void getZoneFaces
1441  (
1442  const labelList& zoneIDs,
1444  labelList& ownPatch,
1445  labelList& neiPatch,
1446  labelList& nBaffles
1447  ) const;
1448 
1449  //- Create baffles for faces on faceZones. Return created baffles
1450  // (= pairs of faces) and corresponding faceZone
1452  (
1453  const labelList& zoneIDs,
1454  List<labelPair>& baffles,
1455  labelList& originatingFaceZone
1456  );
1457 
1458  //- Merge baffles. Gets pairs of faces and boundary faces to move
1459  // onto (coupled) patches
1461  (
1462  const List<labelPair>&,
1463  const Map<label>& faceToPatch
1464  );
1465 
1466  //- Merge all baffles on faceZones
1468  (
1469  const bool doInternalZones,
1470  const bool doBaffleZones
1471  );
1472 
1473  //- Put faces/cells into zones according to surface specification.
1474  // Returns null if no zone surfaces present. Regions containing
1475  // locationsInMesh/regionsInMesh will be put in corresponding
1476  // cellZone. keepPoints is for backwards compatibility and sets
1477  // all yet unassigned cells to be non-zoned (zone = -1)
1478  autoPtr<mapPolyMesh> zonify
1479  (
1480  const bool allowFreeStandingZoneFaces,
1481  const label nErodeCellZones,
1482  const pointField& locationsInMesh,
1483  const wordList& regionsInMesh,
1484  const pointField& locationsOutsideMesh,
1485  const bool exitIfLeakPath,
1486  const refPtr<coordSetWriter>& leakPathFormatter,
1487  refPtr<surfaceWriter>& surfFormatter,
1488  wordPairHashTable& zonesToFaceZone
1489  );
1490 
1491 
1492  // Other topo changes
1493 
1494  //- Helper:append patch to end of mesh.
1495  static label appendPatch
1496  (
1497  fvMesh&,
1498  const label insertPatchi,
1499  const word&,
1500  const dictionary&
1501  );
1502 
1503  //- Helper:add patch to mesh. Update all registered fields.
1504  // Used by addMeshedPatch to add patches originating from surfaces.
1505  static label addPatch(fvMesh&, const word& name, const dictionary&);
1506 
1507  //- Add patch originating from meshing. Update meshedPatches_.
1508  label addMeshedPatch(const word& name, const dictionary&);
1509 
1510  //- Get patchIDs for patches added in addMeshedPatch.
1511  labelList meshedPatches() const;
1512 
1513  //- Add/lookup faceZone and update information. Return index of
1514  // faceZone
1515  label addFaceZone
1516  (
1517  const word& fzName,
1518  const word& masterPatch,
1519  const word& slavePatch,
1520  const surfaceZonesInfo::faceZoneType& fzType
1521  );
1522 
1523  //- Lookup faceZone information. Return false if no information
1524  // for faceZone
1525  bool getFaceZoneInfo
1526  (
1527  const word& fzName,
1528  label& masterPatchID,
1529  label& slavePatchID,
1531  ) const;
1532 
1533  //- Add pointZone if does not exist. Return index of zone
1534  label addPointZone(const word& name);
1535 
1536  //- Count number of faces per patch edge. Parallel consistent.
1538 
1539  //- Select coupled faces that are not collocated
1541 
1542  //- Find any intersection of surface. Store in surfaceIndex_.
1543  void updateIntersections(const labelList& changedFaces);
1544 
1545  //- Calculate nearest intersection for selected mesh faces
1546  void nearestIntersection
1547  (
1548  const labelList& surfacesToTest,
1549  const labelList& testFaces,
1550 
1551  labelList& surface1,
1552  List<pointIndexHit>& hit1,
1553  labelList& region1,
1554  labelList& surface2,
1555  List<pointIndexHit>& hit2,
1556  labelList& region2
1557  ) const;
1558 
1559  //- Remove cells. Put exposedFaces into exposedPatchIDs.
1561  (
1562  const labelList& cellsToRemove,
1563  const labelList& exposedFaces,
1564  const labelList& exposedPatchIDs,
1565  removeCells& cellRemover
1566  );
1567 
1568  //- Find cell point is in. Uses optional perturbation to re-test.
1569  // Returns -1 on processors that do not have the cell.
1570  static label findCell
1571  (
1572  const polyMesh&,
1573  const vector& perturbVec,
1574  const point& p
1575  );
1576 
1577  //- Find region point is in. Uses optional perturbation to re-test.
1578  static label findRegion
1579  (
1580  const polyMesh&,
1581  const labelList& cellRegion,
1582  const vector& perturbVec,
1583  const point& p
1584  );
1585 
1586  //- Find regions points are in.
1587  // \return number of cells to be removed
1588  static label findRegions
1589  (
1590  const polyMesh&,
1591  const vector& perturbVec,
1592  const pointField& locationsInMesh,
1593  const pointField& locationsOutsideMesh,
1594  const label nRegions,
1595  labelList& cellRegion,
1596  const boolList& blockedFace,
1597  // Leak-path
1598  const bool exitIfLeakPath,
1599  const refPtr<coordSetWriter>& leakPathFormatter
1600  );
1601 
1602  //- Split mesh. Keep part containing point. Return empty map if
1603  // no cells removed.
1605  (
1606  const labelList& globalToMasterPatch,
1607  const labelList& globalToSlavePatch,
1608  const pointField& locationsInMesh,
1609  const pointField& locationsOutsideMesh,
1610  // Leak-path
1611  const bool exitIfLeakPath,
1612  const refPtr<coordSetWriter>& leakPathFormatter
1613  );
1614 
1615  //- Split faces into two
1616  void doSplitFaces
1617  (
1618  const labelList& splitFaces,
1619  const labelPairList& splits,
1620  polyTopoChange& meshMod
1621  ) const;
1622 
1623  //- Split faces along diagonal. Maintain mesh quality. Return
1624  // total number of faces split.
1625  label splitFacesUndo
1626  (
1627  const labelList& splitFaces,
1628  const labelPairList& splits,
1629  const dictionary& motionDict,
1630 
1631  labelList& duplicateFace,
1632  List<labelPair>& baffles
1633  );
1634 
1635  //- Update local numbering for mesh redistribution
1636  void distribute(const mapDistributePolyMesh&);
1637 
1638  //- Update for external change to mesh. changedFaces are in new mesh
1639  // face labels.
1640  void updateMesh
1641  (
1642  const mapPolyMesh&,
1643  const labelList& changedFaces
1644  );
1645 
1646  //- Helper: reorder list according to map.
1647  template<class T>
1648  static void updateList
1649  (
1650  const labelList& newToOld,
1651  const T& nullValue,
1652  List<T>& elems
1653  );
1654 
1655 
1656  // Restoring : is where other processes delete and reinsert data.
1657 
1658  //- Signal points/face/cells for which to store data
1659  void storeData
1660  (
1661  const labelList& pointsToStore,
1662  const labelList& facesToStore,
1663  const labelList& cellsToStore
1664  );
1665 
1666  //- Update local numbering + undo
1667  // Data to restore given as new pointlabel + stored pointlabel
1668  // (i.e. what was in pointsToStore)
1669  void updateMesh
1670  (
1671  const mapPolyMesh&,
1672  const labelList& changedFaces,
1673  const Map<label>& pointsToRestore,
1674  const Map<label>& facesToRestore,
1675  const Map<label>& cellsToRestore
1676  );
1677 
1678  // Merging coplanar faces and edges
1679 
1680  //- Merge coplanar faces if sets are of size mergeSize
1681  // (usually 4)
1682  label mergePatchFaces
1683  (
1684  const scalar minCos,
1685  const scalar concaveCos,
1686  const label mergeSize,
1687  const labelList& patchIDs,
1688  const meshRefinement::FaceMergeType mergeType
1689  );
1690 
1691  //- Merge coplanar faces. preserveFaces is != -1 for faces
1692  // to be preserved
1693  label mergePatchFacesUndo
1694  (
1695  const scalar minCos,
1696  const scalar concaveCos,
1697  const labelList& patchIDs,
1698  const dictionary& motionDict,
1699  const labelList& preserveFaces,
1700  const meshRefinement::FaceMergeType mergeType
1701  );
1702 
1704  (
1705  removePoints& pointRemover,
1706  const boolList& pointCanBeDeleted
1707  );
1708 
1710  (
1711  removePoints& pointRemover,
1712  const labelList& facesToRestore
1713  );
1714 
1716  (
1717  const labelList& candidateFaces,
1718  const labelHashSet& set
1719  ) const;
1720 
1721  // Pick up faces of cells of faces in set.
1723  (
1724  const labelUList& set
1725  ) const;
1726 
1727  // Pick up faces of cells of faces in set.
1729  (
1730  const labelHashSet& set
1731  ) const;
1732 
1733  //- Merge edges, maintain mesh quality. Return global number
1734  // of edges merged
1735  label mergeEdgesUndo
1736  (
1737  const scalar minCos,
1738  const dictionary& motionDict
1739  );
1740 
1741 
1742  // Debug/IO
1743 
1744  //- Debugging: check that all faces still obey start()>end()
1745  void checkData();
1746 
1747  static void testSyncPointList
1748  (
1749  const string& msg,
1750  const polyMesh& mesh,
1751  const List<scalar>& fld
1752  );
1753 
1754  static void testSyncPointList
1755  (
1756  const string& msg,
1757  const polyMesh& mesh,
1758  const List<point>& fld
1759  );
1760 
1761  //- Compare two lists over all boundary faces
1762  template<class T>
1764  (
1765  const scalar mergeDistance,
1766  const string&,
1767  const UList<T>&,
1768  const UList<T>&
1769  ) const;
1770 
1771  //- Print list according to (collected and) sorted coordinate
1772  template<class T>
1773  static void collectAndPrint
1774  (
1775  const UList<point>& points,
1776  const UList<T>& data
1777  );
1778 
1779  //- Determine master point for subset of points. If coupled
1780  // chooses only one
1781  static bitSet getMasterPoints
1782  (
1783  const polyMesh& mesh,
1784  const labelList& meshPoints
1785  );
1786 
1787  //- Determine master edge for subset of edges. If coupled
1788  // chooses only one
1789  static bitSet getMasterEdges
1790  (
1791  const polyMesh& mesh,
1792  const labelList& meshEdges
1793  );
1794 
1795  //- Print some mesh stats.
1796  void printMeshInfo
1797  (
1798  const bool debug,
1799  const string& msg,
1800  const bool printCellLevel
1801  ) const;
1802 
1803  //- Replacement for Time::timeName() that returns oldInstance
1804  //- (if overwrite_)
1805  word timeName() const;
1806 
1807  //- Set instance of all local IOobjects
1808  void setInstance(const fileName&);
1809 
1810  //- Write mesh and all data
1811  bool write() const;
1812 
1813  //- Write refinement level as volScalarFields for postprocessing
1814  void dumpRefinementLevel() const;
1815 
1816  //- Debug: Write intersection information to OBJ format
1817  void dumpIntersections(const fileName& prefix) const;
1818 
1819  //- Do any one of above IO functions
1820  void write
1821  (
1822  const debugType debugFlags,
1823  const writeType writeFlags,
1824  const fileName&
1825  ) const;
1826 
1827  //- Helper: remove all relevant files from mesh instance
1828  static void removeFiles(const polyMesh&);
1829 
1830  //- Helper: calculate average
1831  template<class T>
1832  static T gAverage
1833  (
1834  const bitSet& isMasterElem,
1835  const UList<T>& values
1836  );
1837 
1838  //- Get/set write level
1839  static writeType writeLevel();
1840  static void writeLevel(const writeType);
1841 
1843  //static outputType outputLevel();
1844  //static void outputLevel(const outputType);
1845 
1846 
1847  //- Helper: convert wordList into bit pattern using provided Enum
1848  template<class EnumContainer>
1849  static int readFlags
1850  (
1851  const EnumContainer& namedEnum,
1852  const wordList& words
1853  );
1854 
1855  //- Wrapper around dictionary::get which does not exit
1856  template<class Type>
1857  static Type get
1858  (
1859  const dictionary& dict,
1860  const word& keyword,
1861  const bool noExit,
1862  enum keyType::option matchOpt = keyType::REGEX,
1863  const Type& deflt = Zero
1864  );
1865 
1866  //- Wrapper around dictionary::subDict which does not exit
1867  static const dictionary& subDict
1868  (
1869  const dictionary& dict,
1870  const word& keyword,
1871  const bool noExit,
1872  enum keyType::option matchOpt = keyType::REGEX
1873  );
1874 
1875  //- Wrapper around dictionary::lookup which does not exit
1876  static ITstream& lookup
1877  (
1878  const dictionary& dict,
1879  const word& keyword,
1880  const bool noExit,
1881  enum keyType::option matchOpt = keyType::REGEX
1882  );
1883 };
1884 
1885 
1886 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
1887 
1888 } // End namespace Foam
1889 
1890 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
1891 
1892 #ifdef NoRepository
1893  #include "meshRefinementTemplates.C"
1894 #endif
1895 
1896 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
1897 
1898 #endif
1899 
1900 // ************************************************************************* //
const labelList patchIDs(pbm.indices(polyPatchNames, true))
label addFaceZone(const word &fzName, const word &masterPatch, const word &slavePatch, const surfaceZonesInfo::faceZoneType &fzType)
Add/lookup faceZone and update information. Return index of.
dictionary dict
void markOutsideFaces(const labelList &cellLevel, const labelList &neiLevel, const labelList &refineCell, bitSet &isOutsideFace) const
Mark faces on interface between set and rest.
const refinementSurfaces & surfaces() const
Reference to surface search engines.
const labelIOList & zoneIDs
Definition: correctPhi.H:59
static const dictionary & subDict(const dictionary &dict, const word &keyword, const bool noExit, enum keyType::option matchOpt=keyType::REGEX)
Wrapper around dictionary::subDict which does not exit.
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &f1)
uint8_t direction
Definition: direction.H:46
A class for handling file names.
Definition: fileName.H:72
const List< Tuple2< mapType, labelList > > & userFaceData() const
Additional face data that is maintained across.
label addPointZone(const word &name)
Add pointZone if does not exist. Return index of zone.
autoPtr< mapPolyMesh > mergePoints(const labelList &pointToDuplicate)
Merge duplicate points.
autoPtr< mapDistributePolyMesh > refineAndBalance(const string &msg, decompositionMethod &decomposer, fvMeshDistribute &distributor, const labelList &cellsToRefine, const scalar maxLoadUnbalance, const label maxCellUnbalance)
Refine some cells and rebalance.
label mergePatchFacesUndo(const scalar minCos, const scalar concaveCos, const labelList &patchIDs, const dictionary &motionDict, const labelList &preserveFaces, const meshRefinement::FaceMergeType mergeType)
Merge coplanar faces. preserveFaces is != -1 for faces.
const word & oldInstance() const
(points)instance of mesh upon construction
label mergePatchFaces(const scalar minCos, const scalar concaveCos, const label mergeSize, const labelList &patchIDs, const meshRefinement::FaceMergeType mergeType)
Merge coplanar faces if sets are of size mergeSize.
label countHits() const
Count number of intersections (local)
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
static void removeFiles(const polyMesh &)
Helper: remove all relevant files from mesh instance.
labelList growFaceCellFace(const labelUList &set) const
List< edge > edgeList
List of edge.
Definition: edgeList.H:32
bool getFaceZoneInfo(const word &fzName, label &masterPatchID, label &slavePatchID, surfaceZonesInfo::faceZoneType &fzType) const
Lookup faceZone information. Return false if no information.
static label findRegions(const polyMesh &, const vector &perturbVec, const pointField &locationsInMesh, const pointField &locationsOutsideMesh, const label nRegions, labelList &cellRegion, const boolList &blockedFace, const bool exitIfLeakPath, const refPtr< coordSetWriter > &leakPathFormatter)
Find regions points are in.
bool overwrite() const
Overwrite the mesh?
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:56
bool isNormalGap(const scalar planarCos, const label level0, const vector &point0, const vector &normal0, const label level1, const vector &point1, const vector &normal1) const
Is local topology a small gap normal to the test vector.
static label findRegion(const polyMesh &, const labelList &cellRegion, const vector &perturbVec, const point &p)
Find region point is in. Uses optional perturbation to re-test.
void printMeshInfo(const bool debug, const string &msg, const bool printCellLevel) const
Print some mesh stats.
autoPtr< mapPolyMesh > doRemoveCells(const labelList &cellsToRemove, const labelList &exposedFaces, const labelList &exposedPatchIDs, removeCells &cellRemover)
Remove cells. Put exposedFaces into exposedPatchIDs.
static ITstream & lookup(const dictionary &dict, const word &keyword, const bool noExit, enum keyType::option matchOpt=keyType::REGEX)
Wrapper around dictionary::lookup which does not exit.
label splitFacesUndo(const labelList &splitFaces, const labelPairList &splits, const dictionary &motionDict, labelList &duplicateFace, List< labelPair > &baffles)
Split faces along diagonal. Maintain mesh quality. Return.
const shellSurfaces & shells() const
Reference to refinement shells (regions)
autoPtr< mapPolyMesh > removeGapCells(const scalar planarAngle, const labelList &minSurfaceLevel, const labelList &globalToMasterPatch, const label growIter)
Detect gapRefinement cells and remove them.
Given list of cells to remove, insert all the topology changes.
Definition: removeCells.H:59
engineTime & runTime
autoPtr< mapPolyMesh > createBaffles(const labelList &ownPatch, const labelList &neiPatch)
Create baffle for every internal face where ownPatch != -1.
labelList intersectedFaces() const
Get faces with intersection.
static writeType writeLevel()
Get/set write level.
void baffleAndSplitMesh(const bool handleSnapProblems, const snapParameters &snapParams, const bool useTopologicalSnapDetection, const bool removeEdgeConnectedCells, const scalarField &perpendicularAngle, const label nErodeCellZones, const dictionary &motionDict, Time &runTime, const labelList &globalToMasterPatch, const labelList &globalToSlavePatch, const pointField &locationsInMesh, const wordList &regionsInMesh, const pointField &locationsOutsideMesh, const bool exitIfLeakPath, const refPtr< coordSetWriter > &leakPathFormatter, refPtr< surfaceWriter > &surfFormatter)
Split off unreachable areas of mesh.
Class containing mesh-to-mesh mapping information after a mesh distribution where we send parts of me...
label countFaceDirs(const bitSet &isOutsideFace, const label celli) const
Count number of faces on cell that are in set.
Forwards and collection of common point field types.
static bitSet getMasterEdges(const polyMesh &mesh, const labelList &meshEdges)
Determine master edge for subset of edges. If coupled.
labelList getZones(const List< surfaceZonesInfo::faceZoneType > &fzTypes) const
Get zones of given type.
labelList refineCandidates(const pointField &keepPoints, const scalar curvature, const scalar planarAngle, const bool featureRefinement, const bool featureDistanceRefinement, const bool internalRefinement, const bool surfaceRefinement, const bool curvatureRefinement, const bool smallFeatureRefinement, const bool gapRefinement, const bool bigGapRefinement, const bool spreadGapSize, const label maxGlobalCells, const label maxLocalCells) const
Calculate list of cells to refine.
static List< labelPair > subsetBaffles(const polyMesh &mesh, const labelList &zoneIDs, const List< labelPair > &baffles)
Subset baffles according to zones.
set value to -1 any face that was refined
static void calculateEdgeWeights(const polyMesh &mesh, const bitSet &isMasterEdge, const labelList &meshPoints, const edgeList &edges, scalarField &edgeWeights, scalarField &invSumWeight)
Helper: calculate edge weights (1/length)
An enumeration wrapper for classification of a location as being inside/outside of a volume...
Definition: volumeType.H:55
labelList intersectedPoints() const
Get points on surfaces with intersection and boundary faces.
autoPtr< mapPolyMesh > directionalRefine(const string &msg, const direction cmpt, const labelList &cellsToRefine)
Directionally refine in direction cmpt.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:69
A class for managing references or pointers (no reference counting)
Definition: HashPtrTable.H:49
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:157
labelList collectFaces(const labelList &candidateFaces, const labelHashSet &set) const
Takes mesh with &#39;baffles&#39; (= boundary faces sharing points). Determines for selected points on bounda...
const fvMesh & mesh() const
Reference to mesh.
Container for data on surfaces used for surface-driven refinement. Contains all the data about the le...
static label addPatch(fvMesh &, const word &name, const dictionary &)
Helper:add patch to mesh. Update all registered fields.
label mergeEdgesUndo(const scalar minCos, const dictionary &motionDict)
Merge edges, maintain mesh quality. Return global number.
static const Enum< writeType > writeTypeNames
Encapsulates queries for features.
static label appendPatch(fvMesh &, const label insertPatchi, const word &, const dictionary &)
Helper:append patch to end of mesh.
void doSplitFaces(const labelList &splitFaces, const labelPairList &splits, polyTopoChange &meshMod) const
Split faces into two.
void mergeFreeStandingBaffles(const snapParameters &snapParams, const bool useTopologicalSnapDetection, const bool removeEdgeConnectedCells, const scalarField &perpendicularAngle, const scalar planarAngle, const dictionary &motionDict, Time &runTime, const labelList &globalToMasterPatch, const labelList &globalToSlavePatch, const pointField &locationsInMesh, const pointField &locationsOutsideMesh)
Merge free-standing baffles.
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
Definition: HashOps.H:164
void distribute(const mapDistributePolyMesh &)
Update local numbering for mesh redistribution.
static void updateList(const labelList &newToOld, const T &nullValue, List< T > &elems)
Helper: reorder list according to map.
A list of faces which address into the list of points.
Sends/receives parts of mesh+fvfields to neighbouring processors. Used in load balancing.
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:38
const dimensionedScalar e
Elementary charge.
Definition: createFields.H:11
FaceMergeType
Enumeration for what to do with co-planar patch faces on a single.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
ClassName("meshRefinement")
Runtime type information.
const pointField & points
Refinement of (split) hexes using polyTopoChange.
Definition: hexRef8.H:62
A class for handling words, derived from Foam::string.
Definition: word.H:63
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Simple container to keep together snap specific information.
autoPtr< mapPolyMesh > removeLeakCells(const labelList &globalToMasterPatch, const labelList &globalToSlavePatch, const pointField &locationsInMesh, const pointField &locationsOutsideMesh, const labelList &selectedSurfaces)
Remove minimum amount of cells to break any leak from.
autoPtr< mapPolyMesh > blockLeakFaces(const labelList &globalToMasterPatch, const labelList &globalToSlavePatch, const pointField &locationsInMesh, const wordList &zonesInMesh, const pointField &locationsOutsideMesh, const labelList &selectedSurfaces)
Baffle faces to break any leak from inside to outside.
autoPtr< mapPolyMesh > mergeZoneBaffles(const bool doInternalZones, const bool doBaffleZones)
Merge all baffles on faceZones.
Base class for writing coordSet(s) and tracks with fields.
static void checkCoupledFaceZones(const polyMesh &)
Helper function: check that face zones are synced.
void testSyncBoundaryFaceList(const scalar mergeDistance, const string &, const UList< T > &, const UList< T > &) const
Compare two lists over all boundary faces.
void growSet(const labelList &neiLevel, const bitSet &isOutsideFace, labelList &refineCell, label &nRefine) const
Add one layer of cells to set.
const labelList & surfaceIndex() const
Per start-end edge the index of the surface hit.
autoPtr< mapPolyMesh > removeLimitShells(const label nBufferLayers, const label nErodeCellZones, const labelList &globalToMasterPatch, const labelList &globalToSlavePatch, const pointField &locationsInMesh, const wordList &regionsInMesh, const pointField &locationsOutsideMesh)
Remove cells from limitRegions if level -1.
Dynamically sized Field.
Definition: DynamicField.H:45
Abstract base class for domain decomposition.
Encapsulates queries for volume refinement (&#39;refine all cells within shell&#39;).
Definition: shellSurfaces.H:53
Vector< scalar > vector
Definition: vector.H:57
autoPtr< mapDistributePolyMesh > balance(const bool keepZoneFaces, const bool keepBaffles, const scalarField &cellWeights, decompositionMethod &decomposer, fvMeshDistribute &distributor)
Redecompose according to cell count.
Container with cells to refine. Refinement given as single direction.
Definition: refineCell.H:52
A HashTable similar to std::unordered_map.
Definition: HashTable.H:108
autoPtr< mapPolyMesh > doRemovePoints(removePoints &pointRemover, const boolList &pointCanBeDeleted)
labelList directionalRefineCandidates(const label maxGlobalCells, const label maxLocalCells, const labelList &currentLevel, const direction dir) const
Calculate list of cells to directionally refine.
A HashTable to objects of type <T> with a labelPair key. The hashing is based on labelPair (FixedList...
const refinementFeatures & features() const
Reference to feature edge mesh.
word timeName() const
Replacement for Time::timeName() that returns oldInstance (if overwrite_)
mapType
Enumeration for how userdata is to be mapped upon refinement.
const hexRef8 & meshCutter() const
Reference to meshcutting engine.
static int readFlags(const EnumContainer &namedEnum, const wordList &words)
Helper: convert wordList into bit pattern using provided Enum.
autoPtr< mapDistributePolyMesh > balanceAndRefine(const string &msg, decompositionMethod &decomposer, fvMeshDistribute &distributor, const labelList &cellsToRefine, const scalar maxLoadUnbalance, const label maxCellUnbalance)
Balance before refining some cells.
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
void checkData()
Debugging: check that all faces still obey start()>end()
int debug
Static debugging option.
constexpr auto end(C &c) -> decltype(c.end())
Return iterator to the end of the container c.
Definition: stdFoam.H:201
const Map< label > & faceToCoupledPatch() const
For faces originating from processor faces store the original.
label addMeshedPatch(const word &name, const dictionary &)
Add patch originating from meshing. Update meshedPatches_.
labelList meshedPatches() const
Get patchIDs for patches added in addMeshedPatch.
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
autoPtr< mapPolyMesh > doRestorePoints(removePoints &pointRemover, const labelList &facesToRestore)
static autoPtr< indirectPrimitivePatch > makePatch(const polyMesh &, const labelList &)
Create patch from set of patches.
void updateMesh(const mapPolyMesh &, const labelList &changedFaces)
Update for external change to mesh. changedFaces are in new mesh.
void updateIntersections(const labelList &changedFaces)
Find any intersection of surface. Store in surfaceIndex_.
scalar mergeDistance() const
autoPtr< mapPolyMesh > splitMeshRegions(const labelList &globalToMasterPatch, const labelList &globalToSlavePatch, const pointField &locationsInMesh, const pointField &locationsOutsideMesh, const bool exitIfLeakPath, const refPtr< coordSetWriter > &leakPathFormatter)
Split mesh. Keep part containing point. Return empty map if.
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< ' ';}gmvFile<< nl;for(const word &name :lagrangianScalarNames){ IOField< scalar > fld(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Helper class which maintains intersections of (changing) mesh with (static) surfaces.
autoPtr< mapPolyMesh > createZoneBaffles(const labelList &zoneIDs, List< labelPair > &baffles, labelList &originatingFaceZone)
Create baffles for faces on faceZones. Return created baffles.
autoPtr< mapPolyMesh > refine(const labelList &cellsToRefine)
Refine some cells.
void setInstance(const fileName &)
Set instance of all local IOobjects.
static void collectAndPrint(const UList< point > &points, const UList< T > &data)
Print list according to (collected and) sorted coordinate.
autoPtr< mapPolyMesh > dupNonManifoldPoints()
Find boundary points that connect to more than one cell.
void storeData(const labelList &pointsToStore, const labelList &facesToStore, const labelList &cellsToStore)
Signal points/face/cells for which to store data.
autoPtr< mapPolyMesh > dupNonManifoldBoundaryPoints()
Find boundary points that are on faceZones of type boundary.
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:59
static void testSyncPointList(const string &msg, const polyMesh &mesh, const List< scalar > &fld)
have slaves (upon refinement) from master
const shellSurfaces & limitShells() const
Reference to limit shells (regions)
static bitSet getMasterPoints(const polyMesh &mesh, const labelList &meshPoints)
Determine master point for subset of points. If coupled.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
Direct mesh changes based on v1.3 polyTopoChange syntax.
void getZoneFaces(const labelList &zoneIDs, labelList &faceZoneID, labelList &ownPatch, labelList &neiPatch, labelList &nBaffles) const
Get per-face information (faceZone, master/slave patch)
option
Enumeration for the data type and search/match modes (bitmask)
Definition: keyType.H:79
const std::string patch
OpenFOAM patch number as a std::string.
void selectIntersectedFaces(const labelList &surfaces, boolList &isBlockedFace) const
Faces currently on boundary or intersected by surface.
autoPtr< mapPolyMesh > mergeBaffles(const List< labelPair > &, const Map< label > &faceToPatch)
Merge baffles. Gets pairs of faces and boundary faces to move.
static const Enum< debugType > debugTypeNames
void selectSeparatedCoupledFaces(boolList &) const
Select coupled faces that are not collocated.
constexpr label labelMax
Definition: label.H:55
writeType
Enumeration for what to write. Used as a bit-pattern.
faceZoneType
What to do with faceZone faces.
debugType
Enumeration for what to debug. Used as a bit-pattern.
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
Removes selected points from mesh and updates faces using these points.
Definition: removePoints.H:56
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
bool isGap(const scalar, const vector &, const vector &, const vector &, const vector &) const
Is local topology a small gap?
A subset of mesh faces organised as a primitive patch.
Definition: faceZone.H:60
Contains information about location on a triSurface.
bool write() const
Write mesh and all data.
List< label > labelList
A List of labels.
Definition: List.H:62
static tmp< pointVectorField > makeDisplacementField(const pointMesh &pMesh, const labelList &adaptPatchIDs)
Helper function to make a pointVectorField with correct.
volScalarField & p
static T gAverage(const bitSet &isMasterElem, const UList< T > &values)
Helper: calculate average.
void dumpIntersections(const fileName &prefix) const
Debug: Write intersection information to OBJ format.
static void weightedSum(const polyMesh &mesh, const bitSet &isMasterEdge, const labelList &meshPoints, const edgeList &edges, const scalarField &edgeWeights, const Field< Type > &data, Field< Type > &sum)
Helper: weighted sum (over all subset of mesh points) by.
labelList detectLeakCells(const boolList &isBlockedFace, const labelList &leakFaces, const labelList &seedCells) const
Return list of cells to block by walking from the seedCells.
mode_t mode(const fileName &name, const bool followLink=true)
Return the file mode, normally following symbolic links.
Definition: POSIX.C:773
void dumpRefinementLevel() const
Write refinement level as volScalarFields for postprocessing.
Regular expression.
Definition: keyType.H:83
labelList countEdgeFaces(const uindirectPrimitivePatch &pp) const
Count number of faces per patch edge. Parallel consistent.
const volScalarField & p0
Definition: EEqn.H:36
An input stream of tokens.
Definition: ITstream.H:52
static label findCell(const polyMesh &, const vector &perturbVec, const point &p)
Find cell point is in. Uses optional perturbation to re-test.
uindirectPrimitivePatch pp(UIndirectList< face >(mesh.faces(), faceLabels), mesh.points())
Namespace for OpenFOAM.
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127