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 "checkCellConnectionsOverFaces.H"
29 #include "labelLongList.H"
30 #include "labelledPair.H"
39 #include "helperFunctions.H"
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48 // * * * * * * * * * * Private member functions * * * * * * * * * * * * * * * //
50 namespace meshConnectionsHelper
53 class meshConnectionsNeighbourOperator
55 const polyMeshGen& mesh_;
59 meshConnectionsNeighbourOperator(const polyMeshGen& mesh)
66 return mesh_.cells().size();
69 void operator()(const label cellI, DynList<label>& neighbourCells) const
71 neighbourCells.clear();
73 const labelList& owner = mesh_.owner();
74 const labelList& neighbour = mesh_.neighbour();
76 const cell& c = mesh_.cells()[cellI];
80 label nei = owner[c[fI]];
83 nei = neighbour[c[fI]];
86 neighbourCells.append(nei);
90 template<class labelListType>
93 std::map<label, DynList<label> >& neiGroups,
94 const labelListType& elementInGroup,
95 const DynList<label>& localGroupLabel
98 const PtrList<processorBoundaryPatch>& procBoundaries =
99 mesh_.procBoundaries();
100 const labelList& owner = mesh_.owner();
102 //- send the data to other processors
103 forAll(procBoundaries, patchI)
105 const label start = procBoundaries[patchI].patchStart();
106 const label size = procBoundaries[patchI].patchSize();
108 labelList groupOwner(procBoundaries[patchI].patchSize());
109 for(label faceI=0;faceI<size;++faceI)
111 const label groupI = elementInGroup[owner[start+faceI]];
115 groupOwner[faceI] = -1;
119 groupOwner[faceI] = localGroupLabel[groupI];
125 procBoundaries[patchI].neiProcNo(),
126 groupOwner.byteSize()
129 toOtherProc << groupOwner;
132 //- receive data from other processors
133 forAll(procBoundaries, patchI)
135 const label start = procBoundaries[patchI].patchStart();
137 labelList receivedData;
139 IPstream fromOtherProc
142 procBoundaries[patchI].neiProcNo()
145 fromOtherProc >> receivedData;
147 forAll(receivedData, faceI)
149 if( receivedData[faceI] < 0 )
152 const label groupI = elementInGroup[owner[start+faceI]];
157 DynList<label>& ng = neiGroups[localGroupLabel[groupI]];
159 //- store the connection over the inter-processor boundary
160 ng.appendIfNotIn(receivedData[faceI]);
166 class meshConnectionsSelectorOperator
171 meshConnectionsSelectorOperator()
174 bool operator()(const label cellI) const
180 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
182 } // End namespace meshConnectionsHelper
184 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
186 void checkCellConnectionsOverFaces::findCellGroups()
188 Info << "Checking cell connections" << endl;
195 meshConnectionsHelper::meshConnectionsNeighbourOperator(mesh_),
196 meshConnectionsHelper::meshConnectionsSelectorOperator()
199 Info << "Finished checking cell connections" << endl;
202 // * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * * * * //
205 checkCellConnectionsOverFaces::checkCellConnectionsOverFaces(polyMeshGen& mesh)
208 cellGroup_(mesh.cells().size(), -1),
214 // * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * * * * * //
216 checkCellConnectionsOverFaces::~checkCellConnectionsOverFaces()
219 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
221 bool checkCellConnectionsOverFaces::checkCellGroups()
226 Warning << "Mesh has " << nGroups_ << " unconnected regions" << endl;
228 labelList nCellsInGroup(nGroups_, 0);
230 forAll(cellGroup_, cI)
231 ++nCellsInGroup[cellGroup_[cI]];
233 if( Pstream::parRun() )
235 forAll(nCellsInGroup, groupI)
236 reduce(nCellsInGroup[groupI], sumOp<label>());
239 //- find groups which has most cells this group will be kept
241 forAll(nCellsInGroup, groupI)
242 if( nCellsInGroup[groupI] > maxGroup )
244 maxGroup = nCellsInGroup[groupI];
248 //- remove cells which are not in the group which has max num of cells
249 boolList removeCell(mesh_.cells().size(), false);
250 forAll(cellGroup_, cellI)
251 if( cellGroup_[cellI] != nGroups_ )
252 removeCell[cellI] = true;
254 polyMeshGenModifier(mesh_).removeCells(removeCell);
259 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
261 } // End namespace Foam
263 // ************************************************************************* //