CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM

How to add the source term to epsilon equation of K epsilon model.

Register Blogs Community New Posts Updated Threads Search

Like Tree4Likes
  • 1 Post By crubio.abujas
  • 1 Post By crubio.abujas
  • 1 Post By crubio.abujas
  • 1 Post By crubio.abujas

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 13, 2021, 02:02
Default How to add the source term to epsilon equation of K epsilon model.
  #1
New Member
 
Lakshman R
Join Date: Apr 2017
Posts: 16
Rep Power: 9
lachuktr is on a distinguished road
Currently, I am simulating the atmospheric boundary layer in OpenFOAM. I want to add the source term to the epsilon equation of the k-epsilon turbulence model.

Since z is not defined in kEpsilon.C, I am having trouble initiating the "z" value

"z" is the distance from the ground.
Kindly help.
Attached Images
File Type: jpg epsilon source1.jpg (37.4 KB, 95 views)
lachuktr is offline   Reply With Quote

Old   July 14, 2021, 12:11
Default
  #2
Senior Member
 
Carlos Rubio Abujas
Join Date: Jan 2018
Location: Spain
Posts: 127
Rep Power: 9
crubio.abujas is on a distinguished road
Hi Lakshman,

I think you can try scalarCodedSource attached to epsilon equation. Depending on the OF version you're using the epsilon equation may or may not ask fvOption for additional sources. Ive tried this on OF7 and seems to work fine.

Code:
/*--------------------------------*- C++ -*----------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     | Website:  https://openfoam.org
    \\  /    A nd           | Version:  7
     \\/     M anipulation  |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    object      fvOptions;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

epsilonSource
{
    type    scalarCodedSource;
    name    internalField;
    selectionMode    all;
    fields    (epsilon);

    codeAddSup
    #{
        const vectorField& C = mesh().C();
        const scalarField& V = mesh_.V();

        const volScalarField& k = mesh_.lookupObject<volScalarField>("k");

        scalar C_mu(0.09);      // Coefficient of turbulent viscosity
        scalar z0(0.03);        // Aerodynamics roughness

        scalarField& source = eqn.source();

        forAll(C, i)
        {
           source[i] -= C_mu * pow(k[i], 2) / pow( C[i].z() + z0 , 2 ) * V[i];
        }

        Info<< "epsilonSource min/max: " 
            << gMin(source) << "/" << gMax(source)
            << endl;
  #};
 
}

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
I'm not totally sure if you have to multiply it by the volume or not, you should check if it work as expected.

I hope that helps.
lachuktr likes this.
crubio.abujas is offline   Reply With Quote

Old   July 14, 2021, 21:26
Default
  #3
New Member
 
Lakshman R
Join Date: Apr 2017
Posts: 16
Rep Power: 9
lachuktr is on a distinguished road
Quote:
Originally Posted by crubio.abujas View Post
Hi Lakshman,

I think you can try scalarCodedSource attached to epsilon equation. Depending on the OF version you're using the epsilon equation may or may not ask fvOption for additional sources. Ive tried this on OF7 and seems to work fine.

Code:
/*--------------------------------*- C++ -*----------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     | Website:  https://openfoam.org
    \\  /    A nd           | Version:  7
     \\/     M anipulation  |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    object      fvOptions;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

epsilonSource
{
    type    scalarCodedSource;
    name    internalField;
    selectionMode    all;
    fields    (epsilon);

    codeAddSup
    #{
        const vectorField& C = mesh().C();
        const scalarField& V = mesh_.V();

        const volScalarField& k = mesh_.lookupObject<volScalarField>("k");

        scalar C_mu(0.09);      // Coefficient of turbulent viscosity
        scalar z0(0.03);        // Aerodynamics roughness

        scalarField& source = eqn.source();

        forAll(C, i)
        {
           source[i] -= C_mu * pow(k[i], 2) / pow( C[i].z() + z0 , 2 ) * V[i];
        }

        Info<< "epsilonSource min/max: " 
            << gMin(source) << "/" << gMax(source)
            << endl;
  #};
 
}

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
I'm not totally sure if you have to multiply it by the volume or not, you should check if it work as expected.

I hope that helps.

Thank you so much Carlos... it seems to be working fine.

Since I have not much experience in C++ coding and FvOption, can you please explain the codes you wrote here for better understanding. it will be very helpful for me in the future.
lachuktr is offline   Reply With Quote

Old   July 15, 2021, 02:07
Default
  #4
Senior Member
 
Carlos Rubio Abujas
Join Date: Jan 2018
Location: Spain
Posts: 127
Rep Power: 9
crubio.abujas is on a distinguished road
hi Lakshman,


I've added a commented version of the code. The object mesh_ has a lot of information about the simulation, as it acts as register you can recall different fields to be used in your code (for example the k field). Check out the fvMesh class for more information.


Once you get the information required (center of the cells, volumes, other fields and constants) you loop across all the cells in your domain to apply the given source term.


The system of equation is automatically read by the codedSource. Be aware that this eqn is a fvMatrix so you can see further details in the documentation. In short, it stores the coefficients of the matrix A and the terms of the source b of the system Ax=b. I think that it stores the source as Ax - b = 0, so you need to switch the sign on the source term (thats the by of the -= in the source).



Code:
        const vectorField& C = mesh().C();   // Read from the mesh the center of each cell.

        const scalarField& V = mesh_.V();  // Read from the mesh the volume of each cell.

        const volScalarField& k = mesh_.lookupObject<volScalarField>("k"); // lookup for the kinetic turbulence energy field.

        // Set the constant refereed inthe formula.

        scalar C_mu(0.09);      // Coefficient of turbulent viscosity
        scalar z0(0.03);        // Aerodynamics roughness

        // the codedOption will reach the system of ecuations associated 
        // with the field (Ax=b), the idea is to add an explicit source to it 
        // so the source is extracted (b).
        scalarField& source = eqn.source();

        // loop for each of the cells.
        forAll(C, i)
        {
           // For each cell add the required source term.
           // pow (x, 2) will raise x^2
           source[i] -= C_mu * pow(k[i], 2) / pow( C[i].z() + z0 , 2 ) * V[i];
        }

        // This just prints the max/min source terms for debugging purposes.
        Info<< "epsilonSource min/max: " 
            << gMin(source) << "/" << gMax(source)
            << endl;
lachuktr likes this.
crubio.abujas is offline   Reply With Quote

Old   July 15, 2021, 12:27
Default
  #5
New Member
 
Lakshman R
Join Date: Apr 2017
Posts: 16
Rep Power: 9
lachuktr is on a distinguished road
Thanks a lot for your help...

Can you help me to add the same source term in KEpsilon.C file rather than using fvOption.

I have seen the YAP correction source term (attached file along with this reply )added to KEpsilon.C as follows.


template<class BasicTurbulenceModel>
tmp<volScalarField> YkEpsilon<BasicTurbulenceModel>::sYap() const
{

const volScalarField ell_eps = pow(Cmu_,-0.75)*kappa_*y_;
const volScalarField ell = pow(k_,1.5)/epsilon_;

//create a volScalrField=0 with the same dimensions of sYap
//this will be used to enforce sYap=max(sYap,0)
volScalarField zero_field
(
IOobject
(
"zero_field",
this->runTime_.timeName(),
this->mesh_,
IOobject::NO_READ,
IOobject::NO_WRITE
),
this->mesh_,
dimensionedScalar("0", dimensionSet(0,2,-4,0,0,0,0), 0.0)
);

return
max(Cyap_*pow(epsilon_,2)/k_*(ell/ell_eps-1)*pow((ell/ell_eps),2),zero_field);
}




Can you help me in adding the souce term which i attached in the first message of this forum simillar to the one given above.


I am also attaching the .C and .H files of yap correction implemented kEpsilon model for reference.
Attached Images
File Type: png yap correction.png (13.8 KB, 30 views)
Attached Files
File Type: c YkEpsilon.C (8.6 KB, 12 views)
File Type: h YkEpsilon.H (6.0 KB, 5 views)

Last edited by lachuktr; July 15, 2021 at 20:34.
lachuktr is offline   Reply With Quote

Old   July 17, 2021, 03:27
Default
  #6
Senior Member
 
Carlos Rubio Abujas
Join Date: Jan 2018
Location: Spain
Posts: 127
Rep Power: 9
crubio.abujas is on a distinguished road
In the turbulence model the equation is solved when you call the correct() method. There you can see where the equations are implemented:

Code:
    // Dissipation equation
    tmp<fvScalarMatrix> epsEqn
    (
        fvm::ddt(alpha, rho, epsilon_)
      + fvm::div(alphaRhoPhi, epsilon_)
      - fvm::laplacian(alpha*rho*DepsilonEff(), epsilon_)
     ==
        C1_*alpha()*rho()*G*epsilon_()/k_()
      - fvm::SuSp(((2.0/3.0)*C1_ - C3_)*alpha()*rho()*divU, epsilon_)
      - fvm::Sp(C2_*alpha()*rho()*epsilon_()/k_(), epsilon_)
      + epsilonSource()
      + fvOptions(alpha, rho, epsilon_)
    );
Here you can define an additional source term or modify a source already existing. I've tried to modify the epsilonSource as follows:

Code:
template<class BasicTurbulenceModel>
tmp<fvScalarMatrix> YkEpsilon<BasicTurbulenceModel>::epsilonSource() const
{
    tmp<fvScalarMatrix> epsSource
    (
        new fvScalarMatrix
        (
            epsilon_,
            dimVolume*this->rho_.dimensions()*epsilon_.dimensions()
            /dimTime
        )
    );

    const vectorField& C = this->mesh().C();
    const scalarField& V = this->mesh().V();

    scalar C_mu(0.09);
    scalar z0(0.03);

    scalarField& source = epsSource.ref().source();

    forAll(C, i)
    {
        source[i] -=
            C_mu * pow(k_[i] , 2) / 
            pow( C[i].z() + z0 , 2 ) * V[i];
    }

    return epsSource;
}
which modified the term on the equation to include the correction factor you mention. You have there how to access the position and volume fields. In this case no lookup of the k field is necessary because is already refered in the class.
lachuktr likes this.
crubio.abujas is offline   Reply With Quote

Old   July 17, 2021, 03:49
Default
  #7
New Member
 
Lakshman R
Join Date: Apr 2017
Posts: 16
Rep Power: 9
lachuktr is on a distinguished road
Quote:
Originally Posted by crubio.abujas View Post
In the turbulence model the equation is solved when you call the correct() method. There you can see where the equations are implemented:

Code:
    // Dissipation equation
    tmp<fvScalarMatrix> epsEqn
    (
        fvm::ddt(alpha, rho, epsilon_)
      + fvm::div(alphaRhoPhi, epsilon_)
      - fvm::laplacian(alpha*rho*DepsilonEff(), epsilon_)
     ==
        C1_*alpha()*rho()*G*epsilon_()/k_()
      - fvm::SuSp(((2.0/3.0)*C1_ - C3_)*alpha()*rho()*divU, epsilon_)
      - fvm::Sp(C2_*alpha()*rho()*epsilon_()/k_(), epsilon_)
      + epsilonSource()
      + fvOptions(alpha, rho, epsilon_)
    );
Here you can define an additional source term or modify a source already existing. I've tried to modify the epsilonSource as follows:

Code:
template<class BasicTurbulenceModel>
tmp<fvScalarMatrix> YkEpsilon<BasicTurbulenceModel>::epsilonSource() const
{
    tmp<fvScalarMatrix> epsSource
    (
        new fvScalarMatrix
        (
            epsilon_,
            dimVolume*this->rho_.dimensions()*epsilon_.dimensions()
            /dimTime
        )
    );

    const vectorField& C = this->mesh().C();
    const scalarField& V = this->mesh().V();

    scalar C_mu(0.09);
    scalar z0(0.03);

    scalarField& source = epsSource.ref().source();

    forAll(C, i)
    {
        source[i] -=
            C_mu * pow(k_[i] , 2) / 
            pow( C[i].z() + z0 , 2 ) * V[i];
    }

    return epsSource;
}
which modified the term on the equation to include the correction factor you mention. You have there how to access the position and volume fields. In this case no lookup of the k field is necessary because is already refered in the class.

thanks for the help again Carlos....

So can we do it like this to add a separate new source term (by giving a new name) rather than modifying the available one?...

if possible can you help me with that too
lachuktr is offline   Reply With Quote

Old   July 17, 2021, 04:43
Default
  #8
Senior Member
 
Carlos Rubio Abujas
Join Date: Jan 2018
Location: Spain
Posts: 127
Rep Power: 9
crubio.abujas is on a distinguished road
hi Lakshman,

I think you already have enough information to try it yourself. You just have to mix the solution you already have with the YkEpsilon source you shared with me.

If you find any particular problem you can figure out come with specific doubts.

Good luck!
crubio.abujas is offline   Reply With Quote

Old   July 21, 2021, 20:45
Default
  #9
New Member
 
Lakshman R
Join Date: Apr 2017
Posts: 16
Rep Power: 9
lachuktr is on a distinguished road
Thanks a lot, carlos ... that helps a lot for me.
lachuktr is offline   Reply With Quote

Old   July 21, 2021, 22:26
Default
  #10
New Member
 
Lakshman R
Join Date: Apr 2017
Posts: 16
Rep Power: 9
lachuktr is on a distinguished road
Quote:
Originally Posted by crubio.abujas View Post
hi Lakshman,

I think you already have enough information to try it yourself. You just have to mix the solution you already have with the YkEpsilon source you shared with me.

If you find any particular problem you can figure out come with specific doubts.

Good luck!

in that YkEpsilon source, Cmu is considered as a constant (0.09), but for my work, I want to change it to a variable as shown in the attachment.

I am not succeeding in the implementation. Kindly help
Attached Images
File Type: jpg variable cmu.jpg (19.4 KB, 23 views)
lachuktr is offline   Reply With Quote

Old   July 22, 2021, 02:16
Default
  #11
Senior Member
 
Carlos Rubio Abujas
Join Date: Jan 2018
Location: Spain
Posts: 127
Rep Power: 9
crubio.abujas is on a distinguished road
Hello Lakshman,

I think the most straightforward way to do it is creating a scalarField for C_mu. That should be quite simple to implement.

Code:
    scalar u_tau( 0.511);
    scalar z0(0.03);
    scalarField C_mu( pow(u_tau, 4) / pow(k_ , 2) );

    scalarField& source = epsSource.ref().source();

    forAll(C, i)
    {
        source[i] -=
            C_mu[i] * pow(k_[i] , 2) / 
            pow( C[i].z() + z0 , 2 ) * V[i];
     }
P.D: Ensure that you don't miss the C_mu[i] in the surce formula!
lachuktr likes this.
crubio.abujas is offline   Reply With Quote

Reply

Tags
kepsilonmodel, openfaom-7


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
[swak4Foam] Installation Problem with OF 6 version Aurel OpenFOAM Community Contributions 14 November 18, 2020 16:18
source in SA model(or one equation model) lostking18 CFX 3 August 27, 2018 06:39
SparceImage v1.7.x Issue on MAC OS X rcarmi OpenFOAM Installation 4 August 14, 2014 06:42
"parabolicVelocity" in OpenFoam 2.1.0 ? sawyer86 OpenFOAM Running, Solving & CFD 21 February 7, 2012 11:44
DxFoam reader update hjasak OpenFOAM Post-Processing 69 April 24, 2008 01:24


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