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

Subgrid Viscosity - modifying Smagorinsky

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By carlDahmen

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   January 27, 2022, 20:41
Thumbs up Subgrid Viscosity - modifying Smagorinsky
  #1
New Member
 
Carl Dahmen
Join Date: Jan 2022
Posts: 6
Rep Power: 4
carlDahmen is on a distinguished road
Hello Foamer!

I am working with CFDEM, but my question is OpenFOAM related.
My aim is to modify the Smagorinsky turbulence model and implement a viscosity that depends on the local voidfraction according to Batchelor and Green (1972) as: nu_t = nu*(a*(1-voidfraction)+b*(1-voidfraction)^2)

Since my OpenFOAM knowledge is lacking, have I tried to follow the Smagorinsky model as closely as I can and followed guides to implement a new turbelence model. But my problem comes down to accessing the voidfraction, I assume this can be done by using IOobject but I do not know how.

Here is my code (Protected Member Functions):

Code:
template<class BasicTurbulenceModel>
tmp<volScalarField> BatchelorGreen<BasicTurbulenceModel>::k
(
    const tmp<volScalarField>& voidfrac
) const
{
    volScalarField solidfrac(scalar(1)-voidfrac);

    volScalarField c1(nu_*a_*solidfrac);
    volScalarField c2(nu_*b_*sqr(solidfrac));

    return tmp<volScalarField>
    (
        new volScalarField
        (
            IOobject
            (
                IOobject::groupName("k", this->U_.group()),
                this->runTime_.timeName(),
                this->mesh_
            ),
            c1+c2
        )
    );
}

template<class BasicTurbulenceModel>
void BatchelorGreen<BasicTurbulenceModel>::correctNut()
{
    new volScalarField
    (
	IOobject
	(
	    IOobject::groupName("voidfraction", this->U_.group()),
	    this->runTime_.timeName(),
	    this->mesh_,
	    IOobject::MUST_READ,
	    IOobject::NO_WRITE
	)
    )
	
    volScalarField k(this->k(this->voidfraction_)); 

    this->nut_ = k;
    fv::options::New(this->mesh_).correct(this->nut_);

    BasicTurbulenceModel::correctNut();
}
carlDahmen is offline   Reply With Quote

Old   January 30, 2022, 17:31
Default Update
  #2
New Member
 
Carl Dahmen
Join Date: Jan 2022
Posts: 6
Rep Power: 4
carlDahmen is on a distinguished road
Hey!


My code runs now, need to verify the result. It is attached for anyone interested.




Code:
\*---------------------------------------------------------------------------*/

#include "BatchelorGreen.H"
#include "fvOptions.H"

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

namespace Foam
{
namespace LESModels
{

// * * * * * * * * * * * * Protected Member Functions  * * * * * * * * * * * //

template<class BasicTurbulenceModel>
tmp<volScalarField> BatchelorGreen<BasicTurbulenceModel>::k
(
    const tmp<volScalarField>& voidfrac
) const
{
    volScalarField solidfrac(scalar(1)-voidfrac);

    volScalarField c1(a_*solidfrac+b_*sqr(solidfrac));

    return tmp<volScalarField>
    (
        new volScalarField
        (
            IOobject
            (
                IOobject::groupName("k", this->U_.group()),
                this->runTime_.timeName(),
                this->mesh_
            ),
            c1
        )
    );
}

template<class BasicTurbulenceModel>
void BatchelorGreen<BasicTurbulenceModel>::correctNut()
{
    
    volScalarField k(voidfraction_); 

    this->nut_ = this->nu()*k;
    fv::options::New(this->mesh_).correct(this->nut_);

    BasicTurbulenceModel::correctNut();
}


// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //

template<class BasicTurbulenceModel>
BatchelorGreen<BasicTurbulenceModel>::BatchelorGreen
(
    const alphaField& alpha,
    const rhoField& rho,
    const volVectorField& U,
    const surfaceScalarField& alphaRhoPhi,
    const surfaceScalarField& phi,
    const transportModel& transport,
    const word& propertiesName,
    const word& type
)
:
    LESeddyViscosity<BasicTurbulenceModel>
    (
        type,
        alpha,
        rho,
        U,
        alphaRhoPhi,
        phi,
        transport,
        propertiesName
    ),

    a_
    (
        dimensioned<scalar>::lookupOrAddToDict
        (
            "a",
            this->coeffDict_,
            2.5
        )
    ),

    b_
    (
        dimensioned<scalar>::lookupOrAddToDict
        (
            "b",
            this->coeffDict_,
            7.6
        )
    ),

    voidfraction_
    (
    IOobject
    (
        "voidfraction",
        this->runTime_.timeName(),
            this->mesh_,
        IOobject::MUST_READ,
        IOobject::NO_WRITE
    ),
    this->mesh_
    )

{
    if (type == typeName)
    {
        this->printCoeffs(type);
    }
}


// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //

template<class BasicTurbulenceModel>
bool BatchelorGreen<BasicTurbulenceModel>::read()
{
    if (LESeddyViscosity<BasicTurbulenceModel>::read())
    {
        a_.readIfPresent(this->coeffDict());
    b_.readIfPresent(this->coeffDict());

        return true;
    }
    else
    {
        return false;
    }
}



template<class BasicTurbulenceModel>
void BatchelorGreen<BasicTurbulenceModel>::correct()
{
    LESeddyViscosity<BasicTurbulenceModel>::correct();
    correctNut();
}


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

} // End namespace LESModels
} // End namespace Foam

Last edited by carlDahmen; January 30, 2022 at 20:14.
carlDahmen is offline   Reply With Quote

Old   January 31, 2022, 18:25
Default It doesn't work
  #3
New Member
 
Carl Dahmen
Join Date: Jan 2022
Posts: 6
Rep Power: 4
carlDahmen is on a distinguished road
Seems like the voidfraction is not updated, how do I declare it in the Header file?
carlDahmen is offline   Reply With Quote

Old   February 3, 2022, 12:17
Default
  #4
Senior Member
 
Josh Williams
Join Date: Feb 2021
Location: Scotland
Posts: 112
Rep Power: 5
joshwilliams is on a distinguished road
Quote:
Originally Posted by carlDahmen View Post
Seems like the voidfraction is not updated, how do I declare it in the Header file?
In your header file you can put

Code:
volVectorField UsTilde_;



Or in your *.C file you can put somewhere
Code:
    const volScalarField& voidFraction = mesh.lookupObject<volScalarField>("voidFraction");
joshwilliams is offline   Reply With Quote

Old   February 3, 2022, 20:11
Default Error message
  #5
New Member
 
Carl Dahmen
Join Date: Jan 2022
Posts: 6
Rep Power: 4
carlDahmen is on a distinguished road
Thank you for your answer!

I have put in my correctNut() in the *.C file:
Code:
const volScalarField& voidfraction_ = this->mesh().lookupObject<volScalarField>("voidfraction");
But I get the error message:
Quote:
error: expected primary-expression before '>' token
Do you now what's wrong?
carlDahmen is offline   Reply With Quote

Old   February 3, 2022, 20:49
Default Solved it!
  #6
New Member
 
Carl Dahmen
Join Date: Jan 2022
Posts: 6
Rep Power: 4
carlDahmen is on a distinguished road
It's a template class and I needed:

Code:
const volScalarField& voidfraction_ = this->mesh().template lookupObject<volScalarField>("voidfraction");
joshwilliams likes this.
carlDahmen is offline   Reply With Quote

Reply

Tags
cfdem, smagorinsky, subgrid, viscosity, voidfraction


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
Multiphase non-Newtonian viscosity of blood mdmtramper Fluent Multiphase 3 January 22, 2021 06:09
Problem with divergence TDK FLUENT 13 December 14, 2018 06:00
Quality assessment of LES by the subgrid viscosity ratio shuangqingx Main CFD Forum 13 August 21, 2013 19:53
Compact FD stencils for smagorinsky subgrid force? Dieter Main CFD Forum 2 May 29, 2007 20:07
subgrid turbulent viscosity for UDF in LES David TAIEB FLUENT 0 April 2, 2007 08:27


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