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