nemogcm.F90 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852
  1. MODULE nemogcm
  2. !!======================================================================
  3. !! *** MODULE nemogcm ***
  4. !! Ocean system : NEMO GCM (ocean dynamics, on-line tracers, biochemistry and sea-ice)
  5. !!======================================================================
  6. !! History : OPA ! 1990-10 (C. Levy, G. Madec) Original code
  7. !! 7.0 ! 1991-11 (M. Imbard, C. Levy, G. Madec)
  8. !! 7.1 ! 1993-03 (M. Imbard, C. Levy, G. Madec, O. Marti, M. Guyon, A. Lazar,
  9. !! P. Delecluse, C. Perigaud, G. Caniaux, B. Colot, C. Maes) release 7.1
  10. !! - ! 1992-06 (L.Terray) coupling implementation
  11. !! - ! 1993-11 (M.A. Filiberti) IGLOO sea-ice
  12. !! 8.0 ! 1996-03 (M. Imbard, C. Levy, G. Madec, O. Marti, M. Guyon, A. Lazar,
  13. !! P. Delecluse, L.Terray, M.A. Filiberti, J. Vialar, A.M. Treguier, M. Levy) release 8.0
  14. !! 8.1 ! 1997-06 (M. Imbard, G. Madec)
  15. !! 8.2 ! 1999-11 (M. Imbard, H. Goosse) LIM sea-ice model
  16. !! ! 1999-12 (V. Thierry, A-M. Treguier, M. Imbard, M-A. Foujols) OPEN-MP
  17. !! ! 2000-07 (J-M Molines, M. Imbard) Open Boundary Conditions (CLIPPER)
  18. !! NEMO 1.0 ! 2002-08 (G. Madec) F90: Free form and modules
  19. !! - ! 2004-06 (R. Redler, NEC CCRLE, Germany) add OASIS[3/4] coupled interfaces
  20. !! - ! 2004-08 (C. Talandier) New trends organization
  21. !! - ! 2005-06 (C. Ethe) Add the 1D configuration possibility
  22. !! - ! 2005-11 (V. Garnier) Surface pressure gradient organization
  23. !! - ! 2006-03 (L. Debreu, C. Mazauric) Agrif implementation
  24. !! - ! 2006-04 (G. Madec, R. Benshila) Step reorganization
  25. !! - ! 2007-07 (J. Chanut, A. Sellar) Unstructured open boundaries (BDY)
  26. !! 3.2 ! 2009-08 (S. Masson) open/write in the listing file in mpp
  27. !! 3.3 ! 2010-05 (K. Mogensen, A. Weaver, M. Martin, D. Lea) Assimilation interface
  28. !! - ! 2010-10 (C. Ethe, G. Madec) reorganisation of initialisation phase
  29. !! 3.3.1! 2011-01 (A. R. Porter, STFC Daresbury) dynamical allocation
  30. !! 3.4 ! 2011-11 (C. Harris) decomposition changes for running with CICE
  31. !! ! 2012-05 (C. Calone, J. Simeon, G. Madec, C. Ethe) Add grid coarsening
  32. !!----------------------------------------------------------------------
  33. !!----------------------------------------------------------------------
  34. !! nemo_gcm : solve ocean dynamics, tracer, biogeochemistry and/or sea-ice
  35. !! nemo_init : initialization of the NEMO system
  36. !! nemo_ctl : initialisation of the contol print
  37. !! nemo_closefile : close remaining open files
  38. !! nemo_alloc : dynamical allocation
  39. !! nemo_partition : calculate MPP domain decomposition
  40. !! factorise : calculate the factors of the no. of MPI processes
  41. !!----------------------------------------------------------------------
  42. USE step_oce ! module used in the ocean time stepping module
  43. USE cla ! cross land advection (tra_cla routine)
  44. USE domcfg ! domain configuration (dom_cfg routine)
  45. USE mppini ! shared/distributed memory setting (mpp_init routine)
  46. USE domain ! domain initialization (dom_init routine)
  47. #if defined key_nemocice_decomp
  48. USE ice_domain_size, only: nx_global, ny_global
  49. #endif
  50. USE tideini ! tidal components initialization (tide_ini routine)
  51. USE bdyini ! open boundary cond. setting (bdy_init routine)
  52. USE bdydta ! open boundary cond. setting (bdy_dta_init routine)
  53. USE bdytides ! open boundary cond. setting (bdytide_init routine)
  54. USE istate ! initial state setting (istate_init routine)
  55. USE ldfdyn ! lateral viscosity setting (ldfdyn_init routine)
  56. USE ldftra ! lateral diffusivity setting (ldftra_init routine)
  57. USE zdfini ! vertical physics setting (zdf_init routine)
  58. USE phycst ! physical constant (par_cst routine)
  59. USE trdini ! dyn/tra trends initialization (trd_init routine)
  60. USE asminc ! assimilation increments
  61. USE asmbkg ! writing out state trajectory
  62. USE diaptr ! poleward transports (dia_ptr_init routine)
  63. USE diadct ! sections transports (dia_dct_init routine)
  64. USE diaobs ! Observation diagnostics (dia_obs_init routine)
  65. USE lib_fortran ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)
  66. USE step ! NEMO time-stepping (stp routine)
  67. USE icbini ! handle bergs, initialisation
  68. USE icbstp ! handle bergs, calving, themodynamics and transport
  69. USE cpl_oasis3 ! OASIS3 coupling
  70. USE c1d ! 1D configuration
  71. USE step_c1d ! Time stepping loop for the 1D configuration
  72. USE dyndmp ! Momentum damping
  73. #if defined key_top
  74. USE trcini ! passive tracer initialisation
  75. #endif
  76. USE lib_mpp ! distributed memory computing
  77. #if defined key_iomput
  78. USE xios
  79. #endif
  80. USE sbctide, ONLY: lk_tide
  81. USE crsini ! initialise grid coarsening utility
  82. USE lbcnfd, ONLY: isendto, nsndto, nfsloop, nfeloop ! Setup of north fold exchanges
  83. USE sbc_oce, ONLY: lk_oasis
  84. USE stopar
  85. USE stopts
  86. IMPLICIT NONE
  87. PRIVATE
  88. PUBLIC nemo_gcm ! called by model.F90
  89. PUBLIC nemo_init ! needed by AGRIF
  90. PUBLIC nemo_alloc ! needed by TAM
  91. CHARACTER(lc) :: cform_aaa="( /, 'AAAAAAAA', / ) " ! flag for output listing
  92. !!----------------------------------------------------------------------
  93. !! NEMO/OPA 4.0 , NEMO Consortium (2011)
  94. !! $Id: nemogcm.F90 5531 2015-07-02 13:49:16Z jchanut $
  95. !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
  96. !!----------------------------------------------------------------------
  97. CONTAINS
  98. SUBROUTINE nemo_gcm
  99. !!----------------------------------------------------------------------
  100. !! *** ROUTINE nemo_gcm ***
  101. !!
  102. !! ** Purpose : NEMO solves the primitive equations on an orthogonal
  103. !! curvilinear mesh on the sphere.
  104. !!
  105. !! ** Method : - model general initialization
  106. !! - launch the time-stepping (stp routine)
  107. !! - finalize the run by closing files and communications
  108. !!
  109. !! References : Madec, Delecluse, Imbard, and Levy, 1997: internal report, IPSL.
  110. !! Madec, 2008, internal report, IPSL.
  111. !!----------------------------------------------------------------------
  112. INTEGER :: istp ! time step index
  113. !!----------------------------------------------------------------------
  114. !
  115. #if defined key_agrif
  116. CALL Agrif_Init_Grids() ! AGRIF: set the meshes
  117. #endif
  118. ! !-----------------------!
  119. CALL nemo_init !== Initialisations ==!
  120. ! !-----------------------!
  121. #if defined key_agrif
  122. CALL Agrif_Declare_Var_dom ! AGRIF: set the meshes for DOM
  123. CALL Agrif_Declare_Var ! " " " " " DYN/TRA
  124. # if defined key_top
  125. CALL Agrif_Declare_Var_top ! " " " " " TOP
  126. # endif
  127. # if defined key_lim2
  128. CALL Agrif_Declare_Var_lim2 ! " " " " " LIM
  129. # endif
  130. #endif
  131. ! check that all process are still there... If some process have an error,
  132. ! they will never enter in step and other processes will wait until the end of the cpu time!
  133. IF( lk_mpp ) CALL mpp_max( nstop )
  134. IF(lwp) WRITE(numout,cform_aaa) ! Flag AAAAAAA
  135. ! !-----------------------!
  136. ! !== time stepping ==!
  137. ! !-----------------------!
  138. istp = nit000
  139. #if defined key_c1d
  140. DO WHILE ( istp <= nitend .AND. nstop == 0 )
  141. CALL stp_c1d( istp )
  142. istp = istp + 1
  143. END DO
  144. #else
  145. IF( lk_asminc ) THEN
  146. IF( ln_bkgwri ) CALL asm_bkg_wri( nit000 - 1 ) ! Output background fields
  147. IF( ln_asmdin ) THEN ! Direct initialization
  148. IF( ln_trainc ) CALL tra_asm_inc( nit000 - 1 ) ! Tracers
  149. IF( ln_dyninc ) CALL dyn_asm_inc( nit000 - 1 ) ! Dynamics
  150. IF( ln_sshinc ) CALL ssh_asm_inc( nit000 - 1 ) ! SSH
  151. ENDIF
  152. ENDIF
  153. #if defined key_agrif
  154. CALL Agrif_Regrid()
  155. #endif
  156. DO WHILE ( istp <= nitend .AND. nstop == 0 )
  157. #if defined key_agrif
  158. CALL stp ! AGRIF: time stepping
  159. #else
  160. CALL stp( istp ) ! standard time stepping
  161. #endif
  162. istp = istp + 1
  163. IF( lk_mpp ) CALL mpp_max( nstop )
  164. END DO
  165. #endif
  166. IF( lk_diaobs ) CALL dia_obs_wri
  167. !
  168. IF( ln_icebergs ) CALL icb_end( nitend )
  169. ! !------------------------!
  170. ! !== finalize the run ==!
  171. ! !------------------------!
  172. IF(lwp) WRITE(numout,cform_aaa) ! Flag AAAAAAA
  173. !
  174. IF( nstop /= 0 .AND. lwp ) THEN ! error print
  175. WRITE(numout,cform_err)
  176. WRITE(numout,*) nstop, ' error have been found'
  177. ENDIF
  178. !
  179. #if defined key_agrif
  180. CALL Agrif_ParentGrid_To_ChildGrid()
  181. IF( lk_diaobs ) CALL dia_obs_wri
  182. IF( nn_timing == 1 ) CALL timing_finalize
  183. CALL Agrif_ChildGrid_To_ParentGrid()
  184. #endif
  185. IF( nn_timing == 1 ) CALL timing_finalize
  186. !
  187. CALL nemo_closefile
  188. !
  189. #if defined key_iomput
  190. CALL xios_finalize ! end mpp communications with xios
  191. IF( lk_oasis ) CALL cpl_finalize ! end coupling and mpp communications with OASIS
  192. #else
  193. IF( lk_oasis ) THEN
  194. CALL cpl_finalize ! end coupling and mpp communications with OASIS
  195. ELSE
  196. IF( lk_mpp ) CALL mppstop ! end mpp communications
  197. ENDIF
  198. #endif
  199. !
  200. END SUBROUTINE nemo_gcm
  201. SUBROUTINE nemo_init
  202. !!----------------------------------------------------------------------
  203. !! *** ROUTINE nemo_init ***
  204. !!
  205. !! ** Purpose : initialization of the NEMO GCM
  206. !!----------------------------------------------------------------------
  207. INTEGER :: ji ! dummy loop indices
  208. INTEGER :: ilocal_comm ! local integer
  209. INTEGER :: ios
  210. CHARACTER(len=80), DIMENSION(16) :: cltxt
  211. !
  212. NAMELIST/namctl/ ln_ctl , nn_print, nn_ictls, nn_ictle, &
  213. & nn_isplt, nn_jsplt, nn_jctls, nn_jctle, &
  214. & nn_bench, nn_timing
  215. NAMELIST/namcfg/ cp_cfg, cp_cfz, jp_cfg, jpidta, jpjdta, jpkdta, jpiglo, jpjglo, &
  216. & jpizoom, jpjzoom, jperio, ln_use_jattr
  217. !!----------------------------------------------------------------------
  218. !
  219. cltxt = ''
  220. cxios_context = 'nemo'
  221. !
  222. ! ! Open reference namelist and configuration namelist files
  223. CALL ctl_opn( numnam_ref, 'namelist_ref', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
  224. CALL ctl_opn( numnam_cfg, 'namelist_cfg', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
  225. !
  226. REWIND( numnam_ref ) ! Namelist namctl in reference namelist : Control prints & Benchmark
  227. READ ( numnam_ref, namctl, IOSTAT = ios, ERR = 901 )
  228. 901 IF( ios /= 0 ) CALL ctl_nam ( ios , 'namctl in reference namelist', .TRUE. )
  229. REWIND( numnam_cfg ) ! Namelist namctl in confguration namelist : Control prints & Benchmark
  230. READ ( numnam_cfg, namctl, IOSTAT = ios, ERR = 902 )
  231. 902 IF( ios /= 0 ) CALL ctl_nam ( ios , 'namctl in configuration namelist', .TRUE. )
  232. !
  233. REWIND( numnam_ref ) ! Namelist namcfg in reference namelist : Control prints & Benchmark
  234. READ ( numnam_ref, namcfg, IOSTAT = ios, ERR = 903 )
  235. 903 IF( ios /= 0 ) CALL ctl_nam ( ios , 'namcfg in reference namelist', .TRUE. )
  236. REWIND( numnam_cfg ) ! Namelist namcfg in confguration namelist : Control prints & Benchmark
  237. READ ( numnam_cfg, namcfg, IOSTAT = ios, ERR = 904 )
  238. 904 IF( ios /= 0 ) CALL ctl_nam ( ios , 'namcfg in configuration namelist', .TRUE. )
  239. ! Force values for AGRIF zoom (cf. agrif_user.F90)
  240. #if defined key_agrif
  241. IF( .NOT. Agrif_Root() ) THEN
  242. jpiglo = nbcellsx + 2 + 2*nbghostcells
  243. jpjglo = nbcellsy + 2 + 2*nbghostcells
  244. jpi = ( jpiglo-2*jpreci + (jpni-1+0) ) / jpni + 2*jpreci
  245. jpj = ( jpjglo-2*jprecj + (jpnj-1+0) ) / jpnj + 2*jprecj
  246. jpidta = jpiglo
  247. jpjdta = jpjglo
  248. jpizoom = 1
  249. jpjzoom = 1
  250. nperio = 0
  251. jperio = 0
  252. ln_use_jattr = .false.
  253. ENDIF
  254. #endif
  255. !
  256. ! !--------------------------------------------!
  257. ! ! set communicator & select the local node !
  258. ! ! NB: mynode also opens output.namelist.dyn !
  259. ! ! on unit number numond on first proc !
  260. ! !--------------------------------------------!
  261. #if defined key_iomput
  262. IF( Agrif_Root() ) THEN
  263. IF( lk_oasis ) THEN
  264. CALL cpl_init( "oceanx", ilocal_comm ) ! nemo local communicator given by oasis
  265. CALL xios_initialize( "not used",local_comm=ilocal_comm ) ! send nemo communicator to xios
  266. ELSE
  267. CALL xios_initialize( "for_xios_mpi_id",return_comm=ilocal_comm ) ! nemo local communicator given by xios
  268. ENDIF
  269. ENDIF
  270. ! Nodes selection (control print return in cltxt)
  271. narea = mynode( cltxt, 'output.namelist.dyn', numnam_ref, numnam_cfg, numond , nstop, ilocal_comm )
  272. #else
  273. IF( lk_oasis ) THEN
  274. IF( Agrif_Root() ) THEN
  275. CALL cpl_init( "oceanx", ilocal_comm ) ! nemo local communicator given by oasis
  276. ENDIF
  277. ! Nodes selection (control print return in cltxt)
  278. narea = mynode( cltxt, 'output.namelist.dyn', numnam_ref, numnam_cfg, numond , nstop, ilocal_comm )
  279. ELSE
  280. ilocal_comm = 0
  281. ! Nodes selection (control print return in cltxt)
  282. narea = mynode( cltxt, 'output.namelist.dyn', numnam_ref, numnam_cfg, numond , nstop )
  283. ENDIF
  284. #endif
  285. narea = narea + 1 ! mynode return the rank of proc (0 --> jpnij -1 )
  286. lwm = (narea == 1) ! control of output namelists
  287. lwp = (narea == 1) .OR. ln_ctl ! control of all listing output print
  288. IF(lwm) THEN
  289. ! write merged namelists from earlier to output namelist now that the
  290. ! file has been opened in call to mynode. nammpp has already been
  291. ! written in mynode (if lk_mpp_mpi)
  292. WRITE( numond, namctl )
  293. WRITE( numond, namcfg )
  294. ENDIF
  295. ! If dimensions of processor grid weren't specified in the namelist file
  296. ! then we calculate them here now that we have our communicator size
  297. IF( (jpni < 1) .OR. (jpnj < 1) )THEN
  298. #if defined key_mpp_mpi
  299. IF( Agrif_Root() ) CALL nemo_partition(mppsize)
  300. #else
  301. jpni = 1
  302. jpnj = 1
  303. jpnij = jpni*jpnj
  304. #endif
  305. END IF
  306. ! Calculate domain dimensions given calculated jpni and jpnj
  307. ! This used to be done in par_oce.F90 when they were parameters rather
  308. ! than variables
  309. IF( Agrif_Root() ) THEN
  310. #if defined key_nemocice_decomp
  311. jpi = ( nx_global+2-2*jpreci + (jpni-1) ) / jpni + 2*jpreci ! first dim.
  312. jpj = ( ny_global+2-2*jprecj + (jpnj-1) ) / jpnj + 2*jprecj ! second dim.
  313. #else
  314. jpi = ( jpiglo-2*jpreci + (jpni-1) ) / jpni + 2*jpreci ! first dim.
  315. jpj = ( jpjglo-2*jprecj + (jpnj-1) ) / jpnj + 2*jprecj ! second dim.
  316. #endif
  317. ENDIF
  318. jpk = jpkdta ! third dim
  319. #if defined key_agrif
  320. ! simple trick to use same vertical grid as parent
  321. ! but different number of levels:
  322. ! Save maximum number of levels in jpkdta, then define all vertical grids
  323. ! with this number.
  324. ! Suppress once vertical online interpolation is ok
  325. IF(.NOT.Agrif_Root()) jpkdta = Agrif_Parent(jpkdta)
  326. #endif
  327. jpim1 = jpi-1 ! inner domain indices
  328. jpjm1 = jpj-1 ! " "
  329. jpkm1 = jpk-1 ! " "
  330. jpij = jpi*jpj ! jpi x j
  331. IF(lwp) THEN ! open listing units
  332. !
  333. CALL ctl_opn( numout, 'ocean.output', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE., narea )
  334. !
  335. WRITE(numout,*)
  336. WRITE(numout,*) ' CNRS - NERC - Met OFFICE - MERCATOR-ocean - INGV - CMCC'
  337. WRITE(numout,*) ' NEMO team'
  338. WRITE(numout,*) ' Ocean General Circulation Model'
  339. WRITE(numout,*) ' version 3.6 (2015) '
  340. WRITE(numout,*)
  341. WRITE(numout,*)
  342. DO ji = 1, SIZE(cltxt)
  343. IF( TRIM(cltxt(ji)) /= '' ) WRITE(numout,*) cltxt(ji) ! control print of mynode
  344. END DO
  345. WRITE(numout,cform_aaa) ! Flag AAAAAAA
  346. !
  347. ENDIF
  348. ! Now we know the dimensions of the grid and numout has been set we can
  349. ! allocate arrays
  350. CALL nemo_alloc()
  351. ! !-------------------------------!
  352. ! ! NEMO general initialization !
  353. ! !-------------------------------!
  354. CALL nemo_ctl ! Control prints & Benchmark
  355. ! ! Domain decomposition
  356. IF( jpni*jpnj == jpnij ) THEN ; CALL mpp_init ! standard cutting out
  357. ELSE ; CALL mpp_init2 ! eliminate land processors
  358. ENDIF
  359. !
  360. IF( nn_timing == 1 ) CALL timing_init
  361. !
  362. ! ! General initialization
  363. CALL phy_cst ! Physical constants
  364. CALL eos_init ! Equation of state
  365. IF( lk_c1d ) CALL c1d_init ! 1D column configuration
  366. CALL dom_cfg ! Domain configuration
  367. CALL dom_init ! Domain
  368. IF( ln_nnogather ) CALL nemo_northcomms ! Initialise the northfold neighbour lists (must be done after the masks are defined)
  369. IF( ln_ctl ) CALL prt_ctl_init ! Print control
  370. CALL istate_init ! ocean initial state (Dynamics and tracers)
  371. IF( lk_tide ) CALL tide_init( nit000 ) ! Initialisation of the tidal harmonics
  372. CALL sbc_init ! Forcings : surface module (clem: moved here for bdy purpose)
  373. IF( lk_bdy ) CALL bdy_init ! Open boundaries initialisation
  374. IF( lk_bdy ) CALL bdy_dta_init ! Open boundaries initialisation of external data arrays
  375. IF( lk_bdy .AND. lk_tide ) &
  376. & CALL bdytide_init ! Open boundaries initialisation of tidal harmonic forcing
  377. CALL dyn_nept_init ! simplified form of Neptune effect
  378. !
  379. IF( ln_crs ) CALL crs_init ! Domain initialization of coarsened grid
  380. !
  381. ! Ocean physics
  382. ! ! Vertical physics
  383. CALL zdf_init ! namelist read
  384. CALL zdf_bfr_init ! bottom friction
  385. IF( lk_zdfric ) CALL zdf_ric_init ! Richardson number dependent Kz
  386. IF( lk_zdftke ) CALL zdf_tke_init ! TKE closure scheme
  387. IF( lk_zdfgls ) CALL zdf_gls_init ! GLS closure scheme
  388. IF( lk_zdfkpp ) CALL zdf_kpp_init ! KPP closure scheme
  389. IF( lk_zdftmx ) CALL zdf_tmx_init ! tidal vertical mixing
  390. IF( lk_zdfddm .AND. .NOT. lk_zdfkpp ) &
  391. & CALL zdf_ddm_init ! double diffusive mixing
  392. ! ! Lateral physics
  393. CALL ldf_tra_init ! Lateral ocean tracer physics
  394. CALL ldf_dyn_init ! Lateral ocean momentum physics
  395. IF( lk_ldfslp ) CALL ldf_slp_init ! slope of lateral mixing
  396. ! ! Active tracers
  397. CALL tra_qsr_init ! penetrative solar radiation qsr
  398. CALL tra_bbc_init ! bottom heat flux
  399. IF( lk_trabbl ) CALL tra_bbl_init ! advective (and/or diffusive) bottom boundary layer scheme
  400. CALL tra_dmp_init ! internal damping trends- tracers
  401. CALL tra_adv_init ! horizontal & vertical advection
  402. CALL tra_ldf_init ! lateral mixing
  403. CALL tra_zdf_init ! vertical mixing and after tracer fields
  404. ! ! Dynamics
  405. IF( lk_c1d ) CALL dyn_dmp_init ! internal damping trends- momentum
  406. CALL dyn_adv_init ! advection (vector or flux form)
  407. CALL dyn_vor_init ! vorticity term including Coriolis
  408. CALL dyn_ldf_init ! lateral mixing
  409. CALL dyn_hpg_init ! horizontal gradient of Hydrostatic pressure
  410. CALL dyn_zdf_init ! vertical diffusion
  411. CALL dyn_spg_init ! surface pressure gradient
  412. ! ! Misc. options
  413. IF( nn_cla == 1 .AND. cp_cfg == 'orca' .AND. jp_cfg == 2 ) CALL cla_init ! Cross Land Advection
  414. CALL icb_init( rdt, nit000) ! initialise icebergs instance
  415. CALL sto_par_init ! Stochastic parametrization
  416. IF( ln_sto_eos ) CALL sto_pts_init ! RRandom T/S fluctuations
  417. #if defined key_top
  418. ! ! Passive tracers
  419. CALL trc_init
  420. #endif
  421. ! ! Diagnostics
  422. IF( lk_floats ) CALL flo_init ! drifting Floats
  423. CALL dia_ptr_init ! Poleward TRansports initialization
  424. IF( lk_diadct ) CALL dia_dct_init ! Sections tranports
  425. CALL dia_hsb_init ! heat content, salt content and volume budgets
  426. CALL trd_init ! Mixed-layer/Vorticity/Integral constraints trends
  427. IF( lk_diaobs ) THEN ! Observation & model comparison
  428. CALL dia_obs_init ! Initialize observational data
  429. CALL dia_obs( nit000 - 1 ) ! Observation operator for restart
  430. ENDIF
  431. ! ! Assimilation increments
  432. IF( lk_asminc ) CALL asm_inc_init ! Initialize assimilation increments
  433. IF(lwp) WRITE(numout,*) 'Euler time step switch is ', neuler
  434. !
  435. END SUBROUTINE nemo_init
  436. SUBROUTINE nemo_ctl
  437. !!----------------------------------------------------------------------
  438. !! *** ROUTINE nemo_ctl ***
  439. !!
  440. !! ** Purpose : control print setting
  441. !!
  442. !! ** Method : - print namctl information and check some consistencies
  443. !!----------------------------------------------------------------------
  444. !
  445. IF(lwp) THEN ! control print
  446. WRITE(numout,*)
  447. WRITE(numout,*) 'nemo_ctl: Control prints & Benchmark'
  448. WRITE(numout,*) '~~~~~~~ '
  449. WRITE(numout,*) ' Namelist namctl'
  450. WRITE(numout,*) ' run control (for debugging) ln_ctl = ', ln_ctl
  451. WRITE(numout,*) ' level of print nn_print = ', nn_print
  452. WRITE(numout,*) ' Start i indice for SUM control nn_ictls = ', nn_ictls
  453. WRITE(numout,*) ' End i indice for SUM control nn_ictle = ', nn_ictle
  454. WRITE(numout,*) ' Start j indice for SUM control nn_jctls = ', nn_jctls
  455. WRITE(numout,*) ' End j indice for SUM control nn_jctle = ', nn_jctle
  456. WRITE(numout,*) ' number of proc. following i nn_isplt = ', nn_isplt
  457. WRITE(numout,*) ' number of proc. following j nn_jsplt = ', nn_jsplt
  458. WRITE(numout,*) ' benchmark parameter (0/1) nn_bench = ', nn_bench
  459. WRITE(numout,*) ' timing activated (0/1) nn_timing = ', nn_timing
  460. ENDIF
  461. !
  462. nprint = nn_print ! convert DOCTOR namelist names into OLD names
  463. nictls = nn_ictls
  464. nictle = nn_ictle
  465. njctls = nn_jctls
  466. njctle = nn_jctle
  467. isplt = nn_isplt
  468. jsplt = nn_jsplt
  469. nbench = nn_bench
  470. IF(lwp) THEN ! control print
  471. WRITE(numout,*)
  472. WRITE(numout,*) 'namcfg : configuration initialization through namelist read'
  473. WRITE(numout,*) '~~~~~~~ '
  474. WRITE(numout,*) ' Namelist namcfg'
  475. WRITE(numout,*) ' configuration name cp_cfg = ', TRIM(cp_cfg)
  476. WRITE(numout,*) ' configuration zoom name cp_cfz = ', TRIM(cp_cfz)
  477. WRITE(numout,*) ' configuration resolution jp_cfg = ', jp_cfg
  478. WRITE(numout,*) ' 1st lateral dimension ( >= jpi ) jpidta = ', jpidta
  479. WRITE(numout,*) ' 2nd " " ( >= jpj ) jpjdta = ', jpjdta
  480. WRITE(numout,*) ' 3nd " " jpkdta = ', jpkdta
  481. WRITE(numout,*) ' 1st dimension of global domain in i jpiglo = ', jpiglo
  482. WRITE(numout,*) ' 2nd - - in j jpjglo = ', jpjglo
  483. WRITE(numout,*) ' left bottom i index of the zoom (in data domain) jpizoom = ', jpizoom
  484. WRITE(numout,*) ' left bottom j index of the zoom (in data domain) jpizoom = ', jpjzoom
  485. WRITE(numout,*) ' lateral cond. type (between 0 and 6) jperio = ', jperio
  486. WRITE(numout,*) ' use file attribute if exists as i/p j-start ln_use_jattr = ', ln_use_jattr
  487. ENDIF
  488. ! ! Parameter control
  489. !
  490. IF( ln_ctl ) THEN ! sub-domain area indices for the control prints
  491. IF( lk_mpp .AND. jpnij > 1 ) THEN
  492. isplt = jpni ; jsplt = jpnj ; ijsplt = jpni*jpnj ! the domain is forced to the real split domain
  493. ELSE
  494. IF( isplt == 1 .AND. jsplt == 1 ) THEN
  495. CALL ctl_warn( ' - isplt & jsplt are equal to 1', &
  496. & ' - the print control will be done over the whole domain' )
  497. ENDIF
  498. ijsplt = isplt * jsplt ! total number of processors ijsplt
  499. ENDIF
  500. IF(lwp) WRITE(numout,*)' - The total number of processors over which the'
  501. IF(lwp) WRITE(numout,*)' print control will be done is ijsplt : ', ijsplt
  502. !
  503. ! ! indices used for the SUM control
  504. IF( nictls+nictle+njctls+njctle == 0 ) THEN ! print control done over the default area
  505. lsp_area = .FALSE.
  506. ELSE ! print control done over a specific area
  507. lsp_area = .TRUE.
  508. IF( nictls < 1 .OR. nictls > jpiglo ) THEN
  509. CALL ctl_warn( ' - nictls must be 1<=nictls>=jpiglo, it is forced to 1' )
  510. nictls = 1
  511. ENDIF
  512. IF( nictle < 1 .OR. nictle > jpiglo ) THEN
  513. CALL ctl_warn( ' - nictle must be 1<=nictle>=jpiglo, it is forced to jpiglo' )
  514. nictle = jpiglo
  515. ENDIF
  516. IF( njctls < 1 .OR. njctls > jpjglo ) THEN
  517. CALL ctl_warn( ' - njctls must be 1<=njctls>=jpjglo, it is forced to 1' )
  518. njctls = 1
  519. ENDIF
  520. IF( njctle < 1 .OR. njctle > jpjglo ) THEN
  521. CALL ctl_warn( ' - njctle must be 1<=njctle>=jpjglo, it is forced to jpjglo' )
  522. njctle = jpjglo
  523. ENDIF
  524. ENDIF
  525. ENDIF
  526. !
  527. IF( nbench == 1 ) THEN ! Benchmark
  528. SELECT CASE ( cp_cfg )
  529. CASE ( 'gyre' ) ; CALL ctl_warn( ' The Benchmark is activated ' )
  530. CASE DEFAULT ; CALL ctl_stop( ' The Benchmark is based on the GYRE configuration:', &
  531. & ' cp_cfg = "gyre" in namelist &namcfg or set nbench = 0' )
  532. END SELECT
  533. ENDIF
  534. !
  535. IF( 1_wp /= SIGN(1._wp,-0._wp) ) CALL ctl_stop( 'nemo_ctl: The intrinsec SIGN function follows ', &
  536. & 'f2003 standard. ' , &
  537. & 'Compile with key_nosignedzero enabled' )
  538. !
  539. END SUBROUTINE nemo_ctl
  540. SUBROUTINE nemo_closefile
  541. !!----------------------------------------------------------------------
  542. !! *** ROUTINE nemo_closefile ***
  543. !!
  544. !! ** Purpose : Close the files
  545. !!----------------------------------------------------------------------
  546. !
  547. IF( lk_mpp ) CALL mppsync
  548. !
  549. CALL iom_close ! close all input/output files managed by iom_*
  550. !
  551. IF( numstp /= -1 ) CLOSE( numstp ) ! time-step file
  552. IF( numsol /= -1 ) CLOSE( numsol ) ! solver file
  553. IF( numnam_ref /= -1 ) CLOSE( numnam_ref ) ! oce reference namelist
  554. IF( numnam_cfg /= -1 ) CLOSE( numnam_cfg ) ! oce configuration namelist
  555. IF( lwm.AND.numond /= -1 ) CLOSE( numond ) ! oce output namelist
  556. IF( numnam_ice_ref /= -1 ) CLOSE( numnam_ice_ref ) ! ice reference namelist
  557. IF( numnam_ice_cfg /= -1 ) CLOSE( numnam_ice_cfg ) ! ice configuration namelist
  558. IF( lwm.AND.numoni /= -1 ) CLOSE( numoni ) ! ice output namelist
  559. IF( numevo_ice /= -1 ) CLOSE( numevo_ice ) ! ice variables (temp. evolution)
  560. IF( numout /= 6 ) CLOSE( numout ) ! standard model output file
  561. IF( numdct_vol /= -1 ) CLOSE( numdct_vol ) ! volume transports
  562. IF( numdct_heat /= -1 ) CLOSE( numdct_heat ) ! heat transports
  563. IF( numdct_salt /= -1 ) CLOSE( numdct_salt ) ! salt transports
  564. !
  565. numout = 6 ! redefine numout in case it is used after this point...
  566. !
  567. END SUBROUTINE nemo_closefile
  568. SUBROUTINE nemo_alloc
  569. !!----------------------------------------------------------------------
  570. !! *** ROUTINE nemo_alloc ***
  571. !!
  572. !! ** Purpose : Allocate all the dynamic arrays of the OPA modules
  573. !!
  574. !! ** Method :
  575. !!----------------------------------------------------------------------
  576. USE diawri , ONLY: dia_wri_alloc
  577. USE dom_oce , ONLY: dom_oce_alloc
  578. USE ldfdyn_oce, ONLY: ldfdyn_oce_alloc
  579. USE ldftra_oce, ONLY: ldftra_oce_alloc
  580. USE trc_oce , ONLY: trc_oce_alloc
  581. #if defined key_diadct
  582. USE diadct , ONLY: diadct_alloc
  583. #endif
  584. #if defined key_bdy
  585. USE bdy_oce , ONLY: bdy_oce_alloc
  586. #endif
  587. !
  588. INTEGER :: ierr
  589. !!----------------------------------------------------------------------
  590. !
  591. ierr = oce_alloc () ! ocean
  592. ierr = ierr + dia_wri_alloc ()
  593. ierr = ierr + dom_oce_alloc () ! ocean domain
  594. ierr = ierr + ldfdyn_oce_alloc() ! ocean lateral physics : dynamics
  595. ierr = ierr + ldftra_oce_alloc() ! ocean lateral physics : tracers
  596. ierr = ierr + zdf_oce_alloc () ! ocean vertical physics
  597. !
  598. ierr = ierr + trc_oce_alloc () ! shared TRC / TRA arrays
  599. !
  600. #if defined key_diadct
  601. ierr = ierr + diadct_alloc () !
  602. #endif
  603. #if defined key_bdy
  604. ierr = ierr + bdy_oce_alloc () ! bdy masks (incl. initialization)
  605. #endif
  606. !
  607. IF( lk_mpp ) CALL mpp_sum( ierr )
  608. IF( ierr /= 0 ) CALL ctl_stop( 'STOP', 'nemo_alloc : unable to allocate standard ocean arrays' )
  609. !
  610. END SUBROUTINE nemo_alloc
  611. SUBROUTINE nemo_partition( num_pes )
  612. !!----------------------------------------------------------------------
  613. !! *** ROUTINE nemo_partition ***
  614. !!
  615. !! ** Purpose :
  616. !!
  617. !! ** Method :
  618. !!----------------------------------------------------------------------
  619. INTEGER, INTENT(in) :: num_pes ! The number of MPI processes we have
  620. !
  621. INTEGER, PARAMETER :: nfactmax = 20
  622. INTEGER :: nfact ! The no. of factors returned
  623. INTEGER :: ierr ! Error flag
  624. INTEGER :: ji
  625. INTEGER :: idiff, mindiff, imin ! For choosing pair of factors that are closest in value
  626. INTEGER, DIMENSION(nfactmax) :: ifact ! Array of factors
  627. !!----------------------------------------------------------------------
  628. !
  629. ierr = 0
  630. !
  631. CALL factorise( ifact, nfactmax, nfact, num_pes, ierr )
  632. !
  633. IF( nfact <= 1 ) THEN
  634. WRITE (numout, *) 'WARNING: factorisation of number of PEs failed'
  635. WRITE (numout, *) ' : using grid of ',num_pes,' x 1'
  636. jpnj = 1
  637. jpni = num_pes
  638. ELSE
  639. ! Search through factors for the pair that are closest in value
  640. mindiff = 1000000
  641. imin = 1
  642. DO ji = 1, nfact-1, 2
  643. idiff = ABS( ifact(ji) - ifact(ji+1) )
  644. IF( idiff < mindiff ) THEN
  645. mindiff = idiff
  646. imin = ji
  647. ENDIF
  648. END DO
  649. jpnj = ifact(imin)
  650. jpni = ifact(imin + 1)
  651. ENDIF
  652. !
  653. jpnij = jpni*jpnj
  654. !
  655. END SUBROUTINE nemo_partition
  656. SUBROUTINE factorise( kfax, kmaxfax, knfax, kn, kerr )
  657. !!----------------------------------------------------------------------
  658. !! *** ROUTINE factorise ***
  659. !!
  660. !! ** Purpose : return the prime factors of n.
  661. !! knfax factors are returned in array kfax which is of
  662. !! maximum dimension kmaxfax.
  663. !! ** Method :
  664. !!----------------------------------------------------------------------
  665. INTEGER , INTENT(in ) :: kn, kmaxfax
  666. INTEGER , INTENT( out) :: kerr, knfax
  667. INTEGER, DIMENSION(kmaxfax), INTENT( out) :: kfax
  668. !
  669. INTEGER :: ifac, jl, inu
  670. INTEGER, PARAMETER :: ntest = 14
  671. INTEGER, DIMENSION(ntest) :: ilfax
  672. !
  673. ! ilfax contains the set of allowed factors.
  674. ilfax(:) = (/(2**jl,jl=ntest,1,-1)/)
  675. ! Clear the error flag and initialise output vars
  676. kerr = 0
  677. kfax = 1
  678. knfax = 0
  679. ! Find the factors of n.
  680. IF( kn == 1 ) GOTO 20
  681. ! nu holds the unfactorised part of the number.
  682. ! knfax holds the number of factors found.
  683. ! l points to the allowed factor list.
  684. ! ifac holds the current factor.
  685. inu = kn
  686. knfax = 0
  687. DO jl = ntest, 1, -1
  688. !
  689. ifac = ilfax(jl)
  690. IF( ifac > inu ) CYCLE
  691. ! Test whether the factor will divide.
  692. IF( MOD(inu,ifac) == 0 ) THEN
  693. !
  694. knfax = knfax + 1 ! Add the factor to the list
  695. IF( knfax > kmaxfax ) THEN
  696. kerr = 6
  697. write (*,*) 'FACTOR: insufficient space in factor array ', knfax
  698. return
  699. ENDIF
  700. kfax(knfax) = ifac
  701. ! Store the other factor that goes with this one
  702. knfax = knfax + 1
  703. kfax(knfax) = inu / ifac
  704. !WRITE (*,*) 'ARPDBG, factors ',knfax-1,' & ',knfax,' are ', kfax(knfax-1),' and ',kfax(knfax)
  705. ENDIF
  706. !
  707. END DO
  708. 20 CONTINUE ! Label 20 is the exit point from the factor search loop.
  709. !
  710. END SUBROUTINE factorise
  711. #if defined key_mpp_mpi
  712. SUBROUTINE nemo_northcomms
  713. !!======================================================================
  714. !! *** ROUTINE nemo_northcomms ***
  715. !! nemo_northcomms : Setup for north fold exchanges with explicit
  716. !! point-to-point messaging
  717. !!=====================================================================
  718. !!----------------------------------------------------------------------
  719. !!
  720. !! ** Purpose : Initialization of the northern neighbours lists.
  721. !!----------------------------------------------------------------------
  722. !! 1.0 ! 2011-10 (A. C. Coward, NOCS & J. Donners, PRACE)
  723. !! 2.0 ! 2013-06 Setup avoiding MPI communication (I. Epicoco, S. Mocavero, CMCC)
  724. !!----------------------------------------------------------------------
  725. INTEGER :: sxM, dxM, sxT, dxT, jn
  726. INTEGER :: njmppmax
  727. njmppmax = MAXVAL( njmppt )
  728. !initializes the north-fold communication variables
  729. isendto(:) = 0
  730. nsndto = 0
  731. !if I am a process in the north
  732. IF ( njmpp == njmppmax ) THEN
  733. !sxM is the first point (in the global domain) needed to compute the
  734. !north-fold for the current process
  735. sxM = jpiglo - nimppt(narea) - nlcit(narea) + 1
  736. !dxM is the last point (in the global domain) needed to compute the
  737. !north-fold for the current process
  738. dxM = jpiglo - nimppt(narea) + 2
  739. !loop over the other north-fold processes to find the processes
  740. !managing the points belonging to the sxT-dxT range
  741. DO jn = 1, jpni
  742. !sxT is the first point (in the global domain) of the jn
  743. !process
  744. sxT = nfiimpp(jn, jpnj)
  745. !dxT is the last point (in the global domain) of the jn
  746. !process
  747. dxT = nfiimpp(jn, jpnj) + nfilcit(jn, jpnj) - 1
  748. IF ((sxM .gt. sxT) .AND. (sxM .lt. dxT)) THEN
  749. nsndto = nsndto + 1
  750. isendto(nsndto) = jn
  751. ELSEIF ((sxM .le. sxT) .AND. (dxM .ge. dxT)) THEN
  752. nsndto = nsndto + 1
  753. isendto(nsndto) = jn
  754. ELSEIF ((dxM .lt. dxT) .AND. (sxT .lt. dxM)) THEN
  755. nsndto = nsndto + 1
  756. isendto(nsndto) = jn
  757. END IF
  758. END DO
  759. nfsloop = 1
  760. nfeloop = nlci
  761. DO jn = 2,jpni-1
  762. IF(nfipproc(jn,jpnj) .eq. (narea - 1)) THEN
  763. IF (nfipproc(jn - 1 ,jpnj) .eq. -1) THEN
  764. nfsloop = nldi
  765. ENDIF
  766. IF (nfipproc(jn + 1,jpnj) .eq. -1) THEN
  767. nfeloop = nlei
  768. ENDIF
  769. ENDIF
  770. END DO
  771. ENDIF
  772. l_north_nogather = .TRUE.
  773. END SUBROUTINE nemo_northcomms
  774. #else
  775. SUBROUTINE nemo_northcomms ! Dummy routine
  776. WRITE(*,*) 'nemo_northcomms: You should not have seen this print! error?'
  777. END SUBROUTINE nemo_northcomms
  778. #endif
  779. !!======================================================================
  780. END MODULE nemogcm