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/dev_004_VVL/NEMO/OPA_SRC – NEMO

source: branches/dev_004_VVL/NEMO/OPA_SRC/istate.F90 @ 1389

Last change on this file since 1389 was 1389, checked in by rblod, 15 years ago

Cleaning in VVL (initialisation), see ticket #402

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