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 "removeCells.H"
00028 #include "polyMesh.H"
00029 #include "polyTopoChange.H"
00030 #include "polyRemoveCell.H"
00031 #include "polyRemoveFace.H"
00032 #include "polyModifyFace.H"
00033 #include "polyRemovePoint.H"
00034 #include "syncTools.H"
00035
00036
00037
00038 namespace Foam
00039 {
00040
00041 defineTypeNameAndDebug(removeCells, 0);
00042
00043 }
00044
00045
00046
00047
00048 void Foam::removeCells::uncount
00049 (
00050 const labelList& f,
00051 labelList& nUsage
00052 )
00053 {
00054 forAll(f, fp)
00055 {
00056 nUsage[f[fp]]--;
00057 }
00058 }
00059
00060
00061
00062
00063
00064 Foam::removeCells::removeCells
00065 (
00066 const polyMesh& mesh,
00067 const bool syncPar
00068 )
00069 :
00070 mesh_(mesh),
00071 syncPar_(syncPar)
00072 {}
00073
00074
00075
00076
00077
00078
00079
00080
00081 Foam::labelList Foam::removeCells::getExposedFaces
00082 (
00083 const labelList& cellLabels
00084 ) const
00085 {
00086
00087 boolList removedCell(mesh_.nCells(), false);
00088
00089
00090 forAll(cellLabels, i)
00091 {
00092 removedCell[cellLabels[i]] = true;
00093 }
00094
00095
00096 const labelList& faceOwner = mesh_.faceOwner();
00097 const labelList& faceNeighbour = mesh_.faceNeighbour();
00098
00099
00100 labelList nCellsUsingFace(mesh_.nFaces(), 0);
00101
00102 for (label faceI = 0; faceI < mesh_.nInternalFaces(); faceI++)
00103 {
00104 label own = faceOwner[faceI];
00105 label nei = faceNeighbour[faceI];
00106
00107 if (!removedCell[own])
00108 {
00109 nCellsUsingFace[faceI]++;
00110 }
00111 if (!removedCell[nei])
00112 {
00113 nCellsUsingFace[faceI]++;
00114 }
00115 }
00116
00117 for (label faceI = mesh_.nInternalFaces(); faceI < mesh_.nFaces(); faceI++)
00118 {
00119 label own = faceOwner[faceI];
00120
00121 if (!removedCell[own])
00122 {
00123 nCellsUsingFace[faceI]++;
00124 }
00125 }
00126
00127
00128 if (syncPar_)
00129 {
00130 syncTools::syncFaceList
00131 (
00132 mesh_,
00133 nCellsUsingFace,
00134 plusEqOp<label>(),
00135 false
00136 );
00137 }
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148 DynamicList<label> exposedFaces(mesh_.nFaces()/10);
00149
00150 for (label faceI = 0; faceI < mesh_.nInternalFaces(); faceI++)
00151 {
00152 if (nCellsUsingFace[faceI] == 1)
00153 {
00154 exposedFaces.append(faceI);
00155 }
00156 }
00157
00158 const polyBoundaryMesh& patches = mesh_.boundaryMesh();
00159
00160 forAll(patches, patchI)
00161 {
00162 const polyPatch& pp = patches[patchI];
00163
00164 if (pp.coupled())
00165 {
00166 label faceI = pp.start();
00167
00168 forAll(pp, i)
00169 {
00170 label own = faceOwner[faceI];
00171
00172 if (nCellsUsingFace[faceI] == 1 && !removedCell[own])
00173 {
00174
00175
00176 exposedFaces.append(faceI);
00177 }
00178
00179 faceI++;
00180 }
00181 }
00182 }
00183
00184 return exposedFaces.shrink();
00185 }
00186
00187
00188 void Foam::removeCells::setRefinement
00189 (
00190 const labelList& cellLabels,
00191 const labelList& exposedFaceLabels,
00192 const labelList& exposedPatchIDs,
00193 polyTopoChange& meshMod
00194 ) const
00195 {
00196 const polyBoundaryMesh& patches = mesh_.boundaryMesh();
00197
00198 if (exposedFaceLabels.size() != exposedPatchIDs.size())
00199 {
00200 FatalErrorIn
00201 (
00202 "removeCells::setRefinement(const labelList&"
00203 ", const labelList&, const labelList&, polyTopoChange&)"
00204 ) << "Size of exposedFaceLabels " << exposedFaceLabels.size()
00205 << " differs from size of exposedPatchIDs "
00206 << exposedPatchIDs.size()
00207 << abort(FatalError);
00208 }
00209
00210
00211 labelList newPatchID(mesh_.nFaces(), -1);
00212
00213 forAll(exposedFaceLabels, i)
00214 {
00215 label patchI = exposedPatchIDs[i];
00216
00217 if (patchI < 0 || patchI >= patches.size())
00218 {
00219 FatalErrorIn
00220 (
00221 "removeCells::setRefinement(const labelList&"
00222 ", const labelList&, const labelList&, polyTopoChange&)"
00223 ) << "Invalid patch " << patchI
00224 << " for exposed face " << exposedFaceLabels[i] << endl
00225 << "Valid patches 0.." << patches.size()-1
00226 << abort(FatalError);
00227 }
00228
00229 if (patches[patchI].coupled())
00230 {
00231 FatalErrorIn
00232 (
00233 "removeCells::setRefinement(const labelList&"
00234 ", const labelList&, const labelList&, polyTopoChange&)"
00235 ) << "Trying to put exposed face " << exposedFaceLabels[i]
00236 << " into a coupled patch : " << patches[patchI].name()
00237 << endl
00238 << "This is illegal."
00239 << abort(FatalError);
00240 }
00241
00242 newPatchID[exposedFaceLabels[i]] = patchI;
00243 }
00244
00245
00246
00247 boolList removedCell(mesh_.nCells(), false);
00248
00249
00250
00251 forAll(cellLabels, i)
00252 {
00253 label cellI = cellLabels[i];
00254
00255 removedCell[cellI] = true;
00256
00257
00258
00259
00260 meshMod.setAction(polyRemoveCell(cellI));
00261 }
00262
00263
00264
00265
00266
00267 const faceList& faces = mesh_.faces();
00268 const labelList& faceOwner = mesh_.faceOwner();
00269 const labelList& faceNeighbour = mesh_.faceNeighbour();
00270 const faceZoneMesh& faceZones = mesh_.faceZones();
00271
00272
00273
00274 labelList nFacesUsingPoint(mesh_.nPoints(), 0);
00275
00276 forAll(faces, faceI)
00277 {
00278 const face& f = faces[faceI];
00279
00280 forAll(f, fp)
00281 {
00282 nFacesUsingPoint[f[fp]]++;
00283 }
00284 }
00285
00286
00287 for (label faceI = 0; faceI < mesh_.nInternalFaces(); faceI++)
00288 {
00289 const face& f = faces[faceI];
00290 label own = faceOwner[faceI];
00291 label nei = faceNeighbour[faceI];
00292
00293 if (removedCell[own])
00294 {
00295 if (removedCell[nei])
00296 {
00297
00298
00299
00300
00301 meshMod.setAction(polyRemoveFace(faceI));
00302 uncount(f, nFacesUsingPoint);
00303 }
00304 else
00305 {
00306 if (newPatchID[faceI] == -1)
00307 {
00308 FatalErrorIn
00309 (
00310 "removeCells::setRefinement(const labelList&"
00311 ", const labelList&, const labelList&"
00312 ", polyTopoChange&)"
00313 ) << "No patchID provided for exposed face " << faceI
00314 << " on cell " << nei << nl
00315 << "Did you provide patch IDs for all exposed faces?"
00316 << abort(FatalError);
00317 }
00318
00319
00320
00321 label zoneID = faceZones.whichZone(faceI);
00322 bool zoneFlip = false;
00323
00324 if (zoneID >= 0)
00325 {
00326 const faceZone& fZone = faceZones[zoneID];
00327 zoneFlip = fZone.flipMap()[fZone.whichFace(faceI)];
00328 }
00329
00330
00331
00332
00333
00334 meshMod.setAction
00335 (
00336 polyModifyFace
00337 (
00338 f.reverseFace(),
00339 faceI,
00340 nei,
00341 -1,
00342 false,
00343 newPatchID[faceI],
00344 false,
00345 zoneID,
00346 zoneFlip
00347 )
00348 );
00349 }
00350 }
00351 else if (removedCell[nei])
00352 {
00353 if (newPatchID[faceI] == -1)
00354 {
00355 FatalErrorIn
00356 (
00357 "removeCells::setRefinement(const labelList&"
00358 ", const labelList&, const labelList&"
00359 ", polyTopoChange&)"
00360 ) << "No patchID provided for exposed face " << faceI
00361 << " on cell " << own << nl
00362 << "Did you provide patch IDs for all exposed faces?"
00363 << abort(FatalError);
00364 }
00365
00366
00367
00368
00369
00370
00371 label zoneID = faceZones.whichZone(faceI);
00372 bool zoneFlip = false;
00373
00374 if (zoneID >= 0)
00375 {
00376 const faceZone& fZone = faceZones[zoneID];
00377 zoneFlip = fZone.flipMap()[fZone.whichFace(faceI)];
00378 }
00379
00380 meshMod.setAction
00381 (
00382 polyModifyFace
00383 (
00384 f,
00385 faceI,
00386 own,
00387 -1,
00388 false,
00389 newPatchID[faceI],
00390 false,
00391 zoneID,
00392 zoneFlip
00393 )
00394 );
00395 }
00396 }
00397
00398 forAll(patches, patchI)
00399 {
00400 const polyPatch& pp = patches[patchI];
00401
00402 if (pp.coupled())
00403 {
00404 label faceI = pp.start();
00405
00406 forAll(pp, i)
00407 {
00408 if (newPatchID[faceI] != -1)
00409 {
00410
00411
00412
00413
00414 label zoneID = faceZones.whichZone(faceI);
00415 bool zoneFlip = false;
00416
00417 if (zoneID >= 0)
00418 {
00419 const faceZone& fZone = faceZones[zoneID];
00420 zoneFlip = fZone.flipMap()[fZone.whichFace(faceI)];
00421 }
00422
00423 meshMod.setAction
00424 (
00425 polyModifyFace
00426 (
00427 faces[faceI],
00428 faceI,
00429 faceOwner[faceI],
00430 -1,
00431 false,
00432 newPatchID[faceI],
00433 false,
00434 zoneID,
00435 zoneFlip
00436 )
00437 );
00438 }
00439 else if (removedCell[faceOwner[faceI]])
00440 {
00441
00442
00443
00444
00445
00446 meshMod.setAction(polyRemoveFace(faceI));
00447 uncount(faces[faceI], nFacesUsingPoint);
00448 }
00449
00450 faceI++;
00451 }
00452 }
00453 else
00454 {
00455 label faceI = pp.start();
00456
00457 forAll(pp, i)
00458 {
00459 if (newPatchID[faceI] != -1)
00460 {
00461 FatalErrorIn
00462 (
00463 "removeCells::setRefinement(const labelList&"
00464 ", const labelList&, const labelList&"
00465 ", polyTopoChange&)"
00466 ) << "new patchID provided for boundary face " << faceI
00467 << " even though it is not on a coupled face."
00468 << abort(FatalError);
00469 }
00470
00471 if (removedCell[faceOwner[faceI]])
00472 {
00473
00474
00475
00476
00477
00478 meshMod.setAction(polyRemoveFace(faceI));
00479 uncount(faces[faceI], nFacesUsingPoint);
00480 }
00481
00482 faceI++;
00483 }
00484 }
00485 }
00486
00487
00488
00489
00490
00491 forAll(nFacesUsingPoint, pointI)
00492 {
00493 if (nFacesUsingPoint[pointI] == 0)
00494 {
00495
00496
00497
00498 meshMod.setAction(polyRemovePoint(pointI));
00499 }
00500 else if (nFacesUsingPoint[pointI] == 1)
00501 {
00502 WarningIn
00503 (
00504 "removeCells::setRefinement(const labelList&"
00505 ", const labelList&, const labelList&"
00506 ", polyTopoChange&)"
00507 ) << "point " << pointI << " at coordinate "
00508 << mesh_.points()[pointI]
00509 << " is only used by 1 face after removing cells."
00510 << " This probably results in an illegal mesh."
00511 << endl;
00512 }
00513 }
00514 }
00515
00516
00517