-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgodunov.f90
194 lines (114 loc) · 3.55 KB
/
godunov.f90
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
MODULE GODUNOV
USE NUMERICS
USE UTILS
IMPLICIT NONE
REAL(RP),ALLOCATABLE, DIMENSION(:,:,:) :: U_GS
REAL(RP),ALLOCATABLE, DIMENSION(:,:) :: E_GS,ENERGY
CONTAINS
SUBROUTINE ENERGY_FD(N,TIM)
INTEGER, INTENT(IN) ::N
REAL(RP) , INTENT(IN) ::TIM
REAL(RP), DIMENSION(NX) ::TMPBIS
INTEGER ::I
REAL(RP) ::S
DO I=1,NX
TMPBIS(I)=E_GS(N,I)**2
END DO
ENERGY(N,1)=TIM
ENERGY(N,2)=SQRT(QUAD(DX,TMPBIS)*0.5_RP)
RETURN
END SUBROUTINE ENERGY_FD
SUBROUTINE E_FIELD(N,A)
INTEGER, INTENT(IN) ::N
REAL(RP),DIMENSION(:),INTENT(OUT) , ALLOCATABLE :: A
INTEGER ::I
REAL(RP)::S
ALLOCATE(A(NX))
A(:)=zero
DO I=2,NX-1
A(I+1)=A(I)+(UN-QUAD(DV,U_GS(N,I,:)))*DX
END DO
S=SUM(A)/NX
DO I=1,NX
A(I)=A(I)-S
END DO
A(NX)=A(1)
RETURN
END SUBROUTINE
SUBROUTINE GS ! GODUNOV SPLITTING SCHEMA UPSTREAM
REAL(rp),ALLOCATABLE, DIMENSION(:,:) :: Q,U,U_STAR
REAL(rp),ALLOCATABLE, DIMENSION(:) :: TMP
INTEGER ::I,J,K
REAL(RP)::CHRONO
ALLOCATE(Q(NX,NV))
ALLOCATE(U(NX,NV))
ALLOCATE(TMP(NX) )
ALLOCATE(ENERGY(NT,2))
ALLOCATE(E_GS(NT,NX))
ALLOCATE(U_GS(NT,NX,NV))
DT=TMAX/NT
U_GS(1,:,:)=FINIT
Q=FINIT
CALL E_FIELD(1,TMP)
E_GS(1,:)=TMP
WRITE(*,*)"CFL_X",ABS(DT*10._rp/DX),"CFL_V",ABS(DT*maxval(tmp)/DV)
WRITE(*,*)'LE NOMBRE D ITERATIONS EST ',NT
CHRONO=ZERO
!---------------------------BOUCLE EN TEMPS-------------------------
DO K=1,NT-1
!--------------------------TRANSPORT EN VITESSE-------------------------
DO J=2,NV-1
DO I=1,NX-1
U(I,J)=Q(I,J)-(MAX(ZERO,-TMP(I))*( Q(I,J)-Q(I,J-1))+MIN(ZERO,-TMP(I))*(Q(I,J+1)-Q(I,J)))*DT/DV
END DO
END DO
U(NX,:)=U(1,:)
!--------------------------TRANSPORT EN ESPACE ------------------------
U(:,1)=ZERO
U(:,NV)=ZERO
DO J=2,NV-1
Q(1,J)=U(1,J)-V(J)*DT*(U(2,J)-U(1,J))/DX
DO I=2,NX-1
Q(I,J)=U(I,J)-(MAX(ZERO,V(J))*(U(I,J)-U(I-1,J))/DX+MIN(ZERO,V(J))*(U(I+1,J)-U(I,J))/DX)*DT
END DO
END DO
Q(NX,:)=Q(1,:)
Q(:,1)=ZERO
Q(:,NV)=ZERO
!---------------------------CALCUL DU CHAMP E---------------------------
U_GS(K+1,:,:)=Q
CALL E_FIELD(K+1,TMP)
E_GS(K+1,:)=TMP
CALL ENERGY_FD(K+1,CHRONO)
CHRONO=CHRONO+DT
END DO
!-----------------------------SAUVEGARDE---------------------------------
CALL SAVE_RESULT(NT)
CALL SAVE_ENERGY(NT)
WRITE(*,*) "LE TEMPS FINAL EST ", CHRONO
CALL SPACE_ERR(U_GS(2,:,:),DT)
DEALLOCATE(U,Q,ENERGY,U_GS,TMP)
END SUBROUTINE GS
SUBROUTINE SAVE_RESULT(K)
INTEGER , INTENT(IN) ::K
integer :: I,J
!stockage dans un fichier
open(unit=13, file='godunov_split.txt', status='REPLACE')
DO I=1,SIZE(FINIT,1)
DO J=1,SIZE(FINIT,2)
WRITE(13,*) X(I),' ',V(J),' ',U_GS(K,I,J)
END DO
END DO
close(13)
END SUBROUTINE save_result
SUBROUTINE SAVE_ENERGY(N)
integer , INTENT(IN):: N
integer :: I
!stockage dans un fichier
open(unit=17, file='GD_ENERGY.txt', status='REPLACE')
DO I=2,NT
WRITE(17,*) ENERGY(I,1),' ', LOG(ENERGY(I,2))
END DO
close(17)
END SUBROUTINE SAVE_ENERGY
END MODULE GODUNOV