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

simpleGeomDecomp.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 Description
00026 
00027 \*---------------------------------------------------------------------------*/
00028 
00029 #include "simpleGeomDecomp.H"
00030 #include "addToRunTimeSelectionTable.H"
00031 #include "SortableList.H"
00032 
00033 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00034 
00035 namespace Foam
00036 {
00037     defineTypeNameAndDebug(simpleGeomDecomp, 0);
00038 
00039     addToRunTimeSelectionTable
00040     (
00041         decompositionMethod,
00042         simpleGeomDecomp,
00043         dictionary
00044     );
00045 
00046     addToRunTimeSelectionTable
00047     (
00048         decompositionMethod,
00049         simpleGeomDecomp,
00050         dictionaryMesh
00051     );
00052 }
00053 
00054 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00055 
00056 // assignToProcessorGroup : given nCells cells and nProcGroup processor
00057 // groups to share them, how do we share them out? Answer : each group
00058 // gets nCells/nProcGroup cells, and the first few get one
00059 // extra to make up the numbers. This should produce almost
00060 // perfect load balancing
00061 
00062 void Foam::simpleGeomDecomp::assignToProcessorGroup
00063 (
00064     labelList& processorGroup,
00065     const label nProcGroup
00066 )
00067 {
00068     label jump = processorGroup.size()/nProcGroup;
00069     label jumpb = jump + 1;
00070     label fstProcessorGroup = processorGroup.size() - jump*nProcGroup;
00071 
00072     label ind = 0;
00073     label j = 0;
00074 
00075     // assign cells to the first few processor groups (those with
00076     // one extra cell each
00077     for (j=0; j<fstProcessorGroup; j++)
00078     {
00079         for (register label k=0; k<jumpb; k++)
00080         {
00081             processorGroup[ind++] = j;
00082         }
00083     }
00084 
00085     // and now to the `normal' processor groups
00086     for (; j<nProcGroup; j++)
00087     {
00088         for (register label k=0; k<jump; k++)
00089         {
00090             processorGroup[ind++] = j;
00091         }
00092     }
00093 }
00094 
00095 
00096 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00097 
00098 Foam::simpleGeomDecomp::simpleGeomDecomp(const dictionary& decompositionDict)
00099 :
00100     geomDecomp(decompositionDict, typeName)
00101 {}
00102 
00103 
00104 Foam::simpleGeomDecomp::simpleGeomDecomp
00105 (
00106     const dictionary& decompositionDict,
00107     const polyMesh&
00108 )
00109 :
00110     geomDecomp(decompositionDict, typeName)
00111 {}
00112 
00113 
00114 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00115 
00116 Foam::labelList Foam::simpleGeomDecomp::decompose(const pointField& points)
00117 {
00118     // construct a list for the final result
00119     labelList finalDecomp(points.size());
00120 
00121     labelList processorGroups(points.size());
00122 
00123     labelList pointIndices(points.size());
00124     forAll(pointIndices, i) {pointIndices[i] = i;}
00125 
00126     pointField rotatedPoints = rotDelta_ & points;
00127 
00128     // and one to take the processor group id's. For each direction.
00129     // we assign the processors to groups of processors labelled
00130     // 0..nX to give a banded structure on the mesh. Then we
00131     // construct the actual processor number by treating this as
00132     // the units part of the processor number.
00133     sort
00134     (
00135         pointIndices,
00136         UList<scalar>::less(rotatedPoints.component(vector::X))
00137     );
00138 
00139     assignToProcessorGroup(processorGroups, n_.x());
00140 
00141     forAll(points, i)
00142     {
00143         finalDecomp[pointIndices[i]] = processorGroups[i];
00144     }
00145 
00146 
00147     // now do the same thing in the Y direction. These processor group
00148     // numbers add multiples of nX to the proc. number (columns)
00149     sort
00150     (
00151         pointIndices,
00152         UList<scalar>::less(rotatedPoints.component(vector::Y))
00153     );
00154 
00155     assignToProcessorGroup(processorGroups, n_.y());
00156 
00157     forAll(points, i)
00158     {
00159         finalDecomp[pointIndices[i]] += n_.x()*processorGroups[i];
00160     }
00161 
00162 
00163     // finally in the Z direction. Now we add multiples of nX*nY to give
00164     // layers
00165     sort
00166     (
00167         pointIndices,
00168         UList<scalar>::less(rotatedPoints.component(vector::Z))
00169     );
00170 
00171     assignToProcessorGroup(processorGroups, n_.z());
00172 
00173     forAll(points, i)
00174     {
00175         finalDecomp[pointIndices[i]] += n_.x()*n_.y()*processorGroups[i];
00176     }
00177 
00178 
00179     return finalDecomp;
00180 }
00181 
00182 
00183 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd