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 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  faceZoneControls_(dict.subOrEmptyDict("faceZoneControls")),
78  allowFreeStandingZoneFaces_
79  (
80  meshRefinement::get<bool>(dict, "allowFreeStandingZoneFaces", dryRun)
81  ),
82  useTopologicalSnapDetection_
83  (
84  dict.getOrDefault("useTopologicalSnapDetection", true)
85  ),
86  maxLoadUnbalance_(dict.getOrDefault<scalar>("maxLoadUnbalance", 0)),
87  handleSnapProblems_
88  (
89  dict.getOrDefault<Switch>("handleSnapProblems", true)
90  ),
91  interfaceRefine_
92  (
93  dict.getOrDefault<Switch>("interfaceRefine", true)
94  ),
95  nErodeCellZone_(dict.getOrDefault<label>("nCellZoneErodeIter", 0)),
96  nFilterIter_(dict.getOrDefault<label>("nFilterIter", 2)),
97  minCellFraction_(dict.getOrDefault<scalar>("minCellFraction", 0)),
98  dryRun_(dryRun)
99 {
100  point locationInMesh;
101  List<Tuple2<point, word>> pointsToZone;
102  if (dict.readIfPresent("locationInMesh", locationInMesh))
103  {
104  locationsInMesh_.append(locationInMesh);
105  zonesInMesh_.append("none"); // special name for no cellZone
106 
107  if (dict.found("locationsInMesh"))
108  {
110  << "Cannot both specify 'locationInMesh' and 'locationsInMesh'"
111  << exit(FatalIOError);
112  }
113  }
114  else if (dict.readIfPresent("locationsInMesh", pointsToZone))
115  {
116  List<Tuple2<point, word>> pointsToZone(dict.lookup("locationsInMesh"));
117  label nZones = locationsInMesh_.size();
118  locationsInMesh_.setSize(nZones+pointsToZone.size());
119  zonesInMesh_.setSize(locationsInMesh_.size());
120 
121  forAll(pointsToZone, i)
122  {
123  locationsInMesh_[nZones] = pointsToZone[i].first();
124  zonesInMesh_[nZones] = pointsToZone[i].second();
125  if (zonesInMesh_[nZones] == word::null)
126  {
127  zonesInMesh_[nZones] = "none";
128  }
129  nZones++;
130  }
131  }
132  else
133  {
135  << "No 'locationInMesh' or 'locationsInMesh' provided"
136  << endl;
137  }
138 
139 
140  const scalar featAngle
141  (
142  meshRefinement::get<scalar>(dict, "resolveFeatureAngle", dryRun)
143  );
144 
145  if (featAngle < 0 || featAngle > 180)
146  {
147  curvature_ = -GREAT;
148  }
149  else
150  {
151  curvature_ = Foam::cos(degToRad(featAngle));
152  }
153 }
154 
155 
156 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
157 
159 (
160  const word& fzName,
162 ) const
163 {
164  dictionary patchInfo;
165  patchInfo.add("type", wallPolyPatch::typeName);
166  faceType = surfaceZonesInfo::INTERNAL;
167 
168  if (faceZoneControls_.found(fzName))
169  {
170  const dictionary& fzDict = faceZoneControls_.subDict(fzName);
171 
172  if (fzDict.found("patchInfo"))
173  {
174  patchInfo = fzDict.subDict("patchInfo");
175  }
176 
177  word faceTypeName;
178  if (fzDict.readIfPresent("faceType", faceTypeName))
179  {
180  faceType = surfaceZonesInfo::faceZoneTypeNames[faceTypeName];
181  }
182  }
183  return patchInfo;
184 }
185 
186 
188 (
189  polyMesh& mesh
190 ) const
191 {
192  labelList zoneIDs(zonesInMesh_.size(), -1);
193  forAll(zonesInMesh_, i)
194  {
195  if (zonesInMesh_[i] != word::null && zonesInMesh_[i] != "none")
196  {
197  zoneIDs[i] = surfaceZonesInfo::addCellZone
198  (
199  zonesInMesh_[i], // name
200  labelList(0), // addressing
201  mesh
202  );
203  }
204  }
205  return zoneIDs;
206 }
207 
208 
210 (
211  const bool checkInsideMesh,
212  const polyMesh& mesh,
213  const pointField& locations
214 )
215 {
216  // Force calculation of tet-diag decomposition (for use in findCell)
217  (void)mesh.tetBasePtIs();
218 
219  // Global calculation engine
220  globalIndex globalCells(mesh.nCells());
221 
222  // Cell label per point
223  labelList cellLabels(locations.size());
224 
225  forAll(locations, i)
226  {
227  const point& location = locations[i];
228 
229  label localCellI = mesh.findCell(location, polyMesh::FACE_DIAG_TRIS);
230 
231  label globalCellI = -1;
232 
233  if (localCellI != -1)
234  {
235  globalCellI = globalCells.toGlobal(localCellI);
236  }
237 
238  reduce(globalCellI, maxOp<label>());
239 
240  if (checkInsideMesh && globalCellI == -1)
241  {
243  << "Point " << location
244  << " is not inside the mesh or on a face or edge." << nl
245  << "Bounding box of the mesh:" << mesh.bounds()
246  << exit(FatalError);
247  }
248 
249 
250  label procI = globalCells.whichProcID(globalCellI);
251  label procCellI = globalCells.toLocal(procI, globalCellI);
252 
253  Info<< "Found point " << location << " in cell " << procCellI
254  << " on processor " << procI << endl;
255 
256  if (globalCells.isLocal(globalCellI))
257  {
258  cellLabels[i] = localCellI;
259  }
260  else
261  {
262  cellLabels[i] = -1;
263  }
264  }
265  return cellLabels;
266 }
267 
268 
270 (
271  const wordList& zonesInMesh
272 )
273 {
274  DynamicList<label> indices(zonesInMesh.size());
275 
276  forAll(zonesInMesh, i)
277  {
278  if
279  (
280  zonesInMesh[i] != word::null
281  && zonesInMesh[i] != "none"
282  )
283  {
284  indices.append(i);
285  }
286  }
287  return indices;
288 }
289 
290 
292 (
293  const wordList& zonesInMesh
294 )
295 {
296  DynamicList<label> indices(0);
297 
298  forAll(zonesInMesh, i)
299  {
300  if
301  (
302  zonesInMesh[i] == word::null
303  || zonesInMesh[i] == "none"
304  )
305  {
306  indices.append(i);
307  }
308  }
309  return indices;
310 }
311 
312 
313 // ************************************************************************* //
nZones
label nZones
Definition: interpolatedFaces.H:24
Foam::refinementParameters::zonedLocations
static labelList zonedLocations(const wordList &zonesInMesh)
Extract indices of named locations (so excludes 'keepPoints')
Definition: refinementParameters.C:270
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:67
Foam::maxOp
Definition: ops.H:223
Foam::Switch
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
Definition: Switch.H:77
Foam::surfaceZonesInfo::faceZoneType
faceZoneType
What to do with faceZone faces.
Definition: surfaceZonesInfo.H:86
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Tuple2.H
Foam::DynamicList< label >
Foam::dictionary::found
bool found(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Search for an entry (const access) with the given keyword.
Definition: dictionaryI.H:87
globalIndex.H
wallPolyPatch.H
unitConversion.H
Unit conversion functions.
Foam::refinementParameters::findCells
static labelList findCells(const bool checkInsideMesh, const polyMesh &, const pointField &locations)
Checks that cells are in mesh. Returns cells (or -1) they.
Definition: refinementParameters.C:210
Foam::List::append
void append(const T &val)
Append an element at the end of the list.
Definition: ListI.H:175
Foam::FatalIOError
IOerror FatalIOError
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
polyMesh.H
zoneIDs
const labelIOList & zoneIDs
Definition: correctPhi.H:59
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::Field< vector >
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
Foam::refinementParameters::unzonedLocations
static labelList unzonedLocations(const wordList &zonesInMesh)
Extract indices of unnamed locations ('keepPoints')
Definition: refinementParameters.C:292
Foam::DynamicList::append
DynamicList< T, SizeMin > & append(const T &val)
Append an element to the end of this list.
Definition: DynamicListI.H:511
Foam::dictionary::subDict
const dictionary & subDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary.
Definition: dictionary.C:460
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
reduce
reduce(hasMovingMesh, orOp< bool >())
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
meshRefinement.H
Foam::globalIndex
Calculates a unique integer (label so might not have enough room - 2G max) for processor + local inde...
Definition: globalIndex.H:68
Foam::degToRad
constexpr scalar degToRad(const scalar deg) noexcept
Conversion from degrees to radians.
Definition: unitConversion.H:48
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::nl
constexpr char nl
Definition: Ostream.H:404
refinementParameters.H
Foam::Vector< scalar >
Foam::refinementParameters::getZoneInfo
dictionary getZoneInfo(const word &fzName, surfaceZonesInfo::faceZoneType &faceType) const
Get patchInfo and faceType for faceZone.
Definition: refinementParameters.C:159
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:63
Foam::dictionary::add
entry * add(entry *entryPtr, bool mergeEntry=false)
Add a new entry.
Definition: dictionary.C:640
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:473
IOWarningInFunction
#define IOWarningInFunction(ios)
Report an IO warning using Foam::Warning.
Definition: messageStream.H:340
Foam::refinementParameters::addCellZonesToMesh
labelList addCellZonesToMesh(polyMesh &) const
Add cellZones to mesh. Return indices of cellZones (or -1)
Definition: refinementParameters.C:188
Foam::dictionary::readIfPresent
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:405
Foam::cos
dimensionedScalar cos(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:265