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-------------------------------------------------------------------------------
11License
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
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
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);
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(
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] == word::null
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 allLocations.shrink();
352
353 return std::move(allLocations);
354}
355
356
357// ************************************************************************* //
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:72
DynamicList< T, SizeMin > & shrink()
Shrink the allocated space to the number of elements used.
Definition: DynamicListI.H:434
void append(const T &val)
Copy append an element to the end of this list.
Definition: DynamicListI.H:503
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:77
void setSize(const label n)
Alias for resize()
Definition: List.H:218
void append(const T &val)
Append an element at the end of the list.
Definition: ListI.H:175
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
Definition: Switch.H:78
T & first()
Return the first element of the list.
Definition: UListI.H:202
label find(const T &val, label pos=0) const
Find index of the first occurrence of the value.
Definition: UList.C:212
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
const dictionary & subDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary.
Definition: dictionary.C:460
ITstream & lookup(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionary.C:386
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
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
entry * add(entry *entryPtr, bool mergeEntry=false)
Add a new entry.
Definition: dictionary.C:640
Calculates a unique integer (label so might not have enough room - 2G max) for processor + local inde...
Definition: globalIndex.H:68
label toGlobal(const label i) const
From local to global index.
Definition: globalIndexI.H:260
label toLocal(const label i) const
From global to local on current processor.
Definition: globalIndexI.H:325
bool isLocal(const label i) const
Is on local processor.
Definition: globalIndexI.H:244
Helper class which maintains intersections of (changing) mesh with (static) surfaces.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:81
label findCell(const point &p, const cellDecomposition=CELL_TETS) const
Find cell enclosing this location and return index.
Definition: polyMesh.C:1522
const boundBox & bounds() const
Return mesh bounding box.
Definition: polyMesh.H:462
const labelIOList & tetBasePtIs() const
Return the tetBasePtIs.
Definition: polyMesh.C:906
label nCells() const noexcept
Number of mesh cells.
Simple container to keep together refinement specific information.
static labelList unzonedLocations(const wordList &zonesInMesh)
Extract indices of unnamed locations ('keepPoints')
labelList addCellZonesToMesh(polyMesh &) const
Add cellZones to mesh. Return indices of cellZones (or -1)
static labelList zonedLocations(const wordList &zonesInMesh)
Extract indices of named locations (so excludes 'keepPoints')
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.
dictionary getZoneInfo(const word &fzName, surfaceZonesInfo::faceZoneType &faceType) const
Get patchInfo and faceType for faceZone.
faceZoneType
What to do with faceZone faces.
static const Enum< faceZoneType > faceZoneTypeNames
static label addCellZone(const word &name, const labelList &addressing, polyMesh &mesh)
A class for handling words, derived from Foam::string.
Definition: word.H:68
bool
Definition: EEqn.H:20
dynamicFvMesh & mesh
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:473
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
const labelIOList & zoneIDs
Definition: correctPhi.H:59
label nZones
#define IOWarningInFunction(ios)
Report an IO warning using Foam::Warning.
List< label > labelList
A List of labels.
Definition: List.H:66
messageStream Info
Information stream (stdout output on master, null elsewhere)
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:44
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
constexpr scalar degToRad() noexcept
Multiplication factor for degrees to radians conversion.
void reduce(const List< UPstream::commsStruct > &comms, T &value, const BinaryOp &bop, const int tag, const label comm)
IOerror FatalIOError
error FatalError
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
dimensionedScalar cos(const dimensionedScalar &ds)
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333
static const char *const typeName
The type name used in ensight case files.
Unit conversion functions.