63 #define OFFSET_TYPE INTEGER(KIND=MPI_OFFSET_KIND) 65 #define OFFSET_TYPE INTEGER 68 CLASS(fosite),
ALLOCATABLE :: Sim
69 TYPE(Dict_TYP),
POINTER :: input
72 CHARACTER(LEN=100) :: filename, filename_tmp
74 INTEGER,
DIMENSION(3) :: decomposition
76 LOGICAL :: file_exists
78 REAL,
DIMENSION(:,:,:),
POINTER :: r, Sigma
79 REAL,
DIMENSION(:,:,:,:),
POINTER :: r_faces
80 REAL,
DIMENSION(:,:,:),
POINTER :: bccsound
81 REAL,
DIMENSION(:,:,:,:),
POINTER :: fcsound
82 REAL,
PARAMETER :: MBH1 = 0.4465*1.0
83 REAL,
PARAMETER :: MBH2 = 0.4465*1.0
88 CALL get_command_argument(1, filename)
89 INQUIRE(file=trim(filename), exist=file_exists)
90 IF(.NOT.file_exists)
THEN 91 print *,
"restart, ",
"Input file does not exist!" 100 input => loadconfig(trim(filename))
101 CALL getattr(input,
"config", sim%config)
104 CALL getattr(input,
'/timedisc/time', time)
106 CALL setattr(sim%config,
"/timedisc/starttime", time)
110 decomposition(2) = -1
112 CALL setattr(sim%config,
"/mesh/decomposition", decomposition)
116 filename_tmp = filename
117 i = scan(filename_tmp,
'_',back=.true.)
119 filename_tmp = filename_tmp(i+1:i+4)
120 IF(filename_tmp(1:1) .EQ.
"0") filename_tmp = filename_tmp(2:)
121 IF(filename_tmp(1:1) .EQ.
"0") filename_tmp = filename_tmp(2:)
122 IF(filename_tmp(1:1) .EQ.
"0") filename_tmp = filename_tmp(2:)
123 READ(filename_tmp,*) step
124 CALL setattr(sim%config,
"/datafile/step", step)
126 CALL sim%Error(
"Restart",
"Unable to find starting step in filename_tmp.")
133 CALL loaddata(sim,trim(filename))
136 SELECT TYPE (phys => sim%Physics)
137 TYPE IS(physics_eulerisotherm)
140 bccsound(sim%Mesh%IGMIN:sim%Mesh%IGMAX,sim%Mesh%JGMIN:sim%Mesh%JGMAX,sim%Mesh%KGMIN:sim%Mesh%KGMAX), &
141 fcsound(sim%Mesh%IGMIN:sim%Mesh%IGMAX,sim%Mesh%JGMIN:sim%Mesh%JGMAX,sim%Mesh%KGMIN:sim%Mesh%KGMAX,6))
143 r => sim%Mesh%RemapBounds(sim%Mesh%radius%bcenter)
144 r_faces => sim%Mesh%RemapBounds(sim%Mesh%radius%faces)
145 bccsound = hratio*sqrt((mbh1+mbh2)*phys%Constants%GN/r(:,:,:))
147 fcsound(:,:,:,i) = hratio*sqrt((mbh1+mbh2)*phys%constants%GN/r_faces(:,:,:,i))
150 CALL phys%SetSoundSpeeds(sim%Mesh,bccsound)
151 CALL phys%SetSoundSpeeds(sim%Mesh,fcsound)
155 SELECT TYPE(bwest => sim%Timedisc%Boundary%boundary(west)%p)
156 CLASS IS (boundary_custom)
157 CALL bwest%SetCustomBoundaries(sim%Mesh,sim%Physics, &
158 (/custom_nograd,custom_outflow,custom_kepler/))
160 SELECT TYPE(beast => sim%Timedisc%Boundary%boundary(east)%p)
161 CLASS IS (boundary_custom)
162 CALL beast%SetCustomBoundaries(sim%Mesh,sim%Physics, &
163 (/custom_nograd,custom_outflow,custom_kepler/))
169 CALL sim%Info(
" DATA-----> initial condition: restarted from data file - " // &
172 CALL sim%Physics%Convert2Conservative(sim%Timedisc%pvar,sim%Timedisc%cvar)
186 FUNCTION loadconfig(filename)
RESULT(res)
189 CHARACTER(LEN=*) :: filename
190 TYPE(Dict_TYP),
POINTER :: res
192 INTEGER :: file, error, keylen, intsize, realsize, &
193 type, bytes, l, dims(5)
194 CHARACTER(LEN=6) :: magic
195 CHARACTER(LEN=2) :: endian
196 CHARACTER(LEN=13) :: header
197 CHARACTER(LEN=4) :: sizestr
198 CHARACTER(LEN=1),
DIMENSION(128) :: buffer
201 CHARACTER(LEN=1) :: version
203 INTEGER(KIND=MPI_OFFSET_KIND) :: offset, offset_0, filesize
206 CHARACTER(LEN=1),
DIMENSION(:),
POINTER :: keybuf
207 CHARACTER(LEN=MAX_CHAR_LEN) :: key,kf
208 REAL,
DIMENSION(:,:,:),
POINTER :: ptr3 => null()
209 CHARACTER(LEN=1),
DIMENSION(:),
POINTER :: val
215 INTEGER,
DIMENSION(2) :: gsizes,lsizes,indices,memsizes
216 INTEGER,
DIMENSION(MPI_STATUS_SIZE) :: status
219 INTENT(IN) :: filename
226 file = trim(filename), &
230 position =
'REWIND', &
234 CALL mpi_file_open(mpi_comm_world,trim(filename),mpi_mode_rdonly, &
235 mpi_info_null,handle,error)
237 CALL mpi_file_set_view(handle,offset_0,mpi_byte,mpi_byte,
'native',mpi_info_null,ierror)
238 CALL mpi_file_seek(handle,offset-1,mpi_seek_set,ierror)
242 READ(file,pos=offset) magic, endian, version, sizestr
244 CALL mpi_file_read_all(handle, header, len(header), mpi_byte, &
246 WRITE (magic,
'(A6)') header(1:6)
247 WRITE (endian,
'(A2)') header(7:8)
248 version = iachar(header(9:9))
249 WRITE (sizestr,
'(A4)') header(10:13)
252 READ(sizestr,
'(I2,I2)') realsize, intsize
255 READ(file, iostat=error, pos=offset) keylen
259 CALL mpi_file_seek(handle,offset-1,mpi_seek_set,ierror)
260 CALL mpi_file_read_all(handle, buffer, intsize, mpi_byte, status,ierror)
261 keylen = transfer(buffer(1:intsize),keylen)
263 offset = offset + intsize
268 ALLOCATE(keybuf(keylen))
270 READ(file, pos=offset) keybuf,
type,bytes
272 CALL mpi_file_seek(handle,offset-1,mpi_seek_set,ierror)
273 CALL mpi_file_read_all(handle, buffer, keylen+2*intsize, mpi_byte, &
275 keybuf = transfer(buffer(1:keylen), keybuf)
276 type = transfer(buffer(keylen+1:keylen+intsize), type)
277 bytes = transfer(buffer(keylen+intsize+1:keylen+2*intsize), bytes)
279 WRITE(kf,
'(A, I4, A)')
'(',keylen,
'(A))' 283 offset = offset + keylen + 2*intsize
288 CASE(dict_real_threed)
290 CASE(dict_real_fourd)
292 CASE(dict_real_fived)
299 READ(file, pos=offset) dims(1:l)
302 CALL mpi_file_seek(handle,offset-1,mpi_seek_set,ierror)
303 CALL mpi_file_read_all(handle,buffer(1:l*intsize),l*intsize,mpi_byte,status,error)
304 dims(1:l) = transfer(buffer(1:l*intsize),dims(1:l))
306 bytes = bytes - l*intsize
307 offset = offset + l*intsize
327 READ(file, pos=offset) val
330 CALL mpi_file_seek(handle,offset-1,mpi_seek_set,ierror)
331 CALL mpi_file_read_all(handle,buffer(1:bytes),bytes,mpi_byte,status,error)
332 val = transfer(buffer(1:bytes),val)
334 IF(key.EQ.
'/config/mesh/decomposition')
THEN 337 CALL setattr(res,key,val,type)
343 offset = offset + bytes
346 READ(file, pos=offset, iostat=error) keylen
349 CALL mpi_file_seek(handle,offset-1,mpi_seek_set,ierror)
350 CALL mpi_file_read_all(handle,buffer(1:intsize),intsize,mpi_byte,status,ierror)
351 keylen = transfer(buffer(1:intsize),keylen)
354 CALL mpi_file_get_position(handle,offset_0,ierror)
355 CALL mpi_file_get_size(handle,filesize,ierror)
356 IF (filesize.LE.offset_0)
THEN 362 offset = offset + intsize
367 END FUNCTION loadconfig
375 SUBROUTINE loaddata(this,filename)
378 CLASS(fosite) :: this
379 CHARACTER(LEN=*) :: filename
381 INTEGER :: unit, error, keylen, &
382 intsize, realsize,
type, bytes, &
385 CHARACTER(LEN=13) :: header
386 CHARACTER(LEN=6) :: magic
387 CHARACTER(LEN=2) :: endian
388 CHARACTER(LEN=1),
DIMENSION(128) :: buffer
391 CHARACTER(LEN=1) :: version
393 INTEGER(KIND=MPI_OFFSET_KIND) :: offset, offset_0, filesize
396 CHARACTER(LEN=4) :: sizestr
397 CHARACTER(LEN=1),
DIMENSION(:),
POINTER :: keybuf
398 CHARACTER(LEN=MAX_CHAR_LEN) :: key,kf
399 REAL,
DIMENSION(:,:),
POINTER :: ptr2 => null()
400 REAL,
DIMENSION(:,:,:),
POINTER :: ptr3 => null()
401 REAL,
DIMENSION(:,:,:,:),
POINTER :: ptr4 => null()
402 REAL,
DIMENSION(:,:,:,:,:),
POINTER :: ptr5 => null()
403 CHARACTER(LEN=1),
DIMENSION(:),
POINTER :: val
410 INTEGER,
DIMENSION(2) :: gsizes,lsizes,indices,memsizes
411 INTEGER,
DIMENSION(MPI_STATUS_SIZE) :: status
413 CLASS(sources_base),
POINTER :: srcptr
414 CLASS(gravity_base),
POINTER :: gravptr
416 INTENT(IN) :: filename
417 INTENT(INOUT) :: this
424 file = trim(filename), &
428 position =
'REWIND', &
432 gsizes(1) = sim%Mesh%INUM
433 gsizes(2) = sim%Mesh%JNUM
434 lsizes(1) = sim%Mesh%IMAX-sim%Mesh%IMIN+1
435 lsizes(2) = sim%Mesh%JMAX-sim%Mesh%JMIN+1
436 indices(1)= sim%Mesh%IMIN-1
437 indices(2)= sim%Mesh%JMIN-1
438 bufsize = product(lsizes)
439 CALL mpi_type_create_subarray(2, gsizes, lsizes, indices, mpi_order_fortran,&
441 CALL mpi_type_commit(filetype,ierror)
444 CALL mpi_file_open(mpi_comm_world,trim(filename),mpi_mode_rdonly, &
445 mpi_info_null,handle,error)
450 READ(unit) magic, endian, version, sizestr
452 CALL mpi_file_read_all(handle, header, len(header), mpi_byte, &
454 WRITE (magic,
'(A6)') header(1:6)
455 WRITE (endian,
'(A2)') header(7:8)
456 version = iachar(header(9:9))
457 WRITE (sizestr,
'(A4)') header(10:13)
460 READ(sizestr,
'(I2,I2)') realsize, intsize
462 READ(unit, iostat=error) keylen
466 CALL mpi_file_read_all(handle, buffer, intsize, mpi_byte, status,ierror)
467 keylen = transfer(buffer(1:intsize),keylen)
469 offset = offset + intsize
476 ALLOCATE(keybuf(keylen))
478 READ(unit) keybuf,
type,bytes
480 CALL mpi_file_read_all(handle, buffer, keylen+2*intsize, mpi_byte, &
482 keybuf = transfer(buffer(1:keylen), keybuf)
483 type = transfer(buffer(keylen+1:keylen+intsize), type)
484 bytes = transfer(buffer(keylen+intsize+1:keylen+2*intsize), bytes)
486 WRITE(kf,
'(A, I4, A)')
'(',keylen,
'(A))' 489 offset = offset + keylen + 2*intsize
494 CASE(dict_real_threed)
496 CASE(dict_real_fourd)
498 CASE(dict_real_fived)
508 CALL mpi_file_read_all(handle,buffer(1:l*intsize),l*intsize,mpi_byte,status,error)
509 dims(1:l) = transfer(buffer(1:l*intsize),dims(1:l))
511 bytes = bytes - l*intsize
512 offset = offset + l*intsize
515 SELECT CASE(trim(key))
516 CASE(
'/timedisc/density')
517 sim%Timedisc%pvar%data4d(sim%Mesh%IGMIN:sim%Mesh%IGMAX,sim%Mesh%JGMIN:sim%Mesh%JGMAX, &
518 sim%Mesh%KGMIN:sim%Mesh%KGMAX,sim%Physics%DENSITY) = 0.0
520 READ(unit) sim%Timedisc%pvar%data4d(sim%Mesh%IMIN:sim%Mesh%IMAX,sim%Mesh%JMIN:sim%Mesh%JMAX, &
521 sim%Mesh%KMIN:sim%Mesh%KMAX,sim%Physics%DENSITY)
523 CALL mpi_file_set_view(handle, offset-1,
default_mpi_real,filetype,
'native', mpi_info_null, ierror)
524 CALL mpi_file_read_all(handle, &
525 sim%Timedisc%pvar%data4d(sim%Mesh%IMIN:sim%Mesh%IMAX,sim%Mesh%JMIN:sim%Mesh%JMAX, &
526 sim%Mesh%KMIN:sim%Mesh%KMAX,sim%Physics%DENSITY), &
529 CALL mpi_file_set_view(handle,offset_0,mpi_byte,mpi_byte,
'native',mpi_info_null,ierror)
531 CASE(
'/timedisc/xvelocity')
532 sim%Timedisc%pvar%data4d(sim%Mesh%IGMIN:sim%Mesh%IGMAX,sim%Mesh%JGMIN:sim%Mesh%JGMAX, &
533 sim%Mesh%KGMIN:sim%Mesh%KGMAX,sim%Physics%XVELOCITY) = 0.0
535 READ(unit) sim%Timedisc%pvar%data4d(sim%Mesh%IMIN:sim%Mesh%IMAX,sim%Mesh%JMIN:sim%Mesh%JMAX, &
536 sim%Mesh%KMIN:sim%Mesh%KMAX,sim%Physics%XVELOCITY)
538 CALL mpi_file_set_view(handle, offset-1,
default_mpi_real,filetype,
'native', mpi_info_null, ierror)
539 CALL mpi_file_read_all(handle, &
540 sim%Timedisc%pvar%data4d(sim%Mesh%IMIN:sim%Mesh%IMAX,sim%Mesh%JMIN:sim%Mesh%JMAX, &
541 sim%Mesh%KMIN:sim%Mesh%KMAX,sim%Physics%XVELOCITY),&
544 CALL mpi_file_set_view(handle,offset_0,mpi_byte,mpi_byte,
'native',mpi_info_null,ierror)
546 CASE(
'/timedisc/yvelocity')
547 sim%Timedisc%pvar%data4d(sim%Mesh%IGMIN:sim%Mesh%IGMAX,sim%Mesh%JGMIN:sim%Mesh%JGMAX, &
548 sim%Mesh%KGMIN:sim%Mesh%KGMAX,sim%Physics%YVELOCITY) = 0.0
550 READ(unit) sim%Timedisc%pvar%data4d(sim%Mesh%IMIN:sim%Mesh%IMAX,sim%Mesh%JMIN:sim%Mesh%JMAX, &
551 sim%Mesh%KMIN:sim%Mesh%KMAX,sim%Physics%YVELOCITY)
553 CALL mpi_file_set_view(handle, offset-1,
default_mpi_real,filetype,
'native', mpi_info_null, ierror)
554 CALL mpi_file_read_all(handle, &
555 sim%Timedisc%pvar%data4d(sim%Mesh%IMIN:sim%Mesh%IMAX,sim%Mesh%JMIN:sim%Mesh%JMAX, &
556 sim%Mesh%KMIN:sim%Mesh%KMAX,sim%Physics%YVELOCITY),&
559 CALL mpi_file_set_view(handle,offset_0,mpi_byte,mpi_byte,
'native',mpi_info_null,ierror)
561 CASE(
'/timedisc/zvelocity')
562 sim%Timedisc%pvar%data4d(sim%Mesh%IGMIN:sim%Mesh%IGMAX,sim%Mesh%JGMIN:sim%Mesh%JGMAX, &
563 sim%Mesh%KGMIN:sim%Mesh%KGMAX,sim%Physics%ZVELOCITY) = 0.0
565 READ(unit) sim%Timedisc%pvar%data4d(sim%Mesh%IMIN:sim%Mesh%IMAX,sim%Mesh%JMIN:sim%Mesh%JMAX, &
566 sim%Mesh%KMIN:sim%Mesh%KMAX,sim%Physics%ZVELOCITY)
568 CALL mpi_file_set_view(handle, offset-1,
default_mpi_real,filetype,
'native', mpi_info_null, ierror)
569 CALL mpi_file_read_all(handle, &
570 sim%Timedisc%pvar%data4d(sim%Mesh%IMIN:sim%Mesh%IMAX,sim%Mesh%JMIN:sim%Mesh%JMAX, &
571 sim%Mesh%KMIN:sim%Mesh%KMAX,sim%Physics%ZVELOCITY),&
574 CALL mpi_file_set_view(handle,offset_0,mpi_byte,mpi_byte,
'native',mpi_info_null,ierror)
576 CASE(
'/timedisc/pressure')
577 SELECT TYPE (phys => sim%Physics)
578 TYPE IS(physics_euler)
579 sim%Timedisc%pvar%data4d(sim%Mesh%IGMIN:sim%Mesh%IGMAX,sim%Mesh%JGMIN:sim%Mesh%JGMAX, &
580 sim%Mesh%KGMIN:sim%Mesh%KGMAX,phys%PRESSURE) = 0.0
582 READ(unit) sim%Timedisc%pvar%data4d(sim%Mesh%IMIN:sim%Mesh%IMAX,sim%Mesh%JMIN:sim%Mesh%JMAX, &
583 sim%Mesh%KMIN:sim%Mesh%KMAX,phys%PRESSURE)
585 CALL mpi_file_set_view(handle, offset-1,
default_mpi_real,filetype,
'native', mpi_info_null, ierror)
586 CALL mpi_file_read_all(handle, &
587 sim%Timedisc%pvar%data4d(sim%Mesh%IMIN:sim%Mesh%IMAX,sim%Mesh%JMIN:sim%Mesh%JMAX, &
588 sim%Mesh%KMIN:sim%Mesh%KMAX,phys%PRESSURE),&
591 CALL mpi_file_set_view(handle,offset_0,mpi_byte,mpi_byte,
'native',mpi_info_null,ierror)
594 CASE(
'/physics/bccsound')
595 SELECT TYPE (phys => sim%Physics)
596 TYPE IS(physics_eulerisotherm)
597 phys%bccsound%data3d(sim%Mesh%IGMIN:sim%Mesh%IGMAX,sim%Mesh%JGMIN:sim%Mesh%JGMAX, &
598 sim%Mesh%KGMIN:sim%Mesh%KGMAX) = 0.0
600 READ(unit) phys%bccsound%data3d(sim%Mesh%IMIN:sim%Mesh%IMAX,sim%Mesh%JMIN:sim%Mesh%JMAX, &
601 sim%Mesh%KMIN:sim%Mesh%KMAX)
603 CALL mpi_file_set_view(handle, offset-1,
default_mpi_real,filetype,
'native', mpi_info_null, ierror)
604 CALL mpi_file_read_all(handle, &
605 phys%bccsound%data3d(sim%Mesh%IMIN:sim%Mesh%IMAX,sim%Mesh%JMIN:sim%Mesh%JMAX, &
606 sim%Mesh%KMIN:sim%Mesh%KMAX),&
609 CALL mpi_file_set_view(handle,offset_0,mpi_byte,mpi_byte,
'native',mpi_info_null,ierror)
612 CASE(
'/physics/fcsound')
613 SELECT TYPE (phys => sim%Physics)
614 TYPE IS(physics_eulerisotherm)
615 phys%fcsound%data4d(sim%Mesh%IGMIN:sim%Mesh%IGMAX,sim%Mesh%JGMIN:sim%Mesh%JGMAX, &
616 sim%Mesh%KGMIN:sim%Mesh%KGMAX,1:sim%Mesh%NFACES) = 0.0
618 READ(unit) phys%fcsound%data4d(sim%Mesh%IMIN:sim%Mesh%IMAX,sim%Mesh%JMIN:sim%Mesh%JMAX, &
619 sim%Mesh%KMIN:sim%Mesh%KMAX,1:sim%Mesh%NFACES)
621 CALL mpi_file_set_view(handle, offset-1,
default_mpi_real,filetype,
'native', mpi_info_null, ierror)
622 CALL mpi_file_read_all(handle, &
623 phys%fcsound%data4d(sim%Mesh%IMIN:sim%Mesh%IMAX,sim%Mesh%JMIN:sim%Mesh%JMAX, &
624 sim%Mesh%KMIN:sim%Mesh%KMAX,1:sim%Mesh%NFACES),&
627 CALL mpi_file_set_view(handle,offset_0,mpi_byte,mpi_byte,
'native',mpi_info_null,ierror)
630 CASE(
'/sources/grav/binary/binpos')
631 srcptr => this%Sources
632 DO WHILE (
ASSOCIATED(srcptr))
633 SELECT TYPE (gravity => srcptr)
634 TYPE IS (sources_gravity)
635 gravptr => gravity%glist
636 DO WHILE (
ASSOCIATED(gravptr))
637 SELECT TYPE (binary => gravptr)
638 TYPE IS (gravity_binary)
639 READ(unit) binary%pos(1:3,1:2)
643 gravptr => gravptr%next
648 srcptr => srcptr%next
650 CASE(
'/sources/grav/binary/mass')
651 srcptr => this%Sources
652 DO WHILE (
ASSOCIATED(srcptr))
653 SELECT TYPE (gravity => srcptr)
654 TYPE IS (sources_gravity)
655 gravptr => gravity%glist
656 DO WHILE (
ASSOCIATED(gravptr))
657 SELECT TYPE (binary => gravptr)
658 TYPE IS (gravity_binary)
659 READ(unit) binary%mass
663 gravptr => gravptr%next
668 srcptr => srcptr%next
670 CASE(
'/sources/grav/binary/mass2')
671 srcptr => this%Sources
672 DO WHILE (
ASSOCIATED(srcptr))
673 SELECT TYPE (gravity => srcptr)
674 TYPE IS (sources_gravity)
675 gravptr => gravity%glist
676 DO WHILE (
ASSOCIATED(gravptr))
677 SELECT TYPE (binary => gravptr)
678 TYPE IS (gravity_binary)
679 READ(unit) binary%mass2
683 gravptr => gravptr%next
688 srcptr => srcptr%next
694 ALLOCATE(ptr2(dims(1),dims(2)))
700 ALLOCATE(ptr3(dims(1),dims(2),dims(3)))
706 ALLOCATE(ptr4(dims(1),dims(2),dims(3),dims(4)))
712 ALLOCATE(ptr5(dims(1),dims(2),dims(3),dims(4),dims(5)))
726 offset = offset + bytes
729 READ(unit, iostat=error) keylen
732 CALL mpi_file_seek(handle,offset-1,mpi_seek_set,ierror)
733 CALL mpi_file_read_all(handle,buffer(1:intsize),intsize,mpi_byte,status,ierror)
734 keylen = transfer(buffer(1:intsize),keylen)
736 CALL mpi_file_get_position(handle,offset_0,ierror)
737 CALL mpi_file_get_size(handle,filesize,ierror)
738 IF (filesize.LE.offset_0)
THEN 743 offset = offset + intsize
748 CALL mpi_file_close(handle,ierror)
750 END SUBROUTINE loaddata
integer, save default_mpi_real
default real type for MPI