33
16. Solution of elliptic partial differential equation

16. Solution of elliptic partial differential equationhomepage.ntu.edu.tw/~wttsai/fortran/ppt/16.Elliptic_PDE.pdfphysical systems, such as Poisson equation, wave equation, heat equation

  • Upload
    others

  • View
    4

  • Download
    0

Embed Size (px)

Citation preview

Page 1: 16. Solution of elliptic partial differential equationhomepage.ntu.edu.tw/~wttsai/fortran/ppt/16.Elliptic_PDE.pdfphysical systems, such as Poisson equation, wave equation, heat equation

16. Solution of elliptic partial differential equation

Page 2: 16. Solution of elliptic partial differential equationhomepage.ntu.edu.tw/~wttsai/fortran/ppt/16.Elliptic_PDE.pdfphysical systems, such as Poisson equation, wave equation, heat equation

Recall in the first lecture of this course ….

Page 3: 16. Solution of elliptic partial differential equationhomepage.ntu.edu.tw/~wttsai/fortran/ppt/16.Elliptic_PDE.pdfphysical systems, such as Poisson equation, wave equation, heat equation

Assume…• you know how to use a computer to compute;

• but have not done any serious numerical computations,

• and only know some very basic numerics.

This course will teach you…

• FORTRAN programing language to compute,

• good habits to write structural Fortran programs,

• to write test driver to test the Fortran program written by you or others,

• to use well developed and optimized libraries, such as LAPACK, FFTW,

• to do parallel computing in multi-process computer using OpenMP

• to use the these skills to solve partial differential equations governing simple

physical systems, such as Poisson equation, wave equation, heat equation.

Page 4: 16. Solution of elliptic partial differential equationhomepage.ntu.edu.tw/~wttsai/fortran/ppt/16.Elliptic_PDE.pdfphysical systems, such as Poisson equation, wave equation, heat equation

… and using these basic blocks plus some extra hard work, eventually you are able to develop your own numerical program to simulate the more realistic physical system, such as …

Page 5: 16. Solution of elliptic partial differential equationhomepage.ntu.edu.tw/~wttsai/fortran/ppt/16.Elliptic_PDE.pdfphysical systems, such as Poisson equation, wave equation, heat equation

Numerical simulation of flow motion

• A popular tool due to the burst in power of computing.

• Substitute for experiment when measurement is inaccessible.

Page 6: 16. Solution of elliptic partial differential equationhomepage.ntu.edu.tw/~wttsai/fortran/ppt/16.Elliptic_PDE.pdfphysical systems, such as Poisson equation, wave equation, heat equation

velocity: � = � �,�,�,�

= � �,�,�,� �̂+ � �,�,�,� �̂+ � �,�,�,� ��

pressure: � = �(�,�,�,�)

• Property variables to describe the flow:

• Equations governing the flow:

��

��+��

��+��

��= 0 � ⋅� =0

��

��= − � ⋅� � −

1

��� + �� ��

= − �� − �(�)

��

��= − �

��

��− �

��

��− �

��

��−1

��

��+ �

���

���+���

���+���

���

��

��= − �

��

��− �

��

��− �

��

��−1

��

��+ �

���

���+���

���+���

���

��

��= − �

��

��− �

��

��− �

��

��−1

��

��+ �

���

���+���

���+���

���

Governing equations for motion of an incompressible fluid

• 4 unknowns with 4 equations

incompressibility of fluid (solenoidal condition):

momentum conservation:

��

Page 7: 16. Solution of elliptic partial differential equationhomepage.ntu.edu.tw/~wttsai/fortran/ppt/16.Elliptic_PDE.pdfphysical systems, such as Poisson equation, wave equation, heat equation

� ⋅� =0

��

��= − �� − �(�)

• Define velocity and pressure at discrete time instance �� = �Δ�: �� and ��

Numerical solution based on explicit schemeHarlow, F.H. & Welch, J.E., 1965. Numerical calculation of time-dependent viscous incompressible flow of fluid with free surface. Phys. Fluids, 8(12), 2182−2189.

��

��≈��

��=��� � − ��

Δ�≈ − ��� − �(��)

� ⋅�� = 0

i.e., after obtaining �� and �� at �� , marching towards ��� � to get ��� �

• But, 1. How is the solenoidal condition � ⋅�� = 0 satisfied?

2. What is the equation for the pressure ��� � ?

� ⋅��� � − ��

Δ�≈ − ��� − �(��)

• Take divergence of the discretized momentum equation:

Page 8: 16. Solution of elliptic partial differential equationhomepage.ntu.edu.tw/~wttsai/fortran/ppt/16.Elliptic_PDE.pdfphysical systems, such as Poisson equation, wave equation, heat equation

� ⋅��� � − ��

Δ�≈ − ��� − � �� ⟹

� ⋅��� � − � ⋅��

Δ�≈ − � ⋅��� − � ⋅�(��)

• Ideally, � ⋅��� � = 0 and � ⋅�� = 0, since the solenoidal condition � ⋅� = 0 must be satisfied at

every time instance.

∴ − � ⋅��

Δ�≈ − � ⋅��� − � ⋅� �� ⟹ � ��� ≈

1

Δ�� ⋅�� − � ⋅�(��) ≡ �

���

���+���

���+���

���= � �,�,�

• This is an elliptic-type partial differential equation called Poisson equation:

• Take divergence of the time-discretized momentum equation:

• But due to numerical approximation, the solenoidal condition may not be satisfied exactly. Let say,

there is a small value of � ⋅�� at �= �� , i.e., � ⋅�� ≈ 0 but � ⋅�� ≠ 0.

• We then project that � ⋅��� � = 0 at �= ��� �.

• So the solenoidal condition at �= ��� � is satisfied by solving the pressure Poisson equation.

This means that pressure is a tuning property to make sure the flow remain solenoidal.

Page 9: 16. Solution of elliptic partial differential equationhomepage.ntu.edu.tw/~wttsai/fortran/ppt/16.Elliptic_PDE.pdfphysical systems, such as Poisson equation, wave equation, heat equation

��,� = � ��,�� = � � ��� ,��� �� ��� ����

��� �

�� ���

��� �

� � ���

��� ,� =1

1

�� � ��,��

� � �� ��� ����

�� �

�� �

� � �

�� �

�� = � �� = � ��� �� �

����

��� �

� � ���

= � ��� �� �� ��

��� �

� � ���

��� =1

�� ���

� � �����

� � �

�� �

=1

�� ���

� � �� ��

� � �

�� �

Discrete Fourier Transform in Higher Dimension

• One-dimensional:

• Two-dimensional:

0 1 2� =

0 ��

�� − 1

�� = ��

�� =����

�� =��

��

�� =����

� = 0 1 2 �− 1 �� = 0

1

2

�− 1

�� =2�

���

�� =2�

���

��,��

Page 10: 16. Solution of elliptic partial differential equationhomepage.ntu.edu.tw/~wttsai/fortran/ppt/16.Elliptic_PDE.pdfphysical systems, such as Poisson equation, wave equation, heat equation

• Elliptic-type partial differential equation for � = � �,�in a rectangular domain:

���

���+���

���= � �,�

Numerical Solution of Poisson Equation

• Numerical solution of the equation means finding discrete ��,� satisfies the discretized equation:

���

�����,�

+���

�����,�

≈ ��,�

• Discrete representation of the continuous function:

� = � �,� ⟹ ��,� = �(��,��)

� = � �,� ⟹ ��,� = �(��,��)

��

��

�� =����

�� =����

� = 0 1 2 �− 1 �� = 0

12

�− 1�

Page 11: 16. Solution of elliptic partial differential equationhomepage.ntu.edu.tw/~wttsai/fortran/ppt/16.Elliptic_PDE.pdfphysical systems, such as Poisson equation, wave equation, heat equation

Discrete ��,� can be represented by a discrete Fourier series with the coefficients to be determined:

��,� = � � ��̂ ,��� �� ��� ����

��� �

�� ���

��� �

� � ���

Similarly,

��,� = � � ��� ,��� �� ��� ����

��� �

�� ���

��� �

� � ���

Since ��,� are given ⟹ ��� ,� are known.

� = 0,1,2,…,� − 1� = 0,1,2,…,� − 1

Rectangular domain with periodic conditions in both directions

� = 0 1 2 � − 1�� = 0

1

2

� − 1

�� =����

�� =����

�� =2�

��� �� =

2�

���

� = ��

� = ���

���

���+���

���= � �,�

periodicperiodic

periodic

periodic

(��,��)

Page 12: 16. Solution of elliptic partial differential equationhomepage.ntu.edu.tw/~wttsai/fortran/ppt/16.Elliptic_PDE.pdfphysical systems, such as Poisson equation, wave equation, heat equation

• This is valid when � ≠ 0 and � ≠ 0. � = 0 and � = 0 corresponds to the constant mode.

• The solution of the Poisson equation subject to periodic boundary conditions in both direction is indeterminant, i.e. any constant, � �,� = �, can be the solution.

∴ For the well posedness of the problem, ��̂,� ≡ 0.

• Substitute ��,� and ��,� into Poisson equation:���

���+���

���= � �,�

��,� = � � ��̂ ,� �� ����� ����

��� �

�� ���

��� �

� � ���

��,� = � � ��� ,��� �� ��� ����

��� �

�� ���

��� �

� � ���

� � − �����̂ ,� − �����̂ ,� = ��� ,� �� �� ��� ����

��

� � ��� ���̂ ,� �� �� ��� ����

��� �

�� ���

+ � � ��� ���̂ ,��� �� ��� ����

��� �

�� ���

=

��� �

� � ���

� � ��� ,� �� ����� ����

��� �

�� ���

��� �

� � ���

��� �

� � ���

�� =2�

��� �� =

2�

���

�� =������ =

����

• Only need to consider � = 0~�/2 and � = 0~�/2 for real DFT.

∴ ��̂ ,� = −��� ,�

��� + ���⟹ ��,� = � � ��̂ ,� �

� ����� �̃��

��� �

�� ���

��� �

� � ���

Page 13: 16. Solution of elliptic partial differential equationhomepage.ntu.edu.tw/~wttsai/fortran/ppt/16.Elliptic_PDE.pdfphysical systems, such as Poisson equation, wave equation, heat equation

Rectangular domain with periodic condition in one direction and Dirichlet conditions on the other boundaries

���

���+���

���= � �,�

periodicperiodic

� = �(�)= given

� = �(�)= given� = ��

� = ��

0

� �,� = � � + ��,�• Unknown:

� �,0 = � � = � � + �� = given

�(�,��)= � � = � � + �� = given

• Boundary conditions:

Page 14: 16. Solution of elliptic partial differential equationhomepage.ntu.edu.tw/~wttsai/fortran/ppt/16.Elliptic_PDE.pdfphysical systems, such as Poisson equation, wave equation, heat equation

• Since � �,� is periodic in � direction only, it can be represented as:

Similarly,

�� � = � ��,� = � ��� � ���� ��

��� �

� � ���

���

���(��,�)= � − �����̂ � ������

��� �

� � ���

���

���(��,�)= �

����̂ �

���������

��� �

� � ���

� ��,0 = �� ⟹ � ��̂ 0 ������

��� �

� � ���

= � ��� ���� ��

��� �

� � ���

� ��,�� = �� ⟹ � ��̂ �� ������

��� �

� � ���

= � ��� ������

��� �

� � ���

�� � = � ��,� = � ��̂ � �������

��� �

� � ���

= � ��̂ � ������

��� �

� � ���

�� =2�

��� �� = �

���

�� = ����

� = 0 1 2 �� − 1

�� = ��

�� = ��

periodicperiodic

���

���+���

���= � ��,�

Page 15: 16. Solution of elliptic partial differential equationhomepage.ntu.edu.tw/~wttsai/fortran/ppt/16.Elliptic_PDE.pdfphysical systems, such as Poisson equation, wave equation, heat equation

• This is an ordinary differential equation for ��̂ � subject to the

upper and lower boundary conditions of Dirichlet type for different � .

• Only need to consider � = 0 to �/2 for real DFT.

• Substitute the expansions of � ��,� and � ��,� into the Poisson equation:���

���+���

���= � ��,�

• Substitute the expansions of � ��,� ,� �� and � �� into the boundary conditions:

� − �����̂ � +����̂ �

��������� = � ��� � ������

��� �

� � ���

��� �

� � ���

⇒����̂ �

���− �����̂ � = ��� �

� ��,0 = �� ⇒ � ��̂ 0 ���� ��

��� �

� � ���

= � ��� ���� ��

��� �

� � ���

⇒��̂ 0 = ���

� ��,�� = �� ⇒ � ��̂ �� ���� ��

��� �

� � ���

= � ��� ���� ��

��� �

� � ���

⇒��̂ �� = ���

�� =2�

���

��̂ 0 = ���

��̂ �� = ���

����̂���

− �����̂ = ��� �

� = 0

� = ��

Page 16: 16. Solution of elliptic partial differential equationhomepage.ntu.edu.tw/~wttsai/fortran/ppt/16.Elliptic_PDE.pdfphysical systems, such as Poisson equation, wave equation, heat equation

• If use 2nd-order finite-difference scheme to approximate the differentiation of �:

����̂ �����

− �����̂ �� = ��� �� ��̂ ,�� � − 2��̂ ,� + ��̂ ,�� �

△�− �����̂ ,� = ��� ,�

2

1

0

� + 1

� − 1

� − 1

� − 2

• Discretize ��̂ � at � = �� = �Δ, Δ = ��/�, � = 0~�.

The unknowns are ��̂ �� = ��̂ ,�, � = 0~�/2, � = 1~� − 1

��̂ (0)= ���

��̂ (��)= ��� ��̂ ,� = ���

− 2 + ���Δ� ��̂ ,�� � + ��̂ ,�� � = Δ���� ,�� � − ���

��̂ ,� − 2 + ���Δ� ��̂ ,� = Δ���� ,� − ���

�� =2�

���

��̂ ,�� � − 2 + ���Δ� ��̂ ,� + ��̂ ,�� � = Δ���� ,�

��̂ ,� = ���

Page 17: 16. Solution of elliptic partial differential equationhomepage.ntu.edu.tw/~wttsai/fortran/ppt/16.Elliptic_PDE.pdfphysical systems, such as Poisson equation, wave equation, heat equation

� = 0

� + 1

� − 1

� − 1�

� − 2

12

− 2 + ���∆� 1

1 − 2 + ���∆� 1

1 − 2 + ���∆� 1

1 − 2 + ���∆� 1

1 − 2 + ���∆�

��� ,�

��� ,�

⋮��� ,�� �

��� ,�

��� ,�� �

⋮��� ,�� �

��� ,�� �

=

Δ���� ,� − ���⋮⋮

△� ��� ,�� �

△� ��� ,�

△� ��� ,�� �

⋮⋮

Δ���� ,�� � − ���

The discretized equation can be represented as a system of linear equation:

Discretized equation for ��̂ �� = ��̂ ,� :

− 2 + ���Δ� ��̂ ,�� � + ��̂ ,�� � = Δ���� ,�� � − ���

��̂ ,� − 2 + ���Δ� ��̂ ,� = Δ���� ,� − ���

��̂ ,�� � − 2 + ���Δ� ��̂ ,� + ��̂ ,�� � = Δ���� ,�

Page 18: 16. Solution of elliptic partial differential equationhomepage.ntu.edu.tw/~wttsai/fortran/ppt/16.Elliptic_PDE.pdfphysical systems, such as Poisson equation, wave equation, heat equation

− 2 + ���∆� 1

1 − 2 + ���∆� 1

1 − 2 + ���∆� 1

1 − 2 + ���∆� 1

1 − 2 + ���∆�

��� ,�

��� ,�

⋮��� ,�� �

��� ,�

��� ,�� �

⋮��� ,�� �

��� ,�� �

=

Δ���� ,� − ���⋮⋮

△� ��� ,�� �

△� ��� ,�

△� ��� ,�� �

⋮⋮

Δ���� ,�� � − ���

In the above system of equation � � = � , � is real but � and � are complex.

So the real and imaginary parts of the unknown vector can be solved separately as:

� �� = �� and � �� = ��

The (�− 1)× �− 1 matrix is tridiagonal. The linear system can be solved efficiently for various �.

Only need to consider � = 0 to �/2 for real DFT.

Page 19: 16. Solution of elliptic partial differential equationhomepage.ntu.edu.tw/~wttsai/fortran/ppt/16.Elliptic_PDE.pdfphysical systems, such as Poisson equation, wave equation, heat equation

Numerical implementation

• Given the source function of the Poisson equation ��,�, and the lower and upper boundary

values �� and ��, where � = 0~(� − 1)and � = 1~(� − 1)

• Call FFT to compute ��� and ���Loops of � for calling FFT to compute ��� ,�

• Loops of � = 0~�/2 for solving for ��̂ ,�

Loops of �=1~�− 1 to construct the tridiagonal matrix � for each �

end loops in �

Call suitable solver to solve � �� = �� and � �� = �� for ��̂ ,� of each �

end loops of �

• Loops of � for calling inverse FFT to get ��̂,�

Page 20: 16. Solution of elliptic partial differential equationhomepage.ntu.edu.tw/~wttsai/fortran/ppt/16.Elliptic_PDE.pdfphysical systems, such as Poisson equation, wave equation, heat equation

Rectangular domain with periodic condition in one direction and Neumann conditions on the other boundaries

���

���+���

���= � �,�

periodicperiodic

��

��= �(�)= given

��

��= �(�)= given

� = ��

� = ��

0

� �,� = � � + ��,�• Unknown:

��

���,0 = � � = � � + �� = given

��

���,�� = � � = � � + �� = given

• Boundary conditions:

Page 21: 16. Solution of elliptic partial differential equationhomepage.ntu.edu.tw/~wttsai/fortran/ppt/16.Elliptic_PDE.pdfphysical systems, such as Poisson equation, wave equation, heat equation

• Since � �,� is periodic in � direction only, it can be represented as:

Similarly,

�� � = � ��,� = � ��� � ���� ��

��� �

� � ���

���

���(��,�)= � − �����̂ � ������

��� �

� � ���

���

���(��,�)= �

����̂ �

���������

��� �

� � ���

��

����,0 = �� ⟹ �

���̂��

�� �

���� ��

��� �

� � ���

= � ��� ������

��� �

� � ���

��

����,�� = �� ⟹ �

���̂��

�� ��

���� ��

��� �

� � ���

= � ��� ���� ��

��� �

� � ���

�� � = � ��,� = � ��̂ � �������

��� �

� � ���

= � ��̂ � ������

��� �

� � ���

�� =2�

��� �� = �

���

�� = ����

� = 0 1 2 �� − 1

��

���

= ��

��

���

= ��

periodicperiodic

���

���+���

���= � ��,�

Page 22: 16. Solution of elliptic partial differential equationhomepage.ntu.edu.tw/~wttsai/fortran/ppt/16.Elliptic_PDE.pdfphysical systems, such as Poisson equation, wave equation, heat equation

• Again, this is an ordinary differential equation for ��̂ � subject to the

upper and lower boundary conditions of Neumann type for different �.

• Substitute the expansions of � ��,� and � ��,� into the Poisson equation:���

���+���

���= � ��,�

• Substitute the expansions of � ��,� ,� �� and � �� into the boundary conditions:

� − �����̂ � +����̂ �

��������� = � ��� � ������

��� �

� � ���

��� �

� � ���

⇒����̂ �

���− �����̂ � = ��� �

��

����,0 = �� �

���̂��

������

��� �

� � ���

= � ��� ���� ��

��� �

� � ���

⇒���̂��

= ���

��

����,�� = �� �

���̂��

���� ��

��� �

� � ���

= � ��� ������

��� �

� � ���

⇒���̂��

= ���

• Only need to consider � = 0 to �/2 for real DFT.

�� =2�

���

���̂��

= ���

���̂��

= ���

����̂���

− �����̂ = ��� �

� = 0

� = ��

Page 23: 16. Solution of elliptic partial differential equationhomepage.ntu.edu.tw/~wttsai/fortran/ppt/16.Elliptic_PDE.pdfphysical systems, such as Poisson equation, wave equation, heat equation

• If use 2nd-order finite-difference scheme to approximate the differentiation of �:

����̂ �����

− �����̂ �� = ��� ��

��̂ ,�� � − 2��̂ ,� + ��̂ ,�� �

△�− �����̂ ,� = ��� ,�

1

0

− 1

� + 1

� − 1

� + 1

� − 1

• Discretize ��̂ � at � = �� = �Δ, Δ = ��/�, � = 0~�, the unknowns are ��̂ �� = ��̂ ,� , � = 0 to �/2.

���̂��

= ���

���̂��

= ���

��̂ ,�� � − ��̂ ,�� �

2Δ= ��� ��̂ ,�� � = ��̂ ,�� � + 2Δ���

− 2 + ���Δ� ��̂ ,� + 2��̂ ,�� � = Δ���� ,� − 2Δ���

��̂ ,� − ��̂ ,� �

2Δ= ��� ��̂ ,� � = ��̂ ,� − 2Δ���

2��̂ ,� − 2 + ���Δ� ��̂ ,� = Δ���� ,� + 2Δ���

�� =2�

���

��̂ ,�� � − 2 + ���Δ� ��̂ ,� + ��̂ ,�� � = Δ���� ,�

Page 24: 16. Solution of elliptic partial differential equationhomepage.ntu.edu.tw/~wttsai/fortran/ppt/16.Elliptic_PDE.pdfphysical systems, such as Poisson equation, wave equation, heat equation

� = 0

� + 1

� − 1

� − 1�

� − 2

12

The (�+ 1)× �+ 1 matrix is tridiagonal. The linear system can be solved efficiently for various �.

Only need to consider � = 0 to �/2 for real DFT.

− 2 + ���∆� 2

1 − 2 + ���∆� 1

1 − 2 + ���∆� 1

1 − 2 + ���∆� 1

2 − 2 + ���∆�

��� ,�

��� ,�

⋮��� ,�� �

��� ,�

��� ,�� �

⋮��� ,�� �

��� ,�

=

Δ���� ,� + 2Δ���⋮⋮

△� ��� ,�� �

△� ��� ,�

△� ��� ,�� �

⋮⋮

Δ���� ,� − 2Δ���

The discretized equation can be represented as a system of linear equation:

Discretized equation for ��̂ �� = ��̂ ,� :

− 2 + ���Δ� ��̂ ,� + 2��̂ ,�� � = Δ���� ,� − 2Δ���

2��̂ ,� − 2 + ���Δ� ��̂ ,� = Δ���� ,� + 2Δ���

��̂ ,�� � − 2 + ���Δ� ��̂ ,� + ��̂ ,�� � = Δ���� ,�

Page 25: 16. Solution of elliptic partial differential equationhomepage.ntu.edu.tw/~wttsai/fortran/ppt/16.Elliptic_PDE.pdfphysical systems, such as Poisson equation, wave equation, heat equation

− 2 + ���∆� 1

1 − 2 + ���∆� 1

1 − 2 + ���∆� 1

1 − 2 + ���∆� 1

1 − 2 + ���∆�

��� ,�

��� ,�

⋮��� ,�� �

��� ,�

��� ,�� �

⋮��� ,�� �

��� ,�� �

=

Δ���� ,� − ���⋮⋮

△� ��� ,�� �

△� ��� ,�

△� ��� ,�� �

⋮⋮

Δ���� ,�� � − ���

− 2 + ���∆� 2

1 − 2 + ���∆� 1

1 − 2 + ���∆� 1

1 − 2 + ���∆� 1

2 − 2 + ���∆�

��� ,�

��� ,�

⋮��� ,�� �

��� ,�

��� ,�� �

⋮��� ,�� �

��� ,�

=

Δ���� ,� + 2Δ���⋮⋮

△� ��� ,�� �

△� ��� ,�

△� ��� ,�� �

⋮⋮

Δ���� ,� − 2Δ���

• Dirichlet conditions on upper and lower boundaries:

• Neumann conditions on upper and lower boundaries:

Page 26: 16. Solution of elliptic partial differential equationhomepage.ntu.edu.tw/~wttsai/fortran/ppt/16.Elliptic_PDE.pdfphysical systems, such as Poisson equation, wave equation, heat equation

− 2 + ���∆� 2

1 − 2 + ���∆� 1

1 − 2 + ���∆� 1

1 − 2 + ���∆� 1

2 − 2 + ���∆�

��� ,�

��� ,�

⋮��� ,�� �

��� ,�

��� ,�� �

⋮��� ,�� �

��� ,�

=

Δ���� ,� + 2Δ���⋮⋮

△� ��� ,�� �

△� ��� ,�

△� ��� ,�� �

⋮⋮

Δ���� ,� − 2Δ���

For � = 0, ��̂,� = ��̂ �� , i.e. the constant Fourier mode, the coefficient matrix � of the above system of equation � � = � is singular, i.e. det � = 0.

For example, � = 2, − 2 2 01 − 2 10 2 − 2

= − 8 + 4 + 4 = 0

� = 3,

− 2 21 − 2

0 01 0

0 10 0

− 2 12 − 2

= − 2 ×− 2 1 01 − 2 10 2 − 2

−2 0 01 − 2 10 2 − 2

= 4 − 4 = 0

���

���+���

���= � �,�

periodicperiodic

��

��= �(�)= given

��

��= �(�)= given

To fix the problem, i.e. to make the solution unique, a given constant is specified at the grid point.

For example, �(0,0)= ��,� ≡ 0.

�(0,0)= ��,� ≡ 0

Page 27: 16. Solution of elliptic partial differential equationhomepage.ntu.edu.tw/~wttsai/fortran/ppt/16.Elliptic_PDE.pdfphysical systems, such as Poisson equation, wave equation, heat equation

��,� = � ��,�� = �� �� = � ��̂ �� �������

��� �

� � ���

= � ��̂ �� ���� ��

��� �

� � ���

�� =2�

��� �� = �

���

�� = ����

��,� = � 0,�� = � ��̂ ,����

����

��� �

� � ���

= � ��̂ ,�

��� �

� � ���

= 2 � ��̂ ,��

��� �

� � �

+ ��̂�,�

� + ��̂,��

��̂,�� = ��,� − 2 � ��̂ ,�

��� �

� � �

− ��̂�,�

��̂ ,� =1

�� ��,��

� � �����

� � �

�� �

⇒��̂,� =1

�� ��,�

� � �

�� �

∈ ℝ⇒��̂,�� = 0

To implement the solvability condition � 0,0 = ��,� ≡ 0:

For � = 0

��̂,�� = ��,� − 2 � ��̂ ,�

��� �

� � �

− ��̂�,�

solutions of � ≠ 0 modes

∴ ��̂,� are treated after solving for ��̂ ,�, � ≠ 0.

Page 28: 16. Solution of elliptic partial differential equationhomepage.ntu.edu.tw/~wttsai/fortran/ppt/16.Elliptic_PDE.pdfphysical systems, such as Poisson equation, wave equation, heat equation

• After obtain ��̂,� = ��̂,�� , the other ��̂,� can be evaluated:

����̂ �����

− 0���̂ �� = ��� ��

��̂,�� � − 2��̂,� + ��̂,�� �△�

− 0���̂,� = ���,�

1

0

− 1

� + 1

� − 1

� + 1

� − 1

���̂��

= ���

���̂��

= ���

��̂,�� � − ��̂,�� �2Δ

= ��� ⇒ ��̂,�� � = ��̂,�� � + 2Δ���

��̂,� =��̂,�� � + Δ��� −1

2����,�

��̂,� − ��̂,� �2Δ

= ��� ⇒ ��̂,� � = ��̂,� − 2Δ���

��̂,�� � = 2��̂,� − ��̂,�� � + Δ����,�

��̂,�� = ��,� − 2 � ��̂ ,�

��� �

� � �

− ��̂�,�

��̂,� = 2��̂,�� � − ��̂,�� � + Δ����,�� �

��̂,� = 2��̂,� − ��̂,� � + Δ����,�

��̂,� =��̂,� + Δ��� +1

2����,�2

Page 29: 16. Solution of elliptic partial differential equationhomepage.ntu.edu.tw/~wttsai/fortran/ppt/16.Elliptic_PDE.pdfphysical systems, such as Poisson equation, wave equation, heat equation

Numerical implementation

• Given the source function of the Poisson equation ��,�, and the lower and upper boundary

derivative values �� and ��, where � = 0~� − 1 and � = 0~�

• Call FFT to compute ��� , ���Loops of � for calling FFT to compute ��� ,�

• Loops of � = 1~�/2 for solving for ��̂ ,�

Loops of �=0~� to construct the tridiagonal matrix � for each �

end loops in �

Call suitable solver to solve � �� = �� and � �� = �� for ��̂ ,� of each �

end loops of �

• The constant modes ��̂,� need to be treated after solving ��̂ ,�,� ≠ 0

Compute ��̂,��

Loops of �=1~� to compute ��̂,� for � = 0

end loops in �

• Loops of � for calling inverse FFT to get ��̂,�

Page 30: 16. Solution of elliptic partial differential equationhomepage.ntu.edu.tw/~wttsai/fortran/ppt/16.Elliptic_PDE.pdfphysical systems, such as Poisson equation, wave equation, heat equation

• Invent a known analytical function �� �,� and compute analytically the right-hand-side source function of the Poisson equation �(�,�):

The first approach:

Two approaches to test the Poisson solver

• Such an approach can be used to test the convergence of the solver by increase the grid points.

� �,� =���′

���+���′

���

• Given the analytical source function ��,�and the boundary conditions at ��and ��, the

Poisson equation is then solved for ��,�, and the numerical solution is compared with the

known function ��,�� .

���

�����,�

+���

�����,�

≈ ��,�

�� =����

�� =����

� = 0 1 2 �− 1 �� = 0

12

�− 1�

� �,0 = �′ �,0

� �,�� = �′ �,��

��

���,0 =

��′

���,0

��

���,�� =

��′

���,��

or

and the boundary conditions:

Page 31: 16. Solution of elliptic partial differential equationhomepage.ntu.edu.tw/~wttsai/fortran/ppt/16.Elliptic_PDE.pdfphysical systems, such as Poisson equation, wave equation, heat equation

• Generate the solutions ��,�� using random numbers.

The second approach:

• Given the source function ��,� and the boundary conditions the Poisson equation is then solved

numerically:

• The source function ��,� and the boundary conditions are then computed numerically using

spectral scheme in the periodic direction and finite-difference scheme in the non-periodic direction.

��,� =���′

�����,�

+���′

�����,�

spectral finite-difference

• The numerical results ��,�should be equal to the original given random numbers ��,�� since the

forward (computing the source function) and inverse (solving the equation) operators are identical.

• Such an approach is for debugging the code.

���

�����,�

+���

�����,�

= ��,�

�� =����

�� =����

� = 0 1 2 �− 1 �� = 0

12

�− 1�

or

• Also generate the boundary conditions using random numbers:

��,� = ��,��

��,� = ��,��

��

���,�

=��′

���,�

��

���,�

=��′

���,�

finite-difference

Page 32: 16. Solution of elliptic partial differential equationhomepage.ntu.edu.tw/~wttsai/fortran/ppt/16.Elliptic_PDE.pdfphysical systems, such as Poisson equation, wave equation, heat equation

■ Write a subroutine solving Poisson equation in a rectangular domain, as shown in the figure below, with

periodic boundary conditions in the � direction, Dirichlet condition on the upper boundary, and Neumann

condition on the lower boundary.

■ Use routine in Lapack to solve the tridiagonal system of linear equation (e,g, dgtsv).

■ Use FFFTW to do discrete Fourier transform.

■ In calling the subroutine, the following data are input :

• the lengths the rectangular domain in � and � directions:�� and ��

• the numbers of discrete grids in � and � directions: � and �

• the right-hand side of the Poisson equation: ��,�, � = 0~(� − 1), � = 0~�

• the values on the lower and upper boundary conditions: �� and �� , � = 0~(� − 1)

■ Write a test driver (use the second approach) to assess the maximum error calling the subroutine to confirm if

the Poisson solver has been implemented correctly. Use random numbers between − 1 and 1.

Homework

��

��

���

���+���

���= � �,�

periodic in �

� = �

��

��= �

periodic in �

� = 0 1 2 �(� − 1) � = 0

1

2

(� − 1)

Page 33: 16. Solution of elliptic partial differential equationhomepage.ntu.edu.tw/~wttsai/fortran/ppt/16.Elliptic_PDE.pdfphysical systems, such as Poisson equation, wave equation, heat equation