CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   Main CFD Forum (http://www.cfd-online.com/Forums/main/)
-   -   Structure of CFD code (http://www.cfd-online.com/Forums/main/11302-structure-cfd-code.html)

Shyam April 25, 2006 04:52

Structure of CFD code
 
Hi all,

I am planning to start writing up a CFD code for my phd. Since mine is Higher Order, i need to develop the code from the scratch. Hence I thought it would be better to ask the experts to advise me of the structure of the code.

Is it advisable to store the variables as a bunch of arrays, or to store them in a structure

Also, is it recommendable to have a one dimensional array or a 3D array for storing the variables?

Scheme: FVM, Explicit time integration, LES/RANS (DES)

Shyam

zxaar April 25, 2006 05:12

Re: Structure of CFD code
 
structure of the code is very simple Start: Starting code Middle: Lot of middle code, and then some more lot of code. End: In the end there is some more code, its not important you can keep it empty and put this code in middle code part.

hurricane April 25, 2006 06:29

Re: Structure of CFD code
 
First of all, any scientific code have 3 major parts :

- Pre-processing : user's data entry (input)

- Processing : code's core (calculus using numerical methods)

- Post-processing : display results (ouput)

For the pre-processing u can choose between 3 ways :

- classical step by step user entry : like when you use a dos or unix terminal

- file user entry : u'll have to specify a language or use a predifined one like CGNS and program an interpreter which will read the file and puts datas in their structures.

- graphical interface user entry : u'll have to build a GUI.

Same thing for the post-processing.

Of course you choice depend on your programming level and the language you choosed (c, c++, ada, java, fortran...)

Concerning data's structures there's many ways, and another time, that's depend on your programming level. U can use structures or classes (oriented object programming).

For arrays the best technique is to use chained lists, but it's really a hard way. But that's must not be your first priority. When your program will run correctly, then you'll try to improve and optimize it. But for now, I think it's preferable to use the techniques you master.

My advice : search for a good book on software engineering and another one on data's structures and algorithmics, that's will really help you to build a good code and save time.

Well, hope that will help you a little bit. If you have other questions you can send me an email.

PS : look for "Code Complete - A Practical Handbook Of Software Construction" by Steve McConnell.

Steve April 25, 2006 08:50

Re: Structure of CFD code
 
To answer the question posed (unlike the two previous responses)...

Structures are great for holding all the relevant data together in the right place. And also great for traversing networks (i.e. pointers to neighbours and all that). But I suspect your solver will work best on big arrays, so you'll need to build them up by pulling data from your structures each time you want to solve and then stuffing results back into the structures after each solution step.

Shyam April 25, 2006 21:01

Re: Structure of CFD code
 
Thanks Steve.. Yes... Thats what i was worried about... Accessing the variabes through a structure requires extra work of pointing to the structure first.

As speed is the first priori, I will try to incorporate array blocks.

The next thing is the choice of 1D or 3D array for holding 3 dimensinal data set. I heard from my friends that in case of explicit schemes with fixed computational stencils, if properly programmed, 1D array can be much faster, as accessing any variable inside that array mostly involves atmost two additions, whereas in 3D (dynamic) array, it involves pointing to the base pointer, then next, then to the variable.

But, when the memory involved is huge, it is often advisable to have smaller chunks of memory allocated (as in 3D array) than a huge chunk as in 1D array.

What is your opinion?

Is the additional computational time involved in these access negligible when compared to the actual calculation involved?


chris April 26, 2006 12:04

Re: Structure of CFD code
 
Well, you can make one more step of abstraction and try to see which solution is best. The user of your storage structure should not see whether it operates on 1D-arrays or 3D-arrays.


All times are GMT -4. The time now is 20:54.