/[MITgcm]/MITgcm_contrib/heimbach/OpenAD/code_shallow_openad3/the_model_main.F
ViewVC logotype

Annotation of /MITgcm_contrib/heimbach/OpenAD/code_shallow_openad3/the_model_main.F

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


Revision 1.4 - (hide annotations) (download)
Wed Jan 17 17:02:51 2007 UTC (19 years, 9 months ago) by utke
Branch: MAIN
Changes since 1.3: +40 -32 lines
partial resync with trunk

1 utke 1.4 C $Header: /u/gcmpack/MITgcm_contrib/heimbach/OpenAD/code_shallow_openad3/the_model_main.F,v 1.3 2007/01/11 16:54:08 utke Exp $
2 utke 1.1
3     CBOI
4     C
5     C !TITLE: MITGCM KERNEL CODE SYNOPSIS
6     C !AUTHORS: mitgcm developers ( support@mitgcm.org )
7     C !AFFILIATION: Massachussetts Institute of Technology
8     C !DATE:
9     C !INTRODUCTION: Kernel dynamical routines
10     C This document summarises MITgcm code under the model/ subdirectory.
11     C The code under model/ ( src/ and inc/ ) contains most of
12     C the driver routines for the baseline forms of the kernel equations in the
13     C MITgcm algorithm. Numerical code for much of the baseline forms of
14     C these equations is also under the model/ directory. Other numerical code
15     C used for the kernel equations is contained in packages in the pkg/
16     C directory tree.
17     C Code for auxilliary equations and alternate dicretizations of the kernel
18     C equations and algorithm can also be found in the pkg/ directory tree.
19     C
20     C \subsection{Getting Help and Reporting Errors and Problems}
21     C If you have questions please e-mail support@mitgcm.org. We also welcome
22     C reports of errors and inconsistencies in the code or in the accompanying
23     C documentation. Please feel free to send these
24     C to support@mitgcm.org. For further information and to review
25     C problems reported to support@mitgcm.org please visit http://mitgcm.org.
26     C
27     C \subsection{MITgcm Kernel Code Calling Sequence}
28     C \bv
29     C
30     C Invocation from WRAPPER level...
31     C :
32     C :
33     C |
34     C |-THE_MODEL_MAIN :: Primary driver for the MITgcm algorithm
35     C | :: Called from WRAPPER level numerical
36 utke 1.4 C | :: code invocation routine. On entry
37 utke 1.1 C | :: to THE_MODEL_MAIN separate thread and
38     C | :: separate processes will have been established.
39     C | :: Each thread and process will have a unique ID
40     C | :: but as yet it will not be associated with a
41     C | :: specific region in decomposed discrete space.
42     C |
43     C |-INITIALISE_FIXED :: Set fixed model arrays such as topography,
44     C | | :: grid, solver matrices etc..
45     C | |
46     C | |-INI_PARMS :: Routine to set kernel model parameters.
47     C | | :: By default kernel parameters are read from file
48     C | | :: "data" in directory in which code executes.
49     C | |
50 utke 1.4 C | |-MON_INIT :: Initializes monitor package ( see pkg/monitor )
51 utke 1.1 C | |
52 utke 1.4 C | |-INI_GRID :: Control grid array (vert. and hori.) initialization.
53 utke 1.1 C | | | :: Grid arrays are held and described in GRID.h.
54     C | | |
55 utke 1.4 C | | |-INI_VERTICAL_GRID :: Initialize vertical grid arrays.
56 utke 1.1 C | | |
57 utke 1.4 C | | |-INI_CARTESIAN_GRID :: Cartesian horiz. grid initialization
58 utke 1.1 C | | | :: (calculate grid from kernel parameters).
59     C | | |
60     C | | |-INI_SPHERICAL_POLAR_GRID :: Spherical polar horiz. grid
61 utke 1.4 C | | | :: initialization (calculate grid from
62 utke 1.1 C | | | :: kernel parameters).
63     C | | |
64     C | | |-INI_CURVILINEAR_GRID :: General orthogonal, structured horiz.
65 utke 1.4 C | | :: grid initializations. ( input from raw
66 utke 1.1 C | | :: grid files, LONC.bin, DXF.bin etc... )
67     C | |
68     C | |-INI_DEPTHS :: Read (from "bathyFile") or set bathymetry/orgography.
69     C | |
70     C | |-INI_MASKS_ETC :: Derive horizontal and vertical cell fractions and
71     C | | :: land masking for solid-fluid boundaries.
72     C | |
73     C | |-INI_LINEAR_PHSURF :: Set ref. surface Bo_surf
74     C | |
75     C | |-INI_CORI :: Set coriolis term. zero, f-plane, beta-plane,
76 utke 1.4 C | | :: sphere options are coded.
77 utke 1.1 C | |
78     C | |-PACAKGES_BOOT :: Start up the optional package environment.
79     C | | :: Runtime selection of active packages.
80     C | |
81     C | |-PACKAGES_READPARMS :: Call active package internal parameter load.
82     C | | |
83     C | | |-GMREDI_READPARMS :: GM Package. see pkg/gmredi
84     C | | |-KPP_READPARMS :: KPP Package. see pkg/kpp
85     C | | |-SHAP_FILT_READPARMS :: Shapiro filter package. see pkg/shap_filt
86     C | | |-OBCS_READPARMS :: Open bndy package. see pkg/obcs
87     C | | |-AIM_READPARMS :: Intermediate Atmos. pacakage. see pkg/aim
88     C | | |-COST_READPARMS :: Cost function package. see pkg/cost
89     C | | |-CTRL_INIT :: Control vector support package. see pkg/ctrl
90     C | | |-OPTIM_READPARMS :: Optimisation support package. see pkg/ctrl
91     C | | |-GRDCHK_READPARMS :: Gradient check package. see pkg/grdchk
92     C | | |-ECCO_READPARMS :: ECCO Support Package. see pkg/ecco
93     C | | |-PTRACERS_READPARMS :: multiple tracer package, see pkg/ptracers
94     C | | |-GCHEM_READPARMS :: tracer interface package, see pkg/gchem
95     C | |
96     C | |-PACKAGES_CHECK
97     C | | |
98     C | | |-KPP_CHECK :: KPP Package. pkg/kpp
99     C | | |-OBCS_CHECK :: Open bndy Pacakge. pkg/obcs
100     C | | |-GMREDI_CHECK :: GM Package. pkg/gmredi
101     C | |
102     C | |-PACKAGES_INIT_FIXED
103     C | | |-OBCS_INIT_FIXED :: Open bndy Package. see pkg/obcs
104     C | | |-FLT_INIT :: Floats Package. see pkg/flt
105     C | | |-GCHEM_INIT_FIXED :: tracer interface pachage, see pkg/gchem
106     C | |
107     C | |-ZONAL_FILT_INIT :: FFT filter Package. see pkg/zonal_filt
108     C | |
109 utke 1.4 C | |-INI_CG2D :: 2d con. grad solver initialization.
110 utke 1.1 C | |
111 utke 1.4 C | |-INI_CG3D :: 3d con. grad solver initialization.
112 utke 1.1 C | |
113     C | |-CONFIG_SUMMARY :: Provide synopsis of kernel setup.
114     C | :: Includes annotated table of kernel
115     C | :: parameter settings.
116     C |
117     C |-CTRL_UNPACK :: Control vector support package. see pkg/ctrl
118     C |
119     C |-ADTHE_MAIN_LOOP :: Derivative evaluating form of main time stepping loop
120 utke 1.4 C ! :: Auotmatically generated by TAMC/TAF.
121 utke 1.1 C |
122     C |-CTRL_PACK :: Control vector support package. see pkg/ctrl
123     C |
124     C |-GRDCHK_MAIN :: Gradient check package. see pkg/grdchk
125     C |
126     C |-THE_MAIN_LOOP :: Main timestepping loop routine.
127     C | |
128     C | |-INITIALISE_VARIA :: Set the initial conditions for time evolving
129     C | | | :: variables
130     C | | |
131     C | | |-INI_LINEAR_PHISURF :: Set ref. surface Bo_surf
132     C | | |
133     C | | |-INI_CORI :: Set coriolis term. zero, f-plane, beta-plane,
134 utke 1.4 C | | | :: sphere options are coded.
135 utke 1.1 C | | |
136 utke 1.4 C | | |-INI_CG2D :: 2d con. grad solver initialization.
137     C | | |-INI_CG3D :: 3d con. grad solver initialization.
138     C | | |-INI_MIXING :: Initialize diapycnal diffusivity.
139     C | | |-INI_DYNVARS :: Initialize to zero all DYNVARS.h arrays (dynamical
140 utke 1.1 C | | | :: fields).
141     C | | |
142 utke 1.4 C | | |-INI_FIELDS :: Control initializing model fields to non-zero
143 utke 1.1 C | | | |-INI_VEL :: Initialize 3D flow field.
144     C | | | |-INI_THETA :: Set model initial temperature field.
145     C | | | |-INI_SALT :: Set model initial salinity field.
146     C | | | |-INI_PSURF :: Set model initial free-surface height/pressure.
147     C | | | |-INI_PRESSURE :: Compute model initial hydrostatic pressure
148     C | | | |-READ_CHECKPOINT :: Read the checkpoint
149     C | | |
150     C | | |-THE_CORRECTION_STEP :: Step forward to next time step.
151     C | | | | :: Here applied to move restart conditions
152     C | | | | :: (saved in mid timestep) to correct level in
153     C | | | | :: time (only used for pre-c35).
154     C | | | |
155     C | | | |-CALC_GRAD_PHI_SURF :: Return DDx and DDy of surface pressure
156     C | | | |-CORRECTION_STEP :: Pressure correction to momentum
157     C | | | |-CYCLE_TRACER :: Move tracers forward in time.
158     C | | | |-OBCS_APPLY :: Open bndy package. see pkg/obcs
159     C | | | |-SHAP_FILT_APPLY :: Shapiro filter package. see pkg/shap_filt
160     C | | | |-ZONAL_FILT_APPLY :: FFT filter package. see pkg/zonal_filt
161     C | | | |-CONVECTIVE_ADJUSTMENT :: Control static instability mixing.
162     C | | | | |-FIND_RHO :: Find adjacent densities.
163     C | | | | |-CONVECT :: Mix static instability.
164     C | | | | |-TIMEAVE_CUMULATE :: Update convection statistics.
165     C | | | |
166     C | | | |-CALC_EXACT_ETA :: Change SSH to flow divergence.
167     C | | |
168     C | | |-CONVECTIVE_ADJUSTMENT_INI :: Control static instability mixing
169     C | | | | :: Extra time history interactions.
170     C | | | |
171     C | | | |-FIND_RHO :: Find adjacent densities.
172     C | | | |-CONVECT :: Mix static instability.
173     C | | | |-TIMEAVE_CUMULATE :: Update convection statistics.
174     C | | |
175 utke 1.4 C | | |-PACKAGES_INIT_VARIABLES :: Does initialization of time evolving
176 utke 1.1 C | | | | :: package data.
177     C | | | |
178     C | | | |-GMREDI_INIT :: GM package. ( see pkg/gmredi )
179     C | | | |-KPP_INIT :: KPP package. ( see pkg/kpp )
180     C | | | |-KPP_OPEN_DIAGS
181     C | | | |-OBCS_INIT_VARIABLES :: Open bndy. package. ( see pkg/obcs )
182     C | | | |-PTRACERS_INIT :: multi. tracer package,(see pkg/ptracers)
183 utke 1.4 C | | | |-GCHEM_INIT :: tracer interface pkg (see pkh/gchem)
184 utke 1.1 C | | | |-AIM_INIT :: Interm. atmos package. ( see pkg/aim )
185     C | | | |-CTRL_MAP_INI :: Control vector package.( see pkg/ctrl )
186     C | | | |-COST_INIT :: Cost function package. ( see pkg/cost )
187     C | | | |-ECCO_INIT :: ECCO support package. ( see pkg/ecco )
188     C | | | |-INI_FORCING :: Set model initial forcing fields.
189     C | | | | :: Either set in-line or from file as shown.
190     C | | | |-READ_FLD_XY_RS(zonalWindFile)
191     C | | | |-READ_FLD_XY_RS(meridWindFile)
192     C | | | |-READ_FLD_XY_RS(surfQFile)
193     C | | | |-READ_FLD_XY_RS(EmPmRfile)
194     C | | | |-READ_FLD_XY_RS(thetaClimFile)
195     C | | | |-READ_FLD_XY_RS(saltClimFile)
196     C | | | |-READ_FLD_XY_RS(surfQswFile)
197     C | | |
198     C | | |-CALC_SURF_DR :: Calculate the new surface level thickness.
199     C | | |-UPDATE_SURF_DR :: Update the surface-level thickness fraction.
200     C | | |-UPDATE_CG2D :: Update 2d conjugate grad. for Free-Surf.
201     C | | |-STATE_SUMMARY :: Summarize model prognostic variables.
202     C | | |-TIMEAVE_STATVARS :: Time averaging package ( see pkg/timeave ).
203     C | |
204     C | |-WRITE_STATE :: Controlling routine for IO to dump model state.
205     C | | |-WRITE_REC_XYZ_RL :: Single file I/O
206     C | | |-WRITE_FLD_XYZ_RL :: Multi-file I/O
207     C | |
208     C | |-MONITOR :: Monitor state ( see pkg/monitor )
209     C | |-CTRL_MAP_FORCING :: Control vector support package. ( see pkg/ctrl )
210     C====|>|
211     C====|>| ****************************
212     C====|>| BEGIN MAIN TIMESTEPPING LOOP
213     C====|>| ****************************
214     C====|>|
215     C/\ | |-FORWARD_STEP :: Step forward a time-step ( AT LAST !!! )
216     C/\ | | |
217     C/\ | | |-DUMMY_IN_STEPPING :: autodiff package ( pkg/autoduff ).
218     C/\ | | |-CALC_EXACT_ETA :: Change SSH to flow divergence.
219     C/\ | | |-CALC_SURF_DR :: Calculate the new surface level thickness.
220     C/\ | | |-EXF_GETFORCING :: External forcing package. ( pkg/exf )
221     C/\ | | |-EXTERNAL_FIELDS_LOAD :: Control loading time dep. external data.
222 utke 1.4 C/\ | | | | :: Simple interpolation between end-points
223 utke 1.1 C/\ | | | | :: for forcing datasets.
224     C/\ | | | |
225     C/\ | | | |-EXCH :: Sync forcing. in overlap regions.
226     C/\ | | |-SEAICE_MODEL :: Compute sea-ice terms. ( pkg/seaice )
227     C/\ | | |-FREEZE :: Limit surface temperature.
228     C/\ | | |-GCHEM_FIELD_LOAD :: load tracer forcing fields (pkg/gchem)
229     C/\ | | |
230     C/\ | | |-THERMODYNAMICS :: theta, salt + tracer equations driver.
231     C/\ | | | |
232     C/\ | | | |-INTEGRATE_FOR_W :: Integrate for vertical velocity.
233     C/\ | | | |-OBCS_APPLY_W :: Open bndy. package ( see pkg/obcs ).
234     C/\ | | | |-FIND_RHO :: Calculates [rho(S,T,z)-RhoConst] of a slice
235     C/\ | | | |-GRAD_SIGMA :: Calculate isoneutral gradients
236     C/\ | | | |-CALC_IVDC :: Set Implicit Vertical Diffusivity for Convection
237     C/\ | | | |
238     C/\ | | | |-OBCS_CALC :: Open bndy. package ( see pkg/obcs ).
239     C/\ | | | |-EXTERNAL_FORCING_SURF:: Accumulates appropriately dimensioned
240     C/\ | | | | | :: forcing terms.
241     C/\ | | | | |-PTRACERS_FORCING_SURF :: Tracer package ( see pkg/ptracers ).
242     C/\ | | | |
243     C/\ | | | |-GMREDI_CALC_TENSOR :: GM package ( see pkg/gmredi ).
244     C/\ | | | |-GMREDI_CALC_TENSOR_DUMMY :: GM package ( see pkg/gmredi ).
245     C/\ | | | |-KPP_CALC :: KPP package ( see pkg/kpp ).
246     C/\ | | | |-KPP_CALC_DUMMY :: KPP package ( see pkg/kpp ).
247     C/\ | | | |-AIM_DO_ATMOS_PHYSICS :: Intermed. atmos package ( see pkg/aim ).
248     C/\ | | | |-GAD_ADVECTION :: Generalised advection driver (multi-dim
249     C/\ | | | | advection case) (see pkg/gad).
250     C/\ | | | |-CALC_COMMON_FACTORS :: Calculate common data (such as volume flux)
251     C/\ | | | |-CALC_DIFFUSIVITY :: Calculate net vertical diffusivity
252     C/\ | | | | |
253     C/\ | | | | |-GMREDI_CALC_DIFF :: GM package ( see pkg/gmredi ).
254     C/\ | | | | |-KPP_CALC_DIFF :: KPP package ( see pkg/kpp ).
255     C/\ | | | |
256     C/\ | | | |-CALC_GT :: Calculate the temperature tendency terms
257     C/\ | | | | |
258     C/\ | | | | |-GAD_CALC_RHS :: Generalised advection package
259     C/\ | | | | | | :: ( see pkg/gad )
260     C/\ | | | | | |-KPP_TRANSPORT_T :: KPP non-local transport ( see pkg/kpp ).
261     C/\ | | | | |
262     C/\ | | | | |-EXTERNAL_FORCING_T :: Problem specific forcing for temperature.
263     C/\ | | | | |-ADAMS_BASHFORTH2 :: Extrapolate tendencies forward in time.
264     C/\ | | | | |-FREESURF_RESCALE_G :: Re-scale Gt for free-surface height.
265     C/\ | | | |
266     C/\ | | | |-TIMESTEP_TRACER :: Step tracer field forward in time
267     C/\ | | | |
268     C/\ | | | |-CALC_GS :: Calculate the salinity tendency terms
269     C/\ | | | | |
270     C/\ | | | | |-GAD_CALC_RHS :: Generalised advection package
271     C/\ | | | | | | :: ( see pkg/gad )
272     C/\ | | | | | |-KPP_TRANSPORT_S :: KPP non-local transport ( see pkg/kpp ).
273     C/\ | | | | |
274     C/\ | | | | |-EXTERNAL_FORCING_S :: Problem specific forcing for salt.
275     C/\ | | | | |-ADAMS_BASHFORTH2 :: Extrapolate tendencies forward in time.
276     C/\ | | | | |-FREESURF_RESCALE_G :: Re-scale Gs for free-surface height.
277     C/\ | | | |
278     C/\ | | | |-TIMESTEP_TRACER :: Step tracer field forward in time
279     C/\ | | | |
280     C/\ | | | |-TIMESTEP_TRACER :: Step tracer field forward in time
281     C/\ | | | |
282 utke 1.4 C/\ | | | |-PTRACERS_INTEGRATE :: Integrate other tracer(s) (see pkg/ptracers).
283 utke 1.1 C/\ | | | | |
284     C/\ | | | | |-GAD_CALC_RHS :: Generalised advection package
285     C/\ | | | | | | :: ( see pkg/gad )
286     C/\ | | | | | |-KPP_TRANSPORT_PTR:: KPP non-local transport ( see pkg/kpp ).
287     C/\ | | | | |
288     C/\ | | | | |-PTRACERS_FORCING :: Problem specific forcing for tracer.
289     C/\ | | | | |-GCHEM_FORCING_INT :: tracer forcing for gchem pkg (if all
290 utke 1.4 C/\ | | | | | tendency terms calcualted together)
291 utke 1.1 C/\ | | | | |-ADAMS_BASHFORTH2 :: Extrapolate tendencies forward in time.
292     C/\ | | | | |-FREESURF_RESCALE_G :: Re-scale Gs for free-surface height.
293     C/\ | | | | |-TIMESTEP_TRACER :: Step tracer field forward in time
294     C/\ | | | |
295     C/\ | | | |-OBCS_APPLY_TS :: Open bndy. package (see pkg/obcs ).
296     C/\ | | | |
297     C/\ | | | |-IMPLDIFF :: Solve vertical implicit diffusion equation.
298     C/\ | | | |-OBCS_APPLY_TS :: Open bndy. package (see pkg/obcs ).
299     C/\ | | | |
300     C/\ | | | |-AIM_AIM2DYN_EXCHANGES :: Inetermed. atmos (see pkg/aim).
301     C/\ | | | |-EXCH :: Update overlaps
302     C/\ | | |
303     C/\ | | |-DYNAMICS :: Momentum equations driver.
304     C/\ | | | |
305     C/\ | | | |-CALC_GRAD_PHI_SURF :: Calculate the gradient of the surface
306     C/\ | | | | Potential anomaly.
307     C/\ | | | |-CALC_VISCOSITY :: Calculate net vertical viscosity
308     C/\ | | | | |-KPP_CALC_VISC :: KPP package ( see pkg/kpp ).
309     C/\ | | | |
310     C/\ | | | |-CALC_PHI_HYD :: Integrate the hydrostatic relation.
311     C/\ | | | |-MOM_FLUXFORM :: Flux form mom eqn. package ( see
312     C/\ | | | | pkg/mom_fluxform ).
313 utke 1.4 C/\ | | | | |-MOM_CALC_VISC :: Calculate Horizontal Viscosities
314 utke 1.1 C/\ | | | |-MOM_VECINV :: Vector invariant form mom eqn. package ( see
315     C/\ | | | | pkg/mom_vecinv ).
316 utke 1.4 C/\ | | | | |-MOM_CALC_VISC :: Calculate Horizontal Viscosities
317 utke 1.1 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/\ | | |-GCHEM_FORCING_SEP :: tracer forcing for gchem pkg (if
357     C/\ | | | tracer dependent tendencies calculated
358     C/\ | | | separatly)
359     C/\ | | |
360     C/\ | | |-FLT_MAIN :: Float package ( pkg/flt ).
361     C/\ | | |
362     C/\ | | |-MONITOR :: Monitor package ( pkg/monitor ).
363     C/\ | | |
364     C/\ | | |-DO_THE_MODEL_IO :: Standard diagnostic I/O.
365     C/\ | | | |-WRITE_STATE :: Core state I/O
366     C/\ | | | |-TIMEAVE_STATV_WRITE :: Time averages. see pkg/timeave
367     C/\ | | | |-AIM_WRITE_DIAGS :: Intermed. atmos diags. see pkg/aim
368     C/\ | | | |-GMREDI_DIAGS :: GM diags. see pkg/gmredi
369     C/\ | | | |-KPP_DO_DIAGS :: KPP diags. see pkg/kpp
370     C/\ | | | |-SBO_CALC :: SBO diags. see pkg/sbo
371     C/\ | | | |-SBO_DIAGS :: SBO diags. see pkg/sbo
372     C/\ | | | |-SEAICE_DO_DIAGS :: SEAICE diags. see pkg/seaice
373     C/\ | | | |-GCHEM_DIAGS :: gchem diags. see pkg/gchem
374     C/\ | | |
375     C/\ | | |-WRITE_CHECKPOINT :: Do I/O for restart files.
376     C/\ | |
377     C/\ | |-COST_TILE :: Cost function package. ( see pkg/cost )
378     C<===|=|
379     C<===|=| **************************
380     C<===|=| END MAIN TIMESTEPPING LOOP
381     C<===|=| **************************
382     C<===|=|
383     C | |-COST_FINAL :: Cost function package. ( see pkg/cost )
384     C |
385     C |-WRITE_CHECKPOINT :: Final state storage, for restart.
386     C |
387     C |-TIMER_PRINTALL :: Computational timing summary
388     C |
389     C |-COMM_STATS :: Summarise inter-proc and inter-thread communication
390     C :: events.
391 utke 1.4 C
392 utke 1.1 C \ev
393     C
394     C
395     CEOI
396    
397    
398     #include "AD_CONFIG.h"
399     #include "PACKAGES_CONFIG.h"
400     #include "CPP_OPTIONS.h"
401    
402     CBOP
403    
404     C !ROUTINE: THE_MODEL_MAIN
405    
406     C !INTERFACE:
407     SUBROUTINE THE_MODEL_MAIN(myThid)
408     IMPLICIT NONE
409    
410     C !DESCRIPTION: \bv
411     C *==========================================================*
412     C | SUBROUTINE THE_MODEL_MAIN
413     C | o Master controlling routine for model using the MITgcm
414     C | UV parallel wrapper.
415     C *==========================================================*
416     C | THE_MODEL_MAIN is invoked by the MITgcm UV parallel
417     C | wrapper with a single integer argument "myThid". This
418     C | variable identifies the thread number of an instance of
419     C | THE_MODEL_MAIN. Each instance of THE_MODEL_MAIN works
420     C | on a particular region of the models domain and
421     C | synchronises with other instances as necessary. The
422     C | routine has to "understand" the MITgcm parallel
423     C | environment and the numerical algorithm. Editing this
424     C | routine is best done with some knowledge of both aspects.
425     C | Notes
426     C | =====
427     C | C*P* comments indicating place holders for which code is
428     C | presently being developed.
429     C *==========================================================*
430     C \ev
431    
432     C !CALLING SEQUENCE:
433     C THE_MODEL_MAIN()
434     C |
435     C |
436     C |--INITIALISE_FIXED
437     C | o Set model configuration (fixed arrays)
438     C | Topography, hydrography, timestep, grid, etc..
439     C |
440     C |--CTRL_UNPACK o Derivative mode. Unpack control vector.
441     C |
442     C |--ADTHE_MAIN_LOOP o Main timestepping loop for combined
443     C | prognostic and reverse mode integration.
444     C |
445     C |--CTRL_PACK o Derivative mode. Unpack control vector.
446     C |
447     C |--GRDCHK_MAIN o Gradient check control routine.
448     C |
449     C |--THE_MAIN_LOOP o Main timestepping loop for pure prognostic
450     C | integration.
451     C |
452     C |--WRITE_CHECKPOINT o Write retsart information.
453     C |
454     C |--TIMER_PRINTALL o Print out timing statistics.
455     C |
456     C |--COMM_STATS o Print out communication statistics.
457    
458     C !USES:
459     C == Global variables ===
460    
461     use active_module
462    
463     use OpenAD_rev
464     use OpenAD_tape
465     use OpenAD_checkpoints
466    
467    
468     #include "SIZE.h"
469     #include "EEPARAMS.h"
470     #include "PARAMS.h"
471     #include "DYNVARS.h"
472     #include "ctrl.h"
473     #include "cost.h"
474    
475     #ifdef ALLOW_AUTODIFF_TAMC
476     # include "tamc.h"
477     #endif
478     #ifdef ALLOW_CTRL
479     # include "optim.h"
480     #endif
481    
482     C !INPUT/OUTPUT PARAMETERS:
483     C == Routine arguments ==
484     C myThid - Thread number for this instance of the routine.
485     INTEGER myThid
486    
487     C !LOCAL VARIABLES:
488     C == Local variables ==
489     C Note: Under the multi-threaded model myCurrentIter and
490     C myCurrentTime are local variables passed around as routine
491     C arguments. Although this is fiddly it saves the need to
492     C impose additional synchronisation points when they are
493     C updated.
494     C myCurrentTime - Time counter for this thread
495     C myCurrentIter - Iteration counter for this thread
496     INTEGER myCurrentIter
497     _RL myCurrentTime
498     logical exst
499     logical lastdiva
500 utke 1.3 _RL foo(1-olx:snx+olx,1-oly:sny+oly,nr,nsx,nsy)
501 utke 1.1 CEOP
502     c-- set default:
503     lastdiva = .TRUE.
504    
505     c set the execution mode
506     our_rev_mode%arg_store=.FALSE.
507     our_rev_mode%arg_restore=.FALSE.
508     our_rev_mode%res_store=.FALSE.
509     our_rev_mode%res_restore=.FALSE.
510     our_rev_mode%plain=.TRUE.
511     our_rev_mode%tape=.FALSE.
512     our_rev_mode%adjoint=.FALSE.
513     our_rev_mode%switchedToCheckpoint=.FALSE.
514     c initialize the tape
515     call tape_init()
516     c initialize the checkpoint areas
517     call cp_init()
518    
519     #ifdef ALLOW_DEBUG
520     IF (debugMode) CALL DEBUG_ENTER('THE_MODEL_MAIN',myThid)
521     #endif
522    
523 utke 1.4 #if defined(USE_PAPI) || defined(USE_PCL_FLOPS_SFP) || defined(USE_PCL_FLOPS) || defined(USE_PCL)
524     CALL TIMER_CONTROL('','INIT','THE_MODEL_MAIN',myThid)
525     #endif
526 utke 1.1 C-- This timer encompasses the whole code
527     CALL TIMER_START('ALL [THE_MODEL_MAIN]',myThid)
528    
529     #ifdef ALLOW_DEBUG
530     IF (debugMode) CALL DEBUG_CALL('INITIALISE_FIXED',myThid)
531     #endif
532    
533     C-- Set model configuration (fixed arrays)
534     CALL TIMER_START('INITIALISE_FIXED [THE_MODEL_MAIN]',myThid)
535     CALL OpenAD_INITIALISE_FIXED( myThid )
536     CALL TIMER_STOP ('INITIALISE_FIXED [THE_MODEL_MAIN]',myThid)
537    
538     myCurrentTime = startTime
539     myCurrentIter = nIter0
540    
541     #if ( defined (ALLOW_ADMTLM) )
542     c
543     STOP 'should never get here; ADMTLM_DSVD calls ADMTLM_DRIVER'
544     c
545     #elif ( defined (ALLOW_AUTODIFF))
546    
547     # ifndef EXCLUDE_CTRL_PACK
548     _BEGIN_MASTER( mythid )
549     IF (myProcId .eq. 0) THEN
550     inquire( file='costfinal', exist=exst )
551     IF ( .NOT. exst ) THEN
552 utke 1.4 IF ( optimcycle.NE.0 .AND. doMainUnpack ) THEN
553 utke 1.1 CALL TIMER_START('CTRL_UNPACK [THE_MODEL_MAIN]',mythid)
554     CALL CTRL_UNPACK( .TRUE. , mythid )
555     CALL TIMER_STOP ('CTRL_UNPACK [THE_MODEL_MAIN]',mythid)
556     ENDIF
557     ENDIF
558     ENDIF
559     _END_MASTER( mythid )
560     _BARRIER
561     # endif /* EXCLUDE_CTRL_PACK */
562    
563     # ifdef ALLOW_COST
564     CALL COST_DEPENDENT_INIT ( mythid )
565     _BARRIER
566     # endif
567    
568     # if ( defined (ALLOW_TANGENTLINEAR_RUN) )
569     c
570     CALL TIMER_START('G_THE_MAIN_LOOP [TANGENT RUN]',mythid)
571     CALL G_THE_MAIN_LOOP ( myCurrentTime, myCurrentIter, myThid )
572     CALL TIMER_STOP ('G_THE_MAIN_LOOP [TANGENT RUN]',mythid)
573     c
574     # elif ( defined (ALLOW_ADJOINT_RUN) || \
575     defined (ALLOW_ECCO_OPTIMIZATION) )
576     c
577     # ifdef ALLOW_DIVIDED_ADJOINT
578     c-- The following assumes the TAF option '-pure'
579     inquire( file='costfinal', exist=exst )
580     IF ( .NOT. exst) THEN
581     CALL TIMER_START('MDTHE_MAIN_LOOP [MD RUN]', mythid)
582     CALL MDTHE_MAIN_LOOP ( myCurrentTime, myCurrentIter, mythid )
583     CALL TIMER_STOP ('MDTHE_MAIN_LOOP [MD RUN]', mythid)
584     CALL COST_FINAL_STORE ( mythid, lastdiva )
585     ELSE
586     CALL TIMER_START('ADTHE_MAIN_LOOP [ADJOINT RUN]', mythid)
587     CALL ADTHE_MAIN_LOOP ( myCurrentTime, myCurrentIter, mythid )
588     CALL TIMER_STOP ('ADTHE_MAIN_LOOP [ADJOINT RUN]', mythid)
589     CALL COST_FINAL_RESTORE ( mythid, lastdiva )
590     ENDIF
591     c--
592     # else /* ALLOW_DIVIDED_ADJOINT undef */
593     CALL TIMER_START('ADTHE_MAIN_LOOP [ADJOINT RUN]', mythid)
594     CALL ADTHE_MAIN_LOOP ( myCurrentTime, myCurrentIter, mythid )
595     cph CALL ADTHE_MAIN_LOOP ( mythid )
596     CALL TIMER_STOP ('ADTHE_MAIN_LOOP [ADJOINT RUN]', mythid)
597     # endif /* ALLOW_DIVIDED_ADJOINT */
598     c
599     # else /* forward run only within AD setting */
600    
601     #ifdef ALLOW_DEBUG
602     IF (debugMode) CALL DEBUG_CALL('THE_MAIN_LOOP',myThid)
603     #endif
604     C-- Call time stepping loop of full model
605     CALL TIMER_START('THE_MAIN_LOOP (F) [THE_MODEL_MAIN]',myThid)
606     our_rev_mode%plain=.FALSE.
607     our_rev_mode%tape=.TRUE.
608 utke 1.2 call timeratio()
609 utke 1.1 CALL OpenAD_THE_MAIN_LOOP( myCurrentTime, myCurrentIter, myThid )
610     CALL TIMER_STOP ('THE_MAIN_LOOP (F) [THE_MODEL_MAIN]',myThid)
611     CALL TIMER_START('THE_MAIN_LOOP (A) [THE_MODEL_MAIN]',myThid)
612     our_rev_mode%arg_store=.FALSE.
613     our_rev_mode%arg_restore=.FALSE.
614     our_rev_mode%plain=.FALSE.
615     our_rev_mode%tape=.FALSE.
616     our_rev_mode%adjoint=.TRUE.
617     fc%d=1.0
618 utke 1.2 call timeratio()
619 utke 1.1 CALL OpenAD_THE_MAIN_LOOP( myCurrentTime, myCurrentIter, myThid )
620 utke 1.2 call timeratio()
621 utke 1.3
622 utke 1.1 do i1=1-olx,snx+olx
623     do i2=1-oly,sny+oly
624     do i3=1,nr
625     do i4=1,nsx
626     do i5=1,nsy
627 utke 1.3 write (*,'(A,5(I3,A),EN26.16E3,A,EN26.16E3)') 'JU: (',
628 utke 1.1 +i1,',',i2,',',i3,',',i4,',',i5,') salt/theta ',
629     +xx_salt(i1,i2,i3,i4,i5)%d,'/',xx_theta(i1,i2,i3,i4,i5)%d
630     end do
631     end do
632     end do
633     end do
634     end do
635 utke 1.3 foo=xx_theta%d
636     call write_rec_xyz_rl('thetaResult',foo,1,0,1)
637     foo=xx_salt%d
638     call write_rec_xyz_rl('saltResult',foo,1,0,1)
639 utke 1.1 our_rev_mode%plain=.TRUE.
640     our_rev_mode%tape=.FALSE.
641     our_rev_mode%adjoint=.FALSE.
642     CALL TIMER_STOP ('THE_MAIN_LOOP (A) [THE_MODEL_MAIN]',myThid)
643    
644     # endif
645    
646     # ifndef EXCLUDE_CTRL_PACK
647     _BEGIN_MASTER( mythid )
648 utke 1.4 IF ( myProcId .eq. 0 .AND. lastdiva .AND. doMainPack ) THEN
649 utke 1.1 CALL TIMER_START('CTRL_PACK [THE_MODEL_MAIN]',mythid)
650 utke 1.4 CALL CTRL_PACK( .FALSE. , mythid )
651 utke 1.1 CALL TIMER_STOP ('CTRL_PACK [THE_MODEL_MAIN]',mythid)
652 utke 1.4 IF ( ( optimcycle.EQ.0 .OR. (.NOT. doMainUnpack) )
653     & .AND. mycurrentiter.EQ.niter0 ) THEN
654 utke 1.1 CALL TIMER_START('CTRL_PACK [THE_MODEL_MAIN]',mythid)
655     CALL CTRL_PACK( .TRUE. , mythid )
656     CALL TIMER_STOP ('CTRL_PACK [THE_MODEL_MAIN]',mythid)
657     ENDIF
658     ENDIF
659     _END_MASTER( mythid )
660     _BARRIER
661     # endif /* EXCLUDE_CTRL_PACK */
662    
663    
664     # ifdef ALLOW_GRDCHK
665     IF ( useGrdchk .AND. lastdiva ) THEN
666     CALL TIMER_START('GRDCHK_MAIN [THE_MODEL_MAIN]',mythid)
667     CALL GRDCHK_MAIN( mythid )
668     CALL TIMER_STOP ('GRDCHK_MAIN [THE_MODEL_MAIN]',mythid)
669     _BARRIER
670     ENDIF
671     # endif
672    
673     #else /* ALL AD-related undef */
674    
675     #ifdef ALLOW_DEBUG
676     IF (debugMode) CALL DEBUG_CALL('THE_MAIN_LOOP',myThid)
677     #endif
678     C-- Call time stepping loop of full model
679     CALL TIMER_START('THE_MAIN_LOOP [THE_MODEL_MAIN]',myThid)
680     CALL THE_MAIN_LOOP( myCurrentTime, myCurrentIter, myThid )
681     CALL TIMER_STOP ('THE_MAIN_LOOP [THE_MODEL_MAIN]',myThid)
682    
683     #endif /* ALLOW_TANGENTLINEAR_RUN ALLOW_ADJOINT_RUN ALLOW_ADMTLM */
684    
685     C-- Final checkpoint (in case the in-loop checkpoint was missed)
686 utke 1.4 CALL TIMER_START('DO_WRITE_PICKUP [THE_MODEL_MAIN]',myThid)
687     CALL DO_WRITE_PICKUP(
688 utke 1.1 I .TRUE., myCurrentTime, myCurrentIter, myThid )
689 utke 1.4 CALL TIMER_STOP ('DO_WRITE_PICKUP [THE_MODEL_MAIN]',myThid)
690 utke 1.1
691     CALL TIMER_STOP ('ALL [THE_MODEL_MAIN]',myThid)
692    
693     #ifdef ALLOW_DIAGNOSTICS
694     IF (useDiagnostics) THEN
695     C Close all diagnostics output files
696     CALL DIAGSTATS_CLOSE_IO( myThid )
697     ENDIF
698     #endif
699    
700     #ifdef ALLOW_MNC
701     IF (useMNC) THEN
702     C Close all open NetCDF files
703     _BEGIN_MASTER( mythid )
704     CALL MNC_FILE_CLOSE_ALL( myThid )
705     _END_MASTER( mythid )
706     ENDIF
707     #endif
708    
709     C-- Write timer statistics
710     IF ( myThid .EQ. 1 ) THEN
711     CALL TIMER_PRINTALL( myThid )
712     CALL COMM_STATS
713     ENDIF
714    
715 utke 1.4 C-- Check threads synchronization :
716     CALL BAR_CHECK( 9, myThid )
717    
718 utke 1.1 #ifdef ALLOW_DEBUG
719     IF (debugMode) CALL DEBUG_LEAVE('THE_MODEL_MAIN',myThid)
720     #endif
721    
722     RETURN
723     END

  ViewVC Help
Powered by ViewVC 1.1.22