1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
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
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
27 \*---------------------------------------------------------------------------*/
29 #include "simpleGeomDecomp.H"
30 #include "addToRunTimeSelectionTable.H"
31 #include "SortableList.H"
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37 defineTypeNameAndDebug(simpleGeomDecomp, 0);
39 addToRunTimeSelectionTable
46 addToRunTimeSelectionTable
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;
75 // assign cells to the first few processor groups (those with
76 // one extra cell each
77 for (j=0; j<fstProcessorGroup; j++)
79 for (register label k=0; k<jumpb; k++)
81 processorGroup[ind++] = j;
85 // and now to the `normal' processor groups
86 for (; j<nProcGroup; j++)
88 for (register label k=0; k<jump; k++)
90 processorGroup[ind++] = j;
96 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
98 Foam::simpleGeomDecomp::simpleGeomDecomp(const dictionary& decompositionDict)
100 geomDecomp(decompositionDict, typeName)
104 Foam::simpleGeomDecomp::simpleGeomDecomp
106 const dictionary& decompositionDict,
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.
136 SortableList<scalar>::less(rotatedPoints.component(vector::X))
139 assignToProcessorGroup(processorGroups, n_.x());
143 finalDecomp[pointIndices[i]] = processorGroups[i];
147 // now do the same thing in the Y direction. These processor group
148 // numbers add multiples of nX to the proc. number (columns)
152 SortableList<scalar>::less(rotatedPoints.component(vector::Y))
155 assignToProcessorGroup(processorGroups, n_.y());
159 finalDecomp[pointIndices[i]] += n_.x()*processorGroups[i];
163 // finally in the Z direction. Now we add multiples of nX*nY to give
168 SortableList<scalar>::less(rotatedPoints.component(vector::Z))
171 assignToProcessorGroup(processorGroups, n_.z());
175 finalDecomp[pointIndices[i]] += n_.x()*n_.y()*processorGroups[i];
183 // ************************************************************************* //