From 731f523188430af6b7bebde94543c235e1c0288c Mon Sep 17 00:00:00 2001
From: mattijs <mattijs>
Date: Mon, 6 Dec 2010 15:54:45 +0000
Subject: [PATCH] ENH: mapDistribute : cleanup

---
 applications/test/parallel/Test-parallel.C    |  10 +-
 .../directMappedFixedValueFvPatchField.C      |  31 +----
 ...MappedVelocityFluxFixedValueFvPatchField.C |  42 +-----
 .../directMappedPatchBase.C                   |  37 +++++-
 .../directMappedPatchBase.H                   |  18 +--
 .../distributedTriSurfaceMesh.C               | 120 ++----------------
 .../distributedTriSurfaceMeshTemplates.C      |  20 +--
 .../field/streamLine/streamLine.C             |   3 +-
 ...rectMappedFixedInternalValueFvPatchField.C |  10 +-
 ...mperatureCoupledBaffleFvPatchScalarField.C |  30 +----
 ...tureCoupledBaffleMixedFvPatchScalarField.C |  20 +--
 11 files changed, 66 insertions(+), 275 deletions(-)

diff --git a/applications/test/parallel/Test-parallel.C b/applications/test/parallel/Test-parallel.C
index 69fcb2d9dda..c0742ceaee4 100644
--- a/applications/test/parallel/Test-parallel.C
+++ b/applications/test/parallel/Test-parallel.C
@@ -129,15 +129,7 @@ int main(int argc, char *argv[])
         mapDistribute map(constructSize, sendMap.xfer(), recvMap.xfer());
 
         // Distribute complexData
-        mapDistribute::distribute
-        (
-            Pstream::nonBlocking,
-            List<labelPair>(),
-            map.constructSize(),
-            map.subMap(),
-            map.constructMap(),
-            complexData
-        );
+        mapDistribute::distribute(complexData);
 
         Pout<< "complexData:" << complexData << endl;
     }
diff --git a/src/finiteVolume/fields/fvPatchFields/derived/directMappedFixedValue/directMappedFixedValueFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/derived/directMappedFixedValue/directMappedFixedValueFvPatchField.C
index 0fb5b64b780..8bfb3a05f86 100644
--- a/src/finiteVolume/fields/fvPatchFields/derived/directMappedFixedValue/directMappedFixedValueFvPatchField.C
+++ b/src/finiteVolume/fields/fvPatchFields/derived/directMappedFixedValue/directMappedFixedValueFvPatchField.C
@@ -272,15 +272,7 @@ void directMappedFixedValueFvPatchField<Type>::updateCoeffs()
                 newValues = sampleField();
             }
 
-            mapDistribute::distribute
-            (
-                Pstream::defaultCommsType,
-                distMap.schedule(),
-                distMap.constructSize(),
-                distMap.subMap(),
-                distMap.constructMap(),
-                newValues
-            );
+            distMap.distribute(newValues);
 
             break;
         }
@@ -305,15 +297,7 @@ void directMappedFixedValueFvPatchField<Type>::updateCoeffs()
             const fieldType& nbrField = sampleField();
 
             newValues = nbrField.boundaryField()[nbrPatchID];
-            mapDistribute::distribute
-            (
-                Pstream::defaultCommsType,
-                distMap.schedule(),
-                distMap.constructSize(),
-                distMap.subMap(),
-                distMap.constructMap(),
-                newValues
-            );
+            distMap.distribute(newValues);
 
             break;
         }
@@ -335,16 +319,7 @@ void directMappedFixedValueFvPatchField<Type>::updateCoeffs()
                 }
             }
 
-            mapDistribute::distribute
-            (
-                Pstream::defaultCommsType,
-                distMap.schedule(),
-                distMap.constructSize(),
-                distMap.subMap(),
-                distMap.constructMap(),
-                allValues
-            );
-
+            distMap.distribute(allValues);
             newValues.transfer(allValues);
 
             break;
diff --git a/src/finiteVolume/fields/fvPatchFields/derived/directMappedVelocityFluxFixedValue/directMappedVelocityFluxFixedValueFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/derived/directMappedVelocityFluxFixedValue/directMappedVelocityFluxFixedValueFvPatchField.C
index 8f64aedc7eb..6405ab78b4b 100644
--- a/src/finiteVolume/fields/fvPatchFields/derived/directMappedVelocityFluxFixedValue/directMappedVelocityFluxFixedValueFvPatchField.C
+++ b/src/finiteVolume/fields/fvPatchFields/derived/directMappedVelocityFluxFixedValue/directMappedVelocityFluxFixedValueFvPatchField.C
@@ -212,26 +212,10 @@ void directMappedVelocityFluxFixedValueFvPatchField::updateCoeffs()
                 }
             }
 
-            mapDistribute::distribute
-            (
-                Pstream::defaultCommsType,
-                distMap.schedule(),
-                distMap.constructSize(),
-                distMap.subMap(),
-                distMap.constructMap(),
-                allUValues
-            );
+            distMap.distribute(allUValues);
             newUValues.transfer(allUValues);
 
-            mapDistribute::distribute
-            (
-                Pstream::defaultCommsType,
-                distMap.schedule(),
-                distMap.constructSize(),
-                distMap.subMap(),
-                distMap.constructMap(),
-                allPhiValues
-            );
+            distMap.distribute(allPhiValues);
             newPhiValues.transfer(allPhiValues);
 
             break;
@@ -244,28 +228,10 @@ void directMappedVelocityFluxFixedValueFvPatchField::updateCoeffs()
             );
 
             newUValues = UField.boundaryField()[nbrPatchID];
-
-            mapDistribute::distribute
-            (
-                Pstream::defaultCommsType,
-                distMap.schedule(),
-                distMap.constructSize(),
-                distMap.subMap(),
-                distMap.constructMap(),
-                newUValues
-            );
+            distMap.distribute(newUValues);
 
             newPhiValues = phiField.boundaryField()[nbrPatchID];
-
-            mapDistribute::distribute
-            (
-                Pstream::defaultCommsType,
-                distMap.schedule(),
-                distMap.constructSize(),
-                distMap.subMap(),
-                distMap.constructMap(),
-                newPhiValues
-            );
+            distMap.distribute(newPhiValues);
 
             break;
         }
diff --git a/src/meshTools/directMapped/directMappedPolyPatch/directMappedPatchBase.C b/src/meshTools/directMapped/directMappedPolyPatch/directMappedPatchBase.C
index 957fd0281bc..6418c8c8c54 100644
--- a/src/meshTools/directMapped/directMappedPolyPatch/directMappedPatchBase.C
+++ b/src/meshTools/directMapped/directMappedPolyPatch/directMappedPatchBase.C
@@ -527,13 +527,14 @@ void Foam::directMappedPatchBase::calcMapping() const
             constructMap[procI]
         );
 
-        if (debug)
-        {
-            Pout<< "To proc:" << procI << " sending values of cells/faces:"
-                << subMap[procI] << endl;
-            Pout<< "From proc:" << procI << " receiving values of patch faces:"
-                << constructMap[procI] << endl;
-        }
+        //if (debug)
+        //{
+        //    Pout<< "To proc:" << procI << " sending values of cells/faces:"
+        //        << subMap[procI] << endl;
+        //    Pout<< "From proc:" << procI
+        //        << " receiving values of patch faces:"
+        //        << constructMap[procI] << endl;
+        //}
     }
 
     // Redo constructSize
@@ -644,6 +645,28 @@ Foam::directMappedPatchBase::directMappedPatchBase
 {}
 
 
+Foam::directMappedPatchBase::directMappedPatchBase
+(
+    const polyPatch& pp,
+    const word& sampleRegion,
+    const sampleMode mode,
+    const word& samplePatch,
+    const scalar distance
+)
+:
+    patch_(pp),
+    sampleRegion_(sampleRegion),
+    mode_(mode),
+    samplePatch_(samplePatch),
+    offsetMode_(NORMAL),
+    offset_(vector::zero),
+    offsets_(0),
+    distance_(distance),
+    sameRegion_(sampleRegion_ == patch_.boundaryMesh().mesh().name()),
+    mapPtr_(NULL)
+{}
+
+
 Foam::directMappedPatchBase::directMappedPatchBase
 (
     const polyPatch& pp,
diff --git a/src/meshTools/directMapped/directMappedPolyPatch/directMappedPatchBase.H b/src/meshTools/directMapped/directMappedPolyPatch/directMappedPatchBase.H
index 96ac05bf7c2..6b3513f374c 100644
--- a/src/meshTools/directMapped/directMappedPolyPatch/directMappedPatchBase.H
+++ b/src/meshTools/directMapped/directMappedPolyPatch/directMappedPatchBase.H
@@ -206,15 +206,15 @@ public:
             const vector& offset
         );
 
-        ////- Construct from normal and distance
-        //directMappedPatchBase
-        //(
-        //    const polyPatch& pp,
-        //    const word& sampleRegion,
-        //    const word& samplePatch,
-        //    const sampleMode sampleMode,
-        //    const vector& offset
-        //);
+        //- Construct from offsetMode=normal and distance
+        directMappedPatchBase
+        (
+            const polyPatch& pp,
+            const word& sampleRegion,
+            const sampleMode sampleMode,
+            const word& samplePatch,
+            const scalar distance
+        );
 
         //- Construct from dictionary
         directMappedPatchBase(const polyPatch&, const dictionary&);
diff --git a/src/parallel/distributed/distributedTriSurfaceMesh/distributedTriSurfaceMesh.C b/src/parallel/distributed/distributedTriSurfaceMesh/distributedTriSurfaceMesh.C
index accee92b3f7..740c2184d5c 100644
--- a/src/parallel/distributed/distributedTriSurfaceMesh/distributedTriSurfaceMesh.C
+++ b/src/parallel/distributed/distributedTriSurfaceMesh/distributedTriSurfaceMesh.C
@@ -440,15 +440,7 @@ void Foam::distributedTriSurfaceMesh::findLine
         // Exchange the segments
         // ~~~~~~~~~~~~~~~~~~~~~
 
-        map.distribute
-        (
-            Pstream::nonBlocking,   //Pstream::scheduled,
-            List<labelPair>(0),     //map.schedule(),
-            map.constructSize(),
-            map.subMap(),           // what to send
-            map.constructMap(),     // what to receive
-            allSegments
-        );
+        map.distribute(allSegments);
 
 
         // Do tests I need to do
@@ -490,21 +482,7 @@ void Foam::distributedTriSurfaceMesh::findLine
         // Exchange the intersections (opposite to segments)
         // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
-        map.distribute
-        (
-            //Pstream::scheduled,
-            //map.schedule            // Note reverse schedule
-            //(
-            //    map.constructMap(),
-            //    map.subMap()
-            //),
-            Pstream::nonBlocking,
-            List<labelPair>(0),
-            nOldAllSegments,
-            map.constructMap(),     // what to send
-            map.subMap(),           // what to receive
-            intersections
-        );
+        map.reverseDistribute(nOldAllSegments, intersections);
 
 
         // Extract the hits
@@ -657,17 +635,7 @@ Foam::distributedTriSurfaceMesh::calcLocalQueries
     // Send over queries
     // ~~~~~~~~~~~~~~~~~
 
-    map.distribute
-    (
-        //Pstream::scheduled,
-        //map.schedule(),
-        Pstream::nonBlocking,
-        List<labelPair>(0),
-        map.constructSize(),
-        map.subMap(),           // what to send
-        map.constructMap(),     // what to receive
-        triangleIndex
-    );
+    map.distribute(triangleIndex);
 
 
     return mapPtr;
@@ -1594,28 +1562,8 @@ void Foam::distributedTriSurfaceMesh::findNearest
         // swap samples to local processor
         // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
-        map.distribute
-        (
-            //Pstream::scheduled,
-            //map.schedule(),
-            Pstream::nonBlocking,
-            List<labelPair>(0),
-            map.constructSize(),
-            map.subMap(),           // what to send
-            map.constructMap(),     // what to receive
-            allCentres
-        );
-        map.distribute
-        (
-            //Pstream::scheduled,
-            //map.schedule(),
-            Pstream::nonBlocking,
-            List<labelPair>(0),
-            map.constructSize(),
-            map.subMap(),           // what to send
-            map.constructMap(),     // what to receive
-            allRadiusSqr
-        );
+        map.distribute(allCentres);
+        map.distribute(allRadiusSqr);
 
 
         // Do my tests
@@ -1639,21 +1587,7 @@ void Foam::distributedTriSurfaceMesh::findNearest
         // Send back results
         // ~~~~~~~~~~~~~~~~~
 
-        map.distribute
-        (
-            //Pstream::scheduled,
-            //map.schedule            // note reverse schedule
-            //(
-            //    map.constructMap(),
-            //    map.subMap()
-            //),
-            Pstream::nonBlocking,
-            List<labelPair>(0),
-            allSegmentMap.size(),
-            map.constructMap(),     // what to send
-            map.subMap(),           // what to receive
-            allInfo
-        );
+        map.reverseDistribute(allSegmentMap.size(), allInfo);
 
 
         // Extract information
@@ -1892,21 +1826,7 @@ void Foam::distributedTriSurfaceMesh::getRegion
     // Send back results
     // ~~~~~~~~~~~~~~~~~
 
-    map.distribute
-    (
-        //Pstream::scheduled,
-        //map.schedule            // note reverse schedule
-        //(
-        //    map.constructMap(),
-        //    map.subMap()
-        //),
-        Pstream::nonBlocking,
-        List<labelPair>(0),
-        info.size(),
-        map.constructMap(),     // what to send
-        map.subMap(),           // what to receive
-        region
-    );
+    map.reverseDistribute(info.size(), region);
 }
 
 
@@ -1956,21 +1876,7 @@ void Foam::distributedTriSurfaceMesh::getNormal
     // Send back results
     // ~~~~~~~~~~~~~~~~~
 
-    map.distribute
-    (
-        //Pstream::scheduled,
-        //map.schedule            // note reverse schedule
-        //(
-        //    map.constructMap(),
-        //    map.subMap()
-        //),
-        Pstream::nonBlocking,
-        List<labelPair>(0),
-        info.size(),
-        map.constructMap(),     // what to send
-        map.subMap(),           // what to receive
-        normal
-    );
+    map.reverseDistribute(info.size(), normal);
 }
 
 
@@ -2024,15 +1930,7 @@ void Foam::distributedTriSurfaceMesh::getField
         // Send back results
         // ~~~~~~~~~~~~~~~~~
 
-        map.distribute
-        (
-            Pstream::nonBlocking,
-            List<labelPair>(0),
-            info.size(),
-            map.constructMap(),     // what to send
-            map.subMap(),           // what to receive
-            values
-        );
+        map.reverseDistribute(info.size(), values);
     }
 }
 
diff --git a/src/parallel/distributed/distributedTriSurfaceMesh/distributedTriSurfaceMeshTemplates.C b/src/parallel/distributed/distributedTriSurfaceMesh/distributedTriSurfaceMeshTemplates.C
index dca179bb72d..0871645154a 100644
--- a/src/parallel/distributed/distributedTriSurfaceMesh/distributedTriSurfaceMeshTemplates.C
+++ b/src/parallel/distributed/distributedTriSurfaceMesh/distributedTriSurfaceMeshTemplates.C
@@ -76,15 +76,7 @@ License
 //    // Send back results
 //    // ~~~~~~~~~~~~~~~~~
 //
-//    map.distribute
-//    (
-//        Pstream::nonBlocking,
-//        List<labelPair>(0),
-//        info.size(),
-//        map.constructMap(),     // what to send
-//        map.subMap(),           // what to receive
-//        values
-//    );
+//    map.reverseDistribute(info.size(), values);
 //}
 
 
@@ -115,15 +107,7 @@ void Foam::distributedTriSurfaceMesh::distributeFields
 
         label oldSize = field.size();
 
-        map.distribute
-        (
-            Pstream::nonBlocking,
-            List<labelPair>(0),
-            map.constructSize(),
-            map.subMap(),
-            map.constructMap(),
-            field
-        );
+        map.distribute(field);
 
         if (debug)
         {
diff --git a/src/postProcessing/functionObjects/field/streamLine/streamLine.C b/src/postProcessing/functionObjects/field/streamLine/streamLine.C
index 42b324e8d27..22b50232a6a 100644
--- a/src/postProcessing/functionObjects/field/streamLine/streamLine.C
+++ b/src/postProcessing/functionObjects/field/streamLine/streamLine.C
@@ -426,7 +426,8 @@ void Foam::streamLine::write()
             );
 
 
-            // Distribute the track positions
+            // Distribute the track positions. Note: use scheduled comms
+            // to prevent buffering.
             mapDistribute::distribute
             (
                 Pstream::scheduled,
diff --git a/src/surfaceFilmModels/derivedFvPatchFields/directMappedFixedInternalValue/directMappedFixedInternalValueFvPatchField.C b/src/surfaceFilmModels/derivedFvPatchFields/directMappedFixedInternalValue/directMappedFixedInternalValueFvPatchField.C
index 9c84101d853..c524491307e 100644
--- a/src/surfaceFilmModels/derivedFvPatchFields/directMappedFixedInternalValue/directMappedFixedInternalValueFvPatchField.C
+++ b/src/surfaceFilmModels/derivedFvPatchFields/directMappedFixedInternalValue/directMappedFixedInternalValueFvPatchField.C
@@ -132,15 +132,7 @@ void directMappedFixedInternalValueFvPatchField<Type>::updateCoeffs()
 
     // Retrieve the neighbour patch internal field
     Field<Type> nbrIntFld = nbrField.patchInternalField();
-    mapDistribute::distribute
-    (
-        Pstream::defaultCommsType,
-        distMap.schedule(),
-        distMap.constructSize(),
-        distMap.subMap(),           // what to send
-        distMap.constructMap(),     // what to receive
-        nbrIntFld
-    );
+    distMap.distribute(nbrIntFld);
 
     // Assign (this) patch internal field to its neighbour values
     Field<Type>& intFld = const_cast<Field<Type>&>(this->internalField());
diff --git a/src/turbulenceModels/compressible/turbulenceModel/derivedFvPatchFields/turbulentTemperatureCoupledBaffle/turbulentTemperatureCoupledBaffleFvPatchScalarField.C b/src/turbulenceModels/compressible/turbulenceModel/derivedFvPatchFields/turbulentTemperatureCoupledBaffle/turbulentTemperatureCoupledBaffleFvPatchScalarField.C
index e417067ce12..3d6a68a0f4c 100644
--- a/src/turbulenceModels/compressible/turbulenceModel/derivedFvPatchFields/turbulentTemperatureCoupledBaffle/turbulentTemperatureCoupledBaffleFvPatchScalarField.C
+++ b/src/turbulenceModels/compressible/turbulenceModel/derivedFvPatchFields/turbulentTemperatureCoupledBaffle/turbulentTemperatureCoupledBaffleFvPatchScalarField.C
@@ -222,27 +222,11 @@ void Foam::turbulentTemperatureCoupledBaffleFvPatchScalarField::updateCoeffs()
 
         // Swap to obtain full local values of neighbour internal field
         scalarField nbrIntFld = nbrField.patchInternalField();
-        mapDistribute::distribute
-        (
-            Pstream::defaultCommsType,
-            distMap.schedule(),
-            distMap.constructSize(),
-            distMap.subMap(),           // what to send
-            distMap.constructMap(),     // what to receive
-            nbrIntFld
-        );
+        distMap.distribute(nbrIntFld);
 
         // Swap to obtain full local values of neighbour K*delta
         scalarField nbrKDelta = nbrField.K(nbrField)*nbrPatch.deltaCoeffs();
-        mapDistribute::distribute
-        (
-            Pstream::defaultCommsType,
-            distMap.schedule(),
-            distMap.constructSize(),
-            distMap.subMap(),           // what to send
-            distMap.constructMap(),     // what to receive
-            nbrKDelta
-        );
+        distMap.distribute(nbrKDelta);
 
         tmp<scalarField> myKDelta = K(*this)*patch().deltaCoeffs();
 
@@ -255,15 +239,7 @@ void Foam::turbulentTemperatureCoupledBaffleFvPatchScalarField::updateCoeffs()
         // Assign to me
         fvPatchScalarField::operator=(Twall);
         // Distribute back and assign to neighbour
-        mapDistribute::distribute
-        (
-            Pstream::defaultCommsType,
-            distMap.schedule(),
-            nbrField.size(),
-            distMap.constructMap(),     // reverse : what to send
-            distMap.subMap(),
-            Twall
-        );
+        distMap.reverseDistribute(nbrField.size(), Twall);
         const_cast<turbulentTemperatureCoupledBaffleFvPatchScalarField&>
         (
             nbrField
diff --git a/src/turbulenceModels/compressible/turbulenceModel/derivedFvPatchFields/turbulentTemperatureCoupledBaffleMixed/turbulentTemperatureCoupledBaffleMixedFvPatchScalarField.C b/src/turbulenceModels/compressible/turbulenceModel/derivedFvPatchFields/turbulentTemperatureCoupledBaffleMixed/turbulentTemperatureCoupledBaffleMixedFvPatchScalarField.C
index 2a66378751a..dc62bfd4e64 100644
--- a/src/turbulenceModels/compressible/turbulenceModel/derivedFvPatchFields/turbulentTemperatureCoupledBaffleMixed/turbulentTemperatureCoupledBaffleMixedFvPatchScalarField.C
+++ b/src/turbulenceModels/compressible/turbulenceModel/derivedFvPatchFields/turbulentTemperatureCoupledBaffleMixed/turbulentTemperatureCoupledBaffleMixedFvPatchScalarField.C
@@ -179,27 +179,11 @@ void turbulentTemperatureCoupledBaffleMixedFvPatchScalarField::updateCoeffs()
 
     // Swap to obtain full local values of neighbour internal field
     scalarField nbrIntFld = nbrField.patchInternalField();
-    mapDistribute::distribute
-    (
-        Pstream::defaultCommsType,
-        distMap.schedule(),
-        distMap.constructSize(),
-        distMap.subMap(),           // what to send
-        distMap.constructMap(),     // what to receive
-        nbrIntFld
-    );
+    distMap.distribute(nbrIntFld);
 
     // Swap to obtain full local values of neighbour K*delta
     scalarField nbrKDelta = nbrField.K(nbrField)*nbrPatch.deltaCoeffs();
-    mapDistribute::distribute
-    (
-        Pstream::defaultCommsType,
-        distMap.schedule(),
-        distMap.constructSize(),
-        distMap.subMap(),           // what to send
-        distMap.constructMap(),     // what to receive
-        nbrKDelta
-    );
+    distMap.distribute(nbrKDelta);
 
     tmp<scalarField> myKDelta = K(*this)*patch().deltaCoeffs();
 
-- 
GitLab