/[MITgcm]/MITgcm/model/src/forward_step.F
ViewVC logotype

Contents of /MITgcm/model/src/forward_step.F

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.72 - (show annotations) (download)
Thu Nov 6 22:01:43 2003 UTC (20 years, 7 months ago) by heimbach
Branch: MAIN
CVS Tags: checkpoint52, checkpoint52a_pre, ecco_c52_e35, checkpoint51u_post
Changes since 1.71: +3 -8 lines
o merging from ecco-branch
o minor CPP options update

1 C $Header: /u/gcmpack/MITgcm/model/src/forward_step.F,v 1.71 2003/11/04 18:40:58 edhill Exp $
2 C $Name: $
3
4 #include "PACKAGES_CONFIG.h"
5 #include "CPP_OPTIONS.h"
6
7 cswdptr -- add --
8 #ifdef ALLOW_GCHEM
9 # include "GCHEM_OPTIONS.h"
10 #endif
11 cswdptr -- end add ---
12
13 CBOP
14 C !ROUTINE: FORWARD_STEP
15 C !INTERFACE:
16 SUBROUTINE FORWARD_STEP( iloop, myTime, myIter, myThid )
17
18 C !DESCRIPTION: \bv
19 C *==================================================================
20 C | SUBROUTINE forward_step
21 C | o Run the ocean model and, optionally, evaluate a cost function.
22 C *==================================================================
23 C |
24 C | THE_MAIN_LOOP is the toplevel routine for the Tangent Linear and
25 C | Adjoint Model Compiler (TAMC). For this purpose the initialization
26 C | of the model was split into two parts. Those parameters that do
27 C | not depend on a specific model run are set in INITIALISE_FIXED,
28 C | whereas those that do depend on the specific realization are
29 C | initialized in INITIALISE_VARIA.
30 C |
31 C *==================================================================
32 C \ev
33
34 C !USES:
35 IMPLICIT NONE
36 C == Global variables ==
37 #include "SIZE.h"
38 #include "EEPARAMS.h"
39 #include "PARAMS.h"
40 #include "DYNVARS.h"
41 #include "FFIELDS.h"
42
43 #ifdef ALLOW_NONHYDROSTATIC
44 #include "CG3D.h"
45 #endif
46
47 #ifdef ALLOW_SHAP_FILT
48 #include "SHAP_FILT.h"
49 #endif
50 #ifdef ALLOW_ZONAL_FILT
51 #include "ZONAL_FILT.h"
52 #endif
53
54 #ifdef ALLOW_AUTODIFF_TAMC
55 # include "tamc.h"
56 # include "ctrl.h"
57 # include "ctrl_dummy.h"
58 # include "cost.h"
59 # include "EOS.h"
60 # ifdef ALLOW_EXF
61 # include "exf_fields.h"
62 # ifdef ALLOW_BULKFORMULAE
63 # include "exf_constants.h"
64 # endif
65 # endif
66 # ifdef ALLOW_OBCS
67 # include "OBCS.h"
68 # endif
69 # ifdef ALLOW_PTRACERS
70 # include "PTRACERS.h"
71 # endif
72 #endif /* ALLOW_AUTODIFF_TAMC */
73
74 C !LOCAL VARIABLES:
75 C == Routine arguments ==
76 C note: under the multi-threaded model myiter and
77 C mytime are local variables passed around as routine
78 C arguments. Although this is fiddly it saves the need to
79 C impose additional synchronisation points when they are
80 C updated.
81 C myiter - iteration counter for this thread
82 C mytime - time counter for this thread
83 C mythid - thread number for this instance of the routine.
84 integer iloop
85 integer mythid
86 integer myiter
87 _RL mytime
88 #ifdef ALLOW_BULK_FORCE
89 INTEGER bi,bj
90 #endif
91
92 CEOP
93
94 #ifdef ALLOW_DEBUG
95 IF ( debugLevel .GE. debLevB )
96 & CALL DEBUG_ENTER('FORWARD_STEP',myThid)
97 #endif
98
99 #ifdef ALLOW_AUTODIFF_TAMC
100 C-- Reset the model iteration counter and the model time.
101 myiter = nIter0 + (iloop-1)
102 mytime = startTime + float(iloop-1)*deltaTclock
103 #endif
104
105 #if (defined (ALLOW_AUTODIFF_TAMC) && defined (ALLOW_AUTODIFF_MONITOR))
106 C Include call to a dummy routine. Its adjoint will be
107 C called at the proper place in the adjoint code.
108 C The adjoint routine will print out adjoint values
109 C if requested. The location of the call is important,
110 C it has to be after the adjoint of the exchanges
111 C (DO_GTERM_BLOCKING_EXCHANGES).
112 CALL DUMMY_IN_STEPPING( myTime, myIter, myThid )
113 cph I've commented this line since it may conflict with MITgcm's adjoint
114 cph However, need to check whether that's still consistent
115 cph with the ecco-branch (it should).
116 cph CALL DO_FIELDS_BLOCKING_EXCHANGES( myThid )
117 #endif
118
119 #ifdef EXACT_CONSERV
120 IF (exactConserv) THEN
121 C-- Update etaH(n+1) :
122 CALL TIMER_START('UPDATE_ETAH [FORWARD_STEP]',mythid)
123 CALL UPDATE_ETAH( myTime, myIter, myThid )
124 CALL TIMER_STOP ('UPDATE_ETAH [FORWARD_STEP]',mythid)
125 ENDIF
126 #endif /* EXACT_CONSERV */
127
128 #ifdef NONLIN_FRSURF
129 IF ( select_rStar.NE.0 ) THEN
130 C-- r* : compute the future level thickness according to etaH(n+1)
131 CALL TIMER_START('CALC_R_STAR [FORWARD_STEP]',mythid)
132 CALL CALC_R_STAR(etaH, myTime, myIter, myThid )
133 CALL TIMER_STOP ('CALC_R_STAR [FORWARD_STEP]',mythid)
134 ELSEIF ( nonlinFreeSurf.GT.0) THEN
135 C-- compute the future surface level thickness according to etaH(n+1)
136 CALL TIMER_START('CALC_SURF_DR [FORWARD_STEP]',mythid)
137 CALL CALC_SURF_DR(etaH, myTime, myIter, myThid )
138 CALL TIMER_STOP ('CALC_SURF_DR [FORWARD_STEP]',mythid)
139 ENDIF
140 #endif /* NONLIN_FRSURF */
141
142 #ifdef ALLOW_AUTODIFF_TAMC
143 c**************************************
144 #include "checkpoint_lev1_directives.h"
145 c**************************************
146 #endif
147
148 C-- Call external forcing package
149 #ifdef ALLOW_BULK_FORCE
150 IF ( useBulkforce ) THEN
151 #ifdef ALLOW_DEBUG
152 IF ( debugLevel .GE. debLevB )
153 & CALL DEBUG_CALL('BULKF_FIELDS_LOAD',myThid)
154 #endif
155 CALL TIMER_START('BULKF_FIELDS_LOAD[THE_MAIN_LOOP]',mythid)
156 CALL BULKF_FIELDS_LOAD( mytime, myiter, mythid )
157 CALL TIMER_STOP ('BULKF_FIELDS_LOAD[THE_MAIN_LOOP]',mythid)
158 c calculate qnet and empmr (and wind stress)
159 DO bj=myByLo(myThid),myByHi(myThid)
160 DO bi=myBxLo(myThid),myBxHi(myThid)
161 CALL BULKF_FORCING( bi,bj, mytime, myiter, mythid )
162 ENDDO
163 ENDDO
164 c Update the tile edges.
165 _EXCH_XY_R8(Qnet, mythid)
166 _EXCH_XY_R8(EmPmR, mythid)
167 CALL EXCH_UV_XY_RS(fu, fv, .TRUE., myThid)
168 C _EXCH_XY_R8(fu , mythid)
169 C _EXCH_XY_R8(fv , mythid)
170 ELSE
171 #endif /* ALLOW_BULK_FORCE */
172
173 # ifdef ALLOW_EXF
174 # ifdef ALLOW_DEBUG
175 IF ( debugLevel .GE. debLevB )
176 & CALL DEBUG_CALL('EXF_GETFORCING',myThid)
177 # endif
178 CALL TIMER_START('EXF_GETFORCING [FORWARD_STEP]',mythid)
179 CALL EXF_GETFORCING( mytime, myiter, mythid )
180 CALL TIMER_STOP ('EXF_GETFORCING [FORWARD_STEP]',mythid)
181 # else /* ALLOW_EXF undef */
182 cph The following IF-statement creates an additional dependency
183 cph for the forcing fields requiring additional storing.
184 cph Therefore, the IF-statement will be put between CPP-OPTIONS,
185 cph assuming that ALLOW_SEAICE has not yet been differentiated.
186 # ifdef ALLOW_SEAICE
187 IF ( .NOT. useSEAICE ) THEN
188 # endif
189 #ifdef ALLOW_DEBUG
190 IF ( debugLevel .GE. debLevB )
191 & CALL DEBUG_CALL('EXTERNAL_FIELDS_LOAD',myThid)
192 #endif
193 CALL TIMER_START('EXTERNAL_FIELDS_LOAD[FORWARD_STEP]',mythid)
194 CALL EXTERNAL_FIELDS_LOAD( mytime, myiter, mythid )
195 CALL TIMER_STOP ('EXTERNAL_FIELDS_LOAD[FORWARD_STEP]',mythid)
196 # ifdef ALLOW_SEAICE
197 ENDIF
198 # endif
199 # endif /* ALLOW_EXF */
200 #ifdef ALLOW_BULK_FORCE
201 C-- end of if/else block useBulfforce --
202 ENDIF
203 #endif /* ALLOW_BULK_FORCE */
204
205 #ifdef ALLOW_AUTODIFF
206 c-- Add control vector for forcing and parameter fields
207 if ( myiter .EQ. nIter0 )
208 & CALL CTRL_MAP_FORCING (mythid)
209 #endif
210
211 # ifdef ALLOW_SEAICE
212 C-- Call sea ice model to compute forcing/external data fields. In
213 C addition to computing prognostic sea-ice variables and diagnosing the
214 C forcing/external data fields that drive the ocean model, SEAICE_MODEL
215 C also sets theta to the freezing point under sea-ice. The implied
216 C surface heat flux is then stored in variable surfaceTendencyTice,
217 C which is needed by KPP package (kpp_calc.F and kpp_transport_t.F)
218 C to diagnose surface buoyancy fluxes and for the non-local transport
219 C term. Because this call precedes model thermodynamics, temperature
220 C under sea-ice may not be "exactly" at the freezing point by the time
221 C theta is dumped or time-averaged.
222 IF ( useSEAICE ) THEN
223 #ifdef ALLOW_DEBUG
224 IF ( debugLevel .GE. debLevB )
225 & CALL DEBUG_CALL('SEAICE_MODEL',myThid)
226 #endif
227 CALL TIMER_START('SEAICE_MODEL [FORWARD_STEP]',myThid)
228 CALL SEAICE_MODEL( myTime, myIter, myThid )
229 CALL TIMER_STOP ('SEAICE_MODEL [FORWARD_STEP]',myThid)
230 ENDIF
231 # endif /* ALLOW_SEAICE */
232
233 #ifdef ALLOW_AUTODIFF_TAMC
234 # ifdef ALLOW_PTRACERS
235 cph this replaces _bibj storing of ptracer within thermodynamics
236 CADJ STORE ptracer = comlev1, key = ikey_dynamics
237 # endif
238 #endif
239
240 #ifdef ALLOW_PTRACERS
241 # ifdef ALLOW_GCHEM
242 CALL GCHEM_FIELDS_LOAD( mytime, myiter, mythid )
243 # endif
244 #endif
245
246 C-- Step forward fields and calculate time tendency terms.
247 #ifdef ALLOW_DEBUG
248 IF ( debugLevel .GE. debLevB )
249 & CALL DEBUG_CALL('THERMODYNAMICS',myThid)
250 #endif
251 CALL TIMER_START('THERMODYNAMICS [FORWARD_STEP]',mythid)
252 CALL THERMODYNAMICS( myTime, myIter, myThid )
253 CALL TIMER_STOP ('THERMODYNAMICS [FORWARD_STEP]',mythid)
254
255 C-- do exchanges (needed for DYNAMICS) when using stagger time-step :
256 #ifdef ALLOW_DEBUG
257 IF ( debugLevel .GE. debLevB )
258 & CALL DEBUG_CALL('DO_STAGGER_FIELDS_EXCH.',myThid)
259 #endif
260 CALL TIMER_START('BLOCKING_EXCHANGES [FORWARD_STEP]',myThid)
261 CALL DO_STAGGER_FIELDS_EXCHANGES( myTime, myIter, myThid )
262 CALL TIMER_STOP ('BLOCKING_EXCHANGES [FORWARD_STEP]',myThid)
263
264 #ifdef ALLOW_SHAP_FILT
265 IF (useSHAP_FILT .AND.
266 & staggerTimeStep .AND. shap_filt_TrStagg ) THEN
267 #ifdef ALLOW_DEBUG
268 IF ( debugLevel .GE. debLevB )
269 & CALL DEBUG_CALL('SHAP_FILT_APPLY_TS',myThid)
270 #endif
271 CALL TIMER_START('SHAP_FILT [FORWARD_STEP]',myThid)
272 CALL SHAP_FILT_APPLY_TS(gT,gS,myTime+deltaT,myIter+1,myThid)
273 CALL TIMER_STOP ('SHAP_FILT [FORWARD_STEP]',myThid)
274 ENDIF
275 #endif
276 #ifdef ALLOW_ZONAL_FILT
277 IF (useZONAL_FILT .AND.
278 & staggerTimeStep .AND. zonal_filt_TrStagg ) THEN
279 #ifdef ALLOW_DEBUG
280 IF ( debugLevel .GE. debLevB )
281 & CALL DEBUG_CALL('ZONAL_FILT_APPLY_TS',myThid)
282 #endif
283 CALL TIMER_START('ZONAL_FILT_APPLY [FORWARD_STEP]',myThid)
284 CALL ZONAL_FILT_APPLY_TS( gT, gS, myThid )
285 CALL TIMER_STOP ('ZONAL_FILT_APPLY [FORWARD_STEP]',myThid)
286 ENDIF
287 #endif
288
289 C-- Step forward fields and calculate time tendency terms.
290 #ifndef ALLOW_AUTODIFF_TAMC
291 IF ( momStepping ) THEN
292 #endif
293 #ifdef ALLOW_DEBUG
294 IF ( debugLevel .GE. debLevB )
295 & CALL DEBUG_CALL('DYNAMICS',myThid)
296 #endif
297 CALL TIMER_START('DYNAMICS [FORWARD_STEP]',mythid)
298 CALL DYNAMICS( myTime, myIter, myThid )
299 CALL TIMER_STOP ('DYNAMICS [FORWARD_STEP]',mythid)
300 #ifndef ALLOW_AUTODIFF_TAMC
301 ENDIF
302 #endif
303
304 #ifdef ALLOW_NONHYDROSTATIC
305 C-- Step forward W field in N-H algorithm
306 IF ( momStepping .AND. nonHydrostatic ) THEN
307 #ifdef ALLOW_DEBUG
308 IF ( debugLevel .GE. debLevB )
309 & CALL DEBUG_CALL('CALC_GW',myThid)
310 #endif
311 CALL TIMER_START('CALC_GW [FORWARD_STEP]',myThid)
312 CALL CALC_GW(myThid)
313 CALL TIMER_STOP ('CALC_GW [FORWARD_STEP]',myThid)
314 ENDIF
315 #endif
316
317 #ifdef NONLIN_FRSURF
318 C-- update hfacC,W,S and recip_hFac according to etaH(n+1) :
319 IF ( nonlinFreeSurf.GT.0) THEN
320 IF ( select_rStar.GT.0 ) THEN
321 CALL TIMER_START('UPDATE_R_STAR [FORWARD_STEP]',myThid)
322 CALL UPDATE_R_STAR( myTime, myIter, myThid )
323 CALL TIMER_STOP ('UPDATE_R_STAR [FORWARD_STEP]',myThid)
324 ELSE
325 CALL TIMER_START('UPDATE_SURF_DR [FORWARD_STEP]',myThid)
326 CALL UPDATE_SURF_DR( myTime, myIter, myThid )
327 CALL TIMER_STOP ('UPDATE_SURF_DR [FORWARD_STEP]',myThid)
328 ENDIF
329 ENDIF
330 C- update also CG2D matrix (and preconditioner)
331 IF ( momStepping .AND. nonlinFreeSurf.GT.2 ) THEN
332 CALL TIMER_START('UPDATE_CG2D [FORWARD_STEP]',myThid)
333 CALL UPDATE_CG2D( myTime, myIter, myThid )
334 CALL TIMER_STOP ('UPDATE_CG2D [FORWARD_STEP]',myThid)
335 ENDIF
336 #endif
337
338 C-- Apply Filters to u*,v* before SOLVE_FOR_PRESSURE
339 #ifdef ALLOW_SHAP_FILT
340 IF (useSHAP_FILT .AND. shap_filt_uvStar) THEN
341 CALL TIMER_START('SHAP_FILT [FORWARD_STEP]',myThid)
342 IF (implicDiv2Dflow.LT.1.) THEN
343 C-- Explicit+Implicit part of the Barotropic Flow Divergence
344 C => Filtering of uVel,vVel is necessary
345 CALL SHAP_FILT_APPLY_UV( uVel,vVel,
346 & myTime+deltaT, myIter+1, myThid )
347 ENDIF
348 CALL SHAP_FILT_APPLY_UV( gU,gV,myTime+deltaT,myIter+1,myThid)
349 CALL TIMER_STOP ('SHAP_FILT [FORWARD_STEP]',myThid)
350 ENDIF
351 #endif
352 #ifdef ALLOW_ZONAL_FILT
353 IF (useZONAL_FILT .AND. zonal_filt_uvStar) THEN
354 CALL TIMER_START('ZONAL_FILT_APPLY [FORWARD_STEP]',myThid)
355 IF (implicDiv2Dflow.LT.1.) THEN
356 C-- Explicit+Implicit part of the Barotropic Flow Divergence
357 C => Filtering of uVel,vVel is necessary
358 CALL ZONAL_FILT_APPLY_UV( uVel, vVel, myThid )
359 ENDIF
360 CALL ZONAL_FILT_APPLY_UV( gU, gV, myThid )
361 CALL TIMER_STOP ('ZONAL_FILT_APPLY [FORWARD_STEP]',myThid)
362 ENDIF
363 #endif
364
365 C-- Solve elliptic equation(s).
366 C Two-dimensional only for conventional hydrostatic or
367 C three-dimensional for non-hydrostatic and/or IGW scheme.
368 IF ( momStepping ) THEN
369 CALL TIMER_START('SOLVE_FOR_PRESSURE [FORWARD_STEP]',myThid)
370 CALL SOLVE_FOR_PRESSURE(myTime, myIter, myThid)
371 CALL TIMER_STOP ('SOLVE_FOR_PRESSURE [FORWARD_STEP]',myThid)
372 ENDIF
373
374 #ifdef ALLOW_AUTODIFF_TAMC
375 cph This is needed because convective_adjustment calls
376 cph find_rho which may use pressure()
377 CADJ STORE totphihyd = comlev1, key = ikey_dynamics
378 #endif
379 C-- Correct divergence in flow field and cycle time-stepping
380 C arrays (for all fields) ; update time-counter
381 myIter = nIter0 + iLoop
382 myTime = startTime + deltaTClock * float(iLoop)
383 CALL TIMER_START('THE_CORRECTION_STEP [FORWARD_STEP]',myThid)
384 CALL THE_CORRECTION_STEP(myTime, myIter, myThid)
385 CALL TIMER_STOP ('THE_CORRECTION_STEP [FORWARD_STEP]',myThid)
386
387 C-- Do "blocking" sends and receives for tendency "overlap" terms
388 c CALL TIMER_START('BLOCKING_EXCHANGES [FORWARD_STEP]',myThid)
389 c CALL DO_GTERM_BLOCKING_EXCHANGES( myThid )
390 c CALL TIMER_STOP ('BLOCKING_EXCHANGES [FORWARD_STEP]',myThid)
391
392 C-- Do "blocking" sends and receives for field "overlap" terms
393 CALL TIMER_START('BLOCKING_EXCHANGES [FORWARD_STEP]',myThid)
394 CALL DO_FIELDS_BLOCKING_EXCHANGES( myThid )
395 CALL TIMER_STOP ('BLOCKING_EXCHANGES [FORWARD_STEP]',myThid)
396
397 cswdptr -- add for seperate timestepping of chemical/biological/forcing
398 cswdptr of ptracers ---
399 #ifdef ALLOW_GCHEM
400 ceh3 This is broken -- this ifdef should not be visible!
401 #ifdef PTRACERS_SEPARATE_FORCING
402 ceh3 needs an IF ( use GCHEM ) THEN
403 call GCHEM_FORCING_SEP( myTime,myIter,myThid )
404 #endif /* PTRACERS_SEPARATE_FORCING */
405 #endif /* ALLOW_GCHEM */
406 cswdptr -- end add ---
407
408
409 #ifdef ALLOW_FLT
410 C-- Calculate float trajectories
411 IF (useFLT) THEN
412 CALL TIMER_START('FLOATS [FORWARD_STEP]',myThid)
413 CALL FLT_MAIN(myIter,myTime, myThid)
414 CALL TIMER_STOP ('FLOATS [FORWARD_STEP]',myThid)
415 ENDIF
416 #endif
417
418 #ifdef ALLOW_MONITOR
419 C-- Check status of solution (statistics, cfl, etc...)
420 CALL TIMER_START('MONITOR [FORWARD_STEP]',myThid)
421 CALL MONITOR( myIter, myTime, myThid )
422 CALL TIMER_STOP ('MONITOR [FORWARD_STEP]',myThid)
423 #endif /* ALLOW_MONITOR */
424
425 C-- Do IO if needed.
426 CALL TIMER_START('DO_THE_MODEL_IO [FORWARD_STEP]',myThid)
427 CALL DO_THE_MODEL_IO( myTime, myIter, myThid )
428 CALL TIMER_STOP ('DO_THE_MODEL_IO [FORWARD_STEP]',myThid)
429
430 C-- Save state for restarts
431 C Note: (jmc: is it still the case after ckp35 ?)
432 C =====
433 C Because of the ordering of the timestepping code and
434 C tendency term code at end of loop model arrays hold
435 C U,V,T,S at "time-level" N but gu, gv, gs, gt, guNM1,...
436 C at "time-level" N+1/2 (guNM1 at "time-level" N+1/2 is
437 C gu at "time-level" N-1/2) and etaN at "time-level" N+1/2.
438 C where N = I+timeLevBase-1
439 C Thus a checkpoint contains U.0000000000, GU.0000000001 and
440 C etaN.0000000001 in the indexing scheme used for the model
441 C "state" files. This example is referred to as a checkpoint
442 C at time level 1
443 CALL TIMER_START('WRITE_CHECKPOINT [FORWARD_STEP]',myThid)
444 CALL WRITE_CHECKPOINT(
445 & .FALSE., myTime, myIter, myThid )
446 CALL TIMER_STOP ('WRITE_CHECKPOINT [FORWARD_STEP]',myThid)
447
448 #ifdef ALLOW_DEBUG
449 IF ( debugLevel .GE. debLevB )
450 & CALL DEBUG_LEAVE('FORWARD_STEP',myThid)
451 #endif
452
453 END

  ViewVC Help
Powered by ViewVC 1.1.22