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