-
Notifications
You must be signed in to change notification settings - Fork 38
/
plot3d_mod.f90
6145 lines (6145 loc) · 192 KB
/
plot3d_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_plot3d
!
#ifdef DEBUG_ON
!!!#define DEBUG_CUTS
#endif
!
!.. Use Statements ..
use module_kind_types
use ovar, only : output_plot3d_to_tecplot
!
implicit none
!
private
!
! ##################################
! ### Module Public Procedures ###
! ##################################
!
! Public Interface for plot3d_element_properties function
!
interface plot3d_element_properties
module procedure element_properties
end interface plot3d_element_properties
!
public :: read_plot3d_gridfile
public :: plot3d_memory_usage
public :: plot3d_element_properties
!
! ###########################
! ### Module Parameters ###
! ###########################
!
character(len=*), parameter :: bcs_default = "bcs.p3d"
character(len=*), parameter :: cut_default = "cut.p3d"
!
character(len=*), parameter :: &
errstr = " ###################### ERROR! ######################"
!
! ################################
! ### Module Local Variables ###
! ################################
!
logical(lk), save :: is_multiblock
logical(lk), save :: is_formatted
logical(lk), save :: is_dbl_precision
logical(lk), save :: blk_header_is_dbl_precision
logical(lk), save :: is_big_endian
!
integer, save :: nblk
integer, save :: nbc
integer, save :: ncut
!
logical(lk), save :: plot3d_has_periodic_faces = fals
!
character(len=150), save :: grid_folder
!
! ###################################
! ### Module Allocatable Arrays ###
! ###################################
!
! Arrays whose size is dependent on the number of blocks, nblk
integer, save, allocatable, dimension(:,:) :: offset
integer, save, allocatable, dimension(:,:) :: ijkpts
!
! Arrays whose size is dependent on the number of boundary conditions
!
type condition
integer :: block
integer :: dir ! 1=i,2=j,3=k
integer :: dir1
integer :: dir2
integer :: loc ! 1=imin,2=imax,3=jmin,4=jmax,5=kmin,6=kmax
integer, dimension(1:3) :: begpt
integer, dimension(1:3) :: endpt
end type condition
!
type boundary_condition
integer :: bc_type
integer :: nfaces
type(condition) :: bc
end type boundary_condition
!
type cut_pair
character(len=20), dimension(1:2) :: cut_name
type(condition), dimension(1:2) :: side
integer :: points
integer, allocatable, dimension(:,:) :: nodes
end type cut_pair
!
type(boundary_condition), save, allocatable, dimension(:) :: bcs_info
type(cut_pair), save, allocatable, dimension(:) :: cut_info
!
interface map1dto3d
module procedure map1dto3d_known_block,map1dto3d_unknown_block
end interface map1dto3d
!
contains
!
!###############################################################################
!
subroutine read_plot3d_gridfile ( gridfile , cutfile , bcsfile )
!
!.. Use Statements ..
use geovar, only : grid
!
! This routine reads in a multi-block grid in plot3d
! format and converts it to an unstructured grid.
!
! GRIDFILE : Gives the name of the Plot3D grid file to use
! BCSFILE : Gives the name of the file that specifies the boundary
! conditions for block boundaries
! CUTFILE : Gives the name of the file that specifies the cut conditions
! for a multiblock Plot3D file
! NOTE: Single block format means the first line of the grid file does not
! give the number of blocks and immediately gives the dimensions of
! the one and only block.
! Multi block format means the first line of the grid file does give
! the number of blocks. The second line (and however many more lines
! it takes) gives the dimensions of each block.
! HOWEVER, a single block grid can be written in a multi block format,
! this just means the first line would contain only the value "1".
!
! NOTE: In order for this Plot3D grid to be used by the FR unstructured
! solver, this subroutine and the helper subroutines that it calls need
! to define the following arrays/variables in the module geovar_mod:
! NR : Number of grid dimensions
! NNODE : Total number of grid nodes
! NCELL : Total number of grid cells
! NFBND : Total number of boundary edges/faces
! XYZ_NODES : Cartesian coordinates of all the grid nodes
! BFACE : Boundary information for each boundary edge/face
! NODES_OF_CELL_PTR : Pointer array for array nodes of cells
! NODES_OF_CELL : Gives the nodes that define each grid cell
!
!.. Formal Arguments ..
character(len=*), intent(in) :: gridfile
character(len=*), intent(inout) :: cutfile
character(len=*), intent(inout) :: bcsfile
!
!.. Local Scalars ..
integer :: ierr,itest
integer :: iotst
!
!.. Local Parameters ..
character(len=*), parameter :: pname = "read_plot3d_gridfile"
!
continue
!
call debug_timer(entering_procedure,pname)
!
! Have only the host roots read in the grid file
!
if (i_am_host_root) then
!
! First, allocate the grid derived type so that it can be filled
! up as needed while processing the Plot3D grid file
!
if (allocated(grid)) then
deallocate ( grid , stat=ierr , errmsg=error_message )
call alloc_error(pname,"grid",2,__LINE__,__FILE__,ierr,error_message)
end if
!
allocate ( grid , stat=ierr , errmsg=error_message )
call alloc_error(pname,"grid",1,__LINE__,__FILE__,ierr,error_message)
!
! Default the Plot3D grid file to unformatted
!
is_formatted = fals
!
! Reading a multi-block grid in Plot3d format
!
! Check to see if the Plot3D grid file can be
! opened and read as a formatted file.
!
open (newunit=iotst,file=gridfile,form="formatted",status="old", &
action="read",position="rewind",iostat=ierr, &
iomsg=error_message)
call io_error(pname,trim(adjustl(gridfile)),1,__LINE__,__FILE__, &
ierr,error_message)
!
! Try to read the grid file as a formatted file.
! Mark the grid file as formated if this succeeds.
!
read (iotst,*,iostat=ierr) itest
if (ierr == 0) then
is_formatted = true
end if
!
close (iotst,iostat=ierr,iomsg=error_message)
call io_error(pname,trim(adjustl(gridfile)),2,__LINE__,__FILE__, &
ierr,error_message)
!
! If the Plot3D grid file could not be read as a formatted file,
! check to see if it can be opened and read as an unformatted file.
!
if (.not.is_formatted) then
!
open (newunit=iotst,file=gridfile,form="unformatted",status="old", &
action="read",position="rewind",iostat=ierr, &
iomsg=error_message)
call io_error(pname,trim(adjustl(gridfile)),1,__LINE__,__FILE__, &
ierr,error_message)
!
! Try to read the grid file as an unformatted file. If this fails,
! something is wrong so throw an error and stop execution.
!
read (iotst,iostat=ierr,iomsg=error_message) itest
if (ierr == 0) then
is_formatted = fals
else
call io_error(pname,trim(adjustl(gridfile)),4,__LINE__,__FILE__, &
ierr,error_message)
end if
!
close (iotst,iostat=ierr,iomsg=error_message)
call io_error(pname,trim(adjustl(gridfile)),2,__LINE__,__FILE__, &
ierr,error_message)
!
end if
!
! Now read the Plot3D grid file in what ever format was determined
!
call readplot3d(gridfile)
!
! Reading the boundary condition information
!
call readbcsinfo(bcsfile)
!
! Create grid cells from the plot3d nodes
!
call create_plot3d_grid_cells
!
! If this is a multiblock grid, we need to do some additional
! work to deal with cut boundaries between blocks
!
if (nblk > 1) then
!
! Read cut information if this is a multiblock grid
!
call readcutinfo(cutfile)
!
! Find the points in the cuts
!
call findcutpoints
!
else
!
ncut = 0
!
end if
!
! Go through the cut boundaries and remove all duplicate nodes.
! This shouldnt do anything if there are no cut boundaries.
!
call remove_duplicate_nodes
!
! Reorder the grid points so that the corners of all the grid cells
! are first followed by any high-order cell points existing due
! to cell agglomeration.
!
call reorder_plot3d_nodes
!
! Get the boundary face information
!
call getbface
!
! Match the periodic boundaries if they exist
!
if (plot3d_has_periodic_faces) then
call match_plot3d_periodic_boundaries
end if
!
end if
!
! Write the output file for tecplot
!
if (output_plot3d_to_tecplot) then
if (mypnum == glb_root) call writetecplot
end if
!
!if (mypnum == glb_root) then
! call create_grid_dt
!end if
!!
!call root_broadcasts_grid_dt
!
if (ncpu > 1) then
call broadcast_solver_geom_arrays
else
call create_serial_geom_arrays
end if
!
! Deallocate all module arrays before we leave
! since we wont be needing them anymore.
!
if (allocated(bcs_info)) then
deallocate ( bcs_info , stat=ierr , errmsg=error_message )
call alloc_error(pname,"bcs_info",2,__LINE__,__FILE__,ierr,error_message)
end if
!
if (allocated(cut_info)) then
deallocate ( cut_info , stat=ierr , errmsg=error_message )
call alloc_error(pname,"cut_info",2,__LINE__,__FILE__,ierr,error_message)
end if
!
if (allocated(ijkpts)) then
deallocate ( ijkpts , stat=ierr , errmsg=error_message )
call alloc_error(pname,"ijkpts",2,__LINE__,__FILE__,ierr,error_message)
end if
!
if (allocated(offset)) then
deallocate ( offset , stat=ierr , errmsg=error_message )
call alloc_error(pname,"offset",2,__LINE__,__FILE__,ierr,error_message)
end if
!
call debug_timer(leaving_procedure,pname)
!
end subroutine read_plot3d_gridfile
!
!###############################################################################
!
subroutine readplot3d(gridfile)
!
! This sub reads a multi-block grid in Plot3d format
!
! ijkpts(1,iblk) : number of points in the x-direction for iblk
! ijkpts(2,iblk) : number of points in the y-direction for iblk
! ijkpts(3,iblk) : number of points in the z-direction for iblk
!
!.. Use Statements ..
use geovar, only : nr,xyz_nodes
use geovar, only : grid
use geovar, only : ncell,nnode
use ovar, only : plot3d_agglomerate_order
use ovar, only : plot3d_all_strides
use ovar, only : plot3d_i_stride
use ovar, only : plot3d_j_stride
use ovar, only : plot3d_k_stride
use ovar, only : grid_scaling_factor
!
!.. Formal Arguments ..
character(len=*), intent(in) :: gridfile
!
!.. Local Scalars ..
integer :: i,j,k,l,n,iblk,ierr,cpos,recl_max
integer :: noff,npts,nnode_new,ncell_new
integer :: ibeg,iend,jbeg,jend,kbeg,kend
integer :: iogrd,tempval
character(len=100) :: read_message
!
!.. Local Arrays ..
integer, dimension(1:3) :: strides
!
!.. Local Allocatable Arrays ..
real(r4), allocatable, dimension(:,:) :: r4_nodes
real(wp), allocatable, dimension(:,:) :: temp_xyz
!
!.. Local Parameters ..
character(len=*), parameter :: pname = "readplot3d"
!
continue
!
call debug_timer(entering_procedure,pname)
!
! Set all the coarsening strides to -1 to prevent coarsening
! if agglomerating cells to create high-order curved cells.
!
if (plot3d_agglomerate_order > 0) then
plot3d_all_strides = -1
plot3d_i_stride = -1
plot3d_j_stride = -1
plot3d_k_stride = -1
end if
!
strides(:) = max(1,plot3d_all_strides)
!
if (plot3d_i_stride > 0) strides(1) = plot3d_i_stride
if (plot3d_j_stride > 0) strides(2) = plot3d_j_stride
if (plot3d_k_stride > 0) strides(3) = plot3d_k_stride
!
! Before we start, extract the name of the
! folder that the grid file resides within
!
cpos = scan( gridfile(1:len_trim(gridfile)), '/' , back=true )
grid_folder = gridfile(1:cpos)
grid_folder = trim(adjustl(grid_folder))
!
! Open the file for multi-block grid
!
if (is_formatted) then
open (newunit=iogrd,file=gridfile,form="formatted",status="old", &
action="read",position="rewind",iostat=ierr, &
iomsg=error_message)
else
open (newunit=iogrd,file=gridfile,form="unformatted",status="old", &
action="read",position="rewind",iostat=ierr, &
iomsg=error_message)
end if
call io_error(pname,trim(adjustl(gridfile)),1,__LINE__,__FILE__, &
ierr,error_message)
!
! If this is a multiblock file, read in the number of blocks
!
if (is_formatted) then
call read_p3d_formatted_header(iogrd,gridfile)
else
call read_p3d_unformatted_header(iogrd,gridfile)
end if
!
! Check that the requested plot3d node stride is acceptable
!
l = 0
do iblk = 1,nblk
do i = 1,nr
if (mod(ijkpts(i,iblk)-1,strides(i)) /= 0) then
if (mypnum == glb_root) then
if (l == 0) write (iout,4)
write (iout,5) iblk,i
end if
l = 1
end if
end do
end do
!
! If an error was found with the strides, only have the global root
! call stop_gfr with an abort flag. We cant use the stop_mpi flag
! here because only the host roots will call this routine, and the
! stop_mpi flag requires all processes to call stop_gfr together,
! which would result in the program hanging within stop_gfr. We
! only want the global root to call it with abort, to make sure that
! the error statements in the above loop are written to iout. If some
! other host root calls stop_gfr with the abort flag, there isnt a
! guarantee that those error statements will be written before the
! call to mpi_abort.
!
if (l == 1) then
if (mypnum == glb_root) then
call stop_gfr(abort,pname,__LINE__,__FILE__)
end if
! Have all the host roots call mpi_barrier here so that the MPI processes
! that arent the global root do not continue past this point before the
! global root has a chance to call mpi_abort within the above conditional.
call mpi_barrier(host_roots_comm,mpierr)
end if
!
! Allocate the node and cell offset array
!
allocate ( offset(1:2,1:nblk) , source=0 , &
stat=ierr , errmsg=error_message )
call alloc_error(pname,"offset",1,__LINE__,__FILE__,ierr,error_message)
!
! Create the offset arrays for each block
!
offset(1,1) = 1 ! node offset
offset(2,1) = 1 ! cell offset
!
do iblk = 2,nblk
!
offset(1,iblk) = offset(1,iblk-1) + product( ijkpts(1:nr,iblk-1) )
offset(2,iblk) = offset(2,iblk-1) + product( ijkpts(1:nr,iblk-1)-1 )
!
end do
!
! Get the total number of nodes and cells
!
nnode = sum( product( ijkpts(1:nr,1:nblk) , dim=1 ) )
ncell = sum( product( ijkpts(1:nr,1:nblk)-1 , dim=1 ) )
!
! Allocate the node coordinate array
!
allocate ( xyz_nodes(1:nr,1:nnode) , source=zero , &
stat=ierr , errmsg=error_message )
call alloc_error(pname,"xyz_nodes",1,__LINE__,__FILE__,ierr,error_message)
!
! Read in the node coordinates
!
if (is_formatted) then
!
! If the grid is formatted, this is straight
! forward so read in the node coordinates
!
do iblk = 1,nblk
write (read_message,10) iblk
call debug_timer(start_timer,read_message)
noff = offset(1,iblk)-1
npts = product(ijkpts(1:nr,iblk))
read (iogrd,*) ((xyz_nodes(l,i+noff), i=1,npts), l=1,nr)
call debug_timer(stop_timer,read_message)
end do
!
else
!
! If the grid is unformatted, we dont know if the grid is in
! single or double precision so we have to be careful about
! reading in the node coordinates.
!
! In an unformatted Plot3D grid file, a separate record exists for
! the node coordinates of each block. Assume the grid file is in
! double precision and try reading in the node coordinates for the
! first block.
!
write (read_message,11) 1
call debug_timer(start_timer,read_message)
noff = offset(1,1)-1
npts = product(ijkpts(1:nr,1))
read (iogrd,iostat=ierr,iomsg=error_message) &
((xyz_nodes(l,i+noff), i=1,npts), l=1,nr)
call debug_timer(stop_timer,read_message)
!
if (ierr /= 0) then
!
write (iout,20) ierr,adjustl(trim(error_message))
!
! If there was an error reading the coordinates in double precision,
! backspace and try to read the grid file in single precision,
! aborting if there is an error for single precision.
!
! Allocate the single precision coordinate array
!
allocate ( r4_nodes(1:nr,1:nnode) , source=0.0_r4 , &
stat=ierr , errmsg=error_message )
call alloc_error(pname,"r4_nodes",1,__LINE__,__FILE__,ierr,error_message)
!
!backspace (iogrd,iostat=ierr,iomsg=error_message)
!if (ierr /= 0) then
! write (iout,22) ierr,adjustl(trim(error_message))
!end if
rewind (iogrd,iostat=ierr,iomsg=error_message)
if (ierr /= 0) then
write (iout,21) ierr,adjustl(trim(error_message))
end if
read (iogrd) tempval
read (iogrd) ((tempval,l=1,nr),i=1,nblk)
!
!do iblk = 1,nblk
! write (iout,'(*(2x,i0))') (ijkpts(l,iblk),l=1,nr)
!end do
do iblk = 1,nblk
write (read_message,12) iblk
call debug_timer(start_timer,read_message)
noff = offset(1,iblk)-1
npts = product(ijkpts(1:nr,iblk))
read (iogrd,iostat=ierr,iomsg=error_message) &
((r4_nodes(l,i+noff), i=1,npts), l=1,nr)
!do i = 1,npts
! write (110,'(*(es20.10))') (r4_nodes(l,i+noff),l=1,nr)
!end do
call io_error(pname,gridfile,-1,__LINE__,__FILE__,ierr,error_message)
call debug_timer(stop_timer,read_message)
end do
!
is_dbl_precision = fals
!
! If the single precision coordinates were successfully read,
! covert them to working precision
!
xyz_nodes(1:nr,1:nnode) = real( r4_nodes(1:nr,1:nnode) , kind=wp )
!
! Finish by deallocate the single precision array
!
deallocate ( r4_nodes , stat=ierr , errmsg=error_message )
call alloc_error(pname,"r4_nodes",2,__LINE__,__FILE__,ierr,error_message)
!
else
!
! If there was no error reading the coordinates for the first
! block in double precision, continue reading the remaining blocks.
!
do iblk = 2,nblk
write (read_message,11) iblk
call debug_timer(start_timer,read_message)
noff = offset(1,iblk)-1
npts = product(ijkpts(1:nr,iblk))
read (iogrd,iostat=ierr,iomsg=error_message) &
((xyz_nodes(l,i+noff), i=1,npts), l=1,nr)
call io_error(pname,gridfile,-1,__LINE__,__FILE__,ierr,error_message)
call debug_timer(stop_timer,read_message)
end do
!
is_dbl_precision = true
!
end if
!
end if
!
! Close the Plot3D grid file since we are finished reading it
!
close (iogrd,iostat=ierr,iomsg=error_message)
call io_error(pname,trim(adjustl(gridfile)),2,__LINE__,__FILE__, &
ierr,error_message)
!
if (mypnum == glb_root) then
!
write (iout,*)
write (iout,1) " Finish reading the Plot3D file"
write (iout,2) " nblk = ", nblk
write (iout,2) " ncell = ", ncell
write (iout,2) " nnode = ", nnode
!
write (iout,2) " Number of blocks = ",nblk
do iblk = 1,nblk
write (iout,3) iblk,(ijkpts(l,iblk),l=1,3)
end do
if (is_multiblock) then
write (iout,*) "This is a multi block grid"
else
write (iout,*) "This is a single block grid"
end if
if (is_formatted) then
write (iout,*) "This is a formatted grid"
else
if (is_dbl_precision) then
write (iout,*) "This is an unformatted grid in double precision"
else
write (iout,*) "This is an unformatted grid in single precision"
end if
!if (is_big_endian) then
! write (iout,*) "The unformatted grid file is in big endian format"
!else
! write (iout,*) "The unformatted grid file is in little endian format"
!end if
end if
write (iout,*)
!
end if
!
! Apply the grid scaling factor to the coordinates of the grid nodes
!
do n = 1,size(xyz_nodes,dim=2)
do i = 1,size(xyz_nodes,dim=1)
xyz_nodes(i,n) = grid_scaling_factor*xyz_nodes(i,n)
end do
end do
!
! Coarsen the grid nodes if any of the coarsening strides are larger than 1
!
if (any(strides > 1)) then
!
nnode_new = 0
do iblk = 1,size(ijkpts,dim=2)
npts = 1
do l = 1,size(ijkpts,dim=1)
npts = npts * ( (ijkpts(l,iblk)-1)/strides(l) + 1 )
end do
nnode_new = nnode_new + npts
end do
!
allocate ( temp_xyz(1:nr,1:nnode_new) , source=zero , &
stat=ierr , errmsg=error_message )
call alloc_error(pname,"temp_xyz",1,__LINE__,__FILE__,ierr,error_message)
!
n = 0
!
do iblk = 1,size(ijkpts,dim=2)
!
noff = offset(1,iblk)-1
!
ibeg = 1
jbeg = 1
kbeg = 1
!
iend = max( ibeg , ijkpts(1,iblk) )
jend = max( jbeg , ijkpts(2,iblk) )
kend = max( kbeg , ijkpts(3,iblk) )
!
do k = kbeg,kend,strides(3)
do j = jbeg,jend,strides(2)
do i = ibeg,iend,strides(1)
!
l = map3dto1d( [i,j,k] , iblk , 1 )
n = n + 1
!
temp_xyz(1:nr,n) = xyz_nodes(1:nr,l+noff)
!
end do
end do
end do
!
end do
!
npts = n
!
do iblk = 1,size(ijkpts,dim=2)
do l = 1,size(ijkpts,dim=1)
ijkpts(l,iblk) = (ijkpts(l,iblk)-1) / strides(l) + 1
end do
end do
!
nnode_new = sum( product( ijkpts(1:nr,1:nblk) , dim=1 ) )
ncell_new = sum( product( ijkpts(1:nr,1:nblk)-1 , dim=1 ) )
!
if (npts /= nnode_new) then
if (mypnum == glb_root) then
write (iout,*) " ERROR WITH NEW NUMBER OF NODES"
write (iout,*) " npts = ",npts
write (iout,*) " nnode_new = ",nnode_new
call stop_gfr(abort,pname,__LINE__,__FILE__)
end if
! Have all the host roots call mpi_barrier here so that the MPI processes
! that arent the global root do not continue past this point before the
! global root has a chance to call mpi_abort within the above conditional.
call mpi_barrier(host_roots_comm,mpierr)
end if
!
offset(1,1) = 1 ! node offset
offset(2,1) = 1 ! cell offset
!
do iblk = 2,nblk
!
offset(1,iblk) = offset(1,iblk-1) + product( ijkpts(1:nr,iblk-1) )
offset(2,iblk) = offset(2,iblk-1) + product( ijkpts(1:nr,iblk-1)-1 )
!
end do
!
if (mypnum == glb_root) then
!
write (iout,*)
write (iout,1) " AFTER COARSENING USING STRIDES OF"
write (iout,2) " Stride in I-direction = ",strides(1)
write (iout,2) " Stride in J-direction = ",strides(2)
write (iout,2) " Stride in K-direction = ",strides(3)
write (iout,*)
write (iout,2) " nblk = ", nblk
write (iout,2) " ncell = ", ncell
write (iout,2) " nnode = ", nnode
!
write (iout,2) " Number of blocks = ",nblk
do iblk = 1,nblk
write (iout,3) iblk,(ijkpts(l,iblk),l=1,3)
end do
!
end if
!
call move_alloc( from=temp_xyz , to=xyz_nodes )
!
nnode = nnode_new
ncell = ncell_new
!
end if
!
!call stop_gfr(stop_mpi,pname,__LINE__,__FILE__, &
! "multiblock testing in readplot3d")
!
call debug_timer(leaving_procedure,pname)
!
! Format Statements
!
1 format (a)
2 format (a,i0)
3 format (" Block #",i0," dimensions: ",i0,2(" x ",i0))
4 format (/," ERROR TRYING TO USE COARSENING STRIDES WITH PLOT3D!!!",/, &
" THE NUMBER OF GRID CELLS MUST BE EVENLY",/, &
" DIVISIBLE BY THE COARSENING STRIDES!!!",/)
5 format (3x,"Cells not evenly divisible in block ",i0," for direction ",i0)
!
10 format ("Reading formatted coordinates for block # ",i0)
11 format ("Reading 64-bit unformatted coordinates for block # ",i0)
12 format ("Reading 32-bit unformatted coordinates for block # ",i0)
!
20 format (/,1x,"read(xyz_nodes[64-bit]) iostat = ",i0,/, &
1x,"read(xyz_nodes[64-bit]) iomsg = ",a,/)
21 format (/,1x,"rewind(xyz_nodes[32-bit]) iostat = ",i0,/, &
1x,"rewind(xyz_nodes[32-bit]) iomsg = ",a,/)
22 format (/,1x,"backspace(xyz_nodes[32-bit]) iostat = ",i0,/, &
1x,"backspace(xyz_nodes[32-bit]) iomsg = ",a,/)
!
end subroutine readplot3d
!
!###############################################################################
!
subroutine read_p3d_formatted_header(iogrd,gridfile)
!
!.. Use Statements ..
use geovar, only : nr
!
!.. Formal Arguments ..
integer, intent(in) :: iogrd
character(len=*), intent(in) :: gridfile
!
!.. Local Scalars ..
integer :: ierr,num_val,n,l,lines
character(len=100) :: text
!
!.. Local Allocatable Arrays ..
character(len=50), allocatable, dimension(:) :: clist
!
!.. Local Parameters ..
character(len=*), parameter :: pname = "read_p3d_formatted_header"
!
continue
!
call debug_timer(entering_procedure,pname)
!
! Read the first line as text to see how many values it contains
!
read (iogrd,1,iostat=ierr,iomsg=error_message) text
call io_error(pname,gridfile,-1,__LINE__,__FILE__,ierr,error_message)
!
! Parse text to see how many values are contained on the first line
!
call parse_list(text,clist)
!
num_val = size(clist)
!
! If the number of values on the first line is one, this
! is probably a multiblock grid. If it is greater than one,
! this is probably a single block grid file.
!
if (num_val > 1) then
!
! This is probably a single block grid file. If this is a single
! block grid, num_val should be equal to the number of grid dimensions.
! Make sure the size of the third dimension is greater than one
! before declaring this a 3D grid.
!
nblk = 1
!
! Allocate ijkpts, and initialize to 1 node in each direction
!
allocate ( ijkpts(1:3,1:nblk) , source=1 , &
stat=ierr , errmsg=error_message )
call alloc_error(pname,"ijkpts (SB)",1,__LINE__,__FILE__,ierr,error_message)
!
! Make sure that num_val is equal to either 2 or 3
!
if (all(num_val /= [2,3])) goto 100 ! go to 100 error statement
!
! Read the values in clist if num_val is equal to either 2 or 3
!
do l = 1,num_val
read (clist(l),*,iostat=ierr,iomsg=error_message) ijkpts(l,1)
call io_error(pname,"clist(l)",-1,__LINE__,__FILE__,ierr,error_message)
end do
!
! If we have reached this point, it probably safe
! to say this is a single block grid file
!
is_multiblock = fals
!
else if (num_val == 1) then
!
! This is probably a multi block grid
!
read (clist(1),*,iostat=ierr,iomsg=error_message) nblk
call io_error(pname,"clist(1)",-1,__LINE__,__FILE__,ierr,error_message)
!
! Make sure that nblk is a valid number of blocks
!
if (nblk <= 0) goto 101 ! go to 101 error statement
!
! Allocate ijkpts, and initialize to 1 node in each direction
!
allocate ( ijkpts(1:3,1:nblk) , source=1 , &
stat=ierr , errmsg=error_message )
call alloc_error(pname,"ijkpts (MB)",1,__LINE__,__FILE__,ierr,error_message)
!
! We need to get the dimensions of each block but we dont know
! if this is a 3D or 2D grid. Therefore, we must continue reading
! lines until we find a line that does not contain integer values.
! To do this, we have to:
! 1. Read each line as a character string.
! 2. Parse this string to separate the individual values contained
! within the string into substrings.
! 3. Test each substring to determine if it is a valid integer value.
! 4. Once a non-integer value is found, this means we have reached the
! node coordinate section and everything before this was the block
! dimensions.
! NOTE: We have to do this because Fortran will not produce an error
! if a floating point value is read as an integer, and
! automatically converts the float to an integer.
!
l = 0
blk_dims: do
read (iogrd,1,iostat=ierr,iomsg=error_message) text
call io_error(pname,gridfile,-1,__LINE__,__FILE__,ierr,error_message)
call parse_list(text,clist)
num_val = size(clist)
do n = 1,num_val
if (string_is_integer(clist(n))) then
l = l + 1
else
exit blk_dims
end if
end do
end do blk_dims
!
if (mod(l,nblk) /= 0) then
goto 102 ! go to 102 error statement
else
nr = l/nblk
if (all(nr /= [2,3])) goto 100 ! go to 100 error statement
end if
!
! We have to rewind the grid file so that we
! can actually read in the block dimensions
!
rewind (iogrd)
!
! Skip the first line containing the number of blocks
!
read (iogrd,1,iostat=ierr,iomsg=error_message) text
call io_error(pname,gridfile,-1,__LINE__,__FILE__,ierr,error_message)
!
! Now read in the block dimensions
!
read (iogrd,*,iostat=ierr,iomsg=error_message) &
((ijkpts(l,n), l=1,nr), n=1,nblk)
call io_error(pname,gridfile,-1,__LINE__,__FILE__,ierr,error_message)
!
! If we have reached this point, it probably safe
! to say this is a single block grid file
!
is_multiblock = true
!
else
!
! There was an unknown error reading the header of the Plot3D grid file
!
goto 103 ! go to 103 error statement
!
end if
!
! Reading the header seemed to be successful. Make sure
! that all the block dimensions are valid values.
!
!if (mypnum == glb_root) then
! do n = 1,nblk
! write (iout,7) n,(ijkpts(l,n),l=1,3)
! end do
!end if
if (any(ijkpts(:,:) < 1)) goto 104 ! go to 104 error statement
!
! If all the third dimensions are 1, this is a 2D grid
!
nr = merge( 2 , 3 , all(ijkpts(3,1:nblk) == 1) )
!
! Deallocate clist before we leave if it is allocated
!
if (allocated(clist)) then
deallocate ( clist , stat=ierr , errmsg=error_message )
call alloc_error(pname,"clist",2,__LINE__,__FILE__,ierr,error_message)
end if
!
call debug_timer(leaving_procedure,pname)
!
! Return statement to ignore the remaining error crap
!
return
!
! Error continuations
!
100 if (mypnum == glb_root) write (iout,2) errstr,errstr ; goto 999
101 if (mypnum == glb_root) write (iout,3) errstr,errstr ; goto 999
102 if (mypnum == glb_root) write (iout,4) errstr,errstr ; goto 999
103 if (mypnum == glb_root) write (iout,5) errstr,errstr ; goto 999
104 if (mypnum == glb_root) write (iout,6) errstr,errstr ; goto 999
!
999 continue
if (mypnum == glb_root) then
call stop_gfr(abort,pname,__LINE__,__FILE__)
end if
! Have all the host roots call mpi_barrier here so that the MPI processes
! that arent the global root do not continue past this point before the
! global root has a chance to call mpi_abort within the above conditional.
call mpi_barrier(host_roots_comm,mpierr)
!
! Format Statements
!
1 format (a)
2 format (/,a,/," ERROR READING THE FORMATTED PLOT3D GRID FILE HEADER!",/, &
" THE GRID FILE SEEMED TO BE IN SINGLE BLOCK FORMAT",/, &
" BUT THE NUMBER OF VALUES ON THE FIRST LINE OF THE",/, &
" GRID FILE WAS INVALID!",/,a,/)
3 format (/,a,/," ERROR READING THE FORMATTED PLOT3D GRID FILE HEADER!",/, &
" THE GRID FILE SEEMED TO BE IN MULTIBLOCK FORMAT",/, &
" BUT THE NUMBER OF BLOCKS ON THE FIRST LINE OF THE",/, &
" GRID FILE WAS INVALID!",/,a,/)
4 format (/,a,/, &
" ERROR READING THE FORMATTED PLOT3D GRID FILE HEADER!",/, &
" THE GRID FILE SEEMED TO BE IN MULTIBLOCK FORMAT BUT THE",/, &
" NUMBER OF GRID DIMENSIONS WAS NOT EVENLY DIVISIBLE BY",/, &
" THE NUMBER OF BLOCKS, TELLING US IF THE GRID IS 2D OR 3D!",/,a,/)
5 format (/,a,/," ERROR READING THE FIRST LINE OF", &
" THE FORMATTED PLOT3D GRID FILE!",/,a,/)
6 format (/,a,/," ERROR READING THE FORMATTED PLOT3D GRID FILE HEADER!",/, &
" THE MINIMUM NUMBER OF NODES IN ANY DIRECTION IS 1!",/,a,/)
7 format ("Block #",i0," dimensions: ",i0,2(" x ",i0))
!
end subroutine read_p3d_formatted_header
!
!###############################################################################
!
subroutine read_p3d_unformatted_header(iogrd,gridfile)
!
!.. Use Statements ..
use geovar, only : nr
!
!.. Formal Arguments ..
integer, intent(in) :: iogrd
character(len=*), intent(in) :: gridfile