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