From d6874f0fce08e19b181045c5019f7cda27a08265 Mon Sep 17 00:00:00 2001
From: mattijs <mattijs>
Date: Mon, 21 Feb 2011 14:33:14 +0000
Subject: [PATCH] ENH: codeStream, codedFixedValue: renamed. added template
 directory.

---
 ReleaseNotes-dev                              |   5 +-
 doc/changes/onTheFly.txt                      |  27 ++--
 .../codeStream/codeStreamTemplate.C           |  48 ++++++
 .../fixedValueFvPatchScalarFieldTemplate.C    | 124 +++++++++++++++
 .../fixedValueFvPatchScalarFieldTemplate.H    | 142 ++++++++++++++++++
 etc/settings.csh                              |   3 +
 etc/settings.sh                               |   3 +
 .../functionEntries/codeStream/codeStream.C   |  12 +-
 .../codeStream/codeStreamTools.C              |   4 +-
 .../codedFixedValueFvPatchScalarField.C       |   9 +-
 .../codedFixedValueFvPatchScalarField.H       |   4 +-
 11 files changed, 358 insertions(+), 23 deletions(-)
 create mode 100644 etc/codeTemplates/codeStream/codeStreamTemplate.C
 create mode 100644 etc/codeTemplates/codeStream/fixedValueFvPatchScalarFieldTemplate.C
 create mode 100644 etc/codeTemplates/codeStream/fixedValueFvPatchScalarFieldTemplate.H

diff --git a/ReleaseNotes-dev b/ReleaseNotes-dev
index 06a9bb7c776..57fc61743df 100644
--- a/ReleaseNotes-dev
+++ b/ReleaseNotes-dev
@@ -190,7 +190,7 @@
 
     outlet
     {
-        type            codedFixedValue;
+        type            codedFixedValue<scalar>;
         value           uniform 0;
         redirectType    fixedValue10;
 
@@ -230,6 +230,9 @@
     + =extrudeMesh=:
             - option to add extrusion to existing mesh.
             - works in parallel
+    + =snappyHexMesh=:
+        + extrude across multi-processor boundaries
+        + preserve faceZones during layering
 * Post-processing
   + =paraFoam=, =foamToVTK=: full support for polyhedral cell type in recent
      Paraview versions.
diff --git a/doc/changes/onTheFly.txt b/doc/changes/onTheFly.txt
index 0fc0b691b5f..9734c1f5a8d 100644
--- a/doc/changes/onTheFly.txt
+++ b/doc/changes/onTheFly.txt
@@ -48,6 +48,9 @@ Example: Look up dictionary entries and do some calculation
 - the #codeStream entry reads the dictionary following it, extracts the
 code, codeInclude, codeOptions sections (these are just strings) and
 calculates the SHA1 checksum of the contents.
+- it copies a template file
+($FOAM_CODESTREAM_TEMPLATE_DIR/codeStreamTemplate.C), substituting all
+occurences of code, codeInclude, codeOptions.
 - it writes library source files to constant/codeStream/<sha1> and compiles it
 using 'wmake libso'.
 - the resulting library gets loaded (dlopen, dlsym) and the function
@@ -59,11 +62,11 @@ gets used to construct the entry to replace the whole #codeStream section.
 
 3. codedFixedValue
 This uses the code from codeStream to have an in-line specialised
-fixedValueFvPatchScalarField:
+fixedValueFvPatchScalarField. For now only for scalars:
 
     outlet
     {
-        type            codedFixedValue;
+        type            codedFixedValue<scalar>;
         value           uniform 0;
         redirectType    fixedValue10;
 
@@ -103,9 +106,9 @@ internalField  #codeStream
 
     code
     #{
-        const IOdictionary& d = refCast<const IOdictionary&>(dict);
+        const IOdictionary& d = dynamicCast<const IOdictionary>(dict);
         const fvMesh& mesh = refCast<const fvMesh>(d.db());
-        scalarField fld(mesh.nCells(), 0.0);
+        scalarField fld(mesh.nCells(), 12.34);
         fld.writeEntry("", os);
     #};
 
@@ -115,18 +118,22 @@ internalField  #codeStream
     #};
 };
 
-There are unfortunately some exceptions. Following applications read
-the field as a dictionary:
+* There are unfortunately some exceptions. Following applications read
+the field as a dictionary, not as an IOdictionary:
 - foamFormatConvert
 - changeDictionaryDict
 - foamUpgradeCyclics
 - fieldToCell
 
-Note: above construct has the problem that the boundary conditions are
-not evaluated so e.g. processor boundaries will might not hold the opposite
-cell value.
+
+Note: above field initialisation has the problem that the boundary
+conditions are not evaluated so e.g. processor boundaries will
+not hold the opposite cell value.
 
 
 6. Other
 - the implementation is still a bit raw - it compiles code overly much
-- parallel running not tested a lot. What about distributed data parallel.
+- both codeStream and codedFixedValue take the contents of the dictionary
+and extract values and re-assemble list of files and environment vars to
+replace. Should just directly pass the dictionary into codeStreamTools.
+- parallel running not tested a lot. What about distributed data parallel?
diff --git a/etc/codeTemplates/codeStream/codeStreamTemplate.C b/etc/codeTemplates/codeStream/codeStreamTemplate.C
new file mode 100644
index 00000000000..af4f82ffc8a
--- /dev/null
+++ b/etc/codeTemplates/codeStream/codeStreamTemplate.C
@@ -0,0 +1,48 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 2011-2011 OpenCFD Ltd.
+     \\/     M anipulation  |
+-------------------------------------------------------------------------------
+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/>.
+
+\*---------------------------------------------------------------------------*/
+
+${codeInclude}
+
+using namespace Foam;
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
+
+extern "C"
+{
+void ${typeName}
+(
+    const dictionary& dict,
+    Ostream& os
+)
+{
+${code};
+}
+}
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+// ************************************************************************* //
diff --git a/etc/codeTemplates/codeStream/fixedValueFvPatchScalarFieldTemplate.C b/etc/codeTemplates/codeStream/fixedValueFvPatchScalarFieldTemplate.C
new file mode 100644
index 00000000000..937fb5b5500
--- /dev/null
+++ b/etc/codeTemplates/codeStream/fixedValueFvPatchScalarFieldTemplate.C
@@ -0,0 +1,124 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 20101-2011 OpenCFD Ltd.
+     \\/     M anipulation  |
+-------------------------------------------------------------------------------
+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 "fixedValueFvPatchScalarFieldTemplate.H"
+#include "addToRunTimeSelectionTable.H"
+#include "fvPatchFieldMapper.H"
+#include "volFields.H"
+#include "surfaceFields.H"
+${codeInclude}
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+namespace Foam
+{
+
+// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
+
+${typeName}FixedValueFvPatchScalarField::
+${typeName}FixedValueFvPatchScalarField
+(
+    const fvPatch& p,
+    const DimensionedField<scalar, volMesh>& iF
+)
+:
+    fixedValueFvPatchScalarField(p, iF)
+{}
+
+
+${typeName}FixedValueFvPatchScalarField::
+${typeName}FixedValueFvPatchScalarField
+(
+    const ${typeName}FixedValueFvPatchScalarField& ptf,
+    const fvPatch& p,
+    const DimensionedField<scalar, volMesh>& iF,
+    const fvPatchFieldMapper& mapper
+)
+:
+    fixedValueFvPatchScalarField(ptf, p, iF, mapper)
+{}
+
+
+${typeName}FixedValueFvPatchScalarField::
+${typeName}FixedValueFvPatchScalarField
+(
+    const fvPatch& p,
+    const DimensionedField<scalar, volMesh>& iF,
+    const dictionary& dict
+)
+:
+    fixedValueFvPatchScalarField(p, iF, dict)
+{}
+
+
+${typeName}FixedValueFvPatchScalarField::
+${typeName}FixedValueFvPatchScalarField
+(
+    const ${typeName}FixedValueFvPatchScalarField& ptf
+)
+:
+    fixedValueFvPatchScalarField(ptf)
+{}
+
+
+${typeName}FixedValueFvPatchScalarField::
+${typeName}FixedValueFvPatchScalarField
+(
+    const ${typeName}FixedValueFvPatchScalarField& ptf,
+    const DimensionedField<scalar, volMesh>& iF
+)
+:
+    fixedValueFvPatchScalarField(ptf, iF)
+{}
+
+
+// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
+
+void ${typeName}FixedValueFvPatchScalarField::updateCoeffs()
+{
+    if (this->updated())
+    {
+        return;
+    }
+
+    ${code}
+    fixedValueFvPatchScalarField::updateCoeffs();
+}
+
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+makePatchTypeField
+(
+    fvPatchScalarField,
+    ${typeName}FixedValueFvPatchScalarField
+);
+
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+} // End namespace Foam
+
+// ************************************************************************* //
diff --git a/etc/codeTemplates/codeStream/fixedValueFvPatchScalarFieldTemplate.H b/etc/codeTemplates/codeStream/fixedValueFvPatchScalarFieldTemplate.H
new file mode 100644
index 00000000000..b6ef87c8bc8
--- /dev/null
+++ b/etc/codeTemplates/codeStream/fixedValueFvPatchScalarFieldTemplate.H
@@ -0,0 +1,142 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 2011-2011 OpenCFD Ltd.
+     \\/     M anipulation  |
+-------------------------------------------------------------------------------
+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::fixedValueFvPatchScalarFieldTemplate
+
+Description
+    Template for use with onTheFlyFixedValue.
+    - fixedValueFvPatchScalarField
+    - without state
+
+SourceFiles
+    fixedValueFvPatchScalarFieldTemplate.C
+
+\*---------------------------------------------------------------------------*/
+
+#ifndef fixedValueFvPatchScalarFieldTemplate_H
+#define fixedValueFvPatchScalarFieldTemplate_H
+
+#include "fixedValueFvPatchFields.H"
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+namespace Foam
+{
+
+/*---------------------------------------------------------------------------*\
+             Class fixedValueFvPatchScalarField Declaration
+\*---------------------------------------------------------------------------*/
+
+class ${typeName}FixedValueFvPatchScalarField
+:
+    public fixedValueFvPatchScalarField
+{
+
+public:
+
+    //- Runtime type information
+    TypeName("${typeName}");
+
+
+    // Constructors
+
+        //- Construct from patch and internal field
+        ${typeName}FixedValueFvPatchScalarField
+        (
+            const fvPatch&,
+            const DimensionedField<scalar, volMesh>&
+        );
+
+        //- Construct from patch, internal field and dictionary
+        ${typeName}FixedValueFvPatchScalarField
+        (
+            const fvPatch&,
+            const DimensionedField<scalar, volMesh>&,
+            const dictionary&
+        );
+
+        //- Construct by mapping given
+        //  ${typeName}FixedValueFvPatchScalarField
+        //  onto a new patch
+        ${typeName}FixedValueFvPatchScalarField
+        (
+            const ${typeName}FixedValueFvPatchScalarField&,
+            const fvPatch&,
+            const DimensionedField<scalar, volMesh>&,
+            const fvPatchFieldMapper&
+        );
+
+        //- Construct as copy
+        ${typeName}FixedValueFvPatchScalarField
+        (
+            const ${typeName}FixedValueFvPatchScalarField&
+        );
+
+        //- Construct and return a clone
+        virtual tmp<fvPatchScalarField> clone() const
+        {
+            return tmp<fvPatchScalarField>
+            (
+                new ${typeName}FixedValueFvPatchScalarField(*this)
+            );
+        }
+
+        //- Construct as copy setting internal field reference
+        ${typeName}FixedValueFvPatchScalarField
+        (
+            const ${typeName}FixedValueFvPatchScalarField&,
+            const DimensionedField<scalar, volMesh>&
+        );
+
+        //- Construct and return a clone setting internal field reference
+        virtual tmp<fvPatchScalarField> clone
+        (
+            const DimensionedField<scalar, volMesh>& iF
+        ) const
+        {
+            return tmp<fvPatchScalarField>
+            (
+                new ${typeName}FixedValueFvPatchScalarField(*this, iF)
+            );
+        }
+
+
+    // Member functions
+
+        // Evaluation functions
+
+            //- Update the coefficients associated with the patch field
+            virtual void updateCoeffs();
+};
+
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+} // End namespace Foam
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+#endif
+
+// ************************************************************************* //
diff --git a/etc/settings.csh b/etc/settings.csh
index 0113cc99a55..a48a1883824 100644
--- a/etc/settings.csh
+++ b/etc/settings.csh
@@ -63,6 +63,9 @@ setenv FOAM_SITE_LIBBIN $WM_PROJECT_INST_DIR/site/$WM_PROJECT_VERSION/platforms/
 setenv FOAM_USER_APPBIN $WM_PROJECT_USER_DIR/platforms/$WM_OPTIONS/bin
 setenv FOAM_USER_LIBBIN $WM_PROJECT_USER_DIR/platforms/$WM_OPTIONS/lib
 
+# codeStream templates
+setenv FOAM_CODESTREAM_TEMPLATE_DIR $WM_PROJECT_DIR/etc/codeTemplates/codeStream
+
 # convenience
 setenv FOAM_APP $WM_PROJECT_DIR/applications
 #setenv FOAM_LIB $WM_PROJECT_DIR/lib
diff --git a/etc/settings.sh b/etc/settings.sh
index aca41877288..9281ffba952 100644
--- a/etc/settings.sh
+++ b/etc/settings.sh
@@ -86,6 +86,9 @@ export FOAM_SITE_LIBBIN=$WM_PROJECT_INST_DIR/site/$WM_PROJECT_VERSION/platforms/
 export FOAM_USER_APPBIN=$WM_PROJECT_USER_DIR/platforms/$WM_OPTIONS/bin
 export FOAM_USER_LIBBIN=$WM_PROJECT_USER_DIR/platforms/$WM_OPTIONS/lib
 
+# codeStream templates
+export FOAM_CODESTREAM_TEMPLATE_DIR=$WM_PROJECT_DIR/etc/codeTemplates/codeStream
+
 # convenience
 export FOAM_APP=$WM_PROJECT_DIR/applications
 #export FOAM_LIB=$WM_PROJECT_DIR/lib
diff --git a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C
index 08f61902b83..297430715a0 100644
--- a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C
+++ b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C
@@ -143,14 +143,18 @@ bool Foam::functionEntries::codeStream::execute
             {
                 Info<< "Creating new library in " << libPath << endl;
 
-                fileName templates(Foam::getEnv("OTF_TEMPLATE_DIR"));
+                fileName templates
+                (
+                    Foam::getEnv("FOAM_CODESTREAM_TEMPLATE_DIR")
+                );
                 if (!templates.size())
                 {
                     FatalIOErrorIn
                     (
                         "functionEntries::codeStream::execute(..)",
                         parentDict
-                    )   << "Please set environment variable OTF_TEMPLATE_DIR"
+                    )   << "Please set environment variable"
+                        " FOAM_CODESTREAM_TEMPLATE_DIR"
                         << " to point to the location of codeStreamTemplate.C"
                         << exit(FatalIOError);
                 }
@@ -158,8 +162,8 @@ bool Foam::functionEntries::codeStream::execute
                 List<fileAndVars> copyFiles(1);
                 copyFiles[0].first() = templates/"codeStreamTemplate.C";
                 stringPairList bodyVars(2);
-                bodyVars[0] = Pair<string>("OTF_INCLUDES", codeInclude);
-                bodyVars[1] = Pair<string>("OTF_BODY", code);
+                bodyVars[0] = Pair<string>("codeInclude", codeInclude);
+                bodyVars[1] = Pair<string>("code", code);
                 copyFiles[0].second() = bodyVars;
 
                 List<fileAndContent> filesContents(2);
diff --git a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStreamTools.C b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStreamTools.C
index 23041274338..1667d2be4e7 100644
--- a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStreamTools.C
+++ b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStreamTools.C
@@ -149,8 +149,8 @@ bool Foam::codeStreamTools::copyFilesContents(const fileName& dir) const
     // Create dir
     mkDir(dir);
 
-    //Info<< "Setting envvar OTF_TYPENAME=" << name_ << endl;
-    setEnv("OTF_TYPENAME", name_, true);
+    //Info<< "Setting envvar typeName=" << name_ << endl;
+    setEnv("typeName", name_, true);
     // Copy any template files
     forAll(copyFiles_, i)
     {
diff --git a/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchScalarField.C b/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchScalarField.C
index 388d013b553..d7f7c3594b6 100644
--- a/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchScalarField.C
+++ b/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchScalarField.C
@@ -78,14 +78,15 @@ void Foam::codedFixedValueFvPatchScalarField::writeLibrary
     // Write files for new library
     if (Pstream::master())
     {
-        fileName templates(Foam::getEnv("OTF_TEMPLATE_DIR"));
+        fileName templates(Foam::getEnv("FOAM_CODESTREAM_TEMPLATE_DIR"));
         if (!templates.size())
         {
             FatalIOErrorIn
             (
                 "codedFixedValueFvPatchScalarField::writeLibrary(..)",
                 dict
-            )   << "Please set environment variable OTF_TEMPLATE_DIR"
+            )   << "Please set environment variable"
+                << " FOAM_CODESTREAM_TEMPLATE_DIR"
                 << " to point to the location of "
                 << "fixedValueFvPatchScalarFieldTemplate.C"
                 << exit(FatalIOError);
@@ -112,8 +113,8 @@ void Foam::codedFixedValueFvPatchScalarField::writeLibrary
             templates/"fixedValueFvPatchScalarFieldTemplate.C";
 
         copyFiles[0].second().setSize(2);
-        copyFiles[0].second()[0] = Pair<string>("OTF_INCLUDES", codeInclude);
-        copyFiles[0].second()[1] = Pair<string>("OTF_UPDATECOEFFS", code);
+        copyFiles[0].second()[0] = Pair<string>("codeInclude", codeInclude);
+        copyFiles[0].second()[1] = Pair<string>("code", code);
 
         copyFiles[1].first() =
             templates/"fixedValueFvPatchScalarFieldTemplate.H";
diff --git a/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchScalarField.H b/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchScalarField.H
index f3d6740e91d..9b3ed6debf9 100644
--- a/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchScalarField.H
+++ b/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchScalarField.H
@@ -35,7 +35,7 @@ Description
 
         movingWall
         {
-            type            codedFixedValue;
+            type            codedFixedValue<scalar>;
             value           uniform 0;
             redirectType    rampedFixedValue;   // name of generated bc
 
@@ -118,7 +118,7 @@ class codedFixedValueFvPatchScalarField
 public:
 
     //- Runtime type information
-    TypeName("codedFixedValue");
+    TypeName("codedFixedValue<scalar>");
 
 
     // Constructors
-- 
GitLab