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

removePoints.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 \*---------------------------------------------------------------------------*/
00026 
00027 #include "BiIndirectList.H"
00028 #include "removePoints.H"
00029 #include "PstreamReduceOps.H"
00030 #include "polyMesh.H"
00031 #include "polyTopoChange.H"
00032 #include "polyRemovePoint.H"
00033 #include "polyAddPoint.H"
00034 #include "polyModifyFace.H"
00035 #include "syncTools.H"
00036 #include "wallPoint.H"  // only to use 'greatPoint'
00037 #include "faceSet.H"
00038 
00039 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00040 
00041 namespace Foam
00042 {
00043 
00044 defineTypeNameAndDebug(removePoints, 0);
00045 
00046 }
00047 
00048 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00049 
00050 // Change the vertices of the face whilst keeping everything else the same.
00051 void Foam::removePoints::modifyFace
00052 (
00053     const label faceI,
00054     const face& newFace,
00055     polyTopoChange& meshMod
00056 ) const
00057 {
00058     // Get other face data.
00059     label patchI = -1;
00060     label owner = mesh_.faceOwner()[faceI];
00061     label neighbour = -1;
00062 
00063     if (mesh_.isInternalFace(faceI))
00064     {
00065         neighbour = mesh_.faceNeighbour()[faceI];
00066     }
00067     else
00068     {
00069         patchI = mesh_.boundaryMesh().whichPatch(faceI);
00070     }
00071 
00072     label zoneID = mesh_.faceZones().whichZone(faceI);
00073 
00074     bool zoneFlip = false;
00075 
00076     if (zoneID >= 0)
00077     {
00078         const faceZone& fZone = mesh_.faceZones()[zoneID];
00079 
00080         zoneFlip = fZone.flipMap()[fZone.whichFace(faceI)];
00081     }
00082 
00083     meshMod.setAction
00084     (
00085         polyModifyFace
00086         (
00087             newFace,        // modified face
00088             faceI,          // label of face being modified
00089             owner,          // owner
00090             neighbour,      // neighbour
00091             false,          // face flip
00092             patchI,         // patch for face
00093             false,          // remove from zone
00094             zoneID,         // zone for face
00095             zoneFlip        // face flip in zone
00096         )
00097     );
00098 }
00099 
00100 
00101 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00102 
00103 // Construct from mesh
00104 Foam::removePoints::removePoints
00105 (
00106     const polyMesh& mesh,
00107     const bool undoable
00108 )
00109 :
00110     mesh_(mesh),
00111     undoable_(undoable)
00112 {}
00113 
00114 
00115 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00116 
00117 Foam::label Foam::removePoints::countPointUsage
00118 (
00119     const scalar minCos,
00120     boolList& pointCanBeDeleted
00121 ) const
00122 {
00123     // Containers to store two edges per point:
00124     // -1   : not filled
00125     // >= 0 : edge label
00126     // -2   : more than two edges for point
00127     labelList edge0(mesh_.nPoints(), -1);
00128     labelList edge1(mesh_.nPoints(), -1);
00129 
00130     const edgeList& edges = mesh_.edges();
00131 
00132     forAll(edges, edgeI)
00133     {
00134         const edge& e = edges[edgeI];
00135 
00136         forAll(e, eI)
00137         {
00138             label pointI = e[eI];
00139 
00140             if (edge0[pointI] == -2)
00141             {
00142                 // Already too many edges
00143             }
00144             else if (edge0[pointI] == -1)
00145             {
00146                 // Store first edge using point
00147                 edge0[pointI] = edgeI;
00148             }
00149             else
00150             {
00151                 // Already one edge using point. Check second container.
00152 
00153                 if (edge1[pointI] == -1)
00154                 {
00155                     // Store second edge using point
00156                     edge1[pointI] = edgeI;
00157                 }
00158                 else
00159                 {
00160                     // Third edge using point. Mark.
00161                     edge0[pointI] = -2;
00162                     edge1[pointI] = -2;
00163                 }
00164             }
00165         }
00166     }
00167 
00168 
00169     // Check the ones used by only 2 edges that these are sufficiently in line.
00170     const pointField& points = mesh_.points();
00171 
00172     pointCanBeDeleted.setSize(mesh_.nPoints());
00173     pointCanBeDeleted = false;
00174     label nDeleted = 0;
00175 
00176     forAll(edge0, pointI)
00177     {
00178         if (edge0[pointI] >= 0 && edge1[pointI] >= 0)
00179         {
00180             // Point used by two edges exactly
00181 
00182             const edge& e0 = edges[edge0[pointI]];
00183             const edge& e1 = edges[edge1[pointI]];
00184 
00185             label common = e0.commonVertex(e1);
00186             label vLeft = e0.otherVertex(common);
00187             label vRight = e1.otherVertex(common);
00188 
00189             vector e0Vec = points[common] - points[vLeft];
00190             e0Vec /= mag(e0Vec) + VSMALL;
00191 
00192             vector e1Vec = points[vRight] - points[common];
00193             e1Vec /= mag(e1Vec) + VSMALL;
00194 
00195             if ((e0Vec & e1Vec) > minCos)
00196             {
00197                 pointCanBeDeleted[pointI] = true;
00198                 nDeleted++;
00199             }
00200         }
00201         else if (edge0[pointI] == -1)
00202         {
00203             // point not used at all
00204             pointCanBeDeleted[pointI] = true;
00205             nDeleted++;
00206         }
00207 
00208     }
00209     edge0.clear();
00210     edge1.clear();
00211 
00212 
00213     // Point can be deleted only if all processors want to delete it
00214     syncTools::syncPointList
00215     (
00216         mesh_,
00217         pointCanBeDeleted,
00218         andEqOp<bool>(),
00219         true,               // null value
00220         false               // no separation
00221     );
00222 
00223     return returnReduce(nDeleted, sumOp<label>());
00224 }
00225 
00226 
00227 void Foam::removePoints::setRefinement
00228 (
00229     const boolList& pointCanBeDeleted,
00230     polyTopoChange& meshMod
00231 )
00232 {
00233     // Count deleted points
00234     label nDeleted = 0;
00235     forAll(pointCanBeDeleted, pointI)
00236     {
00237         if (pointCanBeDeleted[pointI])
00238         {
00239             nDeleted++;
00240         }
00241     }
00242 
00243     // Faces (in mesh face labels) affected by points removed. Will hopefully
00244     // be only a few.
00245     labelHashSet facesAffected(4*nDeleted);
00246 
00247 
00248     // Undo: from global mesh point to index in savedPoint_
00249     Map<label> pointToSaved;
00250 
00251     // Size undo storage
00252     if (undoable_)
00253     {
00254         savedPoints_.setSize(nDeleted);
00255         pointToSaved.resize(2*nDeleted);
00256     }
00257     
00258 
00259     // Remove points
00260     // ~~~~~~~~~~~~~
00261 
00262     nDeleted = 0;
00263 
00264     forAll(pointCanBeDeleted, pointI)
00265     {
00266         if (pointCanBeDeleted[pointI])
00267         {
00268             if (undoable_)
00269             {
00270                 pointToSaved.insert(pointI, nDeleted);
00271                 savedPoints_[nDeleted++] = mesh_.points()[pointI];
00272             }
00273             meshMod.setAction(polyRemovePoint(pointI));
00274 
00275             // Store faces affected
00276             const labelList& pFaces = mesh_.pointFaces()[pointI];
00277 
00278             forAll(pFaces, i)
00279             {
00280                 facesAffected.insert(pFaces[i]);
00281             }
00282         }
00283     }
00284 
00285 
00286 
00287     // Update faces
00288     // ~~~~~~~~~~~~
00289 
00290 
00291     if (undoable_)
00292     {
00293         savedFaceLabels_.setSize(facesAffected.size());
00294         savedFaces_.setSize(facesAffected.size());
00295     }
00296     label nSaved = 0;
00297 
00298     forAllConstIter(labelHashSet, facesAffected, iter)
00299     {
00300         label faceI = iter.key();
00301 
00302         const face& f = mesh_.faces()[faceI];
00303 
00304         face newFace(f.size());
00305 
00306         label newI = 0;
00307 
00308         forAll(f, fp)
00309         {
00310             label pointI = f[fp];
00311 
00312             if (!pointCanBeDeleted[pointI])
00313             {
00314                 newFace[newI++] = pointI;
00315             }
00316         }
00317         newFace.setSize(newI);
00318 
00319         // Actually change the face to the new vertices
00320         modifyFace(faceI, newFace, meshMod);
00321 
00322         // Save the face. Negative indices are into savedPoints_
00323         if (undoable_)
00324         {
00325             savedFaceLabels_[nSaved] = faceI;
00326 
00327             face& savedFace = savedFaces_[nSaved++];
00328             savedFace.setSize(f.size());
00329 
00330             forAll(f, fp)
00331             {
00332                 label pointI = f[fp];
00333 
00334                 if (pointCanBeDeleted[pointI])
00335                 {
00336                     savedFace[fp] = -pointToSaved[pointI]-1;
00337                 }
00338                 else
00339                 {
00340                     savedFace[fp] = pointI;
00341                 }
00342             }
00343         }
00344     }
00345 
00346     if (undoable_)
00347     {
00348         // DEBUG: Compare the stored faces with the current ones.
00349         if (debug)
00350         {
00351             forAll(savedFaceLabels_, saveI)
00352             {
00353                 // Points from the mesh
00354                 List<point> meshPoints
00355                 (
00356                     UIndirectList<point>
00357                     (
00358                         mesh_.points(),
00359                         mesh_.faces()[savedFaceLabels_[saveI]]  // mesh face
00360                     )
00361                 );
00362 
00363                 // Points from the saved face
00364                 List<point> keptPoints
00365                 (
00366                     BiIndirectList<point>
00367                     (
00368                         mesh_.points(),
00369                         savedPoints_,
00370                         savedFaces_[saveI]  // saved face
00371                     )
00372                 );
00373 
00374                 if (meshPoints != keptPoints)
00375                 {
00376                     FatalErrorIn("setRefinement")
00377                         << "faceI:" << savedFaceLabels_[saveI] << nl
00378                         << "meshPoints:" << meshPoints << nl
00379                         << "keptPoints:" << keptPoints << nl
00380                         << abort(FatalError);
00381                 }
00382             }
00383         }
00384     }
00385 }
00386 
00387 
00388 void Foam::removePoints::updateMesh(const mapPolyMesh& map)
00389 {
00390     if (undoable_)
00391     {
00392         forAll(savedFaceLabels_, localI)
00393         {
00394             if (savedFaceLabels_[localI] >= 0)
00395             {
00396                 label newFaceI = map.reverseFaceMap()[savedFaceLabels_[localI]];
00397 
00398                 if (newFaceI == -1)
00399                 {
00400                     FatalErrorIn
00401                     (
00402                         "removePoints::updateMesh(const mapPolyMesh&)"
00403                     )   << "Old face " << savedFaceLabels_[localI]
00404                         << " seems to have dissapeared."
00405                         << abort(FatalError);
00406                 }
00407                 savedFaceLabels_[localI] = newFaceI;
00408             }
00409         }
00410 
00411 
00412         // Renumber mesh vertices (indices >=0). Leave saved vertices
00413         // (<0) intact.
00414         forAll(savedFaces_, i)
00415         {
00416             face& f = savedFaces_[i];
00417 
00418             forAll(f, fp)
00419             {
00420                 label pointI = f[fp];
00421 
00422                 if (pointI >= 0)
00423                 {
00424                     f[fp] = map.reversePointMap()[pointI];
00425 
00426                     if (f[fp] == -1)
00427                     {
00428                         FatalErrorIn
00429                         (
00430                             "removePoints::updateMesh(const mapPolyMesh&)"
00431                         )   << "Old point " << pointI
00432                             << " seems to have dissapeared."
00433                             << abort(FatalError);
00434                     }
00435                 }
00436             }
00437         }
00438 
00439 
00440         // DEBUG: Compare the stored faces with the current ones.
00441         if (debug)
00442         {
00443             forAll(savedFaceLabels_, saveI)
00444             {
00445                 if (savedFaceLabels_[saveI] >= 0)
00446                 {
00447                     const face& f = mesh_.faces()[savedFaceLabels_[saveI]];
00448 
00449                     // Get kept points of saved faces.
00450                     const face& savedFace = savedFaces_[saveI];
00451 
00452                     face keptFace(savedFace.size());
00453                     label keptFp = 0;
00454 
00455                     forAll(savedFace, fp)
00456                     {
00457                         label pointI = savedFace[fp];
00458 
00459                         if (pointI >= 0)
00460                         {
00461                             keptFace[keptFp++] = pointI;
00462                         }
00463                     }
00464                     keptFace.setSize(keptFp);
00465 
00466                     // Compare as faces (since f might have rotated and
00467                     // face::operator== takes care of this)
00468                     if (keptFace != f)
00469                     {
00470                         FatalErrorIn("setRefinement")
00471                             << "faceI:" << savedFaceLabels_[saveI] << nl
00472                             << "face:" << f << nl
00473                             << "keptFace:" << keptFace << nl
00474                             << "saved points:"
00475                             <<  BiIndirectList<point>
00476                                 (
00477                                     mesh_.points(),
00478                                     savedPoints_,
00479                                     savedFace
00480                                 )() << nl
00481                             << abort(FatalError);
00482                     }
00483                 }
00484             }
00485         }
00486     }
00487 }
00488 
00489 
00490 // Given list of faces to undo picks up the local indices of the faces
00491 // to restore. Additionally it also picks up all the faces that use
00492 // any of the deleted points.
00493 void Foam::removePoints::getUnrefimentSet
00494 (
00495     const labelList& undoFaces,
00496     labelList& localFaces,
00497     labelList& localPoints
00498 ) const
00499 {
00500     if (!undoable_)
00501     {
00502         FatalErrorIn
00503         (
00504             "removePoints::getUnrefimentSet(const labelList&"
00505             ", labelList&, labelList&) const"
00506         )   << "removePoints not constructed with"
00507             << " unrefinement capability."
00508             << abort(FatalError);
00509     }
00510 
00511     if (debug)
00512     {
00513         // Check if synced.
00514         faceSet undoFacesSet(mesh_, "undoFacesSet", undoFaces);
00515         label sz = undoFacesSet.size();
00516 
00517         undoFacesSet.sync(mesh_);
00518         if (sz != undoFacesSet.size())
00519         {
00520             FatalErrorIn
00521             (
00522                 "removePoints::getUnrefimentSet(const labelList&"
00523                 ", labelList&, labelList&) const"
00524             )   << "undoFaces not synchronised across coupled faces." << endl
00525                 << "Size before sync:" << sz
00526                 << "  after sync:" << undoFacesSet.size()
00527                 << abort(FatalError);
00528         }
00529     }
00530 
00531 
00532     // Problem: input undoFaces are synced. But e.g.
00533     // two faces, A (uncoupled) and B(coupled) share a deleted point. A gets
00534     // passed in to be restored. Now picking up the deleted point and the
00535     // original faces using it picks up face B. But not its coupled neighbour!
00536     // Problem is that we cannot easily synchronise the deleted points
00537     // (e.g. syncPointList) since they're not in the mesh anymore - only the
00538     // faces are. So we have to collect the points-to-restore as indices
00539     // in the faces (which is information we can synchronise)
00540 
00541 
00542 
00543     // Mark points-to-restore
00544     labelHashSet localPointsSet(undoFaces.size());
00545 
00546     {
00547         // Create set of faces to be restored
00548         labelHashSet undoFacesSet(undoFaces);
00549 
00550         forAll(savedFaceLabels_, saveI)
00551         {
00552             if (savedFaceLabels_[saveI] < 0)
00553             {
00554                 FatalErrorIn
00555                 (
00556                     "removePoints::getUnrefimentSet(const labelList&"
00557                     ", labelList&, labelList&) const"
00558                 )   << "Illegal face label " << savedFaceLabels_[saveI]
00559                     << " at index " << saveI
00560                     << abort(FatalError);
00561             }
00562 
00563             if (undoFacesSet.found(savedFaceLabels_[saveI]))
00564             {
00565                 const face& savedFace = savedFaces_[saveI];
00566 
00567                 forAll(savedFace, fp)
00568                 {
00569                     if (savedFace[fp] < 0)
00570                     {
00571                         label savedPointI = -savedFace[fp]-1;
00572 
00573                         if (savedPoints_[savedPointI] == wallPoint::greatPoint)
00574                         {
00575                             FatalErrorIn
00576                             (
00577                                 "removePoints::getUnrefimentSet"
00578                                 "(const labelList&, labelList&, labelList&)"
00579                                 " const"
00580                             )   << "Trying to restore point " << savedPointI
00581                                 << " from mesh face " << savedFaceLabels_[saveI]
00582                                 << " saved face:" << savedFace
00583                                 << " which has already been undone."
00584                                 << abort(FatalError);
00585                         }
00586 
00587                         localPointsSet.insert(savedPointI);
00588                     }
00589                 }
00590             }
00591         }
00592 
00593 
00594         // Per boundary face, per index in face whether the point needs
00595         // restoring. Note that this is over all saved faces, not just over
00596         // the ones in undoFaces.
00597 
00598         boolListList faceVertexRestore(mesh_.nFaces()-mesh_.nInternalFaces());
00599 
00600         // Populate with my local points-to-restore.
00601         forAll(savedFaces_, saveI)
00602         {
00603             label bFaceI = savedFaceLabels_[saveI] - mesh_.nInternalFaces();
00604 
00605             if (bFaceI >= 0)
00606             {
00607                 const face& savedFace = savedFaces_[saveI];
00608 
00609                 boolList& fRestore = faceVertexRestore[bFaceI];
00610 
00611                 fRestore.setSize(savedFace.size());
00612                 fRestore = false;
00613 
00614                 forAll(savedFace, fp)
00615                 {
00616                     if (savedFace[fp] < 0)
00617                     {
00618                         label savedPointI = -savedFace[fp]-1;
00619 
00620                         if (localPointsSet.found(savedPointI))
00621                         {
00622                             fRestore[fp] = true;
00623                         }
00624                     }
00625                 }
00626             }
00627         }
00628 
00629         syncTools::syncBoundaryFaceList
00630         (
00631             mesh_,
00632             faceVertexRestore,
00633             faceEqOp<bool, orEqOp>(),   // special operator to handle faces
00634             false                       // no separation
00635         );
00636 
00637         // So now if any of the points-to-restore is used by any coupled face
00638         // anywhere the corresponding index in faceVertexRestore will be set.
00639 
00640         // Now combine the localPointSet and the (sychronised)
00641         // boundary-points-to-restore.
00642 
00643         forAll(savedFaces_, saveI)
00644         {
00645             label bFaceI = savedFaceLabels_[saveI] - mesh_.nInternalFaces();
00646 
00647             if (bFaceI >= 0)
00648             {
00649                 const boolList& fRestore = faceVertexRestore[bFaceI];
00650 
00651                 const face& savedFace = savedFaces_[saveI];
00652 
00653                 forAll(fRestore, fp)
00654                 {
00655                     // Does neighbour require point restored?
00656                     if (fRestore[fp])
00657                     {
00658                         if (savedFace[fp] >= 0)
00659                         {
00660                             FatalErrorIn
00661                             (
00662                                 "removePoints::getUnrefimentSet"
00663                                 "(const labelList&, labelList&, labelList&)"
00664                                 " const"
00665                             )   << "Problem: on coupled face:"
00666                                 << savedFaceLabels_[saveI]
00667                                 << " fc:"
00668                                 << mesh_.faceCentres()[savedFaceLabels_[saveI]]
00669                                 << endl
00670                                 << " my neighbour tries to restore the vertex"
00671                                 << " at index " << fp
00672                                 << " whereas my saved face:" << savedFace
00673                                 << " does not indicate a deleted vertex"
00674                                 << " at that position."
00675                                 << abort(FatalError);
00676                         }
00677 
00678                         label savedPointI = -savedFace[fp]-1;
00679 
00680                         localPointsSet.insert(savedPointI);
00681                     }
00682                 }
00683             }
00684         }
00685     }
00686 
00687     localPoints = localPointsSet.toc();
00688 
00689 
00690     // Collect all saved faces using any localPointsSet 
00691     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00692 
00693     labelHashSet localFacesSet(2*undoFaces.size());
00694 
00695     forAll(savedFaces_, saveI)
00696     {
00697         const face& savedFace = savedFaces_[saveI];
00698 
00699         forAll(savedFace, fp)
00700         {
00701             if (savedFace[fp] < 0)
00702             {
00703                 label savedPointI = -savedFace[fp]-1;
00704 
00705                 if (localPointsSet.found(savedPointI))
00706                 {
00707                     localFacesSet.insert(saveI);
00708                 }
00709             }
00710         }
00711     }
00712     localFaces = localFacesSet.toc();
00713 
00714 
00715     // Note that at this point the localFaces to restore can contain points
00716     // that are not going to be restored! The localFaces though will
00717     // be guaranteed to be all the ones affected by the restoration of the
00718     // localPoints.
00719 }
00720 
00721 
00722 void Foam::removePoints::setUnrefinement
00723 (
00724     const labelList& localFaces,
00725     const labelList& localPoints,
00726     polyTopoChange& meshMod
00727 )
00728 {
00729     if (!undoable_)
00730     {
00731         FatalErrorIn
00732         (
00733             "removePoints::setUnrefinement(const labelList&"
00734             ", labelList&, polyTopoChange&)"
00735         )   << "removePoints not constructed with"
00736             << " unrefinement capability."
00737             << abort(FatalError);
00738     }
00739 
00740 
00741     // Per savedPoint -1 or the restored point label
00742     labelList addedPoints(savedPoints_.size(), -1);
00743 
00744     forAll(localPoints, i)
00745     {
00746         label localI = localPoints[i];
00747 
00748         if (savedPoints_[localI] == wallPoint::greatPoint)
00749         {
00750             FatalErrorIn
00751             (
00752                 "removePoints::setUnrefinement(const labelList&"
00753                 ", labelList&, polyTopoChange&)"
00754             )   << "Saved point " << localI << " already restored!"
00755                 << abort(FatalError);
00756         }
00757 
00758         addedPoints[localI] = meshMod.setAction
00759         (
00760             polyAddPoint
00761             (
00762                 savedPoints_[localI],   // point
00763                 -1,                     // master point
00764                 -1,                     // zone for point
00765                 true                    // supports a cell
00766             )
00767         );
00768 
00769         // Mark the restored points so they are not restored again.
00770         savedPoints_[localI] = wallPoint::greatPoint;
00771     }
00772 
00773     forAll(localFaces, i)
00774     {
00775         label saveI = localFaces[i];
00776 
00777         // Modify indices into saved points (so < 0) to point to the
00778         // added points.
00779         face& savedFace = savedFaces_[saveI];
00780 
00781         face newFace(savedFace.size());
00782         label newFp = 0;
00783 
00784         bool hasSavedPoints = false;
00785 
00786         forAll(savedFace, fp)
00787         {
00788             if (savedFace[fp] < 0)
00789             {
00790                 label addedPointI = addedPoints[-savedFace[fp]-1];
00791 
00792                 if (addedPointI != -1)
00793                 {
00794                     savedFace[fp] = addedPointI;
00795                     newFace[newFp++] = addedPointI;
00796                 }
00797                 else
00798                 {
00799                     hasSavedPoints = true;
00800                 }
00801             }
00802             else
00803             {
00804                 newFace[newFp++] = savedFace[fp];
00805             }
00806         }
00807         newFace.setSize(newFp);
00808 
00809         modifyFace(savedFaceLabels_[saveI], newFace, meshMod);
00810 
00811         if (!hasSavedPoints)
00812         {
00813             // Face fully restored. Mark for compaction later on
00814             savedFaceLabels_[saveI] = -1;
00815             savedFaces_[saveI].clear();
00816         }
00817     }
00818 
00819 
00820     // Compact face labels
00821     label newSaveI = 0;
00822 
00823     forAll(savedFaceLabels_, saveI)
00824     {
00825         if (savedFaceLabels_[saveI] != -1)
00826         {
00827             if (newSaveI != saveI)
00828             {
00829                 savedFaceLabels_[newSaveI] = savedFaceLabels_[saveI];
00830                 savedFaces_[newSaveI].transfer(savedFaces_[saveI]);
00831             }
00832             newSaveI++;
00833         }
00834     }
00835 
00836     savedFaceLabels_.setSize(newSaveI);
00837     savedFaces_.setSize(newSaveI);
00838 
00839 
00840     // Check that all faces have been restored that use any restored points
00841     if (debug)
00842     {
00843         forAll(savedFaceLabels_, saveI)
00844         {
00845             const face& savedFace = savedFaces_[saveI];
00846 
00847             forAll(savedFace, fp)
00848             {
00849                 if (savedFace[fp] < 0)
00850                 {
00851                     label addedPointI = addedPoints[-savedFace[fp]-1];
00852 
00853                     if (addedPointI != -1)
00854                     {
00855                         FatalErrorIn("setUnrefinement")
00856                             << "Face:" << savedFaceLabels_[saveI]
00857                             << " savedVerts:" << savedFace
00858                             << " uses restored point:" << -savedFace[fp]-1
00859                             << " with new pointlabel:" << addedPointI
00860                             << abort(FatalError);
00861                     }
00862                 }
00863             }
00864         }
00865     }
00866 }
00867 
00868 
00869 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd