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 / smoothers / geometry / meshOptimizer / meshOptimizerI.H
blobd3da6352eeab5284e97057289f86a192180e3b70
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
27 \*---------------------------------------------------------------------------*/
29 #include "meshOptimizer.H"
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 namespace Foam
36 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 template<class labelListType>
39 inline void meshOptimizer::lockCells(const labelListType& l)
41     boolList lockedFace(mesh_.faces().size(), false);
42     const cellListPMG& cells = mesh_.cells();
43     forAll(l, lcI)
44     {
45         const cell& c = cells[l[lcI]];
47         forAll(c, fI)
48             lockedFace[c[fI]] = true;
49     }
51     if( Pstream::parRun() )
52     {
53         const PtrList<processorBoundaryPatch>& procBoundaries =
54             mesh_.procBoundaries();
56         forAll(procBoundaries, patchI)
57         {
58             labelLongList dataToSend;
60             const label start = procBoundaries[patchI].patchStart();
61             const label end = start+procBoundaries[patchI].patchSize();
63             for(label faceI=start;faceI<end;++faceI)
64                 if( lockedFace[faceI] )
65                     dataToSend.append(faceI-start);
67             OPstream toOtherProc
68             (
69                 Pstream::blocking,
70                 procBoundaries[patchI].neiProcNo(),
71                 dataToSend.byteSize()
72             );
74             toOtherProc << dataToSend;
75         }
77         forAll(procBoundaries, patchI)
78         {
79             const label start = procBoundaries[patchI].patchStart();
81             IPstream fromOtherProc
82             (
83                 Pstream::blocking,
84                 procBoundaries[patchI].neiProcNo()
85             );
87             labelList receivedData;
88             fromOtherProc >> receivedData;
90             forAll(receivedData, i)
91                 lockedFace[start+receivedData[i]];
92         }
93     }
95     //- Finally, mark locked points and faces
96     const faceListPMG& faces = mesh_.faces();
97     forAll(lockedFace, faceI)
98     {
99         if( lockedFace[faceI] )
100         {
101             lockedFaces_.append(faceI);
103             const face& f = faces[faceI];
105             forAll(f, pI)
106                 vertexLocation_[f[pI]] |= LOCKED;
107         }
108     }
110     # ifdef DEBUGSmoothing
111     const label lockedFacesI = mesh_.addFaceSubset("lockedFaces");
112     forAll(lockedFaces_, lfI)
113         mesh_.addFaceToSubset(lockedFacesI, lockedFaces_[lfI]);
115     const label lockPointsI = mesh_.addPointSubset("lockedPoints");
116     forAll(vertexLocation_, pointI)
117         if( vertexLocation_[pointI] & LOCKED )
118             mesh_.addPointToSubset(lockPointsI, pointI);
119     # endif
122 template<class labelListType>
123 inline void meshOptimizer::lockFaces(const labelListType& lf)
125     boolList lockedFace(mesh_.faces().size(), false);
126     forAll(lf, lfI)
127     {
128         lockedFace[lf[lfI]] = true;
129     }
131     if( Pstream::parRun() )
132     {
133         const PtrList<processorBoundaryPatch>& procBoundaries =
134             mesh_.procBoundaries();
136         forAll(procBoundaries, patchI)
137         {
138             labelLongList dataToSend;
140             const label start = procBoundaries[patchI].patchStart();
141             const label end = start+procBoundaries[patchI].patchSize();
143             for(label faceI=start;faceI<end;++faceI)
144                 if( lockedFace[faceI] )
145                     dataToSend.append(faceI-start);
147             OPstream toOtherProc
148             (
149                 Pstream::blocking,
150                 procBoundaries[patchI].neiProcNo(),
151                 dataToSend.byteSize()
152             );
154             toOtherProc << dataToSend;
155         }
157         forAll(procBoundaries, patchI)
158         {
159             const label start = procBoundaries[patchI].patchStart();
161             IPstream fromOtherProc
162             (
163                 Pstream::blocking,
164                 procBoundaries[patchI].neiProcNo()
165             );
167             labelList receivedData;
168             fromOtherProc >> receivedData;
170             forAll(receivedData, i)
171                 lockedFace[start+receivedData[i]];
172         }
173     }
175     //- Finally, mark locked points and faces
176     const faceListPMG& faces = mesh_.faces();
177     forAll(lockedFace, faceI)
178     {
179         if( lockedFace[faceI] )
180         {
181             lockedFaces_.append(faceI);
183             const face& f = faces[faceI];
185             forAll(f, pI)
186                 vertexLocation_[f[pI]] |= LOCKED;
187         }
188     }
190     # ifdef DEBUGSmoothing
191     const label lockedFacesI = mesh_.addFaceSubset("lockedFaces");
192     forAll(lockedFaces_, lfI)
193         mesh_.addFaceToSubset(lockedFacesI, lockedFaces_[lfI]);
195     const label lockPointsI = mesh_.addPointSubset("lockedPoints");
196     forAll(vertexLocation_, pointI)
197         if( vertexLocation_[pointI] & LOCKED )
198             mesh_.addPointToSubset(lockPointsI, pointI);
199     # endif
202 template<class labelListType>
203 inline void meshOptimizer::lockPoints(const labelListType& lp)
205     forAll(lp, lpI)
206         vertexLocation_[lp[lpI]] |= LOCKED;
208     if( Pstream::parRun() )
209     {
210         const PtrList<processorBoundaryPatch>& procBoundaries =
211             mesh_.procBoundaries();
212         const faceListPMG& faces = mesh_.faces();
214         forAll(procBoundaries, patchI)
215         {
216             labelLongList dataToSend;
218             const label start = procBoundaries[patchI].patchStart();
219             const label end = start+procBoundaries[patchI].patchSize();
221             for(label faceI=start;faceI<end;++faceI)
222             {
223                 const face& f = faces[faceI];
225                 forAll(f, pI)
226                 {
227                     if( vertexLocation_[pI] & LOCKED )
228                     {
229                         // send the face lable and the location in the face
230                         dataToSend.append(faceI-start);
231                         dataToSend.append((f.size()-pI)%f.size());
232                     }
233                 }
234             }
236             OPstream toOtherProc
237             (
238                 Pstream::blocking,
239                 procBoundaries[patchI].neiProcNo(),
240                 dataToSend.byteSize()
241             );
243             toOtherProc << dataToSend;
244         }
246         forAll(procBoundaries, patchI)
247         {
248             const label start = procBoundaries[patchI].patchStart();
250             IPstream fromOtherProc
251             (
252                 Pstream::blocking,
253                 procBoundaries[patchI].neiProcNo()
254             );
256             labelList receivedData;
257             fromOtherProc >> receivedData;
259             label counter(0);
260             while( counter < receivedData.size() )
261             {
262                 const face& f = faces[start+receivedData[counter++]];
263                 vertexLocation_[f[receivedData[counter++]]] |= LOCKED;
264             }
265         }
266     }
268     # ifdef DEBUGSmoothing
269     const label lockPointsI = mesh_.addPointSubset("lockedPoints");
270     forAll(vertexLocation_, pointI)
271         if( vertexLocation_[pointI] & LOCKED )
272             mesh_.addPointToSubset(lockPointsI, pointI);
273     # endif
276 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
278 } // End namespace Foam
280 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //