Skip to content

Commit 322c8f8

Browse files
committed
updates adjoint source time indexing
1 parent b6fab06 commit 322c8f8

File tree

4 files changed

+26
-15
lines changed

4 files changed

+26
-15
lines changed

src/specfem3D/compute_add_sources_acoustic.f90

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,9 @@ subroutine compute_add_sources_acoustic(potential_dot_dot_acoustic)
211211

212212
! adds source term
213213
if (it < NSTEP) then
214+
! time step index for adjoint source (time-reversed)
215+
it_index = NTSTEP_BETWEEN_READ_ADJSRC - mod(it-1,NTSTEP_BETWEEN_READ_ADJSRC)
216+
214217
! receivers act as sources
215218
do irec_local = 1, nadj_rec_local
216219
irec = number_adjsources_global(irec_local)
@@ -225,9 +228,6 @@ subroutine compute_add_sources_acoustic(potential_dot_dot_acoustic)
225228

226229
hlagrange = hxir_adjstore(i,irec_local) * hetar_adjstore(j,irec_local) * hgammar_adjstore(k,irec_local)
227230

228-
! time step index
229-
it_index = NTSTEP_BETWEEN_READ_ADJSRC - mod(it-1,NTSTEP_BETWEEN_READ_ADJSRC)
230-
231231
! beware, for acoustic medium, a pressure source would be taking the negative
232232
! and divide by Kappa of the fluid;
233233
! this would have to be done when constructing the adjoint source.

src/specfem3D/compute_add_sources_poroelastic.f90

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ subroutine compute_add_sources_poroelastic()
5959
double precision,external :: get_stf_poroelastic
6060

6161
logical :: ibool_read_adj_arrays
62-
integer :: isource,iglob,i,j,k,ispec,it_sub_adj
62+
integer :: isource,iglob,i,j,k,ispec,it_sub_adj,it_index
6363
integer :: irec_local,irec
6464
real(kind=CUSTOM_REAL) :: phil,tortl,rhol_s,rhol_f,rhol_bar
6565
real(kind=CUSTOM_REAL) :: fac_s,fac_w
@@ -247,6 +247,9 @@ subroutine compute_add_sources_poroelastic()
247247
endif ! if (ibool_read_adj_arrays)
248248

249249
if (it < NSTEP) then
250+
! time step index for adjoint source (time-reversed)
251+
it_index = NTSTEP_BETWEEN_READ_ADJSRC - mod(it-1,NTSTEP_BETWEEN_READ_ADJSRC)
252+
250253
! receivers act as sources
251254
do irec_local = 1, nadj_rec_local
252255
irec = number_adjsources_global(irec_local)
@@ -271,12 +274,11 @@ subroutine compute_add_sources_poroelastic()
271274

272275
! solid phase
273276
accels_poroelastic(:,iglob) = accels_poroelastic(:,iglob) &
274-
+ source_adjoint(:,irec_local,NTSTEP_BETWEEN_READ_ADJSRC - mod(it-1,NTSTEP_BETWEEN_READ_ADJSRC)) * hlagrange
277+
+ source_adjoint(:,irec_local,it_index) * hlagrange
275278
!
276279
! fluid phase
277280
accelw_poroelastic(:,iglob) = accelw_poroelastic(:,iglob) &
278-
- rhol_f/rhol_bar &
279-
* source_adjoint(:,irec_local,NTSTEP_BETWEEN_READ_ADJSRC - mod(it-1,NTSTEP_BETWEEN_READ_ADJSRC)) * hlagrange
281+
- rhol_f/rhol_bar * source_adjoint(:,irec_local,it_index) * hlagrange
280282
enddo
281283
enddo
282284
enddo
@@ -363,10 +365,10 @@ subroutine compute_add_sources_poroelastic()
363365

364366
! solid phase
365367
b_accels_poroelastic(:,iglob) = b_accels_poroelastic(:,iglob) &
366-
+ fac_s * sourcearrays(isource,:,i,j,k)*stf_used
368+
+ fac_s * sourcearrays(isource,:,i,j,k)*stf_used
367369
! fluid phase
368370
b_accelw_poroelastic(:,iglob) = b_accelw_poroelastic(:,iglob) &
369-
+ fac_w * sourcearrays(isource,:,i,j,k)*stf_used
371+
+ fac_w * sourcearrays(isource,:,i,j,k)*stf_used
370372
enddo
371373
enddo
372374
enddo

src/specfem3D/compute_add_sources_viscoelastic.F90

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ subroutine compute_add_sources_viscoelastic(accel)
7070
double precision :: stf,time_source_dble,time_t
7171
double precision,external :: get_stf_viscoelastic
7272

73-
integer :: isource,iglob,i,j,k,ispec,it_sub_adj
73+
integer :: isource,iglob,i,j,k,ispec,it_sub_adj,it_index
7474
integer :: irec_local,irec
7575

7676
character(len=MAX_STRING_LEN) :: adj_source_file
@@ -230,6 +230,9 @@ subroutine compute_add_sources_viscoelastic(accel)
230230

231231
! adds source term
232232
if (it < NSTEP) then
233+
! time step index for adjoint source (time-reversed)
234+
it_index = NTSTEP_BETWEEN_READ_ADJSRC - mod(it-1,NTSTEP_BETWEEN_READ_ADJSRC)
235+
233236
! receivers act as sources
234237
do irec_local = 1, nadj_rec_local
235238
irec = number_adjsources_global(irec_local)
@@ -244,8 +247,7 @@ subroutine compute_add_sources_viscoelastic(accel)
244247

245248
hlagrange = hxir_adjstore(i,irec_local) * hetar_adjstore(j,irec_local) * hgammar_adjstore(k,irec_local)
246249

247-
accel(:,iglob) = accel(:,iglob) &
248-
+ source_adjoint(:,irec_local,NTSTEP_BETWEEN_READ_ADJSRC - mod(it-1,NTSTEP_BETWEEN_READ_ADJSRC)) * hlagrange
250+
accel(:,iglob) = accel(:,iglob) + source_adjoint(:,irec_local,it_index) * hlagrange
249251
enddo
250252
enddo
251253
enddo

src/specfem3D/compute_arrays_source.f90

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ subroutine compute_arrays_adjoint_source(adj_source_file,irec_local)
213213
character(len=*), intent(in) :: adj_source_file
214214

215215
! local
216-
integer :: icomp, itime, ier, it_start, it_end, it_sub_adj
216+
integer :: icomp, itime, ier, it_start, it_end, it_sub_adj, index_i
217217
real(kind=CUSTOM_REAL), dimension(NTSTEP_BETWEEN_READ_ADJSRC) :: adj_source_asdf
218218
real(kind=CUSTOM_REAL) :: val,junk
219219
! note: should have same order as orientation in write_seismograms_to_file()
@@ -244,8 +244,12 @@ subroutine compute_arrays_adjoint_source(adj_source_file,irec_local)
244244

245245
! store the block we need
246246
do itime = it_start, it_end
247+
248+
! index will run from 1 to NTSTEP_BETWEEN_READ_ADJSRC
249+
index_i = itime - it_start + 1
250+
247251
! store adjoint trace
248-
source_adjoint(icomp,irec_local,itime-it_start+1) = adj_source_asdf(itime-it_start+1)
252+
source_adjoint(icomp,irec_local,index_i) = adj_source_asdf(index_i)
249253
enddo
250254
enddo
251255

@@ -278,8 +282,11 @@ subroutine compute_arrays_adjoint_source(adj_source_file,irec_local)
278282
call exit_MPI(myrank,'file '//trim(filename)//' has wrong length, please check with your simulation duration (2)')
279283
endif
280284

285+
! index will run from 1 to NTSTEP_BETWEEN_READ_ADJSRC
286+
index_i = itime - it_start + 1
287+
281288
! store adjoint trace
282-
source_adjoint(icomp,irec_local,itime-it_start+1) = val
289+
source_adjoint(icomp,irec_local,index_i) = val
283290
enddo
284291

285292
close(IIN)

0 commit comments

Comments
 (0)