-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimulation.py
343 lines (296 loc) · 8.11 KB
/
simulation.py
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
334
335
336
337
338
339
# Copyright (C) 2020-2021 by Andrew Hoffman <[email protected]>
#
# This file is part of the two-stage code.
#
# the two-stage glacier model 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 3 of the License,
# or (at your option) any later version.
#
# The full text of the license can be found in the file LICENSE in the
# two-stage glacier model source directory or at <http://www.gnu.org/licenses/>.
import tqdm
import copy
import numpy as np
import model
import linear
import forcing
from constants import (gravity as g,
ice_density as ρ_I,
water_density as ρ_W,
bedrock_density as ρ_s,
glen_flow_law as n,
glen_coefficient as A,
friction_coefficient as C,
theta as θ,
year as year
)
def m(n):
return 1/n
def γ(n):
return n
def α(n):
return 2*n+1
def β(bedn,n):
return (m(bedn)+n+3)/(m(bedn)+1)
def ν(n, C):
return (ρ_I*g/C)**n
def λ(ρ_W,ρ_I):
return ρ_I/ρ_W
def initialize_forcing(Sbar, Sσ, Obar, Oσ, N, δS=0.0, δO=0.0, startS=0, endS=0, startO=0, endO=0):
r"""
return ocean melt and surface mass balance forcing
"""
return forcing.Ω(N,Obar,Oσ,δO,startO,endO), forcing.smb(N,Sbar,Sσ,δS,startS,endS)
def equilibrium(H, L, m0, b0, Ωbar, Sbar,C=C,bedn=n,alphan=n,n=n, N=1000000, dt=1.0,):
r"""
return equilibrium thickness and length
H : float
initial interior ice thickness
L : float
initial glacier length
m0 : float
initial bedrock slope
b0 : float
interior bedrock elevation
Ωbar : float
average discharge coefficient
Sbar : float
average surface mass balace
N : float
number of timesteps
"""
for t in tqdm.trange(N):
b = model.bed(b0,m0,L)
Hg = model.grounding_thickness(b)
Q = model.interior_flux(L,H,ν(bedn,C),α(bedn),bedn)
Qg = model.grounding_flux(Ωbar,b0,m0,L,β(bedn,n))
dh = model.dhdt(Sbar,H,L,b,Q,Qg)*dt*year
dL = model.dLdt(Q,Qg,Hg)*dt*year
H = H + dh
L = L + dL
return H, L
def simulation(H0, L0, m0, b0, Ω, S, N, bedn=n,alphan=n,n=n, C=C, dt=1.0):
r"""
return timeseries of ice thickness, glacier length,
bedrock slope and fluxes.
H0 : float
initial interior ice thickness
L0 : float
initial glacier length
m0 : float
initial bedrock slope
b0 : float
interior bedrock elevation
Ω : float
discharge coefficient
S : float
surface mass balace
N : float
number of timesteps
"""
L = np.zeros(N)
H = np.zeros(N)
M = np.zeros(N)
Q = np.zeros(N)
Qg = np.zeros(N)
Htmp=H0
Ltmp=L0
σ=0.0
σp=0.0
#btmp=b0
for t in tqdm.trange(N):
H[t] = Htmp
L[t] = Ltmp
b = model.bed(b0,m0,Ltmp)
Hg= model.grounding_thickness(b)
Q[t]=model.interior_flux(Ltmp,Htmp,ν(bedn,C),α(bedn,),n)
Qg[t]=model.grounding_flux(Ω[t],b0,m0,Ltmp,β(bedn,n))
dH=model.dhdt(S[t],Htmp,Ltmp,b,Q[t],Qg[t])*dt*year
dL=model.dLdt(Q[t],Qg[t],Hg)*dt*year
Htmp = Htmp + dH
Ltmp = Ltmp + dL
return H,L,Q,Qg
def elastic_simulation(H0, L0, m0, b0, Ω, S, N, E, γ=1.0, dt=1.0):
r"""
return timeseries of ice thickness, glacier length,
bedrock slope and fluxes.
H0 : float
initial interior ice thickness
L0 : float
initial glacier length
m0 : float
initial bedrock slope
b0 : float
interior bedrock elevation
Ω : float
discharge coefficient
S : float
surface mass balace
N : float
number of timesteps
E : float
elasticity
γ : float
aspect ratio
"""
L = np.zeros(N)
H = np.zeros(N)
M = np.zeros(N)
Q = np.zeros(N)
Qg = np.zeros(N)
Htmp=H0
Ltmp=L0
mtmp=m0
#btmp=b0
for t in tqdm.trange(N):
M[t] = mtmp
H[t] = Htmp
L[t] = Ltmp
b = model.bed(b0,mtmp,Ltmp)
Hg= model.grounding_thickness(b)
Q[t]=model.interior_flux(Ltmp,Htmp,ν(n,C),α(n),n)
Qg[t]=model.grounding_flux(Ω[t],b0,mtmp,Ltmp,β(n))
dH=model.dhdt(S[t],Htmp,Ltmp,b,Q[t],Qg[t])*dt*year
dL=model.dLdt(Q[t],Qg[t],Hg)*dt*year
σ=model.stress(Htmp,Ltmp,mtmp, H0, L0, m0, b0)
dm=model.elastic(σ,E,γ)
mtmp =mtmp + dm
Htmp = Htmp + dH
Ltmp = Ltmp + dL
return H,L,M,Q,Qg
def viscoelastic_simulation(H0, L0, m0, b0, Ω, S, N, E, η, γ=1.0, dt=1.0):
r"""
return timeseries of ice thickness, glacier length,
bedrock slope and fluxes.
H0 : float
initial interior ice thickness
L0 : float
initial glacier length
m0 : float
initial bedrock slope
b0 : float
interior bedrock elevation
Ω : float
discharge coefficient
S : float
surface mass balace
N : float
number of timesteps
E : float
elasticity
γ : float
aspect ratio
"""
L = np.zeros(N)
H = np.zeros(N)
M = np.zeros(N)
Q = np.zeros(N)
Qg = np.zeros(N)
Htmp=H0
Ltmp=L0
mtmp=m0
σ=0.0
σp=0.0
#btmp=b0
for i in tqdm.trange(N):
M[t] = mtmp
H[t] = Htmp
L[t] = Ltmp
b = model.bed(b0,mtmp,Ltmp)
Hg= model.grounding_thickness(b)
Q[t]=model.interior_flux(Ltmp,Htmp,ν(n,C),α(n),n)
Qg[t]=model.grounding_flux(Ω[t],b0,mtmp,Ltmp,β(n))
dH=model.dhdt(S[t],Htmp,Ltmp,b,Q[t],Qg[t])*dt*year
dL=model.dLdt(Q[t],Qg[t],Hg)*dt*year
σp=copy.deepcopy(σ)
σ=model.stress(Htmp,Ltmp,mtmp,H0,L0,m0,b0)
dm=model.viscoelastic(σ,σp,E,η,γ,dt*year)*dt*year
mtmp=mtmp + dm
Htmp = Htmp + dH
Ltmp = Ltmp + dL
return H,L,M,Q,Qg
def Oerlemans_simulation(H0, L0, m0, b0, Ω, S, N, τ, dt=1.0):
r"""
return timeseries of ice thickness, glacier length,
bedrock slope and fluxes.
H0 : float
initial interior ice thickness
L0 : float
initial glacier length
m0 : float
initial bedrock slope
b0 : float
interior bedrock elevation
Ω : float
discharge coefficient
S : float
surface mass balace
τ : float
timescale of rebound
E : float
elasticity
γ : float
aspect ratio
"""
L = np.zeros(N)
H = np.zeros(N)
M = np.zeros(N)
Q = np.zeros(N)
Qg = np.zeros(N)
Htmp=H0
Ltmp=L0
mtmp=m0
σ=0.0
σp=0.0
#btmp=b0
for t in tqdm.trange(N):
M[t] = mtmp
H[t] = Htmp
L[t] = Ltmp
b = model.bed(b0,mtmp,Ltmp)
Hg = model.grounding_thickness(b)
Q[t] = model.interior_flux(Ltmp,Htmp,ν(n,C),α(n),n)
Qg[t] = model.grounding_flux(Ω[t],b0,mtmp,Ltmp,β(n))
dH = model.dhdt(S[t],Htmp,Ltmp,b,Q[t],Qg[t])*dt*year
dL = model.dLdt(Q[t],Qg[t],Hg)*dt*year
w = model.deflection_angle(Htmp,Ltmp,mtmp,H0,L0,m0,b0)
dm = model.dmdt(w,mtmp,m0,τ)*dt
mtmp = mtmp + dm
Htmp = Htmp + dH
Ltmp = Ltmp + dL
return H,L,M,Q,Qg
def linear_simulation(Hbar, Lbar, mbar, hgbar, Qgbar, b0, Ω, S, τ, κ, N, γ=1.0, dt=1.0):
r"""
return timeseries of ice thickness, glacier length,
bedrock slope and fluxes.
Hbar : float
initial interior ice thickness
Lbar : float
initial glacier length
mbar : float
initial bedrock slope
hgbar : float
average grounding zone thickness
Qgbar : float
average grounding zone flux
b0 : float
interior bedrock elevation
Ω : float
discharge coefficient
S : float
surface mass balace
τ : float
timescale of rebound
γ : float
aspect ratio
"""
L = np.zeros(N)
H = np.zeros(N)
M = np.zeros(N)
dt=dt*year
for t in tqdm.trange(1,N):
L[t]=linear.Lprime(H[t-1],L[t-1],M[t-1],Hbar,Lbar,mbar,hgbar,Qgbar,α(n),γ,ν(n,C),β(n),λ(ρ_W,ρ_I),b0,Ω[t],S[t],κ,τ,dt)
H[t]=linear.Hprime(H[t-1],L[t-1],M[t-1],Hbar,Lbar,mbar,hgbar,Qgbar,α(n),γ,ν(n,C),β(n),λ(ρ_W,ρ_I),b0,Ω[t],S[t],κ,τ,dt)
M[t]=linear.bxprime(H[t-1],L[t-1],M[t-1],Hbar,Lbar,mbar,hgbar,Qgbar,α(n),γ,ν(n,C),β(n),λ(ρ_W,ρ_I),b0,Ω[t],S[t],κ,τ,dt)
return L,H,M