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 "extendedUpwindCellToFaceStencil.H"
00028 #include "cellToFaceStencil.H"
00029 #include "syncTools.H"
00030 #include "SortableList.H"
00031
00032
00033
00034 void Foam::extendedUpwindCellToFaceStencil::selectOppositeFaces
00035 (
00036 const boolList& nonEmptyFace,
00037 const scalar minOpposedness,
00038 const label faceI,
00039 const label cellI,
00040 DynamicList<label>& oppositeFaces
00041 ) const
00042 {
00043 const vectorField& areas = mesh_.faceAreas();
00044 const labelList& own = mesh_.faceOwner();
00045 const cell& cFaces = mesh_.cells()[cellI];
00046
00047 SortableList<scalar> opposedness(cFaces.size(), -GREAT);
00048
00049
00050 forAll(cFaces, i)
00051 {
00052 label otherFaceI = cFaces[i];
00053
00054 if (otherFaceI != faceI && nonEmptyFace[otherFaceI])
00055 {
00056 if ((own[otherFaceI] == cellI) == (own[faceI] == cellI))
00057 {
00058 opposedness[i] = -(areas[otherFaceI] & areas[faceI]);
00059 }
00060 else
00061 {
00062 opposedness[i] = (areas[otherFaceI] & areas[faceI]);
00063 }
00064 }
00065 }
00066
00067 label sz = opposedness.size();
00068
00069 oppositeFaces.clear();
00070
00071 scalar myAreaSqr = magSqr(areas[faceI]);
00072
00073 if (myAreaSqr > VSMALL)
00074 {
00075 forAll(opposedness, i)
00076 {
00077 opposedness[i] /= myAreaSqr;
00078 }
00079
00080 opposedness.sort();
00081
00082
00083 oppositeFaces.append(cFaces[opposedness.indices()[sz-1]]);
00084
00085 for (label i = sz-2; i >= 0; --i)
00086 {
00087 if (opposedness[i] < minOpposedness)
00088 {
00089 break;
00090 }
00091 oppositeFaces.append(cFaces[opposedness.indices()[i]]);
00092 }
00093 }
00094 else
00095 {
00096
00097 opposedness.sort();
00098
00099
00100
00101 oppositeFaces.append(cFaces[opposedness.indices()[sz-1]]);
00102 }
00103 }
00104
00105
00106 void Foam::extendedUpwindCellToFaceStencil::transportStencil
00107 (
00108 const boolList& nonEmptyFace,
00109 const labelListList& faceStencil,
00110 const scalar minOpposedness,
00111 const label faceI,
00112 const label cellI,
00113 const bool stencilHasNeighbour,
00114
00115 DynamicList<label>& oppositeFaces,
00116 labelHashSet& faceStencilSet,
00117 labelList& transportedStencil
00118 ) const
00119 {
00120 label globalOwn = faceStencil[faceI][0];
00121 label globalNei = -1;
00122 if (stencilHasNeighbour && faceStencil[faceI].size() >= 2)
00123 {
00124 globalNei = faceStencil[faceI][1];
00125 }
00126
00127
00128 selectOppositeFaces
00129 (
00130 nonEmptyFace,
00131 minOpposedness,
00132 faceI,
00133 cellI,
00134 oppositeFaces
00135 );
00136
00137
00138 faceStencilSet.clear();
00139 forAll(oppositeFaces, i)
00140 {
00141 const labelList& fStencil = faceStencil[oppositeFaces[i]];
00142
00143 forAll(fStencil, j)
00144 {
00145 label globalI = fStencil[j];
00146
00147 if (globalI != globalOwn && globalI != globalNei)
00148 {
00149 faceStencilSet.insert(globalI);
00150 }
00151 }
00152 }
00153
00154
00155 if (stencilHasNeighbour)
00156 {
00157 transportedStencil.setSize(faceStencilSet.size()+2);
00158 label n = 0;
00159 transportedStencil[n++] = globalOwn;
00160 transportedStencil[n++] = globalNei;
00161
00162 forAllConstIter(labelHashSet, faceStencilSet, iter)
00163 {
00164 if (iter.key() != globalOwn && iter.key() != globalNei)
00165 {
00166 transportedStencil[n++] = iter.key();
00167 }
00168 }
00169 if (n != transportedStencil.size())
00170 {
00171 FatalErrorIn
00172 (
00173 "extendedUpwindCellToFaceStencil::transportStencil(..)"
00174 ) << "problem:" << faceStencilSet
00175 << abort(FatalError);
00176 }
00177 }
00178 else
00179 {
00180 transportedStencil.setSize(faceStencilSet.size()+1);
00181 label n = 0;
00182 transportedStencil[n++] = globalOwn;
00183
00184 forAllConstIter(labelHashSet, faceStencilSet, iter)
00185 {
00186 if (iter.key() != globalOwn)
00187 {
00188 transportedStencil[n++] = iter.key();
00189 }
00190 }
00191 if (n != transportedStencil.size())
00192 {
00193 FatalErrorIn
00194 (
00195 "extendedUpwindCellToFaceStencil::transportStencil(..)"
00196 ) << "problem:" << faceStencilSet
00197 << abort(FatalError);
00198 }
00199 }
00200 }
00201
00202
00203 void Foam::extendedUpwindCellToFaceStencil::transportStencils
00204 (
00205 const labelListList& faceStencil,
00206 const scalar minOpposedness,
00207 labelListList& ownStencil,
00208 labelListList& neiStencil
00209 )
00210 {
00211 const polyBoundaryMesh& patches = mesh_.boundaryMesh();
00212 const label nBnd = mesh_.nFaces()-mesh_.nInternalFaces();
00213 const labelList& own = mesh_.faceOwner();
00214 const labelList& nei = mesh_.faceNeighbour();
00215
00216
00217 DynamicList<label> oppositeFaces;
00218 labelHashSet faceStencilSet;
00219
00220
00221
00222 boolList nonEmptyFace(mesh_.nFaces(), true);
00223 forAll(patches, patchI)
00224 {
00225 const polyPatch& pp = patches[patchI];
00226
00227 if (isA<emptyPolyPatch>(pp))
00228 {
00229 label faceI = pp.start();
00230 forAll(pp, i)
00231 {
00232 nonEmptyFace[faceI++] = false;
00233 }
00234 }
00235 }
00236
00237
00238
00239
00240
00241
00242 ownStencil.setSize(mesh_.nFaces());
00243
00244
00245 for (label faceI = 0; faceI < mesh_.nInternalFaces(); faceI++)
00246 {
00247
00248 transportStencil
00249 (
00250 nonEmptyFace,
00251 faceStencil,
00252 minOpposedness,
00253 faceI,
00254 own[faceI],
00255 true,
00256 oppositeFaces,
00257 faceStencilSet,
00258 ownStencil[faceI]
00259 );
00260 }
00261
00262 forAll(patches, patchI)
00263 {
00264 const polyPatch& pp = patches[patchI];
00265 label faceI = pp.start();
00266
00267 if (pp.coupled())
00268 {
00269 forAll(pp, i)
00270 {
00271 transportStencil
00272 (
00273 nonEmptyFace,
00274 faceStencil,
00275 minOpposedness,
00276 faceI,
00277 own[faceI],
00278 true,
00279
00280 oppositeFaces,
00281 faceStencilSet,
00282 ownStencil[faceI]
00283 );
00284 faceI++;
00285 }
00286 }
00287 else if (!isA<emptyPolyPatch>(pp))
00288 {
00289 forAll(pp, i)
00290 {
00291
00292 transportStencil
00293 (
00294 nonEmptyFace,
00295 faceStencil,
00296 minOpposedness,
00297 faceI,
00298 own[faceI],
00299 false,
00300
00301 oppositeFaces,
00302 faceStencilSet,
00303 ownStencil[faceI]
00304 );
00305 faceI++;
00306 }
00307 }
00308 }
00309
00310
00311
00312
00313
00314 labelListList neiBndStencil(nBnd);
00315 for (label faceI = mesh_.nInternalFaces(); faceI < mesh_.nFaces(); faceI++)
00316 {
00317 neiBndStencil[faceI-mesh_.nInternalFaces()] = ownStencil[faceI];
00318 }
00319 syncTools::swapBoundaryFaceList(mesh_, neiBndStencil, false);
00320
00321
00322
00323
00324
00325
00326
00327
00328 neiStencil.setSize(mesh_.nFaces());
00329
00330
00331 for (label faceI = 0; faceI < mesh_.nInternalFaces(); faceI++)
00332 {
00333 transportStencil
00334 (
00335 nonEmptyFace,
00336 faceStencil,
00337 minOpposedness,
00338 faceI,
00339 nei[faceI],
00340 true,
00341
00342 oppositeFaces,
00343 faceStencilSet,
00344 neiStencil[faceI]
00345 );
00346 }
00347
00348
00349 forAll(patches, patchI)
00350 {
00351 const polyPatch& pp = patches[patchI];
00352 label faceI = pp.start();
00353
00354 if (pp.coupled())
00355 {
00356 forAll(pp, i)
00357 {
00358 neiStencil[faceI].transfer
00359 (
00360 neiBndStencil[faceI-mesh_.nInternalFaces()]
00361 );
00362 faceI++;
00363 }
00364 }
00365 else
00366 {
00367
00368 }
00369 }
00370 }
00371
00372
00373
00374
00375 Foam::extendedUpwindCellToFaceStencil::extendedUpwindCellToFaceStencil
00376 (
00377 const cellToFaceStencil& stencil,
00378 const bool pureUpwind,
00379 const scalar minOpposedness
00380 )
00381 :
00382 extendedCellToFaceStencil(stencil.mesh()),
00383 pureUpwind_(pureUpwind)
00384 {
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414 transportStencils
00415 (
00416 stencil,
00417 minOpposedness,
00418 ownStencil_,
00419 neiStencil_
00420 );
00421
00422 ownMapPtr_ = calcDistributeMap
00423 (
00424 stencil.mesh(),
00425 stencil.globalNumbering(),
00426 ownStencil_
00427 );
00428
00429 neiMapPtr_ = calcDistributeMap
00430 (
00431 stencil.mesh(),
00432 stencil.globalNumbering(),
00433 neiStencil_
00434 );
00435
00436
00437 if (pureUpwind_)
00438 {
00439 const fvMesh& mesh = dynamic_cast<const fvMesh&>(stencil.mesh());
00440
00441 List<List<point> > stencilPoints(ownStencil_.size());
00442
00443
00444
00445
00446 collectData(ownMapPtr_(), ownStencil_, mesh.C(), stencilPoints);
00447
00448
00449 forAll(stencilPoints, faceI)
00450 {
00451 const point& fc = mesh.faceCentres()[faceI];
00452 const vector& fArea = mesh.faceAreas()[faceI];
00453
00454 const List<point>& points = stencilPoints[faceI];
00455 const labelList& stencil = ownStencil_[faceI];
00456
00457 DynamicList<label> newStencil(stencil.size());
00458 forAll(points, i)
00459 {
00460 if (((points[i]-fc) & fArea) < 0)
00461 {
00462 newStencil.append(stencil[i]);
00463 }
00464 }
00465 if (newStencil.size() != stencil.size())
00466 {
00467 ownStencil_[faceI].transfer(newStencil);
00468 }
00469 }
00470
00471
00472
00473
00474
00475 collectData(neiMapPtr_(), neiStencil_, mesh.C(), stencilPoints);
00476
00477
00478 forAll(stencilPoints, faceI)
00479 {
00480 const point& fc = mesh.faceCentres()[faceI];
00481 const vector& fArea = mesh.faceAreas()[faceI];
00482
00483 const List<point>& points = stencilPoints[faceI];
00484 const labelList& stencil = neiStencil_[faceI];
00485
00486 DynamicList<label> newStencil(stencil.size());
00487 forAll(points, i)
00488 {
00489 if (((points[i]-fc) & fArea) > 0)
00490 {
00491 newStencil.append(stencil[i]);
00492 }
00493 }
00494 if (newStencil.size() != stencil.size())
00495 {
00496 neiStencil_[faceI].transfer(newStencil);
00497 }
00498 }
00499
00500
00501
00502 }
00503 }
00504
00505
00506 Foam::extendedUpwindCellToFaceStencil::extendedUpwindCellToFaceStencil
00507 (
00508 const cellToFaceStencil& stencil
00509 )
00510 :
00511 extendedCellToFaceStencil(stencil.mesh()),
00512 pureUpwind_(true)
00513 {
00514
00515
00516 ownStencil_ = stencil;
00517
00518 ownMapPtr_ = calcDistributeMap
00519 (
00520 stencil.mesh(),
00521 stencil.globalNumbering(),
00522 ownStencil_
00523 );
00524
00525 const fvMesh& mesh = dynamic_cast<const fvMesh&>(stencil.mesh());
00526
00527 List<List<point> > stencilPoints(ownStencil_.size());
00528 collectData(ownMapPtr_(), ownStencil_, mesh.C(), stencilPoints);
00529
00530
00531 neiStencil_.setSize(ownStencil_.size());
00532
00533 forAll(stencilPoints, faceI)
00534 {
00535 const point& fc = mesh.faceCentres()[faceI];
00536 const vector& fArea = mesh.faceAreas()[faceI];
00537
00538 const List<point>& points = stencilPoints[faceI];
00539 const labelList& stencil = ownStencil_[faceI];
00540
00541 DynamicList<label> newOwnStencil(stencil.size());
00542 DynamicList<label> newNeiStencil(stencil.size());
00543 forAll(points, i)
00544 {
00545 if (((points[i]-fc) & fArea) > 0)
00546 {
00547 newNeiStencil.append(stencil[i]);
00548 }
00549 else
00550 {
00551 newOwnStencil.append(stencil[i]);
00552 }
00553 }
00554 if (newNeiStencil.size() > 0)
00555 {
00556 ownStencil_[faceI].transfer(newOwnStencil);
00557 neiStencil_[faceI].transfer(newNeiStencil);
00558 }
00559 }
00560
00561
00562 neiMapPtr_.reset(new mapDistribute(ownMapPtr_()));
00563 }
00564
00565
00566