FreeFOAM The Cross-Platform CFD Toolkit
autoLayerDriver.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 | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::autoLayerDriver
26 
27 Description
28  All to do with adding layers
29 
30 SourceFiles
31  autoLayerDriver.C
32 
33 \*---------------------------------------------------------------------------*/
34 
35 #ifndef autoLayerDriver_H
36 #define autoLayerDriver_H
37 
39 #include <meshTools/wallPoint.H>
40 
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 
43 namespace Foam
44 {
45 
46 // Forward declaration of classes
47 class removePoints;
48 class pointSet;
49 class motionSmoother;
50 class addPatchCellLayer;
51 class pointData;
52 class wallPoint;
53 class faceSet;
54 class layerParameters;
55 
56 /*---------------------------------------------------------------------------*\
57  Class autoLayerDriver Declaration
58 \*---------------------------------------------------------------------------*/
59 
61 {
62  // Static data members
63 
64  //- Extrusion controls
65  enum extrudeMode
66  {
67  NOEXTRUDE,
68  EXTRUDE,
69  EXTRUDEREMOVE
71  };
72 
73 
74  // Private classes
75 
76  //- Combine operator class to combine normal with other normal.
77  class nomalsCombine
78  {
79  public:
80 
81  void operator()(vector& x, const vector& y) const
82  {
83  if (y != wallPoint::greatPoint)
84  {
85  if (x == wallPoint::greatPoint)
86  {
87  x = y;
88  }
89  else
90  {
91  x *= (x&y);
92  }
93  }
94  }
95  };
96 
97 
98  // Private data
99 
100  //- Mesh+surface
101  meshRefinement& meshRefiner_;
102 
103 
104 
105  // Private Member Functions
106 
107 
108  // Face merging
109 
110  //- Merge patch faces. Undo until no checkMesh errors.
111  label mergePatchFacesUndo
112  (
113  const scalar minCos,
114  const scalar concaveCos,
115  const dictionary&
116  );
117 
118  //- Remove points.
119  autoPtr<mapPolyMesh> doRemovePoints
120  (
121  removePoints& pointRemover,
122  const boolList& pointCanBeDeleted
123  );
124 
125  //- Restore faces (which contain removed points)
126  autoPtr<mapPolyMesh> doRestorePoints
127  (
128  removePoints& pointRemover,
129  const labelList& facesToRestore
130  );
131 
132  //- Return candidateFaces that are also in set.
133  labelList collectFaces
134  (
135  const labelList& candidateFaces,
136  const labelHashSet& set
137  ) const;
138 
139  //- Pick up faces of cells of faces in set.
140  labelList growFaceCellFace(const labelHashSet&) const;
141 
142  //- Remove points not used by any face or points used by only
143  // two faces where the edges are in line
144  label mergeEdgesUndo(const scalar minCos, const dictionary&);
145 
146 
147  // Layers
148 
149  //- For debugging: Dump displacement to .obj files
150  static void dumpDisplacement
151  (
152  const fileName&,
153  const indirectPrimitivePatch&,
154  const vectorField&,
155  const List<extrudeMode>&
156  );
157 
158  //- Check that primitivePatch is not multiply connected.
159  // Collect non-manifold points in pointSet.
160  static void checkManifold
161  (
162  const indirectPrimitivePatch&,
163  pointSet& nonManifoldPoints
164  );
165 
166  //- Check that mesh outside is not multiply connected.
167  void checkMeshManifold() const;
168 
169 
170  // Static extrusion setup
171 
172  //- Unset extrusion on point. Returns true if anything unset.
173  static bool unmarkExtrusion
174  (
175  const label patchPointI,
176  pointField& patchDisp,
177  labelList& patchNLayers,
178  List<extrudeMode>& extrudeStatus
179  );
180 
181  //- Unset extrusion on face. Returns true if anything unset.
182  static bool unmarkExtrusion
183  (
184  const face& localFace,
185  pointField& patchDisp,
186  labelList& patchNLayers,
187  List<extrudeMode>& extrudeStatus
188  );
189 
190  //- No extrusion at non-manifold points.
191  void handleNonManifolds
192  (
193  const indirectPrimitivePatch& pp,
194  const labelList& meshEdges,
195  pointField& patchDisp,
196  labelList& patchNLayers,
197  List<extrudeMode>& extrudeStatus
198  ) const;
199 
200  //- No extrusion on feature edges. Assumes non-manifold
201  // edges already handled.
202  void handleFeatureAngle
203  (
204  const indirectPrimitivePatch& pp,
205  const labelList& meshEdges,
206  const scalar minCos,
207  pointField& patchDisp,
208  labelList& patchNLayers,
209  List<extrudeMode>& extrudeStatus
210  ) const;
211 
212  //- No extrusion on warped faces
213  void handleWarpedFaces
214  (
215  const indirectPrimitivePatch& pp,
216  const scalar faceRatio,
217  const scalar edge0Len,
218  const labelList& cellLevel,
219  pointField& patchDisp,
220  labelList& patchNLayers,
221  List<extrudeMode>& extrudeStatus
222  ) const;
223 
224  //- Determine the number of layers per point from the number of
225  // layers per surface.
226  void setNumLayers
227  (
228  const labelList& patchToNLayers,
229  const labelList& patchIDs,
230  const indirectPrimitivePatch& pp,
231  pointField& patchDisp,
232  labelList& patchNLayers,
233  List<extrudeMode>& extrudeStatus
234  ) const;
235 
236  //- Grow no-extrusion layer.
237  static void growNoExtrusion
238  (
239  const indirectPrimitivePatch& pp,
240  pointField& patchDisp,
241  labelList& patchNLayers,
242  List<extrudeMode>& extrudeStatus
243  );
244 
245  //- Calculate pointwise wanted and minimum thickness.
246  // thickness: wanted thickness
247  // minthickness: when to give up and not extrude
248  // Gets per patch parameters and determine pp pointwise
249  // parameters.
250  void calculateLayerThickness
251  (
252  const indirectPrimitivePatch& pp,
253  const labelList& patchIDs,
254 
255  const scalarField& patchExpansionRatio,
256  const bool relativeSizes,
257  const scalarField& patchFinalLayerThickness,
258  const scalarField& patchMinThickness,
259 
260  const labelList& cellLevel,
261  const labelList& patchNLayers,
262  const scalar edge0Len,
263 
264  scalarField& thickness,
265  scalarField& minThickness,
266  scalarField& expansionRatio
267  ) const;
268 
269 
270  // Extrusion execution
271 
272  //- Synchronize displacement among coupled patches.
273  void syncPatchDisplacement
274  (
275  const motionSmoother& meshMover,
276  const scalarField& minThickness,
277  pointField& patchDisp,
278  labelList& patchNLayers,
279  List<extrudeMode>& extrudeStatus
280  ) const;
281 
282  //- Get nearest point on surface to snap to
283  void getPatchDisplacement
284  (
285  const motionSmoother& meshMover,
286  const scalarField& thickness,
287  const scalarField& minThickness,
288  pointField& patchDisp,
289  labelList& patchNLayers,
290  List<extrudeMode>& extrudeStatus
291  ) const;
292 
293  //- Truncates displacement
294  // - for all patchFaces in the faceset displacement gets set
295  // to zero
296  // - all displacement < minThickness gets set to zero
297  label truncateDisplacement
298  (
299  const motionSmoother& meshMover,
300  const scalarField& minThickness,
301  const faceSet& illegalPatchFaces,
302  pointField& patchDisp,
303  labelList& patchNLayers,
304  List<extrudeMode>& extrudeStatus
305  ) const;
306 
307  //- Setup layer information (at points and faces) to
308  // modify mesh topology in
309  // regions where layer mesh terminates. Guarantees an
310  // optional slow decreasing of the number of layers.
311  // Returns the number of layers per face and per point
312  // to go into the actual layer addition engine.
313  void setupLayerInfoTruncation
314  (
315  const motionSmoother& meshMover,
316  const labelList& patchNLayers,
317  const List<extrudeMode>& extrudeStatus,
318  const label nBufferCellsNoExtrude,
319  labelList& nPatchPointLayers,
320  labelList& nPatchFaceLayers
321  ) const;
322 
323  //- Does any of the cells use a face from faces?
324  static bool cellsUseFace
325  (
326  const polyMesh& mesh,
327  const labelList& cellLabels,
328  const labelHashSet& faces
329  );
330 
331  //- Checks the newly added cells and locally unmarks points
332  // so they will not get extruded next time round. Returns
333  // global number of unmarked points (0 if all was fine)
334  static label checkAndUnmark
335  (
336  const addPatchCellLayer& addLayer,
337  const dictionary& motionDict,
338  const indirectPrimitivePatch& pp,
339  const fvMesh&,
340 
341  pointField& patchDisp,
342  labelList& patchNLayers,
343  List<extrudeMode>& extrudeStatus
344  );
345 
346  //- Count global number of extruded faces
347  static label countExtrusion
348  (
349  const indirectPrimitivePatch& pp,
350  const List<extrudeMode>& extrudeStatus
351  );
352 
353  //- Collect layer faces and layer cells into bools
354  // for ease of handling
355  static void getLayerCellsFaces
356  (
357  const polyMesh&,
358  const addPatchCellLayer&,
359  boolList&,
360  boolList&
361  );
362 
363  // Mesh shrinking (to create space for layers)
364 
365  //- Average field (over all subset of mesh points) by
366  // summing contribution from edges. Global parallel since only
367  // does master edges for coupled edges.
368  template<class Type>
369  static void averageNeighbours
370  (
371  const polyMesh& mesh,
372  const PackedBoolList& isMasterEdge,
373  const labelList& meshEdges,
374  const labelList& meshPoints,
375  const edgeList& edges,
376  const scalarField& invSumWeight,
377  const Field<Type>& data,
379  );
380 
381  //- Calculate inverse sum of edge weights (currently always 1.0)
382  void sumWeights
383  (
384  const PackedBoolList& isMasterEdge,
385  const labelList& meshEdges,
386  const labelList& meshPoints,
387  const edgeList& edges,
388  scalarField& invSumWeight
389  ) const;
390 
391  //- Smooth scalar field on patch
392  void smoothField
393  (
394  const motionSmoother& meshMover,
395  const PackedBoolList& isMasterEdge,
396  const labelList& meshEdges,
397  const scalarField& fieldMin,
398  const label nSmoothDisp,
399  scalarField& field
400  ) const;
401 
402  //- Smooth normals on patch.
403  void smoothPatchNormals
404  (
405  const motionSmoother& meshMover,
406  const PackedBoolList& isMasterEdge,
407  const labelList& meshEdges,
408  const label nSmoothDisp,
409  pointField& normals
410  ) const;
411 
412  //- Smooth normals in interior.
413  void smoothNormals
414  (
415  const label nSmoothDisp,
416  const PackedBoolList& isMasterEdge,
417  const labelList& fixedPoints,
418  pointVectorField& normals
419  ) const;
420 
421  bool isMaxEdge
422  (
423  const List<pointData>&,
424  const label edgeI,
425  const scalar minCos
426  ) const;
427 
428  //- Stop layer growth where mesh wraps around edge with a
429  // large feature angle
430  void handleFeatureAngleLayerTerminations
431  (
432  const indirectPrimitivePatch& pp,
433  const scalar minCos,
434  List<extrudeMode>& extrudeStatus,
435  pointField& patchDisp,
436  labelList& patchNLayers,
437  label& nPointCounter
438  ) const;
439 
440  //- Find isolated islands (points, edges and faces and
441  // layer terminations)
442  // in the layer mesh and stop any layer growth at these points.
443  void findIsolatedRegions
444  (
445  const indirectPrimitivePatch& pp,
446  const PackedBoolList& isMasterEdge,
447  const labelList& meshEdges,
448  const scalar minCosLayerTermination,
449  scalarField& field,
450  List<extrudeMode>& extrudeStatus,
451  pointField& patchDisp,
452  labelList& patchNLayers
453  ) const;
454 
455  // Calculate medial axis fields
456  void medialAxisSmoothingInfo
457  (
458  const motionSmoother& meshMover,
459  const label nSmoothNormals,
460  const label nSmoothSurfaceNormals,
461  const scalar minMedianAxisAngleCos,
462 
463  pointVectorField& dispVec,
464  pointScalarField& medialRatio,
465  pointScalarField& medialDist
466  ) const;
467 
468  //- Main routine to shrink mesh
469  void shrinkMeshMedialDistance
470  (
471  motionSmoother& meshMover,
472  const dictionary& meshQualityDict,
473  const label nSmoothThickness,
474  const scalar maxThicknessToMedialRatio,
475  const label nAllowableErrors,
476  const label nSnap,
477  const scalar minCosLayerTermination,
478 
479  const scalarField& layerThickness,
480  const scalarField& minThickness,
481 
482  const pointVectorField& dispVec,
483  const pointScalarField& medialRatio,
484  const pointScalarField& medialDist,
485 
486  List<extrudeMode>& extrudeStatus,
487  pointField& patchDisp,
488  labelList& patchNLayers
489  ) const;
490 
491 
492 
493  //- Disallow default bitwise copy construct
495 
496  //- Disallow default bitwise assignment
497  void operator=(const autoLayerDriver&);
498 
499 
500 public:
501 
502  //- Runtime type information
503  ClassName("autoLayerDriver");
504 
505  // Constructors
506 
507  //- Construct from components
508  autoLayerDriver(meshRefinement& meshRefiner);
509 
510 
511  // Member Functions
512 
513  //- Merge patch faces on same cell.
514  void mergePatchFacesUndo
515  (
516  const layerParameters& layerParams,
517  const dictionary& motionDict
518  );
519 
520  //- Add cell layers
521  void addLayers
522  (
523  const layerParameters& layerParams,
524  const dictionary& motionDict,
525  const labelList& patchIDs,
526  const label nAllowableErrors,
527  decompositionMethod& decomposer,
528  fvMeshDistribute& distributor
529  );
530 
531  //- Add layers according to the dictionary settings
532  void doLayers
533  (
534  const dictionary& shrinkDict,
535  const dictionary& motionDict,
536  const layerParameters& layerParams,
537  const bool preBalance, // balance before adding?
538  decompositionMethod& decomposer,
539  fvMeshDistribute& distributor
540  );
541 
542 };
543 
544 
545 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
546 
547 } // End namespace Foam
548 
549 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
550 
551 #ifdef NoRepository
553 #endif
554 
555 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
556 
557 #endif
558 
559 // ************************ vim: set sw=4 sts=4 et: ************************ //