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

source: trunk/NEMO/OPA_SRC/istate.F90 @ 1191

Last change on this file since 1191 was 1146, checked in by rblod, 16 years ago

Add svn Id (first try), see ticket #210

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 26.8 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_vvl ) 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, sshb, sshn
140            IF( lk_dynspg_ts  )   CALL ts_rst ( nit000, 'READ' )      ! read or initialize the following fields
141            !                                                         ! sshb, sshn, sshb_b, sshn_b, un_b, vn_b
142            IF( lk_dynspg_exp )   CALL exp_rst( nit000, 'READ' )      ! read or initialize the following fields
143            !                                                         ! sshb, sshn
144         ENDIF
145         !
146         IF( .NOT. lk_dynspg_flt ) sshbb(:,:) = sshb(:,:)
147         !
148         CALL dom_vvl               ! ssh init and vertical grid update
149
150         CALL eos_init              ! usefull to get the equation state type neos parameter
151
152         CALL bn2( tb, sb, rn2 )    ! before Brunt Vaissala frequency
153
154         IF( .NOT. ln_rstart ) CALL wzv( nit000 ) 
155
156      ENDIF
157
158      !                                       ! Vertical velocity
159      !                                       ! -----------------
160
161      IF( .NOT. lk_vvl )    CALL wzv( nit000 )                         ! from horizontal divergence
162      !
163   END SUBROUTINE istate_init
164
165
166   SUBROUTINE istate_tem
167      !!---------------------------------------------------------------------
168      !!                  ***  ROUTINE istate_tem  ***
169      !!   
170      !! ** Purpose :   Intialization of the temperature field with an
171      !!      analytical profile or a file (i.e. in EEL configuration)
172      !!
173      !! ** Method  :   Use Philander analytic profile of temperature
174      !!
175      !! References :  Philander ???
176      !!----------------------------------------------------------------------
177      INTEGER :: ji, jj, jk
178      !!----------------------------------------------------------------------
179      !
180      IF(lwp) WRITE(numout,*)
181      IF(lwp) WRITE(numout,*) 'istate_tem : initial temperature profile'
182      IF(lwp) WRITE(numout,*) '~~~~~~~~~~'
183
184      DO jk = 1, jpk
185         DO jj = 1, jpj
186            DO ji = 1, jpi
187               tn(ji,jj,jk) = (  ( ( 7.5 - 0.*ABS(gphit(ji,jj))/30. )   &
188                  &               *( 1.-TANH((fsdept(ji,jj,jk)-80.)/30.) )   &
189                  &            + 10.*(5000.-fsdept(ji,jj,jk))/5000.)  ) * tmask(ji,jj,jk)
190               tb(ji,jj,jk) = tn(ji,jj,jk)
191          END DO
192        END DO
193      END DO
194
195      IF(lwp) CALL prizre( tn    , jpi   , jpj   , jpk   , jpj/2 ,   &
196         &                 1     , jpi   , 5     , 1     , jpk   ,   &
197         &                 1     , 1.    , numout                  )
198      !
199   END SUBROUTINE istate_tem
200
201
202   SUBROUTINE istate_sal
203      !!---------------------------------------------------------------------
204      !!                  ***  ROUTINE istate_sal  ***
205      !!
206      !! ** Purpose :   Intialize the salinity field with an analytic profile
207      !!
208      !! ** Method  :   Use to a constant value 35.5
209      !!             
210      !! ** Action  :   Initialize sn and sb
211      !!----------------------------------------------------------------------
212      REAL(wp) ::   zsal = 35.50_wp
213      !!----------------------------------------------------------------------
214
215      IF(lwp) WRITE(numout,*)
216      IF(lwp) WRITE(numout,*) 'istate_sal : initial salinity : ', zsal
217      IF(lwp) WRITE(numout,*) '~~~~~~~~~~'
218
219      sn(:,:,:) = zsal * tmask(:,:,:)
220      sb(:,:,:) = sn(:,:,:)
221     
222   END SUBROUTINE istate_sal
223
224
225   SUBROUTINE istate_eel
226      !!----------------------------------------------------------------------
227      !!                   ***  ROUTINE istate_eel  ***
228      !!
229      !! ** Purpose :   Initialization of the dynamics and tracers for EEL R5
230      !!      configuration (channel with or without a topographic bump)
231      !!
232      !! ** Method  : - set temprature field
233      !!              - set salinity field
234      !!              - set velocity field including horizontal divergence
235      !!                and relative vorticity fields
236      !!----------------------------------------------------------------------
237      USE eosbn2     ! eq. of state, Brunt Vaisala frequency (eos     routine)
238      USE divcur     ! hor. divergence & rel. vorticity      (div_cur routine)
239      USE iom
240 
241      INTEGER  ::   inum              ! temporary logical unit
242      INTEGER  ::   ji, jj, jk        ! dummy loop indices
243      INTEGER  ::   ijloc
244      REAL(wp) ::   zh1, zh2, zslope, zcst, zfcor   ! temporary scalars
245      REAL(wp) ::   zt1  = 15._wp,               &  ! surface temperature value (EEL R5)
246         &          zt2  =  5._wp,               &  ! bottom  temperature value (EEL R5)
247         &          zsal = 35.0_wp,              &  ! constant salinity (EEL R2, R5 and R6)
248         &          zueel = 0.1_wp                  ! constant uniform zonal velocity (EEL R5)
249# if ! defined key_dynspg_rl
250      REAL(wp), DIMENSION(jpiglo,jpjglo) ::   zssh  ! initial ssh over the global domain
251# endif
252      !!----------------------------------------------------------------------
253
254      SELECT CASE ( jp_cfg ) 
255         !                                              ! ====================
256         CASE ( 5 )                                     ! EEL R5 configuration
257            !                                           ! ====================
258
259            ! set temperature field with a linear profile
260            ! -------------------------------------------
261            IF(lwp) WRITE(numout,*)
262            IF(lwp) WRITE(numout,*) 'istate_eel : EEL R5: linear temperature profile'
263            IF(lwp) WRITE(numout,*) '~~~~~~~~~~'
264
265            zh1 = gdept_0(  1  )
266            zh2 = gdept_0(jpkm1)
267
268            zslope = ( zt1 - zt2 ) / ( zh1 - zh2 )
269            zcst   = ( zt1 * ( zh1 - zh2) - ( zt1 - zt2 ) * zh1 ) / ( zh1 - zh2 )
270
271            DO jk = 1, jpk
272               tn(:,:,jk) = ( zt2 + zt1 * exp( - fsdept(:,:,jk) / 1000 ) ) * tmask(:,:,jk)
273               tb(:,:,jk) = tn(:,:,jk)
274            END DO
275
276            IF(lwp) CALL prizre( tn    , jpi   , jpj   , jpk   , jpj/2 ,   &
277               &                 1     , jpi   , 5     , 1     , jpk   ,   &
278               &                 1     , 1.    , numout                  )
279
280            ! set salinity field to a constant value
281            ! --------------------------------------
282            IF(lwp) WRITE(numout,*)
283            IF(lwp) WRITE(numout,*) 'istate_eel : EEL R5: constant salinity field, S = ', zsal
284            IF(lwp) WRITE(numout,*) '~~~~~~~~~~'
285
286            sn(:,:,:) = zsal * tmask(:,:,:)
287            sb(:,:,:) = sn(:,:,:)
288     
289
290# if ! defined key_dynspg_rl
291            ! set the dynamics: U,V, hdiv, rot (and ssh if necessary)
292            ! ----------------
293            ! Start EEL5 configuration with barotropic geostrophic velocities
294            ! according the sshb and sshn SSH imposed.
295            ! we assume a uniform grid (hence the use of e1t(1,1) for delta_y)
296            ! we use the Coriolis frequency at mid-channel.   
297   
298            ub(:,:,:) = zueel * umask(:,:,:)
299            un(:,:,:) = ub(:,:,:)
300            ijloc = mj0(INT(jpjglo-1)/2)
301            zfcor = ff(1,ijloc)
302
303            DO jj = 1, jpjglo
304               zssh(:,jj) = - (FLOAT(jj)- FLOAT(jpjglo-1)/2.)*zueel*e1t(1,1)*zfcor/grav 
305            END DO
306
307            IF(lwp) THEN
308               WRITE(numout,*) ' Uniform zonal velocity for EEL R5:',zueel
309               WRITE(numout,*) ' Geostrophic SSH profile as a function of y:'
310               WRITE(numout,'(12(1x,f6.2))') zssh(1,:)
311            ENDIF
312
313            DO jj = 1, nlcj
314               DO ji = 1, nlci
315                  sshb(ji,jj) = zssh( mig(ji) , mjg(jj) ) * tmask(ji,jj,1)
316               END DO
317            END DO
318            sshb(nlci+1:jpi,      :   ) = 0.e0      ! set to zero extra mpp columns
319            sshb(      :   ,nlcj+1:jpj) = 0.e0      ! set to zero extra mpp rows
320
321            sshn(:,:) = sshb(:,:)                   ! set now ssh to the before value
322
323            IF( nn_rstssh /= 0 ) THEN 
324               nn_rstssh = 0                           ! hand-made initilization of ssh
325               CALL ctl_warn( 'istate_eel: force nn_rstssh = 0' )
326            ENDIF
327
328            ! horizontal divergence and relative vorticity (curl)
329            CALL div_cur( nit000 )
330
331            ! N.B. the vertical velocity will be computed from the horizontal divergence field
332            ! in istate by a call to wzv routine
333# endif
334
335
336            !                                     ! ==========================
337         CASE ( 2 , 6 )                           ! EEL R2 or R6 configuration
338            !                                     ! ==========================
339 
340            ! set temperature field with a NetCDF file
341            ! ----------------------------------------
342            IF(lwp) WRITE(numout,*)
343            IF(lwp) WRITE(numout,*) 'istate_eel : EEL R2 or R6: read initial temperature in a NetCDF file'
344            IF(lwp) WRITE(numout,*) '~~~~~~~~~~'
345
346            CALL iom_open ( 'eel.initemp', inum )
347            CALL iom_get ( inum, jpdom_data, 'initemp', tb ) ! read before temprature (tb)
348            CALL iom_close( inum )
349     
350            tn(:,:,:) = tb(:,:,:)                            ! set nox temperature to tb
351
352            IF(lwp) CALL prizre( tn    , jpi   , jpj   , jpk   , jpj/2 ,   &
353               &                 1     , jpi   , 5     , 1     , jpk   ,   &
354               &                 1     , 1.    , numout                  )
355
356
357            ! set salinity field to a constant value
358            ! --------------------------------------
359            IF(lwp) WRITE(numout,*)
360            IF(lwp) WRITE(numout,*) 'istate_eel : EEL R5: constant salinity field, S = ', zsal
361            IF(lwp) WRITE(numout,*) '~~~~~~~~~~'
362 
363            sn(:,:,:) = zsal * tmask(:,:,:)
364            sb(:,:,:) = sn(:,:,:)
365
366
367            IF( lk_isl ) THEN
368               ! Horizontal velocity : start from geostrophy (EEL config)
369               CALL eos( tn, sn, rhd )     ! now in situ density
370               CALL istate_uvg             ! compute geostrophic velocity
371
372               ! N.B. the vertical velocity will be computed from the horizontal divergence field
373               ! in istate by a call to wzv routine
374            ENDIF
375            !                                    ! ===========================
376         CASE DEFAULT                            ! NONE existing configuration
377            !                                    ! ===========================
378            WRITE(ctmp1,*) 'EEL with a ', jp_cfg,' km resolution is not coded'
379            CALL ctl_stop( ctmp1 )
380
381      END SELECT
382
383   END SUBROUTINE istate_eel
384
385
386   SUBROUTINE istate_gyre
387      !!----------------------------------------------------------------------
388      !!                   ***  ROUTINE istate_gyre  ***
389      !!
390      !! ** Purpose :   Initialization of the dynamics and tracers for GYRE
391      !!      configuration (double gyre with rotated domain)
392      !!
393      !! ** Method  : - set temprature field
394      !!              - set salinity field
395      !!----------------------------------------------------------------------
396      INTEGER :: ji, jj, jk  ! dummy loop indices
397      INTEGER            ::   inum          ! temporary logical unit
398      INTEGER, PARAMETER ::   ntsinit = 0   ! (0/1) (analytical/input data files) T&S initialization
399      !!----------------------------------------------------------------------
400
401      SELECT CASE ( ntsinit)
402
403      CASE ( 0 )                  ! analytical T/S profil deduced from LEVITUS
404         IF(lwp) WRITE(numout,*)
405         IF(lwp) WRITE(numout,*) 'istate_gyre : initial analytical T and S profil deduced from LEVITUS '
406         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
407
408         DO jk = 1, jpk
409            DO jj = 1, jpj
410               DO ji = 1, jpi
411                  tn(ji,jj,jk) = (  16. - 12. * TANH( (fsdept(ji,jj,jk) - 400) / 700 )         )   &
412                       &           * (-TANH( (500-fsdept(ji,jj,jk)) / 150 ) + 1) / 2               &
413                       &       + (      15. * ( 1. - TANH( (fsdept(ji,jj,jk)-50.) / 1500.) )       &
414                       &                - 1.4 * TANH((fsdept(ji,jj,jk)-100.) / 100.)               &   
415                       &                + 7.  * (1500. - fsdept(ji,jj,jk)) / 1500.             )   & 
416                       &           * (-TANH( (fsdept(ji,jj,jk) - 500) / 150) + 1) / 2
417                  tn(ji,jj,jk) = tn(ji,jj,jk) * tmask(ji,jj,jk)
418                  tb(ji,jj,jk) = tn(ji,jj,jk)
419
420                  sn(ji,jj,jk) =  (  36.25 - 1.13 * TANH( (fsdept(ji,jj,jk) - 305) / 460 )  )  &
421                     &              * (-TANH((500 - fsdept(ji,jj,jk)) / 150) + 1) / 2          &
422                     &          + (  35.55 + 1.25 * (5000. - fsdept(ji,jj,jk)) / 5000.         &
423                     &                - 1.62 * TANH( (fsdept(ji,jj,jk) - 60.  ) / 650. )       &
424                     &                + 0.2  * TANH( (fsdept(ji,jj,jk) - 35.  ) / 100. )       &
425                     &                + 0.2  * TANH( (fsdept(ji,jj,jk) - 1000.) / 5000.)    )  &
426                     &              * (-TANH((fsdept(ji,jj,jk) - 500) / 150) + 1) / 2 
427                  sn(ji,jj,jk) = sn(ji,jj,jk) * tmask(ji,jj,jk)
428                  sb(ji,jj,jk) = sn(ji,jj,jk)
429               END DO
430            END DO
431         END DO
432
433      CASE ( 1 )                  ! T/S data fields read in dta_tem.nc/data_sal.nc files
434         IF(lwp) WRITE(numout,*)
435         IF(lwp) WRITE(numout,*) 'istate_gyre : initial T and S read from dta_tem.nc/data_sal.nc files'
436         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
437         IF(lwp) WRITE(numout,*) '              NetCDF FORMAT'
438
439         ! Read temperature field
440         ! ----------------------
441         CALL iom_open ( 'data_tem', inum )
442         CALL iom_get ( inum, jpdom_data, 'votemper', tn ) 
443         CALL iom_close( inum )
444
445         tn(:,:,:) = tn(:,:,:) * tmask(:,:,:) 
446         tb(:,:,:) = tn(:,:,:)
447
448         ! Read salinity field
449         ! -------------------
450         CALL iom_open ( 'data_sal', inum )
451         CALL iom_get ( inum, jpdom_data, 'vosaline', sn ) 
452         CALL iom_close( inum )
453
454         sn(:,:,:)  = sn(:,:,:) * tmask(:,:,:) 
455         sb(:,:,:)  = sn(:,:,:)
456
457      END SELECT
458
459      IF(lwp) THEN
460         WRITE(numout,*)
461         WRITE(numout,*) '              Initial temperature and salinity profiles:'
462         WRITE(numout, "(9x,' level   gdept_0   temperature   salinity   ')" )
463         WRITE(numout, "(10x, i4, 3f10.2)" ) ( jk, gdept_0(jk), tn(2,2,jk), sn(2,2,jk), jk = 1, jpk )
464      ENDIF
465
466   END SUBROUTINE istate_gyre
467
468
469   SUBROUTINE istate_uvg
470      !!----------------------------------------------------------------------
471      !!                  ***  ROUTINE istate_uvg  ***
472      !!
473      !! ** Purpose :   Compute the geostrophic velocities from (tn,sn) fields
474      !!
475      !! ** Method  :   Using the hydrostatic hypothesis the now hydrostatic
476      !!      pressure is computed by integrating the in-situ density from the
477      !!      surface to the bottom.
478      !!                 p=integral [ rau*g dz ]
479      !!----------------------------------------------------------------------
480      USE dynspg          ! surface pressure gradient             (dyn_spg routine)
481      USE divcur          ! hor. divergence & rel. vorticity      (div_cur routine)
482      USE lbclnk          ! ocean lateral boundary condition (or mpp link)
483
484      INTEGER ::   ji, jj, jk        ! dummy loop indices
485      INTEGER ::   indic             ! ???
486      REAL(wp) ::   zmsv, zphv, zmsu, zphu, zalfg     ! temporary scalars
487      REAL(wp), DIMENSION (jpi,jpj,jpk) ::   zprn     ! workspace
488      !!----------------------------------------------------------------------
489
490      IF(lwp) WRITE(numout,*) 
491      IF(lwp) WRITE(numout,*) 'istate_uvg : Start from Geostrophy'
492      IF(lwp) WRITE(numout,*) '~~~~~~~~~~'
493
494      ! Compute the now hydrostatic pressure
495      ! ------------------------------------
496
497      zalfg = 0.5 * grav * rau0
498     
499      zprn(:,:,1) = zalfg * fse3w(:,:,1) * ( 1 + rhd(:,:,1) )       ! Surface value
500
501      DO jk = 2, jpkm1                                              ! Vertical integration from the surface
502         zprn(:,:,jk) = zprn(:,:,jk-1)   &
503            &         + zalfg * fse3w(:,:,jk) * ( 2. + rhd(:,:,jk) + rhd(:,:,jk-1) )
504      END DO 
505
506      ! Compute geostrophic balance
507      ! ---------------------------
508      DO jk = 1, jpkm1
509         DO jj = 2, jpjm1
510            DO ji = fs_2, fs_jpim1   ! vertor opt.
511               zmsv = 1. / MAX(  umask(ji-1,jj+1,jk) + umask(ji  ,jj+1,jk)   &
512                               + umask(ji-1,jj  ,jk) + umask(ji  ,jj  ,jk) , 1.  )
513               zphv = ( zprn(ji  ,jj+1,jk) - zprn(ji-1,jj+1,jk) ) * umask(ji-1,jj+1,jk) / e1u(ji-1,jj+1)   &
514                    + ( zprn(ji+1,jj+1,jk) - zprn(ji  ,jj+1,jk) ) * umask(ji  ,jj+1,jk) / e1u(ji  ,jj+1)   &
515                    + ( zprn(ji  ,jj  ,jk) - zprn(ji-1,jj  ,jk) ) * umask(ji-1,jj  ,jk) / e1u(ji-1,jj  )   &
516                    + ( zprn(ji+1,jj  ,jk) - zprn(ji  ,jj  ,jk) ) * umask(ji  ,jj  ,jk) / e1u(ji  ,jj  )
517               zphv = 1. / rau0 * zphv * zmsv * vmask(ji,jj,jk)
518
519               zmsu = 1. / MAX(  vmask(ji+1,jj  ,jk) + vmask(ji  ,jj  ,jk)   &
520                               + vmask(ji+1,jj-1,jk) + vmask(ji  ,jj-1,jk) , 1.  )
521               zphu = ( zprn(ji+1,jj+1,jk) - zprn(ji+1,jj  ,jk) ) * vmask(ji+1,jj  ,jk) / e2v(ji+1,jj  )   &
522                    + ( zprn(ji  ,jj+1,jk) - zprn(ji  ,jj  ,jk) ) * vmask(ji  ,jj  ,jk) / e2v(ji  ,jj  )   &
523                    + ( zprn(ji+1,jj  ,jk) - zprn(ji+1,jj-1,jk) ) * vmask(ji+1,jj-1,jk) / e2v(ji+1,jj-1)   &
524                    + ( zprn(ji  ,jj  ,jk) - zprn(ji  ,jj-1,jk) ) * vmask(ji  ,jj-1,jk) / e2v(ji  ,jj-1)
525               zphu = 1. / rau0 * zphu * zmsu * umask(ji,jj,jk)
526
527               ! Compute the geostrophic velocities
528               un(ji,jj,jk) = -2. * zphu / ( ff(ji,jj) + ff(ji  ,jj-1) )
529               vn(ji,jj,jk) =  2. * zphv / ( ff(ji,jj) + ff(ji-1,jj  ) )
530            END DO
531         END DO
532      END DO
533
534      IF(lwp) WRITE(numout,*) '         we force to zero bottom velocity'
535
536      ! Susbtract the bottom velocity (level jpk-1 for flat bottom case)
537      ! to have a zero bottom velocity
538
539      DO jk = 1, jpkm1
540         un(:,:,jk) = ( un(:,:,jk) - un(:,:,jpkm1) ) * umask(:,:,jk)
541         vn(:,:,jk) = ( vn(:,:,jk) - vn(:,:,jpkm1) ) * vmask(:,:,jk)
542      END DO
543
544      CALL lbc_lnk( un, 'U', -1. )
545      CALL lbc_lnk( vn, 'V', -1. )
546     
547      ub(:,:,:) = un(:,:,:)
548      vb(:,:,:) = vn(:,:,:)
549     
550      ! WARNING !!!!!
551      ! after initializing u and v, we need to calculate the initial streamfunction bsf.
552      ! Otherwise, only the trend will be computed and the model will blow up (inconsistency).
553      ! to do that, we call dyn_spg with a special trick:
554      ! we fill ua and va with the velocities divided by dt, and the streamfunction will be brought to the
555      ! right value assuming the velocities have been set up in one time step.
556      ! we then set bsfd to zero (first guess for next step is d(psi)/dt = 0.)
557      !  sets up s false trend to calculate the barotropic streamfunction.
558
559      ua(:,:,:) = ub(:,:,:) / rdt
560      va(:,:,:) = vb(:,:,:) / rdt
561
562      ! calls dyn_spg. we assume euler time step, starting from rest.
563      indic = 0
564      CALL dyn_spg( nit000, indic )       ! surface pressure gradient
565
566      ! the new velocity is ua*rdt
567
568      CALL lbc_lnk( ua, 'U', -1. )
569      CALL lbc_lnk( va, 'V', -1. )
570
571      ub(:,:,:) = ua(:,:,:) * rdt
572      vb(:,:,:) = va(:,:,:) * rdt
573      ua(:,:,:) = 0.e0
574      va(:,:,:) = 0.e0
575      un(:,:,:) = ub(:,:,:)
576      vn(:,:,:) = vb(:,:,:)
577       
578#if defined key_dynspg_rl
579      IF( lk_isl )   bsfb(:,:) = bsfn(:,:)          ! Put bsfb to zero
580#endif
581
582      ! Compute the divergence and curl
583
584      CALL div_cur( nit000 )            ! now horizontal divergence and curl
585
586      hdivb(:,:,:) = hdivn(:,:,:)       ! set the before to the now value
587      rotb (:,:,:) = rotn (:,:,:)       ! set the before to the now value
588      !
589   END SUBROUTINE istate_uvg
590
591   !!=====================================================================
592END MODULE istate
Note: See TracBrowser for help on using the repository browser.