View Issue Details

IDProjectCategoryView StatusLast Update
0002441OpenFOAMBugpublic2017-02-03 21:18
ReporterSamMallinson Assigned Tohenry  
PrioritynormalSeveritymajorReproducibilityalways
Status resolvedResolutionfixed 
PlatformLinux version 4.3.0-1-amd64 OSdebianOS Versiontesting stretch
Summary0002441: codeStream functionality in controlDict seems to be broken
DescriptionPrior to OF-4.x, we would use a codeStream included inside the controlDict to, for eg., calculate and output some values at each output time.

When we run the same code (tweaked for OF-4.x changes**), then there is no output. See Additional Information for extra details. Question: is this a bug in the generation of dynamic code in OpenFOAM-4.x, or has something been omitted here?

===

** in 3.0.x, we had
      outputControl outputTime;

in 4.x, we got this message:

    Using deprecated 'outputControl'
    Please use 'writeControl' with 'writeInterval'

and so we changed to

     writeControl timeStep;
     writeInterval 20;
Steps To Reproduce1. run attached cases (modification of lid-driven cavity problem in icoFoam)
- in the zip file, there are two tar-balls, one for 3.0.x, one for 4.x
2. look at the output
Additional InformationFor the post-processing, in 3.0.x, we added a file to the lid-driven cavity tutorial for icoFoam, system/kineticEnergyFunction, which contained the following:

functions
{
  kineticEnergy
    {
      functionObjectLibs ("libutilityFunctionObjects.so");
      type coded;
      outputControl outputTime;
      redirectType kineticEnergy;
      code
      #{
        const volVectorField& U = mesh().lookupObject<volVectorField>("U");
    dimensionedScalar ke = fvc::domainIntegrate(U & U) / 2;
        Info<< endl << "K.E./rho:" << ke << endl << endl;
      #};
    }
}

and then added the following line to system/controlDict:

#include "kineticEnergyFunction"

For 3.0.x, in the file dynamicCode/kineticEnergy/functionObjectTemplate.C, the kineticEnergyFunctionObject::write method contains the following:

//{{{ begin code
    #line 11 "/run/cavity/system/controlDict.functions.kineticEnergy"
        const volVectorField& U = mesh().lookupObject<volVectorField>("U");
        dimensionedScalar ke = fvc::domainIntegrate(U & U) / 2;
        Info<< endl << "K.E./rho:" << ke << endl << endl;
//}}} end code

whereas under 4.x, dynamicCode/kineticEnergy/functionObjectTemplate.C is empty

//{{{ begin code
                                                                                
//}}} end code

We found, however, if we manually copy the code from the 3.0.x case dynamicCode/kineticEnergy/functionObjectTemplate.C write method to the 4.x version of the file, it works fine.
TagscodeStream, functionObject

Activities

SamMallinson

2017-01-25 00:39

reporter  

wyldckat

2017-01-25 12:17

updater   ~0007663

@SamMallinson: A quick check of the case you provided for 4.x and the documentation for the "codedFunctionObject": http://cpp.openfoam.org/v4/a00297.html#details - and it seems like the first problem is that the "code" keyword change its name.

Specifically, there are now several possible coding opportunities, which are better listed here: http://cpp.openfoam.org/v4/a06447_source.html (there was a rendering bug in the HTML version)

Quoting from there:

    The entries are
        codeInclude : include files
        codeOptions : include paths; inserted into EXE_INC in Make/options
        codeLibs : link line; inserted into LIB_LIBS in Make/options
        codeData : c++; local member data (null constructed);
        localCode : c++; local static functions
        codeRead : c++; upon functionObject::read();
        codeExecute : c++;upon functionObject::execute();
        codeWrite : c++; upon functionObject::write()
        codeEnd : c++; upon functionObject::end();


Please try using either 'codeExecute' or 'codeWrite' and see if it works as intended, e.g.:

      codeExecute
      #{
        const volVectorField& U = mesh().lookupObject<volVectorField>("U");
        dimensionedScalar ke = fvc::domainIntegrate(U & U) / 2;
        Info<< endl << "K.E./rho:" << ke << endl << endl;
      #};

And please let us know if it works!


@Henry: We have a few issues here, which I can provide a patch sometime later on this week(end):

  1. The list in the details section is not rendered properly in the Doxygen generated page, not even in OpenFOAM-dev: http://openfoam.github.io/Documentation-dev/html/a24389.html#details

  2. Not having a check for when there are no "code*" keywords can lead to these kinds of bug reports. It should be enforced that at least one of the listed entries must be defined, otherwise either warn or throw an error message.

SamMallinson

2017-01-26 22:24

reporter   ~0007683

@wykldcat: I can confirm that codeExecute works in this case, outputting at every time step except for the last:

Time = 0.495

Courant Number mean: 0.222158 max: 0.852134
smoothSolver: Solving for Ux, Initial residual = 2.43518e-07, Final residual = 2.43518e-07, No Iterations 0
smoothSolver: Solving for Uy, Initial residual = 5.33314e-07, Final residual = 5.33314e-07, No Iterations 0
DICPCG: Solving for p, Initial residual = 5.25763e-07, Final residual = 5.25763e-07, No Iterations 0
time step continuity errors : sum local = 6.11228e-09, global = 1.51821e-18, cumulative = 1.09644e-17
DICPCG: Solving for p, Initial residual = 7.01015e-07, Final residual = 7.01015e-07, No Iterations 0
time step continuity errors : sum local = 7.5484e-09, global = -4.1723e-19, cumulative = 1.05471e-17
ExecutionTime = 0.14 s ClockTime = 0 s


K.E./rho:(domainIntegrate((U&U))|2) [0 5 -2 0 0 0 0] 3.16144e-06

Time = 0.5

Courant Number mean: 0.222158 max: 0.852134
smoothSolver: Solving for Ux, Initial residual = 2.3091e-07, Final residual = 2.3091e-07, No Iterations 0
smoothSolver: Solving for Uy, Initial residual = 5.0684e-07, Final residual = 5.0684e-07, No Iterations 0
DICPCG: Solving for p, Initial residual = 8.63844e-07, Final residual = 8.63844e-07, No Iterations 0
time step continuity errors : sum local = 8.8828e-09, global = 4.94571e-19, cumulative = 1.10417e-17
DICPCG: Solving for p, Initial residual = 9.59103e-07, Final residual = 9.59103e-07, No Iterations 0
time step continuity errors : sum local = 9.66354e-09, global = 1.13175e-18, cumulative = 1.21735e-17
ExecutionTime = 0.15 s ClockTime = 0 s

End

wyldckat

2017-01-28 15:17

updater  

bug2441_v1.tar.gz (3,363 bytes)

wyldckat

2017-01-28 15:17

updater  

bug2441_v1.patch (3,349 bytes)   
diff --git a/src/functionObjects/utilities/codedFunctionObject/codedFunctionObject.C b/src/functionObjects/utilities/codedFunctionObject/codedFunctionObject.C
index 33d2227..aa2d564 100644
--- a/src/functionObjects/utilities/codedFunctionObject/codedFunctionObject.C
+++ b/src/functionObjects/utilities/codedFunctionObject/codedFunctionObject.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2011-2017 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -284,6 +284,16 @@ bool Foam::codedFunctionObject::read(const dictionary& dict)
         );
     }
 
+    if(!dataPtr && !readPtr && !execPtr && !writePtr && !endPtr)
+    {
+        IOWarningInFunction
+        (
+            dict
+        )   << "No critical \"code\" prefixed keywords were found."
+            << " Please check the code documentation for more details."
+            << nl << endl;
+    }
+
     updateLibrary(name_);
     return redirectFunctionObject().read(dict);
 }
diff --git a/src/functionObjects/utilities/codedFunctionObject/codedFunctionObject.H b/src/functionObjects/utilities/codedFunctionObject/codedFunctionObject.H
index b79144c..c58bdc4 100644
--- a/src/functionObjects/utilities/codedFunctionObject/codedFunctionObject.H
+++ b/src/functionObjects/utilities/codedFunctionObject/codedFunctionObject.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2011-2017 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -31,16 +31,18 @@ Description
     This function object provides a general interface to enable dynamic code
     compilation.
 
-    The entries are
-        codeInclude : include files
-        codeOptions : include paths; inserted into EXE_INC in Make/options
-        codeLibs    : link line; inserted into LIB_LIBS in Make/options
-        codeData    : c++; local member data (null constructed);
-        localCode   : c++; local static functions
-        codeRead    : c++; upon functionObject::read();
-        codeExecute : c++;upon functionObject::execute();
-        codeWrite   : c++; upon functionObject::write()
-        codeEnd     : c++; upon functionObject::end();
+    The entries are:
+    \plaintable
+       codeInclude | include files
+       codeOptions | include paths; inserted into EXE_INC in Make/options
+       codeLibs    | link line; inserted into LIB_LIBS in Make/options
+       codeData    | c++; local member data (null constructed);
+       localCode   | c++; local static functions;
+       codeRead    | c++; upon functionObject::read();
+       codeExecute | c++; upon functionObject::execute();
+       codeWrite   | c++; upon functionObject::write()
+       codeEnd     | c++; upon functionObject::end();
+    \endplaintable
 
     Example of function object specification:
     \verbatim
bug2441_v1.patch (3,349 bytes)   

wyldckat

2017-01-28 15:21

updater   ~0007684

@SamMallinson: Many thanks for confirming this!

Please ignore the "bug2441_v1.*" files for now. I only remembered to check how they adapted from 4.x to OpenFOAM-dev after attaching :(
I'll have the correct v2 patches up in a few more minutes.

wyldckat

2017-01-28 15:27

updater  

bugfix_2441_v2.patch (3,330 bytes)   
diff --git a/src/functionObjects/utilities/codedFunctionObject/codedFunctionObject.C b/src/functionObjects/utilities/codedFunctionObject/codedFunctionObject.C
index c676703..16a11b1 100644
--- a/src/functionObjects/utilities/codedFunctionObject/codedFunctionObject.C
+++ b/src/functionObjects/utilities/codedFunctionObject/codedFunctionObject.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2011-2017 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -284,6 +284,16 @@ bool Foam::codedFunctionObject::read(const dictionary& dict)
         );
     }
 
+    if(!dataPtr && !readPtr && !execPtr && !writePtr && !endPtr)
+    {
+        IOWarningInFunction
+        (
+            dict
+        )   << "No critical \"code\" prefixed keywords were found."
+            << " Please check the code documentation for more details."
+            << nl << endl;
+    }
+
     updateLibrary(name_);
     return redirectFunctionObject().read(dict);
 }
diff --git a/src/functionObjects/utilities/codedFunctionObject/codedFunctionObject.H b/src/functionObjects/utilities/codedFunctionObject/codedFunctionObject.H
index e57e241..bc949c9 100644
--- a/src/functionObjects/utilities/codedFunctionObject/codedFunctionObject.H
+++ b/src/functionObjects/utilities/codedFunctionObject/codedFunctionObject.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2011-2017 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -30,16 +30,18 @@ Group
 Description
     Provides a general interface to enable dynamic code compilation.
 
-    The entries are
-        codeInclude : include files
-        codeOptions : include paths; inserted into EXE_INC in Make/options
-        codeLibs    : link line; inserted into LIB_LIBS in Make/options
-        codeData    : c++; local member data (null constructed);
-        localCode   : c++; local static functions
-        codeRead    : c++; upon functionObject::read();
-        codeExecute : c++;upon functionObject::execute();
-        codeWrite   : c++; upon functionObject::write()
-        codeEnd     : c++; upon functionObject::end();
+    The entries are:
+    \plaintable
+       codeInclude | include files
+       codeOptions | include paths; inserted into EXE_INC in Make/options
+       codeLibs    | link line; inserted into LIB_LIBS in Make/options
+       codeData    | c++; local member data (null constructed);
+       localCode   | c++; local static functions;
+       codeRead    | c++; upon functionObject::read();
+       codeExecute | c++; upon functionObject::execute();
+       codeWrite   | c++; upon functionObject::write()
+       codeEnd     | c++; upon functionObject::end();
+    \endplaintable
 
     Example of function object specification:
     \verbatim
bugfix_2441_v2.patch (3,330 bytes)   

wyldckat

2017-01-28 15:27

updater  

bugfix_2441_v2.tar.gz (3,361 bytes)

wyldckat

2017-01-28 15:37

updater   ~0007685

@Henry: Please find in attachment the following two files that can be applied to both OpenFOAM 4.x and OpenFOAM-dev:

  - "bugfix_2441_v2.patch" - Diff/patch file for easier inspection of the changes provided with these two file. It's indexed to OpenFOAM-dev (last commit 0dd9616dc), which has a few more description fixes that 4.x didn't have.

  - "bugfix_2441_v2.tar.gz" - this provides the following two files:

    - src/functionObjects/utilities/codedFunctionObject/codedFunctionObject.C
    - src/functionObjects/utilities/codedFunctionObject/codedFunctionObject.H

The changes made were:

  - Changed the list in the description from a simple indented line list to a '\plaintable', following the same trend as others. I didn't use the '\vartable', given that table format has been used for describing variables in functions, whereas the plain table is used for listing options, e.g. in "functionObjects/field/streamLine/streamLine.H".

  - A warning message has been added near the end of the 'read()' method, in order to provide some information to the user, which would have potentially helped to avoid the need for this bug report. I used the 'IOWarningInFunction', because it also points out where in the dictionary it failed to find the 'code' prefixed entries.

henry

2017-01-28 18:11

manager   ~0007688

Last edited: 2017-01-28 18:14

Thanks Bruno

Resolved in OpenFOAM-4.x by commit 54efb46f26bb3b34b790e9cedc1504239165640e

Resolved in OpenFOAM-dev by commit 6cf939eca388ae9f60193d69754ecd9ca589e847

Issue History

Date Modified Username Field Change
2017-01-25 00:39 SamMallinson New Issue
2017-01-25 00:39 SamMallinson File Added: lid_driven_cavity_30x_vs_4x.zip
2017-01-25 00:39 SamMallinson Tag Attached: functionObject
2017-01-25 00:39 SamMallinson Tag Attached: codeStream
2017-01-25 12:17 wyldckat Note Added: 0007663
2017-01-26 22:24 SamMallinson Note Added: 0007683
2017-01-28 15:17 wyldckat File Added: bug2441_v1.tar.gz
2017-01-28 15:17 wyldckat File Added: bug2441_v1.patch
2017-01-28 15:21 wyldckat Note Added: 0007684
2017-01-28 15:27 wyldckat File Added: bugfix_2441_v2.patch
2017-01-28 15:27 wyldckat File Added: bugfix_2441_v2.tar.gz
2017-01-28 15:37 wyldckat Note Added: 0007685
2017-01-28 15:37 wyldckat Assigned To => henry
2017-01-28 15:37 wyldckat Status new => assigned
2017-01-28 18:11 henry Status assigned => resolved
2017-01-28 18:11 henry Resolution open => fixed
2017-01-28 18:11 henry Fixed in Version => 4.x
2017-01-28 18:11 henry Note Added: 0007688
2017-01-28 18:14 henry Note Edited: 0007688