Merge remote-tracking branch 'origin/nr/multiSolverFix' into nextRelease
[foam-extend-3.2.git] / src / dynamicMesh / dynamicFvMesh / dynamicTopoFvMesh / lengthScaleEstimator / lengthScaleEstimator.H
blob92f1a2a0bf1823a7cd2d2d46f4f7baf7dedd1ea8
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright held by original author
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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
25 Class
26     lengthScaleEstimator
28 Description
29     Utility class used to provide length-scale estimates at various
30     mesh locations. These estimates are based on specified boundary
31     conditions provided through dictionary entries.
33 Author
34     Sandeep Menon
35     University of Massachusetts Amherst
36     All rights reserved
38 SourceFiles
39     lengthScaleEstimator.C
40     lengthScaleEstimatorI.H
42 \*---------------------------------------------------------------------------*/
44 #ifndef lengthScaleEstimator_H
45 #define lengthScaleEstimator_H
47 #include "polyMesh.H"
48 #include "dictionary.H"
50 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
52 namespace Foam
55 /*---------------------------------------------------------------------------*\
56                       Class lengthScaleEstimator Declaration
57 \*---------------------------------------------------------------------------*/
59 class lengthScaleEstimator
61     // Private data
63         //- Const reference to polyMesh
64         const polyMesh& mesh_;
66         //- Edge bisection/collapse criteria
67         scalar ratioMin_;
68         scalar ratioMax_;
69         scalar growthFactor_;
70         scalar minLengthScale_;
71         scalar maxLengthScale_;
72         scalar curvatureDeviation_;
74         //- Specific to proximity-based refinement
75         label spatialRes_;
76         boundBox proxBoundBox_;
77         labelListList proximityBins_;
79         //- Specific to mesh-slicing operations
80         scalar sliceThreshold_;
81         label sliceHoldOff_;
82         List<boundBox> sliceBoxes_;
84         // Buffers for parallel length-scale calculations
85         labelListList sendLblBuffer_;
86         labelListList recvLblBuffer_;
87         labelListList sendLvlBuffer_;
88         labelListList recvLvlBuffer_;
89         scalarListList sendSclBuffer_;
90         scalarListList recvSclBuffer_;
92         //- Sub-dictionary which specifies
93         //  fixed length-scales for patches
94         dictionary fixedPatches_;
96         //- Sub-dictionary which specifies
97         //  floating length-scales for patches
98         dictionary freePatches_;
100         //- Sub-dictionary which specifies
101         //  patches with curvature-based length-scale
102         dictionary curvaturePatches_;
104         //- Sub-dictionary which specifies
105         //  patches with proximity-based length-scale
106         dictionary proximityPatches_;
108         //- Patches for which edge-refinements
109         //  are to be avoided
110         labelList noModPatchIDs_;
112         //- Field-based refinement
113         word field_;
114         scalar fieldLength_;
115         scalar lowerRefineLevel_;
116         scalar upperRefineLevel_;
118         //- Specify limits for refinement criteria
119         scalar meanScale_;
120         label maxRefineLevel_;
122     // Private Member Functions
124         // Check for legitimacy of patches
125         void checkPatches(const wordList& patchList) const;
127         // Prepare for proximity-based refinement, if necessary
128         void prepareProximityPatches();
130         // Perform spatial hashing on a set of points
131         static void spatialHash
132         (
133             const pointField& pointLocations,
134             const labelList& pointIndices,
135             const boundBox& box,
136             const label resolution,
137             labelListList& bins
138         );
140         // Send length-scale info across processors
141         void writeLengthScaleInfo
142         (
143             const labelList& cellLevels,
144             const scalarList& lengthScale
145         );
147         // Receive length-scale info across processors
148         void readLengthScaleInfo
149         (
150             const label level,
151             label& visitedCells,
152             labelList& cellLevels,
153             UList<scalar>& lengthScale,
154             labelHashSet& levelCells
155         ) const;
157 public:
159     // Declare the name of the class and its debug switch
160         TypeName("lengthScaleEstimator");
162     // Constructors
164         //- Construct from polyMesh and dictionary
165         explicit lengthScaleEstimator
166         (
167             const polyMesh& mesh
168         );
170     // Destructor
172         virtual ~lengthScaleEstimator();
174     // Member Functions
176         //- Read edge refinement options from the dictionary
177         void readRefinementOptions
178         (
179             const dictionary& refineDict,
180             bool reRead = false,
181             bool mandatory = false
182         );
184         //- Set explicitly coupled patch information
185         void setCoupledPatches
186         (
187             const dictionary& coupledPatches
188         );
190         //- Calculate the length scale field
191         void calculateLengthScale(UList<scalar>& lengthScale);
193         //- Return refinement criteria
194         inline scalar ratioMin() const;
195         inline scalar ratioMax() const;
196         inline scalar growthFactor() const;
198         //- Limit length scale for surface-edges
199         inline void limitScale(scalar& scale) const;
201         //- Check if a particular patch is free-floating
202         //  (i.e., gets its length-scale from the interior)
203         inline bool isFreePatch(const label pIndex) const;
205         //- Check if a particular patch is flagged
206         //  for proximity-based refinement
207         inline bool isProximityPatch(const label pIndex) const;
209         //- Check if a particular patch is flagged
210         //  for curvature-based refinement
211         inline bool isCurvaturePatch(const label pIndex) const;
213         //- Return reference curvature deviation
214         inline scalar curvatureDeviation() const
215         {
216             return curvatureDeviation_;
217         }
219         //- Check whether a particular point is too close
220         //  to a previous mesh slice location
221         inline bool checkOldSlices(const vector& gCentre) const;
223         //- Add a boundBox to the existing set of sliceBoxes
224         inline void appendBox(const boundBox& bBox);
226         //- Clear the list of sliceBoxes
227         inline void clearBoxes();
229         //- Set an initial hold-off value
230         inline void setHoldOff(const label hVal)
231         {
232             sliceHoldOff_ = hVal;
233         }
235         //- Return the current holdOff value
236         inline label holdOff() const
237         {
238             return sliceHoldOff_;
239         }
241         //- Decrement the current holdOff value
242         inline void decrementHoldOff()
243         {
244             sliceHoldOff_--;
245         }
247         //- Check whether a particular patch permits refinement
248         inline bool checkRefinementPatch
249         (
250             const label pIndex
251         ) const;
253         //- Return the appropriate length-scale for boundary face
254         inline scalar fixedLengthScale
255         (
256             const label fIndex,
257             const label pIndex,
258             bool usePolyMesh = false
259         ) const;
261         //- Test for proximity to patch faces
262         inline bool testProximity
263         (
264             const vector& gCentre,
265             const vector& gNormal,
266             const scalar testStep,
267             label& proxFace,
268             scalar& proxDistance
269         ) const;
272 } // End namespace Foam
274 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
276 #include "lengthScaleEstimatorI.H"
278 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
280 #endif