-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathout.f90
1893 lines (1667 loc) · 72 KB
/
out.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
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
! *****************************************************************************
! * *
! * ECHO-QGP *
! * *
! * Version: 1.5.0-apha *
! * *
! * Copyright (C) 2015-2019 The ECHO-QGP team *
! * *
! * File: out.f90 *
! * *
! * License: GPL version 2.0 (Please, read the file LICENSE.TXT) *
! * *
! * This program is free software; you can redistribute it and/or *
! * modify it under the terms of the GNU General Public License *
! * as published by the Free Software Foundation; either version 2 *
! * of the License, or (at your option) any later version. *
! * *
! * This program is distributed in the hope that it will be useful, *
! * but WITHOUT ANY WARRANTY; without even the implied warranty of *
! * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
! * GNU General Public License for more details. *
! * *
! * You should have received a copy of the GNU General Public License *
! * along with this program; if not, write to the Free Software *
! * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
! * Boston, MA 02110-1301, USA. *
! * *
! * Authors: Luca Del Zanna ([email protected]) *
! * Gabriele Inghirami ([email protected]) *
! * *
! * Contributors: *
! * *
! * Acknowledgments: *
! * *
! *****************************************************************************
! development note: careful to the mpi_realtype if we switch from/to 4/8 bytes real precision
module out
use parallel
use common
use eos
use hypersurface
implicit none
integer ldir
integer itime1,itime2,iratio
integer output
real(KIND=8), allocatable, dimension(:,:,:) :: arr_to_print_8
real(KIND=8), allocatable, dimension(:,:,:) :: arr_to_print_8_bis
real(KIND=8), allocatable, dimension(:,:,:) :: arr_to_print_8_ter
real(KIND=8), allocatable, dimension(:,:,:) :: arr_to_print_8_quater
real(KIND=8), allocatable, dimension(:,:,:) :: arr_to_print_8_quinquies
contains
! *****************************************************************************
subroutine out_alloc
!-- Allocate in/out arrays
implicit none
integer :: allocate_result
integer :: i !just for counting
if (pe0) then
if (id_of_the_run<10000) write (dir_out,'(a4,i4,a1)') 'outr' ,id_of_the_run,'/'
if (id_of_the_run<1000) write (dir_out,'(a5,i3,a1)') 'outr0' ,id_of_the_run,'/'
if (id_of_the_run<100) write (dir_out,'(a6,i2,a1)') 'outr00' ,id_of_the_run,'/'
if (id_of_the_run<10) write (dir_out,'(a7,i1,a1)') 'outr000', id_of_the_run,'/'
commandline_outdir_length=len_trim(adjustl(custom_output_directory))
if(commandline_outdir_length .gt. 0) then
allocate(character(len=len_trim(adjustl(custom_output_directory))+10) :: prefix_dir)
prefix_dir=trim(adjustl(custom_output_directory))//"/"//dir_out
else
allocate(character(len=9) :: prefix_dir)
prefix_dir=dir_out
end if
if(out_freeze) then
call allocate_hypersurface_arrays
end if
allocate(arr_to_print_8(nx,ny,nz), arr_to_print_8_bis(nx,ny,nz), arr_to_print_8_ter(nx,ny,nz), stat=allocate_result)
if(allocate_result /=0) then
write(*,*) "Proc.0 - Error, I can't allocate the arr_to_print_8 arrays into out_alloc"
write(*,*) "(Problem in source file out.f90, subroutine out_alloc)"
call exit(1)
end if
if(viscosity) then
allocate(arr_to_print_8_quater(nx,ny,nz), arr_to_print_8_quinquies(nx,ny,nz), stat=allocate_result)
if(allocate_result /=0) then
write(*,*) "Proc.0 - Error, I can't allocate the arr_to_print_8_quater/quinquies array into out_alloc"
write(*,*) "(Problem in source file out.f90, subroutine out_alloc)"
call exit(1)
end if
end if
end if
!even if these arrays are used only in parallel runs, since they are small for simplicity we always allocate them
allocate(recvcounts(0:npe-1), displs(0:npe-1), stat=allocate_result)
if(allocate_result /=0) then
write(*,*) "Error, I can't allocate recvcounts or displs array for the MPI_Gatherv funcion (source file common.f08)"
call exit(1)
end if
if((restart_type .ne. 0) .and. (pe0)) then
allocate(uall(nx,ny,nz,1:nv), vallold(nx,ny,nz,krh:kvold_end), uallold(nx,ny,nz,krh:kvold_end), stat=allocate_result)
if(allocate_result /=0) then
write(*,*) "Proc.0 - Error, I can't allocate 'uall', 'vallold' or/and 'uallold' arrays into out_alloc"
write(*,*) "(Problem in source file out.f90, subroutine out_alloc)"
call exit(1)
end if
uall=0.
vallold=0.
uallold=0.
end if
displs(0)=0
if (prl) then
do i=0,npe-1
if (i .lt. ipec) then
recvcounts(i)=nx/npe+1
else
recvcounts(i)=nx/npe
end if
if(i .gt. 0) displs(i)=displs(i-1)+recvcounts(i-1)
end do
end if
if(pe0 .and. derivatives_out) then
allocate(derivatives_all(nx,ny,nz,1:nderivatives), stat=allocate_result)
if(allocate_result /=0) then
write(*,*) "Proc.0 - Error, I can't allocate 'derivatives_all' array into out_alloc"
write(*,*) "(source file out.f08)"
call exit(1)
end if
end if
end subroutine out_alloc
! *****************************************************************************
subroutine out_vars_summary()
!-- Write data on file 'vars_summary.dat'
use viscous
if (pe0) then
if (id_of_the_run<10000) write (dir_out,'(a4,i4,a1)') 'outr' ,id_of_the_run,'/'
if (id_of_the_run<1000) write (dir_out,'(a5,i3,a1)') 'outr0' ,id_of_the_run,'/'
if (id_of_the_run<100) write (dir_out,'(a6,i2,a1)') 'outr00' ,id_of_the_run,'/'
if (id_of_the_run<10) write (dir_out,'(a7,i1,a1)') 'outr000', id_of_the_run,'/'
if(commandline_outdir_length .gt. 0) then
prefix_dir=trim(adjustl(custom_output_directory))//"/"//dir_out
else
prefix_dir=dir_out
end if
open (13,file=prefix_dir//'vars_summary.dat',form='formatted',status='replace')
013 format(i1,a35)
write(13,*) 'Summary of variable printed in the output files. 1 means printed, 0 not printed'
if(output_precision .eq. 4) then
write(13,013) 4, 'precision'
else
write(13,013) 8, 'precision'
end if
write(13,013) out_sel%density, 'density'
write(13,013) out_sel%vx,'vx'
write(13,013) out_sel%vy,'vy'
write(13,013) out_sel%vz,'vz'
write(13,013) out_sel%pressure,'pressure'
write(13,013) out_sel%energy_density, 'energy_density'
write(13,013) out_sel%temperature, 'temperature'
write(13,013) out_sel%entropy_density, 'entropy_density'
if (viscosity) then
write(13,013) out_sel%bulk, 'bulk viscosity'
write(13,013) out_sel%pitt, 'pi^tt shear tensor component'
write(13,013) out_sel%pitx, 'pi^tx shear tensor component'
write(13,013) out_sel%pity, 'pi^ty shear tensor component'
write(13,013) out_sel%pitz, 'pi^tz shear tensor component'
write(13,013) out_sel%pixy, 'pi^xy shear tensor component'
write(13,013) out_sel%pixz, 'pi^xz shear tensor component'
write(13,013) out_sel%piyz, 'pi^yz shear tensor component'
write(13,013) out_sel%pixx, 'pi^xx shear tensor component'
write(13,013) out_sel%piyy, 'pi^yy shear tensor component'
write(13,013) out_sel%pizz, 'pi^zz shear tensor component'
else
write(13,013) 0, 'bulk viscosity'
write(13,013) 0, 'pi^tt shear tensor component'
write(13,013) 0, 'pi^tx shear tensor component'
write(13,013) 0, 'pi^ty shear tensor component'
write(13,013) 0, 'pi^tz shear tensor component'
write(13,013) 0, 'pi^xy shear tensor component'
write(13,013) 0, 'pi^xz shear tensor component'
write(13,013) 0, 'pi^yz shear tensor component'
write(13,013) 0, 'pi^xx shear tensor component'
write(13,013) 0, 'pi^yy shear tensor component'
write(13,013) 0, 'pi^zz shear tensor component'
end if
write(13,013) out_sel%v0, 'vt (or gamma Lorentz factor)'
if (mhd) then
write(13,013) out_sel%bx, 'Bx'
write(13,013) out_sel%by, 'By'
write(13,013) out_sel%bz, 'Bz'
write(13,013) out_sel%ex, 'Ex'
write(13,013) out_sel%ey, 'Ey'
write(13,013) out_sel%ez, 'Ez'
if(divclean) write(13,013) out_sel%glm, 'GLM'
write(13,013) out_sel%rc, 'el. charge density in comoving frame'
else
write(13,013) 0, 'Bx'
write(13,013) 0, 'By'
write(13,013) 0, 'Bz'
write(13,013) 0, 'Ex'
write(13,013) 0, 'Ey'
write(13,013) 0, 'Ez'
write(13,013) 0, 'GLM'
write(13,013) 0, 'el. charge density in comoving frame'
end if
close (13)
end if
end subroutine out_vars_summary
! *****************************************************************************
subroutine out_vars(iout,nooverwrite)
!-- Write data on file 'out000n.dat'
use system_eqgp, only: g_cov,system_EXB,system_compute_E_in_ideal_MHD
use eos
use evolve
use viscous
integer,intent(inout) :: iout
integer :: lv,i,lvm,lvp,proc
integer :: iii,jjj,kkk,lll,mmm,nnn
real(8) energy_density_value
real(8) temperature_value
real(8) entropy_density_value
real(8),dimension(1:3) :: E_field
character(len=7) :: fname
integer :: nooverwrite
logical :: retrieve_derived_data
integer :: error_flag
077 format(e14.8)
error_flag=0
if((out_sel%energy_density .eq. 1) .or. (out_sel%temperature .eq. 1) .or. (out_sel%entropy_density .eq. 1)) then
retrieve_derived_data=.true.
else
retrieve_derived_data=.false.
end if
if (pe0) then
if (iout<10000) write (fname,'(a3,i4)') 'out' ,iout
if (iout<1000) write (fname,'(a4,i3)') 'out0' ,iout
if (iout<100) write (fname,'(a5,i2)') 'out00' ,iout
if (iout<10) write (fname,'(a6,i1)') 'out000', iout
if (id_of_the_run<10000) write (dir_out,'(a4,i4,a1)') 'outr' ,id_of_the_run,'/'
if (id_of_the_run<1000) write (dir_out,'(a5,i3,a1)') 'outr0' ,id_of_the_run,'/'
if (id_of_the_run<100) write (dir_out,'(a6,i2,a1)') 'outr00' ,id_of_the_run,'/'
if (id_of_the_run<10) write (dir_out,'(a7,i1,a1)') 'outr000', id_of_the_run,'/'
if(commandline_outdir_length .gt. 0) then
prefix_dir=trim(adjustl(custom_output_directory))//"/"//dir_out
else
prefix_dir=dir_out
end if
open (10,file=prefix_dir//fname//'.dat',form='unformatted', access='stream',status='replace')
if(nooverwrite .eq. 0) then
open (21,file=prefix_dir//'time.dat',form='formatted',status='replace')
else
open (21,file=prefix_dir//'time.dat',form='formatted',status='old',access='append')
end if
call system_clock(itime1)
if(output_precision .eq. 8) then
write (10) t
else
write (10) real(t,4)
end if
write (21,"(I5,f16.9)") iout,t
close (21)
end if
if((out_sel%rc .eq. 1) .and. mhd) call compute_rho_comoving_frame
call collect_distributed_arrays
if(pe0) then
if(output_precision .eq. 8) then
if(out_sel%density .eq. 1) then
write(10) vall(:,:,:,krh)
end if
if(out_sel%vx .eq. 1) then
write(10) vall(:,:,:,kvx)
end if
if(out_sel%vy .eq. 1) then
write(10) vall(:,:,:,kvy)
end if
if(out_sel%vz .eq. 1) then
write(10) vall(:,:,:,kvz)
end if
if(out_sel%pressure .eq. 1) then
write(10) vall(:,:,:,kpr)
end if
if(retrieve_derived_data) then
do nnn=1,nz
do mmm=1,ny
do lll=1,nx
call get_derived_data(vall(lll,mmm,nnn,krh),vall(lll,mmm,nnn,kpr), energy_density_value,&
&temperature_value, entropy_density_value,error_flag )
if(error_flag .gt. 0) then
write(*,*) "Error into the out_vars subroutine when trying to get derived quantities (temp, entr_dens, en_dens)"
errcode=error_flag
write(*,*) "Error code:", errcode
write(*,*) "Position on the grid: ix=",lll,"iy=",mmm,"iz=",nnn
run_crashed=.true.
return
end if
arr_to_print_8(lll,mmm,nnn)=energy_density_value
arr_to_print_8_bis(lll,mmm,nnn)=temperature_value
arr_to_print_8_ter(lll,mmm,nnn)=entropy_density_value
end do
end do
end do
if(out_sel%energy_density .eq. 1) write(10) arr_to_print_8
if(out_sel%temperature .eq. 1) write(10) arr_to_print_8_bis
if(out_sel%entropy_density .eq. 1) write(10) arr_to_print_8_ter
end if !end if retrieve data
if(viscosity) then
if (out_sel%bulk .eq. 1) then
write(10) vall(:,:,:,kpibu)
end if
if((out_sel%pitx .eq. 1) .or. (out_sel%pity .eq. 1) .or. (out_sel%pitt .eq. 1) .or. &
& (out_sel%pitz .eq. 1) ) then
if(obtained .eq. 'no') then
do nnn=1,nz
do mmm=1,ny
do lll=1,nx
call get_derived_pi(vall(lll,mmm,nnn,:),arr_to_print_8(lll,mmm,nnn),arr_to_print_8_bis(lll,mmm,nnn),&
&arr_to_print_8_ter(lll,mmm,nnn),arr_to_print_8_quater(lll,mmm,nnn))
end do
end do
end do
else
do nnn=1,nz
do mmm=1,ny
do lll=1,nx
call get_derived_pi_zz(vall(lll,mmm,nnn,:),arr_to_print_8(lll,mmm,nnn),arr_to_print_8_bis(lll,mmm,nnn),&
&arr_to_print_8_ter(lll,mmm,nnn),arr_to_print_8_quater(lll,mmm,nnn),arr_to_print_8_quinquies(lll,mmm,nnn))
end do
end do
end do
end if
end if
if(out_sel%pitt .eq. 1) write(10) arr_to_print_8
if(out_sel%pitx .eq. 1) write(10) arr_to_print_8_bis
if(out_sel%pity .eq. 1) write(10) arr_to_print_8_ter
if(out_sel%pitz .eq. 1) write(10) arr_to_print_8_quater
if(out_sel%pixy .eq. 1) then
write(10) vall(:,:,:,kpixy)
end if
if(out_sel%pixz .eq. 1) then
write(10) vall(:,:,:,kpixz)
end if
if(out_sel%piyz .eq. 1) then
write(10) vall(:,:,:,kpiyz)
end if
if(out_sel%pixx .eq. 1) then
write(10) vall(:,:,:,kpixx)
end if
if(out_sel%piyy .eq. 1) then
write(10) vall(:,:,:,kpiyy)
end if
if(out_sel%pizz .eq. 1) then
write(10) arr_to_print_8_quinquies
end if
end if !end if viscosity
if(out_sel%v0 .eq. 1) then
arr_to_print_8=1./sqrt(1.-vall(:,:,:,kvx)**2.*g_cov(1)-vall(:,:,:,kvy)**2.*g_cov(2)-vall(:,:,:,kvz)**2.*g_cov(3))
write(10) arr_to_print_8
end if
if(mhd) then
if(out_sel%bx .eq. 1) then
write(10) vall(:,:,:,kbx)
end if
if(out_sel%by .eq. 1) then
write(10) vall(:,:,:,kby)
end if
if(out_sel%bz .eq. 1) then
write(10) vall(:,:,:,kbz)
end if
if(rmhd) then
if(out_sel%ex .eq. 1) then
write(10) vall(:,:,:,kex)
end if
if(out_sel%ey .eq. 1) then
write(10) vall(:,:,:,key)
end if
if(out_sel%ez .eq. 1) then
write(10) vall(:,:,:,kez)
end if
else
if((out_sel%ex .eq. 1) .or. (out_sel%ey .eq. 1) .or. (out_sel%ez .eq. 1)) then
do nnn=1,nz
do mmm=1,ny
do lll=1,nx
call system_compute_E_in_ideal_MHD(vall(lll,mmm,nnn,kvx:kvz), vall(lll,mmm,nnn,kbx:kbz), E_field)
arr_to_print_8(lll,mmm,nnn)=E_field(1)
arr_to_print_8_bis(lll,mmm,nnn)=E_field(2)
arr_to_print_8_ter(lll,mmm,nnn)=E_field(3)/g_cov(3) !because the previous function returns E covariant
end do
end do
end do
if(out_sel%ex .eq. 1) write(10) arr_to_print_8
if(out_sel%ey .eq. 1) write(10) arr_to_print_8_bis
if(out_sel%ez .eq. 1) write(10) arr_to_print_8_ter
end if !end check any E field component to print
end if!end else rmhd
if(divclean .and. (out_sel%glm .eq. 1)) then
write(10) vall(:,:,:,kglm)
end if
if(out_sel%rc .eq. 1) then
write(10) vall(:,:,:,krc)
end if
end if !end if mhd
close (10)
else!output precision 4 bytes
if(out_sel%density .eq. 1) then
write(10) real(vall(:,:,:,krh),4)
end if
if(out_sel%vx .eq. 1) then
write(10) real(vall(:,:,:,kvx),4)
end if
if(out_sel%vy .eq. 1) then
write(10) real(vall(:,:,:,kvy),4)
end if
if(out_sel%vz .eq. 1) then
write(10) real(vall(:,:,:,kvz),4)
end if
if(out_sel%pressure .eq. 1) then
write(10) real(vall(:,:,:,kpr),4)
end if
if(retrieve_derived_data) then
do nnn=1,nz
do mmm=1,ny
do lll=1,nx
call get_derived_data(vall(lll,mmm,nnn,krh),vall(lll,mmm,nnn,kpr), energy_density_value,&
&temperature_value, entropy_density_value,error_flag )
if(error_flag .gt. 0) then
write(*,*) "Error into the out_vars subroutine when trying to get derived quantities (temp, entr_dens, en_dens)"
errcode=error_flag
write(*,*) "Error code:", errcode
write(*,*) "Position on the grid: ix=",lll,"iy=",mmm,"iz=",nnn
run_crashed=.true.
return
end if
arr_to_print_8(lll,mmm,nnn)=energy_density_value
arr_to_print_8_bis(lll,mmm,nnn)=temperature_value
arr_to_print_8_ter(lll,mmm,nnn)=entropy_density_value
end do
end do
end do
if(out_sel%energy_density .eq. 1) write(10) real(arr_to_print_8,4)
if(out_sel%temperature .eq. 1) write(10) real(arr_to_print_8_bis,4)
if(out_sel%entropy_density .eq. 1) write(10) real(arr_to_print_8_ter,4)
end if !end if retrieve data
if(viscosity) then
if (out_sel%bulk .eq. 1) then
write(10) real(vall(:,:,:,kpibu),4)
end if
if((out_sel%pitx .eq. 1) .or. (out_sel%pity .eq. 1) .or. (out_sel%pitt .eq. 1) .or. &
& (out_sel%pitz .eq. 1) ) then
if(obtained .eq. 'no') then
do nnn=1,nz
do mmm=1,ny
do lll=1,nx
call get_derived_pi(vall(lll,mmm,nnn,:),arr_to_print_8(lll,mmm,nnn),arr_to_print_8_bis(lll,mmm,nnn),&
&arr_to_print_8_ter(lll,mmm,nnn),arr_to_print_8_quater(lll,mmm,nnn))
end do
end do
end do
else
do nnn=1,nz
do mmm=1,ny
do lll=1,nx
call get_derived_pi_zz(vall(lll,mmm,nnn,:),arr_to_print_8(lll,mmm,nnn),arr_to_print_8_bis(lll,mmm,nnn),&
&arr_to_print_8_ter(lll,mmm,nnn),arr_to_print_8_quater(lll,mmm,nnn),arr_to_print_8_quinquies(lll,mmm,nnn))
end do
end do
end do
end if
end if
if(out_sel%pitt .eq. 1) write(10) real(arr_to_print_8,4)
if(out_sel%pitx .eq. 1) write(10) real(arr_to_print_8_bis,4)
if(out_sel%pity .eq. 1) write(10) real(arr_to_print_8_ter,4)
if(out_sel%pitz .eq. 1) write(10) real(arr_to_print_8_quater,4)
if(out_sel%pixy .eq. 1) then
write(10) real(vall(:,:,:,kpixy),4)
end if
if(out_sel%pixz .eq. 1) then
write(10) real(vall(:,:,:,kpixz),4)
end if
if(out_sel%piyz .eq. 1) then
write(10) real(vall(:,:,:,kpiyz),4)
end if
if(out_sel%pixx .eq. 1) then
write(10) real(vall(:,:,:,kpixx),4)
end if
if(out_sel%piyy .eq. 1) then
write(10) real(vall(:,:,:,kpiyy),4)
end if
if(out_sel%pizz .eq. 1) then
write(10) real(arr_to_print_8_quinquies,4)
end if
end if !end if viscosity
if(out_sel%v0 .eq. 1) then
arr_to_print_8=1./sqrt(1.-vall(:,:,:,kvx)**2.*g_cov(1)-vall(:,:,:,kvy)**2.*g_cov(2)-vall(:,:,:,kvz)**2.*g_cov(3))
write(10) real(arr_to_print_8,4)
end if
if(mhd) then
if(out_sel%bx .eq. 1) then
write(10) real(vall(:,:,:,kbx),4)
end if
if(out_sel%by .eq. 1) then
write(10) real(vall(:,:,:,kby),4)
end if
if(out_sel%bz .eq. 1) then
write(10) real(vall(:,:,:,kbz),4)
end if
if(rmhd) then
if(out_sel%ex .eq. 1) then
write(10) real(vall(:,:,:,kex),4)
end if
if(out_sel%ey .eq. 1) then
write(10) real(vall(:,:,:,key),4)
end if
if(out_sel%ez .eq. 1) then
write(10) real(vall(:,:,:,kez),4)
end if
else
if((out_sel%ex .eq. 1) .or. (out_sel%ey .eq. 1) .or. (out_sel%ez .eq. 1)) then
do nnn=1,nz
do mmm=1,ny
do lll=1,nx
call system_compute_E_in_ideal_MHD(vall(lll,mmm,nnn,kvx:kvz), vall(lll,mmm,nnn,kbx:kbz), E_field)
arr_to_print_8(lll,mmm,nnn)=E_field(1)
arr_to_print_8_bis(lll,mmm,nnn)=E_field(2)
arr_to_print_8_ter(lll,mmm,nnn)=E_field(3)/g_cov(3) !because the previous function returns E covariant
end do
end do
end do
if(out_sel%ex .eq. 1) write(10) real(arr_to_print_8,4)
if(out_sel%ey .eq. 1) write(10) real(arr_to_print_8_bis,4)
if(out_sel%ez .eq. 1) write(10) real(arr_to_print_8_ter,4)
end if!end out_sel%ex...
end if !end if rmhd
if(divclean .and. (out_sel%glm .eq. 1 )) then
write(10) real(vall(:,:,:,kglm),4)
end if
if(out_sel%rc .eq. 1) then
write(10) real(vall(:,:,:,krc),4)
end if
end if !end if mhd
close (10)
end if !end if precision 4
endif !end if pe0
if(derivatives_out) call out_derivatives(iout,1)
if(pe0) then
if(flows_out) call compute_on_transverse_plane(iout,error_flag)
end if
if(pe0) then
call system_clock(itime2,iratio)
print '(3x,2(a,f12.8),a)','Time:',t,' - '//fname//'.dat',real((itime2-itime1),8)/real(iratio,8),' secs'
end if
end subroutine out_vars
! *****************************************************************************
subroutine compute_rho_comoving_frame
use evolve
implicit none
integer i, j, k, il, ih, jl, jh, kl, kh
real(KIND=8) :: time_now, time_past, dt, dx, dy, dz, g
real(KIND=8) :: Ex_now, Ey_now, Ez_now, Ex_past, Ey_past, Ez_past, Ex_now_p, Ex_now_m, Ey_now_p, Ey_now_m, Ez_now_p, Ez_now_m
real(KIND=8) :: dBxcov_dy, dBxcov_dz, dBycov_dx, dBycov_dz, dBzcov_dx, dBzcov_dy, dExcont_dx
real(KIND=8) :: dEycont_dy, dEzcont_dz, dExcont_dt, dEycont_dt, dEzcont_dt, Jx, Jy, Jz, divE, curlBx, curlBy, curlBz, Jdotv
! here we define the covariant four velocity, its derivatives and the right/left cell four vectors to compute the derivatives
real(KIND=8) :: uu0,uu1,uu2,uu3,du01,du02,du03,du12,du13,du21,du23,du31,du32,du10,du20,du30
real(KIND=8) :: u0rx,u0ry,u0rz,u1ry,u1rz,u2rx,u2rz,u3rx,u3ry!values of u covariant components at the right cell along x,y or z
real(KIND=8) :: u0lx,u0ly,u0lz,u1ly,u1lz,u2lx,u2lz,u3lx,u3ly!values of u covariant components at the left cell along x,y or z
real(KIND=8) :: g_past,uu0_past,uu1_past,uu2_past,uu3_past!values of the gamma Lorentz factor and 4 velocity components in the past
real(KIND=8) :: grx,glx,gry,gly,grz,glz!values of the gamma Lorentz factor at right and left cell along x,y or z
logical, save :: not_first_time=.false.
logical, parameter :: maxwell=.false.
real(KIND=8), parameter :: e0123=1.d0, e1023=-1.d0, e0132=-1.d0, e0312=1.d0, e3012=-1.d0, e3021=1.d0, e3201=-1.d0, e3210=1.d0
real(KIND=8), parameter :: e0321=-1.d0, e0231=1.d0, e0213=-1.d0, e2013=1.d0, e2031=-1.d0, e1032=1.d0, e1320=1.d0, e1302=-1.d0
real(KIND=8), parameter :: e1230=-1.d0, e1203=1.d0, e2310=-1.d0, e2301=1.d0, e3120=-1.d0, e3102=1.d0, e2130=1.d0, e2103=-1.d0
real(KIND=8) :: om0,om1,om2,om3!components of the kinematic vorticity four-vector
real(KIND=8) :: vdotB,bb0,bb1,bb2,bb3!v_k B^k and components of the magnetic field four-vector as in eq. 36 of arXiv:1609.03042
!if the time has not changed, we don't recompute rho comov
if(t==time_comp_rho_comov) return
if(t==tmin) return
if(coordinates .eq. 1) then
time_now=1
time_past=1
else
time_now=t
time_past=timeold
end if
dt=t-timeold
dz=2.d0/ddz(1)
dx=2.d0/ddx(1)
dy=2.d0/ddy(1)
if((nx==1) .or. (ny==1)) then
write(*,*) "Sorry, but the computation of the charge density works only with both nx and ny > 1"
call exit(4)
end if
w(ix1:ix2,iy1:iy2,iz1:iz2,1:kvold_end)=v(ix1:ix2,iy1:iy2,iz1:iz2,1:kvold_end)
call evolve_bcx(ix1,iy1,iz1,1,kvold_end,kv(1:kvold_end))
w(ix1:ix2,iy1:iy2,iz1:iz2,1:kvold_end)=v(ix1:ix2,iy1:iy2,iz1:iz2,1:kvold_end)
call evolve_bcy(ix1,iy1,iz1,1,kvold_end,kv(1:kvold_end))
if (nz>1) then
w(ix1:ix2,iy1:iy2,iz1:iz2,1:kvold_end)=v(ix1:ix2,iy1:iy2,iz1:iz2,1:kvold_end)
call evolve_bcz(ix1,iy1,iz1,1,kvold_end,kv(1:kvold_end))
if(maxwell) then
do k=iz1,iz2
do j=iy1,iy2
do i=ix1,ix2
dBxcov_dy=(w(i,j+1,k,kbx)-w(i,j-1,k,kbx))/dy
dBxcov_dz=(w(i,j,k+1,kbx)-w(i,j,k-1,kbx))/dz
dBycov_dx=(w(i+1,j,k,kby)-w(i-1,j,k,kby))/dx
dBycov_dz=(w(i,j,k+1,kby)-w(i,j,k-1,kby))/dz
dBzcov_dx=g_cov(3)*(w(i+1,j,k,kbz)-w(i-1,j,k,kbz))/dx
dBzcov_dy=g_cov(3)*(w(i,j+1,k,kbz)-w(i,j-1,k,kbz))/dy
Ex_now=-time_now*(v(i,j,k,kvy)*v(i,j,k,kbz)-v(i,j,k,kvz)*v(i,j,k,kby))
Ex_now_p=-time_now*(w(i+1,j,k,kvy)*w(i+1,j,k,kbz)-w(i+1,j,k,kvz)*w(i+1,j,k,kby))
Ex_now_m=-time_now*(w(i-1,j,k,kvy)*w(i-1,j,k,kbz)-w(i-1,j,k,kvz)*w(i-1,j,k,kby))
Ey_now=-time_now*(v(i,j,k,kvz)*v(i,j,k,kbx)-v(i,j,k,kvx)*v(i,j,k,kbz))
Ey_now_p=-time_now*(w(i,j+1,k,kvz)*w(i,j+1,k,kbx)-w(i,j+1,k,kvx)*w(i,j+1,k,kbz))
Ey_now_m=-time_now*(w(i,j-1,k,kvz)*w(i,j-1,k,kbx)-w(i,j-1,k,kvx)*w(i,j-1,k,kbz))
Ez_now=-(v(i,j,k,kvx)*v(i,j,k,kby)-v(i,j,k,kvy)*v(i,j,k,kbx))/time_now
Ez_now_p=-(w(i,j,k+1,kvx)*w(i,j,k+1,kby)-w(i,j,k+1,kvy)*w(i,j,k+1,kbx))/time_now
Ez_now_m=-(w(i,j,k-1,kvx)*w(i,j,k-1,kby)-w(i,j,k-1,kvy)*w(i,j,k-1,kbx))/time_now
Ex_past=-time_past*(vold(i,j,k,kvy)*vold(i,j,k,kbz)-vold(i,j,k,kvz)*vold(i,j,k,kby))
Ey_past=-time_past*(vold(i,j,k,kvz)*vold(i,j,k,kbx)-vold(i,j,k,kvx)*vold(i,j,k,kbz))
Ez_past=-(vold(i,j,k,kvx)*vold(i,j,k,kby)-vold(i,j,k,kvy)*vold(i,j,k,kbx))/time_past
dExcont_dx=(Ex_now_p-Ex_now_m)/dx
dEycont_dy=(Ey_now_p-Ey_now_m)/dy
dEzcont_dz=(Ez_now_p-Ez_now_m)/dz
dExcont_dt=(time_now*Ex_now-time_past*Ex_past)/dt
dEycont_dt=(time_now*Ey_now-time_past*Ey_past)/dt
dEzcont_dt=(time_now*Ez_now-time_past*Ez_past)/dt
g=1/sqrt(1-v(i,j,k,kvx)**2-v(i,j,k,kvy)**2-v(i,j,k,kvz)**2*g_cov(3))
divE=dExcont_dx+dEycont_dy+dEzcont_dz
curlBx=dBzcov_dy-dBycov_dz
curlBy=dBxcov_dz-dBzcov_dx
curlBz=dBycov_dx-dBxcov_dy
Jx=(curlBx-dExcont_dt)/time_now
Jy=(curlBy-dEycont_dt)/time_now
Jz=(curlBz-dEzcont_dt)/time_now
Jdotv=Jx*v(i,j,k,kvx)+Jy*v(i,j,k,kvy)+Jz*v(i,j,k,kvz)*g_cov(3)
v(i,j,k,krc)=g*(divE-Jdotv)
end do
end do
end do
else !we compute the charge density using the vorticity
do k=iz1,iz2
do j=iy1,iy2
do i=ix1,ix2
g=1.d0/sqrt(1.d0-w(i,j,k,kvx)**2-w(i,j,k,kvy)**2-w(i,j,k,kvz)**2*time_now**2)
uu0=-g!u0 covariant
uu1=g*w(i,j,k,kvx)
uu2=g*w(i,j,k,kvy)
uu3=g*w(i,j,k,kvz)*time_now**2
g_past=1.d0/sqrt(1.d0-vold(i,j,k,kvx)**2-vold(i,j,k,kvy)**2-vold(i,j,k,kvz)**2*time_past**2)
uu0_past=-g_past!u0 covariant at previous timestep
uu1_past=g_past*vold(i,j,k,kvx)
uu2_past=g_past*vold(i,j,k,kvy)
uu3_past=g_past*vold(i,j,k,kvz)*time_past**2
grx=1.d0/sqrt(1.d0-w(i+1,j,k,kvx)**2-w(i+1,j,k,kvy)**2-w(i+1,j,k,kvz)**2*time_now**2)
glx=1.d0/sqrt(1.d0-w(i-1,j,k,kvx)**2-w(i-1,j,k,kvy)**2-w(i-1,j,k,kvz)**2*time_now**2)
gry=1.d0/sqrt(1.d0-w(i,j+1,k,kvx)**2-w(i,j+1,k,kvy)**2-w(i,j+1,k,kvz)**2*time_now**2)
gly=1.d0/sqrt(1.d0-w(i,j-1,k,kvx)**2-w(i,j-1,k,kvy)**2-w(i,j-1,k,kvz)**2*time_now**2)
grz=1.d0/sqrt(1.d0-w(i,j,k+1,kvx)**2-w(i,j,k+1,kvy)**2-w(i,j,k+1,kvz)**2*time_now**2)
glz=1.d0/sqrt(1.d0-w(i,j,k-1,kvx)**2-w(i,j,k-1,kvy)**2-w(i,j,k-1,kvz)**2*time_now**2)
u1ry=gry*w(i,j+1,k,kvx)
u1ly=gly*w(i,j-1,k,kvx)
u1rz=grz*w(i,j,k+1,kvx)
u1lz=glz*w(i,j,k-1,kvx)
u2rx=grx*w(i+1,j,k,kvy)
u2lx=glx*w(i-1,j,k,kvy)
u2rz=grz*w(i,j,k+1,kvy)
u2lz=glz*w(i,j,k-1,kvy)
u3rx=grx*w(i+1,j,k,kvz)*time_now**2
u3lx=glx*w(i-1,j,k,kvz)*time_now**2
u3ry=gry*w(i,j+1,k,kvz)*time_now**2
u3ly=gly*w(i,j-1,k,kvz)*time_now**2
!we recall that dx, dy and dz are already two times the cell spacing, see their definiton above
du10=(uu1-uu1_past)/dt!du_x/dt
du20=(uu2-uu2_past)/dt!du_y/dt
du30=(uu3-uu3_past)/dt!du_z/dt
du01=-(grx-glx)/dx!du_0/dx=-d_gammaLorentz/dx
du02=-(gry-gly)/dy!du_0/dy=-d_gammaLorentz/dy
du03=-(grz-glz)/dz!du_0/dz=-d_gammaLorentz/dz
du12=(u1ry-u1ly)/dy!du_x/dy
du13=(u1rz-u1lz)/dz!du_x/dz
du21=(u2rx-u2lx)/dx!du_y/dx
du23=(u2rz-u2lz)/dz!du_y/dz
du31=(u3rx-u3lx)/dx!du_z/dx
du32=(u3ry-u3ly)/dy!du_z/dy
!we use eq. A1 in https://arxiv.org/pdf/1904.01530.pdf
om0=(e1203*du21*uu3+e2103*du12*uu3+e3102*du13*uu2+e1302*du31*uu2+e2301*du32*uu1+e3201*du23*uu1)/time_now
om1=(e0213*du20*uu3+e2013*du02*uu3+e0312*du30*uu2+e3012*du03*uu2+e2310*du32*uu0+e3210*du23*uu0)/time_now
om2=(e0123*du10*uu3+e1023*du01*uu3+e0321*du30*uu1+e3021*du03*uu1+e1320*du31*uu0+e3120*du13*uu0)/time_now
om3=(e0231*du20*uu1+e2031*du02*uu1+e0132*du10*uu2+e1032*du01*uu2+e1230*du21*uu0+e2130*du12*uu0)/time_now
vdotB=w(i,j,k,kvx)*w(i,j,k,kbx)+w(i,j,k,kvy)*w(i,j,k,kby)+w(i,j,k,kvz)*w(i,j,k,kbz)*time_now**2
bb0=g*vdotB
bb1=w(i,j,k,kbx)/g+g*vdotB*w(i,j,k,kvx)
bb2=w(i,j,k,kby)/g+g*vdotB*w(i,j,k,kvy)
bb3=w(i,j,k,kbz)/g+g*vdotB*w(i,j,k,kvz)
!eq A6 of https://arxiv.org/pdf/1904.01530.pdf
v(i,j,k,krc)=-(-om0*bb0+om1*bb1+om2*bb2+om3*bb3*time_now**2)
end do
end do
end do
end if
else !2D case
if(maxwell) then
do k=iz1,iz2
do j=iy1,iy2
do i=ix1,ix2
dBxcov_dy=(w(i,j+1,k,kbx)-w(i,j-1,k,kbx))/dy
dBxcov_dz=0.
dBycov_dx=(w(i+1,j,k,kby)-w(i-1,j,k,kby))/dx
dBycov_dz=0.
dBzcov_dx=g_cov(3)*(w(i+1,j,k,kbz)-w(i-1,j,k,kbz))/dx
dBzcov_dy=g_cov(3)*(w(i,j+1,k,kbz)-w(i,j-1,k,kbz))/dy
Ex_now=-time_now*(v(i,j,k,kvy)*v(i,j,k,kbz)-v(i,j,k,kvz)*v(i,j,k,kby))
Ex_now_p=-time_now*(w(i+1,j,k,kvy)*w(i+1,j,k,kbz)-w(i+1,j,k,kvz)*w(i+1,j,k,kby))
Ex_now_m=-time_now*(w(i-1,j,k,kvy)*w(i-1,j,k,kbz)-w(i-1,j,k,kvz)*w(i-1,j,k,kby))
Ey_now=-time_now*(v(i,j,k,kvz)*v(i,j,k,kbx)-v(i,j,k,kvx)*v(i,j,k,kbz))
Ey_now_p=-time_now*(w(i,j+1,k,kvz)*w(i,j+1,k,kbx)-w(i,j+1,k,kvx)*w(i,j+1,k,kbz))
Ey_now_m=-time_now*(w(i,j-1,k,kvz)*w(i,j-1,k,kbx)-w(i,j-1,k,kvx)*w(i,j-1,k,kbz))
Ez_now=-(v(i,j,k,kvx)*v(i,j,k,kby)-v(i,j,k,kvy)*v(i,j,k,kbx))/time_now
Ez_now_p=-(w(i,j,k+1,kvx)*w(i,j,k+1,kby)-w(i,j,k+1,kvy)*w(i,j,k+1,kbx))/time_now
Ez_now_m=-(w(i,j,k-1,kvx)*w(i,j,k-1,kby)-w(i,j,k-1,kvy)*w(i,j,k-1,kbx))/time_now
Ex_past=-time_past*(vold(i,j,k,kvy)*vold(i,j,k,kbz)-vold(i,j,k,kvz)*vold(i,j,k,kby))
Ey_past=-time_past*(vold(i,j,k,kvz)*vold(i,j,k,kbx)-vold(i,j,k,kvx)*vold(i,j,k,kbz))
Ez_past=-(vold(i,j,k,kvx)*vold(i,j,k,kby)-vold(i,j,k,kvy)*vold(i,j,k,kbx))/time_past
dExcont_dx=(Ex_now_p-Ex_now_m)/dx
dEycont_dy=(Ey_now_p-Ey_now_m)/dy
dEzcont_dz=0.
dExcont_dt=(time_now*Ex_now-time_past*Ex_past)/dt
dEycont_dt=(time_now*Ey_now-time_past*Ey_past)/dt
dEzcont_dt=(time_now*Ez_now-time_past*Ez_past)/dt
g=1/sqrt(1-v(i,j,k,kvx)**2-v(i,j,k,kvy)**2-v(i,j,k,kvz)**2*g_cov(3))
divE=dExcont_dx+dEycont_dy+dEzcont_dz
curlBx=dBzcov_dy-dBycov_dz
curlBy=dBxcov_dz-dBzcov_dx
curlBz=dBycov_dx-dBxcov_dy
Jx=(curlBx-dExcont_dt)/time_now
Jy=(curlBy-dEycont_dt)/time_now
Jz=(curlBz-dEzcont_dt)/time_now
Jdotv=Jx*v(i,j,k,kvx)+Jy*v(i,j,k,kvy)+Jz*v(i,j,k,kvz)*g_cov(3)
v(i,j,k,krc)=g*(divE-Jdotv)
end do
end do
end do
else !we compute the charge density using the vorticity
do k=iz1,iz2
do j=iy1,iy2
do i=ix1,ix2
g=1.d0/sqrt(1.d0-w(i,j,k,kvx)**2-w(i,j,k,kvy)**2-w(i,j,k,kvz)**2*time_now**2)
uu0=-g!u0 covariant
uu1=g*w(i,j,k,kvx)
uu2=g*w(i,j,k,kvy)
uu3=g*w(i,j,k,kvz)*time_now**2
g_past=1.d0/sqrt(1.d0-vold(i,j,k,kvx)**2-vold(i,j,k,kvy)**2-vold(i,j,k,kvz)**2*time_past**2)
uu0_past=-g_past!u0 covariant at previous timestep
uu1_past=g_past*vold(i,j,k,kvx)
uu2_past=g_past*vold(i,j,k,kvy)
uu3_past=g_past*vold(i,j,k,kvz)*time_past**2
grx=1.d0/sqrt(1.d0-w(i+1,j,k,kvx)**2-w(i+1,j,k,kvy)**2-w(i+1,j,k,kvz)**2*time_now**2)
glx=1.d0/sqrt(1.d0-w(i-1,j,k,kvx)**2-w(i-1,j,k,kvy)**2-w(i-1,j,k,kvz)**2*time_now**2)
gry=1.d0/sqrt(1.d0-w(i,j+1,k,kvx)**2-w(i,j+1,k,kvy)**2-w(i,j+1,k,kvz)**2*time_now**2)
gly=1.d0/sqrt(1.d0-w(i,j-1,k,kvx)**2-w(i,j-1,k,kvy)**2-w(i,j-1,k,kvz)**2*time_now**2)
u1ry=gry*w(i,j+1,k,kvx)
u1ly=gly*w(i,j-1,k,kvx)
u2rx=grx*w(i+1,j,k,kvy)
u2lx=glx*w(i-1,j,k,kvy)
u3rx=grx*w(i+1,j,k,kvz)
u3lx=glx*w(i-1,j,k,kvz)
u3ry=gry*w(i,j+1,k,kvz)
u3ly=gly*w(i,j-1,k,kvz)
!we recall that dx, dy and dz are already two times the cell spacing, see their definiton above
du10=(uu1-uu1_past)/dt!du_x/dt
du20=(uu2-uu2_past)/dt!du_y/dt
du30=(uu3-uu3_past)/dt!du_z/dt
du01=-(grx-glx)/dx!du_0/dx=-d_gammaLorentz/dx
du02=-(gry-gly)/dy!du_0/dy=-d_gammaLorentz/dy
du03=0.d0!du_0/dz
du12=(u1ry-u1ly)/dy!du_x/dy
du13=0.d0!du_x/dz
du21=(u2rx-u2lx)/dx!du_y/dx
du23=0.d0!du_y/dz
du31=(u3rx-u3lx)/dx!du_z/dx
du32=(u3ry-u3ly)/dy!du_z/dy
!we use eq. A1 in https://arxiv.org/pdf/1904.01530.pdf
om0=(e1203*du21*uu3+e2103*du12*uu3+e3102*du13*uu2+e1302*du31*uu2+e2301*du32*uu1+e3201*du23*uu1)/time_now
om1=(e0213*du20*uu3+e2013*du02*uu3+e0312*du30*uu2+e3012*du03*uu2+e2310*du32*uu0+e3210*du23*uu0)/time_now
om2=(e0123*du10*uu3+e1023*du01*uu3+e0321*du30*uu1+e3021*du03*uu1+e1320*du31*uu0+e3120*du13*uu0)/time_now
om3=(e0231*du20*uu1+e2031*du02*uu1+e0132*du10*uu2+e1032*du01*uu2+e1230*du21*uu0+e2130*du12*uu0)/time_now
vdotB=w(i,j,k,kvx)*w(i,j,k,kbx)+w(i,j,k,kvy)*w(i,j,k,kby)+w(i,j,k,kvz)*w(i,j,k,kbz)*time_now**2
bb0=g*vdotB
bb1=w(i,j,k,kbx)/g+g*vdotB*w(i,j,k,kvx)
bb2=w(i,j,k,kby)/g+g*vdotB*w(i,j,k,kvy)
bb3=w(i,j,k,kbz)/g+g*vdotB*w(i,j,k,kvz)
!eq A6 of https://arxiv.org/pdf/1904.01530.pdf
v(i,j,k,krc)=-(-om0*bb0+om1*bb1+om2*bb2+om3*bb3*time_now**2)
end do
end do
end do
end if
end if
time_comp_rho_comov=t
end subroutine compute_rho_comoving_frame
! *****************************************************************************
subroutine out_derivatives(iout, compute_or_print)
!-- Write data on file 'der000n.dat'
use system_eqgp, only: g_cov
use work
use evolve
use viscous
integer,intent(inout) :: iout
integer :: lv,i,lvm,lvp,proc
integer :: iii,jjj,kkk,lll,mmm,nnn
character(len=7) :: fname
integer :: ix,iy,iz
integer :: error_flag, allocate_result
real(8) :: v2, glf, vx, vy, vz, sum_der, sum_der_t, sum_der_0, sum_der_x, sum_der_y, sum_der_z
real(8) :: dutdt, dutdx, dutdy, dutdz, duxdx, duydy, duzdz, duzdt, duzdx, duzdy, duxdt, duxdy, duxdz, duydt, duydx, duydz
real(8) :: dtedt, dtedx, dtedy, dtedz, temperature
real(8) :: uxr, uyr, uzr, uxl, uyl, uzl, glfr, glfl, tempr, templ, ds, enr, enl
integer :: ixc, iyc, izc !used to simplify some indexese inside a loop
!bitbucket variables just to call correctly the get_derived_data subroutine
real(8) :: energy_density_bb, entropy_density_bb, temperature_bb
integer, parameter :: kind_of_deriv=0 !if 1 it uses the reconstruction algorithm, otherwise the second order derivative
integer, intent(in) :: compute_or_print !if 0 it only computes derivatives, if 1 it also prints them
error_flag=0
if (pe0 .and. (compute_or_print .eq. 1)) then
if (iout<10000) write (fname,'(a3,i4)') 'der' ,iout
if (iout<1000) write (fname,'(a4,i3)') 'der0' ,iout
if (iout<100) write (fname,'(a5,i2)') 'der00' ,iout
if (iout<10) write (fname,'(a6,i1)') 'der000', iout
if (id_of_the_run<10000) write (dir_out,'(a4,i4,a1)') 'outr' ,id_of_the_run,'/'
if (id_of_the_run<1000) write (dir_out,'(a5,i3,a1)') 'outr0' ,id_of_the_run,'/'
if (id_of_the_run<100) write (dir_out,'(a6,i2,a1)') 'outr00' ,id_of_the_run,'/'
if (id_of_the_run<10) write (dir_out,'(a7,i1,a1)') 'outr000', id_of_the_run,'/'
if(commandline_outdir_length .gt. 0) then
prefix_dir=trim(adjustl(custom_output_directory))//"/"//dir_out
else
prefix_dir=dir_out
end if
open (15,file=prefix_dir//fname//'.dat',form='unformatted', access='stream')
if(output_precision .eq. 8) then
write (15) t
else
write (15) real(t,4)
end if
end if
w(ix1:ix2,iy1:iy2,iz1:iz2,1:nv)=v(ix1:ix2,iy1:iy2,iz1:iz2,1:nv)
if(kind_of_deriv .eq. 1) then
if (nx>1) then
call evolve_bcx(ix1,iy1,iz1,1,nv,kv(1:nv))
do iz=iz1,iz2
do iy=iy1,iy2
do ix=1-ngc, mx+ngc
ixc=ix1+ix-1
wd(ix,1)=1./sqrt(1.-w(ixc,iy,iz,kvx)**2.-w(ixc,iy,iz,kvy)**2.-g_cov(3)*w(ixc,iy,iz,kvz)**2.)
wd(ix,2)=wd(ix,1)*w(ixc,iy,iz,kvx)
wd(ix,3)=wd(ix,1)*w(ixc,iy,iz,kvy)
wd(ix,4)=wd(ix,1)*w(ixc,iy,iz,kvz)
if(freeze_type .eq. 0) then
call get_derived_data(w(ixc,iy,iz,krh), w(ixc,iy,iz,kpr), energy_density_bb, wd(ix,5), entropy_density_bb,error_flag)
else
call get_derived_data(w(ixc,iy,iz,krh), w(ixc,iy,iz,kpr), wd(ix,5), temperature_bb, entropy_density_bb,error_flag)
end if
if(error_flag .gt. 0) then
write(*,*) "Error into the out_vars subroutine when trying to get derived quantities (temp, entr_dens, en_dens)"
errcode=error_flag
write(*,*) "Error code:", errcode
write(*,*) "Position on the grid: ix=",ix,"iy=",iy,"iz=",iz
run_crashed=.true.
return
end if
end do
call work_rec(mx,1,5,1)
deriv(ix1:ix2,iy,iz,dtx)=ddx(ix1:ix2)*0.5*( wdl(1:mx,1) + wdr(1:mx,1) - wdl(0:mx-1,1) - wdr(0:mx-1,1))
deriv(ix1:ix2,iy,iz,dxx)=ddx(ix1:ix2)*0.5*( wdl(1:mx,2) + wdr(1:mx,2) - wdl(0:mx-1,2) - wdr(0:mx-1,2))
deriv(ix1:ix2,iy,iz,dyx)=ddx(ix1:ix2)*0.5*( wdl(1:mx,3) + wdr(1:mx,3) - wdl(0:mx-1,3) - wdr(0:mx-1,3))
deriv(ix1:ix2,iy,iz,dzx)=ddx(ix1:ix2)*0.5*( wdl(1:mx,4) + wdr(1:mx,4) - wdl(0:mx-1,4) - wdr(0:mx-1,4))
deriv(ix1:ix2,iy,iz,dtex)=ddx(ix1:ix2)*0.5*( wdl(1:mx,5) + wdr(1:mx,5) - wdl(0:mx-1,5) - wdr(0:mx-1,5))
end do
end do
end if
if(ny>1) then
call evolve_bcy(ix1,iy1,iz1,1,nv,kv(1:nv))
do iz=iz1,iz2
do ix=ix1,ix2
do iy=1-ngc, my+ngc
iyc=iy1+iy-1
wd(iy,1)=1./sqrt(1.-w(ix,iyc,iz,kvx)**2.-w(ix,iyc,iz,kvy)**2.-g_cov(3)*w(ix,iyc,iz,kvz)**2.)
wd(iy,2)=wd(iy,1)*w(ix,iyc,iz,kvx)
wd(iy,3)=wd(iy,1)*w(ix,iyc,iz,kvy)
wd(iy,4)=wd(iy,1)*w(ix,iyc,iz,kvz)
if(freeze_type .eq. 0) then
call get_derived_data(w(ix,iyc,iz,krh), w(ix,iyc,iz,kpr), energy_density_bb, wd(iy,5), entropy_density_bb,error_flag)
else
call get_derived_data(w(ix,iyc,iz,krh), w(ix,iyc,iz,kpr), wd(iy,5), temperature_bb, entropy_density_bb,error_flag)
end if
if(error_flag .gt. 0) then
write(*,*) "Error into the out_vars subroutine when trying to get derived quantities (temp, entr_dens, en_dens)"
errcode=error_flag
write(*,*) "Error code:", errcode
write(*,*) "Position on the grid: ix=",ix,"iy=",iy,"iz=",iz
run_crashed=.true.
return
end if
end do
call work_rec(my,1,5,1)
deriv(ix,iy1:iy2,iz,dty)=ddy(iy1:iy2)*0.5*( wdl(1:my,1) + wdr(1:my,1) - wdl(0:my-1,1) - wdr(0:my-1,1))
deriv(ix,iy1:iy2,iz,dxy)=ddy(iy1:iy2)*0.5*( wdl(1:my,2) + wdr(1:my,2) - wdl(0:my-1,2) - wdr(0:my-1,2))
deriv(ix,iy1:iy2,iz,dyy)=ddy(iy1:iy2)*0.5*( wdl(1:my,3) + wdr(1:my,3) - wdl(0:my-1,3) - wdr(0:my-1,3))
deriv(ix,iy1:iy2,iz,dzy)=ddy(iy1:iy2)*0.5*( wdl(1:my,4) + wdr(1:my,4) - wdl(0:my-1,4) - wdr(0:my-1,4))
deriv(ix,iy1:iy2,iz,dtey)=ddy(iy1:iy2)*0.5*( wdl(1:my,5) + wdr(1:my,5) - wdl(0:my-1,5) - wdr(0:my-1,5))
end do
end do
end if
if (nz>1) then