Go to the documentation of this file.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 "layerAdditionRemoval.H"
00030 #include <OpenFOAM/polyMesh.H>
00031 #include <OpenFOAM/primitiveMesh.H>
00032 #include <dynamicMesh/polyTopoChange.H>
00033 #include <OpenFOAM/oppositeFace.H>
00034 #include <dynamicMesh/polyTopoChanger.H>
00035 #include <dynamicMesh/polyRemoveCell.H>
00036 #include <dynamicMesh/polyRemoveFace.H>
00037 #include <dynamicMesh/polyRemovePoint.H>
00038 #include <dynamicMesh/polyModifyFace.H>
00039
00040
00041
00042 bool Foam::layerAdditionRemoval::validCollapse() const
00043 {
00044
00045
00046
00047 if (debug)
00048 {
00049 Pout << "Checking layer collapse for object " << name() << endl;
00050 }
00051
00052
00053 const polyMesh& mesh = topoChanger().mesh();
00054
00055 const labelList& ftc = facesPairing();
00056 const labelList& mf = mesh.faceZones()[faceZoneID_.index()];
00057
00058 label nBoundaryHits = 0;
00059
00060 forAll (mf, faceI)
00061 {
00062 if
00063 (
00064 !mesh.isInternalFace(mf[faceI])
00065 && !mesh.isInternalFace(ftc[faceI])
00066 )
00067 {
00068 nBoundaryHits++;
00069 }
00070 }
00071
00072
00073 if (debug)
00074 {
00075 Pout<< "Finished checking layer collapse for object "
00076 << name() <<". Number of boundary-on-boundary hits: "
00077 << nBoundaryHits << endl;
00078 }
00079
00080 if (returnReduce(nBoundaryHits, sumOp<label>()) > 0)
00081 {
00082 return false;
00083 }
00084 else
00085 {
00086 return true;
00087 }
00088 }
00089
00090 void Foam::layerAdditionRemoval::removeCellLayer
00091 (
00092 polyTopoChange& ref
00093 ) const
00094 {
00095
00096
00097
00098
00099
00100
00101
00102
00103 if (debug)
00104 {
00105 Pout << "Removing the cell layer for object " << name() << endl;
00106 }
00107
00108 const polyMesh& mesh = topoChanger().mesh();
00109
00110 const labelList& ptc = pointsPairing();
00111 const labelList& ftc = facesPairing();
00112
00113
00114 const labelList& mc =
00115 topoChanger().mesh().faceZones()[faceZoneID_.index()].masterCells();
00116
00117 forAll (mc, cellI)
00118 {
00119 ref.setAction(polyRemoveCell(mc[cellI]));
00120 }
00121
00122
00123
00124 labelHashSet facesToRemoveMap(mc.size()*primitiveMesh::facesPerCell_);
00125
00126 const cellList& cells = mesh.cells();
00127
00128 forAll (mc, cellI)
00129 {
00130 const cell& curCell = cells[mc[cellI]];
00131
00132 forAll (curCell, faceI)
00133 {
00134
00135 if
00136 (
00137 mesh.faceZones().whichZone(curCell[faceI])
00138 != faceZoneID_.index()
00139 )
00140 {
00141 facesToRemoveMap.insert(curCell[faceI]);
00142 }
00143 }
00144 }
00145
00146 forAllConstIter(labelHashSet, facesToRemoveMap, iter)
00147 {
00148 ref.setAction(polyRemoveFace(iter.key()));
00149 }
00150
00151
00152 forAll (ptc, pointI)
00153 {
00154 ref.setAction(polyRemovePoint(ptc[pointI]));
00155 }
00156
00157
00158
00159
00160
00161
00162
00163
00164 Map<label> removedPointMap(2*ptc.size());
00165
00166 const labelList& meshPoints =
00167 mesh.faceZones()[faceZoneID_.index()]().meshPoints();
00168
00169 forAll (ptc, pointI)
00170 {
00171 removedPointMap.insert(ptc[pointI], meshPoints[pointI]);
00172 }
00173
00174 const labelListList& pf = mesh.pointFaces();
00175
00176 const faceList& faces = mesh.faces();
00177 const labelList& own = mesh.faceOwner();
00178 const labelList& nei = mesh.faceNeighbour();
00179
00180
00181 labelHashSet facesToModify(ptc.size()*primitiveMesh::facesPerPoint_);
00182
00183 forAll (ptc, pointI)
00184 {
00185 const labelList& curFaces = pf[ptc[pointI]];
00186
00187 forAll (curFaces, faceI)
00188 {
00189 if (!facesToRemoveMap.found(curFaces[faceI]))
00190 {
00191 facesToModify.insert(curFaces[faceI]);
00192 }
00193 }
00194 }
00195
00196 labelList ftm = facesToModify.toc();
00197
00198
00199
00200 forAll (ftm, faceI)
00201 {
00202
00203
00204
00205 label curFaceID = ftm[faceI];
00206
00207 face newFace(faces[curFaceID]);
00208
00209 forAll (newFace, pointI)
00210 {
00211 Map<label>::iterator rpmIter =
00212 removedPointMap.find(newFace[pointI]);
00213
00214 if (rpmIter != removedPointMap.end())
00215 {
00216
00217 newFace[pointI] = rpmIter();
00218 }
00219 }
00220
00221
00222
00223
00224
00225
00226 label modifiedFaceZone = mesh.faceZones().whichZone(curFaceID);
00227 bool modifiedFaceZoneFlip = false;
00228
00229 if (modifiedFaceZone >= 0)
00230 {
00231 modifiedFaceZoneFlip =
00232 mesh.faceZones()[modifiedFaceZone].flipMap()
00233 [
00234 mesh.faceZones()[modifiedFaceZone].whichFace(curFaceID)
00235 ];
00236 }
00237
00238 label newNei;
00239
00240 if (curFaceID < mesh.nInternalFaces())
00241 {
00242 newNei = nei[curFaceID];
00243 }
00244 else
00245 {
00246 newNei = -1;
00247 }
00248
00249
00250 ref.setAction
00251 (
00252 polyModifyFace
00253 (
00254 newFace,
00255 curFaceID,
00256 own[curFaceID],
00257 newNei,
00258 false,
00259 mesh.boundaryMesh().whichPatch(curFaceID),
00260 false,
00261 modifiedFaceZone,
00262 modifiedFaceZoneFlip
00263 )
00264 );
00265 }
00266
00267
00268
00269 const labelList& mf = mesh.faceZones()[faceZoneID_.index()];
00270 const boolList& mfFlip = mesh.faceZones()[faceZoneID_.index()].flipMap();
00271
00272 forAll (mf, faceI)
00273 {
00274
00275
00276 label masterSideCell = own[mf[faceI]];
00277
00278 if (masterSideCell == mc[faceI])
00279 {
00280
00281
00282 masterSideCell = nei[mf[faceI]];
00283 }
00284
00285 label slaveSideCell = own[ftc[faceI]];
00286
00287 if (slaveSideCell == mc[faceI])
00288 {
00289
00290
00291 slaveSideCell = nei[ftc[faceI]];
00292 }
00293
00294
00295 label newOwner = -1;
00296 label newNeighbour = -1;
00297 bool flipFace = false;
00298 label newPatchID = -1;
00299 label newZoneID = -1;
00300
00301
00302
00303
00304
00305 if (!mesh.isInternalFace(mf[faceI]))
00306 {
00307
00308 newOwner = slaveSideCell;
00309 newNeighbour = -1;
00310 flipFace = false;
00311 newPatchID = mesh.boundaryMesh().whichPatch(mf[faceI]);
00312 newZoneID = mesh.faceZones().whichZone(mf[faceI]);
00313 }
00314 else if (!mesh.isInternalFace(ftc[faceI]))
00315 {
00316
00317 newOwner = slaveSideCell;
00318 newNeighbour = -1;
00319
00320
00321 if (own[mf[faceI]] == slaveSideCell)
00322 {
00323 flipFace = false;
00324 }
00325 else
00326 {
00327 flipFace = true;
00328 }
00329
00330 newPatchID = mesh.boundaryMesh().whichPatch(ftc[faceI]);
00331
00332
00333 newZoneID = mesh.faceZones().whichZone(mf[faceI]);
00334 }
00335 else
00336 {
00337
00338
00339 newOwner = min(masterSideCell, slaveSideCell);
00340 newNeighbour = max(masterSideCell, slaveSideCell);
00341
00342 if (newOwner == own[mf[faceI]] || newNeighbour == nei[mf[faceI]])
00343 {
00344 flipFace = false;
00345 }
00346 else
00347 {
00348 flipFace = true;
00349 }
00350
00351 newPatchID = -1;
00352
00353
00354 newZoneID = mesh.faceZones().whichZone(mf[faceI]);
00355 }
00356
00357
00358 face newFace = faces[mf[faceI]];
00359 bool zoneFlip = mfFlip[faceI];
00360
00361 if (flipFace)
00362 {
00363 newFace = newFace.reverseFace();
00364 zoneFlip = !zoneFlip;
00365 }
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377 ref.setAction
00378 (
00379 polyModifyFace
00380 (
00381 newFace,
00382 mf[faceI],
00383 newOwner,
00384 newNeighbour,
00385 flipFace,
00386 newPatchID,
00387 false,
00388 newZoneID,
00389 zoneFlip
00390 )
00391 );
00392 }
00393 }
00394
00395
00396