View Issue Details

IDProjectCategoryView StatusLast Update
0003622OpenFOAMBugpublic2021-02-04 17:06
ReportermarniemannAssigned Tohenry 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
PlatformGNU/LinuxOSUbuntu 18.04OS Version(please specify)
Product Version8 
Fixed in Version8 
Summary0003622: Variable caluclation fails for divisions
DescriptionCalculating variables using the #calc statement fails for divisions, if the slash operator is not separated by spaces.
Example:

a 1;
b 2;
c #calc "$a / $b"; // works
d #calc "$a+$b"; // works
e #calc "$a/$b"; // does NOT work

The last statement to compute variable e leads to a declaration error: ‘$a’ was not declared in this scope
Since the last statement was still valid in OpenFOAM-6, I assume (but am not sure) that the issue might stem from this new feature:
https://github.com/OpenFOAM/OpenFOAM-dev/commit/a7b842569064ede1574a77210b731904a206182a
TagsNo tags attached.

Activities

henry

2021-02-04 17:05

manager   ~0011843

I have updated the documentation for #calc:

Class
    Foam::functionEntries::calcEntry

Description
    Uses dynamic compilation to provide calculating functionality
    for entering dictionary entries.

    E.g.

    \verbatim
    a 1.0;
    b 3;
    c #calc "$a*$b";
    \endverbatim

    Note the explicit trailing 0 ('1.0') to force a to be read (and written)
    as a floating point number.

    Special care is required for calc entries that include a division since
    "/" is also used as the scoping operator to identify keywords in
    sub-dictionaries. For example, "$a/b" expects a keyword "b" within a
    sub-dictionary named "a". A division can be correctly executed by using a
    space between a variables and "/", e.g.

    \verbatim
    c #calc "$a / $b";
    \endverbatim

    or "()" scoping around the variable, e.g.

    \verbatim
    c #calc "($a)/$b";
    \endverbatim

henry

2021-02-04 17:06

manager   ~0011844

Resolved by commit 2d9c05f8cb5d52a35dc7068c5d268d8b995d9f95

Issue History

Date Modified Username Field Change
2021-02-04 16:16 marniemann New Issue
2021-02-04 17:05 henry Note Added: 0011843
2021-02-04 17:06 henry Assigned To => henry
2021-02-04 17:06 henry Status new => resolved
2021-02-04 17:06 henry Resolution open => fixed
2021-02-04 17:06 henry Fixed in Version => 8
2021-02-04 17:06 henry Note Added: 0011844