1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 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, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 All to do with adding layers
34 \*---------------------------------------------------------------------------*/
36 #ifndef autoLayerDriver_H
37 #define autoLayerDriver_H
39 #include <autoMesh/meshRefinement.H>
40 #include <meshTools/wallPoint.H>
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 // Forward declaration of classes
51 class addPatchCellLayer;
55 class layerParameters;
57 /*---------------------------------------------------------------------------*\
58 Class autoLayerDriver Declaration
59 \*---------------------------------------------------------------------------*/
63 // Static data members
65 //- Extrusion controls
68 NOEXTRUDE, /*!< Do not extrude. No layers added. */
69 EXTRUDE, /*!< Extrude */
70 EXTRUDEREMOVE /*!< Extrude but afterwards remove added */
77 //- Combine operator class to combine normal with other normal.
82 void operator()(vector& x, const vector& y) const
84 if (y != wallPoint::greatPoint)
86 if (x == wallPoint::greatPoint)
102 meshRefinement& meshRefiner_;
106 // Private Member Functions
111 //- Merge patch faces. Undo until no checkMesh errors.
112 label mergePatchFacesUndo
115 const scalar concaveCos,
120 autoPtr<mapPolyMesh> doRemovePoints
122 removePoints& pointRemover,
123 const boolList& pointCanBeDeleted
126 //- Restore faces (which contain removed points)
127 autoPtr<mapPolyMesh> doRestorePoints
129 removePoints& pointRemover,
130 const labelList& facesToRestore
133 //- Return candidateFaces that are also in set.
134 labelList collectFaces
136 const labelList& candidateFaces,
137 const labelHashSet& set
140 //- Pick up faces of cells of faces in set.
141 labelList growFaceCellFace(const labelHashSet&) const;
143 //- Remove points not used by any face or points used by only
144 // two faces where the edges are in line
145 label mergeEdgesUndo(const scalar minCos, const dictionary&);
150 //- For debugging: Dump displacement to .obj files
151 static void dumpDisplacement
154 const indirectPrimitivePatch&,
156 const List<extrudeMode>&
159 //- Check that primitivePatch is not multiply connected.
160 // Collect non-manifold points in pointSet.
161 static void checkManifold
163 const indirectPrimitivePatch&,
164 pointSet& nonManifoldPoints
167 //- Check that mesh outside is not multiply connected.
168 void checkMeshManifold() const;
171 // Static extrusion setup
173 //- Unset extrusion on point. Returns true if anything unset.
174 static bool unmarkExtrusion
176 const label patchPointI,
177 pointField& patchDisp,
178 labelList& patchNLayers,
179 List<extrudeMode>& extrudeStatus
182 //- Unset extrusion on face. Returns true if anything unset.
183 static bool unmarkExtrusion
185 const face& localFace,
186 pointField& patchDisp,
187 labelList& patchNLayers,
188 List<extrudeMode>& extrudeStatus
191 //- No extrusion at non-manifold points.
192 void handleNonManifolds
194 const indirectPrimitivePatch& pp,
195 const labelList& meshEdges,
196 pointField& patchDisp,
197 labelList& patchNLayers,
198 List<extrudeMode>& extrudeStatus
201 //- No extrusion on feature edges. Assumes non-manifold
202 // edges already handled.
203 void handleFeatureAngle
205 const indirectPrimitivePatch& pp,
206 const labelList& meshEdges,
208 pointField& patchDisp,
209 labelList& patchNLayers,
210 List<extrudeMode>& extrudeStatus
213 //- No extrusion on warped faces
214 void handleWarpedFaces
216 const indirectPrimitivePatch& pp,
217 const scalar faceRatio,
218 const scalar edge0Len,
219 const labelList& cellLevel,
220 pointField& patchDisp,
221 labelList& patchNLayers,
222 List<extrudeMode>& extrudeStatus
225 //- Determine the number of layers per point from the number of
226 // layers per surface.
229 const labelList& patchToNLayers,
230 const labelList& patchIDs,
231 const indirectPrimitivePatch& pp,
232 pointField& patchDisp,
233 labelList& patchNLayers,
234 List<extrudeMode>& extrudeStatus
237 //- Grow no-extrusion layer.
238 static void growNoExtrusion
240 const indirectPrimitivePatch& pp,
241 pointField& patchDisp,
242 labelList& patchNLayers,
243 List<extrudeMode>& extrudeStatus
246 //- Calculate pointwise wanted and minimum thickness.
247 // thickness: wanted thickness
248 // minthickness: when to give up and not extrude
249 // Gets per patch parameters and determine pp pointwise
251 void calculateLayerThickness
253 const indirectPrimitivePatch& pp,
254 const labelList& patchIDs,
256 const scalarField& patchExpansionRatio,
257 const bool relativeSizes,
258 const scalarField& patchFinalLayerThickness,
259 const scalarField& patchMinThickness,
261 const labelList& cellLevel,
262 const labelList& patchNLayers,
263 const scalar edge0Len,
265 scalarField& thickness,
266 scalarField& minThickness,
267 scalarField& expansionRatio
271 // Extrusion execution
273 //- Synchronize displacement among coupled patches.
274 void syncPatchDisplacement
276 const motionSmoother& meshMover,
277 const scalarField& minThickness,
278 pointField& patchDisp,
279 labelList& patchNLayers,
280 List<extrudeMode>& extrudeStatus
283 //- Get nearest point on surface to snap to
284 void getPatchDisplacement
286 const motionSmoother& meshMover,
287 const scalarField& thickness,
288 const scalarField& minThickness,
289 pointField& patchDisp,
290 labelList& patchNLayers,
291 List<extrudeMode>& extrudeStatus
294 //- Truncates displacement
295 // - for all patchFaces in the faceset displacement gets set
297 // - all displacement < minThickness gets set to zero
298 label truncateDisplacement
300 const motionSmoother& meshMover,
301 const scalarField& minThickness,
302 const faceSet& illegalPatchFaces,
303 pointField& patchDisp,
304 labelList& patchNLayers,
305 List<extrudeMode>& extrudeStatus
308 //- Setup layer information (at points and faces) to
309 // modify mesh topology in
310 // regions where layer mesh terminates. Guarantees an
311 // optional slow decreasing of the number of layers.
312 // Returns the number of layers per face and per point
313 // to go into the actual layer addition engine.
314 void setupLayerInfoTruncation
316 const motionSmoother& meshMover,
317 const labelList& patchNLayers,
318 const List<extrudeMode>& extrudeStatus,
319 const label nBufferCellsNoExtrude,
320 labelList& nPatchPointLayers,
321 labelList& nPatchFaceLayers
324 //- Does any of the cells use a face from faces?
325 static bool cellsUseFace
327 const polyMesh& mesh,
328 const labelList& cellLabels,
329 const labelHashSet& faces
332 //- Checks the newly added cells and locally unmarks points
333 // so they will not get extruded next time round. Returns
334 // global number of unmarked points (0 if all was fine)
335 static label checkAndUnmark
337 const addPatchCellLayer& addLayer,
338 const dictionary& motionDict,
339 const indirectPrimitivePatch& pp,
342 pointField& patchDisp,
343 labelList& patchNLayers,
344 List<extrudeMode>& extrudeStatus
347 //- Count global number of extruded faces
348 static label countExtrusion
350 const indirectPrimitivePatch& pp,
351 const List<extrudeMode>& extrudeStatus
354 //- Collect layer faces and layer cells into bools
355 // for ease of handling
356 static void getLayerCellsFaces
359 const addPatchCellLayer&,
364 // Mesh shrinking (to create space for layers)
366 //- Average field (over all subset of mesh points) by
367 // summing contribution from edges. Global parallel since only
368 // does master edges for coupled edges.
370 static void averageNeighbours
372 const polyMesh& mesh,
373 const PackedBoolList& isMasterEdge,
374 const labelList& meshEdges,
375 const labelList& meshPoints,
376 const edgeList& edges,
377 const scalarField& invSumWeight,
378 const Field<Type>& data,
382 //- Calculate inverse sum of edge weights (currently always 1.0)
385 const PackedBoolList& isMasterEdge,
386 const labelList& meshEdges,
387 const labelList& meshPoints,
388 const edgeList& edges,
389 scalarField& invSumWeight
392 //- Smooth scalar field on patch
395 const motionSmoother& meshMover,
396 const PackedBoolList& isMasterEdge,
397 const labelList& meshEdges,
398 const scalarField& fieldMin,
399 const label& nSmoothDisp,
403 //- Smooth normals on patch.
404 void smoothPatchNormals
406 const motionSmoother& meshMover,
407 const PackedBoolList& isMasterEdge,
408 const labelList& meshEdges,
409 const label nSmoothDisp,
413 //- Smooth normals in interior.
416 const label nSmoothDisp,
417 const PackedBoolList& isMasterEdge,
418 const labelList& fixedPoints,
419 pointVectorField& normals
424 const List<pointData>&,
429 //- Stop layer growth where mesh wraps around edge with a
430 // large feature angle
431 void handleFeatureAngleLayerTerminations
433 const indirectPrimitivePatch& pp,
435 List<extrudeMode>& extrudeStatus,
436 pointField& patchDisp,
437 labelList& patchNLayers,
441 //- Find isolated islands (points, edges and faces and
442 // layer terminations)
443 // in the layer mesh and stop any layer growth at these points.
444 void findIsolatedRegions
446 const indirectPrimitivePatch& pp,
447 const PackedBoolList& isMasterEdge,
448 const labelList& meshEdges,
449 const scalar minCosLayerTermination,
451 List<extrudeMode>& extrudeStatus,
452 pointField& patchDisp,
453 labelList& patchNLayers
456 // Calculate medial axis fields
457 void medialAxisSmoothingInfo
459 const motionSmoother& meshMover,
460 const label nSmoothNormals,
461 const label nSmoothSurfaceNormals,
462 const scalar minMedianAxisAngleCos,
464 pointVectorField& dispVec,
465 pointScalarField& medialRatio,
466 pointScalarField& medialDist
469 //- Main routine to shrink mesh
470 void shrinkMeshMedialDistance
472 motionSmoother& meshMover,
473 const dictionary& meshQualityDict,
474 const label nSmoothThickness,
475 const scalar maxThicknessToMedialRatio,
476 const label nAllowableErrors,
478 const scalar minCosLayerTermination,
480 const scalarField& layerThickness,
481 const scalarField& minThickness,
483 const pointVectorField& dispVec,
484 const pointScalarField& medialRatio,
485 const pointScalarField& medialDist,
487 List<extrudeMode>& extrudeStatus,
488 pointField& patchDisp,
489 labelList& patchNLayers
494 //- Disallow default bitwise copy construct
495 autoLayerDriver(const autoLayerDriver&);
497 //- Disallow default bitwise assignment
498 void operator=(const autoLayerDriver&);
503 //- Runtime type information
504 ClassName("autoLayerDriver");
508 //- Construct from components
509 autoLayerDriver(meshRefinement& meshRefiner);
514 //- Merge patch faces on same cell.
515 void mergePatchFacesUndo
517 const layerParameters& layerParams,
518 const dictionary& motionDict
524 const layerParameters& layerParams,
525 const dictionary& motionDict,
526 const label nAllowableErrors,
527 motionSmoother& meshMover,
528 decompositionMethod& decomposer,
529 fvMeshDistribute& distributor
532 //- Add layers according to the dictionary settings
535 const dictionary& shrinkDict,
536 const dictionary& motionDict,
537 const layerParameters& layerParams,
538 decompositionMethod& decomposer,
539 fvMeshDistribute& distributor
545 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
547 } // End namespace Foam
549 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
552 # include <autoMesh/autoLayerDriverTemplates.C>
555 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
559 // ************************ vim: set sw=4 sts=4 et: ************************ //