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

meshRefinementMerge.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 "meshRefinement.H"
00028 #include "combineFaces.H"
00029 #include "polyTopoChange.H"
00030 #include "removePoints.H"
00031 
00032 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00033 
00034 // Merge faces that are in-line.
00035 Foam::label Foam::meshRefinement::mergePatchFaces
00036 (
00037     const scalar minCos,
00038     const scalar concaveCos,
00039     const labelList& patchIDs
00040 )
00041 {
00042     // Patch face merging engine
00043     combineFaces faceCombiner(mesh_);
00044 
00045     const polyBoundaryMesh& patches = mesh_.boundaryMesh();
00046 
00047     // Pick up all candidate cells on boundary
00048     labelHashSet boundaryCells(mesh_.nFaces()-mesh_.nInternalFaces());
00049 
00050     forAll(patchIDs, i)
00051     {
00052         label patchI = patchIDs[i];
00053 
00054         const polyPatch& patch = patches[patchI];
00055 
00056         if (!patch.coupled())
00057         {
00058             forAll(patch, i)
00059             {
00060                 boundaryCells.insert(mesh_.faceOwner()[patch.start()+i]);
00061             }
00062         }
00063     }
00064 
00065     // Get all sets of faces that can be merged
00066     labelListList mergeSets
00067     (
00068         faceCombiner.getMergeSets
00069         (
00070             minCos,
00071             concaveCos,
00072             boundaryCells
00073         )
00074     );
00075 
00076     label nFaceSets = returnReduce(mergeSets.size(), sumOp<label>());
00077 
00078     Info<< "mergePatchFaces : Merging " << nFaceSets
00079         << " sets of faces." << endl;
00080 
00081     if (nFaceSets > 0)
00082     {
00083         // Topology changes container
00084         polyTopoChange meshMod(mesh_);
00085 
00086         // Merge all faces of a set into the first face of the set. Remove
00087         // unused points.
00088         faceCombiner.setRefinement(mergeSets, meshMod);
00089 
00090         // Change the mesh (no inflation)
00091         autoPtr<mapPolyMesh> map = meshMod.changeMesh(mesh_, false, true);
00092 
00093         // Update fields
00094         mesh_.updateMesh(map);
00095 
00096         // Move mesh (since morphing does not do this)
00097         if (map().hasMotionPoints())
00098         {
00099             mesh_.movePoints(map().preMotionPoints());
00100         }
00101         else
00102         {
00103             // Delete mesh volumes. No other way to do this?
00104             mesh_.clearOut();
00105         }
00106 
00107         if (overwrite())
00108         {
00109             mesh_.setInstance(oldInstance());
00110         }
00111 
00112         faceCombiner.updateMesh(map);
00113 
00114         // Get the kept faces that need to be recalculated.
00115         // Merging two boundary faces might shift the cell centre
00116         // (unless the faces are absolutely planar)
00117         labelHashSet retestFaces(6*mergeSets.size());
00118 
00119         forAll(mergeSets, setI)
00120         {
00121             label oldMasterI = mergeSets[setI][0];
00122 
00123             label faceI = map().reverseFaceMap()[oldMasterI];
00124 
00125             // faceI is always uncoupled boundary face
00126             const cell& cFaces = mesh_.cells()[mesh_.faceOwner()[faceI]];
00127 
00128             forAll(cFaces, i)
00129             {
00130                 retestFaces.insert(cFaces[i]);
00131             }
00132         }
00133         updateMesh(map, retestFaces.toc());
00134     }
00135 
00136 
00137     return nFaceSets;
00138 }
00139 
00140 
00141 // Remove points not used by any face or points used by only two faces where
00142 // the edges are in line
00143 Foam::autoPtr<Foam::mapPolyMesh> Foam::meshRefinement::mergeEdges
00144 (
00145     const scalar minCos
00146 )
00147 {
00148     // Point removal analysis engine
00149     removePoints pointRemover(mesh_);
00150 
00151     // Count usage of points
00152     boolList pointCanBeDeleted;
00153     label nRemove = pointRemover.countPointUsage(minCos, pointCanBeDeleted);
00154 
00155     Info<< "Removing " << nRemove
00156         << " straight edge points." << endl;
00157 
00158     autoPtr<mapPolyMesh> map;
00159 
00160     if (nRemove > 0)
00161     {
00162         // Save my local faces that will change. These changed faces might
00163         // cause a shift in the cell centre which needs to be retested.
00164         // Have to do this before changing mesh since point will be removed.
00165         labelHashSet retestOldFaces(nRemove / Pstream::nProcs());
00166 
00167         {
00168             const faceList& faces = mesh_.faces();
00169 
00170             forAll(faces, faceI)
00171             {
00172                 const face& f = faces[faceI];
00173 
00174                 forAll(f, fp)
00175                 {
00176                     if (pointCanBeDeleted[f[fp]])
00177                     {
00178                         retestOldFaces.insert(faceI);
00179                         break;
00180                     }
00181                 }
00182             }
00183         }
00184 
00185         // Topology changes container
00186         polyTopoChange meshMod(mesh_);
00187 
00188         pointRemover.setRefinement(pointCanBeDeleted, meshMod);
00189 
00190         // Change the mesh (no inflation)
00191         map = meshMod.changeMesh(mesh_, false, true);
00192 
00193         // Update fields
00194         mesh_.updateMesh(map);
00195 
00196         // Move mesh (since morphing does not do this)
00197         if (map().hasMotionPoints())
00198         {
00199             mesh_.movePoints(map().preMotionPoints());
00200         }
00201         else
00202         {
00203             // Delete mesh volumes. No other way to do this?
00204             mesh_.clearOut();
00205         }
00206 
00207         if (overwrite())
00208         {
00209             mesh_.setInstance(oldInstance());
00210         }
00211 
00212         pointRemover.updateMesh(map);
00213 
00214         // Get the kept faces that need to be recalculated.
00215         labelHashSet retestFaces(6*retestOldFaces.size());
00216 
00217         const cellList& cells = mesh_.cells();
00218 
00219         forAllConstIter(labelHashSet, retestOldFaces, iter)
00220         {
00221             label faceI = map().reverseFaceMap()[iter.key()];
00222 
00223             const cell& ownFaces = cells[mesh_.faceOwner()[faceI]];
00224 
00225             forAll(ownFaces, i)
00226             {
00227                 retestFaces.insert(ownFaces[i]);
00228             }
00229 
00230             if (mesh_.isInternalFace(faceI))
00231             {
00232                 const cell& neiFaces = cells[mesh_.faceNeighbour()[faceI]];
00233 
00234                 forAll(neiFaces, i)
00235                 {
00236                     retestFaces.insert(neiFaces[i]);
00237                 }
00238             }
00239         }
00240         updateMesh(map, retestFaces.toc());
00241     }
00242 
00243     return map;
00244 }
00245 
00246 
00247 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd