-
Notifications
You must be signed in to change notification settings - Fork 237
/
streamice_advect_thickness.F
472 lines (412 loc) · 14.8 KB
/
streamice_advect_thickness.F
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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
#include "STREAMICE_OPTIONS.h"
#ifdef ALLOW_AUTODIFF
# include "AUTODIFF_OPTIONS.h"
#endif
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
CBOP
SUBROUTINE STREAMICE_ADVECT_THICKNESS ( myThid,myIter,time_step )
C *============================================================*
C | SUBROUTINE |
C | o |
C *============================================================*
C | |
C *============================================================*
IMPLICIT NONE
C === Global variables ===
#include "SIZE.h"
#include "GRID.h"
#include "EEPARAMS.h"
#include "PARAMS.h"
#include "STREAMICE.h"
#include "STREAMICE_ADV.h"
#ifdef ALLOW_AUTODIFF_TAMC
# include "tamc.h"
#endif
#ifdef ALLOW_SHELFICE
# include "SHELFICE.h"
#endif
INTEGER myThid, myIter
_RL time_step
#ifdef ALLOW_STREAMICE
INTEGER i, j, bi, bj, Gi, Gj
_RL uflux, vflux, max_icfl, loc_icfl
_RL time_step_full, time_step_rem
_RL sec_per_year, time_step_loc, MR, SMB, TMB, irho
_RL bdot_depth, bdot_max
_RL BCVALX(1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
_RL BCVALY(1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
_RS BCMASKX(1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
_RS BCMASKY(1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
_RL utrans(1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
_RL vtrans(1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
_RL h_after_uflux_SI(1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
_RL h_after_vflux_SI(1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
_RL hflux_x_SI(1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
_RL hflux_y_SI(1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
CHARACTER*(MAX_LEN_MBUF) msgBuf
CALL TIMER_START ('STREAMICE_ADVECT_THICKNESS',myThid)
sec_per_year = 365.*86400.
time_step_loc = time_step / sec_per_year
time_step_full = time_step_loc
time_step_rem = time_step_loc
PRINT *, "time_step_loc ", time_step_loc
#ifdef ALLOW_AUTODIFF_TAMC
CADJ INIT loctape_stream_adv = COMMON, 1
CADJ STORE area_shelf_streamice = loctape_stream_adv, key = 1
CADJ STORE bdot_streamice = loctape_stream_adv, key = 1
#endif
#ifdef ALLOW_OPENAD
DO k=1,streamice_smooth_thick_adjoint
CALL STREAMICE_SMOOTH_ADJOINT_FIELD (
O H_streamice,
I myThid)
ENDDO
#endif
#ifdef ALLOW_AUTODIFF_TAMC
CADJ STORE streamice_hmask = comlev1, key=ikey_dynamics
#endif
DO bj=myByLo(myThid),myByHi(myThid)
DO bi=myBxLo(myThid),myBxHi(myThid)
DO j=1,sNy+1
DO i=1,sNx+1
H_streamice_prev(i,j,bi,bj) =
& H_streamice(i,j,bi,bj)
hflux_x_SI (i,j,bi,bj) = 0. _d 0
hflux_y_SI (i,j,bi,bj) = 0. _d 0
IF (STREAMICE_hmask(i,j,bi,bj).eq.1.0) THEN
h_after_uflux_SI(i,j,bi,bj) = 0. _d 0
h_after_vflux_SI(i,j,bi,bj) = 0. _d 0
ELSE
h_after_uflux_SI(i,j,bi,bj) = H_streamice(i,j,bi,bj)
h_after_vflux_SI(i,j,bi,bj) = H_streamice(i,j,bi,bj)
ENDIF
IF (STREAMICE_ufacemask(i,j,bi,bj).eq.3.0) THEN
BCMASKX(i,j,bi,bj) = 3.0
BCVALX(i,j,bi,bj) = h_ubdry_values_SI(i,j,bi,bj)
IF (STREAMICE_vel_ext_cgrid) THEN
utrans(i,j,bi,bj) = u_streamice_ext(i,j,bi,bj)
ELSEIF (STREAMICE_vel_ext) THEN
utrans(i,j,bi,bj) = .5 * (
& u_streamice_ext(i,j,bi,bj)+u_streamice_ext(i,j+1,bi,bj))
ELSE
utrans(i,j,bi,bj) = .5 * (
& u_streamice(i,j,bi,bj)+u_streamice(i,j+1,bi,bj))
ENDIF
ELSEIF (STREAMICE_ufacemask(i,j,bi,bj).eq.4.0) THEN
IF (STREAMICE_hmask(i,j,bi,bj).eq.1.0) THEN
uflux = u_flux_bdry_SI(i,j,bi,bj)
BCMASKX(i,j,bi,bj) = 3.0
BCVALX(i,j,bi,bj) = uflux
utrans(i,j,bi,bj) = 1.0
ELSEIF (STREAMICE_hmask(i-1,j,bi,bj).eq.1.0) THEN
uflux = u_flux_bdry_SI(i,j,bi,bj)
BCMASKX(i,j,bi,bj) = 3.0
BCVALX(i,j,bi,bj) = uflux
utrans(i,j,bi,bj) = -1.0
ENDIF
ELSEIF (.not.(
& STREAMICE_hmask(i,j,bi,bj).eq.1.0.OR.
& STREAMICE_hmask(i-1,j,bi,bj).eq.1.0)) THEN
BCMASKX(i,j,bi,bj) = 0.0
BCVALX(i,j,bi,bj) = 0. _d 0
utrans(i,j,bi,bj) = 0. _d 0
ELSE
BCMASKX(i,j,bi,bj) = 0.0
BCVALX(i,j,bi,bj) = 0. _d 0
IF (STREAMICE_vel_ext_cgrid) THEN
utrans(i,j,bi,bj) = u_streamice_ext(i,j,bi,bj)
ELSEIF (STREAMICE_vel_ext) THEN
utrans(i,j,bi,bj) = .5 * (
& u_streamice_ext(i,j,bi,bj)+u_streamice_ext(i,j+1,bi,bj))
ELSE
utrans(i,j,bi,bj) = .5 * (
& u_streamice(i,j,bi,bj)+u_streamice(i,j+1,bi,bj))
ENDIF
ENDIF
IF (STREAMICE_vfacemask(i,j,bi,bj).eq.3.0) THEN
BCMASKy(i,j,bi,bj) = 3.0
BCVALy(i,j,bi,bj) = h_vbdry_values_SI(i,j,bi,bj)
IF (STREAMICE_vel_ext_cgrid) THEN
vtrans(i,j,bi,bj) = v_streamice_ext(i,j,bi,bj)
ELSEIF (STREAMICE_vel_ext) THEN
vtrans(i,j,bi,bj) = .5 * (
& v_streamice_ext(i,j,bi,bj)+v_streamice_ext(i+1,j,bi,bj))
ELSE
vtrans(i,j,bi,bj) = .5 * (
& v_streamice(i,j,bi,bj)+v_streamice(i+1,j,bi,bj))
ENDIF
ELSEIF (STREAMICE_vfacemask(i,j,bi,bj).eq.4.0) THEN
IF (STREAMICE_hmask(i,j,bi,bj).eq.1.0) THEN
vflux = v_flux_bdry_SI(i,j,bi,bj)
BCMASKY(i,j,bi,bj) = 3.0
BCVALY(i,j,bi,bj) = vflux
vtrans(i,j,bi,bj) = 1.0
ELSEIF (STREAMICE_hmask(i,j-1,bi,bj).eq.1.0) THEN
vflux = v_flux_bdry_SI(i,j,bi,bj)
BCMASKY(i,j,bi,bj) = 3.0
BCVALY(i,j,bi,bj) = vflux
vtrans(i,j,bi,bj) = -1.0
ENDIF
ELSEIF (.not.(
& STREAMICE_hmask(i,j,bi,bj).eq.1.0.OR.
& STREAMICE_hmask(i,j-1,bi,bj).eq.1.0)) THEN
BCMASKY(i,j,bi,bj) = 0.0
BCVALY(i,j,bi,bj) = 0. _d 0
vtrans(i,j,bi,bj) = 0. _d 0
ELSE
BCMASKy(i,j,bi,bj) = 0.0
BCVALy(i,j,bi,bj) = 0. _d 0
IF (STREAMICE_vel_ext_cgrid) THEN
vtrans(i,j,bi,bj) = v_streamice_ext(i,j,bi,bj)
ELSEIF (STREAMICE_vel_ext) THEN
vtrans(i,j,bi,bj) = .5 * (
& v_streamice_ext(i,j,bi,bj)+v_streamice_ext(i+1,j,bi,bj))
ELSE
vtrans(i,j,bi,bj) = .5 * (
& v_streamice(i,j,bi,bj)+v_streamice(i+1,j,bi,bj))
ENDIF
ENDIF
ENDDO
ENDDO
ENDDO
ENDDO
_EXCH_XY_RL(utrans,myThid)
_EXCH_XY_RL(vtrans,myThid)
_EXCH_XY_RS(BCMASKx,myThid)
_EXCH_XY_RS(BCMASKy,myThid)
_EXCH_XY_RL(BCVALX,myThid)
_EXCH_XY_RL(BCVALY,myThid)
_EXCH_XY_RL(h_after_uflux_SI,myThid)
_EXCH_XY_RL(h_after_vflux_SI,myThid)
_EXCH_XY_RL(hflux_x_SI,myThid)
_EXCH_XY_RL(hflux_y_SI,myThid)
#ifdef ALLOW_AUTODIFF_TAMC
CADJ STORE BCMASKx, BCMASKy= comlev1, key=ikey_dynamics
CADJ STORE BCVALX, BCVALY = comlev1, key=ikey_dynamics
CADJ STORE utrans, vtrans = comlev1, key=ikey_dynamics
CADJ STORE streamice_hmask = comlev1, key=ikey_dynamics
CADJ STORE H_streamice = comlev1, key=ikey_dynamics
#endif
#ifndef ALLOW_AUTODIFF
max_icfl = 1.e-20
DO bj=myByLo(myThid),myByHi(myThid)
DO bi=myBxLo(myThid),myBxHi(myThid)
DO j=1,sNy
DO i=1,sNx
IF (streamice_hmask(i,j,bi,bj).eq.1.0) THEN
loc_icfl=max(abs(utrans(i,j,bi,bj)),
& abs(utrans(i+1,j,bi,bj))) / dxF(i,j,bi,bj)
loc_icfl=max(loc_icfl,max(abs(vtrans(i,j,bi,bj)),
& abs(vtrans(i,j+1,bi,bj))) / dyF(i,j,bi,bj))
if (loc_icfl.gt.max_icfl) then
max_icfl = loc_icfl
ENDIF
ENDIF
ENDDO
ENDDO
ENDDO
ENDDO
CALL GLOBAL_MAX_R8 (max_icfl, myThid)
#endif /* ALLOW_AUTODIFF */
#ifdef ALLOW_AUTODIFF_TAMC
CADJ STORE streamice_hmask = comlev1, key=ikey_dynamics
CADJ STORE H_streamice = comlev1, key=ikey_dynamics
#endif
#ifndef ALLOW_AUTODIFF
do while (time_step_rem .gt. 1.e-15)
time_step_loc = min (
& streamice_cfl_factor / max_icfl,
& time_step_rem )
if (time_step_loc .lt. time_step_full) then
PRINT *, "TAKING PARTIAL TIME STEP", time_step_loc
endif
#endif /* ALLOW_AUTODIFF */
CALL STREAMICE_ADV_FLUX_FL_X ( myThid ,
I utrans ,
I H_streamice ,
I BCMASKX,
I BCVALX,
O hflux_x_SI,
I time_step_loc )
DO bj=myByLo(myThid),myByHi(myThid)
DO bi=myBxLo(myThid),myBxHi(myThid)
DO j=1-3,sNy+3
DO i=1,sNx
Gi = (myXGlobalLo-1)+(bi-1)*sNx+i
Gj = (myYGlobalLo-1)+(bj-1)*sNy+j
IF (((Gj .ge. 1) .and. (Gj .le. Ny))
& .or.STREAMICE_NS_PERIODIC) THEN
IF (STREAMICE_hmask(i,j,bi,bj).eq.1.0) THEN
h_after_uflux_SI (i,j,bi,bj) = H_streamice(i,j,bi,bj) -
& (hflux_x_SI(i+1,j,bi,bj)*dyG(i+1,j,bi,bj) -
& hflux_x_SI(i,j,bi,bj)*dyG(i,j,bi,bj))
& * recip_rA (i,j,bi,bj) * time_step_loc
IF ( h_after_uflux_SI (i,j,bi,bj).le.0.0) THEN
PRINT *, "h neg after x", i,j,hflux_x_SI(i+1,j,bi,bj),
& hflux_x_SI(i,j,bi,bj)
ENDIF
ENDIF
ENDIF
ENDDO
ENDDO
ENDDO
ENDDO
#ifdef ALLOW_AUTODIFF_TAMC
CADJ STORE h_after_uflux_SI = comlev1, key = ikey_dynamics
#endif
c CALL STREAMICE_ADVECT_THICKNESS_Y ( myThid,
c O hflux_y_SI,
c O h_after_vflux_SI,
c I time_step_loc )
CALL STREAMICE_ADV_FLUX_FL_Y ( myThid ,
I vtrans ,
I h_after_uflux_si ,
I BCMASKY,
I BCVALY,
O hflux_y_SI,
I time_step_loc )
DO bj=myByLo(myThid),myByHi(myThid)
DO bi=myBxLo(myThid),myBxHi(myThid)
DO j=1,sNy
DO i=1,sNx
Gi = (myXGlobalLo-1)+(bi-1)*sNx+i
Gj = (myYGlobalLo-1)+(bj-1)*sNy+j
IF (((Gj .ge. 1) .and. (Gj .le. Ny))
& .or.STREAMICE_EW_PERIODIC) THEN
IF (STREAMICE_hmask(i,j,bi,bj).eq.1.0) THEN
h_after_vflux_SI (i,j,bi,bj) = h_after_uflux_SI(i,j,bi,bj) -
& (hflux_y_SI(i,j+1,bi,bj)*dxG(i,j+1,bi,bj) -
& hflux_y_SI(i,j,bi,bj)*dxG(i,j,bi,bj)) *
& recip_rA (i,j,bi,bj) * time_step_loc
IF ( h_after_vflux_SI (i,j,bi,bj).le.0.0) THEN
PRINT *, "h neg after y", i,j,hflux_y_SI(i,j+1,bi,bj),
& hflux_y_SI(i,j,bi,bj)
ENDIF
ENDIF
ENDIF
ENDDO
ENDDO
ENDDO
ENDDO
DO bj=myByLo(myThid),myByHi(myThid)
DO bi=myBxLo(myThid),myBxHi(myThid)
DO j=1,sNy
DO i=1,sNx
IF (STREAMICE_hmask(i,j,bi,bj).eq.1.0) THEN
H_streamice (i,j,bi,bj) =
& h_after_vflux_SI (i,j,bi,bj)
ENDIF
ENDDO
ENDDO
ENDDO
ENDDO
c NOTE: AT THIS POINT H IS NOT VALID ON OVERLAP!!!
if (streamice_move_front) then
CALL STREAMICE_ADV_FRONT (
& myThid, time_step_loc,
& hflux_x_SI, hflux_y_SI )
endif
#ifdef ALLOW_AUTODIFF_TAMC
C These make calling S/R STREAMICE_ADV_FRONT in
C S/R STREAMICE_ADVECTION_THICKNESS_AD go away.
CADJ STORE H_streamice = comlev1, key=ikey_dynamics
CADJ STORE streamice_hmask = comlev1, key=ikey_dynamics
#endif
#ifdef ALLOW_STREAMICE_2DTRACER
CALL STREAMICE_ADVECT_2DTRACER(
& myThid,
& myIter,
& time_step,
& uTrans,
& vTrans,
& BCMASKx,
& BCMASKy )
#endif
#ifndef ALLOW_AUTODIFF
time_step_rem = time_step_rem - time_step_loc
enddo
#endif /* ALLOW_AUTODIFF */
c NOW WE APPLY MELT RATES !!
c THIS MAY BE MOVED TO A SEPARATE SUBROUTINE
irho = 1./streamice_density
DO bj=myByLo(myThid),myByHi(myThid)
DO bi=myBxLo(myThid),myBxHi(myThid)
DO j=1,sNy
DO i=1,sNx
Gi = (myXGlobalLo-1)+(bi-1)*sNx+i
Gj = (myYGlobalLo-1)+(bj-1)*sNy+j
#ifdef ALLOW_AUTODIFF
C Interestingly, this helps avoiding 10 recomputation warnings;
C hopefully it does not change results.
MR = 0. _d 0
#endif
IF (STREAMICE_hmask(i,j,bi,bj).eq.1.0 .or.
& STREAMICE_hmask(i,j,bi,bj).eq.2.0) THEN
IF (STREAMICE_allow_cpl) THEN
#ifdef ALLOW_SHELFICE
MR = -1. * (1.-float_frac_streamice(i,j,bi,bj)) *
& shelfIceFreshWaterFlux(i,j,bi,bj) * irho *
& sec_per_year
#else
STOP 'SHELFICE IS NOT ENABLED'
#endif
ELSE
IF (STREAMICEBdotConfig.EQ.'FILE' ) THEN
MR = (1.-float_frac_streamice(i,j,bi,bj)) *
& (BDOT_STREAMICE(i,j,bi,bj) +
& BDOT_pert(i,j,bi,bj))
ELSEIF (STREAMICEBdotConfig.EQ.'PARAM') THEN
bdot_depth =
& streamice_bdot_depth_maxmelt_v(i,j,bi,bj) +
& streamice_bdot_depth_maxmelt
bdot_max =
& streamice_bdot_maxmelt_v(i,j,bi,bj) +
& streamice_bdot_maxmelt
IF (base_el_streamice(i,j,bi,bj) .lt.
& streamice_bdot_depth_nomelt) THEN
IF (base_el_streamice(i,j,bi,bj) .lt.
& bdot_depth) THEN
MR = ABS(bdot_max)**streamice_bdot_exp
ELSE
MR = (ABS((streamice_bdot_depth_nomelt-
& base_el_streamice(i,j,bi,bj)) /
& (streamice_bdot_depth_nomelt-
& bdot_depth) *
& bdot_max))**streamice_bdot_exp
ENDIF
ELSE
MR = 0.0
ENDIF
MR = (1.-float_frac_streamice(i,j,bi,bj)) *
& (MR + BDOT_pert(i,j,bi,bj))
BDOT_STREAMICE(i,j,bi,bj) = MR
ELSE
MR = 0.
BDOT_STREAMICE(i,j,bi,bj) = MR
ENDIF
ENDIF
SMB = ADOT_STREAMICE(i,j,bi,bj)
TMB = SMB - MR
IF ((TMB.lt.0.0) .and.
& (MR * time_step_loc .gt.
& H_streamice (i,j,bi,bj))) THEN
H_streamice (i,j,bi,bj) = 0. _d 0
STREAMICE_hmask(i,j,bi,bj) = 0.0
PRINT *, "GOT HERE melted away! ", i,j
ELSE
H_streamice (i,j,bi,bj) =
& H_streamice (i,j,bi,bj) + TMB * time_step_loc
ENDIF
ENDIF
ENDDO
ENDDO
ENDDO
ENDDO
_EXCH_XY_RL(H_streamice,myThid)
WRITE(msgBuf,'(A)') 'END STREAMICE_ADVECT_THICKNESS'
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
& SQUEEZE_RIGHT , 1)
CALL TIMER_STOP ('STREAMICE_ADVECT_THICKNESS',myThid)
#endif
RETURN
END