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

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-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 Class
00025     Foam::fvMeshDistribute
00026 
00027 Description
00028     Sends/receives parts of mesh+fvfields to neighbouring processors.
00029     Used in load balancing.
00030 
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 <OpenFOAM/Field.H>
00056 //#include <OpenFOAM/uLabel.H>
00057 #include <finiteVolume/fvMeshSubset.H>
00058 
00059 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00060 
00061 namespace Foam
00062 {
00063 
00064 // Forward declaration of classes
00065 class mapAddedPolyMesh;
00066 class mapDistributePolyMesh;
00067 
00068 /*---------------------------------------------------------------------------*\
00069                            Class fvMeshDistribute Declaration
00070 \*---------------------------------------------------------------------------*/
00071 
00072 class fvMeshDistribute
00073 {
00074     // Private data
00075 
00076         //- Underlying fvMesh
00077         fvMesh& mesh_;
00078 
00079         //- Absolute merging tolerance (constructing meshes gets done using
00080         //  geometric matching)
00081         const scalar mergeTol_;
00082 
00083 
00084     // Private Member Functions
00085 
00086         //- Find indices with value
00087         static labelList select
00088         (
00089             const bool selectEqual,
00090             const labelList& values,
00091             const label value
00092         );
00093 
00094         //- Check all procs have same names and in exactly same order.
00095         static void checkEqualWordList(const string&, const wordList&);
00096 
00097         //- Merge wordlists over all processors
00098         static wordList mergeWordList(const wordList&);
00099 
00100 
00101         // Patch handling
00102 
00103             //- Find patch to put exposed faces into.
00104             label findNonEmptyPatch() const;
00105 
00106             //- Appends processorPolyPatch. Returns patchID.
00107             label addProcPatch(const word& patchName, const label nbrProc);
00108 
00109             //- Add patch field
00110             template<class GeoField>
00111             void addPatchFields(const word& patchFieldType);
00112 
00113             //- Deletes last patch.
00114             void deleteTrailingPatch();
00115 
00116             // Delete trailing patch fields
00117             template<class GeoField>
00118             void deleteTrailingPatchFields();
00119 
00120             //- Save boundary fields
00121             template <class T, class Mesh>
00122             void saveBoundaryFields
00123             (
00124                 PtrList<FieldField<fvsPatchField, T> >& bflds
00125             ) const;
00126 
00127             //- Map boundary fields
00128             template <class T, class Mesh>
00129             void mapBoundaryFields
00130             (
00131                 const mapPolyMesh& map,
00132                 const PtrList<FieldField<fvsPatchField, T> >& oldBflds
00133             );
00134 
00135             //- Init patch fields of certain type
00136             template<class GeoField, class PatchFieldType>
00137             void initPatchFields
00138             (
00139                 const typename GeoField::value_type& initVal
00140             );
00141 
00142             //- Delete all processor patches. Move any processor faces into
00143             //  patchI.
00144             autoPtr<mapPolyMesh> deleteProcPatches(const label patchI);
00145 
00146             //- Repatch the mesh. This is only nessecary for the proc
00147             //  boundary faces. newPatchID is over all boundary faces: -1 or
00148             //  new patchID. constructFaceMap is being adapted for the
00149             //  possible new face position (since proc faces get automatically
00150             //  matched)
00151             autoPtr<mapPolyMesh> repatch
00152             (
00153                 const labelList& newPatchID,
00154                 labelListList& constructFaceMap
00155             );
00156 
00157             //- Merge any shared points that are geometrically shared. Needs
00158             //  parallel valid mesh - uses globalMeshData.
00159             //  constructPointMap is adapted for the new point labels.
00160             autoPtr<mapPolyMesh> mergeSharedPoints
00161             (
00162                 labelListList& constructPointMap
00163             );
00164 
00165         // Coupling information
00166 
00167             //- Construct the local environment of all boundary faces.
00168             void getNeighbourData
00169             (
00170                 const labelList& distribution,
00171                 labelList& sourceFace,
00172                 labelList& sourceProc,
00173                 labelList& sourceNewProc
00174             ) const;
00175 
00176             // Subset the neighbourCell/neighbourProc fields
00177             static void subsetBoundaryData
00178             (
00179                 const fvMesh& mesh,
00180                 const labelList& faceMap,
00181                 const labelList& cellMap,
00182 
00183                 const labelList& oldDistribution,
00184                 const labelList& oldFaceOwner,
00185                 const labelList& oldFaceNeighbour,
00186                 const label oldInternalFaces,
00187 
00188                 const labelList& sourceFace,
00189                 const labelList& sourceProc,
00190                 const labelList& sourceNewProc,
00191 
00192                 labelList& subFace,
00193                 labelList& subProc,
00194                 labelList& subNewProc
00195             );
00196 
00197             //- Find cells on mesh whose faceID/procID match the neighbour
00198             //  cell/proc of domainMesh. Store the matching face.
00199             static void findCouples
00200             (
00201                 const primitiveMesh&,
00202                 const labelList& sourceFace,
00203                 const labelList& sourceProc,
00204 
00205                 const label domain,
00206                 const primitiveMesh& domainMesh,
00207                 const labelList& domainFace,
00208                 const labelList& domainProc,
00209 
00210                 labelList& masterCoupledFaces,
00211                 labelList& slaveCoupledFaces
00212             );
00213 
00214             //- Map data on boundary faces to new mesh (resulting from adding
00215             //  two meshes)
00216             static labelList mapBoundaryData
00217             (
00218                 const primitiveMesh& mesh,      // mesh after adding
00219                 const mapAddedPolyMesh& map,
00220                 const labelList& boundaryData0, // mesh before adding
00221                 const label nInternalFaces1,
00222                 const labelList& boundaryData1  // added mesh
00223             );
00224 
00225 
00226         // Other
00227 
00228             //- Remove cells. Add all exposed faces to patch oldInternalPatchI
00229             autoPtr<mapPolyMesh> doRemoveCells
00230             (
00231                 const labelList& cellsToRemove,
00232                 const label oldInternalPatchI
00233             );
00234 
00235             //- Add processor patches. Changes mesh and returns per neighbour
00236             //  proc the processor patchID.
00237             void addProcPatches
00238             (
00239                 const labelList&, // processor that neighbour is on
00240                 labelList& procPatchID
00241             );
00242 
00243             //- Get boundary faces to be repatched. Is -1 or new patchID
00244             static labelList getProcBoundaryPatch
00245             (
00246                 const labelList& neighbourNewProc,// new processor per b. face
00247                 const labelList& procPatchID      // patchID
00248             );
00249 
00250             //- Send mesh and coupling data.
00251             static void sendMesh
00252             (
00253                 const label domain,
00254                 const fvMesh& mesh,
00255                 const wordList& pointZoneNames,
00256                 const wordList& facesZoneNames,
00257                 const wordList& cellZoneNames,
00258                 const labelList& sourceFace,
00259                 const labelList& sourceProc,
00260                 const labelList& sourceNewProc,
00261                 OSstream& toDomain
00262             );
00263             //- Send subset of fields
00264             template<class GeoField>
00265             static void sendFields
00266             (
00267                 const label domain,
00268                 const wordList& fieldNames,
00269                 const fvMeshSubset&,
00270                 OSstream& toNbr
00271             );
00272 
00273             //- Receive mesh. Opposite of sendMesh
00274             static autoPtr<fvMesh> receiveMesh
00275             (
00276                 const label domain,
00277                 const wordList& pointZoneNames,
00278                 const wordList& facesZoneNames,
00279                 const wordList& cellZoneNames,
00280                 const Time& runTime,
00281                 labelList& domainSourceFace,
00282                 labelList& domainSourceProc,
00283                 labelList& domainSourceNewProc,
00284                 ISstream& fromNbr
00285             );
00286 
00287             //- Receive fields. Opposite of sendFields
00288             template<class GeoField>
00289             static void receiveFields
00290             (
00291                 const label domain,
00292                 const wordList& fieldNames,
00293                 fvMesh&,
00294                 PtrList<GeoField>&,
00295                 const dictionary& fieldDicts
00296             );
00297 
00298             //- Do parallel exchange
00299             template <class Container, class T>
00300             static void exchange
00301             (
00302                 const List<Container >& sendBufs,
00303                 List<Container >& recvBufs,
00304                 labelListList& sizes
00305             );
00306 
00307             //- Disallow default bitwise copy construct
00308             fvMeshDistribute(const fvMeshDistribute&);
00309 
00310             //- Disallow default bitwise assignment
00311             void operator=(const fvMeshDistribute&);
00312 
00313 public:
00314 
00315     ClassName("fvMeshDistribute");
00316 
00317 
00318     // Constructors
00319 
00320         //- Construct from mesh and absolute merge tolerance
00321         fvMeshDistribute(fvMesh& mesh, const scalar mergeTol);
00322 
00323 
00324     // Member Functions
00325 
00326         //- Helper function: count cells per processor in wanted distribution
00327         static labelList countCells(const labelList&);
00328 
00329         //- Send cells to neighbours according to distribution
00330         //  (for every cell the new proc)
00331         autoPtr<mapDistributePolyMesh> distribute(const labelList& dist);
00332 
00333         // Debugging
00334 
00335             //- Print some info on coupling data
00336             static void printCoupleInfo
00337             (
00338                 const primitiveMesh&,
00339                 const labelList&,
00340                 const labelList&,
00341                 const labelList&
00342             );
00343 
00344             //- Print some field info
00345             template<class GeoField>
00346             static void printFieldInfo(const fvMesh&);
00347 
00348             //- Print some info on mesh.
00349             static void printMeshInfo(const fvMesh&);
00350 };
00351 
00352 
00353 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00354 
00355 } // End namespace Foam
00356 
00357 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00358 
00359 #ifdef NoRepository
00360 #   include <dynamicMesh/fvMeshDistributeTemplates.C>
00361 #endif
00362 
00363 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00364 
00365 #endif
00366 
00367 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines