1 |
C $Header: /u/u0/gcmpack/MITgcm/model/src/forward_step.F,v 1.38 2002/11/15 19:58:21 cheisey Exp $ |
2 |
C $Name: $ |
3 |
|
4 |
#include "CPP_OPTIONS.h" |
5 |
|
6 |
CBOP |
7 |
C !ROUTINE: FORWARD_STEP |
8 |
C !INTERFACE: |
9 |
SUBROUTINE FORWARD_STEP( iloop, myTime, myIter, myThid ) |
10 |
|
11 |
C !DESCRIPTION: \bv |
12 |
C *================================================================== |
13 |
C | SUBROUTINE forward_step |
14 |
C | o Run the ocean model and, optionally, evaluate a cost function. |
15 |
C *================================================================== |
16 |
C | |
17 |
C | THE_MAIN_LOOP is the toplevel routine for the Tangent Linear and |
18 |
C | Adjoint Model Compiler (TAMC). For this purpose the initialization |
19 |
C | of the model was split into two parts. Those parameters that do |
20 |
C | not depend on a specific model run are set in INITIALISE_FIXED, |
21 |
C | whereas those that do depend on the specific realization are |
22 |
C | initialized in INITIALISE_VARIA. |
23 |
C | |
24 |
C *================================================================== |
25 |
C \ev |
26 |
|
27 |
C !USES: |
28 |
IMPLICIT NONE |
29 |
C == Global variables == |
30 |
#include "SIZE.h" |
31 |
#include "EEPARAMS.h" |
32 |
#include "PARAMS.h" |
33 |
#include "DYNVARS.h" |
34 |
#include "FFIELDS.h" |
35 |
|
36 |
#ifdef ALLOW_NONHYDROSTATIC |
37 |
#include "CG3D.h" |
38 |
#endif |
39 |
|
40 |
#ifdef ALLOW_SHAP_FILT |
41 |
#include "SHAP_FILT.h" |
42 |
#endif |
43 |
#ifdef ALLOW_ZONAL_FILT |
44 |
#include "ZONAL_FILT.h" |
45 |
#endif |
46 |
|
47 |
#ifdef ALLOW_AUTODIFF_TAMC |
48 |
# include "tamc.h" |
49 |
# include "ctrl.h" |
50 |
# include "ctrl_dummy.h" |
51 |
# include "cost.h" |
52 |
# include "EOS.h" |
53 |
# ifdef INCLUDE_EXTERNAL_FORCING_PACKAGE |
54 |
# include "exf_fields.h" |
55 |
# ifdef ALLOW_BULKFORMULAE |
56 |
# include "exf_constants.h" |
57 |
# endif |
58 |
# endif |
59 |
# ifdef ALLOW_OBCS |
60 |
# include "OBCS.h" |
61 |
# endif |
62 |
#endif |
63 |
|
64 |
C !LOCAL VARIABLES: |
65 |
C == Routine arguments == |
66 |
C note: under the multi-threaded model myiter and |
67 |
C mytime are local variables passed around as routine |
68 |
C arguments. Although this is fiddly it saves the need to |
69 |
C impose additional synchronisation points when they are |
70 |
C updated. |
71 |
C myiter - iteration counter for this thread |
72 |
C mytime - time counter for this thread |
73 |
C mythid - thread number for this instance of the routine. |
74 |
integer iloop |
75 |
integer mythid |
76 |
integer myiter |
77 |
_RL mytime |
78 |
INTEGER bi,bj |
79 |
|
80 |
CEOP |
81 |
|
82 |
|
83 |
#ifdef ALLOW_AUTODIFF_TAMC |
84 |
C-- Reset the model iteration counter and the model time. |
85 |
myiter = nIter0 + (iloop-1) |
86 |
mytime = startTime + float(iloop-1)*deltaTclock |
87 |
#endif |
88 |
|
89 |
#if (defined (ALLOW_AUTODIFF_TAMC) && defined (ALLOW_AUTODIFF_MONITOR)) |
90 |
C Include call to a dummy routine. Its adjoint will be |
91 |
C called at the proper place in the adjoint code. |
92 |
C The adjoint routine will print out adjoint values |
93 |
C if requested. The location of the call is important, |
94 |
C it has to be after the adjoint of the exchanges |
95 |
C (DO_GTERM_BLOCKING_EXCHANGES). |
96 |
CALL DUMMY_IN_STEPPING( myTime, myIter, myThid ) |
97 |
CALL DO_FIELDS_BLOCKING_EXCHANGES( myThid ) |
98 |
#endif |
99 |
|
100 |
#ifdef EXACT_CONSERV |
101 |
IF (exactConserv) THEN |
102 |
C-- Update etaH(n+1) : |
103 |
CALL TIMER_START('UPDATE_ETAH [FORWARD_STEP]',mythid) |
104 |
CALL UPDATE_ETAH( myTime, myIter, myThid ) |
105 |
CALL TIMER_STOP ('UPDATE_ETAH [FORWARD_STEP]',mythid) |
106 |
ENDIF |
107 |
#endif /* EXACT_CONSERV */ |
108 |
|
109 |
#ifdef NONLIN_FRSURF |
110 |
C-- compute the future surface level thickness |
111 |
C according to etaH(n+1) |
112 |
IF ( nonlinFreeSurf.GT.0) THEN |
113 |
CALL TIMER_START('CALC_SURF_DR [FORWARD_STEP]',mythid) |
114 |
CALL CALC_SURF_DR(etaH, myTime, myIter, myThid ) |
115 |
CALL TIMER_STOP ('CALC_SURF_DR [FORWARD_STEP]',mythid) |
116 |
ENDIF |
117 |
#endif /* NONLIN_FRSURF */ |
118 |
|
119 |
|
120 |
|
121 |
|
122 |
C-- Load forcing/external data fields. |
123 |
#ifdef ALLOW_AUTODIFF_TAMC |
124 |
c************************************** |
125 |
#include "checkpoint_lev1_directives.h" |
126 |
c************************************** |
127 |
#endif |
128 |
|
129 |
|
130 |
C-- Call external forcing package |
131 |
cswdblk -- add --- |
132 |
#ifdef ALLOW_BULKFORMULA |
133 |
CALL TIMER_START('BULKF_FIELDS_LOAD[THE_MAIN_LOOP]',mythid) |
134 |
CALL BULKF_FIELDS_LOAD( mytime, myiter, mythid ) |
135 |
CALL TIMER_STOP ('BULKF_FIELDS_LOAD[THE_MAIN_LOOP]',mythid) |
136 |
c calculate qnet and empmr (and wind stress) |
137 |
DO bj=myByLo(myThid),myByHi(myThid) |
138 |
DO bi=myBxLo(myThid),myBxHi(myThid) |
139 |
CALL BULKF_FORCING( bi,bj, mytime, myiter, mythid ) |
140 |
ENDDO |
141 |
ENDDO |
142 |
c Update the tile edges. |
143 |
_EXCH_XY_R8(Qnet, mythid) |
144 |
_EXCH_XY_R8(EmPmR, mythid) |
145 |
_EXCH_XY_R8(fu , mythid) |
146 |
_EXCH_XY_R8(fv , mythid) |
147 |
cswdblk -- end add --- |
148 |
#endif |
149 |
#ifdef INCLUDE_EXTERNAL_FORCING_PACKAGE |
150 |
IF ( .not. useSEAICE ) THEN |
151 |
CALL TIMER_START('EXF_GETFORCING [FORWARD_STEP]',mythid) |
152 |
CALL EXF_GETFORCING( mytime, myiter, mythid ) |
153 |
CALL TIMER_STOP ('EXF_GETFORCING [FORWARD_STEP]',mythid) |
154 |
ENDIF |
155 |
#else |
156 |
IF ( .not. useSEAICE ) THEN |
157 |
CALL TIMER_START('EXTERNAL_FIELDS_LOAD[FORWARD_STEP]',mythid) |
158 |
CALL EXTERNAL_FIELDS_LOAD( mytime, myiter, mythid ) |
159 |
CALL TIMER_STOP ('EXTERNAL_FIELDS_LOAD[FORWARD_STEP]',mythid) |
160 |
ENDIF |
161 |
#endif /* INCLUDE_EXTERNAL_FORCING_PACKAGE */ |
162 |
|
163 |
|
164 |
|
165 |
|
166 |
#ifdef ALLOW_SEAICE |
167 |
C-- Call sea ice model to compute forcing/external data fields. |
168 |
IF ( useSEAICE ) THEN |
169 |
CALL TIMER_START('SEAICE_MODEL [FORWARD_STEP]',myThid) |
170 |
Cxxxx CALL SEAICE_MODEL( myTime, myIter, myThid ) |
171 |
CALL TIMER_STOP ('SEAICE_MODEL [FORWARD_STEP]',myThid) |
172 |
ENDIF |
173 |
#endif ALLOW_SEAICE |
174 |
|
175 |
C-- Step forward fields and calculate time tendency terms. |
176 |
CALL TIMER_START('THERMODYNAMICS [FORWARD_STEP]',mythid) |
177 |
CALL THERMODYNAMICS( myTime, myIter, myThid ) |
178 |
CALL TIMER_STOP ('THERMODYNAMICS [FORWARD_STEP]',mythid) |
179 |
|
180 |
C-- do exchanges (needed for DYNAMICS) when using stagger time-step : |
181 |
CALL TIMER_START('BLOCKING_EXCHANGES [FORWARD_STEP]',myThid) |
182 |
CALL DO_STAGGER_FIELDS_EXCHANGES( myTime, myIter, myThid ) |
183 |
CALL TIMER_STOP ('BLOCKING_EXCHANGES [FORWARD_STEP]',myThid) |
184 |
|
185 |
#ifdef ALLOW_SHAP_FILT |
186 |
IF (useSHAP_FILT .AND. |
187 |
& staggerTimeStep .AND. shap_filt_TrStagg ) THEN |
188 |
CALL TIMER_START('SHAP_FILT [FORWARD_STEP]',myThid) |
189 |
CALL SHAP_FILT_APPLY_TS( gT, gS, myTime, myIter, myThid ) |
190 |
CALL TIMER_STOP ('SHAP_FILT [FORWARD_STEP]',myThid) |
191 |
ENDIF |
192 |
#endif |
193 |
#ifdef ALLOW_ZONAL_FILT |
194 |
IF (useZONAL_FILT .AND. |
195 |
& staggerTimeStep .AND. zonal_filt_TrStagg ) THEN |
196 |
CALL TIMER_START('ZONAL_FILT_APPLY [FORWARD_STEP]',myThid) |
197 |
CALL ZONAL_FILT_APPLY_TS( gT, gS, myThid ) |
198 |
CALL TIMER_STOP ('ZONAL_FILT_APPLY [FORWARD_STEP]',myThid) |
199 |
ENDIF |
200 |
#endif |
201 |
|
202 |
C-- Step forward fields and calculate time tendency terms. |
203 |
IF ( momStepping ) THEN |
204 |
CALL TIMER_START('DYNAMICS [FORWARD_STEP]',mythid) |
205 |
CALL DYNAMICS( myTime, myIter, myThid ) |
206 |
CALL TIMER_STOP ('DYNAMICS [FORWARD_STEP]',mythid) |
207 |
ENDIF |
208 |
|
209 |
#ifdef ALLOW_NONHYDROSTATIC |
210 |
C-- Step forward W field in N-H algorithm |
211 |
IF ( momStepping .AND. nonHydrostatic ) THEN |
212 |
CALL TIMER_START('CALC_GW [FORWARD_STEP]',myThid) |
213 |
CALL CALC_GW(myThid) |
214 |
CALL TIMER_STOP ('CALC_GW [FORWARD_STEP]',myThid) |
215 |
ENDIF |
216 |
#endif |
217 |
|
218 |
#ifdef NONLIN_FRSURF |
219 |
C-- update hfacC,W,S and recip_hFac according to etaH(n+1) : |
220 |
IF ( nonlinFreeSurf.GT.0) THEN |
221 |
CALL TIMER_START('UPDATE_SURF_DR [FORWARD_STEP]',mythid) |
222 |
CALL UPDATE_SURF_DR( myTime, myIter, myThid ) |
223 |
CALL TIMER_STOP ('UPDATE_SURF_DR [FORWARD_STEP]',myThid) |
224 |
ENDIF |
225 |
C- update also CG2D matrix (and preconditioner) |
226 |
IF ( momStepping .AND. nonlinFreeSurf.GT.2 ) THEN |
227 |
CALL TIMER_START('UPDATE_CG2D [FORWARD_STEP]',mythid) |
228 |
CALL UPDATE_CG2D( myTime, myIter, myThid ) |
229 |
CALL TIMER_START('UPDATE_CG2D [FORWARD_STEP]',mythid) |
230 |
ENDIF |
231 |
#endif |
232 |
|
233 |
C-- Apply Filters to u*,v* before SOLVE_FOR_PRESSURE |
234 |
#ifdef ALLOW_SHAP_FILT |
235 |
IF (useSHAP_FILT .AND. shap_filt_uvStar) THEN |
236 |
CALL TIMER_START('SHAP_FILT [FORWARD_STEP]',myThid) |
237 |
CALL SHAP_FILT_APPLY_UV( gUnm1,gVnm1, myTime,myIter,myThid ) |
238 |
IF (implicDiv2Dflow.LT.1.) THEN |
239 |
C-- Explicit+Implicit part of the Barotropic Flow Divergence |
240 |
C => Filtering of uVel,vVel is necessary |
241 |
CALL SHAP_FILT_APPLY_UV( uVel,vVel, myTime,myIter,myThid ) |
242 |
ENDIF |
243 |
CALL TIMER_STOP ('SHAP_FILT [FORWARD_STEP]',myThid) |
244 |
ENDIF |
245 |
#endif |
246 |
#ifdef ALLOW_ZONAL_FILT |
247 |
IF (useZONAL_FILT .AND. zonal_filt_uvStar) THEN |
248 |
CALL TIMER_START('ZONAL_FILT_APPLY [FORWARD_STEP]',myThid) |
249 |
CALL ZONAL_FILT_APPLY_UV( gUnm1, gVnm1, myThid ) |
250 |
IF (implicDiv2Dflow.LT.1.) THEN |
251 |
C-- Explicit+Implicit part of the Barotropic Flow Divergence |
252 |
C => Filtering of uVel,vVel is necessary |
253 |
CALL ZONAL_FILT_APPLY_UV( uVel, vVel, myThid ) |
254 |
ENDIF |
255 |
CALL TIMER_STOP ('ZONAL_FILT_APPLY [FORWARD_STEP]',myThid) |
256 |
ENDIF |
257 |
#endif |
258 |
|
259 |
C-- Solve elliptic equation(s). |
260 |
C Two-dimensional only for conventional hydrostatic or |
261 |
C three-dimensional for non-hydrostatic and/or IGW scheme. |
262 |
IF ( momStepping ) THEN |
263 |
CALL TIMER_START('SOLVE_FOR_PRESSURE [FORWARD_STEP]',myThid) |
264 |
CALL SOLVE_FOR_PRESSURE(myTime, myIter, myThid) |
265 |
CALL TIMER_STOP ('SOLVE_FOR_PRESSURE [FORWARD_STEP]',myThid) |
266 |
ENDIF |
267 |
|
268 |
#ifdef ALLOW_AUTODIFF_TAMC |
269 |
cph This is needed because convective_adjustment calls |
270 |
cph find_rho which may use pressure() |
271 |
CADJ STORE pressure = comlev1, key = ikey_dynamics |
272 |
#endif |
273 |
C-- Correct divergence in flow field and cycle time-stepping |
274 |
C arrays (for all fields) ; update time-counter |
275 |
myIter = nIter0 + iLoop |
276 |
myTime = startTime + deltaTClock * float(iLoop) |
277 |
CALL TIMER_START('THE_CORRECTION_STEP [FORWARD_STEP]',myThid) |
278 |
CALL THE_CORRECTION_STEP(myTime, myIter, myThid) |
279 |
CALL TIMER_STOP ('THE_CORRECTION_STEP [FORWARD_STEP]',myThid) |
280 |
|
281 |
C-- Do "blocking" sends and receives for tendency "overlap" terms |
282 |
c CALL TIMER_START('BLOCKING_EXCHANGES [FORWARD_STEP]',myThid) |
283 |
c CALL DO_GTERM_BLOCKING_EXCHANGES( myThid ) |
284 |
c CALL TIMER_STOP ('BLOCKING_EXCHANGES [FORWARD_STEP]',myThid) |
285 |
|
286 |
C-- Do "blocking" sends and receives for field "overlap" terms |
287 |
CALL TIMER_START('BLOCKING_EXCHANGES [FORWARD_STEP]',myThid) |
288 |
CALL DO_FIELDS_BLOCKING_EXCHANGES( myThid ) |
289 |
CALL TIMER_STOP ('BLOCKING_EXCHANGES [FORWARD_STEP]',myThid) |
290 |
|
291 |
#ifdef ALLOW_FLT |
292 |
C-- Calculate float trajectories |
293 |
IF (useFLT) THEN |
294 |
CALL TIMER_START('FLOATS [FORWARD_STEP]',myThid) |
295 |
CALL FLT_MAIN(myIter,myTime, myThid) |
296 |
CALL TIMER_STOP ('FLOATS [FORWARD_STEP]',myThid) |
297 |
ENDIF |
298 |
#endif |
299 |
|
300 |
#ifndef EXCLUDE_MONITOR |
301 |
C-- Check status of solution (statistics, cfl, etc...) |
302 |
CALL TIMER_START('MONITOR [FORWARD_STEP]',mythid) |
303 |
CALL MONITOR( myIter, myTime, myThid ) |
304 |
CALL TIMER_STOP ('MONITOR [FORWARD_STEP]',myThid) |
305 |
#endif /* EXCLUDE_MONITOR */ |
306 |
|
307 |
C-- Do IO if needed. |
308 |
CALL TIMER_START('DO_THE_MODEL_IO [FORWARD_STEP]',myThid) |
309 |
CALL DO_THE_MODEL_IO( myTime, myIter, myThid ) |
310 |
CALL TIMER_STOP ('DO_THE_MODEL_IO [FORWARD_STEP]',myThid) |
311 |
|
312 |
C-- Save state for restarts |
313 |
C Note: (jmc: is it still the case after ckp35 ?) |
314 |
C ===== |
315 |
C Because of the ordering of the timestepping code and |
316 |
C tendency term code at end of loop model arrays hold |
317 |
C U,V,T,S at "time-level" N but gu, gv, gs, gt, guNM1,... |
318 |
C at "time-level" N+1/2 (guNM1 at "time-level" N+1/2 is |
319 |
C gu at "time-level" N-1/2) and etaN at "time-level" N+1/2. |
320 |
C where N = I+timeLevBase-1 |
321 |
C Thus a checkpoint contains U.0000000000, GU.0000000001 and |
322 |
C etaN.0000000001 in the indexing scheme used for the model |
323 |
C "state" files. This example is referred to as a checkpoint |
324 |
C at time level 1 |
325 |
CALL TIMER_START('WRITE_CHECKPOINT [FORWARD_STEP]',myThid) |
326 |
CALL WRITE_CHECKPOINT( |
327 |
& .FALSE., myTime, myIter, myThid ) |
328 |
CALL TIMER_STOP ('WRITE_CHECKPOINT [FORWARD_STEP]',myThid) |
329 |
|
330 |
END |