Skip to content

Commit 1366f99

Browse files
fangjianfangjian
authored andcommitted
fix data backup and recovery bugs
1 parent 5fb7dcf commit 1366f99

8 files changed

Lines changed: 348 additions & 133 deletions

File tree

Makefile.pastr

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ TARGET = $(BINDIR)/$(EXE)
2424

2525
VPATH = $(SRCDIR):$(OBJDIR)
2626

27-
srs= pastr_commvar.F90 pastr_constdef.F90 pastr_utility.F90 pastr_h5io.F90 \
28-
pastr_io.F90 pastr_tecio.F90 pastr_xdmf.F90 pastr_gradients.F90 \
29-
pastr_thermo_phys.F90 pastr_flowvis.F90 pastr_input.F90 \
30-
pastr_data_convert.F90 pastr_field_view.F90 pastr_udf.F90 \
31-
pastr_process.F90 pastr_main.F90
27+
srs= pastr_constdef.F90 pastr_commtype.F90 pastr_commvar.F90 pastr_multiblock_type.F90 \
28+
pastr_utility.F90 pastr_h5io.F90 pastr_io.F90 pastr_tecio.F90 pastr_xdmf.F90 \
29+
pastr_gradients.F90 pastr_thermo_phys.F90 pastr_flowvis.F90 pastr_input.F90 \
30+
pastr_data_convert.F90 pastr_field_view.F90 pastr_udf.F90 pastr_process.F90 \
31+
pastr_main.F90
3232

3333
OBJS=$(srs:.F90=.o)
3434

pastr/src/pastr_commtype.F90

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
module pastr_commtype
2+
3+
use iso_fortran_env, only: wp => real64
4+
use pastr_constdef
5+
6+
implicit none
7+
8+
type :: montype
9+
integer :: npoints,nvariables
10+
character(len=16),allocatable :: varname(:)
11+
integer,allocatable :: nstep(:)
12+
real(wp),allocatable :: time(:),data(:,:)
13+
contains
14+
procedure :: init => alloc_monitor
15+
end type montype
16+
17+
type :: tblock
18+
integer :: im,jm,nvar
19+
integer :: ilo,ihi,jlo,jhi
20+
character(len=16),allocatable :: varname(:)
21+
real(wp), allocatable, dimension(:,:) :: x,y
22+
real(wp), allocatable, dimension(:,:,:) :: var
23+
contains
24+
procedure :: init_data => alloc_block_data
25+
end type tblock
26+
27+
contains
28+
29+
subroutine alloc_monitor(amonitor)
30+
31+
class(montype),target :: amonitor
32+
33+
allocate(amonitor%varname(amonitor%nvariables))
34+
allocate(amonitor%time(amonitor%npoints))
35+
allocate(amonitor%nstep(amonitor%npoints))
36+
allocate(amonitor%data(amonitor%nvariables,amonitor%npoints))
37+
38+
end subroutine alloc_monitor
39+
40+
subroutine alloc_block_data(ablock)
41+
42+
class(tblock),target :: ablock
43+
44+
allocate(ablock%varname(ablock%nvar))
45+
allocate(ablock%x(0:ablock%im,0:ablock%jm))
46+
allocate(ablock%y(0:ablock%im,0:ablock%jm))
47+
allocate(ablock%var(0:ablock%im,0:ablock%jm,1:ablock%nvar))
48+
49+
end subroutine alloc_block_data
50+
51+
end module pastr_commtype

pastr/src/pastr_commvar.F90

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module pastr_commvar
22

33
use iso_fortran_env, only: wp => real64
44
use pastr_constdef
5+
use pastr_commtype
56

67
implicit none
78

@@ -25,37 +26,11 @@ module pastr_commvar
2526
real(wp), allocatable, dimension(:, :, :) :: x, y, z, ro, u1, u2, u3, p, t
2627
real(wp), allocatable, dimension(:, :, :) :: ro_m, u1_m, u2_m, u3_m, p_m, t_m
2728
real(wp), allocatable, dimension(:, :) :: ro_zm, u1_zm, u2_zm, u3_zm, &
28-
p_zm, t_zm
29+
p_zm, t_zm
2930
real(wp), allocatable, dimension(:) :: ro_xzm, u1_xzm, u2_xzm, u3_xzm, &
30-
p_xzm, t_xzm
31+
p_xzm, t_xzm
3132
real(wp), allocatable, dimension(:, :, :, :) :: du1_m, du2_m, du3_m, dt_m
3233
real(wp), allocatable, dimension(:, :, :) :: du1_zm, du2_zm, du3_zm, dt_zm
3334
real(wp), allocatable, dimension(:, :) :: du1_xzm, du2_xzm, du3_xzm, dt_xzm
3435

35-
type :: montype
36-
integer :: npoints,nvariables
37-
character(len=16),allocatable :: varname(:)
38-
integer,allocatable :: nstep(:)
39-
real(wp),allocatable :: time(:),data(:,:)
40-
contains
41-
procedure :: init => alloc_monitor
42-
end type montype
43-
44-
45-
46-
47-
contains
48-
49-
subroutine alloc_monitor(amonitor)
50-
!
51-
class(montype),target :: amonitor
52-
53-
allocate(amonitor%varname(amonitor%nvariables))
54-
allocate(amonitor%time(amonitor%npoints))
55-
allocate(amonitor%nstep(amonitor%npoints))
56-
allocate(amonitor%data(amonitor%nvariables,amonitor%npoints))
57-
58-
end subroutine alloc_monitor
59-
60-
6136
end module pastr_commvar

pastr/src/pastr_field_view.F90

Lines changed: 65 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ subroutine write_xy_slice(filein,fileout,nfirst,nlast,slice,format)
1919
use pastr_tecio
2020
use pastr_xdmf
2121
use pastr_data_convert
22+
use pastr_commtype
2223

2324
character(len=*),intent(in), optional :: filein,fileout
2425
integer,intent(in), optional :: nfirst,nlast
@@ -33,6 +34,10 @@ subroutine write_xy_slice(filein,fileout,nfirst,nlast,slice,format)
3334
character(len=6) :: src_of_data
3435
real(wp),allocatable :: r8dat(:,:)
3536
real(wp),allocatable,dimension(:,:,:) :: dat_var_in,dat_var_out
37+
type(tblock),allocatable,target :: pblocks(:)
38+
type(tblock),pointer :: b
39+
integer :: nblocks
40+
logical :: multi_block
3641

3742
call parse_command_line( string=src_of_data )
3843

@@ -90,13 +95,29 @@ subroutine write_xy_slice(filein,fileout,nfirst,nlast,slice,format)
9095

9196
dat_var_out=dat_out_cal(dat_var_in,nam_var_in,nam_var_out,x,y)
9297

93-
if(trim(format)=='plt') then
94-
call writetecbin2dlist_xy('snapshot/'//trim(file2write),x(is:ie,js:je), &
95-
y(is:ie,js:je), &
96-
dat_var_out(is:ie,js:je,:),nam_var_out)
97-
elseif(trim(format)=='xdmf') then
98-
call xdmfwriter(dir='snapshot/',filename=trim(file2write),x=x(is:ie,0),y=y(0,js:je), &
99-
var=dat_var_out(is:ie,js:je,:),varname=nam_var_out )
98+
call block_define(multi_block,nblocks,pblocks)
99+
100+
do i=1,nblocks
101+
b=>pblocks(i)
102+
b%nvar=num_var_out
103+
call b%init_data()
104+
b%x(0:b%im,0:b%jm)=x(b%ilo:b%ihi,b%jlo:b%jhi)
105+
b%y(0:b%im,0:b%jm)=y(b%ilo:b%ihi,b%jlo:b%jhi)
106+
b%var(0:b%im,0:b%jm,1:num_var_out)=dat_var_out(b%ilo:b%ihi,b%jlo:b%jhi,1:num_var_out )
107+
b%varname=nam_var_out
108+
enddo
109+
110+
if(multi_block) then
111+
call xdmfwriter(dir='snapshot/',filename=trim(file2write),blocks=pblocks )
112+
else
113+
if(trim(format)=='plt') then
114+
call writetecbin2dlist_xy('snapshot/'//trim(file2write),x(is:ie,js:je), &
115+
y(is:ie,js:je), &
116+
dat_var_out(is:ie,js:je,:),nam_var_out)
117+
elseif(trim(format)=='xdmf') then
118+
call xdmfwriter(dir='snapshot/',filename=trim(file2write),x=x(is:ie,0),y=y(0,js:je), &
119+
var=dat_var_out(is:ie,js:je,:),varname=nam_var_out )
120+
endif
100121
endif
101122

102123
enddo
@@ -263,7 +284,7 @@ subroutine write_3d_field(filein,fileout,nfirst,nlast,format)
263284
enddo
264285

265286
dat_var_out=dat_out_cal(dat_var_in,nam_var_in,nam_var_out,x,y,z)
266-
287+
267288
if(trim(format)=='plt') then
268289
call writetecbin3dlist('snapshot/'//trim(file2write),x(is:ie,js:je,ks:ke), &
269290
y(is:ie,js:je,ks:ke), &
@@ -366,4 +387,40 @@ subroutine var_define(num_var_in,nam_var_in,num_var_out,nam_var_out)
366387

367388
end subroutine var_define
368389

390+
subroutine block_define(multi_block,nblocks,pblocks)
391+
392+
use pastr_commtype
393+
394+
logical,intent(out) :: multi_block
395+
integer,intent(out) :: nblocks
396+
type(tblock),intent(out),allocatable :: pblocks(:)
397+
398+
integer :: i
399+
logical :: lfex
400+
401+
inquire(file='blockdef.txt',exist=lfex)
402+
if(lfex) then
403+
multi_block=.true.
404+
else
405+
multi_block=.false.
406+
return
407+
endif
408+
409+
open(12,file='blockdef.txt')
410+
read(12,*)nblocks
411+
allocate(pblocks(nblocks))
412+
do i=1,nblocks
413+
read(12,*)pblocks(i)%ilo,pblocks(i)%ihi,pblocks(i)%jlo,pblocks(i)%jhi
414+
pblocks(i)%im=pblocks(i)%ihi-pblocks(i)%ilo
415+
pblocks(i)%jm=pblocks(i)%jhi-pblocks(i)%jlo
416+
enddo
417+
close(12)
418+
print*,' >> blockdef.txt'
419+
420+
print*,' ** nblocks: ',nblocks
421+
422+
return
423+
424+
end subroutine block_define
425+
369426
end module pastr_field_view

pastr/src/pastr_multiblock_type.F90

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,22 @@ module pastr_multiblock_type
66

77
implicit none
88

9+
type :: stencil_type
10+
real(wp),pointer :: a(:)
11+
end type stencil_type
12+
13+
type :: fdm_type
14+
integer :: first_node,last_node,dim
15+
type(stencil_type),allocatable :: s(:)
16+
17+
contains
18+
19+
procedure :: init =>fdm_solver_init
20+
procedure :: cal=>fdm_solver_operator
21+
procedure :: info=>fdm_solver_print
22+
23+
end type fdm_type
24+
925
type :: link_type
1026

1127
logical :: active=.false.
@@ -83,21 +99,7 @@ module pastr_multiblock_type
8399

84100
end type block_type
85101

86-
type :: stencil_type
87-
real(wp),pointer :: a(:)
88-
end type stencil_type
89-
90-
type :: fdm_type
91-
integer :: first_node,last_node,dim
92-
type(stencil_type),allocatable :: s(:)
93102

94-
contains
95-
96-
procedure :: init =>fdm_solver_init
97-
procedure :: cal=>fdm_solver_operator
98-
procedure :: info=>fdm_solver_print
99-
100-
end type fdm_type
101103
contains
102104
subroutine alloc_block(ablock)
103105

pastr/src/pastr_xdmf.F90

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module pastr_xdmf
77
Interface xdmfwriter
88
module procedure xdmfwriter_2d
99
module procedure xdmfwriter_2drec
10+
module procedure xdmfwriter_2drec_block
1011
module procedure xdmfwriter_2drec_list_xy
1112
module procedure xdmfwriter_3d
1213
module procedure xdmfwriter_3drec
@@ -1012,4 +1013,100 @@ subroutine xdmfwriter_2drec_list_xy(dir,filename,x,y,var,varname)
10121013
!
10131014
end subroutine xdmfwriter_2drec_list_xy
10141015

1016+
subroutine xdmfwriter_2drec_block(dir,filename,blocks)
1017+
1018+
use pastr_utility, only : make_dir
1019+
use pastr_commtype,only : tblock
1020+
1021+
! arguments
1022+
character(len=*),intent(in) :: dir,filename
1023+
type(tblock),intent(in),dimension(:) :: blocks
1024+
1025+
real(4),allocatable :: bufr4(:,:)
1026+
character(len=3) :: bname
1027+
character(len=64) :: gridnamex,gridnamey,filavarname
1028+
!
1029+
! local data
1030+
integer :: fh,i,m,nvar
1031+
integer :: im,jm
1032+
logical :: lfex
1033+
1034+
call make_dir(dir)
1035+
1036+
fh=18
1037+
open(fh,file=dir//filename//'.xdmf',form='formatted')
1038+
write(fh,'(A)')'<?xml version="1.0" ?>'
1039+
write(fh,'(A)')'<!DOCTYPE Xdmf SYSTEM "Xdmf.dtd" []>'
1040+
write(fh,'(A)')'<Xdmf xmlns:xi="http://www.w3.org/2001/XInclude" Version="2.0">'
1041+
write(fh,'(A)')' <Domain>'
1042+
1043+
do i=1,size(blocks)
1044+
1045+
im=blocks(i)%im
1046+
jm=blocks(i)%jm
1047+
1048+
write(bname,'(i3.3)') i
1049+
gridnamex='block'//bname//'-grid-x.bin'
1050+
gridnamey='block'//bname//'-grid-y.bin'
1051+
1052+
inquire(file=dir//trim(gridnamex),exist=lfex)
1053+
if(.not. lfex) then
1054+
open(17,file=dir//trim(gridnamex),access="stream")
1055+
write(17)sngl(blocks(i)%x(0:im,0))
1056+
close(17)
1057+
print*,' << ',dir//trim(gridnamex)
1058+
endif
1059+
inquire(file=dir//trim(gridnamey),exist=lfex)
1060+
if(.not. lfex) then
1061+
open(17,file=dir//trim(gridnamey),access="stream")
1062+
write(17)sngl(blocks(i)%y(0,0:jm))
1063+
close(17)
1064+
print*,' << ',dir//trim(gridnamey)
1065+
endif
1066+
1067+
write(fh,'(3(A))')' <Grid Name=" block-',bname,'" GridType="Uniform">'
1068+
1069+
write(fh,'(A,2(1X,I0),A)')' <Topology name="topo" TopologyType="3DRectMesh" Dimensions=" 1', &
1070+
jm+1,im+1,'"> </Topology>'
1071+
write(fh,'(A)')' <Geometry name="geo" Type="VXVYVZ">'
1072+
write(fh,'(A)')' <DataItem Format="Binary" DataType="Float" Precision="4" Endian="little" Seek="0" '
1073+
write(fh,'(A,1X,I0,3(A))') ' Dimensions=" ',im+1,'"> ',gridnamex,' </DataItem>'
1074+
write(fh,'(A)')' <DataItem Format="Binary" DataType="Float" Precision="4" Endian="little" Seek="0" '
1075+
write(fh,'(A,1X,I0,3(A))') ' Dimensions=" ',jm+1,'"> ',gridnamey,' </DataItem>'
1076+
write(fh,'(A)')' <DataItem Dimensions=" 1 " Numbewp="Float" Precision="4" Format="XML" > 0.0 </DataItem>'
1077+
write(fh,'(A)')' </Geometry>'
1078+
write(fh,*)
1079+
1080+
allocate(bufr4(0:im,0:jm))
1081+
1082+
do m=1,blocks(i)%nvar
1083+
1084+
filavarname=filename//'-'//'block'//bname//'-'//trim(blocks(i)%varname(m))
1085+
1086+
write(fh,'(3(A))')' <Attribute Name="',trim(blocks(i)%varname(m)),'" Center="Node">'
1087+
write(fh,'(A)')' <DataItem Format="Binary" DataType="Float" Precision="4" Endian="little" Seek="0"'
1088+
write(fh,'(A,2(1X,I0),3(A))')' Dimensions=" 1 ',jm+1,im+1,'"> ',trim(filavarname),'</DataItem>'
1089+
1090+
write(fh,'(A)')' </Attribute>'
1091+
1092+
bufr4=sngl(blocks(i)%var(0:im,0:jm,m))
1093+
open(fh+1,file=dir//trim(filavarname),access="stream")
1094+
write(fh+1)bufr4
1095+
close(fh+1)
1096+
print*,' << ',dir//filename//'-'//trim(blocks(i)%varname(m))
1097+
1098+
deallocate(bufr4)
1099+
enddo
1100+
1101+
write(fh,'(A)')' </Grid>'
1102+
enddo
1103+
!
1104+
write(fh,'(A)')' </Domain>'
1105+
write(fh,'(A)')'</Xdmf>'
1106+
!
1107+
close(fh)
1108+
print*,' <<',dir//filename//'.xdmf done.'
1109+
1110+
end subroutine xdmfwriter_2drec_block
1111+
10151112
end module pastr_xdmf

0 commit comments

Comments
 (0)