1 |
cnh |
1.1 |
C $Header: /u/gcmpack/MITgcm_contrib/ESMF/global_ocean.128x64x15/code/forward_step_execute.F,v 1.1.1.1 2004/02/15 22:28:18 cnh 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_EXECUTE |
15 |
|
|
C !INTERFACE: |
16 |
|
|
SUBROUTINE FORWARD_STEP_EXECUTE( 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 |
|
|
integer i,L |
89 |
|
|
CEOP |
90 |
|
|
|
91 |
|
|
#ifdef ALLOW_DEBUG |
92 |
|
|
IF ( debugLevel .GE. debLevB ) |
93 |
|
|
& CALL DEBUG_CALL('THERMODYNAMICS',myThid) |
94 |
|
|
#endif |
95 |
|
|
CALL TIMER_START('THERMODYNAMICS [FORWARD_STEP]',mythid) |
96 |
|
|
CALL THERMODYNAMICS( myTime, myIter, myThid ) |
97 |
|
|
CALL TIMER_STOP ('THERMODYNAMICS [FORWARD_STEP]',mythid) |
98 |
|
|
|
99 |
|
|
C-- do exchanges (needed for DYNAMICS) when using stagger time-step : |
100 |
|
|
#ifdef ALLOW_DEBUG |
101 |
|
|
IF ( debugLevel .GE. debLevB ) |
102 |
|
|
& CALL DEBUG_CALL('DO_STAGGER_FIELDS_EXCH.',myThid) |
103 |
|
|
#endif |
104 |
|
|
CALL TIMER_START('BLOCKING_EXCHANGES [FORWARD_STEP]',myThid) |
105 |
|
|
CALL DO_STAGGER_FIELDS_EXCHANGES( myTime, myIter, myThid ) |
106 |
|
|
CALL TIMER_STOP ('BLOCKING_EXCHANGES [FORWARD_STEP]',myThid) |
107 |
|
|
|
108 |
|
|
#ifdef ALLOW_SHAP_FILT |
109 |
|
|
IF (useSHAP_FILT .AND. |
110 |
|
|
& staggerTimeStep .AND. shap_filt_TrStagg ) THEN |
111 |
|
|
#ifdef ALLOW_DEBUG |
112 |
|
|
IF ( debugLevel .GE. debLevB ) |
113 |
|
|
& CALL DEBUG_CALL('SHAP_FILT_APPLY_TS',myThid) |
114 |
|
|
#endif |
115 |
|
|
CALL TIMER_START('SHAP_FILT [FORWARD_STEP]',myThid) |
116 |
|
|
CALL SHAP_FILT_APPLY_TS(gT,gS,myTime+deltaT,myIter+1,myThid) |
117 |
|
|
CALL TIMER_STOP ('SHAP_FILT [FORWARD_STEP]',myThid) |
118 |
|
|
ENDIF |
119 |
|
|
#endif |
120 |
|
|
|
121 |
|
|
#ifdef ALLOW_ZONAL_FILT |
122 |
|
|
IF (useZONAL_FILT .AND. |
123 |
|
|
& staggerTimeStep .AND. zonal_filt_TrStagg ) THEN |
124 |
|
|
#ifdef ALLOW_DEBUG |
125 |
|
|
IF ( debugLevel .GE. debLevB ) |
126 |
|
|
& CALL DEBUG_CALL('ZONAL_FILT_APPLY_TS',myThid) |
127 |
|
|
#endif |
128 |
|
|
CALL TIMER_START('ZONAL_FILT_APPLY [FORWARD_STEP]',myThid) |
129 |
|
|
CALL ZONAL_FILT_APPLY_TS( gT, gS, myThid ) |
130 |
|
|
CALL TIMER_STOP ('ZONAL_FILT_APPLY [FORWARD_STEP]',myThid) |
131 |
|
|
ENDIF |
132 |
|
|
#endif |
133 |
|
|
|
134 |
|
|
C-- Step forward fields and calculate time tendency terms. |
135 |
|
|
#ifndef ALLOW_AUTODIFF_TAMC |
136 |
|
|
IF ( momStepping ) THEN |
137 |
|
|
#endif |
138 |
|
|
#ifdef ALLOW_DEBUG |
139 |
|
|
IF ( debugLevel .GE. debLevB ) |
140 |
|
|
& CALL DEBUG_CALL('DYNAMICS',myThid) |
141 |
|
|
#endif |
142 |
|
|
CALL TIMER_START('DYNAMICS [FORWARD_STEP]',mythid) |
143 |
|
|
CALL DYNAMICS( myTime, myIter, myThid ) |
144 |
|
|
CALL TIMER_STOP ('DYNAMICS [FORWARD_STEP]',mythid) |
145 |
|
|
#ifndef ALLOW_AUTODIFF_TAMC |
146 |
|
|
ENDIF |
147 |
|
|
#endif |
148 |
|
|
|
149 |
|
|
#ifdef ALLOW_NONHYDROSTATIC |
150 |
|
|
C-- Step forward W field in N-H algorithm |
151 |
|
|
IF ( momStepping .AND. nonHydrostatic ) THEN |
152 |
|
|
#ifdef ALLOW_DEBUG |
153 |
|
|
IF ( debugLevel .GE. debLevB ) |
154 |
|
|
& CALL DEBUG_CALL('CALC_GW',myThid) |
155 |
|
|
#endif |
156 |
|
|
CALL TIMER_START('CALC_GW [FORWARD_STEP]',myThid) |
157 |
|
|
CALL CALC_GW(myThid) |
158 |
|
|
CALL TIMER_STOP ('CALC_GW [FORWARD_STEP]',myThid) |
159 |
|
|
ENDIF |
160 |
|
|
#endif |
161 |
|
|
|
162 |
|
|
#ifdef NONLIN_FRSURF |
163 |
|
|
C-- update hfacC,W,S and recip_hFac according to etaH(n+1) : |
164 |
|
|
IF ( nonlinFreeSurf.GT.0) THEN |
165 |
|
|
IF ( select_rStar.GT.0 ) THEN |
166 |
|
|
CALL TIMER_START('UPDATE_R_STAR [FORWARD_STEP]',myThid) |
167 |
|
|
CALL UPDATE_R_STAR( myTime, myIter, myThid ) |
168 |
|
|
CALL TIMER_STOP ('UPDATE_R_STAR [FORWARD_STEP]',myThid) |
169 |
|
|
ELSE |
170 |
|
|
CALL TIMER_START('UPDATE_SURF_DR [FORWARD_STEP]',myThid) |
171 |
|
|
CALL UPDATE_SURF_DR( myTime, myIter, myThid ) |
172 |
|
|
CALL TIMER_STOP ('UPDATE_SURF_DR [FORWARD_STEP]',myThid) |
173 |
|
|
ENDIF |
174 |
|
|
ENDIF |
175 |
|
|
C- update also CG2D matrix (and preconditioner) |
176 |
|
|
IF ( momStepping .AND. nonlinFreeSurf.GT.2 ) THEN |
177 |
|
|
CALL TIMER_START('UPDATE_CG2D [FORWARD_STEP]',myThid) |
178 |
|
|
CALL UPDATE_CG2D( myTime, myIter, myThid ) |
179 |
|
|
CALL TIMER_STOP ('UPDATE_CG2D [FORWARD_STEP]',myThid) |
180 |
|
|
ENDIF |
181 |
|
|
#endif |
182 |
|
|
|
183 |
|
|
C-- Apply Filters to u*,v* before SOLVE_FOR_PRESSURE |
184 |
|
|
#ifdef ALLOW_SHAP_FILT |
185 |
|
|
IF (useSHAP_FILT .AND. shap_filt_uvStar) THEN |
186 |
|
|
CALL TIMER_START('SHAP_FILT [FORWARD_STEP]',myThid) |
187 |
|
|
IF (implicDiv2Dflow.LT.1.) THEN |
188 |
|
|
C-- Explicit+Implicit part of the Barotropic Flow Divergence |
189 |
|
|
C => Filtering of uVel,vVel is necessary |
190 |
|
|
CALL SHAP_FILT_APPLY_UV( uVel,vVel, |
191 |
|
|
& myTime+deltaT, myIter+1, myThid ) |
192 |
|
|
ENDIF |
193 |
|
|
CALL SHAP_FILT_APPLY_UV( gU,gV,myTime+deltaT,myIter+1,myThid) |
194 |
|
|
CALL TIMER_STOP ('SHAP_FILT [FORWARD_STEP]',myThid) |
195 |
|
|
ENDIF |
196 |
|
|
#endif |
197 |
|
|
#ifdef ALLOW_ZONAL_FILT |
198 |
|
|
IF (useZONAL_FILT .AND. zonal_filt_uvStar) THEN |
199 |
|
|
CALL TIMER_START('ZONAL_FILT_APPLY [FORWARD_STEP]',myThid) |
200 |
|
|
IF (implicDiv2Dflow.LT.1.) THEN |
201 |
|
|
C-- Explicit+Implicit part of the Barotropic Flow Divergence |
202 |
|
|
C => Filtering of uVel,vVel is necessary |
203 |
|
|
CALL ZONAL_FILT_APPLY_UV( uVel, vVel, myThid ) |
204 |
|
|
ENDIF |
205 |
|
|
CALL ZONAL_FILT_APPLY_UV( gU, gV, myThid ) |
206 |
|
|
CALL TIMER_STOP ('ZONAL_FILT_APPLY [FORWARD_STEP]',myThid) |
207 |
|
|
ENDIF |
208 |
|
|
#endif |
209 |
|
|
|
210 |
|
|
C-- Solve elliptic equation(s). |
211 |
|
|
C Two-dimensional only for conventional hydrostatic or |
212 |
|
|
C three-dimensional for non-hydrostatic and/or IGW scheme. |
213 |
|
|
IF ( momStepping ) THEN |
214 |
|
|
CALL TIMER_START('SOLVE_FOR_PRESSURE [FORWARD_STEP]',myThid) |
215 |
|
|
CALL SOLVE_FOR_PRESSURE(myTime, myIter, myThid) |
216 |
|
|
CALL TIMER_STOP ('SOLVE_FOR_PRESSURE [FORWARD_STEP]',myThid) |
217 |
|
|
ENDIF |
218 |
|
|
|
219 |
|
|
#ifdef ALLOW_AUTODIFF_TAMC |
220 |
|
|
cph This is needed because convective_adjustment calls |
221 |
|
|
cph find_rho which may use pressure() |
222 |
|
|
CADJ STORE totphihyd = comlev1, key = ikey_dynamics |
223 |
|
|
#endif |
224 |
|
|
C-- Correct divergence in flow field and cycle time-stepping |
225 |
|
|
C arrays (for all fields) ; update time-counter |
226 |
|
|
myIter = nIter0 + iLoop |
227 |
|
|
myTime = startTime + deltaTClock * float(iLoop) |
228 |
|
|
CALL TIMER_START('THE_CORRECTION_STEP [FORWARD_STEP]',myThid) |
229 |
|
|
CALL THE_CORRECTION_STEP(myTime, myIter, myThid) |
230 |
|
|
CALL TIMER_STOP ('THE_CORRECTION_STEP [FORWARD_STEP]',myThid) |
231 |
|
|
|
232 |
|
|
C-- Do "blocking" sends and receives for tendency "overlap" terms |
233 |
|
|
c CALL TIMER_START('BLOCKING_EXCHANGES [FORWARD_STEP]',myThid) |
234 |
|
|
c CALL DO_GTERM_BLOCKING_EXCHANGES( myThid ) |
235 |
|
|
c CALL TIMER_STOP ('BLOCKING_EXCHANGES [FORWARD_STEP]',myThid) |
236 |
|
|
|
237 |
|
|
C-- Do "blocking" sends and receives for field "overlap" terms |
238 |
|
|
CALL TIMER_START('BLOCKING_EXCHANGES [FORWARD_STEP]',myThid) |
239 |
|
|
CALL DO_FIELDS_BLOCKING_EXCHANGES( myThid ) |
240 |
|
|
CALL TIMER_STOP ('BLOCKING_EXCHANGES [FORWARD_STEP]',myThid) |
241 |
|
|
|
242 |
|
|
cswdptr -- add for seperate timestepping of chemical/biological/forcing |
243 |
|
|
cswdptr of ptracers --- |
244 |
|
|
#ifdef ALLOW_GCHEM |
245 |
|
|
ceh3 This is broken -- this ifdef should not be visible! |
246 |
|
|
#ifdef PTRACERS_SEPARATE_FORCING |
247 |
|
|
ceh3 needs an IF ( use GCHEM ) THEN |
248 |
|
|
call GCHEM_FORCING_SEP( myTime,myIter,myThid ) |
249 |
|
|
#endif /* PTRACERS_SEPARATE_FORCING */ |
250 |
|
|
#endif /* ALLOW_GCHEM */ |
251 |
|
|
cswdptr -- end add --- |
252 |
|
|
|
253 |
|
|
C AMM |
254 |
|
|
#ifdef ALLOW_FIZHI |
255 |
|
|
CALL STEP_FIZHI_CORR ( myTime, myIter, myThid ) |
256 |
|
|
#endif |
257 |
|
|
C AMM |
258 |
|
|
|
259 |
|
|
#ifdef ALLOW_FLT |
260 |
|
|
C-- Calculate float trajectories |
261 |
|
|
IF (useFLT) THEN |
262 |
|
|
CALL TIMER_START('FLOATS [FORWARD_STEP]',myThid) |
263 |
|
|
CALL FLT_MAIN(myIter,myTime, myThid) |
264 |
|
|
CALL TIMER_STOP ('FLOATS [FORWARD_STEP]',myThid) |
265 |
|
|
ENDIF |
266 |
|
|
#endif |
267 |
|
|
|
268 |
|
|
#ifdef ALLOW_MONITOR |
269 |
|
|
C-- Check status of solution (statistics, cfl, etc...) |
270 |
|
|
CALL TIMER_START('MONITOR [FORWARD_STEP]',myThid) |
271 |
|
|
CALL MONITOR( myIter, myTime, myThid ) |
272 |
|
|
CALL TIMER_STOP ('MONITOR [FORWARD_STEP]',myThid) |
273 |
|
|
#endif /* ALLOW_MONITOR */ |
274 |
|
|
|
275 |
|
|
C-- Do IO if needed. |
276 |
|
|
CALL TIMER_START('DO_THE_MODEL_IO [FORWARD_STEP]',myThid) |
277 |
|
|
CALL DO_THE_MODEL_IO( myTime, myIter, myThid ) |
278 |
|
|
CALL TIMER_STOP ('DO_THE_MODEL_IO [FORWARD_STEP]',myThid) |
279 |
|
|
|
280 |
|
|
C-- Save state for restarts |
281 |
|
|
C Note: (jmc: is it still the case after ckp35 ?) |
282 |
|
|
C ===== |
283 |
|
|
C Because of the ordering of the timestepping code and |
284 |
|
|
C tendency term code at end of loop model arrays hold |
285 |
|
|
C U,V,T,S at "time-level" N but gu, gv, gs, gt, guNM1,... |
286 |
|
|
C at "time-level" N+1/2 (guNM1 at "time-level" N+1/2 is |
287 |
|
|
C gu at "time-level" N-1/2) and etaN at "time-level" N+1/2. |
288 |
|
|
C where N = I+timeLevBase-1 |
289 |
|
|
C Thus a checkpoint contains U.0000000000, GU.0000000001 and |
290 |
|
|
C etaN.0000000001 in the indexing scheme used for the model |
291 |
|
|
C "state" files. This example is referred to as a checkpoint |
292 |
|
|
C at time level 1 |
293 |
|
|
CALL TIMER_START('WRITE_CHECKPOINT [FORWARD_STEP]',myThid) |
294 |
|
|
CALL PACKAGES_WRITE_PICKUP( |
295 |
|
|
I .FALSE., myTime, myIter, myThid ) |
296 |
|
|
CALL WRITE_CHECKPOINT( |
297 |
|
|
I .FALSE., myTime, myIter, myThid ) |
298 |
|
|
CALL TIMER_STOP ('WRITE_CHECKPOINT [FORWARD_STEP]',myThid) |
299 |
|
|
|
300 |
|
|
#ifdef ALLOW_DEBUG |
301 |
|
|
IF ( debugLevel .GE. debLevB ) |
302 |
|
|
& CALL DEBUG_LEAVE('FORWARD_STEP',myThid) |
303 |
|
|
#endif |
304 |
|
|
|
305 |
|
|
RETURN |
306 |
|
|
END |