extendedCellToFaceStencil.C
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
00027 #include "extendedCellToFaceStencil.H"
00028 #include "globalIndex.H"
00029 #include "syncTools.H"
00030 #include "SortableList.H"
00031
00032
00033
00034 defineTypeNameAndDebug(Foam::extendedCellToFaceStencil, 0);
00035
00036
00037
00038
00039 void Foam::extendedCellToFaceStencil::writeStencilStats
00040 (
00041 Ostream& os,
00042 const labelListList& stencil,
00043 const mapDistribute& map
00044 )
00045 {
00046 label sumSize = 0;
00047 label nSum = 0;
00048 label minSize = labelMax;
00049 label maxSize = labelMin;
00050
00051 forAll(stencil, i)
00052 {
00053 const labelList& sCells = stencil[i];
00054
00055 if (sCells.size() > 0)
00056 {
00057 sumSize += sCells.size();
00058 nSum++;
00059 minSize = min(minSize, sCells.size());
00060 maxSize = max(maxSize, sCells.size());
00061 }
00062 }
00063 reduce(sumSize, sumOp<label>());
00064 reduce(nSum, sumOp<label>());
00065
00066 reduce(minSize, minOp<label>());
00067 reduce(maxSize, maxOp<label>());
00068
00069 os << "Stencil size :" << nl
00070 << " average : " << scalar(sumSize)/nSum << nl
00071 << " min : " << minSize << nl
00072 << " max : " << maxSize << nl
00073 << endl;
00074
00075
00076 label nSent = 0;
00077 label nLocal = 0;
00078 forAll(map.subMap(), procI)
00079 {
00080 if (procI != Pstream::myProcNo())
00081 {
00082 nSent += map.subMap()[procI].size();
00083 }
00084 else
00085 {
00086 nLocal += map.subMap()[procI].size();
00087 }
00088 }
00089
00090 os << "Local data size : " << returnReduce(nLocal, sumOp<label>()) << nl
00091 << "Sent data size : " << returnReduce(nSent, sumOp<label>()) << nl
00092 << endl;
00093 }
00094
00095
00096 Foam::autoPtr<Foam::mapDistribute>
00097 Foam::extendedCellToFaceStencil::calcDistributeMap
00098 (
00099 const polyMesh& mesh,
00100 const globalIndex& globalNumbering,
00101 labelListList& faceStencil
00102 )
00103 {
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115 List<Map<label> > globalToProc(Pstream::nProcs());
00116 {
00117 const labelList& procPatchMap = mesh.globalData().procPatchMap();
00118 const polyBoundaryMesh& patches = mesh.boundaryMesh();
00119
00120
00121 forAll(procPatchMap, procI)
00122 {
00123 if (procPatchMap[procI] != -1)
00124 {
00125 globalToProc[procI].resize
00126 (
00127 patches[procPatchMap[procI]].size()
00128 );
00129 }
00130 }
00131
00132
00133 forAll(faceStencil, faceI)
00134 {
00135 const labelList& stencilCells = faceStencil[faceI];
00136
00137 forAll(stencilCells, i)
00138 {
00139 label globalCellI = stencilCells[i];
00140 label procI = globalNumbering.whichProcID(stencilCells[i]);
00141
00142 if (procI != Pstream::myProcNo())
00143 {
00144 label nCompact = globalToProc[procI].size();
00145 globalToProc[procI].insert(globalCellI, nCompact);
00146 }
00147 }
00148 }
00149
00150 forAll(globalToProc, procI)
00151 {
00152 if (procI != Pstream::myProcNo())
00153 {
00154 Map<label>& globalMap = globalToProc[procI];
00155
00156 SortableList<label> sorted(globalMap.toc().xfer());
00157
00158 forAll(sorted, i)
00159 {
00160 Map<label>::iterator iter = globalMap.find(sorted[i]);
00161 iter() = i;
00162 }
00163 }
00164 }
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178 }
00179
00180
00181
00182
00183
00184
00185 labelList compactStart(Pstream::nProcs());
00186 compactStart[Pstream::myProcNo()] = 0;
00187 label nCompact = globalNumbering.localSize();
00188 forAll(compactStart, procI)
00189 {
00190 if (procI != Pstream::myProcNo())
00191 {
00192 compactStart[procI] = nCompact;
00193 nCompact += globalToProc[procI].size();
00194 }
00195 }
00196
00197
00198
00199 labelListList recvCompact(Pstream::nProcs());
00200 for (label procI = 0; procI < Pstream::nProcs(); procI++)
00201 {
00202 if (procI != Pstream::myProcNo())
00203 {
00204 labelList wantedGlobals(globalToProc[procI].size());
00205 recvCompact[procI].setSize(globalToProc[procI].size());
00206
00207 label i = 0;
00208 forAllConstIter(Map<label>, globalToProc[procI], iter)
00209 {
00210 wantedGlobals[i] = iter.key();
00211 recvCompact[procI][i] = compactStart[procI]+iter();
00212 i++;
00213 }
00214
00215
00216 OPstream str(Pstream::blocking, procI);
00217 str << wantedGlobals;
00218 }
00219 else
00220 {
00221 recvCompact[procI] =
00222 compactStart[procI]
00223 + identity(globalNumbering.localSize());
00224 }
00225 }
00226 labelListList sendCompact(Pstream::nProcs());
00227 for (label procI = 0; procI < Pstream::nProcs(); procI++)
00228 {
00229 if (procI != Pstream::myProcNo())
00230 {
00231
00232
00233 IPstream str(Pstream::blocking, procI);
00234 labelList globalCells(str);
00235
00236 labelList& procCompact = sendCompact[procI];
00237 procCompact.setSize(globalCells.size());
00238
00239
00240
00241 forAll(globalCells, i)
00242 {
00243 label cellI = globalNumbering.toLocal(globalCells[i]);
00244 procCompact[i] = compactStart[Pstream::myProcNo()]+cellI;
00245 }
00246 }
00247 else
00248 {
00249 sendCompact[procI] = recvCompact[procI];
00250 }
00251 }
00252
00253
00254 forAll(faceStencil, faceI)
00255 {
00256 labelList& stencilCells = faceStencil[faceI];
00257
00258 forAll(stencilCells, i)
00259 {
00260 label globalCellI = stencilCells[i];
00261 label procI = globalNumbering.whichProcID(globalCellI);
00262 if (procI != Pstream::myProcNo())
00263 {
00264 label localCompact = globalToProc[procI][globalCellI];
00265 stencilCells[i] = compactStart[procI]+localCompact;
00266 }
00267 else
00268 {
00269 label localCompact = globalNumbering.toLocal(globalCellI);
00270 stencilCells[i] = compactStart[procI]+localCompact;
00271 }
00272
00273 }
00274 }
00275
00276
00277
00278 autoPtr<mapDistribute> mapPtr
00279 (
00280 new mapDistribute
00281 (
00282 nCompact,
00283 sendCompact,
00284 recvCompact,
00285 true
00286 )
00287 );
00288
00289 return mapPtr;
00290 }
00291
00292
00293
00294
00295 Foam::extendedCellToFaceStencil::extendedCellToFaceStencil(const polyMesh& mesh)
00296 :
00297 mesh_(mesh)
00298 {
00299
00300 const polyBoundaryMesh& patches = mesh.boundaryMesh();
00301
00302 forAll(patches, patchI)
00303 {
00304 if (isA<coupledPolyPatch>(patches[patchI]))
00305 {
00306 const coupledPolyPatch& cpp =
00307 refCast<const coupledPolyPatch>(patches[patchI]);
00308
00309 if (!cpp.parallel() || cpp.separated())
00310 {
00311 FatalErrorIn
00312 (
00313 "extendedCellToFaceStencil::extendedCellToFaceStencil"
00314 "(const polyMesh&)"
00315 ) << "Coupled patches with transformations not supported."
00316 << endl
00317 << "Problematic patch " << cpp.name() << exit(FatalError);
00318 }
00319 }
00320 }
00321 }
00322
00323
00324
Copyright © 2000-2009 OpenCFD Ltd