Rudolf Žitný, Ústav procesní a zpracovatelské techniky ČVUT FS 2010

57
Remark: foils with „black background“ could be skipped, they are aimed to the more advanced courses Rudolf Žitný, Ústav procesní a zpracovatelské techniky ČVUT FS 2010 Solvers, schemes SIMPLEx, upwind,… Computer Fluid Dynamics E181107 CFD7 2181106

description

Computer Fluid Dynamics E181107. 2181106. CFD7. Solvers, schemes SIMPLEx, upwind,…. Remark : fo i l s with „ black background “ could be skipped, they are aimed to the more advanced courses. Rudolf Žitný, Ústav procesní a zpracovatelské techniky ČVUT FS 2010. FINITE VO LUME METHOD. CFD7. - PowerPoint PPT Presentation

Transcript of Rudolf Žitný, Ústav procesní a zpracovatelské techniky ČVUT FS 2010

Page 1: Rudolf Žitný, Ústav procesní a zpracovatelské techniky ČVUT FS 2010

Remark: foils with „black background“ could be skipped, they are aimed to the more advanced courses

Rudolf Žitný, Ústav procesní a zpracovatelské techniky ČVUT FS 2010

Solvers, schemes SIMPLEx, upwind,…

Computer Fluid Dynamics E181107CFD7

2181106

Page 2: Rudolf Žitný, Ústav procesní a zpracovatelské techniky ČVUT FS 2010

FINITE VOLUME METHODCFD7

Principle of the Finite Volume Method is in application of Gauss theorem upon integral of the solved transport equation.

Thus the volumetric integral inside the fluid element is replaced by surface integral, evaluated as the sum of integrals at faces of the fluid element.

faces of fluid elementFLUID element

CV A

dV n dA

Page 3: Rudolf Žitný, Ústav procesní a zpracovatelské techniky ČVUT FS 2010

FINITE VOLUME METHODCFD7

x

x

y

z

zSouthWest

Top

E

North

Bottom

x

y

FINITE CONTROL VOLUME x = Fluid element dx

Finite size Infinitely small size

Page 4: Rudolf Žitný, Ústav procesní a zpracovatelské techniky ČVUT FS 2010

FVM diffusion problem 1DCFD7

CV - control volume

A – surface of CV

[ ( ) ] 0

( ) 0

CV

A CV

S dV

n dA S dV

Gauss theorem

1D case ( ) 0 ( ) ( )A B

d dS A B

dx dx

A W P E B

w e

|2

P E E Pe e

PE

d

dx x

|2

P W P Ww w

WP

d

dx x

Diffusive flux

Page 5: Rudolf Žitný, Ústav procesní a zpracovatelské techniky ČVUT FS 2010

FVM diffusion problem 1DCFD7

( ) 0A CV

n dA S dV

( ) ( ) 0

0

( ) ( ) ( )

e w

P WE Pe e w w U P P

PE WP

e e w w w w e eP P W E U

PE WP WP PE

d dA A S V

dx dx

A A S Sx x

A A A AS S

x x x x

aPaW

aE

Check properties

aP = aW+aE for S=0 (without sources)

All coefficients are positive

Overall flux from the west side

Linearization of source term

Page 6: Rudolf Žitný, Ústav procesní a zpracovatelské techniky ČVUT FS 2010

Tutorial – sphere dryingCFD7

W P E

0P WE Pe e w w

PE WP

T TT Tr k r k

x x

e eA r2

02

202

1( ) 0 | 0 | ( ( ))

1( ) 0 | 0 | ( ( ))

wr r R o

w w wr r R e w

dd dT dT dTr k k T T R hD

r dr dr dr dr drd d dd

r D k Rr dr dr dr dr

Heat transfer from air at temperature To

Enthalpy of evaporation

Diffusion coefficientMass transfer

coefficient

x x/2

W P R

Internal control volumes

( ) 0P Wo R w w

WP

T TR T T r k

x

TR temperature at surface of sphere must be extrapolated (using TW and TP)

Page 7: Rudolf Žitný, Ústav procesní a zpracovatelské techniky ČVUT FS 2010

FVM diffusion problem 2DCFD7

, ,....

P P W W E E N N S S U

w w e eW E

WP PE

P W E N S P

a a a a a S

A Aa a

x x

a a a a a S

( ) ( ) 0Sx x y y

W P E

N

S

A

Boundary conditions

( )

|

| ( ( ) )

A

A A

A e

A

qx

k Ax

First kind (Dirichlet BC)

Second kind (Neumann BC)

Third kind (Newton’s BC)

Example: insulation q=0

Example: Finite thermal resistance (heat transfer

coefficient )

Page 8: Rudolf Žitný, Ústav procesní a zpracovatelské techniky ČVUT FS 2010

FVM convection diffusion 1DCFD7

CV - control volume

A – surface of CV

( ) [ ( ) ]

( ) ( )

CV CV

A A CV

u dV S dV

n u dA n dA S dV

Gauss theorem

1D case ( ) ( )d d d

u Sdx dx dx

A W P E B

w e

( ) ee e e

PE

F u Dx

( ) ww w w

WP

F u Dx

( ) ( )e w e E Pe w w P W U P PF F D D S S

Page 9: Rudolf Žitný, Ústav procesní a zpracovatelské techniky ČVUT FS 2010

FVM convection diffusion 1DCFD7

Relative importance of convective transport is characterised by Peclet number of cell (of control volume, because Pe depends upon size of cell)

w ew e

WP PE

D Dx x

( ) ( ) w w e eF u F u F-mass flux (through faces A)

D-diffusion conductanceContinuity equation (mass flowrate conservation) Fe=Fw

2

3

Re [ . ]

Re Pr [ ]/

Re [ ]

p p

m ABAB

u x F kgPe Pa s

D m s

u x k W kg K kgPe

k c c m K J m s

u x kg m kgPe Sc D

D m s m s

Prandtl

Schmidt

Binary diffusion coef

Thermal conductivity F

PeD

Page 10: Rudolf Žitný, Ústav procesní a zpracovatelské techniky ČVUT FS 2010

FVM convection diffusion 1DCFD7

Methods differ in the way how the unknown transported values at the control

volume faces (w , e) are calculated (different interpolation techniques)

Result can be always expressed in the form

Properties of resulting schemes should be evaluated

Conservativeness

Boundedness (positivity of coefficients)

Transportivity (schemes should depend upon the Peclet number of cell)

P P nb nbneighbours

a a

Page 11: Rudolf Žitný, Ústav procesní a zpracovatelské techniky ČVUT FS 2010

FVM central scheme 1DCFD7

Conservativeness (yes)

Boundedness (positivity of coefficients)

Transportivness (no)

2 2

P P W W E E

w eW w E e

a a a

F Fa D a D

1 1( ) ( )

2 2e P E w P W

| |2e

ee

FPe

D

Very fine mesh is necessary

Page 12: Rudolf Žitný, Ústav procesní a zpracovatelské techniky ČVUT FS 2010

FVM upwind 1st order 1DCFD7

Conservativeness (yes)

Boundedness (positivity of coefficients) YES for any Pe

Transportivness (YES)

max ,0 max ,0P P W W E E

W w w E e e

a a a

a D F a D F

for flow direction to right 0 else

for 0 else e P e e E

w P w w W

F

F

But at a prize of decreased order of accuracy (only 1st

order!!)

Page 13: Rudolf Žitný, Ústav procesní a zpracovatelské techniky ČVUT FS 2010

FVM Upwind FLUENTCFD7

= V A

dV dA

0

1f

fA

f

ff AV

1

)(2

110 f

Upwind of the first order

Upwind of the second order0f s

0 f

Page 14: Rudolf Žitný, Ústav procesní a zpracovatelské techniky ČVUT FS 2010

FVM hybrid upwind Spalding 1972 1DCFD7

Conservativeness (yes)

Boundedness (positivity of coefficients) YES for any Pe

Transportivness (YES)

max , ,0 max , ,02 2

P P W W E E

w eW w w E e e

a a a

F Fa F D a F D

But at a prize of decreased order of accuracy at high

Pe

Central scheme for Pe<2

Upwind with diffusion supressed for Pe>2

Page 15: Rudolf Žitný, Ústav procesní a zpracovatelské techniky ČVUT FS 2010

FVM power law Patankar 1980 1DCFD7

Conservativeness (yes)

Boundedness (positivity of coefficients) YES for any Pe

Transportivness (YES)

5

5

max (1 ) ,0 max( ,0) 10

max (1 ) ,0 max( ,0)10

P P W W E E

wW w w

eE e e

a a a

Pea D F

Pea D F

Polynomial flow for Pe<10

Upwind with zero diffusion for Pe>10

5(1 ) 110 2

Pe Pe

Page 16: Rudolf Žitný, Ústav procesní a zpracovatelské techniky ČVUT FS 2010

FVM QUICK Leonard 1979 1DCFD7

Third order of accuracy very low numerical diffusion comparing with other schemes

Scheme is not bounded (stability problems are frequently encountered)

3 3+ ( +1) (1 )- (2- )

8 8 8 8

(1 ) 8 8

P P W W E E WW WW EE EE

e w w wW e w w E w e e

w eWW w EE e

a a a a a

F F F Fa D a D

F Fa a

Quadratic Upwind Interpolation – more nodal points necessary

WW W P E EE

w e

e=1 for Fe>0 else e=0. w=1 for Fw>0 else w=0.

Page 17: Rudolf Žitný, Ústav procesní a zpracovatelské techniky ČVUT FS 2010

FVM exponential Patankar 1980 1DCFD7

Conservativeness (yes)

Boundedness (positivity of coefficients) YES for any Pe

Transportivness (YES)

/2 /2

/2 /2 /2 /2

P P W W E E

Pe Pe

W EPe Pe Pe Pe

a a a

e ea a

e e e e

Exact solution for constant velocity and diffusion coefficient

FPe

D

Page 18: Rudolf Žitný, Ústav procesní a zpracovatelské techniky ČVUT FS 2010

FVM exponential FLUENTCFD7

For Pe<<1 the exponential profile is reduced to linear profile

0

1 0

( ) 1=

1

rPe

L

Pe

r e

e

Exact solution of )()(rr

vr r

LvPe r

r

0

1

Projection of velocity to the direction r

Called power law model in Fluent

Page 19: Rudolf Žitný, Ústav procesní a zpracovatelské techniky ČVUT FS 2010

FVM exponential proofCFD7

1 1 2 1( )x

PexF x

c c c e cx x x F x Pe x

2 1

2 1

PeE

PeW

c e c

c e c

Exact solution for constant velocity and diffusion coefficient

Assume constant mass flux F and constant Pe=F/D.

1

2

Pe PeE W

Pe Pe

E WPe Pe

e ec

e e

ce e

(1 ) (1 )Pe Pe Pe PeE W E W E W

P Pe Pe Pe Pe Pe Pe

e e e e

e e e e e e

/2 /2 /2 /2

/2 /2 /2 /2 /2 /2

/2

/2 /2

1 ( )

( )( )

Pe Pe Pe Pe Pe

E Pe Pe Pe Pe Pe Pe Pe Pe

Pe

W Pe Pe

e e e e ea

e e e e e e e e

ea

e e

Analytical solution

Boundary condition

s

Identified constants

Exact solution at central point

Page 20: Rudolf Žitný, Ústav procesní a zpracovatelské techniky ČVUT FS 2010

FVM central scheme with modified viscosityCFD7

Almost any scheme (with the exception of QUICK) can be converted to central scheme introducing modified transport coefficient

Modified diffusion conductances are

and

.

* * 2 2w e

P P W W E E

w eW E

a a a

F Fa D a D

*** * e

w e

w

WP PE

D Dx x

*

*

*

1

| |1

2

/ 2

tanh / 2

Pe

Pe

Pe

Central scheme

Upwind scheme

Exponential scheme

Page 21: Rudolf Žitný, Ústav procesní a zpracovatelské techniky ČVUT FS 2010

There are two basic errors caused by approximation of convective terms

False diffusion (or numerical diffusion) – artificial smearing of jumps, discontinuities. Neglected terms in the Taylor series expansion of first derivatives (convective terms) represent in fact the terms with second derivatives (diffusion terms). So when using low order formula for convection terms (for example upwind of the first order), their inaccuracy is manifested by the artificial increase of diffusive terms (e.g. by increase of viscosity). The false diffusion effect is important first of all in the case when the flow direction is not aligned with mesh, see example

Dispersion (or aliasing) – causing overshoots, artificial oscillations. Dispersion means that different components of Fourier expansion (of numerical solution) move with different velocities, for example shorter wavelengths move slower than the velocity of flow.

FVM dispersion / diffusionCFD7

0 - boundary condition, all

values are zero in the right triangle (without diffusion)

1Numerical diffusion

Numerical dispersion

Page 22: Rudolf Žitný, Ústav procesní a zpracovatelské techniky ČVUT FS 2010

FVM unstructural mesh generationCFD7

i

j

Voronoi control volume associated with node i. Set of points x,y having distance to i less than the distance to any other node j.

Voronoi polygons

Delaunay triangulation each side of Voronoi polygon has a node associated with the node i and these nodes are vertices of Delaunay triangles

Property of Delaunay triangles: Circumcenter

remains inside the

Delaunay triangle

Finite Volume Method

Finite Element Method

Page 23: Rudolf Žitný, Ústav procesní a zpracovatelské techniky ČVUT FS 2010

FVM structural mesh generationCFD7

0

1

0

1

0

1

0

1

0X 0Y

Laplace equation solvers

Page 24: Rudolf Žitný, Ústav procesní a zpracovatelské techniky ČVUT FS 2010

FVM Navier Stokes equationsCFD7

Beckman

Different methods are used for numerical solution of Navier Stokes equations at

Compressible flows (finite speed of sound, existence of velocity discontinuities at shocks)

Incompressible flows (infinite speed of sound)

Explicit methods (e.g. MacCormax) but also implicit methods (Beam-Warming scheme) are used. These methods will not be discussed here.

Vorticity and stream function methods (pressure is eliminated from NS equations). These methods are suitable especially for 2D flows.

Primitive variable approach (formulation in terms of velocities and pressure). Pressure represents a continuity equation constraint. Only these methods (pressure corrections methods SIMPLE, SIMPLER, SIMPLEC and PISO) using staggered and collocated grid will be discussed in this lecture.

Page 25: Rudolf Žitný, Ústav procesní a zpracovatelské techniky ČVUT FS 2010

FVM Navier Stokes equationsCFD7

2

2

( ) ( )

( ) ( )

0

u

v

u uv p u uS

x y x x x y y

uv v p v vS

x y y x x y y

u v

x y

Example: Steady state and 2D (velocities u,v and pressure p are unknown functions)

This is equation

for u

This is equation

for v

This is equation for

p? But pressure p is not in the continuity equation! Solution of this problem is in SIMPLE methods, described later

Page 26: Rudolf Žitný, Ústav procesní a zpracovatelské techniky ČVUT FS 2010

FVM checkerboard patternCFD7

10

10

10

10

10

10

10

10 10

1000

0

0

0

0

0

00 0

0

Other problem is called checkerboard pattern

This nonuniform distribution of pressure has no effect upon NS equations

The problem appears as soon as the u,v,p values are concentrated in the same control volume

W P E

2

( ) ( ) u

vS

x y x x x

u u up

y

u

y

10 10| 0

2 2E W

P

p pp

x x x

Page 27: Rudolf Žitný, Ústav procesní a zpracovatelské techniky ČVUT FS 2010

FVM staggered gridCFD7

10

10

10

10

10

10

10

10 10

1000

0

0

0

0

0

00 0

0

Different control volumes for different equations

Control volume for momentum balance

in y-direction

Control volume for momentum balance

in x-direction

Control volume for continuity equation,

temperature, concentrations

2

0 10

( ) ( ) u

p

u u u

x x

vS

x y x x x

p u

y y

Page 28: Rudolf Žitný, Ústav procesní a zpracovatelské techniky ČVUT FS 2010

FVM staggered gridCFD7

Location of velocities and pressure in staggered grid

I-2 I-1 I I+1 I+2i-1 i i+1 i+2

J+1

J

J-1

J-2

j+2

j+1

j

j-1

pu

v

Pressure I,J

U i,J

V I,j

Control volume for continuity equation,

temperature, concentrations

Control volume for momentum balance

in x-direction

Control volume for momentum

balance in y-direction

Page 29: Rudolf Žitný, Ústav procesní a zpracovatelské techniky ČVUT FS 2010

FVM continuity equationCFD7

I-2 I-1 I I+1 I+2i-1 i i+1 i+2

J+1

J

J-1

J-2

j+2

j+1

j

j-1

pu

v

Pressure I,J

U i,J

V I,j

Control volume for continuity equation,

temperature, concentrations

, 1 ,1, , 0I j I ji J i J v vu u

x y

x

0u v

x y

Page 30: Rudolf Žitný, Ústav procesní a zpracovatelské techniky ČVUT FS 2010

FVM momentum xCFD7

I-2 I-1 I I+1 I+2i-1 i i+1 i+2

J+1

J

J-1

J-2

j+2

j+1

j

j-1

pu

Pressure I,J

U i,J

V I,j

p

Control volume for momentum balance

in x-direction

, , , 1, ,( )i J i J nb nb i J I J I J iJneighbours

a u a u A p p b

2

( ) ( ) u

vS

x y x x x

u u up

y

u

y

Page 31: Rudolf Žitný, Ústav procesní a zpracovatelské techniky ČVUT FS 2010

FVM momentum yCFD7

I-2 I-1 I I+1 I+2i-1 i i+1 i+2

J+1

J

J-1

J-2

j+2

j+1

j

j-1

p

v

Pressure I,J

U i,J

V I,j

Control volume for momentum balance

in y-direction

p

( ) ( ) v

uS

x y y x

v vv v

x y y

vp

, , , , 1 , ,( )I j I j nb nb I j I J I J I jneighbours

a v a v A p p b

Page 32: Rudolf Žitný, Ústav procesní a zpracovatelské techniky ČVUT FS 2010

FVM SIMPLE step 1 (velocities)CFD7

, , 1 ,

* * * *, , ,( )

I j nb I J I JI j nb I j I jneighbours

a v va A p p b

Input: Approximation of pressure p*

, 1, ,

* * * *, , ( )

i J nb I J I Ji J nb i J iJneighbours

a u Au a p p b

Page 33: Rudolf Žitný, Ústav procesní a zpracovatelské techniky ČVUT FS 2010

FVM SIMPLE step 2 (pressure correction)CFD7

* * *' ' 'p p p u u u v v v

' ' 'IJ IJ nb nb IJneighbours

a p a p b

, 1, ,

* * * *, , ( )

i J nb I J I Ji J nb i J iJneighbours

a u Au a p p b

, , , 1, ,( )i J i J nb nb i J I J I J iJ

neighbours

a u a u A p p b “true”

solution

, 1, ,

' ' ' ', , ( )

i J nb I J I Ji J nb i Jneighbours

a au u A p p

subtract Neglect!!

!

, 1, , , 1 ,

' ' ' ' ' ', , ,( ) ( )

i J I J I J I J I Ji J I j I jd p p d p pu v

Substitute u*+u’ and v*+v’ into continuity equationSolve equations for pressure corrections

Page 34: Rudolf Žitný, Ústav procesní a zpracovatelské techniky ČVUT FS 2010

FVM SIMPLE step 3 (update p,u,v)CFD7

*, , ,

*, , , 1, ,

*, , , , 1 ,

'

( ' ' )

( ' ' )

I J I J I J

i J i J i J I J I J

I j I j I j I J I J

p p p

u u d p p

v v d p p

Continue with the improved pressures to the step 1

Only these new pressures are necessary for next iteration

Page 35: Rudolf Žitný, Ústav procesní a zpracovatelské techniky ČVUT FS 2010

FVM SIMPLEC (SIMPLE corrected)CFD7

, 1, ,

, , , 1, ,

, 1, ,

' ' ' ', ,

' ' ' ' ' ', ,

,' ' '

,

( )

( )

( )

i J nb I J I J

i J i J nb i J I J I J

i J I J I J

i J nb i Jneighbours

i J nb nb nb i Jneighbours neighbours neighbours

i J

i J nbneighbours

a a A p p

a a a a A p p

Ap p

a a

u u

u u u u

u

Improved diJ

Neglect!!! Good estimate as soon as neighbours are

not far from center

Page 36: Rudolf Žitný, Ústav procesní a zpracovatelské techniky ČVUT FS 2010

FVM SIMPLER (SIMPLE Revised)CFD7

Idea: calculate pressure distribution directly from the Poisson’s equation

2

2

2

( )

( )

( , )

uu p u

uu p u

p f u v

Page 37: Rudolf Žitný, Ústav procesní a zpracovatelské techniky ČVUT FS 2010

This technique is called Rhie-Chow interpolation.

FVM Rhie Chow (Fluent)CFD7

Rhie C.M., Chow W.L.: Numerical study of the turbulent flow past an airfoil with trailing edge separation. AIAA Journal, Vol.21, No.11, 1983

The way how to avoid staggering (difficult implementation in unstructured meshes) was suggested in the paper

Page 38: Rudolf Žitný, Ústav procesní a zpracovatelské techniky ČVUT FS 2010

FVM Rhie Chow (Fluent)CFD7

Rhie C.M., Chow W.L.: Numerical study of the turbulent flow past an airfoil with trailing edge separation. AIAA Journal, Vol.21, No.11, 1983

0

1

1

y

v

x

u

fy

p

y

vv

x

vu

fx

p

y

uv

x

uu

y

x

ynvnPvPvPvP

xnunPuPuPuP

fvASy

pBSv

fuASx

pBSu

*

**

**

*

|

|P Ee

)||(**

**EPuEPEuPu x

p

x

pBuuSS

**

**

* ** * * * * * * ***

|

|

1| ( ( ))

2 2 2 2 2

P Pu u P

E Eu u E

Pu Eu E WE P P E E P EE Pe eu u e u u

pu S B

x

pu S B

x

S S p pp p u u p p p ppu S B B B

x x x x x

How to interpolate ue velocity at a control volume face

Page 39: Rudolf Žitný, Ústav procesní a zpracovatelské techniky ČVUT FS 2010

Fluent - solversCFD7

, , cp,…

u…

v…

w…

p… (SIMPLE…)

T,k,,……

Segregated solver

u

u uu

v vut

w wu

E Eu

, , cp,…

k,,……

Coupled solver

Nonstationary problem always solved by implicit Euler

Nonstationary problem solved by implicit Euler (CFL~5), explicit Euler (CFL~1) or Runge Kutta

Algebraic eq. by multigrid AMG Algebraic eq. by multigrid AMG, or FAS (Full Aproximation Storage)

CFL Courant Friedrichs Lewy criterion

Cx

tu

Page 40: Rudolf Žitný, Ústav procesní a zpracovatelské techniky ČVUT FS 2010

FVM solversCFD7

Dalí

Page 41: Rudolf Žitný, Ústav procesní a zpracovatelské techniky ČVUT FS 2010

FVM solversCFD7

TDMA – Gauss elimination tridiagonal matrix

(obvious choice for 1D problems, but suitable for 2D and 3D problems too, iteratively along the x,y,z grid lines – method of alternating directions ADI)

PDMA – pentadiagonal matrix (suitable for QUICK), Fortran version

CGM – Conjugated Gradient Method (iterative method: each

iteration calculates increment of vector in the direction of gradient of minimised function – square of residual vector)

Multigrid method (Fluent)

Solution of linear algebraic equation system Ax=b

Page 42: Rudolf Žitný, Ústav procesní a zpracovatelské techniky ČVUT FS 2010

Solver TDMA tridiagonal system MATLABCFD7

function x = TDMAsolver(a,b,c,d)%a, b, c, and d are the column vectors for the compressed tridiagonal matrixn = length(b); % n is the number of rows % Modify the first-row coefficientsc(1) = c(1) / b(1); % Division by zero risk.d(1) = d(1) / b(1); % Division by zero would imply a singular matrix. for i = 2:n id = 1 / (b(i) - c(i-1) * a(i)); % Division by zero risk. c(i) = c(i)* id; % Last value calculated is redundant. d(i) = (d(i) - d(i-1) * a(i)) * id;end % Now back substitute.x(n) = d(n);for i = n-1:-1:1 x(i) = d(i) - c(i) * x(i + 1);endend

Forward step (elimination entries bellow diagonal)

1 1 1, 2,...,i i i i i i ia x b x c x d i n

Page 43: Rudolf Žitný, Ústav procesní a zpracovatelské techniky ČVUT FS 2010

Solver TDMA applied to 2D problems (ADI)CFD7

x

y

Y-implicit step (repeated application of TDMA for 10 equations, proceeds from

left to right) X-implicit step (proceeds bottom up)

Page 44: Rudolf Žitný, Ústav procesní a zpracovatelské techniky ČVUT FS 2010

Solver PDMA pentagonal system MATLABCFD7

function x=pentsolve(A,b)

% Solve a pentadiagonal system Ax=b where A is a strongly nonsingular matrix% Reference: G. Engeln-Muellges, F. Uhlig, "Numerical Algorithms with C"% Chapter 4. Springer-Verlag Berlin (1996)%% Written by Greg von Winckel 3/15/04% Contact: [email protected]%[M,N]=size(A);x=zeros(N,1);% Check for symmetryif A==A' % Symmetric Matrix Scheme % Extract bands d=diag(A); f=diag(A,1); e=diag(A,2); alpha=zeros(N,1); gamma=zeros(N-1,1); delta=zeros(N-2,1); c=zeros(N,1); z=zeros(N,1); % Factor A=LDL' alpha(1)=d(1); gamma(1)=f(1)/alpha(1); delta(1)=e(1)/alpha(1); alpha(2)=d(2)-f(1)*gamma(1); gamma(2)=(f(2)-e(1)*gamma(1))/alpha(2); delta(2)=e(2)/alpha(2); for k=3:N-2 alpha(k)=d(k)-e(k-2)*delta(k-2)-alpha(k-1)*gamma(k-1)^2; gamma(k)=(f(k)-e(k-1)*gamma(k-1))/alpha(k); delta(k)=e(k)/alpha(k); end alpha(N-1)=d(N-1)-e(N-3)*delta(N-3)-alpha(N-2)*gamma(N-2)^2; gamma(N-1)=(f(N-1)-e(N-2)*gamma(N-2))/alpha(N-1); alpha(N)=d(N)-e(N-2)*delta(N-2)-alpha(N-1)*gamma(N-1)^2; % Update Lx=b, Dc=z z(1)=b(1); z(2)=b(2)-gamma(1)*z(1); for k=3:N z(k)=b(k)-gamma(k-1)*z(k-1)-delta(k-2)*z(k-2); end c=z./alpha;

% Backsubstitution L'x=c x(N)=c(N); x(N-1)=c(N-1)-gamma(N-1)*x(N); for k=N-2:-1:1 x(k)=c(k)-gamma(k)*x(k+1)-delta(k)*x(k+2); end else % Non-symmetric Matrix Scheme d=diag(A); e=diag(A,1); f=diag(A,2); h=[0;diag(A,-1)]; g=[0;0;diag(A,-2)]; alpha=zeros(N,1); gam=zeros(N-1,1); delta=zeros(N-2,1); bet=zeros(N,1); c=zeros(N,1); z=zeros(N,1); alpha(1)=d(1); gam(1)=e(1)/alpha(1); delta(1)=f(1)/alpha(1); bet(2)=h(2); alpha(2)=d(2)-bet(2)*gam(1); gam(2)=( e(2)-bet(2)*delta(1) )/alpha(2); delta(2)=f(2)/alpha(2); for k=3:N-2 bet(k)=h(k)-g(k)*gam(k-2); alpha(k)=d(k)-g(k)*delta(k-2)-bet(k)*gam(k-1); gam(k)=( e(k)-bet(k)*delta(k-1) )/alpha(k); delta(k)=f(k)/alpha(k); end bet(N-1)=h(N-1)-g(N-1)*gam(N-3); alpha(N-1)=d(N-1)-g(N-1)*delta(N-3)-bet(N-1)*gam(N-2); gam(N-1)=( e(N-1)-bet(N-1)*delta(N-2) )/alpha(N-1); bet(N)=h(N)-g(N)*gam(N-2); alpha(N)=d(N)-g(N)*delta(N-2)-bet(N)*gam(N-1); % Update b=Lc c(1)=b(1)/alpha(1); c(2)=(b(2)-bet(2)*c(1))/alpha(2); for k=3:N c(k)=( b(k)-g(k)*c(k-2)-bet(k)*c(k-1) )/alpha(k); end

% Back substitution Rx=c x(N)=c(N); x(N-1)=c(N-1)-gam(N-1)*x(N); for k=N-2:-1:1 x(k)=c(k)-gam(k)*x(k+1)-delta(k)*x(k+2); end end

Page 45: Rudolf Žitný, Ústav procesní a zpracovatelské techniky ČVUT FS 2010

Solver CGM conjugated gradient GNUCFD7

function [x] = conjgrad(A,b,x) r=b-A*x; p=r; rsold=r'*r; for i=1:size(A)(1) Ap=A*p; alpha=rsold/(p'*Ap); x=x+alpha*p; r=r-alpha*Ap; rsnew=r'*r; if sqrt(rsnew)<1e-10 break; end p=r+rsnew/rsold*p; rsold=rsnew; endend

Solution of linear algebraic equation system Ax=b

Minimisation of quadratic function

Residual vector in k-th iteration

Vector of increment conjugated with previous increments

Page 46: Rudolf Žitný, Ústav procesní a zpracovatelské techniky ČVUT FS 2010

Solver MULTIGRIDCFD7

Rough grid (small wave numbers) Fine grid (large wave numbers details)

Interpolation from rough to fine grid

Averaging from fine to rough grid

Solution on a rough grid takes into account very quickly long waves (distant boundaries etc), that is refined on a finer grid.

Page 47: Rudolf Žitný, Ústav procesní a zpracovatelské techniky ČVUT FS 2010

Unsteady flowsCFD7

Discretisation like in the finite difference methods discussed previously

n

n+1

∆x

∆tnPTn

WT nET

1nPT

n-1

n

n+1

∆x

∆tnPT

1nWT 1n

ET 1nPT

n-1

n

n+1

∆x

∆tnPTn

WT nET

1nPT

n-1

1nWT 1n

ET

Example: Temperature field

EXPLICIT scheme IMPLICIT scheme CRANK NICHOLSON scheme

2

2

xt

a

2

2

T Ta

t x

First order accuracy in time First order accuracy in time Second order accuracy in time

Stable only if Unconditionally stable and bounded Unconditionally stable, but bounded 2x

ta

only if

Page 48: Rudolf Žitný, Ústav procesní a zpracovatelské techniky ČVUT FS 2010

FVM Boundary conditionsCFD7

Boundary conditions are specified at faces of cells (not at grid points)

INLET specified u,v,w,T,k, (but not pressure!)

OUTLET nothing is specified (p is calculated from continuity eq.)

PRESSURE only pressure is specified (not velocities)

WALL zero velocities, kP, P calculated from the law of wallPyP

Recommended combinations for several outlets

INLET

PRESSURE

PRESSURE

INLET

OUTLET

OUTLET

PRESSURE

PRESSURE

PRESSURE

Forbidden combinations for several outlets

PRESSURE

PRESSURE

OUTLET

there is no unique solution because no flowrate is specified

Page 49: Rudolf Žitný, Ústav procesní a zpracovatelské techniky ČVUT FS 2010

Stream function-vorticityCFD7

Ghirlandaio

Introducing stream function and vorticity instead of primitive variables (velocities and pressure) eliminates the problem with the checkerboard pattern. Continuity equation is exactly satisfied.

However the technique is used mostly for 2D problems (it is sufficient to solve only 2 equations), because in 3D problems 3 components of vorticity and 3 components of vector potential must be solved (comparing with only 4 equations when using primitive variable formulation of NS equations).

Page 50: Rudolf Žitný, Ústav procesní a zpracovatelské techniky ČVUT FS 2010

Stream function-vorticityCFD7

The best method for solution of 2D problems of incompressible flows

vy

p

y

vv

x

vu

ux

p

y

uv

x

uu

2

2

1

1

Pressure elimination

2( ) ( ) ( )u v u v u v

u vx y x y y x y x

Introduction vorticity (z-component of vorticity vector)

,u vy x

wvuzyx

kji

u

2u vx y

Velocities expressed in terms of scalar stream function

Vorticity expressed in terms of stream function

2

0

y

v

x

u

y

u

x

v

Page 51: Rudolf Žitný, Ústav procesní a zpracovatelské techniky ČVUT FS 2010

Stream function-vorticityCFD7

Three equations for u,v,p are replaced by two equations for , . Advantage: continuity equation is exactly satisfied. Vorticity transport is parabolic equation, Poisson equaion for stream function is eliptic.

| , |w w w wu vy x

2u vx y

How to do it, is shown in the next slide on example of flow in a channel

2

Lines of constant are streamlines (at wall =const). The no-slip condition at wall (prescribed velocities) must be reflected by boundary condition for vorticity

Page 52: Rudolf Žitný, Ústav procesní a zpracovatelské techniky ČVUT FS 2010

Stream function-vorticityCFD7

( | , | )w w w wu vy x

x

y

=0

H

w dyyu0

)(

H

Increases from 0 to w for example =uy

1 2 N-1 N

1

2

M

N-1=N

y

u

x

v

Stream function

Vorticity

Zero vorticity at axis (follows from definition)

Prescribed velocity profile at inlet u1(y) and v1(y)=0

y

u

x

12

2

1

221

2

12

21

21

12 2

1

2

1x

xx

xx

x

2 1 11 2

2( ) u

x y

Vorticity at wall (prescribed velocity U, in this case zero)

)(2

12yU

y MMMM

Page 53: Rudolf Žitný, Ústav procesní a zpracovatelské techniky ČVUT FS 2010

Example: cavity flow 1/4CFD7

x

y

H

1 2 N-1 N

1

2

M

UM

Cavity flow. Lid of cavity is moving with a constant velocity U. There is no in-out flow, therefore stream function (proportional to flowrate) is zero at boundary, at all walls of cavity

)(2

12yU

y MMMM

Vorticity at moving lid

Vorticity at fixed walls 1 1 2 1 1 1 22 2 2

2 2 2( ) ( ) ( )N N Nx x y

Page 54: Rudolf Žitný, Ústav procesní a zpracovatelské techniky ČVUT FS 2010

CFD7

FVM applied to vorticity transport equation (upwind of the first order). Equidistant grid is assumed =x=y

x

y

W P E

UM

N

S

))0,max(

())0,max(

())0,max(

())0,max(

()4||||

(22222

P

NP

SP

EP

WPP

P

vvuuvu

Eliptic equation for stream function

2 2

4 1( )P W E S N P

This systém of algebraic equation (including boundary conditions) is to be solved iteratively (for example by alternating direction method ADI described previously)

2

SNPu

2W E

Pv

Example: cavity flow 2/4

Page 55: Rudolf Žitný, Ústav procesní a zpracovatelské techniky ČVUT FS 2010

CFD7 Example: cavity flow 3/4Matlab% tok v dutině. metoda vířivosti a pokutové funkice. Upwind. Metoda% střídavých směrů. h=0.01; um=0.0001; visc=1e-6;% parametry site, a casovy krok relax=0.5; n=21; d=h/(n-1); d2=d^2; niter=50; psi=zeros(n,n); omega=zeros(n,n); u=zeros(n,n); v=zeros(n,n); a=zeros(n,1); b=ones(n,1); c=zeros(n,1); r=zeros(n,1); for iter=1:niter for i=1:n u(i,n)=um; end for i=2:n-1 for j=2:n-1 u(i,j)=(psi(i,j+1)-psi(i,j-1))/(2*d); v(i,j)=(psi(i-1,j)-psi(i+1,j))/(2*d); end end

%stream function x-implicitfor j=2:n-1 for i=2:n-1 a(i)=-1/d2;b(i)=4/d2;c(i)=-1/d2; r(i)=(psi(i,j-1)+psi(i,j+1))/d2+ omega(i,j); end r(1)=0;r(n)=0; ps=tridag(a,b,c,r,n); for i=2:n-1 psi(i,j)=(1-relax)*psi(i,j)+relax*ps(i); endend%stream function y-implicitfor i=2:n-1 for j=2:n-1 a(j)=-1/d2;b(j)=4/d2;c(j)=-1/d2;r(j)=(psi(i-1,j)+psi(i+1,j))/d2+ omega(i,j); end r(1)=0;r(n)=0; ps=tridag(a,b,c,r,n); for j=2:n-1 psi(i,j)=(1-relax)*psi(i,j)+relax*ps(j); endend% vorticity boundary conditionsfor i=1:n omega(i,n)=relax*omega(i,n)+(1-relax)*2/d2* (psi(i,n)-psi(i,n-1)-um*d); omega(i,1)=relax*omega(i,1)+(1-relax)*2* (psi(i,1)-psi(i,2))/d2; omega(1,i)=relax*omega(1,i)+(1-relax)*2*(psi(1,i)-psi(2,i))/d2; omega(n,i)=relax*omega(n,i)+(1-relax)*2*(psi(n,i)-psi(n-1,i))/d2;end

%vorticity x-implicitfor j=2:n-1 for i=2:n-1 up=u(i,j);vp=v(i,j); a(i)=-visc/d2-max(up,0)/d; b(i)=4*visc/d2+(abs(up)+abs(vp))/d; c(i)=-visc/d2-max(-up,0)/d; r(i)=omega(i,j-1)*(visc/d2+max(vp,0)/d)+ omega(i,j+1)*(visc/d2+max(-vp,0)/d); end r(1)=omega(1,j);r(n)=omega(n,j); ps=tridag(a,b,c,r,n); for i=2:n-1 omega(i,j)=(1-relax)*omega(i,j)+relax*ps(i); endend%vorticity y-implicitfor i=2:n-1 for j=2:n-1 up=u(i,j);vp=v(i,j); a(j)=-visc/d2-max(vp,0)/d; b(i)=4*visc/d2+(abs(up)+abs(vp))/d; c(j)=-visc/d2-max(-vp,0)/d; r(j)=omega(i-,j)*(visc/d2+max(up,0)/d)+ omega(i+1,j)* (visc/d2+max(-up,0)/d); end r(1)=omega(i,1);r(n)=omega(i,n); ps=tridag(a,b,c,r,n); for j=2:n-1 omega(i,j)=(1-relax)*omega(i,j)+relax*ps(j); endend end

Page 56: Rudolf Žitný, Ústav procesní a zpracovatelské techniky ČVUT FS 2010

CFD7 Example: cavity flow 4/4

5 10 15 20 25 30

5

10

15

20

25

30

-9

-8

-7

-6

-5

-4

-3

-2

-1

0x 10

-8

5 10 15 20 25 30

5

10

15

20

25

30

-1

0

1

2

3

4

5

6

7

8

9x 10

-5

u

5 10 15 20 25 30

5

10

15

20

25

30

-0.4

-0.35

-0.3

-0.25

-0.2

-0.15

-0.1

-0.05

0

0.05

0.1

5 10 15 20 25 30

5

10

15

20

25

30

-3

-2

-1

0

1

2

3x 10

-5

v

Re=1

10 20 30 40 50 60 70

10

20

30

40

50

60

70

-10

-9

-8

-7

-6

-5

-4

-3

-2

-1

0x 10

-6

Re=1000

Page 57: Rudolf Žitný, Ústav procesní a zpracovatelské techniky ČVUT FS 2010

CFD7 Example: cavity flow FLUENT

Re=1

u v