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

is double precision default of OF?

Register Blogs Community New Posts Updated Threads Search

Like Tree25Likes
  • 9 Post By haakon
  • 5 Post By alberto
  • 3 Post By wyldckat
  • 1 Post By wyldckat
  • 4 Post By haakon
  • 2 Post By haakon
  • 1 Post By immortality

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 17, 2013, 09:17
Default is double precision default of OF?
  #1
Senior Member
 
immortality's Avatar
 
Ehsan
Join Date: Oct 2012
Location: Iran
Posts: 2,208
Rep Power: 27
immortality is on a distinguished road
can anyone answer me?
Thanks.
immortality is offline   Reply With Quote

Old   March 17, 2013, 18:23
Default
  #2
Senior Member
 
Join Date: Dec 2011
Posts: 111
Rep Power: 20
haakon will become famous soon enough
Yes, by default it is double precision. But you can change this at compile time by setting WM_PRECISION_OPTION=SP instead of WM_PRECISION_OPTION=DP in etc/bashrc before you compile. Anyways, that is not something I would recommend.
haakon is offline   Reply With Quote

Old   March 18, 2013, 02:13
Default
  #3
Senior Member
 
Alberto Passalacqua
Join Date: Mar 2009
Location: Ames, Iowa, United States
Posts: 1,912
Rep Power: 36
alberto will become famous soon enoughalberto will become famous soon enough
One comment: the calculation is done in double precision by default, but results are saved to disk typically with a precision of 6 digits. Use the binary format to preserve precision.

Best,
__________________
Alberto Passalacqua

GeekoCFD - A free distribution based on openSUSE 64 bit with CFD tools, including OpenFOAM. Available as in both physical and virtual formats (current status: http://albertopassalacqua.com/?p=1541)
OpenQBMM - An open-source implementation of quadrature-based moment methods.

To obtain more accurate answers, please specify the version of OpenFOAM you are using.
alberto is offline   Reply With Quote

Old   March 18, 2013, 05:44
Default
  #4
Senior Member
 
immortality's Avatar
 
Ehsan
Join Date: Oct 2012
Location: Iran
Posts: 2,208
Rep Power: 27
immortality is on a distinguished road
thank you dear Hacon and Alberto.
double precision is 14 digit after point,isn't?
When tolerances are set for example e-20 does it have any effect on accuracy of calculations since it's lower than DP criteria?
Thanks again.
immortality is offline   Reply With Quote

Old   March 18, 2013, 18:56
Default
  #5
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,981
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
Greetings to all!

Quote:
Originally Posted by immortality View Post
thank you dear Hacon and Alberto.
double precision is 14 digit after point,isn't?
When tolerances are set for example e-20 does it have any effect on accuracy of calculations since it's lower than DP criteria?
Thanks again.
It depends. Some extensive description is given here: http://en.wikipedia.org/wiki/Floatin...uracy_problems

In essence:
  • If you add 1.0 with 1e-20, you still get 1.0.
  • If you multiply 1.0 by 1e-20, you get 1e-20.
Usually, you shouldn't have any problems, since double precision works between e-308 and e+308. The problem only occurs if you have a simulation domain where in one corner you have very small values, e.g. 1e-20, while on the opposite corner you have very large values, e.g. 1e20.
If I'm not mistaken, this is where the continuity indicators help figure out how good or bad the solution is... but that's all I can remember

Best regards,
Bruno
__________________
wyldckat is offline   Reply With Quote

Old   March 21, 2013, 13:30
Default
  #6
Senior Member
 
immortality's Avatar
 
Ehsan
Join Date: Oct 2012
Location: Iran
Posts: 2,208
Rep Power: 27
immortality is on a distinguished road
thanks but I wonder then whats its relation to zero of machine thats about 1e-17 that must reached by continuity residuals?Is it a limit while DP can work with numbers very smaller than 1e-17?
immortality is offline   Reply With Quote

Old   March 21, 2013, 13:36
Default
  #7
Senior Member
 
immortality's Avatar
 
Ehsan
Join Date: Oct 2012
Location: Iran
Posts: 2,208
Rep Power: 27
immortality is on a distinguished road
I was curious about DP but didn't find it in etc/bashrc file.
immortality is offline   Reply With Quote

Old   March 24, 2013, 13:22
Default
  #8
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,981
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
Quick answers:
Quote:
Originally Posted by immortality View Post
thanks but I wonder then whats its relation to zero of machine thats about 1e-17 that must reached by continuity residuals?Is it a limit while DP can work with numbers very smaller than 1e-17?
Ah, that's probably due to EPS - http://en.wikipedia.org/wiki/Machine_epsilon - on the first table, you'll find this line:
Quote:
binary64 double precision double 2 53 (one bit is implicit) 2 -53 pow (2, -53) 1.11e-16
1.11e-16 is the eps for double precision.

Quote:
Originally Posted by immortality View Post
I was curious about DP but didn't find it in etc/bashrc file.
https://github.com/OpenFOAM/OpenFOAM...etc/bashrc#L75 - line 75!?


edit: "eps" is actually the name of the command on MATLAB that gives us this machine precision... it looks like it's not an acronym but it actually stands for "epsilon"
immortality likes this.
__________________

Last edited by wyldckat; March 24, 2013 at 13:49. Reason: see "edit:"
wyldckat is offline   Reply With Quote

Old   March 24, 2013, 13:49
Default
  #9
Senior Member
 
Join Date: Dec 2011
Posts: 111
Rep Power: 20
haakon will become famous soon enough
Quote:
Originally Posted by immortality View Post
thanks but I wonder then whats its relation to zero of machine thats about 1e-17 that must reached by continuity residuals?Is it a limit while DP can work with numbers very smaller than 1e-17?
Be aware that you can work with numbers much smaller than eps, as the maximum and minimum exponents (with 10-base) is -308 and 308 respectively (double prec.). That means that it is possible to represent a number down to to 2.2250738585072014e-308 (equal to 2^-1022) in double precision. It is also perfectly possible to do arithmetics with small numbers, for example 1e-30 + 1e-30 equals (correctly) 2e-30. The trouble arise when the numbers differ greatly in magnitude. If you for example try to calculate the sum 1+10^-16, the result is still 1 (exactly).

See this page for more information: http://en.wikipedia.org/wiki/Double-...g-point_format
haakon is offline   Reply With Quote

Old   March 29, 2013, 02:04
Default
  #10
Senior Member
 
immortality's Avatar
 
Ehsan
Join Date: Oct 2012
Location: Iran
Posts: 2,208
Rep Power: 27
immortality is on a distinguished road
thank you both so much for explanations.
But still a doubt is remaind about the relation between machine eps(around 1e-16) and DP(that calculates until e-308 in low values) or SP.
immortality is offline   Reply With Quote

Old   March 29, 2013, 17:39
Default
  #11
Senior Member
 
immortality's Avatar
 
Ehsan
Join Date: Oct 2012
Location: Iran
Posts: 2,208
Rep Power: 27
immortality is on a distinguished road
hakon and bruno,please complete your useful explanations with giving a comparison between DP bound and machine epsilon.
Why machine epsilon is restricted to e-17 when calculations could be done untile e-308 according to DP accuracy?
immortality is offline   Reply With Quote

Old   March 29, 2013, 19:58
Default
  #12
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,981
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
Quote:
Originally Posted by immortality View Post
hakon and bruno,please complete your useful explanations with giving a comparison between DP bound and machine epsilon.
Why machine epsilon is restricted to e-17 when calculations could be done untile e-308 according to DP accuracy?
First I've got to ask the following questions, because I'm curious:
  1. Is your internet access restricted in any way, in the sense that it does not allow you to access Wikipedia? Because your question is answered on the pages we've posted.
  2. You've described in the past that you're doing a master's degree and that your using/doing CFD for the thesis. Did you have a course on Computational Mathematics or something similar? Because this topic should have been addressed on that course...

Anyway, to try to answer your question, I'll go through a somewhat of summary bullet point presentation:
  • Double Precision usually follows the IEEE 754 standard, where 64 bits (8 bytes) pack numbers in the following format:
    • 1 bit for the sign of the global value.
    • 11 bits for the exponent, which allows for the 1e+308 to 1e-308 values.
    • 52 bits for the fraction, which allows for roughly 14 to 16 decimal digits.
  • As for machine epsilon, I'll quote from the Wikipedia article:
    Quote:
    machine epsilon is the maximum relative error of the chosen rounding procedure.
    This equates to the error associated with changing only the last bit of the fraction part of 52bit.
I hope this answers your question... because right now I'm almost falling asleep ... it's been a long week...
__________________
wyldckat is offline   Reply With Quote

Old   March 30, 2013, 05:20
Default
  #13
Senior Member
 
immortality's Avatar
 
Ehsan
Join Date: Oct 2012
Location: Iran
Posts: 2,208
Rep Power: 27
immortality is on a distinguished road
thank you Bruno
I grasped it.
There isn't any comparison description in wiki.no,i don't remember such topics in the courses.professor assumed such subject too simple that he want to describe.so my friends i asked wasn't certain like me.although we had courses like numerical analysis in bsc but they're too far to remember!
Have a nice day and good asleep.
immortality is offline   Reply With Quote

Old   March 30, 2013, 08:49
Default
  #14
Senior Member
 
Join Date: Dec 2011
Posts: 111
Rep Power: 20
haakon will become famous soon enough
I started on writing a short explanation yesterday, so I thought I might post it even tough this thread should be laid dead:

The magic lies in the definition of epsilon, which according to the Wikipedia article "gives an upper bound on the relative error due to rounding in floating point arithmetic" (my emphasis).

To use my previous example, if you add two numbers of different magnitude, you might get roundoff errors. This also goes for other operations, such as multiplication/division. For the sake of simplicity assume that one of the numbers is one (exactly).

First, let the other number also be one (exactly). In double precision that is:
Code:
1+1=2.00000000000000000000
And the result is represented accurately, i.e. no errors.

Then let us assume that we are to do a division, 1/10, witch we know (from numerics) is exactly 0.1. In double precision that is actually not the case:
Code:
1/10 = 0.10000000000000000555
As we can see, we have got an error. In this case the absolute error is 5.55e-18. If we normalize with respect to the correct answer (0.1) we get the relative error, which is 5.55e-17.

We might as well do this with some other numbers:
Code:
1e-67/1e-66 = 0.09999999999999999167
The absolute error in this case: 8.32e-18. The relative error (with respect to the correct answer): 8.32e-17

Lets do some additions:
Code:
1e-100+2e-100 = 3.00000000000000005998e-100
The absolute error? 5.998e-117 The relative error? 5.998e-17.

Do you get the concept? The crux is that we are dealing with relative errors due to round-offs. The last example is an good one, because we are dealing with numbers that are small (order of magnitude of 10^-100), and thus get small absolute errors. The key in the definition of epsilon is that it (i repeat myself) "gives an upper bound on the relative error due to rounding in floating point arithmetic". In all of our examples the relative errors are smaller than epsilon, and that is what it is all about.

Disclaimer: I have not considered that numbers like 1e-100 are not possible to represent exactly in double precision, and hence the error calculated here is a result of first converting 1e-100 (in the exact sense) to a binary number (witch is 1.00000000000000001999e-100) and then doing the same thing with the other numbers before actually performing the operation. Nevertheless, it illustrate the concept fairly well without adding to much complexity. I'm just a silly hydrodynamics engineer, so if some computer geeks wants to blow my head off and come with some exact calculations and considerations, feel free to do that.
immortality and SHUBHAM9595 like this.
haakon is offline   Reply With Quote

Old   March 30, 2013, 09:20
Default
  #15
Senior Member
 
immortality's Avatar
 
Ehsan
Join Date: Oct 2012
Location: Iran
Posts: 2,208
Rep Power: 27
immortality is on a distinguished road
thank you so much dear hakon for precise writing.that illuminated the concept more.this topic is alive for refers and add thoughts.I hope it is useful to anyone who has some questions related machine epsilon and double precision.
Ramzy1990 likes this.
immortality is offline   Reply With Quote

Reply


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
Continuing User Defined Real Gas Model issues aeroman FLUENT 6 April 8, 2016 04:34
Parallel User Defined Real Gas Model aeroman FLUENT 4 July 1, 2015 07:09
Missing math.h header Travis FLUENT 4 January 15, 2009 12:48
what's wrong about my code for 2d burgers equation morxio Main CFD Forum 3 April 27, 2007 11:38
REAL GAS UDF brian FLUENT 6 September 11, 2006 09:23


All times are GMT -4. The time now is 18:40.