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