CFD Online Discussion Forums

CFD Online Discussion Forums (
-   OpenFOAM (
-   -   Modify kEpsilon model (

harly November 30, 2008 20:05

Hi, I want to modify the ex

I want to modify the existing k - epsilon model in OpenFoam.
My first question would be has anyone of experience with something like that?

Basically I need to add a line that is computed in every iteration. The main problem is, that I can't find the proper files.

I can do almost everything in kEpsilon.H/.C but a few things. For example: Is there an array where all the k_ and epsilon_ values are stored ? I have a formula in which I need to apply the current k_ (iteration) and a k0_ (timestep) to calculate a new variable.

Maybe someone can give me a lead where I could look for that or how I could create such an array. Especially where I can find the loops for timesteps and iterations. (I want to use turbFoam)

I would appreciate your help - this is my first bigger modification in OpenFoam and I feel a bit lost in all those files.


henrik December 1, 2008 07:19

Daniel, - new turbulence mo

- new turbulence model: Have a look here

- arrays: k_ and epsilon_ are volScalarField and contain the arrays you are looking for.

Info << k_[cellI] << endl;

Prints the value of k in cell cellI.

- Loops: Have a look at the source of turbFoam and you will surely find them.


harly December 1, 2008 14:55

Hi, thanks a lot especially

thanks a lot especially for the link - I have one small questions - how can I access the k_ value of a previous timestep/iteration? Because in your example I get the current k_ or not?

or is there a easy explanation how a volScalarField is structured I couldn't find a proper description.


hjasak December 1, 2008 19:06

Try: k_.oldTime() You ge


You get the complete field for the old time. Also, things like

k.oldTime().oldTime().oldTime() (as many as you like!)

will work fine. Beware: this kind of game costs memory



harly December 2, 2008 19:36

thanks that is perfect So n
thanks that is perfect

So now that I can access all the fields data I have another question:

I need to Implement an equation like this:

C1_new = C1_*(1+Ct_*k_/epsilon_*1/(Q+k_)*abs(d(Q+k_)/dt) )

with Q = 0.5(u^2 + v^2) (for 2D)

and Ct_ will become a Constant

So here is the thing how can I implement Q ? I am not sure how to call the components from U_


I wonder what would be the best solution for the part in the abs(), because I would have done (Q_+k_)-(Q_old+k_.oldTime())/deltaT

maybe someone can give me a hint

harly December 3, 2008 18:43

Hi, I think I figured it o

I think I figured it out but one small issue:
I have now the following for my
C1_*(0.38*k_/epsilon_*1.0/(0.5*magSqr(U_)+k_)*mag((0.5*magSqr(U_)+k_-0.5*magSqr( U_.oldTime())+k_.oldTime())/1.0));

The problem is in front of the 0.38 there should be a vector full of ones the same size like k_ and epsilon_ but I don't know how to create it.

Basically I want to make:


Has someone an idea?


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