Getting more out of system/controlDict

With OpenFOAM-1.6, the functions entry in system/controlDict changed from being a primitive entry to a dictionary entry. Even although the old format is still supported, the added flexibility of the dictionary entry means that you probably should be using the new form.

Previously

// system/controlDict

functions
(
    function1
    {
        type ...;
        settings ...;
    }
    function2
    {
        type ...;
        settings ...;
    }
    function3
    {
        type ...;
        settings ...;
    }
);

If you wanted to somehow centralized the values, for example, for an easier setup, you’d have a problem.

Now

Using dictionary entries, you can harness the #include dictionary directive combined with the "~OpenFOAM/" expansion for much easier configuration:

// system/controlDict

#include  "~OpenFOAM/system/controlDict/steadyState"
#include  "~OpenFOAM/system/controlDict/function1"
#include  "~OpenFOAM/system/controlDict/function2"
#include  "~OpenFOAM/system/controlDict/function3"

functions
{
    function1
    {
        settings mergeCustom;
    }
}

where the files are found under the usual expansion hierarchy and can thus be defined on a per-user basis or for the entire site. We also added in some default steadyState settings while we were at it.

In this example we also took advantage of the dictionary merge functionality to first include the function1, and then subsequently merge in some custom values into it.

If we also remember about the little-used #remove dictionary directive, we can even write something like this:

functions
{
    #remove function3
}

which can be included like this:

#include  "~OpenFOAM/system/controlDict/noFunction3"

to remove particular elements again.

In addition to the extra flexibility, the new dictionary form is internally slightly more efficient too.

Note added 2009-12-10.
The #remove directive currently does not actually work as I suggested, since the remove action is restricted to the current dictionary scope and thus does not affect other dictionary contents when merged. For example,
    dict
    {
       foo xxx;
       bar yyy;
    }

    dict
    {
       baz zzz;
       #remove foo
    }
This only removes 'foo' from the current scope (the second dict), since it occurs before the dictionary merge does.
02 Nov 2009 | OpenFOAM