-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwrite_vtk_3D.F90
1544 lines (1232 loc) · 43.7 KB
/
write_vtk_3D.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
module ntypes
integer, parameter :: r4=4
integer, parameter :: r8=8
integer, parameter :: i4=4
end module ntypes
!DOMAIN
module Domain
use ntypes
integer(i4) :: NX, NY, NZ, N_TH, NXM, NYM, NZM, TNKZ, TNKY
integer(i4) :: NKX,s11
integer(i4) :: NXP,NZP,NXV,NZV, NKXV, NKXP,NX2V,NX2P,NXP_L,NX2P_L
integer(i4) :: ni,nj,np,mm,nk_en,nk,y_1,y_2,y_3, nk_st,ii
parameter (nk_st=10672, nk_en=10764)
! parameter (nk=NZ+2, nj=NY+2, ni=NX)
!INCLUDE 'grid_def'
integer(i4) :: np1,np2, np3
! parameter(np1 = ni, np3 = nj-2, np2 = nk-2)
end module Domain
!GRID
module Grid
use ntypes
real(r8) :: LX, LY, LZ, CSX, CSY, CSZ !Length
real(r8) :: TH_3D, U_1, V_1, W_1, PR_TOT
INTEGER :: jstart, jend , ZSTART, ZEND
!
real(r8),allocatable,dimension(:) :: GX, GY, GZ, DX, DY, DZ, &
GXF, GYF, GZF, DXF, DYF, DZF
real(r8),allocatable,dimension(:,:) :: xpoint, ypoint
end module Grid
!run_variable
module run_variable
use ntypes
use Domain
logical :: READING_FLOW, grid_write
real(r4),allocatable,dimension(:,:,:) :: g1vtk(:),g2vtk(:),g3vtk(:), &
var_1(:),var_2(:)
! g1vtk(1:ni),g2vtk(1:nk),g3vtk(1:nj), var_1(1:3*np1*np2*np3)
real(r4) :: xL
!real(r4) :: vrms(1:np1,1:np2),wrms(1:np1,1:np2), &
! u1(1:np1,1:np2),u2(1:np1,1:np2), u3(1:np1,1:np2),
! &
! th_div(1:np1,1:np2,1:N_TH),th_wh(1:np1,1:np2,1:N_TH+1),
! &
! cp(1:np1,1:np2)
Real(r8) DX_s,DZ_s,time_old, time_sum, delta_time,time,dt,ubulk
real(r8),allocatable,dimension(:,:,:) :: x,y,z,u,v,w,u1,u2,u3
real(r8),allocatable,dimension(:,:,:) :: th,pr_3D
real(r8),allocatable,dimension(:,:,:) :: x_c,y_c,z_c,th_wh_c, &
u2_c,u3_c,f1_c
real(r8),allocatable,dimension(:,:,:) :: u1_avg,u2_avg,u3_avg,s1
real(r8),allocatable,dimension(:,:) :: u2_avg_2D, th_avg_2D,thv_avg_2D
real(r8),allocatable,dimension(:,:,:) :: varSP_zstar
real(r8),allocatable,dimension(:,:) :: rho_1D_tot
real(r4),allocatable,dimension(:,:,:) :: th_wh,th_wh_avg, omega_x
Real(r8) :: th_b
real(r8),allocatable,dimension(:) :: H_hill_tot, DX_hill
integer, allocatable,dimension(:) :: hill_ind_tot
real(r8) :: u_0,Gravity,alpha_T, NU, rho_0
parameter (u_0=0.125, Gravity = 10.0d0, alpha_T = 2.0d0*10.0d0**(-4.0),&
NU = 10.0**(-6), rho_0 = 1000.0d0)
real(r8) :: sum_Prod, sum_dissp, sum_buoyF, sum_Prod_avg, sum_dissp_avg, &
sum_buoyF_avg, sum_wstress, &
sum_dtkdt, sum_vis, sum_trans, sum_advec, dv,ds, vol_box
integer :: i_1, j_1, i_2, i_3,j_3
parameter (i_1 = 152, j_1 = 45, i_2 = i_1, i_3 = i_1, j_3 =118 )
integer :: imax,jmax,kmax,pp,jj,p_p,p_m
integer :: debug,ier,itot ! local_Y(3,ni)
integer :: tecini,tecdat,teczne,tecnod,tecfil,tecend
integer :: visdouble,disdouble,i_strt,i_end,j_strt,j_end
character*1 nulchar
! real(r8) :: var_1_spectrum(2*np),var_2_spectrum(2*np)
! CHARACTER*34 file_name_1,file_name_3
! CHARACTER*18 file_name_2
! CHARACTER*31 file_name_4
LOGICAL :: TKE_FIELD, WRITE_TECP, X_PLANE,Y_PLANE,INTER_pol_y, &
INTER_pol_z, vorticity_cal, PE_cal, WRITE_PARA_View,CAL_STAT_AVG, IBM
end module run_variable
module qsort_c_module
implicit none
public :: QsortC
private :: Partition
contains
recursive subroutine QsortC(A,B)
use ntypes
real(r8), intent(in out), dimension(:) :: A
real(r8), intent(in out), dimension(:) :: B
integer :: iq
!write(6,*) 'MADE IT INTO QSORTC'
!write(6,*) 'iq = ', iq
! write(6,*) 'INSIDE QsortC: rho_1D_tot(5000,1) = ', rho_1D_tot(5000,1)
if (size(A) > 1) then
call Partition(A,B,iq)
call QsortC(A(:iq-1),B(:iq-1))
call QsortC(A(iq:),B(iq:))
endif
end subroutine QsortC
subroutine Partition(A,B,marker)
use ntypes
real(r8), intent(in out), dimension(:) :: A
real(r8), intent(in out), dimension(:) :: B
integer, intent(out) :: marker
integer :: i, j
real(r8) :: temp
real(r8) :: x ! pivot point
x = A(1)
i = 0
j = size(A) + 1
do
j = j-1
do
if (A(j) <= x) exit
j = j-1
end do
i = i+1
do
if (A(i) >= x) exit
i = i+1
end do
if (i < j) then
! exchange A(i) and A(j)
temp = A(i)
A(i) = A(j)
A(j) = temp
temp = B(j)
B(j) = B(i)
B(i) = temp
elseif (i == j) then
marker = i+1
return
else
marker = i
return
endif
end do
end subroutine Partition
end module qsort_c_module
Program main
use ntypes
use Domain
use Grid
use run_variable
implicit none
integer :: i,j,k,kk,p
! integer np1,np2,np3
!FILENAMES
character(len=100) :: InFileName, OutFileName
character(len=100) :: dataDIR, outputDIR
character(len=80) :: basename
!OTHER STRINGS
character(len=25) :: ss
! real(r4),allocatable,dimension(:) :: g1vtk,g2vtk,g3vtk
! real(4) :: g1vtk(1:np1),g3vtk(1:np2),g2vtk(1:np3), var_1(1:3*np1*np2*np3)
! real(4) :: th_wh(np1,np3,np2)
real(8) :: sum_1, sum_2
CHARACTER*5 file_num
CHARACTER*39 file_name_1,file_time
CHARACTER*16 base_name
character(len=18) :: title
! X_PLANE = .FALSE.
! Y_PLANE = .FALSE.
! WRITE_TECP = .FALSE.
WRITE_PARA_View = .FALSE.
IBM = .FALSE.
PE_cal = .FALSE.
CAL_STAT_AVG = .TRUE.
vorticity_cal = .FALSE.
! Inter_pol_y = .FALSE.
! Inter_pol_z = .FALSE.
outputDIR='plane_data_3D/'
basename = 'data_binary_3D'
write(OutFileName,'(a,a,i5.5,a4)') trim(outputDIR), &
trim(basename)//"_n",nk_st,".pln"
open(unit=22,file=OutFileName,access='stream', &
form='unformatted',status='old', &
convert='big_endian',iostat=s11)
write(6,*)'Reading time and grid data', nk_st,' ', OutFileName
read(22) time, ni, nk, nj, DX_s, LX, LY, LZ
close(22)
NZ = nk-2
NX = ni
NY = nj-2
np = ni+2
WRITE(6,*) 'NX',NX,'NY',NY,'NZ',NZ,'np',np
WRITE(6,*) 'TIME = ',TIME
IF (CAL_STAT_AVG) THEN
allocate(th_wh_avg(nk,nj,np),u1_avg(nk,nj,np),u2_avg(nk,nj,np),u3_avg(nk,nj,np))
allocate(s1(nk,nj,np))
th_wh_avg(:,:,:)= 0.0d0
u1_avg(:,:,:) = 0.0d0
u2_avg(:,:,:) = 0.0d0
u3_avg(:,:,:) = 0.0d0
s1(:,:,:) = 0.0d0
time_sum = 0.0d0
ENDIF
IF (IBM) THEN
WRITE(6,*) 'Reading Hill Profile'
allocate(H_hill_tot(ni), hill_ind_tot(ni), DX_hill(ni))
H_hill_tot(:) = 0.0d0
hill_ind_tot(:) = 0
DX_hill(:) = 0.0d0
open(202,file='hill_prof.dat',form='formatted',status='old')
DO I=1,ni
read(202,*) DX_hill(I), H_hill_tot(I), hill_ind_tot(I)
END DO
close(202)
! open(333,file='hill_prof_test.txt',form='formatted',status='unknown')
! DO I=1,ni
! write(333,111) DX_hill(I), H_hill_tot(I), hill_ind_tot(I)
! END DO
!111 format(2f12.6,i5)
! close(333)
END IF
allocate (u(ni,nk,nj),v(ni,nk,nj),w(ni,nk,nj), &
th(ni,nk,nj), th_wh(nk,nj,np), pr_3D(ni,nk,nj),u1(nk,nj,np), &
u2(nk,nj,np),u3(nk,nj,np))
allocate(u2_avg_2D(nk,nj), th_avg_2D(nk,nj), thv_avg_2D(nk,nj))
u(:,:,:) = 0.0d0
v(:,:,:) = 0.0d0
w(:,:,:) = 0.0d0
th(:,:,:) = 0.0d0
th_wh(:,:,:) = 0.0d0
pr_3D(:,:,:) = 0.0d0
u1(:,:,:) = 0.0d0
u2(:,:,:) = 0.0d0
u3(:,:,:) = 0.0d0
write(6,*) 'Grid is reading ', ni
call read_grid
write(6,*) 'Grid reading done', ni
th_b = 30.0d0
allocate(omega_x(nk,nj,np))
omega_x(:,:,:) = 0.d0
DO kk=nk_st,nk_en
outputDIR='plane_data_3D/'
basename = 'data_binary_3D'
write(OutFileName,'(a,a,i5.5,a4)') trim(outputDIR), &
trim(basename)//"_n",kk,".pln"
open(unit=22,file=OutFileName,access='stream', &
form='unformatted',status='old', &
convert='big_endian',iostat=s11)
write(6,*)'Reading flow statistics', kk,' ',OutFileName
read(22) TIME, ni, nk, nj, DX_s, LX, LY, LZ
read(22) (((th(I,K,J),I=1,ni),K=1,nk),J=1,nj)
read(22) (((u(I,K,J),I=1,ni),K=1,nk),J=1,nj)
read(22) (((w(I,K,J),I=1,ni),K=1,nk),J=1,nj)
read(22) (((v(I,K,J),I=1,ni),K=1,nk),J=1,nj)
read(22) (((pr_3D(I,K,J),I=1,ni),K=1,nk),J=1,nj)
close(22)
! open(66,file='plane_data_3D/time_bulk_3D_test.txt',form='formatted', &
! status='unknown')
! DO I = 1,NX
! TH_3D = th(I, 124,113)
! U_1 = u(I, 124,113)
! W_1 = w(I, 124,113)
! V_1 = v(I,124,113)
! PR_TOT = pr_3D(I,124,113)
! write(66,565) DX_s*(I-1) , TH_3D, U_1, W_1, V_1, PR_TOT
! END DO
!565 ! format(f12.5,5f13.8)
! close(66)
WRITE(6,*) 'Transforming Co-ordinate System'
DO p=1,np-2
DO j=1,nj
DO k=1,nk
th_wh(k,j,p)=th(p,k,j) + th_b !(-y(i,j,np)+y(1,nj,np))
u1(k,j,p) = v(p,k,j)
u2(k,j,p) = w(p,k,j)
u3(k,j,p) = u(p,k,j)
END DO
END DO
END DO
! DO p=np-1,np
p=np-1
DO j=1,nj
DO k=1,nk
u1(k,j,p) = u1(k,j,1)
u2(k,j,p) = u2(k,j,1)
u3(k,j,p) = u3(k,j,1)
th_wh(k,j,p)=th_wh(k,j,1)
END DO
END DO
p=np
DO j=1,nj
DO k=1,nk
u1(k,j,p) = u1(k,j,2)
u2(k,j,p) = u2(k,j,2)
u3(k,j,p) = u3(k,j,2)
th_wh(k,j,p)=th_wh(k,j,2)
END DO
END DO
if (vorticity_cal) then
WRITE(6,*) 'Calculating Vorticity'
do p=1,np
p_p = p+1
p_m = p
if (p==np) THEN
p_p = 1
endif
do j=1,nj-1
do k=1,nk
omega_x(k,j,p)= (u2(k,j+1,p_m)-u2(k,j,p_m))/(GYF(j)-GYF(j-1)) &
-(u3(k,j,p_p)-u3(k,j,p_m))/DX_s
end do
end do
end do
do jj = 1,2
do p=1,np
do j=1,nj
do k=2,nk
omega_x(k,j,p)= 0.5*(omega_x(k,j,p) + omega_x(k-1,j,p))
end do
end do
end do
end do
! open(333,file='vorticity_test.txt',form='formatted', &
! status='unknown')
! do p=1,np
! do j=nj/2
! do k=nk/2
! write(333,111) omega_x(k,j,p)
! end do
! end do
! end do
!111 format(2f12.6,i5)
! close(333)
WRITE(6,*) 'Done calculating Vorticity'
endif
IF (WRITE_PARA_View) THEN
WRITE(6,*) 'Writing Instantaneous Paraview'
call plane_parav_vel(kk)
ENDIF
IF( (CAL_STAT_AVG).AND. (kk .gt. nk_st) ) THEN
WRITE(6,*) 'kk', kk, '> nk_st', nk_st
delta_time = time-time_old
time_sum = time_sum + delta_time
do p=1,np
do j=1,nj
do k=1,nk
th_wh_avg(k,j,p)= th_wh_avg(k,j,p)+th_wh(k,j,p)*delta_time
u1_avg(k,j,p)= u1_avg(k,j,p) + u1(k,j,p)*delta_time
u2_avg(k,j,p)= u2_avg(k,j,p) + u2(k,j,p)*delta_time
u3_avg(k,j,p)= u3_avg(k,j,p) + u3(k,j,p)*delta_time
end do
end do
end do
ENDIF
time_old = time
END DO
IF (CAL_STAT_AVG) THEN
do p=1,np
do j=1,nj
do k=1,nk
th_wh_avg(k,j,p)=th_wh_avg(k,j,p)/time_sum
u1_avg(k,j,p)= u1_avg(k,j,p)/time_sum
u2_avg(k,j,p)= u2_avg(k,j,p)/time_sum
u3_avg(k,j,p)= u3_avg(k,j,p)/time_sum
s1(k,j,p) = 0.5d0*((u1_avg(k,j,p))**2+(u2_avg(k,j,p))**2+&
(u3_avg(k,j,p))**2)
end do
end do
end do
WRITE(6,*) 'Writing average paraview'
call plane_parav_vel(1)
write(6,*) 'Done with averaging'
write(6,*) 'Opening tke_budget.dat, mean_tke_budget.dat &
and mean_ke_budget.dat'
open(70,file='tke_budget.dat',form='formatted', &
status='unknown')
open(69,file='mean_tke_budget.dat',form='formatted', &
status='unknown')
open(67,file='mean_ke_budget.dat',form='formatted', &
status='unknown')
! Calculating mean KE budget
call call_stat_cal_avg
write(6,*) 'time = ', time, &
'sum_dissp = ', sum_dissp, &
'sum_buoyF = ', sum_buoyF, &
'sum_advec = ', sum_advec, &
'sum_wstress = ', sum_wstress
write(67,112) time, sum_dissp, sum_buoyF, sum_advec, sum_wstress
!sum_dissp_1,sum_dissp_2,sum_dissp_3,sum_dissp_4, &
!sum_buoyF_1, sum_buoyF_2, sum_buoyF_3, sum_buoyF_4
!,sum_advec_1,sum_advec_2,sum_advec_3,sum_advec_4, &
!sum_advec_1+sum_advec_2 +sum_advec_3 +sum_advec_4
! k starts at nk_st+1 because it is subtracted from the mean, which only has a
! value at nk_st+1
do kk=nk_st+1,nk_en
outputDIR='plane_data_3D/'
basename = 'data_binary_3D'
write(OutFileName,'(a,a,i5.5,a4)') trim(outputDIR), &
trim(basename)//"_n",nk_st+1,".pln"
open(unit=22,file=OutFileName,access='stream', &
form='unformatted',status='old', &
convert='big_endian',iostat=s11)
! write(6,'(i6,2a)') nk_st+1,' ', OutFileName
read(22) time, ni, nk, nj, DX_s, LX, LY, LZ
close(22)
NZ = nk-2
NX = ni
NY = nj-2
np = ni+2
deallocate(u,v,w,th)
allocate (u(ni,nk,nj))
allocate (v(ni,nk,nj))
allocate (w(ni,nk,nj))
allocate (th(ni,nk,nj))
outputDIR='plane_data_3D/'
basename = 'data_binary_3D'
write(OutFileName,'(a,a,i5.5,a4)') trim(outputDIR), &
trim(basename)//"_n",kk,".pln"
open(unit=22,file=OutFileName,access='stream', &
form='unformatted',status='old', &
convert='big_endian',iostat=s11)
! write(6,'(i6,2a)') kk,' ',OutFileName
read(22) TIME, ni, nk, nj, DX_s, LX, LY, LZ
read(22) (((th(I,K,J),I=1,ni),K=1,nk),J=1,nj)
read(22) (((u(I,K,J),I=1,ni),K=1,nk),J=1,nj)
read(22) (((w(I,K,J),I=1,ni),K=1,nk),J=1,nj)
read(22) (((v(I,K,J),I=1,ni),K=1,nk),J=1,nj)
read(22) (((pr_3D(I,K,J),I=1,ni),K=1,nk),J=1,nj)
close(22)
DO p=1,np-2
DO j=1,nj
DO k=1,nk
th_wh(k,j,p)=th(p,k,j) + th_b !(-y(i,j,np)+y(1,nj,np))
u1(k,j,p) = v(p,k,j)
u2(k,j,p) = w(p,k,j)
u3(k,j,p) = u(p,k,j)
END DO
END DO
END DO
! DO p=np-1,np
p=np-1
DO j=1,nj
DO k=1,nk
u1(k,j,p) = u1(k,j,1)
u2(k,j,p) = u2(k,j,1)
u3(k,j,p) = u3(k,j,1)
th_wh(k,j,p)=th_wh(k,j,1)
END DO
END DO
p=np
DO j=1,nj
DO k=1,nk
u1(k,j,p) = u1(k,j,2)
u2(k,j,p) = u2(k,j,2)
u3(k,j,p) = u3(k,j,2)
th_wh(k,j,p)=th_wh(k,j,2)
END DO
END DO
deallocate(u,v,w,th)
allocate (u(nk,nj,np))
allocate (v(nk,nj,np))
allocate (w(nk,nj,np))
allocate (th(nk,nj,np))
! Calculating tke_budget
call call_stat_cal
IF (kk.eq.nk_st+1) THEN
delta_time = 2.00000000004366
ELSE
delta_time = time-time_old
END IF
! delta_time = time-time_old
WRITE(6,*) time, delta_time, sum_dtkdt, sum_advec, sum_Prod, sum_dissp, sum_buoyF
write(70,113) time, delta_time, sum_dtkdt, sum_advec, sum_Prod, sum_dissp, sum_buoyF
time_sum = time_sum + delta_time
sum_Prod_avg= sum_Prod_avg+sum_Prod*delta_time
sum_dissp_avg= sum_dissp_avg+sum_dissp*delta_time
sum_buoyF_avg= sum_buoyF_avg+sum_buoyF*delta_time
time_old = time
! write(68,113)TIME,sum_dtkdt,sum_advec, sum_Prod_1, sum_dissp_1,
!sum_buoyF_1
! write(69,113)TIME,sum_dtkdt,sum_advec, sum_Prod_2, sum_dissp_2,
!sum_buoyF_2
! write(70,113)TIME,sum_dtkdt,sum_advec, sum_Prod_3, sum_dissp_3,
!sum_buoyF_3
! write(71,113)TIME,sum_dtkdt,sum_advec, sum_Prod_4, sum_dissp_4,
!sum_buoyF_4
! Calculating Phi_d and Phi_b2
IF (PE_cal) THEN
write(6,'(a)') 'Before call z_star', kk
call z_star_cal
write(6,'(a)') 'After call z_star', kk
END IF
end do
sum_Prod_avg = sum_Prod_avg/time_sum
sum_dissp_avg = sum_dissp_avg/time_sum
sum_buoyF_avg = sum_buoyF_avg/time_sum
WRITE(6,*) sum_Prod_avg, sum_dissp_avg, sum_buoyF_avg
write(69,114) sum_Prod_avg, sum_dissp_avg, sum_buoyF_avg
112 format(f12.6,3E18.9)
113 format(f12.6,9E18.9)
114 format(3f12.6)
close(70)
close(67)
close(69)
END IF
! stop
end
subroutine read_grid
use ntypes
use Grid
use domain
implicit none
integer :: i,j,k, NZ_T, NY_T
!Local Variables
integer :: s_1
!&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
! grid allocation
! &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
allocate (GX(0:NX+1), stat=s_1)
allocate (GY(0:NY+1), stat=s_1)
allocate (GZ(0:NZ+1), stat=s_1)
allocate (DX(0:NX+1), stat=s_1)
allocate (DY(0:NY+1), stat=s_1)
allocate (DZ(0:NZ+1), stat=s_1)
allocate (GXF(0:NX), stat=s_1)
allocate (GYF(0:NY+1), stat=s_1)
allocate (GZF(0:NZ+1), stat=s_1)
allocate (DXF(0:NX), stat=s_1)
allocate (DYF(0:NY+1), stat=s_1)
allocate (DZF(0:NZ+1), stat=s_1)
NZM = NZ-1
NYM = NY-1
if (s_1.NE.0) then
write(6,*) "Error Allocating Grid Variables"
endif
OPEN (30,file='zgrid.txt',form='formatted',status='old')
READ (30,*) NZ_T
!C Check to make sure that grid file is the correct dimensions
IF (NZ_T.ne.NZ) THEN
WRITE(6,*) 'NZ, NZ_T',NZ,NZ_T
STOP 'Error: zgrid.txt wrong dimensions'
END IF
DO K=1,NZ+1
READ(30,*) GZ(k)
END DO
DO K=1,NZ
READ(30,*) GZF(k)
END DO
!C Define ghost cells, if needed for this grid...
GZF(0)=2.d0*GZF(1)-GZF(2)
GZF(NZ+1)=2.d0*GZF(NZ)-GZF(NZM)
GZ(0)=2.d0*GZ(1)-GZ(2)
!C Define grid spacing
DO K=1,NZ+1
DZ(K)=(GZF(K)-GZF(K-1))
END DO
DO K=1,NZ
DZF(K)=(GZ(K+1)-GZ(K))
write(400,*) DZF(K)
END DO
DZ(0)=DZ(1)
DZF(NZ+1)=DZF(NZ)
OPEN (30,file='./ygrid.txt',form='formatted',status='old')
READ (30,*) NY_T
!C Check to make sure that grid file is the correct dimensions
IF (NY_T.ne.NY) THEN
WRITE(6,*) 'NY, NY_T',NY,NY_T
STOP 'Error: ygrid.txt wrong dimensions'
END IF
DO J=1,NY+1
READ(30,*) GY(j)
END DO
DO J=1,NY
READ(30,*) GYF(j)
END DO
CLOSE(30)
!C Define ghost cells
GYF(0)=2.d0*GYF(1)-GYF(2)
GYF(NY+1)=2.d0*GYF(NY)-GYF(NYM)
GY(0)=2.d0*GY(1)-GY(2)
!C Define grid spacing
DO J=1,NY+1
DY(J)=(GYF(J)-GYF(J-1))
END DO
DO J=1,NY
DYF(J)=(GY(J+1)-GY(J))
END DO
DY(0)=DY(1)
DYF(NY+1)=DYF(NY)
return
end subroutine
subroutine plane_parav_vel(kk)
use ntypes
use Grid
use Domain
use run_variable
implicit none
integer i,j,k,kk,N
!FILENAMES
! parameter(np1 = ni, np2 = nj-2, np3 = nk-2)
character(len=100) :: InFileName, OutFileName
character(len=100) :: dataDIR, outputDIR
character(len=80) :: basename
!OTHER STRINGS
character(len=25) :: ss
np1 = ni
np2 = nj-2
np3 = nk-1
allocate(g1vtk(1:np1),g2vtk(1:np2),g3vtk(1:np3), &
var_1(1:3*np1*np2*np3),var_2(1:3*np1*np2*np3))
g1vtk(:) = 0.0
g2vtk(:) = 0.0
g3vtk(:) = 0.0
var_1(:) = 0.0
var_2(:) = 0.0
do k=1,np3
g3vtk(k) = GZF(k)
enddo
do j=1,np2
g2vtk(j) = GYF(j)
enddo
do i=1,np1
g1vtk(i) = real(DX_s)*(i-1)
enddo
! DO N=1,N_TH
! th_wh(k,j,N)=dble(CTHX(0,k,j,N)) + TH_BAR(K,j,N) !
! ENDDO
! IF (Non_linear_ST) THEN
! call density_TC(.true.,.true.)
! ELSE
! do j=0,NY+1
! do k=0,NZ+1
! th_wh(k,j,N_TH+1)= -alpha_w*dble(CTHX(0,K,J,1)) +
! gamma_w*dble(CTHX(0,K,J,2)) + TH_BAR(K,j,N_TH+1) !
! enddo
! enddo
! ENDIF
! outputDIR='plane_3D_para/'
! basename = 'data_parav'
IF((CAL_STAT_AVG) .AND. (kk .eq. 1) ) THEN
outputDIR='plane_data_3D/'
basename = 'data_parav_avg'
IF (IBM) THEN
DO I=1,ni
DO J=1,hill_ind_tot(I)+1
u1_avg(:,J,I)=1.0d0
u2_avg(:,J,I)=1.0d0
u3_avg(:,J,I)=1.0d0
th_wh_avg(:,J,I)=100.0d0
ENDDO
ENDDO
ENDIF
write(OutFileName,'(a,a,i5.5,a4)') trim(outputDIR), &
trim(basename)//".vtk"
ELSE
outputDIR='plane_data_3D/'
basename = 'data_parav'
IF (IBM) THEN
DO I=1,ni
DO J=1,hill_ind_tot(I)+1
u(I,:,J)=1.0d0
v(I,:,J)=1.0d0
w(I,:,J)=1.0d0
th_wh(:,J,I)=100.0d0
ENDDO
ENDDO
ENDIF
write(OutFileName,'(a,a,i5.5,a4)') trim(outputDIR), &
trim(basename)//"_n",kk,".vtk"
ENDIF
open(unit=13,file=OutFileName,access='stream', &
form='unformatted',status='unknown', &
convert='big_endian',iostat=s11)
WRITE(6,*) 'Wrting in ', OutFileName,' for paraview'
!HEADER: note termination with char(10)
write(13) "# vtk DataFile Version 3.0"//char(10)
write(13) trim(BaseName)//char(10)
write(13) "BINARY"//char(10)
write(13) "DATASET RECTILINEAR_GRID"//char(10)
write(ss,fmt='(A10,3I5)') "DIMENSIONS",np1,np3,np2
write(13) ss//char(10)
!Xgrid
write(ss,fmt='(A13,I6,A6)') "X_COORDINATES",np1," float"
write(13) char(10)//ss//char(10)
do i = 1,np1
write(13) g1vtk(i)
enddo
!Ygrid
write(ss,fmt='(A13,I6,A6)') "Y_COORDINATES",np3," float"
write(13) char(10)//ss//char(10)
do k = 1,np3
write(13) g3vtk(k)
enddo
!Zgrid
write(ss,fmt='(A13,I6,A6)') "Z_COORDINATES",np2," float"
write(13) char(10)//ss//char(10)
do j = 1,np2
write(13) g2vtk(j)
enddo
!Field
IF((CAL_STAT_AVG) .AND. (kk .eq. 1) ) THEN
jj = 1
do j = 1,np2
do k = 1, np3
do i = 1, np1
var_1(jj) = real(u1_avg(k,j,i))
jj = jj+1
var_1(jj) = real(u2_avg(k,j,i))
jj = jj+1
var_1(jj) = real(u3_avg(k,j,i))
jj = jj+1
end do
end do
end do
jj = 1
do j = 1,np2
do k = 1, np3
do i = 1, np1
var_2(jj) = real(th_wh_avg(k,j,i))
jj = jj+1
enddo
enddo
enddo
ELSE
jj = 1
do j = 1,np2
do k = 1, np3
do i = 1, np1
var_1(jj) = real(u(i,k,j))
jj = jj+1
var_1(jj) = real(v(i,k,j))
jj = jj+1
var_1(jj) = real(w(i,k,j))
jj = jj+1
enddo
enddo
enddo
jj = 1
do j = 1,np2
do k = 1, np3
do i = 1, np1
var_2(jj) = real(th_wh(k,j,i))
jj = jj+1
enddo
enddo
enddo
ENDIF
!Field
IF((CAL_STAT_AVG) .AND. (kk .eq. 1) ) THEN
write(ss,fmt='(A10,I15)') "POINT_DATA",np1*np2*np3
write(13) char(10)//ss//char(10)
write(13) "VECTORS velocity_vectors_avg float 1"//char(10)
write(13) var_1
write(13) "SCALARS TH_wh_avg float 1"//char(10)
write(13) "LOOKUP_TABLE default"//char(10)
write(13) var_2
ELSE
write(ss,fmt='(A10,I15)') "POINT_DATA",np1*np2*np3
write(13) char(10)//ss//char(10)
write(13) "VECTORS velocity_vectors float 1"//char(10)
write(13) var_1
write(13) "SCALARS TH_wh float 1"//char(10)
write(13) "LOOKUP_TABLE default"//char(10)
write(13) var_2
! write(13) "SCALARS omega_x float 1"//char(10)
! write(13) "LOOKUP_TABLE default"//char(10)
! write(13) th_wh
END IF
!Close VTK File
close(13)
deallocate(g1vtk,g2vtk,g3vtk,var_1,var_2)
!if (allocated(SPplane) ) deallocate(SPplane)
!if (allocated(DPplane) ) deallocate(DPplane)
return
end subroutine plane_parav_vel
subroutine call_stat_cal_avg
use ntypes
use Grid
use Domain
use run_variable
implicit none
integer :: k,j,p
real(r8) :: temp_val
! s1 = Gravity*alpha_T*th*v
sum_Prod = 0.0d0 ;
sum_dissp = 0.0d0 ;
sum_buoyF = 0.0d0 ;
sum_dtkdt = 0.0d0 ;
sum_vis = 0.0d0 ;
sum_trans = 0.0d0 ;
sum_advec = 0.0d0 ;
vol_box = 0.0d0 ;
sum_wstress = 0.0d0;
! sum_advec_1 = 0.0d0 ;
! sum_advec_2 = 0.0d0 ;
! sum_advec_3 = 0.0d0 ;
! sum_advec_4 = 0.0d0 ;
! sum_Prod_1 = 0.0d0 ;
! sum_Prod_2 = 0.0d0 ;
! sum_Prod_3 = 0.0d0 ;
! sum_Prod_4 = 0.0d0 ;
! sum_buoyF_1 = 0.0d0 ;
! sum_buoyF_2 = 0.0d0 ;
! sum_buoyF_3 = 0.0d0 ;
! sum_buoyF_4 = 0.0d0 ;