/[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.39 by heimbach, Fri Jul 13 14:26:57 2001 UTC revision 1.83 by heimbach, Wed Nov 17 15:23:35 2004 UTC
# Line 1  Line 1 
1  C $Header$  C $Header$
2  C $Name$  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    | | |-PTRACERS_READPARMS  :: multiple tracer package, see pkg/ptracers
95    C    | | |-GCHEM_READPARMS     :: tracer interface package, see pkg/gchem
96    C    | |
97    C    | |-PACKAGES_CHECK
98    C    | | |
99    C    | | |-KPP_CHECK           :: KPP Package. pkg/kpp
100    C    | | |-OBCS_CHECK          :: Open bndy Pacakge. pkg/obcs
101    C    | | |-GMREDI_CHECK        :: GM Package. pkg/gmredi
102    C    | |
103    C    | |-PACKAGES_INIT_FIXED
104    C    | | |-OBCS_INIT_FIXED     :: Open bndy Package. see pkg/obcs
105    C    | | |-FLT_INIT            :: Floats Package. see pkg/flt
106    C    | | |-GCHEM_INIT_FIXED    :: tracer interface pachage, see pkg/gchem
107    C    | |
108    C    | |-ZONAL_FILT_INIT       :: FFT filter Package. see pkg/zonal_filt
109    C    | |
110    C    | |-INI_CG2D              :: 2d con. grad solver initialisation.
111    C    | |
112    C    | |-INI_CG3D              :: 3d con. grad solver initialisation.
113    C    | |
114    C    | |-CONFIG_SUMMARY        :: Provide synopsis of kernel setup.
115    C    |                         :: Includes annotated table of kernel
116    C    |                         :: parameter settings.
117    C    |
118    C    |-CTRL_UNPACK :: Control vector support package. see pkg/ctrl
119    C    |
120    C    |-ADTHE_MAIN_LOOP :: Derivative evaluating form of main time stepping loop
121    C    !                 :: Auotmatically gerenrated by TAMC/TAF.
122    C    |
123    C    |-CTRL_PACK   :: Control vector support package. see pkg/ctrl
124    C    |
125    C    |-GRDCHK_MAIN :: Gradient check package. see pkg/grdchk
126    C    |
127    C    |-THE_MAIN_LOOP :: Main timestepping loop routine.
128    C    | |
129    C    | |-INITIALISE_VARIA :: Set the initial conditions for time evolving
130    C    | | |                :: variables
131    C    | | |
132    C    | | |-INI_LINEAR_PHISURF :: Set ref. surface Bo_surf
133    C    | | |
134    C    | | |-INI_CORI     :: Set coriolis term. zero, f-plane, beta-plane,
135    C    | | |              :: sphere optins are coded.
136    C    | | |
137    C    | | |-INI_CG2D     :: 2d con. grad solver initialisation.
138    C    | | |-INI_CG3D     :: 3d con. grad solver initialisation.
139    C    | | |-INI_MIXING   :: Initialise diapycnal diffusivity.
140    C    | | |-INI_DYNVARS  :: Initialise to zero all DYNVARS.h arrays (dynamical
141    C    | | |              :: fields).
142    C    | | |
143    C    | | |-INI_FIELDS   :: Control initialising model fields to non-zero
144    C    | | | |-INI_VEL    :: Initialize 3D flow field.
145    C    | | | |-INI_THETA  :: Set model initial temperature field.
146    C    | | | |-INI_SALT   :: Set model initial salinity field.
147    C    | | | |-INI_PSURF  :: Set model initial free-surface height/pressure.
148    C    | | | |-INI_PRESSURE :: Compute model initial hydrostatic pressure
149    C    | | | |-READ_CHECKPOINT :: Read the checkpoint
150    C    | | |
151    C    | | |-THE_CORRECTION_STEP :: Step forward to next time step.
152    C    | | | |                   :: Here applied to move restart conditions
153    C    | | | |                   :: (saved in mid timestep) to correct level in
154    C    | | | |                   :: time (only used for pre-c35).
155    C    | | | |
156    C    | | | |-CALC_GRAD_PHI_SURF :: Return DDx and DDy of surface pressure
157    C    | | | |-CORRECTION_STEP    :: Pressure correction to momentum
158    C    | | | |-CYCLE_TRACER       :: Move tracers forward in time.
159    C    | | | |-OBCS_APPLY         :: Open bndy package. see pkg/obcs
160    C    | | | |-SHAP_FILT_APPLY    :: Shapiro filter package. see pkg/shap_filt
161    C    | | | |-ZONAL_FILT_APPLY   :: FFT filter package. see pkg/zonal_filt
162    C    | | | |-CONVECTIVE_ADJUSTMENT :: Control static instability mixing.
163    C    | | | | |-FIND_RHO  :: Find adjacent densities.
164    C    | | | | |-CONVECT   :: Mix static instability.
165    C    | | | | |-TIMEAVE_CUMULATE :: Update convection statistics.
166    C    | | | |
167    C    | | | |-CALC_EXACT_ETA        :: Change SSH to flow divergence.    
168    C    | | |
169    C    | | |-CONVECTIVE_ADJUSTMENT_INI :: Control static instability mixing
170    C    | | | |                         :: Extra time history interactions.
171    C    | | | |                      
172    C    | | | |-FIND_RHO  :: Find adjacent densities.
173    C    | | | |-CONVECT   :: Mix static instability.
174    C    | | | |-TIMEAVE_CUMULATE :: Update convection statistics.
175    C    | | |
176    C    | | |-PACKAGES_INIT_VARIABLES :: Does initialisation of time evolving
177    C    | | | |                       :: package data.
178    C    | | | |
179    C    | | | |-GMREDI_INIT          :: GM package. ( see pkg/gmredi )
180    C    | | | |-KPP_INIT             :: KPP package. ( see pkg/kpp )
181    C    | | | |-KPP_OPEN_DIAGS    
182    C    | | | |-OBCS_INIT_VARIABLES  :: Open bndy. package. ( see pkg/obcs )
183    C    | | | |-PTRACERS_INIT        :: multi. tracer package,(see pkg/ptracers)
184    C    | | | |-GCHEM_INIT           : : tracer interface pkg (see pkh/gchem)
185    C    | | | |-AIM_INIT             :: Interm. atmos package. ( see pkg/aim )
186    C    | | | |-CTRL_MAP_INI         :: Control vector package.( see pkg/ctrl )
187    C    | | | |-COST_INIT            :: Cost function package. ( see pkg/cost )
188    C    | | | |-ECCO_INIT            :: ECCO support package. ( see pkg/ecco )
189    C    | | | |-INI_FORCING          :: Set model initial forcing fields.
190    C    | | |   |                    :: Either set in-line or from file as shown.
191    C    | | |   |-READ_FLD_XY_RS(zonalWindFile)
192    C    | | |   |-READ_FLD_XY_RS(meridWindFile)
193    C    | | |   |-READ_FLD_XY_RS(surfQFile)
194    C    | | |   |-READ_FLD_XY_RS(EmPmRfile)
195    C    | | |   |-READ_FLD_XY_RS(thetaClimFile)
196    C    | | |   |-READ_FLD_XY_RS(saltClimFile)
197    C    | | |   |-READ_FLD_XY_RS(surfQswFile)
198    C    | | |
199    C    | | |-CALC_SURF_DR   :: Calculate the new surface level thickness.
200    C    | | |-UPDATE_SURF_DR :: Update the surface-level thickness fraction.
201    C    | | |-UPDATE_CG2D    :: Update 2d conjugate grad. for Free-Surf.
202    C    | | |-STATE_SUMMARY    :: Summarize model prognostic variables.
203    C    | | |-TIMEAVE_STATVARS :: Time averaging package ( see pkg/timeave ).
204    C    | |
205    C    | |-WRITE_STATE      :: Controlling routine for IO to dump model state.
206    C    | | |-WRITE_REC_XYZ_RL :: Single file I/O
207    C    | | |-WRITE_FLD_XYZ_RL :: Multi-file I/O
208    C    | |
209    C    | |-MONITOR          :: Monitor state ( see pkg/monitor )
210    C    | |-CTRL_MAP_FORCING :: Control vector support package. ( see pkg/ctrl )
211    C====|>|
212    C====|>| ****************************
213    C====|>| BEGIN MAIN TIMESTEPPING LOOP
214    C====|>| ****************************
215    C====|>|
216    C/\  | |-FORWARD_STEP     :: Step forward a time-step ( AT LAST !!! )
217    C/\  | | |
218    C/\  | | |-DUMMY_IN_STEPPING :: autodiff package ( pkg/autoduff ).
219    C/\  | | |-CALC_EXACT_ETA :: Change SSH to flow divergence.
220    C/\  | | |-CALC_SURF_DR   :: Calculate the new surface level thickness.
221    C/\  | | |-EXF_GETFORCING :: External forcing package. ( pkg/exf )
222    C/\  | | |-EXTERNAL_FIELDS_LOAD :: Control loading time dep. external data.
223    C/\  | | | |                    :: Simple interpolcation between end-points
224    C/\  | | | |                    :: for forcing datasets.
225    C/\  | | | |                  
226    C/\  | | | |-EXCH :: Sync forcing. in overlap regions.
227    C/\  | | |-SEAICE_MODEL   :: Compute sea-ice terms. ( pkg/seaice )
228    C/\  | | |-FREEZE         :: Limit surface temperature.
229    C/\  | | |-GCHEM_FIELD_LOAD :: load tracer forcing fields (pkg/gchem)
230    C/\  | | |
231    C/\  | | |-THERMODYNAMICS :: theta, salt + tracer equations driver.
232    C/\  | | | |
233    C/\  | | | |-INTEGRATE_FOR_W :: Integrate for vertical velocity.
234    C/\  | | | |-OBCS_APPLY_W    :: Open bndy. package ( see pkg/obcs ).
235    C/\  | | | |-FIND_RHO        :: Calculates [rho(S,T,z)-RhoConst] of a slice
236    C/\  | | | |-GRAD_SIGMA      :: Calculate isoneutral gradients
237    C/\  | | | |-CALC_IVDC       :: Set Implicit Vertical Diffusivity for Convection
238    C/\  | | | |
239    C/\  | | | |-OBCS_CALC            :: Open bndy. package ( see pkg/obcs ).
240    C/\  | | | |-EXTERNAL_FORCING_SURF:: Accumulates appropriately dimensioned
241    C/\  | | | | |                    :: forcing terms.
242    C/\  | | | | |-PTRACERS_FORCING_SURF :: Tracer package ( see pkg/ptracers ).
243    C/\  | | | |
244    C/\  | | | |-GMREDI_CALC_TENSOR   :: GM package ( see pkg/gmredi ).
245    C/\  | | | |-GMREDI_CALC_TENSOR_DUMMY :: GM package ( see pkg/gmredi ).
246    C/\  | | | |-KPP_CALC             :: KPP package ( see pkg/kpp ).
247    C/\  | | | |-KPP_CALC_DUMMY       :: KPP package ( see pkg/kpp ).
248    C/\  | | | |-AIM_DO_ATMOS_PHYSICS :: Intermed. atmos package ( see pkg/aim ).
249    C/\  | | | |-GAD_ADVECTION        :: Generalised advection driver (multi-dim
250    C/\  | | | |                         advection case) (see pkg/gad).
251    C/\  | | | |-CALC_COMMON_FACTORS  :: Calculate common data (such as volume flux)
252    C/\  | | | |-CALC_DIFFUSIVITY     :: Calculate net vertical diffusivity
253    C/\  | | | | |
254    C/\  | | | | |-GMREDI_CALC_DIFF   :: GM package ( see pkg/gmredi ).
255    C/\  | | | | |-KPP_CALC_DIFF      :: KPP package ( see pkg/kpp ).
256    C/\  | | | |
257    C/\  | | | |-CALC_GT              :: Calculate the temperature tendency terms
258    C/\  | | | | |
259    C/\  | | | | |-GAD_CALC_RHS       :: Generalised advection package
260    C/\  | | | | | |                  :: ( see pkg/gad )
261    C/\  | | | | | |-KPP_TRANSPORT_T  :: KPP non-local transport ( see pkg/kpp ).
262    C/\  | | | | |
263    C/\  | | | | |-EXTERNAL_FORCING_T :: Problem specific forcing for temperature.
264    C/\  | | | | |-ADAMS_BASHFORTH2   :: Extrapolate tendencies forward in time.
265    C/\  | | | | |-FREESURF_RESCALE_G :: Re-scale Gt for free-surface height.
266    C/\  | | | |
267    C/\  | | | |-TIMESTEP_TRACER      :: Step tracer field forward in time
268    C/\  | | | |
269    C/\  | | | |-CALC_GS              :: Calculate the salinity tendency terms
270    C/\  | | | | |
271    C/\  | | | | |-GAD_CALC_RHS       :: Generalised advection package
272    C/\  | | | | | |                  :: ( see pkg/gad )
273    C/\  | | | | | |-KPP_TRANSPORT_S  :: KPP non-local transport ( see pkg/kpp ).
274    C/\  | | | | |
275    C/\  | | | | |-EXTERNAL_FORCING_S :: Problem specific forcing for salt.
276    C/\  | | | | |-ADAMS_BASHFORTH2   :: Extrapolate tendencies forward in time.
277    C/\  | | | | |-FREESURF_RESCALE_G :: Re-scale Gs for free-surface height.
278    C/\  | | | |
279    C/\  | | | |-TIMESTEP_TRACER      :: Step tracer field forward in time
280    C/\  | | | |
281    C/\  | | | |-TIMESTEP_TRACER      :: Step tracer field forward in time
282    C/\  | | | |
283    C/\  | | | |-PTRACERS_INTEGRATE   :: Integrate other tracer(s) ( see pkg/ptracers ).
284    C/\  | | | | |
285    C/\  | | | | |-GAD_CALC_RHS       :: Generalised advection package
286    C/\  | | | | | |                  :: ( see pkg/gad )
287    C/\  | | | | | |-KPP_TRANSPORT_PTR:: KPP non-local transport ( see pkg/kpp ).
288    C/\  | | | | |
289    C/\  | | | | |-PTRACERS_FORCING   :: Problem specific forcing for tracer.
290    C/\  | | | | |-GCHEM_FORCING_INT  :: tracer forcing for gchem pkg (if all
291    C/\  | | | | |                       tendancy terms calcualted together)
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/\  | | | |
298    C/\  | | | |-IMPLDIFF             :: Solve vertical implicit diffusion equation.
299    C/\  | | | |-OBCS_APPLY_TS        :: Open bndy. package (see pkg/obcs ).
300    C/\  | | | |
301    C/\  | | | |-AIM_AIM2DYN_EXCHANGES :: Inetermed. atmos (see pkg/aim).
302    C/\  | | | |-EXCH                 :: Update overlaps
303    C/\  | | |
304    C/\  | | |-DYNAMICS       :: Momentum equations driver.
305    C/\  | | | |
306    C/\  | | | |-CALC_GRAD_PHI_SURF :: Calculate the gradient of the surface
307    C/\  | | | |                       Potential anomaly.
308    C/\  | | | |-CALC_VISCOSITY     :: Calculate net vertical viscosity
309    C/\  | | | | |-KPP_CALC_VISC    :: KPP package ( see pkg/kpp ).
310    C/\  | | | |                                                      
311    C/\  | | | |-CALC_PHI_HYD       :: Integrate the hydrostatic relation.
312    C/\  | | | |-MOM_FLUXFORM       :: Flux form mom eqn. package ( see
313    C/\  | | | |                       pkg/mom_fluxform ).
314    C/\  | | | |-MOM_VECINV         :: Vector invariant form mom eqn. package ( see
315    C/\  | | | |                       pkg/mom_vecinv   ).
316    C/\  | | | |-TIMESTEP           :: Step momentum fields forward in time
317    C/\  | | | |-OBCS_APPLY_UV      :: Open bndy. package (see pkg/obcs ).
318    C/\  | | | |
319    C/\  | | | |-IMPLDIFF           :: Solve vertical implicit diffusion equation.
320    C/\  | | | |-OBCS_APPLY_UV      :: Open bndy. package (see pkg/obcs ).
321    C/\  | | | |
322    C/\  | | | |-TIMEAVE_CUMUL_1T   :: Time averaging package ( see pkg/timeave ).
323    C/\  | | | |-TIMEAVE_CUMUATE    :: Time averaging package ( see pkg/timeave ).
324    C/\  | | | |-DEBUG_STATS_RL     :: Quick debug package ( see pkg/debug ).
325    C/\  | | |
326    C/\  | | |-CALC_GW        :: vert. momentum tendency terms ( NH, QH only ).
327    C/\  | | |
328    C/\  | | |-UPDATE_SURF_DR :: Update the surface-level thickness fraction.
329    C/\  | | |
330    C/\  | | |-UPDATE_CG2D    :: Update 2d conjugate grad. for Free-Surf.
331    C/\  | | |
332    C/\  | | |-SOLVE_FOR_PRESSURE           :: Find surface pressure.
333    C/\  | | | |-CALC_DIV_GHAT     :: Form the RHS of the surface pressure eqn.
334    C/\  | | | |-CG2D              :: Two-dim pre-con. conjugate-gradient.
335    C/\  | | | |-CG3D              :: Three-dim pre-con. conjugate-gradient solver.
336    C/\  | | |
337    C/\  | | |-THE_CORRECTION_STEP          :: Step forward to next time step.
338    C/\  | | | |
339    C/\  | | | |-CALC_GRAD_PHI_SURF :: Return DDx and DDy of surface pressure
340    C/\  | | | |-CORRECTION_STEP    :: Pressure correction to momentum
341    C/\  | | | |-CYCLE_TRACER       :: Move tracers forward in time.
342    C/\  | | | |-OBCS_APPLY         :: Open bndy package. see pkg/obcs
343    C/\  | | | |-SHAP_FILT_APPLY    :: Shapiro filter package. see pkg/shap_filt
344    C/\  | | | |-ZONAL_FILT_APPLY   :: FFT filter package. see pkg/zonal_filt
345    C/\  | | | |-CONVECTIVE_ADJUSTMENT :: Control static instability mixing.
346    C/\  | | | | |-FIND_RHO  :: Find adjacent densities.
347    C/\  | | | | |-CONVECT   :: Mix static instability.
348    C/\  | | | | |-TIMEAVE_CUMULATE :: Update convection statistics.
349    C/\  | | | |
350    C/\  | | | |-CALC_EXACT_ETA        :: Change SSH to flow divergence.    
351    C/\  | | |
352    C/\  | | |-DO_FIELDS_BLOCKING_EXCHANGES :: Sync up overlap regions.
353    C/\  | | | |-EXCH                                                  
354    C/\  | | |
355    C/\  | | |-GCHEM_FORCING_SEP :: tracer forcing for gchem pkg (if
356    C/\  | | |                      tracer dependent tendencies calculated
357    C/\  | | |                      separatly)
358    C/\  | | |
359    C/\  | | |-FLT_MAIN         :: Float package ( pkg/flt ).
360    C/\  | | |
361    C/\  | | |-MONITOR          :: Monitor package ( pkg/monitor ).
362    C/\  | | |
363    C/\  | | |-DO_THE_MODEL_IO  :: Standard diagnostic I/O.
364    C/\  | | | |-WRITE_STATE    :: Core state I/O
365    C/\  | | | |-TIMEAVE_STATV_WRITE :: Time averages. see pkg/timeave
366    C/\  | | | |-AIM_WRITE_DIAGS     :: Intermed. atmos diags. see pkg/aim
367    C/\  | | | |-GMREDI_DIAGS        :: GM diags. see pkg/gmredi
368    C/\  | | | |-KPP_DO_DIAGS        :: KPP diags. see pkg/kpp
369    C/\  | | | |-SBO_CALC            :: SBO diags. see pkg/sbo
370    C/\  | | | |-SBO_DIAGS           :: SBO diags. see pkg/sbo
371    C/\  | | | |-SEAICE_DO_DIAGS     :: SEAICE diags. see pkg/seaice
372    C/\  | | | |-GCHEM_DIAGS         :: gchem diags. see pkg/gchem
373    C/\  | | |
374    C/\  | | |-WRITE_CHECKPOINT :: Do I/O for restart files.
375    C/\  | |
376    C/\  | |-COST_TILE        :: Cost function package. ( see pkg/cost )
377    C<===|=|
378    C<===|=| **************************
379    C<===|=| END MAIN TIMESTEPPING LOOP
380    C<===|=| **************************
381    C<===|=|
382    C    | |-COST_FINAL       :: Cost function package. ( see pkg/cost )
383    C    |
384    C    |-WRITE_CHECKPOINT :: Final state storage, for restart.
385    C    |
386    C    |-TIMER_PRINTALL :: Computational timing summary
387    C    |
388    C    |-COMM_STATS     :: Summarise inter-proc and inter-thread communication
389    C                     :: events.
390    C \ev
391    C
392    C
393    CEOI
394    
395    
396    #include "AD_CONFIG.h"
397    #include "PACKAGES_CONFIG.h"
398  #include "CPP_OPTIONS.h"  #include "CPP_OPTIONS.h"
399    
400    CBOP
401    
402    C     !ROUTINE: THE_MODEL_MAIN
403    
404    C     !INTERFACE:
405        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     \==========================================================/  
406        IMPLICIT NONE        IMPLICIT NONE
407  C  
408    C     !DESCRIPTION: \bv
409    C     *==========================================================*
410    C     | SUBROUTINE THE_MODEL_MAIN                                
411    C     | o Master controlling routine for model using the MITgcm  
412    C     |   UV parallel wrapper.                                    
413    C     *==========================================================*
414    C     | THE_MODEL_MAIN is invoked by the MITgcm UV parallel      
415    C     | wrapper with a single integer argument "myThid". This    
416    C     | variable identifies the thread number of an instance of  
417    C     | THE_MODEL_MAIN. Each instance of THE_MODEL_MAIN works    
418    C     | on a particular region of the models domain and          
419    C     | synchronises with other instances as necessary. The      
420    C     | routine has to "understand" the MITgcm parallel          
421    C     | environment and the numerical algorithm. Editing this    
422    C     | routine is best done with some knowledge of both aspects.
423    C     | Notes                                                    
424    C     | =====                                                    
425    C     | C*P* comments indicating place holders for which code is  
426    C     |      presently being developed.                          
427    C     *==========================================================*
428    C     \ev
429    
430    C     !CALLING SEQUENCE:
431    C     THE_MODEL_MAIN()
432    C       |
433    C       |
434    C       |--INITIALISE_FIXED
435    C       |   o Set model configuration (fixed arrays)
436    C       |     Topography, hydrography, timestep, grid, etc..
437    C       |
438    C       |--CTRL_UNPACK      o Derivative mode. Unpack control vector.
439    C       |
440    C       |--ADTHE_MAIN_LOOP  o Main timestepping loop for combined
441    C       |                     prognostic and reverse mode integration.
442    C       |
443    C       |--CTRL_PACK        o Derivative mode. Unpack control vector.
444    C       |
445    C       |--GRDCHK_MAIN      o Gradient check control routine.
446    C       |
447    C       |--THE_MAIN_LOOP    o Main timestepping loop for pure prognostic
448    C       |                     integration.
449    C       |
450    C       |--WRITE_CHECKPOINT o Write retsart information.
451    C       |
452    C       |--TIMER_PRINTALL   o Print out timing statistics.
453    C       |
454    C       |--COMM_STATS       o Print out communication statistics.
455    
456    C     !USES:
457  C     == Global variables ===  C     == Global variables ===
458  #include "SIZE.h"  #include "SIZE.h"
459  #include "EEPARAMS.h"  #include "EEPARAMS.h"
460  #include "PARAMS.h"  #include "PARAMS.h"
461  #include "DYNVARS.h"  #include "DYNVARS.h"
462  #ifdef ALLOW_NONHYDROSTATIC  #ifdef ALLOW_NONHYDROSTATIC
463  #include "CG3D.h"  # include "CG3D.h"
464  #endif  #endif
465    
466  #ifdef ALLOW_AUTODIFF_TAMC  #ifdef ALLOW_AUTODIFF_TAMC
467  #include "tamc.h"  # include "tamc.h"
468  #include "cost.h"  # include "optim.h"
 #include "adcost.h"  
469  #endif  #endif
470    
471    C     !INPUT/OUTPUT PARAMETERS:
472  C     == Routine arguments ==  C     == Routine arguments ==
473  C     myThid - Thread number for this instance of the routine.  C     myThid - Thread number for this instance of the routine.
474        INTEGER myThid          INTEGER myThid  
475    
476    C     !LOCAL VARIABLES:
477  C     == Local variables ==  C     == Local variables ==
478  C     Note: Under the multi-threaded model myCurrentIter and  C     Note: Under the multi-threaded model myCurrentIter and
479  C           myCurrentTime are local variables passed around as routine  C           myCurrentTime are local variables passed around as routine
# Line 54  C     myCurrentTime - Time counter for t Line 484  C     myCurrentTime - Time counter for t
484  C     myCurrentIter - Iteration counter for this thread  C     myCurrentIter - Iteration counter for this thread
485        INTEGER myCurrentIter        INTEGER myCurrentIter
486        _RL     myCurrentTime        _RL     myCurrentTime
487          logical  exst
488          logical  lastdiva
489    CEOP
490    c--   set default:
491          lastdiva = .TRUE.
492    
493    #ifdef ALLOW_DEBUG
494          IF (debugMode) CALL DEBUG_ENTER('THE_MODEL_MAIN',myThid)
495    #endif
496    
497  C--   This timer encompasses the whole code  C--   This timer encompasses the whole code
498        CALL TIMER_START('ALL                [THE_MODEL_MAIN]',myThid)        CALL TIMER_START('ALL                    [THE_MODEL_MAIN]',myThid)
499    
500    #ifdef ALLOW_DEBUG
501          IF (debugMode) CALL DEBUG_CALL('INITIALISE_FIXED',myThid)
502    #endif
503    
504  C--   Set model configuration (fixed arrays)  C--   Set model configuration (fixed arrays)
505        CALL TIMER_START('INITIALISE_FIXED   [THE_MODEL_MAIN]',myThid)        CALL TIMER_START('INITIALISE_FIXED       [THE_MODEL_MAIN]',myThid)
506        CALL INITIALISE_FIXED( myThid )        CALL INITIALISE_FIXED( myThid )
507        CALL TIMER_STOP ('INITIALISE_FIXED   [THE_MODEL_MAIN]',myThid)        CALL TIMER_STOP ('INITIALISE_FIXED       [THE_MODEL_MAIN]',myThid)
508    
509        myCurrentTime = startTime        myCurrentTime = startTime
510        myCurrentIter = nIter0        myCurrentIter = nIter0
511    
512  #ifdef ALLOW_ADJOINT_RUN  #if ( defined (ALLOW_ADMTLM) )
513    c
514          STOP 'should never get here; ADMTLM_DSVD calls ADMTLM_DRIVER'
515    c
516    #elif ( defined (ALLOW_AUTODIFF))
517    
518    # ifndef EXCLUDE_CTRL_PACK
519        _BEGIN_MASTER( mythid )        _BEGIN_MASTER( mythid )
520        IF (myProcId .eq. 0) THEN        IF (myProcId .eq. 0) THEN
521           CALL CTRL_UNPACK( mycurrentiter, mycurrenttime, mythid )           inquire( file='costfinal', exist=exst )
522             IF ( .NOT. exst .AND. niter0 .EQ. 0 ) THEN
523                IF ( optimcycle.NE.0 ) THEN
524                   CALL TIMER_START('CTRL_UNPACK   [THE_MODEL_MAIN]',mythid)
525                   CALL CTRL_UNPACK( .TRUE. , mythid )
526                   CALL TIMER_STOP ('CTRL_UNPACK   [THE_MODEL_MAIN]',mythid)
527                ENDIF
528                IF ( optimcycle.EQ.0 .AND. mycurrentiter.EQ.niter0 ) THEN
529                   CALL TIMER_START('CTRL_PACK     [THE_MODEL_MAIN]',mythid)
530                   CALL CTRL_PACK( .TRUE. , mythid )
531                   CALL TIMER_STOP ('CTRL_PACK     [THE_MODEL_MAIN]',mythid)
532                ENDIF
533             ENDIF
534        ENDIF        ENDIF
535        _END_MASTER( mythid )        _END_MASTER( mythid )
536        _BARRIER        _BARRIER
537    # endif /* EXCLUDE_CTRL_PACK */
538    
539        fc   = 0.0        CALL COST_DEPENDENT_INIT ( mythid )
540        adfc = 1.0        _BARRIER
541    
542    # if ( defined (ALLOW_TANGENTLINEAR_RUN) )
543    c
544          CALL TIMER_START('G_THE_MAIN_LOOP           [TANGENT RUN]',mythid)
545          CALL G_THE_MAIN_LOOP ( myCurrentTime, myCurrentIter, myThid )
546          CALL TIMER_STOP ('G_THE_MAIN_LOOP           [TANGENT RUN]',mythid)
547    c
548    # elif ( defined (ALLOW_ADJOINT_RUN) || \
549             defined (ALLOW_ECCO_OPTIMIZATION) )
550    c
551    #  ifdef ALLOW_DIVIDED_ADJOINT
552    c-- The following assumes the TAF option '-pure'
553          inquire( file='costfinal', exist=exst )
554          IF ( .NOT. exst) THEN
555             CALL TIMER_START('MDTHE_MAIN_LOOP            [MD RUN]', mythid)
556             CALL MDTHE_MAIN_LOOP ( myCurrentTime, myCurrentIter, mythid )
557             CALL TIMER_STOP ('MDTHE_MAIN_LOOP            [MD RUN]', mythid)
558             CALL COST_FINAL_STORE ( mythid, lastdiva )
559          ELSE
560             CALL TIMER_START('ADTHE_MAIN_LOOP       [ADJOINT RUN]', mythid)
561             CALL ADTHE_MAIN_LOOP ( myCurrentTime, myCurrentIter, mythid )
562             CALL TIMER_STOP ('ADTHE_MAIN_LOOP       [ADJOINT RUN]', mythid)
563             CALL COST_FINAL_RESTORE ( mythid, lastdiva )
564          ENDIF
565    c--
566    #  else /* ALLOW_DIVIDED_ADJOINT undef */
567        CALL TIMER_START('ADTHE_MAIN_LOOP          [ADJOINT RUN]', mythid)        CALL TIMER_START('ADTHE_MAIN_LOOP          [ADJOINT RUN]', mythid)
568        CALL ADTHE_MAIN_LOOP ( mythid )        CALL ADTHE_MAIN_LOOP ( myCurrentTime, myCurrentIter, mythid )
569    cph      CALL ADTHE_MAIN_LOOP ( mythid )
570        CALL TIMER_STOP ('ADTHE_MAIN_LOOP          [ADJOINT RUN]', mythid)        CALL TIMER_STOP ('ADTHE_MAIN_LOOP          [ADJOINT RUN]', mythid)
571        _BARRIER  #  endif /* ALLOW_DIVIDED_ADJOINT */
572    c
573    # endif
574    
575    # ifndef EXCLUDE_CTRL_PACK
576        _BEGIN_MASTER( mythid )        _BEGIN_MASTER( mythid )
577        IF (myProcId .eq. 0) THEN        IF ( myProcId .eq. 0 .AND. lastdiva ) THEN
578           call CTRL_PACK( mycurrentiter, mycurrenttime, mythid )           CALL TIMER_START('CTRL_PACK           [THE_MODEL_MAIN]',mythid)
579             call CTRL_PACK( .FALSE. , mythid )
580             CALL TIMER_STOP ('CTRL_PACK           [THE_MODEL_MAIN]',mythid)
581        ENDIF        ENDIF
582        _END_MASTER( mythid )        _END_MASTER( mythid )
583        _BARRIER        _BARRIER
584    # endif /* EXCLUDE_CTRL_PACK */
585    
586  #ifdef ALLOW_GRADIENT_CHECK  
587        if (useGrdchk) then  # ifdef ALLOW_GRDCHK
588           CALL TIMER_START('GRDCHK_MAIN          [ADJOINT RUN]', mythid)        IF ( useGrdchk .AND. lastdiva ) THEN
589             CALL TIMER_START('GRDCHK_MAIN         [THE_MODEL_MAIN]',mythid)
590           CALL GRDCHK_MAIN( mythid )           CALL GRDCHK_MAIN( mythid )
591           CALL TIMER_STOP ('GRDCHK_MAIN          [ADJOINT RUN]', mythid)           CALL TIMER_STOP ('GRDCHK_MAIN         [THE_MODEL_MAIN]',mythid)
592           _BARRIER           _BARRIER
593        end if        ENDIF
594  #endif  # endif
   
 #else /* ALLOW_ADJOINT_RUN undef */  
595    
596  C--   Call time stepping loop of full model  #else /* ALL AD-related undef */
       CALL TIMER_START('THE_MAIN_LOOP      [THE_MODEL_MAIN]',myThid)  
       CALL THE_MAIN_LOOP(myCurrentTime, myCurrentIter, myThid )  
       CALL TIMER_STOP ('THE_MAIN_LOOP      [THE_MODEL_MAIN]',myThid)  
597    
598  #endif /* ALLOW_ADJOINT_RUN */  #ifdef ALLOW_DEBUG
599          IF (debugMode) CALL DEBUG_CALL('THE_MAIN_LOOP',myThid)
600    #endif
601    
602  C--   Final checkpoint (incase the in-loop checkpoint was missed)  C--   Call time stepping loop of full model
603        CALL TIMER_START('WRITE_CHECKPOINT   [THE_MODEL_MAIN]',myThid)        CALL TIMER_START('THE_MAIN_LOOP          [THE_MODEL_MAIN]',myThid)
604          CALL THE_MAIN_LOOP( myCurrentTime, myCurrentIter, myThid )
605          CALL TIMER_STOP ('THE_MAIN_LOOP          [THE_MODEL_MAIN]',myThid)
606    
607    #endif /* ALLOW_TANGENTLINEAR_RUN ALLOW_ADJOINT_RUN ALLOW_ADMTLM_RUN */
608    
609    C--   Final checkpoint (in case the in-loop checkpoint was missed)
610          CALL TIMER_START('WRITE_CHECKPOINT       [THE_MODEL_MAIN]',myThid)
611          CALL PACKAGES_WRITE_PICKUP(
612         I        .TRUE., myCurrentTime, myCurrentIter, myThid )
613        CALL WRITE_CHECKPOINT(        CALL WRITE_CHECKPOINT(
614       &        .TRUE., myCurrentTime, myCurrentIter, myThid )       I        .TRUE., myCurrentTime, myCurrentIter, myThid )
615        CALL TIMER_STOP ('WRITE_CHECKPOINT   [THE_MODEL_MAIN]',myThid)        CALL TIMER_STOP ('WRITE_CHECKPOINT       [THE_MODEL_MAIN]',myThid)
616    
617          CALL TIMER_STOP ('ALL                    [THE_MODEL_MAIN]',myThid)
618    
619        CALL TIMER_STOP ('ALL                [THE_MODEL_MAIN]',myThid)  #ifdef ALLOW_MNC
620          IF (useMNC) THEN
621    C       Close all open NetCDF files
622            _BEGIN_MASTER( mythid )
623            CALL MNC_FILE_CLOSE_ALL( myThid )
624            _END_MASTER( mythid )
625          ENDIF
626    #endif
627    
628  C--   Write timer statistics  C--   Write timer statistics
629        IF ( myThid .EQ. 1 ) THEN        IF ( myThid .EQ. 1 ) THEN
# Line 122  C--   Write timer statistics Line 631  C--   Write timer statistics
631         CALL COMM_STATS         CALL COMM_STATS
632        ENDIF        ENDIF
633    
634    #ifdef ALLOW_DEBUG
635          IF (debugMode) CALL DEBUG_LEAVE('THE_MODEL_MAIN',myThid)
636    #endif
637    
638        RETURN        RETURN
639        END        END

Legend:
Removed from v.1.39  
changed lines
  Added in v.1.83

  ViewVC Help
Powered by ViewVC 1.1.22