-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathavanzamento.f90
executable file
·570 lines (490 loc) · 14.2 KB
/
avanzamento.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
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
subroutine avanzamento
!****************************************************************!
! COMPUTE: time advance of the equations !
! [2D version] !
! -------------------------------------------------------------- !
! original version: F. Califano, 2006 !
! MPI parallel version: M. Faganello/F. Valentini, 2008 !
! Anisotropic/FLR-MHD version: S. S. Cerri, 2011 !
!****************************************************************!
use parameter_mod
use box_mod
use fields_UJ_mod
use fields_DP_mod
use fields_EB_mod
use dom_distr_mod
use parallel_mod
IMPLICIT NONE
INTEGER :: ix, iy, iz, ip,i
REAL(dp), ALLOCATABLE :: zx(:)
REAL(dp), ALLOCATABLE :: RHS_x(:,:,:), RHS_y(:,:,:), Den_intermedio(:,:,:)
REAL(dp), ALLOCATABLE :: pi_para_int(:,:,:), pi_perp_int(:,:,:)
REAL(dp), ALLOCATABLE :: pe_para_int(:,:,:), pe_perp_int(:,:,:)
REAL(dp), ALLOCATABLE :: trt1(:,:,:), trt2(:,:,:), trt3(:,:,:)
REAL(dp), ALLOCATABLE :: pi_para_n(:,:,:), pi_perp_n(:,:,:)
REAL(dp), ALLOCATABLE :: pe_para_n(:,:,:), pe_perp_n(:,:,:)
REAL(dp), ALLOCATABLE :: Tracciante_n(:,:,:)
REAL(dp), ALLOCATABLE :: Den_n(:,:,:)
REAL(dp), ALLOCATABLE :: nU_z_n(:,:,:), nU_x_n(:,:,:), nU_y_n(:,:,:)
REAL(dp), ALLOCATABLE :: Bx_n(:,:,:), By_n(:,:,:), Bz_n(:,:,:)
allocate( zx(nxl) )
allocate( RHS_x(nxl,ny,nz) ) !when needed, RHS_x is used instead of RHS_z to save memory
allocate( RHS_y(nxl,ny,nz) )
allocate( Den_intermedio(nxl,ny,nz) )
allocate( pi_para_int(nxl,ny,nz) )
allocate( pi_perp_int(nxl,ny,nz) )
allocate( pe_para_int(nxl,ny,nz) )
allocate( pe_perp_int(nxl,ny,nz) )
allocate( trt1(nx,nyt,nz) )
allocate( trt2(nx,nyt,nz) )
allocate( trt3(nx,nyt,nz) )
allocate( pi_para_n(nxl,nyl,nzl) )
allocate( pi_perp_n(nxl,nyl,nzl) )
allocate( pe_para_n(nxl,nyl,nzl) )
allocate( pe_perp_n(nxl,nyl,nzl) )
allocate( Tracciante_n(nxl,nyl,nzl) )
allocate( Den_n(nxl,nyl,nzl))
allocate( nU_z_n(nxl,nyl,nzl) )
allocate( nU_x_n(nxl,nyl,nzl) )
allocate( nU_y_n(nxl,nyl,nzl) )
allocate( Bx_n(nxl,nyl,nzl) )
allocate( By_n(nxl,nyl,nzl) )
allocate( Bz_n(nxl,nyl,nzl) )
!********************************************************!
! open boundary condition based on MHD characteristics !
! (see: Faganello et al., New J. Phys. 11, 063008 (2009) !
!********************************************************!
!
IF (ibc .EQ. 4) THEN
call BC
ENDIF
!support/auxiliary arrays
pi_para_n = pi_para
pi_perp_n = pi_perp
pe_para_n = pe_para
pe_perp_n = pe_perp
Tracciante_n = Tracciante
Den_n = Den
nU_z_n = nU_z
nU_x_n = nU_x
nU_y_n = nU_y
Bx_n = Bx
By_n = By
Bz_n = Bz
!************************!
!*** Runge-Kutta loop ***!
!************************!
DO i = rk_ord,1,-1 !RK loop: begins
!******************************!
! Compute: gyroviscous tensor !
!******************************!
!
! note: update gyroviscous tensor only if you have FLR_ON = 1
! (otherwise, they are kept = 0 from initial condition)
!
if (flr_on .eq. 1) then
call flr_i
endif
!*** LANDAU-FLUID closures: not available in this release
qi_para = 0.0
qi_perp = 0.0
qe_para = 0.0
qe_perp = 0.0
!*********************************************************************!
! Advancing: ion-pressure equations !
! ------------------------------------------------------------------- !
! (pressures are updated after the momentum equation is advanced too) !
!*********************************************************************!
call pressure_i(RHS_x,RHS_y) !RHS_x per pi_para e RHS_y per pi_perp
pi_para_int = pi_para_n + RHS_x * dt / float(i)
pi_perp_int = pi_perp_n + RHS_y * dt / float(i)
!--apply filters to ion pressures
!
!along x (open)
call traspdist(pi_para_int,trt1,1)
call traspdist(pi_perp_int,trt2,1)
do iz = 1, nz
do iy = 1, nyt
call filtro_open_x(trt1(:,iy,iz))
call filtro_open_x(trt2(:,iy,iz))
enddo
enddo
call traspdist(pi_para_int,trt1,-1)
call traspdist(pi_perp_int,trt2,-1)
!
!along y (periodic)
do iz = 1, nz
do ix = 1, nxl
call filtro_per_y(pi_para_int(ix,:,iz))
call filtro_per_y(pi_perp_int(ix,:,iz))
enddo
enddo
!
!along z (periodic)
![for 3D version: not released yet]
IF (nz.GT.1) THEN
do iy = 1, ny
do ix = 1, nxl
call filtro_per_z(pi_para_int(ix,iy,:))
call filtro_per_z(pi_perp_int(ix,iy,:))
enddo
enddo
ENDIF
!*********************************************************************!
! Advancing: electron-pressure equations !
! ------------------------------------------------------------------- !
! (pressures are updated after the momentum equation is advanced too) !
!*********************************************************************!
call pressure_e(RHS_x,RHS_y) !RHS_x per pe_para e RHS_y per pe_perp
pe_para_int = pe_para_n + RHS_x * dt / float(i)
pe_perp_int = pe_perp_n + RHS_y * dt / float(i)
!--apply filters to electron pressures
!
!along x (open)
call traspdist(pe_para_int,trt1,1)
call traspdist(pe_perp_int,trt2,1)
do iz = 1, nz
do iy = 1, nyt
call filtro_open_x(trt1(:,iy,iz))
call filtro_open_x(trt2(:,iy,iz))
enddo
enddo
call traspdist(pe_para_int,trt1,-1)
call traspdist(pe_perp_int,trt2,-1)
!
!along y (periodic)
do iz = 1, nz
do ix = 1, nxl
call filtro_per_y(pe_para_int(ix,:,iz))
call filtro_per_y(pe_perp_int(ix,:,iz))
enddo
enddo
!
!along z (periodic)
![for 3D version: not released yet]
IF (nz.GT.1) THEN
do iy = 1, ny
do ix = 1, nxl
call filtro_per_z(pe_para_int(ix,iy,:))
call filtro_per_z(pe_perp_int(ix,iy,:))
enddo
enddo
ENDIF
!************************************!
! Advancing: passive-tracer equation !
!************************************!
call trac(RHS_x)
Tracciante = Tracciante_n + RHS_x * dt / float(i)
!--apply filters to passive tracer
!
!along x (open)
call traspdist(Tracciante,trt1,1)
do iz = 1, nz
do iy = 1, nyt
call filtro_open_x(trt1(:,iy,iz))
enddo
enddo
call traspdist(Tracciante, trt1,-1)
!
!along y (periodic)
do iz = 1, nz
do ix = 1, nxl
call filtro_per_y(Tracciante(ix,:,iz))
enddo
enddo
!
!along z (periodic)
![for 3D version: not released yet]
IF (nz.GT.1) THEN
do iy = 1, ny
do ix = 1, nxl
call filtro_per_z(Tracciante(ix,iy,:))
enddo
enddo
ENDIF
!******************************************************************!
! Advancing: continuity equation !
! ---------------------------------------------------------------- !
! (density is updated after the momentum equation is advanced too) !
!******************************************************************!
call cont_n_U(RHS_x)
Den_intermedio = Den_n + RHS_x * dt / float(i)
!--apply filters to density
!
!along x (open)
call traspdist(Den_intermedio,trt1,1)
do iz = 1, nz
do iy = 1, nyt
call filtro_open_x(trt1(:,iy,iz))
enddo
enddo
call traspdist(Den_intermedio, trt1,-1)
!
!along y (periodic)
do iz = 1, nz
do ix = 1, nxl
call filtro_per_y(Den_intermedio(ix,:,iz))
enddo
enddo
!
!along z (periodic)
![for 3D version: not released yet]
IF (nz.GT.1) THEN
do iy = 1, ny
do ix = 1, nxl
call filtro_per_z(Den_intermedio(ix,iy,:))
enddo
enddo
ENDIF
!****************************************!
! Advancing: one-fluid momentum equation !
!****************************************!
!--momentum equation along z
call moto_z(RHS_x) ! using RHS_x rather than RHS_z to save memory
nU_z = nU_z_n + RHS_x * dt / float(i)
!--momentum equation in (x,y) plane
call moto_xy(RHS_x, RHS_y)
nU_x = nU_x_n + RHS_x * dt / float(i)
nU_y = nU_y_n + RHS_y * dt / float(i)
!--apply filters to one-fluid momentum
!
!along x (open)
call traspdist(nU_x,trt1,1)
call traspdist(nU_y,trt2,1)
call traspdist(nU_z,trt3,1)
do iz = 1, nz
do iy = 1, nyt
call filtro_open_x(trt1(:,iy,iz))
call filtro_open_x(trt2(:,iy,iz))
call filtro_open_x(trt3(:,iy,iz))
enddo
enddo
call traspdist(nU_x,trt1,-1)
call traspdist(nU_y,trt2,-1)
call traspdist(nU_z,trt3,-1)
!
!along y (periodic)
do iz = 1, nz
do ix = 1, nxl
call filtro_per_y(nU_x(ix,:,iz))
call filtro_per_y(nU_y(ix,:,iz))
call filtro_per_y(nU_z(ix,:,iz))
enddo
enddo
!
!along z (periodic)
![for 3D version: not released yet]
IF (nz.GT.1) THEN
do iy = 1, ny
do ix = 1, nxl
call filtro_per_z(nU_x(ix,iy,:))
call filtro_per_z(nU_y(ix,iy,:))
call filtro_per_z(nU_z(ix,iy,:))
enddo
enddo
ENDIF
!*****************************!
! Advancing: Faraday equation !
!*****************************!
!--Faraday equation along x
call faraday_x(RHS_x)
Bx = Bx_n + RHS_x * dt / float(i)
!--Faraday equation along y
call faraday_y(RHS_y)
By = By_n + RHS_y * dt / float(i)
!--Faraday equation along z
call faraday_z(RHS_x) ! using RHS_x rather than RHS_z to save memory
Bz = Bz_n + RHS_x * dt / float(i)
!--apply filters to B
!
!along x (open)
call traspdist(Bx,trt1,1)
call traspdist(By,trt2,1)
call traspdist(Bz,trt3,1)
do iz = 1, nz
do iy = 1, nyt
call filtro_open_x(trt1(:,iy,iz))
call filtro_open_x(trt2(:,iy,iz))
call filtro_open_x(trt3(:,iy,iz))
enddo
enddo
call traspdist(Bx,trt1,-1)
call traspdist(By,trt2,-1)
call traspdist(Bz,trt3,-1)
!
!along y (periodic)
do iz = 1, nz
do ix = 1, nxl
call filtro_per_y(Bx(ix,:,iz))
call filtro_per_y(By(ix,:,iz))
call filtro_per_y(Bz(ix,:,iz))
enddo
enddo
!
!along z (periodic)
![for 3D version: not released yet]
IF (nz.GT.1) THEN
do iy = 1, ny
do ix = 1, nxl
call filtro_per_z(Bx(ix,iy,:))
call filtro_per_z(By(ix,iy,:))
call filtro_per_z(Bz(ix,iy,:))
enddo
enddo
ENDIF
!****************!
! Update density !
!****************!
Den = Den_intermedio
Dinv = 1.0d0 / Den
!**************************************************!
! Compute one-fluid velocity U !
! ------------------------------------------------ !
! (from one-fluid momentum, using updated density) !
!**************************************************!
Ux = nU_x * Dinv
Uy = nU_y * Dinv
Uz = nU_z * Dinv
!***********************************!
! Update pressures (with smoothing) !
!***********************************!
!--"effective" isotropic pressures at x-boundaries ( = 1/3 Tr[P] )
pi_para = terzo * ( 2.0d0 * pi_perp_int + pi_para_int )
pe_para = terzo * ( 2.0d0 * pe_perp_int + pe_para_int )
!--smoothing to recover the effective pressures at x-boundaries
!
!ions
do ix = 1, nxl
pi_para(ix,:,:) = lambda(ixlg + ix - 1) * pi_para_int(ix,:,:) + &
( 1.0d0 - lambda(ixlg + ix - 1) ) * pi_para(ix,:,:)
enddo
do ix = 1, nxl
pi_perp(ix,:,:) = lambda(ixlg + ix - 1) * pi_perp_int(ix,:,:) + &
( 1.0d0 - lambda(ixlg + ix - 1) ) * pi_para(ix,:,:)
enddo
!
!electrons
do ix = 1, nxl
pe_para(ix,:,:) = lambda(ixlg + ix - 1) * pe_para_int(ix,:,:) + &
( 1.0d0 - lambda(ixlg + ix - 1) ) * pe_para(ix,:,:)
enddo
do ix = 1, nxl
pe_perp(ix,:,:) = lambda(ixlg + ix - 1) * pe_perp_int(ix,:,:) + &
( 1.0d0 - lambda(ixlg + ix - 1) ) * pe_para(ix,:,:)
enddo
!--associated temperatures
Ti_para = Dinv * pi_para
Ti_perp = Dinv * pi_perp
Te_para = Dinv * pe_para
Te_perp = Dinv * pe_perp
!*************************************!
! Compute current density J = curl(B) !
!*************************************!
call corrente
!--apply filters to J
!
!along x (open)
call traspdist(Jx,trt1,1)
call traspdist(Jy,trt2,1)
call traspdist(Jz,trt3,1)
do iz = 1, nz
do iy = 1, nyt
call filtro_open_x(trt1(:,iy,iz))
call filtro_open_x(trt2(:,iy,iz))
call filtro_open_x(trt3(:,iy,iz))
enddo
enddo
call traspdist(Jx,trt1,-1)
call traspdist(Jy,trt2,-1)
call traspdist(Jz,trt3,-1)
!
!along y (periodic)
do iz = 1, nz
do ix = 1, nxl
call filtro_per_y(Jx(ix,:,iz))
call filtro_per_y(Jy(ix,:,iz))
call filtro_per_y(Jz(ix,:,iz))
enddo
enddo
!
!along z (periodic)
![for 3D version: not released yet]
IF (nz.GT.1) THEN
do iy = 1, ny
do ix = 1, nxl
call filtro_per_z(Jx(ix,iy,:))
call filtro_per_z(Jy(ix,iy,:))
call filtro_per_z(Jz(ix,iy,:))
enddo
enddo
ENDIF
!************************************!
! Computing species' fluid velocitiy !
!************************************!
call u_ei
!****************************************************!
! Compute: Electric field from generalized Ohm's law !
!****************************************************!
call ohm
!--apply filters to E
!
!along x (open)
call traspdist(Ex,trt1,1)
call traspdist(Ey,trt2,1)
call traspdist(Ez,trt3,1)
do iz = 1, nz
do iy = 1, nyt
call filtro_open_x(trt1(:,iy,iz))
call filtro_open_x(trt2(:,iy,iz))
call filtro_open_x(trt3(:,iy,iz))
enddo
enddo
call traspdist(Ex,trt1,-1)
call traspdist(Ey,trt2,-1)
call traspdist(Ez,trt3,-1)
!
!along y (periodic)
do iz = 1, nz
do ix = 1, nxl
call filtro_per_y(Ex(ix,:,iz))
call filtro_per_y(Ey(ix,:,iz))
call filtro_per_y(Ez(ix,:,iz))
enddo
enddo
!
!along z (periodic)
![for 3D version: not released yet]
IF (nz.GT.1) THEN
do iy = 1, ny
do ix = 1, nxl
call filtro_per_z(Ex(ix,iy,:))
call filtro_per_z(Ey(ix,iy,:))
call filtro_per_z(Ez(ix,iy,:))
enddo
enddo
ENDIF
ENDDO !RK loop: ends
deallocate(Den_intermedio)
deallocate(pi_para_int)
deallocate(pi_perp_int)
deallocate(pe_para_int)
deallocate(pe_perp_int)
deallocate(pi_para_n)
deallocate(pi_perp_n)
deallocate(pe_para_n)
deallocate(pe_perp_n)
deallocate(Tracciante_n)
deallocate(Den_n)
deallocate(nU_z_n)
deallocate(nU_y_n)
deallocate(nU_x_n)
deallocate(Bx_n)
deallocate(By_n)
deallocate(Bz_n)
deallocate(zx)
deallocate(RHS_x)
deallocate(RHS_y)
deallocate(trt1)
deallocate(trt2)
deallocate(trt3)
end subroutine