00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "cellDistFuncs.H"
00030 #include "polyMesh.H"
00031 #include "wallPolyPatch.H"
00032 #include "polyBoundaryMesh.H"
00033
00034 namespace Foam
00035 {
00036
00037
00038
00039 defineTypeNameAndDebug(cellDistFuncs, 0);
00040
00041 }
00042
00043
00044
00045
00046
00047 Foam::label Foam::cellDistFuncs::findIndex
00048 (
00049 const label nElems,
00050 const labelList& elems,
00051 const label val
00052 )
00053 {
00054 for (label i = 0; i < nElems; i++)
00055 {
00056 if (elems[i] == val)
00057 {
00058 return i;
00059 }
00060 }
00061 return -1;
00062 }
00063
00064
00065
00066
00067
00068 Foam::cellDistFuncs::cellDistFuncs(const polyMesh& mesh)
00069 :
00070 mesh_(mesh)
00071 {}
00072
00073
00074
00075
00076
00077 Foam::labelHashSet Foam::cellDistFuncs::getPatchIDs
00078 (
00079 const wordList& patchNames
00080 ) const
00081 {
00082 const polyBoundaryMesh& bMesh = mesh().boundaryMesh();
00083
00084
00085 HashSet<word> patchNamesHash(patchNames.size());
00086
00087 forAll(patchNames, patchI)
00088 {
00089 patchNamesHash.insert(patchNames[patchI]);
00090 }
00091
00092
00093
00094 labelHashSet patchIDs(bMesh.size());
00095
00096 forAll(bMesh, patchI)
00097 {
00098 const polyPatch& patch = bMesh[patchI];
00099
00100 if (patchNamesHash.found(patch.name()))
00101 {
00102 patchIDs.insert(patchI);
00103 }
00104 }
00105 return patchIDs;
00106 }
00107
00108
00109
00110 Foam::labelHashSet Foam::cellDistFuncs::getPatchIDs(const word& wantedType)
00111 const
00112 {
00113 const polyBoundaryMesh& bMesh = mesh().boundaryMesh();
00114
00115 labelHashSet patchIDs(bMesh.size());
00116
00117 forAll(bMesh, patchI)
00118 {
00119 const polyPatch& patch = bMesh[patchI];
00120
00121 if (patch.type() == wantedType)
00122 {
00123 patchIDs.insert(patchI);
00124 }
00125 }
00126 return patchIDs;
00127 }
00128
00129
00130
00131
00132
00133 Foam::scalar Foam::cellDistFuncs::smallestDist
00134 (
00135 const point& p,
00136 const polyPatch& patch,
00137 const label nWallFaces,
00138 const labelList& wallFaces,
00139 label& minFaceI
00140 ) const
00141 {
00142 const pointField& points = patch.points();
00143
00144 scalar minDist = GREAT;
00145 minFaceI = -1;
00146
00147 for(label wallFaceI = 0; wallFaceI < nWallFaces; wallFaceI++)
00148 {
00149 label patchFaceI = wallFaces[wallFaceI];
00150
00151 pointHit curHit = patch[patchFaceI].nearestPoint(p, points);
00152
00153 if (curHit.distance() < minDist)
00154 {
00155 minDist = curHit.distance();
00156 minFaceI = patch.start() + patchFaceI;
00157 }
00158 }
00159
00160 return minDist;
00161 }
00162
00163
00164
00165
00166
00167 Foam::label Foam::cellDistFuncs::getPointNeighbours
00168 (
00169 const primitivePatch& patch,
00170 const label patchFaceI,
00171 labelList& neighbours
00172 ) const
00173 {
00174 label nNeighbours = 0;
00175
00176
00177 neighbours[nNeighbours++] = patchFaceI;
00178
00179
00180 const labelList& faceNeighbours = patch.faceFaces()[patchFaceI];
00181
00182 forAll(faceNeighbours, faceNeighbourI)
00183 {
00184 neighbours[nNeighbours++] = faceNeighbours[faceNeighbourI];
00185 }
00186
00187
00188 label nEdgeNbs = nNeighbours;
00189
00190
00191
00192
00193
00194
00195 const face& f = patch.localFaces()[patchFaceI];
00196
00197 forAll(f, fp)
00198 {
00199 label pointI = f[fp];
00200
00201 const labelList& pointNbs = patch.pointFaces()[pointI];
00202
00203 forAll(pointNbs, nbI)
00204 {
00205 label faceI = pointNbs[nbI];
00206
00207
00208 if (findIndex(nEdgeNbs, neighbours, faceI) == -1)
00209 {
00210 neighbours[nNeighbours++] = faceI;
00211 }
00212 }
00213 }
00214
00215
00216 if (debug)
00217 {
00218
00219
00220
00221 labelHashSet nbs(4*f.size());
00222
00223 forAll(f, fp)
00224 {
00225 const labelList& pointNbs = patch.pointFaces()[f[fp]];
00226
00227 forAll(pointNbs, i)
00228 {
00229 nbs.insert(pointNbs[i]);
00230 }
00231 }
00232
00233
00234 for (label i = 0; i < nNeighbours; i++)
00235 {
00236 label nb = neighbours[i];
00237
00238 if (!nbs.found(nb))
00239 {
00240 SeriousErrorIn("Foam::cellDistFuncs::getPointNeighbours")
00241 << "getPointNeighbours : patchFaceI:" << patchFaceI
00242 << " verts:" << f << endl;
00243
00244 forAll(f, fp)
00245 {
00246 SeriousErrorIn("Foam::cellDistFuncs::getPointNeighbours")
00247 << "point:" << f[fp] << " pointFaces:"
00248 << patch.pointFaces()[f[fp]] << endl;
00249 }
00250
00251 for (label i = 0; i < nNeighbours; i++)
00252 {
00253 SeriousErrorIn("Foam::cellDistFuncs::getPointNeighbours")
00254 << "fast nbr:" << neighbours[i]
00255 << endl;
00256 }
00257
00258 FatalErrorIn("getPointNeighbours")
00259 << "Problem: fast pointNeighbours routine included " << nb
00260 << " which is not in proper neigbour list " << nbs.toc()
00261 << abort(FatalError);
00262 }
00263 nbs.erase(nb);
00264 }
00265
00266 if (nbs.size())
00267 {
00268 FatalErrorIn("getPointNeighbours")
00269 << "Problem: fast pointNeighbours routine did not find "
00270 << nbs.toc() << abort(FatalError);
00271 }
00272 }
00273
00274 return nNeighbours;
00275 }
00276
00277
00278
00279 Foam::label Foam::cellDistFuncs::maxPatchSize(const labelHashSet& patchIDs)
00280 const
00281 {
00282 label maxSize = 0;
00283
00284 forAll(mesh().boundaryMesh(), patchI)
00285 {
00286 if (patchIDs.found(patchI))
00287 {
00288 const polyPatch& patch = mesh().boundaryMesh()[patchI];
00289
00290 maxSize = Foam::max(maxSize, patch.size());
00291 }
00292 }
00293 return maxSize;
00294 }
00295
00296
00297
00298 Foam::label Foam::cellDistFuncs::sumPatchSize(const labelHashSet& patchIDs)
00299 const
00300 {
00301 label sum = 0;
00302
00303 forAll(mesh().boundaryMesh(), patchI)
00304 {
00305 if (patchIDs.found(patchI))
00306 {
00307 const polyPatch& patch = mesh().boundaryMesh()[patchI];
00308
00309 sum += patch.size();
00310 }
00311 }
00312 return sum;
00313 }
00314
00315
00316
00317 void Foam::cellDistFuncs::correctBoundaryFaceCells
00318 (
00319 const labelHashSet& patchIDs,
00320 scalarField& wallDistCorrected,
00321 Map<label>& nearestFace
00322 ) const
00323 {
00324
00325 label maxPointNeighbours = maxPatchSize(patchIDs);
00326
00327 labelList neighbours(maxPointNeighbours);
00328
00329
00330
00331 const vectorField& cellCentres = mesh().cellCentres();
00332 const labelList& faceOwner = mesh().faceOwner();
00333
00334 forAll(mesh().boundaryMesh(), patchI)
00335 {
00336 if (patchIDs.found(patchI))
00337 {
00338 const polyPatch& patch = mesh().boundaryMesh()[patchI];
00339
00340
00341 forAll(patch, patchFaceI)
00342 {
00343 label nNeighbours = getPointNeighbours
00344 (
00345 patch,
00346 patchFaceI,
00347 neighbours
00348 );
00349
00350 label cellI = faceOwner[patch.start() + patchFaceI];
00351
00352 label minFaceI = -1;
00353
00354 wallDistCorrected[cellI] = smallestDist
00355 (
00356 cellCentres[cellI],
00357 patch,
00358 nNeighbours,
00359 neighbours,
00360 minFaceI
00361 );
00362
00363
00364 nearestFace.insert(cellI, minFaceI);
00365 }
00366 }
00367 }
00368
00369 }
00370
00371
00372
00373 void Foam::cellDistFuncs::correctBoundaryPointCells
00374 (
00375 const labelHashSet& patchIDs,
00376 scalarField& wallDistCorrected,
00377 Map<label>& nearestFace
00378 ) const
00379 {
00380
00381
00382 const labelListList& pointCells = mesh().pointCells();
00383 const vectorField& cellCentres = mesh().cellCentres();
00384
00385 forAll(mesh().boundaryMesh(), patchI)
00386 {
00387 if (patchIDs.found(patchI))
00388 {
00389 const polyPatch& patch = mesh().boundaryMesh()[patchI];
00390
00391 const labelList& meshPoints = patch.meshPoints();
00392 const labelListList& pointFaces = patch.pointFaces();
00393
00394 forAll(meshPoints, meshPointI)
00395 {
00396 label vertI = meshPoints[meshPointI];
00397
00398 const labelList& neighbours = pointCells[vertI];
00399
00400 forAll(neighbours, neighbourI)
00401 {
00402 label cellI = neighbours[neighbourI];
00403
00404 if (!nearestFace.found(cellI))
00405 {
00406 const labelList& wallFaces = pointFaces[meshPointI];
00407
00408 label minFaceI = -1;
00409
00410 wallDistCorrected[cellI] = smallestDist
00411 (
00412 cellCentres[cellI],
00413 patch,
00414 wallFaces.size(),
00415 wallFaces,
00416 minFaceI
00417 );
00418
00419
00420 nearestFace.insert(cellI, minFaceI);
00421 }
00422 }
00423 }
00424 }
00425 }
00426 }
00427
00428
00429