@@ -36,7 +36,9 @@ subroutine get_elevation_and_z_coordinate_all(npoints,plon,plat,pbur,utm_x,utm_y
3636
3737 use constants, only: CUSTOM_REAL,HUGEVAL,ILONGLAT2UTM
3838 use specfem_par, only: ibool,myrank,NSPEC_AB,NGLOB_AB,USE_SOURCES_RECEIVERS_Z, &
39- xstore,ystore,zstore,NPROC,num_free_surface_faces,free_surface_ispec,free_surface_ijk
39+ xstore,ystore,zstore,NPROC,num_free_surface_faces,free_surface_ispec,free_surface_ijk, &
40+ NSPEC2D_BOTTOM
41+ use shared_parameters, only: BOTTOM_FREE_SURFACE
4042 implicit none
4143
4244 integer , intent (in ) :: npoints
@@ -52,6 +54,7 @@ subroutine get_elevation_and_z_coordinate_all(npoints,plon,plat,pbur,utm_x,utm_y
5254 double precision , dimension (:,:), allocatable :: elevation_all,elevation_distmin_all
5355 real (kind= CUSTOM_REAL) :: xloc,yloc,loc_ele,loc_distmin
5456 integer :: iproc,ier
57+ integer :: num_topo_faces, iface_offset
5558
5659 ! debug
5760 ! print *,'get elevation: ',npoints
@@ -107,6 +110,16 @@ subroutine get_elevation_and_z_coordinate_all(npoints,plon,plat,pbur,utm_x,utm_y
107110 elevation_all(:,:) = 0.d0
108111 elevation_distmin_all(:,:) = HUGEVAL
109112
113+ ! when the bottom is a free surface, its faces are stored first in free_surface_ispec
114+ ! (bottom faces are filled before top faces in get_absorbing_boundary.F90).
115+ ! skip those bottom faces so elevation is always taken from the top surface.
116+ if (BOTTOM_FREE_SURFACE) then
117+ iface_offset = NSPEC2D_BOTTOM
118+ else
119+ iface_offset = 0
120+ endif
121+ num_topo_faces = num_free_surface_faces - iface_offset
122+
110123 ! gets elevation
111124 do ipoin = 1 , npoints
112125 xloc = x_target(ipoin)
@@ -115,7 +128,7 @@ subroutine get_elevation_and_z_coordinate_all(npoints,plon,plat,pbur,utm_x,utm_y
115128 ! get approximate topography elevation at point x/y coordinates
116129 call get_topo_elevation_free(xloc,yloc,loc_ele,loc_distmin, &
117130 NSPEC_AB,NGLOB_AB,ibool,xstore,ystore,zstore, &
118- num_free_surface_faces ,free_surface_ispec,free_surface_ijk)
131+ num_topo_faces ,free_surface_ispec(iface_offset +1 :) ,free_surface_ijk(:,:,iface_offset +1 :) )
119132
120133 elevation(ipoin) = loc_ele
121134 elevation_distmin(ipoin) = loc_distmin
@@ -166,7 +179,9 @@ subroutine get_elevation_and_z_coordinate(lon,lat,utm_x,utm_y,z_target,elevation
166179
167180 use constants
168181 use specfem_par, only: USE_SOURCES_RECEIVERS_Z,ibool,myrank,NSPEC_AB,NGLOB_AB, &
169- xstore,ystore,zstore,NPROC,num_free_surface_faces,free_surface_ispec,free_surface_ijk
182+ xstore,ystore,zstore,NPROC,num_free_surface_faces,free_surface_ispec,free_surface_ijk, &
183+ NSPEC2D_BOTTOM
184+ use shared_parameters, only: BOTTOM_FREE_SURFACE
170185
171186 implicit none
172187
@@ -179,6 +194,7 @@ subroutine get_elevation_and_z_coordinate(lon,lat,utm_x,utm_y,z_target,elevation
179194 double precision ,dimension (1 ) :: altitude_rec,distmin_ele
180195 double precision ,dimension (NPROC) :: distmin_ele_all,elevation_all
181196 real (kind= CUSTOM_REAL) :: xloc,yloc,loc_ele,loc_distmin
197+ integer :: num_topo_faces,iface_offset
182198
183199 ! convert station location to UTM
184200 call utm_geo(lon,lat,utm_x,utm_y,ILONGLAT2UTM)
@@ -194,10 +210,19 @@ subroutine get_elevation_and_z_coordinate(lon,lat,utm_x,utm_y,z_target,elevation
194210 return
195211 endif
196212
213+ ! when the bottom is a free surface, its faces are stored first in free_surface_ispec;
214+ ! skip them so elevation is always taken from the top surface.
215+ if (BOTTOM_FREE_SURFACE) then
216+ iface_offset = NSPEC2D_BOTTOM
217+ else
218+ iface_offset = 0
219+ endif
220+ num_topo_faces = num_free_surface_faces - iface_offset
221+
197222 ! get approximate topography elevation at point long/lat coordinates
198223 call get_topo_elevation_free(xloc,yloc,loc_ele,loc_distmin, &
199224 NSPEC_AB,NGLOB_AB,ibool,xstore,ystore,zstore, &
200- num_free_surface_faces ,free_surface_ispec,free_surface_ijk)
225+ num_topo_faces ,free_surface_ispec(iface_offset +1 :) ,free_surface_ijk(:,:,iface_offset +1 :) )
201226
202227 altitude_rec(1 ) = loc_ele
203228 distmin_ele(1 ) = loc_distmin
0 commit comments