1 |
jmc |
1.33 |
C $Header: /u/gcmpack/MITgcm/model/src/forward_step.F,v 1.32 2002/05/30 02:32:14 heimbach Exp $ |
2 |
adcroft |
1.15 |
C $Name: $ |
3 |
adcroft |
1.1 |
|
4 |
|
|
#include "CPP_OPTIONS.h" |
5 |
|
|
|
6 |
cnh |
1.22 |
CBOP |
7 |
|
|
C !ROUTINE: FORWARD_STEP |
8 |
|
|
C !INTERFACE: |
9 |
adcroft |
1.13 |
SUBROUTINE FORWARD_STEP( iloop, myTime, myIter, myThid ) |
10 |
heimbach |
1.12 |
|
11 |
cnh |
1.22 |
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 |
adcroft |
1.1 |
|
27 |
cnh |
1.22 |
C !USES: |
28 |
|
|
IMPLICIT NONE |
29 |
|
|
C == Global variables == |
30 |
adcroft |
1.1 |
#include "SIZE.h" |
31 |
|
|
#include "EEPARAMS.h" |
32 |
|
|
#include "PARAMS.h" |
33 |
|
|
#include "DYNVARS.h" |
34 |
heimbach |
1.12 |
#include "FFIELDS.h" |
35 |
|
|
|
36 |
adcroft |
1.1 |
#ifdef ALLOW_NONHYDROSTATIC |
37 |
|
|
#include "CG3D.h" |
38 |
|
|
#endif |
39 |
|
|
|
40 |
jmc |
1.27 |
#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 |
heimbach |
1.12 |
#ifdef ALLOW_AUTODIFF_TAMC |
48 |
heimbach |
1.30 |
# include "tamc.h" |
49 |
|
|
# include "ctrl.h" |
50 |
|
|
# include "ctrl_dummy.h" |
51 |
|
|
# include "cost.h" |
52 |
|
|
# ifdef INCLUDE_EXTERNAL_FORCING_PACKAGE |
53 |
|
|
# include "exf_fields.h" |
54 |
|
|
# ifdef ALLOW_BULKFORMULAE |
55 |
|
|
# include "exf_constants.h" |
56 |
|
|
# endif |
57 |
|
|
# endif |
58 |
|
|
# ifdef ALLOW_OBCS |
59 |
|
|
# include "OBCS.h" |
60 |
|
|
# endif |
61 |
heimbach |
1.12 |
#endif |
62 |
|
|
|
63 |
cnh |
1.22 |
C !LOCAL VARIABLES: |
64 |
|
|
C == Routine arguments == |
65 |
adcroft |
1.13 |
C note: under the multi-threaded model myiter and |
66 |
|
|
C mytime are local variables passed around as routine |
67 |
|
|
C arguments. Although this is fiddly it saves the need to |
68 |
|
|
C impose additional synchronisation points when they are |
69 |
|
|
C updated. |
70 |
|
|
C myiter - iteration counter for this thread |
71 |
|
|
C mytime - time counter for this thread |
72 |
|
|
C mythid - thread number for this instance of the routine. |
73 |
heimbach |
1.12 |
integer iloop |
74 |
|
|
integer mythid |
75 |
|
|
integer myiter |
76 |
|
|
_RL mytime |
77 |
jmc |
1.21 |
INTEGER bi,bj |
78 |
heimbach |
1.12 |
|
79 |
cnh |
1.22 |
CEOP |
80 |
heimbach |
1.12 |
|
81 |
|
|
|
82 |
|
|
#ifdef ALLOW_AUTODIFF_TAMC |
83 |
heimbach |
1.14 |
C-- Reset the model iteration counter and the model time. |
84 |
heimbach |
1.12 |
myiter = nIter0 + (iloop-1) |
85 |
|
|
mytime = startTime + float(iloop-1)*deltaTclock |
86 |
|
|
#endif |
87 |
|
|
|
88 |
heimbach |
1.32 |
#if (defined (ALLOW_AUTODIFF_TAMC) && defined (ALLOW_AUTODIFF_MONITOR)) |
89 |
heimbach |
1.16 |
C Include call to a dummy routine. Its adjoint will be |
90 |
|
|
C called at the proper place in the adjoint code. |
91 |
|
|
C The adjoint routine will print out adjoint values |
92 |
|
|
C if requested. The location of the call is important, |
93 |
|
|
C it has to be after the adjoint of the exchanges |
94 |
|
|
C (DO_GTERM_BLOCKING_EXCHANGES). |
95 |
|
|
CALL DUMMY_IN_STEPPING( myTime, myIter, myThid ) |
96 |
heimbach |
1.26 |
CALL DO_FIELDS_BLOCKING_EXCHANGES( myThid ) |
97 |
heimbach |
1.16 |
#endif |
98 |
|
|
|
99 |
jmc |
1.21 |
#ifdef EXACT_CONSERV |
100 |
|
|
IF (exactConserv) THEN |
101 |
|
|
C-- Update etaH(n+1) : |
102 |
|
|
DO bj=myByLo(myThid),myByHi(myThid) |
103 |
|
|
DO bi=myBxLo(myThid),myBxHi(myThid) |
104 |
|
|
CALL CALC_EXACT_ETA( .FALSE., bi,bj, uVel,vVel, |
105 |
jmc |
1.29 |
I myTime, myIter, myThid ) |
106 |
jmc |
1.21 |
ENDDO |
107 |
|
|
ENDDO |
108 |
jmc |
1.29 |
IF (implicDiv2Dflow .NE. 1. _d 0 .OR. useOBCS ) |
109 |
jmc |
1.21 |
& _EXCH_XY_R8(etaH, myThid ) |
110 |
|
|
ENDIF |
111 |
|
|
#endif /* EXACT_CONSERV */ |
112 |
|
|
|
113 |
jmc |
1.18 |
#ifdef NONLIN_FRSURF |
114 |
|
|
C-- compute the future surface level thickness |
115 |
jmc |
1.21 |
C according to etaH(n+1) |
116 |
jmc |
1.18 |
IF ( nonlinFreeSurf.GT.0) THEN |
117 |
jmc |
1.21 |
CALL CALC_SURF_DR(etaH, myTime, myIter, myThid ) |
118 |
jmc |
1.18 |
ENDIF |
119 |
jmc |
1.21 |
#endif /* NONLIN_FRSURF */ |
120 |
jmc |
1.18 |
|
121 |
adcroft |
1.13 |
C-- Load forcing/external data fields. |
122 |
heimbach |
1.12 |
#ifdef INCLUDE_EXTERNAL_FORCING_PACKAGE |
123 |
adcroft |
1.13 |
C NOTE, that although the exf package is part of the |
124 |
|
|
C distribution, it is not currently maintained, i.e. |
125 |
|
|
C exf is disabled by default in genmake. |
126 |
heimbach |
1.28 |
#ifdef ALLOW_AUTODIFF_TAMC |
127 |
|
|
c************************************** |
128 |
|
|
#include "checkpoint_lev1_directives.h" |
129 |
|
|
c************************************** |
130 |
heimbach |
1.23 |
#endif |
131 |
heimbach |
1.12 |
CALL EXF_GETFORCING( mytime, myiter, mythid ) |
132 |
|
|
#else |
133 |
|
|
CALL TIMER_START('EXTERNAL_FIELDS_LOAD[THE_MAIN_LOOP]',mythid) |
134 |
|
|
CALL EXTERNAL_FIELDS_LOAD( mytime, myiter, mythid ) |
135 |
|
|
CALL TIMER_STOP ('EXTERNAL_FIELDS_LOAD[THE_MAIN_LOOP]',mythid) |
136 |
|
|
#endif |
137 |
adcroft |
1.15 |
|
138 |
|
|
C-- Step forward fields and calculate time tendency terms. |
139 |
|
|
CALL TIMER_START('THERMODYNAMICS [THE_MAIN_LOOP]',mythid) |
140 |
|
|
CALL THERMODYNAMICS( myTime, myIter, myThid ) |
141 |
|
|
CALL TIMER_STOP ('THERMODYNAMICS [THE_MAIN_LOOP]',mythid) |
142 |
jmc |
1.24 |
|
143 |
|
|
#ifdef ALLOW_SHAP_FILT |
144 |
jmc |
1.27 |
IF (useSHAP_FILT .AND. |
145 |
|
|
& staggerTimeStep .AND. shap_filt_TrStagg ) THEN |
146 |
|
|
CALL TIMER_START('SHAP_FILT [THE_MAIN_LOOP]',myThid) |
147 |
jmc |
1.24 |
CALL SHAP_FILT_APPLY_TS( gT, gS, myTime, myIter, myThid ) |
148 |
jmc |
1.27 |
CALL TIMER_STOP ('SHAP_FILT [THE_MAIN_LOOP]',myThid) |
149 |
jmc |
1.24 |
ENDIF |
150 |
|
|
#endif |
151 |
jmc |
1.27 |
#ifdef ALLOW_ZONAL_FILT |
152 |
|
|
IF (useZONAL_FILT .AND. |
153 |
|
|
& staggerTimeStep .AND. zonal_filt_TrStagg ) THEN |
154 |
|
|
CALL TIMER_START('ZONAL_FILT_APPLY [THE_MAIN_LOOP]',myThid) |
155 |
|
|
CALL ZONAL_FILT_APPLY_TS( gT, gS, myThid ) |
156 |
|
|
CALL TIMER_STOP ('ZONAL_FILT_APPLY [THE_MAIN_LOOP]',myThid) |
157 |
|
|
ENDIF |
158 |
|
|
#endif |
159 |
heimbach |
1.12 |
|
160 |
adcroft |
1.13 |
C-- Step forward fields and calculate time tendency terms. |
161 |
adcroft |
1.19 |
IF ( momStepping ) THEN |
162 |
heimbach |
1.12 |
CALL TIMER_START('DYNAMICS [THE_MAIN_LOOP]',mythid) |
163 |
|
|
CALL DYNAMICS( myTime, myIter, myThid ) |
164 |
|
|
CALL TIMER_STOP ('DYNAMICS [THE_MAIN_LOOP]',mythid) |
165 |
adcroft |
1.19 |
ENDIF |
166 |
heimbach |
1.12 |
|
167 |
adcroft |
1.1 |
#ifdef ALLOW_NONHYDROSTATIC |
168 |
|
|
C-- Step forward W field in N-H algorithm |
169 |
adcroft |
1.19 |
IF ( momStepping .AND. nonHydrostatic ) THEN |
170 |
heimbach |
1.12 |
CALL TIMER_START('CALC_GW [THE_MAIN_LOOP]',myThid) |
171 |
|
|
CALL CALC_GW(myThid) |
172 |
|
|
CALL TIMER_STOP ('CALC_GW [THE_MAIN_LOOP]',myThid) |
173 |
|
|
ENDIF |
174 |
adcroft |
1.1 |
#endif |
175 |
jmc |
1.18 |
|
176 |
|
|
#ifdef NONLIN_FRSURF |
177 |
jmc |
1.21 |
C-- update hfacC,W,S and recip_hFac according to etaH(n+1) : |
178 |
jmc |
1.18 |
IF ( nonlinFreeSurf.GT.0) THEN |
179 |
|
|
CALL UPDATE_SURF_DR( myTime, myIter, myThid ) |
180 |
|
|
ENDIF |
181 |
|
|
C- update also CG2D matrix (and preconditioner) |
182 |
jmc |
1.33 |
IF ( momStepping .AND. nonlinFreeSurf.GT.2 ) THEN |
183 |
jmc |
1.18 |
CALL UPDATE_CG2D( myTime, myIter, myThid ) |
184 |
adcroft |
1.19 |
ENDIF |
185 |
jmc |
1.18 |
#endif |
186 |
adcroft |
1.1 |
|
187 |
jmc |
1.27 |
C-- Apply Filters to u*,v* before SOLVE_FOR_PRESSURE |
188 |
|
|
#ifdef ALLOW_SHAP_FILT |
189 |
|
|
IF (useSHAP_FILT .AND. shap_filt_uvStar) THEN |
190 |
|
|
CALL TIMER_START('SHAP_FILT [THE_MAIN_LOOP]',myThid) |
191 |
|
|
CALL SHAP_FILT_APPLY_UV( gUnm1,gVnm1, myTime,myIter,myThid ) |
192 |
|
|
IF (implicDiv2Dflow.LT.1.) THEN |
193 |
|
|
C-- Explicit+Implicit part of the Barotropic Flow Divergence |
194 |
|
|
C => Filtering of uVel,vVel is necessary |
195 |
|
|
CALL SHAP_FILT_APPLY_UV( uVel,vVel, myTime,myIter,myThid ) |
196 |
|
|
ENDIF |
197 |
|
|
CALL TIMER_STOP ('SHAP_FILT [THE_MAIN_LOOP]',myThid) |
198 |
|
|
ENDIF |
199 |
|
|
#endif |
200 |
|
|
#ifdef ALLOW_ZONAL_FILT |
201 |
|
|
IF (useZONAL_FILT .AND. zonal_filt_uvStar) THEN |
202 |
|
|
CALL TIMER_START('ZONAL_FILT_APPLY [THE_MAIN_LOOP]',myThid) |
203 |
|
|
CALL ZONAL_FILT_APPLY_UV( gUnm1, gVnm1, myThid ) |
204 |
|
|
IF (implicDiv2Dflow.LT.1.) THEN |
205 |
|
|
C-- Explicit+Implicit part of the Barotropic Flow Divergence |
206 |
|
|
C => Filtering of uVel,vVel is necessary |
207 |
|
|
CALL ZONAL_FILT_APPLY_UV( uVel, vVel, myThid ) |
208 |
|
|
ENDIF |
209 |
|
|
CALL TIMER_STOP ('ZONAL_FILT_APPLY [THE_MAIN_LOOP]',myThid) |
210 |
|
|
ENDIF |
211 |
|
|
#endif |
212 |
heimbach |
1.12 |
|
213 |
adcroft |
1.1 |
C-- Solve elliptic equation(s). |
214 |
|
|
C Two-dimensional only for conventional hydrostatic or |
215 |
|
|
C three-dimensional for non-hydrostatic and/or IGW scheme. |
216 |
adcroft |
1.19 |
IF ( momStepping ) THEN |
217 |
heimbach |
1.12 |
CALL TIMER_START('SOLVE_FOR_PRESSURE [THE_MAIN_LOOP]',myThid) |
218 |
jmc |
1.31 |
CALL SOLVE_FOR_PRESSURE(myTime, myIter, myThid) |
219 |
heimbach |
1.12 |
CALL TIMER_STOP ('SOLVE_FOR_PRESSURE [THE_MAIN_LOOP]',myThid) |
220 |
adcroft |
1.19 |
ENDIF |
221 |
adcroft |
1.1 |
|
222 |
adcroft |
1.5 |
C-- Correct divergence in flow field and cycle time-stepping |
223 |
jmc |
1.7 |
C arrays (for all fields) ; update time-counter |
224 |
heimbach |
1.12 |
myIter = nIter0 + iLoop |
225 |
|
|
myTime = startTime + deltaTClock * float(iLoop) |
226 |
|
|
CALL TIMER_START('THE_CORRECTION_STEP [THE_MAIN_LOOP]',myThid) |
227 |
|
|
CALL THE_CORRECTION_STEP(myTime, myIter, myThid) |
228 |
|
|
CALL TIMER_STOP ('THE_CORRECTION_STEP [THE_MAIN_LOOP]',myThid) |
229 |
adcroft |
1.5 |
|
230 |
adcroft |
1.1 |
C-- Do "blocking" sends and receives for tendency "overlap" terms |
231 |
heimbach |
1.12 |
c CALL TIMER_START('BLOCKING_EXCHANGES [THE_MAIN_LOOP]',myThid) |
232 |
jmc |
1.7 |
c CALL DO_GTERM_BLOCKING_EXCHANGES( myThid ) |
233 |
heimbach |
1.12 |
c CALL TIMER_STOP ('BLOCKING_EXCHANGES [THE_MAIN_LOOP]',myThid) |
234 |
adcroft |
1.5 |
|
235 |
|
|
C-- Do "blocking" sends and receives for field "overlap" terms |
236 |
heimbach |
1.12 |
CALL TIMER_START('BLOCKING_EXCHANGES [THE_MAIN_LOOP]',myThid) |
237 |
adcroft |
1.5 |
CALL DO_FIELDS_BLOCKING_EXCHANGES( myThid ) |
238 |
heimbach |
1.12 |
CALL TIMER_STOP ('BLOCKING_EXCHANGES [THE_MAIN_LOOP]',myThid) |
239 |
adcroft |
1.20 |
|
240 |
|
|
#ifdef ALLOW_FLT |
241 |
|
|
C-- Calculate float trajectories |
242 |
|
|
IF (useFLT) THEN |
243 |
|
|
CALL TIMER_START('FLOATS [THE_MAIN_LOOP]',myThid) |
244 |
|
|
CALL FLT_MAIN(myIter,myTime, myThid) |
245 |
|
|
CALL TIMER_STOP ('FLOATS [THE_MAIN_LOOP]',myThid) |
246 |
|
|
ENDIF |
247 |
|
|
#endif |
248 |
heimbach |
1.12 |
|
249 |
|
|
#ifndef EXCLUDE_MONITOR |
250 |
|
|
C-- Check status of solution (statistics, cfl, etc...) |
251 |
|
|
CALL MONITOR( myIter, myTime, myThid ) |
252 |
|
|
#endif /* EXCLUDE_MONITOR */ |
253 |
adcroft |
1.1 |
|
254 |
heimbach |
1.16 |
#ifndef ALLOW_AUTODIFF_TAMC |
255 |
jmc |
1.7 |
C-- Do IO if needed. |
256 |
heimbach |
1.12 |
CALL TIMER_START('DO_THE_MODEL_IO [THE_MAIN_LOOP]',myThid) |
257 |
|
|
CALL DO_THE_MODEL_IO( myTime, myIter, myThid ) |
258 |
|
|
CALL TIMER_STOP ('DO_THE_MODEL_IO [THE_MAIN_LOOP]',myThid) |
259 |
adcroft |
1.1 |
|
260 |
|
|
C-- Save state for restarts |
261 |
jmc |
1.7 |
C Note: (jmc: is it still the case after ckp35 ?) |
262 |
adcroft |
1.1 |
C ===== |
263 |
|
|
C Because of the ordering of the timestepping code and |
264 |
|
|
C tendency term code at end of loop model arrays hold |
265 |
|
|
C U,V,T,S at "time-level" N but gu, gv, gs, gt, guNM1,... |
266 |
|
|
C at "time-level" N+1/2 (guNM1 at "time-level" N+1/2 is |
267 |
jmc |
1.10 |
C gu at "time-level" N-1/2) and etaN at "time-level" N+1/2. |
268 |
adcroft |
1.1 |
C where N = I+timeLevBase-1 |
269 |
|
|
C Thus a checkpoint contains U.0000000000, GU.0000000001 and |
270 |
jmc |
1.10 |
C etaN.0000000001 in the indexing scheme used for the model |
271 |
adcroft |
1.1 |
C "state" files. This example is referred to as a checkpoint |
272 |
|
|
C at time level 1 |
273 |
heimbach |
1.12 |
CALL TIMER_START('WRITE_CHECKPOINT [THE_MAIN_LOOP]',myThid) |
274 |
adcroft |
1.1 |
CALL WRITE_CHECKPOINT( |
275 |
heimbach |
1.12 |
& .FALSE., myTime, myIter, myThid ) |
276 |
|
|
CALL TIMER_STOP ('WRITE_CHECKPOINT [THE_MAIN_LOOP]',myThid) |
277 |
|
|
|
278 |
|
|
#endif /* ALLOW_AUTODIFF_TAMC */ |
279 |
adcroft |
1.1 |
|
280 |
|
|
END |