-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcondinit.f90
501 lines (383 loc) · 13.4 KB
/
condinit.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
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
491
492
493
494
495
496
497
498
499
500
subroutine condinit
! ------------------------------------ !
! Initial Condition !
! [ Kelvi-Helmholtz instability ] !
! ------------------------------------ !
!**************************************************!
! MPI PARALLEL VERSION: VALENTINI-FAGANELLO 2009 !
! 3D PARALLEL VERSION: FAGANELLO 2010 !
!**************************************************!
!**************************************************!
! FLR corrected MHD equilibria: CERRI 2011 !
! !
! for details see: !
! !
! Cerri et al., Phys. Plasmas 20, 112112 (2013) !
! !
!**************************************************!
use parameter_mod
use dom_distr_mod
use box_mod
use fields_UJ_mod
use fields_DP_mod
use fields_EB_mod
use parallel_mod
IMPLICIT NONE
integer :: ix, iy, iz, ir, iky, ikz
REAL(dp) :: ky, kz, zkk, pph, xx, ab, zz
REAL(dp) :: n0, B0
REAL(dp) :: T0i_para, T0i_perp, T0e_para, T0e_perp
REAL(dp) :: gam_i_perp, gam_i_para, gam_e_perp, gam_e_para
REAL(dp) :: gaminv_i_perp, gam_tilde
REAL(dp) :: beta_i_perp, beta_e_perp
REAL(dp) :: beta_i_perp_tilde, beta_e_perp_tilde
REAL(dp) :: C_0, C_1, C_inf
REAL(dp) :: Den_inf, Dinv_inf!, DeltaDen
REAL(dp) :: pi_para_inf, pi_perp_inf, pe_para_inf, pe_perp_inf, anis_i_0, anis_e_0
REAL(dp) :: Ti_para_inf, Ti_perp_inf, Te_para_inf, Te_perp_inf
REAL(dp),ALLOCATABLE :: equil(:)
REAL(dp),ALLOCATABLE :: f_0(:), fnct(:), equilDen(:), equilB(:)
REAL(dp),ALLOCATABLE :: gx1(:,:,:)
REAL(dp),ALLOCATABLE :: gy1(:), phs(:)
REAL(dp),ALLOCATABLE :: zx(:)
REAL(dp),ALLOCATABLE :: g0(:,:,:), gt(:,:,:)
CHARACTER*13 filen_DT
CHARACTER*1 F_1
CHARACTER*2 F_2
CHARACTER*3 F_3
CHARACTER*4 F_4
allocate(equil(nxl))
allocate(f_0(nxl))
allocate(fnct(nxl))
allocate(equilB(nxl))
allocate(equilDen(nxl))
allocate(g0(nxl,ny,nz))
allocate(gx1(nxl,ny,nz))
allocate(gy1(ny))
allocate(phs(ny))
allocate(gt(nx,nyt,nz))
allocate(zx(nx))
SELECT CASE (istart)
CASE (0) !*** istart=0 ==> first RUN ***!
!**********************************************!
! MHD one-fluid velocity: shear flow along x !
! !
! Uy(x) = Aeq * tanh[ (x - Lx/2) / Leq ] !
! !
! (Leq in d_i units, Aeq in v_A units) !
!**********************************************!
Ux = 0.
Uz = 0.
equil = Aeq * dtanh((x(ixlg:ixlg+nxl-1) - xl*0.5d0 ) / Leq)
if (mpime==0) then
write(6,*) ' ----------------------------- '
write(6,*) ' U_0, L_U = ', Aeq, Leq
write(6,*) ' ----------------------------- '
endif
do iz=1, nz
do iy=1, ny ! nyl == ny
Uy(:,iy,iz) = equil(:)
enddo
enddo
!------------------------------------------------------------!
! 2D incompressible perturbations on U: dU = e_z x grad(phi) !
!------------------------------------------------------------!
ir = 1
call random_seed(ir)
call random_number(phs)
! Sum up modes on phi (2D --> no kz)
g0 = 0.
do iky = 1, MIN(Ny/8,16)
ky = float(iky)
zkk = 1.0 / ky
pph = (phs(ir) - 0.5) * 2.0 * pgreco
ir = ir + 1
do iz = 1, nz
do iy = 1, ny
do ix = 1, nxl
xx = x(ixlg+ix-1) - xl/2.0
ab = abs(xx)/Leq
IF (ab .GE. 9.0) then
g0(ix,iy,iz)= 0.0
ELSE
g0(ix,iy,iz) = g0(ix,iy,iz) + cos(ky * y(iy) * hyl + pph) * zkk *&
exp(-1.0 * xx ** 2.0 / Leq ** 2.0)
ENDIF
enddo
enddo
enddo
enddo
! compute: dU = ez x grad(phi)
! (multiplied by ampl, so that max(|dU|) ~ ampl)
CALL traspdist( g0, gt, 1 )
do iz = 1, nz
do iy = 1, nyt
call derx_1( gt(:,iy,iz), zx )
gt(:,iy,iz) = zx
enddo
enddo
CALL traspdist( gx1, gt, -1 )
Uy = Uy + ampl * gx1
do iz = 1, nz
do ix = 1, nxl
call dery_1( g0(ix,:,iz), gy1 )
Ux(ix,:,iz) = - ampl * gy1
enddo
enddo
Uz = 0.0
deallocate(g0)
deallocate(gx1)
deallocate(gy1)
deallocate(equil)
deallocate(phs)
deallocate(gt)
deallocate(zx)
!**************************************************!
! Compute FLR-corrected MHD equilibrium !
! ------------------------------------------------ !
! for details see: !
! !
! Cerri et al., Phys. Plasmas 20, 112112 (2013) !
! !
!**************************************************!
!-- politropic index of the equilibrium
! (default: isothermal initial condition)
gam_i_perp = 1.0d0
gam_i_para = 1.0d0
gam_e_perp = 1.0d0
gam_e_para = 1.0d0
gaminv_i_perp = 1.0d0 / gam_i_perp
!-- equilibrium quantities "at infinity"
!density
Den_inf = 1.0d0
Dinv_inf = 1.0d0 / Den_inf
!ion pressures and temperatures
anis_i_0 = 0.0d0 ! ion anisotropy at infinity (A = Pperp/Ppara - 1)
pi_para_inf = 0.5d0 ! (note: beta_inf = 0.5*p_inf/B0 => 0.5d0 -> beta = 1)
pi_perp_inf = (1.0d0 + anis_i_0)*pi_para_inf
Ti_para_inf = Dinv_inf * pi_para_inf
Ti_perp_inf = Dinv_inf * pi_perp_inf
!electron pressures and temperatures
anis_e_0 = 0.0d0 ! electron anisotropy at infinity (A = Pperp/Ppara - 1)
pe_para_inf = 0.5d0 ! (0.5d0 --> beta = 1)
pe_perp_inf = (1.0d0 + anis_e_0)*pe_para_inf
Te_para_inf = Dinv_inf * pe_para_inf
Te_perp_inf = Dinv_inf * pe_perp_inf
!perpendicular plasma betas
beta_i_perp = (2.0d0 * pi_perp_inf) / B00 ! ions
beta_e_perp = (2.0d0 * pe_perp_inf) / B00 ! elettrons
! useful quantities: "reduced" betas and gamma
! [see: Cerri et al., PoP 20, 112112 (2013)]
gam_tilde = (gam_e_perp - gam_i_perp)*gaminv_i_perp
beta_i_perp_tilde = beta_i_perp / (1.0d0 + beta_i_perp + beta_e_perp)
beta_e_perp_tilde = beta_e_perp / (1.0d0 + beta_i_perp + beta_e_perp)
if (mpime==0) then
write(6,*) ' ------------------------------------------------------------------ '
write(6,*) ' gam_i_perp, gam_i_para, gam_e_perp, gam_e_para, gam_tilde '
write(6,*) ' ',gam_i_perp, gam_i_para, gam_e_perp, gam_e_para, gam_tilde
write(6,*) ' Den_inf, pi_para_inf, pi_perp_inf, pe_para_inf, pe_perp_inf '
write(6,*) ' ',Den_inf, pi_para_inf, pi_perp_inf, pe_para_inf, pe_perp_inf
write(6,*) ' Ti_para_inf, Ti_perp_inf, Te_para_inf, Te_perp_inf '
write(6,*) ' ',Ti_para_inf, Ti_perp_inf, Te_para_inf, Te_perp_inf
write(6,*) ' beta_i_perp, beta_e_perp, beta_i_perp_tilde, beta_e_perp_tilde '
write(6,*) ' ',beta_i_perp, beta_e_perp, beta_i_perp_tilde, beta_e_perp_tilde
write(6,*) ' ------------------------------------------------------------------ '
endif
if (mpime==0) then
write(6,*) ' ----------------------------- '
write(6,*) ' Delta_N = ', DeltaDen
write(6,*) ' ----------------------------- '
endif
! compute FLR-correction function for equivalent MHD profiles
! [see: Cerri et al., PoP 20, 112112 (2013)]
if (flr_on .eq. 1) then
C_0 = (0.5d0/dsqrt(B00))*(Aeq / Leq)*beta_i_perp_tilde
equilDen(:) = 1.0d0 - 0.5d0*DeltaDen*Dinv_inf*(1.0d0 - dtanh((x(ixlg:ixlg+nxl-1) - xl*0.5d0 ) / Leq) )
f_0(:) = 1.0d0 / (1.0d0 - C_0*equilDen(:)*(1.0d0 - (dtanh((x(ixlg:ixlg+nxl-1) - xl*0.5d0 ) / Leq) )**2.0) )
else
f_0(:) = 1.0d0
endif
fnct(:) = equilDen(:) * f_0(:)
!*** Compute actual equilibrium profiles ***!
!density
do iz=1, nz
do iy=1, ny ! nyl == ny
Den(:,iy,iz) = Den_inf * (fnct(:)**gaminv_i_perp)
enddo
enddo
Dinv = 1.0d0 / Den
!gyrotropic ion pressures
do iz = 1, nz
do iy = 1, ny ! nyl == ny
pi_perp(:,iy,iz) = pi_perp_inf * fnct(:)
enddo
enddo
do iz=1, nz
do iy=1, ny ! nyl == ny
pi_para(:,iy,iz) = pi_para_inf * (fnct(:)**(gam_i_para*gaminv_i_perp))
enddo
enddo
!gyrotropic electron pressures
do iz = 1, nz
do iy = 1, ny ! nyl == ny
pe_perp(:,iy,iz) = pe_perp_inf * (fnct(:)**(gam_e_perp*gaminv_i_perp))
enddo
enddo
do iz=1, nz
do iy=1, ny ! nyl == ny
pe_para(:,iy,iz) = pe_para_inf * (fnct(:)**(gam_e_para*gaminv_i_perp))
enddo
enddo
!gyrotropic temperatures: simply T = p/n
Ti_perp = Dinv * pi_perp
Ti_para = Dinv * pi_para
Te_perp = Dinv * pe_perp
Te_para = Dinv * pe_para
!*** equilibrium magnetic field
!make sure that B is in (y,z) plane
!(i.e., not perpendicular to the flow)
Bx = 0.d0
!FLR-corrected equilibrium profile
equilB(:) = (1.0d0+beta_i_perp+beta_e_perp)*f_0(:) - (beta_i_perp+beta_e_perp)*fnct(:)
do iz=1, nz
do iy=1, ny ! nyl == ny
do ix=1, nxl
Bz(ix,iy,iz) = dsqrt(B00*equilB(ix)) * dcos(angolo)
enddo
enddo
enddo
do iz=1, nz
do iy=1, ny ! nyl == ny
do ix=1, nxl
By(ix,iy,iz) = dsqrt(B00*equilB(ix)) * dsin(angolo)
enddo
enddo
enddo
deallocate(f_0)
deallocate(fnct)
deallocate(equilB)
deallocate(equilDen)
!*****************************************************************!
! Compute: passive tracer (defined on the initial velocity shear) !
! [ note: this is problem dependent, adjust at will ] !
!*****************************************************************!
do iz = 1, nz
do ix = 1, nxl
Tracciante(ix,:,iz) = 0.6 + 0.4 * dtanh(( x(ix + ixlg - 1)-xl*0.5d0) / Leq)
enddo
enddo
!***********************************!
! Compute: initial current density !
!***********************************!
call corrente
!********************************************************!
! Compute: initial fluid velocities (ions and electrons) !
!********************************************************!
call u_ei
!*********************************!
! Compute: initial electric field !
!*********************************!
call ohm
!**************************!
! Compute: inital momentum !
!**************************!
nU_x = Den * Ux
nU_y = Den * Uy
nU_z = Den * Uz
CASE(+1) !istart = 1 -> Restart from existing RUN using the same timestep dt
!***********!
! RESTART !
! (same dt) !
!***********!
l_rst_me=l_rst+mpime
if ( mpime.lt.10 ) then
write( F_1, '(1i1)' ) mpime
filen_DT = 'DATA_TF_000'//F_1
endif
if ( mpime.ge.10.and.mpime.le.99 ) then
write( F_2, '(1i2)' ) mpime
filen_DT = 'DATA_TF_00'//F_2
endif
if ( mpime.gt.99 ) then
write( F_3, '(1i3)' ) mpime
filen_DT = 'DATA_TF_0'//F_3
endif
if ( (mpime.gt.999) .and. (mpime.le.9999) ) then
write( F_4, '(1i4)' ) mpime
filen_DT = 'DATA_TF_'//F_4
endif
OPEN(l_rst_me,status='unknown', form='unformatted',file=filen_DT)
READ(l_rst_me) ioutt, ioutx
READ(l_rst_me) tempo, tt_last, tx_last
READ(l_rst_me) Ti_para, Ti_perp, Te_para, Te_perp
READ(l_rst_me) Uex, Uey, Uez, Uix, Uiy, Uiz, Ux, Uy, Uz, Jx, Jy, Jz
READ(l_rst_me) Den, Dinv, pe_para, pe_perp, pi_para, pi_perp, nU_x, nU_y, nU_z
READ(l_rst_me) Ex, Ey, Ez, Bx, By, Bz, Tracciante!, Tracciante_e
CLOSE(l_rst_me)
CASE(+2) !istart = 2 -> Restart from existing RUN, but using a different timestep dt
!****************!
! RESTART !
! (different dt) !
!****************!
l_rst_me=l_rst+mpime
if ( mpime.lt.10 ) then
write( F_1, '(1i1)' ) mpime
filen_DT = 'DATA_TF_000'//F_1
endif
if ( (mpime.ge.10) .and. (mpime.le.99) ) then
write( F_2, '(1i2)' ) mpime
filen_DT = 'DATA_TF_00'//F_2
endif
if ( (mpime.gt.99) .and. (mpime.le.999) ) then
write( F_3, '(1i3)' ) mpime
filen_DT = 'DATA_TF_0'//F_3
endif
if ( (mpime.gt.999) .and. (mpime.le.9999) ) then
write( F_4, '(1i4)' ) mpime
filen_DT = 'DATA_TF_'//F_4
endif
OPEN(l_rst_me,status='unknown', form='unformatted',file=filen_DT)
READ(l_rst_me) ioutt, ioutx
READ(l_rst_me) tempo, tt_last, tx_last
READ(l_rst_me) Ti_para, Ti_perp, Te_para, Te_perp
READ(l_rst_me) Uex, Uey, Uez, Uix, Uiy, Uiz, Ux, Uy, Uz, Jx, Jy, Jz
READ(l_rst_me) Den, Dinv, pe_para, pe_perp, pi_para, pi_perp, nU_x, nU_y, nU_z
READ(l_rst_me) Ex, Ey, Ez, Bx, By, Bz, Tracciante
CLOSE(l_rst_me)
END SELECT
!*************************************!
! Compute: initial gyroviscous tensor !
!*************************************!
if (flr_on .eq. 1) then
write(6,*) ''
write(6,*) ' IONS FLR: ON! '
call flr_i
else !if (flr_on .eq. 0) then
write(6,*) ''
write(6,*) ' NO IONS FLR: G_i set to zero! '
Gi_xx = 0.0d0
Gi_xy = 0.0d0
Gi_xz = 0.0d0
Gi_yz = 0.0d0
!else
! write(6,*) ''
! write(6,*) '*****************************************'
! write(6,*) '*** !!! WARNING !!! ***'
! write(6,*) '*****************************************'
! write(6,*) '* invalid value for FLR_ON parameter! *'
! write(6,*) '* ------------------------------------- *'
! write(6,*) '* FLR_ON must have 1 or 0 value... *'
! write(6,*) '*****************************************'
endif
if (mpime==0) then
write(6,*) ' --------------------------------------------- '
write(6,*) 'SUBROUTINE CONDINIT, B00, angolo, Lx, Ly, Lz :'
write(6,805) B00, angolo, x(nx)-x(1), y(ny) - y(1), z(nz) - z(1)
write(6,*) ' --------------------------------------------- '
endif
622 format(1x, 2(2x, 1i4), 2(2x, 1e11.4))
822 format(1x, 2(2x, 1f5.1), 2(2x, 1e11.4))
802 format(1x, 2(2x, 1e11.4))
803 format(1x, 3(2x, 1e11.4))
805 format(1x, 5(2x, 1e11.4))
end subroutine