|
[Sponsors] |
November 29, 2006, 09:12 |
C programme issue for CFD
|
#1 |
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? |
|
November 29, 2006, 09:34 |
Re: C programme issue for CFD
|
#2 |
Guest
Posts: n/a
|
Why not simplify things by making the whole code double precision? Why do you really need to mix variable types?
|
|
November 29, 2006, 10:15 |
Re: C programme issue for CFD
|
#3 |
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 |
|
November 30, 2006, 13:27 |
Re: C programme issue for CFD
|
#4 |
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.
|
|
|
|
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 |