/[MITgcm]/MITgcm/model/src/the_model_main.F
ViewVC logotype

Diff of /MITgcm/model/src/the_model_main.F

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.25 by adcroft, Fri Mar 12 16:44:04 1999 UTC revision 1.56 by dimitri, Wed Sep 24 04:52:38 2003 UTC
# Line 1  Line 1 
1  C $Header$  C $Header$
2    C $Name$
3    
4    CBOI
5    C
6    C !TITLE: MITGCM KERNEL CODE SYNOPSIS
7    C !AUTHORS: mitgcm developers ( support@mitgcm.org )
8    C !AFFILIATION: Massachussetts Institute of Technology
9    C !DATE:
10    C !INTRODUCTION: Kernel dynamical routines
11    C This document summarises MITgcm code under the model/ subdirectory.
12    C The code under model/ ( src/ and inc/ ) contains most of
13    C the driver routines for the baseline forms of the kernel equations in the
14    C MITgcm algorithm. Numerical code for much of the baseline forms of
15    C these equations is also under the model/ directory. Other numerical code
16    C used for the kernel equations is contained in packages in the pkg/
17    C directory tree.
18    C Code for auxilliary equations and alternate dicretizations of the kernel
19    C equations and algorithm can also be found in the pkg/ directory tree.
20    C
21    C \subsection{Getting Help and Reporting Errors and Problems}
22    C If you have questions please e-mail support@mitgcm.org. We also welcome
23    C reports of errors and inconsistencies in the code or in the accompanying
24    C documentation. Please feel free to send these
25    C to support@mitgcm.org. For further information and to review
26    C problems reported to support@mitgcm.org please visit http://mitgcm.org.
27    C
28    C \subsection{MITgcm Kernel Code Calling Sequence}
29    C \bv
30    C
31    C Invocation from WRAPPER level...
32    C  :
33    C  :
34    C  |
35    C  |-THE_MODEL_MAIN :: Primary driver for the MITgcm algorithm
36    C    |              :: Called from WRAPPER level numerical
37    C    |              :: code innvocation routine. On entry
38    C    |              :: to THE_MODEL_MAIN separate thread and
39    C    |              :: separate processes will have been established.
40    C    |              :: Each thread and process will have a unique ID
41    C    |              :: but as yet it will not be associated with a
42    C    |              :: specific region in decomposed discrete space.
43    C    |
44    C    |-INITIALISE_FIXED :: Set fixed model arrays such as topography,
45    C    | |                :: grid, solver matrices etc..
46    C    | |              
47    C    | |-INI_PARMS :: Routine to set kernel model parameters.
48    C    | |           :: By default kernel parameters are read from file
49    C    | |           :: "data" in directory in which code executes.
50    C    | |
51    C    | |-MON_INIT :: Initialises monitor pacakge ( see pkg/monitor )
52    C    | |
53    C    | |-INI_GRID :: Control grid array (vert. and hori.) initialisation.
54    C    | | |        :: Grid arrays are held and described in GRID.h.
55    C    | | |
56    C    | | |-INI_VERTICAL_GRID        :: Initialise vertical grid arrays.
57    C    | | |
58    C    | | |-INI_CARTESIAN_GRID       :: Cartesian horiz. grid initialisation
59    C    | | |                          :: (calculate grid from kernel parameters).
60    C    | | |
61    C    | | |-INI_SPHERICAL_POLAR_GRID :: Spherical polar horiz. grid
62    C    | | |                          :: initialisation (calculate grid from
63    C    | | |                          :: kernel parameters).
64    C    | | |
65    C    | | |-INI_CURVILINEAR_GRID     :: General orthogonal, structured horiz.
66    C    | |                            :: grid initialisations. ( input from raw
67    C    | |                            :: grid files, LONC.bin, DXF.bin etc... )
68    C    | |
69    C    | |-INI_DEPTHS    :: Read (from "bathyFile") or set bathymetry/orgography.
70    C    | |
71    C    | |-INI_MASKS_ETC :: Derive horizontal and vertical cell fractions and
72    C    | |               :: land masking for solid-fluid boundaries.
73    C    | |
74    C    | |-INI_LINEAR_PHSURF :: Set ref. surface Bo_surf
75    C    | |
76    C    | |-INI_CORI          :: Set coriolis term. zero, f-plane, beta-plane,
77    C    | |                   :: sphere optins are coded.
78    C    | |
79    C    | |-PACAKGES_BOOT      :: Start up the optional package environment.
80    C    | |                    :: Runtime selection of active packages.
81    C    | |
82    C    | |-PACKAGES_READPARMS :: Call active package internal parameter load.
83    C    | | |
84    C    | | |-GMREDI_READPARMS    :: GM Package. see pkg/gmredi
85    C    | | |-KPP_READPARMS       :: KPP Package. see pkg/kpp
86    C    | | |-SHAP_FILT_READPARMS :: Shapiro filter package. see pkg/shap_filt
87    C    | | |-OBCS_READPARMS      :: Open bndy package. see pkg/obcs
88    C    | | |-AIM_READPARMS       :: Intermediate Atmos. pacakage. see pkg/aim
89    C    | | |-COST_READPARMS      :: Cost function package. see pkg/cost
90    C    | | |-CTRL_INIT           :: Control vector support package. see pkg/ctrl
91    C    | | |-OPTIM_READPARMS     :: Optimisation support package. see pkg/ctrl
92    C    | | |-GRDCHK_READPARMS    :: Gradient check package. see pkg/grdchk
93    C    | | |-ECCO_READPARMS      :: ECCO Support Package. see pkg/ecco
94    C    | |
95    C    | |-PACKAGES_CHECK
96    C    | | |
97    C    | | |-KPP_CHECK           :: KPP Package. pkg/kpp
98    C    | | |-OBCS_CHECK          :: Open bndy Pacakge. pkg/obcs
99    C    | | |-GMREDI_CHECK        :: GM Package. pkg/gmredi
100    C    | |
101    C    | |-PACKAGES_INIT_FIXED
102    C    | | |-OBCS_INIT_FIXED     :: Open bndy Package. see pkg/obcs
103    C    | | |-FLT_INIT            :: Floats Package. see pkg/flt
104    C    | |
105    C    | |-ZONAL_FILT_INIT       :: FFT filter Package. see pkg/zonal_filt
106    C    | |
107    C    | |-INI_CG2D              :: 2d con. grad solver initialisation.
108    C    | |
109    C    | |-INI_CG3D              :: 3d con. grad solver initialisation.
110    C    | |
111    C    | |-CONFIG_SUMMARY        :: Provide synopsis of kernel setup.
112    C    |                         :: Includes annotated table of kernel
113    C    |                         :: parameter settings.
114    C    |
115    C    |-CTRL_UNPACK :: Control vector support package. see pkg/ctrl
116    C    |
117    C    |-ADTHE_MAIN_LOOP :: Derivative evaluating form of main time stepping loop
118    C    !                 :: Auotmatically gerenrated by TAMC/TAF.
119    C    |
120    C    |-CTRL_PACK   :: Control vector support package. see pkg/ctrl
121    C    |
122    C    |-GRDCHK_MAIN :: Gradient check package. see pkg/grdchk
123    C    |
124    C    |-THE_MAIN_LOOP :: Main timestepping loop routine.
125    C    | |
126    C    | |-INITIALISE_VARIA :: Set the initial conditions for time evolving
127    C    | | |                :: variables
128    C    | | |
129    C    | | |-INI_LINEAR_PHISURF :: Set ref. surface Bo_surf
130    C    | | |
131    C    | | |-INI_CORI     :: Set coriolis term. zero, f-plane, beta-plane,
132    C    | | |              :: sphere optins are coded.
133    C    | | |
134    C    | | |-INI_CG2D     :: 2d con. grad solver initialisation.
135    C    | | |-INI_CG3D     :: 3d con. grad solver initialisation.
136    C    | | |-INI_MIXING   :: Initialise diapycnal diffusivity.
137    C    | | |-INI_DYNVARS  :: Initialise to zero all DYNVARS.h arrays (dynamical
138    C    | | |              :: fields).
139    C    | | |
140    C    | | |-INI_FIELDS   :: Control initialising model fields to non-zero
141    C    | | | |-INI_VEL    :: Initialize 3D flow field.
142    C    | | | |-INI_THETA  :: Set model initial temperature field.
143    C    | | | |-INI_SALT   :: Set model initial salinity field.
144    C    | | | |-INI_PSURF  :: Set model initial free-surface height/pressure.
145    C    | | | |-INI_PRESSURE :: Compute model initial hydrostatic pressure
146    C    | | |
147    C    | | |-INI_TR1      :: Set initial tracer 1 distribution.
148    C    | | |
149    C    | | |-THE_CORRECTION_STEP :: Step forward to next time step.
150    C    | | | |                   :: Here applied to move restart conditions
151    C    | | | |                   :: (saved in mid timestep) to correct level in
152    C    | | | |                   :: time (only used for pre-c35).
153    C    | | | |
154    C    | | | |-CALC_GRAD_PHI_SURF :: Return DDx and DDy of surface pressure
155    C    | | | |-CORRECTION_STEP    :: Pressure correction to momentum
156    C    | | | |-CYCLE_TRACER       :: Move tracers forward in time.
157    C    | | | |-OBCS_APPLY         :: Open bndy package. see pkg/obcs
158    C    | | | |-SHAP_FILT_APPLY    :: Shapiro filter package. see pkg/shap_filt
159    C    | | | |-ZONAL_FILT_APPLY   :: FFT filter package. see pkg/zonal_filt
160    C    | | | |-CONVECTIVE_ADJUSTMENT :: Control static instability mixing.
161    C    | | | | |-FIND_RHO  :: Find adjacent densities.
162    C    | | | | |-CONVECT   :: Mix static instability.
163    C    | | | | |-TIMEAVE_CUMULATE :: Update convection statistics.
164    C    | | | |
165    C    | | | |-CALC_EXACT_ETA        :: Change SSH to flow divergence.    
166    C    | | |
167    C    | | |-CONVECTIVE_ADJUSTMENT_INI :: Control static instability mixing
168    C    | | | |                         :: Extra time history interactions.
169    C    | | | |                      
170    C    | | | |-FIND_RHO  :: Find adjacent densities.
171    C    | | | |-CONVECT   :: Mix static instability.
172    C    | | | |-TIMEAVE_CUMULATE :: Update convection statistics.
173    C    | | |
174    C    | | |-PACKAGES_INIT_VARIABLES :: Does initialisation of time evolving
175    C    | | | |                       :: package data.
176    C    | | | |
177    C    | | | |-GMREDI_INIT          :: GM package. ( see pkg/gmredi )
178    C    | | | |-KPP_INIT             :: KPP package. ( see pkg/kpp )
179    C    | | | |-KPP_OPEN_DIAGS    
180    C    | | | |-OBCS_INIT_VARIABLES  :: Open bndy. package. ( see pkg/obcs )
181    C    | | | |-AIM_INIT             :: Interm. atmos package. ( see pkg/aim )
182    C    | | | |-CTRL_MAP_INI         :: Control vector package.( see pkg/ctrl )
183    C    | | | |-COST_INIT            :: Cost function package. ( see pkg/cost )
184    C    | | | |-ECCO_INIT            :: ECCO support package. ( see pkg/ecco )
185    C    | | | |-INI_FORCING          :: Set model initial forcing fields.
186    C    | | |   |                    :: Either set in-line or from file as shown.
187    C    | | |   |-READ_FLD_XY_RS(zonalWindFile)
188    C    | | |   |-READ_FLD_XY_RS(meridWindFile)
189    C    | | |   |-READ_FLD_XY_RS(surfQFile)
190    C    | | |   |-READ_FLD_XY_RS(EmPmRfile)
191    C    | | |   |-READ_FLD_XY_RS(thetaClimFile)
192    C    | | |   |-READ_FLD_XY_RS(saltClimFile)
193    C    | | |   |-READ_FLD_XY_RS(surfQswFile)
194    C    | | |
195    C    | | |-CALC_SURF_DR   :: Calculate the new surface level thickness.
196    C    | | |-UPDATE_SURF_DR :: Update the surface-level thickness fraction.
197    C    | | |-UPDATE_CG2D    :: Update 2d conjugate grad. for Free-Surf.
198    C    | | |-STATE_SUMMARY    :: Summarize model prognostic variables.
199    C    | | |-TIMEAVE_STATVARS :: Time averaging package ( see pkg/timeave ).
200    C    | |
201    C    | |-WRITE_STATE      :: Controlling routine for IO to dump model state.
202    C    | | |-WRITE_REC_XYZ_RL :: Single file I/O
203    C    | | |-WRITE_FLD_XYZ_RL :: Multi-file I/O
204    C    | |
205    C    | |-MONITOR          :: Monitor state ( see pkg/monitor )
206    C    | |-CTRL_MAP_FORCING :: Control vector support package. ( see pkg/ctrl )
207    C====|>|
208    C====|>| ****************************
209    C====|>| BEGIN MAIN TIMESTEPPING LOOP
210    C====|>| ****************************
211    C====|>|
212    C/\  | |-FORWARD_STEP     :: Step forward a time-step ( AT LAST !!! )
213    C/\  | | |
214    C/\  | | |-DUMMY_IN_STEPPING :: autodiff package ( pkg/autoduff ).
215    C/\  | | |-CALC_EXACT_ETA :: Change SSH to flow divergence.
216    C/\  | | |-CALC_SURF_DR   :: Calculate the new surface level thickness.
217    C/\  | | |-EXF_GETFORCING :: External forcing package. ( pkg/exf )
218    C/\  | | |-EXTERNAL_FIELDS_LOAD :: Control loading time dep. external data.
219    C/\  | | | |                    :: Simple interpolcation between end-points
220    C/\  | | | |                    :: for forcing datasets.
221    C/\  | | | |                  
222    C/\  | | | |-EXCH :: Sync forcing. in overlap regions.
223    C/\  | | |-SEAICE_MODEL   :: Compute sea-ice terms. ( pkg/seaice )
224    C/\  | | |
225    C/\  | | |-THERMODYNAMICS :: theta, salt + tracer equations driver.
226    C/\  | | | |
227    C/\  | | | |-INTEGRATE_FOR_W :: Integrate for vertical velocity.
228    C/\  | | | |-OBCS_APPLY_W    :: Open bndy. package ( see pkg/obcs ).
229    C/\  | | | |-FIND_RHO        :: Calculates [rho(S,T,z)-RhoConst] of a slice
230    C/\  | | | |-GRAD_SIGMA      :: Calculate isoneutral gradients
231    C/\  | | | |-CALC_IVDC       :: Set Implicit Vertical Diffusivity for Convection
232    C/\  | | | |
233    C/\  | | | |-OBCS_CALC            :: Open bndy. package ( see pkg/obcs ).
234    C/\  | | | |-EXTERNAL_FORCING_SURF:: Accumulates appropriately dimensioned
235    C/\  | | | | |                    :: forcing terms.
236    C/\  | | | | |-PTRACERS_FORCING_SURF :: Tracer package ( see pkg/ptracers ).
237    C/\  | | | |
238    C/\  | | | |-GMREDI_CALC_TENSOR   :: GM package ( see pkg/gmredi ).
239    C/\  | | | |-GMREDI_CALC_TENSOR_DUMMY :: GM package ( see pkg/gmredi ).
240    C/\  | | | |-KPP_CALC             :: KPP package ( see pkg/kpp ).
241    C/\  | | | |-KPP_CALC_DUMMY       :: KPP package ( see pkg/kpp ).
242    C/\  | | | |-AIM_DO_ATMOS_PHYSICS :: Intermed. atmos package ( see pkg/aim ).
243    C/\  | | | |-GAD_ADVECTION        :: Generalised advection driver (multi-dim
244    C/\  | | | |                         advection case) (see pkg/gad).
245    C/\  | | | |-CALC_COMMON_FACTORS  :: Calculate common data (such as volume flux)
246    C/\  | | | |-CALC_DIFFUSIVITY     :: Calculate net vertical diffusivity
247    C/\  | | | | |
248    C/\  | | | | |-GMREDI_CALC_DIFF   :: GM package ( see pkg/gmredi ).
249    C/\  | | | | |-KPP_CALC_DIFF      :: KPP package ( see pkg/kpp ).
250    C/\  | | | |
251    C/\  | | | |-CALC_GT              :: Calculate the temperature tendency terms
252    C/\  | | | | |
253    C/\  | | | | |-GAD_CALC_RHS       :: Generalised advection package
254    C/\  | | | | | |                  :: ( see pkg/gad )
255    C/\  | | | | | |-KPP_TRANSPORT_T  :: KPP non-local transport ( see pkg/kpp ).
256    C/\  | | | | |
257    C/\  | | | | |-EXTERNAL_FORCING_T :: Problem specific forcing for temperature.
258    C/\  | | | | |-ADAMS_BASHFORTH2   :: Extrapolate tendencies forward in time.
259    C/\  | | | | |-FREESURF_RESCALE_G :: Re-scale Gt for free-surface height.
260    C/\  | | | |
261    C/\  | | | |-TIMESTEP_TRACER      :: Step tracer field forward in time
262    C/\  | | | |
263    C/\  | | | |-CALC_GS              :: Calculate the salinity tendency terms
264    C/\  | | | | |
265    C/\  | | | | |-GAD_CALC_RHS       :: Generalised advection package
266    C/\  | | | | | |                  :: ( see pkg/gad )
267    C/\  | | | | | |-KPP_TRANSPORT_S  :: KPP non-local transport ( see pkg/kpp ).
268    C/\  | | | | |
269    C/\  | | | | |-EXTERNAL_FORCING_S :: Problem specific forcing for salt.
270    C/\  | | | | |-ADAMS_BASHFORTH2   :: Extrapolate tendencies forward in time.
271    C/\  | | | | |-FREESURF_RESCALE_G :: Re-scale Gs for free-surface height.
272    C/\  | | | |
273    C/\  | | | |-TIMESTEP_TRACER      :: Step tracer field forward in time
274    C/\  | | | |
275    C/\  | | | |-CALC_GTR1            :: Calculate other tracer(s) tendency terms
276    C/\  | | | | |
277    C/\  | | | | |-GAD_CALC_RHS       :: Generalised advection package
278    C/\  | | | | | |                  :: ( see pkg/gad )
279    C/\  | | | | | |-KPP_TRANSPORT_PTR:: KPP non-local transport ( see pkg/kpp ).
280    C/\  | | | | |
281    C/\  | | | | |-EXTERNAL_FORCING_TR:: Problem specific forcing for tracer.
282    C/\  | | | | |-ADAMS_BASHFORTH2   :: Extrapolate tendencies forward in time.
283    C/\  | | | | |-FREESURF_RESCALE_G :: Re-scale Gs for free-surface height.
284    C/\  | | | |
285    C/\  | | | |-TIMESTEP_TRACER      :: Step tracer field forward in time
286    C/\  | | | |
287    C/\  | | | |-PTRACERS_INTEGRATE   :: Integrate other tracer(s) ( see pkg/ptracers ).
288    C/\  | | | | |
289    C/\  | | | | |-GAD_CALC_RHS       :: Generalised advection package
290    C/\  | | | | |                    :: ( see pkg/gad )
291    C/\  | | | | |-PTRACERS_FORCING   :: Problem specific forcing for tracer.
292    C/\  | | | | |-ADAMS_BASHFORTH2   :: Extrapolate tendencies forward in time.
293    C/\  | | | | |-FREESURF_RESCALE_G :: Re-scale Gs for free-surface height.
294    C/\  | | | | |-TIMESTEP_TRACER    :: Step tracer field forward in time
295    C/\  | | | |
296    C/\  | | | |-OBCS_APPLY_TS        :: Open bndy. package (see pkg/obcs ).
297    C/\  | | | |-FREEZE               :: Limit range of temperature.
298    C/\  | | | |
299    C/\  | | | |-IMPLDIFF             :: Solve vertical implicit diffusion equation.
300    C/\  | | | |-OBCS_APPLY_TS        :: Open bndy. package (see pkg/obcs ).
301    C/\  | | | |
302    C/\  | | | |-AIM_AIM2DYN_EXCHANGES :: Inetermed. atmos (see pkg/aim).
303    C/\  | | | |-EXCH                 :: Update overlaps
304    C/\  | | |
305    C/\  | | |-DYNAMICS       :: Momentum equations driver.
306    C/\  | | | |
307    C/\  | | | |-CALC_GRAD_PHI_SURF :: Calculate the gradient of the surface
308    C/\  | | | |                       Potential anomaly.
309    C/\  | | | |-CALC_VISCOSITY     :: Calculate net vertical viscosity
310    C/\  | | | | |-KPP_CALC_VISC    :: KPP package ( see pkg/kpp ).
311    C/\  | | | |                                                      
312    C/\  | | | |-CALC_PHI_HYD       :: Integrate the hydrostatic relation.
313    C/\  | | | |-MOM_FLUXFORM       :: Flux form mom eqn. package ( see
314    C/\  | | | |                       pkg/mom_fluxform ).
315    C/\  | | | |-MOM_VECINV         :: Vector invariant form mom eqn. package ( see
316    C/\  | | | |                       pkg/mom_vecinv   ).
317    C/\  | | | |-TIMESTEP           :: Step momentum fields forward in time
318    C/\  | | | |-OBCS_APPLY_UV      :: Open bndy. package (see pkg/obcs ).
319    C/\  | | | |
320    C/\  | | | |-IMPLDIFF           :: Solve vertical implicit diffusion equation.
321    C/\  | | | |-OBCS_APPLY_UV      :: Open bndy. package (see pkg/obcs ).
322    C/\  | | | |
323    C/\  | | | |-TIMEAVE_CUMUL_1T   :: Time averaging package ( see pkg/timeave ).
324    C/\  | | | |-TIMEAVE_CUMUATE    :: Time averaging package ( see pkg/timeave ).
325    C/\  | | | |-DEBUG_STATS_RL     :: Quick debug package ( see pkg/debug ).
326    C/\  | | |
327    C/\  | | |-CALC_GW        :: vert. momentum tendency terms ( NH, QH only ).
328    C/\  | | |
329    C/\  | | |-UPDATE_SURF_DR :: Update the surface-level thickness fraction.
330    C/\  | | |
331    C/\  | | |-UPDATE_CG2D    :: Update 2d conjugate grad. for Free-Surf.
332    C/\  | | |
333    C/\  | | |-SOLVE_FOR_PRESSURE           :: Find surface pressure.
334    C/\  | | | |-CALC_DIV_GHAT     :: Form the RHS of the surface pressure eqn.
335    C/\  | | | |-CG2D              :: Two-dim pre-con. conjugate-gradient.
336    C/\  | | | |-CG3D              :: Three-dim pre-con. conjugate-gradient solver.
337    C/\  | | |
338    C/\  | | |-THE_CORRECTION_STEP          :: Step forward to next time step.
339    C/\  | | | |
340    C/\  | | | |-CALC_GRAD_PHI_SURF :: Return DDx and DDy of surface pressure
341    C/\  | | | |-CORRECTION_STEP    :: Pressure correction to momentum
342    C/\  | | | |-CYCLE_TRACER       :: Move tracers forward in time.
343    C/\  | | | |-OBCS_APPLY         :: Open bndy package. see pkg/obcs
344    C/\  | | | |-SHAP_FILT_APPLY    :: Shapiro filter package. see pkg/shap_filt
345    C/\  | | | |-ZONAL_FILT_APPLY   :: FFT filter package. see pkg/zonal_filt
346    C/\  | | | |-CONVECTIVE_ADJUSTMENT :: Control static instability mixing.
347    C/\  | | | | |-FIND_RHO  :: Find adjacent densities.
348    C/\  | | | | |-CONVECT   :: Mix static instability.
349    C/\  | | | | |-TIMEAVE_CUMULATE :: Update convection statistics.
350    C/\  | | | |
351    C/\  | | | |-CALC_EXACT_ETA        :: Change SSH to flow divergence.    
352    C/\  | | |
353    C/\  | | |-DO_FIELDS_BLOCKING_EXCHANGES :: Sync up overlap regions.
354    C/\  | | | |-EXCH                                                  
355    C/\  | | |
356    C/\  | | |-FLT_MAIN         :: Float package ( pkg/flt ).
357    C/\  | | |
358    C/\  | | |-MONITOR          :: Monitor package ( pkg/monitor ).
359    C/\  | | |
360    C/\  | | |-DO_THE_MODEL_IO  :: Standard diagnostic I/O.
361    C/\  | | | |-WRITE_STATE    :: Core state I/O
362    C/\  | | | |-TIMEAVE_STATV_WRITE :: Time averages. see pkg/timeave
363    C/\  | | | |-AIM_WRITE_DIAGS     :: Intermed. atmos diags. see pkg/aim
364    C/\  | | | |-GMREDI_DIAGS        :: GM diags. see pkg/gmredi
365    C/\  | | | |-KPP_DO_DIAGS        :: KPP diags. see pkg/kpp
366    C/\  | | | |-SBO_CALC            :: SBO diags. see pkg/sbo
367    C/\  | | | |-SBO_DIAGS           :: SBO diags. see pkg/sbo
368    C/\  | | |
369    C/\  | | |-WRITE_CHECKPOINT :: Do I/O for restart files.
370    C/\  | |
371    C/\  | |-COST_TILE        :: Cost function package. ( see pkg/cost )
372    C<===|=|
373    C<===|=| **************************
374    C<===|=| END MAIN TIMESTEPPING LOOP
375    C<===|=| **************************
376    C<===|=|
377    C    | |-COST_FINAL       :: Cost function package. ( see pkg/cost )
378    C    |
379    C    |-WRITE_CHECKPOINT :: Final state storage, for restart.
380    C    |
381    C    |-TIMER_PRINTALL :: Computational timing summary
382    C    |
383    C    |-COMM_STATS     :: Summarise inter-proc and inter-thread communication
384    C                     :: events.
385    C \ev
386    C
387    C
388    CEOI
389    
390    
391  #include "CPP_OPTIONS.h"  #include "CPP_OPTIONS.h"
392    
393    CBOP
394    
395    C     !ROUTINE: THE_MODEL_MAIN
396    
397    C     !INTERFACE:
398        SUBROUTINE THE_MODEL_MAIN(myThid)        SUBROUTINE THE_MODEL_MAIN(myThid)
 C     /==========================================================\  
 C     | SUBROUTINE THE_MODEL_MAIN                                |  
 C     | o Master controlling routine for model using the MITgcm  |  
 C     |   UV parallel wrapper.                                   |  
 C     |==========================================================|  
 C     | THE_MODEL_MAIN is invoked by the MITgcm UV parallel      |  
 C     | wrapper with a single integer argument "myThid". This    |  
 C     | variable identifies the thread number of an instance of  |  
 C     | THE_MODEL_MAIN. Each instance of THE_MODEL_MAIN works    |  
 C     | on a particular region of the models domain and          |  
 C     | synchronises with other instances as necessary. The      |  
 C     | routine has to "understand" the MITgcm parallel          |  
 C     | environment and the numerical algorithm. Editing this    |  
 C     | routine is best done with some knowledge of both aspects.|  
 C     | Notes                                                    |  
 C     | =====                                                    |  
 C     | C*P* comments indicating place holders for which code is |  
 C     |      presently being developed.                          |  
 C     \==========================================================/  
399        IMPLICIT NONE        IMPLICIT NONE
 C  
 C     Call Tree  
 C     =========  
 C      
 C      main ( eesupp )  
 C       |  
 C       .  
 C       .  
 C       . Generic environment initialisation ( see eesupp/src and  
 C       .                                      eesupp/inc )        
 C       . multiple threads and/or processes are created in here  
 C       .  
 C       .  
 C       .  
 C       |  
 C       |-THE_MODEL_MAIN - Begin specific model. One instance  
 C       |  |               of this codes exists for each thread  
 C       |  |               and/or instance. Each instance manages  
 C       |  |               a specifc set of tiles.                
 C       |  |  
 C       |  |--INITIALISE  
 C       |  |   o Set initial conditions and model configuration  
 C       |  |     Topography, hydrography, timestep, grid, etc..  
 C       |  |  
 C  ==>  |  | ** Time stepping loop starts here **  
 C  |    |  |  
 C /|\   |  |  
 C  |    |  |--LOAD_EXTERNAL_DATA  
 C /|\   |  |   o Load and/or set time dependent forcing fields  
 C  |    |  |  
 C /|\   |  |--DYNAMICS  
 C  |    |  |   o Evaluate "forward" terms  
 C /|\   |  |  
 C  |    |  |--DO_THE_MODEL_IO  
 C /|\   |  |   o Write model state  
 C  |    |  |  
 C /|\   |  |--SOLVE_FOR_PRESSURE  
 C  |    |  |   o Find pressure field to keep flow non-divergent  
 C /|\   |  |  
 C  |    |  |--DO_GTERM_BLOCKING_EXCHANGES  
 C /|\   |  |   o Update overlap regions  
 C  |    |  |  
 C /|\   |  |--WRITE_CHECKPOINT  
 C  |    |  |   o Write restart file(s)  
 C /|\   |  |  
 C  |    |  |  
 C  |<== |  | ** Time stepping loop finishes here **  
 C       |  |  
 C       |  |--WRITE_STATE  
 C       |  |--WRITE_CHECKPOINT  
 C       |  
 C       .  
 C       .  
 C       . Generic environment termination ( see eesupp/src and  
 C       .                                      eesupp/inc )        
 C       .  
 C       .  
400    
401    C     !DESCRIPTION: \bv
402    C     *==========================================================*
403    C     | SUBROUTINE THE_MODEL_MAIN                                
404    C     | o Master controlling routine for model using the MITgcm  
405    C     |   UV parallel wrapper.                                    
406    C     *==========================================================*
407    C     | THE_MODEL_MAIN is invoked by the MITgcm UV parallel      
408    C     | wrapper with a single integer argument "myThid". This    
409    C     | variable identifies the thread number of an instance of  
410    C     | THE_MODEL_MAIN. Each instance of THE_MODEL_MAIN works    
411    C     | on a particular region of the models domain and          
412    C     | synchronises with other instances as necessary. The      
413    C     | routine has to "understand" the MITgcm parallel          
414    C     | environment and the numerical algorithm. Editing this    
415    C     | routine is best done with some knowledge of both aspects.
416    C     | Notes                                                    
417    C     | =====                                                    
418    C     | C*P* comments indicating place holders for which code is  
419    C     |      presently being developed.                          
420    C     *==========================================================*
421    C     \ev
422    
423    C     !CALLING SEQUENCE:
424    C     THE_MODEL_MAIN()
425    C       |
426    C       |
427    C       |--INITIALISE_FIXED
428    C       |   o Set model configuration (fixed arrays)
429    C       |     Topography, hydrography, timestep, grid, etc..
430    C       |
431    C       |--CTRL_UNPACK      o Derivative mode. Unpack control vector.
432    C       |
433    C       |--ADTHE_MAIN_LOOP  o Main timestepping loop for combined
434    C       |                     prognostic and reverse mode integration.
435    C       |
436    C       |--CTRL_PACK        o Derivative mode. Unpack control vector.
437    C       |
438    C       |--GRDCHK_MAIN      o Gradient check control routine.
439    C       |
440    C       |--THE_MAIN_LOOP    o Main timestepping loop for pure prognostic
441    C       |                     integration.
442    C       |
443    C       |--WRITE_CHECKPOINT o Write retsart information.
444    C       |
445    C       |--TIMER_PRINTALL   o Print out timing statistics.
446    C       |
447    C       |--COMM_STATS       o Print out communication statistics.
448    
449    C     !USES:
450  C     == Global variables ===  C     == Global variables ===
451  #include "SIZE.h"  #include "SIZE.h"
452  #include "EEPARAMS.h"  #include "EEPARAMS.h"
453  #include "PARAMS.h"  #include "PARAMS.h"
 #include "CG2D.h"  
454  #include "DYNVARS.h"  #include "DYNVARS.h"
455    #ifdef ALLOW_NONHYDROSTATIC
456    #include "CG3D.h"
457    #endif
458    
459    #ifdef ALLOW_AUTODIFF_TAMC
460    #include "tamc.h"
461    #endif
462    
463    C     !INPUT/OUTPUT PARAMETERS:
464  C     == Routine arguments ==  C     == Routine arguments ==
465  C     myThid - Thread number for this instance of the routine.  C     myThid - Thread number for this instance of the routine.
466        INTEGER myThid          INTEGER myThid  
467    
468    C     !LOCAL VARIABLES:
469  C     == Local variables ==  C     == Local variables ==
470  C     Note: Under the multi-threaded model myCurrentIter and  C     Note: Under the multi-threaded model myCurrentIter and
471  C           myCurrentTime are local variables passed around as routine  C           myCurrentTime are local variables passed around as routine
472  C           arguments. Although this is fiddly it saves the need to  C           arguments. Although this is fiddly it saves the need to
473  C           impose additional synchronisation points when they are  C           impose additional synchronisation points when they are
474  C           updated.  C           updated.
 C     myCurrentIter - Iteration counter for this thread  
475  C     myCurrentTime - Time counter for this thread  C     myCurrentTime - Time counter for this thread
476  C     I             - Loop counter  C     myCurrentIter - Iteration counter for this thread
477        INTEGER I, myCurrentIter        INTEGER myCurrentIter
478        REAL    myCurrentTime        _RL     myCurrentTime
479          logical  exst
480          logical  lastdiva
481    CEOP
482    c--   set default:
483          lastdiva = .TRUE.
484    
485    #ifndef DISABLE_DEBUGMODE
486          IF (debugMode) CALL DEBUG_ENTER('THE_MODEL_MAIN',myThid)
487    #endif
488    
489  C--   This timer encompasses the whole code  C--   This timer encompasses the whole code
490        CALL TIMER_START('ALL',myThid)        CALL TIMER_START('ALL                    [THE_MODEL_MAIN]',myThid)
491    
492        CALL TIMER_START('SPIN-UP',myThid)  #ifndef DISABLE_DEBUGMODE
493          IF (debugMode) CALL DEBUG_CALL('INITIALISE_FIXED',myThid)
494    #endif
495    
496    C--   Set model configuration (fixed arrays)
497          CALL TIMER_START('INITIALISE_FIXED       [THE_MODEL_MAIN]',myThid)
498          CALL INITIALISE_FIXED( myThid )
499          CALL TIMER_STOP ('INITIALISE_FIXED       [THE_MODEL_MAIN]',myThid)
500    
 C--   Set model initial conditions  
       CALL TIMER_START('INITIALISE          [SPIN-UP]',myThid)  
       CALL INITIALISE( myThid )  
501        myCurrentTime = startTime        myCurrentTime = startTime
502        myCurrentIter = nIter0        myCurrentIter = nIter0
       CALL TIMER_STOP ('INITIALISE          [SPIN-UP]',myThid)  
503    
504  C--   Dump for start state  #if ( defined (ALLOW_ADJOINT_RUN) || \
505        CALL TIMER_START('I/O (WRITE)         [SPIN-UP]',myThid)        defined (ALLOW_TANGENTLINEAR_RUN) || \
506        CALL WRITE_STATE( .TRUE., myCurrentTime, myCurrentIter, myThid )        defined (ALLOW_GRADIENT_CHECK) || \
507        CALL TIMER_STOP ('I/O (WRITE)         [SPIN-UP]',myThid)        defined (ALLOW_ECCO_OPTIMIZATION) )
508    
509        CALL TIMER_STOP ('SPIN-UP',myThid)        _BEGIN_MASTER( mythid )
510          IF (myProcId .eq. 0) THEN
511  C--   Begin time stepping loop           inquire( file='costfinal', exist=exst )
512        CALL TIMER_START('MAIN LOOP',myThid)           IF ( .NOT. exst) THEN
513        DO I=1, nTimeSteps              CALL TIMER_START('CTRL_UNPACK      [THE_MODEL_MAIN]',mythid)
514                CALL CTRL_UNPACK( mycurrentiter, mycurrenttime, mythid )
515  C--    Load forcing/external data fields              CALL TIMER_STOP ('CTRL_UNPACK      [THE_MODEL_MAIN]',mythid)
516         CALL TIMER_START('I/O (READ)         [MAIN LOOP]',myThid)           ENDIF
        CALL LOAD_EXTERNAL_FIELDS( myCurrentTime, myCurrentIter, myThid )  
        CALL TIMER_STOP ('I/O (READ)         [MAIN LOOP]',myThid)  
   
 #ifdef INCLUDE_SHAPIRO_FILTER_CODE  
 C--    Step forward all tiles, filter and exchange.  
        CALL TIMER_START('SHAP_FILT          [MAIN LOOP]',myThid)  
        CALL SHAP_FILT( myCurrentTime, myCurrentIter, myThid )  
        CALL TIMER_STOP ('SHAP_FILT          [MAIN LOOP]',myThid)  
 #endif  
   
 C--    Set Open Boundaries Values  
        IF (openBoundaries) THEN  
         CALL TIMER_START('OBCS               [MAIN LOOP]',myThid)  
         CALL SET_OBCS( myCurrentTime, myThid )  
         CALL TIMER_STOP ('OBCS               [MAIN LOOP]',myThid)  
        ENDIF  
   
 C--    Step forward fields and calculate time tendency terms  
        CALL TIMER_START('DYNAMICS           [MAIN LOOP]',myThid)  
        CALL DYNAMICS( myCurrentTime, myCurrentIter, myThid )  
        CALL TIMER_STOP ('DYNAMICS           [MAIN LOOP]',myThid)  
   
 C--    Do time averages  
 #ifdef INCLUDE_DIAGNOSTICS_INTERFACE_CODE  
        CALL TIMER_START('I/O (WRITE)        [MAIN LOOP]',myThid)  
        IF (taveFreq.GT.0.) THEN  
         CALL WRITE_TIME_AVERAGES( myCurrentTime, myCurrentIter, myThid )  
        ENDIF  
        CALL TIMER_STOP ('I/O (WRITE)        [MAIN LOOP]',myThid)  
 #endif  
   
 C--    Do IO if needed.  
 C      Note:  
 C      =====  
 C      At this point model arrays hold U,V,T,S  at "time-level" N  
 C      and cg2d_x at "time-level" N-1/2 where N = I+timeLevBase-1.  
 C      By convention this is taken to be the model "state".  
        CALL TIMER_START('I/O (WRITE)        [MAIN LOOP]',myThid)  
        CALL DO_THE_MODEL_IO( myCurrentTime, myCurrentIter, myThid )  
        CALL TIMER_STOP ('I/O (WRITE)        [MAIN LOOP]',myThid)  
   
 C--    Solve elliptic equation(s).  
 C      Two-dimensional only for conventional hydrostatic or  
 C      three-dimensional for non-hydrostatic and/or IGW scheme.  
        CALL TIMER_START('SOLVE_FOR_PRESSURE [MAIN LOOP]',myThid)  
        CALL SOLVE_FOR_PRESSURE( myThid )  
        CALL TIMER_STOP ('SOLVE_FOR_PRESSURE [MAIN LOOP]',myThid)  
   
 C--    Do "blocking" sends and receives for tendency "overlap" terms  
        CALL TIMER_START('BLOCKING_EXCHANGES [MAIN LOOP]',myThid)  
        CALL DO_GTERM_BLOCKING_EXCHANGES( myThid )  
        CALL TIMER_STOP ('BLOCKING_EXCHANGES [MAIN LOOP]',myThid)  
   
        myCurrentIter = myCurrentIter + 1  
        myCurrentTime = myCurrentTime + deltaTClock  
   
 C--    Save state for restarts  
 C      Note:  
 C      =====  
 C      Because of the ordering of the timestepping code and  
 C      tendency term code at end of loop model arrays hold  
 C      U,V,T,S  at "time-level" N but gu, gv, gs, gt, guNM1,...  
 C      at "time-level" N+1/2 (guNM1 at "time-level" N+1/2 is  
 C      gu at "time-level" N-1/2) and cg2d_x at "time-level" N+1/2.  
 C       where N = I+timeLevBase-1  
 C      Thus a checkpoint contains U.0000000000, GU.0000000001 and  
 C      cg2d_x.0000000001 in the indexing scheme used for the model  
 C      "state" files. This example is referred to as a checkpoint  
 C      at time level 1  
        CALL TIMER_START('I/O (WRITE)        [MAIN LOOP]',myThid)  
        CALL  
      & WRITE_CHECKPOINT( .FALSE., myCurrentTime, myCurrentIter, myThid )  
        CALL TIMER_STOP ('I/O (WRITE)        [MAIN LOOP]',myThid)  
   
       ENDDO  
       CALL TIMER_STOP ('MAIN LOOP',myThid)  
       CALL TIMER_START('SPIN-DOWN',myThid)  
   
 C--   Final checkpoint (incase the in-loop checkpoint was missed)  
       CALL TIMER_START('I/O (WRITE)         [SPIN-DOWN]',myThid)  
       CALL  
      & WRITE_CHECKPOINT( .TRUE., myCurrentTime, myCurrentIter, myThid )  
       CALL TIMER_STOP ('I/O (WRITE)         [SPIN-DOWN]',myThid)  
   
 C--   Set Open Boundaries Values  
       IF (openBoundaries) THEN  
        CALL TIMER_START('OBCS               [SPIN_DOWN]',myThid)  
        CALL SET_OBCS( myCurrentTime, myThid )  
        CALL TIMER_STOP ('OBCS               [SPIN_DOWN]',myThid)  
517        ENDIF        ENDIF
518          _END_MASTER( mythid )
519          _BARRIER
520    
521          CALL COST_DEPENDENT_INIT ( mythid )
522          _BARRIER
523    
524  C--   Step-forward U/V/Theta/Salt for purposes of final I/O dump  #ifndef ALLOW_TANGENTLINEAR_RUN
525        CALL TIMER_START('DYNAMICS            [SPIN-DOWN]',myThid)  c
526        CALL DYNAMICS( myCurrentTime, myCurrentIter, myThid )  # if ( defined (ALLOW_ADJOINT_RUN) || \
527        CALL TIMER_STOP ('DYNAMICS            [SPIN-DOWN]',myThid)         defined (ALLOW_ECCO_OPTIMIZATION) )
528    #  ifdef ALLOW_DIVIDED_ADJOINT
529  C--   Do time averages  c-- The following assumes the TAF option '-pure'
530  #ifdef ALLOW_DIAGNOSTICS        inquire( file='costfinal', exist=exst )
531        IF (taveFreq.GT.0.) THEN        IF ( .NOT. exst) THEN
532         CALL TIMER_START('I/O (WRITE)        [SPIN-DOWN]',myThid)           CALL TIMER_START('MDTHE_MAIN_LOOP            [MD RUN]', mythid)
533         CALL WRITE_TIME_AVERAGES( myCurrentTime, myCurrentIter, myThid )           CALL MDTHE_MAIN_LOOP ( myCurrentTime, myCurrentIter, mythid )
534         CALL TIMER_STOP ('I/O (WRITE)        [SPIN-DOWN]',myThid)           CALL TIMER_STOP ('MDTHE_MAIN_LOOP            [MD RUN]', mythid)
535             CALL COST_FINAL_STORE ( mythid, lastdiva )
536          ELSE
537             CALL TIMER_START('ADTHE_MAIN_LOOP       [ADJOINT RUN]', mythid)
538             CALL ADTHE_MAIN_LOOP ( mythid )
539             CALL TIMER_STOP ('ADTHE_MAIN_LOOP       [ADJOINT RUN]', mythid)
540             CALL COST_FINAL_RESTORE ( mythid, lastdiva )
541        ENDIF        ENDIF
542    c--
543    #  else /* ALLOW_DIVIDED_ADJOINT undef */
544          CALL TIMER_START('ADTHE_MAIN_LOOP          [ADJOINT RUN]', mythid)
545          CALL ADTHE_MAIN_LOOP ( mythid )
546          CALL TIMER_STOP ('ADTHE_MAIN_LOOP          [ADJOINT RUN]', mythid)
547    #  endif /* ALLOW_DIVIDED_ADJOINT */
548    # endif
549    c--
550    #else /* ALLOW_TANGENTLINEAR_RUN defined */
551          CALL TIMER_START('G_THE_MAIN_LOOP           [TANGENT RUN]',mythid)
552          CALL G_THE_MAIN_LOOP ( myCurrentTime, myCurrentIter, myThid )
553          CALL TIMER_STOP ('G_THE_MAIN_LOOP           [TANGENT RUN]',mythid)
554    #endif /* ALLOW_TANGENTLINEAR_RUN */
555          _BARRIER
556    
557          _BEGIN_MASTER( mythid )
558          IF ( myProcId .eq. 0 .AND. lastdiva ) THEN
559             CALL TIMER_START('CTRL_PACK           [THE_MODEL_MAIN]',mythid)
560             call CTRL_PACK( mycurrentiter, mycurrenttime, mythid )
561             CALL TIMER_STOP ('CTRL_PACK           [THE_MODEL_MAIN]',mythid)
562          ENDIF
563          _END_MASTER( mythid )
564          _BARRIER
565    
566    #ifdef ALLOW_GRADIENT_CHECK
567          IF ( useGrdchk .AND. lastdiva ) THEN
568             CALL TIMER_START('GRDCHK_MAIN         [THE_MODEL_MAIN]',mythid)
569             CALL GRDCHK_MAIN( mythid )
570             CALL TIMER_STOP ('GRDCHK_MAIN         [THE_MODEL_MAIN]',mythid)
571             _BARRIER
572          ENDIF
573    #endif
574    
575    #else /* ALLOW_ADJOINT_RUN undef */
576    
577    #ifndef DISABLE_DEBUGMODE
578          IF (debugMode) CALL DEBUG_CALL('THE_MAIN_LOOP',myThid)
579    #endif
580    
581    C--   Call time stepping loop of full model
582          CALL TIMER_START('THE_MAIN_LOOP          [THE_MODEL_MAIN]',myThid)
583          CALL THE_MAIN_LOOP( myCurrentTime, myCurrentIter, myThid )
584          CALL TIMER_STOP ('THE_MAIN_LOOP          [THE_MODEL_MAIN]',myThid)
585    
586    #endif /* ALLOW_ADJOINT_RUN */
587    
588    C--   Sea-ice checkpoint (in case the in-loop checkpoint was missed)
589    #ifdef ALLOW_SEAICE
590          IF ( useSEAICE )
591         &     CALL SEAICE_WRITE_PICKUP(
592         &     .TRUE., myCurrentTime, myCurrentIter, myThid )
593  #endif  #endif
594    
595  C--   Dump for end state  C--   Final checkpoint (in case the in-loop checkpoint was missed)
596        CALL TIMER_START('I/O (WRITE)         [SPIN-DOWN]',myThid)        CALL TIMER_START('WRITE_CHECKPOINT       [THE_MODEL_MAIN]',myThid)
597        CALL WRITE_STATE( .FALSE., myCurrentTime, myCurrentIter, myThid )        CALL WRITE_CHECKPOINT(
598        CALL TIMER_STOP ('I/O (WRITE)         [SPIN-DOWN]',myThid)       &        .TRUE., myCurrentTime, myCurrentIter, myThid )
599          CALL TIMER_STOP ('WRITE_CHECKPOINT       [THE_MODEL_MAIN]',myThid)
600    
601        CALL TIMER_STOP ('SPIN-DOWN',myThid)        CALL TIMER_STOP ('ALL                    [THE_MODEL_MAIN]',myThid)
       CALL TIMER_STOP ('ALL',myThid)  
602    
603  C--   Write timer statistics  C--   Write timer statistics
604        IF ( myThid .EQ. 1 ) THEN        IF ( myThid .EQ. 1 ) THEN
# Line 248  C--   Write timer statistics Line 606  C--   Write timer statistics
606         CALL COMM_STATS         CALL COMM_STATS
607        ENDIF        ENDIF
608    
609    #ifndef DISABLE_DEBUGMODE
610          IF (debugMode) CALL DEBUG_LEAVE('THE_MODEL_MAIN',myThid)
611    #endif
612    
613        RETURN        RETURN
614        END        END

Legend:
Removed from v.1.25  
changed lines
  Added in v.1.56

  ViewVC Help
Powered by ViewVC 1.1.22