 module Coef
 
 use variaveis 
 
 implicit none


 contains

	subroutine coeficientes

    real*8  :: x                ! coordenada espacial
	
	dx = 1.0d0 / (N - 1)


	if (prob == 1) then         ! execulta o problema de poisson 

	S0 = 1.0d+0
    S1 = 3.0d+0  
    S2 = 2.6d+1  

    ! contorno esquerdo
    AW(1) = 0.0d0
    AE(1) = 0.0d0
    AP(1) = 1.0d0
    BP(1) = 0.0d0

    !dx = 1.0d0 / (N - 1)

    ! pontos internos
	do i = 2, N-1

       x = (i-1) * dx

	   AW(i) = 1.0d0 / (dx**2)

       AE(i) = 1.0d0 / (dx**2)

       AP(i) = AW(i) + AE(i)

       BP(i) = S0 + S1*x + S2*(x**2)

    end do

	! contorno direito
    AW(N) = 0.0d0
    AE(N) = 0.0d0
    AP(N) = 1.0d0
    BP(N) = 1.0d0


	else                        ! calcula os coeficientes do problema de conveccao 


	    ! contorno esquerdo
    AW(1) = 0.0d0
    AE(1) = 0.0d0
    AP(1) = 1.0d0
    BP(1) = 0.0d0

    ! pontos internos
	do i = 2, N-1

       x = (i-1) * dx

	   !CSD/CDS
	   !AW(i) = 1.0d0/(dx**2.0d0) + Pe/(2.0d0*dx)   
       !AE(i) = 1.0d0/(dx**2.0d0) - Pe/(2.0d0*dx)    

       !UDS/CDS
	   AW(i) = 1.0d0/(dx**2.0d0) + Pe/dx
       AE(i) = 1.0d0/(dx**2.0d0)    

       AP(i) = AW(i) + AE(i)
	   
	   
	 end do

	BP = 0.0d0

	! contorno direito
    AW(N) = 0.0d0
    AE(N) = 0.0d0
    AP(N) = 1.0d0
    BP(N) = 1.0d0


	end if
	
	
  end subroutine coeficientes


end module Coef