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

processorPointPatch.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 "processorPointPatch.H"
00028 #include "pointBoundaryMesh.H"
00029 #include "addToRunTimeSelectionTable.H"
00030 #include "pointMesh.H"
00031 #include "globalPointPatch.H"
00032 #include "faceList.H"
00033 #include "primitiveFacePatch.H"
00034 #include "emptyPolyPatch.H"
00035 
00036 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00037 
00038 namespace Foam
00039 {
00040 
00041 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00042 
00043 defineTypeNameAndDebug(processorPointPatch, 0);
00044 
00045 addToRunTimeSelectionTable
00046 (
00047     facePointPatch,
00048     processorPointPatch,
00049     polyPatch
00050 );
00051 
00052 
00053 // * * * * * * * * * * * * * Protected Member Functions  * * * * * * * * * * //
00054 
00055 void Foam::processorPointPatch::initGeometry()
00056 {
00057     // Algorithm:
00058     // Depending on whether the patch is a master or a slave, get the primitive
00059     // patch points and filter away the points from the global patch.
00060 
00061     if (isMaster())
00062     {
00063         meshPoints_ = procPolyPatch_.meshPoints();
00064     }
00065     else
00066     {
00067         // Slave side. Create the reversed patch and pick up its points
00068         // so that the order is correct
00069         const polyPatch& pp = patch();
00070 
00071         faceList masterFaces(pp.size());
00072 
00073         forAll (pp, faceI)
00074         {
00075             masterFaces[faceI] = pp[faceI].reverseFace();
00076         }
00077 
00078         meshPoints_ = primitiveFacePatch
00079         (
00080             masterFaces,
00081             pp.points()
00082         ).meshPoints();
00083     }
00084 
00085     if (Pstream::parRun())
00086     {
00087         initPatchPatchPoints();
00088     }
00089 }
00090 
00091 
00092 void Foam::processorPointPatch::calcGeometry()
00093 {
00094     if (Pstream::parRun())
00095     {
00096         calcPatchPatchPoints();
00097     }
00098 
00099     // If it is not runing parallel or there are no global points
00100     // create a 1->1 map
00101     if
00102     (
00103         !Pstream::parRun()
00104      || !boundaryMesh().mesh().globalData().nGlobalPoints()
00105     )
00106     {
00107         nonGlobalPatchPoints_.setSize(meshPoints_.size());
00108         forAll(nonGlobalPatchPoints_, i)
00109         {
00110             nonGlobalPatchPoints_[i] = i;
00111         }
00112     }
00113     else
00114     {
00115         // Get reference to shared points
00116         const labelList& sharedPoints =
00117             boundaryMesh().globalPatch().meshPoints();
00118 
00119         nonGlobalPatchPoints_.setSize(meshPoints_.size());
00120 
00121         label noFiltPoints = 0;
00122 
00123         forAll (meshPoints_, pointI)
00124         {
00125             label curP = meshPoints_[pointI];
00126 
00127             bool found = false;
00128 
00129             forAll (sharedPoints, sharedI)
00130             {
00131                 if (sharedPoints[sharedI] == curP)
00132                 {
00133                     found = true;
00134                     break;
00135                 }
00136             }
00137 
00138             if (!found)
00139             {
00140                 nonGlobalPatchPoints_[noFiltPoints] = pointI;
00141                 meshPoints_[noFiltPoints] = curP;
00142                 noFiltPoints++;
00143             }
00144         }
00145 
00146         nonGlobalPatchPoints_.setSize(noFiltPoints);
00147         meshPoints_.setSize(noFiltPoints);
00148     }
00149 }
00150 
00151 
00152 void processorPointPatch::initPatchPatchPoints()
00153 {
00154     if (debug)
00155     {
00156         Info<< "processorPointPatch::calcPatchPatchPoints() : "
00157             << "constructing patch-patch points"
00158             << endl;
00159     }
00160 
00161     const polyBoundaryMesh& bm = boundaryMesh().mesh()().boundaryMesh();
00162 
00163     // Get the mesh points for this patch corresponding to the faces
00164     const labelList& ppmp = meshPoints();
00165 
00166     // Create a HashSet of the point labels for this patch
00167     Map<label> patchPointSet(2*ppmp.size());
00168 
00169     forAll (ppmp, ppi)
00170     {
00171         patchPointSet.insert(ppmp[ppi], ppi);
00172     }
00173 
00174 
00175     // Create the lists of patch-patch points
00176     labelListList patchPatchPoints(bm.size());
00177 
00178     // Create the lists of patch-patch point normals
00179     List<List<vector> > patchPatchPointNormals(bm.size());
00180 
00181     // Loop over all patches looking for other patches that share points
00182     forAll(bm, patchi)
00183     {
00184         if
00185         (
00186             patchi != index()                 // Ignore self-self
00187          && !isA<emptyPolyPatch>(bm[patchi])  // Ignore empty
00188          && !bm[patchi].coupled()             // Ignore other couples
00189         )
00190         {
00191             // Get the meshPoints for the other patch
00192             const labelList& meshPoints = bm[patchi].meshPoints();
00193 
00194             // Get the normals for the other patch
00195             const vectorField& normals = bm[patchi].pointNormals();
00196 
00197             label pppi = 0;
00198             forAll(meshPoints, pointi)
00199             {
00200                 label ppp = meshPoints[pointi];
00201 
00202                 // Check to see if the point of the other patch is shared with
00203                 // this patch
00204                 Map<label>::iterator iter = patchPointSet.find(ppp);
00205 
00206                 if (iter != patchPointSet.end())
00207                 {
00208                     // If it is shared initialise the patchPatchPoints for this
00209                     // patch
00210                     if (!patchPatchPoints[patchi].size())
00211                     {
00212                         patchPatchPoints[patchi].setSize(ppmp.size());
00213                         patchPatchPointNormals[patchi].setSize(ppmp.size());
00214                     }
00215 
00216                     // and add the entry
00217                     patchPatchPoints[patchi][pppi] = iter();
00218                     patchPatchPointNormals[patchi][pppi] = normals[pointi];
00219                     pppi++;
00220                 }
00221             }
00222 
00223             // Resise the list of shared points and normals for the patch
00224             // being considerd
00225             patchPatchPoints[patchi].setSize(pppi);
00226             patchPatchPointNormals[patchi].setSize(pppi);
00227         }
00228     }
00229 
00230     // Send the patchPatchPoints to the neighbouring processor
00231 
00232     OPstream toNeighbProc
00233     (
00234         Pstream::blocking,
00235         neighbProcNo()
00236     );
00237 
00238     toNeighbProc
00239         << ppmp.size()              // number of points for checking
00240         << patchPatchPoints
00241         << patchPatchPointNormals;
00242 
00243     if (debug)
00244     {
00245         Info<< "processorPointPatch::calcPatchPatchPoints() : "
00246             << "constructed patch-patch points"
00247             << endl;
00248     }
00249 }
00250 
00251 
00252 void Foam::processorPointPatch::calcPatchPatchPoints()
00253 {
00254     // Get the patchPatchPoints from the neighbouring processor
00255     IPstream fromNeighbProc
00256     (
00257         Pstream::blocking,
00258         neighbProcNo()
00259     );
00260 
00261     label nbrNPoints(readLabel(fromNeighbProc));
00262     labelListList patchPatchPoints(fromNeighbProc);
00263     List<List<vector> > patchPatchPointNormals(fromNeighbProc);
00264 
00265     pointBoundaryMesh& pbm = const_cast<pointBoundaryMesh&>(boundaryMesh());
00266     const labelList& ppmp = meshPoints();
00267 
00268     // Simple check for the very rare situation when not the same number
00269     // of points on both sides. This can happen with decomposed cyclics.
00270     // If on one side the cyclic shares a point with proc faces coming from
00271     // internal faces it will have a different number of points from
00272     // the situation where the cyclic and the 'normal' proc faces are fully
00273     // separate.
00274     if (nbrNPoints != ppmp.size())
00275     {
00276         WarningIn("processorPointPatch::calcPatchPatchPoints()")
00277             << "Processor patch " << name()
00278             << " has " << ppmp.size() << " points; coupled patch has "
00279             << nbrNPoints << " points." << endl
00280             << "   (usually due to decomposed cyclics)."
00281             << " This might give problems" << endl
00282             << "    when using point fields (interpolation, mesh motion)."
00283             << endl;
00284     }
00285 
00286 
00287 
00288     // Loop over the patches looking for other patches that share points
00289     forAll(patchPatchPoints, patchi)
00290     {
00291         const labelList& patchPoints = patchPatchPoints[patchi];
00292         const List<vector>& patchPointNormals = patchPatchPointNormals[patchi];
00293 
00294         // If there are potentially shared points for the patch being considered
00295         if (patchPoints.size())
00296         {
00297             // Get the current meshPoints list for the patch
00298             facePointPatch& fpp = refCast<facePointPatch>(pbm[patchi]);
00299             const labelList& fmp = fpp.meshPoints();
00300             labelList& mp = fpp.meshPoints_;
00301 
00302             const vectorField& fnormals = fpp.pointNormals();
00303             vectorField& normals = fpp.pointNormals_;
00304 
00305             // Create a HashSet of the point labels for the patch
00306             Map<label> patchPointSet(2*fmp.size());
00307 
00308             forAll (fmp, ppi)
00309             {
00310                 patchPointSet.insert(fmp[ppi], ppi);
00311             }
00312 
00313             label nPoints = mp.size();
00314             label lpi = 0;
00315             bool resized = false;
00316 
00317             // For each potentially shared point...
00318             forAll(patchPoints, ppi)
00319             {
00320                 // Check if it is not already in the patch,
00321                 // i.e. not part of a face of the patch
00322                 if (!patchPointSet.found(ppmp[patchPoints[ppi]]))
00323                 {
00324                     // If it isn't already in the patch check if the local
00325                     // meshPoints is already set and if not initialise the
00326                     // meshPoints_ and pointNormals_
00327                     if (!resized)
00328                     {
00329                         if (!mp.size() && fmp.size())
00330                         {
00331                             mp = fmp;
00332                             normals = fnormals;
00333 
00334                             nPoints = mp.size();
00335                         }
00336 
00337                         mp.setSize(nPoints + patchPoints.size());
00338                         loneMeshPoints_.setSize(patchPoints.size());
00339                         normals.setSize(nPoints + patchPoints.size());
00340                         resized = true;
00341                     }
00342 
00343                     // Add the new point to the patch
00344                     mp[nPoints] = ppmp[patchPoints[ppi]];
00345                     loneMeshPoints_[lpi++] = ppmp[patchPoints[ppi]];
00346                     normals[nPoints++] = patchPointNormals[ppi];
00347                 }
00348             }
00349 
00350             // If the lists have been resized points have been added.
00351             // Shrink the lists to the current size.
00352             if (resized)
00353             {
00354                 mp.setSize(nPoints);
00355                 loneMeshPoints_.setSize(lpi);
00356                 normals.setSize(nPoints);
00357             }
00358         }
00359     }
00360 }
00361 
00362 
00363 void processorPointPatch::initMovePoints(const pointField&)
00364 {}
00365 
00366 
00367 void processorPointPatch::movePoints(const pointField&)
00368 {}
00369 
00370 
00371 void processorPointPatch::initUpdateMesh()
00372 {
00373     facePointPatch::initUpdateMesh();
00374     processorPointPatch::initGeometry();
00375 }
00376 
00377 
00378 void processorPointPatch::updateMesh()
00379 {
00380     facePointPatch::updateMesh();
00381     processorPointPatch::calcGeometry();
00382 }
00383 
00384 
00385 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00386 
00387 processorPointPatch::processorPointPatch
00388 (
00389     const polyPatch& patch,
00390     const pointBoundaryMesh& bm
00391 )
00392 :
00393     coupledFacePointPatch(patch, bm),
00394     procPolyPatch_(refCast<const processorPolyPatch>(patch))
00395 {}
00396 
00397 
00398 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00399 
00400 processorPointPatch::~processorPointPatch()
00401 {}
00402 
00403 
00404 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00405 
00406 } // End namespace Foam
00407 
00408 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd