snappyRefineDriver.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-2014 OpenFOAM Foundation
9  Copyright (C) 2015-2021 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::snappyRefineDriver
29 
30 Description
31 
32 SourceFiles
33  snappyRefineDriver.C
34 
35 \*---------------------------------------------------------------------------*/
36 
37 #ifndef snappyRefineDriver_H
38 #define snappyRefineDriver_H
39 
40 #include "wordPairHashes.H"
41 #include "labelList.H"
42 #include "scalarField.H"
43 #include "Tuple2.H"
44 #include "coordSetWriter.H"
45 #include "DynamicList.H"
46 #include "labelVector.H"
47 #include "meshRefinement.H"
48 
49 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50 
51 namespace Foam
52 {
53 
54 // Forward Declarations
55 class refinementParameters;
56 class snapParameters;
57 
58 class decompositionMethod;
59 class fvMeshDistribute;
60 class fvMesh;
61 
62 /*---------------------------------------------------------------------------*\
63  Class snappyRefineDriver Declaration
64 \*---------------------------------------------------------------------------*/
65 
67 {
68  // Private data
69 
70  //- Mesh+surface
71  meshRefinement& meshRefiner_;
72 
73  //- Reference to decomposition method
74  decompositionMethod& decomposer_;
75 
76  //- Reference to mesh distribution engine
77  fvMeshDistribute& distributor_;
78 
79  //- From surface region to patch
80  const labelList globalToMasterPatch_;
81 
82  //- From surface region to patch
83  const labelList globalToSlavePatch_;
84 
85  //- How to write lines. Used e.g. when writing leak-paths
86  coordSetWriter& setFormatter_;
87 
88  //- How to write surfaces. Used e.g. when writing leak closure faces
89  refPtr<surfaceWriter>& surfFormatter_;
90 
91  //- Are we operating in test mode?
92  const bool dryRun_;
93 
94 
95  // Private Member Functions
96 
97  void addNeighbours
98  (
99  const labelVector& n,
100  const labelList& cellLevel,
101  const labelVector& voxel,
102  const label voxeli,
104  ) const;
105 
106  //- Rough estimate of cell size and cell count
107  void estimateCellSizeAndCount
108  (
109  const refinementParameters& refineParams
110  ) const;
111 
112  //- Refine all cells pierced by explicit feature edges
113  label featureEdgeRefine
114  (
115  const refinementParameters& refineParams,
116  const label maxIter,
117  const label minRefine
118  );
119 
120  //- Refine all cells containing small surface features
121  label smallFeatureRefine
122  (
123  const refinementParameters& refineParams,
124  const label maxIter
125  );
126 
127  //- Refine all cells interacting with the surface
128  label surfaceOnlyRefine
129  (
130  const refinementParameters& refineParams,
131  const label maxIter,
132  const label leakBlockageIter // when to start leak closing
133  );
134 
135  //- Refine all cells in small gaps
136  label gapOnlyRefine
137  (
138  const refinementParameters& refineParams,
139  const label maxIter
140  );
141 
142  //- Block all cells in small gaps
143  label surfaceProximityBlock
144  (
145  const refinementParameters& refineParams,
146  const label maxIter
147  );
148 
149  //- Refine all cells in large gaps
150  label bigGapOnlyRefine
151  (
152  const refinementParameters& refineParams,
153  const bool spreadGapSize,
154  const label maxIter
155  );
156 
157  //- Refine cells with almost all sides refined
158  label danglingCellRefine
159  (
160  const refinementParameters& refineParams,
161  const label nFaces,
162  const label maxIter
163  );
164 
165  //- Refine cells with opposite faces with differing refinement level
166  label refinementInterfaceRefine
167  (
168  const refinementParameters& refineParams,
169  const label maxIter
170  );
171 
172  //- Helper: see if any element in f has higher level than cLevel
173  bool usesHigherLevel
174  (
175  const labelUList& boundaryPointLevel,
176  const labelUList& f,
177  const label cLevel
178  ) const;
179 
180  //- Refine cells with a point/edge but not face on the boundary
181  label boundaryRefinementInterfaceRefine
182  (
183  const refinementParameters& refineParams,
184  const label maxIter
185  );
186 
187  //- Remove all cells within intersected region
188  void removeInsideCells
189  (
190  const refinementParameters& refineParams,
191  const label nBufferLayers
192  );
193 
194  //- Refine all cells inside/outside shell
195  label shellRefine
196  (
197  const refinementParameters& refineParams,
198  const label maxIter
199  );
200 
201  // Directional refinement and smoothing
202 
203  //- Refine (directional) all cells inside/outside shell
204  label directionalShellRefine
205  (
206  const refinementParameters& refineParams,
207  const label maxIter
208  );
209 
210  //- Calculate local edge length from cell volumes
211  void mergeAndSmoothRatio
212  (
213  const scalarList& allSeedPointDist,
214  const label nSmoothExpansion,
215  List<Tuple2<scalar, scalar>>& keyAndValue
216  );
217 
218  //- Smooth the directional expansion ratio
219  label directionalSmooth(const refinementParameters& refineParams);
220 
221 
222  //- Add baffles and remove unreachable cells
223  void baffleAndSplitMesh
224  (
225  const refinementParameters& refineParams,
226  const snapParameters& snapParams,
227  const bool handleSnapProblems,
228  const dictionary& motionDict
229  );
230 
231  //- Add zones
232  void zonify
233  (
234  const refinementParameters& refineParams,
235  wordPairHashTable& zonesToFaceZone
236  );
237 
238  void splitAndMergeBaffles
239  (
240  const refinementParameters& refineParams,
241  const snapParameters& snapParams,
242  const bool handleSnapProblems,
243  const dictionary& motionDict
244  );
245 
246  //- Merge refined boundary faces (from exposing coarser cell)
247  void mergePatchFaces
248  (
249  const meshRefinement::FaceMergeType mergeType,
250  const refinementParameters& refineParams,
251  const dictionary& motionDict
252  );
253 
254  //- Optionally delete some small regions
255  void deleteSmallRegions(const refinementParameters&);
256 
257 
258  //- No copy construct
259  snappyRefineDriver(const snappyRefineDriver&) = delete;
260 
261  //- No copy assignment
262  void operator=(const snappyRefineDriver&) = delete;
263 
264 
265 public:
266 
267  //- Runtime type information
268  ClassName("snappyRefineDriver");
269 
270 
271  // Constructors
272 
273  //- Construct from components
275  (
276  meshRefinement& meshRefiner,
277  decompositionMethod& decomposer,
278  fvMeshDistribute& distributor,
279  const labelUList& globalToMasterPatch,
280  const labelUList& globalToSlavePatch,
281  coordSetWriter& setFormatter,
282  refPtr<surfaceWriter>& surfFormatter,
283  const bool dryRun = false
284  );
285 
286 
287  // Member Functions
288 
289  //- Do all the refinement
290  void doRefine
291  (
292  const dictionary& refineDict,
293  const refinementParameters& refineParams,
294  const snapParameters& snapParams,
295  const bool prepareForSnapping,
296  const meshRefinement::FaceMergeType mergeType,
297  const dictionary& motionDict
298  );
299 
300  //- Helper: add faceZones and patches
301  static void addFaceZones
302  (
303  meshRefinement& meshRefiner,
304  const refinementParameters& refineParams,
305  const HashTable<Pair<word>>& faceZoneToPatches
306  );
307 };
308 
309 
310 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
311 
312 } // End namespace Foam
313 
314 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
315 
316 #endif
317 
318 // ************************************************************************* //
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
Simple container to keep together refinement specific information.
A class for managing references or pointers (no reference counting)
Definition: HashPtrTable.H:49
Sends/receives parts of mesh+fvfields to neighbouring processors. Used in load balancing.
FaceMergeType
Enumeration for what to do with co-planar patch faces on a single.
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
Definition: DynamicList.H:51
Simple container to keep together snap specific information.
Base class for writing coordSet(s) and tracks with fields.
Abstract base class for domain decomposition.
A HashTable similar to std::unordered_map.
Definition: HashTable.H:108
labelList f(nPoints)
static void addFaceZones(meshRefinement &meshRefiner, const refinementParameters &refineParams, const HashTable< Pair< word >> &faceZoneToPatches)
Helper: add faceZones and patches.
Helper class which maintains intersections of (changing) mesh with (static) surfaces.
void doRefine(const dictionary &refineDict, const refinementParameters &refineParams, const snapParameters &snapParams, const bool prepareForSnapping, const meshRefinement::FaceMergeType mergeType, const dictionary &motionDict)
Do all the refinement.
label n
ClassName("snappyRefineDriver")
Runtime type information.
Namespace for OpenFOAM.