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 #include "cellToFaceStencil.H"
00028 #include "syncTools.H"
00029 #include "SortableList.H"
00030 #include "emptyPolyPatch.H"
00031
00032
00033
00034
00035 void Foam::cellToFaceStencil::merge
00036 (
00037 const label global0,
00038 const label global1,
00039 const labelList& listA,
00040 labelList& listB
00041 )
00042 {
00043 sort(listB);
00044
00045
00046 label nGlobalInsert = 0;
00047
00048 if (global0 != -1)
00049 {
00050 label index0 = findSortedIndex(listB, global0);
00051 if (index0 == -1)
00052 {
00053 nGlobalInsert++;
00054 }
00055 }
00056
00057 if (global1 != -1)
00058 {
00059 label index1 = findSortedIndex(listB, global1);
00060 if (index1 == -1)
00061 {
00062 nGlobalInsert++;
00063 }
00064 }
00065
00066
00067
00068 label nInsert = 0;
00069
00070 forAll(listA, i)
00071 {
00072 label elem = listA[i];
00073
00074 if (elem != global0 && elem != global1)
00075 {
00076 if (findSortedIndex(listB, elem) == -1)
00077 {
00078 nInsert++;
00079 }
00080 }
00081 }
00082
00083
00084 labelList result(listB.size() + nGlobalInsert + nInsert);
00085
00086 label resultI = 0;
00087
00088
00089 if (global0 != -1)
00090 {
00091 result[resultI++] = global0;
00092 }
00093 if (global1 != -1)
00094 {
00095 result[resultI++] = global1;
00096 }
00097
00098
00099
00100 forAll(listB, i)
00101 {
00102 label elem = listB[i];
00103
00104 if (elem != global0 && elem != global1)
00105 {
00106 result[resultI++] = elem;
00107 }
00108 }
00109
00110
00111
00112 forAll(listA, i)
00113 {
00114 label elem = listA[i];
00115
00116 if (elem != global0 && elem != global1)
00117 {
00118 if (findSortedIndex(listB, elem) == -1)
00119 {
00120 result[resultI++] = elem;
00121 }
00122 }
00123 }
00124
00125 if (resultI != result.size())
00126 {
00127 FatalErrorIn("cellToFaceStencil::merge(..)")
00128 << "problem" << abort(FatalError);
00129 }
00130
00131 listB.transfer(result);
00132 }
00133
00134
00135
00136 void Foam::cellToFaceStencil::merge
00137 (
00138 const label globalI,
00139 const labelList& pGlobals,
00140 labelList& cCells
00141 )
00142 {
00143 labelHashSet set;
00144 forAll(cCells, i)
00145 {
00146 if (cCells[i] != globalI)
00147 {
00148 set.insert(cCells[i]);
00149 }
00150 }
00151
00152 forAll(pGlobals, i)
00153 {
00154 if (pGlobals[i] != globalI)
00155 {
00156 set.insert(pGlobals[i]);
00157 }
00158 }
00159
00160 cCells.setSize(set.size()+1);
00161 label n = 0;
00162 cCells[n++] = globalI;
00163
00164 forAllConstIter(labelHashSet, set, iter)
00165 {
00166 cCells[n++] = iter.key();
00167 }
00168 }
00169
00170
00171 void Foam::cellToFaceStencil::validBoundaryFaces(boolList& isValidBFace) const
00172 {
00173 const polyBoundaryMesh& patches = mesh().boundaryMesh();
00174
00175 isValidBFace.setSize(mesh().nFaces()-mesh().nInternalFaces(), true);
00176
00177 forAll(patches, patchI)
00178 {
00179 const polyPatch& pp = patches[patchI];
00180
00181 if (pp.coupled() || isA<emptyPolyPatch>(pp))
00182 {
00183 label bFaceI = pp.start()-mesh().nInternalFaces();
00184 forAll(pp, i)
00185 {
00186 isValidBFace[bFaceI++] = false;
00187 }
00188 }
00189 }
00190 }
00191
00192
00193 Foam::autoPtr<Foam::indirectPrimitivePatch>
00194 Foam::cellToFaceStencil::allCoupledFacesPatch() const
00195 {
00196 const polyBoundaryMesh& patches = mesh().boundaryMesh();
00197
00198 label nCoupled = 0;
00199
00200 forAll(patches, patchI)
00201 {
00202 const polyPatch& pp = patches[patchI];
00203
00204 if (pp.coupled())
00205 {
00206 nCoupled += pp.size();
00207 }
00208 }
00209 labelList coupledFaces(nCoupled);
00210 nCoupled = 0;
00211
00212 forAll(patches, patchI)
00213 {
00214 const polyPatch& pp = patches[patchI];
00215
00216 if (pp.coupled())
00217 {
00218 label faceI = pp.start();
00219
00220 forAll(pp, i)
00221 {
00222 coupledFaces[nCoupled++] = faceI++;
00223 }
00224 }
00225 }
00226
00227 return autoPtr<indirectPrimitivePatch>
00228 (
00229 new indirectPrimitivePatch
00230 (
00231 IndirectList<face>
00232 (
00233 mesh().faces(),
00234 coupledFaces
00235 ),
00236 mesh().points()
00237 )
00238 );
00239 }
00240
00241
00242 void Foam::cellToFaceStencil::unionEqOp::operator()
00243 (
00244 labelList& x,
00245 const labelList& y
00246 ) const
00247 {
00248 if (y.size())
00249 {
00250 if (x.empty())
00251 {
00252 x = y;
00253 }
00254 else
00255 {
00256 labelHashSet set(x);
00257 forAll(y, i)
00258 {
00259 set.insert(y[i]);
00260 }
00261 x = set.toc();
00262 }
00263 }
00264 }
00265
00266
00267 void Foam::cellToFaceStencil::insertFaceCells
00268 (
00269 const label exclude0,
00270 const label exclude1,
00271 const boolList& isValidBFace,
00272 const labelList& faceLabels,
00273 labelHashSet& globals
00274 ) const
00275 {
00276 const labelList& own = mesh().faceOwner();
00277 const labelList& nei = mesh().faceNeighbour();
00278
00279 forAll(faceLabels, i)
00280 {
00281 label faceI = faceLabels[i];
00282
00283 label globalOwn = globalNumbering().toGlobal(own[faceI]);
00284 if (globalOwn != exclude0 && globalOwn != exclude1)
00285 {
00286 globals.insert(globalOwn);
00287 }
00288
00289 if (mesh().isInternalFace(faceI))
00290 {
00291 label globalNei = globalNumbering().toGlobal(nei[faceI]);
00292 if (globalNei != exclude0 && globalNei != exclude1)
00293 {
00294 globals.insert(globalNei);
00295 }
00296 }
00297 else
00298 {
00299 label bFaceI = faceI-mesh().nInternalFaces();
00300
00301 if (isValidBFace[bFaceI])
00302 {
00303 label globalI = globalNumbering().toGlobal
00304 (
00305 mesh().nCells()
00306 + bFaceI
00307 );
00308
00309 if (globalI != exclude0 && globalI != exclude1)
00310 {
00311 globals.insert(globalI);
00312 }
00313 }
00314 }
00315 }
00316 }
00317
00318
00319 Foam::labelList Foam::cellToFaceStencil::calcFaceCells
00320 (
00321 const boolList& isValidBFace,
00322 const labelList& faceLabels,
00323 labelHashSet& globals
00324 ) const
00325 {
00326 globals.clear();
00327
00328 insertFaceCells
00329 (
00330 -1,
00331 -1,
00332 isValidBFace,
00333 faceLabels,
00334 globals
00335 );
00336
00337 return globals.toc();
00338 }
00339
00340
00341
00342 void Foam::cellToFaceStencil::calcFaceStencil
00343 (
00344 const labelListList& globalCellCells,
00345 labelListList& faceStencil
00346 ) const
00347 {
00348 const polyBoundaryMesh& patches = mesh_.boundaryMesh();
00349 const label nBnd = mesh_.nFaces()-mesh_.nInternalFaces();
00350 const labelList& own = mesh_.faceOwner();
00351 const labelList& nei = mesh_.faceNeighbour();
00352
00353
00354
00355
00356
00357 labelListList neiGlobalCellCells(nBnd);
00358 forAll(patches, patchI)
00359 {
00360 const polyPatch& pp = patches[patchI];
00361
00362 if (pp.coupled())
00363 {
00364 label faceI = pp.start();
00365
00366 forAll(pp, i)
00367 {
00368 neiGlobalCellCells[faceI-mesh_.nInternalFaces()] =
00369 globalCellCells[own[faceI]];
00370 faceI++;
00371 }
00372 }
00373 }
00374 syncTools::swapBoundaryFaceList(mesh_, neiGlobalCellCells, false);
00375
00376
00377
00378
00379
00380
00381 faceStencil.setSize(mesh_.nFaces());
00382
00383 labelHashSet faceStencilSet;
00384
00385 for (label faceI = 0; faceI < mesh_.nInternalFaces(); faceI++)
00386 {
00387 faceStencilSet.clear();
00388
00389 const labelList& ownCCells = globalCellCells[own[faceI]];
00390 label globalOwn = ownCCells[0];
00391
00392 forAll(ownCCells, i)
00393 {
00394 faceStencilSet.insert(ownCCells[i]);
00395 }
00396
00397 const labelList& neiCCells = globalCellCells[nei[faceI]];
00398 label globalNei = neiCCells[0];
00399
00400 forAll(neiCCells, i)
00401 {
00402 faceStencilSet.insert(neiCCells[i]);
00403 }
00404
00405
00406 faceStencil[faceI].setSize(faceStencilSet.size());
00407 label n = 0;
00408 faceStencil[faceI][n++] = globalOwn;
00409 faceStencil[faceI][n++] = globalNei;
00410 forAllConstIter(labelHashSet, faceStencilSet, iter)
00411 {
00412 if (iter.key() != globalOwn && iter.key() != globalNei)
00413 {
00414 faceStencil[faceI][n++] = iter.key();
00415 }
00416 }
00417
00418
00419 }
00420 forAll(patches, patchI)
00421 {
00422 const polyPatch& pp = patches[patchI];
00423 label faceI = pp.start();
00424
00425 if (pp.coupled())
00426 {
00427 forAll(pp, i)
00428 {
00429 faceStencilSet.clear();
00430
00431 const labelList& ownCCells = globalCellCells[own[faceI]];
00432 label globalOwn = ownCCells[0];
00433 forAll(ownCCells, i)
00434 {
00435 faceStencilSet.insert(ownCCells[i]);
00436 }
00437
00438
00439 const labelList& neiCCells =
00440 neiGlobalCellCells[faceI-mesh_.nInternalFaces()];
00441 label globalNei = neiCCells[0];
00442 forAll(neiCCells, i)
00443 {
00444 faceStencilSet.insert(neiCCells[i]);
00445 }
00446
00447
00448 faceStencil[faceI].setSize(faceStencilSet.size());
00449 label n = 0;
00450 faceStencil[faceI][n++] = globalOwn;
00451 faceStencil[faceI][n++] = globalNei;
00452 forAllConstIter(labelHashSet, faceStencilSet, iter)
00453 {
00454 if (iter.key() != globalOwn && iter.key() != globalNei)
00455 {
00456 faceStencil[faceI][n++] = iter.key();
00457 }
00458 }
00459
00460
00461
00462
00463
00464 faceI++;
00465 }
00466 }
00467 else if (!isA<emptyPolyPatch>(pp))
00468 {
00469 forAll(pp, i)
00470 {
00471 faceStencilSet.clear();
00472
00473 const labelList& ownCCells = globalCellCells[own[faceI]];
00474 label globalOwn = ownCCells[0];
00475 forAll(ownCCells, i)
00476 {
00477 faceStencilSet.insert(ownCCells[i]);
00478 }
00479
00480
00481 faceStencil[faceI].setSize(faceStencilSet.size());
00482 label n = 0;
00483 faceStencil[faceI][n++] = globalOwn;
00484 forAllConstIter(labelHashSet, faceStencilSet, iter)
00485 {
00486 if (iter.key() != globalOwn)
00487 {
00488 faceStencil[faceI][n++] = iter.key();
00489 }
00490 }
00491
00492
00493
00494
00495
00496 faceI++;
00497 }
00498 }
00499 }
00500 }
00501
00502
00503
00504
00505 Foam::cellToFaceStencil::cellToFaceStencil(const polyMesh& mesh)
00506 :
00507 mesh_(mesh),
00508 globalNumbering_(mesh_.nCells()+mesh_.nFaces()-mesh_.nInternalFaces())
00509 {}
00510
00511
00512