-
Notifications
You must be signed in to change notification settings - Fork 2
/
euler1d.f90
395 lines (315 loc) · 9.52 KB
/
euler1d.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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
! Author: Vladimir Fuka
! Solution of Euler equations for compressible fluid
! in 1D - Riemann problem
! added subroutine by Donato Cecere :FLUXESCULD, and a subroutine for not uniform grid.
program Euler1D
use CUeuler
implicit none
real(KND),allocatable,dimension(:):: rho,rhou,e,x
integer i,fnum,frames
real(KND) timefram1,timefram2
!Not uniform grid
real(KND) yp(3), r(3)
real(KND) xp(3)
yp(1) = -1.0
yp(2) = 0.6
yp(3) = 1.0
r(1) = 0.5
r(2) = 0.3
r(3) = 1.0
!Not uniform grid
open(11,file="euler.conf")
read (11,FMT='(/)')
read (11,*) FLUXtype
write(*,*) 'Flux type:',FLUXtype
if ((FLUXtype<1).or.(FLUXtype>5)) then
write (*,*) "Wrong flux type, set to 5...MUSTA"
FLUXtype=5
endif
read (11,FMT='(/)')
read (11,*) MUSTAstages
write (*,*) 'Number of MUSTA stages:',MUSTAstages
if (MUSTAstages<1) then
write (*,*) "Number of MUSTA stages must be positive, set to 4."
MUSTAstages=4
endif
read (11,FMT='(/)')
read (11,*) RECtype
write (*,*) 'Reconstruction type:',RECtype
if ((RECtype<1).or.(RECtype>2)) then
write (*,*) "Wrong reconstruction type, set to 2...p. linear."
FLUXtype=5
endif
read (11,FMT='(/)')
read (11,*) limitertype
write (*,*) 'Limiter type:',limitertype
if ((limitertype<1).or.(limitertype>3)) then
write (*,*) "Wrong limiter type, set to 1...minmod."
FLUXtype=1
endif
read (11,FMT='(/)')
read (11,*) limparam
read (11,FMT='(/)')
read (11,*) RKtype
write (*,*) 'Runge-Kutta method:',RKtype
if ((RKtype<1).or.(RKtype>4)) then
write(*,*) "Wrong Runge-Kutta method type, set to 2...2. order."
RKtype=2
elseif ((RKtype==4).and.((FLUXtype<3).or.(FLUXtype>4))) then
write(*,*) "Full discrete scheme can be only Lax-Friedrichs or Lax-Wendroff. Runge-Kutta type set to 2...2. order."
RKtype=2
endif
read (11,FMT='(/)')
read (11,*) nt
if (nt<1) then
write (*,*) "Number of timesteps must be positive, set to 1000."
nt=1000
endif
read (11,FMT='(/)')
read (11,*) tend
write (*,*) 'End time:',tend
if (tend<=0) then
write (*,*) "End time must be positive, set to 0.1"
tend=0.1
endif
read (11,FMT='(/)')
read (11,*) xl
read (11,FMT='(/)')
read (11,*) xr
if (xl>=xr) then
write (*,*) "Right margin must be greater then the left one, set to xl+2."
xr=xl+2
endif
read (11,FMT='(/)')
read (11,*) nx
if (nt<1) then
write (*,*) "Number of cells must be positive, set to 100."
nx=100
endif
read (11,FMT='(/)')
read (11,*) CFL
if (CFL<=0) then
write (*,*) "CFL must be positive, set to 0.5."
CFL=0.5
endif
read (11,FMT='(/)')
read (11,*) extype
write (*,*) 'Problem type: ',extype
if ((extype<1).or.(extype>2)) then
write (*,*) "Wrong type of problem to solution, sett to 1...Riemann problem."
extype=1
endif
read (11,FMT='(/)')
read (11,*) rhoLEFT
if (rhoLEFT<=0) then
write (*,*) "Left state density must be positive, set to 0.1."
rhoLEFT=0.1
endif
read (11,FMT='(/)')
read (11,*) rhouLEFT
read (11,FMT='(/)')
read (11,*) eLEFT
if (eLEFT<=0) then
write (*,*) "Left state energy must be positive, set to 0.5."
eLEFT=0.5
endif
read (11,FMT='(/)')
read (11,*) rhoRIGHT
if (rhoRIGHT<=0) then
write (*,*) "RIGHT state density must be positive, set to 0.1."
rhoRIGHT=0.1
endif
read (11,FMT='(/)')
read (11,*) rhouRIGHT
read (11,FMT='(/)')
read (11,*) eRIGHT
if (eRIGHT<=0) then
write (*,*) "Right state energy must be positive, set to 0.5."
eRIGHT=0.5
endif
read (11,FMT='(/)')
read (11,*) frames
read (11,FMT='(/)')
read (11,*) timefram1
if ((frames>0).and.(timefram1<0)) then
write (*,*) "Time of first frame must be nonnegative, set to 0.001."
timefram1=0.001
endif
read (11,FMT='(/)')
read (11,*) timefram2
if ((frames>0).and.(timefram2<timefram1)) then
write (*,*) "Time of last frame must be nonnegative, set to tend-0.001."
timefram2=tend-0.001
elseif ((frames>0).and.(timefram2>tend)) then
write (*,*) "Time of last frame can't be greater then tend, set to tend-0.001.",frames,timefram2,tend
timefram2=tend-0.001
endif
read (11,FMT='(/)')
read (11,*) outputtype
if ((frames>0).and.(outputtype==1)) then
write (*,*) "Frames for animation will be stored as muliple *.dat files."
elseif ((frames>0).and.(outputtype==2)) then
elseif ((frames>0).and.((outputtype<1).or.(outputtype>2))) then
write (*,*) "Warning! No filetype set for animation frames, defaulting to text files."
outputtype=1
endif
close(11)
dx=(xr-xl)/nx
allocate(x(-2:nx+3))
! UNIFORM GRID
forall(i=-2:nx+3)
x(i)=xl+dx*(i-1._KND/2._KND)
endforall
! NOT UNIFORM GRID
! call linearMesh(yp, r, 3, x(1:nx), nx)
! dx = x(nx)-x(nx-1)
! do i=1,3
! x(nx+i) = x(nx+i-1) + dx
! enddo
! dx = x(2)-x(1)
! do i=0,-2,-1
! x(i) = x(i+1) - dx
! enddo
allocate(rho(-2:nx+3))
allocate(rhou(-2:nx+3))
allocate(e(-2:nx+3))
if (extype==1) then
forall(i=-2:nx+3,x(i)<xl+(xr-xl)/2._KND) !forall(i=-1:nx+2,x(i)<xl+(xr-xl)/2._KND)
rho(i)=rhoLEFT
rhou(i)=rhouLEFT
e(i)=eLEFT
endforall
forall(i=-2:nx+3,x(i)>=xl+(xr-xl)/2._KND) !forall(i=-1:nx+2,x(i)>=xl+(xr-xl)/2._KND)
rho(i)=rhoRIGHT
rhou(i)=rhouRIGHT
e(i)=eRIGHT
endforall
elseif (extype==2) then
forall(i=1:nx)
rho(i)=2 - (cos(pi*x(i)+dx*2._KND)-cos(pi*x(i)-dx*2._KND))/(dx*pi)
rhou(i)=rho(i)
e(i)=rho(i)
endforall
endif
if (outputtype==2) call open_time_evol !Create the history file
time=0
do i=1,nt
write(*,*) "i=",i
write(*,*) "time=",time
dt=DTIME(rho,rhou,e)
if (dt>(tend-time)) dt=(tend-time)
write (*,*) 'Initial dt ', dt
call TMARCH(rho,rhou,e,x)
time=time+dt
if (frames>0)then
if ((time>=timefram1).and.(time<=timefram2+(timefram2-timefram1)/(frames-1))&
.and.(time>=timefram1+fnum*(timefram2-timefram1)/(frames-1))) then
fnum=fnum+1
if (outputtype==1) then
call FRAME(x,rho,rhou,e,fnum)
elseif (outputtype==2) then
call time_evol(x,rho,rhou,e,fnum)
endif
endif
endif
if (time>=tend) EXIT
enddo
write(*,*) "endtime=",time
call OUTPUT(x,rho,rhou,e)
if (outputtype==1) call close_time_evol
deallocate(x,rho,rhou,e)
contains
real(KND) function DTIME(rho,rhou,e)
real(KND),dimension(-2:):: rho,rhou,e
real(KND) p,c,S,pom
integer i
S=0
do i=1,nx
p=(gamma-1._KND)*(e(i)-(1._KND/2._KND)*(rhou(i)*rhou(i))/rho(i))
if (p<0) then
write (*,*) "p<0!!!",e(i),rho(i),rhou(i)/rho(i)
p=0
endif
c=SQRT(gamma*p/rho(i))
pom=MAX(ABS(rhou(i)/rho(i)-c),ABS(rhou(i)/rho(i)+c))
if (S<p) S=pom
enddo
DTIME=CFL*dx/S
endfunction DTIME
subroutine OUTPUT(x,rho,rhou,e)
real(KND),dimension(-2:):: x,rho,rhou,e
integer i
write (*,"(a)",advance="no") "Saving....."
open(11,file="rho.txt")
do i=1,nx
write(11,*) x(i),rho(i)
enddo
close(11)
open(11,file="u.txt")
do i=1,nx
write(11,*) x(i),rhou(i)/rho(i)
enddo
close(11)
open(11,file="rhou.txt")
do i=1,nx
write(11,*) x(i),rhou(i)
enddo
close(11)
open(11,file="e.txt")
do i=1,nx
write(11,*) x(i),e(i)
enddo
close(11)
open(11,file="p.txt")
do i=1,nx
write(11,*) x(i),(gamma-1._KND)*(e(i)-(1._KND/2._KND)*(rhou(i))*(rhou(i))/rho(i))
enddo
close(11)
open(11,file="m.txt")
do i=1,nx
write(11,*) x(i),rhou(i)/(rho(i)*SQRT(ABS(gamma*(gamma-1._KND)&
*(e(i)-(1._KND/2._KND)*(rhou(i))*(rhou(i))/rho(i))/rho(i))))
enddo
close(11)
write(*,"(a)") "saved"
endsubroutine OUTPUT
subroutine FRAME(x,rho,rhou,e,n)
real(KND),dimension(-2:):: x,rho,rhou,e
integer i,n
character fname*10,str*70
write(fname(1:3),"(I3.3)") n
fname(4:7)=".dat"
write(*,*) "Saving frame:",fname(1:3)," time:",time
open(11,file=fname(1:7))
do i=1,nx
write(11,*) x(i),rho(i),rhou(i)/rho(i), &
(gamma-1._KND)*(e(i)-(1._KND/2._KND)*(rhou(i))*(rhou(i))/rho(i))
enddo
close(11)
write (*,*) "Saved frame",n
endsubroutine FRAME
SUBROUTINE open_time_evol
INTEGER s
CHARACTER VAR_FLUID*298, VAR_Yi*298, VAR_CK*298, VAR_PROP*298, Tec_string*500
VAR_FLUID = "variables = ""z [m]"", ""rho [kg/m^3]"", ""Uz [m/s]"", ""P [Pa]"""
Tec_string = VAR_FLUID
open (30,file='HISTORY.plt', POSITION='APPEND', STATUS='UNKNOWN', ACTION='WRITE')
write(30,'(500(x,a))') Tec_string
END subroutine open_time_evol
SUBROUTINE time_evol(x,rho,rhou,e,n)
real(KND),dimension(-2:):: x,rho,rhou,e
integer i, n, s
CHARACTER*15 FORCHR,nvar
write(Nvar,45) 4
45 format(I1)
!43 format('(F20.12,1X,F20.12,1X,F20.12,1X,F20.12,1X)')
write(30,*) 'ZONE T="time=',time,'"'
do i= 1,nx
write(30,*) x(i),rho(i),rhou(i)/rho(i), &
(gamma-1.D0)*(e(i)-(1.D0/2.D0)*(rhou(i))*(rhou(i))/rho(i))
enddo
END subroutine time_evol
SUBROUTINE close_time_evol
close(30)
END subroutine close_time_evol
end