FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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