CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > General Forums > Main CFD Forum

FORTRAN variable declaration

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   October 20, 2005, 11:44
Default FORTRAN variable declaration
  #1
sriram
Guest
 
Posts: n/a
HI ALL,

I have written a simulation code in matlab,its working perfectly. Now, I tried to convert it into fortran.For the first time step, both the codes produce the same results. But as the time step increases, the fortran code evaluation is on lower side than that of matlab, this is due to the variable declaration in fortran. For example, i explicitly find out in incrementing the timestep(TI),assuming DT = 0.01 if i evaluated at the 6th time step using (TI=TI+DT) its showing 5.99999e-2. but it should be 0.06. But in Matlab its doing correctly. I hope, similar problem is exist throughout the code in variable declaration.I declared the variable as REAL,I need the code to estimate only FOUR DECIMAL places at every time step. If any one there to help me out in this problem.

Thanks!

-sriram-

  Reply With Quote

Old   October 20, 2005, 12:28
Default Re: FORTRAN variable declaration
  #2
agg
Guest
 
Posts: n/a
Try running your simulation in double precision.
  Reply With Quote

Old   October 21, 2005, 13:21
Default Re: FORTRAN variable declaration
  #3
Jeff Moder
Guest
 
Posts: n/a
Floating point numbers (real numbers) are represented as base 2 (binary) fractions in computer hardware. Just because matlab if DISPLAYING 0.06 does not mean it is actually represented exactly as 0.06 when matlab is running. If you only want to see 4 decimal places of accuracy in the output of your Fortran program, then use the format '(ES12.4)'. For the time step you are using (DT=0.01), I personally think single precision is fine, but it is always a good idea to see if running in double precision has a significant effect (judged by you) on your results.

If you want a more information of floating point representation in computer hardware, I think the following is a very nice explanation:

http://docs.python.org/tut/node16.html

(The basic ideas discussed are independent of the computer language).

  Reply With Quote

Old   October 22, 2005, 06:08
Default Re: FORTRAN variable declaration
  #4
Vinod Dhiman
Guest
 
Posts: n/a
Hi

Yes, Jeff is right. Double Precision is really not going to help you. Even that will show 0.0599999 or 0.0600001 or something like that. Either change the format as Jeff suggested or use a different compiler. Changing the compiler may work out.

Vinod Dhiman
  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
[swak4Foam] GroovyBC the dynamic cousin of funkySetFields that lives on the suburb of the mesh gschaider OpenFOAM Community Contributions 300 October 29, 2014 18:00
emag beta feature: charge density charlotte CFX 4 March 22, 2011 09:14
ParaView for OF-1.6-ext Chrisi1984 OpenFOAM Installation 0 December 31, 2010 06:42
DecomposePar links against liblamso0 with OpenMPI jens_klostermann OpenFOAM Bugs 11 June 28, 2007 17:51
Replace periodic by inlet-outlet pair lego CFX 3 November 5, 2002 20:09


All times are GMT -4. The time now is 07:41.