3 |
|
|
4 |
#include "CPP_OPTIONS.h" |
#include "CPP_OPTIONS.h" |
5 |
|
|
6 |
SUBROUTINE FORWARD_STEP( |
CBOP |
7 |
I iLoop, |
C !ROUTINE: FORWARD_STEP |
8 |
U myCurrentTime, myCurrentIter, |
C !INTERFACE: |
9 |
& myThid) |
SUBROUTINE FORWARD_STEP( iloop, myTime, myIter, myThid ) |
10 |
C /==========================================================\ |
|
11 |
C | SUBROUTINE FORWARD_STEP | |
C !DESCRIPTION: \bv |
12 |
C | o Does one instance of the model time stepping | |
C *================================================================== |
13 |
C | The time stepping loop in THE_MAIN_LOOP() calls | |
C | SUBROUTINE forward_step |
14 |
C | this routine | |
C | o Run the ocean model and, optionally, evaluate a cost function. |
15 |
C |==========================================================| |
C *================================================================== |
16 |
C \==========================================================/ |
C | |
17 |
IMPLICIT NONE |
C | THE_MAIN_LOOP is the toplevel routine for the Tangent Linear and |
18 |
C |
C | Adjoint Model Compiler (TAMC). For this purpose the initialization |
19 |
C Call Tree |
C | of the model was split into two parts. Those parameters that do |
20 |
C ========= |
C | not depend on a specific model run are set in INITIALISE_FIXED, |
21 |
C |
C | whereas those that do depend on the specific realization are |
22 |
C THE_MAIN_LOOP() |
C | initialized in INITIALISE_VARIA. |
23 |
C | |
C | |
24 |
C ==> | ** Time stepping loop starts here ** |
C *================================================================== |
25 |
C | | |
C \ev |
|
C /|\ |-FORWARD_STEP |
|
|
C | | | |
|
|
C /|\ | |--LOAD_EXTERNAL_DATA |
|
|
C | | | o Load and/or set time dependent forcing fields |
|
|
C /|\ | | |
|
|
C | | |--DYNAMICS |
|
|
C /|\ | | o Evaluate "forward" terms |
|
|
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 | | |--DO_THE_MODEL_IO |
|
|
C /|\ | | o Write model state |
|
|
C | | | |
|
|
C /|\ | | |
|
|
C | | |--WRITE_CHECKPOINT |
|
|
C /|\ | | o Write restart file(s) |
|
|
C | | |
|
|
C /|\ | |
|
|
C |<== | ** Time stepping loop finishes here ** |
|
|
C |
|
26 |
|
|
27 |
C == Global variables === |
C !USES: |
28 |
|
IMPLICIT NONE |
29 |
|
C == Global variables == |
30 |
#include "SIZE.h" |
#include "SIZE.h" |
31 |
#include "EEPARAMS.h" |
#include "EEPARAMS.h" |
32 |
#include "PARAMS.h" |
#include "PARAMS.h" |
33 |
#include "DYNVARS.h" |
#include "DYNVARS.h" |
34 |
|
#include "FFIELDS.h" |
35 |
|
|
36 |
#ifdef ALLOW_NONHYDROSTATIC |
#ifdef ALLOW_NONHYDROSTATIC |
37 |
#include "CG3D.h" |
#include "CG3D.h" |
38 |
#endif |
#endif |
39 |
|
|
40 |
|
#ifdef ALLOW_AUTODIFF_TAMC |
41 |
|
#include "tamc.h" |
42 |
|
#include "ctrl.h" |
43 |
|
#include "ctrl_dummy.h" |
44 |
|
#include "cost.h" |
45 |
|
#endif |
46 |
|
|
47 |
|
C !LOCAL VARIABLES: |
48 |
C == Routine arguments == |
C == Routine arguments == |
49 |
C iLoop - Invocation count (counter in THE_MAIN_LOOP) |
C note: under the multi-threaded model myiter and |
50 |
C myCurrentIter - Iteration counter for this thread |
C mytime are local variables passed around as routine |
51 |
C myCurrentTime - Time counter for this thread |
C arguments. Although this is fiddly it saves the need to |
52 |
C myThid - Thread number for this instance of the routine. |
C impose additional synchronisation points when they are |
53 |
INTEGER iLoop |
C updated. |
54 |
INTEGER myCurrentIter |
C myiter - iteration counter for this thread |
55 |
_RL myCurrentTime |
C mytime - time counter for this thread |
56 |
INTEGER myThid |
C mythid - thread number for this instance of the routine. |
57 |
|
integer iloop |
58 |
C == Local variables == |
integer mythid |
59 |
|
integer myiter |
60 |
C-- Load forcing/external data fields |
_RL mytime |
61 |
CALL TIMER_START('I/O (READ) [FORWARD_STEP]',myThid) |
INTEGER bi,bj |
62 |
CALL EXTERNAL_FIELDS_LOAD( myCurrentTime, myCurrentIter, myThid ) |
|
63 |
CALL TIMER_STOP ('I/O (READ) [FORWARD_STEP]',myThid) |
CEOP |
64 |
|
|
65 |
C-- Step forward fields and calculate time tendency terms |
|
66 |
CALL TIMER_START('DYNAMICS [FORWARD_STEP]',myThid) |
#ifdef ALLOW_AUTODIFF_TAMC |
67 |
CALL DYNAMICS( myCurrentTime, myCurrentIter, myThid ) |
C-- Reset the model iteration counter and the model time. |
68 |
CALL TIMER_STOP ('DYNAMICS [FORWARD_STEP]',myThid) |
myiter = nIter0 + (iloop-1) |
69 |
|
mytime = startTime + float(iloop-1)*deltaTclock |
70 |
|
#endif |
71 |
|
|
72 |
#ifdef ALLOW_NONHYDROSTATIC |
#ifdef ALLOW_AUTODIFF_TAMC |
73 |
C-- Step forward W field in N-H algorithm |
C Include call to a dummy routine. Its adjoint will be |
74 |
IF ( nonHydrostatic ) THEN |
C called at the proper place in the adjoint code. |
75 |
CALL TIMER_START('CALC_GW [FORWARD_STEP]',myThid) |
C The adjoint routine will print out adjoint values |
76 |
CALL CALC_GW( myThid) |
C if requested. The location of the call is important, |
77 |
CALL TIMER_STOP ('CALC_GW [FORWARD_STEP]',myThid) |
C it has to be after the adjoint of the exchanges |
78 |
|
C (DO_GTERM_BLOCKING_EXCHANGES). |
79 |
|
CALL DUMMY_IN_STEPPING( myTime, myIter, myThid ) |
80 |
|
#endif |
81 |
|
|
82 |
|
#ifdef EXACT_CONSERV |
83 |
|
IF (exactConserv) THEN |
84 |
|
C-- Update etaH(n+1) : |
85 |
|
DO bj=myByLo(myThid),myByHi(myThid) |
86 |
|
DO bi=myBxLo(myThid),myBxHi(myThid) |
87 |
|
CALL CALC_EXACT_ETA( .FALSE., bi,bj, uVel,vVel, |
88 |
|
I startTime, nIter0, myThid ) |
89 |
|
ENDDO |
90 |
|
ENDDO |
91 |
|
IF (implicDiv2Dflow .NE. 1. _d 0 ) |
92 |
|
& _EXCH_XY_R8(etaH, myThid ) |
93 |
ENDIF |
ENDIF |
94 |
|
#endif /* EXACT_CONSERV */ |
95 |
|
|
96 |
|
#ifdef NONLIN_FRSURF |
97 |
|
C-- compute the future surface level thickness |
98 |
|
C according to etaH(n+1) |
99 |
|
IF ( nonlinFreeSurf.GT.0) THEN |
100 |
|
CALL CALC_SURF_DR(etaH, myTime, myIter, myThid ) |
101 |
|
ENDIF |
102 |
|
#endif /* NONLIN_FRSURF */ |
103 |
|
|
104 |
|
C-- Load forcing/external data fields. |
105 |
|
#ifdef INCLUDE_EXTERNAL_FORCING_PACKAGE |
106 |
|
C NOTE, that although the exf package is part of the |
107 |
|
C distribution, it is not currently maintained, i.e. |
108 |
|
C exf is disabled by default in genmake. |
109 |
|
#ifdef ALLOW_BULKFORMULAE |
110 |
|
CADJ STORE theta = comlev1, key = ikey_dynamics |
111 |
|
#endif |
112 |
|
CALL EXF_GETFORCING( mytime, myiter, mythid ) |
113 |
|
#else |
114 |
|
CALL TIMER_START('EXTERNAL_FIELDS_LOAD[THE_MAIN_LOOP]',mythid) |
115 |
|
CALL EXTERNAL_FIELDS_LOAD( mytime, myiter, mythid ) |
116 |
|
CALL TIMER_STOP ('EXTERNAL_FIELDS_LOAD[THE_MAIN_LOOP]',mythid) |
117 |
#endif |
#endif |
118 |
|
|
119 |
|
C-- Step forward fields and calculate time tendency terms. |
120 |
|
CALL TIMER_START('THERMODYNAMICS [THE_MAIN_LOOP]',mythid) |
121 |
|
CALL THERMODYNAMICS( myTime, myIter, myThid ) |
122 |
|
CALL TIMER_STOP ('THERMODYNAMICS [THE_MAIN_LOOP]',mythid) |
123 |
|
|
124 |
#ifdef ALLOW_SHAP_FILT |
#ifdef ALLOW_SHAP_FILT |
125 |
C-- Step forward all tiles, filter and exchange. |
IF (staggerTimeStep .AND. useSHAP_FILT) THEN |
126 |
CALL TIMER_START('SHAP_FILT [FORWARD_STEP]',myThid) |
c CALL TIMER_START('SHAP_FILT [THE_MAIN_LOOP]',myThid) |
127 |
CALL SHAP_FILT_APPLY( |
CALL SHAP_FILT_APPLY_TS( gT, gS, myTime, myIter, myThid ) |
128 |
I gUnm1, gVnm1, gTnm1, gSnm1, |
c CALL TIMER_STOP ('SHAP_FILT [THE_MAIN_LOOP]',myThid) |
129 |
I myCurrentTime, myCurrentIter, myThid ) |
ENDIF |
130 |
IF (implicDiv2Dflow.LT.1.) THEN |
#endif |
131 |
C-- Explicit+Implicit part of the Barotropic Flow Divergence |
|
132 |
C => Filtering of uVel,vVel is necessary |
C-- Step forward fields and calculate time tendency terms. |
133 |
CALL SHAP_FILT_UV( uVel, vVel, myCurrentTime, myThid ) |
IF ( momStepping ) THEN |
134 |
ENDIF |
CALL TIMER_START('DYNAMICS [THE_MAIN_LOOP]',mythid) |
135 |
CALL TIMER_STOP ('SHAP_FILT [FORWARD_STEP]',myThid) |
CALL DYNAMICS( myTime, myIter, myThid ) |
136 |
#endif |
CALL TIMER_STOP ('DYNAMICS [THE_MAIN_LOOP]',mythid) |
137 |
|
ENDIF |
138 |
#ifdef ALLOW_ZONAL_FILT |
|
139 |
IF (zonal_filt_lat.LT.90.) THEN |
#ifdef ALLOW_NONHYDROSTATIC |
140 |
CALL ZONAL_FILT_APPLY( |
C-- Step forward W field in N-H algorithm |
141 |
U gUnm1, gVnm1, gTnm1, gSnm1, |
IF ( momStepping .AND. nonHydrostatic ) THEN |
142 |
I myThid ) |
CALL TIMER_START('CALC_GW [THE_MAIN_LOOP]',myThid) |
143 |
|
CALL CALC_GW(myThid) |
144 |
|
CALL TIMER_STOP ('CALC_GW [THE_MAIN_LOOP]',myThid) |
145 |
|
ENDIF |
146 |
|
#endif |
147 |
|
|
148 |
|
#ifdef NONLIN_FRSURF |
149 |
|
C-- update hfacC,W,S and recip_hFac according to etaH(n+1) : |
150 |
|
IF ( momStepping ) THEN |
151 |
|
IF ( nonlinFreeSurf.GT.0) THEN |
152 |
|
CALL UPDATE_SURF_DR( myTime, myIter, myThid ) |
153 |
|
ENDIF |
154 |
|
C- update also CG2D matrix (and preconditioner) |
155 |
|
IF ( nonlinFreeSurf.GT.2) THEN |
156 |
|
CALL UPDATE_CG2D( myTime, myIter, myThid ) |
157 |
|
ENDIF |
158 |
ENDIF |
ENDIF |
159 |
#endif |
#endif |
160 |
|
|
161 |
|
C-- This block has been moved to the_correction_step(). We have |
162 |
|
C left this code here to indicate where the filters used to be |
163 |
|
C in the algorithm before JMC moved them to after the pressure |
164 |
|
C solver. |
165 |
|
C |
166 |
|
C#ifdef ALLOW_SHAP_FILT |
167 |
|
CC-- Step forward all tiles, filter and exchange. |
168 |
|
C CALL TIMER_START('SHAP_FILT [THE_MAIN_LOOP]',myThid) |
169 |
|
C CALL SHAP_FILT_APPLY( |
170 |
|
C I gUnm1, gVnm1, gTnm1, gSnm1, |
171 |
|
C I myTime, myIter, myThid ) |
172 |
|
C IF (implicDiv2Dflow.LT.1.) THEN |
173 |
|
CC-- Explicit+Implicit part of the Barotropic Flow Divergence |
174 |
|
CC => Filtering of uVel,vVel is necessary |
175 |
|
C CALL SHAP_FILT_UV( uVel, vVel, myTime, myThid ) |
176 |
|
C ENDIF |
177 |
|
C CALL TIMER_STOP ('SHAP_FILT [THE_MAIN_LOOP]',myThid) |
178 |
|
C#endif |
179 |
|
C |
180 |
|
C#ifdef ALLOW_ZONAL_FILT |
181 |
|
C IF (zonal_filt_lat.LT.90.) THEN |
182 |
|
C CALL TIMER_START('ZONAL_FILT_APPLY [THE_MAIN_LOOP]',myThid) |
183 |
|
C CALL ZONAL_FILT_APPLY( |
184 |
|
C U gUnm1, gVnm1, gTnm1, gSnm1, |
185 |
|
C I myThid ) |
186 |
|
C CALL TIMER_STOP ('ZONAL_FILT_APPLY [THE_MAIN_LOOP]',myThid) |
187 |
|
C ENDIF |
188 |
|
C#endif |
189 |
|
|
190 |
C-- Solve elliptic equation(s). |
C-- Solve elliptic equation(s). |
191 |
C Two-dimensional only for conventional hydrostatic or |
C Two-dimensional only for conventional hydrostatic or |
192 |
C three-dimensional for non-hydrostatic and/or IGW scheme. |
C three-dimensional for non-hydrostatic and/or IGW scheme. |
193 |
CALL TIMER_START('SOLVE_FOR_PRESSURE [FORWARD_STEP]',myThid) |
IF ( momStepping ) THEN |
194 |
|
CALL TIMER_START('SOLVE_FOR_PRESSURE [THE_MAIN_LOOP]',myThid) |
195 |
CALL SOLVE_FOR_PRESSURE( myThid ) |
CALL SOLVE_FOR_PRESSURE( myThid ) |
196 |
CALL TIMER_STOP ('SOLVE_FOR_PRESSURE [FORWARD_STEP]',myThid) |
CALL TIMER_STOP ('SOLVE_FOR_PRESSURE [THE_MAIN_LOOP]',myThid) |
197 |
|
ENDIF |
198 |
|
|
199 |
C-- Correct divergence in flow field and cycle time-stepping |
C-- Correct divergence in flow field and cycle time-stepping |
200 |
C arrays (for all fields) ; update time-counter |
C arrays (for all fields) ; update time-counter |
201 |
myCurrentIter = nIter0 + iLoop |
myIter = nIter0 + iLoop |
202 |
myCurrentTime = startTime + deltaTClock * float(iLoop) |
myTime = startTime + deltaTClock * float(iLoop) |
203 |
CALL THE_CORRECTION_STEP(myCurrentTime, myCurrentIter, myThid) |
CALL TIMER_START('THE_CORRECTION_STEP [THE_MAIN_LOOP]',myThid) |
204 |
|
CALL THE_CORRECTION_STEP(myTime, myIter, myThid) |
205 |
|
CALL TIMER_STOP ('THE_CORRECTION_STEP [THE_MAIN_LOOP]',myThid) |
206 |
|
|
207 |
C-- Do "blocking" sends and receives for tendency "overlap" terms |
C-- Do "blocking" sends and receives for tendency "overlap" terms |
208 |
c CALL TIMER_START('BLOCKING_EXCHANGES [FORWARD_STEP]',myThid) |
c CALL TIMER_START('BLOCKING_EXCHANGES [THE_MAIN_LOOP]',myThid) |
209 |
c CALL DO_GTERM_BLOCKING_EXCHANGES( myThid ) |
c CALL DO_GTERM_BLOCKING_EXCHANGES( myThid ) |
210 |
c CALL TIMER_STOP ('BLOCKING_EXCHANGES [FORWARD_STEP]',myThid) |
c CALL TIMER_STOP ('BLOCKING_EXCHANGES [THE_MAIN_LOOP]',myThid) |
211 |
|
|
212 |
C-- Do "blocking" sends and receives for field "overlap" terms |
C-- Do "blocking" sends and receives for field "overlap" terms |
213 |
CALL TIMER_START('BLOCKING_EXCHANGES [FORWARD_STEP]',myThid) |
CALL TIMER_START('BLOCKING_EXCHANGES [THE_MAIN_LOOP]',myThid) |
214 |
CALL DO_FIELDS_BLOCKING_EXCHANGES( myThid ) |
CALL DO_FIELDS_BLOCKING_EXCHANGES( myThid ) |
215 |
CALL TIMER_STOP ('BLOCKING_EXCHANGES [FORWARD_STEP]',myThid) |
CALL TIMER_STOP ('BLOCKING_EXCHANGES [THE_MAIN_LOOP]',myThid) |
216 |
|
|
217 |
|
#ifdef ALLOW_FLT |
218 |
|
C-- Calculate float trajectories |
219 |
|
IF (useFLT) THEN |
220 |
|
CALL TIMER_START('FLOATS [THE_MAIN_LOOP]',myThid) |
221 |
|
CALL FLT_MAIN(myIter,myTime, myThid) |
222 |
|
CALL TIMER_STOP ('FLOATS [THE_MAIN_LOOP]',myThid) |
223 |
|
ENDIF |
224 |
|
#endif |
225 |
|
|
226 |
|
#ifndef EXCLUDE_MONITOR |
227 |
|
C-- Check status of solution (statistics, cfl, etc...) |
228 |
|
CALL MONITOR( myIter, myTime, myThid ) |
229 |
|
#endif /* EXCLUDE_MONITOR */ |
230 |
|
|
231 |
|
#ifndef ALLOW_AUTODIFF_TAMC |
232 |
C-- Do IO if needed. |
C-- Do IO if needed. |
233 |
CALL TIMER_START('I/O (WRITE) [FORWARD_STEP]',myThid) |
CALL TIMER_START('DO_THE_MODEL_IO [THE_MAIN_LOOP]',myThid) |
234 |
CALL DO_THE_MODEL_IO(.FALSE., |
CALL DO_THE_MODEL_IO( myTime, myIter, myThid ) |
235 |
& myCurrentTime, myCurrentIter, myThid ) |
CALL TIMER_STOP ('DO_THE_MODEL_IO [THE_MAIN_LOOP]',myThid) |
|
CALL TIMER_STOP ('I/O (WRITE) [FORWARD_STEP]',myThid) |
|
236 |
|
|
237 |
C-- Save state for restarts |
C-- Save state for restarts |
238 |
C Note: (jmc: is it still the case after ckp35 ?) |
C Note: (jmc: is it still the case after ckp35 ?) |
247 |
C etaN.0000000001 in the indexing scheme used for the model |
C etaN.0000000001 in the indexing scheme used for the model |
248 |
C "state" files. This example is referred to as a checkpoint |
C "state" files. This example is referred to as a checkpoint |
249 |
C at time level 1 |
C at time level 1 |
250 |
CALL TIMER_START('I/O (WRITE) [FORWARD_STEP]',myThid) |
CALL TIMER_START('WRITE_CHECKPOINT [THE_MAIN_LOOP]',myThid) |
251 |
CALL WRITE_CHECKPOINT( |
CALL WRITE_CHECKPOINT( |
252 |
& .FALSE., myCurrentTime, myCurrentIter, myThid ) |
& .FALSE., myTime, myIter, myThid ) |
253 |
CALL TIMER_STOP ('I/O (WRITE) [FORWARD_STEP]',myThid) |
CALL TIMER_STOP ('WRITE_CHECKPOINT [THE_MAIN_LOOP]',myThid) |
254 |
|
|
255 |
|
#endif /* ALLOW_AUTODIFF_TAMC */ |
256 |
|
|
|
RETURN |
|
257 |
END |
END |