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 NEMO/branches/2021/dev_r14318_RK3_stage1/src/TOP/TRP – NEMO

source: NEMO/branches/2021/dev_r14318_RK3_stage1/src/TOP/TRP/trcsbc.F90 @ 15532

Last change on this file since 15532 was 15532, checked in by techene, 3 years ago

#2605 #2715 : version in dev (still buggy)

  • Property svn:keywords set to Id
File size: 19.3 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 par_trc        ! need jptra, number of passive tracers
19   USE oce_trc        ! ocean dynamics and active tracers variables
20   USE trc            ! ocean  passive tracers variables
21   USE prtctl         ! Print control for debbuging
22   USE iom
23   USE trd_oce
24   USE trdtra
25
26   IMPLICIT NONE
27   PRIVATE
28
29   PUBLIC   trc_sbc       ! routine called by trctrp.F90
30   PUBLIC   trc_sbc_RK3   ! routine called by stprk3_stg.F90
31
32   !! * Substitutions
33#  include "do_loop_substitute.h90"
34#  include "domzgr_substitute.h90"
35   !!----------------------------------------------------------------------
36   !! NEMO/TOP 4.0 , NEMO Consortium (2018)
37   !! $Id$
38   !! Software governed by the CeCILL license (see ./LICENSE)
39   !!----------------------------------------------------------------------
40CONTAINS
41
42   SUBROUTINE trc_sbc ( kt, Kmm, ptr, Krhs )
43      !!----------------------------------------------------------------------
44      !!                  ***  ROUTINE trc_sbc  ***
45      !!                   
46      !! ** Purpose :   Compute the tracer surface boundary condition trend of
47      !!      (concentration/dilution effect) and add it to the general
48      !!       trend of tracer equations.
49      !!
50      !! ** Method :
51      !!      * concentration/dilution effect:
52      !!            The surface freshwater flux modify the ocean volume
53      !!         and thus the concentration of a tracer as :
54      !!            tr(Krhs) = tr(Krhs) + emp * tr(Kmm) / e3t_   for k=1
55      !!         where emp, the surface freshwater budget (evaporation minus
56      !!         precipitation ) given in kg/m2/s is divided
57      !!         by 1035 kg/m3 (density of ocean water) to obtain m/s.
58      !!
59      !! ** Action  : - Update the 1st level of tr(:,:,:,:,Krhs) with the trend associated
60      !!                with the tracer surface boundary condition
61      !!
62      !!----------------------------------------------------------------------
63      INTEGER,                                    INTENT(in   ) :: kt        ! ocean time-step index
64      INTEGER,                                    INTENT(in   ) :: Kmm, Krhs ! time level indices
65      REAL(wp), DIMENSION(jpi,jpj,jpk,jptra,jpt), INTENT(inout) :: ptr       ! passive tracers and RHS of tracer equation
66      !
67      INTEGER  ::   ji, jj, jn                      ! dummy loop indices
68      REAL(wp) ::   zse3t, zrtrn, zfact     ! local scalars
69      REAL(wp) ::   zftra, zdtra, ztfx, ztra   !   -      -
70      CHARACTER (len=22) :: charout
71      REAL(wp), DIMENSION(jpi,jpj)   ::   zsfx
72      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) ::   ztrtrd
73      !!---------------------------------------------------------------------
74      !
75      IF( ln_timing )   CALL timing_start('trc_sbc')
76      !
77      ! Allocate temporary workspace
78      IF( l_trdtrc )  ALLOCATE( ztrtrd(jpi,jpj,jpk) )
79      !
80      zrtrn = 1.e-15_wp
81
82      IF( kt == nittrc000 ) THEN
83         IF(lwp) WRITE(numout,*)
84         IF(lwp) WRITE(numout,*) 'trc_sbc : Passive tracers surface boundary condition'
85         IF(lwp) WRITE(numout,*) '~~~~~~~ '
86         !
87#if ! defined key_RK3
88         IF( ln_rsttr .AND. .NOT.ln_top_euler .AND.   &                     ! Restart: read in restart  file
89            iom_varid( numrtr, 'sbc_'//TRIM(ctrcnm(1))//'_b', ldstop = .FALSE. ) > 0 ) THEN
90            IF(lwp) WRITE(numout,*) '          nittrc000-1 surface tracer content forcing fields read in the restart file'
91            zfact = 0.5_wp
92            DO jn = 1, jptra
93               CALL iom_get( numrtr, jpdom_auto, 'sbc_'//TRIM(ctrcnm(jn))//'_b', sbc_trc_b(:,:,jn) )   ! before tracer content sbc
94            END DO
95         ELSE                                         ! No restart or restart not found: Euler forward time stepping
96           zfact = 1._wp
97           sbc_trc_b(:,:,:) = 0._wp
98         ENDIF
99      ELSE                                         ! Swap of forcing fields
100         IF( ln_top_euler ) THEN
101            zfact = 1._wp
102            sbc_trc_b(:,:,:) = 0._wp
103         ELSE
104            zfact = 0.5_wp
105            sbc_trc_b(:,:,:) = sbc_trc(:,:,:)
106         ENDIF
107         !
108#endif
109      ENDIF
110
111      ! Coupling online : river runoff is added to the horizontal divergence (hdiv) in the subroutine sbc_rnf_div
112      ! one only consider the concentration/dilution effect due to evaporation minus precipitation + freezing/melting of sea-ice
113      ! Coupling offline : runoff are in emp which contains E-P-R
114      !
115      IF( .NOT.ln_linssh ) THEN  ! online coupling with vvl
116         zsfx(:,:) = 0._wp
117      ELSE                                      ! online coupling free surface or offline with free surface
118         zsfx(:,:) = emp(:,:)
119      ENDIF
120!!st DO LOOPs used to look like DO_2D( 0, 0, 0, 1 ) I changed it because it does not work in debug mode...
121
122      ! 0. initialization
123      SELECT CASE ( nn_ice_tr )
124
125      CASE ( -1 ) ! No tracers in sea ice (null concentration in sea ice)
126         !
127         DO jn = 1, jptra
128            DO_2D( 0, 0, 0, 0 )
129               sbc_trc(ji,jj,jn) = zsfx(ji,jj) * r1_rho0 * ptr(ji,jj,1,jn,Kmm)
130            END_2D
131         END DO
132         !
133      CASE ( 0 )  ! Same concentration in sea ice and in the ocean
134         !
135         DO jn = 1, jptra
136            DO_2D( 0, 0, 0, 0 )
137               sbc_trc(ji,jj,jn) = ( zsfx(ji,jj) + fmmflx(ji,jj) ) * r1_rho0 * ptr(ji,jj,1,jn,Kmm)
138            END_2D
139         END DO
140         !
141      CASE ( 1 )  ! Specific treatment of sea ice fluxes with an imposed concentration in sea ice
142         !
143         DO jn = 1, jptra
144            DO_2D( 0, 0, 0, 0 )
145               ! tracer flux at the ice/ocean interface (tracer/m2/s)
146               zftra = - trc_i(ji,jj,jn) * fmmflx(ji,jj) ! uptake of tracer in the sea ice
147               !                                         ! only used in the levitating sea ice case
148               ! tracer flux only       : add concentration dilution term in net tracer flux, no F-M in volume flux
149               ! tracer and mass fluxes : no concentration dilution term in net tracer flux, F-M term in volume flux
150               ztfx  = zftra                        ! net tracer flux
151               !
152               zdtra = r1_rho0 * ( ztfx + ( zsfx(ji,jj) + fmmflx(ji,jj) ) * ptr(ji,jj,1,jn,Kmm) ) 
153               IF ( zdtra < 0. ) THEN
154                  zdtra  = MAX(zdtra, -ptr(ji,jj,1,jn,Kmm) * e3t(ji,jj,1,Kmm) / rDt_trc )   ! avoid negative concentrations to arise
155               ENDIF
156               sbc_trc(ji,jj,jn) =  zdtra 
157            END_2D
158         END DO
159      END SELECT
160      !
161      CALL lbc_lnk( 'trcsbc', sbc_trc(:,:,:), 'T', 1.0_wp )
162      !                                       Concentration dilution effect on tracers due to evaporation & precipitation
163      DO jn = 1, jptra
164         !
165         IF( l_trdtrc )   ztrtrd(:,:,:) = ptr(:,:,:,jn,Krhs)  ! save trends
166         !
167         DO_2D( 0, 0, 0, 0 )
168#if defined key_RK3
169            zse3t = 1._wp / e3t(ji,jj,1,Kmm)
170            ptr(ji,jj,1,jn,Krhs) = ptr(ji,jj,1,jn,Krhs) + sbc_trc(ji,jj,jn) * zse3t
171#else
172            zse3t = zfact / e3t(ji,jj,1,Kmm)
173            ptr(ji,jj,1,jn,Krhs) = ptr(ji,jj,1,jn,Krhs) + ( sbc_trc_b(ji,jj,jn) + sbc_trc(ji,jj,jn) ) * zse3t
174#endif
175         END_2D
176         !
177         IF( l_trdtrc ) THEN
178            ztrtrd(:,:,:) = ptr(:,:,:,jn,Krhs) - ztrtrd(:,:,:)
179            CALL trd_tra( kt, Kmm, Krhs, 'TRC', jn, jptra_nsr, ztrtrd )
180         END IF
181         !                                                       ! ===========
182      END DO                                                     ! tracer loop
183      !                                                          ! ===========
184      !
185#if ! defined key_RK3
186      !                                           Write in the tracer restar  file
187      !                                          *******************************
188      IF( lrst_trc .AND. .NOT.ln_top_euler ) THEN
189         IF(lwp) WRITE(numout,*)
190         IF(lwp) WRITE(numout,*) 'sbc : ocean surface tracer content forcing fields written in tracer restart file ',   &
191            &                    'at it= ', kt,' date= ', ndastp
192         IF(lwp) WRITE(numout,*) '~~~~'
193         DO jn = 1, jptra
194            CALL iom_rstput( kt, nitrst, numrtw, 'sbc_'//TRIM(ctrcnm(jn))//'_b', sbc_trc(:,:,jn) )
195         END DO
196      ENDIF
197#endif
198      !
199      IF( sn_cfctl%l_prttrc )   THEN
200         WRITE(charout, FMT="('sbc ')") ;  CALL prt_ctl_info( charout, cdcomp = 'top' )
201                                           CALL prt_ctl( tab4d_1=ptr(:,:,:,:,Krhs), mask1=tmask, clinfo=ctrcnm, clinfo3='trd' )
202      ENDIF
203      IF( l_trdtrc )  DEALLOCATE( ztrtrd )
204      !
205      IF( ln_timing )   CALL timing_stop('trc_sbc')
206      !
207   END SUBROUTINE trc_sbc
208
209!!st
210   SUBROUTINE trc_sbc_RK3 ( kt, Kmm, ptr, Krhs, kstg )
211      !!----------------------------------------------------------------------
212      !!                  ***  ROUTINE trc_sbc_RK3  ***
213      !!                   
214      !! ** Purpose :   Compute the tracer surface boundary condition trend of
215      !!      (concentration/dilution effect) and add it to the general
216      !!       trend of tracer equations.
217      !!
218      !! ** Method :
219      !!      * concentration/dilution effect:
220      !!            The surface freshwater flux modify the ocean volume
221      !!         and thus the concentration of a tracer as :
222      !!            tr(Krhs) = tr(Krhs) + emp * tr(Kmm) / e3t_   for k=1
223      !!         where emp, the surface freshwater budget (evaporation minus
224      !!         precipitation ) given in kg/m2/s is divided
225      !!         by 1035 kg/m3 (density of ocean water) to obtain m/s.
226      !!
227      !! ** Action  : - Update the 1st level of tr(:,:,:,:,Krhs) with the trend associated
228      !!                with the tracer surface boundary condition
229      !!
230      !!----------------------------------------------------------------------
231      INTEGER                                   , INTENT(in   ) ::   kt, Kmm, Krhs   ! ocean time-step and time-level indices
232      INTEGER                                   , INTENT(in   ) ::   kstg            ! RK3 stage index
233      REAL(wp), DIMENSION(jpi,jpj,jpk,jptra,jpt), INTENT(inout) ::   ptr       ! passive tracers and RHS of tracer equation
234      !
235      INTEGER  ::   ji, jj, jn           ! dummy loop indices
236      REAL(wp) ::   z1_rho0_e3t          ! local scalars
237      REAL(wp) ::   zftra, zdtra, ztfx   !   -      -
238      CHARACTER (len=22) :: charout
239      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) ::   ztrtrd
240      !!---------------------------------------------------------------------
241      !
242      IF( ln_timing )   CALL timing_start('trc_sbc_RK3')
243      !
244      IF( kt == nittrc000 ) THEN
245         IF(lwp) WRITE(numout,*)
246         IF(lwp) WRITE(numout,*) 'trc_sbc_RK3 : Passive tracers surface boundary condition'
247         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~ '
248      ENDIF
249      !
250!!st note that trc_sbc can be removed only re-use in atf (not relevant for RK3)
251      SELECT CASE( kstg )
252         !
253      CASE( 1 , 2 )                       !=  stage 1 and 2  =!   only in non linear ssh
254         !
255         IF( .NOT.ln_linssh ) THEN           !* only passive tracer fluxes associated with mass fluxes
256            !                                        ! no passive tracer concentration modification due to ssh variation
257!!st emp includes fmm see iceupdate.F90
258!!not sure about trc_i case... (1)
259            DO jn = 1, jptra
260               DO_2D( 0, 0, 0, 0 )              !!st WHY 1 : exterior here ?
261                  z1_rho0_e3t = r1_rho0 / e3t(ji,jj,1,Kmm)
262                  ptr(ji,jj,1,jn,Krhs) = ptr(ji,jj,1,jn,Krhs) - emp(ji,jj) * ptr(ji,jj,1,jn,Kmm) * z1_rho0_e3t
263               END_2D
264            END DO
265            !
266         ENDIF
267         !
268      CASE( 3 )
269         !
270         ! Allocate temporary workspace
271         IF( l_trdtrc )  ALLOCATE( ztrtrd(jpi,jpj,jpk) )
272         !
273         DO jn = 1, jptra
274            IF( l_trdtrc )   ztrtrd(:,:,:) = ptr(:,:,:,jn,Krhs)  ! save trends
275         END DO
276         !
277         IF( ln_linssh ) THEN                !* linear free surface (add concentration/dilution effect artificially since no volume variation)
278            !
279            SELECT CASE ( nn_ice_tr )
280               !
281            CASE ( -1 ) ! No tracers in sea ice (null concentration in sea ice)
282               !
283               DO jn = 1, jptra
284                  DO_2D( 0, 0, 0, 0 )
285                     z1_rho0_e3t = r1_rho0  / e3t(ji,jj,1,Kmm)
286                     ptr(ji,jj,1,jn,Krhs) = ptr(ji,jj,1,jn,Krhs) + emp(ji,jj) * r1_rho0 * ptr(ji,jj,1,jn,Kmm)
287                  END_2D
288               END DO
289               !
290            CASE ( 0 )  ! Same concentration in sea ice and in the ocean fmm contribution to concentration/dilution effect has to be removed
291               !
292               DO jn = 1, jptra
293                  DO_2D( 0, 0, 0, 1 )
294                     z1_rho0_e3t = r1_rho0  / e3t(ji,jj,1,Kmm)
295                     ptr(ji,jj,1,jn,Krhs) = ptr(ji,jj,1,jn,Krhs) + ( emp(ji,jj) - fmmflx(ji,jj) ) * r1_rho0 * ptr(ji,jj,1,jn,Kmm)
296                  END_2D
297               END DO
298               !
299            CASE ( 1 )  ! Specific treatment of sea ice fluxes with an imposed concentration in sea ice !!st TODO : check Christian new implementation
300               !
301               DO jn = 1, jptra
302                  DO_2D( 0, 0, 0, 0 )
303                     z1_rho0_e3t = r1_rho0  / e3t(ji,jj,1,Kmm)
304                     ! tracer flux at the ice/ocean interface (tracer/m2/s)
305                     zftra = - trc_i(ji,jj,jn) * fmmflx(ji,jj) ! uptake of tracer in the sea ice
306                     !                                         ! only used in the levitating sea ice case
307                     ! tracer flux only       : add concentration dilution term in net tracer flux, no F-M in volume flux
308                     ! tracer and mass fluxes : no concentration dilution term in net tracer flux, F-M term in volume flux
309                     ztfx  = zftra                        ! net tracer flux
310                     !
311                     zdtra = r1_rho0 * ( ztfx +  ( emp(ji,jj) - fmmflx(ji,jj) ) * ptr(ji,jj,1,jn,Kmm) ) 
312                     IF ( zdtra < 0. ) THEN
313                        zdtra  = MAX(zdtra, -ptr(ji,jj,1,jn,Kmm) * e3t(ji,jj,1,Kmm) / rDt_trc )   ! avoid negative concentrations to arise
314                     ENDIF
315                     ptr(ji,jj,1,jn,Krhs) = ptr(ji,jj,1,jn,Krhs) + zdtra
316                  END_2D
317               END DO
318               !
319            END SELECT
320            !
321         ELSE                                !* non linear free surface (concentration/dilution effect due to volume variation)
322            !
323            SELECT CASE ( nn_ice_tr )
324            ! CASE ( -1 ) natural concentration/dilution effect due to volume variation : nothing to do
325            !
326            CASE ( 0 )  ! Same concentration in sea ice and in the ocean : correct concentration/dilution effect due to "freezing - melting"
327               !
328               DO jn = 1, jptra
329                  DO_2D( 0, 0, 0, 1 )
330                     z1_rho0_e3t = r1_rho0  / e3t(ji,jj,1,Kmm)
331                     ptr(ji,jj,1,jn,Krhs) = ptr(ji,jj,1,jn,Krhs) - fmmflx(ji,jj) * r1_rho0 * ptr(ji,jj,1,jn,Kmm)
332                  END_2D
333               END DO
334               !
335            CASE ( 1 )  ! Specific treatment of sea ice fluxes with an imposed concentration in sea ice
336               !
337               DO jn = 1, jptra
338                  DO_2D( 0, 0, 0, 0 )
339                     ! tracer flux at the ice/ocean interface (tracer/m2/s)
340                     zftra = - trc_i(ji,jj,jn) * fmmflx(ji,jj) ! uptake of tracer in the sea ice
341                     !                                         ! only used in the levitating sea ice case
342                     ! tracer flux only       : add concentration dilution term in net tracer flux, no F-M in volume flux
343                     ! tracer and mass fluxes : no concentration dilution term in net tracer flux, F-M term in volume flux
344                     ztfx  = zftra                        ! net tracer flux
345                     !
346                     zdtra = r1_rho0 * ( ztfx -  fmmflx(ji,jj) * ptr(ji,jj,1,jn,Kmm) ) 
347                     IF ( zdtra < 0. ) THEN
348                        zdtra  = MAX(zdtra, -ptr(ji,jj,1,jn,Kmm) * e3t(ji,jj,1,Kmm) / rDt_trc )   ! avoid negative concentrations to arise
349                     ENDIF
350                     ptr(ji,jj,1,jn,Krhs) = ptr(ji,jj,1,jn,Krhs) + zdtra
351                  END_2D
352               END DO
353               !
354            END SELECT
355            !
356         ENDIF
357         !
358         !
359!!st useless trc_sbc only in the interior even in MLF case         CALL lbc_lnk( 'trcsbc', sbc_trc(:,:,:), 'T', 1.0_wp )
360         !                                       Concentration dilution effect on tracers due to evaporation & precipitation
361         DO jn = 1, jptra
362            !
363            IF(lwp) WRITE(numout,*)
364            IF(lwp) WRITE(numout,*) 'trc_sbc_RK3 : Runge Kutta 3rd order at stage ', kstg, jn
365            IF(lwp) WRITE(numout,*)
366            !
367            IF( l_trdtrc ) THEN
368               ztrtrd(:,:,:) = ptr(:,:,:,jn,Krhs) - ztrtrd(:,:,:)
369               CALL trd_tra( kt, Kmm, Krhs, 'TRC', jn, jptra_nsr, ztrtrd )
370            END IF
371            !
372         END DO
373         !
374         IF( l_trdtrc )  DEALLOCATE( ztrtrd )
375         !
376      END SELECT
377      !
378      IF( sn_cfctl%l_prttrc )   THEN
379         WRITE(charout, FMT="('sbc ')") ;  CALL prt_ctl_info( charout, cdcomp = 'top' )
380                                           CALL prt_ctl( tab4d_1=ptr(:,:,:,:,Krhs), mask1=tmask, clinfo=ctrcnm, clinfo3='trd' )
381      ENDIF
382      !
383      IF( ln_timing )   CALL timing_stop('trc_sbc_RK3')
384      !
385   END SUBROUTINE trc_sbc_RK3
386!!st
387
388#else
389   !!----------------------------------------------------------------------
390   !!   Dummy module :                      NO passive tracer
391   !!----------------------------------------------------------------------
392   USE par_oce
393   USE par_trc
394CONTAINS
395   SUBROUTINE trc_sbc ( kt, Kmm, ptr, Krhs )      ! Empty routine
396      INTEGER,                                    INTENT(in   ) :: kt        ! ocean time-step index
397      INTEGER,                                    INTENT(in   ) :: Kmm, Krhs ! time level indices
398      REAL(wp), DIMENSION(jpi,jpj,jpk,jptra,jpt), INTENT(inout) :: ptr       ! passive tracers and RHS of tracer equation
399      WRITE(*,*) 'trc_sbc: You should not have seen this print! error?', kt
400   END SUBROUTINE trc_sbc
401#endif
402   
403   !!======================================================================
404END MODULE trcsbc
Note: See TracBrowser for help on using the repository browser.