Merge branch 'master' of ssh://git.code.sf.net/p/foam-extend/foam-extend-3.2
[foam-extend-3.2.git] / src / mesh / cfMesh / utilities / meshes / polyMeshGenModifier / polyMeshGenModifierReplaceBoundary.C
blob76ec5d9ea54ab4a5c12b3b82e6580848cafb82c4
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | cfMesh: A library for mesh generation
4    \\    /   O peration     |
5     \\  /    A nd           | Author: Franjo Juretic (franjo.juretic@c-fields.com)
6      \\/     M anipulation  | Copyright (C) Creative Fields, Ltd.
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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/>.
24 Description
26 \*---------------------------------------------------------------------------*/
28 #include "polyMeshGenModifier.H"
29 #include "demandDrivenData.H"
30 #include "DynList.H"
32 // #define DEBUGSearch
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
36 namespace Foam
39 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 void polyMeshGenModifier::replaceBoundary
43     const wordList& patchNames,
44     const VRWGraph& boundaryFaces,
45     const labelLongList& faceOwners,
46     const labelLongList& facePatches
49     const label nIntFaces = mesh_.nInternalFaces();
51     faceListPMG& faces = this->facesAccess();
52     cellListPMG& cells = this->cellsAccess();
54     labelLongList newFaceLabel(faces.size(), -1);
55     for(label faceI=0;faceI<nIntFaces;++faceI)
56         newFaceLabel[faceI] = faceI;
58     if( Pstream::parRun() )
59     {
60         //- shift processor faces
61         PtrList<processorBoundaryPatch>& procBoundaries =
62             mesh_.procBoundaries_;
64         label nProcFaces(0);
65         forAll(procBoundaries, patchI)
66             nProcFaces += procBoundaries[patchI].patchSize();
68         const label procStart = nIntFaces + boundaryFaces.size();
69         const label shift = procStart - procBoundaries[0].patchStart();
71         if( shift > 0 )
72         {
73             faces.setSize(procStart+nProcFaces);
74             forAllReverse(procBoundaries, patchI)
75             {
76                 const label start = procBoundaries[patchI].patchStart();
77                 const label end = procBoundaries[patchI].patchSize() + start;
78                 for(label faceI=end-1;faceI>=start;--faceI)
79                 {
80                     faces[faceI+shift].transfer(faces[faceI]);
81                     newFaceLabel[faceI] = faceI+shift;
82                 }
84                 procBoundaries[patchI].patchStart() += shift;
85             }
86         }
87         else if( shift < 0 )
88         {
89             forAll(procBoundaries, patchI)
90             {
91                 const label start = procBoundaries[patchI].patchStart();
92                 const label end = procBoundaries[patchI].patchSize() + start;
93                 for(label faceI=start;faceI<end;++faceI)
94                 {
95                     faces[faceI+shift].transfer(faces[faceI]);
96                     newFaceLabel[faceI] = faceI+shift;
97                 }
99                 procBoundaries[patchI].patchStart() += shift;
100             }
102             faces.setSize(procStart+nProcFaces);
103         }
104         else
105         {
106             //- processor faces are not moved
107             for(label fI=0;fI<nProcFaces;++fI)
108                 newFaceLabel[procStart+fI] = procStart+fI;
109         }
110     }
111     else
112     {
113         faces.setSize(nIntFaces + boundaryFaces.size());
114     }
116     //- change cells according to the new face ordering
117     List<direction> nFacesInCell(cells.size(), direction(0));
118     forAll(cells, cellI)
119     {
120         const cell& c = cells[cellI];
122         cell newC(c.size());
123         forAll(c, fI)
124         if( newFaceLabel[c[fI]] != -1 )
125             newC[nFacesInCell[cellI]++] = newFaceLabel[c[fI]];
127         cells[cellI].transfer(newC);
128     }
130     mesh_.updateFaceSubsets(newFaceLabel);
131     newFaceLabel.setSize(0);
133     //- store boundary faces
134     labelList newPatchStart(patchNames.size());
135     labelList newPatchSize(patchNames.size(), 0);
136     forAll(facePatches, bfI)
137         ++newPatchSize[facePatches[bfI]];
139     newPatchStart[0] = nIntFaces;
140     for(label i=1;i<newPatchSize.size();++i)
141         newPatchStart[i] = newPatchStart[i-1] + newPatchSize[i-1];
143     //- store boundary faces
144     newPatchSize = 0;
145     forAll(boundaryFaces, faceI)
146     {
147         const label fPatch = facePatches[faceI];
148         const label fOwn = faceOwners[faceI];
150         const label fLabel = newPatchStart[fPatch] + newPatchSize[fPatch]++;
152         cells[fOwn].newElmt(nFacesInCell[fOwn]++) = fLabel;
153         faces[fLabel].setSize(boundaryFaces.sizeOfRow(faceI));
154         forAllRow(boundaryFaces, faceI, pI)
155             faces[fLabel][pI] = boundaryFaces(faceI, pI);
156     }
158     forAll(cells, cellI)
159         cells[cellI].setSize(nFacesInCell[cellI]);
161     PtrList<boundaryPatch>& boundaries = mesh_.boundaries_;
162     if( boundaries.size() == patchNames.size() )
163     {
164         forAll(boundaries, patchI)
165         {
166             boundaries[patchI].patchName() = patchNames[patchI];
167             boundaries[patchI].patchStart() = newPatchStart[patchI];
168             boundaries[patchI].patchSize() = newPatchSize[patchI];
169         }
170     }
171     else
172     {
173         boundaries.clear();
174         boundaries.setSize(patchNames.size());
175         forAll(boundaries, patchI)
176             boundaries.set
177             (
178                 patchI,
179                 new boundaryPatch
180                 (
181                     patchNames[patchI],
182                     "patch",
183                     newPatchSize[patchI],
184                     newPatchStart[patchI]
185                 )
186             );
187     }
189     mesh_.clearOut();
190     this->clearOut();
193 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
195 } // End namespace Foam
197 // ************************************************************************* //