308 CHAPTER 16. PARTIAL DIFFERENTIAL EQUATIONS
! 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 , t )
MODULE one_dim_heat_equation
DOUBLE PRECISION, PRIVATE : : xmin , xmax , k
INTEGER, PRIVATE : : m , ndim
CONTAINS
SUBROUTINE i n i t i a l i s e
IMPLICIT NONE
WRITE( , ) ’ read in number of mesh points in x ’
READ( , ) ndim
WRITE( , ) ’ read in xmin and xmax ’
READ( , ) xmin , xmax
WRITE( , ) ’ read in number of time steps ’
READ( , ) m
WRITE( , ) ’ read in s tep s i z e in t ’
READ( , ) k
END SUBROUTINE i n i t i a l i s e
SUBROUTINE solve_1dim_equation ( func )
DOUBLE PRECISION : : h , factor , det , t , pi
INTEGER : : i , j , l
DOUBLE PRECISION, ALLOCATABLE, DIMENSION( : , : ) : : a
DOUBLE PRECISION, ALLOCATABLE, DIMENSION( : ) : : u , v
INTERFACE
DOUBLE PRECISION FUNCTION func ( x )
IMPLICIT NONE
DOUBLE PRECISION, INTENT( IN) : : x
END FUNCTION func
END INTERFACE
! defi ne the step s i ze
h = ( xmax xmin ) /FLOAT( ndim +1)
f act o r = k / h / h
! al loc ate space for the vectors u and v and the matrix a
ALLOCATE ( a ( ndim , ndim ) )
ALLOCATE ( u ( ndim ) , v ( ndim ) )
pi = ACOS( 1.)
DO i =1 , ndim
v( i ) = func ( pi i h )