Skip to content

foamDictionary -set overwrites whole dictionary

Summary

Whenever foamDictionary is used to set the value of any one entry, the whole dictionary is overwritten. Any dynamic calculations are replaced with their constant value at the time this overwrite occurs. Comments are also lost.

Steps to reproduce

Have a dictionary file with comments and/or #eval lines. Use foamDictionary -set to alter a value.

Example case

This file is system/example:

/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  v1912                                 |
|   \\  /    A nd           | Website:  www.openfoam.com                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version         2;
    format          ascii;
    class           dictionary;
    location        "system";
    object          example;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

constant        5;//There is a clever physical explanation for this value

calculated      #eval{ 1 + 1 };

changed         1;


// ************************************************************************* //

Execute foamDictionary system/example -entry changed -set 2

What is the current bug behaviour?

The file becomes:

/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  v1912                                 |
|   \\  /    A nd           | Website:  www.openfoam.com                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
FoamFile
{
    version         2;
    format          ascii;
    class           dictionary;
    location        "system";
    object          example;
}

constant        5;

calculated      2;

changed         2;


// ************************************************************************* //

What is the expected correct behavior?

The file becomes:

/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  v1912                                 |
|   \\  /    A nd           | Website:  www.openfoam.com                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version         2;
    format          ascii;
    class           dictionary;
    location        "system";
    object          example;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

constant        5;//There is a clever physical explanation for this value

calculated      #eval{ 1 + 1 };

changed         2;


// ************************************************************************* //

Relevant logs and/or images

Environment information

  • OpenFOAM version :1912 (compiled from source)
  • Operating system :Ubuntu 18.04
  • Hardware info :
  • Compiler :

Possible fixes