0% found this document useful (0 votes)
19 views

Numerical Models For Engineering: Finite Difference For 1-D Initial Value Problems

The document discusses numerical methods for solving 1D transient heat conduction problems using finite difference methods. It describes explicitly discretizing the temporal derivative using explicit, implicit, and Crank-Nicholson methods. The explicit method treats the temperature at the new time step as explicitly dependent on temperatures from the previous time step. The implicit method instead treats the new time step temperatures implicitly. Crank-Nicholson is a mixed method that takes the average of explicit and implicit formulations. Stability of the numerical solutions is also addressed along with MATLAB implementation and conclusions.

Uploaded by

martonegaetano
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Numerical Models For Engineering: Finite Difference For 1-D Initial Value Problems

The document discusses numerical methods for solving 1D transient heat conduction problems using finite difference methods. It describes explicitly discretizing the temporal derivative using explicit, implicit, and Crank-Nicholson methods. The explicit method treats the temperature at the new time step as explicitly dependent on temperatures from the previous time step. The implicit method instead treats the new time step temperatures implicitly. Crank-Nicholson is a mixed method that takes the average of explicit and implicit formulations. Stability of the numerical solutions is also addressed along with MATLAB implementation and conclusions.

Uploaded by

martonegaetano
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

Dipartimento di Ingegneria

Università degli Studi di Napoli “Parthenope”

Numerical models for


engineering
Lesson 12

Finite Difference for


1-D Initial Value Problems
A.A. 2014/2015 NUMERICAL MODELS FOR ENGINEERING PROF. N. MASSAROTTI 1
Outline

Discretization of the heat conduction transient problems;

Methods for discretization of temporal derivative:

Explicit method;

Implicit method;

Crank-Nicholson.

Stability of numerical solution;

Matlab implementation;

Conclusions.

A.A. 2014/2015 NUMERICAL MODELS FOR ENGINEERING PROF. N. MASSAROTTI 2


Transient problems
For one dimensional transient problems, the unknown is
T(x,q), a function of space and time
∂T ∂ 2T
= a
2
+ uɺ ′′′ (θ ) 0 ≤ x ≤ L; θ > 0
∂θ ∂x

Initial Cond. T (x , 0) = Tb 0≤x ≤L


T0 TL
Dirichlet BC T (0, θ) = T0 θ>0

Dirichlet BC T (L, θ ) = TL θ > 0


x
L

A.A. 2014/2015 NUMERICAL MODELS FOR ENGINEERING PROF. N. MASSAROTTI 3


Transient problems

We already know how to discretize the Right Hand Side


(RHS) in space using finite differences:
1 ∂T ∂2T
= + uɺ ′′′ 0 ≤ x ≤ L; θ > 0
a ∂θ ∂x 2

n +1 n
∂2T Ti −1 − 2Ti + Ti +1
∂T T − T ≃
2
∂θ

∆θ ∂x ∆x 2

It is easy to discretize the LHS in the same way,


considering the time interval θn+1-θn=∆θ
The problem now is how to calculate these terms (?)

A.A. 2014/2015 NUMERICAL MODELS FOR ENGINEERING PROF. N. MASSAROTTI 4


Transient problems

Depending on the time instant in which the heat flux is


calculated:
T n +1 − T n
 i   Ti − 1 − 2Ti + Ti + 1 ??
i  
  = a  
 ∆θ   ∆x 2

It is clear that the LHS refers to the node for which the
equation is discretized in space
The RHS can be calculated at different instants of time:
θn+1 or θn (these will be referred to as instants “n” and
“n+1”);

A.A. 2014/2015 NUMERICAL MODELS FOR ENGINEERING PROF. N. MASSAROTTI 5


Approximation of Physical Problem

From the physical point of view, this corresponds to:


T(θ) n +1
Tn+1 (Qɺ net ) i

∂T  T n +1 − T n 
=  
∂θ  ∆θ 
Tn
n
(Qɺ n et ) i
θn θn+1 θ
∆θ

The temporal approximation of the balance quantities;


T n +1 − T n 
( ρcV )i  i  ??
 = (Qɺ net ) i
i

 ∆θ 

A.A. 2014/2015 NUMERICAL MODELS FOR ENGINEERING PROF. N. MASSAROTTI 6


Transient problems
The calculation of the RHS characterizes the numerical method:

if the RHS is calculated at time θn, the “explicit method” is obtained:


 T n +1 − T n 
( ρcV )i  i i  = (Qɺ ) n
 i
 ∆θ

if the RHS is calculated at time θn+1, the “implicit method” is obtained:


 T n +1 − T n 
( ρcV )i  i i  = (Qɺ ) n +1
 i
 ∆θ 
if the RHS is calculated as mean of values at θn and θn+1, the “Crank
Nicholson method” is obtained:
 T n +1 − T n  1 
( ρcV )i  i i  = ⋅  (Qɺ ) n + (Qɺ ) n +1 
 
 2 
∆θ i i

A.A. 2014/2015 NUMERICAL MODELS FOR ENGINEERING PROF. N. MASSAROTTI 7


Explicit method
In the “explicit method”, without considering heat
generation:
 Ti n +1 − Ti n  ɺn ɺ n ɺ n
T0
( ρ cV )i   = QiNET = Qi −1,i − Qi ,i +1 TL
 ∆θ 
Discretizing the fluxes with central
i-1 i i+1 M
difference approximation, we obtain:
n n
ρ cA∆x n+1 n  kA   kA 
∆θ
( Ti − Ti ) =  (Ti −1 − Ti )  +  (Ti +1 − Ti ) 
 ∆x   ∆x 
∆x
where A refers to section crossed by the heat flux.
The RHS is the discrete formulation of steady state problem. We can write:
a∆θ Ti −n1 − 2Ti n + Ti +n1
(T i
n +1
− Ti ) =
n

∆x ∆x
i = 1,..., M − 1

A.A. 2014/2015 NUMERICAL MODELS FOR ENGINEERING PROF. N. MASSAROTTI 8


Explicit method
For the explicit method ( Forward Euler)
T n +1 − T n
 i
 Ti −1 − 2Ti + Ti +1 n T n
− 2T n
+ T n
i  = a   = a i −1 i i +1
 
 ∆θ   ∆x 2  ∆x 2

the RHS has to be considered a known term, as the


unknown is the temperature at time n+1!
For each point, the algebraic equation to be solved is:

a ∆θ
Tin + 1 = Tin +
∆x 2
(Tin−1 − 2Tin + Tin+ 1 )

Which can be solved starting from the initial condition


(t=0 → values all known on the domain)!
A.A. 2014/2015 NUMERICAL MODELS FOR ENGINEERING PROF. N. MASSAROTTI 9
Explicit method

We can write:
 2a∆θ  n a∆θ
Ti n+1 = 1 −
 ∆x 2

 i

T +
∆x 2
⋅ ( T n
i −1 + Ti +1 )
n
i = 1,..., M − 1

Defining a local Fourier number, Fo:


a∆θ
Foi =
∆x 2

Tin +1 = ( 1 − 2Foi ) ⋅ Tin + Foi ⋅ (Tin−1 + Tin+1 ) i = 1,..., M − 1

For an uniform spatial grid, the local Fourier number assumes a


single value in all domain.

A.A. 2014/2015 NUMERICAL MODELS FOR ENGINEERING PROF. N. MASSAROTTI 10


Explicit method
Introducing a matrix form for M=5:
 T2n +1 − T2n 
 
∆ θ
1 0 0   n +1   2 −1 0  T2  T1n 
n

0 1 0   T3 − T3  = − a  −1 2 −1 T n  + a ⋅ ∆θ  
n

   ∆θ  ∆x 2    3  ∆x 2 0

0 0 1  n +1   0 −1 2  T4n  T n 
 T4 − T4n   5
 
 ∆θ 

 T n +1 − T n  n n
[M ]  = − [ K ]{T } + {b}
 ∆θ 

so we can write:
{T }
n +1
( −1
) n −1
= 1 − [ M ] ⋅ ∆θ [ K ] {T } + [ M ] ∆θ {b}
n

A.A. 2014/2015 NUMERICAL MODELS FOR ENGINEERING PROF. N. MASSAROTTI 11


Explicit method: Stability
The stability of “explicit method” depends on the
growth factor (1-2Foi). So it requires small time steps to
keep the error in the result bounded, in fact:
Ti n
Ti n +1
= (1 − 2 ⋅ Foi ) ⋅ Ti + Foi ⋅ (T + T
n n
i −1
n
i +1 ) Ti−n1 Ti+n1

i-1 i i+1
After ∆θ
This condition corresponds to a limitation on the primary
n +1 n +1
coefficient on RHS; this coefficient should assume a positive Ti−1 Ti n +1 Ti+1
value to achieve a stable solution with explicit method:
1 ∆x 2 i-1 i i+1
1 − 2 ⋅ Foi ≥ 0 ⇔ Foi ≤ ⇔ ∆θ ≤
2 2a
Therefore, only ∆x is fixed.

A.A. 2014/2015 NUMERICAL MODELS FOR ENGINEERING PROF. N. MASSAROTTI 12


Explicit method: Stability
The implementation of explicit method  T1n +1 = c1 ⋅ T1n + ...
requires to write a system of M equations, T2n +1 = ... + c2 ⋅ T2n + ...

where M is the number of nodes. The   ⋮
stability condition requires that all primary T n +1 = ... + c ⋅ T n + ...
 i i i
coefficient should be positive.  ⋮
 n +1 n
ci ≥ 0 i = 1,..., M  T
 M = ... + cM ⋅ TM

To respect stability condition for all equations it is necessary to define:

min ( ci ) = clim ite


i =1,..., M

Imposing that this limit value should be positive, stability condition


will be respected for all equations.

A.A. 2014/2015 NUMERICAL MODELS FOR ENGINEERING PROF. N. MASSAROTTI 13


Implicit method
Implicit method is obtained by calculating the RHS at time n+1:

 n +1 − T n
 Ti   Ti − 1 − 2Ti + Ti + 1 n + 1 Tin−+1 1 − 2Tin + 1 + Tin++1 1
i  
  = a  
= a
 ∆θ   ∆x 2 ∆x 2

and again, as the unknown is the temperature at time n+1, this


value cannot be calculated explicitly!
For each point, the algebraic equation to be solved is:

T in + 1 − T in a
∆θ
=
2
(T i n−+1 1 − 2T i n + 1 + T i n++1 1 )
∆x

Which still needs the known initial condition (t=0)!

A.A. 2014/2015 NUMERICAL MODELS FOR ENGINEERING PROF. N. MASSAROTTI 14


Implicit method
For a case study without generation terms, we can write the implicit
method as follows:

 T n +1 − T n  T0
( ρcV )i  i i
 = Qɺ i
n +1
= Qɺ in−+1,1i − Qɺ in,i++11
 ∆θ 
TL

Discretizing the fluxes with central 0 i-1 i i+1 M


difference approximation, we obtain:
ρcA∆x n +1  kA kA  n +1
∆θ
(Ti − Tin ) =  (T − Ti ) + (Ti +1 − Ti ) 
 ∆x i −1 ∆x  ∆x
Moving known terms from LHS to RHS, we obtain:

( 1 + 2 ⋅ Foi ) ⋅ Tin +1 − Foi ⋅ (Tin−+1 1 + Tin++1 1 ) = Tin i = 1,..., M − 1

A.A. 2014/2015 NUMERICAL MODELS FOR ENGINEERING PROF. N. MASSAROTTI 15


Implicit method:
Introducing a matrix form:


T n + 1 − T n 
 n +1 n +1
 
 { } { }
M    = −  K  T + b
  ∆θ 

 


n +1 n n +1
(  M  + ∆θ  K  ){T } =  M  {T } + ∆θ {b }
     
posing:

A = M  + K 
     
we get:
n +1 −1 n −1 n +1
{T } =  A   M  {T } +  A  ∆θ {b }

A.A. 2014/2015 NUMERICAL MODELS FOR ENGINEERING PROF. N. MASSAROTTI 16


Crank-Nicholson method
The basic idea of semi-implicit scheme is to calculate the RHS as
a mean of values at times n and n+1:

 T n +1 − T n 
( ρcV )i  i i
 = ξ ⋅ Qɺ i
n +1
+ ( 1 − ξ ) ⋅ Qɺ in with 0<ξ<1
 ∆θ 

previous equation can be rewritten as follows:

(Tin +1 − Tin ) = Fo  ξ ⋅ (Ti −1 − 2Ti + Ti +1 )n +1 + ( 1 − ξ ) ⋅ (Ti −1 − 2Ti + Ti +1 )n 




re-organizing the terms of the equation, we get
n +1
( 1 + 2 ⋅ ξ ⋅ Foi ) ⋅ Tin +1 − ξ ⋅ Foi ⋅ (Ti −1 + Ti +1 ) =
 1 − 2 ⋅ ( 1 − ξ ) ⋅ Foi  ⋅ Tin + ( 1 − ξ ) ⋅ Foi ⋅ (Ti −1 + Ti +1 )n i = 1,..., M − 1
 

for ξ=1/2 the classical Crank-Nicholson method is obtained, while for ξ=1 and
ξ=0, the implicit method and the explicit method are obtained, respectively.
A.A. 2014/2015 NUMERICAL MODELS FOR ENGINEERING PROF. N. MASSAROTTI 17
Analysis of stability
By considering a general spatial discretization with M node and by
introducing the matrix [K]:
 1 − 2 ⋅ ( 1 − ξ ) ⋅ Fo ( 1 − ξ ) ⋅ Fo 
 
 ( 1 − ξ ) ⋅ Fo 1 − 2 ⋅ ( 1 − ξ ) ⋅ Fo ( 1 − ξ ) ⋅ Fo 
 
 ( 1 − ξ ) ⋅ Fo 1 − 2 ⋅ ( 1 − ξ ) ⋅ Fo ( 1 − ξ ) ⋅ Fo 
[K ] =  

 ( 1 − ξ ) ⋅ Fo 1 − 2 ⋅ ( 1 − ξ ) ⋅ Fo ( 1 − ξ ) ⋅ Fo 

 ( 1 − ξ ) ⋅ Fo 1 − 2 ⋅ ( 1 − ξ ) ⋅ Fo (1 − ξ ) ⋅ Fo 
 
 ( 1 − ξ ) ⋅ Fo 1 − 2 ⋅ ( 1 − ξ ) ⋅ Fo 

and the matrix M:


 1 + 2 ⋅ ξ ⋅ Fo −ξ ⋅ Fo 
 
 −ξ ⋅ Fo 1 + 2 ⋅ ξ ⋅ Fo −ξ ⋅ Fo 
 
 −ξ ⋅ Fo 1 + 2 ⋅ ξ ⋅ Fo −ξ ⋅ Fo 

[M ] =  
−ξ ⋅ Fo 1 + 2 ⋅ ξ ⋅ Fo −ξ ⋅ Fo 
 
 
 −ξ ⋅ Fo 1 + 2 ⋅ ξ ⋅ Fo −ξ ⋅ Fo 
 
 −ξ ⋅ Fo 1 + 2 ⋅ ξ ⋅ Fo 

we can write:
 M  {T }n +1 =  K  {T }n + {b }n
   

A.A. 2014/2015 NUMERICAL MODELS FOR ENGINEERING PROF. N. MASSAROTTI 18


Analysis of stability
By introducing the global discretization error:
j j j
{e } = { t } − {T }
where tj is the exact solution at time j, we can write:
M 
  ( {t }
n +1
− {e }
n +1
) =  K  ⋅ ( {t } n n
− {e } ) + {b }

 M  {t }n +1 −  K  ⋅ {t }n + {b }n =  M  {e }n +1 −  K  ⋅ {e }n
       
=0
so we obtain:

{e }
n +1
(
=  K  ⋅  M 
−1
)
⋅ {e }
n


n
{e }
n +1
(
=  K  ⋅  M 
−1
) ⋅ {e }
0

A.A. 2014/2015 NUMERICAL MODELS FOR ENGINEERING PROF. N. MASSAROTTI 19


Analysis of stability
By introducing the Euclidian norm:
n
e n +1 = A e0

We can demonstrate that stability conditions are the same of that ones
calculated for the previous case.

Implicit method: UNCONDITIONALLY STABLE;

Explicit method: STABLE for Fo≤0.5;

Crank-Nicholson method: STABLE for Fo≤1.

A.A. 2014/2015 NUMERICAL MODELS FOR ENGINEERING PROF. N. MASSAROTTI 20


Analysis of stability
To analyze the stability limits of the three methods, it is possible to
consider a grid with two nodes; only one node is at an unknown
temperature.

(1 + 2 ⋅ ξ ⋅ Fo) ⋅ T1n+1 − 2 ⋅ ξ ⋅ Fo ⋅ T0 = 1 − 2 ⋅ ( 1 − ξ ) ⋅ Fo  ⋅ T1n + (1 − ξ ) ⋅ Fo ⋅ T0


by imposing the BC we get:
 1 − 2 ⋅ ( 1 − ξ ) ⋅ Fo  T0=0 qɺ = 0
T1n +1 =   ⋅Tn
1
( 1 + 2 ⋅ ξ ⋅ Fo )
=G
0 1
or: T1n +1 =G ⋅ T1n

G = 1 − 2 ⋅ Fo ← ξ = 0 Explicit method


1 − Fo ∆x
G = with: ξ = 1 2 Crank − Nicholson method
1 + Fo
1
G = → ⇒ ξ = 1 Implicit method
1 + 2 ⋅ Fo
A.A. 2014/2015 NUMERICAL MODELS FOR ENGINEERING PROF. N. MASSAROTTI 21
Analysis of stability
By introducing the global discretization error:
ej = t j −T j
where tj is the exact solution at time j, we can write:
t1n +1 − e1n +1 = G ⋅ ( t1n − e1n ) ⇒ t1n +1 − G ⋅ t1n = e1n +1 − G ⋅ e1n
=0
so we obtain:
e1n +1 = G ⋅ e1n

e1n +1 = G n ⋅ e10

The stability is achieved for:

0 ≤G ≤ 1

A.A. 2014/2015 NUMERICAL MODELS FOR ENGINEERING PROF. N. MASSAROTTI 22


Analysis of stability
The stability condition can be examined for the different
problems based on:

T1n +1 = λ ⋅ T1n

G E = 1 − 2 ⋅ F o
1 − F o
G S =
1 + F o
1
G I =
1 + 2 ⋅ F o

A.A. 2014/2015 NUMERICAL MODELS FOR ENGINEERING PROF. N. MASSAROTTI 23


Matlab implementation
Case Study:

∂T ∂ 2T
= a 0 ≤ x ≤ L; θ > 0
∂θ 2
∂x

Initial Cond. T (x , 0) = Tb = 0 0≤x ≤L


T0 TL
Dirichlet BC T(0, θ) = T0 = 20 θ>0

Dirichlet BC T (L, θ) = TL = 0 θ>0


x
L

A.A. 2014/2015 NUMERICAL MODELS FOR ENGINEERING PROF. N. MASSAROTTI 24


Matlab implementation
Implicit method
Parameters declaration
and vectors and matrix
inizialization

A.A. 2014/2015 NUMERICAL MODELS FOR ENGINEERING PROF. N. MASSAROTTI 25


Matlab implementation
Implicit method

Algorithm implementation

n +1 n
{T } − {T } n +1 n +1
M
 
 =  K  SFD ⋅ {T } + {b }
∆θ

A.A. 2014/2015 NUMERICAL MODELS FOR ENGINEERING PROF. N. MASSAROTTI 26


Matlab implementation
Implicit method

Solution plot

A.A. 2014/2015 NUMERICAL MODELS FOR ENGINEERING PROF. N. MASSAROTTI 27


Matlab implementation
Explicit method

Algorithm implementation

A.A. 2014/2015 NUMERICAL MODELS FOR ENGINEERING PROF. N. MASSAROTTI 28


Conclusions

Several engineering problems are described by


differential equations;
Problems described by the same type of equations are
analogous and can be solved using the same methods;
It is fundamental to understand the physical meaning of
single terms appearing in the equations;
Analytical solutions for one dimensional problems
boundary value problems is very often available;
For simple problems, the solution should always be
found by hand (you don’t need big computers)!

A.A. 2014/2015 NUMERICAL MODELS FOR ENGINEERING PROF. N. MASSAROTTI 29


Exercises

Exercise 1: Write a matlab code for the solution of the


problem:

∂T ∂ 2T
= a 0 ≤ x ≤ L; θ > 0
∂θ ∂x 2

Initial Cond. T (x , 0) = Tb 0≤x ≤L T0 qɺ = 0

Dirichlet BC T (0, θ) = T0 θ>0

Neumann BC ∂T (L, θ)
=0 θ>0
∂x L=0.7 m

Use for thermal properties the same values of previous example


A.A. 2014/2015 NUMERICAL MODELS FOR ENGINEERING PROF. N. MASSAROTTI 30
Matlab implementation
Exercise 2: Write a matlab code for the solution of the
problem:

∂T ∂ 2T
= a 0 ≤ x ≤ L; θ > 0
∂θ 2
∂x

T0 TL
Initial Cond. T (x , 0) = Tb = 0 0≤x ≤L

Dirichlet BC T(0, θ) = T0 = 20 θ>0


x
L
Dirichlet BC T (L, θ) = TL ( θ ) θ>0

Assume a boundary condition function of time.


A.A. 2014/2015 NUMERICAL MODELS FOR ENGINEERING PROF. N. MASSAROTTI 31

You might also like