1 |
C $Header$ |
C $Header$ |
2 |
C $Name$ |
C $Name$ |
3 |
|
|
4 |
|
#include "PACKAGES_CONFIG.h" |
5 |
#include "CPP_OPTIONS.h" |
#include "CPP_OPTIONS.h" |
6 |
|
|
7 |
SUBROUTINE FORWARD_STEP( |
#ifdef ALLOW_OFFLINE |
8 |
I doHalfStep, iLoop, |
# include "OFFLINE_OPTIONS.h" |
9 |
U myCurrentTime, myCurrentIter, |
#endif |
10 |
& myThid) |
#ifdef ALLOW_GMREDI |
11 |
C /==========================================================\ |
# include "GMREDI_OPTIONS.h" |
12 |
C | SUBROUTINE FORWARD_STEP | |
#endif |
13 |
C | o Does one instance of the model time stepping | |
|
14 |
C | The time stepping loop in THE_MAIN_LOOP() calls | |
CBOP |
15 |
C | this routine | |
C !ROUTINE: FORWARD_STEP |
16 |
C |==========================================================| |
C !INTERFACE: |
17 |
C \==========================================================/ |
SUBROUTINE FORWARD_STEP( iloop, myTime, myIter, myThid ) |
18 |
IMPLICIT NONE |
|
19 |
C |
C !DESCRIPTION: \bv |
20 |
C Call Tree |
C *================================================================== |
21 |
C ========= |
C | SUBROUTINE forward_step |
22 |
C |
C | o Run the ocean model and, optionally, evaluate a cost function. |
23 |
C THE_MAIN_LOOP() |
C *================================================================== |
24 |
C | |
C | |
25 |
C ==> | ** Time stepping loop starts here ** |
C | THE_MAIN_LOOP is the toplevel routine for the Tangent Linear and |
26 |
C | | |
C | Adjoint Model Compiler (TAMC). For this purpose the initialization |
27 |
C /|\ |-FORWARD_STEP |
C | of the model was split into two parts. Those parameters that do |
28 |
C | | | |
C | not depend on a specific model run are set in INITIALISE_FIXED, |
29 |
C /|\ | |--LOAD_EXTERNAL_DATA |
C | whereas those that do depend on the specific realization are |
30 |
C | | | o Load and/or set time dependent forcing fields |
C | initialized in INITIALISE_VARIA. |
31 |
C /|\ | | |
C | |
32 |
C | | |--DYNAMICS |
C *================================================================== |
33 |
C /|\ | | o Evaluate "forward" terms |
C \ev |
|
C | | | |
|
|
C /|\ | | |
|
|
C | | |--DO_THE_MODEL_IO |
|
|
C /|\ | | o Write model state |
|
|
C | | | |
|
|
C /|\ | | |
|
|
C | | |--SOLVE_FOR_PRESSURE |
|
|
C /|\ | | o Find pressure field to keep flow non-divergent |
|
|
C | | | |
|
|
C /|\ | | |
|
|
C | | |--THE_CORRECTION_STEP |
|
|
C /|\ | | o Correct flow field with pressure gradient |
|
|
C | | | and cycle time-stepping arrays (for all fields) |
|
|
C /|\ | | |
|
|
C | | |--DO_GTERM_BLOCKING_EXCHANGES |
|
|
C /|\ | | o Update overlap regions |
|
|
C | | | |
|
|
C /|\ | | |
|
|
C | | |--WRITE_CHECKPOINT |
|
|
C /|\ | | o Write restart file(s) |
|
|
C | | |
|
|
C /|\ | |
|
|
C |<== | ** Time stepping loop finishes here ** |
|
|
C |
|
34 |
|
|
35 |
C == Global variables === |
C !USES: |
36 |
|
IMPLICIT NONE |
37 |
|
C == Global variables == |
38 |
#include "SIZE.h" |
#include "SIZE.h" |
39 |
#include "EEPARAMS.h" |
#include "EEPARAMS.h" |
40 |
#include "PARAMS.h" |
#include "PARAMS.h" |
41 |
#include "DYNVARS.h" |
#include "DYNVARS.h" |
42 |
#include "CG2D.h" |
|
43 |
#ifdef ALLOW_NONHYDROSTATIC |
#ifdef ALLOW_SHAP_FILT |
44 |
#include "CG3D.h" |
# include "SHAP_FILT.h" |
45 |
|
#endif |
46 |
|
#ifdef ALLOW_ZONAL_FILT |
47 |
|
# include "ZONAL_FILT.h" |
48 |
#endif |
#endif |
49 |
|
#ifdef COMPONENT_MODULE |
50 |
|
# include "CPL_PARAMS.h" |
51 |
|
#endif |
52 |
|
|
53 |
|
#ifdef ALLOW_AUTODIFF_TAMC |
54 |
|
# include "FFIELDS.h" |
55 |
|
|
56 |
|
# ifdef ALLOW_NONHYDROSTATIC |
57 |
|
# include "CG3D.h" |
58 |
|
# endif |
59 |
|
|
60 |
|
# include "tamc.h" |
61 |
|
# include "ctrl.h" |
62 |
|
# include "ctrl_dummy.h" |
63 |
|
# include "cost.h" |
64 |
|
# include "EOS.h" |
65 |
|
# ifdef ALLOW_EXF |
66 |
|
# include "exf_fields.h" |
67 |
|
# include "exf_clim_fields.h" |
68 |
|
# ifdef ALLOW_BULKFORMULAE |
69 |
|
# include "exf_constants.h" |
70 |
|
# endif |
71 |
|
# endif |
72 |
|
# ifdef ALLOW_OBCS |
73 |
|
# include "OBCS.h" |
74 |
|
# endif |
75 |
|
# ifdef ALLOW_PTRACERS |
76 |
|
# include "PTRACERS_SIZE.h" |
77 |
|
# include "PTRACERS.h" |
78 |
|
# endif |
79 |
|
# ifdef ALLOW_CD_CODE |
80 |
|
# include "CD_CODE_VARS.h" |
81 |
|
# endif |
82 |
|
# ifdef ALLOW_EBM |
83 |
|
# include "EBM.h" |
84 |
|
# endif |
85 |
|
# ifdef EXACT_CONSERV |
86 |
|
# include "SURFACE.h" |
87 |
|
# endif |
88 |
|
# ifdef ALLOW_KPP |
89 |
|
# include "KPP.h" |
90 |
|
# endif |
91 |
|
# ifdef ALLOW_GMREDI |
92 |
|
# include "GMREDI.h" |
93 |
|
# endif |
94 |
|
#endif /* ALLOW_AUTODIFF_TAMC */ |
95 |
|
|
96 |
|
C !LOCAL VARIABLES: |
97 |
C == Routine arguments == |
C == Routine arguments == |
98 |
C doHalfStep - If .TRUE. then this is the last half step |
C note: under the multi-threaded model myiter and |
99 |
C iLoop - Invocation count (counter in THE_MAIN_LOOP) |
C mytime are local variables passed around as routine |
100 |
C myCurrentIter - Iteration counter for this thread |
C arguments. Although this is fiddly it saves the need to |
101 |
C myCurrentTime - Time counter for this thread |
C impose additional synchronisation points when they are |
102 |
C myThid - Thread number for this instance of the routine. |
C updated. |
103 |
LOGICAL doHalfStep |
C myIter - iteration counter for this thread |
104 |
INTEGER iLoop |
C myTime - time counter for this thread |
105 |
INTEGER myCurrentIter |
C myThid - thread number for this instance of the routine. |
106 |
_RL myCurrentTime |
INTEGER iloop |
107 |
INTEGER myThid |
INTEGER myThid |
108 |
|
INTEGER myIter |
109 |
|
_RL myTime |
110 |
|
|
111 |
C == Local variables == |
C == Local variables == |
112 |
|
INTEGER myItP1 |
113 |
|
CEOP |
114 |
|
|
115 |
C-- Load forcing/external data fields |
#ifdef ALLOW_DEBUG |
116 |
CALL TIMER_START('I/O (READ) [FORWARD_STEP]',myThid) |
IF ( debugLevel .GE. debLevB ) |
117 |
CALL EXTERNAL_FIELDS_LOAD( myCurrentTime, myCurrentIter, myThid ) |
& CALL DEBUG_ENTER('FORWARD_STEP',myThid) |
118 |
CALL TIMER_STOP ('I/O (READ) [FORWARD_STEP]',myThid) |
#endif |
|
|
|
|
C-- Step forward fields and calculate time tendency terms |
|
|
CALL TIMER_START('DYNAMICS [FORWARD_STEP]',myThid) |
|
|
CALL DYNAMICS( myCurrentTime, myCurrentIter, myThid ) |
|
|
CALL TIMER_STOP ('DYNAMICS [FORWARD_STEP]',myThid) |
|
119 |
|
|
120 |
#ifdef ALLOW_NONHYDROSTATIC |
#ifdef ALLOW_AUTODIFF_TAMC |
121 |
C-- Step forward W field in N-H algorithm |
C-- Reset the model iteration counter and the model time. |
122 |
IF ( nonHydrostatic ) THEN |
myiter = nIter0 + (iloop-1) |
123 |
CALL TIMER_START('CALC_GW [FORWARD_STEP]',myThid) |
mytime = startTime + float(iloop-1)*deltaTclock |
124 |
CALL CALC_GW( myThid) |
#endif |
125 |
CALL TIMER_STOP ('CALC_GW [FORWARD_STEP]',myThid) |
|
126 |
|
#ifdef ALLOW_AUTODIFF_TAMC |
127 |
|
c************************************** |
128 |
|
#include "checkpoint_lev1_directives.h" |
129 |
|
c************************************** |
130 |
|
#endif |
131 |
|
|
132 |
|
C-- Switch on/off diagnostics for snap-shot output: |
133 |
|
#ifdef ALLOW_DIAGNOSTICS |
134 |
|
IF ( useDiagnostics ) THEN |
135 |
|
CALL DIAGNOSTICS_SWITCH_ONOFF( myIter, myThid ) |
136 |
ENDIF |
ENDIF |
137 |
#endif |
#endif |
138 |
|
|
139 |
#ifdef ALLOW_SHAP_FILT |
C-- Call external forcing package |
140 |
C-- Step forward all tiles, filter and exchange. |
#ifdef ALLOW_BULK_FORCE |
141 |
CALL TIMER_START('SHAP_FILT [FORWARD_STEP]',myThid) |
IF ( useBulkForce ) THEN |
142 |
CALL SHAP_FILT_APPLY( |
#ifdef ALLOW_DEBUG |
143 |
I gUnm1, gVnm1, gTnm1, gSnm1, |
IF ( debugLevel .GE. debLevB ) |
144 |
I myCurrentTime, myCurrentIter, myThid ) |
& CALL DEBUG_CALL('BULKF_FIELDS_LOAD',myThid) |
145 |
CALL TIMER_STOP ('SHAP_FILT [FORWARD_STEP]',myThid) |
#endif |
146 |
|
CALL TIMER_START('BULKF_FORCING [FORWARD_STEP]',mythid) |
147 |
|
C- load all forcing fields at current time |
148 |
|
CALL BULKF_FIELDS_LOAD( myTime, myIter, myThid ) |
149 |
|
C- calculate qnet and empmr (and wind stress) |
150 |
|
CALL BULKF_FORCING( myTime, myIter, myThid ) |
151 |
|
CALL TIMER_STOP ('BULKF_FORCING [FORWARD_STEP]',mythid) |
152 |
|
ELSE |
153 |
|
#endif /* ALLOW_BULK_FORCE */ |
154 |
|
|
155 |
|
# ifdef ALLOW_EXF |
156 |
|
# ifdef ALLOW_DEBUG |
157 |
|
IF ( debugLevel .GE. debLevB ) |
158 |
|
& CALL DEBUG_CALL('EXF_GETFORCING',myThid) |
159 |
|
# endif |
160 |
|
CALL TIMER_START('EXF_GETFORCING [FORWARD_STEP]',mythid) |
161 |
|
CALL EXF_GETFORCING( mytime, myiter, mythid ) |
162 |
|
CALL TIMER_STOP ('EXF_GETFORCING [FORWARD_STEP]',mythid) |
163 |
|
# else /* ALLOW_EXF undef */ |
164 |
|
cph The following IF-statement creates an additional dependency |
165 |
|
cph for the forcing fields requiring additional storing. |
166 |
|
cph Therefore, the IF-statement will be put between CPP-OPTIONS, |
167 |
|
cph assuming that ALLOW_SEAICE has not yet been differentiated. |
168 |
|
# if (defined (ALLOW_SEAICE) || defined (ALLOW_EBM)) |
169 |
|
IF ( .NOT. useSEAICE .AND. .NOT. useEBM ) THEN |
170 |
|
# endif |
171 |
|
#ifdef ALLOW_DEBUG |
172 |
|
IF ( debugLevel .GE. debLevB ) |
173 |
|
& CALL DEBUG_CALL('EXTERNAL_FIELDS_LOAD',myThid) |
174 |
#endif |
#endif |
175 |
|
CALL TIMER_START('EXTERNAL_FIELDS_LOAD[FORWARD_STEP]',mythid) |
176 |
|
CALL EXTERNAL_FIELDS_LOAD( mytime, myiter, mythid ) |
177 |
|
CALL TIMER_STOP ('EXTERNAL_FIELDS_LOAD[FORWARD_STEP]',mythid) |
178 |
|
# if (defined (ALLOW_SEAICE) || defined (ALLOW_EBM)) |
179 |
|
ENDIF |
180 |
|
# endif |
181 |
|
# endif /* ALLOW_EXF */ |
182 |
|
#ifdef ALLOW_BULK_FORCE |
183 |
|
C-- end of if/else block useBulfforce -- |
184 |
|
ENDIF |
185 |
|
#endif /* ALLOW_BULK_FORCE */ |
186 |
|
|
187 |
#ifdef ALLOW_ZONAL_FILT |
#ifdef ALLOW_AUTODIFF |
188 |
CALL ZONAL_FILT_APPLY( |
c-- Add control vector for forcing and parameter fields |
189 |
U gUnm1, gVnm1, gTnm1, gSnm1, |
if ( myiter .EQ. nIter0 ) |
190 |
I myThid ) |
& CALL CTRL_MAP_FORCING (mythid) |
191 |
#endif |
#endif |
192 |
|
|
193 |
C-- Do IO if needed. |
#if (defined (ALLOW_AUTODIFF_TAMC) && defined (ALLOW_AUTODIFF_MONITOR)) |
194 |
C Note: |
C Include call to a dummy routine. Its adjoint will be |
195 |
C ===== |
C called at the proper place in the adjoint code. |
196 |
C At this point model arrays hold U,V,T,S at "time-level" N |
C The adjoint routine will print out adjoint values |
197 |
C and cg2d_x at "time-level" N-1/2 where N = I+timeLevBase-1. |
C if requested. The location of the call is important, |
198 |
C By convention this is taken to be the model "state". |
C it has to be after the adjoint of the exchanges |
199 |
CALL TIMER_START('I/O (WRITE) [FORWARD_STEP]',myThid) |
C (DO_GTERM_BLOCKING_EXCHANGES). |
200 |
CALL DO_THE_MODEL_IO( |
CALL DUMMY_IN_STEPPING( myTime, myIter, myThid ) |
201 |
& doHalfStep, myCurrentTime, myCurrentIter, myThid ) |
cph I've commented this line since it may conflict with MITgcm's adjoint |
202 |
CALL TIMER_STOP ('I/O (WRITE) [FORWARD_STEP]',myThid) |
cph However, need to check whether that's still consistent |
203 |
|
cph with the ecco-branch (it should). |
204 |
|
cph CALL DO_FIELDS_BLOCKING_EXCHANGES( myThid ) |
205 |
|
#endif |
206 |
|
|
207 |
|
# ifdef ALLOW_SEAICE |
208 |
|
C-- Call sea ice model to compute forcing/external data fields. In |
209 |
|
C addition to computing prognostic sea-ice variables and diagnosing the |
210 |
|
C forcing/external data fields that drive the ocean model, SEAICE_MODEL |
211 |
|
C also sets theta to the freezing point under sea-ice. The implied |
212 |
|
C surface heat flux is then stored in variable surfaceTendencyTice, |
213 |
|
C which is needed by KPP package (kpp_calc.F and kpp_transport_t.F) |
214 |
|
C to diagnose surface buoyancy fluxes and for the non-local transport |
215 |
|
C term. Because this call precedes model thermodynamics, temperature |
216 |
|
C under sea-ice may not be "exactly" at the freezing point by the time |
217 |
|
C theta is dumped or time-averaged. |
218 |
|
IF ( useSEAICE ) THEN |
219 |
|
#ifdef ALLOW_DEBUG |
220 |
|
IF ( debugLevel .GE. debLevB ) |
221 |
|
& CALL DEBUG_CALL('SEAICE_MODEL',myThid) |
222 |
|
#endif |
223 |
|
CALL TIMER_START('SEAICE_MODEL [FORWARD_STEP]',myThid) |
224 |
|
CALL SEAICE_MODEL( myTime, myIter, myThid ) |
225 |
|
CALL TIMER_STOP ('SEAICE_MODEL [FORWARD_STEP]',myThid) |
226 |
|
ENDIF |
227 |
|
# endif /* ALLOW_SEAICE */ |
228 |
|
|
229 |
IF (.NOT. doHalfStep) THEN |
#ifdef ALLOW_AUTODIFF_TAMC |
230 |
|
# ifdef ALLOW_PTRACERS |
231 |
|
cph this replaces _bibj storing of ptracer within thermodynamics |
232 |
|
CADJ STORE ptracer = comlev1, key = ikey_dynamics |
233 |
|
# endif |
234 |
|
#endif |
235 |
|
|
236 |
|
#ifdef ALLOW_OFFLINE |
237 |
|
call OFFLINE_FIELDS_LOAD( myTime, myIter, myThid ) |
238 |
|
#endif |
239 |
|
|
240 |
|
#ifdef ALLOW_PTRACERS |
241 |
|
# ifdef ALLOW_GCHEM |
242 |
|
IF ( useGCHEM ) THEN |
243 |
|
CALL GCHEM_FIELDS_LOAD( mytime, myiter, mythid ) |
244 |
|
ENDIF |
245 |
|
# endif |
246 |
|
#endif |
247 |
|
|
248 |
|
#ifdef COMPONENT_MODULE |
249 |
|
IF ( useCoupler .AND. cpl_earlyExpImpCall ) THEN |
250 |
|
C Post coupling data that I export. |
251 |
|
C Read in coupling data that I import. |
252 |
|
CALL TIMER_START('CPL_EXPORT-IMPORT [FORWARD_STEP]',myThid) |
253 |
|
CALL CPL_EXPORT_MY_DATA( myIter, myTime, myThid ) |
254 |
|
CALL CPL_IMPORT_EXTERNAL_DATA( myIter, myTime, myThid ) |
255 |
|
CALL TIMER_STOP ('CPL_EXPORT-IMPORT [FORWARD_STEP]',myThid) |
256 |
|
ENDIF |
257 |
|
#endif /* COMPONENT_MODULE */ |
258 |
|
|
259 |
|
#ifdef ALLOW_EBM |
260 |
|
IF ( useEBM ) THEN |
261 |
|
# ifdef ALLOW_DEBUG |
262 |
|
IF ( debugLevel .GE. debLevB ) |
263 |
|
& CALL DEBUG_CALL('EBM',myThid) |
264 |
|
# endif |
265 |
|
CALL TIMER_START('EBM [FORWARD_STEP]',mythid) |
266 |
|
CALL EBM_DRIVER ( myTime, myIter, myThid ) |
267 |
|
CALL TIMER_STOP ('EBM [FORWARD_STEP]',mythid) |
268 |
|
ENDIF |
269 |
|
#endif |
270 |
|
|
271 |
|
C-- Step forward fields and calculate time tendency terms. |
272 |
|
|
273 |
|
#ifdef ALLOW_DEBUG |
274 |
|
IF ( debugLevel .GE. debLevB ) |
275 |
|
& CALL DEBUG_CALL('DO_ATMOSPHERIC_PHYS',myThid) |
276 |
|
#endif |
277 |
|
CALL TIMER_START('DO_ATMOSPHERIC_PHYS [FORWARD_STEP]',mythid) |
278 |
|
CALL DO_ATMOSPHERIC_PHYS( myTime, myIter, myThid ) |
279 |
|
CALL TIMER_STOP ('DO_ATMOSPHERIC_PHYS [FORWARD_STEP]',mythid) |
280 |
|
|
281 |
|
#ifdef ALLOW_AUTODIFF_TAMC |
282 |
|
CADJ STORE theta = comlev1, key = ikey_dynamics |
283 |
|
CADJ STORE salt = comlev1, key = ikey_dynamics |
284 |
|
CADJ STORE totphihyd = comlev1, key = ikey_dynamics |
285 |
|
CADJ STORE surfaceforcingtice = comlev1, key = ikey_dynamics |
286 |
|
# ifdef ALLOW_KPP |
287 |
|
CADJ STORE uvel = comlev1, key = ikey_dynamics |
288 |
|
CADJ STORE vvel = comlev1, key = ikey_dynamics |
289 |
|
# endif |
290 |
|
# ifdef EXACT_CONSERV |
291 |
|
CADJ STORE empmr = comlev1, key = ikey_dynamics |
292 |
|
CADJ STORE pmepr = comlev1, key = ikey_dynamics |
293 |
|
# endif |
294 |
|
#endif /* ALLOW_AUTODIFF_TAMC */ |
295 |
|
|
296 |
|
#ifndef ALLOW_OFFLINE |
297 |
|
#ifdef ALLOW_DEBUG |
298 |
|
IF ( debugLevel .GE. debLevB ) |
299 |
|
& CALL DEBUG_CALL('DO_OCEANIC_PHYS',myThid) |
300 |
|
#endif |
301 |
|
CALL TIMER_START('DO_OCEANIC_PHYS [FORWARD_STEP]',mythid) |
302 |
|
CALL DO_OCEANIC_PHYS( myTime, myIter, myThid ) |
303 |
|
CALL TIMER_STOP ('DO_OCEANIC_PHYS [FORWARD_STEP]',mythid) |
304 |
|
#endif |
305 |
|
|
306 |
|
#ifdef ALLOW_GCHEM |
307 |
|
C GCHEM package is an interface for any bio-geochemical or |
308 |
|
C ecosystem model you would like to include. |
309 |
|
C If GCHEM_SEPARATE_FORCING is not defined, you are |
310 |
|
C responsible for computing tendency terms for passive |
311 |
|
C tracers and storing them on a 3DxNumPtracers-array called |
312 |
|
C gchemTendency in GCHEM_CALC_TENDENCY. This tendency is then added |
313 |
|
C to gPtr in ptracers_forcing later-on. |
314 |
|
C If GCHEM_SEPARATE_FORCING is defined, you are reponsible for |
315 |
|
C UPDATING ptracers directly in GCHEM_FORCING_SEP. This amounts |
316 |
|
C to a completely separate time step that you have to implement |
317 |
|
C yourself (Eulerian seems to be fine in most cases). |
318 |
|
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC |
319 |
|
C CAVEAT: Up to now, when GCHEM is turned on the field ptracerForcingSurf, |
320 |
|
C which is needed for KPP is not set properly. ptracerForcingSurf must |
321 |
|
C be treated differently depending on whether GCHEM_SEPARATE_FORCING |
322 |
|
C is define or not. TBD. |
323 |
|
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC |
324 |
|
#ifdef ALLOW_DEBUG |
325 |
|
IF ( debugLevel .GE. debLevB ) |
326 |
|
& CALL DEBUG_CALL('GCHEM_CALC_TENDENCY',myThid) |
327 |
|
#endif |
328 |
|
IF ( useGCHEM ) THEN |
329 |
|
CALL TIMER_START('GCHEM_CALC_TENDENCY [FORWARD_STEP]',myThid) |
330 |
|
CALL GCHEM_CALC_TENDENCY( myTime, myIter, myThid ) |
331 |
|
CALL TIMER_STOP ('GCHEM_CALC_TENDENCY [FORWARD_STEP]',myThid) |
332 |
|
ENDIF |
333 |
|
#endif /* ALLOW_GCHEM */ |
334 |
|
|
335 |
|
#ifdef ALLOW_AUTODIFF_TAMC |
336 |
|
cph needed to be moved here from do_oceanic_physics |
337 |
|
cph to be visible down the road |
338 |
|
c |
339 |
|
CADJ STORE surfaceForcingS = comlev1, key = ikey_dynamics |
340 |
|
CADJ STORE surfaceForcingT = comlev1, key = ikey_dynamics |
341 |
|
CADJ STORE surfaceForcingTice = comlev1, key = ikey_dynamics |
342 |
|
ctest( |
343 |
|
CADJ STORE IVDConvCount = comlev1, key = ikey_dynamics |
344 |
|
ctest) |
345 |
|
# ifdef ALLOW_PTRACERS |
346 |
|
CADJ STORE surfaceForcingPtr = comlev1, key = ikey_dynamics |
347 |
|
# endif |
348 |
|
c |
349 |
|
# ifdef ALLOW_GMREDI |
350 |
|
CADJ STORE Kwx = comlev1, key = ikey_dynamics |
351 |
|
CADJ STORE Kwy = comlev1, key = ikey_dynamics |
352 |
|
CADJ STORE Kwz = comlev1, key = ikey_dynamics |
353 |
|
# ifdef GM_BOLUS_ADVEC |
354 |
|
CADJ STORE GM_PsiX = comlev1, key = ikey_dynamics |
355 |
|
CADJ STORE GM_PsiY = comlev1, key = ikey_dynamics |
356 |
|
# endif |
357 |
|
# endif |
358 |
|
c |
359 |
|
# ifdef ALLOW_KPP |
360 |
|
CADJ STORE KPPghat = comlev1, key = ikey_dynamics |
361 |
|
CADJ STORE KPPfrac = comlev1, key = ikey_dynamics |
362 |
|
CADJ STORE KPPdiffKzS = comlev1, key = ikey_dynamics |
363 |
|
CADJ STORE KPPdiffKzT = comlev1, key = ikey_dynamics |
364 |
|
# endif |
365 |
|
#endif /* ALLOW_AUTODIFF_TAMC */ |
366 |
|
|
367 |
|
IF ( .NOT.staggerTimeStep ) THEN |
368 |
|
#ifdef ALLOW_DEBUG |
369 |
|
IF ( debugLevel .GE. debLevB ) |
370 |
|
& CALL DEBUG_CALL('THERMODYNAMICS',myThid) |
371 |
|
#endif |
372 |
|
CALL TIMER_START('THERMODYNAMICS [FORWARD_STEP]',mythid) |
373 |
|
CALL THERMODYNAMICS( myTime, myIter, myThid ) |
374 |
|
CALL TIMER_STOP ('THERMODYNAMICS [FORWARD_STEP]',mythid) |
375 |
|
C-- if not staggerTimeStep: end |
376 |
|
ENDIF |
377 |
|
|
378 |
|
#ifdef COMPONENT_MODULE |
379 |
|
IF ( useCoupler .AND. .NOT.cpl_earlyExpImpCall ) THEN |
380 |
|
C Post coupling data that I export. |
381 |
|
C Read in coupling data that I import. |
382 |
|
myItP1 = myIter + 1 |
383 |
|
CALL TIMER_START('CPL_EXPORT-IMPORT [FORWARD_STEP]',myThid) |
384 |
|
CALL CPL_EXPORT_MY_DATA( myItP1, myTime, myThid ) |
385 |
|
CALL CPL_IMPORT_EXTERNAL_DATA( myItP1, myTime, myThid ) |
386 |
|
CALL TIMER_STOP ('CPL_EXPORT-IMPORT [FORWARD_STEP]',myThid) |
387 |
|
# ifndef ALLOW_AIM |
388 |
|
IF ( useRealFreshWaterFlux ) THEN |
389 |
|
CALL OCN_APPLY_IMPORT( .FALSE., myTime, myIter, myThid ) |
390 |
|
ENDIF |
391 |
|
# endif |
392 |
|
ENDIF |
393 |
|
#endif /* COMPONENT_MODULE */ |
394 |
|
|
395 |
|
C-- Step forward fields and calculate time tendency terms. |
396 |
|
#ifndef ALLOW_OFFLINE |
397 |
|
#ifndef ALLOW_AUTODIFF_TAMC |
398 |
|
IF ( momStepping ) THEN |
399 |
|
#endif |
400 |
|
#ifdef ALLOW_DEBUG |
401 |
|
IF ( debugLevel .GE. debLevB ) |
402 |
|
& CALL DEBUG_CALL('DYNAMICS',myThid) |
403 |
|
#endif |
404 |
|
CALL TIMER_START('DYNAMICS [FORWARD_STEP]',mythid) |
405 |
|
CALL DYNAMICS( myTime, myIter, myThid ) |
406 |
|
CALL TIMER_STOP ('DYNAMICS [FORWARD_STEP]',mythid) |
407 |
|
#ifndef ALLOW_AUTODIFF_TAMC |
408 |
|
ENDIF |
409 |
|
#endif |
410 |
|
#endif |
411 |
|
|
412 |
|
#ifdef ALLOW_NONHYDROSTATIC |
413 |
|
C-- Step forward W field in N-H algorithm |
414 |
|
IF ( momStepping .AND. nonHydrostatic ) THEN |
415 |
|
#ifdef ALLOW_DEBUG |
416 |
|
IF ( debugLevel .GE. debLevB ) |
417 |
|
& CALL DEBUG_CALL('CALC_GW',myThid) |
418 |
|
#endif |
419 |
|
CALL TIMER_START('CALC_GW [FORWARD_STEP]',myThid) |
420 |
|
CALL CALC_GW(myThid) |
421 |
|
CALL TIMER_STOP ('CALC_GW [FORWARD_STEP]',myThid) |
422 |
|
ENDIF |
423 |
|
#endif |
424 |
|
|
425 |
|
C-- Update time-counter |
426 |
|
myIter = nIter0 + iLoop |
427 |
|
myTime = startTime + deltaTClock * float(iLoop) |
428 |
|
|
429 |
|
C-- Update geometric factors: |
430 |
|
#ifdef NONLIN_FRSURF |
431 |
|
C- update hfacC,W,S and recip_hFac according to etaH(n+1) : |
432 |
|
IF ( nonlinFreeSurf.GT.0) THEN |
433 |
|
IF ( select_rStar.GT.0 ) THEN |
434 |
|
CALL TIMER_START('UPDATE_R_STAR [FORWARD_STEP]',myThid) |
435 |
|
CALL UPDATE_R_STAR( myTime, myIter, myThid ) |
436 |
|
CALL TIMER_STOP ('UPDATE_R_STAR [FORWARD_STEP]',myThid) |
437 |
|
ELSE |
438 |
|
CALL TIMER_START('UPDATE_SURF_DR [FORWARD_STEP]',myThid) |
439 |
|
CALL UPDATE_SURF_DR( myTime, myIter, myThid ) |
440 |
|
CALL TIMER_STOP ('UPDATE_SURF_DR [FORWARD_STEP]',myThid) |
441 |
|
ENDIF |
442 |
|
ENDIF |
443 |
|
C- update also CG2D matrix (and preconditioner) |
444 |
|
IF ( momStepping .AND. nonlinFreeSurf.GT.2 ) THEN |
445 |
|
CALL TIMER_START('UPDATE_CG2D [FORWARD_STEP]',myThid) |
446 |
|
CALL UPDATE_CG2D( myTime, myIter, myThid ) |
447 |
|
CALL TIMER_STOP ('UPDATE_CG2D [FORWARD_STEP]',myThid) |
448 |
|
ENDIF |
449 |
|
#endif |
450 |
|
|
451 |
|
C-- Apply Filters to u*,v* before SOLVE_FOR_PRESSURE |
452 |
|
#ifdef ALLOW_SHAP_FILT |
453 |
|
IF (useSHAP_FILT .AND. shap_filt_uvStar) THEN |
454 |
|
CALL TIMER_START('SHAP_FILT [FORWARD_STEP]',myThid) |
455 |
|
IF (implicDiv2Dflow.LT.1.) THEN |
456 |
|
C-- Explicit+Implicit part of the Barotropic Flow Divergence |
457 |
|
C => Filtering of uVel,vVel is necessary |
458 |
|
CALL SHAP_FILT_APPLY_UV( uVel,vVel, |
459 |
|
& myTime, myIter, myThid ) |
460 |
|
ENDIF |
461 |
|
CALL SHAP_FILT_APPLY_UV( gU,gV,myTime,myIter,myThid) |
462 |
|
CALL TIMER_STOP ('SHAP_FILT [FORWARD_STEP]',myThid) |
463 |
|
ENDIF |
464 |
|
#endif |
465 |
|
#ifdef ALLOW_ZONAL_FILT |
466 |
|
IF (useZONAL_FILT .AND. zonal_filt_uvStar) THEN |
467 |
|
CALL TIMER_START('ZONAL_FILT_APPLY [FORWARD_STEP]',myThid) |
468 |
|
IF (implicDiv2Dflow.LT.1.) THEN |
469 |
|
C-- Explicit+Implicit part of the Barotropic Flow Divergence |
470 |
|
C => Filtering of uVel,vVel is necessary |
471 |
|
CALL ZONAL_FILT_APPLY_UV( uVel, vVel, myThid ) |
472 |
|
ENDIF |
473 |
|
CALL ZONAL_FILT_APPLY_UV( gU, gV, myThid ) |
474 |
|
CALL TIMER_STOP ('ZONAL_FILT_APPLY [FORWARD_STEP]',myThid) |
475 |
|
ENDIF |
476 |
|
#endif |
477 |
|
|
478 |
C-- Solve elliptic equation(s). |
C-- Solve elliptic equation(s). |
479 |
C Two-dimensional only for conventional hydrostatic or |
C Two-dimensional only for conventional hydrostatic or |
480 |
C three-dimensional for non-hydrostatic and/or IGW scheme. |
C three-dimensional for non-hydrostatic and/or IGW scheme. |
481 |
CALL TIMER_START('SOLVE_FOR_PRESSURE [FORWARD_STEP]',myThid) |
#ifndef ALLOW_OFFLINE |
482 |
CALL SOLVE_FOR_PRESSURE( myThid ) |
IF ( momStepping ) THEN |
483 |
CALL TIMER_STOP ('SOLVE_FOR_PRESSURE [FORWARD_STEP]',myThid) |
CALL TIMER_START('SOLVE_FOR_PRESSURE [FORWARD_STEP]',myThid) |
484 |
|
CALL SOLVE_FOR_PRESSURE(myTime, myIter, myThid) |
485 |
C-- Correct divergence in flow field and cycle time-stepping |
CALL TIMER_STOP ('SOLVE_FOR_PRESSURE [FORWARD_STEP]',myThid) |
486 |
C arrays (for all fields) |
ENDIF |
487 |
CALL THE_CORRECTION_STEP(myCurrentTime, myCurrentIter, myThid) |
#endif |
488 |
|
|
489 |
|
C-- Correct divergence in flow field and cycle time-stepping momentum |
490 |
|
c IF ( momStepping ) THEN |
491 |
|
#ifndef ALLOW_OFFLINE |
492 |
|
CALL TIMER_START('UV_CORRECTION_STEP [FORWARD_STEP]',myThid) |
493 |
|
CALL MOMENTUM_CORRECTION_STEP(myTime, myIter, myThid) |
494 |
|
CALL TIMER_STOP ('UV_CORRECTION_STEP [FORWARD_STEP]',myThid) |
495 |
|
#endif |
496 |
|
c ENDIF |
497 |
|
|
498 |
|
#ifdef EXACT_CONSERV |
499 |
|
IF (exactConserv) THEN |
500 |
|
C-- Update etaH(n+1) : |
501 |
|
CALL TIMER_START('UPDATE_ETAH [FORWARD_STEP]',mythid) |
502 |
|
CALL UPDATE_ETAH( myTime, myIter, myThid ) |
503 |
|
CALL TIMER_STOP ('UPDATE_ETAH [FORWARD_STEP]',mythid) |
504 |
|
ENDIF |
505 |
|
#endif /* EXACT_CONSERV */ |
506 |
|
|
507 |
|
#ifdef NONLIN_FRSURF |
508 |
|
IF ( select_rStar.NE.0 ) THEN |
509 |
|
C-- r* : compute the future level thickness according to etaH(n+1) |
510 |
|
CALL TIMER_START('CALC_R_STAR [FORWARD_STEP]',mythid) |
511 |
|
CALL CALC_R_STAR(etaH, myTime, myIter, myThid ) |
512 |
|
CALL TIMER_STOP ('CALC_R_STAR [FORWARD_STEP]',mythid) |
513 |
|
ELSEIF ( nonlinFreeSurf.GT.0) THEN |
514 |
|
C-- compute the future surface level thickness according to etaH(n+1) |
515 |
|
CALL TIMER_START('CALC_SURF_DR [FORWARD_STEP]',mythid) |
516 |
|
CALL CALC_SURF_DR(etaH, myTime, myIter, myThid ) |
517 |
|
CALL TIMER_STOP ('CALC_SURF_DR [FORWARD_STEP]',mythid) |
518 |
|
ENDIF |
519 |
|
#endif /* NONLIN_FRSURF */ |
520 |
|
|
521 |
|
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
522 |
|
IF ( staggerTimeStep ) THEN |
523 |
|
C-- do exchanges of U,V (needed for multiDim) when using stagger time-step : |
524 |
|
#ifdef ALLOW_DEBUG |
525 |
|
IF ( debugLevel .GE. debLevB ) |
526 |
|
& CALL DEBUG_CALL('DO_STAGGER_FIELDS_EXCH.',myThid) |
527 |
|
#endif |
528 |
|
CALL TIMER_START('BLOCKING_EXCHANGES [FORWARD_STEP]',myThid) |
529 |
|
CALL DO_STAGGER_FIELDS_EXCHANGES( myTime, myIter, myThid ) |
530 |
|
CALL TIMER_STOP ('BLOCKING_EXCHANGES [FORWARD_STEP]',myThid) |
531 |
|
|
532 |
|
#ifdef ALLOW_DEBUG |
533 |
|
IF ( debugLevel .GE. debLevB ) |
534 |
|
& CALL DEBUG_CALL('THERMODYNAMICS',myThid) |
535 |
|
#endif |
536 |
|
CALL TIMER_START('THERMODYNAMICS [FORWARD_STEP]',mythid) |
537 |
|
CALL THERMODYNAMICS( myTime, myIter, myThid ) |
538 |
|
CALL TIMER_STOP ('THERMODYNAMICS [FORWARD_STEP]',mythid) |
539 |
|
|
540 |
|
C-- if staggerTimeStep: end |
541 |
|
ENDIF |
542 |
|
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
543 |
|
|
544 |
|
#ifdef ALLOW_AUTODIFF_TAMC |
545 |
|
cph This is needed because convective_adjustment calls |
546 |
|
cph find_rho which may use pressure() |
547 |
|
CADJ STORE totphihyd = comlev1, key = ikey_dynamics |
548 |
|
#endif |
549 |
|
C-- Cycle time-stepping Tracers arrays (T,S,+pTracers) |
550 |
|
CALL TIMER_START('TS_CORRECTION_STEP [FORWARD_STEP]',myThid) |
551 |
|
CALL TRACERS_CORRECTION_STEP(myTime, myIter, myThid) |
552 |
|
CALL TIMER_STOP ('TS_CORRECTION_STEP [FORWARD_STEP]',myThid) |
553 |
|
|
554 |
|
#ifdef ALLOW_GCHEM |
555 |
|
C Add separate timestepping of chemical/biological/forcing |
556 |
|
C of ptracers here in GCHEM_FORCING_SEP |
557 |
|
#ifdef ALLOW_DEBUG |
558 |
|
IF ( debugLevel .GE. debLevB ) |
559 |
|
& CALL DEBUG_CALL('GCHEM_FORCING_SEP',myThid) |
560 |
|
#endif /* ALLOW_DEBUG */ |
561 |
|
IF ( useGCHEM ) THEN |
562 |
|
CALL TIMER_START('GCHEM_FORCING_SEP [FORWARD_STEP]',myThid) |
563 |
|
CALL GCHEM_FORCING_SEP( myTime,myIter,myThid ) |
564 |
|
CALL TIMER_STOP ('GCHEM_FORCING_SEP [FORWARD_STEP]',myThid) |
565 |
|
ENDIF |
566 |
|
#endif /* ALLOW_GCHEM */ |
567 |
|
|
568 |
C-- Do "blocking" sends and receives for tendency "overlap" terms |
C-- Do "blocking" sends and receives for tendency "overlap" terms |
569 |
C CALL TIMER_START('BLOCKING_EXCHANGES [FORWARD_STEP]',myThid) |
c CALL TIMER_START('BLOCKING_EXCHANGES [FORWARD_STEP]',myThid) |
570 |
C CALL DO_GTERM_BLOCKING_EXCHANGES( myThid ) |
c CALL DO_GTERM_BLOCKING_EXCHANGES( myThid ) |
571 |
C CALL TIMER_STOP ('BLOCKING_EXCHANGES [FORWARD_STEP]',myThid) |
c CALL TIMER_STOP ('BLOCKING_EXCHANGES [FORWARD_STEP]',myThid) |
572 |
|
|
573 |
C-- Do "blocking" sends and receives for field "overlap" terms |
C-- Do "blocking" sends and receives for field "overlap" terms |
574 |
CALL TIMER_START('BLOCKING_EXCHANGES [FORWARD_STEP]',myThid) |
CALL TIMER_START('BLOCKING_EXCHANGES [FORWARD_STEP]',myThid) |
575 |
CALL DO_FIELDS_BLOCKING_EXCHANGES( myThid ) |
CALL DO_FIELDS_BLOCKING_EXCHANGES( myThid ) |
576 |
CALL TIMER_STOP ('BLOCKING_EXCHANGES [FORWARD_STEP]',myThid) |
CALL TIMER_STOP ('BLOCKING_EXCHANGES [FORWARD_STEP]',myThid) |
577 |
|
|
578 |
|
|
579 |
|
C AMM |
580 |
|
#ifdef ALLOW_GRIDALT |
581 |
|
if (useGRIDALT) then |
582 |
|
CALL GRIDALT_UPDATE(myThid) |
583 |
|
endif |
584 |
|
#endif |
585 |
|
C AMM |
586 |
|
|
587 |
|
C AMM |
588 |
|
#ifdef ALLOW_FIZHI |
589 |
|
if( useFIZHI) then |
590 |
|
CALL TIMER_START('FIZHI [FORWARD_STEP]',mythid) |
591 |
|
CALL STEP_FIZHI_CORR ( myTime, myIter, myThid ) |
592 |
|
CALL TIMER_STOP('FIZHI [FORWARD_STEP]',mythid) |
593 |
|
endif |
594 |
|
#endif |
595 |
|
C AMM |
596 |
|
|
597 |
c myCurrentIter = myCurrentIter + 1 |
#ifdef ALLOW_FLT |
598 |
c myCurrentTime = myCurrentTime + deltaTClock |
C-- Calculate float trajectories |
599 |
myCurrentIter = nIter0 + iLoop |
IF (useFLT) THEN |
600 |
myCurrentTime = startTime + deltaTClock * float(iLoop) |
CALL TIMER_START('FLOATS [FORWARD_STEP]',myThid) |
601 |
|
CALL FLT_MAIN(myIter,myTime, myThid) |
602 |
|
CALL TIMER_STOP ('FLOATS [FORWARD_STEP]',myThid) |
603 |
|
ENDIF |
604 |
|
#endif |
605 |
|
|
606 |
|
C-- State-variables statistics (time-aver, diagnostics ...) |
607 |
|
CALL TIMER_START('DO_STATEVARS_DIAGS [FORWARD_STEP]',myThid) |
608 |
|
CALL DO_STATEVARS_DIAGS( myTime, myIter, myThid ) |
609 |
|
CALL TIMER_STOP ('DO_STATEVARS_DIAGS [FORWARD_STEP]',myThid) |
610 |
|
|
611 |
|
#ifndef ALLOW_OFFLINE |
612 |
|
#ifdef ALLOW_MONITOR |
613 |
|
C-- Check status of solution (statistics, cfl, etc...) |
614 |
|
CALL TIMER_START('MONITOR [FORWARD_STEP]',myThid) |
615 |
|
CALL MONITOR( myIter, myTime, myThid ) |
616 |
|
CALL TIMER_STOP ('MONITOR [FORWARD_STEP]',myThid) |
617 |
|
#endif /* ALLOW_MONITOR */ |
618 |
|
#endif |
619 |
|
|
620 |
|
#ifdef ALLOW_COST |
621 |
|
C-- compare model with data and compute cost function |
622 |
|
C-- this is done after exchanges to allow interpolation |
623 |
|
CALL TIMER_START('COST_TILE [FORWARD_STEP]',myThid) |
624 |
|
CALL COST_TILE ( mytime, myiter, myThid ) |
625 |
|
CALL TIMER_STOP ('COST_TILE [FORWARD_STEP]',myThid) |
626 |
|
#endif |
627 |
|
|
628 |
|
C-- Do IO if needed. |
629 |
|
#ifdef ALLOW_OFFLINE |
630 |
|
CALL TIMER_START('OFFLINE_MODEL_IO [FORWARD_STEP]',myThid) |
631 |
|
CALL OFFLINE_MODEL_IO( myTime, myIter, myThid ) |
632 |
|
CALL TIMER_STOP ('OFFLINE_MODEL_IO [FORWARD_STEP]',myThid) |
633 |
|
#else |
634 |
|
CALL TIMER_START('DO_THE_MODEL_IO [FORWARD_STEP]',myThid) |
635 |
|
CALL DO_THE_MODEL_IO( myTime, myIter, myThid ) |
636 |
|
CALL TIMER_STOP ('DO_THE_MODEL_IO [FORWARD_STEP]',myThid) |
637 |
|
#endif |
638 |
|
|
639 |
C-- Save state for restarts |
C-- Save state for restarts |
640 |
C Note: |
CALL TIMER_START('WRITE_CHECKPOINT [FORWARD_STEP]',myThid) |
641 |
C ===== |
CALL PACKAGES_WRITE_PICKUP( |
642 |
C Because of the ordering of the timestepping code and |
I .FALSE., myTime, myIter, myThid ) |
643 |
C tendency term code at end of loop model arrays hold |
#ifndef ALLOW_OFFLINE |
|
C U,V,T,S at "time-level" N but gu, gv, gs, gt, guNM1,... |
|
|
C at "time-level" N+1/2 (guNM1 at "time-level" N+1/2 is |
|
|
C gu at "time-level" N-1/2) and cg2d_x at "time-level" N+1/2. |
|
|
C where N = I+timeLevBase-1 |
|
|
C Thus a checkpoint contains U.0000000000, GU.0000000001 and |
|
|
C cg2d_x.0000000001 in the indexing scheme used for the model |
|
|
C "state" files. This example is referred to as a checkpoint |
|
|
C at time level 1 |
|
|
CALL TIMER_START('I/O (WRITE) [FORWARD_STEP]',myThid) |
|
644 |
CALL WRITE_CHECKPOINT( |
CALL WRITE_CHECKPOINT( |
645 |
& .FALSE., myCurrentTime, myCurrentIter, myThid ) |
I .FALSE., myTime, myIter, myThid ) |
646 |
CALL TIMER_STOP ('I/O (WRITE) [FORWARD_STEP]',myThid) |
#endif |
647 |
|
CALL TIMER_STOP ('WRITE_CHECKPOINT [FORWARD_STEP]',myThid) |
648 |
|
|
649 |
ENDIF |
#ifdef ALLOW_DEBUG |
650 |
|
IF ( debugLevel .GE. debLevB ) |
651 |
|
& CALL DEBUG_LEAVE('FORWARD_STEP',myThid) |
652 |
|
#endif |
653 |
|
|
654 |
RETURN |
RETURN |
655 |
END |
END |