[3324] | 1 | MODULE nemogcm |
---|
| 2 | !!====================================================================== |
---|
| 3 | !! *** MODULE nemogcm *** |
---|
[7646] | 4 | !! StandAlone Surface module : surface fluxes + sea-ice + iceberg floats |
---|
[3324] | 5 | !!====================================================================== |
---|
[7646] | 6 | !! History : 3.6 ! 2011-11 (S. Alderson, G. Madec) original code |
---|
| 7 | !! - ! 2013-06 (I. Epicoco, S. Mocavero, CMCC) nemo_northcomms: setup avoiding MPI communication |
---|
| 8 | !! - ! 2014-12 (G. Madec) remove KPP scheme and cross-land advection (cla) |
---|
| 9 | !! 4.0 ! 2016-10 (G. Madec, S. Flavoni) domain configuration / user defined interface |
---|
[3324] | 10 | !!---------------------------------------------------------------------- |
---|
| 11 | |
---|
| 12 | !!---------------------------------------------------------------------- |
---|
[7646] | 13 | !! nemo_gcm : solve ocean dynamics, tracer, biogeochemistry and/or sea-ice |
---|
| 14 | !! nemo_init : initialization of the NEMO system |
---|
| 15 | !! nemo_ctl : initialisation of the contol print |
---|
| 16 | !! nemo_closefile: close remaining open files |
---|
| 17 | !! nemo_alloc : dynamical allocation |
---|
| 18 | !! nemo_partition: calculate MPP domain decomposition |
---|
| 19 | !! factorise : calculate the factors of the no. of MPI processes |
---|
[3324] | 20 | !!---------------------------------------------------------------------- |
---|
[7646] | 21 | USE step_oce ! module used in the ocean time stepping module |
---|
| 22 | USE sbc_oce ! surface boundary condition: ocean |
---|
| 23 | USE phycst ! physical constant (par_cst routine) |
---|
| 24 | USE domain ! domain initialization (dom_init & dom_cfg routines) |
---|
| 25 | USE usrdef_nam ! user defined configuration |
---|
| 26 | USE daymod ! calendar |
---|
| 27 | USE step ! NEMO time-stepping (stp routine) |
---|
| 28 | USE cpl_oasis3 ! |
---|
| 29 | USE sbcssm ! |
---|
| 30 | USE icbini ! handle bergs, initialisation |
---|
| 31 | USE icbstp ! handle bergs, calving, themodynamics and transport |
---|
| 32 | USE bdyini ! open boundary cond. setting (bdy_init routine). clem: mandatory for LIM3 |
---|
| 33 | USE bdydta ! open boundary cond. setting (bdy_dta_init routine). clem: mandatory for LIM3 |
---|
| 34 | ! |
---|
| 35 | USE lib_mpp ! distributed memory computing |
---|
| 36 | USE mppini ! shared/distributed memory setting (mpp_init routine) |
---|
| 37 | USE lbcnfd , ONLY: isendto, nsndto, nfsloop, nfeloop ! Setup of north fold exchanges |
---|
| 38 | USE lib_fortran ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined) |
---|
[3324] | 39 | #if defined key_iomput |
---|
[7646] | 40 | USE xios ! xIOserver |
---|
[3324] | 41 | #endif |
---|
| 42 | |
---|
| 43 | IMPLICIT NONE |
---|
| 44 | PRIVATE |
---|
| 45 | |
---|
| 46 | PUBLIC nemo_gcm ! called by model.F90 |
---|
| 47 | PUBLIC nemo_init ! needed by AGRIF |
---|
| 48 | |
---|
| 49 | CHARACTER(lc) :: cform_aaa="( /, 'AAAAAAAA', / ) " ! flag for output listing |
---|
| 50 | |
---|
| 51 | !!---------------------------------------------------------------------- |
---|
[7646] | 52 | !! NEMO/OPA 4.0 , NEMO Consortium (2016) |
---|
[5215] | 53 | !! $Id$ |
---|
[3324] | 54 | !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt) |
---|
| 55 | !!---------------------------------------------------------------------- |
---|
| 56 | CONTAINS |
---|
| 57 | |
---|
| 58 | SUBROUTINE nemo_gcm |
---|
| 59 | !!---------------------------------------------------------------------- |
---|
| 60 | !! *** ROUTINE nemo_gcm *** |
---|
| 61 | !! |
---|
[7646] | 62 | !! ** Purpose : NEMO solves the primitive equations on an orthogonal |
---|
[3324] | 63 | !! curvilinear mesh on the sphere. |
---|
| 64 | !! |
---|
| 65 | !! ** Method : - model general initialization |
---|
| 66 | !! - launch the time-stepping (stp routine) |
---|
| 67 | !! - finalize the run by closing files and communications |
---|
| 68 | !! |
---|
| 69 | !! References : Madec, Delecluse, Imbard, and Levy, 1997: internal report, IPSL. |
---|
| 70 | !! Madec, 2008, internal report, IPSL. |
---|
| 71 | !!---------------------------------------------------------------------- |
---|
[7646] | 72 | INTEGER :: istp ! time step index |
---|
[3324] | 73 | !!---------------------------------------------------------------------- |
---|
| 74 | ! |
---|
| 75 | #if defined key_agrif |
---|
[7646] | 76 | CALL Agrif_Init_Grids() ! AGRIF: set the meshes |
---|
[3324] | 77 | #endif |
---|
[7646] | 78 | ! |
---|
[3324] | 79 | ! !-----------------------! |
---|
| 80 | CALL nemo_init !== Initialisations ==! |
---|
| 81 | ! !-----------------------! |
---|
| 82 | #if defined key_agrif |
---|
[5407] | 83 | CALL Agrif_Declare_Var_dom ! AGRIF: set the meshes for DOM |
---|
| 84 | CALL Agrif_Declare_Var ! " " " " " DYN/TRA |
---|
| 85 | # if defined key_top |
---|
| 86 | CALL Agrif_Declare_Var_top ! " " " " " TOP |
---|
| 87 | # endif |
---|
[7646] | 88 | # if defined key_lim3 |
---|
| 89 | CALL Agrif_Declare_Var_lim3 ! " " " " " LIM3 |
---|
| 90 | # endif |
---|
[3324] | 91 | #endif |
---|
| 92 | ! check that all process are still there... If some process have an error, |
---|
| 93 | ! they will never enter in step and other processes will wait until the end of the cpu time! |
---|
| 94 | IF( lk_mpp ) CALL mpp_max( nstop ) |
---|
| 95 | |
---|
| 96 | IF(lwp) WRITE(numout,cform_aaa) ! Flag AAAAAAA |
---|
| 97 | |
---|
| 98 | ! !-----------------------! |
---|
| 99 | ! !== time stepping ==! |
---|
| 100 | ! !-----------------------! |
---|
| 101 | istp = nit000 |
---|
[7646] | 102 | #if defined key_agrif |
---|
| 103 | CALL Agrif_Regrid() |
---|
| 104 | #endif |
---|
| 105 | |
---|
[3331] | 106 | DO WHILE ( istp <= nitend .AND. nstop == 0 ) |
---|
[3324] | 107 | #if defined key_agrif |
---|
[7646] | 108 | CALL stp ! AGRIF: time stepping |
---|
[3324] | 109 | #else |
---|
[7646] | 110 | IF ( .NOT. ln_diurnal_only ) THEN |
---|
| 111 | CALL stp( istp ) ! standard time stepping |
---|
| 112 | ELSE |
---|
| 113 | CALL stp_diurnal( istp ) ! time step only the diurnal SST |
---|
| 114 | ENDIF |
---|
[3324] | 115 | #endif |
---|
[3331] | 116 | istp = istp + 1 |
---|
| 117 | IF( lk_mpp ) CALL mpp_max( nstop ) |
---|
[7646] | 118 | END DO |
---|
[5407] | 119 | ! |
---|
| 120 | IF( ln_icebergs ) CALL icb_end( nitend ) |
---|
| 121 | |
---|
[3324] | 122 | ! !------------------------! |
---|
| 123 | ! !== finalize the run ==! |
---|
| 124 | ! !------------------------! |
---|
[7646] | 125 | IF(lwp) WRITE(numout,cform_aaa) ! Flag AAAAAAA |
---|
[3324] | 126 | ! |
---|
[7646] | 127 | IF( nstop /= 0 .AND. lwp ) THEN ! error print |
---|
[3324] | 128 | WRITE(numout,cform_err) |
---|
[7646] | 129 | WRITE(numout,*) nstop, ' error have been found' |
---|
[3324] | 130 | ENDIF |
---|
| 131 | ! |
---|
| 132 | #if defined key_agrif |
---|
[8226] | 133 | !!clem2017 IF( .NOT. Agrif_Root() ) THEN |
---|
[7646] | 134 | CALL Agrif_ParentGrid_To_ChildGrid() |
---|
| 135 | IF( nn_timing == 1 ) CALL timing_finalize |
---|
| 136 | CALL Agrif_ChildGrid_To_ParentGrid() |
---|
[8226] | 137 | !!clem2017 ENDIF |
---|
[3324] | 138 | #endif |
---|
| 139 | IF( nn_timing == 1 ) CALL timing_finalize |
---|
| 140 | ! |
---|
| 141 | CALL nemo_closefile |
---|
[5407] | 142 | ! |
---|
[3769] | 143 | #if defined key_iomput |
---|
[7646] | 144 | CALL xios_finalize ! end mpp communications with xios |
---|
| 145 | IF( lk_oasis ) CALL cpl_finalize ! end coupling and mpp communications with OASIS |
---|
[3769] | 146 | #else |
---|
[5407] | 147 | IF( lk_oasis ) THEN |
---|
[7646] | 148 | CALL cpl_finalize ! end coupling and mpp communications with OASIS |
---|
[5407] | 149 | ELSE |
---|
[7646] | 150 | IF( lk_mpp ) CALL mppstop ! end mpp communications |
---|
[5407] | 151 | ENDIF |
---|
[3769] | 152 | #endif |
---|
[3324] | 153 | ! |
---|
| 154 | END SUBROUTINE nemo_gcm |
---|
| 155 | |
---|
| 156 | |
---|
| 157 | SUBROUTINE nemo_init |
---|
| 158 | !!---------------------------------------------------------------------- |
---|
| 159 | !! *** ROUTINE nemo_init *** |
---|
| 160 | !! |
---|
| 161 | !! ** Purpose : initialization of the NEMO GCM |
---|
| 162 | !!---------------------------------------------------------------------- |
---|
[7646] | 163 | INTEGER :: ji ! dummy loop indices |
---|
| 164 | INTEGER :: ilocal_comm ! local integer |
---|
| 165 | INTEGER :: ios, inum ! - - |
---|
| 166 | CHARACTER(len=120), DIMENSION(30) :: cltxt, cltxt2, clnam |
---|
| 167 | CHARACTER(len=80) :: clname |
---|
[5407] | 168 | ! |
---|
[7646] | 169 | NAMELIST/namctl/ ln_ctl , nn_print, nn_ictls, nn_ictle, & |
---|
| 170 | & nn_isplt , nn_jsplt, nn_jctls, nn_jctle, & |
---|
| 171 | & nn_timing, nn_diacfl |
---|
| 172 | NAMELIST/namcfg/ ln_read_cfg, cn_domcfg, ln_write_cfg, cn_domcfg_out, ln_use_jattr |
---|
[3324] | 173 | !!---------------------------------------------------------------------- |
---|
[5407] | 174 | ! |
---|
[7646] | 175 | cltxt = '' |
---|
| 176 | cltxt2 = '' |
---|
| 177 | clnam = '' |
---|
| 178 | cxios_context = 'nemo' |
---|
[3324] | 179 | ! |
---|
[4147] | 180 | ! ! Open reference namelist and configuration namelist files |
---|
[5407] | 181 | IF( lk_oasis ) THEN |
---|
| 182 | CALL ctl_opn( numnam_ref, 'namelist_sas_ref', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. ) |
---|
| 183 | CALL ctl_opn( numnam_cfg, 'namelist_sas_cfg', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. ) |
---|
| 184 | cxios_context = 'sas' |
---|
| 185 | clname = 'output.namelist_sas.dyn' |
---|
| 186 | ELSE |
---|
| 187 | CALL ctl_opn( numnam_ref, 'namelist_ref', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. ) |
---|
| 188 | CALL ctl_opn( numnam_cfg, 'namelist_cfg', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. ) |
---|
| 189 | cxios_context = 'nemo' |
---|
| 190 | clname = 'output.namelist.dyn' |
---|
| 191 | ENDIF |
---|
[3324] | 192 | ! |
---|
[7646] | 193 | REWIND( numnam_ref ) ! Namelist namctl in reference namelist : Control prints |
---|
[4147] | 194 | READ ( numnam_ref, namctl, IOSTAT = ios, ERR = 901 ) |
---|
[4290] | 195 | 901 IF( ios /= 0 ) CALL ctl_nam ( ios , 'namctl in reference namelist', .TRUE. ) |
---|
[7646] | 196 | ! |
---|
| 197 | REWIND( numnam_cfg ) ! Namelist namctl in confguration namelist |
---|
[4147] | 198 | READ ( numnam_cfg, namctl, IOSTAT = ios, ERR = 902 ) |
---|
[4290] | 199 | 902 IF( ios /= 0 ) CALL ctl_nam ( ios , 'namctl in configuration namelist', .TRUE. ) |
---|
[3324] | 200 | ! |
---|
[7646] | 201 | REWIND( numnam_ref ) ! Namelist namcfg in reference namelist : Control prints |
---|
[4147] | 202 | READ ( numnam_ref, namcfg, IOSTAT = ios, ERR = 903 ) |
---|
[4290] | 203 | 903 IF( ios /= 0 ) CALL ctl_nam ( ios , 'namcfg in reference namelist', .TRUE. ) |
---|
[4147] | 204 | |
---|
| 205 | REWIND( numnam_cfg ) ! Namelist namcfg in confguration namelist : Control prints & Benchmark |
---|
| 206 | READ ( numnam_cfg, namcfg, IOSTAT = ios, ERR = 904 ) |
---|
[4290] | 207 | 904 IF( ios /= 0 ) CALL ctl_nam ( ios , 'namcfg in configuration namelist', .TRUE. ) |
---|
| 208 | |
---|
[7646] | 209 | ! !--------------------------! |
---|
| 210 | ! ! Set global domain size ! (control print return in cltxt2) |
---|
| 211 | ! !--------------------------! |
---|
| 212 | IF( ln_read_cfg ) THEN ! Read sizes in domain configuration file |
---|
| 213 | CALL domain_cfg ( cltxt2, cn_cfg, nn_cfg, jpiglo, jpjglo, jpkglo, jperio ) |
---|
| 214 | ! |
---|
| 215 | ELSE ! user-defined namelist |
---|
| 216 | CALL usr_def_nam( cltxt2, clnam, cn_cfg, nn_cfg, jpiglo, jpjglo, jpkglo, jperio ) |
---|
| 217 | ENDIF |
---|
| 218 | ! |
---|
| 219 | jpk = jpkglo |
---|
| 220 | ! |
---|
[5407] | 221 | #if defined key_agrif |
---|
[7646] | 222 | IF( .NOT. Agrif_Root() ) THEN ! AGRIF children: specific setting (cf. agrif_user.F90) |
---|
| 223 | jpiglo = nbcellsx + 2 + 2*nbghostcells |
---|
| 224 | jpjglo = nbcellsy + 2 + 2*nbghostcells |
---|
| 225 | jpi = ( jpiglo-2*jpreci + (jpni-1+0) ) / jpni + 2*jpreci |
---|
| 226 | jpj = ( jpjglo-2*jprecj + (jpnj-1+0) ) / jpnj + 2*jprecj |
---|
| 227 | nperio = 0 |
---|
| 228 | jperio = 0 |
---|
| 229 | ln_use_jattr = .false. |
---|
| 230 | ENDIF |
---|
[5407] | 231 | #endif |
---|
| 232 | ! |
---|
[3324] | 233 | ! !--------------------------------------------! |
---|
| 234 | ! ! set communicator & select the local node ! |
---|
[4624] | 235 | ! ! NB: mynode also opens output.namelist.dyn ! |
---|
| 236 | ! ! on unit number numond on first proc ! |
---|
[3324] | 237 | ! !--------------------------------------------! |
---|
| 238 | #if defined key_iomput |
---|
| 239 | IF( Agrif_Root() ) THEN |
---|
[5407] | 240 | IF( lk_oasis ) THEN |
---|
| 241 | CALL cpl_init( "sas", ilocal_comm ) ! nemo local communicator given by oasis |
---|
| 242 | CALL xios_initialize( "not used",local_comm=ilocal_comm ) ! send nemo communicator to xios |
---|
| 243 | ELSE |
---|
[7646] | 244 | CALL xios_initialize( "for_xios_mpi_id",return_comm=ilocal_comm ) ! nemo local communicator given by xios |
---|
[5407] | 245 | ENDIF |
---|
[3324] | 246 | ENDIF |
---|
[5407] | 247 | narea = mynode ( cltxt, clname, numnam_ref, numnam_cfg, numond , nstop, ilocal_comm ) ! Nodes selection |
---|
[3324] | 248 | #else |
---|
[5407] | 249 | IF( lk_oasis ) THEN |
---|
| 250 | IF( Agrif_Root() ) THEN |
---|
| 251 | CALL cpl_init( "sas", ilocal_comm ) ! nemo local communicator given by oasis |
---|
| 252 | ENDIF |
---|
| 253 | narea = mynode( cltxt, clname, numnam_ref, numnam_cfg, numond , nstop, ilocal_comm ) ! Nodes selection (control print return in cltxt) |
---|
| 254 | ELSE |
---|
| 255 | ilocal_comm = 0 |
---|
| 256 | narea = mynode( cltxt, clname, numnam_ref, numnam_cfg, numond , nstop ) ! Nodes selection (control print return in cltxt) |
---|
| 257 | ENDIF |
---|
[3324] | 258 | #endif |
---|
[7646] | 259 | |
---|
[3324] | 260 | narea = narea + 1 ! mynode return the rank of proc (0 --> jpnij -1 ) |
---|
| 261 | |
---|
[4624] | 262 | lwm = (narea == 1) ! control of output namelists |
---|
[3324] | 263 | lwp = (narea == 1) .OR. ln_ctl ! control of all listing output print |
---|
| 264 | |
---|
[7646] | 265 | IF(lwm) THEN ! write merged namelists from earlier to output namelist |
---|
| 266 | ! ! now that the file has been opened in call to mynode. |
---|
| 267 | ! ! NB: nammpp has already been written in mynode (if lk_mpp_mpi) |
---|
[4624] | 268 | WRITE( numond, namctl ) |
---|
| 269 | WRITE( numond, namcfg ) |
---|
[7646] | 270 | IF( .NOT.ln_read_cfg ) THEN |
---|
| 271 | DO ji = 1, SIZE(clnam) |
---|
| 272 | IF( TRIM(clnam(ji)) /= '' ) WRITE(numond, * ) clnam(ji) ! namusr_def print |
---|
| 273 | END DO |
---|
| 274 | ENDIF |
---|
[4624] | 275 | ENDIF |
---|
| 276 | |
---|
[7646] | 277 | ! If dimensions of processor grid weren't specified in the namelist file |
---|
[3324] | 278 | ! then we calculate them here now that we have our communicator size |
---|
[7646] | 279 | IF( jpni < 1 .OR. jpnj < 1 ) THEN |
---|
[3324] | 280 | #if defined key_mpp_mpi |
---|
[7646] | 281 | IF( Agrif_Root() ) CALL nemo_partition( mppsize ) |
---|
[3324] | 282 | #else |
---|
| 283 | jpni = 1 |
---|
| 284 | jpnj = 1 |
---|
| 285 | jpnij = jpni*jpnj |
---|
| 286 | #endif |
---|
[7646] | 287 | ENDIF |
---|
[3324] | 288 | |
---|
[7646] | 289 | IF( Agrif_Root() ) THEN ! AGRIF mother: specific setting from jpni and jpnj |
---|
[3324] | 290 | #if defined key_nemocice_decomp |
---|
[7646] | 291 | jpi = ( nx_global+2-2*jpreci + (jpni-1) ) / jpni + 2*jpreci ! first dim. |
---|
| 292 | jpj = ( ny_global+2-2*jprecj + (jpnj-1) ) / jpnj + 2*jprecj ! second dim. |
---|
[3324] | 293 | #else |
---|
[7646] | 294 | jpi = ( jpiglo -2*jpreci + (jpni-1) ) / jpni + 2*jpreci ! first dim. |
---|
| 295 | jpj = ( jpjglo -2*jprecj + (jpnj-1) ) / jpnj + 2*jprecj ! second dim. |
---|
[3324] | 296 | #endif |
---|
[5407] | 297 | ENDIF |
---|
[3324] | 298 | |
---|
[7646] | 299 | #if defined key_agrif |
---|
| 300 | ! simple trick to use same vertical grid as parent but different number of levels: |
---|
| 301 | ! Save maximum number of levels in jpkglo, then define all vertical grids with this number. |
---|
| 302 | ! Suppress once vertical online interpolation is ok |
---|
| 303 | IF(.NOT.Agrif_Root()) jpkglo = Agrif_Parent( jpkglo ) |
---|
| 304 | #endif |
---|
| 305 | jpim1 = jpi-1 ! inner domain indices |
---|
| 306 | jpjm1 = jpj-1 ! " " |
---|
[7761] | 307 | jpkm1 = MAX( 1, jpk-1 ) ! " " |
---|
[7646] | 308 | jpij = jpi*jpj ! jpi x j |
---|
| 309 | |
---|
[3324] | 310 | IF(lwp) THEN ! open listing units |
---|
| 311 | ! |
---|
[5407] | 312 | IF( lk_oasis ) THEN |
---|
| 313 | CALL ctl_opn( numout, 'sas.output', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE., narea ) |
---|
| 314 | ELSE |
---|
| 315 | CALL ctl_opn( numout, 'ocean.output', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE., narea ) |
---|
| 316 | ENDIF |
---|
[3324] | 317 | ! |
---|
| 318 | WRITE(numout,*) |
---|
| 319 | WRITE(numout,*) ' CNRS - NERC - Met OFFICE - MERCATOR-ocean - INGV - CMCC' |
---|
| 320 | WRITE(numout,*) ' NEMO team' |
---|
| 321 | WRITE(numout,*) ' Ocean General Circulation Model' |
---|
[7646] | 322 | WRITE(numout,*) ' version 3.7 (2016) ' |
---|
[3331] | 323 | WRITE(numout,*) ' StandAlone Surface version (SAS) ' |
---|
[3324] | 324 | WRITE(numout,*) |
---|
| 325 | WRITE(numout,*) |
---|
[7646] | 326 | DO ji = 1, SIZE(cltxt) |
---|
| 327 | IF( TRIM(cltxt (ji)) /= '' ) WRITE(numout,*) cltxt(ji) ! control print of mynode |
---|
[3324] | 328 | END DO |
---|
[7646] | 329 | WRITE(numout,*) |
---|
| 330 | WRITE(numout,*) |
---|
| 331 | DO ji = 1, SIZE(cltxt2) |
---|
| 332 | IF( TRIM(cltxt2(ji)) /= '' ) WRITE(numout,*) cltxt2(ji) ! control print of domain size |
---|
| 333 | END DO |
---|
[3324] | 334 | ! |
---|
[7646] | 335 | WRITE(numout,cform_aaa) ! Flag AAAAAAA |
---|
| 336 | ! |
---|
[3324] | 337 | ENDIF |
---|
| 338 | |
---|
[7646] | 339 | ! Now we know the dimensions of the grid and numout has been set: we can allocate arrays |
---|
[3324] | 340 | CALL nemo_alloc() |
---|
| 341 | ! !-------------------------------! |
---|
| 342 | ! ! NEMO general initialization ! |
---|
| 343 | ! !-------------------------------! |
---|
| 344 | |
---|
[7646] | 345 | CALL nemo_ctl ! Control prints |
---|
[3324] | 346 | |
---|
| 347 | ! ! Domain decomposition |
---|
| 348 | IF( jpni*jpnj == jpnij ) THEN ; CALL mpp_init ! standard cutting out |
---|
| 349 | ELSE ; CALL mpp_init2 ! eliminate land processors |
---|
| 350 | ENDIF |
---|
| 351 | ! |
---|
| 352 | IF( nn_timing == 1 ) CALL timing_init |
---|
| 353 | ! |
---|
[3331] | 354 | ! ! General initialization |
---|
| 355 | CALL phy_cst ! Physical constants |
---|
| 356 | CALL eos_init ! Equation of state |
---|
| 357 | CALL dom_init ! Domain |
---|
[3324] | 358 | |
---|
[7646] | 359 | IF( ln_nnogather ) CALL nemo_northcomms ! Initialise the northfold neighbour lists (must be done after the masks are defined) |
---|
[3324] | 360 | |
---|
[7646] | 361 | IF( ln_ctl ) CALL prt_ctl_init ! Print control |
---|
[3331] | 362 | CALL day_init ! model calendar (using both namelist and restart infos) |
---|
[3324] | 363 | |
---|
[3331] | 364 | CALL sbc_init ! Forcings : surface module |
---|
[7646] | 365 | |
---|
[5510] | 366 | ! ==> clem: open boundaries init. is mandatory for LIM3 because ice BDY is not decoupled from |
---|
| 367 | ! the environment of ocean BDY. Therefore bdy is called in both OPA and SAS modules. |
---|
| 368 | ! This is not clean and should be changed in the future. |
---|
[7761] | 369 | CALL bdy_init |
---|
[5510] | 370 | ! ==> |
---|
[7646] | 371 | CALL icb_init( rdt, nit000) ! initialise icebergs instance |
---|
[3324] | 372 | |
---|
| 373 | IF(lwp) WRITE(numout,*) 'Euler time step switch is ', neuler |
---|
| 374 | ! |
---|
| 375 | END SUBROUTINE nemo_init |
---|
| 376 | |
---|
| 377 | |
---|
| 378 | SUBROUTINE nemo_ctl |
---|
| 379 | !!---------------------------------------------------------------------- |
---|
| 380 | !! *** ROUTINE nemo_ctl *** |
---|
| 381 | !! |
---|
| 382 | !! ** Purpose : control print setting |
---|
| 383 | !! |
---|
| 384 | !! ** Method : - print namctl information and check some consistencies |
---|
| 385 | !!---------------------------------------------------------------------- |
---|
| 386 | ! |
---|
| 387 | IF(lwp) THEN ! control print |
---|
| 388 | WRITE(numout,*) |
---|
[7646] | 389 | WRITE(numout,*) 'nemo_ctl: Control prints' |
---|
[3324] | 390 | WRITE(numout,*) '~~~~~~~ ' |
---|
| 391 | WRITE(numout,*) ' Namelist namctl' |
---|
| 392 | WRITE(numout,*) ' run control (for debugging) ln_ctl = ', ln_ctl |
---|
| 393 | WRITE(numout,*) ' level of print nn_print = ', nn_print |
---|
| 394 | WRITE(numout,*) ' Start i indice for SUM control nn_ictls = ', nn_ictls |
---|
| 395 | WRITE(numout,*) ' End i indice for SUM control nn_ictle = ', nn_ictle |
---|
| 396 | WRITE(numout,*) ' Start j indice for SUM control nn_jctls = ', nn_jctls |
---|
| 397 | WRITE(numout,*) ' End j indice for SUM control nn_jctle = ', nn_jctle |
---|
| 398 | WRITE(numout,*) ' number of proc. following i nn_isplt = ', nn_isplt |
---|
| 399 | WRITE(numout,*) ' number of proc. following j nn_jsplt = ', nn_jsplt |
---|
[7646] | 400 | WRITE(numout,*) ' timing activated (0/1) nn_timing = ', nn_timing |
---|
[3324] | 401 | ENDIF |
---|
| 402 | ! |
---|
| 403 | nprint = nn_print ! convert DOCTOR namelist names into OLD names |
---|
| 404 | nictls = nn_ictls |
---|
| 405 | nictle = nn_ictle |
---|
| 406 | njctls = nn_jctls |
---|
| 407 | njctle = nn_jctle |
---|
| 408 | isplt = nn_isplt |
---|
| 409 | jsplt = nn_jsplt |
---|
[4147] | 410 | |
---|
| 411 | IF(lwp) THEN ! control print |
---|
| 412 | WRITE(numout,*) |
---|
| 413 | WRITE(numout,*) 'namcfg : configuration initialization through namelist read' |
---|
| 414 | WRITE(numout,*) '~~~~~~~ ' |
---|
| 415 | WRITE(numout,*) ' Namelist namcfg' |
---|
[7646] | 416 | WRITE(numout,*) ' read domain configuration files ln_read_cfg = ', ln_read_cfg |
---|
| 417 | WRITE(numout,*) ' filename to be read cn_domcfg = ', TRIM(cn_domcfg) |
---|
| 418 | WRITE(numout,*) ' write configuration definition files ln_write_cfg = ', ln_write_cfg |
---|
| 419 | WRITE(numout,*) ' filename to be written cn_domcfg_out = ', TRIM(cn_domcfg_out) |
---|
| 420 | WRITE(numout,*) ' use file attribute if exists as i/p j-start ln_use_jattr = ', ln_use_jattr |
---|
[4147] | 421 | ENDIF |
---|
[3324] | 422 | ! ! Parameter control |
---|
| 423 | ! |
---|
| 424 | IF( ln_ctl ) THEN ! sub-domain area indices for the control prints |
---|
| 425 | IF( lk_mpp .AND. jpnij > 1 ) THEN |
---|
| 426 | isplt = jpni ; jsplt = jpnj ; ijsplt = jpni*jpnj ! the domain is forced to the real split domain |
---|
| 427 | ELSE |
---|
| 428 | IF( isplt == 1 .AND. jsplt == 1 ) THEN |
---|
| 429 | CALL ctl_warn( ' - isplt & jsplt are equal to 1', & |
---|
| 430 | & ' - the print control will be done over the whole domain' ) |
---|
| 431 | ENDIF |
---|
| 432 | ijsplt = isplt * jsplt ! total number of processors ijsplt |
---|
| 433 | ENDIF |
---|
| 434 | IF(lwp) WRITE(numout,*)' - The total number of processors over which the' |
---|
| 435 | IF(lwp) WRITE(numout,*)' print control will be done is ijsplt : ', ijsplt |
---|
| 436 | ! |
---|
| 437 | ! ! indices used for the SUM control |
---|
| 438 | IF( nictls+nictle+njctls+njctle == 0 ) THEN ! print control done over the default area |
---|
[7646] | 439 | lsp_area = .FALSE. |
---|
[3324] | 440 | ELSE ! print control done over a specific area |
---|
| 441 | lsp_area = .TRUE. |
---|
| 442 | IF( nictls < 1 .OR. nictls > jpiglo ) THEN |
---|
| 443 | CALL ctl_warn( ' - nictls must be 1<=nictls>=jpiglo, it is forced to 1' ) |
---|
| 444 | nictls = 1 |
---|
| 445 | ENDIF |
---|
| 446 | IF( nictle < 1 .OR. nictle > jpiglo ) THEN |
---|
| 447 | CALL ctl_warn( ' - nictle must be 1<=nictle>=jpiglo, it is forced to jpiglo' ) |
---|
| 448 | nictle = jpiglo |
---|
| 449 | ENDIF |
---|
| 450 | IF( njctls < 1 .OR. njctls > jpjglo ) THEN |
---|
| 451 | CALL ctl_warn( ' - njctls must be 1<=njctls>=jpjglo, it is forced to 1' ) |
---|
| 452 | njctls = 1 |
---|
| 453 | ENDIF |
---|
| 454 | IF( njctle < 1 .OR. njctle > jpjglo ) THEN |
---|
| 455 | CALL ctl_warn( ' - njctle must be 1<=njctle>=jpjglo, it is forced to jpjglo' ) |
---|
| 456 | njctle = jpjglo |
---|
| 457 | ENDIF |
---|
| 458 | ENDIF |
---|
| 459 | ENDIF |
---|
| 460 | ! |
---|
[5407] | 461 | IF( 1_wp /= SIGN(1._wp,-0._wp) ) CALL ctl_stop( 'nemo_ctl: The intrinsec SIGN function follows ', & |
---|
| 462 | & 'f2003 standard. ' , & |
---|
| 463 | & 'Compile with key_nosignedzero enabled' ) |
---|
| 464 | ! |
---|
[3324] | 465 | END SUBROUTINE nemo_ctl |
---|
| 466 | |
---|
| 467 | |
---|
| 468 | SUBROUTINE nemo_closefile |
---|
| 469 | !!---------------------------------------------------------------------- |
---|
| 470 | !! *** ROUTINE nemo_closefile *** |
---|
| 471 | !! |
---|
| 472 | !! ** Purpose : Close the files |
---|
| 473 | !!---------------------------------------------------------------------- |
---|
| 474 | ! |
---|
| 475 | IF( lk_mpp ) CALL mppsync |
---|
| 476 | ! |
---|
| 477 | CALL iom_close ! close all input/output files managed by iom_* |
---|
| 478 | ! |
---|
[4147] | 479 | IF( numstp /= -1 ) CLOSE( numstp ) ! time-step file |
---|
| 480 | IF( numnam_ref /= -1 ) CLOSE( numnam_ref ) ! oce reference namelist |
---|
| 481 | IF( numnam_cfg /= -1 ) CLOSE( numnam_cfg ) ! oce configuration namelist |
---|
[4624] | 482 | IF( lwm.AND.numond /= -1 ) CLOSE( numond ) ! oce output namelist |
---|
[4147] | 483 | IF( numnam_ice_ref /= -1 ) CLOSE( numnam_ice_ref ) ! ice reference namelist |
---|
| 484 | IF( numnam_ice_cfg /= -1 ) CLOSE( numnam_ice_cfg ) ! ice configuration namelist |
---|
[4624] | 485 | IF( lwm.AND.numoni /= -1 ) CLOSE( numoni ) ! ice output namelist |
---|
[4147] | 486 | IF( numevo_ice /= -1 ) CLOSE( numevo_ice ) ! ice variables (temp. evolution) |
---|
| 487 | IF( numout /= 6 ) CLOSE( numout ) ! standard model output file |
---|
[3324] | 488 | ! |
---|
| 489 | numout = 6 ! redefine numout in case it is used after this point... |
---|
| 490 | ! |
---|
| 491 | END SUBROUTINE nemo_closefile |
---|
| 492 | |
---|
| 493 | |
---|
| 494 | SUBROUTINE nemo_alloc |
---|
| 495 | !!---------------------------------------------------------------------- |
---|
| 496 | !! *** ROUTINE nemo_alloc *** |
---|
| 497 | !! |
---|
| 498 | !! ** Purpose : Allocate all the dynamic arrays of the OPA modules |
---|
| 499 | !! |
---|
| 500 | !! ** Method : |
---|
| 501 | !!---------------------------------------------------------------------- |
---|
| 502 | USE diawri , ONLY: dia_wri_alloc |
---|
| 503 | USE dom_oce , ONLY: dom_oce_alloc |
---|
[7646] | 504 | USE bdy_oce , ONLY: ln_bdy, bdy_oce_alloc |
---|
[5510] | 505 | USE oce ! clem: mandatory for LIM3 because needed for bdy arrays |
---|
[3324] | 506 | ! |
---|
[7646] | 507 | INTEGER :: ierr |
---|
[3324] | 508 | !!---------------------------------------------------------------------- |
---|
| 509 | ! |
---|
[3335] | 510 | ierr = dia_wri_alloc () |
---|
[3324] | 511 | ierr = ierr + dom_oce_alloc () ! ocean domain |
---|
[7646] | 512 | ierr = ierr + oce_alloc () ! (tsn...) needed for agrif and/or lim3 and bdy |
---|
[5510] | 513 | ierr = ierr + bdy_oce_alloc () ! bdy masks (incl. initialization) |
---|
[3324] | 514 | ! |
---|
| 515 | IF( lk_mpp ) CALL mpp_sum( ierr ) |
---|
| 516 | IF( ierr /= 0 ) CALL ctl_stop( 'STOP', 'nemo_alloc : unable to allocate standard ocean arrays' ) |
---|
| 517 | ! |
---|
| 518 | END SUBROUTINE nemo_alloc |
---|
| 519 | |
---|
| 520 | |
---|
| 521 | SUBROUTINE nemo_partition( num_pes ) |
---|
| 522 | !!---------------------------------------------------------------------- |
---|
| 523 | !! *** ROUTINE nemo_partition *** |
---|
| 524 | !! |
---|
| 525 | !! ** Purpose : |
---|
| 526 | !! |
---|
| 527 | !! ** Method : |
---|
| 528 | !!---------------------------------------------------------------------- |
---|
[7646] | 529 | INTEGER, INTENT(in) :: num_pes ! The number of MPI processes we have |
---|
[3324] | 530 | ! |
---|
| 531 | INTEGER, PARAMETER :: nfactmax = 20 |
---|
| 532 | INTEGER :: nfact ! The no. of factors returned |
---|
| 533 | INTEGER :: ierr ! Error flag |
---|
| 534 | INTEGER :: ji |
---|
| 535 | INTEGER :: idiff, mindiff, imin ! For choosing pair of factors that are closest in value |
---|
| 536 | INTEGER, DIMENSION(nfactmax) :: ifact ! Array of factors |
---|
| 537 | !!---------------------------------------------------------------------- |
---|
[5407] | 538 | ! |
---|
[3324] | 539 | ierr = 0 |
---|
[5407] | 540 | ! |
---|
[3324] | 541 | CALL factorise( ifact, nfactmax, nfact, num_pes, ierr ) |
---|
[5407] | 542 | ! |
---|
[3324] | 543 | IF( nfact <= 1 ) THEN |
---|
| 544 | WRITE (numout, *) 'WARNING: factorisation of number of PEs failed' |
---|
| 545 | WRITE (numout, *) ' : using grid of ',num_pes,' x 1' |
---|
| 546 | jpnj = 1 |
---|
| 547 | jpni = num_pes |
---|
| 548 | ELSE |
---|
| 549 | ! Search through factors for the pair that are closest in value |
---|
| 550 | mindiff = 1000000 |
---|
| 551 | imin = 1 |
---|
| 552 | DO ji = 1, nfact-1, 2 |
---|
| 553 | idiff = ABS( ifact(ji) - ifact(ji+1) ) |
---|
| 554 | IF( idiff < mindiff ) THEN |
---|
| 555 | mindiff = idiff |
---|
| 556 | imin = ji |
---|
| 557 | ENDIF |
---|
| 558 | END DO |
---|
| 559 | jpnj = ifact(imin) |
---|
| 560 | jpni = ifact(imin + 1) |
---|
| 561 | ENDIF |
---|
| 562 | ! |
---|
| 563 | jpnij = jpni*jpnj |
---|
| 564 | ! |
---|
| 565 | END SUBROUTINE nemo_partition |
---|
| 566 | |
---|
| 567 | |
---|
| 568 | SUBROUTINE factorise( kfax, kmaxfax, knfax, kn, kerr ) |
---|
| 569 | !!---------------------------------------------------------------------- |
---|
| 570 | !! *** ROUTINE factorise *** |
---|
| 571 | !! |
---|
| 572 | !! ** Purpose : return the prime factors of n. |
---|
[7646] | 573 | !! knfax factors are returned in array kfax which is of |
---|
[3324] | 574 | !! maximum dimension kmaxfax. |
---|
| 575 | !! ** Method : |
---|
| 576 | !!---------------------------------------------------------------------- |
---|
| 577 | INTEGER , INTENT(in ) :: kn, kmaxfax |
---|
| 578 | INTEGER , INTENT( out) :: kerr, knfax |
---|
| 579 | INTEGER, DIMENSION(kmaxfax), INTENT( out) :: kfax |
---|
| 580 | ! |
---|
| 581 | INTEGER :: ifac, jl, inu |
---|
| 582 | INTEGER, PARAMETER :: ntest = 14 |
---|
[7646] | 583 | INTEGER, DIMENSION(ntest) :: ilfax |
---|
| 584 | !!---------------------------------------------------------------------- |
---|
[5407] | 585 | ! |
---|
[3324] | 586 | ! lfax contains the set of allowed factors. |
---|
[7646] | 587 | ilfax(:) = (/(2**jl,jl=ntest,1,-1)/) |
---|
| 588 | ! |
---|
[3324] | 589 | ! Clear the error flag and initialise output vars |
---|
[7646] | 590 | kerr = 0 |
---|
| 591 | kfax = 1 |
---|
[3324] | 592 | knfax = 0 |
---|
[7646] | 593 | ! |
---|
[3324] | 594 | ! Find the factors of n. |
---|
| 595 | IF( kn == 1 ) GOTO 20 |
---|
| 596 | |
---|
| 597 | ! nu holds the unfactorised part of the number. |
---|
| 598 | ! knfax holds the number of factors found. |
---|
| 599 | ! l points to the allowed factor list. |
---|
| 600 | ! ifac holds the current factor. |
---|
[7646] | 601 | ! |
---|
[3324] | 602 | inu = kn |
---|
| 603 | knfax = 0 |
---|
[7646] | 604 | ! |
---|
[3324] | 605 | DO jl = ntest, 1, -1 |
---|
| 606 | ! |
---|
| 607 | ifac = ilfax(jl) |
---|
| 608 | IF( ifac > inu ) CYCLE |
---|
| 609 | |
---|
| 610 | ! Test whether the factor will divide. |
---|
| 611 | |
---|
| 612 | IF( MOD(inu,ifac) == 0 ) THEN |
---|
| 613 | ! |
---|
| 614 | knfax = knfax + 1 ! Add the factor to the list |
---|
| 615 | IF( knfax > kmaxfax ) THEN |
---|
| 616 | kerr = 6 |
---|
| 617 | write (*,*) 'FACTOR: insufficient space in factor array ', knfax |
---|
| 618 | return |
---|
| 619 | ENDIF |
---|
| 620 | kfax(knfax) = ifac |
---|
| 621 | ! Store the other factor that goes with this one |
---|
| 622 | knfax = knfax + 1 |
---|
| 623 | kfax(knfax) = inu / ifac |
---|
| 624 | !WRITE (*,*) 'ARPDBG, factors ',knfax-1,' & ',knfax,' are ', kfax(knfax-1),' and ',kfax(knfax) |
---|
| 625 | ENDIF |
---|
| 626 | ! |
---|
| 627 | END DO |
---|
[7646] | 628 | ! |
---|
[3324] | 629 | 20 CONTINUE ! Label 20 is the exit point from the factor search loop. |
---|
| 630 | ! |
---|
| 631 | END SUBROUTINE factorise |
---|
| 632 | |
---|
| 633 | #if defined key_mpp_mpi |
---|
[7646] | 634 | |
---|
[3324] | 635 | SUBROUTINE nemo_northcomms |
---|
[7646] | 636 | !!---------------------------------------------------------------------- |
---|
[3324] | 637 | !! *** ROUTINE nemo_northcomms *** |
---|
[7646] | 638 | !! ** Purpose : Setup for north fold exchanges with explicit |
---|
| 639 | !! point-to-point messaging |
---|
[4232] | 640 | !! |
---|
[7646] | 641 | !! ** Method : Initialization of the northern neighbours lists. |
---|
[3324] | 642 | !!---------------------------------------------------------------------- |
---|
[4232] | 643 | !! 1.0 ! 2011-10 (A. C. Coward, NOCS & J. Donners, PRACE) |
---|
| 644 | !! 2.0 ! 2013-06 Setup avoiding MPI communication (I. Epicoco, S. Mocavero, CMCC) |
---|
[3324] | 645 | !!---------------------------------------------------------------------- |
---|
[4232] | 646 | INTEGER :: sxM, dxM, sxT, dxT, jn |
---|
| 647 | INTEGER :: njmppmax |
---|
[7646] | 648 | !!---------------------------------------------------------------------- |
---|
| 649 | ! |
---|
[4232] | 650 | njmppmax = MAXVAL( njmppt ) |
---|
[7646] | 651 | ! |
---|
[4232] | 652 | !initializes the north-fold communication variables |
---|
| 653 | isendto(:) = 0 |
---|
[7646] | 654 | nsndto = 0 |
---|
| 655 | ! |
---|
[4232] | 656 | !if I am a process in the north |
---|
| 657 | IF ( njmpp == njmppmax ) THEN |
---|
| 658 | !sxM is the first point (in the global domain) needed to compute the |
---|
| 659 | !north-fold for the current process |
---|
| 660 | sxM = jpiglo - nimppt(narea) - nlcit(narea) + 1 |
---|
| 661 | !dxM is the last point (in the global domain) needed to compute the |
---|
| 662 | !north-fold for the current process |
---|
| 663 | dxM = jpiglo - nimppt(narea) + 2 |
---|
[3324] | 664 | |
---|
[4232] | 665 | !loop over the other north-fold processes to find the processes |
---|
| 666 | !managing the points belonging to the sxT-dxT range |
---|
[5407] | 667 | |
---|
| 668 | DO jn = 1, jpni |
---|
[4232] | 669 | !sxT is the first point (in the global domain) of the jn |
---|
| 670 | !process |
---|
[5407] | 671 | sxT = nfiimpp(jn, jpnj) |
---|
[4232] | 672 | !dxT is the last point (in the global domain) of the jn |
---|
| 673 | !process |
---|
[5407] | 674 | dxT = nfiimpp(jn, jpnj) + nfilcit(jn, jpnj) - 1 |
---|
[4232] | 675 | IF ((sxM .gt. sxT) .AND. (sxM .lt. dxT)) THEN |
---|
| 676 | nsndto = nsndto + 1 |
---|
[5407] | 677 | isendto(nsndto) = jn |
---|
| 678 | ELSEIF ((sxM .le. sxT) .AND. (dxM .ge. dxT)) THEN |
---|
[4232] | 679 | nsndto = nsndto + 1 |
---|
| 680 | isendto(nsndto) = jn |
---|
| 681 | ELSEIF ((dxM .lt. dxT) .AND. (sxT .lt. dxM)) THEN |
---|
| 682 | nsndto = nsndto + 1 |
---|
| 683 | isendto(nsndto) = jn |
---|
[7646] | 684 | ENDIF |
---|
[4232] | 685 | END DO |
---|
[5407] | 686 | nfsloop = 1 |
---|
| 687 | nfeloop = nlci |
---|
| 688 | DO jn = 2,jpni-1 |
---|
| 689 | IF(nfipproc(jn,jpnj) .eq. (narea - 1)) THEN |
---|
| 690 | IF (nfipproc(jn - 1 ,jpnj) .eq. -1) THEN |
---|
| 691 | nfsloop = nldi |
---|
| 692 | ENDIF |
---|
| 693 | IF (nfipproc(jn + 1,jpnj) .eq. -1) THEN |
---|
| 694 | nfeloop = nlei |
---|
| 695 | ENDIF |
---|
| 696 | ENDIF |
---|
| 697 | END DO |
---|
| 698 | |
---|
[3324] | 699 | ENDIF |
---|
[4232] | 700 | l_north_nogather = .TRUE. |
---|
| 701 | END SUBROUTINE nemo_northcomms |
---|
[3324] | 702 | |
---|
| 703 | #else |
---|
| 704 | SUBROUTINE nemo_northcomms ! Dummy routine |
---|
| 705 | WRITE(*,*) 'nemo_northcomms: You should not have seen this print! error?' |
---|
| 706 | END SUBROUTINE nemo_northcomms |
---|
| 707 | #endif |
---|
[7646] | 708 | |
---|
[3324] | 709 | !!====================================================================== |
---|
| 710 | END MODULE nemogcm |
---|