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-2019 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.lookupOrDefault
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.lookupOrDefault
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.lookupOrDefault("useTopologicalSnapDetection", true)
85  ),
86  maxLoadUnbalance_(dict.lookupOrDefault<scalar>("maxLoadUnbalance", 0)),
87  handleSnapProblems_
88  (
89  dict.lookupOrDefault<Switch>("handleSnapProblems", true)
90  ),
91  interfaceRefine_
92  (
93  dict.lookupOrDefault<Switch>("interfaceRefine", true)
94  ),
95  nErodeCellZone_(dict.lookupOrDefault<label>("nCellZoneErodeIter", 0)),
96  nFilterIter_(dict.lookupOrDefault<label>("nFilterIter", 2)),
97  dryRun_(dryRun)
98 {
99  point locationInMesh;
100  List<Tuple2<point, word>> pointsToZone;
101  if (dict.readIfPresent("locationInMesh", locationInMesh))
102  {
103  locationsInMesh_.append(locationInMesh);
104  zonesInMesh_.append("none"); // special name for no cellZone
105 
106  if (dict.found("locationsInMesh"))
107  {
109  << "Cannot both specify 'locationInMesh' and 'locationsInMesh'"
110  << exit(FatalIOError);
111  }
112  }
113  else if (dict.readIfPresent("locationsInMesh", pointsToZone))
114  {
115  List<Tuple2<point, word>> pointsToZone(dict.lookup("locationsInMesh"));
116  label nZones = locationsInMesh_.size();
117  locationsInMesh_.setSize(nZones+pointsToZone.size());
118  zonesInMesh_.setSize(locationsInMesh_.size());
119 
120  forAll(pointsToZone, i)
121  {
122  locationsInMesh_[nZones] = pointsToZone[i].first();
123  zonesInMesh_[nZones] = pointsToZone[i].second();
124  if (zonesInMesh_[nZones] == word::null)
125  {
126  zonesInMesh_[nZones] = "none";
127  }
128  nZones++;
129  }
130  }
131  else
132  {
134  << "No 'locationInMesh' or 'locationsInMesh' provided"
135  << endl;
136  }
137 
138 
139  const scalar featAngle
140  (
141  meshRefinement::get<scalar>(dict, "resolveFeatureAngle", dryRun)
142  );
143 
144  if (featAngle < 0 || featAngle > 180)
145  {
146  curvature_ = -GREAT;
147  }
148  else
149  {
150  curvature_ = Foam::cos(degToRad(featAngle));
151  }
152 }
153 
154 
155 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
156 
158 (
159  const word& fzName,
161 ) const
162 {
163  dictionary patchInfo;
164  patchInfo.add("type", wallPolyPatch::typeName);
165  faceType = surfaceZonesInfo::INTERNAL;
166 
167  if (faceZoneControls_.found(fzName))
168  {
169  const dictionary& fzDict = faceZoneControls_.subDict(fzName);
170 
171  if (fzDict.found("patchInfo"))
172  {
173  patchInfo = fzDict.subDict("patchInfo");
174  }
175 
176  word faceTypeName;
177  if (fzDict.readIfPresent("faceType", faceTypeName))
178  {
179  faceType = surfaceZonesInfo::faceZoneTypeNames[faceTypeName];
180  }
181  }
182  return patchInfo;
183 }
184 
185 
187 (
188  polyMesh& mesh
189 ) const
190 {
191  labelList zoneIDs(zonesInMesh_.size(), -1);
192  forAll(zonesInMesh_, i)
193  {
194  if (zonesInMesh_[i] != word::null && zonesInMesh_[i] != "none")
195  {
196  zoneIDs[i] = surfaceZonesInfo::addCellZone
197  (
198  zonesInMesh_[i], // name
199  labelList(0), // addressing
200  mesh
201  );
202  }
203  }
204  return zoneIDs;
205 }
206 
207 
209 (
210  const bool checkInsideMesh,
211  const polyMesh& mesh,
212  const pointField& locations
213 )
214 {
215  // Force calculation of tet-diag decomposition (for use in findCell)
216  (void)mesh.tetBasePtIs();
217 
218  // Global calculation engine
219  globalIndex globalCells(mesh.nCells());
220 
221  // Cell label per point
222  labelList cellLabels(locations.size());
223 
224  forAll(locations, i)
225  {
226  const point& location = locations[i];
227 
228  label localCellI = mesh.findCell(location, polyMesh::FACE_DIAG_TRIS);
229 
230  label globalCellI = -1;
231 
232  if (localCellI != -1)
233  {
234  globalCellI = globalCells.toGlobal(localCellI);
235  }
236 
237  reduce(globalCellI, maxOp<label>());
238 
239  if (checkInsideMesh && globalCellI == -1)
240  {
242  << "Point " << location
243  << " is not inside the mesh or on a face or edge." << nl
244  << "Bounding box of the mesh:" << mesh.bounds()
245  << exit(FatalError);
246  }
247 
248 
249  label procI = globalCells.whichProcID(globalCellI);
250  label procCellI = globalCells.toLocal(procI, globalCellI);
251 
252  Info<< "Found point " << location << " in cell " << procCellI
253  << " on processor " << procI << endl;
254 
255  if (globalCells.isLocal(globalCellI))
256  {
257  cellLabels[i] = localCellI;
258  }
259  else
260  {
261  cellLabels[i] = -1;
262  }
263  }
264  return cellLabels;
265 }
266 
267 
269 (
270  const wordList& zonesInMesh
271 )
272 {
273  DynamicList<label> indices(zonesInMesh.size());
274 
275  forAll(zonesInMesh, i)
276  {
277  if
278  (
279  zonesInMesh[i] != word::null
280  && zonesInMesh[i] != "none"
281  )
282  {
283  indices.append(i);
284  }
285  }
286  return indices;
287 }
288 
289 
291 (
292  const wordList& zonesInMesh
293 )
294 {
295  DynamicList<label> indices(0);
296 
297  forAll(zonesInMesh, i)
298  {
299  if
300  (
301  zonesInMesh[i] == word::null
302  || zonesInMesh[i] == "none"
303  )
304  {
305  indices.append(i);
306  }
307  }
308  return indices;
309 }
310 
311 
312 // ************************************************************************* //
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:269
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:74
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:70
Foam::surfaceZonesInfo::faceZoneType
faceZoneType
What to do with faceZone faces.
Definition: surfaceZonesInfo.H:76
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
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: dictionary.C:359
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:209
Foam::List::append
void append(const T &val)
Append an element at the end of the list.
Definition: ListI.H:182
Foam::FatalIOError
IOerror FatalIOError
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:337
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:290
Foam::reduce
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
Definition: PstreamReduceOps.H:51
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:62
Foam::Field< vector >
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
Foam::refinementParameters::unzonedLocations
static labelList unzonedLocations(const wordList &zonesInMesh)
Extract indices of unnamed locations ('keepPoints')
Definition: refinementParameters.C:291
Foam::DynamicList::append
DynamicList< T, SizeMin > & append(const T &val)
Append an element to the end of this list.
Definition: DynamicListI.H:472
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:523
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:121
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:355
Foam::nl
constexpr char nl
Definition: Ostream.H:372
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:158
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:102
Foam::dictionary::add
entry * add(entry *entryPtr, bool mergeEntry=false)
Add a new entry.
Definition: dictionary.C:703
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:375
IOWarningInFunction
#define IOWarningInFunction(ios)
Report an IO warning using Foam::Warning.
Definition: messageStream.H:306
Foam::refinementParameters::addCellZonesToMesh
labelList addCellZonesToMesh(polyMesh &) const
Add cellZones to mesh. Return indices of cellZones (or -1)
Definition: refinementParameters.C:187
Foam::dictionary::readIfPresent
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:417
Foam::cos
dimensionedScalar cos(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:265