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

Implementation of a RANS k epsilon solver

Register Blogs Community New Posts Updated Threads Search

Like Tree3Likes
  • 1 Post By sbaffini
  • 1 Post By LuckyTran
  • 1 Post By sbaffini

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   January 2, 2022, 09:01
Default Implementation of a RANS k epsilon solver
  #1
New Member
 
David
Join Date: Oct 2020
Posts: 21
Rep Power: 5
fidu is on a distinguished road
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
fidu is offline   Reply With Quote

Old   January 3, 2022, 03:13
Default
  #2
Senior Member
 
sbaffini's Avatar
 
Paolo Lampitella
Join Date: Mar 2009
Location: Italy
Posts: 2,168
Blog Entries: 29
Rep Power: 39
sbaffini will become famous soon enoughsbaffini will become famous soon enough
Send a message via Skype™ to sbaffini
Quote:
Originally Posted by fidu View Post
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.
fidu likes this.
sbaffini is offline   Reply With Quote

Old   January 3, 2022, 05:30
Default
  #3
New Member
 
David
Join Date: Oct 2020
Posts: 21
Rep Power: 5
fidu is on a distinguished road
Quote:
Originally Posted by sbaffini View Post
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
File Type: png T.png (22.5 KB, 8 views)
File Type: png w.png (24.4 KB, 7 views)
fidu is offline   Reply With Quote

Old   January 3, 2022, 06:09
Default
  #4
Senior Member
 
Lucky
Join Date: Apr 2011
Location: Orlando, FL USA
Posts: 5,704
Rep Power: 66
LuckyTran has a spectacular aura aboutLuckyTran has a spectacular aura aboutLuckyTran has a spectacular aura about
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.
LuckyTran is offline   Reply With Quote

Old   January 3, 2022, 07:41
Default
  #5
Senior Member
 
sbaffini's Avatar
 
Paolo Lampitella
Join Date: Mar 2009
Location: Italy
Posts: 2,168
Blog Entries: 29
Rep Power: 39
sbaffini will become famous soon enoughsbaffini will become famous soon enough
Send a message via Skype™ to sbaffini
Quote:
Originally Posted by fidu View Post
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
fidu likes this.
sbaffini is offline   Reply With Quote

Old   January 4, 2022, 03:21
Default
  #6
New Member
 
David
Join Date: Oct 2020
Posts: 21
Rep Power: 5
fidu is on a distinguished road
Quote:
Originally Posted by LuckyTran View Post
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.
fidu is offline   Reply With Quote

Old   January 4, 2022, 03:23
Default
  #7
New Member
 
David
Join Date: Oct 2020
Posts: 21
Rep Power: 5
fidu is on a distinguished road
Quote:
Originally Posted by sbaffini View Post
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.
fidu is offline   Reply With Quote

Reply

Tags
coding skills.., k-epsilon model, numerical methods, rans modelling, reynolds shear stress


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
foam-extend-4.1 release hjasak OpenFOAM Announcements from Other Sources 19 July 16, 2021 05:02
Fail to converge when solving with a fabricated solution zizhou FLUENT 0 March 22, 2021 06:33
Divergence detected in AMG solver: k, epsilon, pressure coupled Tanjina FLUENT 5 January 13, 2014 10:46
Puzzled by multi-block solver implementation...... Chen Zhi Main CFD Forum 3 February 14, 2010 20:10
SimpleFoam k and epsilon bounded nedved OpenFOAM Running, Solving & CFD 1 November 25, 2008 20:21


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