A Thorough Description Of How Wall Functions Are ...hani/.../FangqingLiu/pptFinal.pdf · Some basic...

30
Some basic theory Wall function in openfoam Structure and implemention A Thorough Description Of How Wall Functions Are Implemented In OpenFOAM Fangqing liu Naval architecture and ocean engineering, Chalmers University of Technology, Gothenburg, Sweden 2016-12-08 Fangqing Liu Wall functions 2016-12-08 1 / 30

Transcript of A Thorough Description Of How Wall Functions Are ...hani/.../FangqingLiu/pptFinal.pdf · Some basic...

Page 1: A Thorough Description Of How Wall Functions Are ...hani/.../FangqingLiu/pptFinal.pdf · Some basic theory Wall function in openfoamStructure and implemention What is wall function

Some basic theory Wall function in openfoam Structure and implemention

A Thorough Description Of How Wall Functions AreImplemented In OpenFOAM

Fangqing liu

Naval architecture and ocean engineering,Chalmers University of Technology,

Gothenburg, Sweden

2016-12-08

Fangqing Liu Wall functions 2016-12-08 1 / 30

Page 2: A Thorough Description Of How Wall Functions Are ...hani/.../FangqingLiu/pptFinal.pdf · Some basic theory Wall function in openfoamStructure and implemention What is wall function

Some basic theory Wall function in openfoam Structure and implemention

What is wall function and why we use it

Outline

1 Basic theory

2 wall function in openfoam

3 structure and implementation

Fangqing Liu Wall functions 2016-12-08 2 / 30

Page 3: A Thorough Description Of How Wall Functions Are ...hani/.../FangqingLiu/pptFinal.pdf · Some basic theory Wall function in openfoamStructure and implemention What is wall function

Some basic theory Wall function in openfoam Structure and implemention

What is wall function and why we use it

Why using wall functions

In order to solve the boundary layer of wall bounded flow:

1 Wall integration of turbulence modelsFirst computational cell above the wall to be located within theviscous sublayer, at about y+ = 1.

2 Wall functionsThe first cell might be placed in the logarithmic layer, leading to asignificant reduction of cells number.

Empirical formula.

Set the boundary condition.

Fangqing Liu Wall functions 2016-12-08 3 / 30

Page 4: A Thorough Description Of How Wall Functions Are ...hani/.../FangqingLiu/pptFinal.pdf · Some basic theory Wall function in openfoamStructure and implemention What is wall function

Some basic theory Wall function in openfoam Structure and implemention

What is wall function and why we use it

What is the wall function

Figure:

Fangqing Liu Wall functions 2016-12-08 4 / 30

Page 5: A Thorough Description Of How Wall Functions Are ...hani/.../FangqingLiu/pptFinal.pdf · Some basic theory Wall function in openfoamStructure and implemention What is wall function

Some basic theory Wall function in openfoam Structure and implemention

What is wall function and why we use it

Some parameters

y+ =y × uτν

Where y is the distance from wall to thepatch, ν is the viscosity. uτ is the frictionvelocity.

u+ =u

uτWhere u is the velocity parallel to the wall.

uτ =

√τwρ

Where τw is the wall shear stress.

For the definition of near wall area and the derivation of wall functions.

Fangqing Liu Wall functions 2016-12-08 5 / 30

Page 6: A Thorough Description Of How Wall Functions Are ...hani/.../FangqingLiu/pptFinal.pdf · Some basic theory Wall function in openfoamStructure and implemention What is wall function

Some basic theory Wall function in openfoam Structure and implemention

What is wall function and why we use it

Near wall region

u+ = y+In this layer the fluid is dominated by theviscous of wall it can be assumed that theshear stress in the flow is equal to the wallshear stress uτ .

u+ =1

κ× In(Ey+)

In this area the turbulence stress decides theflow

Buffer layer

Fangqing Liu Wall functions 2016-12-08 6 / 30

Page 7: A Thorough Description Of How Wall Functions Are ...hani/.../FangqingLiu/pptFinal.pdf · Some basic theory Wall function in openfoamStructure and implemention What is wall function

Some basic theory Wall function in openfoam Structure and implemention

What is wall function and why we use it

The derivation of wall function

refer to the paperNear-wall behavior of RANS turbulence models and implications forwall functions

The dimensionless form:

U+ =U

uτ; k+ =

k

uτ 2; ε+ =

εν

uτ 4; v2

+=

v2

uτ 2; f+ =

uτ 2

V2-f and k-ω turbulence model in viscous and log area

Fangqing Liu Wall functions 2016-12-08 7 / 30

Page 8: A Thorough Description Of How Wall Functions Are ...hani/.../FangqingLiu/pptFinal.pdf · Some basic theory Wall function in openfoamStructure and implemention What is wall function

Some basic theory Wall function in openfoam Structure and implemention

Boundary condition

Abstract class boundary condition

FvPatchField.H

The first level of derivation is to basic patchFields which coverzero-gradient fixed-gradient , fixed-value and mixed condition

Neumonn DirichletMixture of Neumonnand Dirichlet

1 updateCoeffs()

2 evaluate

Fangqing Liu Wall functions 2016-12-08 8 / 30

Page 9: A Thorough Description Of How Wall Functions Are ...hani/.../FangqingLiu/pptFinal.pdf · Some basic theory Wall function in openfoamStructure and implemention What is wall function

Some basic theory Wall function in openfoam Structure and implemention

Boundary condition

Approximate structure

Location of wall funcitons

$FOAM_SRC/TurbulenceModels/turbulenceModels/

derivedFvPatchFields/wallFunctions

In the directory there is are six kinds of wall function files:

epsilonWallFunctions two kinds

kqRWallFunctions two kinds

omegaWallFunctions one kind

fWallFunctions one kind

nutWallFunctions eight kinds

v2WallFunctions one kind

Fangqing Liu Wall functions 2016-12-08 9 / 30

Page 10: A Thorough Description Of How Wall Functions Are ...hani/.../FangqingLiu/pptFinal.pdf · Some basic theory Wall function in openfoamStructure and implemention What is wall function

Some basic theory Wall function in openfoam Structure and implemention

Wall Functions

YplusLam

border between the viscous and log-law layer

Foam::epsilonLowReWallFunctionFvPatchScalarField::yPlusLam

( const scalar kappa,

const scalar E )

{scalar ypl = 11.0;

for (int i=0; i<10; i++)

{

ypl = log(max(E*ypl, 1))/kappa;

}

return ypl;}

ypl =log(max(E × ypl+, 1))

κ

Result is about 11.53

Fangqing Liu Wall functions 2016-12-08 10 / 30

Page 11: A Thorough Description Of How Wall Functions Are ...hani/.../FangqingLiu/pptFinal.pdf · Some basic theory Wall function in openfoamStructure and implemention What is wall function

Some basic theory Wall function in openfoam Structure and implemention

Wall Functions

Turbulence kinetic energy

kWallFunctionIn this directory the kqRWallFunctions includes two directories

kqRWallFunction (inheret from zeroGradientFvPatchField) only

kLowReWallFunction (inheret from fixedValueFvPatchField)

Fangqing Liu Wall functions 2016-12-08 11 / 30

Page 12: A Thorough Description Of How Wall Functions Are ...hani/.../FangqingLiu/pptFinal.pdf · Some basic theory Wall function in openfoamStructure and implemention What is wall function

Some basic theory Wall function in openfoam Structure and implemention

Wall Functions

update

In the FvPatchField : this is a base class for all the boundary conditionclass.

if (updated())

{

return;

}

bool updated() const

{

return updated_;

}

void Foam::fvPatchField<Type>::updateCoeffs()

{

updated_ = true;

}Fangqing Liu Wall functions 2016-12-08 12 / 30

Page 13: A Thorough Description Of How Wall Functions Are ...hani/.../FangqingLiu/pptFinal.pdf · Some basic theory Wall function in openfoamStructure and implemention What is wall function

Some basic theory Wall function in openfoam Structure and implemention

Wall Functions

Details

const scalarField& y = turbModel.y()[patchi];

const tmp<volScalarField> tk = turbModel.k();

const volScalarField& k = tk();

const tmp<scalarField> tnuw = turbModel.nu(patchi);

const scalarField& nuw = tnuw();

const turbulenceModel& turbModel =

db().lookupObject<turbulenceModel>

include ”turbulenceModel.H”

//- Return the near wall distances

//- Return the laminar viscosity

//-Return the turbulence kinetic energy

To the theory part.Fangqing Liu Wall functions 2016-12-08 13 / 30

Page 14: A Thorough Description Of How Wall Functions Are ...hani/.../FangqingLiu/pptFinal.pdf · Some basic theory Wall function in openfoamStructure and implemention What is wall function

Some basic theory Wall function in openfoam Structure and implemention

Wall Functions

Two modes calculation 1

The calculation of yPlus and friction velocity: (faceCelli)

label faceCelli = patch().faceCells()[facei];

scalar uTau = Cmu25*sqrt(k[faceCelli]);

scalar yPlus = uTau*y[facei]/nuw[facei];

uτ = C1/4µ

√k

y+ =y × uτν

Fangqing Liu Wall functions 2016-12-08 14 / 30

Page 15: A Thorough Description Of How Wall Functions Are ...hani/.../FangqingLiu/pptFinal.pdf · Some basic theory Wall function in openfoamStructure and implemention What is wall function

Some basic theory Wall function in openfoam Structure and implemention

Wall Functions

Two modes calculation 2

forAll(kw, facei)

(yPlus > yPlusLam_)

{

scalar Ck = -0.416;

scalar Bk = 8.366;

kw[facei] = Ck/kappa_*log(yPlus) + Bk;

}

else

{

scalar C = 11.0;

scalar Cf = (1.0/sqr(yPlus + C) + 2.0*yPlus/pow3(C) -

1.0/sqr(C));

kw[facei] = 2400.0/sqr(Ceps2_)*Cf;

}

kw[facei] *= sqr(uTau); // put dimentioneless to dumentioned

} Fangqing Liu Wall functions 2016-12-08 15 / 30

Page 16: A Thorough Description Of How Wall Functions Are ...hani/.../FangqingLiu/pptFinal.pdf · Some basic theory Wall function in openfoamStructure and implemention What is wall function

Some basic theory Wall function in openfoam Structure and implemention

Wall Functions

v2 and f wall function

1 v2Wallfunctions provide the stress normal to streamlines boundarycondition

2 fWallfunctions provides the damping function

1 one kind

2 similar structure two modes

3 f wall function is not same as theory.

Fangqing Liu Wall functions 2016-12-08 16 / 30

Page 17: A Thorough Description Of How Wall Functions Are ...hani/.../FangqingLiu/pptFinal.pdf · Some basic theory Wall function in openfoamStructure and implemention What is wall function

Some basic theory Wall function in openfoam Structure and implemention

Wall Functions

Epsilon wall function

Internal valueupdateCoeffs()

1 epsilonWallFunction2 epsilonLowReWallFunction

Inheret relationship

εcenter =1

3ε1 +

1

3ε2 +

1

3ε3

Fangqing Liu Wall functions 2016-12-08 17 / 30

Page 18: A Thorough Description Of How Wall Functions Are ...hani/.../FangqingLiu/pptFinal.pdf · Some basic theory Wall function in openfoamStructure and implemention What is wall function

Some basic theory Wall function in openfoam Structure and implemention

Wall Functions

epsilonWallFunction

updateCoeffs()

1 setMaster()Setting the master patch.master_ is the ID of the master patch.

Master doing the main calculation.

2 createAveragingWeights()Creating the averaging corner weightscornerWeights_is used to list the averaging corner weights.

3 calculateTurbulenceFields()Main calculationit call member function calculate.

Fangqing Liu Wall functions 2016-12-08 18 / 30

Page 19: A Thorough Description Of How Wall Functions Are ...hani/.../FangqingLiu/pptFinal.pdf · Some basic theory Wall function in openfoamStructure and implemention What is wall function

Some basic theory Wall function in openfoam Structure and implemention

Wall Functions

setMaster

open epsilonWallFunctionFvPatchScalarField.Ccheck the setMaster() function

An simple examplepatch with patchi=0 ; First patch

patch with patchi=1 ; Second patch

const scalarField& epsilon0 = this->epsilon();

open epsilonWallFunctionFvPatchScalarField.Ccheck the epsilon() function

//- Return non-const access to the master’s epsilon field

scalarField& epsilon(bool init = false);

Fangqing Liu Wall functions 2016-12-08 19 / 30

Page 20: A Thorough Description Of How Wall Functions Are ...hani/.../FangqingLiu/pptFinal.pdf · Some basic theory Wall function in openfoamStructure and implemention What is wall function

Some basic theory Wall function in openfoam Structure and implemention

Wall Functions

calculation part

Only for master patch

patch().index() == master_

createAveragingWeights()

calculateTurbulenceFields (call member function calculate)w is the cornerweight

ε =1

W

W∑f=i

(c3/4µ k3/2

κyi

)

Fangqing Liu Wall functions 2016-12-08 20 / 30

Page 21: A Thorough Description Of How Wall Functions Are ...hani/.../FangqingLiu/pptFinal.pdf · Some basic theory Wall function in openfoamStructure and implemention What is wall function

Some basic theory Wall function in openfoam Structure and implemention

Wall Functions

omega wall function

Turbulence specific dissipationSimilar to the epsilon

AutomaticCombination of viscous and log

ω =√ω2V is + ω2

Log

Fangqing Liu Wall functions 2016-12-08 21 / 30

Page 22: A Thorough Description Of How Wall Functions Are ...hani/.../FangqingLiu/pptFinal.pdf · Some basic theory Wall function in openfoamStructure and implemention What is wall function

Some basic theory Wall function in openfoam Structure and implemention

Wall Functions

Turbulence viscosity

Why do we need it?

τw = ν · ∂U∂n|w (1)

τw = νUc − Uw

y(2)

uτ = C1/4µ k1/2

In log area

τw = ρuτ ·U

U+=ρuτ (Up − Uw)

1κ ln(Ey

+)

νnew =uτy

1κ ln(Ey

+)=

y+ν1κ ln(Ey

+)= ν + νt

νt = ν ·(

κy+

ln(Ey+)− 1

)νnew =

uτy1κ ln(Ey

+)=

y+ν1κ ln(Ey

+)= ν + νt

Fangqing Liu Wall functions 2016-12-08 22 / 30

Page 23: A Thorough Description Of How Wall Functions Are ...hani/.../FangqingLiu/pptFinal.pdf · Some basic theory Wall function in openfoamStructure and implemention What is wall function

Some basic theory Wall function in openfoam Structure and implemention

Wall Functions

Abstract class of nut wall functions

void nutWallFunctionFvPatchScalarField::updateCoeffs()

{

if (updated())

{

return;

}

operator==(calcNut());

fixedValueFvPatchScalarField::updateCoeffs();

}

Fangqing Liu Wall functions 2016-12-08 23 / 30

Page 24: A Thorough Description Of How Wall Functions Are ...hani/.../FangqingLiu/pptFinal.pdf · Some basic theory Wall function in openfoamStructure and implemention What is wall function

Some basic theory Wall function in openfoam Structure and implemention

Wall Functions

nutkwallfunction

1 nutw

2 standard wall function.

Here yplus is calculated in the function like before. defined but not uesd:

yPlus()

yPlusRAS.C:calculate the yplus for all wall patches when using RASturbulence model:

Fangqing Liu Wall functions 2016-12-08 24 / 30

Page 25: A Thorough Description Of How Wall Functions Are ...hani/.../FangqingLiu/pptFinal.pdf · Some basic theory Wall function in openfoamStructure and implemention What is wall function

Some basic theory Wall function in openfoam Structure and implemention

Wall Functions

nutUwallfunction

This function is similar to the nutkwallfunciton.But the functionCalcYPlus should be paid attention.(Newton-Raphson iteration)

U+ =Ucuτ

=1

κln(Ey+)

Ucyuτ/ν

· (y/ν) = Ucy+· (y/ν) = 1

κln(Ey+)

y+ ln(Ey+)− κyUcν

= 0

y+n+1 = y+n −f(y+)

f ′(y+)= y+n −

y+n ln(Ey+n )−κyUc

ν

1 + ln(Ey+n )=

y+n + κyUc

ν

1 + ln(Ey+n )

Fangqing Liu Wall functions 2016-12-08 25 / 30

Page 26: A Thorough Description Of How Wall Functions Are ...hani/.../FangqingLiu/pptFinal.pdf · Some basic theory Wall function in openfoamStructure and implemention What is wall function

Some basic theory Wall function in openfoam Structure and implemention

Wall Functions

nutUsplendingwallfunction

y+ = u+ +1

E

[eκu

+ − 1− κu+ − 1

2(κu+)2 − 1

6(κu+)3

]

Figure: Caption

Fangqing Liu Wall functions 2016-12-08 26 / 30

Page 27: A Thorough Description Of How Wall Functions Are ...hani/.../FangqingLiu/pptFinal.pdf · Some basic theory Wall function in openfoamStructure and implemention What is wall function

Some basic theory Wall function in openfoam Structure and implemention

Wall Functions

Conclusion

Table: The wall function

kqRWallFunction For high Re, zero gradient condition

kLowReWallFunction for high and low Re, the condition based on the position of y+

epsilonWallFunction High Re

epsilonLowReWallFunction for High and Low Re, the condition based on the position of y+

v2WallFunction For High and Low Re, The condition based on the position of y+

fWallFunction For High and Low Re, The condition based on the position of y+

omegaWallFunction For High and Low Re, The condition based the blanding of viscous and log layernutWallFunction abstract class, not provide specific nut

nutLowReWallFunction for low Re, the condition is zeronutUWallFunction condition based on the velocitynutkWallFunction condition based on the kinematic

nutUSpaldingWallFunction for the whole area

+

Fangqing Liu Wall functions 2016-12-08 27 / 30

Page 28: A Thorough Description Of How Wall Functions Are ...hani/.../FangqingLiu/pptFinal.pdf · Some basic theory Wall function in openfoamStructure and implemention What is wall function

Some basic theory Wall function in openfoam Structure and implemention

Structures

1 in the simpleFoam.C turbulence->correct()

2 in the kEpsilon.Cepsilon_.boundaryFieldRef().updateCoeffs(defined inGeometricField.C)

3 in the updateCoeffs caculate

Fangqing Liu Wall functions 2016-12-08 28 / 30

Page 29: A Thorough Description Of How Wall Functions Are ...hani/.../FangqingLiu/pptFinal.pdf · Some basic theory Wall function in openfoamStructure and implemention What is wall function

Some basic theory Wall function in openfoam Structure and implemention

The implementation of wall functionFirstly, copy to your own folder.

OF4x

cd $WM_PROJECT_USER_DIR/src

cp -r --parents $WM_PROJECT_DIR/src/TurbulenceModel .

cd TurbulenceModels/turbulenceModels/derivedFvPatchFields/wallFunctions

Secondly,rename the fwallfunction to zetawallfunction.

mv zetaWallFunctions/fWallFunction zetaWallFunctions/zetaWallFunction

cd zetaWallFunctions/zetaWallFunction

mv fWallFunctionFvPatchScalarField.C zetaWallFunctionFvPatchScalarField.C

mv fWallFunctionFvPatchScalarField.H zetaWallFunctionFvPatchScalarField.H

sed -i s/fWallFunctionFvPatchScalarField/zetaWallFunctionFvPatchScalarField/g

zetaWallFunctionFvPatchScalarField.*

sed -i s/fWallFunction/zetaWallFunction/g

zetaWallFunctionFvPatchScalarField.*

Thirdly, modify the make/files

LIB = $(FOAM_USER_LIBBIN)/libturbulenceModels

Fourthly, modify the Make/files

zetaWallFunctions = $(wallFunctions)/zetaWallFunctions

$(zetaWallFunctions)/zetaWallFunction/zetaWallFunctionFvPatchScalarField.C

Fangqing Liu Wall functions 2016-12-08 29 / 30

Page 30: A Thorough Description Of How Wall Functions Are ...hani/.../FangqingLiu/pptFinal.pdf · Some basic theory Wall function in openfoamStructure and implemention What is wall function

Some basic theory Wall function in openfoam Structure and implemention

Thanks

Thanks

Fangqing Liu Wall functions 2016-12-08 30 / 30