Implementation of A Complete Wall Function For The Standard K Turbulence Model in Openfoam 4.0
Implementation of A Complete Wall Function For The Standard K Turbulence Model in Openfoam 4.0
Implementation of A Complete Wall Function For The Standard K Turbulence Model in Openfoam 4.0
Author:
Shengnan Liu Peer reviewed by:
University of Stavanger Mohammad Arabnejad
[email protected] Håkan Nilsson
Disclaimer: This is a student project work, done as part of a course where OpenFOAM and some
other OpenSource software are introduced to the students. Any reader should be aware that it
might not be free of errors. Still, it might be useful for someone who would like learn some details
similar to the ones presented in the report and in the accompanying files. The material has gone
through a review process. The role of the reviewer is to go through the tutorial and make sure that
it works, that it is possible to follow, and to some extent correct the writing. The reviewer has no
responsibility for the contents.
1 Introduction 3
2 Near-wall Physics 4
2.1 Overview on k − model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.2 Wall Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
4 New Wall Function Implementation for Standard k− Turbulence Model in Open-
FOAM 4.0 22
4.1 Implementation of new wall function in OpenFOAM 4.0 . . . . . . . . . . . . . . . . 22
4.2 Modifications to existing wall functions . . . . . . . . . . . . . . . . . . . . . . . . . 23
4.2.1 Modification to kOngWallFunction . . . . . . . . . . . . . . . . . . . . . . . . 24
4.2.2 Modification to epsilonOngWallFunction . . . . . . . . . . . . . . . . . . . . . 29
4.2.3 Modification to nutOngWallFunction . . . . . . . . . . . . . . . . . . . . . . . 30
4.2.4 Compile Ong wall functions in OpenFOAM 4.0 . . . . . . . . . . . . . . . . . 31
5 Test Cases 33
5.1 Test case 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
5.1.1 Case set up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
5.1.2 Post-processig in paraFoam . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
5.2 Test Case 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
5.2.1 Case set up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
5.2.2 Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
1
Learning outcomes
2
Chapter 1
Introduction
Most turbulent flows are bounded by one or more solid surfaces, such as channel flow, pipe flow and
flow around offshore foundations or ships. In turbulent flow, the presence of a wall causes a number
of different effects, some of which are shown as follows:
• Low Reynolds number - the turbulence Reynolds number Rel = k 2 /(v) decreases as the wall
is approached. Here k is the turbulent kinetic energy, is the turbulence dissipation rate and
v is the kinematic velocity.
• High shear rate - the highest mean shear rate ∂ < U >/∂y (< U > is the mean shear velocity,
y is the distance in normal direction) occurs at the wall. The velocity changes from the no-slip
condition at the wall to its stream value.
• Wall blocking - through the pressure field, the impermeability condition the v=0 (at y=0)
affects the flow up to an integral scale from the wall.
The present work is based on the k − turbulent model. The form of the basic k − and shear
stress models have not changed since 1970s (pioneered by Jones and Launder, 1972; Launder and
Sharma, 1974). However, researchers still have different ideas about the near wall treatment until
present (Kalitzin et al., 2005; Ong et al., 2009; Parente et al., 2011 and Balogh et al., 2012). In
the late 1980s (pioneered by Rogallo, 1981), detailed direct numerical simulation (DNS) data for
viscous near-wall region started to be available, which the current wall function mainly based on. If
DNS is used to simulate the near-wall region, very fine mesh close to the wall is required to resolve
the flow field for the direct integration, especially at high Reynolds number flow condition. The
smallest turbulence scales decrease with the increase of Reynolds numbers, moreover the boundary
layer will be thin and there will be high mean velocity gradient on the wall, so a large number of
grids are needed to capture near-wall pressure and velocity gradients. The idea of the wallf unction
approach is to use appropriate wall boundary conditions at some distance away from the wall, so
that fine grids are not required to resolve the near-wall flow condition. In this way, it will reduce
the computational cost significantly.
3
Chapter 2
Near-wall Physics
• The first is the transport equation for turbulent kinetic energy k, which determines the energy
in the turbulence.
• The second is the transport equation for turbulent dissipation , which determines the rate of
dissipation of the turbulent kinetic energy.
• The turbulent viscosity is specified as νT = Cµ k 2 / and C1 = 1.44, C2 = 1.92, Cµ = 0.09,
σk = 1.0, σ = 1.3.
4
2.2. WALL FUNCTIONS ·
• Viscous sub-layer
The fluid very close to the wall is dominated by viscous shear in absence of the turbulent
shear stress effects for y + < 5. It can be assumed that the shear stress is almost equal to the
wall shear stress τω throughout the viscous layer.
∂u
τω = µ (2.3)
∂y
The expression shows the velocity gradient on the wall, where u is the tangential veloc-
ity. In this region u+ = y + , but the standard specification νT = Cµ k 2 / yields too large
for turbulent viscosity in the near wall region. Jones and Launder (1972) include vari-
ous damping functions to allow the model to be used within the viscous near wall region,
νT = fµ Cµ k 2 /. Rodi and Mansour (1993) suggested one relation according to the DNS data:
fµ = 1−exp(−0.0002y + −0.00065y +2 ) , which is used in the present study. Applying boundary
conditions and manipulations, we obtain the following equation set to be used in the viscous
near wall region:
y = u∗ y/ν
+
u+ = u/u∗
u+ = y +
(2.4)
k = u∗2 / Cµ
p
= Cµ3/4 k 3/2 /κy
νT = fµ Cµ k 2 /
Outside the viscous sub-layer (5 < y + < 30) buffer layer region exists. The largest varia-
tion occurs from either law occurring approximately where the two equations intercept, at
5
2.2. WALL FUNCTIONS ·
y + = 11. That is, before 11 wall units the linear approximation is more accurate and after
11 wall units the logarithmic approximation should be used. Considering both the linear and
logarithmic approximation by a weighted average (linear interpolation), u+ can be obtained
as follows (Ong et al., 2009).
1
u+ = κω 1−ω (2.5)
( ln(Ey + ) ) + ( y+ )
where the weighting factor ω = (y + − 5)/25, E = 9.8, von Karman constant κ = 0.41. Simi-
larly, we can obtain the following equation set to be used in the near wall region:
y = u∗ y/ν
+
u+ = u/u∗
1
u+ =
κω 1−ω
( ln(Ey + ) + ( y+ )
) (2.6)
∗2
p
k = u / Cµ
3/4 3/2
= Cµ k /κy
νT = fµ Cµ k 2 /
• Log-law layer
At some distance from the wall and outside the buffer layer (30 < y + < 100) a region exists
where turbulent effects are important. Within this inner region the shear stress is assumed to
be constant and equal to wall shear stress and varying gradually with distance from the wall.
The relationship between y + and u+ in the log-law region is given as:
1
u+ = ln(Ey + ) (2.7)
κ
where E=9.8. As the relationship between y + and u+ is logarithmic, the above expression is
known as log-law and the layer where y + takes the values between 30 and 100 is known as
log-law layer. We can obtain the following equation set to be used in the near wall region:
y = u∗ y/ν
+
u+ = u/u∗
u+ = 1 ln(Ey + )
κ p (2.8)
∗2
k = u / C
µ
= C 3/4 k 3/2 /κy
µ
νT = fµ Cµ k 2 /
• Defect layer
In an defect layer (overlap region, y + >= 100) with approximately constant shear stress
and far enough from the wall for (direct) viscous effects to be negligible.
Due to different wall functions in different regions, the height of the first layer must be ac-
curately calculated, so that the first node results will be obtained from the right functions.
However, in OpenFOAM, the wall function for k − model are not defined strictly according
to the method stated above, which are only available for one region (log-law region) or at
most two regions (viscous region and log-law region), as the green dash line in Figure 2.1. The
objective of this project is to modify the wall functions for the k − model in OpenFOAM in
order to cover all the regions in boundary layer .
6
Chapter 3
The main code of kEpsilon < BasicT urbulenceM odel > is shown as follows.
39 template <c l a s s BasicTurbulenceModel>
40 v o i d k E p s i l o n <BasicTurbulenceModel > : : c o r r e c t N u t ( )
41 {
42 t h i s −>n u t = Cmu ∗ s q r ( k ) / e p s i l o n ;
43 t h i s −>n u t . c o r r e c t B o u n d a r y C o n d i t i o n s ( ) ;
44 f v : : o p t i o n s : : New( t h i s −>mesh ) . c o r r e c t ( t h i s −>n u t ) ;
45
46 BasicTurbulenceModel : : c o r r e c t N u t ( ) ;
47 }
48
49
7
3.1. K − TURBULENCE MODEL CODE IN OPENFOAM 4.0 ·
Firstly, kSource() is defined to obtain the value of k, and epsilonSource() is defined to obtain the
value of epsilon, correctN ut() is used to correct νT in the whole field. Then the function correct() is
defined which is also the main function of kEpsilon.C (shown below). The main calculation process
stated in the code will be explained.
v o i d k E p s i l o n <BasicTurbulenceModel > : : c o r r e c t ( )
222 {
223 i f ( ! t h i s −>t u r b u l e n c e )
224 {
225 r e t u r n ;
226 }
227
228 // L o c a l r e f e r e n c e s
229 c o n s t a l p h a F i e l d& a l p h a = t h i s −>a l p h a ;
230 c o n s t r h o F i e l d& rho = t h i s −>r h o ;
231 c o n s t s u r f a c e S c a l a r F i e l d& alphaRhoPhi = t h i s −>alphaRhoPhi ;
232 c o n s t v o l V e c t o r F i e l d& U = t h i s −>U ;
233 v o l S c a l a r F i e l d& nut = t h i s −>n u t ;
234 f v : : o p t i o n s& f v O p t i o n s ( f v : : o p t i o n s : : New( t h i s −>mesh ) ) ;
235
236 e d d y V i s c o s i t y <RASModel<BasicTurbulenceModel >>:: c o r r e c t ( ) ;
237
238 v o l S c a l a r F i e l d : : I n t e r n a l divU
239 (
8
3.1. K − TURBULENCE MODEL CODE IN OPENFOAM 4.0 ·
240 f v c : : d i v ( f v c : : a b s o l u t e ( t h i s −>p h i ( ) , U ) ) ( ) . v ( )
241 );
242
243 tmp<v o l T e n s o r F i e l d > tgradU = f v c : : grad (U ) ;
244 volScalarField : : Internal G
245 (
246 t h i s −>GName( ) ,
247 nut . v ( ) ∗ ( dev (twoSymm( tgradU ( ) . v ( ) ) ) && tgradU ( ) . v ( ) )
248 );
249 tgradU . c l e a r ( ) ;
250
251 // Update e p s i l o n and G a t t h e w a l l
252 e p s i l o n . boundaryFieldRef ( ) . updateCoeffs ( ) ;
253
254 // D i s s i p a t i o n e q u a t i o n
255 tmp<f v S c a l a r M a t r i x > epsEqn
256 (
257 fvm : : ddt ( alpha , rho , e p s i l o n )
258 + fvm : : d i v ( alphaRhoPhi , e p s i l o n )
259 − fvm : : l a p l a c i a n ( a l p h a ∗ rho ∗ D e p s i l o n E f f ( ) , e p s i l o n )
260 ==
261 C1 ∗ a l p h a ( ) ∗ rho ( ) ∗G∗ e p s i l o n ( ) / k ( )
262 − fvm : : SuSp ( ( ( 2 . 0 / 3 . 0 ) ∗ C1 + C3 ) ∗ a l p h a ( ) ∗ rho ( ) ∗ divU , e p s i l o n )
263 − fvm : : Sp ( C2 ∗ a l p h a ( ) ∗ rho ( ) ∗ e p s i l o n ( ) / k ( ) , e p s i l o n )
264 + epsilonSource ()
265 + f v O p t i o n s ( alpha , rho , e p s i l o n )
266 );
267
268 epsEqn . r e f ( ) . r e l a x ( ) ;
269 f v O p t i o n s . c o n s t r a i n ( epsEqn . r e f ( ) ) ;
270 epsEqn . r e f ( ) . boundaryManipulate ( e p s i l o n . b o u n d a r y F i e l d R e f ( ) ) ;
271 s o l v e ( epsEqn ) ;
272 fvOptions . c o r r e c t ( e p s i l o n ) ;
273 bound ( e p s i l o n , t h i s −>e p s i l o n M i n ) ;
274
275 // Turbulent k i n e t i c e n e r g y e q u a t i o n
276 tmp<f v S c a l a r M a t r i x > kEqn
277 (
278 fvm : : ddt ( alpha , rho , k )
279 + fvm : : d i v ( alphaRhoPhi , k )
280 − fvm : : l a p l a c i a n ( a l p h a ∗ rho ∗ DkEff ( ) , k )
281 ==
282 a l p h a ( ) ∗ rho ( ) ∗G
283 − fvm : : SuSp ( ( 2 . 0 / 3 . 0 ) ∗ a l p h a ( ) ∗ rho ( ) ∗ divU , k )
284 − fvm : : Sp ( a l p h a ( ) ∗ rho ( ) ∗ e p s i l o n ( ) / k ( ) , k )
285 + kSource ( )
286 + f v O p t i o n s ( alpha , rho , k )
287 );
288
289 kEqn . r e f ( ) . r e l a x ( ) ;
290 f v O p t i o n s . c o n s t r a i n ( kEqn . r e f ( ) ) ;
291 s o l v e ( kEqn ) ;
292 fvOptions . c o r r e c t ( k ) ;
293 bound ( k , t h i s −>kMin ) ;
9
3.2. SUMMARY OF AVAILABLE WALL FUNCTIONS OF K − TURBULENCE MODEL IN
OPENFOAM 4.0 ·
294
295 c o r r e c t N u t ( ) ;
296 }
From the code above, the turbulence calculation can be concluded as following:
• Calculate turbulent kinetic energy production term G and correct the value of G at first layer
mesh close to the wall by ’epsilon .boundaryF ieldRef ().updateCoef f s()’. The correction on
and G is achieved by updateCoeffs() function of .
• After updating G, the equation is built by this new G. Then the equation is revised by
’epsEqn.ref ().boundaryM anipulate(epsilon .boundaryF ieldRef ());’
• Solve equation and obtain the updated field.
• Solve k equation using the new , and k field including the k on the wall is renewed.
• Calculate νT , and update the νT at wall by correctNut();
The key parameters of k − wall function include k, , νT . The available wall functions of k, , νT
of OpenFOAM 4.0 are concluded here. In addition the wall functions used for further modification
are explained in detail.
In OpenFOAM 4.0, there are two available wall functions for k, i.e., kqRWallFunction and kLowRe-
WallFunction. Normally, kqRWallFunction is used for high Reynolds numbers and kLowReWall-
Function can be used for both low Reynolds numbers and high Reynolds numbers. See Table 3.1.
10
3.2. SUMMARY OF AVAILABLE WALL FUNCTIONS OF K − TURBULENCE MODEL IN
OPENFOAM 4.0 ·
First, the function yP lusLam is used to calculate the switching point of y + , and the return value
will be stored at yPlusLam .
s c a l a r kLowReWallFunctionFvPatchScalarField : : yPlusLam
57 (
58 c o n s t s c a l a r kappa ,
59 c o n s t s c a l a r E
60 )
61 {
62 s c a l a r y p l = 1 1 . 0 ;
63
64 f o r ( i n t i =0; i <10; i ++)
65 {
66 y p l = l o g (max(E∗ ypl , 1 ) ) / kappa ;
67 }
68
69 r e t u r n y p l ;
70 }
71
According to the code above, y + at switching point is calculated by 10-step iteration. The itera-
tion formula used here is y + = log(max(E ∗ y + , 1))/κ; because in viscous sublayer u+ = y + , and
u+ = 1/kln(Ey + ) in log-law layer. Through the iteration, the switching point of y + between viscous
sublayer and log-law layer can be obtained and will also be used for the mode change for k, and
nut. The initial value of y + is set to 11, because theoretically the switch point will be around 11.
After the iteration, the value is around 11.53. And this value will be stored in yPlusLam .
11
3.2. SUMMARY OF AVAILABLE WALL FUNCTIONS OF K − TURBULENCE MODEL IN
OPENFOAM 4.0 ·
This function shows how the k value at the current wall calculated. This refers to Kalitzin et al.
(2005) and is designed for v 2 − f model. At first friction velocity u∗ is calculated by kc (subscript c
means the value of the cell close to the wall) and y + is calculated based on this u∗ with the following
expression. ( p
u∗ = Cµ1/4 kc
(3.1)
y + = u∗ y/νw
Then kw (value at the wall ) is calculated through:
12
3.2. SUMMARY OF AVAILABLE WALL FUNCTIONS OF K − TURBULENCE MODEL IN
OPENFOAM 4.0 ·
Correspondingly, there are two available wall functions for in OpenFOAM 4.0, i.e., epsilonWall-
Function and epsilonLowReWallFunction. Normally, epsilonWallFunction is used for high Reynolds
numbers and epsilonLowReWallFunction can be used for both low Reynolds numbers and high
Reynolds numbers (see Table 3.2). epsilonWallFunction provides a turbulence dissipation wall func-
tion condition for high Reynolds number turbulent flow cases. This wall function calculates and
G (produnction term), and inserts near wall epsilon values directly into the epsilon equation to act
as a constraint. epsilonLowReWallFunction can be used for both low- and high-Reynolds number
turbulent flow cases. The model operates in two modes, based on the computed laminar-to-turbulent
switch-over y+ value derived from kappa and E, which is the same with the calculation in kLowRe-
WallFunction. epsilonWallFunctionFvPatchScalarField.C is explained here.
The main external function of epsilonW allF unctionF vP atchScalarF ield.C is updateW eighted −
Coef f s(), first it checks whether the epsilon value at the wall is updated, if not, it calls the
setM aster() function to set the master patch, then update the values of epsilon on master patches
(wall patches). The code of updateW eightedCoef f s() is shown below.
v o i d Foam : : e p s i l o n W a l l F u n c t i o n F v P a t c h S c a l a r F i e l d : : u p d a t e W e i g h t e d C o e f f s
449 (
450 c o n s t s c a l a r F i e l d& w e i g h t s
451 )
452 {
453 i f ( updated ( ) )
454 {
455 return ;
456 }
457
458 c o n s t t u r b u l e n c e M o d e l& turbModel
= db ( ) . lookupObject <t urb ul en c eM od el >
459 (
13
3.2. SUMMARY OF AVAILABLE WALL FUNCTIONS OF K − TURBULENCE MODEL IN
OPENFOAM 4.0 ·
460 I O o b j e c t : : groupName
461 (
462 t u r b u l e n c e M o d e l : : propertiesName ,
463 i n t e r n a l F i e l d ( ) . group ( )
464 )
465 );
466
467 setMaster ( ) ;
468
469 i f ( patch ( ) . i n d e x ( ) == m a s t e r )
470 {
471 createAveragingWeights ( ) ;
472 c a l c u l a t e T u r b u l e n c e F i e l d s ( turbModel , G( t r u e )
, epsilon ( true ) ) ;
473 }
474
475 c o n s t s c a l a r F i e l d& G0 = t h i s −>G( ) ;
476 c o n s t s c a l a r F i e l d& e p s i l o n 0 = t h i s −>e p s i l o n ( ) ;
477
478 t y p e d e f D ime ns ion edF ie ld <s c a l a r , volMesh> FieldType ;
479
480 FieldType& G =
481 c o n s t c a s t <FieldType&>
482 (
483 db ( ) . lookupObject <FieldType >(turbModel . GName ( ) )
484 );
485
486 FieldType& e p s i l o n = c o n s t c a s t <FieldType&>( i n t e r n a l F i e l d ( ) ) ;
487
488 s c a l a r F i e l d& e p s i l o n = ∗ t h i s ;
489
490 // o n l y s e t t h e v a l u e s i f t h e w e i g h t s a r e > t o l e r a n c e
491 f o r A l l ( weights , f a c e i )
492 {
493 s c a l a r w = weights [ f a c e i ] ;
494
495 i f (w > t o l e r a n c e )
496 {
497 l a b e l c e l l i = patch ( ) . f a c e C e l l s ( ) [ f a c e i ] ;
498
499 G[ c e l l i ] = ( 1 . 0 − w) ∗G[ c e l l i ] + w∗G0 [ c e l l i ] ;
500 e p s i l o n [ c e l l i ] = ( 1 . 0 − w) ∗ e p s i l o n [ c e l l i ]
+ w∗ e p s i l o n 0 [ c e l l i ] ;
501 epsilonf [ facei ] = epsilon [ c e l l i ] ;
502 }
503 }
504
505 f v P a t c h F i e l d <s c a l a r > : : u p d a t e C o e f f s ( ) ;
506 }
14
3.2. SUMMARY OF AVAILABLE WALL FUNCTIONS OF K − TURBULENCE MODEL IN
OPENFOAM 4.0 ·
67 i f ( m a s t e r != −1)
68 {
69 return ;
70 }
71
72 c o n s t v o l S c a l a r F i e l d& e p s i l o n =
73 s t a t i c c a s t <c o n s t v o l S c a l a r F i e l d &>( t h i s −>i n t e r n a l F i e l d ( ) ) ;
74
75 c o n s t v o l S c a l a r F i e l d : : Boundary& b f = e p s i l o n . b o u n d a r y F i e l d ( ) ;
76
77 l a b e l master = −1;
78 f o r A l l ( bf , p a t c h i )
79 {
80 i f ( isA<e p s i l o n W a l l F u n c t i o n F v P a t c h S c a l a r F i e l d >( b f [ p a t c h i ] ) )
81 {
82 e p s i l o n W a l l F u n c t i o n F v P a t c h S c a l a r F i e l d& e p f
= epsilonPatch ( patchi ) ;
83
84 i f ( master == −1)
85 {
86 master = p a t c h i ;
87 }
88
89 e p f . master ( ) = master ;
90 }
91 }
92 }
First, this ’setM aster’ function judges that if the master value of the current member is not equal
to −1. If it is true, then the return action will be executed. Otherwise it will obtain the epsilon
boundary and store the value at bf . Then for all the bf , if the boundary type is ’epsilonWallFunc-
tionFvPatchScalarField’, then it will do another judgement, i.e. whether the temporary variable
’master’ is equal to 1, if it is true, pass the value of ’patchi’ to ’master’, then pass the value of tem-
porary variable ’master’ to the corresponding epf.master(). Overall, if there are several boundaries
use the ’epsilonWallFunctionFvPatchScalarField’ boundary type, the the boundary with smallest
index will be set as master, the non-master boundary can obtain information from master.
According to the updateW eightedCoef f s() code, after setMaster(), check whether the patch type
is master type ’epsilonW allF unctionF vP atch’. If it is ture, then ’createAveragingW eights()’ and
’calculateT urbulenceF ields()’ will be executed. These two functions are explained as follows.
void
Foam : : epsilonWallFunctionFvPatchScalarField : : createAveragingWeights ()
96 {
97 c o n s t v o l S c a l a r F i e l d& e p s i l o n =
98 s t a t i c c a s t <c o n s t v o l S c a l a r F i e l d &>( t h i s −>i n t e r n a l F i e l d ( ) ) ;
99
100 c o n s t v o l S c a l a r F i e l d : : Boundary& b f = e p s i l o n . b o u n d a r y F i e l d ( ) ;
101
102 c o n s t fvMesh& mesh = e p s i l o n . mesh ( ) ;
103
104 if ( initialised && ! mesh . c h a n g i n g ( ) )
105 {
106 return ;
15
3.2. SUMMARY OF AVAILABLE WALL FUNCTIONS OF K − TURBULENCE MODEL IN
OPENFOAM 4.0 ·
107 }
108
109 volScalarField weights
110 (
111 IOobject
112 (
113 ” weights ” ,
114 mesh . time ( ) . timeName ( ) ,
115 mesh ,
116 I O o b j e c t : : NO READ,
117 I O o b j e c t : : NO WRITE,
118 f a l s e // do not r e g i s t e r
119 ),
120 mesh ,
121 dimensionedScalar ( ” zero ” , dimless , 0 . 0)
122 );
123
124 DynamicList<l a b e l > e p s i l o n P a t c h e s ( b f . s i z e ( ) ) ;
125 f o r A l l ( bf , p a t c h i )
126 {
127 i f ( isA<e p s i l o n W a l l F u n c t i o n F v P a t c h S c a l a r F i e l d >( b f [ p a t c h i ] ) )
128 {
129 e p s i l o n P a t c h e s . append ( p a t c h i ) ;
130
131 c o n s t l a b e l U L i s t& f a c e C e l l s
= b f [ p a t c h i ] . patch ( ) . f a c e C e l l s ( ) ;
132 forAll ( faceCells , i )
133 {
134 weights [ f a c e C e l l s [ i ]]++;
135 }
136 }
137 }
138
139 cornerWeights . s e t S i z e ( bf . s i z e ( ) ) ;
140 forAll ( epsilonPatches , i )
141 {
142 label patchi = epsilonPatches [ i ] ;
143 c o n s t f v P a t c h S c a l a r F i e l d& wf
= weights . boundaryField ( ) [ patchi ] ;
144 c o r n e r W e i g h t s [ p a t c h i ] = 1 . 0 / wf . p a t c h I n t e r n a l F i e l d ( ) ;
145 }
146
147 G . setSize ( internalField (). size () , 0.0);
148 epsilon . setSize ( internalField (). size () , 0.0);
149
150 initialised = true ;
151 }
’createAveragingW eights()’ is used to set the weight of every patch cell. The weight will be
used in the calculation of G and epsilon later. Inside this function, ’DynamicList’ means check-
ing all the boundary fields. If its type is ’epsilonW allF unctionF vP atchScalarF ield’, it will then
be put in DynamicList. ’weight’ is the number of wall boundary faces in one cell, it is used to
weight how many boundary faces with ’epsilonW allF unctionF vP atchScalarF ield’ type the celli
16
3.2. SUMMARY OF AVAILABLE WALL FUNCTIONS OF K − TURBULENCE MODEL IN
OPENFOAM 4.0 ·
use. ’cornerW eights’ is used to save the inversed value of ’weight’, and weight of every boundary
faces equal to the weight of the cell which the faces belong to. Then line 147 and line 148 set initial
value of G and epsilon to 0. Actually, G and epsilon save the value of the whole internal field
instead of the boundary cell value. It means the data member G and epsilon of master patch
contain the information of both master patches and non-master patches. So the value of non-master
patches can also be obtained from G and epsilon according to the corresponding cell id.
Subsequently, calculateT urbulenceF ields function is called, the details are explained as follows.
v o i d Foam : :
epsilonWallFunctionFvPatchScalarField : : calculateTurbulenceFields
170 (
171 c o n s t t u r b u l e n c e M o d e l& t u r b u l e n c e ,
172 s c a l a r F i e l d& G0 ,
173 s c a l a r F i e l d& e p s i l o n 0
174 )
175 {
176 // accumulate a l l o f t h e G and e p s i l o n c o n t r i b u t i o n s
177 f o r A l l ( cornerWeights , patchi )
178 {
179 i f ( ! c o r n e r W e i g h t s [ p a t c h i ] . empty ( ) )
180 {
181 e p s i l o n W a l l F u n c t i o n F v P a t c h S c a l a r F i e l d& e p f
= epsilonPatch ( patchi ) ;
182
183 c o n s t L i s t <s c a l a r >& w = c o r n e r W e i g h t s [ p a t c h i ] ;
184
185 e p f . c a l c u l a t e ( t u r b u l e n c e , w, e p f . patch ( ) , G0 , e p s i l o n 0 ) ;
186 }
187 }
188
189 // apply z e r o −g r a d i e n t c o n d i t i o n f o r e p s i l o n
190 f o r A l l ( cornerWeights , patchi )
191 {
192 i f ( ! c o r n e r W e i g h t s [ p a t c h i ] . empty ( ) )
193 {
194 e p s i l o n W a l l F u n c t i o n F v P a t c h S c a l a r F i e l d& e p f
= epsilonPatch ( patchi ) ;
195
196 e p f == s c a l a r F i e l d ( e p s i l o n 0 , e p f . patch ( ) . f a c e C e l l s ( ) ) ;
197 }
198 }
199 }
In function ’calculateT urbulenceF ields’, first ’if !cornerWeights [patchI].empty()’ is used to judge
the wall type. If it is ’epsilonW allF unctionF vP atchScalarF ield’, then the calculate function is
called to update the G0 and epsilon value. Then zero-gradient condition is applied for epsilon. The
first layer mesh value is assigned to the wall patch value.
The statements ’constscalarF ield&G0 = this− > G();’ and ’ constscalarF ield&epsilon0 = this− >
epsilon();’ return the value of member function G and epsilon back to variable G0 and epsilon0.
The definition of member function G and epsilon are shown as follows.
Foam : : s c a l a r F i e l d&
17
3.2. SUMMARY OF AVAILABLE WALL FUNCTIONS OF K − TURBULENCE MODEL IN
OPENFOAM 4.0 ·
Foam : : e p s i l o n W a l l F u n c t i o n F v P a t c h S c a l a r F i e l d : : G( b o o l i n i t )
365 {
366 i f ( patch ( ) . i n d e x ( ) == m a s t e r )
367 {
368 if ( init )
369 {
370 G = 0.0;
371 }
372
373 return G ;
374 }
375
376 r e t u r n e p s i l o n P a t c h ( m a s t e r ) .G( ) ;
377 }
378
379
380 Foam : : s c a l a r F i e l d&
Foam : : e p s i l o n W a l l F u n c t i o n F v P a t c h S c a l a r F i e l d : : e p s i l o n
381 (
382 bool i n i t
383 )
384 {
385 i f ( patch ( ) . i n d e x ( ) == m a s t e r )
386 {
387 if ( init )
388 {
389 epsilon = 0.0;
390 }
391
392 return epsilon ;
393 }
394
395 return epsilonPatch ( master ) . e p s i l o n ( i n i t ) ;
396 }
The two functions G and epsilon return the values of G and epsilon , for the ’epsilonWallFunction-
FvPatchScalarField’ type wall boundary patches. Then the returned values of non-master patches
come from the data member of master .
As a summary, the patch cell with smaller id number will be set to ’master’ when using this wall
function. When the ’master’ type is called, the parameters will be calculated, and ’non-master’
members can obtain required information from ’master’.
The calculate function is the function to calculate the value of epsilon and G, it is shown as follows.
v o i d Foam : : e p s i l o n W a l l F u n c t i o n F v P a t c h S c a l a r F i e l d : : c a l c u l a t e
203 (
204 c o n s t t u r b u l e n c e M o d e l& t u r b u l e n c e ,
205 c o n s t L i s t <s c a l a r >& cornerWeights ,
206 c o n s t f v Pa t ch& patch ,
207 s c a l a r F i e l d& G,
208 s c a l a r F i e l d& e p s i l o n
209 )
18
3.2. SUMMARY OF AVAILABLE WALL FUNCTIONS OF K − TURBULENCE MODEL IN
OPENFOAM 4.0 ·
210 {
211 c o n s t l a b e l p a t c h i = patch . i n d e x ( ) ;
212
213 c o n s t s c a l a r F i e l d& y = t u r b u l e n c e . y ( ) [ p a t c h i ] ;
214
215 c o n s t s c a l a r Cmu25 = pow025 (Cmu ) ;
216 c o n s t s c a l a r Cmu75 = pow (Cmu , 0 . 7 5 ) ;
217
218 c o n s t tmp<v o l S c a l a r F i e l d > tk = t u r b u l e n c e . k ( ) ;
219 c o n s t v o l S c a l a r F i e l d& k = tk ( ) ;
220
221 c o n s t tmp<s c a l a r F i e l d > tnuw = t u r b u l e n c e . nu ( p a t c h i ) ;
222 c o n s t s c a l a r F i e l d& nuw = tnuw ( ) ;
223
224 c o n s t tmp<s c a l a r F i e l d > tnutw = t u r b u l e n c e . nut ( p a t c h i ) ;
225 c o n s t s c a l a r F i e l d& nutw = tnutw ( ) ;
226
227 c o n s t f v P a t c h V e c t o r F i e l d& Uw =
t u r b u l e n c e .U ( ) . b o u n d a r y F i e l d ( ) [ p a t c h i ] ;
228
229 c o n s t s c a l a r F i e l d magGradUw(mag(Uw. snGrad ( ) ) ) ;
230
231 // S e t e p s i l o n and G
232 f o r A l l ( nutw , f a c e i )
233 {
234 l a b e l c e l l i = patch . f a c e C e l l s ( ) [ f a c e i ] ;
235
236 s c a l a r w = cornerWeights [ f a c e i ] ;
237
238 e p s i l o n [ c e l l i ] +=
w∗Cmu75∗pow ( k [ c e l l i ] , 1 . 5 ) / ( kappa ∗y [ f a c e i ] ) ;
239
240 G[ c e l l i ] +=
241 w
242 ∗ ( nutw [ f a c e i ] + nuw [ f a c e i ] )
243 ∗magGradUw [ f a c e i ]
244 ∗Cmu25∗ s q r t ( k [ c e l l i ] )
245 / ( kappa ∗y [ f a c e i ] ) ;
246 }
247 }
The calculate function calculates the value of G and epsilon using the following expression:
N 3/4 3/2
1 X Cµ kc
c = ( )
N κyi
f =i
(3.3)
N 1/4 1/2
1 X (ν + νT ) ∗ | Ui −U
d
c
|Cµ kc
Gc = ( )
N κyi
f =i
Subscript c means the value of the cell close to the wall; i represents the index of boundary cell; y
is the normal distance from the cell center to the wall patch. ’M anipulateM atrix’ function (line
525-575) renews the parameters of each patch cell into the matrix.
19
3.2. SUMMARY OF AVAILABLE WALL FUNCTIONS OF K − TURBULENCE MODEL IN
OPENFOAM 4.0 ·
There are many types of νT wall functions in OpenFOAM 4.0 which are built based on one virtual
base class ’nutW allF unction’. The νT wall functions calculat the turbulence viscosity on the wall
by using virtual function ’calcN ut’, and return the νT value to the boundary through function
’updateCoef f s’. Different νT wall functions are summerized in Table 3.3.
These νT wall functions can be divided into two categories, i.e., (i) calculated from U (ii) calcu-
lated from k, this can be easily identified by checking the type name. nutkWallFunction provides
a turbulent kinematic viscosity condition based on turbulence kinetic energy. nutUWallFunction
provides turbulent kinematic viscosity condition based on U . In addition, nutkRoughWallFunction
and nutkRoughWallFunction manipulate the E parameter to account for the effects of roughness.
nutLowReWallFunction provides a turbulent kinematic viscosity condition for low Reynolds number
models, it sets νT to zero, and provides an access function to calculate y + . nutUSpaldingWall-
Function is used for rough walls to give a continuous νT profile to the wall based on one fitting
formula of y + and u+ proposed by Spalding (1961). ’nutU T abulatedW allF unction’ needs one user-
defined table of U+ as a function of near-wall Reynolds number. The table should be located in the
$FOAM CASE/constant directory.nutkAtmRoughWallFunction provides νT for atmospheric veloc-
20
3.2. SUMMARY OF AVAILABLE WALL FUNCTIONS OF K − TURBULENCE MODEL IN
OPENFOAM 4.0 ·
In the present study, a new νT wall function is built based on ’nutkW allF unction’ which is ex-
plained as follows. The main function is ’calcN ut()’, and the value of νT will be returned to
’updateCoef f s()’.
tmp<s c a l a r F i e l d > n u t k W a l l F u n c t i o n F v P a t c h S c a l a r F i e l d : : c a l c N u t ( ) c o n s t
41 {
42 c o n s t l a b e l p a t c h i = patch ( ) . i n d e x ( ) ;
43
44 c o n s t t u r b u l e n c e M o d e l& turbModel =
db ( ) . lookupObject <tu rb ul en ce M od el >
45 (
46 I O o b j e c t : : groupName
47 (
48 t u r b u l e n c e M o d e l : : propertiesName ,
49 i n t e r n a l F i e l d ( ) . group ( )
50 )
51 );
52
53 c o n s t s c a l a r F i e l d& y = turbModel . y ( ) [ p a t c h i ] ;
54 c o n s t tmp<v o l S c a l a r F i e l d > tk = turbModel . k ( ) ;
55 c o n s t v o l S c a l a r F i e l d& k = tk ( ) ;
56 c o n s t tmp<s c a l a r F i e l d > tnuw = turbModel . nu ( p a t c h i ) ;
57 c o n s t s c a l a r F i e l d& nuw = tnuw ( ) ;
58
59 c o n s t s c a l a r Cmu25 = pow025 (Cmu ) ;
60
61 tmp<s c a l a r F i e l d > tnutw ( new s c a l a r F i e l d ( patch ( ) . s i z e ( ) , 0 . 0 ) ) ;
62 s c a l a r F i e l d& nutw = tnutw . r e f ( ) ;
63
64 f o r A l l ( nutw , f a c e i )
65 {
66 l a b e l f a c e C e l l i = patch ( ) . f a c e C e l l s ( ) [ f a c e i ] ;
67
68 s c a l a r yPlus = Cmu25∗y [ f a c e i ]
∗ s q r t ( k [ f a c e C e l l i ] ) / nuw [ f a c e i ] ;
69
70 i f ( yPlus > yPlusLam )
71 {
72 nutw [ f a c e i ] =
nuw [ f a c e i ] ∗ ( yPlus ∗ kappa / l o g ( E ∗ yPlus ) − 1 . 0 ) ;
73 }
74 }
75
76 r e t u r n tnutw ;
77 }
This achieves the standard wall function, νT is set to zero when yP lus < yP lusLam , and νT =
κy +
ν ∗ ( ln(Ey + ) − 1) when yP lus > yP lusLam .
21
Chapter 4
As mentioned in Chapter 2, the new wall function includes three section functions which cover all
the wall regions. The name of the new wall function is given as kOngWallFunction, epsilonOng-
WallFunction and nutOngWallFunction (based on Ong et al., 2009). According to equation 2.4, 2.6
and 2.8, the new expression of k, and νT can be obtained. The methodology of the wall function
implementation is first calculating turbulence kinetic energy k based on velocity; then and νT are
calculated based on k.
u∗ . Solving the equation set 2.4, 2.6 and 2.8, equation of u∗ can be obtained in different regions, see
equation 4.1.
uν
u∗ = (y + < 5)
y
κ(yu∗ /ν − 5)yu∗ /ν − (30 − yu∗ /ν)ln(Eyu∗ /ν) u∗
− =0 (5 <= y + <= 30) (4.1)
25yu∗ /νln(Eyu∗ /ν) u
∗
Eyu − exp( κu ) = 0
(y + > 30)
ν u∗
Equation 4.1 shows the u∗ expression when y + is in different regions. For the case of y + < 5, the
expression of u∗ is simple and can be directly used for the calculation of k. However, for the cases
of 5 <= y + <= 30 and y + > 30, u∗ can not be solved directly. The approach here is using Newton
iteration method to solve the equation of u∗ .The equations of u∗ are defined as follows:
22
4.2. MODIFICATIONS TO EXISTING WALL FUNCTIONS ·
According to Newton iteration method, the iteration relation of f 1(u∗ ) and f 2(u∗ ) are:
f 1(u∗n )
∗ ∗ +
un+1 = un − f 10 (u∗ ) (5 <= y <= 30)
n
(4.4)
f 2(u∗n )
u∗n+1 = u∗n − (y + > 30)
f 20 (u∗n )
where u is the velocity, y is the height of the first layer cell, u∗ is the only unknown variable. Replace
f 1(u∗ ) and f 2(u∗ ) with the expression 4.2, after a certain number p of iteration steps, the value of u
∗
∗2
can be obtained. Subsequently k can be obtained by k = u / Cµ . and νT are calculated based
on equation (2.4). This section gives a basic idea of implementation. Next section will introduce
how to modify the code in OpenFOAM 4.0.
The Ong wall functions are modified based on kLowReWallFunction, epsilonWallFunction and nutk-
WallFunction. First, copy these three files to the corresponding folder usig the following commands.
OF4X
cd $FOAM_SRC/TurbulenceModels/turbulenceModels/derivedFvPatchFields/wallFunctions
cp -r kqRWallFunctions/kLowReWallFunction kqRWallFunctions/kOngWallFunction
cp -r epsilonWallFunctions/epsilonWallFunction epsilonWallFunctions/\
epsilonOngWallFunction
cp -r nutWallFunctions/nutkWallFunction nutWallFunctions/nutOngWallFunction
23
4.2. MODIFICATIONS TO EXISTING WALL FUNCTIONS ·
Change the .H and .C files’ names to the new wall function names.
cd kqRWallFunctions/kOngWallFunction
mv kLowReWallFunctionFvPatchScalarField.C kOngWallFunctionFvPatchScalarField.C
mv kLowReWallFunctionFvPatchScalarField.H kOngWallFunctionFvPatchScalarField.H
Change all the key words from kLowReW allF unction to kOngW allF unction
’yP lusLam’ function is not required in the kOngWallFunction, the declaration and definition of
’yP lusLam’ function are deleted in case of any conflict. Then modify the original ’updateCoef f s()’
into:
v o i d kMukWallFunctionFvPatchScalarField : : u p d a t e C o e f f s ( )
{
i f ( updated ( ) )
{
return ;
}
c o n s t l a b e l p a t c h i = patch ( ) . i n d e x ( ) ;
c o n s t f v P a t c h V e c t o r F i e l d& Uw = turbModel .U ( ) . b o u n d a r y F i e l d ( ) [ p a t c h i ] ;
c o n s t s c a l a r F i e l d magUp(mag(Uw. p a t c h I n t e r n a l F i e l d ( ) − Uw) ) ;
c o n s t s c a l a r F i e l d magGradU (mag(Uw. snGrad ( ) ) ) ;
s c a l a r F i e l d& kw = ∗ t h i s ;
24
4.2. MODIFICATIONS TO EXISTING WALL FUNCTIONS ·
// S e t k w a l l v a l u e s
f o r A l l (kw , f a c e i )
{
l a b e l f a c e C e l l i = patch ( ) . f a c e C e l l s ( ) [ f a c e i ] ;
s c a l a r uTau = Cmu25∗ s q r t ( k [ f a c e C e l l i ] ) ;
i f ( yPlus <= 5 )
{
kw [ f a c e i ] = magUp [ f a c e i ] ∗ nuw [ f a c e i ] / y [ f a c e i ] ;
}
e l s e i f ( yPlus > 5 && yPlus < 3 0 )
{
kw [ f a c e i ] = u t s 2 [ f a c e i ] ∗ u t s 2 [ f a c e i ] ;
}
else
{
kw [ f a c e i ] = u t s [ f a c e i ] ∗ u t s [ f a c e i ] ;
kw [ f a c e i ] /= s q r t (Cmu ) ;
}
kw = max(kw , SMALL) ;
f i x e d V a l u e F v P a t c h F i e l d <s c a l a r > : : u p d a t e C o e f f s ( ) ;
This is the main function calculating k according to equation (2.4), (2.6) and (2.8). Two new member
functions are used here to calculate u∗ in different regions. Member function calcU T au is defined to
calculate the u∗ in Log-law region. Then the value of u∗ will be returned back to the else statement
in updateCoef f s():
else
{
kw [ f a c e i ] = u t s [ f a c e i ] ∗ u t s [ f a c e i ] ;
25
4.2. MODIFICATIONS TO EXISTING WALL FUNCTIONS ·
The other member function ’calcU T au2’ is defined to calculate the u∗ in buffer layer region and the
value of u∗ will be returned back to the ’else if ’ statement in ’updateCoef f s()’:
e l s e i f ( yPlus > 5 && yPlus < 3 0 )
{
kw [ f a c e i ] = u t s 2 [ f a c e i ] ∗ u t s 2 [ f a c e i ] ;
c o n s t f v P a t c h V e c t o r F i e l d& Uw = turbModel .U ( ) . b o u n d a r y F i e l d ( ) [ p a t c h i ] ;
c o n s t s c a l a r F i e l d magUp(mag(Uw. p a t c h I n t e r n a l F i e l d ( ) − Uw) ) ;
c o n s t s c a l a r F i e l d& nutw = ∗ t h i s ;
f o r A l l ( uTau , f a c e i )
{
s c a l a r ut = s q r t ( ( nutw [ f a c e i ] + nuw [ f a c e i ] ) ∗ magGradU [ f a c e i ] ) ;
i f ( ut > ROOTVSMALL)
{
int iter = 0;
s c a l a r e r r = GREAT;
do
{
s c a l a r kUu = max( kappa ∗magUp [ f a c e i ] / ut , 1 3 . 8 6 ) ;
s c a l a r fkUu = exp (kUu ) ;
26
4.2. MODIFICATIONS TO EXISTING WALL FUNCTIONS ·
scalar f =
− ut ∗y [ f a c e i ] / nuw [ f a c e i ]+ 1/ E ∗ fkUu ;
s c a l a r df =
y [ f a c e i ] / nuw [ f a c e i ] + 1/ E ∗kUu∗ fkUu / ut ;
s c a l a r uTauNew = ut + f / d f ;
e r r = mag ( ( ut − uTauNew) / ut ) ;
ut = uTauNew ;
uTau [ f a c e i ] = max ( 0 . 0 , ut ) ;
}
}
r e t u r n tuTau ;
}
First u∗ is assigned with a initial value. ROOTVSMALL and GREAT are simply constant defined
in
src/OpenFOAM/primitives/Scalar/scalar/scalar.H
src/OpenFOAM/primitives/Scalar/floatScalar/floatScalar.H
The value of ROOTVSMALL is 1.0e-18, GREAT is 1.0e+6. u+ is defined as kU u here. This function
is used when y + is larger the 30(corresponding u+ > 13.86), therefore, the value of u+ keeps larger
|u∗ −u∗ |
than 13.86. The relative error is defined as err = n u∗n+1 . Then do at least 10 steps interation of
n
f 2(u∗ )(refer to equation(4.4) which is introduced in Section 4.1) until the relative error is less than
0.01. Then return back the value of u∗ .
The definition of ’calcU T au2’ is shown as follows:
c o n s t f v P a t c h V e c t o r F i e l d& Uw = turbModel .U ( ) . b o u n d a r y F i e l d ( ) [ p a t c h i ] ;
27
4.2. MODIFICATIONS TO EXISTING WALL FUNCTIONS ·
c o n s t s c a l a r F i e l d magUp(mag(Uw. p a t c h I n t e r n a l F i e l d ( ) − Uw) ) ;
c o n s t s c a l a r F i e l d& nutw = ∗ t h i s ;
f o r A l l ( uTau2 , f a c e i )
{
s c a l a r ut2 = s q r t ( ( nutw [ f a c e i ] + nuw [ f a c e i ] ) ∗ magGradU [ f a c e i ] ) ;
do
{
s c a l a r l g = l o g ( E ∗y [ f a c e i ] ∗ ut2 /nuw [ f a c e i ] ) ;
s c a l a r yp = min ( y [ f a c e i ] ∗ ut2 /nuw [ f a c e i ] , 3 0 ) ;
yp = max ( 5 , yp ) ;
scalar f =
−ut2 /magUp [ f a c e i ]+
( kappa ∗ ( yp −5)∗yp−(30−yp ) ∗ l g ) / ( 2 5 ∗ yp∗ l g ) ;
s c a l a r d f 1=
(( −2∗ kappa ∗yp+5∗kappa −l g ) ∗ y [ f a c e i ] / nuw [ f a c e i ]
+(30−yp ) / ut2 ) / ( 2 5 ∗ yp∗ l g ) ;
s c a l a r d f 2=
−(−kappa ∗ ( yp −5)∗yp+(30−yp ) ∗ l g ) ∗ ( yp/ ut2+l g ∗y [ f a c e i ]
/nuw [ f a c e i ] ) / ( 2 5 ∗ s q r ( yp∗ l g ) ) ;
s c a l a r df =
1/magUp [ f a c e i ]+ d f 1+d f 2 ;
s c a l a r uTauNew = ut2 + f / d f ;
e r r = mag ( ( ut2 − uTauNew) / ut2 ) ;
ut2 = uTauNew ;
r e t u r n tuTau2 ;
}
The structure of ’calcU T au2’ function is similar with ’calcU T au’, the difference is the iteration part
28
4.2. MODIFICATIONS TO EXISTING WALL FUNCTIONS ·
// S e t e p s i l o n and G
f o r A l l ( nutw , f a c e i )
{
l a b e l c e l l i = patch . f a c e C e l l s ( ) [ f a c e i ] ;
s c a l a r w = cornerWeights [ f a c e i ] ;
e p s i l o n [ c e l l i ] += w∗Cmu75∗pow ( k [ c e l l i ] , 1 . 5 ) / ( kappa ∗y [ f a c e i ] ) ;
G[ c e l l i ] +=
w
∗ ( nutw [ f a c e i ] + nuw [ f a c e i ] )
∗magGradUw [ f a c e i ]
∗Cmu25∗ s q r t ( k [ c e l l i ] )
/ ( kappa ∗y [ f a c e i ] ) ;
}
cd epsilonWallFunctions/epsilonOngWallFunction
mv epsilonWallFunctionFvPatchScalarField.C\
epsilonOngWallFunctionFvPatchScalarField.C
mv epsilonWallFunctionFvPatchScalarField.H\
epsilonOngWallFunctionFvPatchScalarField.H
Change the file name first, then rename all the class name in the .C and .H file.
sed -i s/epsilonWallFunction/epsilonOngWallFunction/g\
epsilonOngWallFunctionFvPatchScalarField.C
sed -i s/epsilonWallFunction/epsilonOngWallFunction/g\
epsilonOngWallFunctionFvPatchScalarField.H
29
4.2. MODIFICATIONS TO EXISTING WALL FUNCTIONS ·
cd nutWallFunctions/nutOngWallFunction
mv nutkWallFunctionFvPatchScalarField.C nutOngWallFunctionFvPatchScalarField.C
mv nutkWallFunctionFvPatchScalarField.H nutOngWallFunctionFvPatchScalarField.H
Then, the main function ’calcN ut()’ should be renewed to the following one.
f o r A l l ( nutw , f a c e i )
{
l a b e l f a c e C e l l i = patch ( ) . f a c e C e l l s ( ) [ f a c e i ] ;
r e t u r n tnutw ;
}
30
4.2. MODIFICATIONS TO EXISTING WALL FUNCTIONS ·
cd $FOAM_SRC/TurbulenceModels/turbulenceModels/Make
Open the ’files’ file, add the following statement inside under the ’wallFunctions = derivedFvPatch-
Fields/wallFunctions’ accordingly.
$(nutWallFunctions)/nutOngWallFunction/nutOngWallFunctionFvPatchScalarField.C
$(epsilonWallFunctions)/epsilonOngWallFunction\
/epsilonOngWallFunctionFvPatchScalarField.C
$(kqRWallFunctions)/kOngWallFunction/kOngWallFunctionFvPatchScalarField.C
Then change the last line ’LIB = $(FOAM LIBBIN)/libturbulenceModels’ to ’LIB = $(FOAM
USER LIBBIN)/ libturbulenceModels’ Touch the change of wall functions:
cd $FOAM_SRC/TurbulenceModels
wclean
touch turbulenceModels/derivedFvPatchFields/wallFunctions\
/epsilonWallFunctions/epsilonOngWallFunction\
/epsilonOngWallFunctionFvPatchScalarField.C
touch turbulenceModels/derivedFvPatchFields/wallFunctions\
/epsilonWallFunctions/epsilonOngWallFunction\
/epsilonOngWallFunctionFvPatchScalarField.H
touch turbulenceModels/derivedFvPatchFields/wallFunctions\
/kqRWallFunctions/kOngWallFunction\
/kOngWallFunctionFvPatchScalarField.C
touch turbulenceModels/derivedFvPatchFields/wallFunctions\
/kqRWallFunctions/kOngWallFunction\
/kOngWallFunctionFvPatchScalarField.H
touch turbulenceModels/derivedFvPatchFields/wallFunctions\
/nutWallFunctions/nutOngWallFunction\
/nutOngWallFunctionFvPatchScalarField.C
touch turbulenceModels/derivedFvPatchFields/wallFunctions\
/nutWallFunctions/nutOngWallFunction\
/nutOngWallFunctionFvPatchScalarField.H
cd $FOAM_SRC/TurbulenceModels
wmake libso turbulenceModels/derivedFvPatchFields/wallFunctions\
/nutWallFunctions/nutOngWallFunction
wmake libso turbulenceModels/derivedFvPatchFields/wallFunctions\
/kqRWallFunctions/kOngWallFunction
wmake libso turbulenceModels/derivedFvPatchFields/wallFunctions\
31
4.2. MODIFICATIONS TO EXISTING WALL FUNCTIONS ·
/epsilonWallFunctions/epsilonOngWallFunction
./Allwmake
After compiling successfully, restart the terminal window and prepare for the case Test.
32
Chapter 5
Test Cases
A verification study will be performed to ensure that the new wall function (Ong wall function) is
implemented correctly. Two test cases are introduced here, i.e. (i) Case 1: The uniform velocity
flow past a long flat plate; (ii) Case 2: A fully developed boundary layer flow past a short flat plate.
A summary of test cases are shown in Table 5.1.
A uniform velocity profile is introduced in the inlet. The main improvement of Ong wall function is
including the buffer layer. Therefore, in these two test cases, the first layer cell is set in buffer layer
(5 < y + < 30). The set up of Case 1 is shown as Figure 5.1. The outlet velocity profile are used
to check whether the newly-implemented wall function can produce physically-sound velocity profiles.
The calculation process of inlet velocity can be concluded as: (1) According to the experience,
assume that at the position y = 0.22 it is the switching point to fully developed flow; (2) According
the wall function equation (2.8), the value of u∗ can be calculated; (3) Combine the equation (2.4)
(2.6)and (2.8) with the known u∗ , the velocity profile can be obtained. The key step during this
process is selecting the position of first point, we must make sure that this point is above the real
boundary layer switching point, thus, it will not cause that the boundary layer region is forced to
be fully developed flow.
The computational domain of a simple 2-D flow along a horizontal plate is shown below.
where H is the height of the 2D domain. The inlet velocity is uniform value, the bottom is set as
33
5.1. TEST CASE 1 ·
noSlip (wall), top and outlet is set as zeroGradient (patch). The summary of the test cases is shown
as Table 5.1. At inlet boundary, the following expression are used for k, and νT (Ong et al., 2009).
3
k= (Iu U∞ )2
2
Cµ k ( 3/2)
= (5.1)
0.1L
k2
νT = Cµ
For the 0 folder, the setting for U , p, k, and νT are required. On the wall, the k, and νT are set to
the wall function name we defined (kOngWallFunction, epsilonOngWallFunction, nutOngWallFunc-
tion), νT are set to ’calculated’ on inlet patches. Detailed setting in 0, cnstant and system folder
can be found in Appendix C.
After finishing the setting, run simpleF oam in the test case folder.
When the simulation is done, type paraF oam in terminal. Click ’Apply’, then select U in the upper
toolbar. Click ’slice’ then input the coordinate (9, 0.5, 0.5) and apply.
Then click ’splithorizontal0 − >0 spreadsheetview’, the data can be seen as Figure 5.3. Then save
the data to csv format file by 0 F ile− > savedata0 . In this way, after plate flow is stable, outlet
velocity profile can be compared with the theoretical value to check whether this new wall function
is applicable.
According to the stable velocity profile and the equations of Ong wall function, the theoretical
velocity profile can be obtained. Different wall function will cause a big difference in the real simu-
lation especially for the cases that the separating point varies with the flow.
The results comparison of present simulated velocity profile and the velocity profile calculated based
on Ong et al., (2009) is shown as Figure 5.4.
It can be seen that he results of simulated results and the calculated results do not agree so good.
The reason is that the plate flow is still not fully developed, which can be seen by comparing the
velocity profiles between x = 8H and x = 10H. It means the flow around the horizontal plate
needs longer computation domain and longer time to achieve the fully developed boundary layer.
In addition, the meshes must be fine enough to capture the velocity profile. Therefore, Case 2 is
suggested for further verification study.
34
5.2. TEST CASE 2 ·
Test Case 1 requires lone simulation time to achieve the converged results, Test Case 2 is less time-
consuming and also a good way to verify the newly implemented wall function. The basic idea is to
calculate a fully developed boundary layer flow according to the equations of Ong wall function. Set
this boundary layer flow on the inlet pathes, and compare the velocity profile of inlet and outlet.
If these two velocity profiles fit well, it means the new wall function can maintain the velocity and
produce the correct velocity profile.
The case set up is shown in Figure 5.5. The inlet velocity in case 2 is a boundary layer flow.
A nonuniform setting for U , k, and νT is required in 0’ folder. In addition, boundaryData folder
is required in ’constant’ folder, which contains all the nonuniform inlet information. This process
can also be done by swak4Foam, but in the present study, the data points are used to set up the
boundary condition at the inlet. The inlet velocity profile calculated from the Ong wall function is
shown in Figure 5.6. The detailed setting can be found in Attachment C.
The inlet boundary conditions for k, and νT are based on Ong et al., (2010) :
k = max{Cµ( − 1/2)(1 − y/y f )2 u∗2 , 0.0001U∞
2
}
Cµ (3/4)ky 3/2
= (5.2)
l
k2
νT = C µ
where U∞ is the velocity of infinity. y f is the height of first layer cell. The expression of l is:
35
5.2. TEST CASE 2 ·
5.2.2 Results
The post-processing is similar with those shown section 5.1.2. The comparison of inlet and outlet
velocity profile is shown in Figure 5.7.
The result shows that the Ong wall functions keep the fully-developed velocity profile stable.
It also means that the new wall function is implemented successfully.
36
5.2. TEST CASE 2 ·
37
5.2. TEST CASE 2 ·
38
Study questions
1. How many near-wall regions are usually used around the wall? What are them? What does
the division depends on?
5. How to verify a newly complemented wall function? Please describe what kind of case should
be used and what results are expected?
39
Reference
Balogh, M., Parente, A. and Carlo B. ”RANS simulation of ABL flow over complex terrains applying
an enhanced k − model and wall function formulation: Implementation and Comparison for Fluent
and OpenFOAM.” Journal of Wind Engineering and Industrial Aerodynamics 104 (2012): 360-368.
Jones, W. P., and Launder B.E. ”The prediction of laminarization with a two-equation model of
turbulence.” International journal of heat and mass transfer 15.2 (1972): 301-314.
Kalitzin, G., Medic, G., Iaccarino, G. and Durbin, P. ”Near-wall behavior of RANS turbulence
models and implications for wall functions.” Journal of Computational Physics 204.1 (2005): 265-
291.
Launder, B. E., and Sharma, B. I. ”Application of the energy-dissipation model of turbulence to the
calculation of flow near a spinning disc.” Letters in heat and mass transfer 1.2 (1974): 131-137.
Liestyarini, U. C. CFD Analysis of Internal Pipe Flows, Master Thesis, University of Stavanger,
Norway (2016).
Ong, M.C., Trygsland, E. and Myrhaug, D. ”Numerical Study of Seabed Boundary Layer Flow
around Monopile and Gravity-Based Wind Turbine Foundation”, Proceedings of 35th International
Conference on Ocean, Offshore and Arctic Engineering, ASME, OMAE2016-54643, Busan, Korea
(2016).
Ong, M.C., Utnes, T., Holmedal, L.E., Myrhaug, D. and Pettersen, B. ”Numerical simulation of flow
around a smooth circular cylinder at very high Reynolds numbers.” Marine Structures 22.2 (2009):
142-153.
Ong, M.C., Utnes, T., Holmedal, L.E., Myrhaug, D. and Pettersen, B. ”Numerical simulation of
flow around a circular cylinder close to a flat seabed at high Reynolds numbers using a k − model.”
Coastal Engineering 57.10 (2010): 931-947.
Parente, A., Gorle, C., van Beeck, J. and Benocci, C. ”Improved k − model and wall function
formulation for the RANS simulation of ABL flows.” Journal of wind engineering and industrial
aerodynamics 99.4 (2011): 267-278.
Rodi, W., and Mansour, N. N. ”Low Reynolds number k − modelling with the aid of direct
simulation data.” Journal of Fluid Mechanics 250 (1993): 509-529.
Spalding, D. B. ”A single formula for the ”law of the wall”. ”Journal of Applied Mechanics 28.3
(1961): 455-458.
Tennekes, H., and Lumley, J.L. A first course in turbulence. MIT press, 1972.
40