From 9a5125111e96097a6947081fb66565c12ce59c25 Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@esi-group.com>
Date: Fri, 3 Dec 2021 15:33:07 +0100
Subject: [PATCH] ENH: add coded Function1 (#2282)

- update coded templates with qualified names

GIT: add in missing PatchFunction1 constant() method

- was missed in a previous commit
---
 .../dynamicCode/codedFunction1Template.C      | 121 +++++++++
 .../dynamicCode/codedFunction1Template.H      | 119 +++++++++
 .../dynamicCode/codedFvOptionTemplate.C       |  14 +-
 .../dynamicCode/codedFvOptionTemplate.H       |   2 +-
 .../dynamicCode/codedPatchFunction1Template.C |  16 +-
 .../dynamicCode/codedPatchFunction1Template.H |  13 +-
 .../codedPoints0MotionSolverTemplate.C        |  17 +-
 .../codedPoints0MotionSolverTemplate.H        |   2 +-
 .../fixedValueFvPatchFieldTemplate.C          |  13 +-
 .../fixedValueFvPatchFieldTemplate.H          |   2 +-
 .../fixedValuePointPatchFieldTemplate.C       |  13 +-
 .../fixedValuePointPatchFieldTemplate.H       |   2 +-
 .../dynamicCode/functionObjectTemplate.C      |  21 +-
 .../dynamicCode/functionObjectTemplate.H      |   6 +-
 .../dynamicCode/mixedFvPatchFieldTemplate.C   |  13 +-
 .../dynamicCode/mixedFvPatchFieldTemplate.H   |   2 +-
 .../codedFixedValuePointPatchField.C          |  12 +-
 .../Function1/Coded/CodedFunction1.C          | 247 ++++++++++++++++++
 .../Function1/Coded/CodedFunction1.H          | 225 ++++++++++++++++
 .../FunctionObjectTrigger.C                   |   2 +-
 .../functions/Function1/makeFunction1s.C      |   2 +
 .../codedFixedValueFvPatchField.C             |  12 +-
 .../codedMixed/codedMixedFvPatchField.C       |  10 +-
 .../PatchFunction1/CodedField/CodedField.C    |  32 +--
 .../PatchFunction1/CodedField/CodedField.H    |  18 +-
 .../PatchFunction1/PatchFunction1.H           |  13 +-
 .../rhoSimpleFoam/squareBendLiq/0.orig/T      |  10 +
 .../rhoSimpleFoam/squareBendLiq/0.orig/U      |  20 +-
 .../rhoSimpleFoam/squareBendLiq/Allrun        |   6 +
 .../rhoSimpleFoam/squareBendLiq/Allrun-seq    |   6 +
 .../MPPICInterFoam/twoPhasePachuka/0.orig/U   |   4 +-
 31 files changed, 883 insertions(+), 112 deletions(-)
 create mode 100644 etc/codeTemplates/dynamicCode/codedFunction1Template.C
 create mode 100644 etc/codeTemplates/dynamicCode/codedFunction1Template.H
 create mode 100644 src/OpenFOAM/primitives/functions/Function1/Coded/CodedFunction1.C
 create mode 100644 src/OpenFOAM/primitives/functions/Function1/Coded/CodedFunction1.H

diff --git a/etc/codeTemplates/dynamicCode/codedFunction1Template.C b/etc/codeTemplates/dynamicCode/codedFunction1Template.C
new file mode 100644
index 00000000000..ebdf9765561
--- /dev/null
+++ b/etc/codeTemplates/dynamicCode/codedFunction1Template.C
@@ -0,0 +1,121 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | www.openfoam.com
+     \\/     M anipulation  |
+-------------------------------------------------------------------------------
+    Copyright (C) 2021 OpenCFD Ltd.
+    Copyright (C) YEAR AUTHOR,AFFILIATION
+-------------------------------------------------------------------------------
+License
+    This file is part of OpenFOAM.
+
+    OpenFOAM is free software: you can redistribute it and/or modify it
+    under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
+    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+    for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
+
+\*---------------------------------------------------------------------------*/
+
+#include "codedFunction1Template.H"
+#include "addToRunTimeSelectionTable.H"
+#include "unitConversion.H"
+
+//{{{ begin codeInclude
+${codeInclude}
+//}}} end codeInclude
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+namespace Foam
+{
+
+// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
+
+//{{{ begin localCode
+${localCode}
+//}}} end localCode
+
+// * * * * * * * * * * * * * * * Global Functions  * * * * * * * * * * * * * //
+
+// dynamicCode:
+// SHA1 = ${SHA1sum}
+//
+// unique function name that can be checked if the correct library version
+// has been loaded
+extern "C" void ${typeName}_${SHA1sum}(bool load)
+{
+    if (load)
+    {
+        // Code that can be explicitly executed after loading
+    }
+    else
+    {
+        // Code that can be explicitly executed before unloading
+    }
+}
+
+
+namespace Function1Types
+{
+
+// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
+
+//makeFunction1(${typeName}Function1, ${TemplateType});
+defineTypeNameAndDebug
+(
+    ${typeName}Function1_${TemplateType},
+    0
+);
+Function1<${TemplateType}>::addRemovabledictionaryConstructorToTable
+    <${typeName}Function1_${TemplateType}>
+    addRemovable${typeName}Function1_${TemplateType}ConstructorToTable_;
+
+} // namespace Function1Types
+} // namespace Foam
+
+
+// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
+
+Foam::Function1Types::
+${typeName}Function1_${TemplateType}::
+${typeName}Function1_${TemplateType}
+(
+    const word& entryName,
+    const dictionary& dict,
+    const objectRegistry* obrPtr
+)
+:
+    Function1<${TemplateType}>(entryName, dict, obrPtr)
+{
+    if (${verbose:-false})
+    {
+        printMessage("Construct ${typeName} Function1 from dictionary");
+    }
+}
+
+
+// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
+
+Foam::${TemplateType}
+Foam::Function1Types::${typeName}Function1_${TemplateType}::value
+(
+    const scalar x
+) const
+{
+//{{{ begin code
+    ${code}
+//}}} end code
+}
+
+
+// ************************************************************************* //
diff --git a/etc/codeTemplates/dynamicCode/codedFunction1Template.H b/etc/codeTemplates/dynamicCode/codedFunction1Template.H
new file mode 100644
index 00000000000..3b2de974a93
--- /dev/null
+++ b/etc/codeTemplates/dynamicCode/codedFunction1Template.H
@@ -0,0 +1,119 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | www.openfoam.com
+     \\/     M anipulation  |
+-------------------------------------------------------------------------------
+    Copyright (C) 2021 OpenCFD Ltd.
+-------------------------------------------------------------------------------
+License
+    This file is part of OpenFOAM.
+
+    OpenFOAM is free software: you can redistribute it and/or modify it
+    under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
+    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+    for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
+
+Description
+    Template for use with dynamic code generation of a Function1
+
+SourceFiles
+    codedFunction1Template.C
+
+\*---------------------------------------------------------------------------*/
+
+#ifndef dynamicCode_codedFunction1_${typeName}_${TemplateType}_H
+#define dynamicCode_codedFunction1_${typeName}_${TemplateType}_H
+
+#include "Function1.H"
+#include "dictionaryContent.H"
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+namespace Foam
+{
+namespace Function1Types
+{
+
+/*---------------------------------------------------------------------------*\
+                           A coded version Function1
+\*---------------------------------------------------------------------------*/
+
+class ${typeName}Function1_${TemplateType}
+:
+    public Function1<${TemplateType}>,
+    public dictionaryContent
+{
+    // Private Member Functions
+
+        //- Report a message with the SHA1sum
+        inline static void printMessage(const char* message)
+        {
+            Info<< message << " sha1: " << SHA1sum << '\n';
+        }
+
+public:
+
+    //- SHA1 representation of the code content
+    static constexpr const char* const SHA1sum = "${SHA1sum}";
+
+    //- Runtime type information
+    TypeName("${typeName}");
+
+
+    // Constructors
+
+        //- Construct from entry name, dictionary and registry
+        ${typeName}Function1_${TemplateType}
+        (
+            const word& entryName,
+            const dictionary& dict,
+            const objectRegistry* obrPtr = nullptr
+        );
+
+        //- Copy construct
+        ${typeName}Function1_${TemplateType}
+        (
+            const ${typeName}Function1_${TemplateType}& rhs
+        ) = default;
+
+        //- Construct and return a clone
+        virtual tmp<Function1<${TemplateType}>> clone() const
+        {
+            return tmp<Function1<${TemplateType}>>
+            (
+                new ${typeName}Function1_${TemplateType}(*this)
+            );
+        }
+
+
+    //- Destructor
+    virtual ~${typeName}Function1_${TemplateType}() = default;
+
+
+    // Member Functions
+
+        //- Return value as a function of (scalar) independent variable
+        virtual ${TemplateType} value(const scalar x) const;
+};
+
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+} // End namespace Function1Types
+} // End namespace Foam
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+#endif
+
+// ************************************************************************* //
diff --git a/etc/codeTemplates/dynamicCode/codedFvOptionTemplate.C b/etc/codeTemplates/dynamicCode/codedFvOptionTemplate.C
index aad851509e8..0e8a9cb9aad 100644
--- a/etc/codeTemplates/dynamicCode/codedFvOptionTemplate.C
+++ b/etc/codeTemplates/dynamicCode/codedFvOptionTemplate.C
@@ -83,9 +83,13 @@ addRemovableToRunTimeSelectionTable
     dictionary
 );
 
+} // End namespace fv
+} // End namespace Foam
+
 
 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
 
+Foam::fv::
 ${typeName}FvOption${SourceType}::
 ${typeName}FvOption${SourceType}
 (
@@ -106,6 +110,7 @@ ${typeName}FvOption${SourceType}
 
 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
 
+Foam::fv::
 ${typeName}FvOption${SourceType}::
 ~${typeName}FvOption${SourceType}()
 {
@@ -119,6 +124,7 @@ ${typeName}FvOption${SourceType}::
 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
 
 void
+Foam::fv::
 ${typeName}FvOption${SourceType}::correct
 (
     GeometricField<${TemplateType}, fvPatchField, volMesh>& fld
@@ -136,6 +142,7 @@ ${typeName}FvOption${SourceType}::correct
 
 
 void
+Foam::fv::
 ${typeName}FvOption${SourceType}::addSup
 (
     fvMatrix<${TemplateType}>& eqn,
@@ -154,6 +161,7 @@ ${typeName}FvOption${SourceType}::addSup
 
 
 void
+Foam::fv::
 ${typeName}FvOption${SourceType}::addSup
 (
     const volScalarField& rho,
@@ -173,6 +181,7 @@ ${typeName}FvOption${SourceType}::addSup
 
 
 void
+Foam::fv::
 ${typeName}FvOption${SourceType}::constrain
 (
     fvMatrix<${TemplateType}>& eqn,
@@ -190,9 +199,4 @@ ${typeName}FvOption${SourceType}::constrain
 }
 
 
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
-
-} // End namespace fv
-} // End namespace Foam
-
 // ************************************************************************* //
diff --git a/etc/codeTemplates/dynamicCode/codedFvOptionTemplate.H b/etc/codeTemplates/dynamicCode/codedFvOptionTemplate.H
index b38b4e92f60..199c07243bc 100644
--- a/etc/codeTemplates/dynamicCode/codedFvOptionTemplate.H
+++ b/etc/codeTemplates/dynamicCode/codedFvOptionTemplate.H
@@ -163,7 +163,7 @@ public:
     // Member Functions
 
         //- Code context as a dictionary
-        const dictionary& codeContext() const
+        const dictionary& codeContext() const noexcept
         {
             return dictionaryContent::dict();
         }
diff --git a/etc/codeTemplates/dynamicCode/codedPatchFunction1Template.C b/etc/codeTemplates/dynamicCode/codedPatchFunction1Template.C
index ffce21acf36..79a06ac799e 100644
--- a/etc/codeTemplates/dynamicCode/codedPatchFunction1Template.C
+++ b/etc/codeTemplates/dynamicCode/codedPatchFunction1Template.C
@@ -80,14 +80,17 @@ defineTypeNameAndDebug
     ${typeName}PatchFunction1${FieldType},
     0
 );
-PatchFunction1<${TemplateType}>::adddictionaryConstructorToTable
+PatchFunction1<${TemplateType}>::addRemovabledictionaryConstructorToTable
     <${typeName}PatchFunction1${FieldType}>
-    add${typeName}PatchFunction1${FieldType}ConstructorToTable_;
+    addRemovable${typeName}PatchFunction1${FieldType}ConstructorToTable_;
 
+} // namespace PatchFunction1Types
+} // namespace Foam
 
 
 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
 
+Foam::PatchFunction1Types::
 ${typeName}PatchFunction1${FieldType}::
 ${typeName}PatchFunction1${FieldType}
 (
@@ -107,6 +110,7 @@ ${typeName}PatchFunction1${FieldType}
 }
 
 
+Foam::PatchFunction1Types::
 ${typeName}PatchFunction1${FieldType}::
 ${typeName}PatchFunction1${FieldType}
 (
@@ -121,7 +125,7 @@ ${typeName}PatchFunction1${FieldType}
 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
 
 Foam::tmp<Foam::Field<Foam::${TemplateType}>>
-${typeName}PatchFunction1${FieldType}::value
+Foam::PatchFunction1Types::${typeName}PatchFunction1${FieldType}::value
 (
     const scalar x
 ) const
@@ -132,10 +136,4 @@ ${typeName}PatchFunction1${FieldType}::value
 }
 
 
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
-
-} // End namespace PatchFunction1Types
-} // End namespace Foam
-
-
 // ************************************************************************* //
diff --git a/etc/codeTemplates/dynamicCode/codedPatchFunction1Template.H b/etc/codeTemplates/dynamicCode/codedPatchFunction1Template.H
index 46d7d08086b..c67d1600127 100644
--- a/etc/codeTemplates/dynamicCode/codedPatchFunction1Template.H
+++ b/etc/codeTemplates/dynamicCode/codedPatchFunction1Template.H
@@ -31,8 +31,8 @@ SourceFiles
 
 \*---------------------------------------------------------------------------*/
 
-#ifndef codedPatchFunction1Template${FieldType}_H
-#define codedPatchFunction1Template${FieldType}_H
+#ifndef dynamicCode_codedPatchFunction1_${typeName}_${FieldType}_H
+#define dynamicCode_codedPatchFunction1_${typeName}_${FieldType}_H
 
 #include "PatchFunction1.H"
 #include "dictionaryContent.H"
@@ -126,14 +126,11 @@ public:
 
     // Member Functions
 
+        //- Is value uniform (i.e. independent of coordinate)
+        virtual bool uniform() const { return false; }
+
         //- Return value as a function of (scalar) independent variable
         virtual tmp<Field<${TemplateType}>> value(const scalar x) const;
-
-        //- Is value uniform (i.e. independent of coordinate)
-        virtual bool uniform() const
-        {
-            return false;
-        }
 };
 
 
diff --git a/etc/codeTemplates/dynamicCode/codedPoints0MotionSolverTemplate.C b/etc/codeTemplates/dynamicCode/codedPoints0MotionSolverTemplate.C
index d38ef18c97e..4ce7a79d083 100644
--- a/etc/codeTemplates/dynamicCode/codedPoints0MotionSolverTemplate.C
+++ b/etc/codeTemplates/dynamicCode/codedPoints0MotionSolverTemplate.C
@@ -75,10 +75,14 @@ extern "C" void ${typeName}_${SHA1sum}(bool load)
 ${localCode}
 //}}} end localCode
 
+} // End namespace Foam
+
 
 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
 
-${typeName}Points0MotionSolver::${typeName}Points0MotionSolver
+Foam::
+${typeName}Points0MotionSolver::
+${typeName}Points0MotionSolver
 (
     const polyMesh& mesh,
     const IOdictionary& dict
@@ -90,13 +94,16 @@ ${typeName}Points0MotionSolver::${typeName}Points0MotionSolver
 
 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
 
-${typeName}Points0MotionSolver::~${typeName}Points0MotionSolver()
+Foam::
+${typeName}Points0MotionSolver::
+~${typeName}Points0MotionSolver()
 {}
 
 
 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
 
-tmp<pointField> ${typeName}Points0MotionSolver::curPoints() const
+Foam::tmp<Foam::pointField>
+Foam::${typeName}Points0MotionSolver::curPoints() const
 {
     if (${verbose:-false})
     {
@@ -109,8 +116,4 @@ tmp<pointField> ${typeName}Points0MotionSolver::curPoints() const
 }
 
 
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
-
-} // End namespace Foam
-
 // ************************************************************************* //
diff --git a/etc/codeTemplates/dynamicCode/codedPoints0MotionSolverTemplate.H b/etc/codeTemplates/dynamicCode/codedPoints0MotionSolverTemplate.H
index 8a2a70fcf8d..e420c2af675 100644
--- a/etc/codeTemplates/dynamicCode/codedPoints0MotionSolverTemplate.H
+++ b/etc/codeTemplates/dynamicCode/codedPoints0MotionSolverTemplate.H
@@ -103,7 +103,7 @@ public:
     // Member Functions
 
         //- Code context as a dictionary
-        const dictionary& codeContext() const
+        const dictionary& codeContext() const noexcept
         {
             return dictionaryContent::dict();
         }
diff --git a/etc/codeTemplates/dynamicCode/fixedValueFvPatchFieldTemplate.C b/etc/codeTemplates/dynamicCode/fixedValueFvPatchFieldTemplate.C
index a9db42f5fde..3252c4cc76a 100644
--- a/etc/codeTemplates/dynamicCode/fixedValueFvPatchFieldTemplate.C
+++ b/etc/codeTemplates/dynamicCode/fixedValueFvPatchFieldTemplate.C
@@ -78,9 +78,12 @@ makeRemovablePatchTypeField
     ${typeName}FixedValueFvPatch${FieldType}
 );
 
+} // End namespace Foam
+
 
 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
 
+Foam::
 ${typeName}FixedValueFvPatch${FieldType}::
 ${typeName}FixedValueFvPatch${FieldType}
 (
@@ -97,6 +100,7 @@ ${typeName}FixedValueFvPatch${FieldType}
 }
 
 
+Foam::
 ${typeName}FixedValueFvPatch${FieldType}::
 ${typeName}FixedValueFvPatch${FieldType}
 (
@@ -115,6 +119,7 @@ ${typeName}FixedValueFvPatch${FieldType}
 }
 
 
+Foam::
 ${typeName}FixedValueFvPatch${FieldType}::
 ${typeName}FixedValueFvPatch${FieldType}
 (
@@ -132,6 +137,7 @@ ${typeName}FixedValueFvPatch${FieldType}
 }
 
 
+Foam::
 ${typeName}FixedValueFvPatch${FieldType}::
 ${typeName}FixedValueFvPatch${FieldType}
 (
@@ -147,6 +153,7 @@ ${typeName}FixedValueFvPatch${FieldType}
 }
 
 
+Foam::
 ${typeName}FixedValueFvPatch${FieldType}::
 ${typeName}FixedValueFvPatch${FieldType}
 (
@@ -165,6 +172,7 @@ ${typeName}FixedValueFvPatch${FieldType}
 
 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
 
+Foam::
 ${typeName}FixedValueFvPatch${FieldType}::
 ~${typeName}FixedValueFvPatch${FieldType}()
 {
@@ -178,6 +186,7 @@ ${typeName}FixedValueFvPatch${FieldType}::
 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
 
 void
+Foam::
 ${typeName}FixedValueFvPatch${FieldType}::updateCoeffs()
 {
     if (this->updated())
@@ -198,8 +207,4 @@ ${typeName}FixedValueFvPatch${FieldType}::updateCoeffs()
 }
 
 
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
-
-} // End namespace Foam
-
 // ************************************************************************* //
diff --git a/etc/codeTemplates/dynamicCode/fixedValueFvPatchFieldTemplate.H b/etc/codeTemplates/dynamicCode/fixedValueFvPatchFieldTemplate.H
index 5c345838d9e..1baf7be91e7 100644
--- a/etc/codeTemplates/dynamicCode/fixedValueFvPatchFieldTemplate.H
+++ b/etc/codeTemplates/dynamicCode/fixedValueFvPatchFieldTemplate.H
@@ -143,7 +143,7 @@ public:
     // Member Functions
 
         //- Code context as a dictionary
-        const dictionary& codeContext() const
+        const dictionary& codeContext() const noexcept
         {
             return dictionaryContent::dict();
         }
diff --git a/etc/codeTemplates/dynamicCode/fixedValuePointPatchFieldTemplate.C b/etc/codeTemplates/dynamicCode/fixedValuePointPatchFieldTemplate.C
index c91a478c621..93bdec669ed 100644
--- a/etc/codeTemplates/dynamicCode/fixedValuePointPatchFieldTemplate.C
+++ b/etc/codeTemplates/dynamicCode/fixedValuePointPatchFieldTemplate.C
@@ -77,9 +77,12 @@ makePointPatchTypeField
     ${typeName}FixedValuePointPatch${FieldType}
 );
 
+} // End namespace Foam
+
 
 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
 
+Foam::
 ${typeName}FixedValuePointPatch${FieldType}::
 ${typeName}FixedValuePointPatch${FieldType}
 (
@@ -96,6 +99,7 @@ ${typeName}FixedValuePointPatch${FieldType}
 }
 
 
+Foam::
 ${typeName}FixedValuePointPatch${FieldType}::
 ${typeName}FixedValuePointPatch${FieldType}
 (
@@ -114,6 +118,7 @@ ${typeName}FixedValuePointPatch${FieldType}
 }
 
 
+Foam::
 ${typeName}FixedValuePointPatch${FieldType}::
 ${typeName}FixedValuePointPatch${FieldType}
 (
@@ -132,6 +137,7 @@ ${typeName}FixedValuePointPatch${FieldType}
 }
 
 
+Foam::
 ${typeName}FixedValuePointPatch${FieldType}::
 ${typeName}FixedValuePointPatch${FieldType}
 (
@@ -147,6 +153,7 @@ ${typeName}FixedValuePointPatch${FieldType}
 }
 
 
+Foam::
 ${typeName}FixedValuePointPatch${FieldType}::
 ${typeName}FixedValuePointPatch${FieldType}
 (
@@ -165,6 +172,7 @@ ${typeName}FixedValuePointPatch${FieldType}
 
 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
 
+Foam::
 ${typeName}FixedValuePointPatch${FieldType}::
 ~${typeName}FixedValuePointPatch${FieldType}()
 {
@@ -178,6 +186,7 @@ ${typeName}FixedValuePointPatch${FieldType}::
 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
 
 void
+Foam::
 ${typeName}FixedValuePointPatch${FieldType}::updateCoeffs()
 {
     if (this->updated())
@@ -198,8 +207,4 @@ ${typeName}FixedValuePointPatch${FieldType}::updateCoeffs()
 }
 
 
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
-
-} // End namespace Foam
-
 // ************************************************************************* //
diff --git a/etc/codeTemplates/dynamicCode/fixedValuePointPatchFieldTemplate.H b/etc/codeTemplates/dynamicCode/fixedValuePointPatchFieldTemplate.H
index 9fd6198afbf..85a9cf08fc3 100644
--- a/etc/codeTemplates/dynamicCode/fixedValuePointPatchFieldTemplate.H
+++ b/etc/codeTemplates/dynamicCode/fixedValuePointPatchFieldTemplate.H
@@ -144,7 +144,7 @@ public:
     // Member Functions
 
         //- Code context as a dictionary
-        const dictionary& codeContext() const
+        const dictionary& codeContext() const noexcept
         {
             return dictionaryContent::dict();
         }
diff --git a/etc/codeTemplates/dynamicCode/functionObjectTemplate.C b/etc/codeTemplates/dynamicCode/functionObjectTemplate.C
index 274fd29f7c2..f6b014bd1e0 100644
--- a/etc/codeTemplates/dynamicCode/functionObjectTemplate.C
+++ b/etc/codeTemplates/dynamicCode/functionObjectTemplate.C
@@ -75,10 +75,13 @@ extern "C" void ${typeName}_${SHA1sum}(bool load)
 ${localCode}
 //}}} end localCode
 
+} // End namespace Foam
+
 
 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
 
-const fvMesh& ${typeName}FunctionObject::mesh() const
+const Foam::fvMesh&
+Foam::${typeName}FunctionObject::mesh() const
 {
     return refCast<const fvMesh>(obr_);
 }
@@ -86,7 +89,9 @@ const fvMesh& ${typeName}FunctionObject::mesh() const
 
 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
 
-${typeName}FunctionObject::${typeName}FunctionObject
+Foam::
+${typeName}FunctionObject::
+${typeName}FunctionObject
 (
     const word& name,
     const Time& runTime,
@@ -101,13 +106,16 @@ ${typeName}FunctionObject::${typeName}FunctionObject
 
 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
 
-${typeName}FunctionObject::~${typeName}FunctionObject()
+Foam::
+${typeName}FunctionObject::
+~${typeName}FunctionObject()
 {}
 
 
 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
 
 bool
+Foam::
 ${typeName}FunctionObject::read(const dictionary& dict)
 {
     if (${verbose:-false})
@@ -124,6 +132,7 @@ ${typeName}FunctionObject::read(const dictionary& dict)
 
 
 bool
+Foam::
 ${typeName}FunctionObject::execute()
 {
     if (${verbose:-false})
@@ -140,6 +149,7 @@ ${typeName}FunctionObject::execute()
 
 
 bool
+Foam::
 ${typeName}FunctionObject::write()
 {
     if (${verbose:-false})
@@ -156,6 +166,7 @@ ${typeName}FunctionObject::write()
 
 
 bool
+Foam::
 ${typeName}FunctionObject::end()
 {
     if (${verbose:-false})
@@ -171,8 +182,4 @@ ${typeName}FunctionObject::end()
 }
 
 
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
-
-} // End namespace Foam
-
 // ************************************************************************* //
diff --git a/etc/codeTemplates/dynamicCode/functionObjectTemplate.H b/etc/codeTemplates/dynamicCode/functionObjectTemplate.H
index 8cb7aaaca4d..2742cf9e787 100644
--- a/etc/codeTemplates/dynamicCode/functionObjectTemplate.H
+++ b/etc/codeTemplates/dynamicCode/functionObjectTemplate.H
@@ -32,8 +32,8 @@ SourceFiles
 
 \*---------------------------------------------------------------------------*/
 
-#ifndef functionObjectTemplate_H
-#define functionObjectTemplate_H
+#ifndef coded_functionObjectTemplate_H
+#define coded_functionObjectTemplate_H
 
 #include "regionFunctionObject.H"
 #include "dictionaryContent.H"
@@ -116,7 +116,7 @@ public:
     // Member Functions
 
         //- Code context as a dictionary
-        const dictionary& codeContext() const
+        const dictionary& codeContext() const noexcept
         {
             return dictionaryContent::dict();
         }
diff --git a/etc/codeTemplates/dynamicCode/mixedFvPatchFieldTemplate.C b/etc/codeTemplates/dynamicCode/mixedFvPatchFieldTemplate.C
index 8602b151bec..6a42a890a9f 100644
--- a/etc/codeTemplates/dynamicCode/mixedFvPatchFieldTemplate.C
+++ b/etc/codeTemplates/dynamicCode/mixedFvPatchFieldTemplate.C
@@ -77,9 +77,12 @@ makeRemovablePatchTypeField
     ${typeName}MixedValueFvPatch${FieldType}
 );
 
+} // End namespace Foam
+
 
 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
 
+Foam::
 ${typeName}MixedValueFvPatch${FieldType}::
 ${typeName}MixedValueFvPatch${FieldType}
 (
@@ -96,6 +99,7 @@ ${typeName}MixedValueFvPatch${FieldType}
 }
 
 
+Foam::
 ${typeName}MixedValueFvPatch${FieldType}::
 ${typeName}MixedValueFvPatch${FieldType}
 (
@@ -114,6 +118,7 @@ ${typeName}MixedValueFvPatch${FieldType}
 }
 
 
+Foam::
 ${typeName}MixedValueFvPatch${FieldType}::
 ${typeName}MixedValueFvPatch${FieldType}
 (
@@ -131,6 +136,7 @@ ${typeName}MixedValueFvPatch${FieldType}
 }
 
 
+Foam::
 ${typeName}MixedValueFvPatch${FieldType}::
 ${typeName}MixedValueFvPatch${FieldType}
 (
@@ -146,6 +152,7 @@ ${typeName}MixedValueFvPatch${FieldType}
 }
 
 
+Foam::
 ${typeName}MixedValueFvPatch${FieldType}::
 ${typeName}MixedValueFvPatch${FieldType}
 (
@@ -164,6 +171,7 @@ ${typeName}MixedValueFvPatch${FieldType}
 
 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
 
+Foam::
 ${typeName}MixedValueFvPatch${FieldType}::
 ~${typeName}MixedValueFvPatch${FieldType}()
 {
@@ -177,6 +185,7 @@ ${typeName}MixedValueFvPatch${FieldType}::
 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
 
 void
+Foam::
 ${typeName}MixedValueFvPatch${FieldType}::updateCoeffs()
 {
     if (this->updated())
@@ -197,8 +206,4 @@ ${typeName}MixedValueFvPatch${FieldType}::updateCoeffs()
 }
 
 
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
-
-} // End namespace Foam
-
 // ************************************************************************* //
diff --git a/etc/codeTemplates/dynamicCode/mixedFvPatchFieldTemplate.H b/etc/codeTemplates/dynamicCode/mixedFvPatchFieldTemplate.H
index 83ef277870c..74195dc8df5 100644
--- a/etc/codeTemplates/dynamicCode/mixedFvPatchFieldTemplate.H
+++ b/etc/codeTemplates/dynamicCode/mixedFvPatchFieldTemplate.H
@@ -143,7 +143,7 @@ public:
     // Member Functions
 
         //- Code context as a dictionary
-        const dictionary& codeContext() const
+        const dictionary& codeContext() const noexcept
         {
             return dictionaryContent::dict();
         }
diff --git a/src/OpenFOAM/fields/pointPatchFields/derived/codedFixedValue/codedFixedValuePointPatchField.C b/src/OpenFOAM/fields/pointPatchFields/derived/codedFixedValue/codedFixedValuePointPatchField.C
index ae21366c0f6..25a067f2f4a 100644
--- a/src/OpenFOAM/fields/pointPatchFields/derived/codedFixedValue/codedFixedValuePointPatchField.C
+++ b/src/OpenFOAM/fields/pointPatchFields/derived/codedFixedValue/codedFixedValuePointPatchField.C
@@ -150,7 +150,7 @@ Foam::codedFixedValuePointPatchField<Type>::codedFixedValuePointPatchField
 :
     parent_bctype(rhs, p, iF, mapper),
     codedBase(),
-    dict_(rhs.dict_),
+    dict_(rhs.dict_),  // Deep copy
     name_(rhs.name_),
     redirectPatchFieldPtr_(nullptr)
 {}
@@ -169,12 +169,12 @@ Foam::codedFixedValuePointPatchField<Type>::codedFixedValuePointPatchField
     codedBase(),
     dict_
     (
-        // Copy dictionary, but without "heavy" data chunks
+        // Copy dictionary without "heavy" data chunks
         dictionaryContent::copyDict
         (
             dict,
-            wordRes(),  // allow
-            wordRes     // deny
+            wordList(),  // allow
+            wordList     // deny
             ({
                 "type",  // redundant
                 "value"
@@ -196,7 +196,7 @@ Foam::codedFixedValuePointPatchField<Type>::codedFixedValuePointPatchField
 :
     parent_bctype(rhs),
     codedBase(),
-    dict_(rhs.dict_),
+    dict_(rhs.dict_),  // Deep copy
     name_(rhs.name_),
     redirectPatchFieldPtr_(nullptr)
 {}
@@ -211,7 +211,7 @@ Foam::codedFixedValuePointPatchField<Type>::codedFixedValuePointPatchField
 :
     parent_bctype(rhs, iF),
     codedBase(),
-    dict_(rhs.dict_),
+    dict_(rhs.dict_),  // Deep copy
     name_(rhs.name_),
     redirectPatchFieldPtr_(nullptr)
 {}
diff --git a/src/OpenFOAM/primitives/functions/Function1/Coded/CodedFunction1.C b/src/OpenFOAM/primitives/functions/Function1/Coded/CodedFunction1.C
new file mode 100644
index 00000000000..bd7aa98dce2
--- /dev/null
+++ b/src/OpenFOAM/primitives/functions/Function1/Coded/CodedFunction1.C
@@ -0,0 +1,247 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | www.openfoam.com
+     \\/     M anipulation  |
+-------------------------------------------------------------------------------
+    Copyright (C) 2021 OpenCFD Ltd.
+-------------------------------------------------------------------------------
+License
+    This file is part of OpenFOAM.
+
+    OpenFOAM is free software: you can redistribute it and/or modify it
+    under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
+    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+    for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
+
+\*---------------------------------------------------------------------------*/
+
+#include "dynamicCode.H"
+#include "dynamicCodeContext.H"
+#include "dictionaryContent.H"
+
+// * * * * * * * * * * * * Protected Member Functions  * * * * * * * * * * * //
+
+template<class Type>
+Foam::dlLibraryTable&
+Foam::Function1Types::CodedFunction1<Type>::libs() const
+{
+    return this->time().libs();
+}
+
+
+template<class Type>
+Foam::string
+Foam::Function1Types::CodedFunction1<Type>::description() const
+{
+    return "CodedFunction1 " + redirectName_;
+}
+
+
+template<class Type>
+void Foam::Function1Types::CodedFunction1<Type>::clearRedirect() const
+{
+    redirectFunctionPtr_.reset(nullptr);
+}
+
+
+template<class Type>
+const Foam::dictionary&
+Foam::Function1Types::CodedFunction1<Type>::codeContext() const
+{
+    // What else would make sense?
+    return dict_;
+}
+
+
+template<class Type>
+const Foam::dictionary&
+Foam::Function1Types::CodedFunction1<Type>::codeDict
+(
+    const dictionary& dict
+) const
+{
+    // Use named subdictionary if present to provide the code.
+    // This allows running with multiple Function1s
+
+    return
+    (
+        dict.found("code")
+      ? dict
+      : dict.subDict(redirectName_)
+    );
+}
+
+
+template<class Type>
+const Foam::dictionary&
+Foam::Function1Types::CodedFunction1<Type>::codeDict() const
+{
+    return codeDict(dict_);
+}
+
+
+template<class Type>
+void Foam::Function1Types::CodedFunction1<Type>::prepare
+(
+    dynamicCode& dynCode,
+    const dynamicCodeContext& context
+) const
+{
+    if (context.code().empty())
+    {
+        FatalIOErrorInFunction(dict_)
+            << "No code section in input dictionary for Function1 "
+            << " name " << redirectName_
+            << exit(FatalIOError);
+    }
+
+    // Take no chances - typeName must be identical to redirectName_
+    dynCode.setFilterVariable("typeName", redirectName_);
+
+    // Set TemplateType and FieldType filter variables
+    dynCode.setFieldTemplates<Type>();
+
+    // Compile filtered C template
+    dynCode.addCompileFile(codeTemplateC);
+
+    // Copy filtered H template
+    dynCode.addCopyFile(codeTemplateH);
+
+    #ifdef FULLDEBUG
+    dynCode.setFilterVariable("verbose", "true");
+    DetailInfo
+        <<"compile " << redirectName_ << " sha1: " << context.sha1() << endl;
+    #endif
+
+    // Define Make/options
+    dynCode.setMakeOptions
+    (
+        "EXE_INC = -g \\\n"
+        "-I$(LIB_SRC)/meshTools/lnInclude \\\n"
+      + context.options()
+      + "\n\nLIB_LIBS = \\\n"
+        "    -lOpenFOAM \\\n"
+        "    -lmeshTools \\\n"
+      + context.libs()
+    );
+}
+
+
+// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
+
+template<class Type>
+Foam::Function1Types::CodedFunction1<Type>::CodedFunction1
+(
+    const word& entryName,
+    const dictionary& dict,
+    const objectRegistry* obrPtr
+)
+:
+    Function1<Type>(entryName, dict, obrPtr),
+    codedBase(),
+    dict_(dict),
+    redirectName_(dict.getOrDefault<word>("name", entryName))
+{
+    this->codedBase::setCodeContext(dict_);
+
+    // No additional code chunks...
+
+    updateLibrary(redirectName_);
+}
+
+
+template<class Type>
+Foam::Function1Types::CodedFunction1<Type>::CodedFunction1
+(
+    const CodedFunction1<Type>& rhs
+)
+:
+    Function1<Type>(rhs),
+    codedBase(),
+    dict_(rhs.dict_),
+    redirectName_(rhs.redirectName_)
+{}
+
+
+// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
+
+template<class Type>
+const Foam::Function1<Type>&
+Foam::Function1Types::CodedFunction1<Type>::redirectFunction() const
+{
+    if (!redirectFunctionPtr_)
+    {
+        dictionary constructDict;
+        // Force 'redirectName_' sub-dictionary into existence
+        dictionary& coeffs = constructDict.subDictOrAdd(redirectName_);
+
+        coeffs = dict_;  // Copy input code and coefficients
+        coeffs.remove("name");      // Redundant
+        coeffs.set("type", redirectName_);  // Specify our new (redirect) type
+
+        redirectFunctionPtr_.reset
+        (
+            Function1<Type>::New
+            (
+                redirectName_,
+                constructDict,
+                this->whichDb()
+            )
+        );
+
+        // Forward copy of codeContext to the code template
+        auto* contentPtr =
+            dynamic_cast<dictionaryContent*>(redirectFunctionPtr_.get());
+
+        if (contentPtr)
+        {
+            contentPtr->dict(this->codeContext());
+        }
+        else
+        {
+            WarningInFunction
+                << redirectName_ << " Did not derive from dictionaryContent"
+                << nl << nl;
+        }
+    }
+    return *redirectFunctionPtr_;
+}
+
+
+template<class Type>
+Type Foam::Function1Types::CodedFunction1<Type>::value
+(
+    const scalar x
+) const
+{
+    // Ensure library containing user-defined code is up-to-date
+    updateLibrary(redirectName_);
+
+    return redirectFunction().value(x);
+}
+
+
+template<class Type>
+void Foam::Function1Types::CodedFunction1<Type>::writeData
+(
+    Ostream& os
+) const
+{
+    // Should really only output only relevant entries but since using
+    // Function1-from-subdict upon construction our dictionary contains
+    // only the relevant entries.
+    dict_.writeEntry(this->name(), os);
+}
+
+
+// ************************************************************************* //
diff --git a/src/OpenFOAM/primitives/functions/Function1/Coded/CodedFunction1.H b/src/OpenFOAM/primitives/functions/Function1/Coded/CodedFunction1.H
new file mode 100644
index 00000000000..ed8dbfe01e4
--- /dev/null
+++ b/src/OpenFOAM/primitives/functions/Function1/Coded/CodedFunction1.H
@@ -0,0 +1,225 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | www.openfoam.com
+     \\/     M anipulation  |
+-------------------------------------------------------------------------------
+    Copyright (C) 2021 OpenCFD Ltd.
+-------------------------------------------------------------------------------
+License
+    This file is part of OpenFOAM.
+
+    OpenFOAM is free software: you can redistribute it and/or modify it
+    under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
+    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+    for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
+
+Class
+    Foam::Function1Types::CodedFunction1
+
+Description
+    Function1 with the code supplied by an on-the-fly compiled C++
+    expression.
+
+    The code entries:
+    \plaintable
+       codeInclude | include files
+       codeOptions | compiler line: added to EXE_INC (Make/options)
+       codeLibs    | linker line: added to LIB_LIBS (Make/options)
+       localCode   | c++; local static functions
+       code        | c++; return the patch values at (scalar x)
+    \endplaintable
+
+Usage
+    Example:
+    \verbatim
+    <patchName>
+    {
+        type            uniformFixedValue;
+        uniformValue
+        {
+            type  coded;
+            name  myExpression;  // Name of generated PatchFunction1
+
+            code
+            #{
+                const polyPatch& pp = this->patch();
+                Pout<< "** Patch size:" << pp.size() << endl;
+                return tmp<vectorField>::New(pp.size(), vector(1, 0, 0))
+            #};
+
+            //codeInclude
+            //#{
+            //    #include "volFields.H"
+            //#};
+
+            //codeOptions
+            //#{
+            //    -I$(LIB_SRC)/finiteVolume/lnInclude
+            //#};
+        }
+    }
+    \endverbatim
+
+Note
+    The code context dictionary is simply the dictionary used to specify
+    the PatchFunction1 coefficients.
+
+See also
+    Foam::dynamicCode
+    Foam::codedFixedValue
+    Foam::functionEntries::codeStream
+
+SourceFiles
+    CodedFunction1.C
+
+\*---------------------------------------------------------------------------*/
+
+#ifndef Function1Types_CodedFunction1_H
+#define Function1Types_CodedFunction1_H
+
+#include "Function1.H"
+#include "codedBase.H"
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+namespace Foam
+{
+namespace Function1Types
+{
+
+/*---------------------------------------------------------------------------*\
+                         Class CodedFunction1 Declaration
+\*---------------------------------------------------------------------------*/
+
+template<class Type>
+class CodedFunction1
+:
+    public Function1<Type>,
+    protected codedBase
+{
+    // Private Data
+
+        //- Dictionary contents for the function
+        const dictionary dict_;
+
+        const word redirectName_;
+
+        mutable autoPtr<Function1<Type>> redirectFunctionPtr_;
+
+
+    // Private Member Functions
+
+        //- Get reference to the underlying Function1
+        const Function1<Type>& redirectFunction() const;
+
+
+protected:
+
+    // Protected Member Functions
+
+        //- Mutable access to the loaded dynamic libraries
+        virtual dlLibraryTable& libs() const;
+
+        //- Description (type + name) for the output
+        virtual string description() const;
+
+        //- Clear redirected object(s)
+        virtual void clearRedirect() const;
+
+        //- Additional 'codeContext' dictionary to pass through
+        virtual const dictionary& codeContext() const;
+
+        // Get the code (sub)dictionary
+        virtual const dictionary& codeDict(const dictionary& dict) const;
+
+        // Get the code dictionary
+        virtual const dictionary& codeDict() const;
+
+        //- Adapt the context for the current object
+        virtual void prepare(dynamicCode&, const dynamicCodeContext&) const;
+
+
+    // Generated Methods
+
+        //- No copy assignment
+        void operator=(const CodedFunction1<Type>&) = delete;
+
+public:
+
+    // Static Data Members
+
+        //- Name of the C code template to be used
+        static constexpr const char* const codeTemplateC
+            = "codedFunction1Template.C";
+
+        //- Name of the H code template to be used
+        static constexpr const char* const codeTemplateH
+            = "codedFunction1Template.H";
+
+
+    //- Runtime type information
+    TypeName("coded");
+
+
+    // Constructors
+
+        //- Construct from entry name, dictionary and optional registry
+        CodedFunction1
+        (
+            const word& entryName,
+            const dictionary& dict,
+            const objectRegistry* obrPtr = nullptr
+        );
+
+        //- Copy construct
+        explicit CodedFunction1(const CodedFunction1<Type>& rhs);
+
+        //- Construct and return a clone
+        virtual tmp<Function1<Type>> clone() const
+        {
+            return tmp<Function1<Type>>(new CodedFunction1<Type>(*this));
+        }
+
+
+    //- Destructor
+    virtual ~CodedFunction1() = default;
+
+
+    // Member Functions
+
+        //- Return value at current time
+        virtual inline Type value(const scalar x) const;
+
+        // Integrate etc are not implemented!
+
+        //- Write in dictionary format
+        virtual void writeData(Ostream& os) const;
+};
+
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+} // End namespace Function1Types
+} // End namespace Foam
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+#ifdef NoRepository
+    #include "CodedFunction1.C"
+#endif
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+#endif
+
+// ************************************************************************* //
diff --git a/src/OpenFOAM/primitives/functions/Function1/FunctionObjectTrigger/FunctionObjectTrigger.C b/src/OpenFOAM/primitives/functions/Function1/FunctionObjectTrigger/FunctionObjectTrigger.C
index cc94b94eb58..710e91b3ae7 100644
--- a/src/OpenFOAM/primitives/functions/Function1/FunctionObjectTrigger/FunctionObjectTrigger.C
+++ b/src/OpenFOAM/primitives/functions/Function1/FunctionObjectTrigger/FunctionObjectTrigger.C
@@ -78,7 +78,7 @@ void Foam::Function1Types::FunctionObjectTrigger<Type>::writeEntries
 ) const
 {
     os.writeKeyword("triggers");
-    flatOutput(triggers_);
+    os << flatOutput(triggers_);
     os.endEntry();
 
     if (defaultValue_)
diff --git a/src/OpenFOAM/primitives/functions/Function1/makeFunction1s.C b/src/OpenFOAM/primitives/functions/Function1/makeFunction1s.C
index 06f07ca8fd8..f77245ea0fd 100644
--- a/src/OpenFOAM/primitives/functions/Function1/makeFunction1s.C
+++ b/src/OpenFOAM/primitives/functions/Function1/makeFunction1s.C
@@ -26,6 +26,7 @@ License
 
 \*---------------------------------------------------------------------------*/
 
+#include "CodedFunction1.H"
 #include "Constant.H"
 #include "Uniform.H"
 #include "ZeroConstant.H"
@@ -48,6 +49,7 @@ License
 
 #define makeFunction1s(Type)                                                   \
     makeFunction1(Type);                                                       \
+    makeFunction1Type(CodedFunction1, Type);                                   \
     makeFunction1Type(Constant, Type);                                         \
     makeFunction1Type(Uniform, Type);                                          \
     makeFunction1Type(None, Type);                                             \
diff --git a/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchField.C
index 73f1e360041..c85d0dc2638 100644
--- a/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchField.C
+++ b/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchField.C
@@ -150,7 +150,7 @@ Foam::codedFixedValueFvPatchField<Type>::codedFixedValueFvPatchField
 :
     parent_bctype(rhs, p, iF, mapper),
     codedBase(),
-    dict_(rhs.dict_),
+    dict_(rhs.dict_),  // Deep copy
     name_(rhs.name_),
     redirectPatchFieldPtr_(nullptr)
 {}
@@ -168,12 +168,12 @@ Foam::codedFixedValueFvPatchField<Type>::codedFixedValueFvPatchField
     codedBase(),
     dict_
     (
-        // Copy dictionary, but without "heavy" data chunks
+        // Copy dictionary without "heavy" data chunks
         dictionaryContent::copyDict
         (
             dict,
-            wordRes(),  // allow
-            wordRes     // deny
+            wordList(),  // allow
+            wordList     // deny
             ({
                 "type",  // redundant
                 "value"
@@ -195,7 +195,7 @@ Foam::codedFixedValueFvPatchField<Type>::codedFixedValueFvPatchField
 :
     parent_bctype(rhs),
     codedBase(),
-    dict_(rhs.dict_),
+    dict_(rhs.dict_),  // Deep copy
     name_(rhs.name_),
     redirectPatchFieldPtr_(nullptr)
 {}
@@ -210,7 +210,7 @@ Foam::codedFixedValueFvPatchField<Type>::codedFixedValueFvPatchField
 :
     parent_bctype(rhs, iF),
     codedBase(),
-    dict_(rhs.dict_),
+    dict_(rhs.dict_),  // Deep copy
     name_(rhs.name_),
     redirectPatchFieldPtr_(nullptr)
 {}
diff --git a/src/finiteVolume/fields/fvPatchFields/derived/codedMixed/codedMixedFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/derived/codedMixed/codedMixedFvPatchField.C
index e294c6474d5..c63ebc4abc2 100644
--- a/src/finiteVolume/fields/fvPatchFields/derived/codedMixed/codedMixedFvPatchField.C
+++ b/src/finiteVolume/fields/fvPatchFields/derived/codedMixed/codedMixedFvPatchField.C
@@ -150,7 +150,7 @@ Foam::codedMixedFvPatchField<Type>::codedMixedFvPatchField
 :
     parent_bctype(rhs, p, iF, mapper),
     codedBase(),
-    dict_(rhs.dict_),
+    dict_(rhs.dict_),  // Deep copy
     name_(rhs.name_),
     redirectPatchFieldPtr_(nullptr)
 {}
@@ -172,8 +172,8 @@ Foam::codedMixedFvPatchField<Type>::codedMixedFvPatchField
         dictionaryContent::copyDict
         (
             dict,
-            wordRes(),  // allow
-            wordRes     // deny
+            wordList(),  // allow
+            wordList     // deny
             ({
                 "type",  // redundant
                 "value", "refValue", "refGradient", "valueFraction"
@@ -195,7 +195,7 @@ Foam::codedMixedFvPatchField<Type>::codedMixedFvPatchField
 :
     parent_bctype(rhs),
     codedBase(),
-    dict_(rhs.dict_),
+    dict_(rhs.dict_),  // Deep copy
     name_(rhs.name_),
     redirectPatchFieldPtr_(nullptr)
 {}
@@ -210,7 +210,7 @@ Foam::codedMixedFvPatchField<Type>::codedMixedFvPatchField
 :
     parent_bctype(rhs, iF),
     codedBase(),
-    dict_(rhs.dict_),
+    dict_(rhs.dict_),  // Deep copy
     name_(rhs.name_),
     redirectPatchFieldPtr_(nullptr)
 {}
diff --git a/src/meshTools/PatchFunction1/CodedField/CodedField.C b/src/meshTools/PatchFunction1/CodedField/CodedField.C
index 60ca1ecca87..8cea612466b 100644
--- a/src/meshTools/PatchFunction1/CodedField/CodedField.C
+++ b/src/meshTools/PatchFunction1/CodedField/CodedField.C
@@ -43,7 +43,7 @@ template<class Type>
 Foam::string
 Foam::PatchFunction1Types::CodedField<Type>::description() const
 {
-    return "CodedField " + name_;
+    return "CodedField " + redirectName_;
 }
 
 
@@ -77,7 +77,7 @@ Foam::PatchFunction1Types::CodedField<Type>::codeDict
     (
         dict.found("code")
       ? dict
-      : dict.subDict(name_)
+      : dict.subDict(redirectName_)
     );
 }
 
@@ -102,12 +102,12 @@ void Foam::PatchFunction1Types::CodedField<Type>::prepare
         FatalIOErrorInFunction(dict_)
             << "No code section in input dictionary for patch "
             << this->patch_.name()
-            << " name " << name_
+            << " name " << redirectName_
             << exit(FatalIOError);
     }
 
-    // Take no chances - typeName must be identical to name_
-    dynCode.setFilterVariable("typeName", name_);
+    // Take no chances - typeName must be identical to redirectName_
+    dynCode.setFilterVariable("typeName", redirectName_);
 
     // Set TemplateType and FieldType filter variables
     dynCode.setFieldTemplates<Type>();
@@ -121,7 +121,7 @@ void Foam::PatchFunction1Types::CodedField<Type>::prepare
     #ifdef FULLDEBUG
     dynCode.setFilterVariable("verbose", "true");
     DetailInfo
-        <<"compile " << name_ << " sha1: " << context.sha1() << endl;
+        <<"compile " << redirectName_ << " sha1: " << context.sha1() << endl;
     #endif
 
     // Define Make/options
@@ -155,13 +155,13 @@ Foam::PatchFunction1Types::CodedField<Type>::CodedField
     PatchFunction1<Type>(pp, entryName, dict, faceValues),
     codedBase(),
     dict_(dict),
-    name_(dict.getOrDefault<word>("name", entryName))
+    redirectName_(dict.getOrDefault<word>("name", entryName))
 {
     this->codedBase::setCodeContext(dict_);
 
     // No additional code chunks...
 
-    updateLibrary(name_);
+    updateLibrary(redirectName_);
 }
 
 
@@ -185,7 +185,7 @@ Foam::PatchFunction1Types::CodedField<Type>::CodedField
     PatchFunction1<Type>(rhs, pp),
     codedBase(),
     dict_(rhs.dict_),
-    name_(rhs.name_)
+    redirectName_(rhs.redirectName_)
 {}
 
 
@@ -198,19 +198,19 @@ Foam::PatchFunction1Types::CodedField<Type>::redirectFunction() const
     if (!redirectFunctionPtr_)
     {
         dictionary constructDict;
-        // Force 'name_' sub-dictionary into existence
-        dictionary& coeffs = constructDict.subDictOrAdd(name_);
+        // Force 'redirectName_' sub-dictionary into existence
+        dictionary& coeffs = constructDict.subDictOrAdd(redirectName_);
 
         coeffs = dict_;  // Copy input code and coefficients
         coeffs.remove("name");      // Redundant
-        coeffs.set("type", name_);  // Specify our new (redirect) type
+        coeffs.set("type", redirectName_);  // Specify our new (redirect) type
 
         redirectFunctionPtr_.reset
         (
             PatchFunction1<Type>::New
             (
                 this->patch(),
-                name_,
+                redirectName_,
                 constructDict,
                 this->faceValues()
             )
@@ -227,7 +227,7 @@ Foam::PatchFunction1Types::CodedField<Type>::redirectFunction() const
         else
         {
             WarningInFunction
-                << name_ << " Did not derive from dictionaryContent"
+                << redirectName_ << " Did not derive from dictionaryContent"
                 << nl << nl;
         }
     }
@@ -243,7 +243,7 @@ Foam::PatchFunction1Types::CodedField<Type>::value
 ) const
 {
     // Ensure library containing user-defined code is up-to-date
-    updateLibrary(name_);
+    updateLibrary(redirectName_);
 
     return redirectFunction().value(x);
 }
@@ -258,7 +258,7 @@ Foam::PatchFunction1Types::CodedField<Type>::integrate
 ) const
 {
     // Ensure library containing user-defined code is up-to-date
-    updateLibrary(name_);
+    updateLibrary(redirectName_);
 
     return redirectFunction().integrate(x1, x2);
 }
diff --git a/src/meshTools/PatchFunction1/CodedField/CodedField.H b/src/meshTools/PatchFunction1/CodedField/CodedField.H
index a4dd238c8d6..54cf23076e1 100644
--- a/src/meshTools/PatchFunction1/CodedField/CodedField.H
+++ b/src/meshTools/PatchFunction1/CodedField/CodedField.H
@@ -112,7 +112,7 @@ class CodedField
         //- Dictionary contents for the function
         const dictionary dict_;
 
-        const word name_;
+        const word redirectName_;
 
         mutable autoPtr<PatchFunction1<Type>> redirectFunctionPtr_;
 
@@ -216,23 +216,15 @@ public:
 
     // Member Functions
 
+        //- Is value uniform (i.e. independent of coordinate)
+        virtual inline bool uniform() const { return false; }
+
+
         // Evaluation
 
             //- Return CodedField value
             virtual tmp<Field<Type>> value(const scalar x) const;
 
-            //- Is value constant (i.e. independent of x)
-            virtual inline bool constant() const
-            {
-                return false;
-            }
-
-            //- Is value uniform (i.e. independent of coordinate)
-            virtual inline bool uniform() const
-            {
-                return false;
-            }
-
             //- Integrate between two values
             virtual tmp<Field<Type>> integrate
             (
diff --git a/src/meshTools/PatchFunction1/PatchFunction1/PatchFunction1.H b/src/meshTools/PatchFunction1/PatchFunction1/PatchFunction1.H
index 1f844cfaa42..56a7994c46d 100644
--- a/src/meshTools/PatchFunction1/PatchFunction1/PatchFunction1.H
+++ b/src/meshTools/PatchFunction1/PatchFunction1/PatchFunction1.H
@@ -215,17 +215,18 @@ public:
 
     // Member Functions
 
+        //- Is value constant (i.e. independent of x)
+        virtual bool constant() const { return false; }
+
+        //- Is value uniform (i.e. independent of coordinate)
+        virtual bool uniform() const = 0;
+
+
         // Evaluation
 
             //- Return value as a function of (scalar) independent variable
             virtual tmp<Field<Type>> value(const scalar x) const;
 
-            //- Is value constant (i.e. independent of x)
-            virtual bool constant() const = 0;
-
-            //- Is value uniform (i.e. independent of coordinate)
-            virtual bool uniform() const = 0;
-
             //- Integrate between two (scalar) values
             virtual tmp<Field<Type>> integrate
             (
diff --git a/tutorials/compressible/rhoSimpleFoam/squareBendLiq/0.orig/T b/tutorials/compressible/rhoSimpleFoam/squareBendLiq/0.orig/T
index 59a334114a0..a2ccf90752c 100644
--- a/tutorials/compressible/rhoSimpleFoam/squareBendLiq/0.orig/T
+++ b/tutorials/compressible/rhoSimpleFoam/squareBendLiq/0.orig/T
@@ -40,6 +40,16 @@ boundaryField
         // For general testing purposes:
         type            exprFixedValue;
 
+        functions<scalar>
+        {
+            trigger
+            {
+                type     functionObjectTrigger;
+                triggers (2 4);
+                defaultValue true;
+            }
+        }
+
         variables
         (
             "Tcrit = 500"
diff --git a/tutorials/compressible/rhoSimpleFoam/squareBendLiq/0.orig/U b/tutorials/compressible/rhoSimpleFoam/squareBendLiq/0.orig/U
index 7192f3f9cb1..5136d6af518 100644
--- a/tutorials/compressible/rhoSimpleFoam/squareBendLiq/0.orig/U
+++ b/tutorials/compressible/rhoSimpleFoam/squareBendLiq/0.orig/U
@@ -23,8 +23,26 @@ boundaryField
     inlet
     {
         type            flowRateInletVelocity;
-        massFlowRate    constant 5;
         rhoInlet        1000;    // Guess for rho
+
+        // massFlowRate constant 5;
+
+        massFlowRate
+        {
+            type  coded;
+            name  liquidIn;
+            code
+            #{
+                // Receives 'x' as the argument
+                static bool reported(false);
+                if (!reported)
+                {
+                    Info<< "Using coded value for massFlowRate" << nl;
+                    reported = true;
+                }
+                return 5;
+            #};
+        }
     }
 
     outlet
diff --git a/tutorials/compressible/rhoSimpleFoam/squareBendLiq/Allrun b/tutorials/compressible/rhoSimpleFoam/squareBendLiq/Allrun
index 088d3bc0581..2a084391f1f 100755
--- a/tutorials/compressible/rhoSimpleFoam/squareBendLiq/Allrun
+++ b/tutorials/compressible/rhoSimpleFoam/squareBendLiq/Allrun
@@ -5,6 +5,12 @@ cd "${0%/*}" || exit                                # Run from this directory
 
 ./Allrun.pre
 
+if ! canCompile
+then
+   echo "-- No dynamicCode: replace coded Function1 with constant value"
+   foamDictionary -entry boundaryField/inlet/massFlowRate -set 'constant 5' 0/U
+fi
+
 runApplication decomposePar
 
 #- Run without processorAgglomerator
diff --git a/tutorials/compressible/rhoSimpleFoam/squareBendLiq/Allrun-seq b/tutorials/compressible/rhoSimpleFoam/squareBendLiq/Allrun-seq
index 78d5debbe7f..908248a7116 100755
--- a/tutorials/compressible/rhoSimpleFoam/squareBendLiq/Allrun-seq
+++ b/tutorials/compressible/rhoSimpleFoam/squareBendLiq/Allrun-seq
@@ -5,6 +5,12 @@ cd "${0%/*}" || exit                                # Run from this directory
 
 ./Allrun.pre
 
+if ! canCompile
+then
+   echo "-- No dynamicCode: replace coded Function1 with constant value"
+   foamDictionary -entry boundaryField/inlet/massFlowRate -set 'constant 5' 0/U
+fi
+
 runApplication $(getApplication)
 
 #------------------------------------------------------------------------------
diff --git a/tutorials/multiphase/MPPICInterFoam/twoPhasePachuka/0.orig/U b/tutorials/multiphase/MPPICInterFoam/twoPhasePachuka/0.orig/U
index ebe13c6d5df..0fa62ef7a07 100644
--- a/tutorials/multiphase/MPPICInterFoam/twoPhasePachuka/0.orig/U
+++ b/tutorials/multiphase/MPPICInterFoam/twoPhasePachuka/0.orig/U
@@ -70,7 +70,7 @@ boundaryField
                 {
                     baseVel = Function1<scalar>::New
                     (
-                        "timeFunction", dict, &db()
+                        "timeFunction", dict, this->whichDb()
                     );
                 }
 
@@ -81,7 +81,7 @@ boundaryField
                     // ie, NewIfPresent
                     baseDir = Function1<vector>::New
                     (
-                        "directionFunction", dict, &db()
+                        "directionFunction", dict, this->whichDb()
                     );
 
                     InfoErr
-- 
GitLab