|
[Sponsors] |
How to add the source term to epsilon equation of K epsilon model. |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
July 13, 2021, 03:02 |
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 |
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. |
|
July 14, 2021, 13:11 |
|
#2 |
Senior Member
Carlos Rubio Abujas
Join Date: Jan 2018
Location: Spain
Posts: 127
Rep Power: 11 |
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 hope that helps. |
|
July 14, 2021, 22:26 |
|
#3 | |
New Member
Lakshman R
Join Date: Apr 2017
Posts: 16
Rep Power: 9 |
Quote:
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. |
||
July 15, 2021, 03:07 |
|
#4 |
Senior Member
Carlos Rubio Abujas
Join Date: Jan 2018
Location: Spain
Posts: 127
Rep Power: 11 |
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; |
|
July 15, 2021, 13:27 |
|
#5 |
New Member
Lakshman R
Join Date: Apr 2017
Posts: 16
Rep Power: 9 |
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. Last edited by lachuktr; July 15, 2021 at 21:34. |
|
July 17, 2021, 04:27 |
|
#6 |
Senior Member
Carlos Rubio Abujas
Join Date: Jan 2018
Location: Spain
Posts: 127
Rep Power: 11 |
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_) ); 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; } |
|
July 17, 2021, 04:49 |
|
#7 | |
New Member
Lakshman R
Join Date: Apr 2017
Posts: 16
Rep Power: 9 |
Quote:
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 |
||
July 17, 2021, 05:43 |
|
#8 |
Senior Member
Carlos Rubio Abujas
Join Date: Jan 2018
Location: Spain
Posts: 127
Rep Power: 11 |
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! |
|
July 21, 2021, 21:45 |
|
#9 |
New Member
Lakshman R
Join Date: Apr 2017
Posts: 16
Rep Power: 9 |
Thanks a lot, carlos ... that helps a lot for me.
|
|
July 21, 2021, 23:26 |
|
#10 | |
New Member
Lakshman R
Join Date: Apr 2017
Posts: 16
Rep Power: 9 |
Quote:
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 |
||
July 22, 2021, 03:16 |
|
#11 |
Senior Member
Carlos Rubio Abujas
Join Date: Jan 2018
Location: Spain
Posts: 127
Rep Power: 11 |
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]; } |
|
September 12, 2024, 13:03 |
|
#12 | |
Member
Marķa Rosales
Join Date: Mar 2023
Location: Spain
Posts: 48
Rep Power: 3 |
Quote:
Hello Lakshman, I'm curious, which theory of atmospheric boundary layer proposes those source terms in epsilon field? additionally, was finally correct to compute the epsilon source term values by the volume of the cell? I have my doubts if it's related to finite volume method Thanks for any info |
||
Tags |
kepsilonmodel, openfaom-7 |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[swak4Foam] Installation Problem with OF 6 version | Aurel | OpenFOAM Community Contributions | 14 | November 18, 2020 17:18 |
source in SA model(or one equation model) | lostking18 | CFX | 3 | August 27, 2018 07:39 |
SparceImage v1.7.x Issue on MAC OS X | rcarmi | OpenFOAM Installation | 4 | August 14, 2014 07:42 |
"parabolicVelocity" in OpenFoam 2.1.0 ? | sawyer86 | OpenFOAM Running, Solving & CFD | 21 | February 7, 2012 12:44 |
DxFoam reader update | hjasak | OpenFOAM Post-Processing | 69 | April 24, 2008 02:24 |