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 trunk/NEMOGCM/NEMO/TOP_SRC/TRP – NEMO

source: trunk/NEMOGCM/NEMO/TOP_SRC/TRP/trcsbc.F90 @ 7698

Last change on this file since 7698 was 7698, checked in by mocavero, 7 years ago

update trunk with OpenMP parallelization

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