-
Notifications
You must be signed in to change notification settings - Fork 1
/
reader-hydro.f
490 lines (383 loc) · 13.3 KB
/
reader-hydro.f
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
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
C+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
C++ JEWEL Add-On to Read v-USPhydro 2+1D Profiles ++
C++ ++
C++ The program is part of the developed interface between the ++
C++ parton propagation of JEWEL and an external hydrodynamic 2+1D ++
C++ medium profile, intended for v-USPhydro. ++
C++ ++
C++ This code implements multiple auxiliary functions for reading ++
C++ and interpolating data of a medium profile. ++
C++ ++
C++ ++
C++ Created by: ++
C++ - Fabio M. Canedo [fabio.canedo@usp.br] ++
C++ - Leonardo Barreto [leonardo.barreto.campos@usp.br] ++
C++ Instituto de Fisica, Universidade de Sao Paulo, Brazil ++
C++ 2019 ++
C+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
subroutine reader(filename,np,nt,timesteps,tprofile,u,theta)
implicit none
integer i,j,k
integer np,nt
integer geti
integer ios
character*100 filename
double precision timesteps(60)
double precision tprofile(np,np,60)
double precision u(np,np,60)
double precision theta(np,np,60)
double precision t,x,y,temp,vx,vy
double precision pi
DATA PI/3.141592653589793d0/
integer linecounter
open(unit=1,file=filename,iostat=ios)
write(*,*) "Opening file: ",filename
do k=2,60
timesteps(k)=1.d20
end do
k=1
timesteps(k)=0.d0
linecounter=0
do while (ios.eq.0)
read(1,*,iostat=ios) t,x,y,temp,vx,vy
i=geti(x,np)
j=geti(y,np)
linecounter=linecounter+1
if(t.ne.timesteps(k)) then
k=k+1
timesteps(k)=t
end if
tprofile(i,j,k)=temp
u(i,j,k)=sqrt(vx**2+vy**2)
if(vx.ne.0.d0) then
theta(i,j,k)=atan(vy/vx)
else
if(vy.gt.0.d0) then
theta(i,j,k)=pi/2.d0
else
theta(i,j,k)=-pi/2.d0
end if
end if
end do
write(*,*) "File has ",linecounter, " lines"
!Stop simulations if file has not enough lines (arbitrary)
if (linecounter.lt.10) then
STOP
end if
end subroutine
! Create matrix of probabilities given
! temperature at tau0 and initvtxmap.dat
subroutine read_initvtx(np, tprofile, vtxprofile)
implicit none
COMMON/logfile/logfid
INTEGER logfid
integer np, ios, i, j, nlines, k
logical f_exist
double precision tprofile(np, np, 60)
double precision vtxprofile(np, np), tempmap(2000), vtxmap(2000)
double precision temp, dT, dsup, dinf
C--hydro auxiliary files
COMMON /HYDROF/ INITVTXF, IDEALN0, CUSTOMN0F
CHARACTER*200 INITVTXF, CUSTOMN0F
LOGICAL IDEALN0
! Load initial vertex map from INITVTXF
tempmap = 0.0
vtxmap = 0.0
nlines = 1
write(*,*) 'Loading initial vertex transformation from ', INITVTXF
write(logfid,*) 'read initial vertex table from ', INITVTXF
inquire(file=INITVTXF, exist=f_exist)
if (f_exist .eqv. .false.) then
write(*,*) 'INITVTXF does not exist. Killing simulation.'
stop
end if
open(1, file=INITVTXF, iostat=ios)
do while (ios .eq. 0)
read(1, *, iostat=ios) tempmap(nlines), vtxmap(nlines)
nlines = nlines + 1
end do
close(1)
if (nlines .gt. 2001 .or. nlines .lt. 2) then
write(*,*) 'WARNING: init vertex table size is wrong.
&Check read_initvtx'
end if
! Transform tprofile IC (tau0) into hard scattering
! probability from linear interpolation of vertex map
! Check boundaries
if ((maxval(tprofile) .gt. maxval(tempmap)) .or.
&(minval(tprofile) .lt. minval(tempmap))) then
write(*,*) 'Temperature (', temp, ' GeV) out of bounds
&in initvtx. Check initvertex table.'
stop
end if
do i = 1, np
do j = 1, np
temp = tprofile(i, j, 2)
! No temperature => no entropy
if (temp .eq. 0) then
vtxprofile(i, j) = 0.d0
else
! Check where temp is found in tempmap
do k = 2, nlines
if (tempmap(k) .gt. temp) then
dT = tempmap(k) - tempmap(k - 1)
dsup = vtxmap(k - 1) * (tempmap(k) - temp)
dinf = vtxmap(k) * (temp - tempmap(k - 1))
! Interpolate
vtxprofile(i, j) = (dsup + dinf) / dT
! Only do this for the first k, since temp is
! increasing with k
exit
end if
end do
end if
end do
end do
! Normalize probabilities
vtxprofile = vtxprofile / sum(vtxprofile)
end subroutine
! Read array for n0 function interpolation
subroutine read_customn0(tempmap, n0array)
implicit none
COMMON/logfile/logfid
INTEGER logfid
integer np, ios, i, j, nlines, k
logical f_exist
double precision tempmap(2000), n0array(2000)
C--hydro auxiliary files
COMMON /HYDROF/ INITVTXF, IDEALN0, CUSTOMN0F
CHARACTER*200 INITVTXF, CUSTOMN0F
LOGICAL IDEALN0
! Load n0array from CUSTOMN0F
tempmap = 0.0
n0array = 0.0
nlines = 1
if (IDEALN0) then
write(logfid,*)
&'Assuming ideal number density (propto T ** 3).'
else
write(*,*) 'Loading n0 custom function from ', CUSTOMN0F
write(logfid,*) 'read n0 interpolation table from ', CUSTOMN0F
inquire(file=CUSTOMN0F, exist=f_exist)
if (f_exist .eqv. .false.) then
write(*,*) 'CUSTOMN0F does not exist. Killing simulation.'
stop
end if
open(1, file=CUSTOMN0F, iostat=ios)
do while (ios .eq. 0)
read(1, *, iostat=ios) tempmap(nlines), n0array(nlines)
nlines = nlines + 1
end do
close(1)
if (nlines .gt. 2001 .or. nlines .lt. 2) then
write(*,*) 'WARNING: custom n0 table size is wrong.
&Check read_customn0'
end if
end if
end subroutine
integer function geti(x,np)
implicit none
integer np
double precision x,xmin,xmax,dx
xmax=25.d0
xmin=-25.d0
dx=(xmax-xmin)/(np-1)
geti=1+(x-xmin)/dx
end function
integer function getk(t,timesteps)
implicit none
integer k
double precision t
double precision timesteps(60)
getk=1
do k=1,60
if(timesteps(k).le.t) then
getk=k
endif
enddo
end function
double precision function interpol(t,x,y,np,timesteps,tgrid,norm)
implicit none
integer i,j,ii,jj,iii,jjj,np
integer k,kk
logical norm
double precision timesteps(60)
double precision tgrid(np,np,60),igrid(4,4),xgrid(4,4),ygrid(4,4)
double precision xmax,xmin,dx,dt
double precision t,x,y,xa,ya
double precision f(2)
double precision bicubic
integer getk
COMMON/GAMMAMAX/GAMMAMAXIMUM,VELMAXIMUM
DOUBLE PRECISION GAMMAMAXIMUM,VELMAXIMUM
k=getk(t,timesteps)
if(timesteps(k).eq.0.d0.and.timesteps(k+1).eq.0.d0) then
dt=1e30
else
dt=timesteps(k+1)-timesteps(k)
end if
xmax=25.d0
xmin=-25.d0
dx=(xmax-xmin)/(np-1)
i=1+floor((x-xmin)/dx)
j=1+floor((y-xmin)/dx)
xa=mod(x-xmin,dx)
ya=mod(y-xmin,dx)
do kk=1,2
!write(*,*) "k:",k-1+kk
do ii=1,4
do jj=1,4
iii=i+ii-2
jjj=j+jj-2
if (iii.gt.np.or.iii.lt.1) then
igrid(ii,jj)=0.d0
else if (jjj.gt.np.or.jjj.lt.1) then
igrid(ii,jj)=0.d0
else if (k-1+kk.gt.59.or.k-1+kk.lt.1) then
igrid(ii,jj)=0.d0
else
igrid(ii,jj)=tgrid(iii,jjj,k-1+kk)
end if
xgrid(ii,jj)=xa+(ii-1)*dx
ygrid(ii,jj)=ya+(jj-1)*dx
enddo
enddo
f(kk)=bicubic(xa,ya,dx,xmin,xmax,igrid,xgrid,ygrid,norm)
enddo
interpol=f(1)+(t-timesteps(k))*(f(2)-f(1))/dt
if (norm .and. interpol.gt.VELMAXIMUM) then
!write(*,*) "V > VELMAXIMUM", interpol, VELMAXIMUM
interpol=VELMAXIMUM
end if
if (norm .and. interpol.lt.0) then
interpol=0.d0
!write(*,*) "Negative velocity norm"
end if
!interpol=0.1
end function
double precision function
& bicubic(xa,ya,dx,xmin,xmax,igrid,xc,yc,norm)
implicit none
integer i,j
logical norm
double precision y(2,2),y1(2,2),y2(2,2),y12(2,2)
double precision igrid(4,4)
double precision xc(4,4),yc(4,4),ansy
double precision xa,ya,dx,xmin,xmax
double precision dertwospline
do i=1,2
do j=1,2
y(i,j)=igrid(i+1,j+1)
y1(i,j)=(igrid(i+2,j+1)-igrid(i,j+1))/(xc(i+2,j+1)
&-xc(i,j+1))
y2(i,j)=(igrid(i+1,j+2)-igrid(i+1,j))/(yc(i+1,j+2)
&-yc(i+1,j))
y12(i,j)=(igrid(i+2,j+2)-igrid(i+2,j)-igrid(i,j+2)
&+igrid(i,j))/(yc(i+1,j+2)-yc(i+1,j))*(xc(i+2,j+1)-xc(i,j+1))
end do
end do
bicubic=dertwospline(xc(2:3,2:3),yc(2:3,2:3),y,y1,y2,y12,
&xa,ya,norm)
end function
double precision function
& dertwospline(x1,x2,y,y1,y2,y12,xa,xb,norm)
implicit none
integer i
logical norm
double precision x1(2,2)
double precision x2(2,2)
double precision y(2,2)
double precision y1(2,2)
double precision y2(2,2)
double precision y12(2,2)
double precision w(2),w1(2)
double precision xa,xb
double precision derspline
w(1)=derspline(x1(:,1),y(:,1),y1(:,1),xa,norm)
w(2)=derspline(x1(:,2),y(:,2),y1(:,1),xa,norm)
w1(1)=derspline(x1(:,1),y2(:,1),y12(:,1),xa,norm)
w1(2)=derspline(x1(:,2),y2(:,2),y12(:,1),xa,norm)
dertwospline=derspline(x2(1,:),w(:),w1(:),xb,norm)
end function
double precision function derspline(x,y,yprime,xval,norm)
implicit none
integer i
logical norm
double precision x(2),y(2),yprime(2),c(4),yvec(4)
double precision dx,xval,t
double precision a(4,4)
data a/1.d0,0.d0,-3.d0,2.d0,0.d0,0.d0,3.d0,-2.d0,0.d0,1.d0,
&-2.d0,1.d0,0.d0,0.d0,-1.d0,1.d0/
dx=x(2)-x(1)
do i=1,2
yvec(i)=y(i)
yvec(i+2)=dx*yprime(i)
end do
c=matmul(transpose(a),yvec)
t=(xval-x(1))/dx
derspline=0.d0
do i=1,4
derspline=derspline+c(i)*t**(i-1)
end do
end function
DOUBLE PRECISION FUNCTION INTERPOLATEN0(T)
IMPLICIT NONE
COMMON/logfile/logfid
INTEGER logfid
C--number density parameters
common/n0par/ densconst, n0array(2000), tempn0array(2000),
&temparraymaxpos, temparrayminpos
double precision densconst, n0array, tempn0array
integer temparraymaxpos, temparrayminpos
C--local variables
double precision T, Tmin, Tmax, n0min, n0max
integer counter, up, down, binarysearch
interpolaten0 = 0.d0
! Flag if out of bounds
if ((T .lt. minval(tempn0array)) .or.
&(T .gt. maxval(tempn0array))) then
write(logfid,*)
&"Temperature out of CUSTOMN0F bounds in INTERPOLATEN0"
write(logfid,*) "Will continue with n0 = 0 (no density)"
return
end if
! Find bin with binary search, n0array must be sorted for this
counter = binarysearch(T, tempn0array, temparrayminpos,
&temparraymaxpos)
if (counter .eq. -1) then
write(logfid,*) "INTERPOLATEN0: T not found in binary search"
write(logfid,*) "Will continue with n0 = 0 (no density)"
return
end if
Tmin = tempn0array(counter)
Tmax = tempn0array(counter + 1)
n0min = n0array(counter)
n0max = n0array(counter + 1)
! Linear interpolation
interpolaten0 = n0min + (T - Tmin) * (n0max - n0min)
&/ (Tmax - Tmin)
return
END
INTEGER FUNCTION BINARYSEARCH(X, ARRAY, LOWBOUND, HIGHBOUND)
IMPLICIT NONE
C--local variables
double precision x, array(2000)
integer lowbound, highbound
integer down, up, mid
binarysearch = -1
down = lowbound
up = highbound
do while (down .le. up)
mid = (down + up) / 2
if (x .gt. array(mid) .and. x .le. array(mid + 1)) then
binarysearch = mid
return
end if
if (x .gt. array(mid)) then
down = mid + 1
else
up = mid - 1
end if
end do
return
END