OpenFOAM logo
The Open Source CFD Toolbox
  Programmer’s C++ Doxygen OpenCFD Solutions Contact OpenFOAM

fvMeshDistribute.H

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-2007 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 Class
00026     fvMeshDistribute
00027 
00028 Description
00029     Sends/receives parts of mesh+fvfields to neighbouring processors.
00030     Used in load balancing.
00031     Input is per local cell the processor it should move to. Moves meshes
00032     and volFields/surfaceFields and returns map which can be used to
00033     distribute other.
00034 
00035     Notes:
00036     - does not handle cyclics. Will probably handle separated proc patches.
00037     - if all cells move off processor also all its processor patches will
00038       get deleted so comms might be screwed up (since e.g. globalMeshData
00039       expects procPatches on all)
00040     - initial mesh has to have procPatches last and all normal patches common
00041       to all processors and in the same order. This is checked.
00042     - faces are matched topologically but points on the faces are not. So
00043       expect problems -on separated patches (cyclics?) -on zero sized processor
00044       edges.
00045 
00046 SourceFiles
00047     fvMeshDistribute.C
00048     fvMeshDistributeTemplates.C
00049 
00050 \*---------------------------------------------------------------------------*/
00051 
00052 #ifndef fvMeshDistribute_H
00053 #define fvMeshDistribute_H
00054 
00055 #include "Field.H"
00056 #include "fvMeshSubset.H"
00057 
00058 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00059 
00060 namespace Foam
00061 {
00062 
00063 // Class forward declarations
00064 class mapAddedPolyMesh;
00065 class mapDistributePolyMesh;
00066 
00067 /*---------------------------------------------------------------------------*\
00068                            Class fvMeshDistribute Declaration
00069 \*---------------------------------------------------------------------------*/
00070 
00071 class fvMeshDistribute
00072 {
00073     // Private data
00074 
00075         //- Underlying fvMesh
00076         fvMesh& mesh_;
00077 
00078         //- Absolute merging tolerance (constructing meshes gets done using
00079         //  geometric matching)
00080         const scalar mergeTol_;
00081 
00082 
00083     // Private classes
00084 
00085         //- Check words are the same. Used in patch type checking of similarly
00086         //  named patches.
00087         class checkEqualType
00088         {
00089         public:
00090 
00091             void operator()(word& x, const word& y) const
00092             {
00093                 if (x != y)
00094                 {
00095                     FatalErrorIn("checkEqualType()(word&, const word&) const")
00096                         << "Patch type " << x << " possibly on processor "
00097                         << Pstream::myProcNo()
00098                         << " does not equal patch type " << y
00099                         << " on some other processor." << nl
00100                         << "Please check similarly named patches for"
00101                         << " having exactly the same type."
00102                         << abort(FatalError);
00103                 }
00104             }
00105         };
00106 
00107         // Hash labelPair. Note non-commutative since p[0] is face, p[1] is
00108         // processor.
00109         class labelPairHash
00110         {
00111         public:
00112 
00113             labelPairHash()
00114             {}
00115 
00116             label operator()(const labelPair& p) const
00117             {
00118                 return label(p[0]*p[0]+p[0]+p[1]);
00119             }
00120 
00121             label operator()(const labelPair& p, const label tableSize) const
00122             {
00123                 return mag(operator()(p)) % tableSize;
00124             }
00125         };
00126 
00127 
00128     // Private Member Functions
00129 
00130         //- Given distribution work out a communication schedule. Is list
00131         //  of pairs. First element of pair is send processor, second is
00132         //  receive processor.
00133         //static List<labelPair> getSchedule(const labelList&);
00134 
00135         //- Find indices with value
00136         static labelList select
00137         (
00138             const bool selectEqual,
00139             const labelList& values,
00140             const label value
00141         );
00142 
00143         //- Check all procs have same names and in exactly same order.
00144         static void checkEqualWordList(const wordList&);
00145 
00146         //- Merge wordlists over all processors
00147         static wordList mergeWordList(const wordList&);
00148 
00149 
00150         // Patch handling
00151 
00152             //- Find patch to put exposed faces into.
00153             label findNonEmptyPatch() const;
00154 
00155             //- Appends processorPolyPatch. Returns patchID.
00156             label addProcPatch(const word& patchName, const label nbrProc);
00157 
00158             //- Add patch field
00159             template<class GeoField>
00160             void addPatchFields(const word& patchFieldType);
00161 
00162             //- Deletes last patch.
00163             void deleteTrailingPatch();
00164 
00165             // Delete trailing patch fields
00166             template<class GeoField>
00167             void deleteTrailingPatchFields();
00168 
00169             //- Save boundary fields
00170             template <class T, class Mesh>
00171             void saveBoundaryFields
00172             (
00173                 PtrList<FieldField<fvsPatchField, T> >& bflds
00174             ) const;
00175 
00176             //- Map boundary fields
00177             template <class T, class Mesh>
00178             void mapBoundaryFields
00179             (
00180                 const mapPolyMesh& map,
00181                 const PtrList<FieldField<fvsPatchField, T> >& oldBflds
00182             );
00183 
00184             //- Init patch fields of certain type
00185             template<class GeoField>
00186             void initPatchFields
00187             (
00188                 const word& patchFieldType,
00189                 const typename GeoField::value_type& initVal
00190             );
00191 
00192             //- Delete all processor patches. Move any processor faces into
00193             //  patchI.
00194             autoPtr<mapPolyMesh> deleteProcPatches(const label patchI);
00195 
00196             //- Repatch the mesh. This is only nessecary for the proc
00197             //  boundary faces. newPatchID is over all boundary faces: -1 or
00198             //  new patchID. constructFaceMap is being adapted for the
00199             //  possible new face position (since proc faces get automatically
00200             //  matched)
00201             autoPtr<mapPolyMesh> repatch
00202             (
00203                 const labelList& newPatchID,
00204                 labelListList& constructFaceMap
00205             );
00206 
00207             //- Merge any shared points that are geometrically shared. Needs
00208             //  parallel valid mesh - uses globalMeshData.
00209             //  constructPointMap is adapted for the new point labels.
00210             autoPtr<mapPolyMesh> mergeSharedPoints
00211             (
00212                 labelListList& constructPointMap
00213             );
00214 
00215         // Coupling information
00216 
00217             //- Construct the local environment of all boundary faces.
00218             void getNeighbourData
00219             (
00220                 const labelList& distribution,
00221                 labelList& sourceFace,
00222                 labelList& sourceProc,
00223                 labelList& sourceNewProc
00224             ) const;
00225 
00226             // Subset the neighbourCell/neighbourProc fields
00227             static void subsetBoundaryData
00228             (
00229                 const fvMesh& mesh,
00230                 const labelList& faceMap,
00231                 const labelList& cellMap,
00232 
00233                 const labelList& oldDistribution,
00234                 const labelList& oldFaceOwner,
00235                 const labelList& oldFaceNeighbour,
00236                 const label oldInternalFaces,
00237 
00238                 const labelList& sourceFace,
00239                 const labelList& sourceProc,
00240                 const labelList& sourceNewProc,
00241 
00242                 labelList& subFace,
00243                 labelList& subProc,
00244                 labelList& subNewProc
00245             );
00246 
00247             //- Find cells on mesh whose faceID/procID match the neighbour
00248             //  cell/proc of domainMesh. Store the matching face.
00249             static void findCouples
00250             (
00251                 const primitiveMesh&,
00252                 const labelList& sourceFace,
00253                 const labelList& sourceProc,
00254 
00255                 const label domain,
00256                 const primitiveMesh& domainMesh,
00257                 const labelList& domainFace,
00258                 const labelList& domainProc,
00259 
00260                 labelList& masterCoupledFaces,
00261                 labelList& slaveCoupledFaces
00262             );
00263 
00264             //- Map data on boundary faces to new mesh (resulting from adding
00265             //  two meshes)
00266             static labelList mapBoundaryData
00267             (
00268                 const primitiveMesh& mesh,      // mesh after adding
00269                 const mapAddedPolyMesh& map,
00270                 const labelList& boundaryData0, // mesh before adding
00271                 const label nInternalFaces1,
00272                 const labelList& boundaryData1  // added mesh
00273             );
00274 
00275 
00276         // Other
00277 
00278             //- Remove cells. Add all exposed faces to patch oldInternalPatchI
00279             autoPtr<mapPolyMesh> doRemoveCells
00280             (
00281                 const labelList& cellsToRemove,
00282                 const label oldInternalPatchI
00283             );
00284 
00285             //- Add processor patches. Changes mesh and returns per neighbour
00286             //  proc the processor patchID.
00287             void addProcPatches
00288             (
00289                 const labelList&, // processor that neighbour is on
00290                 labelList& procPatchID              
00291             );
00292 
00293             //- Get boundary faces to be repatched. Is -1 or new patchID
00294             static labelList getProcBoundaryPatch
00295             (
00296                 const labelList& neighbourNewProc,// new processor per b. face
00297                 const labelList& procPatchID      // patchID
00298             );
00299 
00300             //- Send mesh and coupling data.
00301             static void sendMesh
00302             (
00303                 const label domain,
00304                 const fvMesh& mesh,
00305                 const wordList& pointZoneNames,
00306                 const wordList& facesZoneNames,
00307                 const wordList& cellZoneNames,
00308                 const labelList& sourceFace,
00309                 const labelList& sourceProc,
00310                 const labelList& sourceNewProc
00311             );
00312             //- Send subset of fields
00313             template<class GeoField>
00314             static void sendFields
00315             (
00316                 const label domain,
00317                 const wordList& fieldNames,
00318                 const fvMeshSubset&
00319             );
00320 
00321             //- Receive mesh. Opposite of sendMesh
00322             static autoPtr<fvMesh> receiveMesh
00323             (
00324                 const label domain,
00325                 const wordList& pointZoneNames,
00326                 const wordList& facesZoneNames,
00327                 const wordList& cellZoneNames,
00328                 Time& runTime,
00329                 labelList& domainSourceFace,
00330                 labelList& domainSourceProc,
00331                 labelList& domainSourceNewProc
00332             );
00333 
00334             //- Receive fields. Opposite of sendFields
00335             template<class GeoField>
00336             static void receiveFields
00337             (
00338                 const label domain,
00339                 const wordList& fieldNames,
00340                 fvMesh&,
00341                 PtrList<GeoField>&
00342             );
00343 
00344             //- Disallow default bitwise copy construct
00345             fvMeshDistribute(const fvMeshDistribute&);
00346 
00347             //- Disallow default bitwise assignment
00348             void operator=(const fvMeshDistribute&);
00349 
00350 public:
00351 
00352     ClassName("fvMeshDistribute");
00353 
00354 
00355     // Constructors
00356 
00357         //- Construct from mesh and absolute merge tolerance
00358         fvMeshDistribute(fvMesh& mesh, const scalar mergeTol);
00359 
00360 
00361     // Member Functions
00362 
00363         //- Helper funntion: count cells per processor in wanted distribution
00364         static labelList countCells(const labelList&);
00365 
00366         //- Send cells to neighbours according to distribution
00367         //  (for every cell the new proc)
00368         autoPtr<mapDistributePolyMesh> distribute(const labelList& dist);
00369 
00370         // Debugging
00371 
00372             //- Print some info on coupling data
00373             static void printCoupleInfo
00374             (
00375                 const primitiveMesh&,
00376                 const labelList&,
00377                 const labelList&,
00378                 const labelList&
00379             );
00380 
00381             //- Print some field info
00382             template<class GeoField>
00383             static void printFieldInfo(const fvMesh&);
00384 
00385             //- Print some info on mesh.
00386             static void printMeshInfo(const fvMesh&);
00387 };
00388 
00389 
00390 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00391 
00392 } // End namespace Foam
00393 
00394 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00395 
00396 #ifdef NoRepository
00397 #   include "fvMeshDistributeTemplates.C"
00398 #endif
00399 
00400 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00401 
00402 #endif
00403 
00404 // ************************************************************************* //
Copyright © 2000-2007 OpenCFD Ltd