! File:  test_sor_d2.f90
!
! Creation Date: 09.11.2015; Time: 19:11
! Time-stamp: <2015-11-09 20:59:30 (andrzejbaran)> 
!
! Andrzej Baran, IF UMCS
! baran@kft.umcs.lublin.pl
!
program test_sor_d2
  implicit none
  integer, parameter :: n = 11
  integer :: i, j, k, iter
  double precision, dimension(1:n,1:n) :: u, f
  double precision x, y, rhs, pi, h, omega
  !
  ! Test sor (gauss-seidel by successive-over-relaxation)
  ! Rozwiązywanie cząstkowego równania różniczkowego:
  !   Laplacian(u(x,u)) = (4-pi**2)*exp(2*x)*cos(pi*y), 0 < x,y < 1
  !   u(x,0) = exp(2*x)                   dla 0 < x < 1
  !   u(1,y) = exp(2.)*cos(pi*y)          dla 0 < y < 1
  !   u(x,1) = -exp(2*x)                  dla 0 < x < 1
  !   u(0,y) = cos(pi*y)                  dla 0 < y < 1
  ! Rozwiązanie dokładne: u(x,y) = exp(2*x)*cos(pi*y)
  !
  H = 1./(n-1)

  ! boundary conditions and trial solution
  pi = 4*atan(1d0)
  u = 0d0
  do i=1,n
     x = (i-1)*h
     y = x
     u(i,1) = exp(2d0*x)
     u(n,i) = exp(2d0)*cos(pi*y)
     u(i,n) = -u(i,1)
     u(1,i) = cos(pi*y)
  end do

  ! right hand side of the eq.
  do i=1,n
     do j=1,n
        x = (i-1)*h
        y = (j-1)*h
        f(i,j) = h * h * (4-pi*pi)*exp(2*x)*cos(pi*y)
     end do
  end do

  omega = 1.9d0
  call sor_d2(f,u,n,omega,iter)

  write(*,"(a,i4)") 'Number of iterations = ', iter
  write(*, "(11f8.3)") ((u(i,j), j=1,n), i=1,n)

end Program test_sor_d2


