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