Professional Documents
Culture Documents
Lecture 4
Lecture 4
1
Lecture 4: What we will learn
2
Treatment of Non-Linear Sources
d 2f
Recall our governing equation
2
= Sf
dx
In general, the source term could be a function of both x and f. In some
cases, the source term could be a non-linear function of f.
This equation can only be solved iteratively using the following procedure
Ø Guess value of f at all nodes (= fi*)
Ø Evaluate the non-linear source (RHS) using guess: exp(fi*)
Ø Solve tri-diagonal system of equations and obtain new fi
Ø Repeat procedure until convergence
3
Treatment of Non-linear Sources
Unfortunately, with this procedure, convergence is often very slow or not
attained.
A better approach is to linearize the source using a Taylor Series
expansion. Note that this is, in fact, the principle of the Newton’s method
for solving non-linear equations, to be discussed later.
Using a Taylor Series expansion, we can write
*
dSf
Sf (f ) » Sf (f *) + (f - f *)
df
fi +1 - 2fi + fi -1
Therefore = exp(fi
*
) + exp(fi
*
)(fi - f *
i )
(Dx) 2
é 2 ù 1 1
Rearranging êexp(fi* ) + f
2 ú i
- f
2 i +1
- f
2 i -1
= exp(fi
*
)[fi - 1]
*
2 1 1
f
2 i
- f
2 i +1
- f = - exp(-fi )
2 i -1
(Dx) ( Dx) ( Dx)
6
Treatment of Non-linear Sources
Step 3: Write the source term in “equation of a line” form
2 1 1
f - f - f = exp( -f *
) f - exp( -f *
) - exp( -f *
)f *
(Dx) 2
i
(Dx) 2
i +1
( Dx) 2
i -1
i i
i i
i
SP SC
Step 4: Modify the diagonal and source using the following logic
Recall that the algebraic equation we are trying to solve iteratively for the
interior nodes is
fi +1 - 2fi + fi -1
= exp(fi ) "i = 2,..., N - 1
(Dx) 2
fi +1 - 2fi + fi -1
Ri = exp(fi ) - "i = 2,..., N - 1
(Dx) 2
9
Convergence
Performing an IF check on the residual of each node would be
computationally expensive.
One alternative would be to perform an IF check on the net residual, i.e.,
combined residual of all the cells.
However, simply adding the residuals of the individual nodes will not work
because the residuals may be positive or negative. Therefore, adding
them might result in a small number (and a false message).
Therefore, the most common way of calculating the net residual is to
square the nodal residuals and then add them. This is referred to as the L2
norm or L2 norm, and is defined as
2
é fi +1 - 2fi + fi -1 ù
R2 = å i
êexp(fi ) -
ë ( Dx ) 2 ú
û
Convergence means getting R2 down to a small enough value.
A converged solution implies that the governing algebraic equations have
10
been satisfied.
Convergence
A typical plot of the residuals on a semi-log scale looks as follows:
-5
Log10(R2)
-10
Note: Do not use DO WHILE (R2 > tolerance) logic. This has the danger
of the iteration going into an infinite loop.
Instead, use dual logic:
DO WHILE (R2 > tolerance .AND. Iteration# < max_iterations)
12
Newton’s Method
Newton’s method is the most prolific method for finding roots of non-linear
equations. It uses a gradient based algorithm to approach the root.
Let’s first review Newton’s method for a single non-linear equation
(scalar case). We desire to find the roots of the equation
f ( x) = 0
Since this is a non-linear equation of arbitrary form, we must start with a
guess for f, and then perform iterations to approach the root in some
manner. Let the initial guess for the root be x*
Using a Taylor series expansion, we can write
*
df
f ( x) = f ( x ) +
*
( x - x* ) + ...
dx
One approach to solving f(x) = 0 is to instead set the RHS of the above
equation to zero, and solve the resulting equation for a change in f, i.e.,
* *
df d f 2
(Dx) 2
0 = f ( x* ) + (Dx) + 2 + ... where Dx = x - x*
dx dx 2 13
Newton’s Method
Unfortunately, this equation is also a non-linear equation (albeit in
polynomial form) and is equally difficult to solve.
In order to make a solution possible, we drop all non-linear terms in the
equation such that *
f (x )
df
*
x=x - *
*
f (x ) +
*
(Dx) » 0 or df
dx
dx
Since the higher-order terms have been dropped, the above equation is
not the same as the equation at the bottom of the previous page.
Therefore, its solution will only give an approximate value for the root.
However, it is easy to see graphically that this root is closer to the actual
root than the initial guess
Initial guess for The process may be repeated
Actual
root root, x* by replacing the initial guess
f(x)
by the new estimate, i.e.,
iterations
Root after 1 linear
14
approximation
Newton’s Method for Coupled Non-Linear Equations
The approach discussed earlier for a single unknown (scalar case) can be
extended to multiple unknowns (vector case).
fi +1 - 2fi + fi -1
Note that = exp(fi ) is a non-linear set of equations with
( Dx ) 2
As in the scalar case, we now solve for the RHS equal to zero, but after
neglecting the higher order terms. After some rearrangement, and after
writing the resulting equation in matrix form, this yields
16
Newton’s Method for Coupled Non-Linear Equations
é ¶f * * *
ù é Df1 ù é f (f *
)ù
¶f1 ¶f1 ê
1
ê 1 ... ú ê Df ú * ú
ê ¶f1 ¶f2 ¶fN úê 2 ú ê f 2 (f ) ú
ê ê ú ê. ú
*ú .
ê ¶f 2
*
¶f 2
*
¶f 2 úê ú ê ú
ê ¶f ¶f2
...
¶fN ú ê. ú = - ê. ú [J ][ Df ] = -[ f (f * )]
ê 1 ú ê. ú ê ú
ê . ú
ê . . ... . úê ú
ê ú ê . ú ê. ú
ê ¶f N
* * *
úê . ú ê ú
¶f N ¶f N ê . ú
ê ... úê ú
êë ¶f1 ¶f2 ¶fN úû êë DfN úû ê f (f * ) ú
ë N û
The square matrix on the LHS is called the Jacobian matrix (J). Its
determination requires all individual partial derivatives.
The above equation represents a set of linear algebraic equations that can
be solved using Gaussian Elimination to yield the solution for Df.
Update solution using f = f * + Df
17
Newton’s Method for Coupled Non-Linear Equations
Solution Algorithm
1. Start with guessed value for all, 𝜙 (&) (= 𝜙 ∗), and set 𝑙 = 0
2. Calculate 𝑓 𝜙 (")
3. Calculate [𝐉 (") ] (Derive partial derivatives analytically)
𝑙 =𝑙+1 " "
4. Solve 𝐉 ∆𝜙 = −𝑓 𝜙 (")
5. Update Solution: 𝜙 ("#$) = 𝜙 (") + ∆𝜙 (")
6. Repeat Steps 2-5 until convergence
As before, convergence may be enforced by calculating the L2norm
and monitoring it. In this case, the L2norm is simply
R2 = å[ f i ]
i
2
𝑖 = 𝑁: 𝜙$ = 𝜙,
2 1
𝑒𝑥𝑝 𝜙' + '
− '
⋯
Δ𝑥 Δ𝑥
1 2 1
= − '
𝑒𝑥𝑝 𝜙- + '
− '
⋯
Δ𝑥 Δ𝑥 Δ𝑥
⋮ ⋮ ⋮ ⋯ ⋮ ⋮
1 2
− '
𝑒𝑥𝑝 𝜙.&$ + ' 19
Δ𝑥 Δ𝑥