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

C programme issue for CFD

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   November 29, 2006, 09:12
Default C programme issue for CFD
  #1
john
Guest
 
Posts: n/a
I am writing my own CFD code using c language. I want to create a function which can deal with both single and double precision arrays such that

grad_cal1(fi1) where fi1 is an array of float

grad_cal2(fi2) where fi2 is an array of double

void grad_cal1(float *fi){a.h}

void grad_cal2(double *fi){a.h}

Inside the function, the programme is exactly the same. Is there any way to call the same function instead of two?
  Reply With Quote

Old   November 29, 2006, 09:34
Default Re: C programme issue for CFD
  #2
pc
Guest
 
Posts: n/a
Why not simplify things by making the whole code double precision? Why do you really need to mix variable types?

  Reply With Quote

Old   November 29, 2006, 10:15
Default Re: C programme issue for CFD
  #3
Markus Lummer
Guest
 
Posts: n/a
Hello John,

in C it is possible to compile the function with appropriate preprocessor macros, e.g.

#define REAL float

or

#define REAL double

and the corresponding definitions in the source, e.g.

void grad_cal1(REAL *fi){a.h}

Another (and much better) possibility would be using C++ templates.

Regards, Markus

  Reply With Quote

Old   November 30, 2006, 13:27
Default Re: C programme issue for CFD
  #4
Mani
Guest
 
Posts: n/a
Markus' preprocessor approach lets you create either version independently at compile-time. To have both options simultaneously at run-time you are basically talking about object oriented programming: This is a case for C++, not C.
  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
How to write UDF programme inside FLUENT? coolyihao Fluent UDF and Scheme Programming 9 June 5, 2016 22:08
[swak4Foam] groovyBC elevated inlet. pos() issue grjmell OpenFOAM Community Contributions 6 January 23, 2013 09:14
Meshing related issue in Flow EFD appu FloEFD, FloWorks & FloTHERM 1 May 22, 2011 09:27
[snappyHexMesh] snappyHexMesh Issue thomasnwalshiii OpenFOAM Meshing & Mesh Conversion 3 March 15, 2011 14:49
My experience Installing Elmer (Open Source Multi physics programme) on Linux Ahmed Main CFD Forum 3 August 10, 2010 14:42


All times are GMT -4. The time now is 23:37.