-
Notifications
You must be signed in to change notification settings - Fork 220
/
get_jacobian_boundaries.f90
334 lines (259 loc) · 10.8 KB
/
get_jacobian_boundaries.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
!=====================================================================
!
! S p e c f e m 3 D V e r s i o n 1 . 4
! ---------------------------------------
!
! Dimitri Komatitsch and Jeroen Tromp
! Seismological Laboratory - California Institute of Technology
! (c) California Institute of Technology September 2006
!
! This program is free software; you can redistribute it and/or modify
! it under the terms of the GNU General Public License as published by
! the Free Software Foundation; either version 2 of the License, or
! (at your option) any later version.
!
! This program is distributed in the hope that it will be useful,
! but WITHOUT ANY WARRANTY; without even the implied warranty of
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
! GNU General Public License for more details.
!
! You should have received a copy of the GNU General Public License along
! with this program; if not, write to the Free Software Foundation, Inc.,
! 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
!
!=====================================================================
subroutine get_jacobian_boundaries(myrank,iboun,nspec,xstore,ystore,zstore, &
dershape2D_x,dershape2D_y,dershape2D_bottom,dershape2D_top, &
ibelm_xmin,ibelm_xmax,ibelm_ymin,ibelm_ymax,ibelm_bottom,ibelm_top, &
nspec2D_xmin,nspec2D_xmax,nspec2D_ymin,nspec2D_ymax, &
jacobian2D_xmin,jacobian2D_xmax, &
jacobian2D_ymin,jacobian2D_ymax, &
jacobian2D_bottom,jacobian2D_top, &
normal_xmin,normal_xmax, &
normal_ymin,normal_ymax, &
normal_bottom,normal_top, &
NSPEC2D_BOTTOM,NSPEC2D_TOP, &
NSPEC2DMAX_XMIN_XMAX,NSPEC2DMAX_YMIN_YMAX)
implicit none
include "constants.h"
integer nspec,myrank
integer NSPEC2D_BOTTOM,NSPEC2D_TOP,NSPEC2DMAX_XMIN_XMAX,NSPEC2DMAX_YMIN_YMAX
integer nspec2D_xmin,nspec2D_xmax,nspec2D_ymin,nspec2D_ymax
integer ibelm_xmin(NSPEC2DMAX_XMIN_XMAX),ibelm_xmax(NSPEC2DMAX_XMIN_XMAX)
integer ibelm_ymin(NSPEC2DMAX_YMIN_YMAX),ibelm_ymax(NSPEC2DMAX_YMIN_YMAX)
integer ibelm_bottom(NSPEC2D_BOTTOM),ibelm_top(NSPEC2D_TOP)
logical iboun(6,nspec)
double precision xstore(NGLLX,NGLLY,NGLLZ,nspec)
double precision ystore(NGLLX,NGLLY,NGLLZ,nspec)
double precision zstore(NGLLX,NGLLY,NGLLZ,nspec)
real(kind=CUSTOM_REAL) jacobian2D_xmin(NGLLY,NGLLZ,NSPEC2DMAX_XMIN_XMAX)
real(kind=CUSTOM_REAL) jacobian2D_xmax(NGLLY,NGLLZ,NSPEC2DMAX_XMIN_XMAX)
real(kind=CUSTOM_REAL) jacobian2D_ymin(NGLLX,NGLLZ,NSPEC2DMAX_YMIN_YMAX)
real(kind=CUSTOM_REAL) jacobian2D_ymax(NGLLX,NGLLZ,NSPEC2DMAX_YMIN_YMAX)
real(kind=CUSTOM_REAL) jacobian2D_bottom(NGLLX,NGLLY,NSPEC2D_BOTTOM)
real(kind=CUSTOM_REAL) jacobian2D_top(NGLLX,NGLLY,NSPEC2D_TOP)
real(kind=CUSTOM_REAL) normal_xmin(NDIM,NGLLY,NGLLZ,NSPEC2DMAX_XMIN_XMAX)
real(kind=CUSTOM_REAL) normal_xmax(NDIM,NGLLY,NGLLZ,NSPEC2DMAX_XMIN_XMAX)
real(kind=CUSTOM_REAL) normal_ymin(NDIM,NGLLX,NGLLZ,NSPEC2DMAX_YMIN_YMAX)
real(kind=CUSTOM_REAL) normal_ymax(NDIM,NGLLX,NGLLZ,NSPEC2DMAX_YMIN_YMAX)
real(kind=CUSTOM_REAL) normal_bottom(NDIM,NGLLX,NGLLY,NSPEC2D_BOTTOM)
real(kind=CUSTOM_REAL) normal_top(NDIM,NGLLX,NGLLY,NSPEC2D_TOP)
double precision dershape2D_x(NDIM2D,NGNOD2D,NGLLY,NGLLZ)
double precision dershape2D_y(NDIM2D,NGNOD2D,NGLLX,NGLLZ)
double precision dershape2D_bottom(NDIM2D,NGNOD2D,NGLLX,NGLLY)
double precision dershape2D_top(NDIM2D,NGNOD2D,NGLLX,NGLLY)
! global element numbering
integer ispec
! counters to keep track of number of elements on each of the boundaries
integer ispecb1,ispecb2,ispecb3,ispecb4,ispecb5,ispecb6
double precision xelm(NGNOD2D),yelm(NGNOD2D),zelm(NGNOD2D)
! check that the parameter file is correct
if(NGNOD /= 8) call exit_MPI(myrank,'elements should have 8 control nodes')
if(NGNOD2D /= 4) call exit_MPI(myrank,'surface elements should have 4 control nodes')
ispecb1 = 0
ispecb2 = 0
ispecb3 = 0
ispecb4 = 0
ispecb5 = 0
ispecb6 = 0
do ispec=1,nspec
! determine if the element falls on a boundary
! on boundary: xmin
if(iboun(1,ispec)) then
ispecb1=ispecb1+1
ibelm_xmin(ispecb1)=ispec
! specify the 4 nodes for the 2-D boundary element
xelm(1)=xstore(1,1,1,ispec)
yelm(1)=ystore(1,1,1,ispec)
zelm(1)=zstore(1,1,1,ispec)
xelm(2)=xstore(1,NGLLY,1,ispec)
yelm(2)=ystore(1,NGLLY,1,ispec)
zelm(2)=zstore(1,NGLLY,1,ispec)
xelm(3)=xstore(1,NGLLY,NGLLZ,ispec)
yelm(3)=ystore(1,NGLLY,NGLLZ,ispec)
zelm(3)=zstore(1,NGLLY,NGLLZ,ispec)
xelm(4)=xstore(1,1,NGLLZ,ispec)
yelm(4)=ystore(1,1,NGLLZ,ispec)
zelm(4)=zstore(1,1,NGLLZ,ispec)
call compute_jacobian_2D(myrank,ispecb1,xelm,yelm,zelm,dershape2D_x, &
jacobian2D_xmin,normal_xmin,NGLLY,NGLLZ,NSPEC2DMAX_XMIN_XMAX)
endif
! on boundary: xmax
if(iboun(2,ispec)) then
ispecb2=ispecb2+1
ibelm_xmax(ispecb2)=ispec
! specify the 4 nodes for the 2-D boundary element
xelm(1)=xstore(NGLLX,1,1,ispec)
yelm(1)=ystore(NGLLX,1,1,ispec)
zelm(1)=zstore(NGLLX,1,1,ispec)
xelm(2)=xstore(NGLLX,NGLLY,1,ispec)
yelm(2)=ystore(NGLLX,NGLLY,1,ispec)
zelm(2)=zstore(NGLLX,NGLLY,1,ispec)
xelm(3)=xstore(NGLLX,NGLLY,NGLLZ,ispec)
yelm(3)=ystore(NGLLX,NGLLY,NGLLZ,ispec)
zelm(3)=zstore(NGLLX,NGLLY,NGLLZ,ispec)
xelm(4)=xstore(NGLLX,1,NGLLZ,ispec)
yelm(4)=ystore(NGLLX,1,NGLLZ,ispec)
zelm(4)=zstore(NGLLX,1,NGLLZ,ispec)
call compute_jacobian_2D(myrank,ispecb2,xelm,yelm,zelm,dershape2D_x, &
jacobian2D_xmax,normal_xmax,NGLLY,NGLLZ,NSPEC2DMAX_XMIN_XMAX)
endif
! on boundary: ymin
if(iboun(3,ispec)) then
ispecb3=ispecb3+1
ibelm_ymin(ispecb3)=ispec
! specify the 4 nodes for the 2-D boundary element
xelm(1)=xstore(1,1,1,ispec)
yelm(1)=ystore(1,1,1,ispec)
zelm(1)=zstore(1,1,1,ispec)
xelm(2)=xstore(NGLLX,1,1,ispec)
yelm(2)=ystore(NGLLX,1,1,ispec)
zelm(2)=zstore(NGLLX,1,1,ispec)
xelm(3)=xstore(NGLLX,1,NGLLZ,ispec)
yelm(3)=ystore(NGLLX,1,NGLLZ,ispec)
zelm(3)=zstore(NGLLX,1,NGLLZ,ispec)
xelm(4)=xstore(1,1,NGLLZ,ispec)
yelm(4)=ystore(1,1,NGLLZ,ispec)
zelm(4)=zstore(1,1,NGLLZ,ispec)
call compute_jacobian_2D(myrank,ispecb3,xelm,yelm,zelm,dershape2D_y, &
jacobian2D_ymin,normal_ymin,NGLLX,NGLLZ,NSPEC2DMAX_YMIN_YMAX)
endif
! on boundary: ymax
if(iboun(4,ispec)) then
ispecb4=ispecb4+1
ibelm_ymax(ispecb4)=ispec
! specify the 4 nodes for the 2-D boundary element
xelm(1)=xstore(1,NGLLY,1,ispec)
yelm(1)=ystore(1,NGLLY,1,ispec)
zelm(1)=zstore(1,NGLLY,1,ispec)
xelm(2)=xstore(NGLLX,NGLLY,1,ispec)
yelm(2)=ystore(NGLLX,NGLLY,1,ispec)
zelm(2)=zstore(NGLLX,NGLLY,1,ispec)
xelm(3)=xstore(NGLLX,NGLLY,NGLLZ,ispec)
yelm(3)=ystore(NGLLX,NGLLY,NGLLZ,ispec)
zelm(3)=zstore(NGLLX,NGLLY,NGLLZ,ispec)
xelm(4)=xstore(1,NGLLY,NGLLZ,ispec)
yelm(4)=ystore(1,NGLLY,NGLLZ,ispec)
zelm(4)=zstore(1,NGLLY,NGLLZ,ispec)
call compute_jacobian_2D(myrank,ispecb4,xelm,yelm,zelm,dershape2D_y, &
jacobian2D_ymax,normal_ymax,NGLLX,NGLLZ,NSPEC2DMAX_YMIN_YMAX)
endif
! on boundary: bottom
if(iboun(5,ispec)) then
ispecb5=ispecb5+1
ibelm_bottom(ispecb5)=ispec
xelm(1)=xstore(1,1,1,ispec)
yelm(1)=ystore(1,1,1,ispec)
zelm(1)=zstore(1,1,1,ispec)
xelm(2)=xstore(NGLLX,1,1,ispec)
yelm(2)=ystore(NGLLX,1,1,ispec)
zelm(2)=zstore(NGLLX,1,1,ispec)
xelm(3)=xstore(NGLLX,NGLLY,1,ispec)
yelm(3)=ystore(NGLLX,NGLLY,1,ispec)
zelm(3)=zstore(NGLLX,NGLLY,1,ispec)
xelm(4)=xstore(1,NGLLY,1,ispec)
yelm(4)=ystore(1,NGLLY,1,ispec)
zelm(4)=zstore(1,NGLLY,1,ispec)
call compute_jacobian_2D(myrank,ispecb5,xelm,yelm,zelm,dershape2D_bottom, &
jacobian2D_bottom,normal_bottom,NGLLX,NGLLY,NSPEC2D_BOTTOM)
endif
! on boundary: top
if(iboun(6,ispec)) then
ispecb6=ispecb6+1
ibelm_top(ispecb6)=ispec
xelm(1)=xstore(1,1,NGLLZ,ispec)
yelm(1)=ystore(1,1,NGLLZ,ispec)
zelm(1)=zstore(1,1,NGLLZ,ispec)
xelm(2)=xstore(NGLLX,1,NGLLZ,ispec)
yelm(2)=ystore(NGLLX,1,NGLLZ,ispec)
zelm(2)=zstore(NGLLX,1,NGLLZ,ispec)
xelm(3)=xstore(NGLLX,NGLLY,NGLLZ,ispec)
yelm(3)=ystore(NGLLX,NGLLY,NGLLZ,ispec)
zelm(3)=zstore(NGLLX,NGLLY,NGLLZ,ispec)
xelm(4)=xstore(1,NGLLY,NGLLZ,ispec)
yelm(4)=ystore(1,NGLLY,NGLLZ,ispec)
zelm(4)=zstore(1,NGLLY,NGLLZ,ispec)
call compute_jacobian_2D(myrank,ispecb6,xelm,yelm,zelm,dershape2D_top, &
jacobian2D_top,normal_top,NGLLX,NGLLY,NSPEC2D_TOP)
endif
enddo
! check theoretical value of elements at the bottom
if(ispecb5 /= NSPEC2D_BOTTOM) call exit_MPI(myrank,'ispecb5 should equal NSPEC2D_BOTTOM')
! check theoretical value of elements at the top
if(ispecb6 /= NSPEC2D_TOP) call exit_MPI(myrank,'ispecb6 should equal NSPEC2D_TOP')
nspec2D_xmin = ispecb1
nspec2D_xmax = ispecb2
nspec2D_ymin = ispecb3
nspec2D_ymax = ispecb4
end subroutine get_jacobian_boundaries
! -------------------------------------------------------
subroutine compute_jacobian_2D(myrank,ispecb,xelm,yelm,zelm,dershape2D,jacobian2D,normal,NGLLA,NGLLB,NSPEC2DMAX_AB)
implicit none
include "constants.h"
! generic routine that accepts any polynomial degree in each direction
integer ispecb,NGLLA,NGLLB,NSPEC2DMAX_AB,myrank
double precision xelm(NGNOD2D),yelm(NGNOD2D),zelm(NGNOD2D)
double precision dershape2D(NDIM2D,NGNOD2D,NGLLA,NGLLB)
real(kind=CUSTOM_REAL) jacobian2D(NGLLA,NGLLB,NSPEC2DMAX_AB)
real(kind=CUSTOM_REAL) normal(3,NGLLA,NGLLB,NSPEC2DMAX_AB)
integer i,j,ia
double precision xxi,xeta,yxi,yeta,zxi,zeta
double precision unx,uny,unz,jacobian
do j=1,NGLLB
do i=1,NGLLA
xxi=ZERO
xeta=ZERO
yxi=ZERO
yeta=ZERO
zxi=ZERO
zeta=ZERO
do ia=1,NGNOD2D
xxi=xxi+dershape2D(1,ia,i,j)*xelm(ia)
xeta=xeta+dershape2D(2,ia,i,j)*xelm(ia)
yxi=yxi+dershape2D(1,ia,i,j)*yelm(ia)
yeta=yeta+dershape2D(2,ia,i,j)*yelm(ia)
zxi=zxi+dershape2D(1,ia,i,j)*zelm(ia)
zeta=zeta+dershape2D(2,ia,i,j)*zelm(ia)
enddo
! calculate the unnormalized normal to the boundary
unx=yxi*zeta-yeta*zxi
uny=zxi*xeta-zeta*xxi
unz=xxi*yeta-xeta*yxi
jacobian=dsqrt(unx**2+uny**2+unz**2)
if(jacobian == ZERO) call exit_MPI(myrank,'2D Jacobian undefined')
! normalize normal vector and store surface jacobian
! distinguish if single or double precision for reals
if(CUSTOM_REAL == SIZE_REAL) then
jacobian2D(i,j,ispecb)=sngl(jacobian)
normal(1,i,j,ispecb)=sngl(unx/jacobian)
normal(2,i,j,ispecb)=sngl(uny/jacobian)
normal(3,i,j,ispecb)=sngl(unz/jacobian)
else
jacobian2D(i,j,ispecb)=jacobian
normal(1,i,j,ispecb)=unx/jacobian
normal(2,i,j,ispecb)=uny/jacobian
normal(3,i,j,ispecb)=unz/jacobian
endif
enddo
enddo
end subroutine compute_jacobian_2D