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 "attachDetach.H"
00028 #include "polyMesh.H"
00029 #include "primitiveMesh.H"
00030 #include "polyTopoChange.H"
00031 #include "polyTopoChanger.H"
00032 #include "polyAddPoint.H"
00033 #include "polyModifyFace.H"
00034 #include "polyAddFace.H"
00035
00036
00037
00038 void Foam::attachDetach::detachInterface
00039 (
00040 polyTopoChange& ref
00041 ) const
00042 {
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065 if (debug)
00066 {
00067 Pout<< "void attachDetach::detachInterface("
00068 << "polyTopoChange& ref) const "
00069 << " for object " << name() << " : "
00070 << "Detaching interface" << endl;
00071 }
00072
00073 const polyMesh& mesh = topoChanger().mesh();
00074 const faceZoneMesh& zoneMesh = mesh.faceZones();
00075
00076
00077
00078
00079 if (debug)
00080 {
00081 const labelList& faceLabels = zoneMesh[faceZoneID_.index()];
00082 if (faceLabels.size() > 0)
00083 {
00084 for (label i = 1; i < faceLabels.size(); i++)
00085 {
00086 if (faceLabels[i] <= faceLabels[i-1])
00087 {
00088 FatalErrorIn
00089 (
00090 "attachDetach::detachInterface"
00091 "(polyTopoChange&) const"
00092 ) << "faceZone " << zoneMesh[faceZoneID_.index()].name()
00093 << " does not have mesh face labels in"
00094 << " increasing order." << endl
00095 << "Face label " << faceLabels[i]
00096 << " at position " << i
00097 << " is smaller than the previous value "
00098 << faceLabels[i-1]
00099 << exit(FatalError);
00100 }
00101 }
00102 }
00103 }
00104
00105
00106
00107 const primitiveFacePatch& masterFaceLayer = zoneMesh[faceZoneID_.index()]();
00108 const pointField& points = mesh.points();
00109 const labelListList& meshEdgeFaces = mesh.edgeFaces();
00110
00111 const labelList& mp = masterFaceLayer.meshPoints();
00112 const edgeList& zoneLocalEdges = masterFaceLayer.edges();
00113
00114 const labelList& meshEdges = zoneMesh[faceZoneID_.index()].meshEdges();
00115
00116
00117
00118 labelList addedPoints(mp.size(), -1);
00119
00120
00121
00122
00123 label nIntEdges = masterFaceLayer.nInternalEdges();
00124
00125 for (label curEdgeID = nIntEdges; curEdgeID < meshEdges.size(); curEdgeID++)
00126 {
00127 const labelList& curFaces = meshEdgeFaces[meshEdges[curEdgeID]];
00128
00129 bool edgeIsInternal = true;
00130
00131 forAll (curFaces, faceI)
00132 {
00133 if (!mesh.isInternalFace(curFaces[faceI]))
00134 {
00135
00136 edgeIsInternal = false;
00137 break;
00138 }
00139 }
00140
00141 if (edgeIsInternal)
00142 {
00143 const edge& e = zoneLocalEdges[curEdgeID];
00144
00145
00146 addedPoints[e.start()] = mp[e.start()];
00147 addedPoints[e.end()] = mp[e.end()];
00148 }
00149 }
00150
00151
00152
00153 forAll (addedPoints, pointI)
00154 {
00155 if (addedPoints[pointI] < 0)
00156 {
00157 addedPoints[pointI] =
00158 ref.setAction
00159 (
00160 polyAddPoint
00161 (
00162 points[mp[pointI]],
00163 mp[pointI],
00164 -1,
00165 true
00166 )
00167 );
00168
00169
00170
00171
00172 }
00173 }
00174
00175
00176
00177 const labelList& mf = zoneMesh[faceZoneID_.index()];
00178 const boolList& mfFlip = zoneMesh[faceZoneID_.index()].flipMap();
00179 const faceList& zoneFaces = masterFaceLayer.localFaces();
00180
00181 const faceList& faces = mesh.faces();
00182 const labelList& own = mesh.faceOwner();
00183 const labelList& nei = mesh.faceNeighbour();
00184
00185 forAll (mf, faceI)
00186 {
00187 const label curFaceID = mf[faceI];
00188
00189
00190 const face oldFace = zoneFaces[faceI].reverseFace();
00191
00192 face newFace(oldFace.size());
00193
00194 forAll (oldFace, pointI)
00195 {
00196 newFace[pointI] = addedPoints[oldFace[pointI]];
00197 }
00198
00199 if (mfFlip[faceI])
00200 {
00201
00202 ref.setAction
00203 (
00204 polyModifyFace
00205 (
00206 faces[curFaceID].reverseFace(),
00207 curFaceID,
00208 nei[curFaceID],
00209 -1,
00210 true,
00211 masterPatchID_.index(),
00212 false,
00213 faceZoneID_.index(),
00214 !mfFlip[faceI]
00215 )
00216 );
00217
00218
00219
00220 ref.setAction
00221 (
00222 polyAddFace
00223 (
00224 newFace,
00225 own[curFaceID],
00226 -1,
00227 -1,
00228 -1,
00229 curFaceID,
00230 false,
00231 slavePatchID_.index(),
00232 -1,
00233 false
00234 )
00235 );
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245 }
00246 else
00247 {
00248
00249 ref.setAction
00250 (
00251 polyModifyFace
00252 (
00253 faces[curFaceID],
00254 curFaceID,
00255 own[curFaceID],
00256 -1,
00257 false,
00258 masterPatchID_.index(),
00259 false,
00260 faceZoneID_.index(),
00261 mfFlip[faceI]
00262 )
00263 );
00264
00265
00266
00267 ref.setAction
00268 (
00269 polyAddFace
00270 (
00271 newFace,
00272 nei[curFaceID],
00273 -1,
00274 -1,
00275 -1,
00276 curFaceID,
00277 true,
00278 slavePatchID_.index(),
00279 -1,
00280 false
00281 )
00282 );
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292 }
00293 }
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310 const labelList& mc =
00311 mesh.faceZones()[faceZoneID_.index()].masterCells();
00312
00313 labelHashSet masterCellFaceMap(6*mc.size());
00314
00315 const cellList& cells = mesh.cells();
00316
00317 forAll (mc, cellI)
00318 {
00319 const labelList& curFaces = cells[mc[cellI]];
00320
00321 forAll (curFaces, faceI)
00322 {
00323
00324 if (zoneMesh.whichZone(curFaces[faceI]) != faceZoneID_.index())
00325 {
00326 masterCellFaceMap.insert(curFaces[faceI]);
00327 }
00328 }
00329 }
00330
00331
00332
00333 {
00334
00335 labelHashSet mcMap(2*mc.size());
00336
00337 forAll (mc, mcI)
00338 {
00339 mcMap.insert(mc[mcI]);
00340 }
00341
00342
00343
00344
00345 const labelList mcf = masterCellFaceMap.toc();
00346
00347 forAll (mcf, mcfI)
00348 {
00349
00350 const label ownCell = own[mcf[mcfI]];
00351
00352 if (!mcMap.found(ownCell))
00353 {
00354
00355 const cell& curFaces = cells[ownCell];
00356
00357 forAll (curFaces, faceI)
00358 {
00359 masterCellFaceMap.insert(curFaces[faceI]);
00360 }
00361 }
00362
00363
00364 if (mesh.isInternalFace(mcf[mcfI]))
00365 {
00366 const label neiCell = nei[mcf[mcfI]];
00367
00368 if (!mcMap.found(neiCell))
00369 {
00370
00371 const cell& curFaces = cells[neiCell];
00372
00373 forAll (curFaces, faceI)
00374 {
00375 masterCellFaceMap.insert(curFaces[faceI]);
00376 }
00377 }
00378 }
00379 }
00380 }
00381
00382
00383 Map<label> masterLayerPointMap(2*mp.size());
00384
00385 forAll (mp, pointI)
00386 {
00387 masterLayerPointMap.insert
00388 (
00389 mp[pointI],
00390 addedPoints[pointI]
00391 );
00392 }
00393
00394
00395 const labelList masterCellFaces = masterCellFaceMap.toc();
00396
00397 forAll (masterCellFaces, faceI)
00398 {
00399
00400
00401
00402 const label curFaceID = masterCellFaces[faceI];
00403
00404 const face& oldFace = faces[curFaceID];
00405
00406 face newFace(oldFace.size());
00407
00408 bool changed = false;
00409
00410 forAll (oldFace, pointI)
00411 {
00412 if (masterLayerPointMap.found(oldFace[pointI]))
00413 {
00414 changed = true;
00415
00416 newFace[pointI] = masterLayerPointMap.find(oldFace[pointI])();
00417 }
00418 else
00419 {
00420 newFace[pointI] = oldFace[pointI];
00421 }
00422 }
00423
00424
00425 if (changed)
00426 {
00427 if (mesh.isInternalFace(curFaceID))
00428 {
00429 ref.setAction
00430 (
00431 polyModifyFace
00432 (
00433 newFace,
00434 curFaceID,
00435 own[curFaceID],
00436 nei[curFaceID],
00437 false,
00438 -1,
00439 false,
00440 -1,
00441 false
00442 )
00443 );
00444
00445 }
00446 else
00447 {
00448 ref.setAction
00449 (
00450 polyModifyFace
00451 (
00452 newFace,
00453 curFaceID,
00454 own[curFaceID],
00455 -1,
00456 false,
00457 mesh.boundaryMesh().whichPatch(curFaceID),
00458 false,
00459 -1,
00460 false
00461 )
00462 );
00463
00464 }
00465 }
00466 }
00467
00468 if (debug)
00469 {
00470 Pout<< "void attachDetach::detachInterface("
00471 << "polyTopoChange& ref) const "
00472 << " for object " << name() << " : "
00473 << "Finished detaching interface" << endl;
00474 }
00475 }
00476
00477
00478