snappyLayerDriver.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-2015 OpenFOAM Foundation
9 Copyright (C) 2017 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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
27Class
28 Foam::snappyLayerDriver
29
30Description
31 All to do with adding layers
32
33SourceFiles
34 snappyLayerDriver.C
35 snappyLayerDriverOneByOne.C
36
37\*---------------------------------------------------------------------------*/
38
39#ifndef snappyLayerDriver_H
40#define snappyLayerDriver_H
41
42#include "meshRefinement.H"
43#include "scalarIOField.H"
44
45// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46
47namespace Foam
48{
49
50// Forward declaration of classes
51class removePoints;
52class pointSet;
53class motionSmoother;
54class addPatchCellLayer;
55class faceSet;
56class layerParameters;
57class externalDisplacementMeshMover;
58
59/*---------------------------------------------------------------------------*\
60 Class snappyLayerDriver Declaration
61\*---------------------------------------------------------------------------*/
64{
65public:
66
67 // Public data types
68
69 //- Extrusion controls
70 enum extrudeMode
71 {
73 EXTRUDE,
76 };
77
78private:
79
80 // Private classes
81
82 //- Combine operator class to combine normal with other normal.
83 class nomalsCombine
84 {
85 public:
86
87 void operator()(vector& x, const vector& y) const
88 {
89 if (y != point::max)
90 {
91 if (x == point::max)
92 {
93 x = y;
94 }
95 else
96 {
97 x *= (x&y);
98 }
99 }
100 }
101 };
102
103
104 // Private data
105
106 //- Mesh+surface
107 meshRefinement& meshRefiner_;
108
109 //- From surface region to patch
110 const labelList globalToMasterPatch_;
111
112 //- From surface region to patch
113 const labelList globalToSlavePatch_;
114
115 //- Are we operating in test mode?
116 const bool dryRun_;
117
118
119 // Private Member Functions
120
121 // Layers
122
123 //- For debugging: Dump displacement to .obj files
124 static void dumpDisplacement
125 (
126 const fileName&,
128 const vectorField&,
129 const List<extrudeMode>&
130 );
131
132 //- Average point wise data to face wise
133 static tmp<scalarField> avgPointData
134 (
136 const scalarField& pointFld
137 );
138
139 //- Check that primitivePatch is not multiply connected.
140 // Collect non-manifold points in pointSet.
141 static void checkManifold
142 (
144 pointSet& nonManifoldPoints
145 );
146
147 //- Check that mesh outside is not multiply connected.
148 void checkMeshManifold() const;
149
150
151 // Static extrusion setup
152
153 //- Unset extrusion on point. Returns true if anything unset.
154 static bool unmarkExtrusion
155 (
156 const label patchPointi,
157 pointField& patchDisp,
158 labelList& patchNLayers,
159 List<extrudeMode>& extrudeStatus
160 );
161
162 //- Unset extrusion on face. Returns true if anything unset.
163 static bool unmarkExtrusion
164 (
165 const face& localFace,
166 pointField& patchDisp,
167 labelList& patchNLayers,
168 List<extrudeMode>& extrudeStatus
169 );
170
171 //- Truncate index in face
172 static label constrainFp(const label sz, const label fp);
173
174 //- Count common points between face and its neighbours
175 void countCommonPoints
176 (
178 const label facei,
179 Map<label>&
180 ) const;
181
182 //- Check if any common points form single string. Return
183 // false if not.
184 bool checkCommonOrder
185 (
186 const label nCommon,
187 const face& curFace,
188 const face& nbFace
189 ) const;
190
191 //- Check if any common points form single string; unmark
192 // points on face if not
193 void checkCommonOrder
194 (
195 const indirectPrimitivePatch& pp,
196 const label facei,
197 const Map<label>& nCommonPoints,
198 pointField& patchDisp,
199 labelList& patchNLayers,
200 List<extrudeMode>& extrudeStatus
201 ) const;
202
203 //- Check if any common points form single string; unmark
204 // points on face if not
205 void handleNonStringConnected
206 (
207 const indirectPrimitivePatch& pp,
208 pointField& patchDisp,
209 labelList& patchNLayers,
210 List<extrudeMode>& extrudeStatus
211 ) const;
212
213 //- No extrusion at non-manifold points.
214 void handleNonManifolds
215 (
216 const indirectPrimitivePatch& pp,
217 const labelList& meshEdges,
218 const labelListList& edgeGlobalFaces,
219 pointField& patchDisp,
220 labelList& patchNLayers,
221 List<extrudeMode>& extrudeStatus
222 ) const;
223
224 //- No extrusion on feature edges. Assumes non-manifold
225 // edges already handled.
226 void handleFeatureAngle
227 (
228 const indirectPrimitivePatch& pp,
229 const labelList& meshEdges,
230 const scalar minAngle,
231 pointField& patchDisp,
232 labelList& patchNLayers,
233 List<extrudeMode>& extrudeStatus
234 ) const;
235
236 //- No extrusion on warped faces
237 void handleWarpedFaces
238 (
239 const indirectPrimitivePatch& pp,
240 const scalar faceRatio,
241 const boolList& relativeSizes,
242 const scalar edge0Len,
243 const labelList& cellLevel,
244 pointField& patchDisp,
245 labelList& patchNLayers,
246 List<extrudeMode>& extrudeStatus
247 ) const;
248
249 //- Determine the number of layers per point from the number of
250 // layers per surface.
251 void setNumLayers
252 (
253 const labelList& patchToNLayers,
254 const labelList& patchIDs,
255 const indirectPrimitivePatch& pp,
256
257 labelList& patchNLayers,
258 List<extrudeMode>& extrudeStatus,
259 label& nIdealAddedCells
260 ) const;
261
262 //- Determine number of layers per point; include static checks
263 //- on invalid extrusion (e.g. non-manifold)
264 label setPointNumLayers
265 (
266 const layerParameters& layerParams,
267
268 const labelList& numLayers,
269 const labelList& patchIDs,
270 const indirectPrimitivePatch& pp,
271 const labelListList& edgeGlobalFaces,
272
273 vectorField& patchDisp,
274 labelList& patchNLayers,
275 List<extrudeMode>&
276 ) const;
277 autoPtr<externalDisplacementMeshMover> makeMeshMover
278 (
279 const layerParameters& layerParams,
280 const dictionary& motionDict,
281 const labelList& internalFaceZones,
282 const scalarIOField& minThickness,
283 pointVectorField& displacement
284 ) const;
285 void mapFaceZonePoints
286 (
287 const mapPolyMesh& map,
288 labelPairList& baffles,
289 labelList& pointToMaster
290 ) const;
291 void updatePatch
292 (
293 const labelList& patchIDs,
294 const mapPolyMesh& map,
295 autoPtr<indirectPrimitivePatch>& pp,
296 labelList& newToOldPatchPoints
297 ) const;
298
299
300 //- Helper function to make a pointVectorField with correct
301 // bcs for layer addition:
302 // - numLayers > 0 : fixedValue
303 // - numLayers == 0 : fixedValue (always zero)
304 // - processor : calculated (so free to move)
305 // - cyclic/wedge/symmetry : slip
306 // - other : slip
307 static tmp<pointVectorField> makeLayerDisplacementField
308 (
309 const pointMesh& pMesh,
310 const labelList& numLayers
311 );
312
313 //- Grow no-extrusion layer.
314 void growNoExtrusion
315 (
316 const indirectPrimitivePatch& pp,
317 pointField& patchDisp,
318 labelList& patchNLayers,
319 List<extrudeMode>& extrudeStatus
320 ) const;
321
322 //- Duplicate points on faceZones with layers
323 void dupFaceZonePoints
324 (
325 const labelList& patchIDs, // patch indices
326 const labelList& numLayers, // number of layers per patch
327 List<labelPair> baffles,
328 labelList& pointToMaster
329 );
330
331 //- Re-merge points/faces on faceZones. Opposite of
332 //- dupFaceZonePoints above
333 void mergeFaceZonePoints
334 (
335 const labelList& pointToMaster,
336 labelList& cellNLayers,
337 scalarField& faceRealThickness,
338 scalarField& faceWantedThickness
339 );
340
341 //- See what zones and patches edges should be extruded into
342 void determineSidePatches
343 (
344 const globalIndex& globalFaces,
345 const labelListList& edgeGlobalFaces,
346 const indirectPrimitivePatch& pp,
347
348 labelList& edgePatchID,
349 labelList& edgeZoneID,
350 boolList& edgeFlip,
351 labelList& inflateFaceID
352 );
353
354 //- Calculate pointwise wanted and minimum thickness.
355 // thickness: wanted thickness
356 // minthickness: when to give up and not extrude
357 // Gets per patch parameters and determine pp pointwise
358 // parameters.
359 void calculateLayerThickness
360 (
361 const indirectPrimitivePatch& pp,
362 const labelList& patchIDs,
363 const layerParameters& layerParams,
364 const labelList& cellLevel,
365 const labelList& patchNLayers,
366 const scalar edge0Len,
367
368 scalarField& thickness,
369 scalarField& minThickness,
370 scalarField& expansionRatio
371 ) const;
372
373
374 // Extrusion execution
375
376 //- Synchronize displacement among coupled patches.
377 void syncPatchDisplacement
378 (
379 const indirectPrimitivePatch& pp,
380 const scalarField& minThickness,
381 pointField& patchDisp,
382 labelList& patchNLayers,
383 List<extrudeMode>& extrudeStatus
384 ) const;
385
386 //- Get nearest point on surface to snap to
387 void getPatchDisplacement
388 (
389 const indirectPrimitivePatch& pp,
390 const scalarField& thickness,
391 const scalarField& minThickness,
392 const scalarField& expansionRatio,
393
394 pointField& patchDisp,
395 labelList& patchNLayers,
396 List<extrudeMode>& extrudeStatus
397 ) const;
398
399 //- For truncateDisplacement: find strings of edges
400 bool sameEdgeNeighbour
401 (
402 const labelListList& globalEdgeFaces,
403 const label myGlobalFacei,
404 const label nbrGlobFacei,
405 const label edgeI
406 ) const;
407
408 //- For truncateDisplacement: find strings of edges
409 void getVertexString
410 (
411 const indirectPrimitivePatch& pp,
412 const labelListList& globalEdgeFaces,
413 const label facei,
414 const label edgeI,
415 const label myGlobFacei,
416 const label nbrGlobFacei,
417 DynamicList<label>& vertices
418 ) const;
419
420 //- Truncates displacement
421 // - for all patchFaces in the faceset displacement gets set
422 // to zero
423 // - all displacement < minThickness gets set to zero
424 // - all non-consecutive extrusions get set to 0
425 label truncateDisplacement
426 (
427 const globalIndex& globalFaces,
428 const labelListList& edgeGlobalFaces,
429 const indirectPrimitivePatch& pp,
430 const scalarField& minThickness,
431 const faceSet& illegalPatchFaces,
432 pointField& patchDisp,
433 labelList& patchNLayers,
434 List<extrudeMode>& extrudeStatus
435 ) const;
436
437 //- Setup layer information (at points and faces) to
438 // modify mesh topology in
439 // regions where layer mesh terminates. Guarantees an
440 // optional slow decreasing of the number of layers.
441 // Returns the number of layers per face and per point
442 // to go into the actual layer addition engine.
443 void setupLayerInfoTruncation
444 (
445 const indirectPrimitivePatch& pp,
446 const labelList& patchNLayers,
447 const List<extrudeMode>& extrudeStatus,
448 const label nBufferCellsNoExtrude,
449 labelList& nPatchPointLayers,
450 labelList& nPatchFaceLayers
451 ) const;
452
453 //- Does any of the cells use a face from faces?
454 static bool cellsUseFace
455 (
456 const polyMesh& mesh,
457 const labelList& cellLabels,
458 const labelHashSet& faces
459 );
460
461 //- Checks the newly added cells and locally unmarks points
462 // so they will not get extruded next time round. Returns
463 // global number of unmarked points (0 if all was fine)
464 static label checkAndUnmark
465 (
466 const addPatchCellLayer& addLayer,
467 const dictionary& motionDict,
468 const bool additionalReporting,
469 const List<labelPair>& baffles,
470 const indirectPrimitivePatch& pp,
471 const fvMesh&,
472
473 pointField& patchDisp,
474 labelList& patchNLayers,
475 List<extrudeMode>& extrudeStatus
476 );
477
478 //- Count global number of extruded faces
479 static label countExtrusion
480 (
481 const indirectPrimitivePatch& pp,
482 const List<extrudeMode>& extrudeStatus
483 );
484
485 //- After adding to mesh get the new baffles
486 static List<labelPair> getBafflesOnAddedMesh
487 (
488 const polyMesh& mesh,
489 const labelList& newToOldFaces,
490 const List<labelPair>& baffles
491 );
492
493 //- Collect layer faces and layer cells into bools
494 // for ease of handling
495 static void getLayerCellsFaces
496 (
497 const polyMesh&,
498 const addPatchCellLayer&,
499 const scalarField& oldRealThickness,
500
501 labelList& cellStatus,
502 scalarField& faceRealThickness
503 );
504
505 //- Print layer coverage table
506 void printLayerData
507 (
508 const fvMesh& mesh,
509 const labelList& patchIDs,
510 const labelList& cellNLayers,
511 const scalarField& faceWantedThickness,
512 const scalarField& faceRealThickness
513 ) const;
514
515 //- Write cellSet,faceSet for layers
516 bool writeLayerSets
517 (
518 const fvMesh& mesh,
519 const labelList& cellNLayers,
520 const scalarField& faceRealThickness
521 ) const;
522
523 //- Write volFields,cellSet,faceSet for layers depending
524 // on write level
525 bool writeLayerData
526 (
527 const fvMesh& mesh,
528 const labelList& patchIDs,
529 const labelList& cellNLayers,
530 const scalarField& faceWantedThickness,
531 const scalarField& faceRealThickness
532 ) const;
533
534
535 // Mesh shrinking (to create space for layers)
536
537 //- Average field (over all subset of mesh points) by
538 // summing contribution from edges. Global parallel since only
539 // does master edges for coupled edges.
540 template<class Type>
541 static void averageNeighbours
542 (
543 const polyMesh& mesh,
544 const bitSet& isMasterEdge,
545 const labelList& meshEdges,
546 const labelList& meshPoints,
547 const edgeList& edges,
548 const scalarField& invSumWeight,
549 const Field<Type>& data,
550 Field<Type>& average
551 );
552
553 //- Calculate inverse sum of edge weights (currently always 1.0)
554 void sumWeights
555 (
556 const bitSet& isMasterEdge,
557 const labelList& meshEdges,
558 const labelList& meshPoints,
559 const edgeList& edges,
560 scalarField& invSumWeight
561 ) const;
562
563 //- Smooth scalar field on patch
564 void smoothField
565 (
566 const motionSmoother& meshMover,
567 const bitSet& isMasterPoint,
568 const bitSet& isMasterEdge,
569 const labelList& meshEdges,
570 const scalarField& fieldMin,
571 const label nSmoothDisp,
573 ) const;
574
575 //- Smooth normals on patch.
576 void smoothPatchNormals
577 (
578 const motionSmoother& meshMover,
579 const bitSet& isMasterPoint,
580 const bitSet& isMasterEdge,
581 const labelList& meshEdges,
582 const label nSmoothDisp,
583 pointField& normals
584 ) const;
585
586 //- Smooth normals in interior.
587 void smoothNormals
588 (
589 const label nSmoothDisp,
590 const bitSet& isMasterPoint,
591 const bitSet& isMasterEdge,
592 const labelList& fixedPoints,
593 pointVectorField& normals
594 ) const;
595
596 //- Stop layer growth where mesh wraps around edge with a
597 // large feature angle
598 void handleFeatureAngleLayerTerminations
599 (
600 const scalar minCos,
601 const bitSet& isMasterPoint,
602 const indirectPrimitivePatch& pp,
603 const labelList& meshEdges,
604
605 List<extrudeMode>& extrudeStatus,
606 pointField& patchDisp,
607 labelList& patchNLayers,
608 label& nPointCounter
609 ) const;
610
611 //- Find isolated islands (points, edges and faces and
612 // layer terminations)
613 // in the layer mesh and stop any layer growth at these points.
614 void findIsolatedRegions
615 (
616 const scalar minCosLayerTermination,
617 const bitSet& isMasterPoint,
618 const bitSet& isMasterEdge,
619 const indirectPrimitivePatch& pp,
620 const labelList& meshEdges,
621 const scalarField& minThickness,
622
623 List<extrudeMode>& extrudeStatus,
624 pointField& patchDisp,
625 labelList& patchNLayers
626 ) const;
627
628
629 //- No copy construct
630 snappyLayerDriver(const snappyLayerDriver&) = delete;
631
632 //- No copy assignment
633 void operator=(const snappyLayerDriver&) = delete;
634
635
636public:
637
638 //- Runtime type information
639 ClassName("snappyLayerDriver");
640
641 // Constructors
642
643 //- Construct from components
645 (
646 meshRefinement& meshRefiner,
647 const labelList& globalToMasterPatch,
648 const labelList& globalToSlavePatch,
649 const bool dryRun = false
650 );
651
652
653 // Member Functions
654
655 //- Merge patch faces on same cell.
657 (
658 const layerParameters& layerParams,
659 const dictionary& motionDict,
660 const meshRefinement::FaceMergeType mergeType
661 );
662
663 void addLayers
664 (
665 const layerParameters& layerParams,
666 const label nLayerIter,
667
668 const dictionary& motionDict,
669 const label nRelaxedIter,
670 const label nAllowableErrors,
671
672 const labelList& patchIDs,
673 const labelList& internalFaceZones,
674 const List<labelPair>& baffles,
675 const labelList& numLayers,
676 const label nIdealTotAddedCells,
677
678 const globalIndex& globalFaces,
680 const labelListList& edgeGlobalFaces,
681 const labelList& edgePatchID,
682 const labelList& edgeZoneID,
683 const boolList& edgeFlip,
684 const labelList& inflateFaceID,
685 const scalarField& thickness,
686 const scalarIOField& minThickness,
687 const scalarField& expansionRatio,
688 vectorField& patchDisp,
689 labelList& patchNLayers,
690 List<extrudeMode>& extrudeStatus,
691 polyTopoChange& savedMeshMod,
692 labelList& cellNLayers,
693 scalarField& faceRealThickness
694 );
695
696 //- Add cell layers
697 void addLayers
698 (
699 const layerParameters& layerParams,
700 const dictionary& motionDict,
701 const labelList& patchIDs,
702 const label nAllowableErrors,
703 decompositionMethod& decomposer,
704 fvMeshDistribute& distributor
705 );
706
707 //- For debugging. Can be removed.
709 (
710 const layerParameters& layerParams,
711 const dictionary& motionDict,
712 const labelList& patchIDs,
713 const label nAllowableErrors,
714 decompositionMethod& decomposer,
715 fvMeshDistribute& distributor
716 );
717
718 //- Add layers according to the dictionary settings
719 void doLayers
720 (
721 const dictionary& shrinkDict,
722 const dictionary& motionDict,
723 const layerParameters& layerParams,
724 const meshRefinement::FaceMergeType mergeType,
725 const bool preBalance, // balance before adding?
726 decompositionMethod& decomposer,
727 fvMeshDistribute& distributor
728 );
729};
730
731
732// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
733
734} // End namespace Foam
735
736// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
737
738#ifdef NoRepository
740#endif
741
742// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
743
744#endif
745
746// ************************************************************************* //
scalar y
A list of faces which address into the list of points.
Abstract base class for domain decomposition.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
Sends/receives parts of mesh+fvfields to neighbouring processors. Used in load balancing.
Calculates a unique integer (label so might not have enough room - 2G max) for processor + local inde...
Definition: globalIndex.H:68
Simple container to keep together layer specific information.
Helper class which maintains intersections of (changing) mesh with (static) surfaces.
FaceMergeType
Enumeration for what to do with co-planar patch faces on a single.
static const complex max
complex (VGREAT,VGREAT)
Definition: complex.H:293
Direct mesh changes based on v1.3 polyTopoChange syntax.
All to do with adding layers.
void addLayersSinglePass(const layerParameters &layerParams, const dictionary &motionDict, const labelList &patchIDs, const label nAllowableErrors, decompositionMethod &decomposer, fvMeshDistribute &distributor)
For debugging. Can be removed.
void addLayers(const layerParameters &layerParams, const label nLayerIter, const dictionary &motionDict, const label nRelaxedIter, const label nAllowableErrors, const labelList &patchIDs, const labelList &internalFaceZones, const List< labelPair > &baffles, const labelList &numLayers, const label nIdealTotAddedCells, const globalIndex &globalFaces, indirectPrimitivePatch &pp, const labelListList &edgeGlobalFaces, const labelList &edgePatchID, const labelList &edgeZoneID, const boolList &edgeFlip, const labelList &inflateFaceID, const scalarField &thickness, const scalarIOField &minThickness, const scalarField &expansionRatio, vectorField &patchDisp, labelList &patchNLayers, List< extrudeMode > &extrudeStatus, polyTopoChange &savedMeshMod, labelList &cellNLayers, scalarField &faceRealThickness)
void mergePatchFacesUndo(const layerParameters &layerParams, const dictionary &motionDict, const meshRefinement::FaceMergeType mergeType)
Merge patch faces on same cell.
void doLayers(const dictionary &shrinkDict, const dictionary &motionDict, const layerParameters &layerParams, const meshRefinement::FaceMergeType mergeType, const bool preBalance, decompositionMethod &decomposer, fvMeshDistribute &distributor)
Add layers according to the dictionary settings.
ClassName("snappyLayerDriver")
Runtime type information.
extrudeMode
Extrusion controls.
@ NOEXTRUDE
Do not extrude. No layers added.
#define ClassName(TypeNameString)
Add typeName information from argument TypeNameString to a class.
Definition: className.H:67
rDeltaTY field()
dynamicFvMesh & mesh
Namespace for OpenFOAM.
List< labelPair > labelPairList
List of labelPairs.
Definition: labelPair.H:64
List< label > labelList
A List of labels.
Definition: List.H:66
IOField< scalar > scalarIOField
scalarField with IO.
Definition: scalarIOField.H:44
GeometricField< vector, pointPatchField, pointMesh > pointVectorField
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:44
dimensioned< Type > average(const DimensionedField< Type, GeoMesh > &df)
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:56
pointField vertices(const blockVertexList &bvl)
Field< vector > vectorField
Specialisation of Field<T> for vector.
List< bool > boolList
A List of bools.
Definition: List.H:64
HashSet< label, Hash< label > > labelHashSet
A HashSet of labels, uses label hasher.
Definition: HashSet.H:85
List< edge > edgeList
A List of edges.
Definition: edgeList.H:63
PrimitivePatch< IndirectList< face >, const pointField & > indirectPrimitivePatch
A PrimitivePatch with an IndirectList for the faces, const reference for the point field.