1 |
cnh |
1.2 |
C $Header: /u/u0/gcmpack/MITgcm_contrib/CS_ADJOINT_TESTS/diffuse/code/the_main_loop.F,v 1.1 2004/07/07 03:12:36 cnh Exp $ |
2 |
cnh |
1.1 |
C $Name: $ |
3 |
|
|
|
4 |
|
|
#include "PACKAGES_CONFIG.h" |
5 |
|
|
#include "CPP_OPTIONS.h" |
6 |
|
|
#ifdef ALLOW_PTRACERS |
7 |
|
|
# include "PTRACERS_OPTIONS.h" |
8 |
|
|
#endif |
9 |
|
|
#ifdef ALLOW_OBCS |
10 |
|
|
# include "OBCS_OPTIONS.h" |
11 |
|
|
#endif |
12 |
|
|
|
13 |
|
|
CBOP |
14 |
|
|
C !ROUTINE: THE_MAIN_LOOP |
15 |
|
|
C !INTERFACE: |
16 |
|
|
SUBROUTINE THE_MAIN_LOOP( myTime, myIter, myThid ) |
17 |
|
|
|
18 |
|
|
C !DESCRIPTION: \bv |
19 |
|
|
C *================================================================* |
20 |
|
|
C | SUBROUTINE the_main_loop |
21 |
|
|
C | o Run the ocean model and evaluate the specified cost function. |
22 |
|
|
C *================================================================* |
23 |
|
|
C | |
24 |
|
|
C | THE_MAIN_LOOP is the toplevel routine for the Tangent Linear and |
25 |
|
|
C | Adjoint Model Compiler (TAMC). For this purpose the initialization |
26 |
|
|
C | of the model was split into two parts. Those parameters that do |
27 |
|
|
C | not depend on a specific model run are set in INITIALISE_FIXED, |
28 |
|
|
C | whereas those that do depend on the specific realization are |
29 |
|
|
C | initialized in INITIALISE_VARIA. |
30 |
|
|
C | This routine is to be used in conjuction with the MITgcmuv |
31 |
|
|
C | checkpoint 37. |
32 |
|
|
C *================================================================* |
33 |
|
|
C \ev |
34 |
|
|
|
35 |
|
|
C !USES: |
36 |
|
|
IMPLICIT NONE |
37 |
|
|
C == Global variables == |
38 |
|
|
#include "SIZE.h" |
39 |
|
|
#include "EEPARAMS.h" |
40 |
|
|
#include "PARAMS.h" |
41 |
|
|
#include "DYNVARS.h" |
42 |
|
|
#include "GRID.h" |
43 |
|
|
|
44 |
|
|
c************************************** |
45 |
|
|
#ifdef ALLOW_AUTODIFF_TAMC |
46 |
|
|
|
47 |
|
|
c These includes are needed for |
48 |
|
|
c AD-checkpointing. |
49 |
|
|
c They provide the fields to be stored. |
50 |
|
|
|
51 |
|
|
# include "GRID.h" |
52 |
|
|
# include "DYNVARS.h" |
53 |
|
|
# include "FFIELDS.h" |
54 |
|
|
# include "EOS.h" |
55 |
|
|
# ifdef ALLOW_GENERIC_ADVDIFF |
56 |
|
|
# include "GAD.h" |
57 |
|
|
# endif |
58 |
|
|
# ifdef ALLOW_CD_CODE |
59 |
|
|
# include "CD_CODE_VARS.h" |
60 |
|
|
# endif |
61 |
|
|
# ifdef ALLOW_PASSIVE_TRACER |
62 |
|
|
# include "TR1.h" |
63 |
|
|
# endif |
64 |
|
|
# ifdef ALLOW_PTRACERS |
65 |
|
|
# include "PTRACERS.h" |
66 |
|
|
# endif |
67 |
|
|
# ifdef ALLOW_NONHYDROSTATIC |
68 |
|
|
# include "CG3D.h" |
69 |
|
|
# endif |
70 |
|
|
# ifdef EXACT_CONSERV |
71 |
|
|
# include "SURFACE.h" |
72 |
|
|
# endif |
73 |
|
|
# ifdef ALLOW_OBCS |
74 |
|
|
# include "OBCS.h" |
75 |
|
|
# endif |
76 |
|
|
# ifdef ALLOW_EXF |
77 |
|
|
# include "exf_fields.h" |
78 |
|
|
# include "exf_clim_fields.h" |
79 |
|
|
# ifdef ALLOW_BULKFORMULAE |
80 |
|
|
# include "exf_constants.h" |
81 |
|
|
# endif |
82 |
|
|
# endif /* ALLOW_EXF */ |
83 |
|
|
# ifdef ALLOW_SEAICE |
84 |
|
|
# include "SEAICE.h" |
85 |
|
|
# endif |
86 |
|
|
# ifdef ALLOW_EBM |
87 |
|
|
# include "EBM.h" |
88 |
|
|
# endif |
89 |
|
|
# ifdef ALLOW_DIVIDED_ADJOINT_MPI |
90 |
|
|
# include "mpif.h" |
91 |
|
|
# endif |
92 |
|
|
|
93 |
|
|
# include "tamc.h" |
94 |
|
|
# include "ctrl.h" |
95 |
|
|
# include "ctrl_dummy.h" |
96 |
|
|
# include "cost.h" |
97 |
|
|
|
98 |
|
|
#endif /* ALLOW_AUTODIFF_TAMC */ |
99 |
|
|
c************************************** |
100 |
|
|
|
101 |
|
|
C !INPUT/OUTPUT PARAMETERS: |
102 |
|
|
C == Routine arguments == |
103 |
|
|
C note: under the multi-threaded model myiter and |
104 |
|
|
C mytime are local variables passed around as routine |
105 |
|
|
C arguments. Although this is fiddly it saves the need to |
106 |
|
|
C impose additional synchronisation points when they are |
107 |
|
|
C updated. |
108 |
|
|
C myIter - iteration counter for this thread |
109 |
|
|
C myTime - time counter for this thread |
110 |
|
|
C myThid - thread number for this instance of the routine. |
111 |
|
|
INTEGER myThid |
112 |
|
|
INTEGER myIter |
113 |
|
|
_RL myTime |
114 |
|
|
|
115 |
|
|
C !LOCAL VARIABLES: |
116 |
|
|
C == Local variables == |
117 |
|
|
integer iloop |
118 |
|
|
INTEGER I,J,K,bi,bj |
119 |
|
|
#ifdef ALLOW_TAMC_CHECKPOINTING |
120 |
|
|
integer ilev_1 |
121 |
|
|
integer ilev_2 |
122 |
|
|
integer ilev_3 |
123 |
|
|
integer max_lev2 |
124 |
|
|
integer max_lev3 |
125 |
|
|
#endif |
126 |
|
|
CEOP |
127 |
|
|
|
128 |
|
|
#ifdef ALLOW_DEBUG |
129 |
|
|
IF (debugMode) CALL DEBUG_ENTER('THE_MAIN_LOOP',myThid) |
130 |
|
|
#endif |
131 |
|
|
|
132 |
|
|
#ifdef ALLOW_AUTODIFF_TAMC |
133 |
|
|
c-- Initialize storage for the cost function evaluation. |
134 |
|
|
CADJ INIT dummytape = common, 1 |
135 |
|
|
c-- Initialize storage for the outermost loop. |
136 |
|
|
CADJ INIT tapelev3 = USER |
137 |
|
|
CADJ INIT tapelev_ini_bibj_k = USER |
138 |
|
|
#ifdef ALLOW_TAMC_CHECKPOINTING |
139 |
|
|
nIter0 = INT( startTime/deltaTClock ) |
140 |
|
|
ikey_dynamics = 1 |
141 |
|
|
#endif |
142 |
|
|
CALL TIMER_START('ADJOINT SPIN-UP', mythid) |
143 |
|
|
#endif |
144 |
|
|
|
145 |
|
|
#ifdef ALLOW_DEBUG |
146 |
|
|
IF (debugMode) CALL DEBUG_CALL('INITIALISE_VARIA',myThid) |
147 |
|
|
#endif |
148 |
|
|
|
149 |
|
|
C-- Set initial conditions (variable arrays) |
150 |
|
|
CALL TIMER_START('INITIALISE_VARIA [THE_MAIN_LOOP]', mythid) |
151 |
|
|
CALL INITIALISE_VARIA( mythid ) |
152 |
|
|
CALL TIMER_STOP ('INITIALISE_VARIA [THE_MAIN_LOOP]', mythid) |
153 |
|
|
|
154 |
|
|
#ifdef ALLOW_MONITOR |
155 |
|
|
#ifdef ALLOW_DEBUG |
156 |
|
|
IF (debugMode) CALL DEBUG_CALL('MONITOR',myThid) |
157 |
|
|
#endif |
158 |
|
|
C-- Check status of solution (statistics, cfl, etc...) |
159 |
|
|
CALL TIMER_START('MONITOR [THE_MAIN_LOOP]', mythid) |
160 |
|
|
CALL MONITOR( myIter, myTime, myThid ) |
161 |
|
|
CALL TIMER_STOP ('MONITOR [THE_MAIN_LOOP]', mythid) |
162 |
|
|
#endif /* ALLOW_MONITOR */ |
163 |
|
|
|
164 |
|
|
C-- Do IO if needed (Dump for start state). |
165 |
|
|
#ifdef ALLOW_DEBUG |
166 |
|
|
IF (debugMode) CALL DEBUG_CALL('DO_THE_MODEL_IO',myThid) |
167 |
|
|
#endif |
168 |
|
|
CALL TIMER_START('DO_THE_MODEL_IO [THE_MAIN_LOOP]', mythid) |
169 |
|
|
CALL DO_THE_MODEL_IO( myTime, myIter, mythid ) |
170 |
|
|
CALL TIMER_STOP ('DO_THE_MODEL_IO [THE_MAIN_LOOP]', mythid) |
171 |
|
|
|
172 |
|
|
#ifdef ALLOW_AUTODIFF_TAMC |
173 |
|
|
CALL TIMER_STOP ('ADJOINT SPIN-UP', mythid) |
174 |
|
|
_BARRIER |
175 |
|
|
#endif |
176 |
|
|
|
177 |
|
|
C CALL CTRL_MAP_INI(mythid) |
178 |
|
|
|
179 |
|
|
DO bj=myByLo(myThid),myByHi(myThid) |
180 |
|
|
DO bi=myBxLo(myThid),myBxHi(myThid) |
181 |
|
|
DO K=1,Nr |
182 |
|
|
DO J=1-OLy,sNy+OLy |
183 |
|
|
DO I=1-OLx,sNx+OLx |
184 |
cnh |
1.2 |
theta(i,j,k,bi,bj) = 1.*maskC(i,j,k,bi,bj) |
185 |
cnh |
1.1 |
gT (i,j,k,bi,bj) = 0. |
186 |
|
|
gTNM1(i,j,k,bi,bj) = 0. |
187 |
|
|
ENDDO |
188 |
|
|
ENDDO |
189 |
|
|
ENDDO |
190 |
|
|
ENDDO |
191 |
|
|
ENDDO |
192 |
cnh |
1.2 |
C theta(7,17,1,2,1) = 0. |
193 |
cnh |
1.1 |
|
194 |
|
|
DO iLoop=1,10000 |
195 |
cnh |
1.2 |
C CALL DIFFUSE_THETA(myTime, myIter, myThid) |
196 |
|
|
CALL ADVECT_AND_DIFFUSE_THETA(myTime, myIter, myThid) |
197 |
cnh |
1.1 |
ENDDO |
198 |
|
|
|
199 |
|
|
CALL DO_FIELDS_BLOCKING_EXCHANGES( mythid ) |
200 |
|
|
|
201 |
|
|
CALL DO_FIELDS_BLOCKING_EXCHANGES( mythid ) |
202 |
|
|
|
203 |
|
|
CALL DO_FIELDS_BLOCKING_EXCHANGES( mythid ) |
204 |
|
|
|
205 |
|
|
CALL DO_FIELDS_BLOCKING_EXCHANGES( mythid ) |
206 |
|
|
|
207 |
|
|
#ifdef ALLOW_COST |
208 |
|
|
c-- Sum all cost function contributions. |
209 |
|
|
call TIMER_START('COST_FINAL [ADJOINT SPIN-DOWN]', mythid) |
210 |
|
|
call COST_FINAL ( mythid ) |
211 |
|
|
call TIMER_STOP ('COST_FINAL [ADJOINT SPIN-DOWN]', mythid) |
212 |
|
|
#endif |
213 |
|
|
|
214 |
|
|
_BARRIER |
215 |
|
|
CALL TIMER_STOP ('MAIN LOOP [THE_MAIN_LOOP]', mythid) |
216 |
|
|
|
217 |
|
|
#ifdef ALLOW_DEBUG |
218 |
|
|
IF (debugMode) CALL DEBUG_LEAVE('THE_MAIN_LOOP',myThid) |
219 |
|
|
#endif |
220 |
|
|
|
221 |
|
|
END |