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-2018 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 "wordPairHashTable.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  //- Remove all cells within intersected region
169  void removeInsideCells
170  (
171  const refinementParameters& refineParams,
172  const label nBufferLayers
173  );
174 
175  //- Refine all cells inside/outside shell
176  label shellRefine
177  (
178  const refinementParameters& refineParams,
179  const label maxIter
180  );
181 
182  // Directional refinement and smoothing
183 
184  //- Refine (directional) all cells inside/outside shell
185  label directionalShellRefine
186  (
187  const refinementParameters& refineParams,
188  const label maxIter
189  );
190 
191  //- Calculate local edge length from cell volumes
192  void mergeAndSmoothRatio
193  (
194  const scalarList& allSeedPointDist,
195  const label nSmoothExpansion,
196  List<Tuple2<scalar, scalar>>& keyAndValue
197  );
198 
199  //- Smooth the directional expansion ratio
200  label directionalSmooth(const refinementParameters& refineParams);
201 
202 
203  //- Add baffles and remove unreachable cells
204  void baffleAndSplitMesh
205  (
206  const refinementParameters& refineParams,
207  const snapParameters& snapParams,
208  const bool handleSnapProblems,
209  const dictionary& motionDict
210  );
211 
212  //- Add zones
213  void zonify
214  (
215  const refinementParameters& refineParams,
216  wordPairHashTable& zonesToFaceZone
217  );
218 
219  void splitAndMergeBaffles
220  (
221  const refinementParameters& refineParams,
222  const snapParameters& snapParams,
223  const bool handleSnapProblems,
224  const dictionary& motionDict
225  );
226 
227  //- Merge refined boundary faces (from exposing coarser cell)
228  void mergePatchFaces
229  (
230  const meshRefinement::FaceMergeType mergeType,
231  const refinementParameters& refineParams,
232  const dictionary& motionDict
233  );
234 
235  //- No copy construct
236  snappyRefineDriver(const snappyRefineDriver&) = delete;
237 
238  //- No copy assignment
239  void operator=(const snappyRefineDriver&) = delete;
240 
241 
242 public:
243 
244  //- Runtime type information
245  ClassName("snappyRefineDriver");
246 
247 
248  // Constructors
249 
250  //- Construct from components
252  (
253  meshRefinement& meshRefiner,
254  decompositionMethod& decomposer,
255  fvMeshDistribute& distributor,
256  const labelUList& globalToMasterPatch,
257  const labelUList& globalToSlavePatch,
258  const writer<scalar>& setFormatter,
259  const bool dryRun = false
260  );
261 
262 
263  // Member Functions
264 
265  //- Do all the refinement
266  void doRefine
267  (
268  const dictionary& refineDict,
269  const refinementParameters& refineParams,
270  const snapParameters& snapParams,
271  const bool prepareForSnapping,
272  const meshRefinement::FaceMergeType mergeType,
273  const dictionary& motionDict
274  );
275 
276  //- Helper: add faceZones and patches
277  static void addFaceZones
278  (
279  meshRefinement& meshRefiner,
280  const refinementParameters& refineParams,
281  const HashTable<Pair<word>>& faceZoneToPatches
282  );
283 };
284 
285 
286 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
287 
288 } // End namespace Foam
289 
290 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
291 
292 #endif
293 
294 // ************************************************************************* //
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:57
labelVector.H
Foam::meshRefinement::FaceMergeType
FaceMergeType
Enumeration for what to do with co-planar patch faces on a single.
Definition: meshRefinement.H:134
n
label n
Definition: TABSMDCalcMethod2.H:31
Foam::snapParameters
Simple container to keep together snap specific information.
Definition: snapParameters.H:52
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:62
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:121
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:2872
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
wordPairHashTable.H
Foam::Pair< word >
Foam::Vector< label >
Foam::List< label >
Foam::meshRefinement
Helper class which maintains intersections of (changing) mesh with (static) surfaces.
Definition: meshRefinement.H:86
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:2735
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:73