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.
dtauvd.F90 in branches/2015/dev_r5836_NOC3_vvl_by_default/NEMOGCM/NEMO/OPA_SRC/C1D – NEMO

source: branches/2015/dev_r5836_NOC3_vvl_by_default/NEMOGCM/NEMO/OPA_SRC/C1D/dtauvd.F90 @ 5845

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

#1613: vvl by default: suppression of domzgr_substitute.h90

  • Property svn:keywords set to Id
File size: 11.9 KB
Line 
1MODULE dtauvd
2   !!======================================================================
3   !!                     ***  MODULE  dtauvd  ***
4   !! Ocean data  :  read ocean U & V current data from gridded data
5   !!======================================================================
6   !! History :  3.5   ! 2013-08  (D. Calvert)  Original code
7   !!----------------------------------------------------------------------
8
9   !!----------------------------------------------------------------------
10   !!   dta_uvd_init   : read namelist and allocate data structures
11   !!   dta_uvd        : read and time-interpolate ocean U & V current data
12   !!----------------------------------------------------------------------
13   USE oce             ! ocean dynamics and tracers
14   USE dom_oce         ! ocean space and time domain
15   USE fldread         ! read input fields
16   USE in_out_manager  ! I/O manager
17   USE phycst          ! physical constants
18   USE lib_mpp         ! MPP library
19   USE wrk_nemo        ! Memory allocation
20   USE timing          ! Timing
21
22   IMPLICIT NONE
23   PRIVATE
24
25   PUBLIC   dta_uvd_init   ! called by nemogcm.F90
26   PUBLIC   dta_uvd        ! called by istate.F90 and dyndmp.90
27
28   LOGICAL , PUBLIC ::   ln_uvd_init         ! Flag to initialise with U & V current data
29   LOGICAL , PUBLIC ::   ln_uvd_dyndmp       ! Flag for Newtonian damping toward U & V current data
30
31   TYPE(FLD), ALLOCATABLE, DIMENSION(:) ::   sf_uvd   ! structure for input U & V current (file information and data)
32
33   !!----------------------------------------------------------------------
34   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
35   !! $Id$
36   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
37   !!----------------------------------------------------------------------
38CONTAINS
39
40   SUBROUTINE dta_uvd_init( ld_dyndmp )
41      !!----------------------------------------------------------------------
42      !!                   ***  ROUTINE dta_uvd_init  ***
43      !!                   
44      !! ** Purpose :   initialization of U & V current input data
45      !!
46      !! ** Method  : - read namc1d_uvd namelist
47      !!              - allocate U & V current data structure
48      !!              - fld_fill data structure with namelist information
49      !!----------------------------------------------------------------------
50      LOGICAL, INTENT(in), OPTIONAL ::   ld_dyndmp         ! force the initialization when dyndmp is used
51      !
52      INTEGER ::   ierr0, ierr1, ierr2, ierr3              ! temporary integers
53      !
54      CHARACTER(len=100)            ::   cn_dir            ! Root directory for location of files to be used
55      TYPE(FLD_N), DIMENSION(2)     ::   suv_i             ! Combined U & V namelist information
56      TYPE(FLD_N)                   ::   sn_ucur, sn_vcur  ! U & V data namelist information
57      !!
58      NAMELIST/namc1d_uvd/ ln_uvd_init, ln_uvd_dyndmp, cn_dir, sn_ucur, sn_vcur
59      INTEGER  ::   ios
60      !!----------------------------------------------------------------------
61      !
62      IF( nn_timing == 1 )  CALL timing_start('dta_uvd_init')
63      !
64      ierr0 = 0  ;  ierr1 = 0  ;  ierr2 = 0  ;  ierr3 = 0
65
66      REWIND( numnam_ref )              ! Namelist namc1d_uvd in reference namelist :
67      READ  ( numnam_ref, namc1d_uvd, IOSTAT = ios, ERR = 901)
68901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namc1d_uvd in reference namelist', lwp )
69
70      REWIND( numnam_cfg )              ! Namelist namc1d_uvd in configuration namelist : Parameters of the run
71      READ  ( numnam_cfg, namc1d_uvd, IOSTAT = ios, ERR = 902 )
72902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namc1d_uvd in configuration namelist', lwp )
73      IF(lwm) WRITE ( numond, namc1d_uvd )
74
75      !                             ! force the initialization when dyndmp is used
76      IF( PRESENT( ld_dyndmp ) )   ln_uvd_dyndmp = .TRUE.
77     
78      IF(lwp) THEN                  ! control print
79         WRITE(numout,*)
80         WRITE(numout,*) 'dta_uvd_init : U & V current data '
81         WRITE(numout,*) '~~~~~~~~~~~~ '
82         WRITE(numout,*) '   Namelist namc1d_uvd : Set flags'
83         WRITE(numout,*) '      Initialization of ocean U & V current with input data   ln_uvd_init   = ', ln_uvd_init
84         WRITE(numout,*) '      Damping of ocean U & V current toward input data        ln_uvd_dyndmp = ', ln_uvd_dyndmp
85         WRITE(numout,*)
86         IF( .NOT. ln_uvd_init .AND. .NOT. ln_uvd_dyndmp ) THEN
87            WRITE(numout,*)
88            WRITE(numout,*) '   U & V current data not used'
89         ENDIF
90      ENDIF
91      !                             ! no initialization when restarting
92      IF( ln_rstart .AND. ln_uvd_init ) THEN
93         CALL ctl_warn( 'dta_uvd_init: ocean restart and U & V current data initialization, ',   &
94            &           'we keep the restart U & V current values and set ln_uvd_init to FALSE' )
95         ln_uvd_init = .FALSE.
96      ENDIF
97
98      !
99      IF(  ln_uvd_init .OR. ln_uvd_dyndmp  ) THEN
100         !                          !==   allocate the data arrays   ==!
101         ALLOCATE( sf_uvd(2), STAT=ierr0 )
102         IF( ierr0 > 0 ) THEN
103            CALL ctl_stop( 'dta_uvd_init: unable to allocate sf_uvd structure' )             ;   RETURN
104         ENDIF
105         !
106                                 ALLOCATE( sf_uvd(1)%fnow(jpi,jpj,jpk)   , STAT=ierr0 )
107         IF( sn_ucur%ln_tint )   ALLOCATE( sf_uvd(1)%fdta(jpi,jpj,jpk,2) , STAT=ierr1 )
108                                 ALLOCATE( sf_uvd(2)%fnow(jpi,jpj,jpk)   , STAT=ierr2 )
109         IF( sn_vcur%ln_tint )   ALLOCATE( sf_uvd(2)%fdta(jpi,jpj,jpk,2) , STAT=ierr3 )
110         !
111         IF( ierr0 + ierr1 + ierr2 + ierr3 > 0 ) THEN
112            CALL ctl_stop( 'dta_uvd_init : unable to allocate U & V current data arrays' )   ;   RETURN
113         ENDIF
114         !                          !==   fill sf_uvd with sn_ucur, sn_vcur and control print   ==!
115         suv_i(1) = sn_ucur   ;   suv_i(2) = sn_vcur
116         CALL fld_fill( sf_uvd, suv_i, cn_dir, 'dta_uvd', 'U & V current data', 'namc1d_uvd' )
117         !
118      ENDIF
119      !
120      IF( nn_timing == 1 )  CALL timing_stop('dta_uvd_init')
121      !
122   END SUBROUTINE dta_uvd_init
123
124
125   SUBROUTINE dta_uvd( kt, puvd )
126      !!----------------------------------------------------------------------
127      !!                   ***  ROUTINE dta_uvd  ***
128      !!                   
129      !! ** Purpose :   provides U & V current data at time step kt
130      !!
131      !! ** Method  : - call fldread routine
132      !!              - ORCA_R2: make some hand made alterations to the data (EMPTY)
133      !!              - s- or mixed s-zps coordinate: vertical interpolation onto model mesh
134      !!              - zps coordinate: vertical interpolation onto last partial level
135      !!              - ln_uvd_dyndmp=False: deallocate the U & V current data structure,
136      !!                                     as the data is no longer used
137      !!
138      !! ** Action  :   puvd,  U & V current data interpolated onto model mesh at time-step kt
139      !!----------------------------------------------------------------------
140      INTEGER                           , INTENT(in   ) ::   kt     ! ocean time-step
141      REAL(wp), DIMENSION(jpi,jpj,jpk,2), INTENT(  out) ::   puvd   ! U & V current data
142      !
143      INTEGER ::   ji, jj, jk, jl, jkk               ! dummy loop indicies
144      INTEGER ::   ik, il0, il1, ii0, ii1, ij0, ij1  ! local integers
145      REAL(wp)::   zl, zi                            ! local floats
146      REAL(wp), POINTER, DIMENSION(:) ::  zup, zvp   ! 1D workspace
147      !!----------------------------------------------------------------------
148      !
149      IF( nn_timing == 1 )  CALL timing_start('dta_uvd')
150      !
151      CALL fld_read( kt, 1, sf_uvd )      !==   read U & V current data at time step kt   ==!
152      !
153      !
154      !                                   !==   ORCA_R2 configuration and U & V current damping   ==!
155      IF( cp_cfg == "orca" .AND. jp_cfg == 2 .AND. ln_uvd_dyndmp ) THEN    ! some hand made alterations
156         !!! EMPTY- to be added for running in 3D context !!!
157      ENDIF
158      !
159      puvd(:,:,:,1) = sf_uvd(1)%fnow(:,:,:)                 ! NO mask
160      puvd(:,:,:,2) = sf_uvd(2)%fnow(:,:,:) 
161      !
162      IF( ln_sco ) THEN                   !==   s- or mixed s-zps-coordinate   ==!
163         !
164         CALL wrk_alloc( jpk, zup, zvp )
165         !
166         IF( kt == nit000 .AND. lwp )THEN
167            WRITE(numout,*)
168            WRITE(numout,*) 'dta_uvd: interpolate U & V current data onto the s- or mixed s-z-coordinate mesh'
169         ENDIF
170         !
171         DO jj = 1, jpj                   ! vertical interpolation of U & V current:
172            DO ji = 1, jpi                ! determines the interpolated U & V current profiles at each (i,j) point
173               DO jk = 1, jpk
174                  zl = gdept_n(ji,jj,jk)
175                  IF    ( zl < gdept_1d(1  ) ) THEN          ! extrapolate above the first level of data
176                     zup(jk) =  puvd(ji,jj,1    ,1)
177                     zvp(jk) =  puvd(ji,jj,1    ,2)
178                  ELSEIF( zl > gdept_1d(jpk) ) THEN          ! extrapolate below the last level of data
179                     zup(jk) =  puvd(ji,jj,jpkm1,1)
180                     zvp(jk) =  puvd(ji,jj,jpkm1,2)
181                  ELSE                                      ! inbetween : vertical interpolation between jkk & jkk+1
182                     DO jkk = 1, jpkm1                      ! when  gdept(jkk) < zl < gdept(jkk+1)
183                        IF( (zl-gdept_1d(jkk)) * (zl-gdept_1d(jkk+1)) <= 0._wp ) THEN
184                           zi = ( zl - gdept_1d(jkk) ) / (gdept_1d(jkk+1)-gdept_1d(jkk))
185                           zup(jk) = puvd(ji,jj,jkk,1) + ( puvd(ji,jj,jkk+1,1 ) - puvd(ji,jj,jkk,1) ) * zi 
186                           zvp(jk) = puvd(ji,jj,jkk,2) + ( puvd(ji,jj,jkk+1,2 ) - puvd(ji,jj,jkk,2) ) * zi
187                        ENDIF
188                     END DO
189                  ENDIF
190               END DO
191               DO jk = 1, jpkm1           ! apply mask
192                  puvd(ji,jj,jk,1) = zup(jk) * umask(ji,jj,jk)
193                  puvd(ji,jj,jk,2) = zvp(jk) * vmask(ji,jj,jk)
194               END DO
195               puvd(ji,jj,jpk,1) = 0._wp
196               puvd(ji,jj,jpk,2) = 0._wp
197            END DO
198         END DO
199         !
200         CALL wrk_dealloc( jpk, zup, zvp )
201         !
202      ELSE                                !==   z- or zps- coordinate   ==!
203         !                             
204         puvd(:,:,:,1) = puvd(:,:,:,1) * umask(:,:,:)       ! apply mask
205         puvd(:,:,:,2) = puvd(:,:,:,2) * vmask(:,:,:)
206         !
207         IF( ln_zps ) THEN                ! zps-coordinate (partial steps) interpolation at the last ocean level
208            DO jj = 1, jpj
209               DO ji = 1, jpi
210                  ik = mbkt(ji,jj) 
211                  IF( ik > 1 ) THEN
212                     zl = ( gdept_1d(ik) - gdept_0(ji,jj,ik) ) / ( gdept_1d(ik) - gdept_1d(ik-1) )
213                     puvd(ji,jj,ik,1) = (1.-zl) * puvd(ji,jj,ik,1) + zl * puvd(ji,jj,ik-1,1)
214                     puvd(ji,jj,ik,2) = (1.-zl) * puvd(ji,jj,ik,2) + zl * puvd(ji,jj,ik-1,2)
215                  ENDIF
216               END DO
217            END DO
218         ENDIF
219         !
220      ENDIF
221      !
222      IF( .NOT. ln_uvd_dyndmp    ) THEN   !==   deallocate U & V current structure   ==!
223         !                                !==   (data used only for initialization)  ==!
224         IF(lwp) WRITE(numout,*) 'dta_uvd: deallocate U & V current arrays as they are only used to initialize the run'
225                                   DEALLOCATE( sf_uvd(1)%fnow )     ! U current arrays in the structure
226         IF( sf_uvd(1)%ln_tint )   DEALLOCATE( sf_uvd(1)%fdta )
227                                   DEALLOCATE( sf_uvd(2)%fnow )     ! V current arrays in the structure
228         IF( sf_uvd(2)%ln_tint )   DEALLOCATE( sf_uvd(2)%fdta )
229                                   DEALLOCATE( sf_uvd         )     ! the structure itself
230      ENDIF
231      !
232      IF( nn_timing == 1 )  CALL timing_stop('dta_uvd')
233      !
234   END SUBROUTINE dta_uvd
235
236   !!======================================================================
237END MODULE dtauvd
Note: See TracBrowser for help on using the repository browser.