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