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 "polyMeshGenModifier.H"
29 #include "polyMeshGenAddressing.H"
30 #include "demandDrivenData.H"
31 #include "labelledPoint.H"
32 #include "helperFunctions.H"
34 // #define DEBUGSearch
36 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 void polyMeshGenModifier::addBufferCells()
45 if( !Pstream::parRun() )
48 Info << "Adding buffer layers" << endl;
50 const labelList& owner = mesh_.owner();
51 pointFieldPMG& points = mesh_.points();
52 faceListPMG& faces = facesAccess();
53 const cellListPMG& cells = mesh_.cells();
54 const PtrList<processorBoundaryPatch>& procBoundaries = mesh_.procBoundaries();
55 const polyMeshGenAddressing& addressing = mesh_.addressingData();
56 const labelLongList& globalPointLabel = addressing.globalPointLabel();
57 const Map<label>& globalToLocal = addressing.globalToLocalPointAddressing();
60 forAll(procBoundaries, patchI)
62 labelHashSet pointsToSend;
64 label faceI = procBoundaries[patchI].patchStart();
65 const label end = faceI + procBoundaries[patchI].patchSize();
66 for(;faceI<end;++faceI)
68 const cell& c = cells[owner[faceI]];
71 const face& f = faces[c[fI]];
74 pointsToSend.insert(f[pI]);
79 List<labelledPoint> ptsToSend(pointsToSend.size());
80 forAllConstIter(labelHashSet, pointsToSend, it)
84 globalPointLabel[it.key()],
91 procBoundaries[patchI].neiProcNo()
94 toOtherProc << ptsToSend;
97 Map<label> globalToLocalReceived;
98 forAll(procBoundaries, patchI)
100 List<labelledPoint> receivedPoints;
101 IPstream fromOtherProc
104 procBoundaries[patchI].neiProcNo()
107 fromOtherProc >> receivedPoints;
109 forAll(receivedPoints, i)
111 if( globalToLocal.found(receivedPoints[i].pointLabel()) )
113 if( globalToLocalReceived.found(receivedPoints[i].pointLabel()) )
116 globalToLocalReceived.insert
118 receivedPoints[i].pointLabel(),
121 points.append(receivedPoints[i].coordinates());
125 //- send cells to other processors
126 forAll(procBoundaries, patchI)
128 labelHashSet cellsToSend;
130 label faceI = procBoundaries[patchI].patchStart();
131 const label end = faceI + procBoundaries[patchI].patchSize();
132 for(;faceI<end;++faceI)
133 cellsToSend.insert(owner[faceI]);
135 labelLongList flattenedCells;
136 forAllConstIter(labelHashSet, cellsToSend, it)
138 const cell& c = cells[it.key()];
140 //- the number of faces in the cell
141 flattenedCells.append(c.size());
146 const face& f = faces[c[fI]];
148 //- the number of vertices in the face
149 flattenedCells.append(f.size());
151 flattenedCells.append(globalPointLabel[f[pI]]);
158 procBoundaries[patchI].neiProcNo()
161 toOtherProc << flattenedCells;
164 forAll(procBoundaries, patchI)
166 word subsetName = "processor_";
167 subsetName += help::scalarToText(procBoundaries[patchI].neiProcNo());
168 const label subsetID = mesh_.addCellSubset(subsetName);
170 labelList receivedCells;
172 IPstream fromOtherProc
175 procBoundaries[patchI].neiProcNo()
178 fromOtherProc >> receivedCells;
181 while( counter < receivedCells.size() )
183 faceList c(receivedCells[counter++]);
186 c[fI].setSize(receivedCells[counter++]);
189 const label gpI = receivedCells[counter++];
191 if( globalToLocal.found(gpI) )
193 c[fI][pI] = globalToLocal[gpI];
197 c[fI][pI] = globalToLocalReceived[gpI];
202 mesh_.addCellToSubset(subsetID, cells.size());
209 Info << "Finished adding buffer layers" << endl;
212 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
214 } // End namespace Foam
216 // ************************************************************************* //