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