Skip to content

Commit fb55620

Browse files
committed
uses direct access for reading coupling wavefield files
1 parent c088aba commit fb55620

File tree

2 files changed

+79
-18
lines changed

2 files changed

+79
-18
lines changed

src/specfem3D/compute_stacey_viscoelastic.F90

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ subroutine compute_coupled_injection_contribution_el(NGLOB_AB,accel,iphase,it)
630630

631631
case (INJECTION_TECHNIQUE_IS_SPECFEM)
632632
! SPECFEM coupling
633-
call read_specfem_file(Veloc_specfem,Tract_specfem,num_abs_boundary_faces*NGLLSQUARE)
633+
call read_specfem_file(Veloc_specfem,Tract_specfem,num_abs_boundary_faces*NGLLSQUARE,it)
634634

635635
case (INJECTION_TECHNIQUE_IS_FK)
636636
! FK coupling
@@ -824,17 +824,31 @@ end subroutine read_axisem_file
824824

825825
!=============================================================================
826826

827-
subroutine read_specfem_file(Veloc_specfem,Tract_specfem,nb)
827+
subroutine read_specfem_file(Veloc_specfem,Tract_specfem,nb,it)
828828

829-
use constants, only: CUSTOM_REAL,NDIM,IIN_veloc_dsm
829+
use constants, only: myrank,CUSTOM_REAL,NDIM,IIN_veloc_dsm
830830

831831
implicit none
832832

833833
integer, intent(in) :: nb
834834
real(kind=CUSTOM_REAL), intent(out) :: Veloc_specfem(NDIM,nb)
835835
real(kind=CUSTOM_REAL), intent(out) :: Tract_specfem(NDIM,nb)
836+
integer,intent(in) :: it
836837

837-
read(IIN_veloc_dsm) Veloc_specfem, Tract_specfem
838+
! local parameters
839+
integer :: ier
840+
841+
! reads velocity & traction
842+
!read(IIN_veloc_dsm,iostat=ier) Veloc_specfem, Tract_specfem
843+
! w/ direct access
844+
read(IIN_veloc_dsm,rec=it,iostat=ier) Veloc_specfem, Tract_specfem
845+
846+
! check
847+
if (ier /= 0) then
848+
print *,'Error: rank ',myrank,'failed to read in wavefield (veloc & traction) at time step it = ',it
849+
print *,' Please check that the wavefield injection files proc***_sol_specfem.bin exists.'
850+
call exit_MPI(myrank,'Error reading injection wavefield file')
851+
endif
838852

839853
end subroutine read_specfem_file
840854

src/specfem3D/couple_with_injection.f90

Lines changed: 61 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3082,7 +3082,7 @@ subroutine couple_with_injection_prepare_specfem_files()
30823082
integer :: num_coupling_points_total,ntimesteps
30833083
real(kind=CUSTOM_REAL), dimension(:,:), allocatable :: tmp_veloc,tmp_traction
30843084
real(kind=CUSTOM_REAL), dimension(:,:,:), allocatable :: tmp_veloc_points_timeseries,tmp_traction_points_timeseries
3085-
integer :: offset_proc
3085+
integer :: offset_proc,reclen
30863086

30873087
double precision :: tmin_file,tmax_file,tmin_curr,tmax_curr
30883088
double precision :: sizeval
@@ -3158,7 +3158,14 @@ subroutine couple_with_injection_prepare_specfem_files()
31583158
endif
31593159

31603160
! first line: #num_points #step_size #start_time #ntimesteps
3161-
read(IIN) num_coupling_points_total, dt_incr, start_time, ntimesteps
3161+
read(IIN,iostat=ier) num_coupling_points_total, dt_incr, start_time, ntimesteps
3162+
3163+
! check
3164+
if (ier /= 0) then
3165+
print *,'Error: rank ',myrank,' failed to read file ',trim(filename)
3166+
print *,' Please check that the file contains data...'
3167+
stop 'Error reading specfem_coupling_solution.bin'
3168+
endif
31623169

31633170
! solution file time range
31643171
tmin_file = start_time ! start_time is negative
@@ -3217,7 +3224,14 @@ subroutine couple_with_injection_prepare_specfem_files()
32173224
! read in points and save local time series
32183225
do i = 1,ntimesteps
32193226
! reads current time step values for all points
3220-
read(IIN) tmp_veloc,tmp_traction
3227+
read(IIN,iostat=ier) tmp_veloc,tmp_traction
3228+
3229+
! check
3230+
if (ier /= 0) then
3231+
print *,'Error: rank ',myrank,' failed to read wavefields in file ',trim(filename),' at timestep ',i
3232+
print *,' Please check that the file contains all wavefield data...'
3233+
stop 'Error reading specfem_coupling_solution.bin'
3234+
endif
32213235

32223236
! assigns values on local points
32233237
if (npoints_local > 0) then
@@ -3296,14 +3310,6 @@ subroutine couple_with_injection_prepare_specfem_files()
32963310
call flush_IMAIN()
32973311
endif
32983312

3299-
! open files to store wavefield solution for this slice and simulation time stepping
3300-
open(unit=IOUT,file=trim(filename),status='unknown',action='write',form='unformatted',iostat=ier)
3301-
if (ier /= 0) then
3302-
print *,'Error: could not open file ',trim(filename)
3303-
print *,' Please check if path exists...'
3304-
stop 'Error opening database proc***_sol_specfem.bin'
3305-
endif
3306-
33073313
! boundary arrays for reading/writing
33083314
allocate(Veloc_specfem(NDIM,npoints_local),stat=ier)
33093315
if (ier /= 0) call exit_MPI(myrank,'error allocating array 2192')
@@ -3316,6 +3322,32 @@ subroutine couple_with_injection_prepare_specfem_files()
33163322
! synchronizes to be sure all processes had enough memory
33173323
call synchronize_all()
33183324

3325+
! file with direct access
3326+
! gets size of single record
3327+
inquire(iolength=reclen) Veloc_specfem
3328+
! check integer size limit: size of reclen must fit onto an 4-byte integer
3329+
if (reclen > int(2147483646.0 / 2)) then
3330+
print *,'reclen needed exceeds integer 4-byte limit: ',reclen
3331+
print *,' ',reclen,' custom_real/ndim/npoints_local = ',CUSTOM_REAL, NDIM, npoints_local
3332+
print *,'bit size Fortran: ',bit_size(reclen)
3333+
call exit_MPI(myrank,"Error reclen integer limit")
3334+
endif
3335+
! record size for velocity & traction fields
3336+
reclen = 2 * reclen
3337+
3338+
! open files to store wavefield solution for this slice and simulation time stepping
3339+
!open(unit=IOUT,file=trim(filename),status='unknown',action='write',form='unformatted',iostat=ier)
3340+
! w/ direct access
3341+
open(unit=IOUT,file=trim(filename),status='unknown',action='write',form='unformatted', &
3342+
access='direct',recl=reclen,iostat=ier)
3343+
3344+
! check
3345+
if (ier /= 0) then
3346+
print *,'Error: could not open file ',trim(filename)
3347+
print *,' Please check if path exists...'
3348+
stop 'Error opening database proc***_sol_specfem.bin'
3349+
endif
3350+
33193351
! interpolate wavefield solution in time
33203352
!
33213353
! Sinc (Whittaker-Shannon) interpolation:
@@ -3374,7 +3406,13 @@ subroutine couple_with_injection_prepare_specfem_files()
33743406

33753407
! open the file created before
33763408
! to read in corresponding time slices in routine compute_Stacey_elastic()
3377-
open(unit=IIN_veloc_dsm,file=trim(filename),status='old',action='read',form='unformatted',iostat=ier)
3409+
!open(unit=IIN_veloc_dsm,file=trim(filename),status='old',action='read',form='unformatted',iostat=ier)
3410+
!
3411+
! with direct access
3412+
open(unit=IIN_veloc_dsm,file=trim(filename),status='old',action='read',form='unformatted', &
3413+
access='direct',recl=reclen,iostat=ier)
3414+
3415+
! check
33783416
if (ier /= 0) then
33793417
print *,'Error: could not open file ',trim(filename)
33803418
print *,'Please check if traction file has been created for coupling with SPECFEM solution...'
@@ -3421,7 +3459,7 @@ subroutine interpolate_with_Catmull_Rom(ntimesteps,dt_incr,start_time, &
34213459
tmp_traction_points_timeseries
34223460

34233461
! local parameters
3424-
integer :: it_tmp,ipoin_local,i
3462+
integer :: it_tmp,ipoin_local,i,ier
34253463
double precision :: current_time
34263464
double precision :: tmin_file,tmax_file
34273465

@@ -3564,7 +3602,16 @@ subroutine interpolate_with_Catmull_Rom(ntimesteps,dt_incr,start_time, &
35643602
endif
35653603

35663604
! store in file
3567-
write(IOUT) Veloc_specfem,Tract_specfem
3605+
!write(IOUT,iostat=ier) Veloc_specfem,Tract_specfem
3606+
! w/ direct access
3607+
write(IOUT,rec=it_tmp,iostat=ier) Veloc_specfem,Tract_specfem
3608+
3609+
! check
3610+
if (ier /= 0) then
3611+
print *,'Error: rank ',myrank,' failed to write out interpolated wavefields'
3612+
print *,' Please check if enough file space is available...'
3613+
stop 'Error output interpolated wavefields'
3614+
endif
35683615

35693616
! user output
35703617
if (myrank == 0) then

0 commit comments

Comments
 (0)