1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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.
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
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/>.
28 All to do with adding layers
33 \*---------------------------------------------------------------------------*/
35 #ifndef autoLayerDriver_H
36 #define autoLayerDriver_H
38 #include "meshRefinement.H"
40 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 // Forward declaration of classes
49 class addPatchCellLayer;
52 class layerParameters;
54 /*---------------------------------------------------------------------------*\
55 Class autoLayerDriver Declaration
56 \*---------------------------------------------------------------------------*/
60 // Static data members
62 //- Extrusion controls
65 NOEXTRUDE, /*!< Do not extrude. No layers added. */
66 EXTRUDE, /*!< Extrude */
67 EXTRUDEREMOVE /*!< Extrude but afterwards remove added */
74 //- Combine operator class to combine normal with other normal.
79 void operator()(vector& x, const vector& y) const
99 meshRefinement& meshRefiner_;
101 //- From surface region to patch
102 const labelList globalToPatch_;
106 // Private Member Functions
110 //- For debugging: Dump displacement to .obj files
111 static void dumpDisplacement
114 const indirectPrimitivePatch&,
116 const List<extrudeMode>&
119 //- Check that primitivePatch is not multiply connected.
120 // Collect non-manifold points in pointSet.
121 static void checkManifold
123 const indirectPrimitivePatch&,
124 pointSet& nonManifoldPoints
127 //- Check that mesh outside is not multiply connected.
128 void checkMeshManifold() const;
131 // Static extrusion setup
133 //- Unset extrusion on point. Returns true if anything unset.
134 static bool unmarkExtrusion
136 const label patchPointI,
137 pointField& patchDisp,
138 labelList& patchNLayers,
139 List<extrudeMode>& extrudeStatus
142 //- Unset extrusion on face. Returns true if anything unset.
143 static bool unmarkExtrusion
145 const face& localFace,
146 pointField& patchDisp,
147 labelList& patchNLayers,
148 List<extrudeMode>& extrudeStatus
151 //- No extrusion at non-manifold points.
152 void handleNonManifolds
154 const indirectPrimitivePatch& pp,
155 const labelList& meshEdges,
156 const labelListList& edgeGlobalFaces,
157 pointField& patchDisp,
158 labelList& patchNLayers,
159 List<extrudeMode>& extrudeStatus
162 //- No extrusion on feature edges. Assumes non-manifold
163 // edges already handled.
164 void handleFeatureAngle
166 const indirectPrimitivePatch& pp,
167 const labelList& meshEdges,
169 pointField& patchDisp,
170 labelList& patchNLayers,
171 List<extrudeMode>& extrudeStatus
174 //- No extrusion on warped faces
175 void handleWarpedFaces
177 const indirectPrimitivePatch& pp,
178 const scalar faceRatio,
179 const scalar edge0Len,
180 const labelList& cellLevel,
181 pointField& patchDisp,
182 labelList& patchNLayers,
183 List<extrudeMode>& extrudeStatus
186 //- Determine the number of layers per point from the number of
187 // layers per surface.
190 const labelList& patchToNLayers,
191 const labelList& patchIDs,
192 const indirectPrimitivePatch& pp,
193 pointField& patchDisp,
194 labelList& patchNLayers,
195 List<extrudeMode>& extrudeStatus
198 //- Grow no-extrusion layer.
201 const indirectPrimitivePatch& pp,
202 pointField& patchDisp,
203 labelList& patchNLayers,
204 List<extrudeMode>& extrudeStatus
207 //- See what patches boundaryedges should be extruded into
208 void determineSidePatches
210 const globalIndex& globalFaces,
211 const labelListList& edgeGlobalFaces,
212 const indirectPrimitivePatch& pp,
214 labelList& sidePatchID
217 //- Calculate pointwise wanted and minimum thickness.
218 // thickness: wanted thickness
219 // minthickness: when to give up and not extrude
220 // Gets per patch parameters and determine pp pointwise
222 void calculateLayerThickness
224 const indirectPrimitivePatch& pp,
225 const labelList& patchIDs,
227 const scalarField& patchExpansionRatio,
228 const bool relativeSizes,
229 const scalarField& patchFinalLayerThickness,
230 const scalarField& patchMinThickness,
232 const labelList& cellLevel,
233 const labelList& patchNLayers,
234 const scalar edge0Len,
236 scalarField& thickness,
237 scalarField& minThickness,
238 scalarField& expansionRatio
242 // Extrusion execution
244 //- Synchronize displacement among coupled patches.
245 void syncPatchDisplacement
247 const motionSmoother& meshMover,
248 const scalarField& minThickness,
249 pointField& patchDisp,
250 labelList& patchNLayers,
251 List<extrudeMode>& extrudeStatus
254 //- Get nearest point on surface to snap to
255 void getPatchDisplacement
257 const motionSmoother& meshMover,
258 const scalarField& thickness,
259 const scalarField& minThickness,
260 pointField& patchDisp,
261 labelList& patchNLayers,
262 List<extrudeMode>& extrudeStatus
265 //- for truncateDisplacement: find strings of edges
266 bool sameEdgeNeighbour
268 const labelListList& globalEdgeFaces,
269 const label myGlobalFaceI,
270 const label nbrGlobFaceI,
274 //- for truncateDisplacement: find strings of edges
277 const indirectPrimitivePatch& pp,
278 const labelListList& globalEdgeFaces,
281 const label myGlobFaceI,
282 const label nbrGlobFaceI,
283 DynamicList<label>& vertices
286 //- Truncates displacement
287 // - for all patchFaces in the faceset displacement gets set
289 // - all displacement < minThickness gets set to zero
290 // - all non-consecutive extrusions get set to 0
291 label truncateDisplacement
293 const globalIndex& globalFaces,
294 const labelListList& edgeGlobalFaces,
295 const motionSmoother& meshMover,
296 const scalarField& minThickness,
297 const faceSet& illegalPatchFaces,
298 pointField& patchDisp,
299 labelList& patchNLayers,
300 List<extrudeMode>& extrudeStatus
303 //- Setup layer information (at points and faces) to
304 // modify mesh topology in
305 // regions where layer mesh terminates. Guarantees an
306 // optional slow decreasing of the number of layers.
307 // Returns the number of layers per face and per point
308 // to go into the actual layer addition engine.
309 void setupLayerInfoTruncation
311 const motionSmoother& meshMover,
312 const labelList& patchNLayers,
313 const List<extrudeMode>& extrudeStatus,
314 const label nBufferCellsNoExtrude,
315 labelList& nPatchPointLayers,
316 labelList& nPatchFaceLayers
319 //- Does any of the cells use a face from faces?
320 static bool cellsUseFace
322 const polyMesh& mesh,
323 const labelList& cellLabels,
324 const labelHashSet& faces
327 //- Checks the newly added cells and locally unmarks points
328 // so they will not get extruded next time round. Returns
329 // global number of unmarked points (0 if all was fine)
330 static label checkAndUnmark
332 const addPatchCellLayer& addLayer,
333 const dictionary& motionDict,
334 const bool additionalReporting,
335 const List<labelPair>& baffles,
336 const indirectPrimitivePatch& pp,
339 pointField& patchDisp,
340 labelList& patchNLayers,
341 List<extrudeMode>& extrudeStatus
344 //- Count global number of extruded faces
345 static label countExtrusion
347 const indirectPrimitivePatch& pp,
348 const List<extrudeMode>& extrudeStatus
351 //- Collect layer faces and layer cells into bools
352 // for ease of handling
353 static void getLayerCellsFaces
356 const addPatchCellLayer&,
361 // Mesh shrinking (to create space for layers)
363 //- Average field (over all subset of mesh points) by
364 // summing contribution from edges. Global parallel since only
365 // does master edges for coupled edges.
367 static void averageNeighbours
369 const polyMesh& mesh,
370 const PackedBoolList& isMasterEdge,
371 const labelList& meshEdges,
372 const labelList& meshPoints,
373 const edgeList& edges,
374 const scalarField& invSumWeight,
375 const Field<Type>& data,
379 //- Calculate inverse sum of edge weights (currently always 1.0)
382 const PackedBoolList& isMasterEdge,
383 const labelList& meshEdges,
384 const labelList& meshPoints,
385 const edgeList& edges,
386 scalarField& invSumWeight
389 //- Smooth scalar field on patch
392 const motionSmoother& meshMover,
393 const PackedBoolList& isMasterEdge,
394 const labelList& meshEdges,
395 const scalarField& fieldMin,
396 const label nSmoothDisp,
400 //- Smooth normals on patch.
401 void smoothPatchNormals
403 const motionSmoother& meshMover,
404 const PackedBoolList& isMasterEdge,
405 const labelList& meshEdges,
406 const label nSmoothDisp,
410 //- Smooth normals in interior.
413 const label nSmoothDisp,
414 const PackedBoolList& isMasterEdge,
415 const labelList& fixedPoints,
416 pointVectorField& normals
421 const List<pointData>&,
426 //- Stop layer growth where mesh wraps around edge with a
427 // large feature angle
428 void handleFeatureAngleLayerTerminations
430 const indirectPrimitivePatch& pp,
432 List<extrudeMode>& extrudeStatus,
433 pointField& patchDisp,
434 labelList& patchNLayers,
438 //- Find isolated islands (points, edges and faces and
439 // layer terminations)
440 // in the layer mesh and stop any layer growth at these points.
441 void findIsolatedRegions
443 const indirectPrimitivePatch& pp,
444 const PackedBoolList& isMasterEdge,
445 const labelList& meshEdges,
446 const scalar minCosLayerTermination,
448 List<extrudeMode>& extrudeStatus,
449 pointField& patchDisp,
450 labelList& patchNLayers
453 // Calculate medial axis fields
454 void medialAxisSmoothingInfo
456 const motionSmoother& meshMover,
457 const label nSmoothNormals,
458 const label nSmoothSurfaceNormals,
459 const scalar minMedianAxisAngleCos,
461 pointVectorField& dispVec,
462 pointScalarField& medialRatio,
463 pointScalarField& medialDist
466 //- Main routine to shrink mesh
467 void shrinkMeshMedialDistance
469 motionSmoother& meshMover,
470 const dictionary& meshQualityDict,
471 const List<labelPair>& baffles,
472 const label nSmoothThickness,
473 const scalar maxThicknessToMedialRatio,
474 const label nAllowableErrors,
476 const scalar minCosLayerTermination,
478 const scalarField& layerThickness,
479 const scalarField& minThickness,
481 const pointVectorField& dispVec,
482 const pointScalarField& medialRatio,
483 const pointScalarField& medialDist,
485 List<extrudeMode>& extrudeStatus,
486 pointField& patchDisp,
487 labelList& patchNLayers
492 //- Disallow default bitwise copy construct
493 autoLayerDriver(const autoLayerDriver&);
495 //- Disallow default bitwise assignment
496 void operator=(const autoLayerDriver&);
501 //- Runtime type information
502 ClassName("autoLayerDriver");
506 //- Construct from components
509 meshRefinement& meshRefiner,
510 const labelList& globalToPatch
516 //- Merge patch faces on same cell.
517 void mergePatchFacesUndo
519 const layerParameters& layerParams,
520 const dictionary& motionDict
526 const layerParameters& layerParams,
527 const dictionary& motionDict,
528 const labelList& patchIDs,
529 const label nAllowableErrors,
530 decompositionMethod& decomposer,
531 fvMeshDistribute& distributor
534 //- Add layers according to the dictionary settings
537 const dictionary& shrinkDict,
538 const dictionary& motionDict,
539 const layerParameters& layerParams,
540 const bool preBalance, // balance before adding?
541 decompositionMethod& decomposer,
542 fvMeshDistribute& distributor
548 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
550 } // End namespace Foam
552 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
555 # include "autoLayerDriverTemplates.C"
558 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
562 // ************************************************************************* //