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

Scalar precision: float vs. double

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

Reply
 
LinkBack Thread Tools Display Modes
Old   August 25, 2011, 09:35
Default Scalar precision: float vs. double
  #1
Senior Member
 
Hisham's Avatar
 
Hisham El Safti
Join Date: Apr 2011
Location: Braunschweig, Germany
Posts: 247
Blog Entries: 10
Rep Power: 8
Hisham is on a distinguished road
Hi

I use scalars to solve a (simple closed form) quadratic equation. Nevertheless, they always give a 6 digits precision (a float). I tried to declare the scalars as doubleScalar instead of just scalar. However, the result is still in 6 digits. I made sure that the solution can be more precise http://www.mathsisfun.com/quadratic-...on-solver.html
Hisham is offline   Reply With Quote

Old   August 25, 2011, 09:51
Default
  #2
Senior Member
 
Felix L.
Join Date: Feb 2010
Location: Hamburg
Posts: 165
Rep Power: 9
FelixL is on a distinguished road
This is probably an output related issue.
How are you printing out your results?


Greetings,
Felix
FelixL is offline   Reply With Quote

Old   August 25, 2011, 09:56
Default
  #3
Senior Member
 
Hisham's Avatar
 
Hisham El Safti
Join Date: Apr 2011
Location: Braunschweig, Germany
Posts: 247
Blog Entries: 10
Rep Power: 8
Hisham is on a distinguished road
I use the following

Quote:
#include "IOstreams.H"
using namespace Foam

Info << scalar;
Hisham is offline   Reply With Quote

Old   August 25, 2011, 10:24
Default
  #4
Senior Member
 
Hisham's Avatar
 
Hisham El Safti
Join Date: Apr 2011
Location: Braunschweig, Germany
Posts: 247
Blog Entries: 10
Rep Power: 8
Hisham is on a distinguished road
Thanks for the tip. I guess it is an output issue. So using "cout" one can use:

Quote:
cout.precision(15);
Is there a possible way around for "Info" just for debugging sake. Anyway thanks a lot for quick answer.

Vielen Dank nochmal
Hisham is offline   Reply With Quote

Old   August 25, 2011, 11:09
Default
  #5
Senior Member
 
David Gaden
Join Date: Apr 2009
Location: Winnipeg, Canada
Posts: 397
Rep Power: 12
marupio is on a distinguished road
There's a couple of precision options in the controlDict. One is for the time directory name, and the other is for the output. Can't remember what they are off-hand, but they should be easy to find.
marupio is offline   Reply With Quote

Old   August 25, 2011, 11:24
Default
  #6
Senior Member
 
Hisham's Avatar
 
Hisham El Safti
Join Date: Apr 2011
Location: Braunschweig, Germany
Posts: 247
Blog Entries: 10
Rep Power: 8
Hisham is on a distinguished road
Hi marupio

Thanks a lot, I found it:

Quote:
writePrecision 15;
Hisham is offline   Reply With Quote

Reply

Tags
double, float, scalar

Thread Tools
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 On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Parallel User Defined Real Gas Model aeroman FLUENT 4 July 1, 2015 06:09
Continuing User Defined Real Gas Model issues aeroman FLUENT 5 May 1, 2015 02:57
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 10:38
REAL GAS UDF brian FLUENT 6 September 11, 2006 08:23


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