From 3d695a48da9877c8f351b1c4ee4bbd5929589f22 Mon Sep 17 00:00:00 2001
From: Henry <Henry>
Date: Mon, 9 Mar 2015 10:40:51 +0000
Subject: [PATCH] functionObjects/forces: limit the bins to handle moving
 meshes This approach simply accumulates data outside the range of the bins
 into the first or last bin which may be OK for small motions.  For larger
 motions it may be better if the bins are updated or operate in a coordinate
 system attached to the body for solid-body motion. Resolves bug-report
 http://www.openfoam.org/mantisbt/view.php?id=1560

---
 .../functionObjects/forces/forces/forces.C        | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/src/postProcessing/functionObjects/forces/forces/forces.C b/src/postProcessing/functionObjects/forces/forces/forces.C
index fa8cfdcfc6b..1794a8b8898 100644
--- a/src/postProcessing/functionObjects/forces/forces/forces.C
+++ b/src/postProcessing/functionObjects/forces/forces/forces.C
@@ -375,13 +375,14 @@ void Foam::forces::applyBins
 
         forAll(dd, i)
         {
-            label binI = floor(dd[i]/binDx_);
-            force_[0][binI] += fN[i];
-            force_[1][binI] += fT[i];
-            force_[2][binI] += fP[i];
-            moment_[0][binI] += Md[i]^fN[i];
-            moment_[1][binI] += Md[i]^fT[i];
-            moment_[2][binI] += Md[i]^fP[i];
+            label bini = min(max(floor(dd[i]/binDx_), 0), force_[0].size());
+
+            force_[0][bini] += fN[i];
+            force_[1][bini] += fT[i];
+            force_[2][bini] += fP[i];
+            moment_[0][bini] += Md[i]^fN[i];
+            moment_[1][bini] += Md[i]^fT[i];
+            moment_[2][bini] += Md[i]^fP[i];
         }
     }
 }
-- 
GitLab