From c88070040ee806bbe6b296073b280b656032ba1e Mon Sep 17 00:00:00 2001
From: Henry Weller <http://cfd.direct>
Date: Tue, 7 Jun 2016 10:56:33 +0100
Subject: [PATCH] PatchFlowRateInjection: Corrected parallel handling of the
 random position Resolves bug-report http://bugs.openfoam.org/view.php?id=2111

---
 .../PatchFlowRateInjection/PatchFlowRateInjection.C      | 9 ++++++---
 .../InjectionModel/PatchInjection/patchInjectionBase.C   | 9 +--------
 2 files changed, 7 insertions(+), 11 deletions(-)

diff --git a/src/lagrangian/intermediate/submodels/Kinematic/InjectionModel/PatchFlowRateInjection/PatchFlowRateInjection.C b/src/lagrangian/intermediate/submodels/Kinematic/InjectionModel/PatchFlowRateInjection/PatchFlowRateInjection.C
index 81be9ea9cef..4703885b37a 100644
--- a/src/lagrangian/intermediate/submodels/Kinematic/InjectionModel/PatchFlowRateInjection/PatchFlowRateInjection.C
+++ b/src/lagrangian/intermediate/submodels/Kinematic/InjectionModel/PatchFlowRateInjection/PatchFlowRateInjection.C
@@ -161,6 +161,9 @@ Foam::label Foam::PatchFlowRateInjection<CloudType>::parcelsToInject
         scalar c = concentration_.value(0.5*(time0 + time1));
 
         scalar nParcels = parcelConcentration_*c*flowRate()*dt;
+
+        cachedRandom& rnd = this->owner().rndGen();
+
         label nParcelsToInject = floor(nParcels);
 
         // Inject an additional parcel with a probability based on the
@@ -170,7 +173,7 @@ Foam::label Foam::PatchFlowRateInjection<CloudType>::parcelsToInject
             nParcelsToInject > 0
          && (
                nParcels - scalar(nParcelsToInject)
-             > this->owner().rndGen().position(scalar(0), scalar(1))
+             > rnd.globalPosition(scalar(0), scalar(1))
             )
         )
         {
@@ -242,10 +245,10 @@ void Foam::PatchFlowRateInjection<CloudType>::setProperties
     typename CloudType::parcelType& parcel
 )
 {
-    // set particle velocity to carrier velocity
+    // Set particle velocity to carrier velocity
     parcel.U() = this->owner().U()[parcel.cell()];
 
-    // set particle diameter
+    // Set particle diameter
     parcel.d() = sizeDistribution_->sample();
 }
 
diff --git a/src/lagrangian/intermediate/submodels/Kinematic/InjectionModel/PatchInjection/patchInjectionBase.C b/src/lagrangian/intermediate/submodels/Kinematic/InjectionModel/PatchInjection/patchInjectionBase.C
index 82d56739dc1..a83812ab010 100644
--- a/src/lagrangian/intermediate/submodels/Kinematic/InjectionModel/PatchInjection/patchInjectionBase.C
+++ b/src/lagrangian/intermediate/submodels/Kinematic/InjectionModel/PatchInjection/patchInjectionBase.C
@@ -156,14 +156,7 @@ void Foam::patchInjectionBase::setPositionAndCell
     label& tetPtI
 )
 {
-    scalar areaFraction = 0;
-
-    if (Pstream::master())
-    {
-        areaFraction = rnd.position<scalar>(0, patchArea_);
-    }
-
-    Pstream::scatter(areaFraction);
+    scalar areaFraction = rnd.globalPosition(scalar(0), patchArea_);
 
     if (cellOwners_.size() > 0)
     {
-- 
GitLab