-
Notifications
You must be signed in to change notification settings - Fork 38
/
postproc_mod.f90
4270 lines (4269 loc) · 133 KB
/
postproc_mod.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 postprocessor_mod
!
!.. Global Use Statements ..
use module_kind_types
use module_cgns_types
use eqn_idx, only : nq,nec,nmx,nmy,nmz,nee,nmb,nme,ntk
!
implicit none
!
private
!
! ##################################
! ### Module Public Procedures ###
! ##################################
!
public :: new_write_parallel_cgns
!
!
! ################################
! ### Module Local Variables ###
! ################################
!
type :: geom_pnt_map_t
integer, allocatable :: sp(:)
integer, allocatable :: fp(:)
integer, allocatable :: ep(:)
integer, allocatable :: np(:)
end type geom_pnt_map_t
!
type :: output_face_pts_t
integer :: face_idx
integer, allocatable :: out_idx(:)
end type output_face_pts_t
!
type :: output_edge_pts_t
integer :: edge_idx
integer, allocatable :: out_idx(:)
end type output_edge_pts_t
!
type :: output_node_pts_t
integer :: node_idx
integer :: out_idx
end type output_node_pts_t
!
integer, allocatable :: output_sol_pts(:)
!
type(output_face_pts_t), allocatable :: output_face_pts(:)
!
type(output_edge_pts_t), allocatable :: output_edge_pts(:)
!
type(output_node_pts_t), allocatable :: output_node_pts(:)
!
type :: plot_func_t
integer :: func
character(len=CGLEN) :: varname = ""
contains
procedure :: get_function_name
end type plot_func_t
!
type(plot_func_t), public, parameter :: &
plot_static_density = plot_func_t( 1), &
plot_velocity_x = plot_func_t( 2), &
plot_velocity_y = plot_func_t( 3), &
plot_velocity_z = plot_func_t( 4), &
plot_static_pressure = plot_func_t( 5), &
plot_static_temperature = plot_func_t( 6), &
plot_momentum_x = plot_func_t( 7), &
plot_momentum_y = plot_func_t( 8), &
plot_momentum_z = plot_func_t( 9), &
plot_total_energy = plot_func_t(10), &
plot_entropy = plot_func_t(11), &
plot_mach_number = plot_func_t(12), &
plot_vorticity_x = plot_func_t(13), &
plot_vorticity_y = plot_func_t(14), &
plot_vorticity_z = plot_func_t(15), &
plot_grad_density(3) = [plot_func_t(16), &
plot_func_t(17), &
plot_func_t(18)], &
plot_grad_momentum_x(3) = [plot_func_t(19), &
plot_func_t(20), &
plot_func_t(21)], &
plot_grad_momentum_y(3) = [plot_func_t(22), &
plot_func_t(23), &
plot_func_t(24)], &
plot_grad_momentum_z(3) = [plot_func_t(25), &
plot_func_t(26), &
plot_func_t(27)], &
plot_grad_energy(3) = [plot_func_t(28), &
plot_func_t(29), &
plot_func_t(30)]
!
type(plot_func_t), allocatable :: plot_var(:)
!
integer, save :: npvar = 20
!
integer, save, allocatable :: ipelem_of_cells(:,:,:)
!
! INITIALIZATION_NEEDED: Private module variable that indicates whether the
! initializations required for CGNS have been completed
! or not.
!
logical(lk), save :: initialization_needed = true
!
character(len=*), parameter :: char_xyz(1:3) = ["X","Y","Z"]
!
! ###########################
! ### Module Parameters ###
! ###########################
!
logical(lk), parameter :: check_gradients = fals
!logical(lk), parameter :: check_gradients = true
!
! ################################
! ### Module Local Variables ###
! ################################
!
!.. Output File Names ..
character(len=*), parameter :: cgns_base_fname = "solution.grid.cgns"
character(len=170), save :: cgns_dir = ""
character(len=170), save :: cgns_grid_file
!
character(len=170), save :: cgnsfile_fmt
!
!.. CGNS Path Variables ..
integer(CBT), save :: ifile_n
integer(CBT), save :: ibase_n
integer(CBT), save :: izone_n
integer(CBT), save :: isect_n
integer(CBT), parameter :: iiter_n = 1_CBT
!
integer(CBT), save, allocatable, dimension(:) :: isvar_s
!
!.. CGNS Time Dependent Variables ..
integer, save :: cgns_zone_counter
!
real(sp), save, allocatable, dimension(:) :: soltime
character(len=CGLEN), save, allocatable, dimension(:) :: solname
!
character(len=*), parameter :: base_name = "gfr_base"
character(len=*), parameter :: zone_name = "Solution"
!
!.. CGNS Parallel Point Indices ..
integer, save :: n_my_output_pts
integer, save :: my_pts_beg
integer, save :: my_pts_end
!
integer(CST), dimension(1:3) :: zone_size
!
! DISABLE_CGNS_OUTPUT: Private module variable to disable CGNS output. It
! is currently only relevant to the Taylor-Green Vortex
! problem and is more of a temporary addition until the
! output logic/code becomes more robust.
!
logical(lk), save :: disable_cgns_output = fals
!
!!" FINISHED SUBROUTINE MAP_TO_OUTPUT_POINTS AND THE RELATED FUNCTIONS FOR"
!!" HEXAHEDRA CELLS. NOW NEED TO GO BACK AND FIGURE OUT HOW TO APPLY THIS"
!!" FOR THE CONNECTIVITY AND FOR CREATING THE SOLUTION ARRAY SENT TO CGNS."
!!!
!!" WHEN CREATING THE SOLUTION ARRAY, NEED TO FIGURE OUT WHAT TO DO ABOUT"
!!" POINTS FOR WHICH AN ADJACENT PARTITION IS RESPONSIBLE. IN THESE CASES"
!!" THERE IS A POINT IN THE SOLUTION ARRAY THAT NEEDS TO BE SKIPPED FOR A"
!!" PARTITION THAT SHARES THIS POINT BUT IS NOT RESPONSIBLE FOR ITS SOLUTION."
!!!
!!!
!!" NEED TO FIGURE OUT CONNECTIVITY OF THE GLOBAL GRID AND WHICH CELLS ARE"
!!" RESPONSIBLE FOR WHICH OUTPUT POINTS."
!!" - NEED TO FIGURE THIS OUT FOR BOTH SERIAL AND PARALLEL CASES."
!!" - USE CELL(:)%NODE(:)%CELL_IDX, CELL(:)%EDGE(:)%CELL_IDX(:), AND"
!!" CELL(:)%FACE(:)%CELL_IDX(:) TO MAP THE LOCATIONS OF THE NODE, EDGE,"
!!" AND FACE VALUES WITHIN NODEUSP, NODEDUSP, EDGEUSP, EDGEDUSP, FACEUSP,"
!!" AND FACEDUSP TO THE CORRECT LOCATIONS WITHIN THE ARRAY THATS CREATED"
!!" TO COLLECT THE SOLUTIONS FOR SENDING TO CGNS."
!!" - TO REMOVE THE DUPLICATE POINT INDICES ON PARTITION BOUNDARIES IN THE"
!!" CGNS FILE, A POSSIBLE PATH COULD BE TO USE THE NODEUSP, EDGEUSP, AND"
!!" FACEUSP ARRAYS TO STORE A REAL VALUE OF A GIVEN POINT INDEX ON THE"
!!" PROCESSOR THAT IS RESPONSIBLE FOR WRITING THE SOLUTION AT THIS POINT,"
!!" AND ALL OTHER PROCESSORS STORE A NEGATIVE VALUE (OR SOMETHING THAT CAN"
!!" BE IDENTIFIED AS A POINT INDEX FROM THE WRONG PROCESSOR) AND USE THE"
!!" EXISTING COMMUNICATION/EXCHANGE CODE TO SYNCRONIZE THE CORRECT POINT"
!!" INDEX ON ALL PROCESSORS. THERE COULD BE SOME LOGIC THAT ONLY ADDS"
!!" POSITIVE VALUES FROM THE RECEIVE BUFFER BACK INTO NODEUSP, EDGEUSP,"
!!" OR FACEUSP. AFTER THAT, ITS JUST A MATTER OF CONVERTING THE REAL"
!!" VALUES TO INTEGERS AND USE THEM TO OVERWRITE THE PROPER POINT INDICES"
!!" IN THE CONNECTIVITY ARRAY THAT SENT INTO CGNS. JUST MAKE SURE NOT"
!!" TO INCLUDE ANY AVERAGING COEFFICIENTS."
!!!
!!" NEED TO FIGURE OUT HOW TO OVERRIDE THE INTERIOR SOLUTIONS FOR THE"
!!" SOLUTIONS ON BOUNDARY FACES, EDGES, AND NODES."
!!" - NEED TO ADJUST THE LOCAL CELLS_WITH_NODE AND CELLS_WITH_EDGE ARRAYS"
!!" ON EACH PARTITION SO THAT IF A NODE OR AN EDGE ARE ON A BOUNDARY"
!!" FACES THE ONLY CELLS REMAINING WITHIN THESE ARRAYS ARE THE GHOST"
!!" CELLS/FACES THAT CONTRIBUTE TO THE SOLUTION AT THE NODE/EDGE."
!!" - NEED TO TAKE INTO ACCOUNT LOCAL BC PRIORITIES AS WELL."
!!" - NEED TO CREATE SOMETHING TO INTERPOLATE THE BOUNDARY FACE SOLUTION"
!!" FOR THE GHOST CELLS/FACES TO THE NODES/EDGES FOR THE BOUNDARY FACES."
!!" INTERPOLATING THE INTERIOR SOLUTION TO THOSE NODE/EDGE POINTS WOULD"
!!" NOT BE CORRECT, FOR EXAMPLE INTERPOLATING THE HOST CELL SOLUTION"
!!" TO A BOUNDARY FACE THAT HAS A NO-SLIP WALL BOUNDARY CONDITION."
!!" - THIS WILL PROBABLY NEED TO BE DONE BEFORE EXCHANGING SINCE THE"
!!" SOLUTION FROM AN ADJACENT PARTITION MIGHT OVERRIDE THE LOCAL"
!!" SOLUTION OR VICE-VERSA."
!!" + IF THIS IS DONE BEFORE THE EXCHANGE, WE NEED TO MAKE SURE THE"
!!" AVERAGING CORRECTION IS BASED ON THE NUMBER OF BOUNDARY FACES"
!!" THAT CONTAIN THE NODE/EDGE AND NOT THE NUMBER OF INTERNAL GRID"
!!" CELLS."
!!!
!!" NEED TO FIGURE OUT HOW TO CONSTRUCT THE GLOBAL EDGE AND NODE"
!!" CONNECTIVITY SO THAT WE CAN CREATE THE MPI DATA TYPES FOR EXCHANGING"
!!" EDGE AND NODE SOLUTIONS."
!!" - NEED TO CREATE THE EDGE DERIVED TYPE ARRAY"
!!" + MAKE SURE THAT THE INDICES IN EDGE(:)%CPU(:)%EDGPTS STARTS AT 0"
!!" - MIGHT NEED TO FIX THE ORDERING OF THE EDGE POINT INDICES THAT"
!!" ARE STORED IN EDGE(:)%CPU(:)%EDGPTS. CURRENTLY IT JUST ASSUMES"
!!" THE ORDERING IS [0:NUMBER OF EDGE POINTS-1]."
!!" + NEED TO CREATE THE NODE DERIVED TYPE ARRAY"
!!" + NEED TO CREATE THE EDGE_MAP ARRAY"
!!" + NEED TO CREATE THE EXCH_NEUSP ARRAY"
!!" - "
!!" - "
!!!
!!" NEED TO FIGURE OUT HOW TO COLLECT THE INTERIOR, FACE, EDGE, AND NODE"
!!" SOLUTIONS TOGETHER AS ONE SOLUTION FOR A CELL BEFORE WRITING IT TO"
!!" THE CGNS SOLUTION FILE."
!!" - USE THE SAME SUBCONNECTIVITY FROM BEFORE INCLUDING THE ADD POINTS"
!!" VALUE DEPENDING ON THE CONTINUOUS SOLUTION INPUT PARAMETER. WE JUST"
!!" NEED A SIMPLE INTEGER ARRAY THAT MAPS THE VARIOUS FACE, EDGE, AND"
!!" NODE POINTS TO THE CORRECT LOCATIONS WITHIN THE ARRAY THAT WILL"
!!" STORE THE SOLUTION FOR THE CELL."
!!!
!!" NEED TO DEALLOCATE THE EDGEXYZ AND FACEXYZ (EXCEPT WHEN USING MMS)"
!!" ARRAYS AFTER WRITING THE FIRST GRID CGNS FILE SINCE THEY WILL NO"
!!" LONGER BE NEEDED."
!!!
!!" THE LOCAL AVERAGING COEFFICIENTS SHOULD ACCOUNT ONLY FOR LOCAL CELLS."
!!" THE BND_NODES AND BND_EDGES ARRAYS WILL CORRECT THE LOCAL AVERAGING"
!!" COEFFICIENTS TO THE CORRECT GLOBAL AVERAGING COEFFICIENT."
!
!
interface operator(==)
module procedure plot_func_type_equals
end interface
!
contains
!
!###############################################################################
!
subroutine new_write_parallel_cgns()
!
!.. Use Statements ..
use geovar, only : nr
use ovar, only : itcur,time,time_ref
use ovar, only : completely_disable_cgns
use ovar, only : write_TaylorGreen_full_solution
!
use, intrinsic :: iso_c_binding, only : C_NULL_CHAR
!
!.. Local Scalars ..
integer :: n,ierr
!
character(len=CGLEN) :: tname
character(len=170) :: sol_file
character(len=300) :: link_path
!
!.. Local Arrays ..
integer, dimension(1:2) :: idata
!
!.. Local Parameters ..
character(len=*), parameter :: pname = "new_write_parallel_cgns"
!
continue
!
if (completely_disable_cgns) return
!
if (disable_cgns_output) then
if (.not. initialization_needed) then
if (.not. write_TaylorGreen_full_solution) then
return
end if
end if
end if
!
call debug_timer(entering_procedure,pname)
!
if (initialization_needed) then
!
! Check for the CGNS output directory and create it if not found
!
call check_cgns_dir
!
! Initialize the functions that will be written to the CGNS solution files
!
call get_plot_functions
!
! Write the CGNS grid file
!
call write_grid_parallel_cgns
!
! Now that the CGNS grid file has been successfully created, set the
! initialization flag to false so this isnt done again.
!
initialization_needed = fals
!
else
!
! The CGNS grid file has already been created so we need to reopen
! it in modification mode.
!
call cgp_open_f(cgns_grid_file,CG_MODE_MODIFY,ifile_n,cgierr)
call cgns_error(pname,cgns_grid_file,"cgp_open_f", &
cgierr,__LINE__,__FILE__,"Mode = CG_MODE_MODIFY")
!
end if
!
! Get the name for the current solution node
!
write (tname,'("FlowSolution",i0)') cgns_zone_counter
!write (sol_file,'("solution.",i0,".cgns")') cgns_zone_counter
write (sol_file,cgnsfile_fmt) itcur
!
! Reallocate the soltime and solname arrays so we
! can concatenate this solution onto those arrays
!
call reallocate(soltime,cgns_zone_counter+1)
call reallocate(solname,cgns_zone_counter+1)
soltime(size(soltime)) = real(time*time_ref,kind(soltime))
solname(size(solname)) = tname
!
! Create a link to the solution node in the current solution file
!
call cg_goto_f(ifile_n,ibase_n,cgierr, &
"Zone_t",izone_n, &
CGNS_GOTO_END)
call cgns_error(pname,cgns_grid_file,"cg_goto_f",cgierr,__LINE__,__FILE__)
!
link_path = base_name//"/"//zone_name//"/"//trim(tname)
!
call cg_link_write_f(trim(tname),trim(sol_file),trim(link_path),cgierr)
call cgns_error(pname,cgns_grid_file,"cg_link_write_f", &
cgierr,__LINE__,__FILE__)
!
! Write the solution file
!
call write_solution_parallel_cgns(sol_file,tname)
!
! ################################################
! ##### FINISHED WRITING FIELD VARIABLES #####
! ################################################
!
call set_cgns_queue(STOP_CGNS_QUEUE,pname,cgns_grid_file)
!
! Update the solution times within the base iterative node
!
call cg_biter_write_f(ifile_n,ibase_n,'TimeIterValues', &
size(soltime,kind=CBT),cgierr)
call cgns_error(pname,cgns_grid_file,"cg_biter_write_f", &
cgierr,__LINE__,__FILE__)
!
call cg_goto_f(ifile_n,ibase_n,cgierr, &
"BaseIterativeData_t",iiter_n, &
CGNS_GOTO_END)
call cgns_error(pname,cgns_grid_file,"cg_goto_f", &
cgierr,__LINE__,__FILE__)
!
call cg_array_write_f("TimeValues",CGNS_KIND_REAL,1_CBT, &
size(soltime,kind=CST),soltime,ierr)
call cgns_error(pname,cgns_grid_file,"cg_array_write_f", &
cgierr,__LINE__,__FILE__)
!
! Update the names of the zone iterative nodes
!
call cg_ziter_write_f(ifile_n,ibase_n,izone_n,"ZoneIterativeData",cgierr)
call cgns_error(pname,cgns_grid_file,"cg_ziter_write_f", &
cgierr,__LINE__,__FILE__)
!
call cg_goto_f(ifile_n,ibase_n,cgierr, &
"Zone_t",izone_n, &
"ZoneIterativeData_t",iiter_n, &
CGNS_GOTO_END)
call cgns_error(pname,cgns_grid_file,"cg_goto_f", &
cgierr,__LINE__,__FILE__)
!
idata(:) = int( [32,size(solname)] , kind=CST )
call cg_array_write_f("FlowSolutionPointers",CHARACTER,2_CBT, &
idata,solname,cgierr)
call cgns_error(pname,cgns_grid_file,"cg_array_write_f", &
cgierr,__LINE__,__FILE__)
!
! Identify the flow solution within the CGNS file as time dependent
!
call cg_simulation_type_write_f(ifile_n,ibase_n,TIMEACCURATE,cgierr)
call cgns_error(pname,cgns_grid_file,"cg_simulation_type_write_f", &
cgierr,__LINE__,__FILE__)
!
! Close the CGNS FILE
!
call cgp_close_f(ifile_n,cgierr)
call cgns_error(pname,cgns_grid_file,"cgp_close_f",cgierr,__LINE__,__FILE__)
!
! Update the zone counter
!
cgns_zone_counter = cgns_zone_counter + 1
!
write (error_message,100)
100 format ("Temporary stop after writing initial CGNS files using the ", &
"new continuous output from the post-processor module.")
call stop_gfr(stop_mpi,pname,__LINE__,__FILE__,error_message)
!
call debug_timer(leaving_procedure,pname)
!
! Format Statements
!
1 format ("#############################################",/, &
" FOR PROCESSOR #",i0)
2 format (a," = ",i0)
!
end subroutine new_write_parallel_cgns
!
!###############################################################################
!
subroutine write_grid_parallel_cgns()
!
!.. Use Statements ..
use geovar, only : nr
!
!.. Local Scalars ..
integer :: n,ierr
!
integer(CST) :: my_cells_beg,my_cells_end
integer(CST) :: n_total_output_pts
integer(CST) :: n_total_output_cells
!
character(len=CGLEN) :: varname
!
!.. Local Arrays ..
integer(CBT), dimension(1:nr) :: ixyz_n
!
!.. Local Allocatable Arrays ..
integer(CST), allocatable :: ipelem(:,:)
real(wp), allocatable :: vartmp(:,:)
real(CRT), allocatable :: var(:)
!
!.. Local Parameters ..
character(len=*), parameter :: pname = "write_grid_parallel_cgns"
!
continue
!
call debug_timer(entering_procedure,pname)
!
cgns_grid_file = trim(adjustl(cgns_dir)) // cgns_base_fname
!
! Initialize the variables and data arrays needed for CGNS output
! NOTE: This call to routine create_cell_subconnectivity will initialize
! the module variables my_pts_beg, my_pts_end, and n_my_output_pts.
!
call create_cell_subconnectivity(my_cells_beg,my_cells_end,ipelem)
!
! Extract the total number of pts and cells from the zone_size array
!
n_total_output_pts = zone_size(1)
n_total_output_cells = zone_size(2)
!
! Allocate the temporary variable arrays
!
allocate ( vartmp(1:nr,1:n_my_output_pts) , source=zero , &
stat=ierr , errmsg=error_message )
call alloc_error(pname,"vartmp",1,__LINE__,__FILE__,ierr,error_message)
!
allocate ( var(1:n_my_output_pts) , source=real(0,CRT) , &
stat=ierr , errmsg=error_message )
call alloc_error(pname,"var",1,__LINE__,__FILE__,ierr,error_message)
!
! Initialize the zone counter
!
cgns_zone_counter = 0
!
call cgp_open_f(cgns_grid_file,CG_MODE_WRITE,ifile_n,cgierr)
call cgns_error(pname,cgns_grid_file,"cgp_open_f", &
cgierr,__LINE__,__FILE__,"Mode = CG_MODE_WRITE")
!
! Set the CGNS base (who knows what this is for)
!
call cg_base_write_f(ifile_n,base_name,int(nr,kind=CBT), &
int(nr,kind=CBT),ibase_n,cgierr)
call cgns_error(pname,cgns_grid_file,"cg_base_write_f", &
cgierr,__LINE__,__FILE__)
!
! Write the title for this solution
!
call cg_zone_write_f(ifile_n,ibase_n,zone_name,zone_size, &
UNSTRUCTURED,izone_n,ierr)
call cgns_error(pname,cgns_grid_file,"cg_zone_write_f", &
cgierr,__LINE__,__FILE__)
!
! Create data nodes for the coordinates
!
do n = 1,nr
varname = "Coordinate"//char_xyz(n)
call cgp_coord_write_f(ifile_n,ibase_n,izone_n,CGNS_KIND_REAL, &
trim(varname),ixyz_n(n),ierr)
call cgns_error(pname,cgns_grid_file,"cgp_coord_write_f", &
cgierr,__LINE__,__FILE__,"Write node: Coordinate",n)
end do
!
! Now create and write the coordinate data in parallel
!
! Stop/Disable the CGNS queue if it is not to be used
!
call disable_cgns_queue(pname,cgns_grid_file)
!
! Collect the coordinates for all the output points that this processor
! is responsible for writing to the CGNS files
!
call collect_coordinates_for_output(vartmp)
!
if (ncpu == 1) then
call write_tecplot_file(vartmp,ipelem)
end if
!
! Write the coordinates for the output points to the CGNS grid file
!
do n = 1,nr
!
! Copy the current coordinate variable into the array var
! and convert to the real type required for the CGNS file.
!
var(:) = real( vartmp(n,:) , kind=kind(var) )
!
! Reset the queue.
!
call set_cgns_queue(BEGIN_CGNS_QUEUE,pname,cgns_grid_file)
!
! Add the data for current coordinate variable to the output queue.
!
call cgp_coord_write_data_f(ifile_n,ibase_n,izone_n,ixyz_n(n), &
my_pts_beg,my_pts_end,var,ierr)
call cgns_error(pname,cgns_grid_file,"cgp_coord_write_data_f", &
cgierr,__LINE__,__FILE__,"Write data: Coordinate",n)
!
! Finally, flush the queue containing the
! current coordinate variable to the CGNS file.
!
call flush_cgns_queue(pname,cgns_grid_file)
!
end do
!
! Create the data node for the grid connectivity
!
if (nr == 2) then
call cgp_section_write_f(ifile_n,ibase_n,izone_n,"Quadrilaterals", &
QUAD_4,1_CST,n_total_output_cells, &
0_CBT,isect_n,ierr)
call cgns_error(pname,cgns_grid_file,"cgp_section_write_f", &
cgierr,__LINE__,__FILE__,"Element Type = QUAD_4")
else if (nr == 3) then
call cgp_section_write_f(ifile_n,ibase_n,izone_n,"Hexahedrals", &
HEXA_8,1_CST,n_total_output_cells, &
0_CBT,isect_n,ierr)
call cgns_error(pname,cgns_grid_file,"cgp_section_write_f", &
cgierr,__LINE__,__FILE__,"Element Type = HEXA_8")
end if
!
! Write the element connectivity in parallel
!
! Reset the queue.
!
call set_cgns_queue(BEGIN_CGNS_QUEUE,pname,cgns_grid_file)
!
! Add the element connectivity data to the output queue.
!
call cgp_elements_write_data_f(ifile_n,ibase_n,izone_n,isect_n, &
my_cells_beg,my_cells_end,ipelem,ierr)
call cgns_error(pname,cgns_grid_file,"cgp_elements_write_data_f", &
cgierr,__LINE__,__FILE__)
!
! Finally, flush the queue containing the
! element connectivity to the CGNS file.
!
call flush_cgns_queue(pname,cgns_grid_file)
!
! Deallocate the arrays var, vartmp, and ipelem
!
if (allocated(var)) then
deallocate ( var , stat=ierr , errmsg=error_message )
call alloc_error(pname,"var",2,__LINE__,__FILE__,ierr,error_message)
end if
if (allocated(vartmp)) then
deallocate ( vartmp , stat=ierr , errmsg=error_message )
call alloc_error(pname,"vartmp",2,__LINE__,__FILE__,ierr,error_message)
end if
if (allocated(ipelem)) then
deallocate ( ipelem , stat=ierr , errmsg=error_message )
call alloc_error(pname,"ipelem",2,__LINE__,__FILE__,ierr,error_message)
end if
!
call debug_timer(leaving_procedure,pname)
!
end subroutine write_grid_parallel_cgns
!
!###############################################################################
!
subroutine write_solution_parallel_cgns(sol_file,tname)
!
!.. Use Statements ..
use geovar, only : nr
!
use, intrinsic :: iso_c_binding, only : C_NULL_CHAR
!
!.. Formal Arguments ..
character(len=*), intent(in) :: sol_file
character(len=*), intent(in) :: tname
!
!.. Local Scalars ..
integer :: n,ierr
!
character(len=CGLEN) :: sect_name
character(len=170) :: cgns_sol_file
character(len=300) :: link_path
!
!.. Local Arrays ..
integer(CBT) :: ifile_s,ibase_s,izone_s,isol_s
!
!.. Local Allocatable Arrays ..
real(wp), allocatable :: vartmp(:,:)
real(CRT), allocatable :: var(:)
!
!.. Local Parameters ..
character(len=*), parameter :: pname = "write_solution_parallel_cgns"
!
continue
!
call debug_timer(entering_procedure,pname)
!
cgns_sol_file = trim(adjustl(cgns_dir)) // trim(adjustl(sol_file))
!
! Open the cgns output file if iflag is equal to open_CGNS
!
! Initialize the zone counter
!
call cgp_open_f(cgns_sol_file,CG_MODE_WRITE,ifile_s,cgierr)
call io_error(pname,cgns_sol_file,1,__LINE__,__FILE__,cgierr)
!
! Set the CGNS base (who knows what this is for)
!
call cg_base_write_f(ifile_s,base_name,int(nr,kind=CBT), &
int(nr,kind=CBT),ibase_s,cgierr)
call cgns_error(pname,cgns_sol_file,"cg_base_write_f", &
cgierr,__LINE__,__FILE__)
!
! Write the title for this solution
!
call cg_zone_write_f(ifile_s,ibase_s,zone_name,zone_size, &
UNSTRUCTURED,izone_s,ierr)
call cgns_error(pname,cgns_sol_file,"cg_zone_write_f", &
cgierr,__LINE__,__FILE__)
!
! Create a link to the grid coordinates in the grid file
!
call cg_goto_f(ifile_s,ibase_s,cgierr, &
"Zone_t",izone_s, &
CGNS_GOTO_END)
call cgns_error(pname,cgns_sol_file,"cg_goto_f",cgierr,__LINE__,__FILE__)
!
link_path = base_name//"/"//zone_name//"/GridCoordinates"
!
call cg_link_write_f("GridCoordinates",trim(cgns_base_fname), &
trim(link_path),ierr)
call cgns_error(pname,cgns_sol_file,"cg_link_write_f(GridCoordinates)", &
cgierr,__LINE__,__FILE__)
!
! Create a link to the element connectivity in the grid file
!
if (nr == 2) then
sect_name = "Quadrilaterals"
else if (nr == 3) then
sect_name = "Hexahedrals"
end if
link_path = base_name//"/"//zone_name//"/"//trim(sect_name)
!
call cg_link_write_f(trim(sect_name),trim(cgns_base_fname), &
trim(link_path),ierr)
call cgns_error(pname,cgns_sol_file, &
"cg_link_write_f("//trim(sect_name)//")", &
cgierr,__LINE__,__FILE__)
!
! Allocate var and vartmp if they arent already allocated
!
allocate ( vartmp(1:npvar,1:n_my_output_pts) , source=zero , &
stat=ierr , errmsg=error_message )
call alloc_error(pname,"vartmp",1,__LINE__,__FILE__,ierr,error_message)
!
allocate ( var(1:n_my_output_pts) , source=real(0,CRT) , &
stat=ierr , errmsg=error_message )
call alloc_error(pname,"var",1,__LINE__,__FILE__,ierr,error_message)
!
! Collect the solution into vartmp
!
call collect_solution_for_output(vartmp)
!
! Write the flow variables
!
call cg_sol_write_f(ifile_s,ibase_s,izone_s,tname,VERTEX,isol_s,cgierr)
call cgns_error(pname,cgns_sol_file,"cg_sol_write_f",cgierr,__LINE__,__FILE__)
!
! ################################################
! ##### WRITING SOLUTION FIELD VARIABLES #####
! ################################################
!
! Create data nodes for the solution variables
!
do n = 1,size(plot_var)
call cgp_field_write_f(ifile_s,ibase_s,izone_s,isol_s,CGNS_KIND_REAL, &
trim(plot_var(n)%varname),isvar_s(n),ierr)
call cgns_error(pname,cgns_sol_file,"cgp_field_write_f", &
cgierr,__LINE__,__FILE__,"Write node: Solution variable",n)
end do
!
! Now create the output data and write it to the CGNS file in parallel
!
do n = 1,size(plot_var)
!
! Save this plot function into a separate contiguous array
!
var(:) = real( vartmp(n,:) , kind=kind(var) )
!
! Reset the queue.
!
call set_cgns_queue(BEGIN_CGNS_QUEUE,pname,cgns_sol_file)
!
! Add the data for current variable to the output queue.
!
call cgp_field_write_data_f(ifile_s,ibase_s,izone_s,isol_s,isvar_s(n), &
my_pts_beg,my_pts_end,var,ierr)
call cgns_error(pname,cgns_sol_file,"cgp_field_write_data_f", &
cgierr,__LINE__,__FILE__,"Write data: Solution variable",n)
!
! Finally, flush the queue containing
! the current variable to the CGNS file.
!
call flush_cgns_queue(pname,cgns_sol_file)
!
end do
!
! ################################################
! ##### FINISHED WRITING FIELD VARIABLES #####
! ################################################
!
call set_cgns_queue(STOP_CGNS_QUEUE,pname,cgns_sol_file)
!
! Close the CGNS FILE
!
call cgp_close_f(ifile_s,cgierr)
call io_error(pname,cgns_grid_file,2,__LINE__,__FILE__,cgierr)
!
! Deallocate the arrays var and vartmp
!
if (allocated(var)) then
deallocate ( var , stat=ierr , errmsg=error_message )
call alloc_error(pname,"var",2,__LINE__,__FILE__,ierr,error_message)
end if
if (allocated(vartmp)) then
deallocate ( vartmp , stat=ierr , errmsg=error_message )
call alloc_error(pname,"vartmp",2,__LINE__,__FILE__,ierr,error_message)
end if
!
call debug_timer(leaving_procedure,pname)
!
! Format Statements
!
1 format ("#############################################",/, &
" FOR PROCESSOR #",i0)
2 format (a," = ",i0)
!
end subroutine write_solution_parallel_cgns
!
!###############################################################################
!
subroutine collect_coordinates_for_output(var)
!
!.. Use Statements ..
use geovar, only : nfbnd,ncell,cell
use geovar, only : xyz,xyz_nodes
use flowvar, only : edgexyz,facexyz
use flowvar, only : face_xyz
use ovar, only : mms_opt
!
!.. Formal Arguments ..
real(wp), dimension(:,:), intent(out) :: var
!
!.. Local Scalars ..
integer :: k,l,n,nc,ne,nf,nn,np1,np2,ierr
integer :: face_idx,edge_idx,node_idx
!
!.. Local Allocatable Arrays ..
type(face_xyz), allocatable :: temp_facexyz(:)
!
!.. Local Parameters ..
character(len=*), parameter :: pname = "collect_coordinates_for_output"
!
continue
!
call debug_timer(entering_procedure,pname)
!
cell_loop: do nc = 1,ncell
!
np1 = cell(nc)%beg_sp
np2 = cell(nc)%end_sp
!
write (170,1) nc
do n = np1,np2
!
l = output_sol_pts(n)
write (170,2) n,l,(xyz(nn,n), nn=1,size(var,dim=1))
!
var(:,l) = xyz(:,n)
!
end do
!
end do cell_loop
1 format (" Cell ",i0)
2 format (" SP ",i0," => ",i0," : ",3es14.6)
3 format (" Face ",i0)
4 format (" FP ",i0," => ",i0," : ",3es14.6)
5 format (" Edge ",i0)
6 format (" EP ",i0," => ",i0," : ",3es14.6)
7 format (" Node")
8 format (" NP ",i0," => ",i0," : ",3es14.6)
!
!
!
face_loop: do nf = 1,size(output_face_pts)
!
face_idx = output_face_pts(nf)%face_idx
!
write (170,3) face_idx
do k = 1,size(output_face_pts(nf)%out_idx)
!
l = output_face_pts(nf)%out_idx(k)
!
write (170,4) k,l,(facexyz(face_idx)%v(n,k), n=1,size(var,dim=1))
var(:,l) = facexyz(face_idx)%v(:,k)
!
end do
!
end do face_loop
!
!
!
edge_loop: do ne = 1,size(output_edge_pts)
!
edge_idx = output_edge_pts(ne)%edge_idx
!
write (170,5) edge_idx
do k = 1,size(output_edge_pts(ne)%out_idx)
!
l = output_edge_pts(ne)%out_idx(k)
!
write (170,6) k,l,(edgexyz(edge_idx)%v(n,k), n=1,size(var,dim=1))
var(:,l) = edgexyz(edge_idx)%v(:,k)
!
end do
!
end do edge_loop
!
!
!
write (170,7)
node_loop: do nn = 1,size(output_node_pts)
!
node_idx = output_node_pts(nn)%node_idx
!
l = output_node_pts(nn)%out_idx
!
write (170,8) node_idx,l,(xyz_nodes(n,node_idx), n=1,size(var,dim=1))
var(:,l) = xyz_nodes(:,node_idx)
!
end do node_loop
!
! Deallocate edgexyz since it is no longer needed
!
deallocate ( edgexyz , stat=ierr , errmsg=error_message )
call alloc_error(pname,"edgexyz",2,__LINE__,__FILE__,ierr,error_message)
!
! Deallocate or shrink facexyz depending on if MMS is enabled
!
if (mms_opt /= 0) then
!
! MMS is enabled, so shrink facexyz to only the boundary faces because the
! coordinates for the face points on the interior faces are no longer needed
!
allocate ( temp_facexyz(1:nfbnd) , source=facexyz(1:nfbnd) , &
stat=ierr , errmsg=error_message )
call alloc_error(pname,"temp_facexyz",1,__LINE__,__FILE__,ierr, &
error_message)
call move_alloc( from=temp_facexyz , to=facexyz )
!
else
!
! MMS is not enabled, so deallocate facexyz
! entirely since it is no longer needed
!
deallocate ( facexyz , stat=ierr , errmsg=error_message )
call alloc_error(pname,"facexyz",2,__LINE__,__FILE__,ierr,error_message)
!
end if
!
call debug_timer(leaving_procedure,pname)
!
end subroutine collect_coordinates_for_output
!
!###############################################################################
!
subroutine collect_solution_for_output(var)
!
!.. Use Statements ..
use geovar, only : ncell,cell
use flowvar, only : usp,dusp
use flowvar, only : faceusp,facedusp
use flowvar, only : nodeusp,nodedusp
use flowvar, only : edgeusp,edgedusp
!
!.. Formal Arguments ..
real(wp), dimension(:,:), intent(out) :: var
!
!.. Local Scalars ..
integer :: k,l,n,nc,ne,nf,nn,np1,np2
integer :: face_idx,edge_idx,node_idx
!
!.. Local Parameters ..
character(len=*), parameter :: pname = "collect_solution_for_output"
!
continue
!
call debug_timer(entering_procedure,pname)
!
call get_face_solutions
!
call get_edge_and_node_solutions
!
!
cell_loop: do nc = 1,ncell
!
np1 = cell(nc)%beg_sp
np2 = cell(nc)%end_sp
!
do n = np1,np2
!
l = output_sol_pts(n)
!
var(:,l) = compute_output_variables(usp(:,n),dusp(:,:,n))
!
end do
!
end do cell_loop
!
!
!
face_loop: do nf = 1,size(output_face_pts)
!
face_idx = output_face_pts(nf)%face_idx
!
do k = 1,size(output_face_pts(nf)%out_idx)
!
l = output_face_pts(nf)%out_idx(k)
!
var(:,l) = compute_output_variables(faceusp(face_idx)%v(:,k,1), &
facedusp(face_idx)%v(:,:,k,1))
!
end do
!
end do face_loop
!
!
!
edge_loop: do ne = 1,size(output_edge_pts)
!
edge_idx = output_edge_pts(ne)%edge_idx
!
do k = 1,size(output_edge_pts(ne)%out_idx)
!
l = output_edge_pts(ne)%out_idx(k)
!
var(:,l) = compute_output_variables(edgeusp(edge_idx)%v(:,k), &
edgedusp(edge_idx)%v(:,:,k))
!
end do
!
end do edge_loop
!
!
!
node_loop: do nn = 1,size(output_node_pts)
!
node_idx = output_node_pts(nn)%node_idx
!
l = output_node_pts(nn)%out_idx
!
var(:,l) = compute_output_variables(nodeusp(node_idx)%v(:), &
nodedusp(node_idx)%v(:,:))
!