OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

meshCutter.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Description
00026 
00027 \*---------------------------------------------------------------------------*/
00028 
00029 #include "meshCutter.H"
00030 #include "polyMesh.H"
00031 #include "polyTopoChange.H"
00032 #include "cellCuts.H"
00033 #include "mapPolyMesh.H"
00034 #include "meshTools.H"
00035 #include "polyModifyFace.H"
00036 #include "polyAddPoint.H"
00037 #include "polyAddFace.H"
00038 #include "polyAddCell.H"
00039 
00040 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00041 
00042 defineTypeNameAndDebug(Foam::meshCutter, 0);
00043 
00044 
00045 // * * * * * * * * * * * * * Private Static Functions  * * * * * * * * * * * //
00046 
00047 // Returns true if lst1 and lst2 share elements
00048 bool Foam::meshCutter::uses(const labelList& elems1, const labelList& elems2)
00049 {
00050     forAll(elems1, elemI)
00051     {
00052         if (findIndex(elems2, elems1[elemI]) != -1)
00053         {
00054             return true;
00055         }
00056     }
00057     return false;
00058 }
00059 
00060 
00061 // Check if twoCuts at two consecutive position in cuts.
00062 bool Foam::meshCutter::isIn
00063 (
00064     const edge& twoCuts,
00065     const labelList& cuts
00066 )
00067 {
00068     label index = findIndex(cuts, twoCuts[0]);
00069 
00070     if (index == -1)
00071     {
00072         return false;
00073     }
00074 
00075     return
00076     (
00077         cuts[cuts.fcIndex(index)] == twoCuts[1]
00078      || cuts[cuts.rcIndex(index)] == twoCuts[1]
00079     );
00080 }
00081 
00082 
00083 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00084 
00085 // Returns the cell in cellLabels that is cut. Or -1.
00086 Foam::label Foam::meshCutter::findCutCell
00087 (
00088     const cellCuts& cuts,
00089     const labelList& cellLabels
00090 ) const
00091 {
00092     forAll(cellLabels, labelI)
00093     {
00094         label cellI = cellLabels[labelI];
00095 
00096         if (cuts.cellLoops()[cellI].size())
00097         {
00098             return cellI;
00099         }
00100     }
00101     return -1;
00102 }
00103 
00104 
00105 //- Returns first pointI in pointLabels that uses an internal
00106 //  face. Used to find point to inflate cell/face from (has to be
00107 //  connected to internal face). Returns -1 (so inflate from nothing) if
00108 //  none found.
00109 Foam::label Foam::meshCutter::findInternalFacePoint
00110 (
00111     const labelList& pointLabels
00112 ) const
00113 {
00114     forAll(pointLabels, labelI)
00115     {
00116         label pointI = pointLabels[labelI];
00117 
00118         const labelList& pFaces = mesh().pointFaces()[pointI];
00119 
00120         forAll(pFaces, pFaceI)
00121         {
00122             label faceI = pFaces[pFaceI];
00123 
00124             if (mesh().isInternalFace(faceI))
00125             {
00126                 return pointI;
00127             }
00128         }
00129     }
00130 
00131     if (pointLabels.empty())
00132     {
00133         FatalErrorIn("meshCutter::findInternalFacePoint(const labelList&)")
00134             << "Empty pointLabels" << abort(FatalError);
00135     }
00136 
00137     return -1;
00138 }
00139 
00140 
00141 // Get new owner and neighbour of face. Checks anchor points to see if
00142 // need to get original or added cell.
00143 void Foam::meshCutter::faceCells
00144 (
00145     const cellCuts& cuts,
00146     const label faceI,
00147     label& own,
00148     label& nei
00149 ) const
00150 {
00151     const labelListList& anchorPts = cuts.cellAnchorPoints();
00152     const labelListList& cellLoops = cuts.cellLoops();
00153 
00154     const face& f = mesh().faces()[faceI];
00155 
00156     own = mesh().faceOwner()[faceI];
00157 
00158     if (cellLoops[own].size() && uses(f, anchorPts[own]))
00159     {
00160         own = addedCells_[own];
00161     }
00162 
00163     nei = -1;
00164 
00165     if (mesh().isInternalFace(faceI))
00166     {
00167         nei = mesh().faceNeighbour()[faceI];
00168 
00169         if (cellLoops[nei].size() && uses(f, anchorPts[nei]))
00170         {
00171             nei = addedCells_[nei];
00172         }
00173     }
00174 }
00175 
00176 
00177 void Foam::meshCutter::getFaceInfo
00178 (
00179     const label faceI,
00180     label& patchID,
00181     label& zoneID,
00182     label& zoneFlip
00183 ) const
00184 {
00185     patchID = -1;
00186 
00187     if (!mesh().isInternalFace(faceI))
00188     {
00189         patchID = mesh().boundaryMesh().whichPatch(faceI);
00190     }
00191 
00192     zoneID = mesh().faceZones().whichZone(faceI);
00193 
00194     zoneFlip = false;
00195 
00196     if (zoneID >= 0)
00197     {
00198         const faceZone& fZone = mesh().faceZones()[zoneID];
00199 
00200         zoneFlip = fZone.flipMap()[fZone.whichFace(faceI)];
00201     }
00202 }
00203 
00204 
00205 // Adds a face on top of existing faceI.
00206 void Foam::meshCutter::addFace
00207 (
00208     polyTopoChange& meshMod,
00209     const label faceI,
00210     const face& newFace,
00211     const label own,
00212     const label nei
00213 )
00214 {
00215     label patchID, zoneID, zoneFlip;
00216 
00217     getFaceInfo(faceI, patchID, zoneID, zoneFlip);
00218 
00219     if ((nei == -1) || (own < nei))
00220     {
00221         // Ordering ok.
00222         if (debug & 2)
00223         {
00224             Pout<< "Adding face " << newFace
00225                 << " with new owner:" << own
00226                 << " with new neighbour:" << nei
00227                 << " patchID:" << patchID
00228                 << " zoneID:" << zoneID
00229                 << " zoneFlip:" << zoneFlip
00230                 << endl;
00231         }
00232 
00233         meshMod.setAction
00234         (
00235             polyAddFace
00236             (
00237                 newFace,                    // face
00238                 own,                        // owner
00239                 nei,                        // neighbour
00240                 -1,                         // master point
00241                 -1,                         // master edge
00242                 faceI,                      // master face for addition
00243                 false,                      // flux flip
00244                 patchID,                    // patch for face
00245                 zoneID,                     // zone for face
00246                 zoneFlip                    // face zone flip
00247             )
00248         );
00249     }
00250     else
00251     {
00252         // Reverse owner/neighbour
00253         if (debug & 2)
00254         {
00255             Pout<< "Adding (reversed) face " << newFace.reverseFace()
00256                 << " with new owner:" << nei
00257                 << " with new neighbour:" << own
00258                 << " patchID:" << patchID
00259                 << " zoneID:" << zoneID
00260                 << " zoneFlip:" << zoneFlip
00261                 << endl;
00262         }
00263 
00264         meshMod.setAction
00265         (
00266             polyAddFace
00267             (
00268                 newFace.reverseFace(),      // face
00269                 nei,                        // owner
00270                 own,                        // neighbour
00271                 -1,                         // master point
00272                 -1,                         // master edge
00273                 faceI,                      // master face for addition
00274                 false,                      // flux flip
00275                 patchID,                    // patch for face
00276                 zoneID,                     // zone for face
00277                 zoneFlip                    // face zone flip
00278             )
00279         );
00280     }
00281 }
00282 
00283 
00284 // Modifies existing faceI for either new owner/neighbour or new face points.
00285 void Foam::meshCutter::modFace
00286 (
00287     polyTopoChange& meshMod,
00288     const label faceI,
00289     const face& newFace,
00290     const label own,
00291     const label nei
00292 )
00293 {
00294     label patchID, zoneID, zoneFlip;
00295 
00296     getFaceInfo(faceI, patchID, zoneID, zoneFlip);
00297 
00298     if
00299     (
00300         (own != mesh().faceOwner()[faceI])
00301      || (
00302             mesh().isInternalFace(faceI)
00303          && (nei != mesh().faceNeighbour()[faceI])
00304         )
00305      || (newFace != mesh().faces()[faceI])
00306     )
00307     {
00308         if (debug & 2)
00309         {
00310             Pout<< "Modifying face " << faceI
00311                 << " old vertices:" << mesh().faces()[faceI]
00312                 << " new vertices:" << newFace
00313                 << " new owner:" << own
00314                 << " new neighbour:" << nei
00315                 << " new zoneID:" << zoneID
00316                 << " new zoneFlip:" << zoneFlip
00317                 << endl;
00318         }
00319 
00320         if ((nei == -1) || (own < nei))
00321         {
00322             meshMod.setAction
00323             (
00324                 polyModifyFace
00325                 (
00326                     newFace,            // modified face
00327                     faceI,              // label of face being modified
00328                     own,                // owner
00329                     nei,                // neighbour
00330                     false,              // face flip
00331                     patchID,            // patch for face
00332                     false,              // remove from zone
00333                     zoneID,             // zone for face
00334                     zoneFlip            // face flip in zone
00335                 )
00336             );
00337         }
00338         else
00339         {
00340             meshMod.setAction
00341             (
00342                 polyModifyFace
00343                 (
00344                     newFace.reverseFace(),  // modified face
00345                     faceI,                  // label of face being modified
00346                     nei,                    // owner
00347                     own,                    // neighbour
00348                     false,                  // face flip
00349                     patchID,                // patch for face
00350                     false,                  // remove from zone
00351                     zoneID,                 // zone for face
00352                     zoneFlip                // face flip in zone
00353                 )
00354             );
00355         }
00356     }
00357 }
00358 
00359 
00360 // Copies face starting from startFp up to and including endFp.
00361 void Foam::meshCutter::copyFace
00362 (
00363     const face& f,
00364     const label startFp,
00365     const label endFp,
00366     face& newFace
00367 ) const
00368 {
00369     label fp = startFp;
00370 
00371     label newFp = 0;
00372 
00373     while (fp != endFp)
00374     {
00375         newFace[newFp++] = f[fp];
00376 
00377         fp = (fp + 1) % f.size();
00378     }
00379     newFace[newFp] = f[fp];
00380 }
00381 
00382 
00383 // Actually split face in two along splitEdge v0, v1 (the two vertices in new
00384 // vertex numbering). Generates faces in same ordering
00385 // as original face. Replaces cutEdges by the points introduced on them
00386 // (addedPoints_).
00387 void Foam::meshCutter::splitFace
00388 (
00389     const face& f,
00390     const label v0,
00391     const label v1,
00392 
00393     face& f0,
00394     face& f1
00395 ) const
00396 {
00397     // Check if we find any new vertex which is part of the splitEdge.
00398     label startFp = findIndex(f, v0);
00399 
00400     if (startFp == -1)
00401     {
00402         FatalErrorIn
00403         (
00404             "meshCutter::splitFace"
00405             ", const face&, const label, const label, face&, face&)"
00406         )   << "Cannot find vertex (new numbering) " << v0
00407             << " on face " << f
00408             << abort(FatalError);
00409     }
00410 
00411     label endFp = findIndex(f, v1);
00412 
00413     if (endFp == -1)
00414     {
00415         FatalErrorIn
00416         (
00417             "meshCutter::splitFace("
00418             ", const face&, const label, const label, face&, face&)"
00419         )   << "Cannot find vertex (new numbering) " << v1
00420             << " on face " << f
00421             << abort(FatalError);
00422     }
00423 
00424 
00425     f0.setSize((endFp + 1 + f.size() - startFp) % f.size());
00426     f1.setSize(f.size() - f0.size() + 2);
00427 
00428     copyFace(f, startFp, endFp, f0);
00429     copyFace(f, endFp, startFp, f1);
00430 }
00431 
00432 
00433 // Adds additional vertices (from edge cutting) to face. Used for faces which
00434 // are not split but still might use edge that has been cut.
00435 Foam::face Foam::meshCutter::addEdgeCutsToFace(const label faceI) const
00436 {
00437     const face& f = mesh().faces()[faceI];
00438 
00439     face newFace(2 * f.size());
00440 
00441     label newFp = 0;
00442 
00443     forAll(f, fp)
00444     {
00445         // Duplicate face vertex .
00446         newFace[newFp++] = f[fp];
00447 
00448         // Check if edge has been cut.
00449         label fp1 = f.fcIndex(fp);
00450 
00451         HashTable<label, edge, Hash<edge> >::const_iterator fnd =
00452             addedPoints_.find(edge(f[fp], f[fp1]));
00453 
00454         if (fnd != addedPoints_.end())
00455         {
00456             // edge has been cut. Introduce new vertex.
00457             newFace[newFp++] = fnd();
00458         }
00459     }
00460 
00461     newFace.setSize(newFp);
00462 
00463     return newFace;
00464 }
00465 
00466 
00467 // Walk loop (loop of cuts) across circumference of cellI. Returns face in
00468 // new vertices.
00469 // Note: tricky bit is that it can use existing edges which have been split.
00470 Foam::face Foam::meshCutter::loopToFace
00471 (
00472     const label cellI,
00473     const labelList& loop
00474 ) const
00475 {
00476     face newFace(2*loop.size());
00477 
00478     label newFaceI = 0;
00479 
00480     forAll(loop, fp)
00481     {
00482         label cut = loop[fp];
00483 
00484         if (isEdge(cut))
00485         {
00486             label edgeI = getEdge(cut);
00487 
00488             const edge& e = mesh().edges()[edgeI];
00489 
00490             label vertI = addedPoints_[e];
00491 
00492             newFace[newFaceI++] = vertI;
00493         }
00494         else
00495         {
00496             // cut is vertex.
00497             label vertI = getVertex(cut);
00498 
00499             newFace[newFaceI++] = vertI;
00500 
00501             label nextCut = loop[loop.fcIndex(fp)];
00502 
00503             if (!isEdge(nextCut))
00504             {
00505                 // From vertex to vertex -> cross cut only if no existing edge.
00506                 label nextVertI = getVertex(nextCut);
00507 
00508                 label edgeI = meshTools::findEdge(mesh(), vertI, nextVertI);
00509 
00510                 if (edgeI != -1)
00511                 {
00512                     // Existing edge. Insert split-edge point if any.
00513                     HashTable<label, edge, Hash<edge> >::const_iterator fnd =
00514                         addedPoints_.find(mesh().edges()[edgeI]);
00515 
00516                     if (fnd != addedPoints_.end())
00517                     {
00518                         newFace[newFaceI++] = fnd();
00519                     }
00520                 }
00521             }
00522         }
00523     }
00524     newFace.setSize(newFaceI);
00525 
00526     return newFace;
00527 }
00528 
00529 
00530 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00531 
00532 // Construct from components
00533 Foam::meshCutter::meshCutter(const polyMesh& mesh)
00534 :
00535     edgeVertex(mesh),
00536     addedCells_(),
00537     addedFaces_(),
00538     addedPoints_()
00539 
00540 {}
00541 
00542 
00543 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00544 
00545 Foam::meshCutter::~meshCutter()
00546 {}
00547 
00548 
00549 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00550 
00551 void Foam::meshCutter::setRefinement
00552 (
00553     const cellCuts& cuts,
00554     polyTopoChange& meshMod
00555 )
00556 {
00557     // Clear and size maps here since mesh size will change.
00558     addedCells_.clear();
00559     addedCells_.resize(cuts.nLoops());
00560 
00561     addedFaces_.clear();
00562     addedFaces_.resize(cuts.nLoops());
00563 
00564     addedPoints_.clear();
00565     addedPoints_.resize(cuts.nLoops());
00566 
00567     if (cuts.nLoops() == 0)
00568     {
00569         return;
00570     }
00571 
00572     const labelListList& anchorPts = cuts.cellAnchorPoints();
00573     const labelListList& cellLoops = cuts.cellLoops();
00574 
00575     //
00576     // Add new points along cut edges.
00577     //
00578 
00579     forAll(cuts.edgeIsCut(), edgeI)
00580     {
00581         if (cuts.edgeIsCut()[edgeI])
00582         {
00583             const edge& e = mesh().edges()[edgeI];
00584 
00585             // Check if there is any cell using this edge.
00586             if (debug && findCutCell(cuts, mesh().edgeCells()[edgeI]) == -1)
00587             {
00588                 FatalErrorIn
00589                 (
00590                     "meshCutter::setRefinement(const cellCuts&"
00591                     ", polyTopoChange&)"
00592                 )   << "Problem: cut edge but none of the cells using it is\n"
00593                     << "edge:" << edgeI << " verts:" << e
00594                     << abort(FatalError);
00595             }
00596 
00597             // One of the edge end points should be master point of nbCellI.
00598             label masterPointI = e.start();
00599 
00600             const point& v0 = mesh().points()[e.start()];
00601             const point& v1 = mesh().points()[e.end()];
00602 
00603             scalar weight = cuts.edgeWeight()[edgeI];
00604 
00605             point newPt = weight*v1 + (1.0-weight)*v0;
00606 
00607             label addedPointI =
00608                 meshMod.setAction
00609                 (
00610                     polyAddPoint
00611                     (
00612                         newPt,              // point
00613                         masterPointI,       // master point
00614                         -1,                 // zone for point
00615                         true                // supports a cell
00616                     )
00617                 );
00618 
00619             // Store on (hash of) edge.
00620             addedPoints_.insert(e, addedPointI);
00621 
00622             if (debug & 2)
00623             {
00624                 Pout<< "Added point " << addedPointI
00625                     << " to vertex "
00626                     << masterPointI << " of edge " << edgeI
00627                     << " vertices " << e << endl;
00628             }
00629         }
00630     }
00631 
00632     //
00633     // Add cells (on 'anchor' side of cell)
00634     //
00635 
00636     forAll(cellLoops, cellI)
00637     {
00638         if (cellLoops[cellI].size())
00639         {
00640             // Add a cell to the existing cell
00641             label addedCellI =
00642                 meshMod.setAction
00643                 (
00644                     polyAddCell
00645                     (
00646                         -1,                 // master point
00647                         -1,                 // master edge
00648                         -1,                 // master face
00649                         cellI,              // master cell
00650                         -1                  // zone for cell
00651                     )
00652                 );
00653 
00654             addedCells_.insert(cellI, addedCellI);
00655 
00656             if (debug & 2)
00657             {
00658                 Pout<< "Added cell " << addedCells_[cellI] << " to cell "
00659                     << cellI << endl;
00660             }
00661         }
00662     }
00663 
00664 
00665     //
00666     // For all cut cells add an internal face
00667     //
00668 
00669     forAll(cellLoops, cellI)
00670     {
00671         const labelList& loop = cellLoops[cellI];
00672 
00673         if (loop.size())
00674         {
00675             //
00676             // Convert loop (=list of cuts) into proper face.
00677             // Orientation should already be ok. (done by cellCuts)
00678             //
00679             face newFace(loopToFace(cellI, loop));
00680 
00681             // Pick any anchor point on cell
00682             label masterPointI = findInternalFacePoint(anchorPts[cellI]);
00683 
00684             label addedFaceI =
00685                 meshMod.setAction
00686                 (
00687                     polyAddFace
00688                     (
00689                         newFace,                // face
00690                         cellI,                  // owner
00691                         addedCells_[cellI],     // neighbour
00692                         masterPointI,           // master point
00693                         -1,                     // master edge
00694                         -1,                     // master face for addition
00695                         false,                  // flux flip
00696                         -1,                     // patch for face
00697                         -1,                     // zone for face
00698                         false                   // face zone flip
00699                     )
00700                 );
00701 
00702             addedFaces_.insert(cellI, addedFaceI);
00703 
00704             if (debug & 2)
00705             {
00706                 // Gets edgeweights of loop
00707                 scalarField weights(loop.size());
00708                 forAll(loop, i)
00709                 {
00710                     label cut = loop[i];
00711 
00712                     weights[i] =
00713                     (
00714                         isEdge(cut)
00715                       ? cuts.edgeWeight()[getEdge(cut)]
00716                       : -GREAT
00717                     );
00718                 }
00719 
00720                 Pout<< "Added splitting face " << newFace << " index:"
00721                     << addedFaceI
00722                     << " to owner " << cellI
00723                     << " neighbour " << addedCells_[cellI]
00724                     << " from Loop:";
00725                 writeCuts(Pout, loop, weights);
00726                 Pout<< endl;
00727             }
00728         }
00729     }
00730 
00731 
00732     //
00733     // Modify faces on the outside and create new ones
00734     // (in effect split old faces into two)
00735     //
00736 
00737     // Maintain whether face has been updated (for -split edges
00738     // -new owner/neighbour)
00739     boolList faceUptodate(mesh().nFaces(), false);
00740 
00741     const Map<edge>& faceSplitCuts = cuts.faceSplitCut();
00742 
00743     for
00744     (
00745         Map<edge>::const_iterator iter = faceSplitCuts.begin();
00746         iter != faceSplitCuts.end();
00747         ++iter
00748     )
00749     {
00750         label faceI = iter.key();
00751 
00752         // Renumber face to include split edges.
00753         face newFace(addEdgeCutsToFace(faceI));
00754 
00755         // Edge splitting the face. Convert cuts to new vertex numbering.
00756         const edge& splitEdge = iter();
00757 
00758         label cut0 = splitEdge[0];
00759 
00760         label v0;
00761         if (isEdge(cut0))
00762         {
00763             label edgeI = getEdge(cut0);
00764             v0 = addedPoints_[mesh().edges()[edgeI]];
00765         }
00766         else
00767         {
00768             v0 = getVertex(cut0);
00769         }
00770 
00771         label cut1 = splitEdge[1];
00772         label v1;
00773         if (isEdge(cut1))
00774         {
00775             label edgeI = getEdge(cut1);
00776             v1 = addedPoints_[mesh().edges()[edgeI]];
00777         }
00778         else
00779         {
00780             v1 = getVertex(cut1);
00781         }
00782 
00783         // Split face along the elements of the splitEdge.
00784         face f0, f1;
00785         splitFace(newFace, v0, v1, f0, f1);
00786 
00787         label own = mesh().faceOwner()[faceI];
00788 
00789         label nei = -1;
00790 
00791         if (mesh().isInternalFace(faceI))
00792         {
00793             nei = mesh().faceNeighbour()[faceI];
00794         }
00795 
00796         if (debug & 2)
00797         {
00798             Pout<< "Split face " << mesh().faces()[faceI]
00799                 << " own:" << own << " nei:" << nei
00800                 << " into f0:" << f0
00801                 << " and f1:" << f1 << endl;
00802         }
00803 
00804         // Check which face uses anchorPoints (connects to addedCell)
00805         // and which one doesn't (connects to original cell)
00806 
00807         // Bit tricky. We have to know whether this faceSplit splits owner/
00808         // neighbour or both. Even if cell is cut we have to make sure this is
00809         // the one that cuts it (this face cut might not be the one splitting
00810         // the cell)
00811 
00812         const face& f = mesh().faces()[faceI];
00813 
00814         label f0Owner = -1;
00815         label f1Owner = -1;
00816 
00817         if (cellLoops[own].empty())
00818         {
00819             f0Owner = own;
00820             f1Owner = own;
00821         }
00822         else if (isIn(splitEdge, cellLoops[own]))
00823         {
00824             // Owner is cut by this splitCut. See which of f0, f1 gets
00825             // owner, which gets addedCells_[owner]
00826             if (uses(f0, anchorPts[own]))
00827             {
00828                 f0Owner = addedCells_[own];
00829                 f1Owner = own;
00830             }
00831             else
00832             {
00833                 f0Owner = own;
00834                 f1Owner = addedCells_[own];
00835             }
00836         }
00837         else
00838         {
00839             // Owner not cut by this splitCut. Check on original face whether
00840             // use anchorPts.
00841             if (uses(f, anchorPts[own]))
00842             {
00843                 label newCellI = addedCells_[own];
00844                 f0Owner = newCellI;
00845                 f1Owner = newCellI;
00846             }
00847             else
00848             {
00849                 f0Owner = own;
00850                 f1Owner = own;
00851             }
00852         }
00853 
00854 
00855         label f0Neighbour = -1;
00856         label f1Neighbour = -1;
00857 
00858         if (nei != -1)
00859         {
00860             if (cellLoops[nei].empty())
00861             {
00862                 f0Neighbour = nei;
00863                 f1Neighbour = nei;
00864             }
00865             else if (isIn(splitEdge, cellLoops[nei]))
00866             {
00867                 // Neighbour is cut by this splitCut. See which of f0, f1
00868                 // gets which neighbour/addedCells_[neighbour]
00869                 if (uses(f0, anchorPts[nei]))
00870                 {
00871                     f0Neighbour = addedCells_[nei];
00872                     f1Neighbour = nei;
00873                 }
00874                 else
00875                 {
00876                     f0Neighbour = nei;
00877                     f1Neighbour = addedCells_[nei];
00878                 }
00879             }
00880             else
00881             {
00882                 // neighbour not cut by this splitCut. Check on original face
00883                 // whether use anchorPts.
00884                 if (uses(f, anchorPts[nei]))
00885                 {
00886                     label newCellI = addedCells_[nei];
00887                     f0Neighbour = newCellI;
00888                     f1Neighbour = newCellI;
00889                 }
00890                 else
00891                 {
00892                     f0Neighbour = nei;
00893                     f1Neighbour = nei;
00894                 }
00895             }
00896         }
00897 
00898         // f0 is the added face, f1 the modified one
00899         addFace(meshMod, faceI, f0, f0Owner, f0Neighbour);
00900 
00901         modFace(meshMod, faceI, f1, f1Owner, f1Neighbour);
00902 
00903         faceUptodate[faceI] = true;
00904     }
00905 
00906 
00907     //
00908     // Faces that have not been split but just appended to. Are guaranteed
00909     // to be reachable from an edgeCut.
00910     //
00911 
00912     const boolList& edgeIsCut = cuts.edgeIsCut();
00913 
00914     forAll(edgeIsCut, edgeI)
00915     {
00916         if (edgeIsCut[edgeI])
00917         {
00918             const labelList& eFaces = mesh().edgeFaces()[edgeI];
00919 
00920             forAll(eFaces, i)
00921             {
00922                 label faceI = eFaces[i];
00923 
00924                 if (!faceUptodate[faceI])
00925                 {
00926                     // Renumber face to include split edges.
00927                     face newFace(addEdgeCutsToFace(faceI));
00928 
00929                     if (debug & 2)
00930                     {
00931                         Pout<< "Added edge cuts to face " << faceI
00932                             << " f:" << mesh().faces()[faceI]
00933                             << " newFace:" << newFace << endl;
00934                     }
00935 
00936                     // Get (new or original) owner and neighbour of faceI
00937                     label own, nei;
00938                     faceCells(cuts, faceI, own, nei);
00939 
00940                     modFace(meshMod, faceI, newFace, own, nei);
00941 
00942                     faceUptodate[faceI] = true;
00943                 }
00944             }
00945         }
00946     }
00947 
00948 
00949     //
00950     // Correct any original faces on split cell for new neighbour/owner
00951     //
00952 
00953     forAll(cellLoops, cellI)
00954     {
00955         if (cellLoops[cellI].size())
00956         {
00957             const labelList& cllFaces = mesh().cells()[cellI];
00958 
00959             forAll(cllFaces, cllFaceI)
00960             {
00961                 label faceI = cllFaces[cllFaceI];
00962 
00963                 if (!faceUptodate[faceI])
00964                 {
00965                     // Update face with new owner/neighbour (if any)
00966                     const face& f = mesh().faces()[faceI];
00967 
00968                     if (debug && (f != addEdgeCutsToFace(faceI)))
00969                     {
00970                         FatalErrorIn
00971                         (
00972                             "meshCutter::setRefinement(const cellCuts&"
00973                             ", polyTopoChange&)"
00974                         )   << "Problem: edges added to face which does "
00975                             << " not use a marked cut" << endl
00976                             << "faceI:" << faceI << endl
00977                             << "face:" << f << endl
00978                             << "newFace:" << addEdgeCutsToFace(faceI)
00979                             << abort(FatalError);
00980                     }
00981 
00982                     // Get (new or original) owner and neighbour of faceI
00983                     label own, nei;
00984                     faceCells(cuts, faceI, own, nei);
00985 
00986                     modFace
00987                     (
00988                         meshMod,
00989                         faceI,
00990                         f,
00991                         own,
00992                         nei
00993                     );
00994 
00995                     faceUptodate[faceI] = true;
00996                 }
00997             }
00998         }
00999     }
01000 
01001     if (debug)
01002     {
01003         Pout<< "meshCutter:" << nl
01004             << "    cells split:" << addedCells_.size() << nl
01005             << "    faces added:" << addedFaces_.size() << nl
01006             << "    points added on edges:" << addedPoints_.size() << nl
01007             << endl;
01008     }
01009 }
01010 
01011 
01012 void Foam::meshCutter::updateMesh(const mapPolyMesh& morphMap)
01013 {
01014     // Update stored labels for mesh change.
01015 
01016     {
01017         // Create copy since new label might (temporarily) clash with existing
01018         // key.
01019         Map<label> newAddedCells(addedCells_.size());
01020 
01021         for
01022         (
01023             Map<label>::const_iterator iter = addedCells_.begin();
01024             iter != addedCells_.end();
01025             ++iter
01026         )
01027         {
01028             label cellI = iter.key();
01029 
01030             label newCellI = morphMap.reverseCellMap()[cellI];
01031 
01032             label addedCellI = iter();
01033 
01034             label newAddedCellI = morphMap.reverseCellMap()[addedCellI];
01035 
01036             if (newCellI >= 0 && newAddedCellI >= 0)
01037             {
01038                 if
01039                 (
01040                     (debug & 2)
01041                  && (newCellI != cellI || newAddedCellI != addedCellI)
01042                 )
01043                 {
01044                     Pout<< "meshCutter::updateMesh :"
01045                         << " updating addedCell for cell " << cellI
01046                         << " from " << addedCellI
01047                         << " to " << newAddedCellI << endl;
01048                 }
01049                 newAddedCells.insert(newCellI, newAddedCellI);
01050             }
01051         }
01052 
01053         // Copy
01054         addedCells_.transfer(newAddedCells);
01055     }
01056 
01057     {
01058         Map<label> newAddedFaces(addedFaces_.size());
01059 
01060         for
01061         (
01062             Map<label>::const_iterator iter = addedFaces_.begin();
01063             iter != addedFaces_.end();
01064             ++iter
01065         )
01066         {
01067             label cellI = iter.key();
01068 
01069             label newCellI = morphMap.reverseCellMap()[cellI];
01070 
01071             label addedFaceI = iter();
01072 
01073             label newAddedFaceI = morphMap.reverseFaceMap()[addedFaceI];
01074 
01075             if ((newCellI >= 0) && (newAddedFaceI >= 0))
01076             {
01077                 if
01078                 (
01079                     (debug & 2)
01080                  && (newCellI != cellI || newAddedFaceI != addedFaceI)
01081                 )
01082                 {
01083                     Pout<< "meshCutter::updateMesh :"
01084                         << " updating addedFace for cell " << cellI
01085                         << " from " << addedFaceI
01086                         << " to " << newAddedFaceI
01087                         << endl;
01088                 }
01089                 newAddedFaces.insert(newCellI, newAddedFaceI);
01090             }
01091         }
01092 
01093         // Copy
01094         addedFaces_.transfer(newAddedFaces);
01095     }
01096 
01097     {
01098         HashTable<label, edge, Hash<edge> > newAddedPoints(addedPoints_.size());
01099 
01100         for
01101         (
01102             HashTable<label, edge, Hash<edge> >::const_iterator iter =
01103                 addedPoints_.begin();
01104             iter != addedPoints_.end();
01105             ++iter
01106         )
01107         {
01108             const edge& e = iter.key();
01109 
01110             label newStart = morphMap.reversePointMap()[e.start()];
01111 
01112             label newEnd = morphMap.reversePointMap()[e.end()];
01113 
01114             label addedPointI = iter();
01115 
01116             label newAddedPointI = morphMap.reversePointMap()[addedPointI];
01117 
01118             if ((newStart >= 0) && (newEnd >= 0) && (newAddedPointI >= 0))
01119             {
01120                 edge newE = edge(newStart, newEnd);
01121 
01122                 if
01123                 (
01124                     (debug & 2)
01125                  && (e != newE || newAddedPointI != addedPointI)
01126                 )
01127                 {
01128                     Pout<< "meshCutter::updateMesh :"
01129                         << " updating addedPoints for edge " << e
01130                         << " from " << addedPointI
01131                         << " to " << newAddedPointI
01132                         << endl;
01133                 }
01134 
01135                 newAddedPoints.insert(newE, newAddedPointI);
01136             }
01137         }
01138 
01139         // Copy
01140         addedPoints_.transfer(newAddedPoints);
01141     }
01142 }
01143 
01144 
01145 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd