-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenergy.F
462 lines (458 loc) · 14.6 KB
/
energy.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
subroutine ge1 (joff, js, je, is, ie, n)
c
c-----------------------------------------------------------------------
c compute global energetics by taking u dot the momentum equations
c and integrating over the ocean volume
c
c input:
c joff = offset relating "j" in the MW to latitude "jrow"
c js = starting row in the MW
c je = ending row in the MW
c is = starting longitude index in the MW
c ie = ending longitude index in the MW
c n = velocity component
c author: r. c. pacanowski e-mail=> rcp@gfdl.gov
c-----------------------------------------------------------------------
c
#ifdef energy_analysis
# include "param.h"
# include "coord.h"
# include "emode.h"
# include "diag.h"
# include "grdvar.h"
# include "hmixc.h"
# include "levind.h"
# include "mw.h"
# include "vmixc.h"
dimension ext(imt,2)
# include "fdifm.h"
c
# ifdef timing
call tic ('diagnostic', 'energy analysis')
# endif
c
do j=js,je
jrow = j + joff
# ifdef stream_function
c
c-----------------------------------------------------------------------
c compute the external mode velocities
c-----------------------------------------------------------------------
c
do i=is,ie
diag1 = psi(i+1,jrow+1,1) - psi(i ,jrow,1)
diag0 = psi(i ,jrow+1,1) - psi(i+1,jrow,1)
ext(i,1) = -(diag1+diag0)*dyu2r(jrow)*hr(i,jrow)
ext(i,2) = (diag1-diag0)*dxu2r(i)*hr(i,jrow)*csur(jrow)
enddo
# endif
c
c-----------------------------------------------------------------------
c compute work done by each term on the internal and external
c modes in the momentum equations
c-----------------------------------------------------------------------
c
fx = csu(jrow)*dyu(jrow)
# ifdef symmetry
if (jrow .eq. jmtm1) fx = fx*p5
# endif
do k=1,km
do i=is,ie
# ifdef stream_function
uext = ext(i,n)
# else
uext = ubar(i,jrow,n)
# endif
uint = u(i,k,j,n,tau) - uext
boxvol = fx*dxu(i)*dzt(k)
c
c-----------------------------------------------------------------------
c pressure term
c-----------------------------------------------------------------------
c
term = -umask(i,k,j)*grad_p(i,k,j,n)
call addto (engint(k,6,jrow), uint*term*boxvol)
call addto (engext(6,jrow), uext*term*boxvol)
c
c-----------------------------------------------------------------------
c coriolis term does no work: u*fv - v*fu = 0
c implicit coriolis work will be reflected in the imbalance
c between horizontal pressure forces and buoyancy
c-----------------------------------------------------------------------
c
c
c-----------------------------------------------------------------------
c zonal and meridional advection of momentum + metric term
c-----------------------------------------------------------------------
c
term =-umask(i,k,j)*
& (ADV_Ux(i,k,j) + ADV_Uy(i,k,j) + ADV_metric(i,k,j,n))
call addto (engint(k,2,jrow), uint*term*boxvol)
call addto (engext(2,jrow), uext*term*boxvol)
c
c-----------------------------------------------------------------------
c vertical advection of momentum
c-----------------------------------------------------------------------
c
term = -umask(i,k,j)*ADV_Uz(i,k,j)
call addto (engint(k,3,jrow), uint*term*boxvol)
call addto (engext(3,jrow), uext*term*boxvol)
# ifdef implicit_free_surface
c
c add effect due to change in volume of top layer
c
if (k .eq. 1) then
dhdt = p5*umask(i,1,j)*fx*dxu(i)*adv_vbu(i,0,j)
call addto (engext(3,jrow), dhdt*u(i,1,j,n,tau)**2)
endif
# endif
c
c-----------------------------------------------------------------------
c zonal and meridional diffusion of momentum + metric term
c-----------------------------------------------------------------------
c
term = umask(i,k,j)*
& (DIFF_Ux(i,k,j) + DIFF_Uy(i,k,j)+DIFF_metric(i,k,j,n))
call addto (engint(k,4,jrow), uint*term*boxvol)
call addto (engext(4,jrow), uext*term*boxvol)
c
c-----------------------------------------------------------------------
c vertical diffusion of momentum
c-----------------------------------------------------------------------
c
term = umask(i,k,j)*DIFF_Uz(i,k,j)
# ifdef implicitvmix
& + umask(i,k,j)*zzi(i,k,j)
# endif
call addto (engint(k,5,jrow), uint*term*boxvol)
call addto (engext(5,jrow), uext*term*boxvol)
enddo
enddo
c
c-----------------------------------------------------------------------
c work done by wind stress
c-----------------------------------------------------------------------
c
k = 1
do i=is,ie
# ifdef stream_function
uext = ext(i,n)
# else
uext = ubar(i,jrow,n)
# endif
uint = u(i,k,j,n,tau) - uext
term = umask(i,k,j)*smf(i,j,n)
call addto (engint(k,7,jrow), uint*term*fx*dxu(i))
call addto (engext(7,jrow), uext*term*fx*dxu(i))
enddo
c
c-----------------------------------------------------------------------
c work done by bottom drag
c-----------------------------------------------------------------------
c
do i=is,ie
# ifdef stream_function
uext = ext(i,n)
# else
uext = ubar(i,jrow,n)
# endif
k = kmu(i,jrow)
if (k .ne. 0) then
uint = u(i,k,j,n,tau) - uext
term = -umask(i,k,j)*bmf(i,j,n)
call addto (engint(k,8,jrow), uint*term*fx*dxu(i))
call addto (engext(8,jrow), uext*term*fx*dxu(i))
endif
enddo
enddo
c
# ifdef timing
call toc ('diagnostic', 'energy analysis')
# endif
return
end
subroutine ge2 (joff, js, je, is, ie, kmt, kmu, c2dtuv, grav
&, rho0r)
c
c-----------------------------------------------------------------------
c compute global energetics by taking u dot the momentum equations
c and integrating over the entire ocean volume
c
c input:
c joff = offset relating "j" in the MW to latitude "jrow"
c js = starting row in the MW
c je = ending row in the MW
c is = starting longitude index in the MW
c ie = ending longitude index in the MW
c author: r. c. pacanowski e-mail=> rcp@gfdl.gov
c-----------------------------------------------------------------------
c
# include "param.h"
# include "coord.h"
# include "emode.h"
# include "diag.h"
# include "grdvar.h"
# include "mw.h"
dimension ext(imt,2)
dimension kmt(imt,jmt), kmu(imt,jmt)
# include "fdifm.h"
# ifdef timing
call tic ('diagnostic', 'energy analysis')
# endif
c
do j=js,je
jrow = j + joff
c
c-----------------------------------------------------------------------
c set local constants
c-----------------------------------------------------------------------
c
fx = csu(jrow)*dyu(jrow)
# ifdef symmetry
if (jrow .eq. jmtm1) fx = fx*p5
# endif
# ifdef stream_function
c
c-----------------------------------------------------------------------
c compute the external mode velocities
c-----------------------------------------------------------------------
c
do i=is,ie
diag1 = psi(i+1,jrow+1,1) - psi(i ,jrow,1)
diag0 = psi(i ,jrow+1,1) - psi(i+1,jrow,1)
ext(i,1) = -(diag1+diag0)*dyu2r(jrow)*hr(i,jrow)
ext(i,2) = (diag1-diag0)*dxu2r(i)*hr(i,jrow)*csur(jrow)
enddo
# endif
c
c-----------------------------------------------------------------------
c compute work done by each term on the internal and external
c modes in the momentum equations
c-----------------------------------------------------------------------
c
r2dt = c1/c2dtuv
do n=1,2
do k=1,km
do i=is,ie
# ifdef stream_function
uext = ext(i,n)
# else
uext = ubar(i,jrow,n)
# endif
uint = u(i,k,j,n,tau) - uext
boxvol = fx*dxu(i)*dzt(k)
c
c-----------------------------------------------------------------------
c total change in kinetic energy.
c-----------------------------------------------------------------------
c
term = umask(i,k,j)*(u(i,k,j,n,taup1)-
& u(i,k,j,n,taum1))*r2dt
call addto (engint(k,1,jrow), uint*term*boxvol)
call addto (engext(1,jrow), uext*term*boxvol)
enddo
enddo
enddo
enddo
c
c-----------------------------------------------------------------------
c compute the work done by buoyancy integrated over the entire
c ocean volume.
c-----------------------------------------------------------------------
c
do j=js,je
jrow = j + joff
f1 = cst(jrow)*dyt(jrow)
do i=is,ie
kz = kmt(i,jrow)
if (kz .ne. 0) then
area = f1*dxt(i)
fx = area*grav*rho0r*p5
term = - c2*fx*dzw(0)*adv_vbt(i,0,j)*rho(i,1,j)
call addto (buoy(1,jrow), term)
do k=2,kz
term =-fx*dzw(k-1)*adv_vbt(i,k-1,j)*
& (rho(i,k-1,j) + rho(i,k,j))
call addto (buoy(k,jrow), term)
enddo
endif
enddo
enddo
c
c-----------------------------------------------------------------------
c find maximum error in continuity for "t" cells and "u" cells
c-----------------------------------------------------------------------
c
do j=js,je
jrow = j + joff
do k=1,km
do i=is,ie
term =
& ((adv_vet(i,k,j) - adv_vet(i-1,k,j))*cstr(jrow)*dxtr(i)
& +(adv_vnt(i,k,j) - adv_vnt(i,k,j-1))*cstr(jrow)*dytr(jrow)
& +(adv_vbt(i,k-1,j) - adv_vbt(i,k,j))*dztr(k))*tmask(i,k,j)
if (abs(term) .gt. abs(tcerr(jrow))) then
tcerr(jrow) = term
itcerr(jrow) = i
jtcerr(jrow) = jrow
ktcerr(jrow) = k
endif
c
term =
& ((adv_veu(i,k,j) - adv_veu(i-1,k,j))*csur(jrow)*dxur(i)
& +(adv_vnu(i,k,j) - adv_vnu(i,k,j-1))*csur(jrow)*dyur(jrow)
& +(adv_vbu(i,k-1,j) - adv_vbu(i,k,j))*dztr(k))*umask(i,k,j)
if (abs(term) .gt. abs(ucerr(jrow))) then
ucerr(jrow) = term
iucerr(jrow) = i
jucerr(jrow) = jrow
kucerr(jrow) = k
endif
enddo
enddo
enddo
c
c-----------------------------------------------------------------------
c find max error in "adv_vbt" at bottom and max "adv_vbu" at bottom
c-----------------------------------------------------------------------
c
do j=js,je
jrow = j + joff
do i=is,ie
k = kmt(i,jrow)
if (k.ne.0 .and.
& (abs(adv_vbt(i,k,j)) .gt. abs(wtbot(jrow)))) then
wtbot(jrow) = adv_vbt(i,k,j)
iwtbot(jrow) = i
jwtbot(jrow) = jrow
kwtbot(jrow) = k
endif
enddo
enddo
c
do j=js,je
jrow = j + joff
do i=is,ie
k = kmu(i,jrow)
if (k.ne.0 .and.
& (abs(adv_vbu(i,k,j)) .gt. abs(wubot(jrow))))then
wubot(jrow) = adv_vbu(i,k,j)
iwubot(jrow) = i
jwubot(jrow) = jrow
kwubot(jrow) = k
endif
enddo
enddo
c
c
c-----------------------------------------------------------------------
c integrate "adv_vbt" and "adv_vbu" for all lat and lon
c-----------------------------------------------------------------------
c
do j=js,je
jrow = j + joff
do k=1,km
do i=is,ie
udxdy = umask(i,k,j)*dxu(i)*csu(jrow)*dyu(jrow)
tdxdy = tmask(i,k,j)*dxt(i)*cst(jrow)*dyt(jrow)
wtlev(k,jrow) = wtlev(k,jrow) + adv_vbt(i,k,j)*tdxdy
wulev(k,jrow) = wulev(k,jrow) + adv_vbu(i,k,j)*udxdy
enddo
enddo
enddo
c
# ifdef timing
call toc ('diagnostic', 'energy analysis')
# endif
return
end
subroutine ge3 (c2dtuv)
c
c-----------------------------------------------------------------------
c compute global energetics by taking u dot the momentum equations
c and integrating over the entire ocean volume
c
c author: r. c. pacanowski e-mail=> rcp@gfdl.gov
c-----------------------------------------------------------------------
c
# include "param.h"
# include "coord.h"
# include "emode.h"
# include "diag.h"
# include "grdvar.h"
# include "levind.h"
# include "mw.h"
dimension ext(imt,2,2)
c
# ifdef timing
call tic ('diagnostic', 'energy analysis')
# endif
do jrow=2,jmt-1
fx = csu(jrow)*dyu(jrow)
# ifdef symmetry
if (jrow .eq. jmtm1) fx = fx*p5
# endif
# ifdef stream_function
c
c-----------------------------------------------------------------------
c compute the external mode velocities after external mode has
c been updated. since the external mode has been updated,
c m = 1 is "tau+1"
c m = 2 is "tau"
c-----------------------------------------------------------------------
c
do m=1,2
do i=2,imtm1
diag1 = psi(i+1,jrow+1,m) - psi(i ,jrow,m)
diag0 = psi(i ,jrow+1,m) - psi(i+1,jrow,m)
ext(i,1,m) = -(diag1+diag0)*dyu2r(jrow)*hr(i,jrow)
ext(i,2,m) = (diag1-diag0)*dxu2r(i)*hr(i,jrow)*csur(jrow)
enddo
enddo
# endif
c
c-----------------------------------------------------------------------
c compute external mode part of work done by "tau+1"
c component of d/dt. internal mode part is zero. since the
c external mode has been updated:
c ubarm1 is "tau"
c ubar is "tau+1"
c note: if using 5 point numerics when solving for the stream
c function, the total integral is not conserved for the
c external mode which shows itself as the "ficticious" term
c in the global energy integrals.
c-----------------------------------------------------------------------
c
r2dt = c1/c2dtuv
do i=2,imtm1
# ifdef stream_function
uext = ext(i,1,2)
vext = ext(i,2,2)
uextn = ext(i,1,1)
vextn = ext(i,2,1)
# else
uext = ubarm1(i,jrow,1)
vext = ubarm1(i,jrow,2)
uextn = ubar(i,jrow,1)
vextn = ubar(i,jrow,2)
# endif
boxvol = fx*dxu(i)*h(i,jrow)
term = (uext*uextn + vext*vextn)*r2dt
call addto (engext(1,jrow), term*boxvol)
enddo
c
enddo
# ifdef timing
call toc ('diagnostic', 'energy analysis')
# endif
#endif
return
end
c
subroutine addto (sum, term)
c
c place lock here to prevent conflicts when parallel processing
c
sum = sum + term
return
end