1 |
C $Header: /u/gcmpack/models/MITgcmUV/model/src/forward_step.F,v 1.16 2001/08/13 23:28:40 heimbach Exp $ |
2 |
C $Name: $ |
3 |
|
4 |
#include "CPP_OPTIONS.h" |
5 |
|
6 |
SUBROUTINE FORWARD_STEP( iloop, myTime, myIter, myThid ) |
7 |
IMPLICIT NONE |
8 |
|
9 |
c ================================================================== |
10 |
c SUBROUTINE forward_step |
11 |
c ================================================================== |
12 |
c |
13 |
c o Run the ocean model and evaluate the specified cost function. |
14 |
c |
15 |
c *the_main_loop* is the toplevel routine for the Tangent Linear and |
16 |
c Adjoint Model Compiler (TAMC). For this purpose the initialization |
17 |
c of the model was split into two parts. Those parameters that do |
18 |
c not depend on a specific model run are set in *initialise_fixed*, |
19 |
c whereas those that do depend on the specific realization are |
20 |
c initialized in *initialise_varia*. |
21 |
|
22 |
C == global variables == |
23 |
#include "SIZE.h" |
24 |
#include "EEPARAMS.h" |
25 |
#include "PARAMS.h" |
26 |
#include "DYNVARS.h" |
27 |
#include "FFIELDS.h" |
28 |
|
29 |
#ifdef ALLOW_NONHYDROSTATIC |
30 |
#include "CG3D.h" |
31 |
#endif |
32 |
|
33 |
#ifdef ALLOW_AUTODIFF_TAMC |
34 |
#include "tamc.h" |
35 |
#include "ctrl.h" |
36 |
#include "ctrl_dummy.h" |
37 |
#include "cost.h" |
38 |
#endif |
39 |
|
40 |
C == routine arguments == |
41 |
C note: under the multi-threaded model myiter and |
42 |
C mytime are local variables passed around as routine |
43 |
C arguments. Although this is fiddly it saves the need to |
44 |
C impose additional synchronisation points when they are |
45 |
C updated. |
46 |
C myiter - iteration counter for this thread |
47 |
C mytime - time counter for this thread |
48 |
C mythid - thread number for this instance of the routine. |
49 |
integer iloop |
50 |
integer mythid |
51 |
integer myiter |
52 |
_RL mytime |
53 |
|
54 |
C == local variables == |
55 |
|
56 |
|
57 |
#ifdef ALLOW_AUTODIFF_TAMC |
58 |
C-- Reset the model iteration counter and the model time. |
59 |
myiter = nIter0 + (iloop-1) |
60 |
mytime = startTime + float(iloop-1)*deltaTclock |
61 |
#endif |
62 |
|
63 |
#ifdef ALLOW_AUTODIFF_TAMC |
64 |
C Include call to a dummy routine. Its adjoint will be |
65 |
C called at the proper place in the adjoint code. |
66 |
C The adjoint routine will print out adjoint values |
67 |
C if requested. The location of the call is important, |
68 |
C it has to be after the adjoint of the exchanges |
69 |
C (DO_GTERM_BLOCKING_EXCHANGES). |
70 |
CALL DUMMY_IN_STEPPING( myTime, myIter, myThid ) |
71 |
#endif |
72 |
|
73 |
C-- Load forcing/external data fields. |
74 |
#ifdef INCLUDE_EXTERNAL_FORCING_PACKAGE |
75 |
C NOTE, that although the exf package is part of the |
76 |
C distribution, it is not currently maintained, i.e. |
77 |
C exf is disabled by default in genmake. |
78 |
CALL EXF_GETFORCING( mytime, myiter, mythid ) |
79 |
#else |
80 |
CALL TIMER_START('EXTERNAL_FIELDS_LOAD[THE_MAIN_LOOP]',mythid) |
81 |
CALL EXTERNAL_FIELDS_LOAD( mytime, myiter, mythid ) |
82 |
CALL TIMER_STOP ('EXTERNAL_FIELDS_LOAD[THE_MAIN_LOOP]',mythid) |
83 |
#endif |
84 |
|
85 |
C-- Step forward fields and calculate time tendency terms. |
86 |
CALL TIMER_START('THERMODYNAMICS [THE_MAIN_LOOP]',mythid) |
87 |
CALL THERMODYNAMICS( myTime, myIter, myThid ) |
88 |
CALL TIMER_STOP ('THERMODYNAMICS [THE_MAIN_LOOP]',mythid) |
89 |
|
90 |
C-- Step forward fields and calculate time tendency terms. |
91 |
CALL TIMER_START('DYNAMICS [THE_MAIN_LOOP]',mythid) |
92 |
CALL DYNAMICS( myTime, myIter, myThid ) |
93 |
CALL TIMER_STOP ('DYNAMICS [THE_MAIN_LOOP]',mythid) |
94 |
|
95 |
#ifndef ALLOW_AUTODIFF_TAMC |
96 |
#ifdef ALLOW_NONHYDROSTATIC |
97 |
C-- Step forward W field in N-H algorithm |
98 |
IF ( nonHydrostatic ) THEN |
99 |
CALL TIMER_START('CALC_GW [THE_MAIN_LOOP]',myThid) |
100 |
CALL CALC_GW(myThid) |
101 |
CALL TIMER_STOP ('CALC_GW [THE_MAIN_LOOP]',myThid) |
102 |
ENDIF |
103 |
#endif |
104 |
#endif /* ALLOW_AUTODIFF_TAMC */ |
105 |
|
106 |
C-- This block has been moved to the_correction_step(). We have |
107 |
C left this code here to indicate where the filters used to be |
108 |
C in the algorithm before JMC moved them to after the pressure |
109 |
C solver. |
110 |
C |
111 |
C#ifdef ALLOW_SHAP_FILT |
112 |
CC-- Step forward all tiles, filter and exchange. |
113 |
C CALL TIMER_START('SHAP_FILT [THE_MAIN_LOOP]',myThid) |
114 |
C CALL SHAP_FILT_APPLY( |
115 |
C I gUnm1, gVnm1, gTnm1, gSnm1, |
116 |
C I myTime, myIter, myThid ) |
117 |
C IF (implicDiv2Dflow.LT.1.) THEN |
118 |
CC-- Explicit+Implicit part of the Barotropic Flow Divergence |
119 |
CC => Filtering of uVel,vVel is necessary |
120 |
C CALL SHAP_FILT_UV( uVel, vVel, myTime, myThid ) |
121 |
C ENDIF |
122 |
C CALL TIMER_STOP ('SHAP_FILT [THE_MAIN_LOOP]',myThid) |
123 |
C#endif |
124 |
C |
125 |
C#ifdef ALLOW_ZONAL_FILT |
126 |
C IF (zonal_filt_lat.LT.90.) THEN |
127 |
C CALL TIMER_START('ZONAL_FILT_APPLY [THE_MAIN_LOOP]',myThid) |
128 |
C CALL ZONAL_FILT_APPLY( |
129 |
C U gUnm1, gVnm1, gTnm1, gSnm1, |
130 |
C I myThid ) |
131 |
C CALL TIMER_STOP ('ZONAL_FILT_APPLY [THE_MAIN_LOOP]',myThid) |
132 |
C ENDIF |
133 |
C#endif |
134 |
|
135 |
C-- Solve elliptic equation(s). |
136 |
C Two-dimensional only for conventional hydrostatic or |
137 |
C three-dimensional for non-hydrostatic and/or IGW scheme. |
138 |
CALL TIMER_START('SOLVE_FOR_PRESSURE [THE_MAIN_LOOP]',myThid) |
139 |
CALL SOLVE_FOR_PRESSURE( myThid ) |
140 |
CALL TIMER_STOP ('SOLVE_FOR_PRESSURE [THE_MAIN_LOOP]',myThid) |
141 |
|
142 |
C-- Correct divergence in flow field and cycle time-stepping |
143 |
C arrays (for all fields) ; update time-counter |
144 |
myIter = nIter0 + iLoop |
145 |
myTime = startTime + deltaTClock * float(iLoop) |
146 |
CALL TIMER_START('THE_CORRECTION_STEP [THE_MAIN_LOOP]',myThid) |
147 |
CALL THE_CORRECTION_STEP(myTime, myIter, myThid) |
148 |
CALL TIMER_STOP ('THE_CORRECTION_STEP [THE_MAIN_LOOP]',myThid) |
149 |
|
150 |
C-- Do "blocking" sends and receives for tendency "overlap" terms |
151 |
c CALL TIMER_START('BLOCKING_EXCHANGES [THE_MAIN_LOOP]',myThid) |
152 |
c CALL DO_GTERM_BLOCKING_EXCHANGES( myThid ) |
153 |
c CALL TIMER_STOP ('BLOCKING_EXCHANGES [THE_MAIN_LOOP]',myThid) |
154 |
|
155 |
C-- Do "blocking" sends and receives for field "overlap" terms |
156 |
CALL TIMER_START('BLOCKING_EXCHANGES [THE_MAIN_LOOP]',myThid) |
157 |
CALL DO_FIELDS_BLOCKING_EXCHANGES( myThid ) |
158 |
CALL TIMER_STOP ('BLOCKING_EXCHANGES [THE_MAIN_LOOP]',myThid) |
159 |
|
160 |
#ifndef EXCLUDE_MONITOR |
161 |
C-- Check status of solution (statistics, cfl, etc...) |
162 |
CALL MONITOR( myIter, myTime, myThid ) |
163 |
#endif /* EXCLUDE_MONITOR */ |
164 |
|
165 |
#ifndef ALLOW_AUTODIFF_TAMC |
166 |
C-- Do IO if needed. |
167 |
CALL TIMER_START('DO_THE_MODEL_IO [THE_MAIN_LOOP]',myThid) |
168 |
CALL DO_THE_MODEL_IO( myTime, myIter, myThid ) |
169 |
CALL TIMER_STOP ('DO_THE_MODEL_IO [THE_MAIN_LOOP]',myThid) |
170 |
|
171 |
C-- Save state for restarts |
172 |
C Note: (jmc: is it still the case after ckp35 ?) |
173 |
C ===== |
174 |
C Because of the ordering of the timestepping code and |
175 |
C tendency term code at end of loop model arrays hold |
176 |
C U,V,T,S at "time-level" N but gu, gv, gs, gt, guNM1,... |
177 |
C at "time-level" N+1/2 (guNM1 at "time-level" N+1/2 is |
178 |
C gu at "time-level" N-1/2) and etaN at "time-level" N+1/2. |
179 |
C where N = I+timeLevBase-1 |
180 |
C Thus a checkpoint contains U.0000000000, GU.0000000001 and |
181 |
C etaN.0000000001 in the indexing scheme used for the model |
182 |
C "state" files. This example is referred to as a checkpoint |
183 |
C at time level 1 |
184 |
CALL TIMER_START('WRITE_CHECKPOINT [THE_MAIN_LOOP]',myThid) |
185 |
CALL WRITE_CHECKPOINT( |
186 |
& .FALSE., myTime, myIter, myThid ) |
187 |
CALL TIMER_STOP ('WRITE_CHECKPOINT [THE_MAIN_LOOP]',myThid) |
188 |
|
189 |
#endif /* ALLOW_AUTODIFF_TAMC */ |
190 |
|
191 |
END |