cellDistFuncs.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-2016 OpenFOAM Foundation
9 Copyright (C) 2020 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
29#include "cellDistFuncs.H"
30#include "polyMesh.H"
31#include "polyBoundaryMesh.H"
32
33// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34
35namespace Foam
36{
38}
39
40// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
41
43:
44 mesh_(mesh)
45{}
46
47
48// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
49
51(
53) const
54{
55 return mesh().boundaryMesh().patchSet(patchNames, false);
56}
57
58
59// Return smallest true distance from p to any of wallFaces.
60// Note that even if normal hits face we still check other faces.
61// Note that wallFaces is untruncated and we explicitly pass in size.
63(
64 const point& p,
65 const polyPatch& patch,
66 const labelUList& wallFaces,
67 label& minFacei
68) const
69{
70 const pointField& points = patch.points();
71
72 scalar minDist = GREAT;
73 minFacei = -1;
74
75 for (const label patchFacei : wallFaces)
76 {
77 const pointHit curHit = patch[patchFacei].nearestPoint(p, points);
78
79 if (curHit.distance() < minDist)
80 {
81 minDist = curHit.distance();
82 minFacei = patch.start() + patchFacei;
83 }
84 }
85
86 return minDist;
87}
88
89
90// Get point neighbours of facei (including facei). Returns number of faces.
91// Note: does not allocate storage but does use linear search to determine
92// uniqueness. For polygonal faces this might be quite inefficient.
94(
95 const primitivePatch& patch,
96 const label patchFacei,
97 DynamicList<label>& neighbours
98) const
99{
100 neighbours.clear();
101
102 // Add myself
103 neighbours.append(patchFacei);
104
105 // Add all face neighbours
106 const labelList& faceNeighbours = patch.faceFaces()[patchFacei];
107
108 for (const label nbr : faceNeighbours)
109 {
110 neighbours.appendUniq(nbr);
111 }
112
113 // Add all point-only neighbours by linear searching in edge neighbours.
114 // Assumes that point-only neighbours are not using multiple points on
115 // face.
116
117 const face& f = patch.localFaces()[patchFacei];
118
119 forAll(f, fp)
120 {
121 label pointi = f[fp];
122
123 const labelList& pointNbs = patch.pointFaces()[pointi];
124
125 for (const label facei : pointNbs)
126 {
127 // Check for facei in edge-neighbours part of neighbours
128 neighbours.appendUniq(facei);
129 }
130 }
131
132
133 if (debug)
134 {
135 // Check for duplicates
136
137 // Use hashSet to determine nbs.
138 labelHashSet nbs(4*f.size());
139
140 forAll(f, fp)
141 {
142 const labelList& pointNbs = patch.pointFaces()[f[fp]];
143 nbs.insert(pointNbs);
144 }
145
146 // Subtract ours.
147 for (const label nb : neighbours)
148 {
149 if (!nbs.found(nb))
150 {
152 << "getPointNeighbours : patchFacei:" << patchFacei
153 << " verts:" << f << endl;
154
155 forAll(f, fp)
156 {
158 << "point:" << f[fp] << " pointFaces:"
159 << patch.pointFaces()[f[fp]] << endl;
160 }
161
162 for (const label facei : neighbours)
163 {
165 << "fast nbr:" << facei
166 << endl;
167 }
168
170 << "Problem: fast pointNeighbours routine included " << nb
171 << " which is not in proper neighbour list " << nbs.toc()
172 << abort(FatalError);
173 }
174 nbs.erase(nb);
175 }
176
177 if (nbs.size())
178 {
180 << "Problem: fast pointNeighbours routine did not find "
181 << nbs.toc() << abort(FatalError);
182 }
183 }
184}
185
186
187// size of largest patch (out of supplied subset of patches)
189(
190 const labelHashSet& patchIDs
191) const
192{
193 label maxSize = 0;
194
195 forAll(mesh().boundaryMesh(), patchi)
196 {
197 if (patchIDs.found(patchi))
198 {
199 const polyPatch& patch = mesh().boundaryMesh()[patchi];
200
201 maxSize = Foam::max(maxSize, patch.size());
202 }
203 }
204 return maxSize;
205}
206
207
208// sum of patch sizes (out of supplied subset of patches)
210(
211 const labelHashSet& patchIDs
212)
213const
214{
215 label sum = 0;
216
217 forAll(mesh().boundaryMesh(), patchi)
218 {
219 if (patchIDs.found(patchi))
220 {
221 const polyPatch& patch = mesh().boundaryMesh()[patchi];
222
223 sum += patch.size();
224 }
225 }
226 return sum;
227}
228
229
230// Gets nearest wall for cells next to wall
232(
233 const labelHashSet& patchIDs,
234 scalarField& wallDistCorrected,
235 Map<label>& nearestFace
236) const
237{
238 // Size neighbours array for maximum possible (= size of largest patch)
239 DynamicList<label> neighbours(maxPatchSize(patchIDs));
240
241 // Correct all cells with face on wall
242 const vectorField& cellCentres = mesh().cellCentres();
243 const labelList& faceOwner = mesh().faceOwner();
244
245 forAll(mesh().boundaryMesh(), patchi)
246 {
247 if (patchIDs.found(patchi))
248 {
249 const polyPatch& patch = mesh().boundaryMesh()[patchi];
250
251 // Check cells with face on wall
252 forAll(patch, patchFacei)
253 {
254 getPointNeighbours(patch, patchFacei, neighbours);
255
256 label celli = faceOwner[patch.start() + patchFacei];
257
258 label minFacei = -1;
259
260 wallDistCorrected[celli] = smallestDist
261 (
262 cellCentres[celli],
263 patch,
264 neighbours,
265 minFacei
266 );
267
268 // Store wallCell and its nearest neighbour
269 nearestFace.insert(celli, minFacei);
270 }
271 }
272 }
273}
274
275
276// Correct all cells connected to wall (via point) and not in nearestFace
278(
279 const labelHashSet& patchIDs,
280 scalarField& wallDistCorrected,
281 Map<label>& nearestFace
282) const
283{
284 // Correct all (non-visited) cells with point on wall
285
286 const vectorField& cellCentres = mesh().cellCentres();
287
288 forAll(mesh().boundaryMesh(), patchi)
289 {
290 if (patchIDs.found(patchi))
291 {
292 const polyPatch& patch = mesh().boundaryMesh()[patchi];
293
294 const labelList& meshPoints = patch.meshPoints();
295 const labelListList& pointFaces = patch.pointFaces();
296
297 forAll(meshPoints, meshPointi)
298 {
299 const label vertI = meshPoints[meshPointi];
300
301 const labelList& neighbours = mesh().pointCells(vertI);
302
303 for (const label celli : neighbours)
304 {
305 if (!nearestFace.found(celli))
306 {
307 const labelList& wallFaces = pointFaces[meshPointi];
308
309 label minFacei = -1;
310
311 wallDistCorrected[celli] = smallestDist
312 (
313 cellCentres[celli],
314 patch,
315 wallFaces,
316 minFacei
317 );
318
319 // Store wallCell and its nearest neighbour
320 nearestFace.insert(celli, minFacei);
321 }
322 }
323 }
324 }
325 }
326}
327
328
329// ************************************************************************* //
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:72
void clear() noexcept
Clear the addressed list, i.e. set the size to zero.
Definition: DynamicListI.H:391
void append(const T &val)
Copy append an element to the end of this list.
Definition: DynamicListI.H:503
label appendUniq(const T &val)
Append an element if not already in the list.
Definition: DynamicListI.H:640
bool insert(const Key &key)
Insert a new entry, not overwriting existing entries.
Definition: HashSet.H:191
List< Key > toc() const
The table of contents (the keys) in unsorted order.
Definition: HashTable.C:122
bool found(const Key &key) const
Return true if hashed entry is found in table.
Definition: HashTableI.H:100
bool insert(const Key &key, const T &obj)
Copy insert a new entry, not overwriting existing entries.
Definition: HashTableI.H:180
label size() const noexcept
The number of elements in table.
Definition: HashTableI.H:52
bool erase(const iterator &iter)
Erase an entry specified by given iterator.
Definition: HashTable.C:440
A HashTable to objects of type <T> with a label key.
Definition: Map.H:60
Describes the interaction of a face and a point. It carries the info of a successful hit and (if succ...
Definition: PointHit.H:54
scalar distance() const noexcept
Return distance to hit.
Definition: PointHit.H:139
A list of faces which address into the list of points.
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: UList.H:94
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
Addressing for all faces on surface of mesh. Can either be read from polyMesh or from triSurface....
Definition: boundaryMesh.H:63
Collection of functions used in wall distance calculation.
Definition: cellDistFuncs.H:64
label maxPatchSize(const labelHashSet &patchIDs) const
Size of largest patch (out of supplied subset of patches)
label sumPatchSize(const labelHashSet &patchIDs) const
Sum of patch sizes (out of supplied subset of patches).
labelHashSet getPatchIDs() const
Get patchIDs of/derived off certain type (e.g. 'processorPolyPatch')
void correctBoundaryFaceCells(const labelHashSet &patchIDs, scalarField &wallDistCorrected, Map< label > &nearestFace) const
Correct all cells connected to boundary (via face). Sets values in.
void getPointNeighbours(const primitivePatch &, const label patchFacei, DynamicList< label > &) const
Get faces sharing point with face on patch.
Definition: cellDistFuncs.C:94
void correctBoundaryPointCells(const labelHashSet &patchIDs, scalarField &wallDistCorrected, Map< label > &nearestFace) const
Correct all cells connected to wall (via point). Sets values in.
scalar smallestDist(const point &p, const polyPatch &patch, const labelUList &wallFaces, label &meshFacei) const
Calculate smallest true distance (and face index)
Definition: cellDistFuncs.C:63
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
labelHashSet patchSet(const UList< wordRe > &patchNames, const bool warnNotFound=true, const bool useGroups=true) const
Return the set of patch IDs corresponding to the given names.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:81
virtual const labelList & faceOwner() const
Return face owner.
Definition: polyMesh.C:1121
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:456
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:75
const labelListList & pointCells() const
const vectorField & cellCentres() const
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
volScalarField & p
dynamicFvMesh & mesh
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
const pointField & points
#define SeriousErrorInFunction
Report an error message using Foam::SeriousError.
Namespace for OpenFOAM.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &df)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
errorManip< error > abort(error &err)
Definition: errorManip.H:144
error FatalError
wordList patchNames(nPatches)
labelList f(nPoints)
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333