cellToCellStencil.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 "cellToCellStencil.H"
00028 #include "syncTools.H"
00029 #include "SortableList.H"
00030 #include "emptyPolyPatch.H"
00031
00032
00033
00034
00035 void Foam::cellToCellStencil::merge
00036 (
00037 const label global0,
00038 const label global1,
00039 const labelList& listA,
00040 labelList& listB
00041 )
00042 {
00043 sort(listB);
00044
00045
00046 label nGlobalInsert = 0;
00047
00048 if (global0 != -1)
00049 {
00050 label index0 = findSortedIndex(listB, global0);
00051 if (index0 == -1)
00052 {
00053 nGlobalInsert++;
00054 }
00055 }
00056
00057 if (global1 != -1)
00058 {
00059 label index1 = findSortedIndex(listB, global1);
00060 if (index1 == -1)
00061 {
00062 nGlobalInsert++;
00063 }
00064 }
00065
00066
00067
00068 label nInsert = 0;
00069
00070 forAll(listA, i)
00071 {
00072 label elem = listA[i];
00073
00074 if (elem != global0 && elem != global1)
00075 {
00076 if (findSortedIndex(listB, elem) == -1)
00077 {
00078 nInsert++;
00079 }
00080 }
00081 }
00082
00083
00084 labelList result(listB.size() + nGlobalInsert + nInsert);
00085
00086 label resultI = 0;
00087
00088
00089 if (global0 != -1)
00090 {
00091 result[resultI++] = global0;
00092 }
00093 if (global1 != -1)
00094 {
00095 result[resultI++] = global1;
00096 }
00097
00098
00099
00100 forAll(listB, i)
00101 {
00102 label elem = listB[i];
00103
00104 if (elem != global0 && elem != global1)
00105 {
00106 result[resultI++] = elem;
00107 }
00108 }
00109
00110
00111
00112 forAll(listA, i)
00113 {
00114 label elem = listA[i];
00115
00116 if (elem != global0 && elem != global1)
00117 {
00118 if (findSortedIndex(listB, elem) == -1)
00119 {
00120 result[resultI++] = elem;
00121 }
00122 }
00123 }
00124
00125 if (resultI != result.size())
00126 {
00127 FatalErrorIn("cellToCellStencil::merge(..)")
00128 << "problem" << abort(FatalError);
00129 }
00130
00131 listB.transfer(result);
00132 }
00133
00134
00135
00136 void Foam::cellToCellStencil::merge
00137 (
00138 const label globalI,
00139 const labelList& pGlobals,
00140 labelList& cCells
00141 )
00142 {
00143 labelHashSet set;
00144 forAll(cCells, i)
00145 {
00146 if (cCells[i] != globalI)
00147 {
00148 set.insert(cCells[i]);
00149 }
00150 }
00151
00152 forAll(pGlobals, i)
00153 {
00154 if (pGlobals[i] != globalI)
00155 {
00156 set.insert(pGlobals[i]);
00157 }
00158 }
00159
00160 cCells.setSize(set.size()+1);
00161 label n = 0;
00162 cCells[n++] = globalI;
00163
00164 forAllConstIter(labelHashSet, set, iter)
00165 {
00166 cCells[n++] = iter.key();
00167 }
00168 }
00169
00170
00171 void Foam::cellToCellStencil::validBoundaryFaces(boolList& isValidBFace) const
00172 {
00173 const polyBoundaryMesh& patches = mesh().boundaryMesh();
00174
00175 isValidBFace.setSize(mesh().nFaces()-mesh().nInternalFaces(), true);
00176
00177 forAll(patches, patchI)
00178 {
00179 const polyPatch& pp = patches[patchI];
00180
00181 if (pp.coupled() || isA<emptyPolyPatch>(pp))
00182 {
00183 label bFaceI = pp.start()-mesh().nInternalFaces();
00184 forAll(pp, i)
00185 {
00186 isValidBFace[bFaceI++] = false;
00187 }
00188 }
00189 }
00190 }
00191
00192
00193 Foam::autoPtr<Foam::indirectPrimitivePatch>
00194 Foam::cellToCellStencil::allCoupledFacesPatch() const
00195 {
00196 const polyBoundaryMesh& patches = mesh().boundaryMesh();
00197
00198 label nCoupled = 0;
00199
00200 forAll(patches, patchI)
00201 {
00202 const polyPatch& pp = patches[patchI];
00203
00204 if (pp.coupled())
00205 {
00206 nCoupled += pp.size();
00207 }
00208 }
00209 labelList coupledFaces(nCoupled);
00210 nCoupled = 0;
00211
00212 forAll(patches, patchI)
00213 {
00214 const polyPatch& pp = patches[patchI];
00215
00216 if (pp.coupled())
00217 {
00218 label faceI = pp.start();
00219
00220 forAll(pp, i)
00221 {
00222 coupledFaces[nCoupled++] = faceI++;
00223 }
00224 }
00225 }
00226
00227 return autoPtr<indirectPrimitivePatch>
00228 (
00229 new indirectPrimitivePatch
00230 (
00231 IndirectList<face>
00232 (
00233 mesh().faces(),
00234 coupledFaces
00235 ),
00236 mesh().points()
00237 )
00238 );
00239 }
00240
00241
00242 void Foam::cellToCellStencil::unionEqOp::operator()
00243 (
00244 labelList& x,
00245 const labelList& y
00246 ) const
00247 {
00248 if (y.size())
00249 {
00250 if (x.empty())
00251 {
00252 x = y;
00253 }
00254 else
00255 {
00256 labelHashSet set(x);
00257 forAll(y, i)
00258 {
00259 set.insert(y[i]);
00260 }
00261 x = set.toc();
00262 }
00263 }
00264 }
00265
00266
00267 void Foam::cellToCellStencil::insertFaceCells
00268 (
00269 const label exclude0,
00270 const label exclude1,
00271 const boolList& isValidBFace,
00272 const labelList& faceLabels,
00273 labelHashSet& globals
00274 ) const
00275 {
00276 const labelList& own = mesh().faceOwner();
00277 const labelList& nei = mesh().faceNeighbour();
00278
00279 forAll(faceLabels, i)
00280 {
00281 label faceI = faceLabels[i];
00282
00283 label globalOwn = globalNumbering().toGlobal(own[faceI]);
00284 if (globalOwn != exclude0 && globalOwn != exclude1)
00285 {
00286 globals.insert(globalOwn);
00287 }
00288
00289 if (mesh().isInternalFace(faceI))
00290 {
00291 label globalNei = globalNumbering().toGlobal(nei[faceI]);
00292 if (globalNei != exclude0 && globalNei != exclude1)
00293 {
00294 globals.insert(globalNei);
00295 }
00296 }
00297 else
00298 {
00299 label bFaceI = faceI-mesh().nInternalFaces();
00300
00301 if (isValidBFace[bFaceI])
00302 {
00303 label globalI = globalNumbering().toGlobal
00304 (
00305 mesh().nCells()
00306 + bFaceI
00307 );
00308
00309 if (globalI != exclude0 && globalI != exclude1)
00310 {
00311 globals.insert(globalI);
00312 }
00313 }
00314 }
00315 }
00316 }
00317
00318
00319 Foam::labelList Foam::cellToCellStencil::calcFaceCells
00320 (
00321 const boolList& isValidBFace,
00322 const labelList& faceLabels,
00323 labelHashSet& globals
00324 ) const
00325 {
00326 globals.clear();
00327
00328 insertFaceCells
00329 (
00330 -1,
00331 -1,
00332 isValidBFace,
00333 faceLabels,
00334 globals
00335 );
00336
00337 return globals.toc();
00338 }
00339
00340
00341
00342
00343 Foam::cellToCellStencil::cellToCellStencil(const polyMesh& mesh)
00344 :
00345 mesh_(mesh),
00346 globalNumbering_(mesh_.nCells()+mesh_.nFaces()-mesh_.nInternalFaces())
00347 {}
00348
00349
00350
Copyright © 2000-2009 OpenCFD Ltd