1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend 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 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
28 Utility class used to provide length-scale estimates at various
29 mesh locations. These estimates are based on specified boundary
30 conditions provided through dictionary entries.
34 University of Massachusetts Amherst
38 lengthScaleEstimator.C
39 lengthScaleEstimatorI.H
41 \*---------------------------------------------------------------------------*/
43 #ifndef lengthScaleEstimator_H
44 #define lengthScaleEstimator_H
48 #include "dictionary.H"
50 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
55 /*---------------------------------------------------------------------------*\
56 Class lengthScaleEstimator Declaration
57 \*---------------------------------------------------------------------------*/
59 class lengthScaleEstimator
63 //- Const reference to polyMesh
64 const polyMesh& mesh_;
66 //- Edge bisection/collapse criteria
70 scalar minLengthScale_;
71 scalar maxLengthScale_;
72 scalar curvatureDeviation_;
74 //- Specific to proximity-based refinement
76 boundBox proxBoundBox_;
77 labelListList proximityBins_;
79 //- Specific to mesh-slicing operations
80 scalar sliceThreshold_;
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
110 labelList noModPatchIDs_;
112 //- Typedefs for field refinement function pointers
113 typedef scalar (lengthScaleEstimator::*ScaleFn)(const scalar) const;
114 typedef Tuple2<const char*, ScaleFn> ScaleFnPair;
116 //- Field-based refinement
121 scalar lowerRefineLevel_;
122 scalar upperRefineLevel_;
124 //- Specify limits for refinement criteria
126 label maxRefineLevel_;
128 //- Function pointers for scale methods
129 static ScaleFnPair methods_[];
131 // Private Member Functions
133 // Check for legitimacy of patches
134 void checkPatches(const wordList& patchList) const;
136 // Prepare for proximity-based refinement, if necessary
137 void prepareProximityPatches();
139 // Perform spatial hashing on a set of points
140 static void spatialHash
142 const pointField& pointLocations,
143 const labelList& pointIndices,
145 const label resolution,
149 // Send length-scale info across processors
150 void writeLengthScaleInfo
152 const labelList& cellLevels,
153 const scalarList& lengthScale
156 // Receive length-scale info across processors
157 void readLengthScaleInfo
161 labelList& cellLevels,
162 UList<scalar>& lengthScale,
163 labelHashSet& levelCells
166 // Use a constant length scale for field-based refinement
167 scalar constantScale(const scalar fieldValue) const;
169 // Use a direct-proportion length scale for field-based refinement
170 scalar directScale(const scalar fieldValue) const;
172 // Use an inverse-proportion length scale for field-based refinement
173 scalar inverseScale(const scalar fieldValue) const;
177 // Declare the name of the class and its debug switch
179 TypeName("lengthScaleEstimator");
183 //- Construct from polyMesh and dictionary
184 explicit lengthScaleEstimator
191 virtual ~lengthScaleEstimator();
195 //- Read edge refinement options from the dictionary
196 void readRefinementOptions
198 const dictionary& refineDict,
200 bool mandatory = false
203 //- Set explicitly coupled patch information
204 void setCoupledPatches
206 const dictionary& coupledPatches
209 //- Calculate the length scale field
210 void calculateLengthScale(UList<scalar>& lengthScale);
212 //- Return refinement criteria
213 inline scalar ratioMin() const;
214 inline scalar ratioMax() const;
215 inline scalar growthFactor() const;
217 //- Limit length scale for surface-edges
218 inline void limitScale(scalar& scale) const;
220 //- Check if a particular patch is free-floating
221 // (i.e., gets its length-scale from the interior)
222 inline bool isFreePatch(const label pIndex) const;
224 //- Check if a particular patch is flagged
225 // for proximity-based refinement
226 inline bool isProximityPatch(const label pIndex) const;
228 //- Check if a particular patch is flagged
229 // for curvature-based refinement
230 inline bool isCurvaturePatch(const label pIndex) const;
232 //- Return reference curvature deviation
233 inline scalar curvatureDeviation() const
235 return curvatureDeviation_;
238 //- Check whether a particular point is too close
239 // to a previous mesh slice location
240 inline bool checkOldSlices(const vector& gCentre) const;
242 //- Add a boundBox to the existing set of sliceBoxes
243 inline void appendBox(const boundBox& bBox);
245 //- Clear the list of sliceBoxes
246 inline void clearBoxes();
248 //- Set an initial hold-off value
249 inline void setHoldOff(const label hVal)
251 sliceHoldOff_ = hVal;
254 //- Return the current holdOff value
255 inline label holdOff() const
257 return sliceHoldOff_;
260 //- Decrement the current holdOff value
261 inline void decrementHoldOff()
266 //- Check whether a particular patch permits refinement
267 inline bool checkRefinementPatch
272 //- Return the appropriate length-scale for boundary face
273 inline scalar fixedLengthScale
277 bool usePolyMesh = false
280 //- Test for proximity to patch faces
281 inline bool testProximity
283 const vector& gCentre,
284 const vector& gNormal,
285 const scalar testStep,
291 } // End namespace Foam
293 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
295 #include "lengthScaleEstimatorI.H"
297 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //