1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software; you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*----------------------------------------------------------------------------*/
27 #include "meshRefinement.H"
28 #include "combineFaces.H"
29 #include "polyTopoChange.H"
30 #include "removePoints.H"
33 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
36 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
38 // Merge faces that are in-line.
39 Foam::label Foam::meshRefinement::mergePatchFaces
42 const scalar concaveCos,
43 const labelList& patchIDs
46 // Patch face merging engine
47 combineFaces faceCombiner(mesh_);
49 const polyBoundaryMesh& patches = mesh_.boundaryMesh();
51 // Pick up all candidate cells on boundary
52 labelHashSet boundaryCells(mesh_.nFaces()-mesh_.nInternalFaces());
56 label patchI = patchIDs[i];
58 const polyPatch& patch = patches[patchI];
64 boundaryCells.insert(mesh_.faceOwner()[patch.start()+i]);
69 // Get all sets of faces that can be merged
70 labelListList mergeSets
72 faceCombiner.getMergeSets
80 label nFaceSets = returnReduce(mergeSets.size(), sumOp<label>());
82 Info<< "mergePatchFaces : Merging " << nFaceSets
83 << " sets of faces." << endl;
87 // Topology changes container
88 polyTopoChange meshMod(mesh_);
90 // Merge all faces of a set into the first face of the set. Remove
92 faceCombiner.setRefinement(mergeSets, meshMod);
94 // Change the mesh (no inflation)
95 autoPtr<mapPolyMesh> map = meshMod.changeMesh(mesh_, false, true);
98 mesh_.updateMesh(map);
100 // Move mesh (since morphing does not do this)
101 if (map().hasMotionPoints())
103 mesh_.movePoints(map().preMotionPoints());
107 // Delete mesh volumes. No other way to do this?
111 faceCombiner.updateMesh(map);
113 // Get the kept faces that need to be recalculated.
114 // Merging two boundary faces might shift the cell centre
115 // (unless the faces are absolutely planar)
116 labelHashSet retestFaces(6*mergeSets.size());
118 forAll(mergeSets, setI)
120 label oldMasterI = mergeSets[setI][0];
122 label faceI = map().reverseFaceMap()[oldMasterI];
124 // faceI is always uncoupled boundary face
125 const cell& cFaces = mesh_.cells()[mesh_.faceOwner()[faceI]];
129 retestFaces.insert(cFaces[i]);
132 updateMesh(map, retestFaces.toc());
140 // Remove points not used by any face or points used by only two faces where
141 // the edges are in line
142 Foam::autoPtr<Foam::mapPolyMesh> Foam::meshRefinement::mergeEdges
147 // Point removal analysis engine
148 removePoints pointRemover(mesh_);
150 // Count usage of points
151 boolList pointCanBeDeleted;
152 label nRemove = pointRemover.countPointUsage(minCos, pointCanBeDeleted);
154 Info<< "Removing " << nRemove
155 << " straight edge points." << endl;
157 autoPtr<mapPolyMesh> map;
161 // Save my local faces that will change. These changed faces might
162 // cause a shift in the cell centre which needs to be retested.
163 // Have to do this before changing mesh since point will be removed.
164 labelHashSet retestOldFaces(nRemove / Pstream::nProcs());
167 const faceList& faces = mesh_.faces();
171 const face& f = faces[faceI];
175 if (pointCanBeDeleted[f[fp]])
177 retestOldFaces.insert(faceI);
184 // Topology changes container
185 polyTopoChange meshMod(mesh_);
187 pointRemover.setRefinement(pointCanBeDeleted, meshMod);
189 // Change the mesh (no inflation)
190 map = meshMod.changeMesh(mesh_, false, true);
193 mesh_.updateMesh(map);
195 // Move mesh (since morphing does not do this)
196 if (map().hasMotionPoints())
198 mesh_.movePoints(map().preMotionPoints());
202 // Delete mesh volumes. No other way to do this?
206 pointRemover.updateMesh(map);
208 // Get the kept faces that need to be recalculated.
209 labelHashSet retestFaces(6*retestOldFaces.size());
211 const cellList& cells = mesh_.cells();
213 forAllConstIter(labelHashSet, retestOldFaces, iter)
215 label faceI = map().reverseFaceMap()[iter.key()];
217 const cell& ownFaces = cells[mesh_.faceOwner()[faceI]];
221 retestFaces.insert(ownFaces[i]);
224 if (mesh_.isInternalFace(faceI))
226 const cell& neiFaces = cells[mesh_.faceNeighbour()[faceI]];
230 retestFaces.insert(neiFaces[i]);
234 updateMesh(map, retestFaces.toc());
241 // ************************************************************************* //