-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathcgns_mod.f90
7453 lines (7450 loc) · 246 KB
/
cgns_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 module_cgns
!
#define PROFILE_ON
!!!#define DEBUG_HOST_HANG
!.. Use Statements
use module_kind_types, global_debug_timer => debug_timer
use module_cgns_types
use geovar, only : grid_t
use geovar, only : elem_t
use geovar, only : prop_t
!use geovar, only : cgns_idx_t
!
implicit none
!
private
!
! ##################################
! ### Module Public Procedures ###
! ##################################
!
! Public Interface for CGNS element_properties function
!
interface cgns_element_properties
module procedure element_properties
end interface cgns_element_properties
!
public :: read_cgns_gridfile
public :: cgns_element_properties
public :: cgns_memory_usage
!
! ###########################################################################
! ###########################################################################
! ### ###
! ### Explanation of different element types defined by the CGNS standard ###
! ### ###
! ###########################################################################
! ###########################################################################
!
! ----------------------------------------------------------------------------
!
! NOTES: * The terms EDGE-DEFINED and SERENDIPITY are synonymous.
! * Gmsh exclusively uses the terms incomplete and serendipity
! interchangeably but the CGNS standard uses none of these terms.
! * I coined the terms EDGE-DEFINED and FACE-DEFINED for CGNS to
! differentiate between these two element types because they both are
! incomplete element types.
! * EDGE-DEFINED elements are equivalent to Gmsh SERENDIPITY elements
! and only define the high-order nodes on the edges of the element.
! * FACE-DEFINED elements go one step further and also define the
! high-order interior nodes on the faces of a volume element.
! * A COMPLETE element takes the final step and defines the high-order
! nodes within the interior of the area or volume element.
! * EDGE-DEFINED/SERENDIPITY elements are possible for both 2D and 3D
! element types.
! * FACE-DEFINED elements are only possible for 3D element types.
!
! ----------------------------------------------------------------------------
!
! NODE : 1-node 1st order node
!
! BAR_2 : 2-node 1st order edge
! BAR_3 : 3-node 2nd order edge
! BAR_4 : 4-node 3rd order edge
! BAR_5 : 5-node 4th order edge
!
! TRI_3 : 3-node 1st order COMPLETE triangle
! TRI_6 : 6-node 2nd order COMPLETE triangle
! TRI_9 : 9-node 3rd order EDGE-DEFINED triangle
! TRI_10 : 10-node 3rd order COMPLETE triangle
! TRI_12 : 12-node 4th order EDGE-DEFINED triangle
! TRI_15 : 15-node 4th order COMPLETE triangle
!
! QUAD_4 : 4-node 1st order COMPLETE quadrilateral
! QUAD_8 : 8-node 2nd order EDGE-DEFINED quadrilateral
! QUAD_9 : 9-node 2nd order COMPLETE quadrilateral
! QUAD_12 : 12-node 3rd order EDGE-DEFINED quadrilateral
! QUAD_16 : 16-node 3rd order COMPLETE quadrilateral
! QUAD_P4_16 : 16-node 4th order EDGE-DEFINED quadrilateral
! QUAD_25 : 25-node 4th order COMPLETE quadrilateral
!
! TETRA_4 : 4-node 1st order COMPLETE tetrahedron
! TETRA_10 : 10-node 2nd order COMPLETE tetrahedron
! TETRA_16 : 16-node 3rd order EDGE-DEFINED tetrahedron
! TETRA_20 : 20-node 3rd order COMPLETE tetrahedron
! TETRA_22 : 22-node 4th order EDGE-DEFINED tetrahedron
! TETRA_34 : 34-node 4th order FACE-DEFINED tetrahedron
! TETRA_35 : 35-node 4th order COMPLETE tetrahedron
!
! PYRA_5 : 5-node 1st order COMPLETE pyramid
! PYRA_13 : 13-node 2nd order EDGE-DEFINED pyramid
! PYRA_14 : 14-node 2nd order COMPLETE pyramid
! PYRA_21 : 21-node 3rd order EDGE-DEFINED pyramid
! PYRA_29 : 29-node 3rd order FACE-DEFINED pyramid
! PYRA_30 : 30-node 3rd order COMPLETE pyramid
! PYRA_P4_29 : 29-node 4th order EDGE-DEFINED pyramid
! PYRA_50 : 50-node 4th order FACE-DEFINED pyramid
! PYRA_55 : 55-node 4th order COMPLETE pyramid
!
! PENTA_6 : 6-node 1st order COMPLETE prism
! PENTA_15 : 15-node 2nd order EDGE-DEFINED prism
! PENTA_18 : 18-node 2nd order COMPLETE prism
! PENTA_24 : 24-node 3rd order EDGE-DEFINED prism
! PENTA_38 : 38-node 3rd order FACE-DEFINED prism
! PENTA_40 : 40-node 3rd order COMPLETE prism
! PENTA_33 : 33-node 4th order EDGE-DEFINED prism
! PENTA_66 : 66-node 4th order FACE-DEFINED prism
! PENTA_75 : 75-node 4th order COMPLETE prism
!
! HEXA_8 : 8-node 1st order COMPLETE hexahedron
! HEXA_20 : 20-node 2nd order EDGE-DEFINED hexahedron
! HEXA_27 : 27-node 2nd order COMPLETE hexahedron
! HEXA_32 : 32-node 3rd order EDGE-DEFINED hexahedron
! HEXA_56 : 56-node 3rd order FACE-DEFINED hexahedron
! HEXA_64 : 64-node 3rd order COMPLETE hexahedron
! HEXA_44 : 44-node 4th order EDGE-DEFINED hexahedron
! HEXA_98 : 98-node 4th order FACE-DEFINED hexahedron
! HEXA_125 : 125-node 4th order COMPLETE hexahedron
!
! MIXED : Arbitrary mixture of all possible element types
! except NGON_n or NFACE_n
!
! ################################################################
! ##### NON-COMPATIBLE ELEMENT TYPES, THEREFORE NOT USED #####
! ################################################################
!
! NGON_n : Face elements used for defining arbitrary polyhedral elements
! NFACE_n : Arbitrary polyhedral element defined by collection of
! face elements of NGON_n element type
!
!
! ###########################
! ### Module Parameters ###
! ###########################
!
logical(lk), parameter :: debug_cgns = fals
!logical(lk), parameter :: debug_cgns = true
!
logical(lk), parameter :: create_nozzle_interior_cgns_gridfile = fals
!logical(lk), parameter :: create_nozzle_interior_cgns_gridfile = true
!
! ###################################
! ### Module Derived Data Types ###
! ###################################
!
type :: cg_t
character(len=CGLEN) :: name
end type cg_t
!
type, extends(cg_t) :: cg_sz_t
!character(len=CGLEN) :: name ! INHERITED FROM CG_T
integer(CST) :: nsize
end type cg_sz_t
!
type, extends(cg_t) :: cg_dataarray_t
!character(len=CGLEN) :: name ! INHERITED FROM CG_T
real(wp), allocatable :: data(:)
end type cg_dataarray_t
!
type, extends(cg_t) :: cg_bc_t
!character(len=CGLEN) :: name ! INHERITED FROM CG_T
integer(CET) :: boco_type, ptset_type, normal_datatype, location
integer(CST) :: npnts, normal_list_size
integer(CBT) :: normal_index(3), ndataset
integer(CST), allocatable :: pnts(:)!, faces(:)
real(wp), allocatable :: normal_list(:)
end type cg_bc_t
!
type, extends(cg_t) :: cg_coord_t
!character(len=CGLEN) :: name ! INHERITED FROM CG_T
real(wp), allocatable :: x(:)
end type cg_coord_t
!
type, extends(cg_t) :: cg_grid_t
!character(len=CGLEN) :: name ! INHERITED FROM CG_T
type(cg_coord_t), allocatable :: coord(:)
end type cg_grid_t
!
type, extends(cg_t) :: cg_section_t
!character(len=CGLEN) :: name ! INHERITED FROM CG_T
integer(CET) :: type
integer(CST) :: start, end
integer(CBT) :: nbndry, parent_flag
integer(CST), allocatable :: elements(:), parentdata(:)
!integer(CET), allocatable :: elemtypes(:)
end type cg_section_t
!
type, extends(cg_sz_t) :: cg_zone_t
!character(len=CGLEN) :: name ! INHERITED FROM CG_T
!integer(CST) :: nsize ! INHERITED FROM CG_SZ_T
integer(CST) :: nvertex, ncell, nboundvertex
integer(CET) :: type
integer(CBT) :: index_dim
type(cg_grid_t), allocatable :: grid(:)
type(cg_section_t), allocatable :: section(:)
type(cg_bc_t), allocatable :: bc(:)
end type cg_zone_t
!
type, extends(cg_sz_t) :: cg_base_t
!character(len=CGLEN) :: name ! INHERITED FROM CG_T
!integer(CST) :: nsize ! INHERITED FROM CG_SZ_T
integer(CBT) :: cell_dim, phys_dim
type(cg_zone_t), allocatable :: zone(:)
end type cg_base_t
!
! ################################
! ### Module Local Variables ###
! ################################
!
integer(CBT), save :: if_g ! CGNS file index number
integer(CBT), save :: ib_g ! base index number
integer(CBT), save :: iz_g ! zone index number
integer(CBT), save :: ig_g ! grid index number
integer(CBT), save :: is_g ! element section index number
integer(CBT), save :: ic_g ! coordinate array index number
integer(CBT), save :: ia_g ! data array index number
integer(CBT), save :: ibc_g ! boundary condition index number
!
character(len=150), save :: gridfile
character(len=1000), save :: array_name
!
! Grid dimensions specified by the CGNS grid file
!
integer, save :: npnts_correct ! total # of grid points
integer, save :: ncell_correct ! total # of interior cells
integer, save :: nfbnd_correct ! total # of boundary faces
!
! ##################################
! ### Module Fixed-Size Arrays ###
! ##################################
!
! data_sizes( 1) = base(1)%cell_dim
! data_sizes( 2) = base(1)%phys_dim
! data_sizes( 3) = base(1)%zone(1)%nvertex
! data_sizes( 4) = base(1)%zone(1)%ncell
! data_sizes( 5) = base(1)%zone(1)%nboundvertex
! data_sizes( 6) = total # of grids across all zones
! data_sizes( 7) = size( grid_data )
! data_sizes( 8) = total # of element sections across all zones
! data_sizes( 9) = size( section_data )
! data_sizes(10) = total # of BCs across all zones
! data_sizes(11) = size( boco_data )
!
integer(wip), save :: data_sizes(1:11) = 0
!
! ###################################
! ### Module Allocatable Arrays ###
! ###################################
!
type(cg_base_t), save, allocatable :: base(:)
!
real(wp), save, allocatable :: grid_data(:,:)
integer(wip), save, allocatable :: section_data(:)
integer(wip), save, allocatable :: boco_data(:)
!
type :: cell_grps_t
integer :: cell_dim
integer :: grp_id
integer :: ibc
character(len=CGLEN) :: name
integer, allocatable :: cells(:)
end type cell_grps_t
!
type(cell_grps_t), save, allocatable :: cell_grps(:)
!
! ######################################
! ### Generic Procedure Interfaces ###
! ######################################
!
interface create_element
module procedure create_element_i4, create_element_i8
end interface create_element
!
contains
!
!###############################################################################
!
subroutine read_cgns_gridfile( input_gridfile )
!
!.. Use Statements ..
use ovar, only : itestcase
!
!.. Formal Arguments ..
character(len=*), intent(in) :: input_gridfile
!
!.. Local Scalars ..
integer :: ierr
integer(CBT) :: nbases,grid_precision
!
!.. Local Parameters ..
character(len=*), parameter :: pname = "read_cgns_gridfile"
!
continue
!
call debug_timer(entering_procedure,pname)
!
gridfile = trim(adjustl(input_gridfile))
!
call cgp_mpi_comm_f(mpi_comm_self_val,cgierr)
!call cgns_error(pname,gridfile,"cgp_mpi_comm_f",cgierr,__LINE__,__FILE__)
!
! Open the grid file
!
call cgp_open_f(trim(adjustl(gridfile)),CG_MODE_READ,if_g,cgierr)
if (debug_cgns) write (*,1) mypnum,"opened CGNS grid file"
call cgns_error(pname,gridfile,"cgp_open_f",cgierr, &
__LINE__,__FILE__,"Mode = CG_MODE_READ")
!
! Have only the root processor read in the data from the CGNS grid file
!
if (mypnum == glb_root) then
!
! Get the precision of the grid file
!
call cg_precision_f(if_g,grid_precision,cgierr)
call cgns_error(pname,gridfile,"cg_precision_f",cgierr, &
__LINE__,__FILE__,not_parallel=true)
if (debug_cgns) then
write (iout,1) mypnum, &
"The CGNS grid file was written using a precision of ", &
grid_precision
end if
!
! Read the number of bases
!
call cg_nbases_f(if_g,nbases,cgierr)
call cgns_error(pname,gridfile,"cg_nbases_f",cgierr, &
__LINE__,__FILE__,not_parallel=true)
!
! Allocate the base array
!
allocate ( base(1:nbases) , stat=ierr , errmsg=error_message )
call alloc_error(pname,"base",1,__LINE__,__FILE__,ierr,error_message)
!
do ib_g = 1,size(base)
if (debug_cgns) write (iout,1) mypnum,"reading CGNS base node #",ib_g
call read_cgns_base( base(ib_g) )
end do
!
end if
!
! We are done reading the grid file so close it
!
call cgp_close_f(if_g,cgierr)
if (debug_cgns) write (*,1) mypnum,"closed CGNS grid file"
call cgns_error(pname,gridfile,"cgp_close_f",cgierr,__LINE__,__FILE__)
!
! Reset the MPI communicator for CGNS back to MPI_COMM_WORLD
!
call cgp_mpi_comm_f(mpi_comm_world_val,cgierr)
!call cgns_error(pname,gridfile,"cgp_mpi_comm_f",cgierr,__LINE__,__FILE__)
call mpi_barrier(MPI_COMM_WORLD,mpierr)
!
!
!
if (mypnum == glb_root) then
!
! Check to see if there are any unsupported features in the CGNS grid file
!
call check_for_unsupported_cgns_file
!
! Take the information read from the CGNS grid file and transfer it into
! the grid derived type and cell_grps arrays
!
call transfer_cgns_data_to_grid_dt
!
if (itestcase == Nozzle_Jet) then
if (create_nozzle_interior_cgns_gridfile) then
call extract_nozzle_grid
else
call find_elem_for_initial_jet_profile
end if
end if
!
! Create the arrays needed by the solver that define the grid
! geometry: bface, nodes_of_cell_ptr, nodes_of_cell, etc.
!
call create_solver_geom_arrays_cgns
!
end if
!
! Broadcast the grid derived type to all processors
! but save it on only the root processes of each host
!
call root_broadcasts_grid_dt
!
! It should now be safe to deallocate the base derived-type array.
! We dont need it wasting a bunch of memory since we are about to
! give each MPI process copies of the grid_data, section_data, and
! boco_data arrays.
!
if (allocated(base)) then
deallocate ( base , stat=ierr , errmsg=error_message )
call alloc_error(pname,"base",2,__LINE__,__FILE__,ierr,error_message)
end if
call mpi_barrier(MPI_COMM_WORLD,mpierr)
!
! Broadcast the grid arrays to all processors
!
if (ncpu > 1) then
!call broadcast_grid_arrays
call broadcast_solver_geom_arrays
else
call create_serial_geom_arrays
end if
if (debug_cgns) then
if (mypnum == glb_root) then
write (*,*)
write (*,*) "Leaving read_cgns_gridfile! Press any key to continue"
read (*,*)
end if
end if
call mpi_barrier(MPI_COMM_WORLD,mpierr)
!
call mpi_barrier(MPI_COMM_WORLD,mpierr)
!call stop_gfr(stop_mpi,pname,__LINE__,__FILE__, &
! "TEMPORARY STOP AFTER READING CGNS GRID")
!
! Finish create the arrays defining the grid geometry:
! bface, nodes_of_cell_ptr, nodes_of_cell, etc.
!
!call create_arrays_from_cgns_data
!
call debug_timer(leaving_procedure,pname)
!
! Format Statements
!
1 format (" CPU #",i0,": ",a,:,i0)
!
end subroutine read_cgns_gridfile
!
!###############################################################################
!
subroutine check_for_unsupported_cgns_file
!
!.. Local Scalars ..
integer :: ib,iz,ig,ic,is,n
logical(lk) :: grid_requires_int64
!
!.. Local Parameters ..
character(len=*), parameter :: pname = "check_for_unsupported_cgns_file"
!
continue
!
call debug_timer(entering_procedure,pname)
!
! Check whether 64-bit integers are required for this grid
!
call debug_timer(start_timer,"check_if_grid_requires_int64")
grid_requires_int64 = check_if_grid_requires_int64()
call debug_timer(stop_timer,"check_if_grid_requires_int64")
!
if (grid_requires_int64) then
write (error_message,1)
call stop_gfr(abort,pname,__LINE__,__FILE__,error_message)
end if
!
! FOR NOW: Abort if there is more than one base in the CGNS file
!
if (allocated(base)) then
if (size(base) > 1) then
write (error_message,2)
call stop_gfr(abort,pname,__LINE__,__FILE__,error_message)
end if
else
write (error_message,12)
call stop_gfr(abort,pname,__LINE__,__FILE__,error_message)
end if
!
! FOR NOW: Abort if there is more than one zone in the CGNS file for any base
!
do ib = 1,size(base)
if (allocated(base(ib)%zone)) then
if (size(base(ib)%zone) > 1) then
write (error_message,3)
call stop_gfr(abort,pname,__LINE__,__FILE__,error_message)
end if
else
write (error_message,13)
call stop_gfr(abort,pname,__LINE__,__FILE__,error_message)
end if
end do
!
! Abort if there is a section that contains an
! unsupported element type (NGON_n or NFACE_n)
!
do ib = 1,size(base)
do iz = 1,size(base(ib)%zone)
if (allocated(base(ib)%zone(iz)%section)) then
do is = 1,size(base(ib)%zone(iz)%section)
if (any(base(ib)%zone(iz)%section(is)%type == [NGON_n,NFACE_n])) then
write (error_message,4)
call stop_gfr(abort,pname,__LINE__,__FILE__,error_message)
end if
end do
else
write (error_message,14)
call stop_gfr(abort,pname,__LINE__,__FILE__,error_message)
end if
end do
end do
!
! FOR NOW: Abort if there is more than one set of grid coordinates
! for any zone
!
do ib = 1,size(base)
do iz = 1,size(base(ib)%zone)
if (allocated(base(ib)%zone(iz)%grid)) then
if (size(base(ib)%zone(iz)%grid) > 1) then
write (error_message,5)
call stop_gfr(abort,pname,__LINE__,__FILE__,error_message)
end if
else
write (error_message,15)
call stop_gfr(abort,pname,__LINE__,__FILE__,error_message)
end if
end do
end do
!
! FOR NOW: Abort if the number of coordinate data is inconsistent within
! any of the grids
!
do ib = 1,size(base)
do iz = 1,size(base(ib)%zone)
do ig = 1,size(base(ib)%zone(iz)%grid)
if (allocated(base(ib)%zone(iz)%grid(ig)%coord)) then
n = size(base(ib)%zone(iz)%grid(ig)%coord(1)%x)
do ic = 2,size(base(ib)%zone(iz)%grid(ig)%coord)
if (n /= size(base(ib)%zone(iz)%grid(ig)%coord(ic)%x)) then
write (error_message,6)
call stop_gfr(abort,pname,__LINE__,__FILE__,error_message)
end if
end do
else
write (error_message,16)
call stop_gfr(abort,pname,__LINE__,__FILE__,error_message)
end if
end do
end do
end do
!
call debug_timer(leaving_procedure,pname)
!
! Format Statements
!
1 format (" THE CGNS GRID FILE APPEARS TO REQUIRE 64-BIT INTEGERS", &
" WHICH IS NOT CURRENTLY SUPPORTED IN THE SOLVER!!!")
2 format (" THE CGNS GRID FILE APPEARS TO CONTAIN MORE THAN ONE CGNSBase_t", &
" NODE WHICH IS NOT CURRENTLY SUPPORTED IN THE CGNS GRID READER!!!")
3 format (" THE CGNS GRID FILE APPEARS TO CONTAIN MORE THAN ONE Zone_t", &
" NODE WHICH IS NOT CURRENTLY SUPPORTED IN THE CGNS GRID READER!!!")
4 format (" THE CGNS GRID FILE APPEARS TO CONTAIN AN Elements_t NODE", &
" WITH AN UNSUPPORTED ELEMENT TYPE OF NGON_n or NFACE_n!!")
5 format (" THE CGNS GRID FILE APPEARS TO CONTAIN MORE THAN ONE", &
" GridCoordinates_t NODE WHICH IS NOT CURRENTLY SUPPORTED IN", &
" THE CGNS GRID READER!!!")
6 format (" THE CGNS GRID FILE APPEARS TO CONTAIN AN INCONSISTENCY WITHIN", &
" ONE OF THE GridCoordinates_t NODES!!! THE SIZE OF ALL THE", &
" DataArray_t NODES UNDER A GridCoordinate_t NODE SHOULD ALL", &
" BE THE SAME SIZE!!!")
!
12 format(" THE base DERIVED-TYPE ARRAY USED TO STORE ALL THE DATA READ", &
" IN FROM THE CGNS GRID FILE IS NOT ALLOCATED WHEN IT SHOULD BE!!!")
13 format(" THE zone DERIVED-TYPE ARRAY FOR STORING THE Zone_t NODES UNDER", &
" THE base(",i0,") CGNSBase_t NODE IS NOT ALLOCATED WHEN IT", &
" SHOULD BE!!!")
14 format(" THE section DERIVED-TYPE ARRAY FOR STORING THE Elements_t", &
" NODES UNDER THE base(",i0,")%zone(",i0,") Zone_t NODE IS NOT", &
" ALLOCATED WHEN IT SHOULD BE!!!")
15 format(" THE grid DERIVED-TYPE ARRAY FOR STORING THE GridCoordinates_t", &
" NODES UNDER THE base(",i0,")%zone(",i0,") Zone_t NODE IS NOT", &
" ALLOCATED WHEN IT SHOULD BE!!!")
16 format(" THE coord DERIVED-TYPE ARRAY FOR STORING THE DataArray_t", &
" NODES UNDER THE base(",i0,")%zone(",i0,")%grid(",i0,")", &
" GridCoordinates_t NODE IS NOT ALLOCATED WHEN IT SHOULD BE!!!")
!
end subroutine check_for_unsupported_cgns_file
!
!###############################################################################
!
subroutine read_cgns_base(b)
!
!.. Formal Arguments ..
type(cg_base_t), intent(inout) :: b
!
!.. Local Scalars ..
integer :: ierr
integer(CBT) :: nzones
!
!.. Local Parameters ..
character(len=*), parameter :: pname = "read_cgns_base"
!
continue
!
call debug_timer(entering_procedure,pname)
!
! Read the information for the current base
!
call cg_base_read_f(if_g,ib_g,b%name,b%cell_dim,b%phys_dim,cgierr)
call cgns_error(pname,gridfile,"cg_base_read_f",cgierr, &
__LINE__,__FILE__,not_parallel=true)
!
! Read the number of zones in the current base
!
call cg_nzones_f(if_g,ib_g,nzones,cgierr)
call cgns_error(pname,gridfile,"cg_nzones_f",cgierr, &
__LINE__,__FILE__,not_parallel=true)
!
! Allocate the zones component for the current base
!
allocate ( b%zone(1:nzones) , stat=ierr , errmsg=error_message )
array_name = get_array_name()
call alloc_error(pname,array_name,1,__LINE__,__FILE__,ierr,error_message)
!
! Read each of the zones
!
do iz_g = 1,size(b%zone)
if (debug_cgns) write (iout,1) mypnum,"reading CGNS zone node #",iz_g
call read_cgns_zone( b%zone(iz_g) )
end do
!
call debug_timer(leaving_procedure,pname)
!
! Format Statements
!
1 format (" CPU #",i0,": ",a,:,i0)
!
end subroutine read_cgns_base
!
!###############################################################################
!
subroutine read_cgns_zone(z)
!
!.. Formal Arguments ..
type(cg_zone_t), intent(inout) :: z
!
!.. Local Scalars ..
integer :: ierr
integer(CBT) :: ngrids,nsections,nbocos
!
!.. Local Arrays ..
integer(CST) :: zone_size(3*3)
!
!.. Local Parameters ..
character(len=*), parameter :: pname = "read_cgns_zone"
!
continue
!
call debug_timer(entering_procedure,pname)
!
! Read the information for the current zone
!
call cg_zone_read_f(if_g,ib_g,iz_g,z%name,zone_size,cgierr)
call cgns_error(pname,gridfile,"cg_zone_read_f",cgierr, &
__LINE__,__FILE__,not_parallel=true)
!
z%nvertex = zone_size(1)
z%ncell = zone_size(2)
z%nboundvertex = zone_size(3)
!
call cg_zone_type_f(if_g,ib_g,iz_g,z%type,cgierr)
call cgns_error(pname,gridfile,"cg_zone_type_f",cgierr, &
__LINE__,__FILE__,not_parallel=true)
!
call cg_index_dim_f(if_g,ib_g,iz_g,z%index_dim,cgierr)
call cgns_error(pname,gridfile,"cg_index_dim_f",cgierr, &
__LINE__,__FILE__,not_parallel=true)
!
if (z%type /= UNSTRUCTURED .or. base(ib_g)%zone(iz_g)%index_dim /= 1) then
write (error_message,1) ib_g,iz_g
call stop_gfr(abort,pname,__LINE__,__FILE__,error_message)
end if
!
! Read the number of grids that are in the current zone
!
call cg_ngrids_f(if_g,ib_g,iz_g,ngrids,cgierr)
call cgns_error(pname,gridfile,"cg_ngrids_f",cgierr, &
__LINE__,__FILE__,not_parallel=true)
!
! Allocate the grid component for the current zone
!
allocate ( z%grid(1:ngrids) , stat=ierr , errmsg=error_message )
array_name = get_array_name("grid")
call alloc_error(pname,array_name,1,__LINE__,__FILE__,ierr,error_message)
!
! Read the number of element sections that are in the current zone
!
call cg_nsections_f(if_g,ib_g,iz_g,nsections,cgierr)
call cgns_error(pname,gridfile,"cg_nsections_f",cgierr, &
__LINE__,__FILE__,not_parallel=true)
!
! Allocate the section component for the current zone
!
allocate ( z%section(1:nsections) , stat=ierr , errmsg=error_message )
array_name = get_array_name("section")
call alloc_error(pname,array_name,1,__LINE__,__FILE__,ierr,error_message)
!
! Read the number of boundary conditions that are in the current zone
!
call cg_nbocos_f(if_g,ib_g,iz_g,nbocos,cgierr)
call cgns_error(pname,gridfile,"cg_nbocos_f",cgierr, &
__LINE__,__FILE__,not_parallel=true)
!
! Allocate the bc component for the current zone
!
allocate ( z%bc(1:nbocos) , stat=ierr , errmsg=error_message )
array_name = get_array_name("bc")
call alloc_error(pname,array_name,1,__LINE__,__FILE__,ierr,error_message)
!
! Read the grids for the current zone
!
do ig_g = 1,size(z%grid)
if (debug_cgns) write (iout,2) mypnum,"reading CGNS grid node #",ig_g
call read_cgns_grid( z%grid(ig_g) )
end do
!
! Read the sections for the current zone
!
do is_g = 1,size(z%section)
if (debug_cgns) write (iout,2) mypnum,"reading CGNS section node #",is_g
call read_cgns_section( z%section(is_g) )
end do
!
! Read the sections for the current zone
!
do ibc_g = 1,size(z%bc)
if (debug_cgns) write (iout,2) mypnum,"reading CGNS bc node #",ibc_g
call read_cgns_bc( z%bc(ibc_g) )
end do
!
! Fix the boundary condition lists
!
!call fix_boco_lists(z%nvertex,z%ncell,z%section,z%bc)
!
call debug_timer(leaving_procedure,pname)
!
! Format Statements
!
1 format (" The CGNS grid file seems to contain a structured zone", &
" which are not currently supported! Error occured in", &
" CGNS base # ",i0," , zone # ",i0," !")
2 format (" CPU #",i0,": ",a,:,i0)
!
end subroutine read_cgns_zone
!
!###############################################################################
!
subroutine read_cgns_grid(g)
!
!.. Formal Arguments ..
type(cg_grid_t), intent(inout) :: g
!
!.. Local Scalars ..
integer :: ierr
integer(CBT) :: ncoords,narrays
!
!.. Local Parameters ..
character(len=*), parameter :: pname = "read_cgns_grid"
!
continue
!
call debug_timer(entering_procedure,pname)
!
! Get the name of the current grid
!
call cg_grid_read_f(if_g,ib_g,iz_g,ig_g,g%name,cgierr)
call cgns_error(pname,gridfile,"cg_grid_read_f",cgierr, &
__LINE__,__FILE__,not_parallel=true)
!
if (ig_g == 1) then
!
! This is for the original grid, so we need to use the cg_coord_* functions
!
! Get the number of coordinates
!
call cg_ncoords_f(if_g,ib_g,iz_g,ncoords,cgierr)
call cgns_error(pname,gridfile,"cg_ncoords_f",cgierr, &
__LINE__,__FILE__,not_parallel=true)
!
! Allocate the coord component of the current grid
!
allocate ( g%coord(1:ncoords) , stat=ierr , errmsg=error_message )
array_name = get_array_name("grid",ig_g,"coord")
call alloc_error(pname,array_name,1,__LINE__,__FILE__,ierr,error_message)
!
! Read the coordinate data
!
do ic_g = 1,size(g%coord)
if (debug_cgns) write (iout,1) mypnum,"reading CGNS coord node #",ic_g
call read_cgns_coord( g%coord(ic_g) )
end do
!
else
!
! This is for an additional grid beyond the original
! so we need to use the cg_array_* functions
!
! Because the grid data is stored in a generic DataArray_t, we need to
! manually move to the current GridCoordinates_t node to read the data
!
call cg_goto_f(if_g,ib_g,cgierr, &
"Zone_t",iz_g, &
"GridCoordinates_t",ig_g, &
CGNS_GOTO_END)
call cgns_error(pname,gridfile,"cg_goto_f",cgierr, &
__LINE__,__FILE__,not_parallel=true)
!
! Get the number of coordinate arrays for the current grid
!
call cg_narrays_f(narrays,cgierr)
call cgns_error(pname,gridfile,"cg_narrays_f",cgierr, &
__LINE__,__FILE__,not_parallel=true)
!
! Allocate the coord component of the current grid
!
allocate ( g%coord(1:narrays) , stat=ierr , errmsg=error_message )
array_name = get_array_name("grid",ig_g,"coord")
call alloc_error(pname,array_name,1,__LINE__,__FILE__,ierr,error_message)
!
! Read the coordinate data
!
do ia_g = 1,size(g%coord)
if (debug_cgns) then
write (iout,1) mypnum,"reading CGNS additional coord node #",ia_g
end if
call read_cgns_additional_coord( g%coord(ia_g) )
end do
!
end if
!
call debug_timer(leaving_procedure,pname)
!
! Format Statements
!
1 format (" CPU #",i0,": ",a,:,i0)
!
end subroutine read_cgns_grid
!
!###############################################################################
!
subroutine read_cgns_coord(c)
!
!.. Formal Arguments ..
type(cg_coord_t), intent(inout) :: c
!
!.. Local Scalars ..
integer :: ierr
integer(CST) :: np,ibeg,iend
integer(CET) :: stored_datatype
integer(CET) :: read_datatype
!
!.. Local Parameters ..
character(len=*), parameter :: pname = "read_cgns_coord"
!
continue
!
call debug_timer(entering_procedure,pname)
!
read_datatype = merge(REALDOUBLE,REALSINGLE,wp==r8)
!
! Read the coordinate info
!
call cg_coord_info_f(if_g,ib_g,iz_g,ic_g,stored_datatype,c%name,cgierr)
call cgns_error(pname,gridfile,"cg_coord_info_f",cgierr, &
__LINE__,__FILE__,not_parallel=true)
!
! Allocate the data array to the total number of nodes in the grid
!
np = base(ib_g)%zone(iz_g)%nvertex
!
allocate ( c%x(1:np) , source=zero , stat=ierr , errmsg=error_message )
array_name = get_array_name("grid",ig_g,"coord",ic_g,"x")
call alloc_error(pname,array_name,1,__LINE__,__FILE__,ierr,error_message)
!
! Read in the coordinate data
!
ibeg = 1_CST
iend = np
!
call cg_coord_read_f(if_g,ib_g,iz_g,trim(adjustl(c%name)),read_datatype, &
ibeg,iend,c%x,cgierr)
call cgns_error(pname,gridfile,"cg_coord_read_f",cgierr, &
__LINE__,__FILE__,not_parallel=true)
!
call debug_timer(leaving_procedure,pname)
!
end subroutine read_cgns_coord
!
!###############################################################################
!
subroutine read_cgns_additional_coord(c)
!
!.. Formal Arguments ..
type(cg_coord_t), intent(inout) :: c
!
!.. Local Scalars ..
integer :: ierr
integer(CST) :: np,ibeg,iend
integer(CBT) :: data_dimension
integer(CET) :: stored_datatype
integer(CET) :: read_datatype
!
!.. Local Arrays ..
integer(CST) :: dimension_vector(1:12) ! NOTE: 12 is the maximum number of
! data dimensions for a
! DataArray_t node defined by the
! CGNS standard
!
!.. Local Parameters ..
character(len=*), parameter :: pname = "read_cgns_additional_coord"
!
continue
!
call debug_timer(entering_procedure,pname)
!
read_datatype = merge(REALDOUBLE,REALSINGLE,wp==r8)
!
! Read the coordinate info
!
call cg_array_info_f(ia_g,c%name,stored_datatype,data_dimension, &
dimension_vector,cgierr)
call cgns_error(pname,gridfile,"cg_array_info_f",cgierr, &
__LINE__,__FILE__,not_parallel=true)
!
! Allocate the data array to the total number of nodes in the grid
!
np = product( dimension_vector(1:data_dimension) )
!
allocate ( c%x(1:np) , source=zero , stat=ierr , errmsg=error_message )
array_name = get_array_name("grid",ig_g,"coord",ia_g,"x")
call alloc_error(pname,array_name,1,__LINE__,__FILE__,ierr,error_message)
!
! Read in the coordinate data
!
call cg_array_read_as_f(ia_g,read_datatype,c%x,cgierr)
call cgns_error(pname,gridfile,"cg_array_read_as_f",cgierr, &
__LINE__,__FILE__,not_parallel=true)
!
call debug_timer(leaving_procedure,pname)
!
end subroutine read_cgns_additional_coord
!
!###############################################################################
!
subroutine read_cgns_section(s)
!
!.. Use Statements ..
use iso_c_binding, only : c_null_ptr
!
!.. Formal Arguments ..
type(cg_section_t), intent(inout) :: s
!
!.. Local Scalars ..
integer :: ierr
integer(CST) :: np,nelem,element_data_size
!
!.. Local Parameters ..
character(len=*), parameter :: pname = "read_cgns_section"
!
!logical(lk), parameter :: read_parent_data = true
logical(lk), parameter :: read_parent_data = fals
!
continue
!
call debug_timer(entering_procedure,pname)
!
! Read the info for this element section
!
call cg_section_read_f(if_g,ib_g,iz_g,is_g,s%name,s%type,s%start,s%end, &
s%nbndry,s%parent_flag,cgierr)
call cgns_error(pname,gridfile,"cg_section_read_f",cgierr, &
__LINE__,__FILE__,not_parallel=true)
!
! Get the size of the element data
!
call cg_elementdatasize_f(if_g,ib_g,iz_g,is_g,element_data_size,cgierr)
call cgns_error(pname,gridfile,"cg_elementdatasize_f",cgierr, &
__LINE__,__FILE__,not_parallel=true)
!
np = element_data_size
!
allocate ( s%elements(1:np) , stat=ierr , errmsg=error_message )
array_name = get_array_name("section",is_g,"elements")
call alloc_error(pname,array_name,1,__LINE__,__FILE__,ierr,error_message)
!
if (s%parent_flag == 1_CBT .and. read_parent_data) then
!
nelem = s%end - s%start + 1_CST
np = nelem*4_CST
!
allocate ( s%parentdata(1:np) , stat=ierr , errmsg=error_message )
array_name = get_array_name("section",is_g,"parentdata")
call alloc_error(pname,array_name,1,__LINE__,__FILE__,ierr,error_message)
!
call cg_elements_read_f(if_g,ib_g,iz_g,is_g,s%elements,s%parentdata,cgierr)
call cgns_error(pname,gridfile,"cg_elements_read_f",cgierr, &
__LINE__,__FILE__,not_parallel=true)
!
else
!
call cg_elements_read_f(if_g,ib_g,iz_g,is_g,s%elements,c_null_ptr,cgierr)