GAMGAgglomerateLduAddressing.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 "GAMGAgglomeration.H"
00028 #include "GAMGInterface.H"
00029
00030
00031
00032 void Foam::GAMGAgglomeration::agglomerateLduAddressing
00033 (
00034 const label fineLevelIndex
00035 )
00036 {
00037 const lduMesh& fineMesh = meshLevel(fineLevelIndex);
00038 const lduAddressing& fineMeshAddr = fineMesh.lduAddr();
00039
00040 const unallocLabelList& upperAddr = fineMeshAddr.upperAddr();
00041 const unallocLabelList& lowerAddr = fineMeshAddr.lowerAddr();
00042
00043 label nFineFaces = upperAddr.size();
00044
00045
00046 const labelField& restrictMap = restrictAddressing(fineLevelIndex);
00047
00048 if (min(restrictMap) == -1)
00049 {
00050 FatalErrorIn("GAMGAgglomeration::agglomerateLduAddressing")
00051 << "min(restrictMap) == -1" << exit(FatalError);
00052 }
00053
00054 if (restrictMap.size() != fineMeshAddr.size())
00055 {
00056 FatalErrorIn
00057 (
00058 "GAMGAgglomeration::agglomerateLduAddressing"
00059 "(const label fineLevelIndex)"
00060 ) << "restrict map does not correspond to fine level. " << endl
00061 << " Sizes: restrictMap: " << restrictMap.size()
00062 << " nEqns: " << fineMeshAddr.size()
00063 << abort(FatalError);
00064 }
00065
00066
00067
00068 const label nCoarseCells = nCells_[fineLevelIndex];
00069
00070
00071
00072
00073 label maxNnbrs = 10;
00074
00075
00076 labelList cCellnFaces(nCoarseCells, 0);
00077
00078
00079 labelList cCellFaces(maxNnbrs*nCoarseCells);
00080
00081
00082 faceRestrictAddressing_.set(fineLevelIndex, new labelList(nFineFaces));
00083 labelList& faceRestrictAddr = faceRestrictAddressing_[fineLevelIndex];
00084
00085
00086 labelList initCoarseNeighb(nFineFaces);
00087
00088
00089 label nCoarseFaces = 0;
00090
00091
00092 forAll (upperAddr, fineFacei)
00093 {
00094 label rmUpperAddr = restrictMap[upperAddr[fineFacei]];
00095 label rmLowerAddr = restrictMap[lowerAddr[fineFacei]];
00096
00097 if (rmUpperAddr == rmLowerAddr)
00098 {
00099
00100
00101
00102 faceRestrictAddr[fineFacei] = -(rmUpperAddr + 1);
00103 }
00104 else
00105 {
00106
00107
00108 label cOwn = rmUpperAddr;
00109 label cNei = rmLowerAddr;
00110
00111
00112 if (rmUpperAddr > rmLowerAddr)
00113 {
00114 cOwn = rmLowerAddr;
00115 cNei = rmUpperAddr;
00116 }
00117
00118
00119 label* ccFaces = &cCellFaces[maxNnbrs*cOwn];
00120
00121 bool nbrFound = false;
00122 label& ccnFaces = cCellnFaces[cOwn];
00123
00124 for (int i=0; i<ccnFaces; i++)
00125 {
00126 if (initCoarseNeighb[ccFaces[i]] == cNei)
00127 {
00128 nbrFound = true;
00129 faceRestrictAddr[fineFacei] = ccFaces[i];
00130 break;
00131 }
00132 }
00133
00134 if (!nbrFound)
00135 {
00136 if (ccnFaces >= maxNnbrs)
00137 {
00138 label oldMaxNnbrs = maxNnbrs;
00139 maxNnbrs *= 2;
00140
00141 cCellFaces.setSize(maxNnbrs*nCoarseCells);
00142
00143 forAllReverse(cCellnFaces, i)
00144 {
00145 label* oldCcNbrs = &cCellFaces[oldMaxNnbrs*i];
00146 label* newCcNbrs = &cCellFaces[maxNnbrs*i];
00147
00148 for (int j=0; j<cCellnFaces[i]; j++)
00149 {
00150 newCcNbrs[j] = oldCcNbrs[j];
00151 }
00152 }
00153
00154 ccFaces = &cCellFaces[maxNnbrs*cOwn];
00155 }
00156
00157 ccFaces[ccnFaces] = nCoarseFaces;
00158 initCoarseNeighb[nCoarseFaces] = cNei;
00159 faceRestrictAddr[fineFacei] = nCoarseFaces;
00160 ccnFaces++;
00161
00162
00163 nCoarseFaces++;
00164 }
00165 }
00166 }
00167
00168
00169
00170
00171
00172 labelList coarseOwner(nCoarseFaces);
00173 labelList coarseNeighbour(nCoarseFaces);
00174 labelList coarseFaceMap(nCoarseFaces);
00175
00176 label coarseFacei = 0;
00177
00178 forAll (cCellnFaces, cci)
00179 {
00180 label* cFaces = &cCellFaces[maxNnbrs*cci];
00181 label ccnFaces = cCellnFaces[cci];
00182
00183 for (int i=0; i<ccnFaces; i++)
00184 {
00185 coarseOwner[coarseFacei] = cci;
00186 coarseNeighbour[coarseFacei] = initCoarseNeighb[cFaces[i]];
00187 coarseFaceMap[cFaces[i]] = coarseFacei;
00188 coarseFacei++;
00189 }
00190 }
00191
00192 forAll(faceRestrictAddr, fineFacei)
00193 {
00194 if (faceRestrictAddr[fineFacei] >= 0)
00195 {
00196 faceRestrictAddr[fineFacei] =
00197 coarseFaceMap[faceRestrictAddr[fineFacei]];
00198 }
00199 }
00200
00201
00202 cCellnFaces.setSize(0);
00203 cCellFaces.setSize(0);
00204 initCoarseNeighb.setSize(0);
00205 coarseFaceMap.setSize(0);
00206
00207
00208
00209
00210
00211 const lduInterfacePtrsList& fineInterfaces =
00212 interfaceLevels_[fineLevelIndex];
00213
00214
00215 interfaceLevels_.set
00216 (
00217 fineLevelIndex + 1,
00218 new lduInterfacePtrsList(fineInterfaces.size())
00219 );
00220
00221 lduInterfacePtrsList& coarseInterfaces =
00222 interfaceLevels_[fineLevelIndex + 1];
00223
00224 labelListList coarseInterfaceAddr(fineInterfaces.size());
00225
00226
00227 forAll (fineInterfaces, inti)
00228 {
00229 if (fineInterfaces.set(inti))
00230 {
00231 fineInterfaces[inti].initInternalFieldTransfer
00232 (
00233 Pstream::blocking,
00234 restrictMap
00235 );
00236 }
00237 }
00238
00239
00240 forAll (fineInterfaces, inti)
00241 {
00242 if (fineInterfaces.set(inti))
00243 {
00244 coarseInterfaces.set
00245 (
00246 inti,
00247 GAMGInterface::New
00248 (
00249 fineInterfaces[inti],
00250 fineInterfaces[inti].interfaceInternalField(restrictMap),
00251 fineInterfaces[inti].internalFieldTransfer
00252 (
00253 Pstream::blocking,
00254 restrictMap
00255 )
00256 ).ptr()
00257 );
00258
00259 coarseInterfaceAddr[inti] = coarseInterfaces[inti].faceCells();
00260 }
00261 }
00262
00263
00264
00265 meshLevels_.set
00266 (
00267 fineLevelIndex,
00268 new lduPrimitiveMesh
00269 (
00270 nCoarseCells,
00271 coarseOwner,
00272 coarseNeighbour,
00273 coarseInterfaceAddr,
00274 coarseInterfaces,
00275 fineMeshAddr.patchSchedule(),
00276 true
00277 )
00278 );
00279 }
00280
00281
00282
Copyright © 2000-2009 OpenCFD Ltd