From c24035bcf1aef458febe250463a66a7832244aa5 Mon Sep 17 00:00:00 2001
From: andy <andy>
Date: Fri, 12 Apr 2013 16:17:27 +0100
Subject: [PATCH] ENH: Added utility functions

---
 .../AMIInterpolation/AMIInterpolation.C       | 141 ++++++++++++------
 .../AMIInterpolation/AMIInterpolation.H       |  18 ++-
 2 files changed, 107 insertions(+), 52 deletions(-)

diff --git a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolation.C b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolation.C
index 6c268a42293..f37d7ae2bdc 100644
--- a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolation.C
+++ b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolation.C
@@ -28,6 +28,101 @@ License
 #include "meshTools.H"
 #include "mapDistribute.H"
 
+// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
+
+template<class SourcePatch, class TargetPatch>
+Foam::word
+Foam::AMIInterpolation<SourcePatch, TargetPatch>::interpolationMethodToWord
+(
+    const interpolationMethod& im
+)
+{
+    word method = "unknown-interpolationMethod";
+
+    switch (im)
+    {
+        case imDirect:
+        {
+            method = "directAMI";
+            break;
+        }
+        case imMapNearest:
+        {
+            method = "mapNearestAMI";
+            break;
+        }
+        case imFaceAreaWeight:
+        {
+            method = "faceAreaWeightAMI";
+            break;
+        }
+        default:
+        {
+            FatalErrorIn
+            (
+                "const Foam::word"
+                "Foam::AMIInterpolation<SourcePatch, TargetPatch>::"
+                "interpolationMethodToWord"
+                "("
+                    "const interpolationMethod&"
+                ")"
+            )
+                << "Unhandled interpolationMethod enumeration " << method
+                << abort(FatalError);
+        }
+    }
+
+    return method;
+}
+
+
+template<class SourcePatch, class TargetPatch>
+typename Foam::AMIInterpolation<SourcePatch, TargetPatch>::interpolationMethod
+Foam::AMIInterpolation<SourcePatch, TargetPatch>::wordTointerpolationMethod
+(
+    const word& im
+)
+{
+    interpolationMethod method = imDirect;
+
+    wordList methods
+    (
+        IStringStream("(directAMI mapNearestAMI faceAreaWeightAMI)")()
+    );
+
+    if (im == "directAMI")
+    {
+        method = imDirect;
+    }
+    else if (im == "mapNearestAMI")
+    {
+        method = imMapNearest;
+    }
+    else if (im == "faceAreaWeightAMI")
+    {
+        method = imFaceAreaWeight;
+    }
+    else
+    {
+        FatalErrorIn
+        (
+            "Foam::AMIInterpolation<SourcePatch, TargetPatch>::"
+            "interpolationMethod"
+            "Foam::AMIInterpolation<SourcePatch, TargetPatch>::"
+            "wordTointerpolationMethod"
+            "("
+                "const word&"
+            ")"
+        )
+            << "Invalid interpolationMethod " << im
+            << ".  Valid methods are:" << methods
+            << exit(FatalError);
+    }
+
+    return method;
+}
+
+
 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
 
 template<class SourcePatch, class TargetPatch>
@@ -634,52 +729,6 @@ Foam::AMIInterpolation<SourcePatch, TargetPatch>::~AMIInterpolation()
 
 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
 
-template<class SourcePatch, class TargetPatch>
-Foam::word
-Foam::AMIInterpolation<SourcePatch, TargetPatch>::interpolationMethodToWord
-(
-    const interpolationMethod& im
-)
-{
-    word method = "unknown-interpolationMethod";
-
-    switch (im)
-    {
-        case imDirect:
-        {
-            method = "directAMI";
-            break;
-        }
-        case imMapNearest:
-        {
-            method = "mapNearestAMI";
-            break;
-        }
-        case imFaceAreaWeight:
-        {
-            method = "faceAreaWeightAMI";
-            break;
-        }
-        default:
-        {
-            FatalErrorIn
-            (
-                "const Foam::word"
-                "Foam::AMIInterpolation<SourcePatch, TargetPatch>::"
-                "interpolationMethodToWord"
-                "("
-                    "const interpolationMethod&"
-                ") const"
-            )
-                << "Unhandled interpolationMethod enumeration " << method
-                << abort(FatalError);
-        }
-    }
-
-    return method;
-}
-
-
 template<class SourcePatch, class TargetPatch>
 void Foam::AMIInterpolation<SourcePatch, TargetPatch>::update
 (
diff --git a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolation.H b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolation.H
index ffe36dd2ac9..e31eb91e1c6 100644
--- a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolation.H
+++ b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolation.H
@@ -91,6 +91,18 @@ public:
             imFaceAreaWeight
         };
 
+        //- Convert interpolationMethod to word representation
+        static word interpolationMethodToWord
+        (
+            const interpolationMethod& method
+        );
+
+        //- Convert word to interpolationMethod
+        static interpolationMethod wordTointerpolationMethod
+        (
+            const word& method
+        );
+
 
 private:
 
@@ -301,12 +313,6 @@ public:
             //  the AMI
             label singlePatchProc() const;
 
-            //- Convert interpolationMethod to word representation
-            static word interpolationMethodToWord
-            (
-                const interpolationMethod& method
-            );
-
 
             // Source patch
 
-- 
GitLab