refinementParameters.C
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) 2015-2020,2022 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
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 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "refinementParameters.H"
30 #include "unitConversion.H"
31 #include "polyMesh.H"
32 #include "globalIndex.H"
33 #include "Tuple2.H"
34 #include "wallPolyPatch.H"
35 #include "meshRefinement.H"
36 
37 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
38 
39 Foam::refinementParameters::refinementParameters
40 (
41  const dictionary& dict,
42  const bool dryRun
43 )
44 :
45  maxGlobalCells_
46  (
47  meshRefinement::get<label>(dict, "maxGlobalCells", dryRun)
48  ),
49  maxLocalCells_
50  (
51  meshRefinement::get<label>(dict, "maxLocalCells", dryRun)
52  ),
53  minRefineCells_
54  (
55  meshRefinement::get<label>(dict, "minRefinementCells", dryRun)
56  ),
57  planarAngle_
58  (
59  dict.getOrDefault
60  (
61  "planarAngle",
62  dict.get<scalar>("resolveFeatureAngle")
63  )
64  ),
65  nBufferLayers_
66  (
67  meshRefinement::get<label>(dict, "nCellsBetweenLevels", dryRun)
68  ),
69  locationsOutsideMesh_
70  (
71  dict.getOrDefault
72  (
73  "locationsOutsideMesh",
74  pointField(0)
75  )
76  ),
77  useLeakClosure_(dict.getOrDefault<bool>("useLeakClosure", false)),
78  faceZoneControls_(dict.subOrEmptyDict("faceZoneControls")),
79  allowFreeStandingZoneFaces_
80  (
81  meshRefinement::get<bool>(dict, "allowFreeStandingZoneFaces", dryRun)
82  ),
83  useTopologicalSnapDetection_
84  (
85  dict.getOrDefault("useTopologicalSnapDetection", true)
86  ),
87  maxLoadUnbalance_(dict.getOrDefault<scalar>("maxLoadUnbalance", 0)),
88  handleSnapProblems_
89  (
90  dict.getOrDefault<Switch>("handleSnapProblems", true)
91  ),
92  interfaceRefine_
93  (
94  dict.getOrDefault<Switch>("interfaceRefine", true)
95  ),
96  nErodeCellZone_(dict.getOrDefault<label>("nCellZoneErodeIter", 0)),
97  nFilterIter_(dict.getOrDefault<label>("nFilterIter", 2)),
98  minCellFraction_(dict.getOrDefault<scalar>("minCellFraction", 0)),
99  nMinCells_(dict.getOrDefault<label>("nMinCells", 0)),
100  dryRun_(dryRun)
101 {
102  point locationInMesh;
103  List<Tuple2<point, word>> pointsToZone;
104  if (dict.readIfPresent("locationInMesh", locationInMesh))
105  {
106  locationsInMesh_.append(locationInMesh);
107  zonesInMesh_.append("none"); // special name for no cellZone
108 
109  if (dict.found("locationsInMesh"))
110  {
112  << "Cannot both specify 'locationInMesh' and 'locationsInMesh'"
113  << exit(FatalIOError);
114  }
115  }
116  else if (dict.readIfPresent("locationsInMesh", pointsToZone))
117  {
118  List<Tuple2<point, word>> pointsToZone(dict.lookup("locationsInMesh"));
119  label nZones = locationsInMesh_.size();
120  locationsInMesh_.setSize(nZones+pointsToZone.size());
121  zonesInMesh_.setSize(locationsInMesh_.size());
122 
123  forAll(pointsToZone, i)
124  {
125  locationsInMesh_[nZones] = pointsToZone[i].first();
126  zonesInMesh_[nZones] = pointsToZone[i].second();
127  if (zonesInMesh_[nZones] == word::null)
128  {
129  zonesInMesh_[nZones] = "none";
130  }
131  nZones++;
132  }
133  }
134  else
135  {
137  << "No 'locationInMesh' or 'locationsInMesh' provided"
138  << endl;
139  }
140 
141 
142  const scalar featAngle
143  (
144  meshRefinement::get<scalar>(dict, "resolveFeatureAngle", dryRun)
145  );
146 
147  if (featAngle < 0 || featAngle > 180)
148  {
149  curvature_ = -GREAT;
150  }
151  else
152  {
153  curvature_ = Foam::cos(degToRad(featAngle));
154  }
155 }
156 
157 
158 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
159 
161 (
162  const word& fzName,
164 ) const
165 {
166  dictionary patchInfo;
167  patchInfo.add("type", wallPolyPatch::typeName);
168  faceType = surfaceZonesInfo::INTERNAL;
169 
170  if (faceZoneControls_.found(fzName))
171  {
172  const dictionary& fzDict = faceZoneControls_.subDict(fzName);
173 
174  if (fzDict.found("patchInfo"))
175  {
176  patchInfo = fzDict.subDict("patchInfo");
177  }
178 
179  word faceTypeName;
180  if (fzDict.readIfPresent("faceType", faceTypeName))
181  {
182  faceType = surfaceZonesInfo::faceZoneTypeNames[faceTypeName];
183  }
184  }
185  return patchInfo;
186 }
187 
188 
190 (
191  polyMesh& mesh
192 ) const
193 {
194  labelList zoneIDs(zonesInMesh_.size(), -1);
195  forAll(zonesInMesh_, i)
196  {
197  if (zonesInMesh_[i] != word::null && zonesInMesh_[i] != "none")
198  {
200  (
201  zonesInMesh_[i], // name
202  labelList(0), // addressing
203  mesh
204  );
205  }
206  }
207  return zoneIDs;
208 }
209 
210 
212 (
213  const bool checkInsideMesh,
214  const polyMesh& mesh,
215  const pointField& locations
216 )
217 {
218  // Force calculation of tet-diag decomposition (for use in findCell)
219  (void)mesh.tetBasePtIs();
220 
221  // Global calculation engine
222  globalIndex globalCells(mesh.nCells());
223 
224  // Cell label per point
225  labelList cellLabels(locations.size());
226 
227  forAll(locations, i)
228  {
229  const point& location = locations[i];
230 
231  label localCellI = mesh.findCell(location, polyMesh::FACE_DIAG_TRIS);
232 
233  label globalCellI = -1;
234 
235  if (localCellI != -1)
236  {
237  globalCellI = globalCells.toGlobal(localCellI);
238  }
239 
240  reduce(globalCellI, maxOp<label>());
241 
242  if (checkInsideMesh && globalCellI == -1)
243  {
245  << "Point " << location
246  << " is not inside the mesh or on a face or edge." << nl
247  << "Bounding box of the mesh:" << mesh.bounds()
248  << exit(FatalError);
249  }
250 
251 
252  label procI = globalCells.whichProcID(globalCellI);
253  label procCellI = globalCells.toLocal(procI, globalCellI);
254 
255  Info<< "Found point " << location << " in cell " << procCellI
256  << " on processor " << procI << endl;
257 
258  if (globalCells.isLocal(globalCellI))
259  {
260  cellLabels[i] = localCellI;
261  }
262  else
263  {
264  cellLabels[i] = -1;
265  }
266  }
267  return cellLabels;
268 }
269 
270 
272 (
273  const wordList& zonesInMesh
274 )
275 {
276  DynamicList<label> indices(zonesInMesh.size());
277 
278  forAll(zonesInMesh, i)
279  {
280  if
281  (
282  zonesInMesh[i] != word::null
283  && zonesInMesh[i] != "none"
284  )
285  {
286  indices.append(i);
287  }
288  }
289  return indices;
290 }
291 
292 
294 (
295  const wordList& zonesInMesh
296 )
297 {
298  DynamicList<label> indices(0);
299 
300  forAll(zonesInMesh, i)
301  {
302  if
303  (
304  zonesInMesh[i] == word::null
305  || zonesInMesh[i] == "none"
306  )
307  {
308  indices.append(i);
309  }
310  }
311  return indices;
312 }
313 
314 
316 (
317  const pointField& locationsInMesh,
318  const wordList& zonesInMesh,
319  const pointField& locationsOutsideMesh
320 )
321 {
322  // Sort locations according to zone. Add outside as last element
323  DynamicList<pointField> allLocations(zonesInMesh.size()+1);
324  DynamicList<word> allZoneNames(allLocations.size());
325 
326  forAll(zonesInMesh, i)
327  {
328  const word name
329  (
330  zonesInMesh[i].empty()
331  ? "none"
332  : zonesInMesh[i]
333  );
334  const point& pt = locationsInMesh[i];
335 
336  const label index = allZoneNames.find(name);
337  if (index == -1)
338  {
339  allZoneNames.append(name);
340  allLocations.append(pointField(1, pt));
341  }
342  else
343  {
344  allLocations[index].append(pt);
345  }
346  }
347 
348  allZoneNames.append("outside");
349  allLocations.append(locationsOutsideMesh);
350 
351  return List<pointField>(std::move(allLocations));
352 }
353 
354 
355 // ************************************************************************* //
List< ReturnType > get(const UPtrList< T > &list, const AccessOp &aop)
List of values generated by applying the access operation to each list item.
dictionary dict
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:118
const labelIOList & zoneIDs
Definition: correctPhi.H:59
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:120
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:578
void append(const T &val)
Append an element at the end of the list.
Definition: List.H:491
const labelIOList & tetBasePtIs() const
Return the tetBasePtIs.
Definition: polyMesh.C:893
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:56
Unit conversion functions.
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:49
T & first()
Access first element of the list, position [0].
Definition: UList.H:798
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:487
A simple wrapper around bool so that it can be read as a word: true/false, on/off, yes/no, any/none. Also accepts 0/1 as a string and shortcuts t/f, y/n.
Definition: Switch.H:77
entry * add(entry *entryPtr, bool mergeEntry=false)
Add a new entry.
Definition: dictionary.C:637
static const Enum< faceZoneType > faceZoneTypeNames
dictionary getZoneInfo(const word &fzName, surfaceZonesInfo::faceZoneType &faceType) const
Get patchInfo and faceType for faceZone.
labelList addCellZonesToMesh(polyMesh &) const
Add cellZones to mesh. Return indices of cellZones (or -1)
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:413
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:38
void setSize(const label n)
Alias for resize()
Definition: List.H:289
dynamicFvMesh & mesh
dimensionedScalar cos(const dimensionedScalar &ds)
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:52
static labelList zonedLocations(const wordList &zonesInMesh)
Extract indices of named locations (so excludes &#39;keepPoints&#39;)
static const word null
An empty word.
Definition: word.H:84
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
Helper class which maintains intersections of (changing) mesh with (static) surfaces.
List< word > wordList
A List of words.
Definition: fileName.H:58
const boundBox & bounds() const
Return mesh bounding box.
Definition: polyMesh.H:592
vector point
Point is a vector.
Definition: point.H:37
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:607
label nCells() const noexcept
Number of mesh cells.
static labelList findCells(const bool checkInsideMesh, const polyMesh &, const pointField &locations)
Checks that cells are in mesh. Returns cells (or -1) they.
static List< pointField > zonePoints(const pointField &locationsInMesh, const wordList &zonesInMesh, const pointField &locationsOutsideMesh)
Helper: per zone (entry in zonesInMesh) the locations with.
void reduce(const List< UPstream::commsStruct > &comms, T &value, const BinaryOp &bop, const int tag, const label comm)
Reduce inplace (cf. MPI Allreduce) using specified communication schedule.
label findCell(const point &p, const cellDecomposition=CELL_TETS) const
Find cell enclosing this location and return index.
Definition: polyMesh.C:1505
messageStream Info
Information stream (stdout output on master, null elsewhere)
faceZoneType
What to do with faceZone faces.
#define IOWarningInFunction(ios)
Report an IO warning using Foam::Warning.
List< label > labelList
A List of labels.
Definition: List.H:62
static labelList unzonedLocations(const wordList &zonesInMesh)
Extract indices of unnamed locations (&#39;keepPoints&#39;)
constexpr scalar degToRad(const scalar deg) noexcept
Conversion from degrees to radians.
IOerror FatalIOError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL IO ERROR&#39; header text and ...
static label addCellZone(const word &name, const labelList &addressing, polyMesh &mesh)