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 "syncTools.H"
00028 #include "polyMesh.H"
00029
00030
00031
00032
00033
00034 bool Foam::syncTools::hasCouples(const polyBoundaryMesh& patches)
00035 {
00036 bool hasAnyCouples = false;
00037
00038 forAll(patches, patchI)
00039 {
00040 if (patches[patchI].coupled())
00041 {
00042 hasAnyCouples = true;
00043 break;
00044 }
00045 }
00046 return returnReduce(hasAnyCouples, orOp<bool>());
00047 }
00048
00049
00050 void Foam::syncTools::checkTransform
00051 (
00052 const coupledPolyPatch& pp,
00053 const bool applySeparation
00054 )
00055 {
00056 if (!pp.parallel() && pp.forwardT().size() > 1)
00057 {
00058 FatalErrorIn("syncTools::checkTransform(const coupledPolyPatch&)")
00059 << "Non-uniform transformation not supported for point or edge"
00060 << " fields." << endl
00061 << "Patch:" << pp.name()
00062 << abort(FatalError);
00063 }
00064 if (applySeparation && pp.separated() && pp.separation().size() > 1)
00065 {
00066 FatalErrorIn("syncTools::checkTransform(const coupledPolyPatch&)")
00067 << "Non-uniform separation vector not supported for point or edge"
00068 << " fields." << endl
00069 << "Patch:" << pp.name()
00070 << abort(FatalError);
00071 }
00072 }
00073
00074
00075
00076 Foam::PackedBoolList Foam::syncTools::getMasterPoints(const polyMesh& mesh)
00077 {
00078 PackedBoolList isMasterPoint(mesh.nPoints(), 0);
00079 PackedBoolList donePoint(mesh.nPoints(), 0);
00080
00081
00082
00083
00084
00085 const labelList& sharedPointAddr =
00086 mesh.globalData().sharedPointAddr();
00087
00088 labelList minProc(mesh.globalData().nGlobalPoints(), labelMax);
00089
00090 UIndirectList<label>(minProc, sharedPointAddr) = Pstream::myProcNo();
00091
00092 Pstream::listCombineGather(minProc, minEqOp<label>());
00093 Pstream::listCombineScatter(minProc);
00094
00095 const labelList& sharedPointLabels =
00096 mesh.globalData().sharedPointLabels();
00097
00098 forAll(sharedPointAddr, i)
00099 {
00100 if (minProc[sharedPointAddr[i]] == Pstream::myProcNo())
00101 {
00102 isMasterPoint.set(sharedPointLabels[i], 1u);
00103 }
00104 donePoint.set(sharedPointLabels[i], 1u);
00105 }
00106
00107
00108
00109
00110
00111 const polyBoundaryMesh& patches = mesh.boundaryMesh();
00112
00113 forAll(patches, patchI)
00114 {
00115 if (patches[patchI].coupled())
00116 {
00117 if
00118 (
00119 Pstream::parRun()
00120 && isA<processorPolyPatch>(patches[patchI])
00121 )
00122 {
00123 const processorPolyPatch& pp =
00124 refCast<const processorPolyPatch>(patches[patchI]);
00125
00126 const labelList& meshPoints = pp.meshPoints();
00127
00128 forAll(meshPoints, i)
00129 {
00130 label pointI = meshPoints[i];
00131
00132 if (donePoint.get(pointI) == 0u)
00133 {
00134 donePoint.set(pointI, 1u);
00135
00136 if (pp.owner())
00137 {
00138 isMasterPoint.set(pointI, 1u);
00139 }
00140 }
00141 }
00142 }
00143 else if (isA<cyclicPolyPatch>(patches[patchI]))
00144 {
00145 const cyclicPolyPatch& pp =
00146 refCast<const cyclicPolyPatch>(patches[patchI]);
00147
00148 const edgeList& coupledPoints = pp.coupledPoints();
00149 const labelList& meshPoints = pp.meshPoints();
00150
00151 forAll(coupledPoints, i)
00152 {
00153
00154
00155 const edge& pointPair = coupledPoints[i];
00156 label p0 = meshPoints[pointPair[0]];
00157 label p1 = meshPoints[pointPair[1]];
00158
00159 if (donePoint.get(p0) == 0u)
00160 {
00161 donePoint.set(p0, 1u);
00162 isMasterPoint.set(p0, 1u);
00163 donePoint.set(p1, 1u);
00164 }
00165 }
00166 }
00167 else
00168 {
00169 FatalErrorIn("syncTools::getMasterPoints(const polyMesh&)")
00170 << "Cannot handle coupled patch " << patches[patchI].name()
00171 << " of type " << patches[patchI].type()
00172 << abort(FatalError);
00173 }
00174 }
00175 }
00176
00177
00178
00179
00180
00181 forAll(donePoint, pointI)
00182 {
00183 if (donePoint.get(pointI) == 0u)
00184 {
00185 donePoint.set(pointI, 1u);
00186 isMasterPoint.set(pointI, 1u);
00187 }
00188 }
00189
00190 return isMasterPoint;
00191 }
00192
00193
00194
00195 Foam::PackedBoolList Foam::syncTools::getMasterEdges(const polyMesh& mesh)
00196 {
00197 PackedBoolList isMasterEdge(mesh.nEdges(), 0);
00198 PackedBoolList doneEdge(mesh.nEdges(), 0);
00199
00200
00201
00202
00203
00204 const labelList& sharedEdgeAddr =
00205 mesh.globalData().sharedEdgeAddr();
00206
00207 labelList minProc(mesh.globalData().nGlobalEdges(), labelMax);
00208
00209 UIndirectList<label>(minProc, sharedEdgeAddr) = Pstream::myProcNo();
00210
00211 Pstream::listCombineGather(minProc, minEqOp<label>());
00212 Pstream::listCombineScatter(minProc);
00213
00214 const labelList& sharedEdgeLabels =
00215 mesh.globalData().sharedEdgeLabels();
00216
00217 forAll(sharedEdgeAddr, i)
00218 {
00219 if (minProc[sharedEdgeAddr[i]] == Pstream::myProcNo())
00220 {
00221 isMasterEdge.set(sharedEdgeLabels[i], 1u);
00222 }
00223 doneEdge.set(sharedEdgeLabels[i], 1u);
00224 }
00225
00226
00227
00228
00229
00230 const polyBoundaryMesh& patches = mesh.boundaryMesh();
00231
00232 forAll(patches, patchI)
00233 {
00234 if (patches[patchI].coupled())
00235 {
00236 if
00237 (
00238 Pstream::parRun()
00239 && isA<processorPolyPatch>(patches[patchI])
00240 )
00241 {
00242 const processorPolyPatch& pp =
00243 refCast<const processorPolyPatch>(patches[patchI]);
00244
00245 const labelList& meshEdges = pp.meshEdges();
00246
00247 forAll(meshEdges, i)
00248 {
00249 label edgeI = meshEdges[i];
00250
00251 if (doneEdge.get(edgeI) == 0u)
00252 {
00253 doneEdge.set(edgeI, 1u);
00254
00255 if (pp.owner())
00256 {
00257 isMasterEdge.set(edgeI, 1u);
00258 }
00259 }
00260 }
00261 }
00262 else if (isA<cyclicPolyPatch>(patches[patchI]))
00263 {
00264 const cyclicPolyPatch& pp =
00265 refCast<const cyclicPolyPatch>(patches[patchI]);
00266
00267 const edgeList& coupledEdges = pp.coupledEdges();
00268 const labelList& meshEdges = pp.meshEdges();
00269
00270 forAll(coupledEdges, i)
00271 {
00272
00273
00274 const edge& edgePair = coupledEdges[i];
00275 label e0 = meshEdges[edgePair[0]];
00276 label e1 = meshEdges[edgePair[1]];
00277
00278 if (doneEdge.get(e0) == 0u)
00279 {
00280 doneEdge.set(e0, 1u);
00281 isMasterEdge.set(e0, 1u);
00282 doneEdge.set(e1, 1u);
00283 }
00284 }
00285 }
00286 else
00287 {
00288 FatalErrorIn("syncTools::getMasterEdges(const polyMesh&)")
00289 << "Cannot handle coupled patch " << patches[patchI].name()
00290 << " of type " << patches[patchI].type()
00291 << abort(FatalError);
00292 }
00293 }
00294 }
00295
00296
00297
00298
00299
00300 forAll(doneEdge, edgeI)
00301 {
00302 if (doneEdge.get(edgeI) == 0u)
00303 {
00304 doneEdge.set(edgeI, 1u);
00305 isMasterEdge.set(edgeI, 1u);
00306 }
00307 }
00308
00309 return isMasterEdge;
00310 }
00311
00312
00313
00314 Foam::PackedBoolList Foam::syncTools::getMasterFaces(const polyMesh& mesh)
00315 {
00316 PackedBoolList isMasterFace(mesh.nFaces(), 1);
00317
00318 const polyBoundaryMesh& patches = mesh.boundaryMesh();
00319
00320 forAll(patches, patchI)
00321 {
00322 if (patches[patchI].coupled())
00323 {
00324 if (Pstream::parRun() && isA<processorPolyPatch>(patches[patchI]))
00325 {
00326 const processorPolyPatch& pp =
00327 refCast<const processorPolyPatch>(patches[patchI]);
00328
00329 if (!pp.owner())
00330 {
00331 forAll(pp, i)
00332 {
00333 isMasterFace.set(pp.start()+i, 0);
00334 }
00335 }
00336 }
00337 else if (isA<cyclicPolyPatch>(patches[patchI]))
00338 {
00339 const cyclicPolyPatch& pp =
00340 refCast<const cyclicPolyPatch>(patches[patchI]);
00341
00342 for (label i = pp.size()/2; i < pp.size(); i++)
00343 {
00344 isMasterFace.set(pp.start()+i, 0);
00345 }
00346 }
00347 else
00348 {
00349 FatalErrorIn("syncTools::getMasterFaces(const polyMesh&)")
00350 << "Cannot handle coupled patch " << patches[patchI].name()
00351 << " of type " << patches[patchI].type()
00352 << abort(FatalError);
00353 }
00354 }
00355 }
00356
00357 return isMasterFace;
00358 }
00359
00360
00361 template <>
00362 void Foam::syncTools::separateList
00363 (
00364 const vectorField& separation,
00365 UList<vector>& field
00366 )
00367 {
00368 if (separation.size() == 1)
00369 {
00370
00371
00372 forAll(field, i)
00373 {
00374 field[i] += separation[0];
00375 }
00376 }
00377 else if (separation.size() == field.size())
00378 {
00379 forAll(field, i)
00380 {
00381 field[i] += separation[i];
00382 }
00383 }
00384 else
00385 {
00386 FatalErrorIn
00387 (
00388 "syncTools::separateList(const vectorField&, UList<vector>&)"
00389 ) << "Sizes of field and transformation not equal. field:"
00390 << field.size() << " transformation:" << separation.size()
00391 << abort(FatalError);
00392 }
00393 }
00394
00395
00396 template <>
00397 void Foam::syncTools::separateList
00398 (
00399 const vectorField& separation,
00400 Map<vector>& field
00401 )
00402 {
00403 if (separation.size() == 1)
00404 {
00405
00406 forAllIter(Map<vector>, field, iter)
00407 {
00408 iter() += separation[0];
00409 }
00410 }
00411 else if (separation.size() == field.size())
00412 {
00413 forAllIter(Map<vector>, field, iter)
00414 {
00415 iter() += separation[iter.key()];
00416 }
00417 }
00418 else
00419 {
00420 FatalErrorIn
00421 (
00422 "syncTools::separateList(const vectorField&, Map<vector>&)"
00423 ) << "Sizes of field and transformation not equal. field:"
00424 << field.size() << " transformation:" << separation.size()
00425 << abort(FatalError);
00426 }
00427 }
00428
00429
00430 template <>
00431 void Foam::syncTools::separateList
00432 (
00433 const vectorField& separation,
00434 EdgeMap<vector>& field
00435 )
00436 {
00437 if (separation.size() == 1)
00438 {
00439
00440 forAllIter(EdgeMap<vector>, field, iter)
00441 {
00442 iter() += separation[0];
00443 }
00444 }
00445 else
00446 {
00447 FatalErrorIn
00448 (
00449 "syncTools::separateList(const vectorField&, EdgeMap<vector>&)"
00450 ) << "Multiple separation vectors not supported. field:"
00451 << field.size() << " transformation:" << separation.size()
00452 << abort(FatalError);
00453 }
00454 }
00455
00456
00457