-
Notifications
You must be signed in to change notification settings - Fork 69
/
Copy pathio.f90
1410 lines (1191 loc) · 44.9 KB
/
io.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
!!
!! Copyright (C) 2009-2017 Johns Hopkins University
!!
!! This file is part of lesgo.
!!
!! lesgo 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 3 of the License, or
!! (at your option) any later version.
!!
!! lesgo 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 lesgo. If not, see <http://www.gnu.org/licenses/>.
!*******************************************************************************
module io
!*******************************************************************************
use types, only : rprec
use param, only : ld, nx, ny, nz, nz_tot, path, coord, rank, nproc, jt_total
use param, only : total_time, total_time_dim, lbz, jzmin, jzmax
use param, only : cumulative_time
use sim_param , only : w, dudz, dvdz
use sgs_param , only : Cs_opt2
use string_util
use messages
use time_average
#ifdef PPMPI
use mpi
#endif
#ifdef PPCGNS
use cgns
#ifdef PPMPI
use param, only: ierr
#endif
#endif
implicit none
save
private
public jt_total, openfiles, energy, output_loop, output_final, output_init, &
write_tau_wall_bot, write_tau_wall_top
! Where to end with nz index.
integer :: nz_end
! time averaging
type(tavg_t) :: tavg
character(:), allocatable :: fcumulative_time
contains
!*******************************************************************************
subroutine openfiles()
!*******************************************************************************
use param, only : use_cfl_dt, dt, cfl_f, checkpoint_file
implicit none
logical :: exst
! Temporary values used to read time step and CFL from file
real(rprec) :: dt_r, cfl_r
! Create file names
allocate(fcumulative_time, source = path // 'total_time.dat')
allocate(checkpoint_file , source = path // 'vel.out')
if (cumulative_time) then
inquire (file=fcumulative_time, exist=exst)
if (exst) then
open (1, file=fcumulative_time)
read(1, *) jt_total, total_time, total_time_dim, dt_r, cfl_r
close (1)
else
! assume this is the first run on cumulative time
if ( coord == 0 ) then
write (*, *) '--> Assuming jt_total = 0, total_time = 0.0'
end if
jt_total = 0
total_time = 0._rprec
total_time_dim = 0._rprec
end if
end if
! Update dynamic time stepping info if required; otherwise discard.
if ( use_cfl_dt ) then
dt = dt_r
cfl_f = cfl_r
end if
end subroutine openfiles
!*******************************************************************************
subroutine energy (ke)
!*******************************************************************************
use types, only : rprec
use param
use sim_param, only : u, v, w
use messages
implicit none
integer :: jx, jy, jz, nan_count
real(rprec)::KE,temp_w
#ifdef PPMPI
real(rprec) :: ke_global
#endif
! Initialize variables
nan_count = 0
ke = 0._rprec
do jz = 1, nz-1
do jy = 1, ny
do jx = 1, nx
temp_w = 0.5_rprec*(w(jx,jy,jz)+w(jx,jy,jz+1))
ke = ke + (u(jx,jy,jz)**2+v(jx,jy,jz)**2+temp_w**2)
end do
end do
end do
! Perform spatial averaging
ke = ke*0.5_rprec/(nx*ny*(nz-1))
#ifdef PPMPI
call mpi_reduce (ke, ke_global, 1, MPI_RPREC, MPI_SUM, 0, comm, ierr)
if (rank == 0) then ! note that it's rank here, not coord
ke = ke_global/nproc
#endif
open(2,file=path // 'output/check_ke.dat', status='unknown', &
form='formatted', position='append')
write(2,*) total_time,ke
close(2)
#ifdef PPMPI
end if
#endif
end subroutine energy
!*******************************************************************************
subroutine write_tau_wall_bot()
!*******************************************************************************
use types ,only: rprec
use param ,only: jt_total, total_time, total_time_dim, dt, dt_dim, wbase
use param ,only: L_x, z_i, u_star
use functions ,only: get_tau_wall_bot
implicit none
real(rprec) :: turnovers
turnovers = total_time_dim / (L_x * z_i / u_star)
open(2,file=path // 'output/tau_wall_bot.dat', status='unknown', &
form='formatted', position='append')
!! one time header output
if (jt_total==wbase) write(2,*) &
'jt_total, total_time, total_time_dim, turnovers, dt, dt_dim, 1.0, tau_wall'
!! continual time-related output
write(2,*) jt_total, total_time, total_time_dim, turnovers, dt, dt_dim, &
1.0, get_tau_wall_bot()
close(2)
end subroutine write_tau_wall_bot
!*******************************************************************************
subroutine write_tau_wall_top()
!*******************************************************************************
use types, only : rprec
use param, only : jt_total, total_time, total_time_dim, dt, dt_dim, wbase
use param, only : L_x, z_i, u_star
use functions, only : get_tau_wall_top
implicit none
real(rprec) :: turnovers
turnovers = total_time_dim / (L_x * z_i / u_star)
open(2,file=path // 'output/tau_wall_top.dat', status='unknown', &
form='formatted', position='append')
! one time header output
if (jt_total==wbase) write(2,*) &
'jt_total, total_time, total_time_dim, turnovers, dt, dt_dim, 1.0, tau_wall'
! continual time-related output
write(2,*) jt_total, total_time, total_time_dim, turnovers, dt, dt_dim, &
1.0, get_tau_wall_top()
close(2)
end subroutine write_tau_wall_top
#ifdef PPCGNS
#ifdef PPMPI
!*******************************************************************************
subroutine write_parallel_cgns (file_name, nx, ny, nz, nz_tot, start_n_in, &
end_n_in, xin, yin, zin, num_fields, fieldNames, input )
!*******************************************************************************
implicit none
integer, intent(in) :: nx, ny, nz, nz_tot, num_fields
! Name of file to be written
character(*), intent(in) :: file_name
! Name of fields we are writing
character(*), intent(in), dimension(:) :: fieldNames
! Data to be written
real(rprec), intent(in), dimension(:) :: input
! Coordinates to write
real(rprec), intent(in), dimension(:) :: xin, yin, zin
! Where the total node counter starts nodes
integer, intent(in) :: start_n_in(3)
! Where the total node counter ends nodes
integer, intent(in) :: end_n_in(3)
integer :: fn=1 ! CGNS file index number
integer :: ier ! CGNS error status
integer :: base=1 ! base number
integer :: zone=1 ! zone number
integer :: nnodes ! Number of nodes in this processor
integer :: sol =1 ! solution number
integer :: field ! section number
integer(cgsize_t) :: sizes(3,3) ! Sizes
! Convert input to right data type
integer(cgsize_t) :: start_n(3) ! Where the total node counter starts nodes
integer(cgsize_t) :: end_n(3) ! Where the total node counter ends nodes
! Building the lcoal mesh
integer :: i,j,k
real(rprec), dimension(nx,ny,nz) :: xyz
! ! Set the parallel communicator
! call cgp_mpi_comm_f(cgnsParallelComm, ierr)
! Convert types such that CGNS libraries can handle the input
start_n(1) = int(start_n_in(1), cgsize_t)
start_n(2) = int(start_n_in(2), cgsize_t)
start_n(3) = int(start_n_in(3), cgsize_t)
end_n(1) = int(end_n_in(1), cgsize_t)
end_n(2) = int(end_n_in(2), cgsize_t)
end_n(3) = int(end_n_in(3), cgsize_t)
! The total number of nodes in this processor
nnodes = nx*ny*nz
! Sizes, used to create zone
sizes(:,1) = (/int(nx, cgsize_t),int(ny, cgsize_t),int(nz_tot, cgsize_t)/)
sizes(:,2) = (/int(nx-1, cgsize_t),int(ny-1, cgsize_t),int(nz_tot-1, cgsize_t)/)
sizes(:,3) = (/int(0, cgsize_t) , int(0, cgsize_t), int(0, cgsize_t)/)
! Open CGNS file
call cgp_open_f(file_name, CG_MODE_WRITE, fn, ier)
if (ier .ne. CG_OK) call cgp_error_exit_f
! Write base
call cg_base_write_f(fn, 'Base', 3, 3, base, ier)
if (ier .ne. CG_OK) call cgp_error_exit_f
! Write zone
call cg_zone_write_f(fn, base, 'Zone', sizes, Structured, zone, ier)
if (ier .ne. CG_OK) call cgp_error_exit_f
! Write print info to screen
if (coord .eq. 0) then
write(*,*) 'Writing, ', file_name
end if
! Create data nodes for coordinates
call cgp_coord_write_f(fn, base, zone, RealDouble, 'CoordinateX', nnodes, ier)
if (ier .ne. CG_OK) call cgp_error_exit_f
call cgp_coord_write_f(fn, base, zone, RealDouble, 'CoordinateY', nnodes, ier)
if (ier .ne. CG_OK) call cgp_error_exit_f
call cgp_coord_write_f(fn, base, zone, RealDouble, 'CoordinateZ', nnodes, ier)
if (ier .ne. CG_OK) call cgp_error_exit_f
! Write the coordinate data in parallel to the queue
! call cgp_queue_set_f(1, ier)
! if (ier .ne. CG_OK) call cgp_error_exit_f
! This is done for the 3 dimensions x,y and z
! It writes the coordinates
! Create grid points
do k = 1, nz
do j = 1, ny
do i = 1, nx
xyz(i,j,k) = xin(i)
end do
end do
end do
call cgp_coord_write_data_f(fn, base, zone, 1, &
start_n, end_n, xyz(1:nx,1:ny,1:nz), ier)
if (ier .ne. CG_OK) call cgp_error_exit_f
! Write out the queued coordinate data
! call cgp_queue_flush_f(ier)
! if (ier .ne. CG_OK) call cgp_error_exit_f
! call cgp_queue_set_f(0, ier)
! Write the coordinate data in parallel to the queue
! call cgp_queue_set_f(1, ier)
! if (ier .ne. CG_OK) call cgp_error_exit_f
do k = 1, nz
do j = 1, ny
do i = 1, nx
xyz(i,j,k) = yin(j)
end do
end do
end do
call cgp_coord_write_data_f(fn, base, zone, 2, &
start_n, end_n, xyz(1:nx,1:ny,1:nz), ier)
if (ier .ne. CG_OK) call cgp_error_exit_f
! Write out the queued coordinate data
! call cgp_queue_flush_f(ier)
! if (ier .ne. CG_OK) call cgp_error_exit_f
! call cgp_queue_set_f(0, ier)
! Write the coordinate data in parallel to the queue
! call cgp_queue_set_f(1, ier)
! if (ier .ne. CG_OK) call cgp_error_exit_f
do k = 1, nz
do j = 1, ny
do i = 1, nx
xyz(i,j,k) = zin(k)
end do
end do
end do
call cgp_coord_write_data_f(fn, base, zone, 3, &
start_n, end_n, xyz(1:nx,1:ny,1:nz), ier)
if (ier .ne. CG_OK) call cgp_error_exit_f
! Write out the queued coordinate data
! call cgp_queue_flush_f(ier)
! if (ier .ne. CG_OK) call cgp_error_exit_f
! call cgp_queue_set_f(0, ier)
! Create a centered solution
call cg_sol_write_f(fn, base, zone, 'Solution', Vertex, sol, ier)
if (ier .ne. CG_OK) call cgp_error_exit_f
! Write the solution
do i=1,num_fields
call cgp_field_write_f(fn, base, zone, sol, RealDouble, fieldNames(i), &
field, ier)
if (ier .ne. CG_OK) call cgp_error_exit_f
call cgp_field_write_data_f(fn, base, zone, sol, field, start_n, end_n, &
input((i-1)*nnodes+1:(i)*nnodes), ier)
if (ier .ne. CG_OK) call cgp_error_exit_f
end do
! Close the file
call cgp_close_f(fn, ier)
if (ier .ne. CG_OK) call cgp_error_exit_f
end subroutine write_parallel_cgns
!*******************************************************************************
subroutine write_null_cgns (file_name, nx, ny, nz, nz_tot, start_n_in, &
end_n_in, xin, yin, zin, num_fields, fieldNames )
!*******************************************************************************
implicit none
integer, intent(in) :: nx, ny, nz, nz_tot, num_fields
! Name of file to be written
character(*), intent(in) :: file_name
! Name of fields we are writing
character(*), intent(in), dimension(:) :: fieldNames
! Coordinates to write
real(rprec), intent(in), dimension(:) :: xin, yin, zin
! Where the total node counter starts nodes
integer, intent(in) :: start_n_in(3)
! Where the total node counter ends nodes
integer, intent(in) :: end_n_in(3)
integer :: fn=1 ! CGNS file index number
integer :: ier ! CGNS error status
integer :: base=1 ! base number
integer :: zone=1 ! zone number
integer :: nnodes ! Number of nodes in this processor
integer :: sol =1 ! solution number
integer :: field ! section number
integer(cgsize_t) :: sizes(3,3) ! Sizes
! Convert input to right data type
integer(cgsize_t) :: start_n(3) ! Where the total node counter starts nodes
integer(cgsize_t) :: end_n(3) ! Where the total node counter ends nodes
! Building the lcoal mesh
integer :: i,j,k
real(rprec), dimension(nx,ny,nz) :: xyz
! ! Set the parallel communicator
! call cgp_mpi_comm_f(cgnsParallelComm, ierr)
! Convert types such that CGNS libraries can handle the input
start_n(1) = int(start_n_in(1), cgsize_t)
start_n(2) = int(start_n_in(2), cgsize_t)
start_n(3) = int(start_n_in(3), cgsize_t)
end_n(1) = int(end_n_in(1), cgsize_t)
end_n(2) = int(end_n_in(2), cgsize_t)
end_n(3) = int(end_n_in(3), cgsize_t)
! The total number of nodes in this processor
nnodes = nx*ny*nz
! Sizes, used to create zone
sizes(:,1) = (/int(nx, cgsize_t),int(ny, cgsize_t),int(nz_tot, cgsize_t)/)
sizes(:,2) = (/int(nx-1, cgsize_t),int(ny-1, cgsize_t),int(nz_tot-1, cgsize_t)/)
sizes(:,3) = (/int(0, cgsize_t) , int(0, cgsize_t), int(0, cgsize_t)/)
! Open CGNS file
call cgp_open_f(file_name, CG_MODE_WRITE, fn, ier)
if (ier .ne. CG_OK) call cgp_error_exit_f
! Write base
call cg_base_write_f(fn, 'Base', 3, 3, base, ier)
if (ier .ne. CG_OK) call cgp_error_exit_f
! Write zone
call cg_zone_write_f(fn, base, 'Zone', sizes, Structured, zone, ier)
if (ier .ne. CG_OK) call cgp_error_exit_f
! Write print info to screen
if (coord .eq. 0) then
write(*,*) 'Writing, ', file_name
end if
! Create data nodes for coordinates
call cgp_coord_write_f(fn, base, zone, RealDouble, 'CoordinateX', nnodes, ier)
if (ier .ne. CG_OK) call cgp_error_exit_f
call cgp_coord_write_f(fn, base, zone, RealDouble, 'CoordinateY', nnodes, ier)
if (ier .ne. CG_OK) call cgp_error_exit_f
call cgp_coord_write_f(fn, base, zone, RealDouble, 'CoordinateZ', nnodes, ier)
if (ier .ne. CG_OK) call cgp_error_exit_f
! This is done for the 3 dimensions x,y and z
! It writes the coordinates
! Create grid points
do k = 1, nz
do j = 1, ny
do i = 1, nx
xyz(i,j,k) = xin(i)
end do
end do
end do
write(*,*) "HERE 0.8"
call cgp_coord_write_data_f(fn, base, zone, 1, start_n, end_n, %VAL(0), ier)
write(*,*) "HERE 0.85"
if (ier .ne. CG_OK) call cgp_error_exit_f
write(*,*) "HERE 0.9"
! Write out the queued coordinate data
! call cgp_queue_flush_f(ier)
! if (ier .ne. CG_OK) call cgp_error_exit_f
! call cgp_queue_set_f(0, ier)
! Write the coordinate data in parallel to the queue
! call cgp_queue_set_f(1, ier)
! if (ier .ne. CG_OK) call cgp_error_exit_f
do k = 1, nz
do j = 1, ny
do i = 1, nx
xyz(i,j,k) = yin(j)
end do
end do
end do
call cgp_coord_write_data_f(fn, base, zone, 2, start_n, end_n, %VAL(0), ier)
if (ier .ne. CG_OK) call cgp_error_exit_f
write(*,*) "HERE 1.0"
! Write out the queued coordinate data
! call cgp_queue_flush_f(ier)
! if (ier .ne. CG_OK) call cgp_error_exit_f
! call cgp_queue_set_f(0, ier)
! Write the coordinate data in parallel to the queue
! call cgp_queue_set_f(1, ier)
! if (ier .ne. CG_OK) call cgp_error_exit_f
do k = 1, nz
do j = 1, ny
do i = 1, nx
xyz(i,j,k) = zin(k)
end do
end do
end do
write(*,*) "HERE 1.1"
call cgp_coord_write_data_f(fn, base, zone, 3, start_n, end_n, %VAL(0), ier)
if (ier .ne. CG_OK) call cgp_error_exit_f
! Create a centered solution
call cg_sol_write_f(fn, base, zone, 'Solution', Vertex, sol, ier)
if (ier .ne. CG_OK) call cgp_error_exit_f
! Write the solution
do i = 1, num_fields
call cgp_field_write_f(fn, base, zone, sol, RealDouble, fieldNames(i), &
field, ier)
if (ier .ne. CG_OK) call cgp_error_exit_f
call cgp_field_write_data_f(fn, base, zone, sol, field, start_n, end_n, &
%VAL(0), ier)
if (ier .ne. CG_OK) call cgp_error_exit_f
end do
! Close the file
call cgp_close_f(fn, ier)
if (ier .ne. CG_OK) call cgp_error_exit_f
write(*,*) "end of write_null_cgns"
end subroutine write_null_cgns
#endif
#endif
!*******************************************************************************
subroutine output_loop()
!*******************************************************************************
!
! This subroutine is called every time step and acts as a driver for
! computing statistics and outputing instantaneous data. No actual
! calculations are performed here.
!
use param, only : jt_total, dt
use param, only : checkpoint_data, checkpoint_nskip
use param, only : tavg_calc, tavg_nstart, tavg_nend, tavg_nskip
use param, only : point_calc, point_nstart, point_nend, point_nskip
use param, only : domain_calc, domain_nstart, domain_nend, domain_nskip
use param, only : xplane_calc, xplane_nstart, xplane_nend, xplane_nskip
use param, only : yplane_calc, yplane_nstart, yplane_nend, yplane_nskip
use param, only : zplane_calc, zplane_nstart, zplane_nend, zplane_nskip
implicit none
! Determine if we are to checkpoint intermediate times
if( checkpoint_data ) then
! Now check if data should be checkpointed this time step
if ( modulo (jt_total, checkpoint_nskip) == 0) call checkpoint()
end if
! Determine if time summations are to be calculated
if (tavg_calc) then
! Are we between the start and stop timesteps?
if ((jt_total >= tavg_nstart).and.(jt_total <= tavg_nend)) then
! Every timestep (between nstart and nend), add to tavg%dt
tavg%dt = tavg%dt + dt
! Are we at the beginning or a multiple of nstart?
if ( mod(jt_total-tavg_nstart,tavg_nskip)==0 ) then
! Check if we have initialized tavg
if (.not.tavg%initialized) then
if (coord == 0) then
write(*,*) '-------------------------------'
write(*,"(1a,i9,1a,i9)") &
'Starting running time summation from ', &
tavg_nstart, ' to ', tavg_nend
write(*,*) '-------------------------------'
end if
call tavg%init()
else
call tavg%compute()
end if
end if
end if
end if
! Determine if instantaneous point velocities are to be recorded
if(point_calc) then
if (jt_total >= point_nstart .and. jt_total <= point_nend .and. &
( mod(jt_total-point_nstart,point_nskip)==0) ) then
if (jt_total == point_nstart) then
if (coord == 0) then
write(*,*) '-------------------------------'
write(*,"(1a,i9,1a,i9)") &
'Writing instantaneous point velocities from ', &
point_nstart, ' to ', point_nend
write(*,"(1a,i9)") 'Iteration skip:', point_nskip
write(*,*) '-------------------------------'
end if
end if
call inst_write(1)
end if
end if
! Determine if instantaneous domain velocities are to be recorded
if(domain_calc) then
if (jt_total >= domain_nstart .and. jt_total <= domain_nend .and. &
( mod(jt_total-domain_nstart,domain_nskip)==0) ) then
if (jt_total == domain_nstart) then
if (coord == 0) then
write(*,*) '-------------------------------'
write(*,"(1a,i9,1a,i9)") &
'Writing instantaneous domain velocities from ', &
domain_nstart, ' to ', domain_nend
write(*,"(1a,i9)") 'Iteration skip:', domain_nskip
write(*,*) '-------------------------------'
end if
end if
call inst_write(2)
end if
end if
! Determine if instantaneous x-plane velocities are to be recorded
if(xplane_calc) then
if (jt_total >= xplane_nstart .and. jt_total <= xplane_nend .and. &
( mod(jt_total-xplane_nstart,xplane_nskip)==0) ) then
if (jt_total == xplane_nstart) then
if (coord == 0) then
write(*,*) '-------------------------------'
write(*,"(1a,i9,1a,i9)") &
'Writing instantaneous x-plane velocities from ', &
xplane_nstart, ' to ', xplane_nend
write(*,"(1a,i9)") 'Iteration skip:', xplane_nskip
write(*,*) '-------------------------------'
end if
end if
call inst_write(3)
end if
end if
! Determine if instantaneous y-plane velocities are to be recorded
if(yplane_calc) then
if (jt_total >= yplane_nstart .and. jt_total <= yplane_nend .and. &
( mod(jt_total-yplane_nstart,yplane_nskip)==0) ) then
if (jt_total == yplane_nstart) then
if (coord == 0) then
write(*,*) '-------------------------------'
write(*,"(1a,i9,1a,i9)") &
'Writing instantaneous y-plane velocities from ', &
yplane_nstart, ' to ', yplane_nend
write(*,"(1a,i9)") 'Iteration skip:', yplane_nskip
write(*,*) '-------------------------------'
end if
end if
call inst_write(4)
end if
end if
! Determine if instantaneous z-plane velocities are to be recorded
if(zplane_calc) then
if (jt_total >= zplane_nstart .and. jt_total <= zplane_nend .and. &
( mod(jt_total-zplane_nstart,zplane_nskip)==0) ) then
if (jt_total == zplane_nstart) then
if (coord == 0) then
write(*,*) '-------------------------------'
write(*,"(1a,i9,1a,i9)") &
'Writing instantaneous z-plane velocities from ', &
zplane_nstart, ' to ', zplane_nend
write(*,"(1a,i9)") 'Iteration skip:', zplane_nskip
write(*,*) '-------------------------------'
end if
end if
call inst_write(5)
end if
end if
end subroutine output_loop
!*******************************************************************************
subroutine inst_write(itype)
!*******************************************************************************
!
! This subroutine is used to write all of the instantaneous data from
! lesgo to file. The types of data written are:
!
! points : itype=1
! domain : itype=2
! x-planes : itype=3
! y-planes : itype=4
! z-planes : itype=5
!
! For the points and planar data, this subroutine writes using the
! locations specfied from the param module.
! If additional instantenous values are
! desired to be written, they should be done so using this subroutine.
!
use functions, only : linear_interp, trilinear_interp, interp_to_uv_grid
use param, only : point_nloc, point_loc
use param, only : xplane_nloc, xplane_loc
use param, only : yplane_nloc, yplane_loc
use param, only : zplane_nloc, zplane_loc
use param, only : dx, dy
use param, only : write_endian
use grid_m
use sim_param, only : u, v, w, p
use sim_param, only : dwdy, dwdx, dvdx, dudy
use functions, only : interp_to_w_grid
use stat_defs, only : xplane, yplane
#ifdef PPMPI
use stat_defs, only : zplane, point
use param, only : ny, nz, dz
#endif
#ifdef PPLVLSET
use level_set_base, only : phi
use sim_param, only : fx, fy, fz, fxa, fya, fza
#endif
#ifdef PPSCALARS
use scalars, only : theta
#endif
implicit none
integer, intent(in) :: itype
character (64) :: fname
integer :: n, i, j, k
real(rprec), allocatable, dimension(:,:,:) :: ui, vi, wi,w_uv
real(rprec), pointer, dimension(:) :: x, y, z, zw
! Vorticity
real(rprec), dimension (:,:,:), allocatable :: vortx, vorty, vortz
! Pressure
real(rprec), dimension(:,:,:), allocatable :: pres_real
#ifndef PPCGNS
character(64) :: bin_ext
#ifdef PPLVLSET
real(rprec), allocatable, dimension(:,:,:) :: fx_tot, fy_tot, fz_tot
#endif
#ifdef PPMPI
call string_splice(bin_ext, '.c', coord, '.bin')
#else
bin_ext = '.bin'
#endif
#endif
! Nullify pointers
nullify(x,y,z,zw)
! Set grid pointers
x => grid % x
y => grid % y
z => grid % z
zw => grid % zw
! Allocate space for the interpolated w values
allocate(w_uv(nx,ny,lbz:nz))
! Make sure w has been interpolated to uv-grid
w_uv = interp_to_uv_grid(w(1:nx,1:ny,lbz:nz), lbz)
! Instantaneous velocity sampled at point
if(itype==1) then
do n = 1, point_nloc
! Common file name for all output types
call string_splice(fname, path // 'output/vel.x-', point_loc(n)%xyz(1),&
'.y-', point_loc(n)%xyz(2), '.z-', point_loc(n)%xyz(3), '.dat')
#ifdef PPMPI
if(point(n) % coord == coord) then
#endif
open(unit=13, position="append", file=fname)
write(13,*) total_time, &
trilinear_interp(u(1:nx,1:ny,lbz:nz), lbz, point_loc(n)%xyz), &
trilinear_interp(v(1:nx,1:ny,lbz:nz), lbz, point_loc(n)%xyz), &
trilinear_interp(w_uv(1:nx,1:ny,lbz:nz), lbz, point_loc(n)%xyz)
close(13)
#ifdef PPMPI
end if
#endif
end do
! Instantaneous write for entire domain
elseif(itype==2) then
! Common file name for all output types
call string_splice(fname, path //'output/vel.', jt_total)
#if defined(PPCGNS) && defined(PPMPI)
! Write CGNS Output
call string_concat(fname, '.cgns')
call write_parallel_cgns(fname, nx, ny, nz - nz_end, nz_tot, &
(/ 1, 1, (nz-1)*coord + 1 /), &
(/ nx, ny, (nz-1)*(coord+1) + 1 - nz_end /), &
x(1:nx) , y(1:ny) , z(1:(nz-nz_end) ), &
3, (/ 'VelocityX', 'VelocityY', 'VelocityZ' /), &
(/ u(1:nx,1:ny,1:(nz-nz_end)), v(1:nx,1:ny,1:(nz-nz_end)), &
w_uv(1:nx,1:ny,1:(nz-nz_end)) /) )
#else
! Write binary Output
call string_concat(fname, bin_ext)
open(unit=13, file=fname, form='unformatted', convert=write_endian, &
access='direct', recl=nx*ny*nz*rprec)
write(13,rec=1) u(:nx,:ny,1:nz)
write(13,rec=2) v(:nx,:ny,1:nz)
write(13,rec=3) w_uv(:nx,:ny,1:nz)
close(13)
#endif
! Compute vorticity
allocate(vortx(nx,ny,lbz:nz), vorty(nx,ny,lbz:nz), vortz(nx,ny,lbz:nz))
vortx(1:nx,1:ny,lbz:nz) = 0._rprec
vorty(1:nx,1:ny,lbz:nz) = 0._rprec
vortz(1:nx,1:ny,lbz:nz) = 0._rprec
! Use vorticityx as an intermediate step for performing uv-w interpolation
! Vorticity is written in w grid
vortx(1:nx,1:ny,lbz:nz) = dvdx(1:nx,1:ny,lbz:nz) - dudy(1:nx,1:ny,lbz:nz)
vortz(1:nx,1:ny,lbz:nz) = interp_to_w_grid( vortx(1:nx,1:ny,lbz:nz), lbz)
vortx(1:nx,1:ny,lbz:nz) = dwdy(1:nx,1:ny,lbz:nz) - dvdz(1:nx,1:ny,lbz:nz)
vorty(1:nx,1:ny,lbz:nz) = dudz(1:nx,1:ny,lbz:nz) - dwdx(1:nx,1:ny,lbz:nz)
if (coord == 0) then
vortz(1:nx,1:ny, 1) = 0._rprec
end if
! Common file name for all output types
call string_splice(fname, path //'output/vort.', jt_total)
#if defined(PPCGNS) && defined(PPMPI)
! Write CGNS Output
call string_concat(fname, '.cgns')
call write_parallel_cgns(fname,nx,ny, nz - nz_end, nz_tot, &
(/ 1, 1, (nz-1)*coord + 1 /), &
(/ nx, ny, (nz-1)*(coord+1) + 1 - nz_end /), &
x(1:nx) , y(1:ny) , zw(1:(nz-nz_end) ), &
3, (/ 'VorticityX', 'VorticityY', 'VorticityZ' /), &
(/ vortx(1:nx,1:ny,1:(nz-nz_end)), vorty(1:nx,1:ny,1:(nz-nz_end)), &
vortz(1:nx,1:ny,1:(nz-nz_end)) /) )
#else
! Write binary Output
call string_concat(fname, bin_ext)
open(unit=13, file=fname, form='unformatted', convert=write_endian, &
access='direct', recl=nx*ny*nz*rprec)
write(13,rec=1) vortx(:nx,:ny,1:nz)
write(13,rec=2) vorty(:nx,:ny,1:nz)
write(13,rec=3) vortz(:nx,:ny,1:nz)
close(13)
#endif
deallocate(vortx, vorty, vortz)
! Compute pressure
allocate(pres_real(nx,ny,lbz:nz))
pres_real(1:nx,1:ny,lbz:nz) = 0._rprec
! Calculate real pressure
pres_real(1:nx,1:ny,lbz:nz) = p(1:nx,1:ny,lbz:nz) &
- 0.5 * ( u(1:nx,1:ny,lbz:nz)**2 &
+ interp_to_uv_grid( w(1:nx,1:ny,lbz:nz), lbz)**2 &
+ v(1:nx,1:ny,lbz:nz)**2 )
! Common file name for all output types
call string_splice(fname, path //'output/pres.', jt_total)
#if defined(PPCGNS) && defined(PPMPI)
! Write CGNS Output
call string_concat(fname, '.cgns')
call write_parallel_cgns(fname, nx, ny, nz - nz_end, nz_tot, &
(/ 1, 1, (nz-1)*coord + 1 /), &
(/ nx, ny, (nz-1)*(coord+1) + 1 - nz_end /), &
x(1:nx) , y(1:ny) , z(1:(nz-nz_end) ), &
1, (/ 'Pressure' /), (/ pres_real(1:nx,1:ny,1:(nz-nz_end)) /) )
#else
! Write binary Output
call string_concat(fname, bin_ext)
open(unit=13, file=fname, form='unformatted', convert=write_endian, &
access='direct', recl=nx*ny*nz*rprec)
write(13,rec=1) pres_real(:nx,:ny,1:nz)
close(13)
#endif
deallocate(pres_real)
#ifdef PPSCALARS
! Common file name for all output types
call string_splice(fname, path //'output/theta.', jt_total)
#if defined(PPCGNS) && defined(PPMPI)
! Write CGNS Output
call string_concat(fname, '.cgns')
call write_parallel_cgns(fname, nx, ny, nz - nz_end, nz_tot, &
(/ 1, 1, (nz-1)*coord + 1 /), &
(/ nx, ny, (nz-1)*(coord+1) + 1 - nz_end /), &
x(1:nx) , y(1:ny) , z(1:(nz-nz_end) ), &
1, (/ 'Theta' /), (/ theta(1:nx,1:ny,1:(nz-nz_end)) /) )
#else
! Write binary Output
call string_concat(fname, bin_ext)
open(unit=13, file=fname, form='unformatted', convert=write_endian, &
access='direct', recl=nx*ny*nz*rprec)
write(13,rec=1) theta(:nx,:ny,1:nz)
close(13)
#endif
#endif
! Write instantaneous x-plane values
elseif(itype==3) then
allocate(ui(1,ny,nz), vi(1,ny,nz), wi(1,ny,nz))
! Loop over all xplane locations
do i = 1, xplane_nloc
do k = 1, nz
do j = 1, ny
ui(1,j,k) = linear_interp(u(xplane(i) % istart,j,k), &
u(xplane(i) % istart+1,j,k), dx, xplane(i) % ldiff)
vi(1,j,k) = linear_interp(v(xplane(i) % istart,j,k), &
v(xplane(i) % istart+1,j,k), dx, xplane(i) % ldiff)
wi(1,j,k) = linear_interp(w_uv(xplane(i) % istart,j,k), &
w_uv(xplane(i) % istart+1,j,k), dx, &
xplane(i) % ldiff)
end do
end do
! Common file name portion for all output types
call string_splice(fname, path // 'output/vel.x-', xplane_loc(i), '.', jt_total)
#if defined(PPCGNS) && defined(PPMPI)
! Write CGNS Output
call string_concat(fname, '.cgns')
call write_parallel_cgns (fname,1,ny, nz - nz_end, nz_tot, &
(/ 1, 1, (nz-1)*coord + 1 /), &
(/ 1, ny, (nz-1)*(coord+1) + 1 - nz_end /), &
xplane_loc(i:i) , y(1:ny) , z(1:(nz-nz_end) ), &
3, (/ 'VelocityX', 'VelocityY', 'VelocityZ' /), &
(/ ui(1,1:ny,1:(nz-nz_end)), vi(1,1:ny,1:(nz-nz_end)), &
wi(1,1:ny,1:(nz-nz_end)) /) )
#else
! Write binary output
call string_concat(fname, bin_ext)
open(unit=13,file=fname,form='unformatted',convert=write_endian, access='direct',recl=ny*nz*rprec)
write(13,rec=1) ui
write(13,rec=2) vi
write(13,rec=3) wi
close(13)
#endif
end do
deallocate(ui,vi,wi)
! Write instantaneous y-plane values
elseif(itype==4) then
allocate(ui(nx,1,nz), vi(nx,1,nz), wi(nx,1,nz))
! Loop over all yplane locations
do j = 1, yplane_nloc
do k = 1, nz
do i = 1, nx
ui(i,1,k) = linear_interp(u(i,yplane(j) % istart,k), &
u(i,yplane(j) % istart+1,k), dy, yplane(j) % ldiff)
vi(i,1,k) = linear_interp(v(i,yplane(j) % istart,k), &
v(i,yplane(j) % istart+1,k), dy, yplane(j) % ldiff)
wi(i,1,k) = linear_interp(w_uv(i,yplane(j) % istart,k), &
w_uv(i,yplane(j) % istart+1,k), dy, yplane(j) % ldiff)
end do
end do
! Common file name portion for all output types
call string_splice(fname, path // 'output/vel.y-', yplane_loc(j), '.', &
jt_total)
#if defined(PPCGNS) && defined(PPMPI)
call string_concat(fname, '.cgns')
call write_parallel_cgns (fname,nx,1, nz - nz_end, nz_tot, &
(/ 1, 1, (nz-1)*coord + 1 /), &
(/ nx, 1, (nz-1)*(coord+1) + 1 - nz_end /), &
x(1:nx) , yplane_loc(j:j) , z(1:(nz-nz_end) ), &
3, (/ 'VelocityX', 'VelocityY', 'VelocityZ' /), &
(/ ui(1:nx,1,1:(nz-nz_end)), vi(1:nx,1,1:(nz-nz_end)), &
wi(1:nx,1,1:(nz-nz_end)) /) )
#else
! Write binary output
call string_concat(fname, bin_ext)
open(unit=13,file=fname,form='unformatted',convert=write_endian, access='direct',recl=nx*nz*rprec)
write(13,rec=1) ui
write(13,rec=2) vi
write(13,rec=3) wi
close(13)
#endif
end do
deallocate(ui,vi,wi)