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