OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

syncToolsTemplates.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*----------------------------------------------------------------------------*/
00026 
00027 #include "syncTools.H"
00028 #include "polyMesh.H"
00029 #include "processorPolyPatch.H"
00030 #include "cyclicPolyPatch.H"
00031 #include "globalMeshData.H"
00032 #include "contiguous.H"
00033 #include "transform.H"
00034 
00035 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00036 
00037 template <class T>
00038 void Foam::syncTools::separateList
00039 (
00040     const vectorField& separation,
00041     UList<T>& field
00042 )
00043 {}
00044 
00045 
00046 template <class T>
00047 void Foam::syncTools::separateList
00048 (
00049     const vectorField& separation,
00050     Map<T>& field
00051 )
00052 {}
00053 
00054 
00055 template <class T>
00056 void Foam::syncTools::separateList
00057 (
00058     const vectorField& separation,
00059     EdgeMap<T>& field
00060 )
00061 {}
00062 
00063 
00064 // Combine val with existing value at index
00065 template <class T, class CombineOp>
00066 void Foam::syncTools::combine
00067 (
00068     Map<T>& pointValues,
00069     const CombineOp& cop,
00070     const label index,
00071     const T& val
00072 )
00073 {
00074     typename Map<T>::iterator iter = pointValues.find(index);
00075 
00076     if (iter != pointValues.end())
00077     {
00078         cop(iter(), val);
00079     }
00080     else
00081     {
00082         pointValues.insert(index, val);
00083     }
00084 }
00085 
00086 
00087 // Combine val with existing value at (implicit index) e.
00088 template <class T, class CombineOp>
00089 void Foam::syncTools::combine
00090 (
00091     EdgeMap<T>& edgeValues,
00092     const CombineOp& cop,
00093     const edge& index,
00094     const T& val
00095 )
00096 {
00097     typename EdgeMap<T>::iterator iter = edgeValues.find(index);
00098 
00099     if (iter != edgeValues.end())
00100     {
00101         cop(iter(), val);
00102     }
00103     else
00104     {
00105         edgeValues.insert(index, val);
00106     }
00107 }
00108 
00109 
00110 template <class T, class CombineOp>
00111 void Foam::syncTools::syncPointMap
00112 (
00113     const polyMesh& mesh,
00114     Map<T>& pointValues,        // from mesh point label to value
00115     const CombineOp& cop,
00116     const bool applySeparation
00117 )
00118 {
00119     const polyBoundaryMesh& patches = mesh.boundaryMesh();
00120 
00121     if (!hasCouples(patches))
00122     {
00123         return;
00124     }
00125 
00126     // Is there any coupled patch with transformation?
00127     bool hasTransformation = false;
00128 
00129     if (Pstream::parRun())
00130     {
00131         // Send
00132 
00133         forAll(patches, patchI)
00134         {
00135             if
00136             (
00137                 isA<processorPolyPatch>(patches[patchI])
00138              && patches[patchI].nPoints() > 0
00139             )
00140             {
00141                 const processorPolyPatch& procPatch =
00142                     refCast<const processorPolyPatch>(patches[patchI]);
00143 
00144                 // Get data per patchPoint in neighbouring point numbers.
00145 
00146                 const labelList& meshPts = procPatch.meshPoints();
00147                 const labelList& nbrPts = procPatch.neighbPoints();
00148 
00149                 // Extract local values. Create map from nbrPoint to value.
00150                 // Note: how small initial size?
00151                 Map<T> patchInfo(meshPts.size() / 20);
00152 
00153                 forAll(meshPts, i)
00154                 {
00155                     typename Map<T>::const_iterator iter =
00156                         pointValues.find(meshPts[i]);
00157 
00158                     if (iter != pointValues.end())
00159                     {
00160                         if (nbrPts[i] >= 0)
00161                         {
00162                             patchInfo.insert(nbrPts[i], iter());
00163                         }
00164                     }
00165                 }
00166 
00167                 OPstream toNeighb(Pstream::blocking, procPatch.neighbProcNo());
00168                 toNeighb << patchInfo;
00169             }
00170         }
00171 
00172 
00173         // Receive and combine.
00174 
00175         forAll(patches, patchI)
00176         {
00177             if
00178             (
00179                 isA<processorPolyPatch>(patches[patchI])
00180              && patches[patchI].nPoints() > 0
00181             )
00182             {
00183                 const processorPolyPatch& procPatch =
00184                     refCast<const processorPolyPatch>(patches[patchI]);
00185                 checkTransform(procPatch, applySeparation);
00186 
00187                 IPstream fromNb(Pstream::blocking, procPatch.neighbProcNo());
00188                 Map<T> nbrPatchInfo(fromNb);
00189 
00190                 if (!procPatch.parallel())
00191                 {
00192                     hasTransformation = true;
00193                     transformList(procPatch.forwardT(), nbrPatchInfo);
00194                 }
00195                 else if (applySeparation && procPatch.separated())
00196                 {
00197                     hasTransformation = true;
00198                     separateList(-procPatch.separation(), nbrPatchInfo);
00199                 }
00200 
00201                 const labelList& meshPts = procPatch.meshPoints();
00202 
00203                 // Only update those values which come from neighbour
00204 
00205                 forAllConstIter
00206                 (
00207                     typename Map<T>,
00208                     nbrPatchInfo,
00209                     nbrIter
00210                 )
00211                 {
00212                     combine
00213                     (
00214                         pointValues,
00215                         cop,
00216                         meshPts[nbrIter.key()],
00217                         nbrIter()
00218                     );
00219                 }
00220             }
00221         }
00222     }
00223 
00224     // Do the cyclics.
00225     forAll(patches, patchI)
00226     {
00227         if (isA<cyclicPolyPatch>(patches[patchI]))
00228         {
00229             const cyclicPolyPatch& cycPatch =
00230                 refCast<const cyclicPolyPatch>(patches[patchI]);
00231             checkTransform(cycPatch, applySeparation);
00232 
00233             const edgeList& coupledPoints = cycPatch.coupledPoints();
00234             const labelList& meshPts = cycPatch.meshPoints();
00235 
00236             // Extract local values. Create map from nbrPoint to value.
00237             Map<T> half0Values(meshPts.size() / 20);
00238             Map<T> half1Values(meshPts.size() / 20);
00239 
00240             forAll(coupledPoints, i)
00241             {
00242                 const edge& e = coupledPoints[i];
00243 
00244                 typename Map<T>::const_iterator point0Fnd =
00245                     pointValues.find(meshPts[e[0]]);
00246 
00247                 if (point0Fnd != pointValues.end())
00248                 {
00249                     half0Values.insert(i, point0Fnd());
00250                 }
00251 
00252                 typename Map<T>::const_iterator point1Fnd =
00253                     pointValues.find(meshPts[e[1]]);
00254 
00255                 if (point1Fnd != pointValues.end())
00256                 {
00257                     half1Values.insert(i, point1Fnd());
00258                 }
00259             }
00260 
00261             if (!cycPatch.parallel())
00262             {
00263                 hasTransformation = true;
00264                 transformList(cycPatch.reverseT(), half0Values);
00265                 transformList(cycPatch.forwardT(), half1Values);
00266             }
00267             else if (applySeparation && cycPatch.separated())
00268             {
00269                 hasTransformation = true;
00270 
00271                 const vectorField& v = cycPatch.coupledPolyPatch::separation();
00272                 separateList(v, half0Values);
00273                 separateList(-v, half1Values);
00274             }
00275 
00276             forAll(coupledPoints, i)
00277             {
00278                 const edge& e = coupledPoints[i];
00279 
00280                 typename Map<T>::const_iterator half1Fnd = half1Values.find(i);
00281 
00282                 if (half1Fnd != half1Values.end())
00283                 {
00284                     combine
00285                     (
00286                         pointValues,
00287                         cop,
00288                         meshPts[e[0]],
00289                         half1Fnd()
00290                     );
00291                 }
00292 
00293                 typename Map<T>::const_iterator half0Fnd = half0Values.find(i);
00294 
00295                 if (half0Fnd != half0Values.end())
00296                 {
00297                     combine
00298                     (
00299                         pointValues,
00300                         cop,
00301                         meshPts[e[1]],
00302                         half0Fnd()
00303                     );
00304                 }
00305             }
00306         }
00307     }
00308 
00309     //- Note: hasTransformation is only used for warning messages so
00310     //  reduction not strictly nessecary.
00311     //reduce(hasTransformation, orOp<bool>());
00312 
00313     // Synchronize multiple shared points.
00314     const globalMeshData& pd = mesh.globalData();
00315 
00316     if (pd.nGlobalPoints() > 0)
00317     {
00318         if (hasTransformation)
00319         {
00320             WarningIn
00321             (
00322                 "syncTools<class T, class CombineOp>::syncPointMap"
00323                 "(const polyMesh&, Map<T>&, const CombineOp&"
00324                 ", const bool)"
00325             )   << "There are decomposed cyclics in this mesh with"
00326                 << " transformations." << endl
00327                 << "This is not supported. The result will be incorrect"
00328                 << endl;
00329         }
00330         // meshPoint per local index
00331         const labelList& sharedPtLabels = pd.sharedPointLabels();
00332         // global shared index per local index
00333         const labelList& sharedPtAddr = pd.sharedPointAddr();
00334 
00335         // Values on shared points. Keyed on global shared index.
00336         Map<T> sharedPointValues(sharedPtAddr.size());
00337 
00338 
00339         // Fill my entries in the shared points
00340         forAll(sharedPtLabels, i)
00341         {
00342             label meshPointI = sharedPtLabels[i];
00343 
00344             typename Map<T>::const_iterator fnd =
00345                 pointValues.find(meshPointI);
00346 
00347             if (fnd != pointValues.end())
00348             {
00349                 combine
00350                 (
00351                     sharedPointValues,
00352                     cop,
00353                     sharedPtAddr[i],    // index
00354                     fnd()               // value
00355                 );
00356             }
00357         }
00358 
00359         // Reduce on master.
00360 
00361         if (Pstream::parRun())
00362         {
00363             if (Pstream::master())
00364             {
00365                 // Receive the edges using shared points from the slave.
00366                 for
00367                 (
00368                     int slave=Pstream::firstSlave();
00369                     slave<=Pstream::lastSlave();
00370                     slave++
00371                 )
00372                 {
00373                     IPstream fromSlave(Pstream::blocking, slave);
00374                     Map<T> nbrValues(fromSlave);
00375 
00376                     // Merge neighbouring values with my values
00377                     forAllConstIter(typename Map<T>, nbrValues, iter)
00378                     {
00379                         combine
00380                         (
00381                             sharedPointValues,
00382                             cop,
00383                             iter.key(), // edge
00384                             iter()      // value
00385                         );
00386                     }
00387                 }
00388 
00389                 // Send back
00390                 for
00391                 (
00392                     int slave=Pstream::firstSlave();
00393                     slave<=Pstream::lastSlave();
00394                     slave++
00395                 )
00396                 {
00397                     OPstream toSlave(Pstream::blocking, slave);
00398                     toSlave << sharedPointValues;
00399                 }
00400             }
00401             else
00402             {
00403                 // Send to master
00404                 {
00405                     OPstream toMaster
00406                     (
00407                         Pstream::blocking,
00408                         Pstream::masterNo()
00409                     );
00410                     toMaster << sharedPointValues;
00411                 }
00412                 // Receive merged values
00413                 {
00414                     IPstream fromMaster
00415                     (
00416                         Pstream::blocking,
00417                         Pstream::masterNo()
00418                     );
00419                     fromMaster >> sharedPointValues;
00420                 }
00421             }
00422         }
00423 
00424 
00425         // Merge sharedPointValues (keyed on sharedPointAddr) into
00426         // pointValues (keyed on mesh points).
00427 
00428         // Map from global shared index to meshpoint
00429         Map<label> sharedToMeshPoint(2*sharedPtAddr.size());
00430         forAll(sharedPtAddr, i)
00431         {
00432             sharedToMeshPoint.insert(sharedPtAddr[i], sharedPtLabels[i]);
00433         }
00434 
00435         forAllConstIter(Map<label>, sharedToMeshPoint, iter)
00436         {
00437             // Do I have a value for my shared point
00438             typename Map<T>::const_iterator sharedFnd =
00439                 sharedPointValues.find(iter.key());
00440 
00441             if (sharedFnd != sharedPointValues.end())
00442             {
00443                 combine
00444                 (
00445                     pointValues,
00446                     cop,
00447                     iter(),     // index
00448                     sharedFnd() // value
00449                 );
00450             }
00451         }
00452     }
00453 }
00454 
00455 
00456 template <class T, class CombineOp>
00457 void Foam::syncTools::syncEdgeMap
00458 (
00459     const polyMesh& mesh,
00460     EdgeMap<T>& edgeValues,
00461     const CombineOp& cop,
00462     const bool applySeparation
00463 )
00464 {
00465     const polyBoundaryMesh& patches = mesh.boundaryMesh();
00466 
00467     if (!hasCouples(patches))
00468     {
00469         return;
00470     }
00471 
00472 
00473     // Do synchronisation without constructing globalEdge addressing
00474     // (since this constructs mesh edge addressing)
00475 
00476 
00477     // Swap proc patch info
00478     // ~~~~~~~~~~~~~~~~~~~~
00479 
00480     if (Pstream::parRun())
00481     {
00482         // Send
00483 
00484         forAll(patches, patchI)
00485         {
00486             if
00487             (
00488                 isA<processorPolyPatch>(patches[patchI])
00489              && patches[patchI].nEdges() > 0
00490             )
00491             {
00492                 const processorPolyPatch& procPatch =
00493                     refCast<const processorPolyPatch>(patches[patchI]);
00494 
00495                 // Get data per patch edge in neighbouring edge.
00496 
00497                 const edgeList& edges = procPatch.edges();
00498                 const labelList& meshPts = procPatch.meshPoints();
00499                 const labelList& nbrPts = procPatch.neighbPoints();
00500 
00501                 EdgeMap<T> patchInfo(edges.size() / 20);
00502 
00503                 forAll(edges, i)
00504                 {
00505                     const edge& e = edges[i];
00506                     const edge meshEdge(meshPts[e[0]], meshPts[e[1]]);
00507 
00508                     typename EdgeMap<T>::const_iterator iter =
00509                         edgeValues.find(meshEdge);
00510 
00511                     if (iter != edgeValues.end())
00512                     {
00513                         const edge nbrEdge(nbrPts[e[0]], nbrPts[e[1]]);
00514 
00515                         if (nbrEdge[0] >= 0 && nbrEdge[1] >= 0)
00516                         {
00517                             patchInfo.insert(nbrEdge, iter());
00518                         }
00519                     }
00520                 }
00521 
00522                 OPstream toNeighb(Pstream::blocking, procPatch.neighbProcNo());
00523                 toNeighb << patchInfo;
00524             }
00525         }
00526 
00527 
00528         // Receive and combine.
00529 
00530         forAll(patches, patchI)
00531         {
00532             if
00533             (
00534                 isA<processorPolyPatch>(patches[patchI])
00535              && patches[patchI].nEdges() > 0
00536             )
00537             {
00538                 const processorPolyPatch& procPatch =
00539                     refCast<const processorPolyPatch>(patches[patchI]);
00540                 checkTransform(procPatch, applySeparation);
00541 
00542                 const labelList& meshPts = procPatch.meshPoints();
00543 
00544                 IPstream fromNbr(Pstream::blocking, procPatch.neighbProcNo());
00545                 EdgeMap<T> nbrPatchInfo(fromNbr);
00546 
00547                 if (!procPatch.parallel())
00548                 {
00549                     transformList(procPatch.forwardT(), nbrPatchInfo);
00550                 }
00551                 else if (applySeparation && procPatch.separated())
00552                 {
00553                     separateList(-procPatch.separation(), nbrPatchInfo);
00554                 }
00555 
00556                 // Only update those values which come from neighbour
00557 
00558                 forAllConstIter
00559                 (
00560                     typename EdgeMap<T>,
00561                     nbrPatchInfo,
00562                     nbrIter
00563                 )
00564                 {
00565                     const edge& e = nbrIter.key();
00566                     const edge meshEdge(meshPts[e[0]], meshPts[e[1]]);
00567 
00568                     combine
00569                     (
00570                         edgeValues,
00571                         cop,
00572                         meshEdge,   // edge
00573                         nbrIter()   // value
00574                     );
00575                 }
00576             }
00577         }
00578     }
00579 
00580 
00581     // Swap cyclic info
00582     // ~~~~~~~~~~~~~~~~
00583 
00584     forAll(patches, patchI)
00585     {
00586         if (isA<cyclicPolyPatch>(patches[patchI]))
00587         {
00588             const cyclicPolyPatch& cycPatch =
00589                 refCast<const cyclicPolyPatch>(patches[patchI]);
00590             checkTransform(cycPatch, applySeparation);
00591 
00592             const edgeList& coupledEdges = cycPatch.coupledEdges();
00593             const labelList& meshPts = cycPatch.meshPoints();
00594             const edgeList& edges = cycPatch.edges();
00595 
00596             // Extract local values. Create map from nbrPoint to value.
00597             Map<T> half0Values(meshPts.size() / 20);
00598             Map<T> half1Values(meshPts.size() / 20);
00599 
00600             forAll(coupledEdges, i)
00601             {
00602                 const edge& twoEdges = coupledEdges[i];
00603 
00604                 {
00605                     const edge& e0 = edges[twoEdges[0]];
00606                     const edge meshEdge0(meshPts[e0[0]], meshPts[e0[1]]);
00607 
00608                     typename EdgeMap<T>::const_iterator iter =
00609                         edgeValues.find(meshEdge0);
00610 
00611                     if (iter != edgeValues.end())
00612                     {
00613                         half0Values.insert(i, iter());
00614                     }
00615                 }
00616                 {
00617                     const edge& e1 = edges[twoEdges[1]];
00618                     const edge meshEdge1(meshPts[e1[0]], meshPts[e1[1]]);
00619 
00620                     typename EdgeMap<T>::const_iterator iter =
00621                         edgeValues.find(meshEdge1);
00622 
00623                     if (iter != edgeValues.end())
00624                     {
00625                         half1Values.insert(i, iter());
00626                     }
00627                 }
00628             }
00629 
00630 
00631             // Transform
00632 
00633             if (!cycPatch.parallel())
00634             {
00635                 transformList(cycPatch.reverseT(), half0Values);
00636                 transformList(cycPatch.forwardT(), half1Values);
00637             }
00638             else if (applySeparation && cycPatch.separated())
00639             {
00640                 const vectorField& v = cycPatch.coupledPolyPatch::separation();
00641                 separateList(v, half0Values);
00642                 separateList(-v, half1Values);
00643             }
00644 
00645 
00646             // Extract and combine information
00647 
00648             forAll(coupledEdges, i)
00649             {
00650                 const edge& twoEdges = coupledEdges[i];
00651 
00652                 typename Map<T>::const_iterator half1Fnd =
00653                     half1Values.find(i);
00654 
00655                 if (half1Fnd != half1Values.end())
00656                 {
00657                     const edge& e0 = edges[twoEdges[0]];
00658                     const edge meshEdge0(meshPts[e0[0]], meshPts[e0[1]]);
00659 
00660                     combine
00661                     (
00662                         edgeValues,
00663                         cop,
00664                         meshEdge0,  // edge
00665                         half1Fnd()  // value
00666                     );
00667                 }
00668 
00669                 typename Map<T>::const_iterator half0Fnd =
00670                     half0Values.find(i);
00671                 if (half0Fnd != half0Values.end())
00672                 {
00673                     const edge& e1 = edges[twoEdges[1]];
00674                     const edge meshEdge1(meshPts[e1[0]], meshPts[e1[1]]);
00675 
00676                     combine
00677                     (
00678                         edgeValues,
00679                         cop,
00680                         meshEdge1,  // edge
00681                         half0Fnd()  // value
00682                     );
00683                 }
00684             }
00685         }
00686     }
00687 
00688     // Synchronize multiple shared points.
00689     // Problem is that we don't want to construct shared edges so basically
00690     // we do here like globalMeshData but then using sparse edge representation
00691     // (EdgeMap instead of mesh.edges())
00692 
00693     const globalMeshData& pd = mesh.globalData();
00694     const labelList& sharedPtAddr = pd.sharedPointAddr();
00695     const labelList& sharedPtLabels = pd.sharedPointLabels();
00696 
00697     // 1. Create map from meshPoint to globalShared index.
00698     Map<label> meshToShared(2*sharedPtLabels.size());
00699     forAll(sharedPtLabels, i)
00700     {
00701         meshToShared.insert(sharedPtLabels[i], sharedPtAddr[i]);
00702     }
00703 
00704     // Values on shared points. From two sharedPtAddr indices to a value.
00705     EdgeMap<T> sharedEdgeValues(meshToShared.size());
00706 
00707     // From shared edge to mesh edge. Used for merging later on.
00708     EdgeMap<edge> potentialSharedEdge(meshToShared.size());
00709 
00710     // 2. Find any edges using two global shared points. These will always be
00711     // on the outside of the mesh. (though might not be on coupled patch
00712     // if is single edge and not on coupled face)
00713     // Store value (if any) on sharedEdgeValues
00714     for (label faceI = mesh.nInternalFaces(); faceI < mesh.nFaces(); faceI++)
00715     {
00716         const face& f = mesh.faces()[faceI];
00717 
00718         forAll(f, fp)
00719         {
00720             label v0 = f[fp];
00721             label v1 = f[f.fcIndex(fp)];
00722 
00723             Map<label>::const_iterator v0Fnd = meshToShared.find(v0);
00724 
00725             if (v0Fnd != meshToShared.end())
00726             {
00727                 Map<label>::const_iterator v1Fnd = meshToShared.find(v1);
00728 
00729                 if (v1Fnd != meshToShared.end())
00730                 {
00731                     const edge meshEdge(v0, v1);
00732 
00733                     // edge in shared point labels
00734                     const edge sharedEdge(v0Fnd(), v1Fnd());
00735 
00736                     // Store mesh edge as a potential shared edge.
00737                     potentialSharedEdge.insert(sharedEdge, meshEdge);
00738 
00739                     typename EdgeMap<T>::const_iterator edgeFnd =
00740                         edgeValues.find(meshEdge);
00741 
00742                     if (edgeFnd != edgeValues.end())
00743                     {
00744                         // edge exists in edgeValues. See if already in map
00745                         // (since on same processor, e.g. cyclic)
00746                         combine
00747                         (
00748                             sharedEdgeValues,
00749                             cop,
00750                             sharedEdge, // edge
00751                             edgeFnd()   // value
00752                         );
00753                     }
00754                 }
00755             }
00756         }
00757     }
00758 
00759 
00760     // Now sharedEdgeValues will contain per potential sharedEdge the value.
00761     // (potential since an edge having two shared points is not nessecary a
00762     //  shared edge).
00763     // Reduce this on the master.
00764 
00765     if (Pstream::parRun())
00766     {
00767         if (Pstream::master())
00768         {
00769             // Receive the edges using shared points from the slave.
00770             for
00771             (
00772                 int slave=Pstream::firstSlave();
00773                 slave<=Pstream::lastSlave();
00774                 slave++
00775             )
00776             {
00777                 IPstream fromSlave(Pstream::blocking, slave);
00778                 EdgeMap<T> nbrValues(fromSlave);
00779 
00780                 // Merge neighbouring values with my values
00781                 forAllConstIter(typename EdgeMap<T>, nbrValues, iter)
00782                 {
00783                     combine
00784                     (
00785                         sharedEdgeValues,
00786                         cop,
00787                         iter.key(), // edge
00788                         iter()      // value
00789                     );
00790                 }
00791             }
00792 
00793             // Send back
00794             for
00795             (
00796                 int slave=Pstream::firstSlave();
00797                 slave<=Pstream::lastSlave();
00798                 slave++
00799             )
00800             {
00801 
00802                 OPstream toSlave(Pstream::blocking, slave);
00803                 toSlave << sharedEdgeValues;
00804             }
00805         }
00806         else
00807         {
00808             // Send to master
00809             {
00810                 OPstream toMaster(Pstream::blocking, Pstream::masterNo());
00811                 toMaster << sharedEdgeValues;
00812             }
00813             // Receive merged values
00814             {
00815                 IPstream fromMaster(Pstream::blocking, Pstream::masterNo());
00816                 fromMaster >> sharedEdgeValues;
00817             }
00818         }
00819     }
00820 
00821 
00822     // Merge sharedEdgeValues (keyed on sharedPointAddr) into edgeValues
00823     // (keyed on mesh points).
00824 
00825     // Loop over all my shared edges.
00826     forAllConstIter(typename EdgeMap<edge>, potentialSharedEdge, iter)
00827     {
00828         const edge& sharedEdge = iter.key();
00829         const edge& meshEdge = iter();
00830 
00831         // Do I have a value for the shared edge?
00832         typename EdgeMap<T>::const_iterator sharedFnd =
00833             sharedEdgeValues.find(sharedEdge);
00834 
00835         if (sharedFnd != sharedEdgeValues.end())
00836         {
00837             combine
00838             (
00839                 edgeValues,
00840                 cop,
00841                 meshEdge,       // edge
00842                 sharedFnd()     // value
00843             );
00844         }
00845     }
00846 }
00847 
00848 
00849 template <class T, class CombineOp>
00850 void Foam::syncTools::syncPointList
00851 (
00852     const polyMesh& mesh,
00853     UList<T>& pointValues,
00854     const CombineOp& cop,
00855     const T& nullValue,
00856     const bool applySeparation
00857 )
00858 {
00859     if (pointValues.size() != mesh.nPoints())
00860     {
00861         FatalErrorIn
00862         (
00863             "syncTools<class T, class CombineOp>::syncPointList"
00864             "(const polyMesh&, UList<T>&, const CombineOp&, const T&"
00865             ", const bool)"
00866         )   << "Number of values " << pointValues.size()
00867             << " is not equal to the number of points in the mesh "
00868             << mesh.nPoints() << abort(FatalError);
00869     }
00870 
00871     const polyBoundaryMesh& patches = mesh.boundaryMesh();
00872 
00873     if (!hasCouples(patches))
00874     {
00875         return;
00876     }
00877 
00878     // Is there any coupled patch with transformation?
00879     bool hasTransformation = false;
00880 
00881     if (Pstream::parRun())
00882     {
00883         // Send
00884 
00885         forAll(patches, patchI)
00886         {
00887             if
00888             (
00889                 isA<processorPolyPatch>(patches[patchI])
00890              && patches[patchI].nPoints() > 0
00891             )
00892             {
00893                 const processorPolyPatch& procPatch =
00894                     refCast<const processorPolyPatch>(patches[patchI]);
00895 
00896                 // Get data per patchPoint in neighbouring point numbers.
00897                 List<T> patchInfo(procPatch.nPoints(), nullValue);
00898 
00899                 const labelList& meshPts = procPatch.meshPoints();
00900                 const labelList& nbrPts = procPatch.neighbPoints();
00901 
00902                 forAll(nbrPts, pointI)
00903                 {
00904                     label nbrPointI = nbrPts[pointI];
00905                     if (nbrPointI >= 0 && nbrPointI < patchInfo.size())
00906                     {
00907                         patchInfo[nbrPointI] = pointValues[meshPts[pointI]];
00908                     }
00909                 }
00910 
00911                 OPstream toNbr(Pstream::blocking, procPatch.neighbProcNo());
00912                 toNbr << patchInfo;
00913             }
00914         }
00915 
00916 
00917         // Receive and combine.
00918 
00919         forAll(patches, patchI)
00920         {
00921             if
00922             (
00923                 isA<processorPolyPatch>(patches[patchI])
00924              && patches[patchI].nPoints() > 0
00925             )
00926             {
00927                 const processorPolyPatch& procPatch =
00928                     refCast<const processorPolyPatch>(patches[patchI]);
00929                 checkTransform(procPatch, applySeparation);
00930 
00931                 List<T> nbrPatchInfo(procPatch.nPoints());
00932                 {
00933                     // We do not know the number of points on the other side
00934                     // so cannot use Pstream::read.
00935                     IPstream fromNbr
00936                     (
00937                         Pstream::blocking,
00938                         procPatch.neighbProcNo()
00939                     );
00940                     fromNbr >> nbrPatchInfo;
00941                 }
00942                 // Null any value which is not on neighbouring processor
00943                 nbrPatchInfo.setSize(procPatch.nPoints(), nullValue);
00944 
00945                 if (!procPatch.parallel())
00946                 {
00947                     hasTransformation = true;
00948                     transformList(procPatch.forwardT(), nbrPatchInfo);
00949                 }
00950                 else if (applySeparation && procPatch.separated())
00951                 {
00952                     hasTransformation = true;
00953                     separateList(-procPatch.separation(), nbrPatchInfo);
00954                 }
00955 
00956                 const labelList& meshPts = procPatch.meshPoints();
00957 
00958                 forAll(meshPts, pointI)
00959                 {
00960                     label meshPointI = meshPts[pointI];
00961                     cop(pointValues[meshPointI], nbrPatchInfo[pointI]);
00962                 }
00963             }
00964         }
00965     }
00966 
00967     // Do the cyclics.
00968     forAll(patches, patchI)
00969     {
00970         if (isA<cyclicPolyPatch>(patches[patchI]))
00971         {
00972             const cyclicPolyPatch& cycPatch =
00973                 refCast<const cyclicPolyPatch>(patches[patchI]);
00974 
00975             checkTransform(cycPatch, applySeparation);
00976 
00977             const edgeList& coupledPoints = cycPatch.coupledPoints();
00978             const labelList& meshPts = cycPatch.meshPoints();
00979 
00980             List<T> half0Values(coupledPoints.size());
00981             List<T> half1Values(coupledPoints.size());
00982 
00983             forAll(coupledPoints, i)
00984             {
00985                 const edge& e = coupledPoints[i];
00986 
00987                 label point0 = meshPts[e[0]];
00988                 label point1 = meshPts[e[1]];
00989 
00990                 half0Values[i] = pointValues[point0];
00991                 half1Values[i] = pointValues[point1];
00992             }
00993 
00994             if (!cycPatch.parallel())
00995             {
00996                 hasTransformation = true;
00997                 transformList(cycPatch.reverseT(), half0Values);
00998                 transformList(cycPatch.forwardT(), half1Values);
00999             }
01000             else if (applySeparation && cycPatch.separated())
01001             {
01002                 hasTransformation = true;
01003                 const vectorField& v = cycPatch.coupledPolyPatch::separation();
01004                 separateList(v, half0Values);
01005                 separateList(-v, half1Values);
01006             }
01007 
01008             forAll(coupledPoints, i)
01009             {
01010                 const edge& e = coupledPoints[i];
01011 
01012                 label point0 = meshPts[e[0]];
01013                 label point1 = meshPts[e[1]];
01014 
01015                 cop(pointValues[point0], half1Values[i]);
01016                 cop(pointValues[point1], half0Values[i]);
01017             }
01018         }
01019     }
01020 
01021     //- Note: hasTransformation is only used for warning messages so
01022     //  reduction not strictly nessecary.
01023     //reduce(hasTransformation, orOp<bool>());
01024 
01025     // Synchronize multiple shared points.
01026     const globalMeshData& pd = mesh.globalData();
01027 
01028     if (pd.nGlobalPoints() > 0)
01029     {
01030         if (hasTransformation)
01031         {
01032             WarningIn
01033             (
01034                 "syncTools<class T, class CombineOp>::syncPointList"
01035                 "(const polyMesh&, UList<T>&, const CombineOp&, const T&"
01036                 ", const bool)"
01037             )   << "There are decomposed cyclics in this mesh with"
01038                 << " transformations." << endl
01039                 << "This is not supported. The result will be incorrect"
01040                 << endl;
01041         }
01042 
01043 
01044         // Values on shared points.
01045         List<T> sharedPts(pd.nGlobalPoints(), nullValue);
01046 
01047         forAll(pd.sharedPointLabels(), i)
01048         {
01049             label meshPointI = pd.sharedPointLabels()[i];
01050             // Fill my entries in the shared points
01051             sharedPts[pd.sharedPointAddr()[i]] = pointValues[meshPointI];
01052         }
01053 
01054         // Combine on master.
01055         Pstream::listCombineGather(sharedPts, cop);
01056         Pstream::listCombineScatter(sharedPts);
01057 
01058         // Now we will all have the same information. Merge it back with
01059         // my local information.
01060         forAll(pd.sharedPointLabels(), i)
01061         {
01062             label meshPointI = pd.sharedPointLabels()[i];
01063             pointValues[meshPointI] = sharedPts[pd.sharedPointAddr()[i]];
01064         }
01065     }
01066 }
01067 
01068 
01069 template <class T, class CombineOp>
01070 void Foam::syncTools::syncPointList
01071 (
01072     const polyMesh& mesh,
01073     const labelList& meshPoints,
01074     UList<T>& pointValues,
01075     const CombineOp& cop,
01076     const T& nullValue,
01077     const bool applySeparation
01078 )
01079 {
01080     if (pointValues.size() != meshPoints.size())
01081     {
01082         FatalErrorIn
01083         (
01084             "syncTools<class T, class CombineOp>::syncPointList"
01085             "(const polyMesh&, const labelList&, UList<T>&, const CombineOp&"
01086             ", const T&, const bool)"
01087         )   << "Number of values " << pointValues.size()
01088             << " is not equal to the number of points "
01089             << meshPoints.size() << abort(FatalError);
01090     }
01091 
01092     if (!hasCouples(mesh.boundaryMesh()))
01093     {
01094         return;
01095     }
01096 
01097     List<T> meshValues(mesh.nPoints(), nullValue);
01098 
01099     forAll(meshPoints, i)
01100     {
01101         meshValues[meshPoints[i]] = pointValues[i];
01102     }
01103 
01104     syncTools::syncPointList
01105     (
01106         mesh,
01107         meshValues,
01108         cop,            // combine op
01109         nullValue,      // null value
01110         applySeparation // separation
01111     );
01112 
01113     forAll(meshPoints, i)
01114     {
01115         pointValues[i] = meshValues[meshPoints[i]];
01116     }
01117 }
01118 
01119 
01120 template <class T, class CombineOp>
01121 void Foam::syncTools::syncEdgeList
01122 (
01123     const polyMesh& mesh,
01124     UList<T>& edgeValues,
01125     const CombineOp& cop,
01126     const T& nullValue,
01127     const bool applySeparation
01128 )
01129 {
01130     if (edgeValues.size() != mesh.nEdges())
01131     {
01132         FatalErrorIn
01133         (
01134             "syncTools<class T, class CombineOp>::syncEdgeList"
01135             "(const polyMesh&, UList<T>&, const CombineOp&, const T&"
01136             ", const bool)"
01137         )   << "Number of values " << edgeValues.size()
01138             << " is not equal to the number of edges in the mesh "
01139             << mesh.nEdges() << abort(FatalError);
01140     }
01141 
01142     const polyBoundaryMesh& patches = mesh.boundaryMesh();
01143 
01144     if (!hasCouples(patches))
01145     {
01146         return;
01147     }
01148 
01149     // Is there any coupled patch with transformation?
01150     bool hasTransformation = false;
01151 
01152     if (Pstream::parRun())
01153     {
01154         // Send
01155 
01156         forAll(patches, patchI)
01157         {
01158             if
01159             (
01160                 isA<processorPolyPatch>(patches[patchI])
01161              && patches[patchI].nEdges() > 0
01162             )
01163             {
01164                 const processorPolyPatch& procPatch =
01165                     refCast<const processorPolyPatch>(patches[patchI]);
01166 
01167                 const labelList& meshEdges = procPatch.meshEdges();
01168                 const labelList& neighbEdges = procPatch.neighbEdges();
01169 
01170                 // Get region per patch edge in neighbouring edge numbers.
01171                 List<T> patchInfo(procPatch.nEdges(), nullValue);
01172 
01173                 forAll(neighbEdges, edgeI)
01174                 {
01175                     label nbrEdgeI = neighbEdges[edgeI];
01176 
01177                     if (nbrEdgeI >= 0 && nbrEdgeI < patchInfo.size())
01178                     {
01179                         patchInfo[nbrEdgeI] = edgeValues[meshEdges[edgeI]];
01180                     }
01181                 }
01182 
01183                 OPstream toNbr(Pstream::blocking, procPatch.neighbProcNo());
01184                 toNbr << patchInfo;
01185             }
01186         }
01187 
01188         // Receive and combine.
01189 
01190         forAll(patches, patchI)
01191         {
01192             if
01193             (
01194                 isA<processorPolyPatch>(patches[patchI])
01195              && patches[patchI].nEdges() > 0
01196             )
01197             {
01198                 const processorPolyPatch& procPatch =
01199                     refCast<const processorPolyPatch>(patches[patchI]);
01200 
01201                 checkTransform(procPatch, applySeparation);
01202 
01203                 const labelList& meshEdges = procPatch.meshEdges();
01204 
01205                 // Receive from neighbour. Is per patch edge the region of the
01206                 // neighbouring patch edge.
01207                 List<T> nbrPatchInfo(procPatch.nEdges());
01208 
01209                 {
01210                     IPstream fromNeighb
01211                     (
01212                         Pstream::blocking,
01213                         procPatch.neighbProcNo()
01214                     );
01215                     fromNeighb >> nbrPatchInfo;
01216                 }
01217                 // Null any value which is not on neighbouring processor
01218                 nbrPatchInfo.setSize(procPatch.nEdges(), nullValue);
01219 
01220                 if (!procPatch.parallel())
01221                 {
01222                     hasTransformation = true;
01223                     transformList(procPatch.forwardT(), nbrPatchInfo);
01224                 }
01225                 else if (applySeparation && procPatch.separated())
01226                 {
01227                     hasTransformation = true;
01228                     separateList(-procPatch.separation(), nbrPatchInfo);
01229                 }
01230 
01231                 forAll(meshEdges, edgeI)
01232                 {
01233                     label meshEdgeI = meshEdges[edgeI];
01234 
01235                     cop(edgeValues[meshEdgeI], nbrPatchInfo[edgeI]);
01236                 }
01237             }
01238         }
01239     }
01240 
01241     // Do the cyclics.
01242     forAll(patches, patchI)
01243     {
01244         if (isA<cyclicPolyPatch>(patches[patchI]))
01245         {
01246             const cyclicPolyPatch& cycPatch =
01247                 refCast<const cyclicPolyPatch>(patches[patchI]);
01248 
01249             checkTransform(cycPatch, applySeparation);
01250 
01251             const edgeList& coupledEdges = cycPatch.coupledEdges();
01252             const labelList& meshEdges = cycPatch.meshEdges();
01253 
01254             List<T> half0Values(coupledEdges.size());
01255             List<T> half1Values(coupledEdges.size());
01256 
01257             forAll(coupledEdges, i)
01258             {
01259                 const edge& e = coupledEdges[i];
01260 
01261                 label meshEdge0 = meshEdges[e[0]];
01262                 label meshEdge1 = meshEdges[e[1]];
01263 
01264                 half0Values[i] = edgeValues[meshEdge0];
01265                 half1Values[i] = edgeValues[meshEdge1];
01266             }
01267 
01268             if (!cycPatch.parallel())
01269             {
01270                 hasTransformation = true;
01271                 transformList(cycPatch.reverseT(), half0Values);
01272                 transformList(cycPatch.forwardT(), half1Values);
01273             }
01274             else if (applySeparation && cycPatch.separated())
01275             {
01276                 hasTransformation = true;
01277 
01278                 const vectorField& v = cycPatch.coupledPolyPatch::separation();
01279                 separateList(v, half0Values);
01280                 separateList(-v, half1Values);
01281             }
01282 
01283             forAll(coupledEdges, i)
01284             {
01285                 const edge& e = coupledEdges[i];
01286 
01287                 label meshEdge0 = meshEdges[e[0]];
01288                 label meshEdge1 = meshEdges[e[1]];
01289 
01290                 cop(edgeValues[meshEdge0], half1Values[i]);
01291                 cop(edgeValues[meshEdge1], half0Values[i]);
01292             }
01293         }
01294     }
01295 
01296     //- Note: hasTransformation is only used for warning messages so
01297     //  reduction not strictly nessecary.
01298     //reduce(hasTransformation, orOp<bool>());
01299 
01300     // Do the multiple shared edges
01301     const globalMeshData& pd = mesh.globalData();
01302 
01303     if (pd.nGlobalEdges() > 0)
01304     {
01305         if (hasTransformation)
01306         {
01307             WarningIn
01308             (
01309                 "syncTools<class T, class CombineOp>::syncEdgeList"
01310                 "(const polyMesh&, UList<T>&, const CombineOp&, const T&"
01311                 ", const bool)"
01312             )   << "There are decomposed cyclics in this mesh with"
01313                 << " transformations." << endl
01314                 << "This is not supported. The result will be incorrect"
01315                 << endl;
01316         }
01317 
01318         // Values on shared edges.
01319         List<T> sharedPts(pd.nGlobalEdges(), nullValue);
01320 
01321         forAll(pd.sharedEdgeLabels(), i)
01322         {
01323             label meshEdgeI = pd.sharedEdgeLabels()[i];
01324 
01325             // Fill my entries in the shared edges
01326             sharedPts[pd.sharedEdgeAddr()[i]] = edgeValues[meshEdgeI];
01327         }
01328 
01329         // Combine on master.
01330         Pstream::listCombineGather(sharedPts, cop);
01331         Pstream::listCombineScatter(sharedPts);
01332 
01333         // Now we will all have the same information. Merge it back with
01334         // my local information.
01335         forAll(pd.sharedEdgeLabels(), i)
01336         {
01337             label meshEdgeI = pd.sharedEdgeLabels()[i];
01338             edgeValues[meshEdgeI] = sharedPts[pd.sharedEdgeAddr()[i]];
01339         }
01340     }
01341 }
01342 
01343 
01344 template <class T, class CombineOp>
01345 void Foam::syncTools::syncBoundaryFaceList
01346 (
01347     const polyMesh& mesh,
01348     UList<T>& faceValues,
01349     const CombineOp& cop,
01350     const bool applySeparation
01351 )
01352 {
01353     const label nBFaces = mesh.nFaces() - mesh.nInternalFaces();
01354 
01355     if (faceValues.size() != nBFaces)
01356     {
01357         FatalErrorIn
01358         (
01359             "syncTools<class T, class CombineOp>::syncBoundaryFaceList"
01360             "(const polyMesh&, UList<T>&, const CombineOp&"
01361             ", const bool)"
01362         )   << "Number of values " << faceValues.size()
01363             << " is not equal to the number of boundary faces in the mesh "
01364             << nBFaces << abort(FatalError);
01365     }
01366 
01367     const polyBoundaryMesh& patches = mesh.boundaryMesh();
01368 
01369     if (!hasCouples(patches))
01370     {
01371         return;
01372     }
01373 
01374 
01375     if (Pstream::parRun())
01376     {
01377         // Send
01378 
01379         forAll(patches, patchI)
01380         {
01381             if
01382             (
01383                 isA<processorPolyPatch>(patches[patchI])
01384              && patches[patchI].size() > 0
01385             )
01386             {
01387                 const processorPolyPatch& procPatch =
01388                     refCast<const processorPolyPatch>(patches[patchI]);
01389 
01390                 label patchStart = procPatch.start()-mesh.nInternalFaces();
01391 
01392                 if (contiguous<T>())
01393                 {
01394                     OPstream::write
01395                     (
01396                         Pstream::blocking,
01397                         procPatch.neighbProcNo(),
01398                         reinterpret_cast<const char*>(&faceValues[patchStart]),
01399                         procPatch.size()*sizeof(T)
01400                     );
01401                 }
01402                 else
01403                 {
01404                     OPstream toNbr(Pstream::blocking, procPatch.neighbProcNo());
01405                     toNbr <<
01406                         SubList<T>(faceValues, procPatch.size(), patchStart);
01407                 }
01408             }
01409         }
01410 
01411 
01412         // Receive and combine.
01413 
01414         forAll(patches, patchI)
01415         {
01416             if
01417             (
01418                 isA<processorPolyPatch>(patches[patchI])
01419              && patches[patchI].size() > 0
01420             )
01421             {
01422                 const processorPolyPatch& procPatch =
01423                     refCast<const processorPolyPatch>(patches[patchI]);
01424 
01425                 List<T> nbrPatchInfo(procPatch.size());
01426 
01427                 if (contiguous<T>())
01428                 {
01429                     IPstream::read
01430                     (
01431                         Pstream::blocking,
01432                         procPatch.neighbProcNo(),
01433                         reinterpret_cast<char*>(nbrPatchInfo.begin()),
01434                         nbrPatchInfo.byteSize()
01435                     );
01436                 }
01437                 else
01438                 {
01439                     IPstream fromNeighb
01440                     (
01441                         Pstream::blocking,
01442                         procPatch.neighbProcNo()
01443                     );
01444                     fromNeighb >> nbrPatchInfo;
01445                 }
01446 
01447                 if (!procPatch.parallel())
01448                 {
01449                     transformList(procPatch.forwardT(), nbrPatchInfo);
01450                 }
01451                 else if (applySeparation && procPatch.separated())
01452                 {
01453                     separateList(-procPatch.separation(), nbrPatchInfo);
01454                 }
01455 
01456 
01457                 label bFaceI = procPatch.start()-mesh.nInternalFaces();
01458 
01459                 forAll(nbrPatchInfo, i)
01460                 {
01461                     cop(faceValues[bFaceI++], nbrPatchInfo[i]);
01462                 }
01463             }
01464         }
01465     }
01466 
01467     // Do the cyclics.
01468     forAll(patches, patchI)
01469     {
01470         if (isA<cyclicPolyPatch>(patches[patchI]))
01471         {
01472             const cyclicPolyPatch& cycPatch =
01473                 refCast<const cyclicPolyPatch>(patches[patchI]);
01474 
01475             label patchStart = cycPatch.start()-mesh.nInternalFaces();
01476 
01477             label half = cycPatch.size()/2;
01478             label half1Start = patchStart+half;
01479 
01480             List<T> half0Values(SubList<T>(faceValues, half, patchStart));
01481             List<T> half1Values(SubList<T>(faceValues, half, half1Start));
01482 
01483             if (!cycPatch.parallel())
01484             {
01485                 transformList(cycPatch.reverseT(), half0Values);
01486                 transformList(cycPatch.forwardT(), half1Values);
01487             }
01488             else if (applySeparation && cycPatch.separated())
01489             {
01490                 const vectorField& v = cycPatch.coupledPolyPatch::separation();
01491                 separateList(v, half0Values);
01492                 separateList(-v, half1Values);
01493             }
01494 
01495             label i0 = patchStart;
01496             forAll(half1Values, i)
01497             {
01498                 cop(faceValues[i0++], half1Values[i]);
01499             }
01500 
01501             label i1 = half1Start;
01502             forAll(half0Values, i)
01503             {
01504                 cop(faceValues[i1++], half0Values[i]);
01505             }
01506         }
01507     }
01508 }
01509 
01510 
01511 template <class T, class CombineOp>
01512 void Foam::syncTools::syncFaceList
01513 (
01514     const polyMesh& mesh,
01515     UList<T>& faceValues,
01516     const CombineOp& cop,
01517     const bool applySeparation
01518 )
01519 {
01520     if (faceValues.size() != mesh.nFaces())
01521     {
01522         FatalErrorIn
01523         (
01524             "syncTools<class T, class CombineOp>::syncFaceList"
01525             "(const polyMesh&, UList<T>&, const CombineOp&"
01526             ", const bool)"
01527         )   << "Number of values " << faceValues.size()
01528             << " is not equal to the number of faces in the mesh "
01529             << mesh.nFaces() << abort(FatalError);
01530     }
01531 
01532     SubList<T> bndValues
01533     (
01534         faceValues,
01535         mesh.nFaces()-mesh.nInternalFaces(),
01536         mesh.nInternalFaces()
01537     );
01538 
01539     syncBoundaryFaceList
01540     (
01541         mesh,
01542         bndValues,
01543         cop,
01544         applySeparation
01545     );
01546 }
01547 
01548 
01549 template <class T>
01550 void Foam::syncTools::swapBoundaryFaceList
01551 (
01552     const polyMesh& mesh,
01553     UList<T>& faceValues,
01554     const bool applySeparation
01555 )
01556 {
01557     syncBoundaryFaceList(mesh, faceValues, eqOp<T>(), applySeparation);
01558 }
01559 
01560 
01561 template <class T>
01562 void Foam::syncTools::swapFaceList
01563 (
01564     const polyMesh& mesh,
01565     UList<T>& faceValues,
01566     const bool applySeparation
01567 )
01568 {
01569     syncFaceList(mesh, faceValues, eqOp<T>(), applySeparation);
01570 }
01571 
01572 
01573 template <unsigned nBits, class CombineOp>
01574 void Foam::syncTools::syncFaceList
01575 (
01576     const polyMesh& mesh,
01577     PackedList<nBits>& faceValues,
01578     const CombineOp& cop
01579 )
01580 {
01581     if (faceValues.size() != mesh.nFaces())
01582     {
01583         FatalErrorIn
01584         (
01585             "syncTools<unsigned nBits, class CombineOp>::syncFaceList"
01586             "(const polyMesh&, PackedList<nBits>&, const CombineOp&)"
01587         )   << "Number of values " << faceValues.size()
01588             << " is not equal to the number of faces in the mesh "
01589             << mesh.nFaces() << abort(FatalError);
01590     }
01591 
01592     const polyBoundaryMesh& patches = mesh.boundaryMesh();
01593 
01594     if (!hasCouples(patches))
01595     {
01596         return;
01597     }
01598 
01599     // Patch data (proc patches only).
01600     List<List<unsigned int> > patchValues(patches.size());
01601 
01602     if (Pstream::parRun())
01603     {
01604         // Send
01605 
01606         forAll(patches, patchI)
01607         {
01608             if
01609             (
01610                 isA<processorPolyPatch>(patches[patchI])
01611              && patches[patchI].size() > 0
01612             )
01613             {
01614                 const processorPolyPatch& procPatch =
01615                     refCast<const processorPolyPatch>(patches[patchI]);
01616 
01617                 patchValues[patchI].setSize(procPatch.size());
01618                 forAll(procPatch, i)
01619                 {
01620                     patchValues[patchI][i] =
01621                         faceValues.get(procPatch.start()+i);
01622                 }
01623 
01624                 OPstream toNbr(Pstream::blocking, procPatch.neighbProcNo());
01625                 toNbr << patchValues[patchI];
01626             }
01627         }
01628 
01629 
01630         // Receive and combine.
01631 
01632         forAll(patches, patchI)
01633         {
01634             if
01635             (
01636                 isA<processorPolyPatch>(patches[patchI])
01637              && patches[patchI].size() > 0
01638             )
01639             {
01640                 const processorPolyPatch& procPatch =
01641                     refCast<const processorPolyPatch>(patches[patchI]);
01642 
01643                 {
01644                     IPstream fromNbr
01645                     (
01646                         Pstream::blocking,
01647                         procPatch.neighbProcNo()
01648                     );
01649                     fromNbr >> patchValues[patchI];
01650                 }
01651 
01652                 // Combine (bitwise)
01653                 forAll(procPatch, i)
01654                 {
01655                     unsigned int patchVal = patchValues[patchI][i];
01656                     label meshFaceI = procPatch.start()+i;
01657                     unsigned int faceVal = faceValues.get(meshFaceI);
01658                     cop(faceVal, patchVal);
01659                     faceValues.set(meshFaceI, faceVal);
01660                 }
01661             }
01662         }
01663     }
01664 
01665     // Do the cyclics.
01666     forAll(patches, patchI)
01667     {
01668         if (isA<cyclicPolyPatch>(patches[patchI]))
01669         {
01670             const cyclicPolyPatch& cycPatch =
01671                 refCast<const cyclicPolyPatch>(patches[patchI]);
01672 
01673             label half = cycPatch.size()/2;
01674 
01675             for (label i = 0; i < half; i++)
01676             {
01677                 label meshFace0 = cycPatch.start()+i;
01678                 unsigned int val0 = faceValues.get(meshFace0);
01679                 label meshFace1 = meshFace0 + half;
01680                 unsigned int val1 = faceValues.get(meshFace1);
01681 
01682                 unsigned int t = val0;
01683                 cop(t, val1);
01684                 faceValues.set(meshFace0, t);
01685 
01686                 cop(val1, val0);
01687                 faceValues.set(meshFace1, val1);
01688             }
01689         }
01690     }
01691 }
01692 
01693 
01694 template <unsigned nBits>
01695 void Foam::syncTools::swapFaceList
01696 (
01697     const polyMesh& mesh,
01698     PackedList<nBits>& faceValues
01699 )
01700 {
01701     syncFaceList(mesh, faceValues, eqOp<unsigned int>());
01702 }
01703 
01704 
01705 template <unsigned nBits, class CombineOp>
01706 void Foam::syncTools::syncPointList
01707 (
01708     const polyMesh& mesh,
01709     PackedList<nBits>& pointValues,
01710     const CombineOp& cop,
01711     const unsigned int nullValue
01712 )
01713 {
01714     if (pointValues.size() != mesh.nPoints())
01715     {
01716         FatalErrorIn
01717         (
01718             "syncTools<unsigned nBits, class CombineOp>::syncPointList"
01719             "(const polyMesh&, PackedList<nBits>&, const CombineOp&"
01720             ", const unsigned int&)"
01721         )   << "Number of values " << pointValues.size()
01722             << " is not equal to the number of points in the mesh "
01723             << mesh.nPoints() << abort(FatalError);
01724     }
01725 
01726     const polyBoundaryMesh& patches = mesh.boundaryMesh();
01727 
01728     if (!hasCouples(patches))
01729     {
01730         return;
01731     }
01732 
01733     // Patch data (proc patches only).
01734     List<List<unsigned int> > patchValues(patches.size());
01735 
01736     if (Pstream::parRun())
01737     {
01738         // Send
01739 
01740         forAll(patches, patchI)
01741         {
01742             if
01743             (
01744                 isA<processorPolyPatch>(patches[patchI])
01745              && patches[patchI].nPoints() > 0
01746             )
01747             {
01748                 const processorPolyPatch& procPatch =
01749                     refCast<const processorPolyPatch>(patches[patchI]);
01750 
01751                 patchValues[patchI].setSize(procPatch.nPoints());
01752                 patchValues[patchI] = nullValue;
01753 
01754                 const labelList& meshPts = procPatch.meshPoints();
01755                 const labelList& nbrPts = procPatch.neighbPoints();
01756 
01757                 forAll(nbrPts, pointI)
01758                 {
01759                     label nbrPointI = nbrPts[pointI];
01760                     if (nbrPointI >= 0 && nbrPointI < procPatch.nPoints())
01761                     {
01762                         patchValues[patchI][nbrPointI] =
01763                             pointValues.get(meshPts[pointI]);
01764                     }
01765                 }
01766 
01767                 OPstream toNbr(Pstream::blocking, procPatch.neighbProcNo());
01768                 toNbr << patchValues[patchI];
01769             }
01770         }
01771 
01772 
01773         // Receive and combine.
01774 
01775         forAll(patches, patchI)
01776         {
01777             if
01778             (
01779                 isA<processorPolyPatch>(patches[patchI])
01780              && patches[patchI].nPoints() > 0
01781             )
01782             {
01783                 const processorPolyPatch& procPatch =
01784                     refCast<const processorPolyPatch>(patches[patchI]);
01785 
01786                 {
01787                     // We do not know the number of points on the other side
01788                     // so cannot use Pstream::read.
01789                     IPstream fromNbr
01790                     (
01791                         Pstream::blocking,
01792                         procPatch.neighbProcNo()
01793                     );
01794                     fromNbr >> patchValues[patchI];
01795                 }
01796 
01797                 // Null any value which is not on neighbouring processor
01798                 patchValues[patchI].setSize(procPatch.nPoints(), nullValue);
01799 
01800                 const labelList& meshPts = procPatch.meshPoints();
01801 
01802                 forAll(meshPts, pointI)
01803                 {
01804                     label meshPointI = meshPts[pointI];
01805                     unsigned int pointVal = pointValues.get(meshPointI);
01806                     cop(pointVal, patchValues[patchI][pointI]);
01807                     pointValues.set(meshPointI, pointVal);
01808                 }
01809             }
01810         }
01811     }
01812 
01813     // Do the cyclics.
01814     forAll(patches, patchI)
01815     {
01816         if (isA<cyclicPolyPatch>(patches[patchI]))
01817         {
01818             const cyclicPolyPatch& cycPatch =
01819                 refCast<const cyclicPolyPatch>(patches[patchI]);
01820 
01821             const edgeList& coupledPoints = cycPatch.coupledPoints();
01822             const labelList& meshPts = cycPatch.meshPoints();
01823 
01824             forAll(coupledPoints, i)
01825             {
01826                 const edge& e = coupledPoints[i];
01827 
01828                 label point0 = meshPts[e[0]];
01829                 label point1 = meshPts[e[1]];
01830 
01831                 unsigned int val0 = pointValues.get(point0);
01832                 unsigned int t = val0;
01833                 unsigned int val1 = pointValues.get(point1);
01834 
01835                 cop(t, val1);
01836                 pointValues.set(point0, t);
01837                 cop(val1, val0);
01838                 pointValues.set(point1, val1);
01839             }
01840         }
01841     }
01842 
01843     // Synchronize multiple shared points.
01844     const globalMeshData& pd = mesh.globalData();
01845 
01846     if (pd.nGlobalPoints() > 0)
01847     {
01848         // Values on shared points. Use unpacked storage for ease!
01849         List<unsigned int> sharedPts(pd.nGlobalPoints(), nullValue);
01850 
01851         forAll(pd.sharedPointLabels(), i)
01852         {
01853             label meshPointI = pd.sharedPointLabels()[i];
01854             // Fill my entries in the shared points
01855             sharedPts[pd.sharedPointAddr()[i]] = pointValues.get(meshPointI);
01856         }
01857 
01858         // Combine on master.
01859         Pstream::listCombineGather(sharedPts, cop);
01860         Pstream::listCombineScatter(sharedPts);
01861 
01862         // Now we will all have the same information. Merge it back with
01863         // my local information.
01864         forAll(pd.sharedPointLabels(), i)
01865         {
01866             label meshPointI = pd.sharedPointLabels()[i];
01867             pointValues.set(meshPointI, sharedPts[pd.sharedPointAddr()[i]]);
01868         }
01869     }
01870 }
01871 
01872 
01873 template <unsigned nBits, class CombineOp>
01874 void Foam::syncTools::syncEdgeList
01875 (
01876     const polyMesh& mesh,
01877     PackedList<nBits>& edgeValues,
01878     const CombineOp& cop,
01879     const unsigned int nullValue
01880 )
01881 {
01882     if (edgeValues.size() != mesh.nEdges())
01883     {
01884         FatalErrorIn
01885         (
01886             "syncTools<unsigned nBits, class CombineOp>::syncEdgeList"
01887             "(const polyMesh&, PackedList<nBits>&, const CombineOp&"
01888             ", const unsigned int&)"
01889         )   << "Number of values " << edgeValues.size()
01890             << " is not equal to the number of edges in the mesh "
01891             << mesh.nEdges() << abort(FatalError);
01892     }
01893 
01894     const polyBoundaryMesh& patches = mesh.boundaryMesh();
01895 
01896     if (!hasCouples(patches))
01897     {
01898         return;
01899     }
01900 
01901     // Patch data (proc patches only).
01902     List<List<unsigned int> > patchValues(patches.size());
01903 
01904     if (Pstream::parRun())
01905     {
01906         // Send
01907 
01908         forAll(patches, patchI)
01909         {
01910             if
01911             (
01912                 isA<processorPolyPatch>(patches[patchI])
01913              && patches[patchI].nEdges() > 0
01914             )
01915             {
01916                 const processorPolyPatch& procPatch =
01917                     refCast<const processorPolyPatch>(patches[patchI]);
01918 
01919                 patchValues[patchI].setSize(procPatch.nEdges(), nullValue);
01920 
01921                 const labelList& meshEdges = procPatch.meshEdges();
01922                 const labelList& neighbEdges = procPatch.neighbEdges();
01923 
01924                 forAll(neighbEdges, edgeI)
01925                 {
01926                     label nbrEdgeI = neighbEdges[edgeI];
01927                     if (nbrEdgeI >= 0 && nbrEdgeI < procPatch.nEdges())
01928                     {
01929                         patchValues[patchI][nbrEdgeI] =
01930                             edgeValues.get(meshEdges[edgeI]);
01931                     }
01932                 }
01933 
01934                 OPstream toNbr(Pstream::blocking, procPatch.neighbProcNo());
01935                 toNbr << patchValues[patchI];
01936             }
01937         }
01938 
01939 
01940         // Receive and combine.
01941 
01942         forAll(patches, patchI)
01943         {
01944             if
01945             (
01946                 isA<processorPolyPatch>(patches[patchI])
01947              && patches[patchI].nEdges() > 0
01948             )
01949             {
01950                 const processorPolyPatch& procPatch =
01951                     refCast<const processorPolyPatch>(patches[patchI]);
01952 
01953                 {
01954                     IPstream fromNeighb
01955                     (
01956                         Pstream::blocking,
01957                         procPatch.neighbProcNo()
01958                     );
01959                     fromNeighb >> patchValues[patchI];
01960                 }
01961 
01962                 patchValues[patchI].setSize(procPatch.nEdges(), nullValue);
01963 
01964                 const labelList& meshEdges = procPatch.meshEdges();
01965 
01966                 forAll(meshEdges, edgeI)
01967                 {
01968                     unsigned int patchVal = patchValues[patchI][edgeI];
01969                     label meshEdgeI = meshEdges[edgeI];
01970                     unsigned int edgeVal = edgeValues.get(meshEdgeI);
01971                     cop(edgeVal, patchVal);
01972                     edgeValues.set(meshEdgeI, edgeVal);
01973                 }
01974             }
01975         }
01976     }
01977 
01978     // Do the cyclics.
01979     forAll(patches, patchI)
01980     {
01981         if (isA<cyclicPolyPatch>(patches[patchI]))
01982         {
01983             const cyclicPolyPatch& cycPatch =
01984                 refCast<const cyclicPolyPatch>(patches[patchI]);
01985 
01986             const edgeList& coupledEdges = cycPatch.coupledEdges();
01987             const labelList& meshEdges = cycPatch.meshEdges();
01988 
01989             forAll(coupledEdges, i)
01990             {
01991                 const edge& e = coupledEdges[i];
01992 
01993                 label edge0 = meshEdges[e[0]];
01994                 label edge1 = meshEdges[e[1]];
01995 
01996                 unsigned int val0 = edgeValues.get(edge0);
01997                 unsigned int t = val0;
01998                 unsigned int val1 = edgeValues.get(edge1);
01999 
02000                 cop(t, val1);
02001                 edgeValues.set(edge0, t);
02002                 cop(val1, val0);
02003                 edgeValues.set(edge1, val1);
02004             }
02005         }
02006     }
02007 
02008     // Synchronize multiple shared edges.
02009     const globalMeshData& pd = mesh.globalData();
02010 
02011     if (pd.nGlobalEdges() > 0)
02012     {
02013         // Values on shared edges. Use unpacked storage for ease!
02014         List<unsigned int> sharedPts(pd.nGlobalEdges(), nullValue);
02015 
02016         forAll(pd.sharedEdgeLabels(), i)
02017         {
02018             label meshEdgeI = pd.sharedEdgeLabels()[i];
02019             // Fill my entries in the shared edges
02020             sharedPts[pd.sharedEdgeAddr()[i]] = edgeValues.get(meshEdgeI);
02021         }
02022 
02023         // Combine on master.
02024         Pstream::listCombineGather(sharedPts, cop);
02025         Pstream::listCombineScatter(sharedPts);
02026 
02027         // Now we will all have the same information. Merge it back with
02028         // my local information.
02029         forAll(pd.sharedEdgeLabels(), i)
02030         {
02031             label meshEdgeI = pd.sharedEdgeLabels()[i];
02032             edgeValues.set(meshEdgeI, sharedPts[pd.sharedEdgeAddr()[i]]);
02033         }
02034     }
02035 }
02036 
02037 
02038 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd