1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
| module fonctions
!module principal contenant les subroutines
implicit none
contains
!**************************************************************************
!Résolution d'un système linéaire triangulaire supérieur
subroutine Resol_Triang_Sup(n,A,B,X)
implicit none
integer, intent(in) :: n
real*8, dimension(n,n),intent(in) :: A
real*8, dimension(n), intent(in) :: B
real*8, dimension(n), intent(out) :: X
integer :: i, j
real*8 :: somme
!initialisation de X et somme
X = 0
somme = 0
!algorithme de résolution
X(n) = B(n)/A(n,n)
Do i = n-1,1,-1
somme = B(i)
Do j = n, i, -1
somme = somme - A(i,j)*X(j)
End Do
X(i) = somme/A(i,i)
End Do
end subroutine Resol_Triang_Sup
!*****************************************************************************
!Résolution d'un système linéaire triangulaire inférieur
subroutine Resol_Triang_Inf(n,A,B,X)
implicit none
integer, intent(in) :: n
real*8, dimension(n,n),intent(in) :: A
real*8, dimension(n), intent(in) :: B
real*8, dimension(n), intent(out) :: X
integer :: i, j
real*8 :: somme
!initialisation de X et somme
X = 0
somme = 0
!algorithme de résolution
X(1) = B(1)/A(1,1)
Do i = 2, n
somme = B(i)
Do j = 1, i-1
somme = somme - A(i,j)*X(j)
End Do
X(i) = somme/A(i,i)
End Do
end subroutine Resol_Triang_Inf
!**************************************************************************
!Factorisation LU
subroutine LU(n,A,L,U)
implicit none
integer, intent(in) :: n
real*8, dimension(n,n), intent(in) :: A
real*8, dimension(n,n), intent(out) :: L, U
integer :: i, j, k
U = A
L = 0
Do i = 1, n
L(i,i) = 1
End Do
Do i = 1, n
Do j = i+1, n
L(j,i) = U(j,i)/U(i,i)
U(j,i) = 0
Do k = i+1, n
U(j,k) = U(j,k) - L(j,i)*U(i,k)
End Do
End Do
End Do
end subroutine LU
!***************************************************************************
!Resolution LU
subroutine Resolution(n,L,U,B,X)
implicit none
integer, intent(in) :: n
real*8, dimension(n,n), intent(in) :: L, U
real*8, dimension(n), intent(in) :: B
real*8, dimension(n), intent(out) :: X
real*8, dimension(n) :: Y
integer :: i, j
call Resol_Triang_Inf(n,L,B,Y)
call Resol_Triang_Sup(n,U,Y,X)
end subroutine Resolution
!***************************************************************
!ecriture dans un fichier
subroutine WriteGnuPlot(nom_fichier, v)
implicit none
character(len=*) :: nom_fichier
real*8, dimension(:,:) :: v
integer :: i,j
open(unit = 11, file = nom_fichier, form = 'formatted', &
status = 'unknown', action = 'write')
do i = 1, size(v,1)
do j=1,size(v,2)
write(11, * )i, j, v(i,j)
end do
write(11, *)
end do
close(11)
end subroutine WriteGnuPlot
end module fonctions
!****************************************************************************
!programme principal
program eulerimplicit
use fonctions
implicit none
real*8,dimension(:,:),allocatable::A,L,U,mat
real*8,dimension(:),allocatable::Un,Un1,y
real*8::Beta1,alpha,dt,dx,tf,D
integer::i,j,nx,nt
D=0.01
tf=1.0D0
dt=0.1d0
dx=0.1d0
nx=floor(1./dx)
nt=floor(tf/dt)
allocate(A(nx,nx))
allocate(L(nx,nx))
allocate(U(nx,nx))
allocate(y(nx))
allocate(Un(nx))
allocate(Un1(nx))
allocate(mat(nx,nt))
Beta1=(1+2*(dt/dx**2))
alpha=dt/dx**2
A(1,1)=1.d0
A(nx,nx)=1.d0
Un(1)=0.d0
Un(nx)=0.d0
do i=2,nx-1
A(i,i)=Beta1
A(i,i+1)=-alpha
A(i,i-1)=-alpha
end do
Un(1)=0.d0
Un(nx)=0.d0
do j=2,nx-1
Un(j)=5.d0
end do
open(unit=24,file='resultatsimplicistp')
print*,A
do i=1,nt
call LU(nt,D*A,L,U) !on multiplie la matrice A par le coefficient D'
call Resolution(nt,L,U,Un,Un1)
mat(:,i) = Un1
Un=Un1
! print*,'la matrice L est :',L
! print*,'la matrice U est :',U
print*, 'la matrice Un1 est :',Un1
end do
call writegnuplot('implicit.dat',mat)
close(24)
deallocate(A)
deallocate(L)
deallocate(U)
deallocate(y)
deallocate(Un)
deallocate(Un1)
end program eulerimplicit |
Partager