[关闭]
@355073677 2016-05-21T11:52:23.000000Z 字数 3984 阅读 1396

Chapter 5 Problem 5.7: Jacobi method and SOR algorithm

计算物理


Name:陈锋
Student Number: 2013301020145
May 21, 2016

Abstract

This article made a comparsion between Jacobi method and SOR algorithm to solve partial differential equation. Also, it compared the number of iterations and figured out the relation between the number of iterations and the number of grid elements.

Introduction

As we known, the electric potential satisfies Laplace's equation in the space without any electric charges.


Numerically, we get that:

Specially, for the 2-dimensional case:

Jacobi Method

If we only use the old potential to calculate the new one, the formula becomes:


This is what we called Jacobi method.

SOR algorithm

Obviously, we can make use of the new values as they become available, which means:


We can then think of

as the change recommend by the Gauss-Seidel algorithm. However, this choice is too conservative. So to speed up convergence we will change he potential by a larger amount calculated according to

This is what we called SOR algorithm. Generally, we set for the Dirichlet boundary conditions.

Setting initial value and boundary conditions

Firstly, I set a crawler to get the initial value and boundary conditions which have been set in a .txt file.
figure_1
Figure 1: This is the initial value and boundary conditions in the case of FIGURE 5.6 of textbook. The potential of boundaries is zero. In the inner space, there are two capacitor plates held at (left plate) and (right plate).
Here is the core code:

  1. def initialization(self,initial_file):
  2. itxt= open(initial_file)
  3. self.lattice_in = []
  4. self.lattice_out = []
  5. for lines in itxt.readlines():
  6. lines=lines.replace("\n","").split(",")
  7. self.lattice_in.append(lines[0].split(" "))
  8. self.lattice_out.append(lines[0].split(" "))
  9. itxt.close()
  10. for i in range(len(self.lattice_in)):
  11. for j in range(len(self.lattice_in[i])):
  12. self.lattice_in[i][j] = float(self.lattice_in[i][j])
  13. self.lattice_out[i][j] = float(self.lattice_out[i][j])
  14. return 0

Solving the partial differential equation of two capacitor plates

Use both of these method, we can easily solve the problem of the potential near two capacitor plates.
figure_2
Figure 2: Solving the problem in the 11*11 grids.
figure_3
Figure 3: Enlarging the grids to 26*26 leads to smoother equipotential curve and a finer structure of electric field.

The relationship between the number of iterations and that of grid elements

In this section, I will make a discussion on the relationship between the number of iterarions and that of grid elements. For convenience, all the grids I used to solve equation is square grids.
figure_4
Figure 4: The fitting results are for the blue curve and for the red one, which means the number of iteration is proportional to for jacobi method and is proportional to for SOR algorithm.
Therefore, the larger grid we used, the bigger advantage of SOR algorithm would be showed.

The Convergence speed

On the other hand, we can make a comparison of the convergence speed of these methods.
figure_5
Figure 5: The convergence speed of SOR algorithm is much larger than that of jacobi method.

The of SOR algorithm

Additionally, I make a discussion of the relation between the number of iteration and the value of .
figure_6
Figure 6: In this case, I set the length of grid is 26, which means the value of is about 1.784. Obviously, this is not the best choice to decrease the number of iterations.

Reference

1.Giodano, N.J., Nakanishi, H. Computational Physics. Tsinghua University Press, December 2007.
2.Matplotlib Gallery, http://matplotlib.org/gallery.html

Programme Code

Initial value files

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注