OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

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-2009 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 the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     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, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include "faceSet.H"
00028 #include "mapPolyMesh.H"
00029 #include "polyMesh.H"
00030 #include "processorPolyPatch.H"
00031 #include "cyclicPolyPatch.H"
00032 
00033 #include "addToRunTimeSelectionTable.H"
00034 
00035 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00036 
00037 namespace Foam
00038 {
00039 
00040 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00041 
00042 defineTypeNameAndDebug(faceSet, 0);
00043 
00044 addToRunTimeSelectionTable(topoSet, faceSet, word);
00045 addToRunTimeSelectionTable(topoSet, faceSet, size);
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 labelHashSet& set,
00087     writeOption w
00088 )
00089 :
00090     topoSet(mesh, name, set, w)
00091 {}
00092 
00093 
00094 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00095 
00096 faceSet::~faceSet()
00097 {}
00098 
00099 
00100 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00101 
00102 void faceSet::sync(const polyMesh& mesh)
00103 {
00104     const polyBoundaryMesh& patches = mesh.boundaryMesh();
00105 
00106     label nAdded = 0;
00107 
00108     if (Pstream::parRun())
00109     {
00110         // Send faces in set that are on a processorPatch. Send as patch face
00111         // indices.
00112         forAll(patches, patchI)
00113         {
00114             const polyPatch& pp = patches[patchI];
00115 
00116             if (isType<processorPolyPatch>(pp))
00117             {
00118                 const processorPolyPatch& procPatch =
00119                     refCast<const processorPolyPatch>(pp);
00120 
00121                 // Convert faceSet locally to labelList.
00122                 DynamicList<label> setFaces(pp.size());
00123 
00124                 forAll(pp, i)
00125                 {
00126                     if (found(pp.start() + i))
00127                     {
00128                         setFaces.append(i);
00129                     }
00130                 }
00131                 setFaces.shrink();
00132 
00133                 OPstream toNeighbour
00134                 (
00135                     Pstream::blocking,
00136                     procPatch.neighbProcNo()
00137                 );
00138 
00139                 toNeighbour << setFaces;
00140             }
00141         }
00142 
00143         // Receive 
00144         forAll(patches, patchI)
00145         {
00146             const polyPatch& pp = patches[patchI];
00147 
00148             if (isType<processorPolyPatch>(pp))
00149             {
00150                 const processorPolyPatch& procPatch =
00151                     refCast<const processorPolyPatch>(pp);
00152 
00153                 IPstream fromNeighbour
00154                 (
00155                     Pstream::blocking,
00156                     procPatch.neighbProcNo()
00157                 );
00158 
00159                 labelList setFaces(fromNeighbour);
00160 
00161                 forAll(setFaces, i)
00162                 {
00163                     if (insert(pp.start() + setFaces[i]))
00164                     {
00165                         nAdded++;
00166                     }
00167                 }
00168             }
00169         }
00170     }
00171 
00172     // Couple cyclic patches
00173     forAll (patches, patchI)
00174     {
00175         const polyPatch& pp = patches[patchI];
00176 
00177         if (typeid(pp) == typeid(cyclicPolyPatch))
00178         {
00179             const cyclicPolyPatch& cycPatch =
00180                 refCast<const cyclicPolyPatch>(pp);
00181 
00182             forAll (cycPatch, i)
00183             {
00184                 label thisFaceI = cycPatch.start() + i;
00185                 label otherFaceI = cycPatch.transformGlobalFace(thisFaceI);
00186 
00187                 if (found(thisFaceI))
00188                 {
00189                     if (insert(otherFaceI))
00190                     {
00191                         nAdded++;
00192                     }
00193                 }
00194                 else if (found(otherFaceI))
00195                 {
00196                     if (insert(thisFaceI))
00197                     {
00198                         nAdded++;
00199                     }
00200                 }
00201             }
00202         }
00203     }
00204 
00205 
00206     reduce(nAdded, sumOp<label>());
00207 
00208     //if (nAdded > 0)
00209     //{
00210     //    Info<< "Added an additional " << nAdded
00211     //        << " faces on coupled patches. "
00212     //        << "(processorPolyPatch, cyclicPolyPatch)" << endl;
00213     //}
00214 }
00215 
00216 
00217 label faceSet::maxSize(const polyMesh& mesh) const
00218 {
00219     return mesh.nFaces();
00220 }
00221 
00222 
00223 void faceSet::updateMesh(const mapPolyMesh& morphMap)
00224 {
00225     updateLabels(morphMap.reverseFaceMap());
00226 }
00227 
00228 
00229 void faceSet::writeDebug
00230 (
00231     Ostream& os,
00232     const primitiveMesh& mesh,
00233     const label maxLen
00234 ) const
00235 {
00236     topoSet::writeDebug(os, mesh.faceCentres(), maxLen);
00237 }
00238 
00239 
00240 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00241 
00242 } // End namespace Foam
00243 
00244 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd