source: NEMO/trunk/src/NST/agrif_user.F90 @ 9596

Last change on this file since 9596 was 9596, checked in by nicolasmartin, 2 years ago

Reorganisation plan for NEMO repository: preliminary implementation of the new trunk structure (ref #2015)

  • Deletion of useless 1st level, add new explicit names for folders
  • Extract dev tools (SETTE and Trusting) to /utils/CI
  • Extract figures folder from documentation to /utils/figures
  • Extrac TEST_CASES to /utils/test_cases
  • Move ./TOOLS/COMPILE to ./mk
  • Add few wiki files at the root: README, INSTALL and LICENSE with full text of CeCILL v2.0
  • Style: uppercase for wiki files, lowercase for folder names

Additionally, inclusion of routines renaming in NST: agrif_si3 → agrif_ice

  • Property svn:keywords set to Id
File size: 35.8 KB
Line 
1#undef UPD_HIGH   /* MIX HIGH UPDATE */
2#if defined key_agrif
3!!----------------------------------------------------------------------
4!! NEMO/NST 4.0 , NEMO Consortium (2017)
5!! $Id$
6!! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
7!!----------------------------------------------------------------------
8SUBROUTINE agrif_user
9END SUBROUTINE agrif_user
10
11SUBROUTINE agrif_before_regridding
12END SUBROUTINE agrif_before_regridding
13
14SUBROUTINE Agrif_InitWorkspace
15   !!----------------------------------------------------------------------
16   !!                 *** ROUTINE Agrif_InitWorkspace ***
17   !!----------------------------------------------------------------------
18   USE par_oce
19   USE dom_oce
20   USE nemogcm
21   USE mppini
22   !!
23   IMPLICIT NONE
24   !!----------------------------------------------------------------------
25   !
26   IF( .NOT. Agrif_Root() ) THEN
27      ! no more static variables
28!!$! JC: change to allow for different vertical levels
29!!$!     jpk is already set
30!!$!     keep it jpk possibly different from jpkglo which
31!!$!     hold parent grid vertical levels number (set earlier)
32!!$!      jpk     = jpkglo
33   ENDIF
34   !
35END SUBROUTINE Agrif_InitWorkspace
36
37
38SUBROUTINE Agrif_InitValues
39   !!----------------------------------------------------------------------
40   !!                 *** ROUTINE Agrif_InitValues ***
41   !!
42   !! ** Purpose :: Declaration of variables to be interpolated
43   !!----------------------------------------------------------------------
44   USE Agrif_Util
45   USE oce 
46   USE dom_oce
47   USE nemogcm
48   USE tradmp
49   USE bdy_oce   , ONLY: ln_bdy
50   !!
51   IMPLICIT NONE
52   !!----------------------------------------------------------------------
53   !
54   CALL nemo_init       !* Initializations of each fine grid
55
56   !                    !* Agrif initialization
57   CALL agrif_nemo_init
58   CALL Agrif_InitValues_cont_dom
59   CALL Agrif_InitValues_cont
60# if defined key_top
61   CALL Agrif_InitValues_cont_top
62# endif
63# if defined key_si3
64   CALL Agrif_InitValues_cont_si3
65# endif
66   !
67   IF ( Agrif_Level().EQ.Agrif_MaxLevel() ) CALL agrif_Update_ini()
68
69   Agrif_UseSpecialValueInUpdate = .FALSE.     
70
71END SUBROUTINE Agrif_initvalues
72
73
74SUBROUTINE Agrif_InitValues_cont_dom
75   !!----------------------------------------------------------------------
76   !!                 *** ROUTINE Agrif_InitValues_cont ***
77   !!
78   !! ** Purpose ::   Declaration of variables to be interpolated
79   !!----------------------------------------------------------------------
80   USE Agrif_Util
81   USE oce 
82   USE dom_oce
83   USE nemogcm
84   USE in_out_manager
85   USE agrif_oce_update
86   USE agrif_oce_interp
87   USE agrif_oce_sponge
88   !
89   IMPLICIT NONE
90   !!----------------------------------------------------------------------
91   !
92   ! Declaration of the type of variable which have to be interpolated
93   !
94   CALL agrif_declare_var_dom
95   !
96END SUBROUTINE Agrif_InitValues_cont_dom
97
98
99SUBROUTINE agrif_declare_var_dom
100   !!----------------------------------------------------------------------
101   !!                 *** ROUTINE agrif_declare_var ***
102   !!
103   !! ** Purpose :: Declaration of variables to be interpolated
104   !!----------------------------------------------------------------------
105   USE agrif_util
106   USE par_oce       
107   USE oce
108   !
109   IMPLICIT NONE
110   !
111   INTEGER :: ind1, ind2, ind3
112   !!----------------------------------------------------------------------
113
114   ! 1. Declaration of the type of variable which have to be interpolated
115   !---------------------------------------------------------------------
116   ind1 =     nbghostcells
117   ind2 = 1 + nbghostcells
118   ind3 = 2 + nbghostcells
119   CALL agrif_declare_variable((/1,2/),(/ind2,ind3/),(/'x','y'/),(/1,1/),(/nlci,nlcj/),e1u_id)
120   CALL agrif_declare_variable((/2,1/),(/ind3,ind2/),(/'x','y'/),(/1,1/),(/nlci,nlcj/),e2v_id)
121
122   ! 2. Type of interpolation
123   !-------------------------
124   CALL Agrif_Set_bcinterp( e1u_id, interp1=Agrif_linear, interp2=AGRIF_ppm    )
125   CALL Agrif_Set_bcinterp( e2v_id, interp1=AGRIF_ppm   , interp2=Agrif_linear )
126
127   ! 3. Location of interpolation
128   !-----------------------------
129   CALL Agrif_Set_bc(e1u_id,(/0,ind1-1/))
130   CALL Agrif_Set_bc(e2v_id,(/0,ind1-1/))
131
132   ! 4. Update type
133   !---------------
134# if defined UPD_HIGH
135   CALL Agrif_Set_Updatetype(e1u_id,update1 = Agrif_Update_Average, update2=Agrif_Update_Full_Weighting)
136   CALL Agrif_Set_Updatetype(e2v_id,update1 = Agrif_Update_Full_Weighting, update2=Agrif_Update_Average)
137#else
138   CALL Agrif_Set_Updatetype(e1u_id,update1 = Agrif_Update_Copy, update2=Agrif_Update_Average)
139   CALL Agrif_Set_Updatetype(e2v_id,update1 = Agrif_Update_Average, update2=Agrif_Update_Copy)
140#endif
141
142END SUBROUTINE agrif_declare_var_dom
143
144
145SUBROUTINE Agrif_InitValues_cont
146   !!----------------------------------------------------------------------
147   !!                 *** ROUTINE Agrif_InitValues_cont ***
148   !!
149   !! ** Purpose ::   Declaration of variables to be interpolated
150   !!----------------------------------------------------------------------
151   USE agrif_oce_update
152   USE agrif_oce_interp
153   USE agrif_oce_sponge
154   USE Agrif_Util
155   USE oce 
156   USE dom_oce
157   USE zdf_oce
158   USE nemogcm
159   !
160   USE lib_mpp
161   USE in_out_manager
162   !
163   IMPLICIT NONE
164   !
165   LOGICAL :: check_namelist
166   CHARACTER(len=15) :: cl_check1, cl_check2, cl_check3, cl_check4 
167   !!----------------------------------------------------------------------
168
169   ! 1. Declaration of the type of variable which have to be interpolated
170   !---------------------------------------------------------------------
171   CALL agrif_declare_var
172
173   ! 2. First interpolations of potentially non zero fields
174   !-------------------------------------------------------
175   Agrif_SpecialValue    = 0._wp
176   Agrif_UseSpecialValue = .TRUE.
177   CALL Agrif_Bc_variable(tsn_id,calledweight=1.,procname=interptsn)
178   CALL Agrif_Sponge
179   tabspongedone_tsn = .FALSE.
180   CALL Agrif_Bc_variable(tsn_sponge_id,calledweight=1.,procname=interptsn_sponge)
181   ! reset tsa to zero
182   tsa(:,:,:,:) = 0.
183
184   Agrif_UseSpecialValue = ln_spc_dyn
185   CALL Agrif_Bc_variable(un_interp_id,calledweight=1.,procname=interpun)
186   CALL Agrif_Bc_variable(vn_interp_id,calledweight=1.,procname=interpvn)
187   tabspongedone_u = .FALSE.
188   tabspongedone_v = .FALSE.
189   CALL Agrif_Bc_variable(un_sponge_id,calledweight=1.,procname=interpun_sponge)
190   tabspongedone_u = .FALSE.
191   tabspongedone_v = .FALSE.
192   CALL Agrif_Bc_variable(vn_sponge_id,calledweight=1.,procname=interpvn_sponge)
193
194   Agrif_UseSpecialValue = .TRUE.
195   CALL Agrif_Bc_variable(sshn_id,calledweight=1., procname=interpsshn )
196   hbdy_w(:,:) = 0.e0 ; hbdy_e(:,:) = 0.e0 ; hbdy_n(:,:) = 0.e0 ; hbdy_s(:,:) = 0.e0
197   ssha(:,:) = 0.e0
198
199   IF ( ln_dynspg_ts ) THEN
200      Agrif_UseSpecialValue = ln_spc_dyn
201      CALL Agrif_Bc_variable(unb_id,calledweight=1.,procname=interpunb)
202      CALL Agrif_Bc_variable(vnb_id,calledweight=1.,procname=interpvnb)
203      CALL Agrif_Bc_variable(ub2b_interp_id,calledweight=1.,procname=interpub2b)
204      CALL Agrif_Bc_variable(vb2b_interp_id,calledweight=1.,procname=interpvb2b)
205      ubdy_w(:,:) = 0.e0 ; vbdy_w(:,:) = 0.e0
206      ubdy_e(:,:) = 0.e0 ; vbdy_e(:,:) = 0.e0
207      ubdy_n(:,:) = 0.e0 ; vbdy_n(:,:) = 0.e0
208      ubdy_s(:,:) = 0.e0 ; vbdy_s(:,:) = 0.e0
209   ENDIF
210
211   Agrif_UseSpecialValue = .FALSE. 
212   ! reset velocities to zero
213   ua(:,:,:) = 0.
214   va(:,:,:) = 0.
215
216   ! 3. Some controls
217   !-----------------
218   check_namelist = .TRUE.
219
220   IF( check_namelist ) THEN 
221
222      ! Check time steps           
223      IF( NINT(Agrif_Rhot()) * NINT(rdt) .NE. Agrif_Parent(rdt) ) THEN
224         WRITE(cl_check1,*)  NINT(Agrif_Parent(rdt))
225         WRITE(cl_check2,*)  NINT(rdt)
226         WRITE(cl_check3,*)  NINT(Agrif_Parent(rdt)/Agrif_Rhot())
227         CALL ctl_stop( 'Incompatible time step between ocean grids',   &
228               &               'parent grid value : '//cl_check1    ,   & 
229               &               'child  grid value : '//cl_check2    ,   & 
230               &               'value on child grid should be changed to : '//cl_check3 )
231      ENDIF
232
233      ! Check run length
234      IF( Agrif_IRhot() * (Agrif_Parent(nitend)- &
235            Agrif_Parent(nit000)+1) .NE. (nitend-nit000+1) ) THEN
236         WRITE(cl_check1,*)  (Agrif_Parent(nit000)-1)*Agrif_IRhot() + 1
237         WRITE(cl_check2,*)   Agrif_Parent(nitend)   *Agrif_IRhot()
238         CALL ctl_warn( 'Incompatible run length between grids'                      ,   &
239               &               'nit000 on fine grid will be changed to : '//cl_check1,   &
240               &               'nitend on fine grid will be changed to : '//cl_check2    )
241         nit000 = (Agrif_Parent(nit000)-1)*Agrif_IRhot() + 1
242         nitend =  Agrif_Parent(nitend)   *Agrif_IRhot()
243      ENDIF
244
245      ! Check free surface scheme
246      IF ( ( Agrif_Parent(ln_dynspg_ts ).AND.ln_dynspg_exp ).OR.&
247         & ( Agrif_Parent(ln_dynspg_exp).AND.ln_dynspg_ts ) ) THEN
248         WRITE(cl_check1,*)  Agrif_Parent( ln_dynspg_ts )
249         WRITE(cl_check2,*)  ln_dynspg_ts
250         WRITE(cl_check3,*)  Agrif_Parent( ln_dynspg_exp )
251         WRITE(cl_check4,*)  ln_dynspg_exp
252         CALL ctl_stop( 'Incompatible free surface scheme between grids' ,  &
253               &               'parent grid ln_dynspg_ts  :'//cl_check1  ,  & 
254               &               'child  grid ln_dynspg_ts  :'//cl_check2  ,  &
255               &               'parent grid ln_dynspg_exp :'//cl_check3  ,  &
256               &               'child  grid ln_dynspg_exp :'//cl_check4  ,  &
257               &               'those logicals should be identical' )                 
258         STOP
259      ENDIF
260
261      ! Check if identical linear free surface option
262      IF ( ( Agrif_Parent(ln_linssh ).AND.(.NOT.ln_linssh )).OR.&
263         & ( (.NOT.Agrif_Parent(ln_linssh)).AND.ln_linssh ) ) THEN
264         WRITE(cl_check1,*)  Agrif_Parent(ln_linssh )
265         WRITE(cl_check2,*)  ln_linssh
266         CALL ctl_stop( 'Incompatible linearized fs option between grids',  &
267               &               'parent grid ln_linssh  :'//cl_check1     ,  &
268               &               'child  grid ln_linssh  :'//cl_check2     ,  &
269               &               'those logicals should be identical' )                 
270         STOP
271      ENDIF
272
273      ! check if masks and bathymetries match
274      IF(ln_chk_bathy) THEN
275         !
276         IF(lwp) WRITE(numout,*) 'AGRIF: Check Bathymetry and masks near bdys. Level: ', Agrif_Level()
277         !
278         kindic_agr = 0
279         ! check if umask agree with parent along western and eastern boundaries:
280         CALL Agrif_Bc_variable(umsk_id,calledweight=1.,procname=interpumsk)
281         ! check if vmask agree with parent along northern and southern boundaries:
282         CALL Agrif_Bc_variable(vmsk_id,calledweight=1.,procname=interpvmsk)
283         ! check if tmask and vertical scale factors agree with parent over first two coarse grid points:
284         CALL Agrif_Bc_variable(e3t_id,calledweight=1.,procname=interpe3t)
285         !
286         IF (lk_mpp) CALL mpp_sum( kindic_agr )
287         IF( kindic_agr /= 0 ) THEN
288            CALL ctl_stop('Child Bathymetry is not correct near boundaries.')
289         ELSE
290            IF(lwp) WRITE(numout,*) 'Child Bathymetry is ok near boundaries.'
291         END IF
292      ENDIF
293      !
294   ENDIF
295   !
296END SUBROUTINE Agrif_InitValues_cont
297
298RECURSIVE SUBROUTINE Agrif_Update_ini( )
299   !!----------------------------------------------------------------------
300   !!                 *** ROUTINE agrif_Update_ini ***
301   !!
302   !! ** Purpose :: Recursive update done at initialization
303   !!----------------------------------------------------------------------
304   USE dom_oce
305   USE agrif_oce_update
306#if defined key_top
307   USE agrif_top_update
308#endif
309#if defined key_si3
310   USE agrif_ice_update
311#endif
312   !
313   IMPLICIT NONE
314   !!----------------------------------------------------------------------
315   !
316   IF (Agrif_Root()) RETURN
317   !
318   CALL Agrif_Update_ssh()
319   IF (.NOT.ln_linssh) CALL Agrif_Update_vvl()
320   CALL Agrif_Update_tra()
321#if defined key_top
322   CALL Agrif_Update_Trc()
323#endif
324   CALL Agrif_Update_dyn()
325! JC remove update because this precludes from perfect restartability
326!!   CALL Agrif_Update_tke(0)
327
328#if defined key_si3
329   CALL agrif_update_si3(0)
330#endif
331   
332   CALL Agrif_ChildGrid_To_ParentGrid()
333   CALL Agrif_Update_ini()
334   CALL Agrif_ParentGrid_To_ChildGrid()
335
336END SUBROUTINE agrif_update_ini
337
338SUBROUTINE agrif_declare_var
339   !!----------------------------------------------------------------------
340   !!                 *** ROUTINE agrif_declarE_var ***
341   !!
342   !! ** Purpose :: Declaration of variables to be interpolated
343   !!----------------------------------------------------------------------
344   USE agrif_util
345   USE agrif_oce
346   USE par_oce       ! ocean parameters
347   USE zdf_oce       ! vertical physics
348   USE oce
349   !
350   IMPLICIT NONE
351   !
352   INTEGER :: ind1, ind2, ind3
353   !!----------------------------------------------------------------------
354
355   ! 1. Declaration of the type of variable which have to be interpolated
356   !---------------------------------------------------------------------
357   ind1 =     nbghostcells
358   ind2 = 1 + nbghostcells
359   ind3 = 2 + nbghostcells
360# if defined key_vertical
361   CALL agrif_declare_variable((/2,2,0,0/),(/ind3,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,jpts+1/),tsn_id)
362   CALL agrif_declare_variable((/2,2,0,0/),(/ind3,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,jpts+1/),tsn_sponge_id)
363
364   CALL agrif_declare_variable((/1,2,0,0/),(/ind2,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,2/),un_interp_id)
365   CALL agrif_declare_variable((/2,1,0,0/),(/ind3,ind2,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,2/),vn_interp_id)
366   CALL agrif_declare_variable((/1,2,0,0/),(/ind2,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,2/),un_update_id)
367   CALL agrif_declare_variable((/2,1,0,0/),(/ind3,ind2,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,2/),vn_update_id)
368   CALL agrif_declare_variable((/1,2,0,0/),(/ind2,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,2/),un_sponge_id)
369   CALL agrif_declare_variable((/2,1,0,0/),(/ind3,ind2,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,2/),vn_sponge_id)
370# else
371   CALL agrif_declare_variable((/2,2,0,0/),(/ind3,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,jpts/),tsn_id)
372   CALL agrif_declare_variable((/2,2,0,0/),(/ind3,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,jpts/),tsn_sponge_id)
373
374   CALL agrif_declare_variable((/1,2,0,0/),(/ind2,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,1/),un_interp_id)
375   CALL agrif_declare_variable((/2,1,0,0/),(/ind3,ind2,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,1/),vn_interp_id)
376   CALL agrif_declare_variable((/1,2,0,0/),(/ind2,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,1/),un_update_id)
377   CALL agrif_declare_variable((/2,1,0,0/),(/ind3,ind2,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,1/),vn_update_id)
378   CALL agrif_declare_variable((/1,2,0,0/),(/ind2,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,1/),un_sponge_id)
379   CALL agrif_declare_variable((/2,1,0,0/),(/ind3,ind2,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,1/),vn_sponge_id)
380# endif
381
382   CALL agrif_declare_variable((/2,2,0/),(/ind3,ind3,0/),(/'x','y','N'/),(/1,1,1/),(/nlci,nlcj,jpk/),e3t_id)
383   CALL agrif_declare_variable((/1,2,0/),(/ind2,ind3,0/),(/'x','y','N'/),(/1,1,1/),(/nlci,nlcj,jpk/),umsk_id)
384   CALL agrif_declare_variable((/2,1,0/),(/ind3,ind2,0/),(/'x','y','N'/),(/1,1,1/),(/nlci,nlcj,jpk/),vmsk_id)
385
386   CALL agrif_declare_variable((/2,2,0,0/),(/ind3,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,3/),scales_t_id)
387
388   CALL agrif_declare_variable((/1,2/),(/ind2,ind3/),(/'x','y'/),(/1,1/),(/nlci,nlcj/),unb_id)
389   CALL agrif_declare_variable((/2,1/),(/ind3,ind2/),(/'x','y'/),(/1,1/),(/nlci,nlcj/),vnb_id)
390   CALL agrif_declare_variable((/1,2/),(/ind2,ind3/),(/'x','y'/),(/1,1/),(/nlci,nlcj/),ub2b_interp_id)
391   CALL agrif_declare_variable((/2,1/),(/ind3,ind2/),(/'x','y'/),(/1,1/),(/nlci,nlcj/),vb2b_interp_id)
392   CALL agrif_declare_variable((/1,2/),(/ind2,ind3/),(/'x','y'/),(/1,1/),(/nlci,nlcj/),ub2b_update_id)
393   CALL agrif_declare_variable((/2,1/),(/ind3,ind2/),(/'x','y'/),(/1,1/),(/nlci,nlcj/),vb2b_update_id)
394
395   CALL agrif_declare_variable((/2,2/),(/ind3,ind3/),(/'x','y'/),(/1,1/),(/nlci,nlcj/),sshn_id)
396
397   IF( ln_zdftke.OR.ln_zdfgls ) THEN
398!      CALL agrif_declare_variable((/2,2,0/),(/ind3,ind3,0/),(/'x','y','N'/),(/1,1,1/),(/nlci,nlcj,jpk/), en_id)
399!      CALL agrif_declare_variable((/2,2,0/),(/ind3,ind3,0/),(/'x','y','N'/),(/1,1,1/),(/nlci,nlcj,jpk/),avt_id)
400# if defined key_vertical
401      CALL agrif_declare_variable((/2,2,0,0/),(/ind3,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,2/),avm_id)
402# else
403      CALL agrif_declare_variable((/2,2,0,0/),(/ind3,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,1/),avm_id)
404# endif
405   ENDIF
406
407   ! 2. Type of interpolation
408   !-------------------------
409   CALL Agrif_Set_bcinterp(tsn_id,interp=AGRIF_linear)
410
411   CALL Agrif_Set_bcinterp(un_interp_id,interp1=Agrif_linear,interp2=AGRIF_ppm)
412   CALL Agrif_Set_bcinterp(vn_interp_id,interp1=AGRIF_ppm,interp2=Agrif_linear)
413
414   CALL Agrif_Set_bcinterp(tsn_sponge_id,interp=AGRIF_linear)
415
416   CALL Agrif_Set_bcinterp(sshn_id,interp=AGRIF_linear)
417   CALL Agrif_Set_bcinterp(unb_id,interp1=Agrif_linear,interp2=AGRIF_ppm)
418   CALL Agrif_Set_bcinterp(vnb_id,interp1=AGRIF_ppm,interp2=Agrif_linear)
419   CALL Agrif_Set_bcinterp(ub2b_interp_id,interp1=Agrif_linear,interp2=AGRIF_ppm)
420   CALL Agrif_Set_bcinterp(vb2b_interp_id,interp1=AGRIF_ppm,interp2=Agrif_linear)
421
422
423   CALL Agrif_Set_bcinterp(un_sponge_id,interp1=Agrif_linear,interp2=AGRIF_ppm)
424   CALL Agrif_Set_bcinterp(vn_sponge_id,interp1=AGRIF_ppm,interp2=Agrif_linear)
425
426   CALL Agrif_Set_bcinterp(e3t_id,interp=AGRIF_constant)
427   CALL Agrif_Set_bcinterp(umsk_id,interp=AGRIF_constant)
428   CALL Agrif_Set_bcinterp(vmsk_id,interp=AGRIF_constant)
429
430   IF( ln_zdftke.OR.ln_zdfgls )   CALL Agrif_Set_bcinterp( avm_id, interp=AGRIF_linear )
431
432   ! 3. Location of interpolation
433   !-----------------------------
434   CALL Agrif_Set_bc(       tsn_id, (/0,ind1/) )
435   CALL Agrif_Set_bc( un_interp_id, (/0,ind1/) )
436   CALL Agrif_Set_bc( vn_interp_id, (/0,ind1/) )
437
438   CALL Agrif_Set_bc( tsn_sponge_id, (/-nn_sponge_len*Agrif_irhox()-1,0/) )  ! if west and rhox=3 and sponge=2 and ghost=1: columns 2 to 9
439   CALL Agrif_Set_bc(  un_sponge_id, (/-nn_sponge_len*Agrif_irhox()-1,0/) )
440   CALL Agrif_Set_bc(  vn_sponge_id, (/-nn_sponge_len*Agrif_irhox()-1,0/) )
441
442   CALL Agrif_Set_bc(        sshn_id, (/0,ind1-1/) )
443   CALL Agrif_Set_bc(         unb_id, (/0,ind1-1/) )
444   CALL Agrif_Set_bc(         vnb_id, (/0,ind1-1/) )
445   CALL Agrif_Set_bc( ub2b_interp_id, (/0,ind1-1/) )
446   CALL Agrif_Set_bc( vb2b_interp_id, (/0,ind1-1/) )
447
448   CALL Agrif_Set_bc(  e3t_id, (/-2*Agrif_irhox()-1,ind1-1/) )   ! if west and rhox=3 and ghost=1: column 2 to 9
449   CALL Agrif_Set_bc( umsk_id, (/0,ind1-1/)                  )
450   CALL Agrif_Set_bc( vmsk_id, (/0,ind1-1/)                  )
451
452   IF( ln_zdftke.OR.ln_zdfgls )   CALL Agrif_Set_bc( avm_id, (/0,ind1/) )
453
454   ! 4. Update type
455   !---------------
456   CALL Agrif_Set_Updatetype(scales_t_id, update = AGRIF_Update_Average)
457
458# if defined UPD_HIGH
459   CALL Agrif_Set_Updatetype(tsn_id, update = Agrif_Update_Full_Weighting)
460   CALL Agrif_Set_Updatetype(un_update_id,update1 = Agrif_Update_Average, update2 = Agrif_Update_Full_Weighting)
461   CALL Agrif_Set_Updatetype(vn_update_id,update1 = Agrif_Update_Full_Weighting, update2 = Agrif_Update_Average)
462
463   CALL Agrif_Set_Updatetype(ub2b_update_id,update1 = Agrif_Update_Average, update2 = Agrif_Update_Full_Weighting)
464   CALL Agrif_Set_Updatetype(vb2b_update_id,update1 = Agrif_Update_Full_Weighting, update2 = Agrif_Update_Average)
465   CALL Agrif_Set_Updatetype(sshn_id, update = Agrif_Update_Full_Weighting)
466   CALL Agrif_Set_Updatetype(e3t_id, update = Agrif_Update_Full_Weighting)
467
468   IF( ln_zdftke.OR.ln_zdfgls ) THEN
469!      CALL Agrif_Set_Updatetype( en_id, update = AGRIF_Update_Full_Weighting)
470!      CALL Agrif_Set_Updatetype(avt_id, update = AGRIF_Update_Full_Weighting)
471!      CALL Agrif_Set_Updatetype(avm_id, update = AGRIF_Update_Full_Weighting)
472   ENDIF
473
474#else
475   CALL Agrif_Set_Updatetype(tsn_id, update = AGRIF_Update_Average)
476   CALL Agrif_Set_Updatetype(un_update_id,update1 = Agrif_Update_Copy, update2 = Agrif_Update_Average)
477   CALL Agrif_Set_Updatetype(vn_update_id,update1 = Agrif_Update_Average, update2 = Agrif_Update_Copy)
478
479   CALL Agrif_Set_Updatetype(ub2b_update_id,update1 = Agrif_Update_Copy, update2 = Agrif_Update_Average)
480   CALL Agrif_Set_Updatetype(vb2b_update_id,update1 = Agrif_Update_Average, update2 = Agrif_Update_Copy)
481   CALL Agrif_Set_Updatetype(sshn_id, update = AGRIF_Update_Average)
482   CALL Agrif_Set_Updatetype(e3t_id, update = AGRIF_Update_Average)
483
484   IF( ln_zdftke.OR.ln_zdfgls ) THEN
485!      CALL Agrif_Set_Updatetype( en_id, update = AGRIF_Update_Average)
486!      CALL Agrif_Set_Updatetype(avt_id, update = AGRIF_Update_Average)
487!      CALL Agrif_Set_Updatetype(avm_id, update = AGRIF_Update_Average)
488   ENDIF
489
490#endif
491   !
492END SUBROUTINE agrif_declare_var
493
494#if defined key_si3
495SUBROUTINE Agrif_InitValues_cont_si3
496   !!----------------------------------------------------------------------
497   !!                 *** ROUTINE Agrif_InitValues_cont_si3 ***
498   !!
499   !! ** Purpose :: Initialisation of variables to be interpolated for LIM3
500   !!----------------------------------------------------------------------
501   USE Agrif_Util
502   USE sbc_oce, ONLY : nn_fsbc  ! clem: necessary otherwise Agrif_Parent(nn_fsbc) = nn_fsbc
503   USE ice
504   USE agrif_ice
505   USE in_out_manager
506   USE agrif_ice_interp
507   USE lib_mpp
508   !
509   IMPLICIT NONE
510   !!----------------------------------------------------------------------
511   !
512   ! Declaration of the type of variable which have to be interpolated (parent=>child)
513   !----------------------------------------------------------------------------------
514   CALL agrif_declare_var_si3
515
516   ! Controls
517
518   ! clem: For some reason, nn_fsbc(child)/=1 does not work properly (signal can be largely degraded by the agrif zoom)
519   !          the run must satisfy CFL=Uice/(dx/dt) < 0.6/nn_fsbc(child)
520   !          therefore, if nn_fsbc(child)>1 one must reduce the time-step in proportion to nn_fsbc(child), which is not acceptable
521   !       If a solution is found, the following stop could be removed because the rest of the code take nn_fsbc(child) into account
522   IF( nn_fsbc > 1 )  CALL ctl_stop('nn_fsbc(child) must be set to 1 otherwise agrif and sea-ice may not work properly')
523
524   ! stop if rhot * nn_fsbc(parent) /= N * nn_fsbc(child) with N being integer
525   IF( MOD( Agrif_irhot() * Agrif_Parent(nn_fsbc), nn_fsbc ) /= 0 )  THEN
526      CALL ctl_stop('rhot * nn_fsbc(parent) /= N * nn_fsbc(child), therefore nn_fsbc(child) should be set to 1 or nn_fsbc(parent)')
527   ENDIF
528   ! First Interpolations (using "after" ice subtime step => lim_nbstep=1)
529   !----------------------------------------------------------------------
530   lim_nbstep = ( Agrif_irhot() * Agrif_Parent(nn_fsbc) / nn_fsbc ) ! clem: to have calledweight=1 in interp (otherwise the western border of the zoom is wrong)
531   CALL agrif_interp_si3('U') ! interpolation of ice velocities
532   CALL agrif_interp_si3('V') ! interpolation of ice velocities
533   CALL agrif_interp_si3('T') ! interpolation of ice tracers
534   lim_nbstep = 0
535   
536   !
537END SUBROUTINE Agrif_InitValues_cont_si3
538
539SUBROUTINE agrif_declare_var_si3
540   !!----------------------------------------------------------------------
541   !!                 *** ROUTINE agrif_declare_var_si3 ***
542   !!
543   !! ** Purpose :: Declaration of variables to be interpolated for LIM3
544   !!----------------------------------------------------------------------
545   USE Agrif_Util
546   USE ice
547   USE par_oce, ONLY : nbghostcells
548   !
549   IMPLICIT NONE
550   !
551   INTEGER :: ind1, ind2, ind3
552   !!----------------------------------------------------------------------
553   !
554   ! 1. Declaration of the type of variable which have to be interpolated (parent=>child)
555   !       agrif_declare_variable(position,1st point index,--,--,dimensions,name)
556   !           ex.:  position=> 1,1 = not-centered (in i and j)
557   !                            2,2 =     centered (    -     )
558   !                 index   => 1,1 = one ghost line
559   !                            2,2 = two ghost lines
560   !-------------------------------------------------------------------------------------
561   ind1 =     nbghostcells
562   ind2 = 1 + nbghostcells
563   ind3 = 2 + nbghostcells
564   CALL agrif_declare_variable((/2,2,0/),(/ind3,ind3,0/),(/'x','y','N'/),(/1,1,1/),(/nlci,nlcj,jpl*(8+nlay_s+nlay_i)/),tra_ice_id)
565   CALL agrif_declare_variable((/1,2/)  ,(/ind2,ind3/)  ,(/'x','y'/)    ,(/1,1/)  ,(/nlci,nlcj/)                      ,u_ice_id  )
566   CALL agrif_declare_variable((/2,1/)  ,(/ind3,ind2/)  ,(/'x','y'/)    ,(/1,1/)  ,(/nlci,nlcj/)                      ,v_ice_id  )
567
568   ! 2. Set interpolations (normal & tangent to the grid cell for velocities)
569   !-----------------------------------
570   CALL Agrif_Set_bcinterp(tra_ice_id, interp  = AGRIF_linear)
571   CALL Agrif_Set_bcinterp(u_ice_id  , interp1 = Agrif_linear,interp2 = AGRIF_ppm   )
572   CALL Agrif_Set_bcinterp(v_ice_id  , interp1 = AGRIF_ppm   ,interp2 = Agrif_linear)
573
574   ! 3. Set location of interpolations
575   !----------------------------------
576   CALL Agrif_Set_bc(tra_ice_id,(/0,ind1/))
577   CALL Agrif_Set_bc(u_ice_id  ,(/0,ind1/))
578   CALL Agrif_Set_bc(v_ice_id  ,(/0,ind1/))
579
580   ! 4. Set update type in case 2 ways (child=>parent) (normal & tangent to the grid cell for velocities)
581   !--------------------------------------------------
582# if defined UPD_HIGH
583   CALL Agrif_Set_Updatetype(tra_ice_id, update  = Agrif_Update_Full_Weighting)
584   CALL Agrif_Set_Updatetype(u_ice_id  , update1 = Agrif_Update_Average       , update2 = Agrif_Update_Full_Weighting)
585   CALL Agrif_Set_Updatetype(v_ice_id  , update1 = Agrif_Update_Full_Weighting, update2 = Agrif_Update_Average       )
586#else
587   CALL Agrif_Set_Updatetype(tra_ice_id, update  = AGRIF_Update_Average)
588   CALL Agrif_Set_Updatetype(u_ice_id  , update1 = Agrif_Update_Copy   , update2 = Agrif_Update_Average)
589   CALL Agrif_Set_Updatetype(v_ice_id  , update1 = Agrif_Update_Average, update2 = Agrif_Update_Copy   )
590#endif
591
592END SUBROUTINE agrif_declare_var_si3
593#endif
594
595
596# if defined key_top
597SUBROUTINE Agrif_InitValues_cont_top
598   !!----------------------------------------------------------------------
599   !!                 *** ROUTINE Agrif_InitValues_cont_top ***
600   !!
601   !! ** Purpose :: Declaration of variables to be interpolated
602   !!----------------------------------------------------------------------
603   USE Agrif_Util
604   USE oce 
605   USE dom_oce
606   USE nemogcm
607   USE par_trc
608   USE lib_mpp
609   USE trc
610   USE in_out_manager
611   USE agrif_oce_sponge
612   USE agrif_top_update
613   USE agrif_top_interp
614   USE agrif_top_sponge
615   !!
616   IMPLICIT NONE
617   !
618   CHARACTER(len=10) :: cl_check1, cl_check2, cl_check3
619   LOGICAL :: check_namelist
620   !!----------------------------------------------------------------------
621
622
623   ! 1. Declaration of the type of variable which have to be interpolated
624   !---------------------------------------------------------------------
625   CALL agrif_declare_var_top
626
627   ! 2. First interpolations of potentially non zero fields
628   !-------------------------------------------------------
629   Agrif_SpecialValue=0.
630   Agrif_UseSpecialValue = .TRUE.
631   CALL Agrif_Bc_variable(trn_id,calledweight=1.,procname=interptrn)
632   Agrif_UseSpecialValue = .FALSE.
633   CALL Agrif_Sponge
634   tabspongedone_trn = .FALSE.
635   CALL Agrif_Bc_variable(trn_sponge_id,calledweight=1.,procname=interptrn_sponge)
636   ! reset tsa to zero
637   tra(:,:,:,:) = 0.
638
639
640   ! 3. Some controls
641   !-----------------
642   check_namelist = .TRUE.
643
644   IF( check_namelist ) THEN
645      ! Check time steps
646      IF( NINT(Agrif_Rhot()) * NINT(rdt) .NE. Agrif_Parent(rdt) ) THEN
647         WRITE(cl_check1,*)  Agrif_Parent(rdt)
648         WRITE(cl_check2,*)  rdt
649         WRITE(cl_check3,*)  rdt*Agrif_Rhot()
650         CALL ctl_stop( 'incompatible time step between grids',   &
651               &               'parent grid value : '//cl_check1    ,   & 
652               &               'child  grid value : '//cl_check2    ,   & 
653               &               'value on child grid should be changed to  &
654               &               :'//cl_check3  )
655      ENDIF
656
657      ! Check run length
658      IF( Agrif_IRhot() * (Agrif_Parent(nitend)- &
659            Agrif_Parent(nit000)+1) .NE. (nitend-nit000+1) ) THEN
660         WRITE(cl_check1,*)  (Agrif_Parent(nit000)-1)*Agrif_IRhot() + 1
661         WRITE(cl_check2,*)   Agrif_Parent(nitend)   *Agrif_IRhot()
662         CALL ctl_warn( 'incompatible run length between grids'               ,   &
663               &              ' nit000 on fine grid will be change to : '//cl_check1,   &
664               &              ' nitend on fine grid will be change to : '//cl_check2    )
665         nit000 = (Agrif_Parent(nit000)-1)*Agrif_IRhot() + 1
666         nitend =  Agrif_Parent(nitend)   *Agrif_IRhot()
667      ENDIF
668
669      ENDIF
670      ! Check passive tracer cell
671      IF( nn_dttrc .NE. 1 ) THEN
672         WRITE(*,*) 'nn_dttrc should be equal to 1'
673      ENDIF
674   ENDIF
675   !
676END SUBROUTINE Agrif_InitValues_cont_top
677
678
679SUBROUTINE agrif_declare_var_top
680   !!----------------------------------------------------------------------
681   !!                 *** ROUTINE agrif_declare_var_top ***
682   !!
683   !! ** Purpose :: Declaration of TOP variables to be interpolated
684   !!----------------------------------------------------------------------
685   USE agrif_util
686   USE agrif_oce
687   USE dom_oce
688   USE trc
689   !!
690   IMPLICIT NONE
691   !
692   INTEGER :: ind1, ind2, ind3
693   !!----------------------------------------------------------------------
694
695   ! 1. Declaration of the type of variable which have to be interpolated
696   !---------------------------------------------------------------------
697   ind1 =     nbghostcells
698   ind2 = 1 + nbghostcells
699   ind3 = 2 + nbghostcells
700# if defined key_vertical
701   CALL agrif_declare_variable((/2,2,0,0/),(/ind3,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,jptra+1/),trn_id)
702   CALL agrif_declare_variable((/2,2,0,0/),(/ind3,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,jptra+1/),trn_sponge_id)
703# else
704   CALL agrif_declare_variable((/2,2,0,0/),(/3,3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,jptra/),trn_id)
705   CALL agrif_declare_variable((/2,2,0,0/),(/3,3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,jptra/),trn_sponge_id)
706# endif
707
708   ! 2. Type of interpolation
709   !-------------------------
710   CALL Agrif_Set_bcinterp(trn_id,interp=AGRIF_linear)
711   CALL Agrif_Set_bcinterp(trn_sponge_id,interp=AGRIF_linear)
712
713   ! 3. Location of interpolation
714   !-----------------------------
715   CALL Agrif_Set_bc(trn_id,(/0,ind1/))
716   CALL Agrif_Set_bc(trn_sponge_id,(/-nn_sponge_len*Agrif_irhox()-1,0/))
717
718   ! 4. Update type
719   !---------------
720# if defined UPD_HIGH
721   CALL Agrif_Set_Updatetype(trn_id, update = Agrif_Update_Full_Weighting)
722#else
723   CALL Agrif_Set_Updatetype(trn_id, update = AGRIF_Update_Average)
724#endif
725   !
726END SUBROUTINE agrif_declare_var_top
727# endif
728
729SUBROUTINE Agrif_detect( kg, ksizex )
730   !!----------------------------------------------------------------------
731   !!                      *** ROUTINE Agrif_detect ***
732   !!----------------------------------------------------------------------
733   INTEGER, DIMENSION(2) :: ksizex
734   INTEGER, DIMENSION(ksizex(1),ksizex(2)) :: kg 
735   !!----------------------------------------------------------------------
736   !
737   RETURN
738   !
739END SUBROUTINE Agrif_detect
740
741
742SUBROUTINE agrif_nemo_init
743   !!----------------------------------------------------------------------
744   !!                     *** ROUTINE agrif_init ***
745   !!----------------------------------------------------------------------
746   USE agrif_oce 
747   USE agrif_ice
748   USE in_out_manager
749   USE lib_mpp
750   !!
751   IMPLICIT NONE
752   !
753   INTEGER  ::   ios                 ! Local integer output status for namelist read
754   INTEGER  ::   iminspon
755   NAMELIST/namagrif/ rn_sponge_tra, rn_sponge_dyn, ln_spc_dyn, ln_chk_bathy
756   !!--------------------------------------------------------------------------------------
757   !
758   REWIND( numnam_ref )              ! Namelist namagrif in reference namelist : AGRIF zoom
759   READ  ( numnam_ref, namagrif, IOSTAT = ios, ERR = 901)
760901 IF( ios /= 0 )   CALL ctl_nam ( ios , 'namagrif in reference namelist', lwp )
761   REWIND( numnam_cfg )              ! Namelist namagrif in configuration namelist : AGRIF zoom
762   READ  ( numnam_cfg, namagrif, IOSTAT = ios, ERR = 902 )
763902 IF( ios >  0 )   CALL ctl_nam ( ios , 'namagrif in configuration namelist', lwp )
764   IF(lwm) WRITE ( numond, namagrif )
765   !
766   IF(lwp) THEN                    ! control print
767      WRITE(numout,*)
768      WRITE(numout,*) 'agrif_nemo_init : AGRIF parameters'
769      WRITE(numout,*) '~~~~~~~~~~~~~~~'
770      WRITE(numout,*) '   Namelist namagrif : set AGRIF parameters'
771      WRITE(numout,*) '      sponge coefficient for tracers    rn_sponge_tra = ', rn_sponge_tra, ' s'
772      WRITE(numout,*) '      sponge coefficient for dynamics   rn_sponge_tra = ', rn_sponge_dyn, ' s'
773      WRITE(numout,*) '      use special values for dynamics   ln_spc_dyn    = ', ln_spc_dyn
774      WRITE(numout,*) '      check bathymetry                  ln_chk_bathy  = ', ln_chk_bathy
775   ENDIF
776   !
777   ! convert DOCTOR namelist name into OLD names
778   visc_tra      = rn_sponge_tra
779   visc_dyn      = rn_sponge_dyn
780   !
781   ! Check sponge length:
782   iminspon = MIN(FLOOR(REAL(jpiglo-4)/REAL(2*Agrif_irhox())), FLOOR(REAL(jpjglo-4)/REAL(2*Agrif_irhox())) )
783   IF (lk_mpp) iminspon = MIN(iminspon,FLOOR(REAL(jpi-2)/REAL(Agrif_irhox())), FLOOR(REAL(jpj-2)/REAL(Agrif_irhox())) )
784   IF (nn_sponge_len > iminspon)  CALL ctl_stop('agrif sponge length is too large')
785   !
786   IF( agrif_oce_alloc()  > 0 )   CALL ctl_warn('agrif agrif_oce_alloc: allocation of arrays failed')
787   !
788END SUBROUTINE agrif_nemo_init
789
790# if defined key_mpp_mpi
791
792SUBROUTINE Agrif_InvLoc( indloc, nprocloc, i, indglob )
793   !!----------------------------------------------------------------------
794   !!                     *** ROUTINE Agrif_InvLoc ***
795   !!----------------------------------------------------------------------
796   USE dom_oce
797   !!
798   IMPLICIT NONE
799   !
800   INTEGER :: indglob, indloc, nprocloc, i
801   !!----------------------------------------------------------------------
802   !
803   SELECT CASE( i )
804   CASE(1)   ;   indglob = indloc + nimppt(nprocloc+1) - 1
805   CASE(2)   ;   indglob = indloc + njmppt(nprocloc+1) - 1
806   CASE DEFAULT
807      indglob = indloc
808   END SELECT
809   !
810END SUBROUTINE Agrif_InvLoc
811
812
813SUBROUTINE Agrif_get_proc_info( imin, imax, jmin, jmax )
814   !!----------------------------------------------------------------------
815   !!                 *** ROUTINE Agrif_get_proc_info ***
816   !!----------------------------------------------------------------------
817   USE par_oce
818   !!
819   IMPLICIT NONE
820   !
821   INTEGER, INTENT(out) :: imin, imax
822   INTEGER, INTENT(out) :: jmin, jmax
823   !!----------------------------------------------------------------------
824   !
825   imin = nimppt(Agrif_Procrank+1)  ! ?????
826   jmin = njmppt(Agrif_Procrank+1)  ! ?????
827   imax = imin + jpi - 1
828   jmax = jmin + jpj - 1
829   !
830END SUBROUTINE Agrif_get_proc_info
831
832
833SUBROUTINE Agrif_estimate_parallel_cost(imin, imax,jmin, jmax, nbprocs, grid_cost)
834   !!----------------------------------------------------------------------
835   !!                 *** ROUTINE Agrif_estimate_parallel_cost ***
836   !!----------------------------------------------------------------------
837   USE par_oce
838   !!
839   IMPLICIT NONE
840   !
841   INTEGER,  INTENT(in)  :: imin, imax
842   INTEGER,  INTENT(in)  :: jmin, jmax
843   INTEGER,  INTENT(in)  :: nbprocs
844   REAL(wp), INTENT(out) :: grid_cost
845   !!----------------------------------------------------------------------
846   !
847   grid_cost = REAL(imax-imin+1,wp)*REAL(jmax-jmin+1,wp) / REAL(nbprocs,wp)
848   !
849END SUBROUTINE Agrif_estimate_parallel_cost
850
851# endif
852
853#else
854SUBROUTINE Subcalledbyagrif
855   !!----------------------------------------------------------------------
856   !!                   *** ROUTINE Subcalledbyagrif ***
857   !!----------------------------------------------------------------------
858   WRITE(*,*) 'Impossible to be here'
859END SUBROUTINE Subcalledbyagrif
860#endif
Note: See TracBrowser for help on using the repository browser.