Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "simpleGeomDecomp.H"
00027 #include <OpenFOAM/addToRunTimeSelectionTable.H>
00028 #include <OpenFOAM/SortableList.H>
00029
00030
00031
00032 namespace Foam
00033 {
00034 defineTypeNameAndDebug(simpleGeomDecomp, 0);
00035
00036 addToRunTimeSelectionTable
00037 (
00038 decompositionMethod,
00039 simpleGeomDecomp,
00040 dictionary
00041 );
00042
00043 addToRunTimeSelectionTable
00044 (
00045 decompositionMethod,
00046 simpleGeomDecomp,
00047 dictionaryMesh
00048 );
00049 }
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059 void Foam::simpleGeomDecomp::assignToProcessorGroup
00060 (
00061 labelList& processorGroup,
00062 const label nProcGroup
00063 )
00064 {
00065 label jump = processorGroup.size()/nProcGroup;
00066 label jumpb = jump + 1;
00067 label fstProcessorGroup = processorGroup.size() - jump*nProcGroup;
00068
00069 label ind = 0;
00070 label j = 0;
00071
00072
00073
00074 for (j=0; j<fstProcessorGroup; j++)
00075 {
00076 for (register label k=0; k<jumpb; k++)
00077 {
00078 processorGroup[ind++] = j;
00079 }
00080 }
00081
00082
00083 for (; j<nProcGroup; j++)
00084 {
00085 for (register label k=0; k<jump; k++)
00086 {
00087 processorGroup[ind++] = j;
00088 }
00089 }
00090 }
00091
00092
00093 void Foam::simpleGeomDecomp::assignToProcessorGroup
00094 (
00095 labelList& processorGroup,
00096 const label nProcGroup,
00097 const labelList& indices,
00098 const scalarField& weights,
00099 const scalar summedWeights
00100 )
00101 {
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112 const scalar jump = summedWeights/nProcGroup;
00113 const label nProcGroupM1 = nProcGroup - 1;
00114 scalar sumWeights = 0;
00115 label ind = 0;
00116 label j = 0;
00117
00118
00119 for (j=0; j<nProcGroupM1; j++)
00120 {
00121 const scalar limit = jump*scalar(j + 1);
00122 while (sumWeights < limit)
00123 {
00124 sumWeights += weights[indices[ind]];
00125 processorGroup[ind++] = j;
00126 }
00127 }
00128
00129 while (ind < processorGroup.size())
00130 {
00131 processorGroup[ind++] = nProcGroupM1;
00132 }
00133 }
00134
00135
00136
00137
00138 Foam::simpleGeomDecomp::simpleGeomDecomp(const dictionary& decompositionDict)
00139 :
00140 geomDecomp(decompositionDict, typeName)
00141 {}
00142
00143
00144 Foam::simpleGeomDecomp::simpleGeomDecomp
00145 (
00146 const dictionary& decompositionDict,
00147 const polyMesh&
00148 )
00149 :
00150 geomDecomp(decompositionDict, typeName)
00151 {}
00152
00153
00154
00155
00156 Foam::labelList Foam::simpleGeomDecomp::decompose(const pointField& points)
00157 {
00158
00159 labelList finalDecomp(points.size());
00160
00161 labelList processorGroups(points.size());
00162
00163 labelList pointIndices(points.size());
00164 forAll(pointIndices, i)
00165 {
00166 pointIndices[i] = i;
00167 }
00168
00169 pointField rotatedPoints = rotDelta_ & points;
00170
00171
00172
00173
00174
00175
00176 sort
00177 (
00178 pointIndices,
00179 UList<scalar>::less(rotatedPoints.component(vector::X))
00180 );
00181
00182 assignToProcessorGroup(processorGroups, n_.x());
00183
00184 forAll(points, i)
00185 {
00186 finalDecomp[pointIndices[i]] = processorGroups[i];
00187 }
00188
00189
00190
00191
00192 sort
00193 (
00194 pointIndices,
00195 UList<scalar>::less(rotatedPoints.component(vector::Y))
00196 );
00197
00198 assignToProcessorGroup(processorGroups, n_.y());
00199
00200 forAll(points, i)
00201 {
00202 finalDecomp[pointIndices[i]] += n_.x()*processorGroups[i];
00203 }
00204
00205
00206
00207
00208 sort
00209 (
00210 pointIndices,
00211 UList<scalar>::less(rotatedPoints.component(vector::Z))
00212 );
00213
00214 assignToProcessorGroup(processorGroups, n_.z());
00215
00216 forAll(points, i)
00217 {
00218 finalDecomp[pointIndices[i]] += n_.x()*n_.y()*processorGroups[i];
00219 }
00220
00221 return finalDecomp;
00222 }
00223
00224
00225 Foam::labelList Foam::simpleGeomDecomp::decompose
00226 (
00227 const pointField& points,
00228 const scalarField& weights
00229 )
00230 {
00231
00232 labelList finalDecomp(points.size());
00233
00234 labelList processorGroups(points.size());
00235
00236 labelList pointIndices(points.size());
00237 forAll(pointIndices, i)
00238 {
00239 pointIndices[i] = i;
00240 }
00241
00242 pointField rotatedPoints = rotDelta_ & points;
00243
00244
00245
00246
00247
00248
00249 sort
00250 (
00251 pointIndices,
00252 UList<scalar>::less(rotatedPoints.component(vector::X))
00253 );
00254
00255 const scalar summedWeights = sum(weights);
00256 assignToProcessorGroup
00257 (
00258 processorGroups,
00259 n_.x(),
00260 pointIndices,
00261 weights,
00262 summedWeights
00263 );
00264
00265 forAll(points, i)
00266 {
00267 finalDecomp[pointIndices[i]] = processorGroups[i];
00268 }
00269
00270
00271
00272
00273 sort
00274 (
00275 pointIndices,
00276 UList<scalar>::less(rotatedPoints.component(vector::Y))
00277 );
00278
00279 assignToProcessorGroup
00280 (
00281 processorGroups,
00282 n_.y(),
00283 pointIndices,
00284 weights,
00285 summedWeights
00286 );
00287
00288 forAll(points, i)
00289 {
00290 finalDecomp[pointIndices[i]] += n_.x()*processorGroups[i];
00291 }
00292
00293
00294
00295
00296 sort
00297 (
00298 pointIndices,
00299 UList<scalar>::less(rotatedPoints.component(vector::Z))
00300 );
00301
00302 assignToProcessorGroup
00303 (
00304 processorGroups,
00305 n_.z(),
00306 pointIndices,
00307 weights,
00308 summedWeights
00309 );
00310
00311 forAll(points, i)
00312 {
00313 finalDecomp[pointIndices[i]] += n_.x()*n_.y()*processorGroups[i];
00314 }
00315
00316 return finalDecomp;
00317 }
00318