# Implementation of a RANS k epsilon solver

 Register Blogs Members List Search Today's Posts Mark Forums Read

 January 2, 2022, 10:01 Implementation of a RANS k epsilon solver #1 New Member   David Join Date: Oct 2020 Posts: 21 Rep Power: 5 Hello everyone I want to implement my own code in fortran to solve a RANS standart k-epsilon problem using the Boussinesq approximation. The idea is to get some coding practice as well as to better understand the generall workings of a solver. I then planing to validate my solver using the pitzDaisy case from the tutorial from openFOAM. I understand the generall approach of the turbulent modelling approach but right now I am struggling at the implementation of the different steps to solve this problem. Can somebody recommend a step by step guide/manual on how to implement such a solver? I am especially struggling on how I can solve for the corresponding k and epsilon using transportation equations. Also how can I use the derived Reynoldstress to derive the velocity field? I would love something like: k_new = k_old + dt * parameters. Does something like this exist? And where could I find something like this? Many thanks already in advance for your help. Best regards fidu

January 3, 2022, 04:13
#2
Senior Member

Paolo Lampitella
Join Date: Mar 2009
Location: Italy
Posts: 2,147
Blog Entries: 29
Rep Power: 38
Quote:
 Originally Posted by fidu Hello everyone I want to implement my own code in fortran to solve a RANS standart k-epsilon problem using the Boussinesq approximation. The idea is to get some coding practice as well as to better understand the generall workings of a solver. I then planing to validate my solver using the pitzDaisy case from the tutorial from openFOAM. I understand the generall approach of the turbulent modelling approach but right now I am struggling at the implementation of the different steps to solve this problem. Can somebody recommend a step by step guide/manual on how to implement such a solver? I am especially struggling on how I can solve for the corresponding k and epsilon using transportation equations. Also how can I use the derived Reynoldstress to derive the velocity field? I would love something like: k_new = k_old + dt * parameters. Does something like this exist? And where could I find something like this? Many thanks already in advance for your help. Best regards fidu
Do you have a working laminar or inviscid code? Otherwise I wouldn't consider anything else before.

Also, k-epsilon models require wall functions or some specific variant to work at walls. I would suggest Spalart-Allmaras or k-omega for a novice as first implementation.

In general, turbulence model equations are not much different from general scalar equations (something you should be really able to solve by yourself before attempting any turbulence model implementation). Some specificities are:

- Most models have similar equations, differing the most trough their source terms. Source terms can indeed be relevant, so an explicit approach might simply not work. You should be ready to implement them implicitly. Most models have suggestions on the implicit source term treatment in their original papers

- You need first to compute the turbulent viscosity from the turbulence variables before solving the momentum equations, then use the effective viscosity (laminar + turbulent) as constant in the momentum equations. With momentum equations solved, you have the massflux to use in the turbulence equations. Then repeat.

January 3, 2022, 06:30
#3
New Member

David
Join Date: Oct 2020
Posts: 21
Rep Power: 5
Quote:
 Originally Posted by sbaffini Do you have a working laminar or inviscid code? Otherwise I wouldn't consider anything else before. Also, k-epsilon models require wall functions or some specific variant to work at walls. I would suggest Spalart-Allmaras or k-omega for a novice as first implementation. In general, turbulence model equations are not much different from general scalar equations (something you should be really able to solve by yourself before attempting any turbulence model implementation). Some specificities are: - Most models have similar equations, differing the most trough their source terms. Source terms can indeed be relevant, so an explicit approach might simply not work. You should be ready to implement them implicitly. Most models have suggestions on the implicit source term treatment in their original papers - You need first to compute the turbulent viscosity from the turbulence variables before solving the momentum equations, then use the effective viscosity (laminar + turbulent) as constant in the momentum equations. With momentum equations solved, you have the massflux to use in the turbulence equations. Then repeat.
Thanks for the summary on how to implement the code as well as you suggestions. It already helps a lot to clarify a few of my concerns. I forgot about the near wall treatment and I think now I will start with a k-omega model first. Especially as I am currently a bit overwhelmed at the prospect of this endeavor. For this reason it would be really helpful to have a simple implemented code or paper which solves/derives the calculation procedure in a code like procedure as a reference. Do you know if any such exists and where I might find something like this?

I have currently a working code a convection programm for low Prandl number which works pretty well and was thinking to exent/change it for my porpose. However this was a 2D modell where my velocity was calculated using streamfunctions. I then updated my vorticity and temperatur fields using the procedure shown in the images.

Thanks again for all your help and time.

Best
fidu
Attached Images
 T.png (22.5 KB, 8 views) w.png (24.4 KB, 7 views)

 January 3, 2022, 07:09 #4 Senior Member   Lucky Join Date: Apr 2011 Location: Orlando, FL USA Posts: 5,635 Rep Power: 65 Have you somehow overlooked that OpenFOAM is open source? You can just open up the source code and look at what is there. I realize it is c++ and not Fortran but you can just skip over all the c-specific stuff. There is also a programmer's guide to help you with the gnitty gritty details. If you want you can even compare your streamfunction code with potentialFoam. Btw k_new = k_old + dt * parameters implies an explicit approach... are you sure you want to do it this way? fidu likes this.

January 3, 2022, 08:41
#5
Senior Member

Paolo Lampitella
Join Date: Mar 2009
Location: Italy
Posts: 2,147
Blog Entries: 29
Rep Power: 38
Quote:
 Originally Posted by fidu Thanks for the summary on how to implement the code as well as you suggestions. It already helps a lot to clarify a few of my concerns. I forgot about the near wall treatment and I think now I will start with a k-omega model first. Especially as I am currently a bit overwhelmed at the prospect of this endeavor. For this reason it would be really helpful to have a simple implemented code or paper which solves/derives the calculation procedure in a code like procedure as a reference. Do you know if any such exists and where I might find something like this? I have currently a working code a convection programm for low Prandl number which works pretty well and was thinking to exent/change it for my porpose. However this was a 2D modell where my velocity was calculated using streamfunctions. I then updated my vorticity and temperatur fields using the procedure shown in the images. Thanks again for all your help and time. Best fidu
You can pretty much use the same temperature template for your turbulence variables, one after the other. However, as already mentioned, you are short lived with an explicit approach.

An additional aspect I never looked into is that I expect the turbulence formalism to be maybe different in the psi-omega framework, unless you maybe derive the psi and omega equations from the RANS equations first

January 4, 2022, 04:21
#6
New Member

David
Join Date: Oct 2020
Posts: 21
Rep Power: 5
Quote:
 Originally Posted by LuckyTran Have you somehow overlooked that OpenFOAM is open source? You can just open up the source code and look at what is there. I realize it is c++ and not Fortran but you can just skip over all the c-specific stuff. There is also a programmer's guide to help you with the gnitty gritty details. If you want you can even compare your streamfunction code with potentialFoam. Btw k_new = k_old + dt * parameters implies an explicit approach... are you sure you want to do it this way?
Yes I kind of forgot about the fact that OpenFOAM is open source and thanks for the reminder. I will try to understand the code there but as I am still new and unexperience in programming I was still hoping for a flow chart guide or someting.

And thanks to pointing it out with the implized approach. I just wanted to make an example on what kind of manueal/floating charte I am looking for.

January 4, 2022, 04:23
#7
New Member

David
Join Date: Oct 2020
Posts: 21
Rep Power: 5
Quote:
 Originally Posted by sbaffini You can pretty much use the same temperature template for your turbulence variables, one after the other. However, as already mentioned, you are short lived with an explicit approach. An additional aspect I never looked into is that I expect the turbulence formalism to be maybe different in the psi-omega framework, unless you maybe derive the psi and omega equations from the RANS equations first
ok thanks then I think I will try this and then adaped the code with an implicte appraoch. Ok thanks I will look into it.

 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 OffTrackbacks are Off Pingbacks are On Refbacks are On Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post hjasak OpenFOAM Announcements from Other Sources 19 July 16, 2021 06:02 zizhou FLUENT 0 March 22, 2021 07:33 Tanjina FLUENT 5 January 13, 2014 11:46 Chen Zhi Main CFD Forum 3 February 14, 2010 21:10 nedved OpenFOAM Running, Solving & CFD 1 November 25, 2008 21:21

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