312 CHAPTER 16. PARTIAL DIFFERENTIAL EQUATIONS
programs/chap16/program2.f90
! Program to solve the 2 dim Laplace equation using i t e r a t i o n .
! No time dependence .
! I n i t i a l c onditions are read in by the functi on i n i t i a l i s e
! such as number of st ep s in the x direction , y direction ,
! xmin and xmax , ymin and ymax . Here we employ a square l a t t i c e
! with equal number of steps in x and y dir e c tio n s
! Note the s t ru ctur e of th i s module , i t contains various
! subrou tines for i n i t i a l i s a t i o n of the problem and sol uti on
! of the PDE with a given i n i t i a l f unct io n for u ( x , y )
MODULE two_dim_laplace_equation
DOUBLE PRECISION, PRIVATE : : xmin , xmax , ymin , ymax
INTEGER, PRIVATE : : ndim , i t e r a t i o n s
DOUBLE PRECISION, ALLOCATABLE, DIMENSION( : , : ) , PRIVATE : : u ,
u_temp
CONTAINS
! t h is f unct ion reads in the s i ze of l a t t i c e , xmin , xmax ,
! ymin and ymax and the number of i t e r a t i o n s
SUBROUTINE i n i t i a l i s e
IMPLICIT NONE
WRITE( , ) ’ read in number of mesh points in x and y di re ction
’
READ( , ) ndim
WRITE( , ) ’ read in xmin and xmax ’
READ( , ) xmin , xmax
WRITE( , ) ’ read in ymin and ymax ’
READ( , ) ymin , ymax
WRITE( , ) ’ read in max number of i t e r a t i o n s ’
READ( , ) i t e r a t i o n s
END SUBROUTINE i n i t i a l i s e
SUBROUTINE solve_2dimlaplace_equation ( func )
DOUBLE PRECISION : : h , x , y , pi , length , d i f f
INTEGER : : i , j , l
INTERFACE
DOUBLE PRECISION FUNCTION func ( argument )
IMPLICIT NONE
DOUBLE PRECISION, INTENT( IN) : : argument