1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | cfMesh: A library for mesh generation
5 \\ / A nd | Author: Franjo Juretic (franjo.juretic@c-fields.com)
6 \\/ M anipulation | Copyright (C) Creative Fields, Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of cfMesh.
11 cfMesh 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 3 of the License, or (at your
14 option) any later version.
16 cfMesh 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 cfMesh. If not, see <http://www.gnu.org/licenses/>.
26 \*---------------------------------------------------------------------------*/
28 #include "surfaceMorpherCells.H"
29 #include "demandDrivenData.H"
30 #include "helperFunctions.H"
31 #include "primitiveMesh.H"
39 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 bool surfaceMorpherCells::removeCellsWithAllVerticesAtTheBoundary()
48 boolList removeCells(cellFlags_.size(), false);
50 const faceListPMG& faces = mesh_.faces();
51 const cellListPMG& cells = mesh_.cells();
56 forAll(cellFlags_, cellI)
57 if( cellFlags_[cellI] & BOUNDARY )
59 const cell& c = cells[cellI];
60 //- remove cells which have all their vertices at the boundary
61 bool allBoundary(true);
63 const labelList labels = c.labels(faces);
66 if( !boundaryVertex_[labels[lI]] )
76 removeCells[cellI] = true;
79 //- remove cells which are not topologically closed
81 DynList<direction> nAppearances;
85 const face& f = faces[c[fI]];
88 const label pos = edges.containsAtPosition(f.faceEdge(eI));
92 edges.append(f.faceEdge(eI));
93 nAppearances.append(1);
102 forAll(nAppearances, eI)
103 if( nAppearances[eI] != 2 )
107 removeCells[cellI] = true;
112 if( Pstream::parRun() )
113 reduce(nRemoved, sumOp<label>());
117 Info << "Removing " << nRemoved
118 << " cells which cannot be morphed" << endl;
119 polyMeshGenModifier(mesh_).removeCells(removeCells);
122 if( Pstream::parRun() )
124 reduce(changed, maxOp<bool>());
130 bool surfaceMorpherCells::morphBoundaryFaces()
132 Info << "Morphing boundary faces" << endl;
134 newBoundaryFaces_.setSize(0);
135 newBoundaryOwners_.setSize(0);
136 newBoundaryPatches_.setSize(0);
138 const faceListPMG& faces = mesh_.faces();
139 const cellListPMG& cells = mesh_.cells();
144 if( cellFlags_[cellI] & BOUNDARY )
146 const cell& c = cells[cellI];
148 DynList<label> bFaces;
151 if( mesh_.faceIsInPatch(c[fI]) != -1 )
152 bFaces.append(c[fI]);
155 Info << "Boundary faces in cell " << cellI
156 << " are " << bFaces << endl;
158 Info << "Face " << bFaces[bfI] << " is "
159 << faces[bFaces[bfI]] << endl;
162 boolList mergedFaces(bFaces.size(), false);
164 face mf = faces[bFaces[0]];
165 mergedFaces[0] = true;
171 for(label i=1;i<bFaces.size();++i)
173 if( mergedFaces[i] ) continue;
175 const face& bf = faces[bFaces[i]];
176 const edgeList bEdges = bf.edges();
177 const edgeList mEdges = mf.edges();
179 direction nSharedEdges(0);
182 if( bEdges[eI] == mEdges[eJ] )
185 direction nSharedPoints(0);
188 if( bf[pI] == mf[pJ] )
193 ((nSharedEdges + 1) == nSharedPoints)
196 mf = help::mergeTwoFaces(mf, bf);
197 mergedFaces[i] = true;
202 cellFlags_[cellI] |= CHANGED;
205 } while( !finished );
207 newBoundaryFaces_.appendList(mf);
208 newBoundaryOwners_.append(cellI);
209 newBoundaryPatches_.append(0);
212 Info << "Adding merged face " << mf << endl;
215 for(label i=1;i<bFaces.size();++i)
216 if( !mergedFaces[i] )
218 newBoundaryFaces_.appendList(faces[bFaces[i]]);
219 newBoundaryOwners_.append(cellI);
220 newBoundaryPatches_.append(0);
223 Info << "Adding untouched boundary face "
224 << faces[bFaces[i]] << endl;
229 if( Pstream::parRun() )
231 reduce(changed, maxOp<bool>());
236 replaceMeshBoundary();
240 labelHashSet zipCells;
241 mesh_.addressingData().checkCellsZipUp(true, &zipCells);
242 if( zipCells.size() )
244 Info << "Cells " << zipCells << " are not zipped!!" << endl;
245 ::exit(EXIT_FAILURE);
247 mesh_.clearAddressingData();
250 Info << "Finished morphing boundary faces" << endl;
255 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
257 } // End namespace Foam
259 // ************************************************************************* //