3 Lab Manual
3 Lab Manual
1.1 Objective
Analyze external flow over a NACA 0012 airfoil at different angles of attack using the
simpleFoam solver to understand pressure distribution, lift, and drag characteristics.
1.2 Theory
The NACA 0012 airfoil is defined by the equation:
t √
0.2969 x − 0.1260x − 0.3516x2 + 0.2843x3 − 0.1015x4 (1.1)
y=±
0.2
where t = 0.12 for the 12% thickness ratio.
The lift coefficient is given by:
L
CL = 1 (1.2)
2
ρU 2 c
1
CFD Lab Manual - OpenFOAM 2406 2
∇·U=0 (1.6)
∇ · (UU) = −∇p + ν∇2 U + ∇ · τ turbulent (1.7)
outlet
{
type zeroGradient ;
}
CFD Lab Manual - OpenFOAM 2406 4
wall
{
type noSlip ;
}
frontAndBack
{
type empty ;
}
outlet
{
type fixedValue ;
value uniform 0;
}
wall
{
type zeroGradient ;
}
outlet
{
type zeroGradient ;
}
wall
{
type kqRWallFunction ;
value uniform 0.375;
}
outlet
{
type zeroGradient ;
}
wall
{
type ome gaWallFu nction ;
value uniform 1708;
}
SIMPLE
CFD Lab Manual - OpenFOAM 2406 6
{
n N o n O r t h o g o n a l C o r r e c t o r s 0;
consistent yes ;
residualControl
{
p 1e -4;
U 1e -5;
"( k | omega ) " 1e -5;
}
}
functions
{
forces
{
type forces ;
libs (" libforces . so ") ;
writeControl timeStep ;
writeInterval 10;
patches ( wall ) ;
rho rhoInf ;
rhoInf 1.225;
CofR (0.25 0 0) ;
}
coeffs
{
type forceCoeffs ;
libs (" libforces . so ") ;
CFD Lab Manual - OpenFOAM 2406 7
writeControl timeStep ;
writeInterval 10;
patches ( wall ) ;
rho rhoInf ;
rhoInf 1.225;
liftDir (0 1 0) ;
dragDir (1 0 0) ;
CofR (0.25 0 0) ;
lRef 1;
Aref 1;
}
}
# Initialize fields
simpleFoam
# Monitor residuals
tail -f log . simpleFoam
# Launch ParaView
paraview
);
fields ( p U Cp ) ;
• At α = 0: CL ≈ 0, CD ≈ 0.008
• At α = 5: CL ≈ 0.5, CD ≈ 0.01
1.6 Assignments
1.6.1 Assignment 1
Analyze the NACA 0012 airfoil at angles of attack: 0°, 5°, 10°, 15°. Plot CL vs α curve
and compare with theoretical thin airfoil theory: CL = 2π sin(α).
1.6.2 Assignment 2
Investigate the effect of mesh refinement on solution accuracy. Use three different mesh
densities and analyze convergence of lift and drag coefficients. Calculate Grid Conver-
gence Index (GCI).
1.6.3 Assignment 3
Implement NACA 2412 airfoil geometry and compare aerodynamic characteristics with
NACA 0012. Analyze the effect of camber on pressure distribution and stall characteris-
tics.
Experiment 2: Fluid Flow and Heat
Transfer in Double Pipe Heat
Exchanger
2.1 Objective
Simulate conjugate heat transfer in a double pipe heat exchanger using chtMultiRegionFoam
to analyze temperature distribution and heat transfer coefficients.
2.2 Theory
The overall heat transfer coefficient for a double pipe heat exchanger is:
1 1 ro ln(ro /ri ) ro
= + + (2.10)
U hi kwall ri ho
The effectiveness-NTU relationship for counter-flow configuration:
1 − exp(−N T U (1 − Cr ))
ε= (2.11)
1 − Cr exp(−N T U (1 − Cr ))
10
CFD Lab Manual - OpenFOAM 2406 11
∂(ρh)
+ ∇ · (ρUh) = ∇ · (αef f ∇h) + Sh (2.15)
∂t
Heat conduction in solid regions:
∂(ρcp T )
= ∇ · (k∇T ) (2.16)
∂t
Turbulent thermal diffusivity:
νt
αef f = α + (2.17)
P rt
cd $FOAM_RUN
cp -r $FOAM_TUTORIALS / heatTransfer / ch tMu lt iR egi on Fo am / multiReg ionHeate r
.
mv multi RegionHe ater doublePipeHX
cd doublePipeHX
convertToMeters 0.001; // mm to m
vertices
(
// Inner pipe vertices ( hot fluid )
(0 0 0) // 0
(1000 0 0) // 1
(1000 10 0) // 2
(0 10 0) // 3
(0 0 10) // 4
(1000 0 10) // 5
(1000 10 10) // 6
(0 10 10) // 7
blocks
(
// Inner fluid region
CFD Lab Manual - OpenFOAM 2406 13
edges () ;
boundary
(
innerInlet
{
type patch ;
faces ((0 4 7 3) ) ;
}
innerOutlet
{
type patch ;
faces ((1 2 6 5) ) ;
}
outerInlet
{
type patch ;
faces ((17 18 22 21) ) ;
}
outerOutlet
{
type patch ;
faces ((16 19 23 20) ) ;
}
frontAndBack
{
type empty ;
faces
(
(0 1 2 3)
(4 5 6 7)
(8 9 10 11)
(12 13 14 15)
(16 17 18 19)
(20 21 22 23)
);
}
);
format ascii ;
class dictionary ;
object topoSetDict ;
}
actions
(
{
name innerFluid ;
type cellSet ;
action new ;
source boxToCell ;
sourceInfo
{
box (0 0 0) (1000 10 10) ;
}
}
{
name pipeWall ;
type cellSet ;
action new ;
source boxToCell ;
sourceInfo
{
box (0 0 -2) (1000 12 12) ;
}
}
{
name outerFluid ;
type cellSet ;
action new ;
source boxToCell ;
sourceInfo
{
box (0 0 -5) (1000 20 20) ;
}
}
);
Create constant/outerFluid/transportProperties:
transportModel Newtonian ;
nu [0 2 -1 0 0 0 0] 1.5 e -05; // Air at 20 C
Pr [0 0 0 0 0 0 0] 0.71; // Prandtl number
Prt [0 0 0 0 0 0 0] 0.85; // Turbulent Prandtl number
Create constant/pipeWall/transportProperties:
CFD Lab Manual - OpenFOAM 2406 15
dimensions [0 0 0 1 0 0 0];
internalField uniform 363; // 90 C
boundaryField
{
innerInlet
{
type fixedValue ;
value uniform 363; // 90 C hot water inlet
}
innerOutlet
{
type zeroGradient ;
}
innerFluid_to_pipeWall
{
type compressible ::
turbulentTemperatureCoupledBaffleMixed ;
Tnbr T;
kappaMethod fluidThermo ;
value uniform 363;
}
frontAndBack
{
type empty ;
}
}
Create 0/outerFluid/T:
FoamFile
{
version 2.0;
format ascii ;
class volScalarField ;
object T;
}
CFD Lab Manual - OpenFOAM 2406 16
dimensions [0 0 0 1 0 0 0];
internalField uniform 293; // 20 C
boundaryField
{
outerInlet
{
type fixedValue ;
value uniform 293; // 20 C cold air inlet
}
outerOutlet
{
type zeroGradient ;
}
outerFluid_to_pipeWall
{
type compressible ::
turbulentTemperatureCoupledBaffleMixed ;
Tnbr T;
kappaMethod fluidThermo ;
value uniform 293;
}
frontAndBack
{
type empty ;
}
}
dimensions [0 1 -1 0 0 0 0];
internalField uniform (0 0 0) ;
boundaryField
{
innerInlet
{
type fixedValue ;
value uniform (2 0 0) ; // 2 m / s inlet velocity
}
innerOutlet
{
CFD Lab Manual - OpenFOAM 2406 17
type zeroGradient ;
}
innerFluid_to_pipeWall
{
type noSlip ;
}
frontAndBack
{
type empty ;
}
}
p rgh
{
solver GAMG ;
tolerance 1e -06;
relTol 0.01;
smoother GaussSeidel ;
}
PIMPLE
{
nOuterCorrectors 2;
nCorrectors 1;
n N o n O r t h o g o n a l C o r r e c t o r s 0;
}
}
}
# Create regions
topoSet
splitMeshRegions - cellZones
# Run simulation
ch tM ul tiR eg io nFo am
# Monitor convergence
tail -f log . ch tMu lt iR egi on Fo am
# Calculate effectiveness
postProcess - func " mag ( T ) " - time 1000
2.6 Assignments
2.6.1 Assignment 1
Vary the mass flow rates of hot and cold fluids and analyze the effect on heat exchanger
effectiveness. Compare results with analytical NTU-effectiveness charts.
2.6.2 Assignment 2
Investigate the effect of pipe wall thermal conductivity (steel vs copper) on overall heat
transfer performance. Calculate the thermal resistance distribution.
2.6.3 Assignment 3
Design an optimal double pipe heat exchanger for given inlet conditions by varying pipe
diameters and length. Perform parametric study to maximize heat transfer while mini-
mizing pressure drop.
Experiment 3: Internal Fluid Flow and
Heat Transfer in Centrifugal Pump
3.1 Objective
Analyze internal flow patterns, pressure distribution, and heat generation in a centrifugal
pump using pimpleFoam with moving reference frame (MRF).
3.2 Theory
The pump head is calculated as:
∆p V22 − V12
H= + + z2 − z1 (3.18)
ρg 2g
Pump efficiency:
Hydraulic Power ρgQH
η= = (3.19)
Shaft Power Pshaf t
The velocity triangle relationships at impeller exit:
Vu = U − Vr cot β (3.20)
U2 Vu2 − U1 Vu1
Hideal = (3.21)
g
where U is blade tip speed, Vr is relative velocity, β is blade angle.
Specific speed: √
n Q
ns = 3/4 (3.22)
H
Affinity laws:
Q2 N2
= (3.23)
Q1 N1
2
H2 N2
= (3.24)
H1 N1
3
P2 N2
= (3.25)
P1 N1
20
CFD Lab Manual - OpenFOAM 2406 21
Figure 3.3: Domain to be simulated (students will simplify this as per the instructions)
convertToMeters 0.001; // mm to m
vertices
(
// Impeller inlet eye
(0 0 0) // 0 - center
(20 0 0) // 1
(0 20 0) // 2
( -20 0 0) // 3
(0 -20 0) // 4
// Impeller exit
(100 0 0) // 5
(0 100 0) // 6
( -100 0 0) // 7
(0 -100 0) // 8
// Volute casing
(150 0 0) // 9
(0 150 0) // 10
( -150 0 0) // 11
(0 -150 0) // 12
// Outlet pipe
(200 -10 0) // 13
(200 10 0) // 14
(300 -10 0) // 15
CFD Lab Manual - OpenFOAM 2406 23
(300 10 0) // 16
// Z - direction (2 D case )
(0 0 5) // 17 - center
(20 0 5) // 18
(0 20 5) // 19
( -20 0 5) // 20
(0 -20 5) // 21
(100 0 5) // 22
(0 100 5) // 23
( -100 0 5) // 24
(0 -100 5) // 25
(150 0 5) // 26
(0 150 5) // 27
( -150 0 5) // 28
(0 -150 5) // 29
(200 -10 5) // 30
(200 10 5) // 31
(300 -10 5) // 32
(300 10 5) // 33
);
blocks
(
// Impeller region ( rotating )
hex (0 1 2 0 17 18 19 17) impeller (20 20 1) simpleGrading (1 1 1)
hex (0 2 3 0 17 19 20 17) impeller (20 20 1) simpleGrading (1 1 1)
hex (0 3 4 0 17 20 21 17) impeller (20 20 1) simpleGrading (1 1 1)
hex (0 4 1 0 17 21 18 17) impeller (20 20 1) simpleGrading (1 1 1)
// Outlet pipe
hex (13 15 16 14 30 32 33 31) volute (20 5 1) simpleGrading (1 1 1)
);
edges () ;
boundary
(
inlet
{
type patch ;
faces
(
(0 17 19 2)
(0 2 20 17)
(0 17 20 3)
CFD Lab Manual - OpenFOAM 2406 24
(0 3 21 17)
(0 17 21 4)
(0 4 18 17)
(0 17 18 1)
(0 1 19 17)
);
}
outlet
{
type patch ;
faces ((15 16 33 32) ) ;
}
impellerWalls
{
type wall ;
faces
(
// Impeller blade surfaces
(1 5 22 18)
(5 6 23 22)
// Add more blade surfaces
);
}
casing
{
type wall ;
faces
(
(9 10 27 26)
(10 11 28 27)
(11 12 29 28)
(12 9 26 29)
);
}
frontAndBack
{
type empty ;
faces () ; // Define all front and back faces
}
);
MRF1
{
cellZone impeller ;
active yes ;
actions
(
{
name impeller ;
type cellSet ;
action new ;
source cylinderToCell ;
sourceInfo
{
p1 (0 0 -1) ;
p2 (0 0 10) ;
radius 80;
}
}
{
name impeller ;
type cellZoneSet ;
action new ;
source setToCellZone ;
sourceInfo
{
set impeller ;
}
}
);
{
version 2.0;
format ascii ;
class volVectorField ;
object U;
}
dimensions [0 1 -1 0 0 0 0];
internalField uniform (0 0 0) ;
boundaryField
{
inlet
{
type fixedValue ;
value uniform (0 0 -5) ; // Axial inlet velocity
}
outlet
{
type zeroGradient ;
}
impellerWalls
{
type mov in gW all Ve lo cit y ;
value uniform (0 0 0) ;
}
casing
{
type noSlip ;
}
frontAndBack
{
type empty ;
}
}
Create 0/p:
FoamFile
{
version 2.0;
format ascii ;
class volScalarField ;
object p;
}
dimensions [0 2 -2 0 0 0 0];
internalField uniform 0;
boundaryField
{
inlet
{
type zeroGradient ;
}
CFD Lab Manual - OpenFOAM 2406 27
outlet
{
type fixedValue ;
value uniform 0;
}
impellerWalls
{
type zeroGradient ;
}
casing
{
type zeroGradient ;
}
frontAndBack
{
type empty ;
}
}
dimensions [0 2 -2 0 0 0 0];
internalField uniform 0.375; // k = 1.5*( U * I ) ^2 , I =0.1
boundaryField
{
inlet
{
type fixedValue ;
value uniform 0.375;
}
outlet
{
type zeroGradient ;
}
impellerWalls
{
type kqRWallFunction ;
value uniform 0.375;
}
CFD Lab Manual - OpenFOAM 2406 28
casing
{
type kqRWallFunction ;
value uniform 0.375;
}
frontAndBack
{
type empty ;
}
}
startFrom startTime ;
startTime 0;
stopAt endTime ;
endTime 10;
deltaT 0.001;
writeControl timeStep ;
writeInterval 100;
functions
{
forces
{
type forces ;
libs (" libforces . so ") ;
writeControl timeStep ;
writeInterval 10;
patches ( impellerWalls ) ;
rho rhoInf ;
rhoInf 1000;
CofR (0 0 0) ;
}
torque
{
type forces ;
libs (" libforces . so ") ;
writeControl timeStep ;
writeInterval 10;
patches ( impellerWalls ) ;
rho rhoInf ;
rhoInf 1000;
CofR (0 0 0) ;
CFD Lab Manual - OpenFOAM 2406 29
binData
{
nBin 1;
direction (0 0 1) ;
cumulative yes ;
}
}
flowRate
{
type sur faceFiel dValue ;
libs (" l i b f i e l d F u n c t i o n O b j e c t s . so ") ;
writeControl timeStep ;
writeInterval 10;
fields ( phi ) ;
operation sum ;
regionType patch ;
name outlet ;
}
}
pFinal
{
$p ;
relTol 0;
}
PIMPLE
CFD Lab Manual - OpenFOAM 2406 30
{
nOuterCorrectors 2;
nCorrectors 1;
n N o n O r t h o g o n a l C o r r e c t o r s 0;
pRefCell 0;
pRefValue 0;
}
Create [Link]:
set xlabel " Flow Rate ( $m ^3 $ / s ) "
set ylabel " Head ( m ) "
plot " postProcessing / forces /0/ forces . dat " using 1:2 with lines title "
Head "
pause -1
CFD Lab Manual - OpenFOAM 2406 31
3.6 Assignments
3.6.1 Assignment 1
Generate pump characteristic curves (H-Q, P-Q, η-Q) by varying flow rates. Compare
with typical centrifugal pump performance curves.
3.6.2 Assignment 2
Analyze the effect of impeller rotational speed on pump performance using similarity
laws. Validate the relationships: Q ∝ N , H ∝ N 2 , P ∝ N 3 .
3.6.3 Assignment 3
Investigate cavitation inception by analyzing pressure distribution at the impeller inlet.
Determine NPSH requirements and critical operating conditions.
Experiment 4: Analysis of Karman
Vortex Street over Cylinder
4.1 Objective
Simulate vortex shedding behind a circular cylinder using pimpleFoam to analyze Strouhal
number and unsteady wake characteristics.
4.2 Theory
The Strouhal number is defined as:
fD
St = (4.29)
U
where f is vortex shedding frequency, D is cylinder diameter, and U is free-stream veloc-
ity.
For Reynolds numbers 40 < Re < 1000:
19.7
St ≈ 0.198 1 − (4.30)
Re
32
CFD Lab Manual - OpenFOAM 2406 33
convertToMeters 1;
// Cylinder parameters
radius 0.5; // Cylinder radius
domain 20; // Domain extent
CFD Lab Manual - OpenFOAM 2406 35
vertices
(
// Inner cylinder boundary ( radius = 0.5)
( 0.3536 0.3536 0) // 0
( -0.3536 0.3536 0) // 1
( -0.3536 -0.3536 0) // 2
( 0.3536 -0.3536 0) // 3
// Outer boundary
( 20 10 0) // 8
( -5 10 0) // 9
( -5 -10 0) // 10
( 20 -10 0) // 11
// Z - direction (2 D case )
( 0.3536 0.3536 0.1) // 12
( -0.3536 0.3536 0.1) // 13
( -0.3536 -0.3536 0.1) // 14
( 0.3536 -0.3536 0.1) // 15
( 1.414 1.414 0.1) // 16
( -1.414 1.414 0.1) // 17
( -1.414 -1.414 0.1) // 18
( 1.414 -1.414 0.1) // 19
( 20 10 0.1) // 20
( -5 10 0.1) // 21
( -5 -10 0.1) // 22
( 20 -10 0.1) // 23
);
blocks
(
// Inner O - grid blocks around cylinder
hex (0 4 5 1 12 16 17 13) (20 20 1) simpleGrading (1 1 1)
hex (1 5 6 2 13 17 18 14) (20 20 1) simpleGrading (1 1 1)
hex (2 6 7 3 14 18 19 15) (20 20 1) simpleGrading (1 1 1)
hex (3 7 4 0 15 19 16 12) (20 20 1) simpleGrading (1 1 1)
edges
(
// Inner circle ( cylinder surface )
arc 0 1 (0 0.5 0)
arc 1 2 ( -0.5 0 0)
arc 2 3 (0 -0.5 0)
arc 3 0 (0.5 0 0)
CFD Lab Manual - OpenFOAM 2406 36
// Middle circle
arc 4 5 (0 2 0)
arc 5 6 ( -2 0 0)
arc 6 7 (0 -2 0)
arc 7 4 (2 0 0)
arc 16 17 (0 2 0.1)
arc 17 18 ( -2 0 0.1)
arc 18 19 (0 -2 0.1)
arc 19 16 (2 0 0.1)
);
boundary
(
inlet
{
type patch ;
faces
(
(9 10 22 21)
);
}
outlet
{
type patch ;
faces
(
(8 20 23 11)
);
}
top
{
type symmetryPlane ;
faces
(
(8 9 21 20)
);
}
bottom
{
type symmetryPlane ;
faces
(
(10 11 23 22)
);
}
cylinder
{
type wall ;
faces
CFD Lab Manual - OpenFOAM 2406 37
(
(0 12 13 1)
(1 13 14 2)
(2 14 15 3)
(3 15 12 0)
);
}
frontAndBack
{
type empty ;
faces
(
// All front and back faces
(0 1 5 4)
(1 2 6 5)
(2 3 7 6)
(3 0 4 7)
(4 5 9 8)
(5 6 10 9)
(6 7 11 10)
(7 4 8 11)
(12 16 17 13)
(13 17 18 14)
(14 18 19 15)
(15 19 16 12)
(16 20 21 17)
(17 21 22 18)
(18 22 23 19)
(19 23 20 16)
);
}
);
mergePatchPairs () ;
dimensions [0 1 -1 0 0 0 0];
internalField uniform (1 0 0) ;
boundaryField
{
inlet
{
type fixedValue ;
value uniform (1 0 0) ; // Re = 100 for D =1 , nu =0.01
CFD Lab Manual - OpenFOAM 2406 38
outlet
{
type zeroGradient ;
}
top
{
type symmetryPlane ;
}
bottom
{
type symmetryPlane ;
}
cylinder
{
type noSlip ;
}
frontAndBack
{
type empty ;
}
}
Create 0/p:
FoamFile
{
version 2.0;
format ascii ;
class volScalarField ;
object p;
}
dimensions [0 2 -2 0 0 0 0];
internalField uniform 0;
boundaryField
{
inlet
{
type zeroGradient ;
}
outlet
{
type fixedValue ;
value uniform 0;
}
top
{
type symmetryPlane ;
}
CFD Lab Manual - OpenFOAM 2406 39
bottom
{
type symmetryPlane ;
}
cylinder
{
type zeroGradient ;
}
frontAndBack
{
type empty ;
}
}
transportModel Newtonian ;
nu [0 2 -1 0 0 0 0] 0.01; // For Re = 100 with U =1 , D =1
startFrom startTime ;
startTime 0;
stopAt endTime ;
endTime 200; // Long enough to establish periodic
shedding
deltaT 0.005; // Small time step for accuracy
writeControl timeStep ;
writeInterval 100;
writeFormat ascii ;
writePrecision 8;
writeCompression off ;
timeFormat general ;
timePrecision 6;
CFD Lab Manual - OpenFOAM 2406 40
functions
{
forces
{
type forces ;
libs (" libforces . so ") ;
writeControl timeStep ;
writeInterval 1;
patches ( cylinder ) ;
rho rhoInf ;
rhoInf 1;
CofR (0 0 0) ;
}
forceCoeffs
{
type forceCoeffs ;
libs (" libforces . so ") ;
writeControl timeStep ;
writeInterval 1;
patches ( cylinder ) ;
rho rhoInf ;
rhoInf 1;
liftDir (0 1 0) ;
dragDir (1 0 0) ;
CofR (0 0 0) ;
lRef 1; // Cylinder diameter
Aref 1; // Reference area ( D *1 for 2 D )
}
probes
{
type probes ;
libs (" libsampling . so ") ;
writeControl timeStep ;
writeInterval 1;
fields (U p);
probeLocations
(
(1 0.5 0.05) // Wake monitoring point
(2 0 0.05) // Downstream centerline
(3 0 0.05) // Far wake
);
}
vorticity
{
type vorticity ;
libs (" l i b f i e l d F u n c t i o n O b j e c t s . so ") ;
writeControl writeTime ;
writeInterval 1;
}
}
CFD Lab Manual - OpenFOAM 2406 41
ddtSchemes
{
default Euler ;
}
gradSchemes
{
default Gauss linear ;
}
divSchemes
{
default none ;
div ( phi , U ) Gauss linearUpwind grad ( U ) ;
div ( phi , k ) Gauss limitedLinear 1;
div ( phi , omega ) Gauss limitedLinear 1;
div (( nuEff * dev2 ( T ( grad ( U ) ) ) ) ) Gauss linear ;
}
laplacianSchemes
{
default Gauss linear orthogonal ;
}
i n t e r p o l a t i on S c h e m e s
{
default linear ;
}
snGradSchemes
{
default orthogonal ;
}
wallDist
{
method meshWave ;
}
format ascii ;
class dictionary ;
object fvSolution ;
}
solvers
{
p
{
solver GAMG ;
tolerance 1e -06;
relTol 0.01;
smoother GaussSeidel ;
}
pFinal
{
$p ;
relTol 0;
}
U
{
solver smoothSolver ;
smoother symGaussSeidel ;
tolerance 1e -05;
relTol 0.1;
}
UFinal
{
$U ;
relTol 0;
}
}
PIMPLE
{
nOuterCorrectors 2;
nCorrectors 1;
n N o n O r t h o g o n a l C o r r e c t o r s 0;
pRefCell 0;
pRefValue 0;
}
# Generate mesh
blockMesh
# Run simulation
pimpleFoam > log . pimpleFoam 2 >&1 &
# Load data
data = np . loadtxt ( ’ cl_data . txt ’)
time = data [: , 0]
cl = data [: , 2] # Lift coefficient
# Perform FFT
frequencies , psd = signal . welch ( cl , fs , nperseg = len ( cl ) //4)
# Plot results
plt . figure ( figsize =(12 , 4) )
plt . subplot (1 , 2 , 1)
plt . plot ( time , cl )
plt . xlabel ( ’ Time ’)
plt . ylabel ( ’ Lift Coefficient ’)
plt . title ( ’ Lift Coefficient vs Time ’)
plt . subplot (1 , 2 , 2)
plt . loglog ( frequencies [1:] , psd [1:])
plt . axvline ( f_shed , color = ’r ’ , linestyle = ’ - - ’ , label =f ’ f = { f_shed :.3 f
} ’)
plt . xlabel ( ’ Frequency ( Hz ) ’)
plt . ylabel ( ’ PSD ’)
plt . title ( ’ Power Spectral Density ’)
plt . legend ()
plt . tight_layout ()
plt . savefig ( ’ strouh al_analy sis . png ’)
plt . show ()
EOF
# Launch ParaView
paraview
# Load case and visualize vorticity contours
# Create animation of vortex shedding
Figure 4.5: Distinct vortex shedding should be seen behind the cylinder
CFD Lab Manual - OpenFOAM 2406 45
4.6 Assignments
4.6.1 Assignment 1
Investigate the effect of Reynolds number (100, 200, 500) on Strouhal number and com-
pare with experimental correlations. Plot St vs Re relationship.
4.6.2 Assignment 2
Analyze the transition from steady to unsteady flow by gradually increasing Reynolds
number. Determine the critical Reynolds number for vortex shedding onset.
4.6.3 Assignment 3
Study the effect of blockage ratio (cylinder diameter to domain height ratio) on vortex
shedding characteristics and develop correction factors.
Experiment 5: Couette Flow Analysis -
Explicit and Implicit Methods
5.1 Objective
Implement and compare explicit and implicit finite difference schemes for solving the
unsteady Couette flow problem using custom OpenFOAM solvers and analyze numerical
stability and accuracy.
5.2 Theory
The governing equation for unsteady Couette flow between parallel plates:
∂u ∂ 2u
=ν 2 (5.38)
∂t ∂y
Initial condition: u(y, 0) = 0 for 0 ≤ y ≤ h
Boundary conditions:
u(0, t) = 0 (5.39)
u(h, t) = Uw (5.40)
Analytical solution using separation of variables:
∞ 2 2
Uw y X 2Uw nπy n π νt
u(y, t) = + n
(−1) sin exp − (5.41)
h n=1
nπ h h2
Steady-state solution:
Uw y
usteady (y) = (5.42)
h
Dimensionless time:
νt
τ= (5.43)
h2
Figure 5.6: Flow conditions that need to be simulated (with proper assumptions made
by the student)
46
CFD Lab Manual - OpenFOAM 2406 47
ai,i−1 = −r (5.49)
ai,i = 1 + 2r (5.50)
ai,i+1 = −r (5.51)
and r = ν∆t
(∆y)2
.
vertices
(
(0 0 0) // 0 - bottom wall
(1 0 0) // 1
(1 10 0) // 2 - top wall
(0 10 0) // 3
(0 0 0.1) // 4
(1 0 0.1) // 5
(1 10 0.1) // 6
(0 10 0.1) // 7
);
blocks
(
hex (0 1 2 3 4 5 6 7) (1 100 1) simpleGrading (1 1 1)
);
edges () ;
boundary
(
bottomWall
{
type wall ;
faces
(
(0 1 5 4)
);
}
topWall
{
type wall ;
faces
(
(2 3 7 6)
);
}
sides
{
type empty ;
faces
(
(0 3 2 1)
(4 5 6 7)
(0 4 7 3)
(1 2 6 5)
);
}
);
mergePatchPairs () ;
CFD Lab Manual - OpenFOAM 2406 49
transportModel Newtonian ;
nu [0 2 -1 0 0 0 0] 1e -06; // Water viscosity
dimensions [0 1 -1 0 0 0 0];
internalField uniform (0 0 0) ;
boundaryField
{
bottomWall
{
type noSlip ;
}
topWall
{
type fixedValue ;
value uniform (1 0 0) ; // Moving wall velocity
}
sides
{
type empty ;
}
}
Create 0/p:
FoamFile
{
version 2.0;
format ascii ;
class volScalarField ;
object p;
}
CFD Lab Manual - OpenFOAM 2406 50
dimensions [0 2 -2 0 0 0 0];
internalField uniform 0;
boundaryField
{
bottomWall
{
type zeroGradient ;
}
topWall
{
type zeroGradient ;
}
sides
{
type empty ;
}
}
IOobject :: MUST_READ ,
IOobject :: AUTO_WRITE
),
mesh
);
Info << " Maximum stable time step : " << maxDt << endl ;
Info << " Current time step : " << runTime . deltaT () . value () << endl ;
runTime . write () ;
Info << " ExecutionTime = " << runTime . elapsedCpuTime () << " s "
<< " ClockTime = " << runTime . elapsedClockTime () << " s "
<< nl << endl ;
}
UEqn . solve () ;
runTime . write () ;
Info << " ExecutionTime = " << runTime . elapsedCpuTime () << " s "
<< " ClockTime = " << runTime . elapsedClockTime () << " s "
<< nl << endl ;
}
explicitCouetteSolver .C
EXE = $ ( FOAM_USER_APPBIN ) / e x p l i c i t C o u e t t e S o l v e r
implicitCouetteSolver .C
EXE = $ ( FOAM_USER_APPBIN ) / i m p l i c i t C o u e t t e S o l v e r
Create Make/options:
EXE_INC = \
- I$ ( LIB_SRC ) / finiteVolume / lnInclude \
- I$ ( LIB_SRC ) / meshTools / lnInclude
EXE_LIBS = \
- lfiniteVolume \
- lmeshTools
application explicitCouetteSolver ;
startFrom startTime ;
startTime 0;
stopAt endTime ;
endTime 0.1;
deltaT 1e -06; // Small time step for stability
writeControl runTime ;
writeInterval 0.01;
writeFormat ascii ;
writePrecision 8;
writeCompression off ;
timeFormat general ;
timePrecision 6;
runTi meModifi able false ;
object controlDict ;
}
application implicitCouetteSolver ;
startFrom startTime ;
startTime 0;
stopAt endTime ;
endTime 0.1;
deltaT 1e -03; // Larger time step allowed
writeControl runTime ;
writeInterval 0.01;
writeFormat ascii ;
writePrecision 8;
writeCompression off ;
timeFormat general ;
timePrecision 6;
runTi meModifi able false ;
ddtSchemes
{
default Euler ;
}
gradSchemes
{
default Gauss linear ;
}
divSchemes
{
default none ;
}
laplacianSchemes
{
default Gauss linear orthogonal ;
}
i n t e r p o l a t i on S c h e m e s
{
default linear ;
}
snGradSchemes
{
CFD Lab Manual - OpenFOAM 2406 55
default orthogonal ;
}
solvers
{
U
{
solver smoothSolver ;
smoother symGaussSeidel ;
tolerance 1e -08;
relTol 0;
}
}
PISO
{
nCorrectors 2;
n N o n O r t h o g o n a l C o r r e c t o r s 0;
}
# Save results
cp -r [0 -9]* results_explicit /
# Save results
cp -r [0 -9]* results_implicit /
CFD Lab Manual - OpenFOAM 2406 56
return u
y = np . linspace (0 , h , 100)
times = [0.001 , 0.01 , 0.05 , 0.1]
plt . tight_layout ()
plt . savefig ( ’ c oue tt e_ com pa ri son . png ’)
plt . show ()
• Explicit method: faster per time step, more time steps needed
• Implicit method: slower per time step, fewer time steps needed
5.6 Assignments
5.6.1 Assignment 1
Determine the maximum stable time step for explicit scheme and compare computational
efficiency with implicit scheme for the same accuracy level.
5.6.2 Assignment 2
Implement Crank-Nicolson scheme and compare the numerical diffusion effects with ex-
plicit and implicit methods.
5.6.3 Assignment 3
Extend the analysis to oscillatory Couette flow and investigate the phase lag between
wall motion and fluid response using different numerical schemes.
Experiment 6: Heat Conduction in 2D
Flat Plate
6.1 Objective
Solve the 2D heat conduction equation using explicit and implicit formulations with
laplacianFoam and custom solvers to analyze numerical stability and accuracy.
6.2 Theory
The 2D unsteady heat conduction equation:
2
∂ 2T
∂T ∂ T
=α + (6.52)
∂t ∂x2 ∂y 2
where α = ρckp is thermal diffusivity.
For a rectangular plate with initial temperature T0 and boundary conditions:
T (0, y, t) = T1 (6.53)
T (L, y, t) = T2 (6.54)
T (x, 0, t) = T3 (6.55)
T (x, H, t) = T4 (6.56)
Analytical solution for steady state:
X∞ nπx nπy
Tsteady (x, y) = An sinh sin (6.57)
n=1
H H
For explicit finite difference in 2D:
α∆t α∆t
n+1
Ti,j n
= Ti,j + n
(Ti+1,j n
− 2Ti,j n
+ Ti−1,j )+ (T n − 2Ti,j
n n
+ Ti,j−1 ) (6.58)
(∆x) 2 (∆y)2 i,j+1
Stability condition for 2D explicit scheme:
α∆t α∆t 1
2
+ 2
≤ (6.59)
(∆x) (∆y) 2
For uniform grid (∆x = ∆y = h):
h2
∆t ≤ (6.60)
4α
Fourier number:
α∆t
Fo = (6.61)
h2
58
CFD Lab Manual - OpenFOAM 2406 59
y
∂T/∂y = 0 (Insulated)
Heat Flow →
H = 5 cm
T₁ = 100°C T₂ = 20°C
Initial: T₀ = 20°C
∂T/∂y = 0 (Insulated) x
L = 10 cm
Solution Methods:
1. Explicit Finite Difference (Custom Solver) | 2. Implicit Finite Difference (laplacianFoam) | 3. Analytical Solution (Fourier Series)
Figure 6.7: Schematic for the setup of the problem (already simplified)
CFD Lab Manual - OpenFOAM 2406 60
convertToMeters 0.01; // cm to m
vertices
(
(0 0 0) // 0
(10 0 0) // 1 - plate length 10 cm
(10 5 0) // 2 - plate height 5 cm
(0 5 0) // 3
(0 0 0.1) // 4 - thickness 1 mm
(10 0 0.1) // 5
(10 5 0.1) // 6
(0 5 0.1) // 7
);
blocks
(
hex (0 1 2 3 4 5 6 7) (50 25 1) simpleGrading (1 1 1)
);
edges () ;
boundary
(
left
{
type patch ;
faces
(
CFD Lab Manual - OpenFOAM 2406 61
(0 4 7 3)
);
}
right
{
type patch ;
faces
(
(1 2 6 5)
);
}
bottom
{
type patch ;
faces
(
(0 1 5 4)
);
}
top
{
type patch ;
faces
(
(2 3 7 6)
);
}
frontAndBack
{
type empty ;
faces
(
(0 3 2 1)
(4 5 6 7)
);
}
);
mergePatchPairs () ;
// Aluminum properties
rho [1 -3 0 0 0 0 0] 2700;
Cp [0 2 -2 -1 0 0 0] 900;
k [1 1 -3 -1 0 0 0] 237;
dimensions [0 0 0 1 0 0 0];
internalField uniform 293; // Initial temperature 20 C
boundaryField
{
left
{
type fixedValue ;
value uniform 373;
}
right
{
type fixedValue ;
value uniform 293;
}
bottom
{
type zeroGradient ; // Insulated
}
top
{
type zeroGradient ; // Insulated
CFD Lab Manual - OpenFOAM 2406 63
frontAndBack
{
type empty ;
}
}
Info << " Cell size ( approx ) : " << deltaX << " m " << endl ;
Info << " Maximum stable time step : " << maxDt << " s " << endl ;
CFD Lab Manual - OpenFOAM 2406 64
Info << " Current time step : " << runTime . deltaT () . value () << " s "
<< endl ;
volScalarField TOld = T ;
// Calculate residual
scalar residual = gMax ( mag ( T - TOld ) () . primitiveField () ) /
runTime . deltaT () . value () ;
Info << " T stats - Min : " << Tmin << " K , Max : " << Tmax
<< " K , Avg : " << Tavg << " K " << endl ;
runTime . write () ;
Info << " ExecutionTime = " << runTime . elapsedCpuTime () << " s "
<< " ClockTime = " << runTime . elapsedClockTime () << " s "
<< nl << endl ;
break ;
}
}
application laplacianFoam ;
startFrom startTime ;
startTime 0;
stopAt endTime ;
endTime 1000;
deltaT 1; // Large time step for implicit
writeControl runTime ;
writeInterval 50;
writeFormat ascii ;
writePrecision 8;
writeCompression off ;
timeFormat general ;
timePrecision 6;
runTi meModifi able true ;
functions
{
temperatureStats
{
type fieldMinMax ;
libs (" l i b f i e l d F u n c t i o n O b j e c t s . so ") ;
writeControl timeStep ;
writeInterval 1;
fields (T);
}
probes
{
type probes ;
libs (" libsampling . so ") ;
writeControl timeStep ;
writeInterval 10;
fields (T);
probeLocations
(
(0.025 0.025 0.05) // Quarter point
CFD Lab Manual - OpenFOAM 2406 66
functions
{
temperatureStats
{
type fieldMinMax ;
libs (" l i b f i e l d F u n c t i o n O b j e c t s . so ") ;
writeControl timeStep ;
writeInterval 100;
fields (T);
}
}
ddtSchemes
{
default Euler ; // First - order in time
// Alternative : backward ; // Second - order in time
}
gradSchemes
{
default Gauss linear ;
}
divSchemes
{
default none ;
}
laplacianSchemes
{
default Gauss linear orthogonal ;
// Alternative : Gauss linear corrected ; // For non - orthogonal
meshes
}
i n t e r p o l a t i on S c h e m e s
{
default linear ;
}
snGradSchemes
{
default orthogonal ;
// Alternative : corrected ; // For non - orthogonal meshes
}
solvers
{
T
{
solver GAMG ;
tolerance 1e -08;
relTol 0.01;
smoother GaussSeidel ;
nPreSweeps 0;
nPostSweeps 2;
CFD Lab Manual - OpenFOAM 2406 68
nFinestSweeps 2;
ca ch eA ggl om er ati on true ;
n C e l l s I n C o a r s e s t L e v e l 10;
agglomerator faceAreaPair ;
mergeLevels 1;
}
TFinal
{
$T ;
relTol 0;
}
}
SIMPLE
{
n N o n O r t h o g o n a l C o r r e c t o r s 0;
residualControl
{
T 1e -6;
}
}
EXE_LIBS = \\
- lfiniteVolume \\
- lmeshTools
EOF
# Compile
wmake
Run simulations:
CFD Lab Manual - OpenFOAM 2406 69
# Generate mesh
blockMesh
# Save results
mkdir results_explicit
cp -r [0 -9]* results_explicit /
# Save results
mkdir results_implicit
cp -r [0 -9]* results_implicit /
# Parameters
L = 0.1 # Length ( m )
H = 0.05 # Height ( m )
T_left = 373 # Hot boundary ( K )
T_right = 293 # Cold boundary ( K )
T_init = 293 # Initial temperature ( K )
alpha = 1e -5 # Thermal diffusivity ( $m ^2 $ / s )
# Create meshgrid
x = np . linspace (0 , L , 50)
y = np . linspace (0 , H , 25)
X , Y = np . meshgrid (x , y )
# Time points
times = [10 , 50 , 100 , 500]
plt . tight_layout ()
plt . savefig ( ’ a n a l y t i c a l _ t e m p e r a t u r e . png ’)
plt . show ()
"""
Load temperature field from OpenFOAM case
( This is a placeholder - actual implementation would parse OpenFOAM
files )
"""
# Use foamToVTK and then load VTK files , or
# Parse the OpenFOAM T file directly
pass
def plot_convergence () :
""" Plot convergence comparison between explicit and implicit
methods """
plt . subplot (1 , 2 , 1)
plt . semilogy ( time_explicit , residual_explicit , ’r - ’ , alpha =0.7 ,
label = ’ Explicit ’)
plt . semilogy ( time_implicit , residual_implicit , ’b - ’ , linewidth =2 ,
label = ’ Implicit ’)
plt . xlabel ( ’ Time ( s ) ’)
plt . ylabel ( ’ Residual ’)
plt . title ( ’ Convergence Comparison ’)
plt . legend ()
plt . grid ( True )
# Computational efficiency
plt . subplot (1 , 2 , 2)
e ff i ci e n cy _ ex p l ic i t = len ( time_explicit ) / 1000 # Relative cost
e ff i ci e n cy _ im p l ic i t = len ( time_implicit ) / 1000
plt . tight_layout ()
plt . savefig ( ’ method _compari son . png ’)
plt . show ()
# Run comparison
plot_convergence ()
CFD Lab Manual - OpenFOAM 2406 72
6.5 Assignments
6.5.1 Assignment 1
Analyze heat conduction in a plate with sinusoidal boundary conditions and compare
numerical results with analytical Fourier series solution.
6.5.2 Assignment 2
Investigate the effect of mesh refinement on solution accuracy using Richardson extrap-
olation method. Calculate the order of accuracy for both schemes.
6.5.3 Assignment 3
Implement alternating direction implicit (ADI) method and compare its performance
with standard explicit and implicit schemes for large-scale problems.
Experiment 7: 1D Wave Propagation
in Still Lake
7.1 Objective
Simulate 1D wave propagation using the shallow water equations with interFoam and
analyze wave characteristics including dispersion and reflection.
7.2 Theory
The 1D shallow water equations:
∂h ∂(hu)
+ =0 (7.62)
∂t ∂x
∂(hu) ∂ 1
+ hu2 + gh2 = 0 (7.63)
∂t ∂x 2
Dispersion relation:
ω 2 = gk tanh(kh) (7.66)
√
For shallow water (kh ≪ 1): ω √= gh · k
For deep water (kh ≫ 1): ω = gk
Phase velocity: r
ω g
cp = = tanh(kh) (7.67)
k k
Group velocity:
r
dω 1 g 2kh
cg = = tanh(kh) 1 + (7.68)
dk 2 k sinh(2kh)
Wave energy:
1
E = ρgA2 (7.69)
2
73
CFD Lab Manual - OpenFOAM 2406 74
Wave Propagation
H=3m
d = 1.5 m
Gauge 1 Gauge
BOTTOM
2 (Wall) Gauge 3 Gauge 4
L = 20 m
convertToMeters 1;
vertices
(
(0 0 0) // 0 - wave tank start
(20 0 0) // 1 - wave tank end (20 m long )
(20 1 0) // 2 - water surface
(0 1 0) // 3
(20 2 0) // 4 - air region top
(0 2 0) // 5
(0 0 0.1) // 6 - back face
(20 0 0.1) // 7
(20 1 0.1) // 8
(0 1 0.1) // 9
(20 2 0.1) // 10
(0 2 0.1) // 11
);
blocks
(
hex (0 1 2 3 6 7 8 9) water (400 20 1) simpleGrading (1 1 1)
// Water region
hex (3 2 4 5 9 8 10 11) air (400 20 1) simpleGrading (1 1 1) //
Air region
);
edges () ;
boundary
(
CFD Lab Manual - OpenFOAM 2406 76
inlet
{
type waveInlet ;
faces
(
(0 3 9 6) // Left boundary ( water )
(3 5 11 9) // Left boundary ( air )
);
}
outlet
{
type waveAbsorption ;
faces
(
(1 7 8 2) // Right boundary ( water )
(2 8 10 4) // Right boundary ( air )
);
}
bottom
{
type wall ;
faces
(
(0 6 7 1) // Tank bottom
);
}
atmosphere
{
type patch ;
faces
(
(5 4 10 11) // Top boundary
);
}
frontAndBack
{
type empty ;
faces
(
(0 1 2 3) // Front water
(3 2 4 5) // Front air
(6 9 8 7) // Back water
(9 11 10 8) // Back air
);
}
);
mergePatchPairs () ;
FoamFile
{
version 2.0;
format ascii ;
class volScalarField ;
object alpha . water ;
}
dimensions [0 0 0 0 0 0 0];
internalField uniform 0;
boundaryField
{
inlet
{
type waveAlpha ;
waveModel StokesFirst ;
nPaddle 1;
waveHeight 0.1; // Wave height ( m )
waveAngle 0.0; // Wave direction
wavePeriod 2.0; // Wave period ( s )
wavePhase 0.0; // Initial phase
seaLevel 1.0; // Still water level
s ea L ev e l As R ef e r en c e true ;
value uniform 0;
}
outlet
{
type waveAbsorption ;
absorptionType shallow ;
value uniform 0;
}
bottom
{
type zeroGradient ;
}
atmosphere
{
type inletOutlet ;
inletValue uniform 0;
value uniform 0;
}
frontAndBack
{
type empty ;
}
}
{
version 2.0;
format ascii ;
class volVectorField ;
object U;
}
dimensions [0 1 -1 0 0 0 0];
internalField uniform (0 0 0) ;
boundaryField
{
inlet
{
type waveVelocity ;
waveModel StokesFirst ;
nPaddle 1;
waveHeight 0.1;
waveAngle 0.0;
wavePeriod 2.0;
wavePhase 0.0;
seaLevel 1.0;
value uniform (0 0 0) ;
}
outlet
{
type waveAbsorption ;
absorptionType shallow ;
value uniform (0 0 0) ;
}
bottom
{
type noSlip ;
}
atmosphere
{
type pressureInletOutletVelocity ;
value uniform (0 0 0) ;
}
frontAndBack
{
type empty ;
}
}
class volScalarField ;
object p rgh ;
}
dimensions [1 -1 -2 0 0 0 0];
internalField uniform 0;
boundaryField
{
inlet
{
type fix edFluxPr essure ;
value uniform 0;
}
outlet
{
type fix edFluxPr essure ;
value uniform 0;
}
bottom
{
type fix edFluxPr essure ;
value uniform 0;
}
atmosphere
{
type totalPressure ;
p0 uniform 0;
value uniform 0;
}
frontAndBack
{
type empty ;
}
}
de fa ul tFi el dV alu es
(
v ol S ca l a rF i el d V al u e alpha . water 0
);
CFD Lab Manual - OpenFOAM 2406 80
regions
(
boxToCell
{
box (0 0 0) (20 1 0.1) ; // Water region
fieldValues
(
v ol S c al a rF i e ld V al u e alpha . water 1
);
}
);
inlet
{
waveModel StokesFirst ;
outlet
{
absorptionType shallow ;
nPaddle 1;
}
FoamFile
{
version 2.0;
format ascii ;
class dictionary ;
object tr a ns p o rt P ro p e rt i es ;
}
water
{
transportModel Newtonian ;
nu [0 2 -1 0 0 0 0] 1e -06;
rho [1 -3 0 0 0 0 0] 1000;
}
air
{
transportModel Newtonian ;
nu [0 2 -1 0 0 0 0] 1.48 e -05;
rho [1 -3 0 0 0 0 0] 1;
}
dimensions [0 1 -2 0 0 0 0];
value (0 -9.81 0) ;
application interFoam ;
startFrom startTime ;
CFD Lab Manual - OpenFOAM 2406 82
startTime 0;
stopAt endTime ;
endTime 20; // Simulate for 10 wave periods
deltaT 0.01; // Small time step for wave accuracy
writeControl runTime ;
writeInterval 0.1;
writeFormat ascii ;
writePrecision 8;
writeCompression off ;
timeFormat general ;
timePrecision 6;
runTi meModifi able true ;
functions
{
waveElevation
{
type surfaceElevation ;
libs (" libwaves . so ") ;
writeControl timeStep ;
writeInterval 1;
setFormat raw ;
i nt e rp o l at i on S c he m e cellPoint ;
fields ( alpha . water ) ;
sets
(
gauge1
{
type face ;
axis xyz ;
start (2 0 0.05) ;
end (2 2 0.05) ;
}
gauge2
{
type face ;
axis xyz ;
start (5 0 0.05) ;
end (5 2 0.05) ;
}
gauge3
{
type face ;
axis xyz ;
start (10 0 0.05) ;
end (10 2 0.05) ;
}
gauge4
{
type face ;
axis xyz ;
start (15 0 0.05) ;
CFD Lab Manual - OpenFOAM 2406 83
forces
{
type forces ;
libs (" libforces . so ") ;
writeControl timeStep ;
writeInterval 10;
patches ( bottom ) ;
rho rhoInf ;
rhoInf 1000;
CofR (10 0 0) ;
}
probes
{
type probes ;
libs (" libsampling . so ") ;
writeControl timeStep ;
writeInterval 5;
fields ( U p rgh alpha . water ) ;
probeLocations
(
(2 0.5 0.05) // Near inlet
(5 0.5 0.05) // Quarter point
(10 0.5 0.05) // Center
(15 0.5 0.05) // Three - quarter point
);
}
}
ddtSchemes
{
default Euler ;
}
gradSchemes
{
default Gauss linear ;
}
divSchemes
CFD Lab Manual - OpenFOAM 2406 84
{
div ( rhoPhi , U ) Gauss linearUpwind grad ( U ) ;
div ( phi , alpha ) Gauss vanLeer ;
div ( phirb , alpha ) Gauss i n t e r f a c e C o m pr e s s i o n ;
div ((( rho * nuEff ) * dev2 ( T ( grad ( U ) ) ) ) ) Gauss linear ;
}
laplacianSchemes
{
default Gauss linear corrected ;
}
i n t e r p o l a t i on S c h e m e s
{
default linear ;
}
snGradSchemes
{
default corrected ;
}
solvers
{
" alpha . water .*"
{
nAlphaCorr 2;
nAlphaSubCycles 1;
cAlpha 1;
MULESCorr yes ;
nLimiterIter 3;
solver smoothSolver ;
smoother symGaussSeidel ;
tolerance 1e -08;
relTol 0;
}
p rgh
{
solver GAMG ;
tolerance 1e -07;
relTol 0.05;
smoother GaussSeidel ;
}
p rghFinal
{
$p rgh ;
relTol 0;
}
U
{
solver smoothSolver ;
smoother symGaussSeidel ;
tolerance 1e -06;
relTol 0;
}
}
PIMPLE
{
momen tumPredi ctor no ;
nOuterCorrectors 1;
nCorrectors 3;
n N o n O r t h o g o n a l C o r r e c t o r s 0;
}
# Run simulation
interFoam > log . interFoam 2 >&1 &
CFD Lab Manual - OpenFOAM 2406 86
# Monitor progress
tail -f log . interFoam
# Frequency analysis
dt = time [1] - time [0]
frequencies = fftfreq ( len ( elevation ) , dt )
fft_elevation = fft ( elevation )
power_spectrum = np . abs ( fft_elevation ) **2
return {
’ height ’: wave_height ,
’ period ’: dominant_period ,
’ frequency ’: dominant_frequency ,
’ mean_level ’: mean_level
}
# Time series
axes [0 ,0]. plot ( time , elevation , ’b - ’ , linewidth =1)
axes [0 ,0]. axhline ( analysis_results [ ’ mean_level ’] , color = ’r ’ ,
linestyle = ’ - - ’ , label = ’ Mean Level ’)
axes [0 ,0]. set_xlabel ( ’ Time ( s ) ’)
axes [0 ,0]. set_ylabel ( ’ Wave Elevation ( m ) ’)
axes [0 ,0]. set_title ( ’ Wave Time Series ’)
axes [0 ,0]. grid ( True )
axes [0 ,0]. legend ()
# Frequency spectrum
dt = time [1] - time [0]
frequencies = fftfreq ( len ( elevation ) , dt )
fft_elevation = fft ( elevation )
power_spectrum = np . abs ( fft_elevation ) **2
# Wave statistics
axes [1 ,1]. text (0.1 , 0.8 , f " Wave Height : { analysis_results [ ’ height
’]:.3 f } m " ,
transform = axes [1 ,1]. transAxes , fontsize =12)
axes [1 ,1]. text (0.1 , 0.6 , f " Period : { analysis_results [ ’ period ’]:.3 f }
s",
transform = axes [1 ,1]. transAxes , fontsize =12)
axes [1 ,1]. text (0.1 , 0.4 , f " Frequency : { analysis_results [ ’ frequency
’]:.3 f } Hz " ,
transform = axes [1 ,1]. transAxes , fontsize =12)
axes [1 ,1]. text (0.1 , 0.2 , f " Mean Level : { analysis_results [ ’
mean_level ’]:.3 f } m " ,
transform = axes [1 ,1]. transAxes , fontsize =12)
axes [1 ,1]. set_title ( ’ Wave Statistics ’)
axes [1 ,1]. set_xlim (0 , 1)
axes [1 ,1]. set_ylim (0 , 1)
axes [1 ,1]. axis ( ’ off ’)
plt . tight_layout ()
plt . savefig ( ’ wave_analysis . png ’ , dpi =300 , bbox_inches = ’ tight ’)
plt . show ()
• Wavelength: λ ≈ 6.25 m
7.5 Assignments
7.5.1 Assignment 1
Generate and analyze progressive waves of different frequencies. Validate dispersion re-
lation and compare with linear wave theory.
7.5.2 Assignment 2
Simulate wave reflection from a vertical wall and analyze standing wave patterns. Cal-
culate reflection coefficients.
7.5.3 Assignment 3
Investigate nonlinear effects by increasing wave amplitude and analyze higher-order har-
monics generation using spectral analysis.
Experiment 8: 2D Rayleigh-Taylor
Instability Using VOF Method
8.1 Objective
Simulate Rayleigh-Taylor instability using Volume of Fluid (VOF) method with interFoam
to study density-driven convection and interfacial instabilities.
8.2 Theory
Rayleigh-Taylor instability occurs when a denser fluid is positioned above a lighter fluid
in a gravitational field. The interface becomes unstable and develops into characteristic
bubble and spike structures.
Linear growth rate of Rayleigh-Taylor instability:
s
gk(ρh − ρl ) σk 3
γ= − (8.70)
ρh + ρl ρh + ρl
where k is wavenumber, ρh and ρl are heavy and light fluid densities, g is gravitational
acceleration, and σ is surface tension.
Atwood number:
ρh − ρl
A= (8.71)
ρh + ρl
For negligible surface tension, the growth rate simplifies to:
(8.72)
p
γ = Agk
90
CFD Lab Manual - OpenFOAM 2406 91
Figure 8.9: Typical representation of a Rayleigh - Taylor Instability (device a case ac-
cordingly)
convertToMeters 0.001; // mm to m
vertices
(
(0 0 0) // 0 - bottom left
(40 0 0) // 1 - bottom right (4 cm width )
(40 80 0) // 2 - top right (8 cm height )
(0 80 0) // 3 - top left
(0 0 1) // 4 - back bottom left
(40 0 1) // 5 - back bottom right
CFD Lab Manual - OpenFOAM 2406 92
blocks
(
hex (0 1 2 3 4 5 6 7) (80 160 1) simpleGrading (1 1 1)
);
edges () ;
boundary
(
left
{
type symmetryPlane ;
faces
(
(0 4 7 3)
);
}
right
{
type symmetryPlane ;
faces
(
(1 2 6 5)
);
}
bottom
{
type wall ;
faces
(
(0 1 5 4)
);
}
top
{
type wall ;
faces
(
(2 3 7 6)
);
}
frontAndBack
{
type empty ;
faces
(
(0 3 2 1)
(4 5 6 7)
);
}
CFD Lab Manual - OpenFOAM 2406 93
);
mergePatchPairs () ;
heavy
{
transportModel Newtonian ;
nu [0 2 -1 0 0 0 0] 1e -06; // Viscosity ( water -
like )
rho [1 -3 0 0 0 0 0] 1200; // Heavy fluid density
}
light
{
transportModel Newtonian ;
nu [0 2 -1 0 0 0 0] 1.5 e -05; // Viscosity ( air - like )
rho [1 -3 0 0 0 0 0] 1; // Light fluid density
}
dimensions [0 0 0 0 0 0 0];
internalField uniform 0;
boundaryField
{
left
CFD Lab Manual - OpenFOAM 2406 94
{
type symmetryPlane ;
}
right
{
type symmetryPlane ;
}
bottom
{
type zeroGradient ;
}
top
{
type zeroGradient ;
}
frontAndBack
{
type empty ;
}
}
dimensions [0 1 -1 0 0 0 0];
internalField uniform (0 0 0) ;
boundaryField
{
left
{
type symmetryPlane ;
}
right
{
type symmetryPlane ;
}
bottom
{
type noSlip ;
}
CFD Lab Manual - OpenFOAM 2406 95
top
{
type noSlip ;
}
frontAndBack
{
type empty ;
}
}
Create 0/p_rgh:
FoamFile
{
version 2.0;
format ascii ;
class volScalarField ;
object p rgh ;
}
dimensions [1 -1 -2 0 0 0 0];
internalField uniform 0;
boundaryField
{
left
{
type symmetryPlane ;
}
right
{
type symmetryPlane ;
}
bottom
{
type fix edFluxPr essure ;
value uniform 0;
}
top
{
type fix edFluxPr essure ;
value uniform 0;
}
frontAndBack
{
type empty ;
}
}
FoamFile
{
version 2.0;
format ascii ;
class dictionary ;
object setFieldsDict ;
}
de fa ul tFi el dV alu es
(
v ol S ca l a rF i el d V al u e alpha . heavy 0 // Light fluid everywhere
initially
);
regions
(
// Main heavy fluid region ( upper half )
boxToCell
{
box (0 40 0) (40 80 1) ; // Upper half
fieldValues
(
v ol S c al a rF i e ld V al u e alpha . heavy 1
);
}
cylinderToCell
{
p1 (30 38.5 0) ;
p2 (30 38.5 1) ;
radius 1.5;
fieldValues
CFD Lab Manual - OpenFOAM 2406 97
(
v ol S c al a rF i e ld V al u e alpha . heavy 1
);
}
);
dimensions [0 1 -2 0 0 0 0];
value (0 -9.81 0) ;
application interFoam ;
startFrom startTime ;
startTime 0;
stopAt endTime ;
endTime 2; // Simulate for 2 seconds
deltaT 1e -05; // Very small initial time step
writeControl adj ustableR unTime ;
writeInterval 0.05; // Write every 0.05 seconds
writeFormat ascii ;
writePrecision 8;
writeCompression off ;
timeFormat general ;
timePrecision 6;
runTi meModifi able true ;
functions
{
CFD Lab Manual - OpenFOAM 2406 98
interfaceHeight
{
type interfaceHeight ;
libs (" l i b f i e l d F u n c t i o n O b j e c t s . so ") ;
writeControl timeStep ;
writeInterval 50;
locations ((0.01 0.04 0.0005) (0.02 0.04 0.0005) (0.03
0.04 0.0005) ) ;
alpha alpha . heavy ;
}
mixingHeight
{
type fieldMinMax ;
libs (" l i b f i e l d F u n c t i o n O b j e c t s . so ") ;
writeControl timeStep ;
writeInterval 50;
fields ( alpha . heavy ) ;
}
centerlineProbe
{
type probes ;
libs (" libsampling . so ") ;
writeControl timeStep ;
writeInterval 10;
fields ( alpha . heavy U p rgh ) ;
probeLocations
(
(0.02 0.01 0.0005) // Bottom
(0.02 0.02 0.0005) // Quarter
(0.02 0.04 0.0005) // Interface
(0.02 0.06 0.0005) // Three - quarter
(0.02 0.07 0.0005) // Top
);
}
vorticity
{
type vorticity ;
libs (" l i b f i e l d F u n c t i o n O b j e c t s . so ") ;
writeControl writeTime ;
writeInterval 1;
}
bubbleTracking
{
type surfaces ;
libs (" libsampling . so ") ;
writeControl writeTime ;
writeInterval 1;
surfaceFormat vtk ;
surfaces
(
interface
{
type isoSurface ;
isoField alpha . heavy ;
CFD Lab Manual - OpenFOAM 2406 99
isoValue 0.5;
interpolate true ;
}
);
}
}
ddtSchemes
{
default Euler ;
}
gradSchemes
{
default Gauss linear ;
}
divSchemes
{
div ( rhoPhi , U ) Gauss linearUpwind grad ( U ) ;
div ( phi , alpha ) Gauss vanLeer ;
div ( phirb , alpha ) Gauss i n t e r f a c e C o m pr e s s i o n ; // Interface
sharpening
div ((( rho * nuEff ) * dev2 ( T ( grad ( U ) ) ) ) ) Gauss linear ;
}
laplacianSchemes
{
default Gauss linear corrected ;
}
i n t e r p o l a t i on S c h e m e s
{
default linear ;
}
snGradSchemes
{
default corrected ;
}
fluxRequired
{
default no ;
p rgh ;
CFD Lab Manual - OpenFOAM 2406 100
pcorr ;
alpha . heavy ;
}
solvers
{
" alpha . heavy .*"
{
nAlphaCorr 2;
nAlphaSubCycles 1;
cAlpha 1; // Interface compression
MULESCorr yes ;
nLimiterIter 5;
al ph aA ppl yP re vCo rr yes ;
solver smoothSolver ;
smoother symGaussSeidel ;
tolerance 1e -08;
relTol 0;
minIter 1;
}
p rgh
{
solver GAMG ;
tolerance 1e -08;
relTol 0.01;
smoother GaussSeidel ;
nPreSweeps 0;
CFD Lab Manual - OpenFOAM 2406 101
nPostSweeps 2;
nFinestSweeps 2;
ca ch eA ggl om er ati on true ;
n C e l l s I n C o a r s e s t L e v e l 10;
agglomerator faceAreaPair ;
mergeLevels 1;
}
p rghFinal
{
$p rgh ;
relTol 0;
}
U
{
solver smoothSolver ;
smoother symGaussSeidel ;
tolerance 1e -06;
relTol 0;
minIter 1;
}
}
PIMPLE
{
momen tumPredi ctor no ;
nOuterCorrectors 1;
nCorrectors 3;
n N o n O r t h o g o n a l C o r r e c t o r s 0;
pRefCell 0;
pRefValue 0;
}
# Run simulation
interFoam > log . interFoam 2 >&1 &
CFD Lab Manual - OpenFOAM 2406 102
# Monitor progress
tail -f log . interFoam
# Theoretical parameters
A = 0.998 # Atwood number
g = 9.81 # Gravity
alpha _theoret ical = 0.05 # Bubble growth coefficient
# Fit to h = $ \ alpha$ A g t2
def t he or eti ca l_ hei gh t (t , alpha ) :
return alpha * A * g * t **2
return alpha_fitted
# Bubble penetration
axes [0 ,0]. plot ( time_data , bubble_data , ’bo - ’ , label = ’ Simulation ’)
# Theoretical curve
A = 0.998
g = 9.81
alpha_b = 0.05
theory_bubble = alpha_b * A * g * time_data **2
axes [0 ,0]. plot ( time_data , theory_bubble , ’r - - ’ , label = ’ Theory ( $ \
alpha$ =0.05) ’)
# Spike penetration
axes [0 ,1]. plot ( time_data , spike_data , ’ro - ’ , label = ’ Simulation ’)
alpha_s = 0.8
theory_spike = alpha_s * A * g * time_data **2
axes [0 ,1]. plot ( time_data , theory_spike , ’b - - ’ , label = ’ Theory ( $ \
alpha$ =0.8) ’)
# Growth rates
if len ( time_data ) > 1:
dt = time_data [1] - time_data [0]
bu bb le _gr ow th _ra te = np . gradient ( bubble_data , dt )
spike _growth_ rate = np . gradient ( spike_data , dt )
# Mixing statistics
mixing_width = bubble_data + spike_data
axes [1 ,1]. plot ( time_data , mixing_width , ’g - ’ , linewidth =2)
axes [1 ,1]. set_xlabel ( ’ Time ( s ) ’)
axes [1 ,1]. set_ylabel ( ’ Mixing Width ( m ) ’)
axes [1 ,1]. set_title ( ’ Total Mixing Layer Width ’)
axes [1 ,1]. grid ( True )
plt . tight_layout ()
plt . savefig ( ’ rt_analysis . png ’ , dpi =300 , bbox_inches = ’ tight ’)
plt . show ()
def c a l c u l a t e _ g r o w t h _ p a r a m e t e r s () :
""" Calculate theoretical growth parameters """
# Material properties
rho_heavy = 1200 # kg / $m ^3 $
rho_light = 1 # kg / $m ^3 $
g = 9.81 # m / $s ^2 $
sigma = 0.01 # N/m
# Atwood number
A = ( rho_heavy - rho_light ) / ( rho_heavy + rho_light )
CFD Lab Manual - OpenFOAM 2406 104
# Critical wavelength
lambda_c = 2 * np . pi * np . sqrt ( sigma / (( rho_heavy - rho_light ) * g
))
# Run analysis
if __name__ == " __main__ ":
c a l c u l a t e _ g r o w t h _ p a r a m e t e r s ()
8.5 Assignments
8.5.1 Assignment 1
Vary the Atwood number and analyze its effect on instability growth rate. Compare with
linear stability theory predictions.
8.5.2 Assignment 2
Study the effect of surface tension on small-scale instabilities and determine the critical
wavelength below which surface tension stabilizes the interface.
8.5.3 Assignment 3
Investigate the nonlinear regime and characterize the transition to turbulent mixing.
Analyze the mixing efficiency and entrainment rates.
Experiment 9: Lid-Driven Cavity Flow
Using Vorticity-Streamfunction
9.1 Objective
Analyze lid-driven cavity flow using vorticity-streamfunction formulation with custom
OpenFOAM solvers to study recirculation patterns and corner vortices.
9.2 Theory
The vorticity-streamfunction formulation transforms the Navier-Stokes equations into:
Vorticity definition:
∂v ∂u
ω =∇×U= − (9.77)
∂x ∂y
Streamfunction definition:
∂ψ
u= (9.78)
∂y
∂ψ
v=− (9.79)
∂x
Poisson equation for streamfunction:
∇2 ψ = −ω (9.80)
106
CFD Lab Manual - OpenFOAM 2406 107
vertices
(
(0 0 0) // 0 - bottom left
(1 0 0) // 1 - bottom right
(1 1 0) // 2 - top right
(0 1 0) // 3 - top left
(0 0 0.1) // 4 - back bottom left
(1 0 0.1) // 5 - back bottom right
(1 1 0.1) // 6 - back top right
(0 1 0.1) // 7 - back top left
);
blocks
(
hex (0 1 2 3 4 5 6 7) (80 80 1) simpleGrading (1 1 1)
);
edges () ;
boundary
(
movingWall
{
type wall ;
faces
(
(3 7 6 2) // Top wall
);
}
fixedWalls
{
type wall ;
faces
(
(0 4 7 3) // Left wall
(1 2 6 5) // Right wall
(0 1 5 4) // Bottom wall
);
}
frontAndBack
{
type empty ;
faces
CFD Lab Manual - OpenFOAM 2406 109
(
(0 3 2 1) // Front
(4 5 6 7) // Back
);
}
);
mergePatchPairs () ;
// Create fields
volScalarField psi
(
IOobject
(
" psi " ,
runTime . timeName () ,
mesh ,
IOobject :: MUST_READ ,
IOobject :: AUTO_WRITE
),
mesh
);
volScalarField omega
(
IOobject
(
" omega " ,
runTime . timeName () ,
mesh ,
CFD Lab Manual - OpenFOAM 2406 110
IOobject :: MUST_READ ,
IOobject :: AUTO_WRITE
),
mesh
);
volVectorField U
(
IOobject
(
"U",
runTime . timeName () ,
mesh ,
IOobject :: NO_READ ,
IOobject :: AUTO_WRITE
),
mesh ,
dimen sionedVe ctor (" U " , dimVelocity , vector :: zero )
);
// Convergence criteria
scalar tolerance = 1e -6;
label maxIterations = 1000;
Info << " Starting vorticity - streamfunction solution " << endl ;
psiEqn . solve () ;
omegaEqn . solve () ;
// Check convergence
scalar omegaRes = gMax ( mag ( omega - omegaOld ) ) ;
scalar psiRes = gMax ( mag ( psi - psiOld ) ) ;
Info << " Vorticity residual : " << omegaRes << endl ;
Info << " Streamfunction residual : " << psiRes << endl ;
return 0;
}
void update Vorticit yBC ( volScalarField & omega , const volVectorField & U ,
const volScalarField & psi , const fvMesh & mesh )
{
// Update vorticity boundary conditions
const fvPatchList & patches = mesh . boundary () ;
{
// Stationary wall BC : omega = - d2psi / dn2
const scalarField & psiPatch = psi . boundaryField () [ patchI ];
const scalarField & psiInternal = psi . internalField () ;
dimensions [0 1 -1 0 0 0 0];
internalField uniform (0 0 0) ;
boundaryField
{
movingWall
{
type fixedValue ;
value uniform (1 0 0) ; // Lid velocity
}
fixedWalls
{
type noSlip ;
}
frontAndBack
{
type empty ;
}
}
Create 0/psi:
FoamFile
{
version 2.0;
format ascii ;
class volScalarField ;
object psi ;
}
CFD Lab Manual - OpenFOAM 2406 113
dimensions [0 2 -1 0 0 0 0];
internalField uniform 0;
boundaryField
{
movingWall
{
type fixedValue ;
value uniform 0;
}
fixedWalls
{
type fixedValue ;
value uniform 0;
}
frontAndBack
{
type empty ;
}
}
Create 0/omega:
FoamFile
{
version 2.0;
format ascii ;
class volScalarField ;
object omega ;
}
dimensions [0 0 -1 0 0 0 0];
internalField uniform 0;
boundaryField
{
movingWall
{
type calculated ;
value uniform 0;
}
fixedWalls
{
type calculated ;
value uniform 0;
}
frontAndBack
{
type empty ;
}
}
CFD Lab Manual - OpenFOAM 2406 114
dimensions [0 2 -2 0 0 0 0];
internalField uniform 0;
boundaryField
{
movingWall
{
type zeroGradient ;
}
fixedWalls
{
type zeroGradient ;
}
frontAndBack
{
type empty ;
}
}
application icoFoam ; // or v o r t i c i t y S t r e a m F u n c t i o n S o l v e r
startFrom startTime ;
startTime 0;
stopAt endTime ;
endTime 10;
deltaT 0.01;
writeControl runTime ;
writeInterval 0.5;
writeFormat ascii ;
writePrecision 8;
writeCompression off ;
CFD Lab Manual - OpenFOAM 2406 115
timeFormat general ;
timePrecision 6;
runTi meModifi able true ;
functions
{
vorticity
{
type vorticity ;
libs (" l i b f i e l d F u n c t i o n O b j e c t s . so ") ;
writeControl writeTime ;
writeInterval 1;
}
streamFunction
{
type streamFunction ;
libs (" l i b f i e l d F u n c t i o n O b j e c t s . so ") ;
writeControl writeTime ;
writeInterval 1;
}
forces
{
type forces ;
libs (" libforces . so ") ;
writeControl timeStep ;
writeInterval 50;
patches ( movingWall fixedWalls ) ;
rho rhoInf ;
rhoInf 1;
CofR (0.5 0.5 0) ;
}
probes
{
type probes ;
libs (" libsampling . so ") ;
writeControl timeStep ;
writeInterval 10;
fields ( U p vorticity ) ;
probeLocations
(
(0.5 0.5 0.05) // Center
(0.75 0.75 0.05) // Primary vortex core
(0.9 0.1 0.05) // Bottom right corner
(0.1 0.9 0.05) // Top left corner
);
}
centerlineData
{
type sets ;
libs (" libsampling . so ") ;
writeControl writeTime ;
writeInterval 1;
i nt e rp o l at i on S c he m e cellPoint ;
setFormat raw ;
CFD Lab Manual - OpenFOAM 2406 116
sets
(
h o r i z o n t a l C en t e r l i n e
{
type uniform ;
axis x;
start (0 0.5 0.05) ;
end (1 0.5 0.05) ;
nPoints 81;
}
ve rt ic alC en te rli ne
{
type uniform ;
axis y;
start (0.5 0 0.05) ;
end (0.5 1 0.05) ;
nPoints 81;
}
);
fields ( U vorticity ) ;
}
}
transportModel Newtonian ;
nu [0 2 -1 0 0 0 0] 0.001; // Re = 1000 for L =0.1 m , U =1 m /
s
ddtSchemes
{
default Euler ;
}
CFD Lab Manual - OpenFOAM 2406 117
gradSchemes
{
default Gauss linear ;
}
divSchemes
{
default none ;
div ( phi , U ) Gauss linearUpwind grad ( U ) ;
div ( phi , omega ) Gauss linearUpwind grad ( omega ) ;
}
laplacianSchemes
{
default Gauss linear orthogonal ;
}
i n t e r p o l a t i on S c h e m e s
{
default linear ;
}
snGradSchemes
{
default orthogonal ;
}
solvers
{
p
{
solver GAMG ;
tolerance 1e -06;
relTol 0.05;
smoother GaussSeidel ;
}
pFinal
{
$p ;
relTol 0;
}
solver GAMG ;
tolerance 1e -08;
relTol 0.01;
smoother GaussSeidel ;
}
U
{
solver smoothSolver ;
smoother symGaussSeidel ;
tolerance 1e -05;
relTol 0.1;
}
UFinal
{
$U ;
relTol 0;
}
}
PISO
{
nCorrectors 2;
n N o n O r t h o g o n a l C o r r e c t o r s 0;
pRefCell 0;
pRefValue 0;
}
# Save results
mkdir res ults_pri mitive
cp -r [0 -9]* re sults_pr imitive /
# Save results
mkdir res ults_vor ticity
cp -r [0 -9]* re sults_vo rticity /
def lo a d _b e nc h m ar k _d a ta () :
""" Load Ghia et al . (1982) benchmark data for Re =1000"""
def an a l yz e _c a v it y _f l ow ( results_dir ) :
""" Analyze cavity flow results and compare with benchmark """
CFD Lab Manual - OpenFOAM 2406 120
plt . subplot (1 , 3 , 3)
plt . semilogx ( Re_values , x_primary , ’bo - ’ , label = ’x - center ’)
plt . semilogx ( Re_values , y_primary , ’ro - ’ , label = ’y - center ’)
plt . xlabel ( ’ Reynolds Number ’)
plt . ylabel ( ’ Vortex Center Location ’)
plt . title ( ’ Primary Vortex Center vs Re ’)
plt . legend ()
plt . grid ( True )
plt . tight_layout ()
plt . savefig ( ’ c a v i t y _ b e n c h m a r k _ c o m p a r i s o n . png ’)
plt . show ()
def p l o t _ s t r e a m l i n e s _ v o r t i c i t y () :
""" Plot streamlines and vorticity contours """
# Streamlines
axes [0]. contour (X , Y , psi , levels =20 , colors = ’ blue ’)
axes [0]. set_xlabel ( ’ x /L ’)
axes [0]. set_ylabel ( ’ y /L ’)
axes [0]. set_title ( ’ Streamlines ’)
axes [0]. set_aspect ( ’ equal ’)
# Vorticity contours
im = axes [1]. contourf (X , Y , omega , levels =20 , cmap = ’ RdBu_r ’)
axes [1]. set_xlabel ( ’ x /L ’)
axes [1]. set_ylabel ( ’ y /L ’)
axes [1]. set_title ( ’ Vorticity Contours ’)
axes [1]. set_aspect ( ’ equal ’)
plt . colorbar ( im , ax = axes [1])
plt . tight_layout ()
plt . savefig ( ’ c a v i t y _ f l o w _ v i s u a l i z a t i o n . png ’)
plt . show ()
# Run analysis
if __name__ == " __main__ ":
a na l yz e _ ca v it y _ fl o w ( ’ results_primitive ’)
p l o t _ s t r e a m l i n e s _ v o r t i c i t y ()
9.5 Assignments
9.5.1 Assignment 1
Investigate the effect of Reynolds number (100, 1000, 5000) on flow patterns and identify
the formation of corner vortices.
9.5.2 Assignment 2
Compare vorticity-streamfunction results with primitive variable solutions using icoFoam.
Analyze computational efficiency and accuracy.
9.5.3 Assignment 3
Extend the analysis to 3D lid-driven cavity and study the development of three-dimensional
instabilities at high Reynolds numbers.
Experiment 10: Turbulence Models for
Pipe Flow
10.1 Objective
Compare different turbulence models (k-ϵ, k-ω, SST) for pipe flow analysis using simpleFoam
at various Reynolds numbers and validate against experimental correlations.
10.2 Theory
Reynolds-averaged momentum equation:
∂ Ūi ∂ Ūi 1 ∂ p̄ ∂ 2 Ūi ∂u′i u′j
+ Ūj =− +ν 2 − (10.85)
∂t ∂xj ρ ∂xi ∂xj ∂xj
The Reynolds stress tensor requires closure models:
∂ Ūi ∂ Ūj 2
−u′i u′j = νt + − kδij (10.86)
∂xj ∂xi 3
123
CFD Lab Manual - OpenFOAM 2406 124
ϕ = F1 ϕ1 + (1 − F1 )ϕ2 (10.91)
Cross-diffusion term:
1 ∂k ∂ω
CDkω = 2(1 − F1 )σω2 (10.92)
ω ∂xj ∂xj
f = 0.316Re−0.25 (10.93)
FoamFile
{
version 2.0;
format ascii ;
class dictionary ;
object blockMeshDict ;
}
convertToMeters 0.001; // mm to m
// Pipe dimensions
diameter 20; // 20 mm diameter
radius 10; // 10 mm radius
length 500; // 500 mm length (25 diameters )
vertices
(
// Inlet face
(0 0 0) // 0 - centerline start
( $radius 0 0) // 1 - wall start
( $radius $y1 $z1 ) // 2 - wall start ( rotated )
(0 $y1 $z1 ) // 3 - centerline start ( rotated )
// Outlet face
( $length 0 0) // 4 - centerline end
(# calc " $length " $radius 0 0) // 5 - wall end
(# calc " $length " $radius $y1 $z1 ) // 6 - wall end ( rotated )
(# calc " $length " 0 $y1 $z1 ) // 7 - centerline end ( rotated )
);
blocks
(
hex (0 1 2 3 4 5 6 7) (250 20 1) simpleGrading (1 10 1) // Grading
toward wall
);
edges () ;
boundary
(
inlet
{
type patch ;
faces
(
(0 3 2 1)
);
}
outlet
{
CFD Lab Manual - OpenFOAM 2406 126
type patch ;
faces
(
(4 5 6 7)
);
}
wall
{
type wall ;
faces
(
(1 2 6 5)
);
}
centerline
{
type symmetryPlane ;
faces
(
(0 4 7 3)
);
}
wedgeFront
{
type wedge ;
faces
(
(0 1 5 4)
);
}
wedgeBack
{
type wedge ;
faces
(
(2 3 7 6)
);
}
);
mergePatchPairs () ;
dimensions [0 1 -1 0 0 0 0];
internalField uniform (5 0 0) ; // 5 m / s bulk velocity
boundaryField
{
inlet
{
type fixedValue ;
value uniform (5 0 0) ;
}
outlet
{
type zeroGradient ;
}
wall
{
type noSlip ;
}
centerline
{
type symmetryPlane ;
}
wedgeFront
{
type wedge ;
}
wedgeBack
{
type wedge ;
}
}
dimensions [0 2 -2 0 0 0 0];
internalField uniform 0;
boundaryField
{
inlet
{
CFD Lab Manual - OpenFOAM 2406 128
type zeroGradient ;
}
outlet
{
type fixedValue ;
value uniform 0;
}
wall
{
type zeroGradient ;
}
centerline
{
type symmetryPlane ;
}
wedgeFront
{
type wedge ;
}
wedgeBack
{
type wedge ;
}
}
dimensions [0 2 -2 0 0 0 0];
boundaryField
{
inlet
{
type fixedValue ;
value uniform 0.09375;
}
CFD Lab Manual - OpenFOAM 2406 129
outlet
{
type zeroGradient ;
}
wall
{
type kqRWallFunction ;
value uniform 0.09375;
}
centerline
{
type symmetryPlane ;
}
wedgeFront
{
type wedge ;
}
wedgeBack
{
type wedge ;
}
}
Create 0/epsilon:
FoamFile
{
version 2.0;
format ascii ;
class volScalarField ;
object epsilon ;
}
dimensions [0 2 -3 0 0 0 0];
boundaryField
{
inlet
{
type fixedValue ;
value uniform 0.206;
}
outlet
{
type zeroGradient ;
}
wall
CFD Lab Manual - OpenFOAM 2406 130
{
type ep s i lo n Wa l l Fu n ct i on ;
value uniform 0.206;
}
centerline
{
type symmetryPlane ;
}
wedgeFront
{
type wedge ;
}
wedgeBack
{
type wedge ;
}
}
dimensions [0 0 -1 0 0 0 0];
boundaryField
{
inlet
{
type fixedValue ;
value uniform 588;
}
outlet
{
type zeroGradient ;
}
wall
{
type ome gaWallFu nction ;
value uniform 588;
}
CFD Lab Manual - OpenFOAM 2406 131
centerline
{
type symmetryPlane ;
}
wedgeFront
{
type wedge ;
}
wedgeBack
{
type wedge ;
}
}
simulationType RAS ;
RAS
{
model kEpsilon ;
turbulence on ;
printCoeffs on ;
kEpsilonCoeffs
{
Cmu 0.09;
C1 1.44;
C2 1.92;
sigmaEps 1.3;
sigmaK 1.0;
}
}
Create constant/[Link]:
FoamFile
{
version 2.0;
format ascii ;
class dictionary ;
object mome ntumTran sport ;
}
simulationType RAS ;
CFD Lab Manual - OpenFOAM 2406 132
RAS
{
model kOmega ;
turbulence on ;
printCoeffs on ;
kOmegaCoeffs
{
betaStar 0.09;
gamma 5.0/9.0;
beta 0.075;
sigmaK 2.0;
sigmaOmega 2.0;
}
}
Create constant/[Link]:
FoamFile
{
version 2.0;
format ascii ;
class dictionary ;
object mome ntumTran sport ;
}
simulationType RAS ;
RAS
{
model kOmegaSST ;
turbulence on ;
printCoeffs on ;
kOmegaSSTCoeffs
{
alphaK1 0.85;
alphaK2 1.0;
alphaOmega1 0.5;
alphaOmega2 0.856;
beta1 0.075;
beta2 0.0828;
betaStar 0.09;
gamma1 5.0/9.0;
gamma2 0.44;
a1 0.31;
b1 1.0;
c1 10.0;
F3 no ;
}
}
FoamFile
{
version 2.0;
format ascii ;
class dictionary ;
object tr a ns p o rt P ro p e rt i es ;
}
transportModel Newtonian ;
application simpleFoam ;
startFrom startTime ;
startTime 0;
stopAt endTime ;
endTime 1000;
deltaT 1;
writeControl runTime ;
writeInterval 100;
writeFormat ascii ;
writePrecision 8;
writeCompression off ;
timeFormat general ;
timePrecision 6;
runTi meModifi able true ;
functions
{
wallShearStress
{
type wallShearStress ;
libs (" l i b f i e l d F u n c t i o n O b j e c t s . so ") ;
writeControl writeTime ;
writeInterval 1;
patches ( wall ) ;
}
yPlus
{
type yPlus ;
libs (" l i b f i e l d F u n c t i o n O b j e c t s . so ") ;
writeControl writeTime ;
CFD Lab Manual - OpenFOAM 2406 134
writeInterval 1;
patches ( wall ) ;
}
pressureDrop
{
type sur faceFiel dValue ;
libs (" l i b f i e l d F u n c t i o n O b j e c t s . so ") ;
writeControl timeStep ;
writeInterval 10;
fields (p);
operation areaAverage ;
regionType patch ;
name inlet ;
}
velocityProfile
{
type sets ;
libs (" libsampling . so ") ;
writeControl writeTime ;
writeInterval 1;
i nt e rp o l at i on S c he m e cellPoint ;
setFormat raw ;
sets
(
radialProfile
{
type uniform ;
axis y;
start (0.4 0 0) ; // 40 cm downstream
end (0.4 0.01 0) ; // Pipe radius
nPoints 50;
}
);
fields ( U k epsilon omega yPlus wallShearStress ) ;
}
frictionFactor
{
type coded ;
libs (" l i b u t i l i t y F u n c t i o n O b j e c t s . so ") ;
name frictionFactor ;
writeControl timeStep ;
writeInterval 50;
code
#{
// Calculate friction factor
const fvMesh & mesh = time () . lookupObject < fvMesh >(" region0 ")
;
const volScalarField & p = mesh . lookupObject < volScalarField
>(" p ") ;
scalar f = 2 * dp * D / ( L * rho * U * U ) ;
solvers
{
p
{
solver GAMG ;
tolerance 1e -06;
relTol 0.1;
smoother GaussSeidel ;
}
tolerance 1e -05;
relTol 0.1;
}
}
SIMPLE
{
n N o n O r t h o g o n a l C o r r e c t o r s 0;
consistent yes ;
residualControl
{
p 1e -4;
U 1e -5;
"( k | epsilon | omega ) " 1e -5;
}
}
# Generate mesh
blockMesh
# Run simulation
simpleFoam > log . $model 2 >&1
# Save results
mkdir results_$model
cp -r [0 -9]* results_$model /
cp log . $model results_$model /
done
Execute:
chmod + x runAllModels . sh
./ runAllModels . sh
# Pipe parameters
D = 0.02 # Diameter ( m )
U = 5.0 # Velocity ( m / s )
# Update tr a ns p o rt P ro p e rt i es
with open ( ’ constant / transportProperties ’ , ’w ’) as f :
f . write (f ’ ’ ’ FoamFile
{{
version 2.0;
format ascii ;
class dictionary ;
object tr a ns p o rt P ro p e rt i es ;
}}
transportModel Newtonian ;
nu [0 2 -1 0 0 0 0] { nu :.2 e };
’ ’ ’)
# Clean case
subprocess . run ([ ’ rm ’ , ’-rf ’] + [ str ( i ) for i in range (1 , 10) ])
# Run simulation
result = subprocess . run ([ ’ simpleFoam ’] , capture_output = True , text =
True )
return friction_factor
def t h e o r e t i c a l _ f r i c t i o n _ f a c t o r ( Re ) :
""" Calculate theoretical friction factor """
if Re < 2300:
return 64 / Re # Laminar flow
elif Re < 1 e5 :
return 0.316 * Re **( -0.25) # Blasius equation
else :
# Colebrook - White ( approximation )
return 0.184 * Re **( -0.2)
def c o m p a r e _ t u r b u l e n c e _ m o d e l s () :
""" Compare different turbulence models """
# Theoretical curves
Re_theory = np . logspace (3 , 6 , 100)
f_laminar = 64 / Re_theory
f_blasius = 0.316 * Re_theory **( -0.25)
f_turbulent = 0.184 * Re_theory **( -0.2)
plt . tight_layout ()
plt . savefig ( ’ f r i c t i o n _ f a c t o r _ c o m p a r i s o n . png ’)
CFD Lab Manual - OpenFOAM 2406 139
plt . show ()
def p l o t _ v e l o c i t y _ p r o f i l e s () :
""" Plot velocity profiles for different turbulence models """
# Theoretical profiles
# Law of the wall : u + = (1/ kappa ) * ln ( y +) + B
# Power law : u / u_centerline = (1 - r / R ) ^(1/ n )
# Velocity profile
plt . subplot (1 , 2 , 1)
plt . plot ( u_power_law , r_normalized , ’k - ’ , linewidth =2 , label = ’1/7
Power Law ’)
plt . plot ( u_log_law , r_normalized , ’k - - ’ , label = ’ Log Law ’)
plt . xlabel ( ’ y + ’)
plt . ylabel ( ’ u + ’)
plt . title ( ’ Law of the Wall ’)
CFD Lab Manual - OpenFOAM 2406 140
plt . legend ()
plt . grid ( True , alpha =0.3)
plt . xlim (1 , 1000)
plt . ylim (0 , 30)
plt . tight_layout ()
plt . savefig ( ’ veloci ty_profi les . png ’)
plt . show ()
# Run analysis
if __name__ == " __main__ ":
c o m p a r e _ t u r b u l e n c e _ m o d e l s ()
p l o t _ v e l o c i t y _ p r o f i l e s ()
10.5 Assignments
10.5.1 Assignment 1
Compare predicted friction factors with Moody chart correlations for Reynolds numbers
ranging from 104 to 106 .
10.5.2 Assignment 2
Analyze near-wall treatment using different y+ values and evaluate the performance of
wall functions vs low-Re models.
10.5.3 Assignment 3
Investigate turbulence model performance for transitional flow regime (2000 < Re <
4000) and compare with DNS/experimental data.
Experiment 11: Convection-Diffusion
Transport Equation
11.1 Objective
Simulate generic convection-diffusion transport with forced and natural convection over
flat plate and in pipe using scalarTransportFoam and analyze numerical schemes.
11.2 Theory
General transport equation for scalar quantity ϕ:
∂ϕ
+ ∇ · (Uϕ) = ∇ · (Γ∇ϕ) + Sϕ (11.97)
∂t
where: - ϕ = transported scalar (concentration, temperature, etc.) - U = velocity
field - Γ = diffusion coefficient - Sϕ = source term
Peclet number (ratio of convection to diffusion):
UL
Pe = = Re · Sc (11.98)
D
where Sc = ν/D is Schmidt number (momentum to mass diffusivity ratio).
For heat transfer: P r = ν/α (Prandtl number)
ϕP + ϕN
ϕf = (11.109)
2
High-resolution schemes (TVD): - Linear upwind - QUICK - MUSCL
cd $FOAM_RUN
mkdir c on v ec t io n D if f us i o n
cd co n ve c ti o n Di f fu s i on
mkdir flatPlate pipeFlow
cd flatPlate
mkdir 0 constant system
FoamFile
{
version 2.0;
format ascii ;
class dictionary ;
object blockMeshDict ;
}
convertToMeters 0.01; // cm to m
vertices
(
// Leading edge region
(0 0 0) // 0 - plate start
(0 2 0) // 1 - far field top
( -2 2 0) // 2 - upstream top
( -2 0 0) // 3 - upstream start
// Z - direction (2 D case )
(0 0 0.1) // 6
(0 2 0.1) // 7
( -2 2 0.1) // 8
( -2 0 0.1) // 9
(10 0 0.1) // 10
(10 2 0.1) // 11
);
blocks
(
// Upstream block
hex (3 0 1 2 9 6 7 8) upstream (20 40 1) simpleGrading (1 10 1)
edges () ;
boundary
(
inlet
{
type patch ;
faces
(
(3 2 8 9)
);
}
outlet
{
type patch ;
faces
CFD Lab Manual - OpenFOAM 2406 144
(
(4 5 11 10)
);
}
top
{
type patch ;
faces
(
(2 1 7 8)
(1 5 11 7)
);
}
plate
{
type wall ;
faces
(
(0 4 10 6)
);
}
upstream
{
type symmetryPlane ;
faces
(
(3 0 6 9)
);
}
frontAndBack
{
type empty ;
faces
(
(3 9 8 2)
(2 8 7 1)
(0 1 7 6)
(0 6 10 4)
(4 10 11 5)
(1 5 11 7)
);
}
);
mergePatchPairs () ;
Velocity Field
Create 0/U:
FoamFile
{
version 2.0;
CFD Lab Manual - OpenFOAM 2406 145
format ascii ;
class volVectorField ;
object U;
}
dimensions [0 1 -1 0 0 0 0];
internalField uniform (2 0 0) ; // 2 m / s freestream
boundaryField
{
inlet
{
type fixedValue ;
value uniform (2 0 0) ;
}
outlet
{
type zeroGradient ;
}
top
{
type fixedValue ;
value uniform (2 0 0) ;
}
plate
{
type noSlip ;
}
upstream
{
type symmetryPlane ;
}
frontAndBack
{
type empty ;
}
}
Temperature/Scalar Field
Create 0/T:
FoamFile
{
version 2.0;
format ascii ;
class volScalarField ;
object T;
}
dimensions [0 0 0 1 0 0 0];
internalField uniform 293; // 20 C ambient
CFD Lab Manual - OpenFOAM 2406 146
boundaryField
{
inlet
{
type fixedValue ;
value uniform 293;
}
outlet
{
type zeroGradient ;
}
top
{
type fixedValue ;
value uniform 293;
}
plate
{
type fixedValue ;
value uniform 373; // 100 C heated plate
}
upstream
{
type symmetryPlane ;
}
frontAndBack
{
type empty ;
}
}
Transport Properties
Create constant/transportProperties:
FoamFile
{
version 2.0;
format ascii ;
class dictionary ;
object tr a ns p o rt P ro p e rt i es ;
}
transportModel Newtonian ;
nu [0 2 -1 0 0 0 0] 1.5 e -05; // Air kinematic viscosity
DT [0 2 -1 0 0 0 0] 2.2 e -05; // Thermal diffusivity ( Pr =
0.7)
application s c al a rT r a ns p or t F oa m ;
startFrom startTime ;
startTime 0;
stopAt endTime ;
endTime 10;
deltaT 0.001;
writeControl runTime ;
writeInterval 0.5;
writeFormat ascii ;
writePrecision 8;
writeCompression off ;
timeFormat general ;
timePrecision 6;
runTi meModifi able true ;
functions
{
heatFlux
{
type sur faceFiel dValue ;
libs (" l i b f i e l d F u n c t i o n O b j e c t s . so ") ;
writeControl timeStep ;
writeInterval 50;
fields (T);
operation sum ;
regionType patch ;
name plate ;
surfaceFormat none ;
nusseltNumber
{
type coded ;
libs (" l i b u t i l i t y F u n c t i o n O b j e c t s . so ") ;
name nusseltNumber ;
writeControl timeStep ;
writeInterval 50;
code
#{
const fvMesh & mesh = time () . lookupObject < fvMesh >(" region0 ")
;
const volScalarField & T = mesh . lookupObject < volScalarField
>(" T ") ;
// Average values
scalar h_avg = gSum ( h * platePatch . magSf () ) / gSum (
platePatch . magSf () ) ;
scalar Nu_avg = h_avg * L / k ;
Info << " Average heat transfer coefficient : " << h_avg << "
W / $m ^2 $K " << endl ;
Info << " Average Nusselt number : " << Nu_avg << endl ;
// Theoretical correlation
scalar Re = 2.0 * L / 1.5 e -05; // Reynolds number
scalar Pr = 0.7; // Prandtl number
scalar Nu_theory = 0.664 * pow ( Re , 0.5) * pow ( Pr , 1.0/3.0) ;
Info << " Theoretical Nusselt number : " << Nu_theory << endl
;
Info << " Error : " << mag ( Nu_avg - Nu_theory ) / Nu_theory *
100 << "%" << endl ;
#};
}
te mp er atu re Pr ofi le
CFD Lab Manual - OpenFOAM 2406 149
{
type sets ;
libs (" libsampling . so ") ;
writeControl writeTime ;
writeInterval 1;
i nt e rp o l at i on S c he m e cellPoint ;
setFormat raw ;
sets
(
x_05cm
{
type uniform ;
axis y;
start (0.005 0 0.05) ;
end (0.005 0.02 0.05) ;
nPoints 40;
}
x_2cm
{
type uniform ;
axis y;
start (0.02 0 0.05) ;
end (0.02 0.02 0.05) ;
nPoints 40;
}
x_5cm
{
type uniform ;
axis y;
start (0.05 0 0.05) ;
end (0.05 0.02 0.05) ;
nPoints 40;
}
);
fields ( T U ) ;
}
}
cd ../ pipeFlow
mkdir 0 constant system
Copy pipe mesh from Experiment 10 and modify for heat transfer:
Create 0/T:
FoamFile
{
version 2.0;
format ascii ;
CFD Lab Manual - OpenFOAM 2406 150
class volScalarField ;
object T;
}
dimensions [0 0 0 1 0 0 0];
internalField uniform 293; // Cold inlet
boundaryField
{
inlet
{
type fixedValue ;
value uniform 293; // 20 C inlet
}
outlet
{
type zeroGradient ;
}
wall
{
type fixedValue ;
value uniform 373; // 100 C heated wall
}
centerline
{
type symmetryPlane ;
}
wedgeFront
{
type wedge ;
}
wedgeBack
{
type wedge ;
}
}
format ascii ;
class dictionary ;
object blockMeshDict ;
}
convertToMeters 0.01; // cm to m
vertices
(
(0 0 0) // 0 - plate bottom
(10 0 0) // 1 - domain width (10 cm )
(10 20 0) // 2 - domain top (20 cm height )
(0 20 0) // 3 - plate top
(0 0 0.1) // 4 - back face
(10 0 0.1) // 5
(10 20 0.1) // 6
(0 20 0.1) // 7
);
blocks
(
hex (0 1 2 3 4 5 6 7) (50 100 1) simpleGrading (5 1 1) // Grading
toward plate
);
edges () ;
boundary
(
plate
{
type wall ;
faces
(
(0 3 7 4)
);
}
right
{
type patch ;
faces
(
(1 2 6 5)
);
}
top
{
type patch ;
faces
(
(3 2 6 7)
);
}
bottom
{
CFD Lab Manual - OpenFOAM 2406 152
type patch ;
faces
(
(0 1 5 4)
);
}
frontAndBack
{
type empty ;
faces
(
(0 4 5 1)
(3 2 6 7)
);
}
);
ddtSchemes
{
default Euler ;
}
gradSchemes
{
default Gauss linear ;
}
divSchemes
{
default none ;
div ( phi , T ) Gauss upwind ; // First - order upwind
}
laplacianSchemes
{
default Gauss linear orthogonal ;
}
i n t e r p o l a t i on S c h e m e s
{
default linear ;
}
CFD Lab Manual - OpenFOAM 2406 153
snGradSchemes
{
default orthogonal ;
}
Create system/[Link]:
divSchemes
{
default none ;
div ( phi , T ) Gauss linearUpwind grad ( T ) ; // Second - order upwind
}
Create system/[Link]:
divSchemes
{
default none ;
div ( phi , T ) Gauss linear ; // Central differencing
}
transportModel Newtonian ;
nu [0 2 -1 0 0 0 0] 1.5 e -05;
DT [0 2 -1 0 0 0 0] { D :.2 e };
’ ’ ’)
# Run simulation
subprocess . run ([ ’ scalarTransportFoam ’] , capture_output = True )
def p l o t _ s c h e m e _ c o m p a r i s o n () :
""" Compare numerical schemes for different Peclet numbers """
# Numerical diffusion
plt . subplot (1 , 3 , 1)
for scheme in schemes :
# Theoretical numerical diffusion coefficients
if scheme == ’ upwind ’:
num_diff = 0.5 * Pe_values / ( Pe_values + 2)
elif scheme == ’ linearUpwind ’:
num_diff = 0.125 * Pe_values / ( Pe_values + 8)
else : # central
num_diff = np . zeros_like ( Pe_values )
# Stability diagram
plt . subplot (1 , 3 , 2)
Pe_crit = np . array ([2 , 8 , 2]) # Critical Pe for each scheme
stability = [ ’ Stable ’ , ’ Conditionally Stable ’ , ’ Unstable ’]
colors = [ ’ green ’ , ’ orange ’ , ’red ’]
# Accuracy comparison
plt . subplot (1 , 3 , 3)
# Placeholder data for accuracy
for scheme in schemes :
if scheme == ’ upwind ’:
accuracy = 1 / Pe_values # First - order
elif scheme == ’ linearUpwind ’:
accuracy = 1 / Pe_values **2 # Second - order
CFD Lab Manual - OpenFOAM 2406 155
else : # central
accuracy = 1 / Pe_values **2 * np . where ( Pe_values < 2 , 1 , np
. inf )
plt . tight_layout ()
plt . savefig ( ’ n u m e r i c a l _ s c h e m e s _ c o m p a r i s o n . png ’)
plt . show ()
def v a l i d a t e _ h e a t _ t r a n s f e r () :
""" Validate heat transfer correlations """
# Theoretical correlations
Re_theory = np . logspace (3 , 6 , 100)
Pr = 0.7
# Laminar
Nu_laminar = 0.664 * Re_theory **0.5 * Pr **(1/3)
# Turbulent
Nu_turbulent = 0.037 * Re_theory **0.8 * Pr **(1/3)
plt . tight_layout ()
plt . savefig ( ’ h e a t _ t r a n s f e r _ v a l i d a t i o n . png ’)
plt . show ()
CFD Lab Manual - OpenFOAM 2406 156
# Run analysis
if __name__ == " __main__ ":
p l o t _ s c h e m e _ c o m p a r i s o n ()
v a l i d a t e _ h e a t _ t r a n s f e r ()
11.5 Assignments
11.5.1 Assignment 1
Analyze the effect of Prandtl number (0.1, 0.7, 7.0) on thermal boundary layer develop-
ment and heat transfer coefficients.
11.5.2 Assignment 2
Investigate numerical schemes (upwind, central, bounded) for different Peclet numbers
and analyze numerical diffusion effects.
11.5.3 Assignment 3
Extend to natural convection over vertical plate and compare with Churchill-Chu corre-
lations for different Rayleigh numbers.