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.
trcsbc.F90 in branches/UKMO/dev_r5518_GO6_under_ice_relax_dr_hook/NEMOGCM/NEMO/TOP_SRC/TRP – NEMO

source: branches/UKMO/dev_r5518_GO6_under_ice_relax_dr_hook/NEMOGCM/NEMO/TOP_SRC/TRP/trcsbc.F90 @ 11738

Last change on this file since 11738 was 11738, checked in by marc, 5 years ago

The Dr Hook changes from my perl code.

File size: 11.6 KB
Line 
1MODULE trcsbc
2   !!==============================================================================
3   !!                       ***  MODULE  trcsbc  ***
4   !! Ocean passive tracers:  surface boundary condition
5   !!======================================================================
6   !! History :  8.2  !  1998-10  (G. Madec, G. Roullet, M. Imbard)  Original code
7   !!            8.2  !  2001-02  (D. Ludicone)  sea ice and free surface
8   !!            8.5  !  2002-06  (G. Madec)  F90: Free form and module
9   !!            9.0  !  2004-03  (C. Ethe)  adapted for passive tracers
10   !!                 !  2006-08  (C. Deltel) Diagnose ML trends for passive tracers
11   !!==============================================================================
12#if defined key_top
13   !!----------------------------------------------------------------------
14   !!   'key_top'                                                TOP models
15   !!----------------------------------------------------------------------
16   !!   trc_sbc      : update the tracer trend at ocean surface
17   !!----------------------------------------------------------------------
18   USE oce_trc         ! ocean dynamics and active tracers variables
19   USE trc             ! ocean  passive tracers variables
20   USE prtctl_trc      ! Print control for debbuging
21   USE iom
22   USE trd_oce
23   USE trdtra
24
25   USE yomhook, ONLY: lhook, dr_hook
26   USE parkind1, ONLY: jprb, jpim
27
28   IMPLICIT NONE
29   PRIVATE
30
31   PUBLIC   trc_sbc   ! routine called by step.F90
32
33   REAL(wp) ::   r2dt  !  time-step at surface
34
35   !! * Substitutions
36#  include "top_substitute.h90"
37   !!----------------------------------------------------------------------
38   !! NEMO/TOP 3.3 , NEMO Consortium (2010)
39   !! $Id$
40   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
41   !!----------------------------------------------------------------------
42CONTAINS
43
44   SUBROUTINE trc_sbc ( kt )
45      !!----------------------------------------------------------------------
46      !!                  ***  ROUTINE trc_sbc  ***
47      !!                   
48      !! ** Purpose :   Compute the tracer surface boundary condition trend of
49      !!      (concentration/dilution effect) and add it to the general
50      !!       trend of tracer equations.
51      !!
52      !! ** Method :
53      !!      * concentration/dilution effect:
54      !!            The surface freshwater flux modify the ocean volume
55      !!         and thus the concentration of a tracer as :
56      !!            tra = tra + emp * trn / e3t   for k=1
57      !!         where emp, the surface freshwater budget (evaporation minus
58      !!         precipitation ) given in kg/m2/s is divided
59      !!         by 1035 kg/m3 (density of ocean water) to obtain m/s.
60      !!
61      !! ** Action  : - Update the 1st level of tra with the trend associated
62      !!                with the tracer surface boundary condition
63      !!
64      !!----------------------------------------------------------------------
65      !
66      INTEGER, INTENT( in ) ::   kt          ! ocean time-step index
67      !
68      INTEGER  ::   ji, jj, jn                                     ! dummy loop indices
69      REAL(wp) ::   zse3t, zrtrn, zratio, zfact                    ! temporary scalars
70      REAL(wp) ::   zswitch, zftra, zcd, zdtra, ztfx, ztra         ! temporary scalars
71      CHARACTER (len=22) :: charout
72      REAL(wp), POINTER, DIMENSION(:,:  ) :: zsfx
73      REAL(wp), POINTER, DIMENSION(:,:,:) :: ztrtrd
74      INTEGER(KIND=jpim), PARAMETER :: zhook_in = 0
75      INTEGER(KIND=jpim), PARAMETER :: zhook_out = 1
76      REAL(KIND=jprb)               :: zhook_handle
77
78      CHARACTER(LEN=*), PARAMETER :: RoutineName='TRC_SBC'
79
80      IF (lhook) CALL dr_hook(RoutineName,zhook_in,zhook_handle)
81
82
83      !!---------------------------------------------------------------------
84      !
85      IF( nn_timing == 1 )  CALL timing_start('trc_sbc')
86      !
87      ! Allocate temporary workspace
88                      CALL wrk_alloc( jpi, jpj,      zsfx   )
89      IF( l_trdtrc )  CALL wrk_alloc( jpi, jpj, jpk, ztrtrd )
90      !
91      zrtrn = 1.e-15_wp
92
93      SELECT CASE( nn_ice_embd )         ! levitating or embedded sea-ice option
94         CASE( 0    )   ;   zswitch = 1  ! (0) standard levitating sea-ice : salt exchange only
95         CASE( 1, 2 )   ;   zswitch = 0  ! (1) levitating sea-ice: salt and volume exchange but no pressure effect                               
96                                         ! (2) embedded sea-ice : salt and volume fluxes and pressure
97      END SELECT
98
99      IF( ln_top_euler) THEN
100         r2dt =  rdttrc(1)              ! = rdttrc (use Euler time stepping)
101      ELSE
102         IF( neuler == 0 .AND. kt == nittrc000 ) THEN     ! at nittrc000
103            r2dt = rdttrc(1)           ! = rdttrc (restarting with Euler time stepping)
104         ELSEIF( kt <= nittrc000 + nn_dttrc ) THEN          ! at nittrc000 or nittrc000+1
105            r2dt = 2. * rdttrc(1)       ! = 2 rdttrc (leapfrog)
106         ENDIF
107      ENDIF
108
109
110      IF( kt == nittrc000 ) THEN
111         IF(lwp) WRITE(numout,*)
112         IF(lwp) WRITE(numout,*) 'trc_sbc : Passive tracers surface boundary condition'
113         IF(lwp) WRITE(numout,*) '~~~~~~~ '
114
115         !! JPALM -- 12-01-2016 -- problem after restart, maybe because of this...
116         !!                     -- set sbc_trc_b to 0 after restart, first, to check.
117         !!------------------------------------------------------------------------------
118        ! IF( ln_rsttr .AND. .NOT.ln_top_euler .AND.   &                     ! Restart: read in restart  file
119        !    iom_varid( numrtr, 'sbc_'//TRIM(ctrcnm(1))//'_b', ldstop = .FALSE. ) > 0 ) THEN
120        !    IF(lwp) WRITE(numout,*) '          nittrc000-nn_dttrc surface tracer content forcing fields red in the restart file'
121        !    zfact = 0.5_wp
122        !    DO jn = 1, jptra
123        !       CALL iom_get( numrtr, jpdom_autoglo, 'sbc_'//TRIM(ctrcnm(jn))//'_b', sbc_trc_b(:,:,jn) )   ! before tracer content sbc
124        !    END DO
125        ! ELSE                                         ! No restart or restart not found: Euler forward time stepping
126           zfact = 1._wp
127           sbc_trc_b(:,:,:) = 0._wp
128        ! ENDIF
129      ELSE                                         ! Swap of forcing fields
130         IF( ln_top_euler ) THEN
131            zfact = 1._wp
132            sbc_trc_b(:,:,:) = 0._wp
133         ELSE
134            zfact = 0.5_wp
135            sbc_trc_b(:,:,:) = sbc_trc(:,:,:)
136         ENDIF
137         !
138      ENDIF
139
140      ! Coupling online : river runoff is added to the horizontal divergence (hdivn) in the subroutine sbc_rnf_div
141      ! one only consider the concentration/dilution effect due to evaporation minus precipitation + freezing/melting of sea-ice
142      ! Coupling offline : runoff are in emp which contains E-P-R
143      !
144      IF( .NOT. lk_offline .AND. lk_vvl ) THEN  ! online coupling with vvl
145         zsfx(:,:) = 0._wp
146      ELSE                                      ! online coupling free surface or offline with free surface
147         zsfx(:,:) = emp(:,:)
148      ENDIF
149
150      ! 0. initialization
151      DO jn = 1, jptra
152         !
153         IF( l_trdtrc ) THEN
154            ztrtrd(:,:,:) = 0.0
155            ztrtrd(:,:,1) = tra(:,:,1,jn)  ! save surface trends
156         !                                 ! add the trend to the general tracer trend
157         ENDIF
158
159         IF ( nn_ice_tr == -1 ) THEN  ! No tracers in sea ice (null concentration in sea ice)
160
161            DO jj = 2, jpj
162               DO ji = fs_2, fs_jpim1   ! vector opt.
163                  sbc_trc(ji,jj,jn) = zsfx(ji,jj) * r1_rau0 * trn(ji,jj,1,jn)
164               END DO
165            END DO
166
167         ELSE
168
169            DO jj = 2, jpj
170               DO ji = fs_2, fs_jpim1   ! vector opt.
171                  zse3t = 1. / fse3t(ji,jj,1)
172                  ! tracer flux at the ice/ocean interface (tracer/m2/s)
173                  zftra = - trc_i(ji,jj,jn) * fmmflx(ji,jj) ! uptake of tracer in the sea ice
174                  zcd   =   trc_o(ji,jj,jn) * fmmflx(ji,jj) ! concentration dilution due to freezing-melting,
175                                                               ! only used in the levitating sea ice case
176                  ! tracer flux only       : add concentration dilution term in net tracer flux, no F-M in volume flux
177                  ! tracer and mass fluxes : no concentration dilution term in net tracer flux, F-M term in volume flux
178                  ztfx  = zftra + zswitch * zcd                ! net tracer flux (+C/D if no ice/ocean mass exchange)
179   
180                  zdtra = r1_rau0 * ( ztfx + zsfx(ji,jj) * trn(ji,jj,1,jn) ) 
181                  IF ( zdtra < 0. ) THEN
182                     zratio = -zdtra * zse3t * r2dt / ( trn(ji,jj,1,jn) + zrtrn )
183                     zdtra = MIN(1.0, zratio) * zdtra ! avoid negative concentrations to arise
184                  ENDIF
185                  sbc_trc(ji,jj,jn) =  zdtra 
186               END DO
187            END DO
188         ENDIF
189         !
190         CALL lbc_lnk( sbc_trc(:,:,jn), 'T', 1. )
191         !                                       Concentration dilution effect on tracers due to evaporation & precipitation
192         DO jj = 2, jpj
193            DO ji = fs_2, fs_jpim1   ! vector opt.
194               zse3t = zfact / fse3t(ji,jj,1)
195               tra(ji,jj,1,jn) = tra(ji,jj,1,jn) + ( sbc_trc_b(ji,jj,jn) + sbc_trc(ji,jj,jn) ) * zse3t
196            END DO
197         END DO
198         !
199         IF( l_trdtrc ) THEN
200            ztrtrd(:,:,1) = tra(:,:,1,jn) - ztrtrd(:,:,1)
201            CALL trd_tra( kt, 'TRC', jn, jptra_nsr, ztrtrd )
202         END IF
203         !                                                       ! ===========
204      END DO                                                     ! tracer loop
205      !                                                          ! ===========
206
207      !                                           Write in the tracer restar  file
208      !                                          *******************************
209      IF( lrst_trc .AND. .NOT.ln_top_euler ) THEN
210         IF(lwp) WRITE(numout,*)
211         IF(lwp) WRITE(numout,*) 'sbc : ocean surface tracer content forcing fields written in tracer restart file ',   &
212            &                    'at it= ', kt,' date= ', ndastp
213         IF(lwp) WRITE(numout,*) '~~~~'
214         DO jn = 1, jptra
215            CALL iom_rstput( kt, nitrst, numrtw, 'sbc_'//TRIM(ctrcnm(jn))//'_b', sbc_trc(:,:,jn) )
216         END DO
217      ENDIF
218      !
219      IF( ln_ctl )   THEN
220         WRITE(charout, FMT="('sbc ')") ;  CALL prt_ctl_trc_info(charout)
221                                           CALL prt_ctl_trc( tab4d=tra, mask=tmask, clinfo=ctrcnm, clinfo2='trd' )
222      ENDIF
223                      CALL wrk_dealloc( jpi, jpj,      zsfx   )
224      IF( l_trdtrc )  CALL wrk_dealloc( jpi, jpj, jpk, ztrtrd )
225      !
226      IF( nn_timing == 1 )  CALL timing_stop('trc_sbc')
227      !
228      IF (lhook) CALL dr_hook(RoutineName,zhook_out,zhook_handle)
229   END SUBROUTINE trc_sbc
230
231#else
232   !!----------------------------------------------------------------------
233   !!   Dummy module :                      NO passive tracer
234   !!----------------------------------------------------------------------
235CONTAINS
236   SUBROUTINE trc_sbc (kt)              ! Empty routine
237      INTEGER, INTENT(in) :: kt
238      INTEGER(KIND=jpim), PARAMETER :: zhook_in = 0
239      INTEGER(KIND=jpim), PARAMETER :: zhook_out = 1
240      REAL(KIND=jprb)               :: zhook_handle
241
242      CHARACTER(LEN=*), PARAMETER :: RoutineName='TRC_SBC'
243
244      IF (lhook) CALL dr_hook(RoutineName,zhook_in,zhook_handle)
245
246      WRITE(*,*) 'trc_sbc: You should not have seen this print! error?', kt
247      IF (lhook) CALL dr_hook(RoutineName,zhook_out,zhook_handle)
248   END SUBROUTINE trc_sbc
249#endif
250   
251   !!======================================================================
252END MODULE trcsbc
Note: See TracBrowser for help on using the repository browser.