-
Notifications
You must be signed in to change notification settings - Fork 0
/
mom.F
523 lines (520 loc) · 17.4 KB
/
mom.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
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
subroutine mom
c
c=======================================================================
c
c GFDL Modular Ocean Model
c
c
c A primitive equation ocean model implemented by
c
c R.C. Pacanowski C. Goldberg A. Rosati K. Dixon
c
c at the
c
c Geophysical Fluid Dynamics Laboratory /NOAA
c Princeton, NJ. 08542
c
c based on the pioneering work of
c
c Kirk Bryan: A numerical method for the study of the of the
c circulation world ocean: 1969, J. Computat. Phys 4 347-376
c
c and
c
c the invaluable work of Mike Cox & Bert Semtner on earlier
c fortran implementations.
c
c
c The GFDL Modular Ocean Model (acronym MOM) is a three
c dimensional primitive equation ocean model intended to be
c a flexible tool useful for ocean and coupled air-sea modeling
c applications over a wide range of space & time scales.
c It is also intended to run efficiently on scalar, vector &
c parallel architectures. The programming approach is
c modular and additions to this model are encouraged to follow
c this approach. Additional modules will be added with time and
c new versions will be released as waranted. Please
c refer to the read_me file for more details until a proper user
c guide is available.
c
c Requirements:
c
c Standard fortran 77 is used (except for namelist, do enddo, and
c variable names longer than 6 characters)
c The preprocessor "cpp" (available on systems using "c" or UNIX)
c
c Please refer questions or problems directly to the author(s)
c who are responsible for their sections of code.
c
c
c Disclaimer:
c
c MOM is an ocean modeling research tool developed at GFDL.
c Others may use it freely but we assume no responsibility
c for problems or incorrect use of MOM. It is left to the user to
c satisfy (him/her)self that a particular configuration is
c working correctly. To this end, many of the included
c diagnostics will be helpful.
c
c author: r. c. pacanowski e-mail=> [email protected]
c=======================================================================
c
external blkdta
c
#include "param.h"
#include "emode.h"
#include "iounit.h"
#include "mw.h"
#include "scalar.h"
#include "switch.h"
#include "tmngr.h"
save cps, itt1st
c
#ifdef timing
call tic ('driver', 'ocean')
call tic ('ocean', 'misc')
#endif
c
c-----------------------------------------------------------------------
c integrate one time step
c-----------------------------------------------------------------------
c
c
c-----------------------------------------------------------------------
c update timestep counter, set corresponding model time, and set
c time dependent logical switches which determine program flow.
c-----------------------------------------------------------------------
c
itt = itt + 1
call tmngr (dtts)
c
c-----------------------------------------------------------------------
c read system clock to calculate compute_time/grid_point/timestep
c (neglecting overhead of "setocn")
c-----------------------------------------------------------------------
c
if (first) then
itt1st = itt
cps = cpusec()
endif
c
c-----------------------------------------------------------------------
c initialize diagnostic variables
c-----------------------------------------------------------------------
c
call diagi
c
c-----------------------------------------------------------------------
c adjust various quantities for leapfrog/mixing timesteps
c
c leapfrog----------> h(tau+1) = h(tau-1) + 2dt*F(tau)
c
c forward-----------> tau-1 <= tau
c h(tau+1) = h(tau-1) + dt*F(tau)
c
c euler backward: tau-1 <= tau
c euler1----------> h(tau` ) = h(tau-1) + dt*F(tau)
c euler2----------> h(tau+1) = h(tau-1) + dt*F(tau')
c-----------------------------------------------------------------------
c
if (leapfrog) then
c
c normal leapfrog time step
c
euler1 = .false.
euler2 = .false.
forward = .false.
eots = .true.
c
c2dtts = c2*dtts
c2dtuv = c2*dtuv
c2dtsf = c2*dtsf
else
c
c mixing time step (forward step or euler backward step)
c
if (eb) then
euler1 = .true.
euler2 = .false.
forward = .false.
eots = .false.
else
euler1 = .false.
euler2 = .false.
forward = .true.
eots = .true.
endif
c
c2dtts = dtts
c2dtuv = dtuv
c2dtsf = dtsf
c
#ifdef stream_function
do jrow=1,jmt
do i=1,imt
psi(i,jrow,2) = psi(i,jrow,1)
enddo
enddo
#endif
endif
c
#if defined rigid_lid_surface_pressure || defined implicit_free_surface
if (leapfrog) then
apgr = alph
else
apgr = theta
do jrow=1,jmt
do i=1,imt
ubarm1(i,jrow,1) = ubar(i,jrow,1)
ubarm1(i,jrow,2) = ubar(i,jrow,2)
enddo
enddo
endif
#endif
c
#ifdef implicit_free_surface
if (leapfrog) then
if (acor .ne. c0) acor = alph
else
if (acor .ne. c0) acor = theta
endif
#endif
c
c-----------------------------------------------------------------------
c set time centering "gcor" for coriolis term
c-----------------------------------------------------------------------
c
if (acor .eq. c0) then
gcor = c1
elseif (acor .ne. c0) then
gcor = c0
endif
c
#if defined implicit_free_surface
c
c set "gcor" for leapfrog or mixing time steps
c
if (leapfrog) then
if (acor .eq. c0) then
gcor = c1
else
gcor = gam
endif
else
gcor = c0
endif
#endif
c
c-----------------------------------------------------------------------
c update pointers to tau-1, tau, & tau+1 data on disk.
c for latitude rows they point to latdisk(1) or latdisk(2)
c for 2D fields they point to records on kflds
c-----------------------------------------------------------------------
c
taum1disk = mod(itt+1,2) + 1
taudisk = mod(itt ,2) + 1
taup1disk = taum1disk
c
c-----------------------------------------------------------------------
c update pointers (indices) to tau-1, tau, & tau+1 data in the MW
c-----------------------------------------------------------------------
c
if (wide_open_mw) then
c
c rotate time levels instead of moving data
c
taum1 = mod(itt+0,3) - 1
tau = mod(itt+1,3) - 1
taup1 = mod(itt+2,3) - 1
else
c
c they are being held constant in time.
c
endif
c
c=======================================================================
c
c SOLVE THE BAROCLINIC AND TRACER EQUATIONS
c
c Since all latitude rows may not fit into central memory, a
c flexible MW (memory window) approach is used. The minimum MW
c holds 3 latitude rows and the maximum MW holds "jmt" latitude
c rows in central memory. Choose the size to fit into available
c central memory. The MW is loaded with variables from disk as
c many times as needed to solve latitude rows 2 through "jmt-2".
c
c Example using a MW with 3 rows (jmw=3)
c
c "loadmw" loads variables from the first 3 latitude jrows into
c rows js=1 through je=3 in the 1st MW (mw=1). Equations are
c computed for j=2 in the MW (corresponding to latitude jrow=2)
c then written to disk. For the second MW (mw=2), "loadmw"
c first moves variables from j=2 to j=1, then moves variables from
c j=3 to j=2 in the MW, before loading latitude jrow=4 variables
c into row js=je=3 in the MW. Equations are computed for j=2 in
c the MW (corresponding to latitude jrow=3) then written to disk. The
c process continues until latitude jrows 2 through jmt-1 are
c computed.
c
c Example using a MW with 5 rows (jmw=5)
c
c "loadmw" loads variables from the first 5 latitude jrows into
c rows js=1 through je=5 in the 1st MW (mw=1). Equations are
c computed for j=2,3,4 in the MW (latitude jrows=2,3,4)
c and written to disk. For the second MW (mw=2),
c "loadmw" first moves variables from j=2 to j=1, then moves
c variables from j=3 to j=2 in the MW, before loading jrow 6,7,8
c variables into rows js=3 to je=5 in the MW. Equations
c are computed for j=2,3,4 in the MW (latitude jrows=5,6,7)
c then written to disk. The process continues until latitude
c jrows 2 through jmt-1 are computed. Note that the last MW may
c not always contain 3 computed rows (depending on "jmt").
c
c Note:
c
c When the MW is fully opened (jmw=jmt), all latitude rows
c reside in the MW (none on disk). Instead of reading/writing
c from MW to disk, data is moved between time levels within the
c MW.
c
c=======================================================================
c
1000 continue
#ifdef trace_indices
if (leapfrog) write (stdout,'(/1x,a)')
& 'Starting a --->Leapfrog timestep'
if (forward) write (stdout,'(/1x,a)')
& 'Starting a --->Forward timestep'
if (euler1) write (stdout,'(/1x,a)')
& 'Starting the first step of an ---> Euler backward timestep'
if (euler2) write (stdout,'(/1x,a)')
& 'Starting the second step of an --->Euler backward tstep'
write (stdout,'(//1x,7(a,i4))')
& "=> In mom: itt=",itt," disk indices: taum1disk =",taum1disk
&," taudisk=",taudisk," taup1disk=",taup1disk
&,", memory window indices: taum1=",taum1," tau=",tau
&," taup1 ",taup1
#endif
c
c-----------------------------------------------------------------------
c establish a queue for reading all "tau-1" and "tau" latitude
c rows from disk into the MW. (only needed when i/o is slow to
c overlap computation. otherwise this does nothing)
c-----------------------------------------------------------------------
c
if (wide_open_mw) then
c
c no need to do anything
c
else
do jrow = 1,jmt
if (leapfrog .or. euler2) then
call ofind (latdisk(taum1disk), nslab, jrow)
endif
call ofind (latdisk(taudisk), nslab, jrow)
enddo
endif
c
c-----------------------------------------------------------------------
c compute latitude rows within one MW, then move northward
c and repeat until latitudes (2..jmt-1) are computed.
c-----------------------------------------------------------------------
c
do mw = 1,maxmw
c
c-----------------------------------------------------------------------
c joff = offset relating row "j" in the MW to latitude "jrow"
c js = starting row within the MW for LOADING latitude row
c je = ending row within the MW for LOADING latitude row
c is = starting index longitude
c ie = ending index longitude
c
c first MW : load latitude rows into js=1 ... je=jmw
c 1 < MW < last: load latitude rows into js=jsmw+1 ... je=jmw
c last MW : load latitude rows into js=jsmw+1 ... je<=jmw
c-----------------------------------------------------------------------
c
joff = (mw-1)*ncrows
#ifdef biharmonic
js = (jsmw+1)*(1-1/mw) + 1
#else
js = jsmw*(1-1/mw) + 1
#endif
je = min(jmw,jmt-joff)
is = 2
ie = imt - 1
#ifdef trace_indices
write (stdout,'(//1x,7(a,i4))')
& "=> In mom: itt=",itt," mw =",mw," js=",js," je=",je
&," joff=",joff," jrows=",js+joff," to ",je+joff
#endif
c
c-----------------------------------------------------------------------
c load prognostic and related variables into the MW
c-----------------------------------------------------------------------
c
call loadmw (joff, js, je, is, ie, latdisk(taum1disk)
&, latdisk(taudisk))
c
c-----------------------------------------------------------------------
c calculate advection velocities for momentum and tracers
c-----------------------------------------------------------------------
c
call adv_vel (joff, js, je, is, ie)
c
#ifdef isopycmix
c
c-----------------------------------------------------------------------
c calculate isopycnal diffusion tensor components (and
c gent_mcwilliams advective velocities) for use with tracers
c-----------------------------------------------------------------------
c
call isopyc (joff, js, je, is, ie)
#endif
c
c-----------------------------------------------------------------------
c set vertical mixing coefficients for momentum and tracers
c-----------------------------------------------------------------------
c
call vmixc (joff, js, je, is, ie)
c
c-----------------------------------------------------------------------
c set horizontal mixing coefficients for momentum and tracers
c-----------------------------------------------------------------------
c
call hmixc (joff, js, je, is, ie)
c
c
c-----------------------------------------------------------------------
c set which MW rows to calculate: jscalc through jecalc
c
c 1 <= MW < last: calculate rows jsmw...jemw
c rows jsmw...jemw-1 for biharmonic
c last MW : calculate rows jsmw...je-1 (MW may not be full
c rows jsmw...je-2 for biharmonic
c-----------------------------------------------------------------------
c
jscalc = jsmw
#ifdef biharmonic
jecalc = je - 2
if (mw .eq. maxmw) jecalc = je - 1
#else
jecalc = je-1
#endif
c
c-----------------------------------------------------------------------
c set vertical boundary conditions for momentum and tracers
c-----------------------------------------------------------------------
c
call setvbc (joff, jscalc, jecalc, is, ie)
c
c-----------------------------------------------------------------------
c compute internal mode velocities and tracers
c-----------------------------------------------------------------------
c
call clinic (joff, jscalc, jecalc, is, ie)
call tracer (joff, jscalc, jecalc, is, ie)
c
c-----------------------------------------------------------------------
c calculate diagnostics
c-----------------------------------------------------------------------
c
call diag (joff, jscalc, jecalc, is, ie)
c
c-----------------------------------------------------------------------
c write prognostic variables from the MW to disk "tau+1"
c-----------------------------------------------------------------------
c
if (wide_open_mw) then
c
c do nothing since variables are already in "tau+1" MW
c
else
call putmw (joff, jscalc, jecalc, latdisk(taup1disk))
endif
c
enddo
c
c=======================================================================
c
c SOLVE THE BAROTROPIC EQUATION
c
c=======================================================================
c
call tropic (c2dtsf, acor, cori(1,1), itt)
c
c-----------------------------------------------------------------------
c if this is the 1st pass of an euler backward timestep, set the
c disk pointers so the proper time levels are read on the 2nd pass
c and go back to do the 2nd pass.
c-----------------------------------------------------------------------
c
if (euler1) then
eots = .true.
euler1 = .false.
euler2 = .true.
ntaux = taum1disk
taum1disk = taudisk
taudisk = taup1disk
taup1disk = ntaux
go to 1000
endif
if (wide_open_mw .and. euler2) then
c
c shuffle "tau" and "tau+1" after euler backward to
c insure data is in the right place for the next timestep
c
call euler_shuffle
c
c re-establish correct pointers for this timestep
c
taum1 = mod(itt+0,3) - 1
tau = mod(itt+1,3) - 1
taup1 = mod(itt+2,3) - 1
endif
c
c-----------------------------------------------------------------------
c output all remaining diagnostics
c-----------------------------------------------------------------------
c
call diago
c
c-----------------------------------------------------------------------
c if it`s the last timestep then clean things up otherwise return
c-----------------------------------------------------------------------
c
if (eorun) then
c
c calculate cp_time/grid_point/timestep (neglecting setocn)
c
ncalls = itt - itt1st + 1
cpe = cpusec()
write (stdout,'(/,1x, a, f9.3, a,1x,a,1pg14.7,a)')
& 'Timing Summary: ', cpe-cps, ' cp seconds,'
&, '(',(cpe-cps)/(ncalls*imt*jmt*km)
&, ' cp seconds per grid point per time step)'
c
c write a restart
c
if (restrt) call write_restart
c
write (stdout,'(1x,a)') 'MOMdone'
call oclose (kflds)
call oclose (latdisk(1))
call oclose (latdisk(2))
endif
c
#ifdef timing
call toc ('ocean', 'misc')
call toc ('driver', 'ocean')
#endif
c
return
end
function cpusec ()
c
c user supplied function to measure cpu time in seconds
c
cpusec = second()
return
end