Skip to content

Commit 9ee442e

Browse files
committed
updates model_prem_iso() routine (for backward version compatibility to match gravity)
1 parent 987b739 commit 9ee442e

File tree

2 files changed

+82
-37
lines changed

2 files changed

+82
-37
lines changed

src/shared/model_prem.f90

Lines changed: 56 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ subroutine model_prem_iso(x,rho,drhodr,vp,vs,Qkappa,Qmu,idoubling,CRUSTAL,check_
114114

115115
! local parameters
116116
double precision :: r,scaleval
117-
double precision :: RICB
117+
double precision :: ROCEAN,RMIDDLE_CRUST,RMOHO,R80,R220,R400,R600,R670,R771,RTOPDDOUBLEPRIME,RCMB,RICB
118118

119119
! compute real physical radius in meters
120120
r = x * R_PLANET
@@ -124,11 +124,42 @@ subroutine model_prem_iso(x,rho,drhodr,vp,vs,Qkappa,Qmu,idoubling,CRUSTAL,check_
124124

125125
! note: using stop statements, not exit_mpi() calls to avoid the need for MPI libraries when linking xcreate_header_file
126126

127-
! version compatibility
127+
! default setting
128+
ROCEAN = PREM_ROCEAN
129+
RMIDDLE_CRUST = PREM_RMIDDLE_CRUST
130+
RMOHO = PREM_RMOHO
131+
R80 = PREM_R80
132+
R220 = PREM_R220
133+
R400 = PREM_R400
134+
R600 = PREM_R600
135+
R670 = PREM_R670
136+
R771 = PREM_R771
137+
RTOPDDOUBLEPRIME = PREM_RTOPDDOUBLEPRIME
138+
RCMB = PREM_RCMB
139+
RICB = PREM_RICB
140+
141+
! note: different versions use different radii when calling this routine
128142
if (USE_OLD_VERSION_FORMAT) then
143+
! version compatibility with older versions 7.0 - 8.0
129144
RICB = PREM_RICB_OLD
130-
else
131-
RICB = PREM_RICB
145+
146+
! version compatibility with special case Berkeley model
147+
! note: old Berkeley implementation used radii different to PREM when calling this routine for gravity evaluation.
148+
! this was inconsistent with the the spline evaluation in the old make_gravity.f90.
149+
! the change here below is to re-introduce this inconsistency to match the old Berkeley model output.
150+
!
151+
! new(er) versions use the "original" PREM model for calculating gravity (and ellipticity).
152+
! that is, gravity (acceleration g) and ellipticity (based on density model) is based on PREM, since we know that
153+
! PREM was constructed with corresponding constraints.
154+
! other reference models might better adapt to velocities, but might violate for example total mass constraints.
155+
! the different radii of the reference models are used for meshing purposes only.
156+
!
157+
if (REFERENCE_1D_MODEL == REFERENCE_MODEL_SEMUCB) then
158+
RICB = PREM_RICB
159+
RMOHO = 6341000.d0
160+
R400 = 5961000.d0
161+
R670 = 5721000.d0
162+
endif
132163
endif
133164

134165
if (check_doubling_flag) then
@@ -145,31 +176,31 @@ subroutine model_prem_iso(x,rho,drhodr,vp,vs,Qkappa,Qmu,idoubling,CRUSTAL,check_
145176
!
146177
!--- outer core
147178
!
148-
else if (r > RICB .and. r < PREM_RCMB) then
179+
else if (r > RICB .and. r < RCMB) then
149180
if (idoubling /= IFLAG_OUTER_CORE_NORMAL) &
150181
stop 'wrong doubling flag for outer core point in model_prem_iso()'
151182
!
152183
!--- D" at the base of the mantle
153184
!
154-
else if (r > PREM_RCMB .and. r < PREM_RTOPDDOUBLEPRIME) then
185+
else if (r > RCMB .and. r < RTOPDDOUBLEPRIME) then
155186
if (idoubling /= IFLAG_MANTLE_NORMAL) &
156187
stop 'wrong doubling flag for D" point in model_prem_iso()'
157188
!
158189
!--- mantle: from top of D" to d670
159190
!
160-
else if (r > PREM_RTOPDDOUBLEPRIME .and. r < PREM_R670) then
191+
else if (r > RTOPDDOUBLEPRIME .and. r < R670) then
161192
if (idoubling /= IFLAG_MANTLE_NORMAL) &
162193
stop 'wrong doubling flag for top D" to d670 point in model_prem_iso()'
163194
!
164195
!--- mantle: from d670 to d220
165196
!
166-
else if (r > PREM_R670 .and. r < PREM_R220) then
197+
else if (r > R670 .and. r < R220) then
167198
if (idoubling /= IFLAG_670_220) &
168199
stop 'wrong doubling flag for d670 to d220 point in model_prem_iso()'
169200
!
170201
!--- mantle and crust: from d220 to MOHO and then to surface
171202
!
172-
else if (r > PREM_R220) then
203+
else if (r > R220) then
173204
if (idoubling /= IFLAG_220_80 .and. idoubling /= IFLAG_80_MOHO .and. idoubling /= IFLAG_CRUST) &
174205
stop 'wrong doubling flag for d220 to Moho to surface point in model_prem_iso()'
175206
endif
@@ -201,7 +232,7 @@ subroutine model_prem_iso(x,rho,drhodr,vp,vs,Qkappa,Qmu,idoubling,CRUSTAL,check_
201232
!
202233
!--- outer core
203234
!
204-
else if (r > RICB .and. r <= PREM_RCMB) then
235+
else if (r > RICB .and. r <= RCMB) then
205236
drhodr = -1.2638d0 - 2.0d0*3.6426d0*x - 3.0d0*5.5281d0*x*x
206237
rho = 12.5815d0 - 1.2638d0*x - 3.6426d0*x*x - 5.5281d0*x*x*x
207238
if (REFERENCE_1D_MODEL == REFERENCE_MODEL_PREM2) then
@@ -223,7 +254,7 @@ subroutine model_prem_iso(x,rho,drhodr,vp,vs,Qkappa,Qmu,idoubling,CRUSTAL,check_
223254
!
224255
!--- D" at the base of the mantle
225256
!
226-
else if (r > PREM_RCMB .and. r <= PREM_RTOPDDOUBLEPRIME) then
257+
else if (r > RCMB .and. r <= RTOPDDOUBLEPRIME) then
227258
drhodr = -6.4761d0 + 2.0d0*5.5283d0*x - 3.0d0*3.0807d0*x*x
228259
rho = 7.9565d0 - 6.4761d0*x + 5.5283d0*x*x - 3.0807d0*x*x*x
229260
if (REFERENCE_1D_MODEL == REFERENCE_MODEL_PREM2) then
@@ -239,7 +270,7 @@ subroutine model_prem_iso(x,rho,drhodr,vp,vs,Qkappa,Qmu,idoubling,CRUSTAL,check_
239270
!
240271
!--- mantle: from top of D" to d670
241272
!
242-
else if (r > PREM_RTOPDDOUBLEPRIME .and. r <= PREM_R771) then
273+
else if (r > RTOPDDOUBLEPRIME .and. r <= R771) then
243274
drhodr = -6.4761d0 + 2.0d0*5.5283d0*x - 3.0d0*3.0807d0*x*x
244275
rho = 7.9565d0 - 6.4761d0*x + 5.5283d0*x*x - 3.0807d0*x*x*x
245276
if (REFERENCE_1D_MODEL == REFERENCE_MODEL_PREM2) then
@@ -258,7 +289,7 @@ subroutine model_prem_iso(x,rho,drhodr,vp,vs,Qkappa,Qmu,idoubling,CRUSTAL,check_
258289
vs = 11.1671d0 - 13.7818d0*x + 17.4575d0*x*x - 9.2777d0*x*x*x
259290
Qmu = 312.0d0
260291
Qkappa = 57827.0d0
261-
else if (r > PREM_R771 .and. r <= PREM_R670) then
292+
else if (r > R771 .and. r <= R670) then
262293
drhodr = -6.4761d0 + 2.0d0*5.5283d0*x - 3.0d0*3.0807d0*x*x
263294
rho = 7.9565d0 - 6.4761d0*x + 5.5283d0*x*x - 3.0807d0*x*x*x
264295
vp = 29.2766d0 - 23.6027d0*x + 5.5242d0*x*x - 2.5514d0*x*x*x
@@ -268,28 +299,28 @@ subroutine model_prem_iso(x,rho,drhodr,vp,vs,Qkappa,Qmu,idoubling,CRUSTAL,check_
268299
!
269300
!--- mantle: above d670
270301
!
271-
else if (r > PREM_R670 .and. r <= PREM_R600) then
302+
else if (r > R670 .and. r <= R600) then
272303
drhodr = -1.4836d0
273304
rho = 5.3197d0 - 1.4836d0*x
274305
vp = 19.0957d0 - 9.8672d0*x
275306
vs = 9.9839d0 - 4.9324d0*x
276307
Qmu = 143.0d0
277308
Qkappa = 57827.0d0
278-
else if (r > PREM_R600 .and. r <= PREM_R400) then
309+
else if (r > R600 .and. r <= R400) then
279310
drhodr = -8.0298d0
280311
rho = 11.2494d0 - 8.0298d0*x
281312
vp = 39.7027d0 - 32.6166d0*x
282313
vs = 22.3512d0 - 18.5856d0*x
283314
Qmu = 143.0d0
284315
Qkappa = 57827.0d0
285-
else if (r > PREM_R400 .and. r <= PREM_R220) then
316+
else if (r > R400 .and. r <= R220) then
286317
drhodr = -3.8045d0
287318
rho = 7.1089d0 - 3.8045d0*x
288319
vp = 20.3926d0 - 12.2569d0*x
289320
vs = 8.9496d0 - 4.4597d0*x
290321
Qmu = 143.0d0
291322
Qkappa = 57827.0d0
292-
else if (r > PREM_R220 .and. r <= PREM_R80) then
323+
else if (r > R220 .and. r <= R80) then
293324
drhodr = 0.6924d0
294325
rho = 2.6910d0 + 0.6924d0*x
295326
vp = 4.1875d0 + 3.9382d0*x
@@ -299,7 +330,7 @@ subroutine model_prem_iso(x,rho,drhodr,vp,vs,Qkappa,Qmu,idoubling,CRUSTAL,check_
299330
else
300331
if (CRUSTAL .and. .not. SUPPRESS_CRUSTAL_MESH) then
301332
! fill with PREM mantle and later add CRUST2.0
302-
if (r > PREM_R80) then
333+
if (r > R80) then
303334
! density/velocity from mantle just below moho
304335
drhodr = 0.6924d0
305336
rho = 2.6910d0 + 0.6924d0*x
@@ -311,7 +342,7 @@ subroutine model_prem_iso(x,rho,drhodr,vp,vs,Qkappa,Qmu,idoubling,CRUSTAL,check_
311342
endif
312343
else
313344
! use PREM crust
314-
if (r > PREM_R80 .and. r <= PREM_RMOHO) then
345+
if (r > R80 .and. r <= RMOHO) then
315346
drhodr = 0.6924d0
316347
rho = 2.6910d0 + 0.6924d0*x
317348
vp = 4.1875d0 + 3.9382d0*x
@@ -322,13 +353,13 @@ subroutine model_prem_iso(x,rho,drhodr,vp,vs,Qkappa,Qmu,idoubling,CRUSTAL,check_
322353
else if (SUPPRESS_CRUSTAL_MESH) then
323354
! extend the Moho up to the surface instead of the crust
324355
drhodr = 0.6924d0
325-
rho = 2.6910d0 + 0.6924d0*(PREM_RMOHO / R_PLANET)
326-
vp = 4.1875d0 + 3.9382d0*(PREM_RMOHO / R_PLANET)
327-
vs = 2.1519d0 + 2.3481d0*(PREM_RMOHO / R_PLANET)
356+
rho = 2.6910d0 + 0.6924d0*(RMOHO / R_PLANET)
357+
vp = 4.1875d0 + 3.9382d0*(RMOHO / R_PLANET)
358+
vs = 2.1519d0 + 2.3481d0*(RMOHO / R_PLANET)
328359
Qmu = 600.0d0
329360
Qkappa = 57827.0d0
330361

331-
else if (r > PREM_RMOHO .and. r <= PREM_RMIDDLE_CRUST) then
362+
else if (r > RMOHO .and. r <= RMIDDLE_CRUST) then
332363
drhodr = 0.0d0
333364
rho = 2.9d0
334365
vp = 6.8d0
@@ -346,15 +377,15 @@ subroutine model_prem_iso(x,rho,drhodr,vp,vs,Qkappa,Qmu,idoubling,CRUSTAL,check_
346377
Qkappa = 57827.0d0
347378
endif
348379

349-
else if (r > PREM_RMIDDLE_CRUST .and. r <= PREM_ROCEAN) then
380+
else if (r > RMIDDLE_CRUST .and. r <= ROCEAN) then
350381
drhodr = 0.0d0
351382
rho = 2.6d0
352383
vp = 5.8d0
353384
vs = 3.2d0
354385
Qmu = 600.0d0
355386
Qkappa = 57827.0d0
356387
! for density profile for gravity, we do not check that r <= R_PLANET
357-
else if (r > PREM_ROCEAN) then
388+
else if (r > ROCEAN) then
358389
drhodr = 0.0d0
359390
rho = 2.6d0
360391
vp = 5.8d0

src/specfem3D/prepare_gravity.f90

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,20 @@ subroutine prepare_gravity()
230230
endif
231231
enddo
232232

233+
! debug - file output
234+
if (.false.) then
235+
open(21,file='tmp_grav.dat',status='unknown')
236+
write(21,*) "# int_radius # radius # rho # minus_g # minus_dg"
237+
do int_radius = 1,NRAD_GRAVITY
238+
radius = r(int_radius)
239+
rho = density_table(int_radius)
240+
minus_g = minus_gravity_table(int_radius)
241+
minus_dg = minus_deriv_gravity_table(int_radius)
242+
write(21,*) int_radius,radius,rho,minus_g,minus_dg
243+
enddo
244+
close(21)
245+
endif
246+
233247
! make sure fluid array is only assigned in outer core between 1222 and 3478 km
234248
! lookup table is defined every 100 m
235249
do int_radius = 1,NRAD_GRAVITY
@@ -320,9 +334,9 @@ subroutine prepare_gravity()
320334
fac = minus_rho_g_over_kappa_fluid(int_radius)
321335

322336
! gravitational acceleration (integrated and multiply by rho / Kappa) in Cartesian coordinates
323-
gxl = dsin(theta) * dcos(phi) * fac
324-
gyl = dsin(theta) * dsin(phi) * fac
325-
gzl = dcos(theta) * fac
337+
gxl = (dsin(theta) * dcos(phi)) * fac
338+
gyl = (dsin(theta) * dsin(phi)) * fac
339+
gzl = (dcos(theta)) * fac
326340
gravity_pre_store_outer_core(1,iglob) = real(gxl,kind=CUSTOM_REAL)
327341
gravity_pre_store_outer_core(2,iglob) = real(gyl,kind=CUSTOM_REAL)
328342
gravity_pre_store_outer_core(3,iglob) = real(gzl,kind=CUSTOM_REAL)
@@ -437,9 +451,9 @@ subroutine prepare_gravity()
437451
fac = d_ln_density_dr_table(int_radius)
438452

439453
! gradient of d ln(rho)/dr in Cartesian coordinates
440-
gxl = dsin(theta) * dcos(phi) * fac
441-
gyl = dsin(theta) * dsin(phi) * fac
442-
gzl = dcos(theta) * fac
454+
gxl = (dsin(theta) * dcos(phi)) * fac
455+
gyl = (dsin(theta) * dsin(phi)) * fac
456+
gzl = (dcos(theta)) * fac
443457
gravity_pre_store_outer_core(1,iglob) = real(gxl,kind=CUSTOM_REAL)
444458
gravity_pre_store_outer_core(2,iglob) = real(gyl,kind=CUSTOM_REAL)
445459
gravity_pre_store_outer_core(3,iglob) = real(gzl,kind=CUSTOM_REAL)
@@ -546,9 +560,9 @@ subroutine prepare_gravity()
546560

547561
! Cartesian components of the gravitational acceleration
548562
! multiplied by common factor rho
549-
gxl = minus_g * sin_theta * cos_phi * rho
550-
gyl = minus_g * sin_theta * sin_phi * rho
551-
gzl = minus_g * cos_theta * rho
563+
gxl = (minus_g * sin_theta * cos_phi) * rho
564+
gyl = (minus_g * sin_theta * sin_phi) * rho
565+
gzl = (minus_g * cos_theta) * rho
552566
gravity_pre_store_crust_mantle(1,iglob) = real(gxl,kind=CUSTOM_REAL)
553567
gravity_pre_store_crust_mantle(2,iglob) = real(gyl,kind=CUSTOM_REAL)
554568
gravity_pre_store_crust_mantle(3,iglob) = real(gzl,kind=CUSTOM_REAL)
@@ -693,9 +707,9 @@ subroutine prepare_gravity()
693707

694708
! Cartesian components of the gravitational acceleration
695709
! multiplied by common factor rho
696-
gxl = minus_g * sin_theta * cos_phi * rho
697-
gyl = minus_g * sin_theta * sin_phi * rho
698-
gzl = minus_g * cos_theta * rho
710+
gxl = (minus_g * sin_theta * cos_phi) * rho
711+
gyl = (minus_g * sin_theta * sin_phi) * rho
712+
gzl = (minus_g * cos_theta) * rho
699713

700714
gravity_pre_store_inner_core(1,iglob) = real(gxl,kind=CUSTOM_REAL)
701715
gravity_pre_store_inner_core(2,iglob) = real(gyl,kind=CUSTOM_REAL)

0 commit comments

Comments
 (0)