Skip to content

Commit 056d6a8

Browse files
authored
Merge pull request #1756 from danielpeter/devel
updates point search to prefer slices that contain point locations inside elements
2 parents a5bb135 + f1aed57 commit 056d6a8

18 files changed

+585
-365
lines changed

src/generate_databases/model_external_values.F90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ subroutine model_external_broadcast()
9494
if (myrank == 0) call read_external_model()
9595

9696
! broadcast the information read on the main to the nodes
97-
call bcast_all_dp(MEXT_V%dvs, size(MEXT_V%dvs))
97+
call bcast_all_dp(MEXT_V%dvs, size(MEXT_V%dvs,kind=4))
9898

9999
end subroutine model_external_broadcast
100100

src/generate_databases/model_salton_trough.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ subroutine model_salton_trough_broadcast()
7171
if (myrank == 0) call read_salton_sea_model()
7272

7373
! broadcast the information read on the main to the nodes
74-
call bcast_all_r(vp_array, size(vp_array))
74+
call bcast_all_r(vp_array, size(vp_array,kind=4))
7575

7676
end subroutine model_salton_trough_broadcast
7777

src/generate_databases/model_tomography.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ subroutine model_tomography_broadcast(myrank)
121121
! allocate( vp_tomography(1:nrecord) ,stat=ier)
122122
! if (ier /= 0) stop 'error allocating array vp_tomography'
123123
!endif
124-
!call bcast_all_cr(vp_tomography,size(vp_tomography))
124+
!call bcast_all_cr(vp_tomography,size(vp_tomography,kind=4))
125125

126126
! synchronizes processes
127127
call synchronize_all()

src/generate_databases/setup_mesh_adjacency.f90

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ subroutine setup_mesh_adjacency()
3131
! setups mesh adjacency array to search element neighbors for point searches
3232

3333
use constants, only: myrank, &
34-
NDIM,NGLLX,NGLLY,NGLLZ,MIDX,MIDY,MIDZ,IMAIN,CUSTOM_REAL,MAX_STRING_LEN
34+
NGLLX,NGLLY,NGLLZ,MIDX,MIDY,MIDZ,IMAIN,MAX_STRING_LEN
3535

3636
use generate_databases_par, only: NSPEC_AB,NGLOB_AB,ibool,NPROC,prname
3737

@@ -255,7 +255,8 @@ subroutine setup_mesh_adjacency()
255255
else
256256
! no neighbors
257257
! warning
258-
print *,'*** Warning: found mesh element with no neighbors : slice ',myrank,' - element ',ispec_ref,' ***'
258+
print *,'*** Warning: found mesh element with no neighbors : slice ',myrank, &
259+
' - element ',ispec_ref,'out of',NSPEC_AB,' ***'
259260
endif
260261

261262
! again loop to get neighbors of neighbors
@@ -377,7 +378,7 @@ subroutine setup_mesh_adjacency()
377378
endif
378379

379380
! check if element has neighbors
380-
! note: in case of a fault in this slice (splitting nodes) and/or scotch paritioning
381+
! note: in case of a fault in this slice (splitting nodes) and/or scotch partitioning
381382
! it can happen that an element has no neighbors
382383
if (NPROC == 1 .and. (.not. ANY_FAULT_IN_THIS_PROC)) then
383384
! checks if neighbors were found

src/meshfem3D/determine_cavity.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,13 +366,13 @@ subroutine cmm_determine_cavity(nglob)
366366
allocate(tmp_all(1,1),stat=ier)
367367
if (ier /= 0) call exit_MPI_without_rank('error allocating array 1330')
368368
endif
369-
call sum_all_1Darray_dp(cavity_boundary,tmp_all,size(cavity_boundary))
369+
call sum_all_1Darray_dp(cavity_boundary,tmp_all,size(cavity_boundary,kind=4))
370370
if (myrank == 0) then
371371
cavity_boundary(:,:) = tmp_all(:,:)
372372
endif
373373
deallocate(tmp_all)
374374
! broadcasts to all others
375-
call bcast_all_dp(cavity_boundary,size(cavity_boundary))
375+
call bcast_all_dp(cavity_boundary,size(cavity_boundary,kind=4))
376376

377377
!print *,'cavity boundary after:',myrank,'array:',cavity_boundary(:,:)
378378

src/shared/recompute_jacobian.f90

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
subroutine recompute_jacobian(xelm,yelm,zelm,xi,eta,gamma,x,y,z, &
3131
xix,xiy,xiz,etax,etay,etaz,gammax,gammay,gammaz,NGNOD)
3232

33-
use constants, only: NDIM,ZERO
33+
use constants, only: NDIM,ZERO,myrank
3434

3535
implicit none
3636

@@ -56,7 +56,7 @@ subroutine recompute_jacobian(xelm,yelm,zelm,xi,eta,gamma,x,y,z, &
5656

5757
! recompute jacobian for any (xi,eta,gamma) point, not necessarily a GLL point
5858

59-
! check that the parameter file is correct
59+
! check that the parameter file is correct
6060
if (NGNOD /= 8 .and. NGNOD /= 27) stop 'elements should have 8 or 27 control nodes'
6161

6262
if (NGNOD == 8) then
@@ -71,51 +71,66 @@ subroutine recompute_jacobian(xelm,yelm,zelm,xi,eta,gamma,x,y,z, &
7171
x = ZERO
7272
y = ZERO
7373
z = ZERO
74+
7475
xxi = ZERO
7576
xeta = ZERO
7677
xgamma = ZERO
78+
7779
yxi = ZERO
7880
yeta = ZERO
7981
ygamma = ZERO
82+
8083
zxi = ZERO
8184
zeta = ZERO
8285
zgamma = ZERO
8386

8487
do ia = 1,NGNOD
85-
x = x+shape3D(ia)*xelm(ia)
86-
y = y+shape3D(ia)*yelm(ia)
87-
z = z+shape3D(ia)*zelm(ia)
88+
x = x + shape3D(ia) * xelm(ia)
89+
y = y + shape3D(ia) * yelm(ia)
90+
z = z + shape3D(ia) * zelm(ia)
8891

8992
! Jacobian matrix elements
9093
! dx/dxi, dx/deta, etc.
91-
xxi = xxi+dershape3D(1,ia)*xelm(ia)
92-
xeta = xeta+dershape3D(2,ia)*xelm(ia)
93-
xgamma = xgamma+dershape3D(3,ia)*xelm(ia)
94-
yxi = yxi+dershape3D(1,ia)*yelm(ia)
95-
yeta = yeta+dershape3D(2,ia)*yelm(ia)
96-
ygamma = ygamma+dershape3D(3,ia)*yelm(ia)
97-
zxi = zxi+dershape3D(1,ia)*zelm(ia)
98-
zeta = zeta+dershape3D(2,ia)*zelm(ia)
99-
zgamma = zgamma+dershape3D(3,ia)*zelm(ia)
94+
xxi = xxi + dershape3D(1,ia)*xelm(ia)
95+
xeta = xeta + dershape3D(2,ia)*xelm(ia)
96+
xgamma = xgamma + dershape3D(3,ia)*xelm(ia)
97+
98+
yxi = yxi + dershape3D(1,ia)*yelm(ia)
99+
yeta = yeta + dershape3D(2,ia)*yelm(ia)
100+
ygamma = ygamma + dershape3D(3,ia)*yelm(ia)
101+
102+
zxi = zxi + dershape3D(1,ia)*zelm(ia)
103+
zeta = zeta + dershape3D(2,ia)*zelm(ia)
104+
zgamma = zgamma + dershape3D(3,ia)*zelm(ia)
100105
enddo
101106

102107
! Jacobian determinant
103108
jacobian = xxi*(yeta*zgamma-ygamma*zeta) - xeta*(yxi*zgamma-ygamma*zxi) + xgamma*(yxi*zeta-yeta*zxi)
104109

105-
if (jacobian <= ZERO) stop '3D Jacobian undefined'
110+
if (jacobian <= ZERO) then
111+
! info
112+
print *,'Error Jacobian rank:',myrank,'has invalid Jacobian ',jacobian
113+
print *,' input xi/eta/gamma: ',xi,eta,gamma
114+
print *,' Jacobian: ',jacobian,'xxi',xxi,xeta,xgamma,'yxi',yxi,yeta,ygamma,'zxi',zxi,zeta,zgamma
115+
print *,' location x/y/z: ',x,y,z
116+
117+
stop '3D Jacobian undefined'
118+
endif
106119

107120
! inverse Jacobian matrix
108121
!
109122
! invert the relation (Fletcher p. 50 vol. 2)
110-
xix = (yeta*zgamma-ygamma*zeta)/jacobian
111-
xiy = (xgamma*zeta-xeta*zgamma)/jacobian
112-
xiz = (xeta*ygamma-xgamma*yeta)/jacobian
113-
etax = (ygamma*zxi-yxi*zgamma)/jacobian
114-
etay = (xxi*zgamma-xgamma*zxi)/jacobian
115-
etaz = (xgamma*yxi-xxi*ygamma)/jacobian
116-
gammax = (yxi*zeta-yeta*zxi)/jacobian
117-
gammay = (xeta*zxi-xxi*zeta)/jacobian
118-
gammaz = (xxi*yeta-xeta*yxi)/jacobian
123+
xix = (yeta*zgamma - ygamma*zeta) / jacobian
124+
xiy = (xgamma*zeta - xeta*zgamma) / jacobian
125+
xiz = (xeta*ygamma - xgamma*yeta) / jacobian
126+
127+
etax = (ygamma*zxi - yxi*zgamma) / jacobian
128+
etay = (xxi*zgamma - xgamma*zxi) / jacobian
129+
etaz = (xgamma*yxi - xxi*ygamma) / jacobian
130+
131+
gammax = (yxi*zeta - yeta*zxi) / jacobian
132+
gammay = (xeta*zxi - xxi*zeta) / jacobian
133+
gammaz = (xxi*yeta - xeta*yxi) / jacobian
119134

120135
end subroutine recompute_jacobian
121136

src/specfem3D/iterate_time.F90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,9 +418,9 @@ subroutine it_transfer_from_GPU()
418418

419419
if (ATTENUATION) then
420420
call transfer_rmemory_from_device(Mesh_pointer,R_xx,R_yy,R_xy,R_xz,R_yz, &
421-
R_trace,size(R_xx))
421+
R_trace,size(R_xx,kind=4))
422422
call transfer_strain_from_device(Mesh_pointer,epsilondev_xx,epsilondev_yy,epsilondev_xy,epsilondev_xz,epsilondev_yz, &
423-
epsilondev_trace,size(epsilondev_xx))
423+
epsilondev_trace,size(epsilondev_xx,kind=4))
424424

425425
endif
426426
endif

src/specfem3D/locate_MPI_slice.f90

Lines changed: 116 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,17 @@ subroutine locate_MPI_slice(npoints_subset,ipoin_already_done, &
6969
double precision, dimension(npoints_subset,0:NPROC-1) :: final_distance_all
7070
double precision, dimension(NDIM,NDIM,npoints_subset,0:NPROC-1) :: nu_all
7171

72+
double precision :: xi,eta,gamma
73+
74+
! point inside element
75+
logical :: found_point_inside
76+
77+
! prefer slice with point location inside element rather than just selecting slice with closest location
78+
logical, parameter :: DO_PREFER_INSIDE_ELEMENT = .true.
79+
80+
!debug
81+
!integer,dimension(1) :: iproc_min
82+
7283
! initializes with dummy values
7384
ispec_selected_all(:,:) = -1
7485
idomain_all(:,:) = -1000
@@ -98,33 +109,117 @@ subroutine locate_MPI_slice(npoints_subset,ipoin_already_done, &
98109
! find the slice and element to put the source
99110
if (myrank == 0) then
100111

101-
! loops over subset
102-
do ipoin_in_this_subset = 1,npoints_subset
112+
! we prefer slices with point locations inside an element over slices with a closer point distance
113+
! but a point location outside the (best) element
114+
if (DO_PREFER_INSIDE_ELEMENT) then
115+
116+
! loops over subset
117+
do ipoin_in_this_subset = 1,npoints_subset
118+
! mapping from station/source number in current subset to real station/source number in all the subsets
119+
ipoin = ipoin_in_this_subset + ipoin_already_done
120+
121+
! checks first if we have a close point inside an element
122+
found_point_inside = .false.
123+
distmin = HUGEVAL
124+
do iproc = 0,NPROC-1
125+
! point position
126+
xi = xi_all(ipoin_in_this_subset,iproc)
127+
eta = eta_all(ipoin_in_this_subset,iproc)
128+
gamma = gamma_all(ipoin_in_this_subset,iproc)
129+
130+
! points inside an element have xi/eta/gamma <= 1.0
131+
if (abs(xi) <= 1.d0 .and. abs(eta) <= 1.d0 .and. abs(gamma) <= 1.d0) then
132+
! takes point if closer
133+
if (final_distance_all(ipoin_in_this_subset,iproc) < distmin) then
134+
found_point_inside = .true.
135+
136+
xi_point(ipoin) = xi
137+
eta_point(ipoin) = eta
138+
gamma_point(ipoin) = gamma
139+
140+
distmin = final_distance_all(ipoin_in_this_subset,iproc)
141+
142+
islice_selected(ipoin) = iproc
143+
ispec_selected(ipoin) = ispec_selected_all(ipoin_in_this_subset,iproc)
144+
idomain(ipoin) = idomain_all(ipoin_in_this_subset,iproc)
145+
146+
nu_point(:,:,ipoin) = nu_all(:,:,ipoin_in_this_subset,iproc)
147+
148+
x_found(ipoin) = x_found_all(ipoin_in_this_subset,iproc)
149+
y_found(ipoin) = y_found_all(ipoin_in_this_subset,iproc)
150+
z_found(ipoin) = z_found_all(ipoin_in_this_subset,iproc)
151+
endif
152+
endif
153+
enddo
154+
155+
! if we haven't found a close point inside an element, then look for just the closest possible
156+
if (.not. found_point_inside) then
157+
do iproc = 0,NPROC-1
158+
if (final_distance_all(ipoin_in_this_subset,iproc) < distmin) then
159+
distmin = final_distance_all(ipoin_in_this_subset,iproc)
160+
161+
islice_selected(ipoin) = iproc
162+
ispec_selected(ipoin) = ispec_selected_all(ipoin_in_this_subset,iproc)
163+
idomain(ipoin) = idomain_all(ipoin_in_this_subset,iproc)
164+
165+
xi_point(ipoin) = xi_all(ipoin_in_this_subset,iproc)
166+
eta_point(ipoin) = eta_all(ipoin_in_this_subset,iproc)
167+
gamma_point(ipoin) = gamma_all(ipoin_in_this_subset,iproc)
168+
169+
nu_point(:,:,ipoin) = nu_all(:,:,ipoin_in_this_subset,iproc)
170+
171+
x_found(ipoin) = x_found_all(ipoin_in_this_subset,iproc)
172+
y_found(ipoin) = y_found_all(ipoin_in_this_subset,iproc)
173+
z_found(ipoin) = z_found_all(ipoin_in_this_subset,iproc)
174+
endif
175+
enddo
176+
endif
103177

104-
! mapping from station/source number in current subset to real station/source number in all the subsets
105-
ipoin = ipoin_in_this_subset + ipoin_already_done
178+
final_distance(ipoin) = distmin
179+
180+
!debug
181+
!iproc_min = minloc(final_distance_all(ipoin_in_this_subset,:)) - 1 ! -1 to start procs at 0
182+
!print *,'debug: locate MPI point',ipoin,ipoin_in_this_subset,'dist',final_distance_all(ipoin_in_this_subset,:), &
183+
! 'iproc min',iproc_min(1), &
184+
! 'xi min',xi_all(ipoin_in_this_subset,iproc_min(1)), &
185+
! eta_all(ipoin_in_this_subset,iproc_min(1)), &
186+
! gamma_all(ipoin_in_this_subset,iproc_min(1)), &
187+
! 'iproc found',islice_selected(ipoin),'dist found',final_distance(ipoin), &
188+
! 'xi found',xi_point(ipoin),eta_point(ipoin),gamma_point(ipoin)
189+
enddo
106190

107-
distmin = HUGEVAL
108-
do iproc = 0,NPROC-1
109-
if (final_distance_all(ipoin_in_this_subset,iproc) < distmin) then
110-
distmin = final_distance_all(ipoin_in_this_subset,iproc)
191+
else
192+
! old version takes closest point
111193

112-
islice_selected(ipoin) = iproc
113-
ispec_selected(ipoin) = ispec_selected_all(ipoin_in_this_subset,iproc)
114-
idomain(ipoin) = idomain_all(ipoin_in_this_subset,iproc)
194+
! loops over subset
195+
do ipoin_in_this_subset = 1,npoints_subset
115196

116-
xi_point(ipoin) = xi_all(ipoin_in_this_subset,iproc)
117-
eta_point(ipoin) = eta_all(ipoin_in_this_subset,iproc)
118-
gamma_point(ipoin) = gamma_all(ipoin_in_this_subset,iproc)
119-
nu_point(:,:,ipoin) = nu_all(:,:,ipoin_in_this_subset,iproc)
197+
! mapping from station/source number in current subset to real station/source number in all the subsets
198+
ipoin = ipoin_in_this_subset + ipoin_already_done
120199

121-
x_found(ipoin) = x_found_all(ipoin_in_this_subset,iproc)
122-
y_found(ipoin) = y_found_all(ipoin_in_this_subset,iproc)
123-
z_found(ipoin) = z_found_all(ipoin_in_this_subset,iproc)
124-
endif
200+
distmin = HUGEVAL
201+
do iproc = 0,NPROC-1
202+
if (final_distance_all(ipoin_in_this_subset,iproc) < distmin) then
203+
distmin = final_distance_all(ipoin_in_this_subset,iproc)
204+
205+
islice_selected(ipoin) = iproc
206+
ispec_selected(ipoin) = ispec_selected_all(ipoin_in_this_subset,iproc)
207+
idomain(ipoin) = idomain_all(ipoin_in_this_subset,iproc)
208+
209+
xi_point(ipoin) = xi_all(ipoin_in_this_subset,iproc)
210+
eta_point(ipoin) = eta_all(ipoin_in_this_subset,iproc)
211+
gamma_point(ipoin) = gamma_all(ipoin_in_this_subset,iproc)
212+
nu_point(:,:,ipoin) = nu_all(:,:,ipoin_in_this_subset,iproc)
213+
214+
x_found(ipoin) = x_found_all(ipoin_in_this_subset,iproc)
215+
y_found(ipoin) = y_found_all(ipoin_in_this_subset,iproc)
216+
z_found(ipoin) = z_found_all(ipoin_in_this_subset,iproc)
217+
endif
218+
enddo
219+
final_distance(ipoin) = distmin
125220
enddo
126-
final_distance(ipoin) = distmin
127-
enddo
221+
222+
endif
128223

129224
endif ! end of section executed by main process only
130225

0 commit comments

Comments
 (0)