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