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 "layerAdditionRemoval.H"
00028 #include "polyMesh.H"
00029 #include "primitiveMesh.H"
00030 #include "polyTopoChange.H"
00031 #include "polyTopoChanger.H"
00032 #include "polyAddPoint.H"
00033 #include "polyAddCell.H"
00034 #include "polyAddFace.H"
00035 #include "polyModifyFace.H"
00036
00037
00038
00039
00040 Foam::tmp<Foam::vectorField> Foam::layerAdditionRemoval::extrusionDir() const
00041 {
00042 const polyMesh& mesh = topoChanger().mesh();
00043 const primitiveFacePatch& masterFaceLayer =
00044 mesh.faceZones()[faceZoneID_.index()]();
00045
00046 const pointField& points = mesh.points();
00047 const labelList& mp = masterFaceLayer.meshPoints();
00048
00049 tmp<vectorField> textrusionDir(new vectorField(mp.size()));
00050 vectorField& extrusionDir = textrusionDir();
00051
00052 if (setLayerPairing())
00053 {
00054 if (debug)
00055 {
00056 Pout<< "void layerAdditionRemoval::extrusionDir() const "
00057 << " for object " << name() << " : "
00058 << "Using edges for point insertion" << endl;
00059 }
00060
00061
00062 const labelList& ptc = pointsPairing();
00063
00064 forAll (extrusionDir, mpI)
00065 {
00066 extrusionDir[mpI] = points[ptc[mpI]] - points[mp[mpI]];
00067 }
00068 }
00069 else
00070 {
00071 if (debug)
00072 {
00073 Pout<< "void layerAdditionRemoval::extrusionDir() const "
00074 << " for object " << name() << " : "
00075 << "A valid layer could not be found in front of "
00076 << "the addition face layer. Using face-based "
00077 << "point normals for point addition"
00078 << endl;
00079 }
00080
00081 extrusionDir = minLayerThickness_*masterFaceLayer.pointNormals();
00082 }
00083 return textrusionDir;
00084 }
00085
00086
00087 void Foam::layerAdditionRemoval::addCellLayer
00088 (
00089 polyTopoChange& ref
00090 ) const
00091 {
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106 if (debug)
00107 {
00108 Pout<< "void layerAdditionRemoval::addCellLayer("
00109 << "polyTopoChange& ref) const for object " << name() << " : "
00110 << "Adding cell layer" << endl;
00111 }
00112
00113
00114
00115 const polyMesh& mesh = topoChanger().mesh();
00116 const primitiveFacePatch& masterFaceLayer =
00117 mesh.faceZones()[faceZoneID_.index()]();
00118
00119 const pointField& points = mesh.points();
00120 const labelList& mp = masterFaceLayer.meshPoints();
00121
00122
00123
00124 tmp<vectorField> tpointOffsets = extrusionDir();
00125
00126
00127 labelList addedPoints(mp.size());
00128
00129 forAll (mp, pointI)
00130 {
00131
00132
00133 addedPoints[pointI] =
00134 ref.setAction
00135 (
00136 polyAddPoint
00137 (
00138 points[mp[pointI]]
00139 + addDelta_*tpointOffsets()[pointI],
00140 mp[pointI],
00141 -1,
00142 true
00143 )
00144 );
00145 }
00146
00147
00148
00149
00150 const labelList& mc =
00151 mesh.faceZones()[faceZoneID_.index()].masterCells();
00152 const labelList& sc =
00153 mesh.faceZones()[faceZoneID_.index()].slaveCells();
00154
00155 const labelList& mf = mesh.faceZones()[faceZoneID_.index()];
00156 const boolList& mfFlip = mesh.faceZones()[faceZoneID_.index()].flipMap();
00157
00158 const labelList& own = mesh.faceOwner();
00159 const labelList& nei = mesh.faceNeighbour();
00160
00161 labelList addedCells(mf.size());
00162
00163 forAll (mf, faceI)
00164 {
00165 addedCells[faceI] =
00166 ref.setAction
00167 (
00168 polyAddCell
00169 (
00170 -1,
00171 -1,
00172 mf[faceI],
00173 -1,
00174 -1
00175 )
00176 );
00177 }
00178
00179
00180
00181
00182 const faceList& zoneFaces = masterFaceLayer.localFaces();
00183
00184
00185
00186
00187
00188
00189
00190
00191 forAll (zoneFaces, faceI)
00192 {
00193 const face oldFace = zoneFaces[faceI].reverseFace();
00194
00195 face newFace(oldFace.size());
00196
00197 forAll (oldFace, pointI)
00198 {
00199 newFace[pointI] = addedPoints[oldFace[pointI]];
00200 }
00201
00202 bool flipFaceFlux = false;
00203
00204
00205 if
00206 (
00207 mc[faceI] == nei[mf[faceI]]
00208 || !mesh.isInternalFace(mf[faceI])
00209 )
00210 {
00211 flipFaceFlux = true;
00212 }
00213
00214
00215 ref.setAction
00216 (
00217 polyAddFace
00218 (
00219 newFace,
00220 mc[faceI],
00221 addedCells[faceI],
00222 -1,
00223 -1,
00224 mf[faceI],
00225 flipFaceFlux,
00226 -1,
00227 -1,
00228 false
00229 )
00230 );
00231
00232
00233 }
00234
00235
00236
00237 const faceList& faces = mesh.faces();
00238
00239 forAll (mf, faceI)
00240 {
00241 const label curfaceID = mf[faceI];
00242
00243
00244
00245 if (!mesh.isInternalFace(curfaceID))
00246 {
00247 ref.setAction
00248 (
00249 polyModifyFace
00250 (
00251 faces[curfaceID],
00252 curfaceID,
00253 addedCells[faceI],
00254 -1,
00255 false,
00256 mesh.boundaryMesh().whichPatch(curfaceID),
00257 false,
00258 faceZoneID_.index(),
00259 mfFlip[faceI]
00260 )
00261 );
00262
00263 }
00264
00265
00266
00267 else if (sc[faceI] == own[curfaceID])
00268 {
00269
00270 ref.setAction
00271 (
00272 polyModifyFace
00273 (
00274 faces[curfaceID],
00275 curfaceID,
00276 own[curfaceID],
00277 addedCells[faceI],
00278 false,
00279 mesh.boundaryMesh().whichPatch(curfaceID),
00280 false,
00281 faceZoneID_.index(),
00282 mfFlip[faceI]
00283 )
00284 );
00285
00286
00287 }
00288 else
00289 {
00290
00291 ref.setAction
00292 (
00293 polyModifyFace
00294 (
00295 faces[curfaceID].reverseFace(),
00296 curfaceID,
00297 nei[curfaceID],
00298 addedCells[faceI],
00299 true,
00300 mesh.boundaryMesh().whichPatch(curfaceID),
00301 false,
00302 faceZoneID_.index(),
00303 !mfFlip[faceI]
00304 )
00305 );
00306
00307 }
00308 }
00309
00310
00311
00312 const edgeList& zoneLocalEdges = masterFaceLayer.edges();
00313
00314 const labelListList& edgeFaces = masterFaceLayer.edgeFaces();
00315
00316 label nInternalEdges = masterFaceLayer.nInternalEdges();
00317
00318 const labelList& meshEdges =
00319 mesh.faceZones()[faceZoneID_.index()].meshEdges();
00320
00321
00322 for (label curEdgeID = 0; curEdgeID < nInternalEdges; curEdgeID++)
00323 {
00324 face newFace(4);
00325
00326 newFace[0] = mp[zoneLocalEdges[curEdgeID].start()];
00327 newFace[1] = mp[zoneLocalEdges[curEdgeID].end()];
00328 newFace[2] = addedPoints[zoneLocalEdges[curEdgeID].end()];
00329 newFace[3] = addedPoints[zoneLocalEdges[curEdgeID].start()];
00330
00331 ref.setAction
00332 (
00333 polyAddFace
00334 (
00335 newFace,
00336 addedCells[edgeFaces[curEdgeID][0]],
00337 addedCells[edgeFaces[curEdgeID][1]],
00338 -1,
00339 meshEdges[curEdgeID],
00340 -1,
00341 false,
00342 -1,
00343 -1,
00344 false
00345 )
00346 );
00347
00348
00349 }
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360 const labelListList& meshEdgeFaces = mesh.edgeFaces();
00361
00362 const faceZoneMesh& zoneMesh = mesh.faceZones();
00363
00364
00365
00366 for
00367 (
00368 label curEdgeID = nInternalEdges;
00369 curEdgeID < zoneLocalEdges.size();
00370 curEdgeID++
00371 )
00372 {
00373 face newFace(4);
00374 newFace[0] = mp[zoneLocalEdges[curEdgeID].start()];
00375 newFace[1] = mp[zoneLocalEdges[curEdgeID].end()];
00376 newFace[2] = addedPoints[zoneLocalEdges[curEdgeID].end()];
00377 newFace[3] = addedPoints[zoneLocalEdges[curEdgeID].start()];
00378
00379
00380 const labelList& curFaces = meshEdgeFaces[meshEdges[curEdgeID]];
00381
00382 label patchID = -1;
00383 label zoneID = -1;
00384
00385 forAll (curFaces, faceI)
00386 {
00387 const label cf = curFaces[faceI];
00388
00389 if (!mesh.isInternalFace(cf))
00390 {
00391
00392 if (zoneMesh.whichZone(cf) != faceZoneID_.index())
00393 {
00394
00395 patchID = mesh.boundaryMesh().whichPatch(cf);
00396 zoneID = mesh.faceZones().whichZone(cf);
00397
00398 break;
00399 }
00400 }
00401 }
00402
00403 if (patchID < 0)
00404 {
00405 FatalErrorIn
00406 (
00407 "void Foam::layerAdditionRemoval::setRefinement("
00408 "polyTopoChange& ref)"
00409 ) << "Cannot find patch for edge " << meshEdges[curEdgeID]
00410 << ". Edge: " << mesh.edges()[meshEdges[curEdgeID]]
00411 << abort(FatalError);
00412 }
00413
00414 ref.setAction
00415 (
00416 polyAddFace
00417 (
00418 newFace,
00419 addedCells[edgeFaces[curEdgeID][0]],
00420 -1,
00421 -1,
00422 meshEdges[curEdgeID],
00423 -1,
00424 false,
00425 patchID,
00426 zoneID,
00427 false
00428 )
00429 );
00430
00431 }
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447 labelHashSet masterCellFaceMap(primitiveMesh::facesPerCell_*mc.size());
00448
00449 const cellList& cells = mesh.cells();
00450
00451 forAll (mc, cellI)
00452 {
00453 const labelList& curFaces = cells[mc[cellI]];
00454
00455 forAll (curFaces, faceI)
00456 {
00457
00458 if (zoneMesh.whichZone(curFaces[faceI]) != faceZoneID_.index())
00459 {
00460 masterCellFaceMap.insert(curFaces[faceI]);
00461 }
00462 }
00463 }
00464
00465
00466 Map<label> masterLayerPointMap(2*mp.size());
00467
00468 forAll (mp, pointI)
00469 {
00470 masterLayerPointMap.insert
00471 (
00472 mp[pointI],
00473 addedPoints[pointI]
00474 );
00475 }
00476
00477
00478 const labelList masterCellFaces = masterCellFaceMap.toc();
00479
00480 forAll (masterCellFaces, faceI)
00481 {
00482
00483
00484
00485 const label curFaceID = masterCellFaces[faceI];
00486
00487 const face& oldFace = faces[curFaceID];
00488
00489 face newFace(oldFace.size());
00490
00491 bool changed = false;
00492
00493 forAll (oldFace, pointI)
00494 {
00495 if (masterLayerPointMap.found(oldFace[pointI]))
00496 {
00497 changed = true;
00498
00499 newFace[pointI] = masterLayerPointMap.find(oldFace[pointI])();
00500 }
00501 else
00502 {
00503 newFace[pointI] = oldFace[pointI];
00504 }
00505 }
00506
00507
00508 if (changed)
00509 {
00510
00511 label modifiedFaceZone = mesh.faceZones().whichZone(curFaceID);
00512 bool modifiedFaceZoneFlip = false;
00513
00514 if (modifiedFaceZone >= 0)
00515 {
00516 modifiedFaceZoneFlip =
00517 mesh.faceZones()[modifiedFaceZone].flipMap()
00518 [
00519 mesh.faceZones()[modifiedFaceZone].whichFace(curFaceID)
00520 ];
00521 }
00522
00523 if (mesh.isInternalFace(curFaceID))
00524 {
00525 ref.setAction
00526 (
00527 polyModifyFace
00528 (
00529 newFace,
00530 curFaceID,
00531 own[curFaceID],
00532 nei[curFaceID],
00533 false,
00534 -1,
00535 false,
00536 modifiedFaceZone,
00537 modifiedFaceZoneFlip
00538 )
00539 );
00540
00541 }
00542 else
00543 {
00544 ref.setAction
00545 (
00546 polyModifyFace
00547 (
00548 newFace,
00549 curFaceID,
00550 own[curFaceID],
00551 -1,
00552 false,
00553 mesh.boundaryMesh().whichPatch(curFaceID),
00554 false,
00555 modifiedFaceZone,
00556 modifiedFaceZoneFlip
00557 )
00558 );
00559
00560 }
00561 }
00562 }
00563
00564 if (debug)
00565 {
00566 Pout<< "void layerAdditionRemoval::addCellLayer("
00567 << "polyTopoChange& ref) const "
00568 << " for object " << name() << " : "
00569 << "Finished adding cell layer" << endl;
00570 }
00571 }
00572
00573
00574