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

K-epsilon source term fvOptions

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   May 18, 2021, 04:28
Default K-epsilon source term fvOptions
  #1
Member
 
Kabir Shariff
Join Date: Oct 2016
Location: France
Posts: 53
Rep Power: 10
Kbshariff is on a distinguished road
Hello foamers,

I would like to add a source term (developed by El-kasmi, 2008) to k-epsilon model in open foam. I found a similar source term defined using the atmTurbSource in OFv2006.
I copied the same file and modified the relation but I have an error in compilation.

Here is the original source term defined:
Code:
template<class AlphaFieldType, class RhoFieldType>
void Foam::fv::myAtmAmbientTurbSource::myAtmAmbientTurbSourceEpsilon
(
    const AlphaFieldType& alpha,
    const RhoFieldType& rho,
    fvMatrix<scalar>& eqn,
    const label fieldi
) const
{

    const auto* turbPtr =
        mesh_.findObject<turbulenceModel>
        (
            turbulenceModel::propertiesName
        );

    const volScalarField& epsilon = turbPtr->epsilon();

    // (Heuristically derived from RS:Eq. 4, rhs-term:5)
    eqn +=
//        fvm::Sp(alpha()*rho()*C2_*sqr(epsilonAmb_)/(kAmb_*epsilon()), epsilon);
        fvm::Sp(alpha()*rho()*C2_*sqr(epsilonAmb_)/(kAmb_));
}


template<class AlphaFieldType, class RhoFieldType>
void Foam::fv::myAtmAmbientTurbSource::myAtmAmbientTurbSourceOmega
(
    const AlphaFieldType& alpha,
    const RhoFieldType& rho,
    fvMatrix<scalar>& eqn,
    const label fieldi
) const
{
    const auto* turbPtr =
        mesh_.findObject<turbulenceModel>
        (
            turbulenceModel::propertiesName
        );
    const volScalarField& omega = turbPtr->omega();
    const volScalarField::Internal& beta =
        mesh_.lookupObjectRef<volScalarField::Internal>
        (
            word(turbPtr->type() + ":beta")
        );

    // (RS:Eq. 4, rhs-term:5)
//    eqn += fvm::Sp(alpha()*rho()*Cmu_*beta*sqr(omegaAmb_)/omega(), omega);
    eqn += fvm::Sp(alpha()*rho()*Cmu_*beta*sqr(omegaAmb_)/omega());
}


template<class AlphaFieldType, class RhoFieldType>
void Foam::fv::myAtmAmbientTurbSource::myAtmAmbientTurbSourceK
(
    const AlphaFieldType& alpha,
    const RhoFieldType& rho,
    fvMatrix<scalar>& eqn,
    const label fieldi
) const
{
    const auto* turbPtr =
        mesh_.findObject<turbulenceModel>
        (
            turbulenceModel::propertiesName
        );
    const volScalarField& k = turbPtr->k();

    if (isEpsilon_)
    {
        // (Heuristically derived from RS:Eq. 3, rhs-term:4)
//        eqn += fvm::Sp(alpha()*rho()*epsilonAmb_/k(), k);
        eqn += fvm::Sp(alpha()*rho()*epsilonAmb_);
    }
    else
    {
        // (RS:Eq. 3, rhs-term:4)
//        eqn += fvm::Sp(alpha()*rho()*Cmu_*omegaAmb_*kAmb_/k(), k);
        eqn += fvm::Sp(alpha()*rho()*Cmu_*omegaAmb_*kAmb_);
    }
}
I have this compilation error

Code:
In file included from myAtmAmbientTurbSource.H:259:0,
                 from myAtmAmbientTurbSource.C:29:
myAtmAmbientTurbSourceTemplates.C: In instantiation of ‘void Foam::fv::myAtmAmbientTurbSource::myAtmAmbientTurbSourceK(const AlphaFieldType&, const RhoFieldType&, Foam::fvMatrix<double>&, Foam::label) const [with AlphaFieldType = Foam::geometricOneField; RhoFieldType = Foam::geometricOneField; Foam::label = int]’:
myAtmAmbientTurbSource.C:170:9:   required from here
myAtmAmbientTurbSourceTemplates.C:106:49: error: no matching function for call to ‘Sp(const Foam::dimensioned<double>&)’
         eqn += fvm::Sp(alpha()*rho()*epsilonAmb_);
                                                 ^
myAtmAmbientTurbSourceTemplates.C:106:49: note: candidates are:
In file included from /soft/OpenFOAM-v2006/OpenFOAM-v2006/src/finiteVolume/lnInclude/fvmSup.H:165:0,
                 from /soft/OpenFOAM-v2006/OpenFOAM-v2006/src/finiteVolume/lnInclude/fvm.H:49,
                 from /soft/OpenFOAM-v2006/OpenFOAM-v2006/src/TurbulenceModels/turbulenceModels/lnInclude/linearViscousStress.C:30,
                 from /soft/OpenFOAM-v2006/OpenFOAM-v2006/src/TurbulenceModels/turbulenceModels/lnInclude/linearViscousStress.H:116,
                 from /soft/OpenFOAM-v2006/OpenFOAM-v2006/src/TurbulenceModels/turbulenceModels/lnInclude/Stokes.H:45,
                 from /soft/OpenFOAM-v2006/OpenFOAM-v2006/src/TurbulenceModels/turbulenceModels/lnInclude/laminarModel.C:30,
                 from /soft/OpenFOAM-v2006/OpenFOAM-v2006/src/TurbulenceModels/turbulenceModels/lnInclude/laminarModel.H:201,
                 from /soft/OpenFOAM-v2006/OpenFOAM-v2006/src/TurbulenceModels/incompressible/lnInclude/turbulentTransportModel.H:49,
                 from myAtmAmbientTurbSource.H:118,
                 from myAtmAmbientTurbSource.C:29:
/soft/OpenFOAM-v2006/OpenFOAM-v2006/src/finiteVolume/lnInclude/fvmSup.C:102:1: note: template<class Type> Foam::tmp<Foam::fvMatrix<Type> > Foam::fvm::Sp(const Internal&, const Foam::GeometricField<Type, Foam::fvPatchField, Foam::volMesh>&)
 Foam::fvm::Sp
 ^
/soft/OpenFOAM-v2006/OpenFOAM-v2006/src/finiteVolume/lnInclude/fvmSup.C:102:1: note:   template argument deduction/substitution failed:
In file included from myAtmAmbientTurbSource.H:259:0,
                 from myAtmAmbientTurbSource.C:29:
myAtmAmbientTurbSourceTemplates.C:106:49: note:   cannot convert ‘Foam::operator*<Foam::dimensioned<double> >((*(const Foam::one*)(& Foam::operator*((*(const Foam::oneField*)(&(& alpha)->Foam::geometricOneField::operator()())), (*(const Foam::oneField*)(&(& rho)->Foam::geometricOneField::operator()()))))), (* &((const Foam::fv::myAtmAmbientTurbSource*)this)->Foam::fv::myAtmAmbientTurbSource::epsilonAmb_))’ (type ‘const Foam::dimensioned<double>’) to type ‘const Internal& {aka const Foam::DimensionedField<double, Foam::volMesh>&}’
         eqn += fvm::Sp(alpha()*rho()*epsilonAmb_);

Kindly assist me in debugging please.


Kabir
Attached Images
File Type: png atmTurbSource.PNG (24.8 KB, 17 views)
File Type: png el-kasmi.PNG (8.6 KB, 19 views)
Kbshariff is offline   Reply With Quote

Old   May 18, 2021, 06:42
Default
  #2
Senior Member
 
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 616
Rep Power: 16
mAlletto will become famous soon enough
Code:
fvm::Sp(alpha()*rho()*C2_*sqr(epsilonAmb_)/(kAmb_))
Check out how implicit sources have to be defined. I didn't read your equation but the epsilon is missing in your term
mAlletto is offline   Reply With Quote

Old   May 18, 2021, 07:28
Default
  #3
Member
 
Kabir Shariff
Join Date: Oct 2016
Location: France
Posts: 53
Rep Power: 10
Kbshariff is on a distinguished road
I have now modified the equations. All variables like epsilonAmb_, kAmb_ were declared as constant in boundary conditions. All parameters are explicit now, I have suppressed all depending on implicit terms in.C file because it's not needed in the new equation.


Here is the error I am unable to debug now

Code:
myAtmAmbientTurbSource.C: In constructor ‘Foam::fv::myAtmAmbientTurbSource::myAtmAmbientTurbSource(const Foam::word&, const Foam::word&, const Foam::dictionary&, const Foam::fvMesh&)’:
myAtmAmbientTurbSource.C:155:1: error: expected ‘{’ before ‘void’
 void Foam::fv::myAtmAmbientTurbSource::addSup // I have checked but there is no unclosed  {}
 ^
In file included from myAtmAmbientTurbSource.H:259:0,
                 from myAtmAmbientTurbSource.C:29:
myAtmAmbientTurbSourceTemplates.C: In instantiation of ‘void Foam::fv::myAtmAmbientTurbSource::myAtmAmbientTurbSourceK(const AlphaFieldType&, const RhoFieldType&, Foam::fvMatrix<double>&, Foam::label) const [with AlphaFieldType = Foam::geometricOneField; RhoFieldType = Foam::geometricOneField; Foam::label = int]’:
myAtmAmbientTurbSource.C:170:9:   required from here
myAtmAmbientTurbSourceTemplates.C:108:49: error: no matching function for call to ‘Sp(const Foam::dimensioned<double>&)’
         eqn += fvm::Sp(alpha()*rho()*epsilonAmb_);
THank you,

Kabir
Kbshariff is offline   Reply With Quote

Old   May 18, 2021, 08:50
Default
  #4
Senior Member
 
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 616
Rep Power: 16
mAlletto will become famous soon enough
What is line number 155 where the error occurred
mAlletto is offline   Reply With Quote

Old   May 18, 2021, 10:35
Default
  #5
Member
 
Kabir Shariff
Join Date: Oct 2016
Location: France
Posts: 53
Rep Power: 10
Kbshariff is on a distinguished road
Quote:
Originally Posted by mAlletto View Post
What is line number 155 where the error occurred
This is the line 155

Code:
void Foam::fv::myAtmAmbientTurbSource::addSup //line 155
(
    fvMatrix<scalar>& eqn,
    const label fieldi
)

{
    if (fieldi == 1)
    {
        myAtmAmbientTurbSourceK
        (
            geometricOneField(),
            geometricOneField(),
            eqn,
            fieldi
        );
        return;
    }

    if (isEpsilon_)
    {
        myAtmAmbientTurbSourceEpsilon
        (
            geometricOneField(),
            geometricOneField(),
            eqn,
            fieldi
        );
    }
    else
    {
        myAtmAmbientTurbSourceOmega
        (
            geometricOneField(),
            geometricOneField(),
            eqn,
            fieldi
        );
    }
}
I bypass the error by using empty braket {}.

Now I have these error ( a & b) and are repeated in several lines in the code
(a)
Code:
myAtmAmbientTurbSourceTemplates.C:114:58: error: no matching function for call to ‘Sp(Foam::tmp<Foam::DimensionedField<double, Foam::volMesh> >)’
         eqn += fvm::Sp(alpha()*rho()*Cmu_*omegaAmb_*kAmb_);
// corresponing line 114 is shown in blue below

void Foam::fv::myAtmAmbientTurbSource::myAtmAmbientTurbSourceK
(
    const AlphaFieldType& alpha,
    const RhoFieldType& rho,
    fvMatrix<scalar>& eqn,
    const label fieldi
) const
{
/*
    const auto* turbPtr =
        mesh_.findObject<turbulenceModel>
        (
            turbulenceModel::propertiesName
        );
    //const volScalarField& k = turbPtr->k();
*/
    if (isEpsilon_)
    {
        // (Heuristically derived from RS:Eq. 3, rhs-term:4)
 //       eqn += fvm::Sp(alpha()*rho()*epsilonAmb_/k(), k);
        eqn += fvm::Sp(alpha()*rho()*epsilonAmb_);
    }
    else
    {
        // (RS:Eq. 3, rhs-term:4)
//        eqn += fvm::Sp(alpha()*rho()*Cmu_*omegaAmb_*kAmb_/k(), k);
        eqn += fvm::Sp(alpha()*rho()*Cmu_*omegaAmb_*kAmb_);
    }
}
(b)
Code:
myAtmAmbientTurbSourceTemplates.C:83:53: note:   candidate expects 2 arguments, 1 provided
     eqn += fvm::Sp(alpha()*rho()*Cmu_*sqr(omegaAmb_));
// corresponding line 83 is shown in blue below

template<class AlphaFieldType, class RhoFieldType>
void Foam::fv::myAtmAmbientTurbSource::myAtmAmbientTurbSourceOmega
(
    const AlphaFieldType& alpha,
    const RhoFieldType& rho,
    fvMatrix<scalar>& eqn,
    const label fieldi
) const
{
/*
    const auto* turbPtr =
        mesh_.findObject<turbulenceModel>
        (
            turbulenceModel::propertiesName
        );
    const volScalarField& omega = turbPtr->omega();
    const volScalarField::Internal& beta =
        mesh_.lookupObjectRef<volScalarField::Internal>
        (
            word(turbPtr->type() + ":beta")
        );
*/
    // (RS:Eq. 4, rhs-term:5)
//    eqn += fvm::Sp(alpha()*rho()*Cmu_*beta*sqr(omegaAmb_)/omega(), omega);
    eqn += fvm::Sp(alpha()*rho()*Cmu_*sqr(omegaAmb_));
}
Merci
Kbshariff is offline   Reply With Quote

Old   May 18, 2021, 11:30
Default
  #6
Senior Member
 
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 616
Rep Power: 16
mAlletto will become famous soon enough
Did you try
Code:
fvc::Sp(alpha()*rho()*C2_*sqr(epsilonAmb_)/(kAmb_))
Please have a look how explicit and implicit sources are implemented in OF
mAlletto is offline   Reply With Quote

Old   May 26, 2021, 10:15
Default
  #7
Member
 
Kabir Shariff
Join Date: Oct 2016
Location: France
Posts: 53
Rep Power: 10
Kbshariff is on a distinguished road
Quote:
Originally Posted by mAlletto View Post
Did you try
Code:
fvc::Sp(alpha()*rho()*C2_*sqr(epsilonAmb_)/(kAmb_))
Please have a look at how explicit and implicit sources are implemented in OF
Sorry for my late reply.

I have check how implicit and explicit terms are applied.
the implicit is in the form of
Code:
fvc::Sp(A,B)
In my case since all the values are constants, I applied the source term as:

Code:
       eqn += alpha()*rho()*epsilonAmb_;;
And it compiled successfully.
The problem now is that the source term is applied in the entire domain not only the region I defined as topoSet.
Here are the results without source and with a source at disc region.
How do I limit the source term to the cellSet region only, please?

Thank you
Attached Images
File Type: jpg TI_no_source.JPG (22.2 KB, 10 views)
File Type: jpg k-e_no source.JPG (32.3 KB, 6 views)
File Type: jpg TI_source.JPG (17.6 KB, 7 views)
File Type: jpg k-e_source.JPG (36.7 KB, 6 views)
Kbshariff is offline   Reply With Quote

Old   June 2, 2021, 07:41
Default
  #8
Member
 
Kabir Shariff
Join Date: Oct 2016
Location: France
Posts: 53
Rep Power: 10
Kbshariff is on a distinguished road
Hello,
Here is my topoSet Dict
Code:
    // sourceDisk1
    {
        name    sourceDisk1CellSet;
        type    cellSet;
        action  new;
        source  cylinderToCell;
        sourceInfo
        {
            radius 0.135;
		p1 (5.9 2.5 0.225);
		p2 (6.1 2.5 0.225);
        }
    }
    {
        name    sourceDisk1;
        type    cellZoneSet;
        action  new;
        source  setToCellZone;
        sourceInfo
        {
            set sourceDisk1CellSet;
        }
    }
My problem now is the source is applied throughout the domain. How can I apply it to soureDisk only?

Thank you.
Kbshariff is offline   Reply With Quote

Old   June 2, 2021, 09:31
Default
  #9
Senior Member
 
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 616
Rep Power: 16
mAlletto will become famous soon enough
You can specify for a fvoption the cellset where it is applied
mAlletto is offline   Reply With Quote

Old   June 2, 2021, 10:04
Default
  #10
Member
 
Kabir Shariff
Join Date: Oct 2016
Location: France
Posts: 53
Rep Power: 10
Kbshariff is on a distinguished road
Here is my fvOptions, I have specified the location defined in topoSet for myAtmTurbSource as follows:

Code:
disk1
{
    type            actuationDiskSource;
    variant         Froude;
    selectionMode   cellSet;
    cellSet         actuationDisk1;
    diskArea        0.50265;
    diskDir         (1 0 0);
    writeToFile     true;
    sink            true;
    Cp		    0.42;
    Ct		    0.83;


    
    monitorMethod   cellSet;
    cellSet         actuationDisk1;

}

atmAmbientTurbSource1
{
    type                atmAmbientTurbSource;
    atmAmbientTurbSourceCoeffs
    {
   	selectionMode   cellSet;
    	cellSet         actuationDisk1;
        kAmb            0.0216;   	// +15%
        epsilonAmb      3.725e-3;
    }
}
The code disk1 applies the actuationDisk term at the defined location but the ambTurbSource applies it in the whole domain as shown in the previous post.
Kbshariff is offline   Reply With Quote

Old   June 5, 2021, 05:28
Default
  #11
Senior Member
 
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 616
Rep Power: 16
mAlletto will become famous soon enough
How do you know the fvoption applies in the whole domain and not only in the cellset you specified
mAlletto is offline   Reply With Quote

Old   June 8, 2021, 10:00
Default
  #12
Member
 
Kabir Shariff
Join Date: Oct 2016
Location: France
Posts: 53
Rep Power: 10
Kbshariff is on a distinguished road
Quote:
Originally Posted by mAlletto View Post
How do you know the fvoption applies in the whole domain and not only in the cellset you specified
The figure below shows the values of TI, k, and epsilon for two simulations (a) without source and (b) with source applied to the disc

(a) The profile without source is decaying as expected
(b) the profile with a source at the disc maintains the kAmb and epsilonAmb throughout the domain.
Moreover, when I used the 'select all' instead of 'cellset' (actuatorDisc) the result is also the same as the source in the disc region only.
Attached Images
File Type: jpg k-e_no source.JPG (32.3 KB, 5 views)
File Type: jpg k-e_source.JPG (36.7 KB, 4 views)
File Type: jpg TI_source.JPG (17.6 KB, 3 views)
File Type: jpg TI_no_source.JPG (22.2 KB, 2 views)
Kbshariff is offline   Reply With Quote

Old   June 11, 2021, 11:59
Default
  #13
Member
 
Kabir Shariff
Join Date: Oct 2016
Location: France
Posts: 53
Rep Power: 10
Kbshariff is on a distinguished road
Hi,

I think I found the reason why the source term is applied in the whole domain instead of the region defined.

I run a simulation of the channel with the source term but without the actuator disc to see the effect of the source term.


From my simpleFoam log, I found this:

Code:
Creating finite volume options from "constant/fvOptions"

Selecting finite volume options type atmAmbientTurbSource
    Source: atmAmbientTurbSource1
    - selecting cells using cellZone zone1
    - selected 12325 cell(s) with volume 0.0929195759224
    Applying atmAmbientTurbSource to: epsilon and k

Starting time loop

turbulenceFields turbulenceFields: storing fields:
    turbulenceProperties:I
From the log file, the source is applied to epsilon and k,

How can I change it to

Applying atmAmbientTurbSource to: zone1 ?


Here is my fvOptions and topoSet

fvOptions:
Code:
    object      fvOptions;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //


atmAmbientTurbSource1
{
    type                atmAmbientTurbSource;
    atmAmbientTurbSourceCoeffs
    {
   	selectionMode   cellZone;
    	cellZone       	zone1;
        kAmb            0.0096;   	// +10%
        epsilonAmb      1.1e-3;
    }
}
topoSet:
Code:
    object      topoSetDict;
}

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

actions
(
    {
        name    box1b;
        type    cellSet;
        action  new;
        source  boxToCell;
        box     (3.8 2.4 0.4) (4.2 2.6 1.6);
    }

    {
        name    zone1;
        type    cellZoneSet;
        action  new;
        source  setToCellZone;
        set     box1b;
    }



);
Merci

- Kabir
Kbshariff is offline   Reply With Quote

Old   June 12, 2021, 17:16
Default
  #14
Senior Member
 
Joachim Herb
Join Date: Sep 2010
Posts: 650
Rep Power: 22
jherb is on a distinguished road
The documentation https://www.openfoam.com/documentati...urbSource.html says:
Code:
        // Mandatory (inherited) entries (unmodifiable)
        selectionMode    all;
If you look at the source code of other source terms, e.g. https://github.com/OpenFOAM/OpenFOAM...sSource.C#L128 there are loops over the cells, the source should be applied to.
So you can expect, that your source is applied in the whole flow domain.


Are you using OpenFOAM.com or OpenFOAM.org? For the first one, here is another example: https://develop.openfoam.com/Develop...gSource.C#L193
jherb is offline   Reply With Quote

Old   June 15, 2021, 07:42
Default
  #15
Member
 
Kabir Shariff
Join Date: Oct 2016
Location: France
Posts: 53
Rep Power: 10
Kbshariff is on a distinguished road
Quote:
Originally Posted by jherb View Post
The documentation https://www.openfoam.com/documentati...urbSource.html says:
Code:
        // Mandatory (inherited) entries (unmodifiable)
        selectionMode    all;
If you look at the source code of other source terms, e.g. https://github.com/OpenFOAM/OpenFOAM...sSource.C#L128 there are loops over the cells, the source should be applied to.
So you can expect, that your source is applied in the whole flow domain.


Are you using OpenFOAM.com or OpenFOAM.org? For the first one, here is another example: https://develop.openfoam.com/Develop...gSource.C#L193

Hi,

I am using OpenFOAM.com, specifically v2006. Thanks, I will check the new example.
Kbshariff is offline   Reply With Quote

Reply

Tags
error, fvoptions, k-epsilon turbulence, source terms


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
Adding source term with fvOptions to k-e model Tibo99 OpenFOAM Programming & Development 20 March 15, 2023 08:12
[swak4Foam] swak4foam for OpenFOAM 4.0 mnikku OpenFOAM Community Contributions 80 May 17, 2022 09:06
Source term for EVAPORATION in Energy Equ. - technical difficulty ? Kummi OpenFOAM 1 September 9, 2019 10:32
[foam-extend.org] Problems installing foam-extend-4.0 on openSUSE 42.2 and Ubuntu 16.04 ordinary OpenFOAM Installation 19 September 3, 2019 19:13
DxFoam reader update hjasak OpenFOAM Post-Processing 69 April 24, 2008 02:24


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