@@ -109,9 +109,9 @@ subroutine compute_add_sources_viscoelastic_moving_sources(accel_elastic,it,i_st
109109 ibool,coord,nspec,nglob,xigll,zigll,NPROC, &
110110 xi_source,gamma_source,coorg,knods,NGNOD,npgeo,iglob_source,x_source,z_source, &
111111 vx_source,vz_source,DT,t0,myrank, &
112- time_stepping_scheme,hxis_store,hgammas_store, tshift_src,source_type,ispec_is_acoustic , &
113- hxis,hpxis,hgammas,hpgammas, anglesource,ispec_is_poroelastic ,Mxx,Mxz,Mzz,gammax,gammaz,xix,xiz, &
114- AXISYM,xiglj,is_on_the_axis,initialfield, SOURCE_IS_MOVING
112+ time_stepping_scheme,tshift_src,source_type, &
113+ anglesource,Mxx,Mxz,Mzz,gammax,gammaz,xix,xiz, &
114+ AXISYM,xiglj,is_on_the_axis,SOURCE_IS_MOVING
115115
116116 use moving_sources_par, only: locate_source_moving
117117
@@ -120,11 +120,13 @@ subroutine compute_add_sources_viscoelastic_moving_sources(accel_elastic,it,i_st
120120 real (kind= CUSTOM_REAL), dimension (NDIM,nglob_elastic) :: accel_elastic
121121 integer :: it, i_stage
122122
123- ! local variable
123+ ! local variables
124124 integer :: i_source,i,j,iglob,ispec
125125 real (kind= CUSTOM_REAL) :: stf_used
126- double precision :: hlagrange
127126 double precision :: xsrc,zsrc,timeval,t_used
127+ ! Lagrange interpolators at source position
128+ double precision , dimension (NGLLX) :: hxis,hpxis
129+ double precision , dimension (NGLLZ) :: hgammas,hpgammas
128130 ! single source array
129131 real (kind= CUSTOM_REAL), dimension (NDIM,NGLLX,NGLLZ) :: sourcearray
130132
@@ -165,6 +167,7 @@ subroutine compute_add_sources_viscoelastic_moving_sources(accel_elastic,it,i_st
165167 enddo
166168 endif
167169
170+ ! updates source positions and re-calculates source arrays
168171 do i_source = 1 ,NSOURCES
169172 if (abs (source_time_function(i_source,it,i_stage)) > TINYVAL) then
170173 t_used = (timeval- t0- tshift_src(i_source))
@@ -173,43 +176,28 @@ subroutine compute_add_sources_viscoelastic_moving_sources(accel_elastic,it,i_st
173176 xsrc = x_source(i_source) + vx_source(i_source)* t_used
174177 zsrc = z_source(i_source) + vz_source(i_source)* t_used
175178
176- ! collocated force source
177- if (source_type(i_source) == 1 ) then
178- ! TODO: this would be more efficient compled with first guess as in init_moving_sources_GPU()
179- ! call locate_source_moving(xsrc,zsrc, &
180- ! ispec_selected_source(i_source),islice_selected_source(i_source), &
181- ! NPROC,myrank,xi_source(i_source),gamma_source(i_source),.true.)
182- call locate_source(ibool,coord,nspec,nglob,xigll,zigll, &
183- xsrc,zsrc, &
184- ispec_selected_source(i_source),islice_selected_source(i_source), &
185- NPROC,myrank,xi_source(i_source),gamma_source(i_source),coorg,knods,NGNOD,npgeo, &
186- iglob_source(i_source),.true. )
187-
188- else if (source_type(i_source) == 2 ) then
189- ! moment-tensor source
190- call locate_source(ibool,coord,nspec,nglob,xigll,zigll, &
191- xsrc,zsrc, &
192- ispec_selected_source(i_source),islice_selected_source(i_source), &
193- NPROC,myrank,xi_source(i_source),gamma_source(i_source),coorg,knods,NGNOD,npgeo, &
194- iglob_source(i_source),.false. )
195-
196- else if (.not. initialfield) then
197-
198- call exit_MPI(myrank,' incorrect source type' )
179+ ! gets source positioning
180+ ! TODO: this would be more efficient compled with first guess as in init_moving_sources_GPU()
181+ ! call locate_source_moving(xsrc,zsrc, &
182+ ! ispec_selected_source(i_source),islice_selected_source(i_source), &
183+ ! NPROC,myrank,xi_source(i_source),gamma_source(i_source),..
184+ call locate_source(ibool,coord,nspec,nglob,xigll,zigll, &
185+ xsrc,zsrc, &
186+ ispec_selected_source(i_source),islice_selected_source(i_source), &
187+ NPROC,myrank,xi_source(i_source),gamma_source(i_source),coorg,knods,NGNOD,npgeo, &
188+ iglob_source(i_source),source_type(i_source))
199189
200- endif
190+ if (myrank == islice_selected_source(i_source)) then
191+ ! element containing source
192+ ispec = ispec_selected_source(i_source)
201193
202- ispec = ispec_selected_source(i_source)
194+ ! only for elastic source elements
195+ if (.not. ispec_is_elastic(ispec)) cycle
203196
204- ! source element is elastic
205- if (ispec_is_elastic(ispec)) then
206197 ! Lagrange interpolators
207198 if (AXISYM) then
208199 if (is_on_the_axis(ispec)) then
209200 call lagrange_any(xi_source(i_source),NGLJ,xiglj,hxis,hpxis)
210- ! do j = 1,NGLJ ! ABAB same result with that loop, this is good
211- ! hxis(j) = hglj(j-1,xi_source(i_source),xiglj,NGLJ)
212- ! enddo
213201 else
214202 call lagrange_any(xi_source(i_source),NGLLX,xigll,hxis,hpxis)
215203 endif
@@ -231,79 +219,21 @@ subroutine compute_add_sources_viscoelastic_moving_sources(accel_elastic,it,i_st
231219 endif
232220 endif
233221
234- ! stores Lagrangians for source
235- hxis_store(i_source,:) = hxis(:)
236- hgammas_store(i_source,:) = hgammas(:)
237-
222+ ! computes source arrays
238223 sourcearray(:,:,:) = 0._CUSTOM_REAL
239224
240- ! computes source arrays
241225 select case (source_type(i_source))
242226 case (1 )
243227 ! collocated force source
244- do j = 1 ,NGLLZ
245- do i = 1 ,NGLLX
246- hlagrange = hxis_store(i_source,i) * hgammas_store(i_source,j)
247-
248- ! source element is acoustic
249- if (ispec_is_acoustic(ispec)) then
250- sourcearray(:,i,j) = real (hlagrange,kind= CUSTOM_REAL)
251- endif
252-
253- ! source element is elastic
254- if (ispec_is_elastic(ispec)) then
255- if (P_SV) then
256- ! P_SV case
257- ! sourcearray(1,i,j) = real(- sin(anglesource(i_source)) * hlagrange,kind=CUSTOM_REAL)
258- ! sourcearray(2,i,j) = real( cos(anglesource(i_source)) * hlagrange,kind=CUSTOM_REAL)
259- ! ! DK DK May 2018: the sign of the source was inverted compared to the analytical solution for a simple elastic benchmark
260- ! ! DK DK May 2018: with a force source (the example that is in EXAMPLES/check_absolute_amplitude_of_force_source_seismograms),
261- ! ! DK DK May 2018: which means that the sign was not right here. I changed it. Please do NOT revert that change,
262- ! ! DK DK May 2018: otherwise the code will give inverted seismograms compared to analytical solutions for benchmarks,
263- ! ! DK DK May 2018: and more generally compared to reality
264- sourcearray(1 ,i,j) = real (+ sin (anglesource(i_source)) * hlagrange,kind= CUSTOM_REAL)
265- sourcearray(2 ,i,j) = real (- cos (anglesource(i_source)) * hlagrange,kind= CUSTOM_REAL)
266- else
267- ! SH case (membrane)
268- sourcearray(:,i,j) = real (hlagrange,kind= CUSTOM_REAL)
269- endif
270- endif
271-
272- ! source element is poroelastic
273- if (ispec_is_poroelastic(ispec)) then
274- ! sourcearray(1,i,j) = real(- sin(anglesource(i_source)) * hlagrange,kind=CUSTOM_REAL)
275- ! sourcearray(2,i,j) = real( cos(anglesource(i_source)) * hlagrange,kind=CUSTOM_REAL)
276- ! ! DK DK May 2018: the sign of the source was inverted compared to the analytical solution for a simple elastic benchmark
277- ! ! DK DK May 2018: with a force source (the example that is in EXAMPLES/check_absolute_amplitude_of_force_source_seismograms),
278- ! ! DK DK May 2018: which means that the sign was not right here. I changed it. Please do NOT revert that change,
279- ! ! DK DK May 2018: otherwise the code will give inverted seismograms compared to analytical solutions for benchmarks,
280- ! ! DK DK May 2018: and more generally compared to reality
281- sourcearray(1 ,i,j) = real (+ sin (anglesource(i_source)) * hlagrange,kind= CUSTOM_REAL)
282- sourcearray(2 ,i,j) = real (- cos (anglesource(i_source)) * hlagrange,kind= CUSTOM_REAL)
283- endif
284-
285- enddo
286- enddo
287-
228+ call compute_arrays_source_forcesolution(ispec,hxis,hgammas,sourcearray,anglesource(i_source))
288229 case (2 )
289230 ! moment-tensor source
290- call compute_arrays_source(ispec,xi_source(i_source),gamma_source(i_source),sourcearray, &
291- Mxx(i_source),Mzz(i_source),Mxz(i_source),xix,xiz,gammax,gammaz,xigll,zigll,nspec)
292- ! checks source
293- if (ispec_is_acoustic(ispec)) then
294- call exit_MPI(myrank,' cannot have moment tensor source in acoustic element' )
295- endif
296-
297- ! checks wave type
298- if (ispec_is_elastic(ispec)) then
299- if (.not. P_SV ) call exit_MPI(myrank,' cannot have moment tensor source in SH (membrane) waves calculation' )
300- endif
301-
231+ call compute_arrays_source_cmt(ispec,hxis,hgammas,hpxis,hpgammas,sourcearray, &
232+ Mxx(i_source),Mzz(i_source),Mxz(i_source),xix,xiz,gammax,gammaz,nspec)
302233 end select
303234
304235 ! stores sourcearray for all sources
305236 sourcearrays(:,:,:,i_source) = sourcearray(:,:,:)
306-
307237 endif
308238 endif
309239 enddo
0 commit comments