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

The precision of "Foam::pow"?

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree1Likes
  • 1 Post By Henning86

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 28, 2015, 12:25
Default The precision of "Foam::pow"?
  #1
Senior Member
 
Dongyue Li
Join Date: Jun 2012
Location: Beijing, China
Posts: 838
Rep Power: 17
sharonyue is on a distinguished road
Hello guys,

I use OpenFOAM to do a simple calculation:

Code:
             scalar z = Foam::exp(Foam::sqr(0.544830258187397)/2.0);
             Info<<"z = "<<z<<endl;
             Info<<"z 16= "<<Foam::pow(z, 16.0)<<endl;
This is the output:

Code:
z = 1.16
z 16= 10.748
However, especially this z, it should be 1.16219666037989. Then my z16 will be 11.0783.

This is what I got from matlab:
Code:
z = 1.1621966603798944501
z6 = 11.0783
How can I handle this? if I use z with 1.16, z16 is not precise.

Thanks guys.
__________________
My OpenFOAM algorithm website: http://dyfluid.com
By far the largest Chinese CFD-based forum: http://www.cfd-china.com/category/6/openfoam
We provide lots of clusters to Chinese customers, and we are considering to do business overseas: http://dyfluid.com/DMCmodel.html
sharonyue is offline   Reply With Quote

Old   September 28, 2015, 12:31
Default
  #2
Member
 
Join Date: Nov 2012
Posts: 83
Rep Power: 13
Henning86 is on a distinguished road
does it change if you change the writePrecision in the controlDict?
Henning86 is offline   Reply With Quote

Old   September 28, 2015, 12:38
Default
  #3
Senior Member
 
Dongyue Li
Join Date: Jun 2012
Location: Beijing, China
Posts: 838
Rep Power: 17
sharonyue is on a distinguished road
update, sorry, sorry, I have a typo in my code....Its my fault not the code

------------------------------------------------------------------


Quote:
Originally Posted by Henning86 View Post
does it change if you change the writePrecision in the controlDict?
Hi,

yeah, I tried in my complete solver to debug, it does not have any effect.

And this code above (just a test) does not need controlDict file..

Code:
#include "fvCFD.H"

int main()
{
             double sigma = 0.544830258187397;
	Info<<"sigma = "<<sigma<<endl;
	Info<<"Foam::sqr(sigma)/2.0 ="<<Foam::sqr(0.544830258187397)/2.0<<endl;
	Info<<"Foam::exp(Foam::sqr(sigma)/2.0) = "<<Foam::exp(Foam::sqr(sigma)/2.0)<<endl;
	double z = Foam::exp(Foam::sqr(sigma)/2.0);
        Info<<"Foam::pow(ans, 16) = "<<Foam::pow(z, 16.0)<<endl;
}
Code:
sigma = 0.54483
Foam::sqr(sigma)/2.0 =0.14842
Foam::exp(Foam::sqr(sigma)/2.0) = 1.16 //????????????????
Foam::pow(ans, 16) = 10.748

The key of this problem is: this function:

Foam::exp(Foam::sqr(0.544830258187397)/2.0)

is 1.16.

But it should be 1.16219666037989
__________________
My OpenFOAM algorithm website: http://dyfluid.com
By far the largest Chinese CFD-based forum: http://www.cfd-china.com/category/6/openfoam
We provide lots of clusters to Chinese customers, and we are considering to do business overseas: http://dyfluid.com/DMCmodel.html
sharonyue is offline   Reply With Quote

Old   September 29, 2015, 09:02
Default
  #4
Member
 
Join Date: Nov 2012
Posts: 83
Rep Power: 13
Henning86 is on a distinguished road
The problem is probably the Info command

try Info.precision(16) i dont know what the exact command is.


google "precision cout". the message stream class should be similar
rarnaunot likes this.
Henning86 is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Single precision better than double precision? 140raiders CFX 1 July 30, 2015 03:32
Double precision does not converge, Single precision does jmmichie Main CFD Forum 0 May 7, 2015 09:16
[ANSYS Meshing] ICEM output precision papis ANSYS Meshing & Geometry 4 July 9, 2013 10:54
Number of elements x double precision matheusguzella ANSYS Meshing & Geometry 2 October 7, 2009 11:15
what's wrong about my code for 2d burgers equation morxio Main CFD Forum 3 April 27, 2007 11:38


All times are GMT -4. The time now is 05:11.