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 "demandDrivenData.H"
38 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40 void polyMeshGenModifier::addProcessorFaces
42 const VRWGraph& procFaces,
43 const labelLongList& facePatches
46 Info << "Adding processor faces" << endl;
48 PtrList<processorBoundaryPatch>& procBoundaries = mesh_.procBoundaries_;
50 labelList nAddedFaces(procBoundaries.size(), 0);
51 forAll(facePatches, fI)
52 ++nAddedFaces[facePatches[fI]];
54 labelList newPatchStart(procBoundaries.size());
55 newPatchStart[0] = procBoundaries[0].patchStart();
56 for(label i=1;i<procBoundaries.size();++i)
59 procBoundaries[i-1].patchSize() + nAddedFaces[i-1];
61 //- set new size of the faceListPMG
62 faceListPMG& faces = mesh_.faces_;
63 const label nFaces = faces.size();
64 faces.setSize(nFaces+procFaces.size());
66 label endProcFaces(0);
67 forAllReverse(procBoundaries, patchI)
69 const processorBoundaryPatch& wp = procBoundaries[patchI];
70 endProcFaces = Foam::max(endProcFaces, wp.patchStart()+wp.patchSize());
73 //- move faces to their new positions
74 labelLongList newFaceLabel(nFaces, -1);
76 if( endProcFaces != nFaces )
78 for(label faceI=nFaces-1;faceI>=endProcFaces;--faceI)
80 newFaceLabel[faceI] = faceI+facePatches.size();
81 faces[faceI+facePatches.size()].transfer(faces[faceI]);
85 labelList faceIndex(procBoundaries.size());
86 for(label patchI=procBoundaries.size()-1;patchI>=0;--patchI)
88 const label start = procBoundaries[patchI].patchStart();
89 const label end = start + procBoundaries[patchI].patchSize();
90 const label shift = newPatchStart[patchI] - start;
94 for(label faceI=end-1;faceI>=start;--faceI)
96 faces[faceI+shift].transfer(faces[faceI]);
97 newFaceLabel[faceI] = faceI+shift;
101 //- set new start for the given patch
102 procBoundaries[patchI].patchStart() = newPatchStart[patchI];
104 newPatchStart[patchI] + procBoundaries[patchI].patchSize();
105 procBoundaries[patchI].patchSize() += nAddedFaces[patchI];
108 //- add new faces into patches
109 forAll(procFaces, fI)
111 face f(procFaces.sizeOfRow(fI));
113 f[pI] = procFaces(fI, pI);
115 faces[faceIndex[facePatches[fI]]++].transfer(f);
119 cellListPMG& cells = mesh_.cells_;
121 # pragma omp parallel for schedule(guided)
125 cell& c = cells[cellI];
128 if( newFaceLabel[c[fI]] != -1 )
129 c[fI] = newFaceLabel[c[fI]];
134 mesh_.updateFaceSubsets(newFaceLabel);
136 Info << "Finished adding processor faces" << endl;
139 label polyMeshGenModifier::addProcessorPatch(const label otherProcLabel)
141 const label nProcPatches = mesh_.procBoundaries().size();
143 PtrList<processorBoundaryPatch>& procBoundaries =
144 this->procBoundariesAccess();
146 procBoundaries.setSize(nProcPatches + 1);
148 std::ostringstream ss;
149 ss << Pstream::myProcNo();
150 std::ostringstream ssNei;
151 ssNei << otherProcLabel;
152 const word name("processor"+ss.str()+"to"+ssNei.str());
157 new processorBoundaryPatch
171 bool polyMeshGenModifier::removeEmptyProcessorPatches()
173 PtrList<processorBoundaryPatch>& procBoundaries =
174 this->procBoundariesAccess();
176 label nValidPatches(0);
177 forAll(procBoundaries, patchI)
179 if( procBoundaries[patchI].patchSize() != 0 )
183 if( nValidPatches == procBoundaries.size() )
186 PtrList<processorBoundaryPatch> newProcBoundaries(nValidPatches);
189 forAll(procBoundaries, patchI)
191 if( procBoundaries[patchI].patchSize() != 0 )
193 newProcBoundaries.set
196 new processorBoundaryPatch(procBoundaries[patchI])
201 procBoundaries.transfer(newProcBoundaries);
206 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
208 } // End namespace Foam
210 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //