Skip to content

#eval and #calc rounding issues

Summary

the #eval function gives wrong results for small calculations. this can be highly troublesome as it is not something that one can 'see' easily.

Steps to reproduce

create a file with different eval commands and use foamDictionary to add an entry so it computes all the results.

Example case

create a file with following variables

dp #eval{ sqrt(3./2.) *1e-3}; 
a #eval{ 2/sqrt(2.)*$dp };
A_square #eval{ $a*$a };
A_inlet #eval{ $A_square-2*degToRad(180)*$dp*$dp*0.25 };
Q $A_inlet;
Qerror #eval{$A_inlet};
e #eval{0.2526944494428081};
Uin #eval{ $Q/($A_square*$e) };

run foamDictionary -entry edges -value file_test -set "( )" the evaluated file gives

dp              0.00122474;
a               0.00173241;
A_square        2.99982e-06;
A_inlet         6.42824e-07;
Q               6.42824e-07;
Qerror          1e-06;
e               0.252694;
Uin             1.31912;
edges           ( );

which are not all correct (it looks like rounding issue)

Environment information

  • OpenFOAM version :v2206
  • Operating system :centos
  • Hardware info :
  • Compiler :