initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / meshTools / sets / topoSets / faceSet.C
blob2ce0d96899b2db0036718802e0fcff78ae1a9f69
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM 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 2 of the License, or (at your
14     option) any later version.
16     OpenFOAM 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 OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "faceSet.H"
28 #include "mapPolyMesh.H"
29 #include "polyMesh.H"
30 #include "processorPolyPatch.H"
31 #include "cyclicPolyPatch.H"
33 #include "addToRunTimeSelectionTable.H"
35 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37 namespace Foam
40 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
42 defineTypeNameAndDebug(faceSet, 0);
44 addToRunTimeSelectionTable(topoSet, faceSet, word);
45 addToRunTimeSelectionTable(topoSet, faceSet, size);
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50 faceSet::faceSet(const IOobject& obj)
52     topoSet(obj, typeName)
56 faceSet::faceSet
58     const polyMesh& mesh,
59     const word& name,
60     readOption r,
61     writeOption w
64     topoSet(mesh, typeName, name, r, w)
66     check(mesh.nFaces());
70 faceSet::faceSet
72     const polyMesh& mesh,
73     const word& name,
74     const label size,
75     writeOption w
78     topoSet(mesh, name, size, w)
82 faceSet::faceSet
84     const polyMesh& mesh,
85     const word& name,
86     const labelHashSet& set,
87     writeOption w
90     topoSet(mesh, name, set, w)
94 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
96 faceSet::~faceSet()
100 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
102 void faceSet::sync(const polyMesh& mesh)
104     const polyBoundaryMesh& patches = mesh.boundaryMesh();
106     label nAdded = 0;
108     if (Pstream::parRun())
109     {
110         // Send faces in set that are on a processorPatch. Send as patch face
111         // indices.
112         forAll(patches, patchI)
113         {
114             const polyPatch& pp = patches[patchI];
116             if (isType<processorPolyPatch>(pp))
117             {
118                 const processorPolyPatch& procPatch =
119                     refCast<const processorPolyPatch>(pp);
121                 // Convert faceSet locally to labelList.
122                 DynamicList<label> setFaces(pp.size());
124                 forAll(pp, i)
125                 {
126                     if (found(pp.start() + i))
127                     {
128                         setFaces.append(i);
129                     }
130                 }
131                 setFaces.shrink();
133                 OPstream toNeighbour
134                 (
135                     Pstream::blocking,
136                     procPatch.neighbProcNo()
137                 );
139                 toNeighbour << setFaces;
140             }
141         }
143         // Receive 
144         forAll(patches, patchI)
145         {
146             const polyPatch& pp = patches[patchI];
148             if (isType<processorPolyPatch>(pp))
149             {
150                 const processorPolyPatch& procPatch =
151                     refCast<const processorPolyPatch>(pp);
153                 IPstream fromNeighbour
154                 (
155                     Pstream::blocking,
156                     procPatch.neighbProcNo()
157                 );
159                 labelList setFaces(fromNeighbour);
161                 forAll(setFaces, i)
162                 {
163                     if (insert(pp.start() + setFaces[i]))
164                     {
165                         nAdded++;
166                     }
167                 }
168             }
169         }
170     }
172     // Couple cyclic patches
173     forAll (patches, patchI)
174     {
175         const polyPatch& pp = patches[patchI];
177         if (typeid(pp) == typeid(cyclicPolyPatch))
178         {
179             const cyclicPolyPatch& cycPatch =
180                 refCast<const cyclicPolyPatch>(pp);
182             forAll (cycPatch, i)
183             {
184                 label thisFaceI = cycPatch.start() + i;
185                 label otherFaceI = cycPatch.transformGlobalFace(thisFaceI);
187                 if (found(thisFaceI))
188                 {
189                     if (insert(otherFaceI))
190                     {
191                         nAdded++;
192                     }
193                 }
194                 else if (found(otherFaceI))
195                 {
196                     if (insert(thisFaceI))
197                     {
198                         nAdded++;
199                     }
200                 }
201             }
202         }
203     }
206     reduce(nAdded, sumOp<label>());
208     //if (nAdded > 0)
209     //{
210     //    Info<< "Added an additional " << nAdded
211     //        << " faces on coupled patches. "
212     //        << "(processorPolyPatch, cyclicPolyPatch)" << endl;
213     //}
217 label faceSet::maxSize(const polyMesh& mesh) const
219     return mesh.nFaces();
223 void faceSet::updateMesh(const mapPolyMesh& morphMap)
225     updateLabels(morphMap.reverseFaceMap());
229 void faceSet::writeDebug
231     Ostream& os,
232     const primitiveMesh& mesh,
233     const label maxLen
234 ) const
236     topoSet::writeDebug(os, mesh.faceCentres(), maxLen);
240 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
242 } // End namespace Foam
244 // ************************************************************************* //