fixed writing out entries in advective bc
[OpenFOAM-1.6-ext.git] / src / meshTools / sets / topoSets / faceSet.C
blob0512f96530cd1f4738dc223f6021d9c750736e21
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright held by original author
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);
46 addToRunTimeSelectionTable(topoSet, faceSet, set);
49 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
51 faceSet::faceSet(const IOobject& obj)
53     topoSet(obj, typeName)
57 faceSet::faceSet
59     const polyMesh& mesh,
60     const word& name,
61     readOption r,
62     writeOption w
65     topoSet(mesh, typeName, name, r, w)
67     check(mesh.nFaces());
71 faceSet::faceSet
73     const polyMesh& mesh,
74     const word& name,
75     const label size,
76     writeOption w
79     topoSet(mesh, name, size, w)
83 faceSet::faceSet
85     const polyMesh& mesh,
86     const word& name,
87     const topoSet& set,
88     writeOption w
91     topoSet(mesh, name, set, w)
95 faceSet::faceSet
97     const polyMesh& mesh,
98     const word& name,
99     const labelHashSet& set,
100     writeOption w
103     topoSet(mesh, name, set, w)
107 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
109 faceSet::~faceSet()
113 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
115 void faceSet::sync(const polyMesh& mesh)
117     const polyBoundaryMesh& patches = mesh.boundaryMesh();
119     label nAdded = 0;
121     if (Pstream::parRun())
122     {
123         // Send faces in set that are on a processorPatch. Send as patch face
124         // indices.
125         forAll(patches, patchI)
126         {
127             const polyPatch& pp = patches[patchI];
129             if (isA<processorPolyPatch>(pp))
130             {
131                 const processorPolyPatch& procPatch =
132                     refCast<const processorPolyPatch>(pp);
134                 // Convert faceSet locally to labelList.
135                 DynamicList<label> setFaces(pp.size());
137                 forAll(pp, i)
138                 {
139                     if (found(pp.start() + i))
140                     {
141                         setFaces.append(i);
142                     }
143                 }
144                 setFaces.shrink();
146                 OPstream toNeighbour
147                 (
148                     Pstream::blocking,
149                     procPatch.neighbProcNo()
150                 );
152                 toNeighbour << setFaces;
153             }
154         }
156         // Receive
157         forAll(patches, patchI)
158         {
159             const polyPatch& pp = patches[patchI];
161             if (isA<processorPolyPatch>(pp))
162             {
163                 const processorPolyPatch& procPatch =
164                     refCast<const processorPolyPatch>(pp);
166                 IPstream fromNeighbour
167                 (
168                     Pstream::blocking,
169                     procPatch.neighbProcNo()
170                 );
172                 labelList setFaces(fromNeighbour);
174                 forAll(setFaces, i)
175                 {
176                     if (insert(pp.start() + setFaces[i]))
177                     {
178                         nAdded++;
179                     }
180                 }
181             }
182         }
183     }
185     // Couple cyclic patches
186     forAll (patches, patchI)
187     {
188         const polyPatch& pp = patches[patchI];
190         if (isA<cyclicPolyPatch>(pp))
191         {
192             const cyclicPolyPatch& cycPatch =
193                 refCast<const cyclicPolyPatch>(pp);
195             forAll (cycPatch, i)
196             {
197                 label thisFaceI = cycPatch.start() + i;
198                 label otherFaceI = cycPatch.transformGlobalFace(thisFaceI);
200                 if (found(thisFaceI))
201                 {
202                     if (insert(otherFaceI))
203                     {
204                         nAdded++;
205                     }
206                 }
207                 else if (found(otherFaceI))
208                 {
209                     if (insert(thisFaceI))
210                     {
211                         nAdded++;
212                     }
213                 }
214             }
215         }
216     }
219     reduce(nAdded, sumOp<label>());
221     //if (nAdded > 0)
222     //{
223     //    Info<< "Added an additional " << nAdded
224     //        << " faces on coupled patches. "
225     //        << "(processorPolyPatch, cyclicPolyPatch)" << endl;
226     //}
230 label faceSet::maxSize(const polyMesh& mesh) const
232     return mesh.nFaces();
236 void faceSet::updateMesh(const mapPolyMesh& morphMap)
238     updateLabels(morphMap.reverseFaceMap());
242 void faceSet::writeDebug
244     Ostream& os,
245     const primitiveMesh& mesh,
246     const label maxLen
247 ) const
249     topoSet::writeDebug(os, mesh.faceCentres(), maxLen);
253 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
255 } // End namespace Foam
257 // ************************************************************************* //