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 "decomposeCells.H"
29 #include "demandDrivenData.H"
30 #include "polyMeshGenAddressing.H"
31 #include "meshSurfaceEngine.H"
32 #include "decomposeFaces.H"
33 #include "labelLongList.H"
35 //#define DEBUGDecompose
37 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 void decomposeCells::decomposeMesh(const boolList& decomposeCell)
44 checkFaceConnections(decomposeCell);
46 createPointsAndCellFaces(decomposeCell);
48 storeBoundaryFaces(decomposeCell);
50 removeDecomposedCells(decomposeCell);
54 # ifdef DEBUGDecompose
55 mesh_.addressingData().checkMesh();
59 void decomposeCells::checkFaceConnections(const boolList& decomposeCell)
61 const faceListPMG& faces = mesh_.faces();
62 const cellListPMG& cells = mesh_.cells();
64 boolList decomposeFace(faces.size(), false);
67 if( decomposeCell[cellI] )
69 DynList<label, 32> vrt;
70 DynList<edge, 64> edges;
71 DynList<DynList<label, 8> > faceEdges;
72 DynList<DynList<label, 2>, 64> edgeFaces;
74 findAddressingForCell(cellI, vrt, edges, faceEdges, edgeFaces);
78 const DynList<label, 8>& fEdges = faceEdges[fI];
80 labelHashSet neiFaces;
83 label neiFace = edgeFaces[fEdges[feI]][0];
85 neiFace = edgeFaces[fEdges[feI]][1];
87 if( neiFaces.found(neiFace) )
89 decomposeFace[cells[cellI][fI]] = true;
93 neiFaces.insert(neiFace);
100 if( Pstream::parRun() )
102 const PtrList<processorBoundaryPatch>& procBoundaries =
103 mesh_.procBoundaries();
105 //- send information to the neighbour processor
106 forAll(procBoundaries, patchI)
108 const label start = procBoundaries[patchI].patchStart();
109 boolList decFace(procBoundaries[patchI].patchSize(), false);
110 const label size = decFace.size();
112 for(label i=0;i<size;++i)
114 if( decomposeFace[start+i] )
121 procBoundaries[patchI].neiProcNo(),
125 toOtherProc << decFace;
128 //- receive information from the neighbour processor
129 forAll(procBoundaries, patchI)
133 IPstream fromOtherProc
136 procBoundaries[patchI].neiProcNo()
139 fromOtherProc >> decFace;
141 const label start = procBoundaries[patchI].patchStart();
145 decomposeFace[start+i] = true;
150 //- decompose faces which would cause invalid connections
151 decomposeFaces(mesh_).decomposeMeshFaces(decomposeFace);
154 void decomposeCells::createPointsAndCellFaces(const boolList& decomposeCell)
156 facesOfNewCells_.clear();
158 forAll(decomposeCell, cI)
159 if( decomposeCell[cI] )
161 decomposeCellIntoPyramids(cI);
165 void decomposeCells::storeBoundaryFaces(const boolList& decomposeCell)
167 meshSurfaceEngine mse(mesh_);
168 const faceList::subList& bFaces = mse.boundaryFaces();
169 const labelList& facePatch = mse.boundaryFacePatches();
173 newBoundaryFaces_.appendList(bFaces[bfI]);
174 newBoundaryPatches_.append(facePatch[bfI]);
178 void decomposeCells::removeDecomposedCells(const boolList& decomposeCell)
180 # ifdef DEBUGDecompose
181 Info << "Number of cells before removal " << mesh_.cells().size() << endl;
184 polyMeshGenModifier meshModifier(mesh_);
185 meshModifier.removeCells(decomposeCell, false);
187 # ifdef DEBUGDecompose
188 Info << "Number of cells after removal " << mesh_.cells().size() << endl;
192 void decomposeCells::addNewCells()
194 Info << "Adding new cells " << endl;
195 polyMeshGenModifier(mesh_).addCells(facesOfNewCells_);
196 facesOfNewCells_.clear();
197 Info << "Reordering bnd faces" << endl;
198 polyMeshGenModifier(mesh_).reorderBoundaryFaces();
200 Info << "Finding bnd faces" << endl;
201 const faceListPMG& faces = mesh_.faces();
202 const labelList& owner = mesh_.owner();
203 const VRWGraph& pointFaces = mesh_.addressingData().pointFaces();
205 labelLongList newBoundaryOwners;
207 forAll(newBoundaryFaces_, faceI)
209 face bf(newBoundaryFaces_.sizeOfRow(faceI));
210 forAllRow(newBoundaryFaces_, faceI, pI)
211 bf[pI] = newBoundaryFaces_(faceI, pI);
213 # ifdef DEBUGDecompose
214 Info << "Finding cell for boundary face " << bf << endl;
216 forAllRow(pointFaces, bf[0], pfI)
217 if( bf == faces[pointFaces(bf[0], pfI)] )
222 "void decomposeCells::addNewCells()"
223 ) << "Face " << bf << " does not exist in the mesh"
224 << abort(FatalError);
227 forAllRow(pointFaces, bf[0], pfI)
229 const label fLabel = pointFaces(bf[0], pfI);
230 if( (mesh_.faceIsInPatch(fLabel) != -1) && (bf == faces[fLabel]) )
232 # ifdef DEBUGDecompose
233 Info << "Boundary face " << bf << " is in cell "
234 << owner[fLabel]] << endl;
237 newBoundaryOwners.append(owner[fLabel]);
242 polyMeshGenModifier(mesh_).replaceBoundary
250 polyMeshGenModifier(mesh_).removeUnusedVertices();
251 polyMeshGenModifier(mesh_).clearAll();
254 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//
256 } // End namespace Foam
258 // ************************************************************************* //