CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Bugs

Foam::pow() function not working with integer fraction

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 10, 2009, 11:18
Default Foam::pow() function not working with integer fraction
  #1
New Member
 
Dominik Christ
Join Date: Mar 2009
Posts: 28
Rep Power: 17
dominik_christ is on a distinguished road
Hello everyone,
the following bug is present in both OF1.5 and OF1.6:

You would expect the following functions to return the same value

Info << pow(turbulence->epsilon(), (1./2.) );
Info << pow(turbulence->epsilon(), (1/2) );

Both compile without error or warning. However, the second line only returns the value 1 in all fields. The first line returns the square root of the epsilon field just as expected.

NB: This bug does not occur with plain integers, so
Info << pow(turbulence->epsilon(), 2. );
Info << pow(turbulence->epsilon(), 2 );
will give you the same (correct) result.

Regards,
Dominik Christ

P.S.: As this is such a fundamental function, I wonder why it passed unnoticed for so long ...
dominik_christ is offline   Reply With Quote

Old   September 10, 2009, 13:11
Default
  #2
Senior Member
 
Mattijs Janssens
Join Date: Mar 2009
Posts: 1,419
Rep Power: 26
mattijs is on a distinguished road
The compiler will evaluate 1/2 as integer division. Hence it will be doing a pow(.., 0) which returns 1 as it should. Apart from this you could also use sqrt or sqr.
mattijs is offline   Reply With Quote

Old   September 10, 2009, 14:32
Default
  #3
New Member
 
Dominik Christ
Join Date: Mar 2009
Posts: 28
Rep Power: 17
dominik_christ is on a distinguished road
Oh, of course, that's the reason.
Thanks Mattijs for pointing that out to me!
dominik_christ is offline   Reply With Quote

Old   August 6, 2015, 13:19
Default
  #4
New Member
 
Sandip Wadekar
Join Date: Oct 2014
Posts: 17
Rep Power: 12
wadekar is on a distinguished road
Hello

I am also struggling with same problem, but i want to do the power (1/3).

Code:
scalar rad = Foam::pow(Vol,1.0/3.0);
Vol is a scalar.

My main problem is that- when i using
Code:
scalar rad = Foam::pow(Vol,1.0/3.0);
then it gives right result without any problem, but its not running in parallel.

And, when i used
Code:
 scalar rad = Foam::pow(Vol,1/3);
then i am getting 1, but code is running in parallel.
wadekar is offline   Reply With Quote

Reply

Tags
bug, fraction, integer, pow


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems in compiling paraview in Suse 10.3 platform chiven OpenFOAM Installation 3 December 1, 2009 08:21
force function not working in OF 1.6 franzisko OpenFOAM 3 August 4, 2009 15:24
Differences between serial and parallel runs carsten OpenFOAM Bugs 11 September 12, 2008 12:16
OpenFoam 14 installation problem gfcoppola OpenFOAM Installation 20 November 2, 2007 14:38
DecomposePar links against liblamso0 with OpenMPI jens_klostermann OpenFOAM Bugs 11 June 28, 2007 18:51


All times are GMT -4. The time now is 14:49.