From 0048b05fdf6fb60e3b2f900baf452774cda38037 Mon Sep 17 00:00:00 2001
From: mattijs <mattijs>
Date: Tue, 30 Oct 2018 15:13:23 +0000
Subject: [PATCH] ENH: PatchFunction1: backwards compatibility. See #1046.

---
 .../functions/Function1/Function1/Function1.H |  5 ++-
 .../Function1/Function1/Function1New.C        | 45 +++++++++++++------
 .../ConstantField/ConstantField.C             |  1 +
 .../ConstantField/ConstantField.H             |  1 +
 .../PatchFunction1/MappedFile/MappedFile.C    |  1 +
 .../PatchFunction1/MappedFile/MappedFile.H    |  1 +
 src/meshTools/PatchFunction1/PatchFunction1.H |  3 +-
 .../PatchFunction1/PatchFunction1New.C        |  6 ++-
 .../UniformValueField/UniformValueField.C     | 11 ++++-
 .../UniformValueField/UniformValueField.H     | 10 +----
 10 files changed, 56 insertions(+), 28 deletions(-)

diff --git a/src/OpenFOAM/primitives/functions/Function1/Function1/Function1.H b/src/OpenFOAM/primitives/functions/Function1/Function1/Function1.H
index 0784f12e17f..8ee8078d893 100644
--- a/src/OpenFOAM/primitives/functions/Function1/Function1/Function1.H
+++ b/src/OpenFOAM/primitives/functions/Function1/Function1/Function1.H
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2017 OpenFOAM Foundation
-     \\/     M anipulation  |
+     \\/     M anipulation  | Copyright (C) 2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -114,7 +114,8 @@ public:
     static autoPtr<Function1<Type>> New
     (
         const word& entryName,
-        const dictionary& dict
+        const dictionary& dict,
+        const word& redirectType = word::null
     );
 
 
diff --git a/src/OpenFOAM/primitives/functions/Function1/Function1/Function1New.C b/src/OpenFOAM/primitives/functions/Function1/Function1/Function1New.C
index 24adbadf994..bb537720c2f 100644
--- a/src/OpenFOAM/primitives/functions/Function1/Function1/Function1New.C
+++ b/src/OpenFOAM/primitives/functions/Function1/Function1/Function1New.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2017 OpenFOAM Foundation
-     \\/     M anipulation  |
+     \\/     M anipulation  | Copyright (C) 2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -31,14 +31,20 @@ template<class Type>
 Foam::autoPtr<Foam::Function1<Type>> Foam::Function1<Type>::New
 (
     const word& entryName,
-    const dictionary& dict
+    const dictionary& dict,
+    const word& redirectType
 )
 {
     if (dict.isDict(entryName))
     {
         const dictionary& coeffsDict(dict.subDict(entryName));
 
-        const word Function1Type(coeffsDict.get<word>("type"));
+        const word Function1Type
+        (
+            redirectType.empty()
+          ? coeffsDict.get<word>("type")
+          : coeffsDict.lookupOrDefault<word>("type", redirectType)
+        );
 
         auto cstrIter = dictionaryConstructorTablePtr_->cfind(Function1Type);
 
@@ -57,24 +63,37 @@ Foam::autoPtr<Foam::Function1<Type>> Foam::Function1<Type>::New
     }
     else
     {
-        Istream& is = dict.lookup(entryName, keyType::REGEX);
+        const dictionary::const_searcher finder
+        (
+            dict.csearch(entryName, keyType::REGEX)
+        );
 
-        token firstToken(is);
         word Function1Type;
-
-        if (!firstToken.isWord())
+        if (finder.found())
         {
-            is.putBack(firstToken);
-            return autoPtr<Function1<Type>>
-            (
-                new Function1Types::Constant<Type>(entryName, is)
-            );
+            Istream& is = finder.ref().stream();
+
+            token firstToken(is);
+
+            if (!firstToken.isWord())
+            {
+                is.putBack(firstToken);
+                return autoPtr<Function1<Type>>
+                (
+                    new Function1Types::Constant<Type>(entryName, is)
+                );
+            }
+            else
+            {
+                Function1Type = firstToken.wordToken();
+            }
         }
         else
         {
-            Function1Type = firstToken.wordToken();
+            Function1Type = redirectType;
         }
 
+
         auto cstrIter = dictionaryConstructorTablePtr_->cfind(Function1Type);
 
         if (!cstrIter.found())
diff --git a/src/meshTools/PatchFunction1/ConstantField/ConstantField.C b/src/meshTools/PatchFunction1/ConstantField/ConstantField.C
index ee0a20229da..2755e472c32 100644
--- a/src/meshTools/PatchFunction1/ConstantField/ConstantField.C
+++ b/src/meshTools/PatchFunction1/ConstantField/ConstantField.C
@@ -127,6 +127,7 @@ template<class Type>
 Foam::PatchFunction1Types::ConstantField<Type>::ConstantField
 (
     const polyPatch& pp,
+    const word& type,
     const word& entryName,
     const dictionary& dict,
     const bool faceValues
diff --git a/src/meshTools/PatchFunction1/ConstantField/ConstantField.H b/src/meshTools/PatchFunction1/ConstantField/ConstantField.H
index c9eeea67f86..307a49c4acb 100644
--- a/src/meshTools/PatchFunction1/ConstantField/ConstantField.H
+++ b/src/meshTools/PatchFunction1/ConstantField/ConstantField.H
@@ -100,6 +100,7 @@ public:
         ConstantField
         (
             const polyPatch& pp,
+            const word& type,
             const word& entryName,
             const dictionary& dict,
             const bool faceValues = true
diff --git a/src/meshTools/PatchFunction1/MappedFile/MappedFile.C b/src/meshTools/PatchFunction1/MappedFile/MappedFile.C
index a13da99ab13..6a283a329e7 100644
--- a/src/meshTools/PatchFunction1/MappedFile/MappedFile.C
+++ b/src/meshTools/PatchFunction1/MappedFile/MappedFile.C
@@ -33,6 +33,7 @@ template<class Type>
 Foam::PatchFunction1Types::MappedFile<Type>::MappedFile
 (
     const polyPatch& pp,
+    const word& type,
     const word& entryName,
     const dictionary& dict,
     const bool faceValues
diff --git a/src/meshTools/PatchFunction1/MappedFile/MappedFile.H b/src/meshTools/PatchFunction1/MappedFile/MappedFile.H
index 89840c2a63d..60bdb325b58 100644
--- a/src/meshTools/PatchFunction1/MappedFile/MappedFile.H
+++ b/src/meshTools/PatchFunction1/MappedFile/MappedFile.H
@@ -122,6 +122,7 @@ public:
         MappedFile
         (
             const polyPatch& pp,
+            const word& type,
             const word& entryName,
             const dictionary& dict,
             const bool faceValues = true
diff --git a/src/meshTools/PatchFunction1/PatchFunction1.H b/src/meshTools/PatchFunction1/PatchFunction1.H
index a1cfaa79019..e6713a3023b 100644
--- a/src/meshTools/PatchFunction1/PatchFunction1.H
+++ b/src/meshTools/PatchFunction1/PatchFunction1.H
@@ -115,11 +115,12 @@ public:
         dictionary,
         (
             const polyPatch& pp,
+            const word& type,
             const word& entryName,
             const dictionary& dict,
             const bool faceValues
         ),
-        (pp, entryName, dict, faceValues)
+        (pp, type, entryName, dict, faceValues)
     );
 
 
diff --git a/src/meshTools/PatchFunction1/PatchFunction1New.C b/src/meshTools/PatchFunction1/PatchFunction1New.C
index a77f23b1c2a..ce379527ebc 100644
--- a/src/meshTools/PatchFunction1/PatchFunction1New.C
+++ b/src/meshTools/PatchFunction1/PatchFunction1New.C
@@ -55,7 +55,7 @@ Foam::autoPtr<Foam::PatchFunction1<Type>> Foam::PatchFunction1<Type>::New
                 << exit(FatalIOError);
         }
 
-        return cstrIter()(pp, entryName, coeffsDict, faceValues);
+        return cstrIter()(pp, modelType, entryName, coeffsDict, faceValues);
     }
     else
     {
@@ -75,7 +75,7 @@ Foam::autoPtr<Foam::PatchFunction1<Type>> Foam::PatchFunction1<Type>::New
                 (
                     pp,
                     entryName,
-                    value,
+                    value,          // Supply value
                     dict,
                     faceValues
                 )
@@ -92,6 +92,7 @@ Foam::autoPtr<Foam::PatchFunction1<Type>> Foam::PatchFunction1<Type>::New
                 new PatchFunction1Types::ConstantField<Type>
                 (
                     pp,
+                    PatchFunction1Types::ConstantField<Type>::typeName,
                     entryName,
                     dict
                 )
@@ -114,6 +115,7 @@ Foam::autoPtr<Foam::PatchFunction1<Type>> Foam::PatchFunction1<Type>::New
         return cstrIter()
         (
             pp,
+            modelType,
             entryName,
             dict.found(entryName + "Coeffs")
           ? dict.subDict(entryName + "Coeffs")
diff --git a/src/meshTools/PatchFunction1/UniformValueField/UniformValueField.C b/src/meshTools/PatchFunction1/UniformValueField/UniformValueField.C
index fa7161f35ce..cbeebbc8315 100644
--- a/src/meshTools/PatchFunction1/UniformValueField/UniformValueField.C
+++ b/src/meshTools/PatchFunction1/UniformValueField/UniformValueField.C
@@ -32,13 +32,22 @@ template<class Type>
 Foam::PatchFunction1Types::UniformValueField<Type>::UniformValueField
 (
     const polyPatch& pp,
+    const word& type,
     const word& entryName,
     const dictionary& dict,
     const bool faceValues
 )
 :
     PatchFunction1<Type>(pp, entryName, dict, faceValues),
-    uniformValuePtr_(Function1<Type>::New(entryName, dict))
+    uniformValuePtr_
+    (
+        Function1<Type>::New
+        (
+            entryName,
+            dict,
+            type
+        )
+    )
 {}
 
 
diff --git a/src/meshTools/PatchFunction1/UniformValueField/UniformValueField.H b/src/meshTools/PatchFunction1/UniformValueField/UniformValueField.H
index 4b021d61d95..683ff0c5607 100644
--- a/src/meshTools/PatchFunction1/UniformValueField/UniformValueField.H
+++ b/src/meshTools/PatchFunction1/UniformValueField/UniformValueField.H
@@ -80,19 +80,11 @@ public:
 
     // Constructors
 
-//        //- Construct from components
-//        UniformValueField
-//        (
-//            const polyPatch& pp,
-//            const word& entryName,
-//            const Field<Type>& value,
-//            const bool faceValues = true
-//        );
-
         //- Construct from entry name and dictionary
         UniformValueField
         (
             const polyPatch& pp,
+            const word& type,
             const word& entryName,
             const dictionary& dict,
             const bool faceValues = true
-- 
GitLab