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

Best practices in CFD (code structure)

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   August 14, 2014, 15:29
Default Best practices in CFD (code structure)
  #1
Senior Member
 
Joachim
Join Date: Mar 2012
Location: Paris, France
Posts: 145
Rep Power: 15
Joachim is on a distinguished road
Hey everyone!

I would like to improve the organization of my CFD code (in Fortran 90), and I would gladly appreciate any suggestions/comments you might have!

To summarize, here is the current structure:

1. import grid / construct metrics, volumes, etc
2. initialize solution
----------------time loop---------------------
3. compute residuals
- compute roe fluxes (including turbulent terms)
- compute transport fluxes (both laminar and turbulent at same time)
- compute source terms if any
4. update solution (laminar and turbulent at same time)
5. impose new boundary conditions in ghost cells and update dependent variables
---------------------------------------------

I have constantly stored in memory the state variables, as well as dependent variables (pressure, temperature, speed of sound, viscosity, etc + turbulent quantities such as eddy viscosity, blending functions, etc). I read that in CFL3D, they only stored the primitive variables, but in FUN3D, they were basically storing everything. Which approach would you recommend?

Some people told me it might be better to separate laminar and turbulent subroutines, and put the latter in a big module. That would make things a bit more clear. However, if I consider the Roe fluxes computation for example, I will need uL and uR in for my turbulent fluxes too. It means that I either have to store them and waste memory or recompute them and waste CPU time...

I guess the new structure would look something like that:

1. import grid / construct metrics, volumes, etc
2. initialize solution
----------------time loop---------------------
3. compute NS residuals
4. add turbulent residuals
5. update solution (laminar and turbulent at same time, since my code is tighly coupled)
6. impose NS boundary conditions
7. impose turbulent boundary conditions
----------------------------------------------

I was also suggested to use structures for my grid, solution, etc. Any comment about that?

What is, in your opinion, the best way to structure a code? I know there is not a single right answer to that question, but I would gladly hear your suggestions!

Thank you very much!

Joachim
Joachim is offline   Reply With Quote

Old   August 16, 2014, 23:31
Default
  #2
Member
 
Ramesh K
Join Date: Dec 2009
Location: Bangalore
Posts: 73
Rep Power: 16
RameshK is on a distinguished road
Send a message via Yahoo to RameshK
Hi

I have written my code for 2D and 3D compressible solvers and my code structure looks similar to yours, except that I apply boundary conditions first and then go about computing others.

Regarding storage of variables, different numerical schemes have different ways of computing, so it does not make sense to store all the values, hence the basic metrics of the grid (if it is stationary ) need to be stored and the primitive and conserved variables should be stored rest need to be calculated. This is how I do....

Regards
RameshK is offline   Reply With Quote

Old   August 17, 2014, 12:04
Default
  #3
Senior Member
 
Joachim
Join Date: Mar 2012
Location: Paris, France
Posts: 145
Rep Power: 15
Joachim is on a distinguished road
Thank you Rameshk!

Actually, my code is working just fine right now, but other people will probably use it after I graduate. I am afraid the current organization will make it difficult for someone to implement a new turbulence model for example. They will basically have to go through each and every subroutine and add some extra-stuffs here and there...

This is mainly why I was thinking about moving from a tightly coupled solver to a loosely coupled one. Then I would put all my kw-SST subroutines in one module, same for SA, and it would become relatively easy to add/modify turbulent stuffs in the solver.

However, it is kind of a pain sometimess...
The best example I have is the computation of the Roe fluxes. For the laminar parts, you need to compute the Roe matrices, which takes quite a while. For the turbulent part, I can reuse the same eigenvectors, eigenvalues, etc and just change a little something. Basically, I am not sure whether I should store all these terms (at all faces!) as global variables and reuse them, or just recompute them (waste of CPU time!!)

Your opinion about that??

Thank you!

Joachim
Joachim is offline   Reply With Quote

Old   August 18, 2014, 16:47
Default
  #4
Senior Member
 
Joachim
Join Date: Mar 2012
Location: Paris, France
Posts: 145
Rep Power: 15
Joachim is on a distinguished road
Actually, it seems that people just neglect the dissipation terms for the turbulent convective fluxes...that makes it simple.

However, what about suing structure in my code? I was suggested to put all the flow variables in a solution structure, and the grid parameters in a grid structure.
I tried that, but now my code is kind of messy, since I have grid%x(i,j) , or solu%u(i,j) everywhere...

Should I really use structures? What is the advantage of doing so?

Thank you so much!

Joachim
Joachim is offline   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
general ARCHITECTURAL structure of the code of a CFD code mecobio Main CFD Forum 0 August 12, 2013 09:04
Give me some advice CFD in Fortran code or Matlab code. tringuyenttt Main CFD Forum 4 May 29, 2013 09:32
STRUCTURE OF CFD CODE MAB Main CFD Forum 5 August 10, 2008 04:47
Structure of CFD code Shyam Main CFD Forum 5 April 26, 2006 13:04
ASME CFD Symposium Chris Kleijn Main CFD Forum 0 August 22, 2001 07:41


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