From 6ca17d929df0508ced086e0c38d8953901daf6ea Mon Sep 17 00:00:00 2001
From: andy <a.heather@opencfd.co.uk>
Date: Wed, 28 Oct 2009 15:15:53 +0000
Subject: [PATCH] updates for parallel running

---
 .../PatchInjection/PatchInjection.C           | 22 ++++++++++++++-----
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/src/lagrangian/intermediate/submodels/Kinematic/InjectionModel/PatchInjection/PatchInjection.C b/src/lagrangian/intermediate/submodels/Kinematic/InjectionModel/PatchInjection/PatchInjection.C
index b79a8a1af10..4e88b90bfeb 100644
--- a/src/lagrangian/intermediate/submodels/Kinematic/InjectionModel/PatchInjection/PatchInjection.C
+++ b/src/lagrangian/intermediate/submodels/Kinematic/InjectionModel/PatchInjection/PatchInjection.C
@@ -124,11 +124,12 @@ Foam::PatchInjection<CloudType>::PatchInjection
 
     label patchSize = cellOwners_.size();
     label totalPatchSize = patchSize;
-    reduce(totalPatchSize, sumOp<scalar>());
-    fraction_ = patchSize/totalPatchSize;
+    reduce(totalPatchSize, sumOp<label>());
+    fraction_ = scalar(patchSize)/totalPatchSize;
 
-    // Set total volume to inject
+    // Set total volume/mass to inject
     this->volumeTotal_ = fraction_*volumeFlowRate_().integrate(0.0, duration_);
+    this->massTotal_ *= fraction_;
 }
 
 
@@ -165,10 +166,19 @@ void Foam::PatchInjection<CloudType>::setPositionAndCell
     label& cellOwner
 )
 {
-    label cellI = this->owner().rndGen().integer(0, cellOwners_.size() - 1);
+    if (cellOwners_.size() > 0)
+    {
+        label cellI = this->owner().rndGen().integer(0, cellOwners_.size() - 1);
 
-    cellOwner = cellOwners_[cellI];
-    position = this->owner().mesh().C()[cellOwner];
+        cellOwner = cellOwners_[cellI];
+        position = this->owner().mesh().C()[cellOwner];
+    }
+    else
+    {
+        cellOwner = -1;
+        // dummy position
+        position = pTraits<vector>::max;
+    }
 }
 
 
-- 
GitLab