Download Numerical Methods in Diffusion

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Quadratic equation wikipedia , lookup

Cubic function wikipedia , lookup

Quartic function wikipedia , lookup

System of polynomial equations wikipedia , lookup

False position method wikipedia , lookup

System of linear equations wikipedia , lookup

Transcript
Numerical Methods
in Diffusion
J.C. LaCombe
University of Nevada, Reno
Reno, NV, USA
[email protected]
These lecture notes complement an online learning module and diffusion simulation
software that can be found at:
http://unr.edu/homepage/lacomj/Diffusion/index.htm
MSE 430 © 2006, J.C.LaCombe
Portions of this lecture were adapted from
Elements of Heat and Mass Transfer, 3rd ed.,
F.P. Incropera, and D.P. De Witt
John Wiley & Sons, NY, 1990
1
Introduction
Numerical Methods
In many real-world problems, the details of the system may not
correspond to a known solution to the diffusion equation. In these cases,
it is usually possible to produce a solution where the equation is solved
through iterative techniques. This is generally a lot of work to do by
hand. However, with the aid of a computer, this becomes possible. The
techniques used to reach such solutions are known as numerical methods.
Situations that often require numerical methods include
• Multi-dimensional problems (not simply 1-D)
• Complex Problems
•Complex Geometry/Shape
•Complex boundary conditions
•Complex initial conditions
MSE 430 © 2006, J.C.LaCombe
2
Discretization of the
Problem
Elements and Nodes
The numerical methods we will use in this course solve complex diffusion
problems by breaking up the system into manageable parts and solving the
diffusion equations for each part simultaneously with all the other parts.
To do this, we discretize the problem mathematically by dividing up space
into little elements or nodes and treating time as moving forward in small
steps.
Element
Component divided into elements
Node
MSE 430 © 2006, J.C.LaCombe
3
Discretization of the
Problem
Discretization of the Problem
Each element is identified using subscripts, and has a finite dimensions.
x
y
y
2
Nodem,n
x
2
MSE 430 © 2006, J.C.LaCombe
4
The Finite-Difference
Approach
Fick’s Laws in 2-D
Recall: Fick’s 1st law simply tells us how solute will flow if there is a
concentration gradient.
Recall: Fick’s 2nd law is simply a combination of Conservation of Mass
with Fick’s 1st law.
Fick’s 2nd Law in 2-D
Cartesian Coordinates.
C
 D 2 C
t
1 C  2C  2C
 2  2
D t
x
y
(1)
Before we solve this, we need to re-write the equation into a discretized
form. The approach presented here is known as a finite-difference
solution approach.
MSE 430 © 2006, J.C.LaCombe
5
The Diffusion Equation Discretizing the Spatial Derivatives
1 C  2C  2C
 2  2
D t
x
y
(1)
Consider first, the spatial 2nd derivatives on the RHS of Equation (1).
The 2nd derivatives can be thought of more simply as the slope of the 1st
derivatives. This is written (approximated) in the x-direction as
Gradient at
RHS of CV
C
x 2
2
Slope of the 1st derivative

m,n
C
x m  1 , n
2
Gradient at
LHS of CV
 Cx
x
m  12 , n
(2)
Note that the 1st derivatives here are simply the concentration gradients.
We can use the central difference approximation to determine these…
MSE 430 © 2006, J.C.LaCombe
6
The Diffusion Equation Discretizing the Spatial Derivatives
 2C
x 2

C
x m  1 , n
2
m,n
 Cx
m  12 , n
x
(2)
m-1,n+1
m,n+1
m+1,n+1
Eq. (2) further simplifies if we can determine
the concentration gradient at the midpoint
between nodes.
The gradient can be estimated using the
concentration values at the neighboring nodes
and the distance between the nodes.
m-1,n
m,n
m+1,n
Evaluate
gradient here
Thus,
C
x
C
x

m  12 , n
MSE 430 © 2006, J.C.LaCombe
x
m  12
(3)
m  12
C(x)

m  12 , n
Cm 1,n  Cm,n
Cm ,n  Cm 1,n
x
(4)
m-1
m
x
m+1
x
7
The Diffusion Equation Discretizing the Spatial Derivatives
Equations (3) and (4) can now be substituted into (2) to produce the
discretized form of the 2nd spatial derivative in the x direction.
 2C
x 2

m,n
Cm 1,n  Cm 1,n  2Cm,n
(5a)
x 
2
The 1st and 2nd derivatives in the y (and z) directions can also be evaluated
in a similar manner…
 2C
y 2

m,n
Cm ,n 1  Cm ,n 1  2Cm,n
(5b)
y 
2
These make up the RHS
of Fick’s 2nd Law (Eq. 1)
MSE 430 © 2006, J.C.LaCombe
8
The Diffusion Equation Discretizing the Time Derivative
Now that we have discretized Fick’s 2nd law in space (1), we must
discretize it in time as well. To do this, we will introduce a new variable,
p, that is an integer that represents the time step. The duration of each step
is t. Thus, the total time, t, is written…
t  pt
(6)
The finite-difference approximation to the time derivative (the LHS of
Fick’s 2nd law) is then expressed as…
This is the LHS of Fick’s
2nd Law (Eq. 1)
p 1
p
C Cm ,n  Cm ,n

t
t
(7)
The superscript, p, denotes the time dependence. The time derivative is
expressed in terms as the difference in concentrations between the new
time (step p+1) and the previous time (step p).
MSE 430 © 2006, J.C.LaCombe
9
Fick’s 2nd Law in
Discretized Form
The 2-D Diffusion Equation
We present here a solution approach known as the explicit method. In this
finite-difference scheme, the concentration at any node m,n at time t+t is
calculated from knowledge of the concentration at the same and
neighboring nodes for the preceding time t.
We now can combine (5a,b) and (7) to produce the discretized form of the
diffusion equation, (1).
Fick’s 2nd Law in discretized form...
p 1
p
p
p
p
p
p
p
1 Cm ,n  Cm ,n Cm 1,n  Cm 1,n  2Cm ,n Cm ,n 1  Cm,n 1  2Cm ,n


2
D
t
x 
y 2
(8)
Note:
Other approaches, such as the implicit method, are more efficient with
a computer, but require more complex algorithms. Nonetheless, the
fundamental principles are the same as we are applying here. We will
not be covering these other methods in this course.
MSE 430 © 2006, J.C.LaCombe
10
The Fourier Number
The Diffusion Equation
Equation (8) is the general form of our solution. We can simplify the
notation a bit if we use square elements, so that x = y. Additionally, we
can form the following group of parameters, which is commonly known
as the dimensionless Fourier Number, Fo.
Fo 
Dt
x 2
(9)
Now, we can re-arrange (8) to solve for the concentration in node m,n at
the new time step, p+1. This equation applies to any element/node on the
interior of a component. The expression simplifies to…
2-D Interior
Node


Cmp,n1  Fo Cmp1,n  Cmp1,n  Cmp,n1  Cmp,n1  1 4FoCmp,n
(10)
The NEW composition in an element is calculated using the PREVIOUS
compositions in the element and its neighbors.
MSE 430 © 2006, J.C.LaCombe
11
Explicit Method &
Solution Stability
The 1-D Diffusion Equation
For the case of 1-D transport, Equation (8) would instead develop into the
form of
1-D Interior
Node


Cmp 1  Fo Cmp1  Cmp1  1  2 FoCmp
(11)
The accuracy of finite-difference solutions may be improved by
decreasing the values of x and t (I.e., finer discretization). On the other
hand, making these values larger will allow the calculation to proceed
more quickly.
One additional limitation of the explicit method is that it is not always a
stable solution. If the values of x and t are not small enough, it can
cause the solution to oscillate (even when this is physically impossible).
MSE 430 © 2006, J.C.LaCombe
12
Stability Criteria
Critical Values of Fo
To prevent such erroneous results when the solution is “unstable”, the
values of x and t must meet certain criteria (details omitted). For
interior nodes, these are,
Fo 
1
2
1-D Stability
Criteria
Fo 
1
4
2-D Stability
Criteria
Recalling,
Fo 
Dt
x 2
So, once you pick a value of either x or t , the other value must be
chosen so that the stability criteria is met. Simply re-arrange the equation
for Fo to calculate the acceptable value.
MSE 430 © 2006, J.C.LaCombe
13
Other Element Configurations
The equations presented so far (10, 11) are for
interior nodes. I.e., each element’s surroundings are
geometrically the same in all directions.
We can develop similar equations for different element
types, but we need to be clever, or it gets messy.
A surface node (with no flux flowing through the
surface), can be modeled using the same equation as an
interior node. All we need to do is include an imaginary
node just outside the surface and set its composition to the
same as the node just inside the surface. This has the effect
of producing a zero net gradient through the surface.
m-1,n+1 m,n+1
m-1,n
m,n
External Surface
(zero-flux plane)
Zero-Flux Elements
and Surfaces
m-1,n-1 m,n-1
m  12
m-1
m
m+1
Imaginary
node
I.e., if the surface node is C mp then the no-flux condition is modeled by
adding an imaginary node at m+1 and setting Cmp1  Cmp1 to achieve a state
of no-flux at node m (no gradient means no net flux).
MSE 430 © 2006, J.C.LaCombe
14
Zero-Flux Elements
and Surfaces
Other Element Configurations
So, we can model a surface node by modifying the equation for an interior
node. Recalling Equation (10) for 2-D,
2-D Interior
Node


Cmp,n1  Fo Cmp1,n  Cmp1,n  Cmp,n1  Cmp,n1  1 4FoCmp,n
(10)
We then incorporate the imaginary node…
Cmp1  Cmp1
And are left with the equation for a surface node…
2-D Surface
Node


Cmp,n1  Fo 2Cmp1,n  Cmp,n1  Cmp,n1  1  4FoCmp,n
(12)
In 1-D, this would work out to…
1-D Surface
Node
MSE 430 © 2006, J.C.LaCombe


Cmp 1  Fo 2Cmp1  1  2 FoCmp
(13)
15
Other Solution
Approaches
Developing Expressions for Other
Element Types
The method used on the previous slides to discretize the problem is not the
only way to produce equations such as Equations (10)-(13).
Another method can be used to provide even greater flexibility with
boundary conditions. It is simply based on conservation of mass (Recall
that Fick’s 2nd law is also essentially this as well).
Let us consider the element surrounding each node to be subject to
conservation of mass. This would be written as…
Solid State
Diffusive Flux
+
Solute
“Generated”
=
Stored
Mass
In practice, this can be
something like solute
entering an element at
external surface
MSE 430 © 2006, J.C.LaCombe
16
Other Solution
Approaches
Other Ways to Discretize
the Problem
Writing this for a generic interior node, we account for all possible
influences. As before, minor changes can be made for an external node.
Note that here, flux into the node is considered “positive”.
J n 1
J m1 A  J m1 A  J n1 A  J n1 A  M gen  C stored Ax
M gen
J m 1
(14)
J m 1
C stored
Where,
C stored 
Cmp,n1  Cmp,n
J n 1
J m 1   D
J m 1   D
MSE 430 © 2006, J.C.LaCombe
t
Cmp,n  Cmp1,n
x
Cmp,n  Cmp1,n
x
"Created"
M gen  Mass
per unit time
J n 1   D
J n 1   D
Cmp,n  Cnp1,n
y
Cmp,n  Cnp1,n
y
17
Diffusion with “Mass
Generation”
Other Ways to Discretize
the Problem
When massaged, Equation (14) evolves into the same form as the earlier
equations (10)-(13), except now, we have added in the solute generation
term.


Cmp,n1  Fo Cmp1,n  Cmp1,n  Cmp,n1  Cmp,n1  M gen  1 4FoCmp,n
(15)
And in 1-D, this is


Cmp1  Fo Cmp1,n  Cmp1,n  M gen  1 2FoCmp,n
(16)
Thus, there are a variety of approaches to produce the discretized diffusion
equations for a variety of different element types.
MSE 430 © 2006, J.C.LaCombe
18
Example
1-D Thick Diffusion Couple
An earlier topic presented the analytical solution to the case of a binary
diffusion couple. Let’s analyze this using a finite-difference model.
Assume D = 110-9 cm2/s, and the initial compositions are Cl = 0.75, and
CR = 0.25.
Cl  0.75
1
2
3
4
5
6
CR  0.25
x
110-3 cm
First, the stability criteria for this 1-D arrangement is that Fo  ½.
D t 1
Fo 

2
x  2


1 110 3 cm
t 
9 cm 2
2 110 s
2
t  500s
MSE 430 © 2006, J.C.LaCombe
Thus the maximum time step for a stable
solution of this problem is 500 seconds.
19
Example
1-D Thick Diffusion Couple
(1-D Interior Node)
p 1
p
p
p
Equation (11) is the suitable solution form: Cm,n  FoCm1  Cm1  1  2FoCm
To handle the “infinite” ends, we treat them as having no-flux conditions
(I.e., the concentration gradient is zero at the ends) using Equation (13).
This will be ok, provided that the concentration field never reaches the end
during our simulation. The equations are written for each of the 6
elements…
 
 FoC  C   1  2 Fo C
 FoC  C   1  2 Fo C
 FoC  C   1  2 Fo C
 FoC  C   1  2 Fo C
 Fo2C   1  2 Fo C
C1p 1  Fo 2C2p  1  2 Fo C1p
C2p 1
C3p 1
C4p 1
C5p 1
C6p 1
MSE 430 © 2006, J.C.LaCombe
p
3
p
1
p
2
p
4
p
2
p
3
p
5
p
3
p
4
p
6
p
4
p
5
p
5
p
6
These 6 equations must be
solved at each time step, p.
There will be one equation
for each node. Models with
lots of elements involve
solving lots of equations.
20
Example
1-D Thick Diffusion Couple
This is expressed more concisely in matrix form.
2 Fo
0
0
0
0  C1p  C1p 1 
1  2 Fo
 Fo
  p   p 1 
1

2
Fo
Fo
0
0
0

 C2  C2 
 0
Fo
1  2 Fo
Fo
0
0  C3p  C3p 1 

  p    p 1 
0
0
Fo
1

2
Fo
Fo
0

 C4  C4 
 0
0
0
Fo
1  2 Fo
Fo  C5p  C5p 1 

  p   p 1 
0
0
0
2 Fo 1  2 Fo C6  C6 
 0
The new concentrations at each node are calculated by solving this matrix at each
time step. At each step, you use the resulting concentrations from the previous
step, Cp+1, as the new values of Cp. Likewise, to get it all started, you just use the
initial concentrations at each node.
You can use whatever methods or software you want to solve the matrix.
Even a spreadsheet will work…
MSE 430 © 2006, J.C.LaCombe
21
Example
1-D Thick Diffusion Couple
MS Excel Worksheet…
Fo= 0.05
p=1
Node
1
0.9
2
0.05
3
4
5
6
0.1
0.9
0.05
dt
50
Old C New C
0.75
0.750
0.05
0.75
0.750
0.9 0.05
0.75
0.725
0.05 0.9 0.05
0.25
0.275
0.05 0.9 0.05 0.25
0.250
0.1 0.9
0.25
0.250
0.8
p=1
p=2
0.7
p=3
p=4
p=3
p=4
1
2
3
4
5
6
0.9
0.05
1
2
3
4
5
6
0.9
0.05
1
2
3
4
5
6
0.9
0.05
0.1
0.9
0.05
0.1
0.9
0.05
0.1
0.9
0.05
0.75
0.75
0.725
0.275
0.25
0.25
0.750
0.749
0.704
0.296
0.251
0.250
0.75
0.05
0.7488
0.9 0.05
0.7038
0.05 0.9 0.05
0.2963
0.05 0.9 0.05 0.2513
0.1 0.9
0.25
0.750
0.747
0.686
0.314
0.253
0.250
0.7499
0.05
0.7466
0.9 0.05
0.6856
0.05 0.9 0.05
0.3144
0.05 0.9 0.05 0.2534
0.1 0.9 0.2501
0.750
0.744
0.670
0.330
0.256
0.250
0.05
0.9 0.05
0.05 0.9 0.05
0.05 0.9 0.05
0.1 0.9
Double-click above (ppt only) to
open the actual spreadsheet!
MSE 430 © 2006, J.C.LaCombe
C
0.6
p=2
Initial
Exact 200s
0.5
0.4
Fo = 0.05
0.3
0.2
1
2
3
4
5
6
Node
Recalling the Analytical Solution,
 x
 C  CR 
C ( x, t )   l
 erfc 
 2 
 2 Dt

  CR

22
2-D Equation
Summary
m,n+1
2-D Explicit Finite Difference
Equations (x=y)
m,n+1
Interior Node
m,n
m,n
m-1,n
Stability Criterion
m+1,n
Fo 



m,n+1
Exterior Corner
m,n
m,n
Stability Criterion
m-1,n
m+1,n
Fo 
m-1,n
1
4
p
m 1, n
 2C
1  4 Fo C
MSE 430 © 2006, J.C.LaCombe
Stability Criterion
m+1,n
Fo 
1
4
m,n-1
m,n-1


1  4 Fo Cmp,n
Interior Corner
m,n+1
 Fo C
1
4
Cmp,n1  Fo 2Cmp1,n  Cmp,n 1  Cmp,n 1
1 4 Fo Cmp,n
C
Fo 
m+1,n
m,n-1
Cmp,n1  Fo Cmp1,n  Cmp1,n  Cmp,n 1  Cmp,n 1
2
3
Stability Criterion
m-1,n
1
4
m,n-1
p 1
m,n
Plane Surface
p
m,n
p
m 1, n
 2C
p
m , n 1
C
p
m , n 1


Cmp,n1  2 Fo Cmp1,n  Cmp,n 1

1  4 Fo Cmp,n
23