1 |
cnh |
1.22 |
C $Header: /u/gcmpack/models/MITgcmUV/model/src/forward_step.F,v 1.21 2001/09/19 13:58:08 jmc 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 |
heimbach |
1.12 |
#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 |
cnh |
1.22 |
C !LOCAL VARIABLES: |
48 |
|
|
C == Routine arguments == |
49 |
adcroft |
1.13 |
C note: under the multi-threaded model myiter and |
50 |
|
|
C mytime are local variables passed around as routine |
51 |
|
|
C arguments. Although this is fiddly it saves the need to |
52 |
|
|
C impose additional synchronisation points when they are |
53 |
|
|
C updated. |
54 |
|
|
C myiter - iteration counter for this thread |
55 |
|
|
C mytime - time counter for this thread |
56 |
|
|
C mythid - thread number for this instance of the routine. |
57 |
heimbach |
1.12 |
integer iloop |
58 |
|
|
integer mythid |
59 |
|
|
integer myiter |
60 |
|
|
_RL mytime |
61 |
jmc |
1.21 |
INTEGER bi,bj |
62 |
heimbach |
1.12 |
|
63 |
cnh |
1.22 |
CEOP |
64 |
heimbach |
1.12 |
|
65 |
|
|
|
66 |
|
|
#ifdef ALLOW_AUTODIFF_TAMC |
67 |
heimbach |
1.14 |
C-- Reset the model iteration counter and the model time. |
68 |
heimbach |
1.12 |
myiter = nIter0 + (iloop-1) |
69 |
|
|
mytime = startTime + float(iloop-1)*deltaTclock |
70 |
|
|
#endif |
71 |
|
|
|
72 |
heimbach |
1.16 |
#ifdef ALLOW_AUTODIFF_TAMC |
73 |
|
|
C Include call to a dummy routine. Its adjoint will be |
74 |
|
|
C called at the proper place in the adjoint code. |
75 |
|
|
C The adjoint routine will print out adjoint values |
76 |
|
|
C if requested. The location of the call is important, |
77 |
|
|
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 |
jmc |
1.21 |
#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 |
94 |
|
|
#endif /* EXACT_CONSERV */ |
95 |
|
|
|
96 |
jmc |
1.18 |
#ifdef NONLIN_FRSURF |
97 |
|
|
C-- compute the future surface level thickness |
98 |
jmc |
1.21 |
C according to etaH(n+1) |
99 |
jmc |
1.18 |
IF ( nonlinFreeSurf.GT.0) THEN |
100 |
jmc |
1.21 |
CALL CALC_SURF_DR(etaH, myTime, myIter, myThid ) |
101 |
jmc |
1.18 |
ENDIF |
102 |
jmc |
1.21 |
#endif /* NONLIN_FRSURF */ |
103 |
jmc |
1.18 |
|
104 |
adcroft |
1.13 |
C-- Load forcing/external data fields. |
105 |
heimbach |
1.12 |
#ifdef INCLUDE_EXTERNAL_FORCING_PACKAGE |
106 |
adcroft |
1.13 |
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 |
heimbach |
1.12 |
CALL EXF_GETFORCING( mytime, myiter, mythid ) |
110 |
|
|
#else |
111 |
|
|
CALL TIMER_START('EXTERNAL_FIELDS_LOAD[THE_MAIN_LOOP]',mythid) |
112 |
|
|
CALL EXTERNAL_FIELDS_LOAD( mytime, myiter, mythid ) |
113 |
|
|
CALL TIMER_STOP ('EXTERNAL_FIELDS_LOAD[THE_MAIN_LOOP]',mythid) |
114 |
|
|
#endif |
115 |
adcroft |
1.15 |
|
116 |
|
|
C-- Step forward fields and calculate time tendency terms. |
117 |
|
|
CALL TIMER_START('THERMODYNAMICS [THE_MAIN_LOOP]',mythid) |
118 |
|
|
CALL THERMODYNAMICS( myTime, myIter, myThid ) |
119 |
|
|
CALL TIMER_STOP ('THERMODYNAMICS [THE_MAIN_LOOP]',mythid) |
120 |
heimbach |
1.12 |
|
121 |
adcroft |
1.13 |
C-- Step forward fields and calculate time tendency terms. |
122 |
adcroft |
1.19 |
IF ( momStepping ) THEN |
123 |
heimbach |
1.12 |
CALL TIMER_START('DYNAMICS [THE_MAIN_LOOP]',mythid) |
124 |
|
|
CALL DYNAMICS( myTime, myIter, myThid ) |
125 |
|
|
CALL TIMER_STOP ('DYNAMICS [THE_MAIN_LOOP]',mythid) |
126 |
adcroft |
1.19 |
ENDIF |
127 |
heimbach |
1.12 |
|
128 |
|
|
#ifndef ALLOW_AUTODIFF_TAMC |
129 |
adcroft |
1.1 |
#ifdef ALLOW_NONHYDROSTATIC |
130 |
|
|
C-- Step forward W field in N-H algorithm |
131 |
adcroft |
1.19 |
IF ( momStepping .AND. nonHydrostatic ) THEN |
132 |
heimbach |
1.12 |
CALL TIMER_START('CALC_GW [THE_MAIN_LOOP]',myThid) |
133 |
|
|
CALL CALC_GW(myThid) |
134 |
|
|
CALL TIMER_STOP ('CALC_GW [THE_MAIN_LOOP]',myThid) |
135 |
|
|
ENDIF |
136 |
adcroft |
1.1 |
#endif |
137 |
adcroft |
1.13 |
#endif /* ALLOW_AUTODIFF_TAMC */ |
138 |
jmc |
1.18 |
|
139 |
|
|
#ifdef NONLIN_FRSURF |
140 |
jmc |
1.21 |
C-- update hfacC,W,S and recip_hFac according to etaH(n+1) : |
141 |
adcroft |
1.19 |
IF ( momStepping ) THEN |
142 |
jmc |
1.18 |
IF ( nonlinFreeSurf.GT.0) THEN |
143 |
|
|
CALL UPDATE_SURF_DR( myTime, myIter, myThid ) |
144 |
|
|
ENDIF |
145 |
|
|
C- update also CG2D matrix (and preconditioner) |
146 |
|
|
IF ( nonlinFreeSurf.GT.2) THEN |
147 |
|
|
CALL UPDATE_CG2D( myTime, myIter, myThid ) |
148 |
|
|
ENDIF |
149 |
adcroft |
1.19 |
ENDIF |
150 |
jmc |
1.18 |
#endif |
151 |
adcroft |
1.1 |
|
152 |
adcroft |
1.13 |
C-- This block has been moved to the_correction_step(). We have |
153 |
|
|
C left this code here to indicate where the filters used to be |
154 |
|
|
C in the algorithm before JMC moved them to after the pressure |
155 |
|
|
C solver. |
156 |
|
|
C |
157 |
|
|
C#ifdef ALLOW_SHAP_FILT |
158 |
|
|
CC-- Step forward all tiles, filter and exchange. |
159 |
|
|
C CALL TIMER_START('SHAP_FILT [THE_MAIN_LOOP]',myThid) |
160 |
|
|
C CALL SHAP_FILT_APPLY( |
161 |
|
|
C I gUnm1, gVnm1, gTnm1, gSnm1, |
162 |
|
|
C I myTime, myIter, myThid ) |
163 |
|
|
C IF (implicDiv2Dflow.LT.1.) THEN |
164 |
|
|
CC-- Explicit+Implicit part of the Barotropic Flow Divergence |
165 |
|
|
CC => Filtering of uVel,vVel is necessary |
166 |
|
|
C CALL SHAP_FILT_UV( uVel, vVel, myTime, myThid ) |
167 |
|
|
C ENDIF |
168 |
|
|
C CALL TIMER_STOP ('SHAP_FILT [THE_MAIN_LOOP]',myThid) |
169 |
|
|
C#endif |
170 |
|
|
C |
171 |
|
|
C#ifdef ALLOW_ZONAL_FILT |
172 |
|
|
C IF (zonal_filt_lat.LT.90.) THEN |
173 |
|
|
C CALL TIMER_START('ZONAL_FILT_APPLY [THE_MAIN_LOOP]',myThid) |
174 |
|
|
C CALL ZONAL_FILT_APPLY( |
175 |
|
|
C U gUnm1, gVnm1, gTnm1, gSnm1, |
176 |
|
|
C I myThid ) |
177 |
|
|
C CALL TIMER_STOP ('ZONAL_FILT_APPLY [THE_MAIN_LOOP]',myThid) |
178 |
|
|
C ENDIF |
179 |
|
|
C#endif |
180 |
heimbach |
1.12 |
|
181 |
adcroft |
1.1 |
C-- Solve elliptic equation(s). |
182 |
|
|
C Two-dimensional only for conventional hydrostatic or |
183 |
|
|
C three-dimensional for non-hydrostatic and/or IGW scheme. |
184 |
adcroft |
1.19 |
IF ( momStepping ) THEN |
185 |
heimbach |
1.12 |
CALL TIMER_START('SOLVE_FOR_PRESSURE [THE_MAIN_LOOP]',myThid) |
186 |
adcroft |
1.1 |
CALL SOLVE_FOR_PRESSURE( myThid ) |
187 |
heimbach |
1.12 |
CALL TIMER_STOP ('SOLVE_FOR_PRESSURE [THE_MAIN_LOOP]',myThid) |
188 |
adcroft |
1.19 |
ENDIF |
189 |
adcroft |
1.1 |
|
190 |
adcroft |
1.5 |
C-- Correct divergence in flow field and cycle time-stepping |
191 |
jmc |
1.7 |
C arrays (for all fields) ; update time-counter |
192 |
heimbach |
1.12 |
myIter = nIter0 + iLoop |
193 |
|
|
myTime = startTime + deltaTClock * float(iLoop) |
194 |
|
|
CALL TIMER_START('THE_CORRECTION_STEP [THE_MAIN_LOOP]',myThid) |
195 |
|
|
CALL THE_CORRECTION_STEP(myTime, myIter, myThid) |
196 |
|
|
CALL TIMER_STOP ('THE_CORRECTION_STEP [THE_MAIN_LOOP]',myThid) |
197 |
adcroft |
1.5 |
|
198 |
adcroft |
1.1 |
C-- Do "blocking" sends and receives for tendency "overlap" terms |
199 |
heimbach |
1.12 |
c CALL TIMER_START('BLOCKING_EXCHANGES [THE_MAIN_LOOP]',myThid) |
200 |
jmc |
1.7 |
c CALL DO_GTERM_BLOCKING_EXCHANGES( myThid ) |
201 |
heimbach |
1.12 |
c CALL TIMER_STOP ('BLOCKING_EXCHANGES [THE_MAIN_LOOP]',myThid) |
202 |
adcroft |
1.5 |
|
203 |
|
|
C-- Do "blocking" sends and receives for field "overlap" terms |
204 |
heimbach |
1.12 |
CALL TIMER_START('BLOCKING_EXCHANGES [THE_MAIN_LOOP]',myThid) |
205 |
adcroft |
1.5 |
CALL DO_FIELDS_BLOCKING_EXCHANGES( myThid ) |
206 |
heimbach |
1.12 |
CALL TIMER_STOP ('BLOCKING_EXCHANGES [THE_MAIN_LOOP]',myThid) |
207 |
adcroft |
1.20 |
|
208 |
|
|
#ifdef ALLOW_FLT |
209 |
|
|
C-- Calculate float trajectories |
210 |
|
|
IF (useFLT) THEN |
211 |
|
|
CALL TIMER_START('FLOATS [THE_MAIN_LOOP]',myThid) |
212 |
|
|
CALL FLT_MAIN(myIter,myTime, myThid) |
213 |
|
|
CALL TIMER_STOP ('FLOATS [THE_MAIN_LOOP]',myThid) |
214 |
|
|
ENDIF |
215 |
|
|
#endif |
216 |
heimbach |
1.12 |
|
217 |
|
|
#ifndef EXCLUDE_MONITOR |
218 |
|
|
C-- Check status of solution (statistics, cfl, etc...) |
219 |
|
|
CALL MONITOR( myIter, myTime, myThid ) |
220 |
|
|
#endif /* EXCLUDE_MONITOR */ |
221 |
adcroft |
1.1 |
|
222 |
heimbach |
1.16 |
#ifndef ALLOW_AUTODIFF_TAMC |
223 |
jmc |
1.7 |
C-- Do IO if needed. |
224 |
heimbach |
1.12 |
CALL TIMER_START('DO_THE_MODEL_IO [THE_MAIN_LOOP]',myThid) |
225 |
|
|
CALL DO_THE_MODEL_IO( myTime, myIter, myThid ) |
226 |
|
|
CALL TIMER_STOP ('DO_THE_MODEL_IO [THE_MAIN_LOOP]',myThid) |
227 |
adcroft |
1.1 |
|
228 |
|
|
C-- Save state for restarts |
229 |
jmc |
1.7 |
C Note: (jmc: is it still the case after ckp35 ?) |
230 |
adcroft |
1.1 |
C ===== |
231 |
|
|
C Because of the ordering of the timestepping code and |
232 |
|
|
C tendency term code at end of loop model arrays hold |
233 |
|
|
C U,V,T,S at "time-level" N but gu, gv, gs, gt, guNM1,... |
234 |
|
|
C at "time-level" N+1/2 (guNM1 at "time-level" N+1/2 is |
235 |
jmc |
1.10 |
C gu at "time-level" N-1/2) and etaN at "time-level" N+1/2. |
236 |
adcroft |
1.1 |
C where N = I+timeLevBase-1 |
237 |
|
|
C Thus a checkpoint contains U.0000000000, GU.0000000001 and |
238 |
jmc |
1.10 |
C etaN.0000000001 in the indexing scheme used for the model |
239 |
adcroft |
1.1 |
C "state" files. This example is referred to as a checkpoint |
240 |
|
|
C at time level 1 |
241 |
heimbach |
1.12 |
CALL TIMER_START('WRITE_CHECKPOINT [THE_MAIN_LOOP]',myThid) |
242 |
adcroft |
1.1 |
CALL WRITE_CHECKPOINT( |
243 |
heimbach |
1.12 |
& .FALSE., myTime, myIter, myThid ) |
244 |
|
|
CALL TIMER_STOP ('WRITE_CHECKPOINT [THE_MAIN_LOOP]',myThid) |
245 |
|
|
|
246 |
|
|
#endif /* ALLOW_AUTODIFF_TAMC */ |
247 |
adcroft |
1.1 |
|
248 |
|
|
END |