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 | Copyright (C) 2011-2015 OpenFOAM Foundation
6  \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
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.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "refinementParameters.H"
27 #include "unitConversion.H"
28 #include "polyMesh.H"
29 #include "globalIndex.H"
30 #include "Tuple2.H"
31 #include "wallPolyPatch.H"
32 
33 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
34 
36 :
37  maxGlobalCells_(readLabel(dict.lookup("maxGlobalCells"))),
38  maxLocalCells_(readLabel(dict.lookup("maxLocalCells"))),
39  minRefineCells_(readLabel(dict.lookup("minRefinementCells"))),
40  planarAngle_
41  (
42  dict.lookupOrDefault
43  (
44  "planarAngle",
45  readScalar(dict.lookup("resolveFeatureAngle"))
46  )
47  ),
48  nBufferLayers_(readLabel(dict.lookup("nCellsBetweenLevels"))),
49  locationsOutsideMesh_
50  (
51  dict.lookupOrDefault
52  (
53  "locationsOutsideMesh",
54  pointField(0)
55  )
56  ),
57  faceZoneControls_(dict.subOrEmptyDict("faceZoneControls")),
58  allowFreeStandingZoneFaces_(dict.lookup("allowFreeStandingZoneFaces")),
59  useTopologicalSnapDetection_
60  (
61  dict.lookupOrDefault<bool>("useTopologicalSnapDetection", true)
62  ),
63  maxLoadUnbalance_(dict.lookupOrDefault<scalar>("maxLoadUnbalance", 0)),
64  handleSnapProblems_
65  (
66  dict.lookupOrDefault<Switch>("handleSnapProblems", true)
67  ),
68  interfaceRefine_
69  (
70  dict.lookupOrDefault<Switch>("interfaceRefine", true)
71  )
72 {
73  point locationInMesh;
74  if (dict.readIfPresent("locationInMesh", locationInMesh))
75  {
76  locationsInMesh_.append(locationInMesh);
77  zonesInMesh_.append("none"); // special name for no cellZone
78 
79  if (dict.found("locationsInMesh"))
80  {
82  << "Cannot both specify 'locationInMesh' and 'locationsInMesh'"
83  << exit(FatalIOError);
84  }
85  }
86 
87  List<Tuple2<point, word> > pointsToZone;
88  if (dict.readIfPresent("locationsInMesh", pointsToZone))
89  {
90  label nZones = locationsInMesh_.size();
91  locationsInMesh_.setSize(nZones+pointsToZone.size());
93 
94  forAll(pointsToZone, i)
95  {
96  locationsInMesh_[nZones] = pointsToZone[i].first();
97  zonesInMesh_[nZones] = pointsToZone[i].second();
98  if (zonesInMesh_[nZones] == word::null)
99  {
100  zonesInMesh_[nZones] = "none";
101  }
102  nZones++;
103  }
104  }
105 
106 
107  scalar featAngle(readScalar(dict.lookup("resolveFeatureAngle")));
108 
109  if (featAngle < 0 || featAngle > 180)
110  {
111  curvature_ = -GREAT;
112  }
113  else
114  {
115  curvature_ = Foam::cos(degToRad(featAngle));
116  }
117 }
118 
119 
120 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
121 
123 (
124  const word& fzName,
126 ) const
127 {
128  dictionary patchInfo;
129  patchInfo.add("type", wallPolyPatch::typeName);
130  faceType = surfaceZonesInfo::INTERNAL;
131 
132  if (faceZoneControls_.found(fzName))
133  {
134  const dictionary& fzDict = faceZoneControls_.subDict(fzName);
135 
136  if (fzDict.found("patchInfo"))
137  {
138  patchInfo = fzDict.subDict("patchInfo");
139  }
140 
141  word faceTypeName;
142  if (fzDict.readIfPresent("faceType", faceTypeName))
143  {
144  faceType = surfaceZonesInfo::faceZoneTypeNames[faceTypeName];
145  }
146  }
147  return patchInfo;
148 }
149 
150 
152 (
153  polyMesh& mesh
154 ) const
155 {
156  labelList zoneIDs(zonesInMesh_.size(), -1);
157  forAll(zonesInMesh_, i)
158  {
159  if (zonesInMesh_[i] != word::null && zonesInMesh_[i] != "none")
160  {
161  zoneIDs[i] = surfaceZonesInfo::addCellZone
162  (
163  zonesInMesh_[i], // name
164  labelList(0), // addressing
165  mesh
166  );
167  }
168  }
169  return zoneIDs;
170 }
171 
172 
174 (
175  const bool checkInsideMesh,
176  const polyMesh& mesh,
177  const pointField& locations
178 )
179 {
180  // Force calculation of tet-diag decomposition (for use in findCell)
181  (void)mesh.tetBasePtIs();
182 
183  // Global calculation engine
184  globalIndex globalCells(mesh.nCells());
185 
186  // Cell label per point
187  labelList cellLabels(locations.size());
188 
189  forAll(locations, i)
190  {
191  const point& location = locations[i];
192 
193  label localCellI = mesh.findCell(location);
194 
195  label globalCellI = -1;
196 
197  if (localCellI != -1)
198  {
199  globalCellI = globalCells.toGlobal(localCellI);
200  }
201 
202  reduce(globalCellI, maxOp<label>());
203 
204  if (checkInsideMesh && globalCellI == -1)
205  {
207  << "Point " << location
208  << " is not inside the mesh or on a face or edge." << nl
209  << "Bounding box of the mesh:" << mesh.bounds()
210  << exit(FatalError);
211  }
212 
213 
214  label procI = globalCells.whichProcID(globalCellI);
215  label procCellI = globalCells.toLocal(procI, globalCellI);
216 
217  Info<< "Found point " << location << " in cell " << procCellI
218  << " on processor " << procI << endl;
219 
220  if (globalCells.isLocal(globalCellI))
221  {
222  cellLabels[i] = localCellI;
223  }
224  else
225  {
226  cellLabels[i] = -1;
227  }
228  }
229  return cellLabels;
230 }
231 
232 
234 (
235  const wordList& zonesInMesh
236 )
237 {
238  DynamicList<label> indices(zonesInMesh.size());
239 
240  forAll(zonesInMesh, i)
241  {
242  if
243  (
244  zonesInMesh[i] != word::null
245  && zonesInMesh[i] != "none"
246  )
247  {
248  indices.append(i);
249  }
250  }
251  return indices;
252 }
253 
254 
256 (
257  const wordList& zonesInMesh
258 )
259 {
260  DynamicList<label> indices(0);
261 
262  forAll(zonesInMesh, i)
263  {
264  if
265  (
266  zonesInMesh[i] == word::null
267  || zonesInMesh[i] == "none"
268  )
269  {
270  indices.append(i);
271  }
272  }
273  return indices;
274 }
275 
276 
277 // ************************************************************************* //
Foam::refinementParameters::zonedLocations
static labelList zonedLocations(const wordList &zonesInMesh)
Extract indices of named locations (so excludes 'keepPoints')
Definition: refinementParameters.C:234
Foam::maxOp
Definition: ops.H:172
Foam::Switch
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
Definition: Switch.H:60
Foam::surfaceZonesInfo::faceZoneType
faceZoneType
What to do with faceZone faces.
Definition: surfaceZonesInfo.H:73
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::labelList
List< label > labelList
A List of labels.
Definition: labelList.H:56
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Tuple2.H
Foam::DynamicList< label >
Foam::dictionary::readIfPresent
bool readIfPresent(const word &, T &, bool recursive=false, bool patternMatch=true) const
Find an entry if present, and assign to T.
Definition: dictionaryTemplates.C:94
Foam::polyMesh::tetBasePtIs
const labelList & tetBasePtIs() const
Return the tetBasePtIs.
Definition: polyMesh.C:818
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:174
Foam::globalIndex::isLocal
bool isLocal(const label i) const
Is on local processor.
Definition: globalIndexI.H:95
Foam::FatalIOError
IOerror FatalIOError
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
polyMesh.H
Foam::refinementParameters::curvature_
scalar curvature_
Curvature.
Definition: refinementParameters.H:69
Foam::refinementParameters::zonesInMesh_
wordList zonesInMesh_
Region for location.
Definition: refinementParameters.H:87
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Foam::primitiveMesh::nCells
label nCells() const
Definition: primitiveMeshI.H:64
Foam::reduce
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
Definition: PstreamReduceOps.H:43
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:59
Foam::dictionary::found
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:304
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::List::append
void append(const T &)
Append an element at the end of the list.
Foam::refinementParameters::refinementParameters
refinementParameters(const refinementParameters &)
Disallow default bitwise copy construct.
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
Foam::refinementParameters::unzonedLocations
static labelList unzonedLocations(const wordList &zonesInMesh)
Extract indices of unnamed locations ('keepPoints')
Definition: refinementParameters.C:256
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
Foam::surfaceZonesInfo::faceZoneTypeNames
static const NamedEnum< faceZoneType, 3 > faceZoneTypeNames
Definition: surfaceZonesInfo.H:80
Foam::globalIndex
Calculates a unique integer (label so might not have enough room - 2G max) for processor + local inde...
Definition: globalIndex.H:63
Foam::DynamicList::append
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
readScalar
#define readScalar
Definition: doubleScalar.C:38
Foam::polyMesh::bounds
const boundBox & bounds() const
Return mesh bounding box.
Definition: polyMesh.H:427
Foam::refinementParameters::locationsInMesh_
pointField locationsInMesh_
Areas to keep.
Definition: refinementParameters.H:84
Foam::List::setSize
void setSize(const label)
Reset size of List.
Foam::globalIndex::toLocal
label toLocal(const label i) const
From global to local on current processor.
Definition: globalIndexI.H:117
Foam::polyMesh::findCell
label findCell(const point &p, const cellDecomposition=CELL_TETS) const
Find cell enclosing this location and return index.
Definition: polyMesh.C:1411
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
Foam::readScalar
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if succesful.
Definition: doubleScalar.H:63
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:123
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:59
Foam::globalIndex::whichProcID
label whichProcID(const label i) const
Which processor does global come from? Binary search.
Definition: globalIndexI.H:123
Foam::word::null
static const word null
An empty word.
Definition: word.H:77
Foam::readLabel
label readLabel(Istream &is)
Definition: label.H:64
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:330
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
Foam::refinementParameters::addCellZonesToMesh
labelList addCellZonesToMesh(polyMesh &) const
Add cellZones to mesh. Return indices of cellZones (or -1)
Definition: refinementParameters.C:152
Foam::dictionary::subDict
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
Definition: dictionary.C:631
Foam::dictionary::add
bool add(entry *, bool mergeEntry=false)
Add a new entry.
Definition: dictionary.C:729
Foam::globalIndex::toGlobal
label toGlobal(const label i) const
From local to global.
Definition: globalIndexI.H:82
lookup
stressControl lookup("compactNormalStress") >> compactNormalStress
Foam::surfaceZonesInfo::addCellZone
static label addCellZone(const word &name, const labelList &addressing, polyMesh &mesh)
Definition: surfaceZonesInfo.C:369
Foam::degToRad
scalar degToRad(const scalar deg)
Conversion from degrees to radians.
Definition: unitConversion.H:45
Foam::cos
dimensionedScalar cos(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:256
Foam::surfaceZonesInfo::INTERNAL
@ INTERNAL
Definition: surfaceZonesInfo.H:75