From bb81cc9f07a2066192f0516cac124735baa50d40 Mon Sep 17 00:00:00 2001
From: mattijs <mattijs>
Date: Mon, 13 Dec 2010 16:08:25 +0000
Subject: [PATCH] BUG: interpolationTable : allow for min != 0

---
 .../interpolationTable/interpolationTable.C   | 26 +++++++------------
 1 file changed, 9 insertions(+), 17 deletions(-)

diff --git a/src/OpenFOAM/interpolations/interpolationTable/interpolationTable.C b/src/OpenFOAM/interpolations/interpolationTable/interpolationTable.C
index 6699b6349b7..be8a2b71ba5 100644
--- a/src/OpenFOAM/interpolations/interpolationTable/interpolationTable.C
+++ b/src/OpenFOAM/interpolations/interpolationTable/interpolationTable.C
@@ -284,10 +284,8 @@ Type Foam::interpolationTable<Type>::rateOfChange(const scalar value) const
             case interpolationTable::REPEAT:
             {
                 // adjust lookupValue to >= minLimit
-                while (lookupValue < minLimit)
-                {
-                    lookupValue += maxLimit;
-                }
+                scalar span = maxLimit-minLimit;
+                lookupValue = fmod(lookupValue-minLimit, span) + minLimit;
                 break;
             }
         }
@@ -325,10 +323,8 @@ Type Foam::interpolationTable<Type>::rateOfChange(const scalar value) const
             case interpolationTable::REPEAT:
             {
                 // adjust lookupValue <= maxLimit
-                while (lookupValue > maxLimit)
-                {
-                    lookupValue -= maxLimit;
-                }
+                scalar span = maxLimit-minLimit;
+                lookupValue = fmod(lookupValue-minLimit, span) + minLimit;
                 break;
             }
         }
@@ -540,11 +536,9 @@ Type Foam::interpolationTable<Type>::operator()(const scalar value) const
             }
             case interpolationTable::REPEAT:
             {
-                // adjust lookupValue to >= minLimin
-                while (lookupValue < minLimit)
-                {
-                    lookupValue += maxLimit;
-                }
+                // adjust lookupValue to >= minLimit
+                scalar span = maxLimit-minLimit;
+                lookupValue = fmod(lookupValue-minLimit, span) + minLimit;
                 break;
             }
         }
@@ -582,10 +576,8 @@ Type Foam::interpolationTable<Type>::operator()(const scalar value) const
             case interpolationTable::REPEAT:
             {
                 // adjust lookupValue <= maxLimit
-                while (lookupValue > maxLimit)
-                {
-                    lookupValue -= maxLimit;
-                }
+                scalar span = maxLimit-minLimit;
+                lookupValue = fmod(lookupValue-minLimit, span) + minLimit;
                 break;
             }
         }
-- 
GitLab