You are on page 1of 12

Computational Modeling for Geosciences

Meysam Shahraki

Institute of Earth Sciences


Goethe University of Frankfurt am Main

computational geodynamics
Goethe University of Frankfurt
Numerical methods in geosciences

Review: explicit FD schemes

left-side unknown quantities


(all quantities at time n+1).

right-side known quantities


(all quantities at time n). forward time, centered space (FTCS)
Numerical methods in geosciences

Implicit FD schemes

Note:

explicit implicit
Numerical methods in geosciences

Implicit FD schemes

explicit implicit

The main advantage of implicit methods is that there are no restrictions on


the time step, the fully implicit scheme is unconditionally stable. BUT, this
does not mean that it is accurate. need to check !
Numerical methods in geosciences

Implicit FD schemes

Note the analogy

forward or backward differences were only


first order accurate, while the central difference
approach achieved second order accuracy

The Crank-Nicolson method is the time analog


of central spatial differences.
Numerical methods in geosciences

1D implicit heat equation

= thermal diffusivity

Initial condition

Dirichlet boundary
Boundary condition
condition

Neumann boundary
condition
Numerical methods in geosciences

Solving an implicit FD scheme

Step # 1 : discretization

Step # 2 :
replace the continuous derivatives with their finite difference approximations

Step # 3 :
rearrangement of the discretized equation.
Numerical methods in geosciences

Implicit FD schemes
Step # 4 :
specify the boundary conditions.

Step # 4 and #5 can be written together in matrix form as .

For example, with a six-node grid, the coefficient matrix A, unknown temperature
vector x and the known right-hand-side vector b are

Dirichlet (fixed temperature) B.C.


Numerical methods in geosciences

Implicit FD schemes
Some notes

Matrix A will have a unity entry on the diagonal and zero else for each node
where Dirichlet (fixed temperature) boundary conditions apply.

Matrix A has a special form because most entries off the diagonal are zero.
Such a matrix is called a sparse matrix. It is important to take advantage
of the sparsity.

The fully implicit FD scheme leads to a “tridiagonal” system of linear equations


that can be solved efficiently by LU decomposition.
Numerical methods in geosciences

Matlab script for implicit FD scheme


Writing a Matlab script for 1D heat equation
with an implicit FD scheme

First, we have to construct the matrices and vectors.

The coefficient matrix, A can be constructed with a


simple loop:

A sparse matrix is a matrix that allows special techniques to


take advantage of the large number of zero elements.
In Matlab we initializing it with the sparse function.
Numerical methods in geosciences

Matlab script for implicit FD scheme


and the boundary conditions are set by:

Once the coefficient matrix has been constructed, its structure can be
visualized with spy(A) command.

The right-hand-side vector b can be constructed with

The only thing that remains to be done is to solve the system of equations and
find x. MATLAB does this with

x is now filled with new temperatures, and we can go to the next time step.
Numerical methods in geosciences

analytical solution for the heat equation


If the initial temperature distribution is:

where 𝑇𝑚𝑚𝑚 is the maximum amplitude of the temperature perturbation


at 𝑥 = 0 and 𝜎 its half-width of the perturbance (𝜎 = 𝑤/2).

The solution is then:

Program the analytical solution and compare the analytical solution with
the numerical solution with the same initial condition.

You might also like