initial commit for version 1.5.x patch release
[OpenFOAM-1.5.x.git] / src / decompositionAgglomeration / decompositionMethods / simpleGeomDecomp / simpleGeomDecomp.C
blob08b5952952751de3ff437d4679e0998cac577acb
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software; you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Description
27 \*---------------------------------------------------------------------------*/
29 #include "simpleGeomDecomp.H"
30 #include "addToRunTimeSelectionTable.H"
31 #include "SortableList.H"
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 namespace Foam
37     defineTypeNameAndDebug(simpleGeomDecomp, 0);
39     addToRunTimeSelectionTable
40     (
41         decompositionMethod,
42         simpleGeomDecomp,
43         dictionary
44     );
46     addToRunTimeSelectionTable
47     (
48         decompositionMethod,
49         simpleGeomDecomp,
50         dictionaryMesh
51     );
54 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
56 // assignToProcessorGroup : given nCells cells and nProcGroup processor
57 // groups to share them, how do we share them out? Answer : each group
58 // gets nCells/nProcGroup cells, and the first few get one
59 // extra to make up the numbers. This should produce almost
60 // perfect load balancing
62 void Foam::simpleGeomDecomp::assignToProcessorGroup
64     labelList& processorGroup,
65     const label nProcGroup
68     label jump = processorGroup.size()/nProcGroup;
69     label jumpb = jump + 1;
70     label fstProcessorGroup = processorGroup.size() - jump*nProcGroup;
72     label ind = 0;
73     label j = 0;
75     // assign cells to the first few processor groups (those with
76     // one extra cell each
77     for (j=0; j<fstProcessorGroup; j++)
78     {
79         for (register label k=0; k<jumpb; k++)
80         {
81             processorGroup[ind++] = j;
82         }
83     }
85     // and now to the `normal' processor groups
86     for (; j<nProcGroup; j++)
87     {
88         for (register label k=0; k<jump; k++)
89         {
90             processorGroup[ind++] = j;
91         }
92     }
96 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
98 Foam::simpleGeomDecomp::simpleGeomDecomp(const dictionary& decompositionDict)
100     geomDecomp(decompositionDict, typeName)
104 Foam::simpleGeomDecomp::simpleGeomDecomp
106     const dictionary& decompositionDict,
107     const polyMesh&
110     geomDecomp(decompositionDict, typeName)
114 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
116 Foam::labelList Foam::simpleGeomDecomp::decompose(const pointField& points)
118     // construct a list for the final result
119     labelList finalDecomp(points.size());
121     labelList processorGroups(points.size());
123     labelList pointIndices(points.size());
124     forAll(pointIndices, i) {pointIndices[i] = i;}
126     pointField rotatedPoints = rotDelta_ & points;
128     // and one to take the processor group id's. For each direction.
129     // we assign the processors to groups of processors labelled
130     // 0..nX to give a banded structure on the mesh. Then we
131     // construct the actual processor number by treating this as
132     // the units part of the processor number.
133     sort
134     (
135         pointIndices,
136         SortableList<scalar>::less(rotatedPoints.component(vector::X))
137     );
139     assignToProcessorGroup(processorGroups, n_.x());
141     forAll(points, i)
142     {
143         finalDecomp[pointIndices[i]] = processorGroups[i];
144     }
147     // now do the same thing in the Y direction. These processor group
148     // numbers add multiples of nX to the proc. number (columns)
149     sort
150     (
151         pointIndices,
152         SortableList<scalar>::less(rotatedPoints.component(vector::Y))
153     );
155     assignToProcessorGroup(processorGroups, n_.y());
157     forAll(points, i)
158     {
159         finalDecomp[pointIndices[i]] += n_.x()*processorGroups[i];
160     }
163     // finally in the Z direction. Now we add multiples of nX*nY to give
164     // layers
165     sort
166     (
167         pointIndices,
168         SortableList<scalar>::less(rotatedPoints.component(vector::Z))
169     );
171     assignToProcessorGroup(processorGroups, n_.z());
173     forAll(points, i)
174     {
175         finalDecomp[pointIndices[i]] += n_.x()*n_.y()*processorGroups[i];
176     }
179     return finalDecomp;
183 // ************************************************************************* //