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"
32 // #define DEBUGSearch
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
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() )
60 //- shift processor faces
61 PtrList<processorBoundaryPatch>& procBoundaries =
62 mesh_.procBoundaries_;
65 forAll(procBoundaries, patchI)
66 nProcFaces += procBoundaries[patchI].patchSize();
68 const label procStart = nIntFaces + boundaryFaces.size();
69 const label shift = procStart - procBoundaries[0].patchStart();
73 faces.setSize(procStart+nProcFaces);
74 forAllReverse(procBoundaries, patchI)
76 const label start = procBoundaries[patchI].patchStart();
77 const label end = procBoundaries[patchI].patchSize() + start;
78 for(label faceI=end-1;faceI>=start;--faceI)
80 faces[faceI+shift].transfer(faces[faceI]);
81 newFaceLabel[faceI] = faceI+shift;
84 procBoundaries[patchI].patchStart() += shift;
89 forAll(procBoundaries, patchI)
91 const label start = procBoundaries[patchI].patchStart();
92 const label end = procBoundaries[patchI].patchSize() + start;
93 for(label faceI=start;faceI<end;++faceI)
95 faces[faceI+shift].transfer(faces[faceI]);
96 newFaceLabel[faceI] = faceI+shift;
99 procBoundaries[patchI].patchStart() += shift;
102 faces.setSize(procStart+nProcFaces);
106 //- processor faces are not moved
107 for(label fI=0;fI<nProcFaces;++fI)
108 newFaceLabel[procStart+fI] = procStart+fI;
113 faces.setSize(nIntFaces + boundaryFaces.size());
116 //- change cells according to the new face ordering
117 List<direction> nFacesInCell(cells.size(), direction(0));
120 const cell& c = cells[cellI];
124 if( newFaceLabel[c[fI]] != -1 )
125 newC[nFacesInCell[cellI]++] = newFaceLabel[c[fI]];
127 cells[cellI].transfer(newC);
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
145 forAll(boundaryFaces, faceI)
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);
159 cells[cellI].setSize(nFacesInCell[cellI]);
161 PtrList<boundaryPatch>& boundaries = mesh_.boundaries_;
162 if( boundaries.size() == patchNames.size() )
164 forAll(boundaries, patchI)
166 boundaries[patchI].patchName() = patchNames[patchI];
167 boundaries[patchI].patchStart() = newPatchStart[patchI];
168 boundaries[patchI].patchSize() = newPatchSize[patchI];
174 boundaries.setSize(patchNames.size());
175 forAll(boundaries, patchI)
183 newPatchSize[patchI],
184 newPatchStart[patchI]
193 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
195 } // End namespace Foam
197 // ************************************************************************* //