New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
istate.F90 in branches/2015/dev_r5836_NOC3_vvl_by_default/NEMOGCM/NEMO/OPA_SRC/DOM – NEMO

source: branches/2015/dev_r5836_NOC3_vvl_by_default/NEMOGCM/NEMO/OPA_SRC/DOM/istate.F90 @ 5883

Last change on this file since 5883 was 5883, checked in by gm, 8 years ago

#1613: vvl by default: TRA/TRC remove optimization associated with linear free surface

  • Property svn:keywords set to Id
File size: 25.8 KB
Line 
1MODULE istate
2   !!======================================================================
3   !!                     ***  MODULE  istate  ***
4   !! Ocean state   :  initial state setting
5   !!=====================================================================
6   !! History :  OPA  !  1989-12  (P. Andrich)  Original code
7   !!            5.0  !  1991-11  (G. Madec)  rewritting
8   !!            6.0  !  1996-01  (G. Madec)  terrain following coordinates
9   !!            8.0  !  2001-09  (M. Levy, M. Ben Jelloul)  istate_eel
10   !!            8.0  !  2001-09  (M. Levy, M. Ben Jelloul)  istate_uvg
11   !!   NEMO     1.0  !  2003-08  (G. Madec, C. Talandier)  F90: Free form, modules + EEL R5
12   !!             -   !  2004-05  (A. Koch-Larrouy)  istate_gyre
13   !!            2.0  !  2006-07  (S. Masson)  distributed restart using iom
14   !!            3.3  !  2010-10  (C. Ethe) merge TRC-TRA
15   !!            3.4  !  2011-04  (G. Madec) Merge of dtatem and dtasal & suppression of tb,tn/sb,sn
16   !!----------------------------------------------------------------------
17
18   !!----------------------------------------------------------------------
19   !!   istate_init   : initial state setting
20   !!   istate_tem    : analytical profile for initial Temperature
21   !!   istate_sal    : analytical profile for initial Salinity
22   !!   istate_eel    : initial state setting of EEL R5 configuration
23   !!   istate_gyre   : initial state setting of GYRE configuration
24   !!   istate_uvg    : initial velocity in geostropic balance
25   !!----------------------------------------------------------------------
26   USE oce             ! ocean dynamics and active tracers
27   USE dom_oce         ! ocean space and time domain
28   USE c1d             ! 1D vertical configuration
29   USE daymod          ! calendar
30   USE eosbn2          ! eq. of state, Brunt Vaisala frequency (eos     routine)
31   USE ldftra          ! lateral physics: ocean active tracers
32   USE zdf_oce         ! ocean vertical physics
33   USE phycst          ! physical constants
34   USE dtatsd          ! data temperature and salinity   (dta_tsd routine)
35   USE dtauvd          ! data: U & V current             (dta_uvd routine)
36   USE domvvl          ! varying vertical mesh
37   USE dynspg_oce      ! pressure gradient schemes
38   USE dynspg_flt      ! filtered free surface
39   USE sol_oce         ! ocean solver variables
40   !
41   USE in_out_manager  ! I/O manager
42   USE iom             ! I/O library
43   USE lib_mpp         ! MPP library
44   USE restart         ! restart
45   USE wrk_nemo        ! Memory allocation
46   USE timing          ! Timing
47
48   IMPLICIT NONE
49   PRIVATE
50
51   PUBLIC   istate_init   ! routine called by step.F90
52
53   !! * Substitutions
54#  include "vectopt_loop_substitute.h90"
55   !!----------------------------------------------------------------------
56   !! NEMO/OPA 3.7 , NEMO Consortium (2014)
57   !! $Id$
58   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
59   !!----------------------------------------------------------------------
60CONTAINS
61
62   SUBROUTINE istate_init
63      !!----------------------------------------------------------------------
64      !!                   ***  ROUTINE istate_init  ***
65      !!
66      !! ** Purpose :   Initialization of the dynamics and tracer fields.
67      !!----------------------------------------------------------------------
68      INTEGER ::   ji, jj, jk   ! dummy loop indices
69      REAL(wp), POINTER, DIMENSION(:,:,:,:) ::   zuvd    ! U & V data workspace
70      !!----------------------------------------------------------------------
71      !
72      IF( nn_timing == 1 )   CALL timing_start('istate_init')
73      !
74
75      IF(lwp) WRITE(numout,*)
76      IF(lwp) WRITE(numout,*) 'istate_ini : Initialization of the dynamics and tracers'
77      IF(lwp) WRITE(numout,*) '~~~~~~~~~~'
78
79                     CALL dta_tsd_init        ! Initialisation of T & S input data
80      IF( lk_c1d )   CALL dta_uvd_init        ! Initialization of U & V input data
81
82      rhd  (:,:,:  ) = 0._wp   ;   rhop (:,:,:  ) = 0._wp      ! set one for all to 0 at level jpk
83      rn2b (:,:,:  ) = 0._wp   ;   rn2  (:,:,:  ) = 0._wp      ! set one for all to 0 at levels 1 and jpk
84      tsa  (:,:,:,:) = 0._wp                                   ! set one for all to 0 at level jpk
85      rab_b(:,:,:,:) = 0._wp   ;   rab_n(:,:,:,:) = 0._wp      ! set one for all to 0 at level jpk
86
87      IF( ln_rstart ) THEN                    ! Restart from a file
88         !                                    ! -------------------
89         CALL rst_read                           ! Read the restart file
90         CALL day_init                           ! model calendar (using both namelist and restart infos)
91      ELSE
92         !                                    ! Start from rest
93         !                                    ! ---------------
94         numror = 0                              ! define numror = 0 -> no restart file to read
95         neuler = 0                              ! Set time-step indicator at nit000 (euler forward)
96         CALL day_init                           ! model calendar (using both namelist and restart infos)
97         !                                       ! Initialization of ocean to zero
98         !   before fields      !       now fields     
99         sshb (:,:)   = 0._wp   ;   sshn (:,:)   = 0._wp
100         ub   (:,:,:) = 0._wp   ;   un   (:,:,:) = 0._wp
101         vb   (:,:,:) = 0._wp   ;   vn   (:,:,:) = 0._wp 
102                                    hdivn(:,:,:) = 0._wp
103         !
104         IF( cp_cfg == 'eel' ) THEN
105            CALL istate_eel                      ! EEL   configuration : start from pre-defined U,V T-S fields
106         ELSEIF( cp_cfg == 'gyre' ) THEN         
107            CALL istate_gyre                     ! GYRE  configuration : start from pre-defined T-S fields
108         ELSE                                    ! Initial T-S, U-V fields read in files
109            IF ( ln_tsd_init ) THEN              ! read 3D T and S data at nit000
110               CALL dta_tsd( nit000, tsb ) 
111               tsn(:,:,:,:) = tsb(:,:,:,:)
112               !
113            ELSE                                 ! Initial T-S fields defined analytically
114               CALL istate_t_s
115            ENDIF
116            IF ( ln_uvd_init .AND. lk_c1d ) THEN ! read 3D U and V data at nit000
117               CALL wrk_alloc( jpi,jpj,jpk,2,   zuvd )
118               CALL dta_uvd( nit000, zuvd )
119               ub(:,:,:) = zuvd(:,:,:,1) ;  un(:,:,:) = ub(:,:,:)
120               vb(:,:,:) = zuvd(:,:,:,2) ;  vn(:,:,:) = vb(:,:,:)
121               CALL wrk_dealloc( jpi,jpj,jpk,2,   zuvd )
122            ENDIF
123         ENDIF
124         !
125!!gm This is to be changed !!!!
126         ! - ML - sshn could be modified by istate_eel, so that initialization of e3t_b is done here
127         IF( .NOT.ln_linssh ) THEN
128            DO jk = 1, jpk
129               e3t_b(:,:,jk) = e3t_n(:,:,jk)
130            END DO
131         ENDIF
132!!gm
133         !
134      ENDIF
135      !
136      IF( lk_agrif ) THEN                  ! read free surface arrays in restart file
137         IF( ln_rstart ) THEN
138            IF( lk_dynspg_flt )  THEN      ! read or initialize the following fields
139               !                           ! gcx, gcxb for agrif_opa_init
140               IF( sol_oce_alloc()  > 0 )   CALL ctl_stop('agrif sol_oce_alloc: allocation of arrays failed')
141               CALL flt_rst( nit000, 'READ' )
142            ENDIF
143         ENDIF                             ! explicit case not coded yet with AGRIF
144      ENDIF
145      !
146      !
147      ! Initialize "now" and "before" barotropic velocities:
148      ! Do it whatever the free surface method, these arrays
149      ! being eventually used
150      !
151      !
152      un_b(:,:) = 0._wp   ;   vn_b(:,:) = 0._wp
153      ub_b(:,:) = 0._wp   ;   vb_b(:,:) = 0._wp
154      !
155      DO jk = 1, jpkm1
156         DO jj = 1, jpj
157            DO ji = 1, jpi
158               un_b(ji,jj) = un_b(ji,jj) + e3u_n(ji,jj,jk) * un(ji,jj,jk) * umask(ji,jj,jk)
159               vn_b(ji,jj) = vn_b(ji,jj) + e3v_n(ji,jj,jk) * vn(ji,jj,jk) * vmask(ji,jj,jk)
160               !
161               ub_b(ji,jj) = ub_b(ji,jj) + e3u_b(ji,jj,jk) * ub(ji,jj,jk) * umask(ji,jj,jk)
162               vb_b(ji,jj) = vb_b(ji,jj) + e3v_b(ji,jj,jk) * vb(ji,jj,jk) * vmask(ji,jj,jk)
163            END DO
164         END DO
165      END DO
166      !
167      un_b(:,:) = un_b(:,:) * r1_hu_n  (:,:)
168      vn_b(:,:) = vn_b(:,:) * r1_hv_n  (:,:)
169      !
170      ub_b(:,:) = ub_b(:,:) * r1_hu_b(:,:)
171      vb_b(:,:) = vb_b(:,:) * r1_hv_b(:,:)
172      !
173      !
174      IF( nn_timing == 1 )   CALL timing_stop('istate_init')
175      !
176   END SUBROUTINE istate_init
177
178
179   SUBROUTINE istate_t_s
180      !!---------------------------------------------------------------------
181      !!                  ***  ROUTINE istate_t_s  ***
182      !!   
183      !! ** Purpose :   Intialization of the temperature field with an
184      !!      analytical profile or a file (i.e. in EEL configuration)
185      !!
186      !! ** Method  : - temperature: use Philander analytic profile
187      !!              - salinity   : use to a constant value 35.5
188      !!
189      !! References :  Philander ???
190      !!----------------------------------------------------------------------
191      INTEGER  ::   ji, jj, jk
192      REAL(wp) ::   zsal = 35.50_wp
193      !!----------------------------------------------------------------------
194      !
195      IF(lwp) WRITE(numout,*)
196      IF(lwp) WRITE(numout,*) 'istate_t_s : Philander s initial temperature profile'
197      IF(lwp) WRITE(numout,*) '~~~~~~~~~~   and constant salinity (',zsal,' psu)'
198      !
199      DO jk = 1, jpk
200         tsn(:,:,jk,jp_tem) = (  ( ( 7.5 - 0. * ABS( gphit(:,:) )/30. ) * ( 1.-TANH((gdept_n(:,:,jk)-80.)/30.) )   &
201            &                + 10. * ( 5000. - gdept_n(:,:,jk) ) /5000.)  ) * tmask(:,:,jk)
202         tsb(:,:,jk,jp_tem) = tsn(:,:,jk,jp_tem)
203      END DO
204      tsn(:,:,:,jp_sal) = zsal * tmask(:,:,:)
205      tsb(:,:,:,jp_sal) = tsn(:,:,:,jp_sal)
206      !
207   END SUBROUTINE istate_t_s
208
209
210   SUBROUTINE istate_eel
211      !!----------------------------------------------------------------------
212      !!                   ***  ROUTINE istate_eel  ***
213      !!
214      !! ** Purpose :   Initialization of the dynamics and tracers for EEL R5
215      !!      configuration (channel with or without a topographic bump)
216      !!
217      !! ** Method  : - set temprature field
218      !!              - set salinity field
219      !!              - set velocity field including horizontal divergence
220      !!                and relative vorticity fields
221      !!----------------------------------------------------------------------
222      USE divhor     ! hor. divergence      (div_hor routine)
223      USE iom
224      !
225      INTEGER  ::   inum              ! temporary logical unit
226      INTEGER  ::   ji, jj, jk        ! dummy loop indices
227      INTEGER  ::   ijloc
228      REAL(wp) ::   zh1, zh2, zslope, zcst, zfcor   ! temporary scalars
229      REAL(wp) ::   zt1  = 15._wp                   ! surface temperature value (EEL R5)
230      REAL(wp) ::   zt2  =  5._wp                   ! bottom  temperature value (EEL R5)
231      REAL(wp) ::   zsal = 35.0_wp                  ! constant salinity (EEL R2, R5 and R6)
232      REAL(wp) ::   zueel = 0.1_wp                  ! constant uniform zonal velocity (EEL R5)
233      REAL(wp), DIMENSION(jpiglo,jpjglo) ::   zssh  ! initial ssh over the global domain
234      !!----------------------------------------------------------------------
235      !
236      SELECT CASE ( jp_cfg ) 
237         !                                              ! ====================
238         CASE ( 5 )                                     ! EEL R5 configuration
239            !                                           ! ====================
240            !
241            ! set temperature field with a linear profile
242            ! -------------------------------------------
243            IF(lwp) WRITE(numout,*)
244            IF(lwp) WRITE(numout,*) 'istate_eel : EEL R5: linear temperature profile'
245            IF(lwp) WRITE(numout,*) '~~~~~~~~~~'
246            !
247            zh1 = gdept_1d(  1  )
248            zh2 = gdept_1d(jpkm1)
249            !
250            zslope = ( zt1 - zt2 ) / ( zh1 - zh2 )
251            zcst   = ( zt1 * ( zh1 - zh2) - ( zt1 - zt2 ) * zh1 ) / ( zh1 - zh2 )
252            !
253            DO jk = 1, jpk
254               tsn(:,:,jk,jp_tem) = ( zt2 + zt1 * exp( - gdept_n(:,:,jk) / 1000 ) ) * tmask(:,:,jk)
255               tsb(:,:,jk,jp_tem) = tsn(:,:,jk,jp_tem)
256            END DO
257            !
258            ! set salinity field to a constant value
259            ! --------------------------------------
260            IF(lwp) WRITE(numout,*)
261            IF(lwp) WRITE(numout,*) 'istate_eel : EEL R5: constant salinity field, S = ', zsal
262            IF(lwp) WRITE(numout,*) '~~~~~~~~~~'
263            !
264            tsn(:,:,:,jp_sal) = zsal * tmask(:,:,:)
265            tsb(:,:,:,jp_sal) = tsn(:,:,:,jp_sal)
266            !
267            ! set the dynamics: U,V, hdiv (and ssh if necessary)
268            ! ----------------
269            ! Start EEL5 configuration with barotropic geostrophic velocities
270            ! according the sshb and sshn SSH imposed.
271            ! we assume a uniform grid (hence the use of e1t(1,1) for delta_y)
272            ! we use the Coriolis frequency at mid-channel.   
273            ub(:,:,:) = zueel * umask(:,:,:)
274            un(:,:,:) = ub(:,:,:)
275            ijloc = mj0(INT(jpjglo-1)/2)
276            zfcor = ff(1,ijloc)
277            !
278            DO jj = 1, jpjglo
279               zssh(:,jj) = - (FLOAT(jj)- FLOAT(jpjglo-1)/2.)*zueel*e1t(1,1)*zfcor/grav 
280            END DO
281            !
282            IF(lwp) THEN
283               WRITE(numout,*) ' Uniform zonal velocity for EEL R5:',zueel
284               WRITE(numout,*) ' Geostrophic SSH profile as a function of y:'
285               WRITE(numout,'(12(1x,f6.2))') zssh(1,:)
286            ENDIF
287            !
288            DO jj = 1, nlcj
289               DO ji = 1, nlci
290                  sshb(ji,jj) = zssh( mig(ji) , mjg(jj) ) * tmask(ji,jj,1)
291               END DO
292            END DO
293            sshb(nlci+1:jpi,      :   ) = 0.e0      ! set to zero extra mpp columns
294            sshb(      :   ,nlcj+1:jpj) = 0.e0      ! set to zero extra mpp rows
295            !
296            sshn(:,:) = sshb(:,:)                   ! set now ssh to the before value
297            !
298            IF( nn_rstssh /= 0 ) THEN 
299               nn_rstssh = 0                        ! hand-made initilization of ssh
300               CALL ctl_warn( 'istate_eel: force nn_rstssh = 0' )
301            ENDIF
302            !
303!!gm  Check  here call to div_hor should not be necessary
304!!gm         div_hor call runoffs  not sure they are defined at that level
305            CALL div_hor( nit000 )                  ! horizontal divergence and relative vorticity (curl)
306            ! N.B. the vertical velocity will be computed from the horizontal divergence field
307            ! in istate by a call to wzv routine
308
309
310            !                                     ! ==========================
311         CASE ( 2 , 6 )                           ! EEL R2 or R6 configuration
312            !                                     ! ==========================
313            !
314            ! set temperature field with a NetCDF file
315            ! ----------------------------------------
316            IF(lwp) WRITE(numout,*)
317            IF(lwp) WRITE(numout,*) 'istate_eel : EEL R2 or R6: read initial temperature in a NetCDF file'
318            IF(lwp) WRITE(numout,*) '~~~~~~~~~~'
319            !
320            CALL iom_open ( 'eel.initemp', inum )
321            CALL iom_get ( inum, jpdom_data, 'initemp', tsb(:,:,:,jp_tem) ) ! read before temprature (tb)
322            CALL iom_close( inum )
323            !
324            tsn(:,:,:,jp_tem) = tsb(:,:,:,jp_tem)                            ! set nox temperature to tb
325            !
326            ! set salinity field to a constant value
327            ! --------------------------------------
328            IF(lwp) WRITE(numout,*)
329            IF(lwp) WRITE(numout,*) 'istate_eel : EEL R5: constant salinity field, S = ', zsal
330            IF(lwp) WRITE(numout,*) '~~~~~~~~~~'
331            !
332            tsn(:,:,:,jp_sal) = zsal * tmask(:,:,:)
333            tsb(:,:,:,jp_sal) = tsn(:,:,:,jp_sal)
334            !
335            !                                    ! ===========================
336         CASE DEFAULT                            ! NONE existing configuration
337            !                                    ! ===========================
338            WRITE(ctmp1,*) 'EEL with a ', jp_cfg,' km resolution is not coded'
339            CALL ctl_stop( ctmp1 )
340            !
341      END SELECT
342      !
343   END SUBROUTINE istate_eel
344
345
346   SUBROUTINE istate_gyre
347      !!----------------------------------------------------------------------
348      !!                   ***  ROUTINE istate_gyre  ***
349      !!
350      !! ** Purpose :   Initialization of the dynamics and tracers for GYRE
351      !!      configuration (double gyre with rotated domain)
352      !!
353      !! ** Method  : - set temprature field
354      !!              - set salinity   field
355      !!----------------------------------------------------------------------
356      INTEGER :: ji, jj, jk  ! dummy loop indices
357      INTEGER            ::   inum          ! temporary logical unit
358      INTEGER, PARAMETER ::   ntsinit = 0   ! (0/1) (analytical/input data files) T&S initialization
359      !!----------------------------------------------------------------------
360      !
361      SELECT CASE ( ntsinit)
362      !
363      CASE ( 0 )                  ! analytical T/S profil deduced from LEVITUS
364         IF(lwp) WRITE(numout,*)
365         IF(lwp) WRITE(numout,*) 'istate_gyre : initial analytical T and S profil deduced from LEVITUS '
366         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
367         !
368         DO jk = 1, jpk
369            DO jj = 1, jpj
370               DO ji = 1, jpi
371                  tsn(ji,jj,jk,jp_tem) = (  16. - 12. * TANH( (gdept_n(ji,jj,jk) - 400) / 700 )         )   &
372                       &           * (-TANH( (500-gdept_n(ji,jj,jk)) / 150 ) + 1) / 2               &
373                       &       + (      15. * ( 1. - TANH( (gdept_n(ji,jj,jk)-50.) / 1500.) )       &
374                       &                - 1.4 * TANH((gdept_n(ji,jj,jk)-100.) / 100.)               &   
375                       &                + 7.  * (1500. - gdept_n(ji,jj,jk)) / 1500.             )   & 
376                       &           * (-TANH( (gdept_n(ji,jj,jk) - 500) / 150) + 1) / 2
377                  tsn(ji,jj,jk,jp_tem) = tsn(ji,jj,jk,jp_tem) * tmask(ji,jj,jk)
378                  tsb(ji,jj,jk,jp_tem) = tsn(ji,jj,jk,jp_tem)
379
380                  tsn(ji,jj,jk,jp_sal) =  (  36.25 - 1.13 * TANH( (gdept_n(ji,jj,jk) - 305) / 460 )  )  &
381                     &              * (-TANH((500 - gdept_n(ji,jj,jk)) / 150) + 1) / 2          &
382                     &          + (  35.55 + 1.25 * (5000. - gdept_n(ji,jj,jk)) / 5000.         &
383                     &                - 1.62 * TANH( (gdept_n(ji,jj,jk) - 60.  ) / 650. )       &
384                     &                + 0.2  * TANH( (gdept_n(ji,jj,jk) - 35.  ) / 100. )       &
385                     &                + 0.2  * TANH( (gdept_n(ji,jj,jk) - 1000.) / 5000.)    )  &
386                     &              * (-TANH((gdept_n(ji,jj,jk) - 500) / 150) + 1) / 2 
387                  tsn(ji,jj,jk,jp_sal) = tsn(ji,jj,jk,jp_sal) * tmask(ji,jj,jk)
388                  tsb(ji,jj,jk,jp_sal) = tsn(ji,jj,jk,jp_sal)
389               END DO
390            END DO
391         END DO
392         !
393      CASE ( 1 )                  ! T/S data fields read in dta_tem.nc/data_sal.nc files
394         IF(lwp) WRITE(numout,*)
395         IF(lwp) WRITE(numout,*) 'istate_gyre : initial T and S read from dta_tem.nc/data_sal.nc files'
396         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
397         IF(lwp) WRITE(numout,*) '              NetCDF FORMAT'
398
399         ! Read temperature field
400         ! ----------------------
401         CALL iom_open ( 'data_tem', inum )
402         CALL iom_get ( inum, jpdom_data, 'votemper', tsn(:,:,:,jp_tem) ) 
403         CALL iom_close( inum )
404
405         tsn(:,:,:,jp_tem) = tsn(:,:,:,jp_tem) * tmask(:,:,:) 
406         tsb(:,:,:,jp_tem) = tsn(:,:,:,jp_tem)
407
408         ! Read salinity field
409         ! -------------------
410         CALL iom_open ( 'data_sal', inum )
411         CALL iom_get ( inum, jpdom_data, 'vosaline', tsn(:,:,:,jp_sal) ) 
412         CALL iom_close( inum )
413
414         tsn(:,:,:,jp_sal) = tsn(:,:,:,jp_sal) * tmask(:,:,:) 
415         tsb(:,:,:,jp_sal) = tsn(:,:,:,jp_sal)
416         !
417      END SELECT
418      !
419      IF(lwp) THEN
420         WRITE(numout,*)
421         WRITE(numout,*) '              Initial temperature and salinity profiles:'
422         WRITE(numout, "(9x,' level   gdept_1d   temperature   salinity   ')" )
423         WRITE(numout, "(10x, i4, 3f10.2)" ) ( jk, gdept_1d(jk), tsn(2,2,jk,jp_tem), tsn(2,2,jk,jp_sal), jk = 1, jpk )
424      ENDIF
425      !
426   END SUBROUTINE istate_gyre
427
428
429   SUBROUTINE istate_uvg
430      !!----------------------------------------------------------------------
431      !!                  ***  ROUTINE istate_uvg  ***
432      !!
433      !! ** Purpose :   Compute the geostrophic velocities from (tn,sn) fields
434      !!
435      !! ** Method  :   Using the hydrostatic hypothesis the now hydrostatic
436      !!      pressure is computed by integrating the in-situ density from the
437      !!      surface to the bottom.
438      !!                 p=integral [ rau*g dz ]
439      !!----------------------------------------------------------------------
440      USE dynspg          ! surface pressure gradient             (dyn_spg routine)
441      USE divhor          ! hor. divergence                       (div_hor routine)
442      USE lbclnk          ! ocean lateral boundary condition (or mpp link)
443      !
444      INTEGER ::   ji, jj, jk        ! dummy loop indices
445      INTEGER ::   indic             ! ???
446      REAL(wp) ::   zmsv, zphv, zmsu, zphu, zalfg     ! temporary scalars
447      REAL(wp), POINTER, DIMENSION(:,:,:) :: zprn
448      !!----------------------------------------------------------------------
449      !
450      CALL wrk_alloc( jpi,jpj,jpk,   zprn)
451      !
452      IF(lwp) WRITE(numout,*) 
453      IF(lwp) WRITE(numout,*) 'istate_uvg : Start from Geostrophy'
454      IF(lwp) WRITE(numout,*) '~~~~~~~~~~'
455
456      ! Compute the now hydrostatic pressure
457      ! ------------------------------------
458
459      zalfg = 0.5 * grav * rau0
460     
461      zprn(:,:,1) = zalfg * e3w_n(:,:,1) * ( 1 + rhd(:,:,1) )       ! Surface value
462
463      DO jk = 2, jpkm1                                              ! Vertical integration from the surface
464         zprn(:,:,jk) = zprn(:,:,jk-1)   &
465            &         + zalfg * e3w_n(:,:,jk) * ( 2. + rhd(:,:,jk) + rhd(:,:,jk-1) )
466      END DO 
467
468      ! Compute geostrophic balance
469      ! ---------------------------
470      DO jk = 1, jpkm1
471         DO jj = 2, jpjm1
472            DO ji = fs_2, fs_jpim1   ! vertor opt.
473               zmsv = 1. / MAX(  umask(ji-1,jj+1,jk) + umask(ji  ,jj+1,jk)   &
474                               + umask(ji-1,jj  ,jk) + umask(ji  ,jj  ,jk) , 1.  )
475               zphv = ( zprn(ji  ,jj+1,jk) - zprn(ji-1,jj+1,jk) ) * umask(ji-1,jj+1,jk) / e1u(ji-1,jj+1)   &
476                    + ( zprn(ji+1,jj+1,jk) - zprn(ji  ,jj+1,jk) ) * umask(ji  ,jj+1,jk) / e1u(ji  ,jj+1)   &
477                    + ( zprn(ji  ,jj  ,jk) - zprn(ji-1,jj  ,jk) ) * umask(ji-1,jj  ,jk) / e1u(ji-1,jj  )   &
478                    + ( zprn(ji+1,jj  ,jk) - zprn(ji  ,jj  ,jk) ) * umask(ji  ,jj  ,jk) / e1u(ji  ,jj  )
479               zphv = 1. / rau0 * zphv * zmsv * vmask(ji,jj,jk)
480
481               zmsu = 1. / MAX(  vmask(ji+1,jj  ,jk) + vmask(ji  ,jj  ,jk)   &
482                               + vmask(ji+1,jj-1,jk) + vmask(ji  ,jj-1,jk) , 1.  )
483               zphu = ( zprn(ji+1,jj+1,jk) - zprn(ji+1,jj  ,jk) ) * vmask(ji+1,jj  ,jk) / e2v(ji+1,jj  )   &
484                    + ( zprn(ji  ,jj+1,jk) - zprn(ji  ,jj  ,jk) ) * vmask(ji  ,jj  ,jk) / e2v(ji  ,jj  )   &
485                    + ( zprn(ji+1,jj  ,jk) - zprn(ji+1,jj-1,jk) ) * vmask(ji+1,jj-1,jk) / e2v(ji+1,jj-1)   &
486                    + ( zprn(ji  ,jj  ,jk) - zprn(ji  ,jj-1,jk) ) * vmask(ji  ,jj-1,jk) / e2v(ji  ,jj-1)
487               zphu = 1. / rau0 * zphu * zmsu * umask(ji,jj,jk)
488
489               ! Compute the geostrophic velocities
490               un(ji,jj,jk) = -2. * zphu / ( ff(ji,jj) + ff(ji  ,jj-1) )
491               vn(ji,jj,jk) =  2. * zphv / ( ff(ji,jj) + ff(ji-1,jj  ) )
492            END DO
493         END DO
494      END DO
495
496      IF(lwp) WRITE(numout,*) '         we force to zero bottom velocity'
497
498      ! Susbtract the bottom velocity (level jpk-1 for flat bottom case)
499      ! to have a zero bottom velocity
500
501      DO jk = 1, jpkm1
502         un(:,:,jk) = ( un(:,:,jk) - un(:,:,jpkm1) ) * umask(:,:,jk)
503         vn(:,:,jk) = ( vn(:,:,jk) - vn(:,:,jpkm1) ) * vmask(:,:,jk)
504      END DO
505
506      CALL lbc_lnk( un, 'U', -1. )
507      CALL lbc_lnk( vn, 'V', -1. )
508     
509      ub(:,:,:) = un(:,:,:)
510      vb(:,:,:) = vn(:,:,:)
511     
512      ! WARNING !!!!!
513      ! after initializing u and v, we need to calculate the initial streamfunction bsf.
514      ! Otherwise, only the trend will be computed and the model will blow up (inconsistency).
515      ! to do that, we call dyn_spg with a special trick:
516      ! we fill ua and va with the velocities divided by dt, and the streamfunction will be brought to the
517      ! right value assuming the velocities have been set up in one time step.
518      ! we then set bsfd to zero (first guess for next step is d(psi)/dt = 0.)
519      !  sets up s false trend to calculate the barotropic streamfunction.
520
521      ua(:,:,:) = ub(:,:,:) / rdt
522      va(:,:,:) = vb(:,:,:) / rdt
523
524      ! calls dyn_spg. we assume euler time step, starting from rest.
525      indic = 0
526      CALL dyn_spg( nit000, indic )       ! surface pressure gradient
527      !
528      ! the new velocity is ua*rdt
529      !
530      CALL lbc_lnk( ua, 'U', -1. )
531      CALL lbc_lnk( va, 'V', -1. )
532
533      ub(:,:,:) = ua(:,:,:) * rdt
534      vb(:,:,:) = va(:,:,:) * rdt
535      ua(:,:,:) = 0.e0
536      va(:,:,:) = 0.e0
537      un(:,:,:) = ub(:,:,:)
538      vn(:,:,:) = vb(:,:,:)
539      !
540!!gm  Check  here call to div_hor should not be necessary
541!!gm         div_hor call runoffs  not sure they are defined at that level
542      CALL div_hor( nit000 )            ! now horizontal divergence
543      !
544      CALL wrk_dealloc( jpi,jpj,jpk,   zprn)
545      !
546   END SUBROUTINE istate_uvg
547
548   !!=====================================================================
549END MODULE istate
Note: See TracBrowser for help on using the repository browser.