CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Pre-Processing (https://www.cfd-online.com/Forums/openfoam-pre-processing/)
-   -   changeDictionary messes it up when #include directive is used (https://www.cfd-online.com/Forums/openfoam-pre-processing/147943-changedictionary-messes-up-when-include-directive-used.html)

zfaraday February 1, 2015 22:34

changeDictionary messes it up when #include directive is used
 
Hello,

I'm working in a chtMultiRegion case and, as it is usual in these kind of cases, I have to use changeDictionary to set up boundaries after creating the geometry with blockMesh and topoSet. So far, no problem. However, in this case I want to make use of the #include directive in order to use some values stored in a particular folder. I want to do that because some values are very common among all regions (and they are a few...) and I have to do a good amount of simulations switching them, so if I could only change the values from the file stored in an outter folder it would be very nice...

The problem is that it seems that changeDictionary is not capable to handle the #include statement. I will show you how I used it and the results it gave me:

·changeDictionaryDict where I used #include dirctive:

Code:

/*--------------------------------*- C++ -*----------------------------------*\
| =========                |                                                |
| \\      /  F ield        | OpenFOAM: The Open Source CFD Toolbox          |
|  \\    /  O peration    | Version:  2.3.0                                |
|  \\  /    A nd          | Web:      www.OpenFOAM.org                      |
|    \\/    M anipulation  |                                                |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version    2.0;
    format      ascii;
    class      dictionary;
    object      changeDictionaryDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
dictionaryReplacement
{
    boundary
    {
    }

    T
    {
        #include "$FOAM_CASE/include/initialCond_sum"
        internalField  uniform $Tini;

        boundaryField
        {
            ".*"
            {
                type            symmetry;
                value          $internalField;
            }
      .....
}

And here comes the result in the 0/region/T file:

Code:

dimensions      [ 0 0 0 1 0 0 0 ];

internalField  uniform 300;

boundaryField
{
  ....
    patch[i]
    {
        type            externalWallHeatFluxTemperature;
        value          $internalField;
        kappa          solidThermo;
        Ta              uniform $Tin;
        h              uniform 2;
        thicknessLayers ( );
        kappaLayers    ( );
        kappaName      none;
        QrName          none;
    }
    ....
}

#include        "$FOAM_CASE/include/initialCond_sum" internalField uniform $Tini;

Of course OpenFOAM complains...

Code:

--> FOAM FATAL IO ERROR:
Illegal dictionary entry or environment variable name "Tin"
Valid dictionary entries are
3
(
type
value
kappa
)


file: path_to_ file 0/region/T.boundaryField.patch[i] from line 36 to line 38.

    From function primitiveEntry::expandVariable(const string&, const dictionary&
    in file db/dictionary/primitiveEntry/primitiveEntry.C at line 96.

FOAM exiting

Why is the utility placing the #include statement at the end of the file instead of the beginning where it is suposed to be placed? Is it a bug or am I doing something wrong? Is there a procedure to make this utility take into account the #include statement correctly?

I also tried to put the statement in an upper position like outside the T keyword or even above the dictionaryReplacement keyword, but OpenFOAM complained either way. Actually, in any of the last cases the utility crushes and no dictionary is replaced.

Any word of advice will be very welcome.

Regards,

Alex

zfaraday February 4, 2015 18:05

Not trying to spam, just asking...
 
Any idea on what the problem could be? Or directly changeDictionary utility can not handle properly the #include directive? May it be a bug?

wyldckat February 5, 2015 15:09

Hi Alex,

If you run changeDictionary with the "-help" option, you should see this line:
Code:

  -literalRE        treat regular expressions literally (i.e., as a keyword)
If I remember correctly, by using this option, it will copy-paste the "#include" lines.

Let us know if this works as intended. I do vaguely remember having problems with this as well in the past, but it was with an older version of OpenFOAM... not sure which one.

Best regards,
Bruno

zfaraday February 5, 2015 19:26

Quote:

Originally Posted by wyldckat (Post 530607)
Hi Alex,

If you run changeDictionary with the "-help" option, you should see this line:
Code:

  -literalRE        treat regular expressions literally (i.e., as a keyword)
If I remember correctly, by using this option, it will copy-paste the "#include" lines.

Let us know if this works as intended. I do vaguely remember having problems with this as well in the past, but it was with an older version of OpenFOAM... not sure which one.

Best regards,
Bruno

Hi Bruno,

Thanks for your tip. However, after running the command changeDictionary -help the correct options seems to be

Code:

  -enableFunctionEntries      enables expansion of dictionary directives - #include, #codeStream etc
It does not copy-paste the #include statement literaly but it substitute its values in the new dictionary!

Regards,

Alex

wyldckat February 6, 2015 08:50

Quick question: Which OpenFOAM version are you using?

zfaraday February 6, 2015 10:59

Quick answer :p : I'm using 2.3.x version

wyldckat February 7, 2015 03:33

Hi Alex,

Sorry, I re-read now the post you had written and yesterday I thought you were still having problems in using changeDictionary.
I quickly had thought of this because that option is provided on older versions of OpenFOAM and I very vaguely remember that the option "-enableFunctionEntries" didn't always work as intended... mmm, possibly because back then I actually wanted to preserve the original includes...

Anyway, I'm glad you've figured out the option you needed :)

Best regards,
Bruno

zfaraday February 7, 2015 14:06

Quote:

Originally Posted by wyldckat (Post 530796)
Hi Alex,

Sorry, I re-read now the post you had written and yesterday I thought you were still having problems in using changeDictionary.
I quickly had thought of this because that option is provided on older versions of OpenFOAM and I very vaguely remember that the option "-enableFunctionEntries" didn't always work as intended... mmm, possibly because back then I actually wanted to preserve the original includes...

Anyway, I'm glad you've figured out the option you needed :)

Best regards,
Bruno

Hi Bruno,

I also wanted that the include line was copy-pasted literally instead of substituting its values in the new dictionary, but as far as I saw the effect is the same since the macro substitution is done correctly.

I also tried to use both "-enableFunctionEntries" and "-literalRE" at a time, the problem is that as it copy-pastes literally the regular expressions instead of interpreting them. Thus, it copied the character ".*" directly to the new file so all the boundaries that were to be found under the ".*" were changed to "calculated" instead...

Best regards,

Alex


All times are GMT -4. The time now is 19:36.