FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

faceSet.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2010 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software: you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
00023 
00024 \*---------------------------------------------------------------------------*/
00025 
00026 #include "faceSet.H"
00027 #include <OpenFOAM/mapPolyMesh.H>
00028 #include <OpenFOAM/polyMesh.H>
00029 #include <OpenFOAM/processorPolyPatch.H>
00030 #include <OpenFOAM/cyclicPolyPatch.H>
00031 
00032 #include <OpenFOAM/addToRunTimeSelectionTable.H>
00033 
00034 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00035 
00036 namespace Foam
00037 {
00038 
00039 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00040 
00041 defineTypeNameAndDebug(faceSet, 0);
00042 
00043 addToRunTimeSelectionTable(topoSet, faceSet, word);
00044 addToRunTimeSelectionTable(topoSet, faceSet, size);
00045 addToRunTimeSelectionTable(topoSet, faceSet, set);
00046 
00047 
00048 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00049 
00050 faceSet::faceSet(const IOobject& obj)
00051 :
00052     topoSet(obj, typeName)
00053 {}
00054 
00055 
00056 faceSet::faceSet
00057 (
00058     const polyMesh& mesh,
00059     const word& name,
00060     readOption r,
00061     writeOption w
00062 )
00063 :
00064     topoSet(mesh, typeName, name, r, w)
00065 {
00066     check(mesh.nFaces());
00067 }
00068 
00069 
00070 faceSet::faceSet
00071 (
00072     const polyMesh& mesh,
00073     const word& name,
00074     const label size,
00075     writeOption w
00076 )
00077 :
00078     topoSet(mesh, name, size, w)
00079 {}
00080 
00081 
00082 faceSet::faceSet
00083 (
00084     const polyMesh& mesh,
00085     const word& name,
00086     const topoSet& set,
00087     writeOption w
00088 )
00089 :
00090     topoSet(mesh, name, set, w)
00091 {}
00092 
00093 
00094 faceSet::faceSet
00095 (
00096     const polyMesh& mesh,
00097     const word& name,
00098     const labelHashSet& set,
00099     writeOption w
00100 )
00101 :
00102     topoSet(mesh, name, set, w)
00103 {}
00104 
00105 
00106 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00107 
00108 faceSet::~faceSet()
00109 {}
00110 
00111 
00112 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00113 
00114 void faceSet::sync(const polyMesh& mesh)
00115 {
00116     const polyBoundaryMesh& patches = mesh.boundaryMesh();
00117 
00118     label nAdded = 0;
00119 
00120     if (Pstream::parRun())
00121     {
00122         // Send faces in set that are on a processorPatch. Send as patch face
00123         // indices.
00124         forAll(patches, patchI)
00125         {
00126             const polyPatch& pp = patches[patchI];
00127 
00128             if (isA<processorPolyPatch>(pp))
00129             {
00130                 const processorPolyPatch& procPatch =
00131                     refCast<const processorPolyPatch>(pp);
00132 
00133                 // Convert faceSet locally to labelList.
00134                 DynamicList<label> setFaces(pp.size());
00135 
00136                 forAll(pp, i)
00137                 {
00138                     if (found(pp.start() + i))
00139                     {
00140                         setFaces.append(i);
00141                     }
00142                 }
00143                 setFaces.shrink();
00144 
00145                 OPstream toNeighbour
00146                 (
00147                     Pstream::blocking,
00148                     procPatch.neighbProcNo()
00149                 );
00150 
00151                 toNeighbour << setFaces;
00152             }
00153         }
00154 
00155         // Receive
00156         forAll(patches, patchI)
00157         {
00158             const polyPatch& pp = patches[patchI];
00159 
00160             if (isA<processorPolyPatch>(pp))
00161             {
00162                 const processorPolyPatch& procPatch =
00163                     refCast<const processorPolyPatch>(pp);
00164 
00165                 IPstream fromNeighbour
00166                 (
00167                     Pstream::blocking,
00168                     procPatch.neighbProcNo()
00169                 );
00170 
00171                 labelList setFaces(fromNeighbour);
00172 
00173                 forAll(setFaces, i)
00174                 {
00175                     if (insert(pp.start() + setFaces[i]))
00176                     {
00177                         nAdded++;
00178                     }
00179                 }
00180             }
00181         }
00182     }
00183 
00184     // Couple cyclic patches
00185     forAll (patches, patchI)
00186     {
00187         const polyPatch& pp = patches[patchI];
00188 
00189         if (isA<cyclicPolyPatch>(pp))
00190         {
00191             const cyclicPolyPatch& cycPatch =
00192                 refCast<const cyclicPolyPatch>(pp);
00193 
00194             forAll (cycPatch, i)
00195             {
00196                 label thisFaceI = cycPatch.start() + i;
00197                 label otherFaceI = cycPatch.transformGlobalFace(thisFaceI);
00198 
00199                 if (found(thisFaceI))
00200                 {
00201                     if (insert(otherFaceI))
00202                     {
00203                         nAdded++;
00204                     }
00205                 }
00206                 else if (found(otherFaceI))
00207                 {
00208                     if (insert(thisFaceI))
00209                     {
00210                         nAdded++;
00211                     }
00212                 }
00213             }
00214         }
00215     }
00216 
00217 
00218     reduce(nAdded, sumOp<label>());
00219 
00220     //if (nAdded > 0)
00221     //{
00222     //    Info<< "Added an additional " << nAdded
00223     //        << " faces on coupled patches. "
00224     //        << "(processorPolyPatch, cyclicPolyPatch)" << endl;
00225     //}
00226 }
00227 
00228 
00229 label faceSet::maxSize(const polyMesh& mesh) const
00230 {
00231     return mesh.nFaces();
00232 }
00233 
00234 
00235 void faceSet::updateMesh(const mapPolyMesh& morphMap)
00236 {
00237     updateLabels(morphMap.reverseFaceMap());
00238 }
00239 
00240 
00241 void faceSet::writeDebug
00242 (
00243     Ostream& os,
00244     const primitiveMesh& mesh,
00245     const label maxLen
00246 ) const
00247 {
00248     topoSet::writeDebug(os, mesh.faceCentres(), maxLen);
00249 }
00250 
00251 
00252 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00253 
00254 } // End namespace Foam
00255 
00256 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines