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.
sbcfwb.F90 in NEMO/releases/r4.0/r4.0-HEAD/src/OCE/SBC – NEMO

source: NEMO/releases/r4.0/r4.0-HEAD/src/OCE/SBC/sbcfwb.F90 @ 15092

Last change on this file since 15092 was 14717, checked in by clem, 3 years ago

4.0-HEAD: correctly handle diagnostics of mass, salt and heat budgets (see ticket #2652). And fix Pierre ticket #2642

  • Property svn:keywords set to Id
File size: 14.1 KB
Line 
1MODULE sbcfwb
2   !!======================================================================
3   !!                       ***  MODULE  sbcfwb  ***
4   !! Ocean fluxes   : domain averaged freshwater budget
5   !!======================================================================
6   !! History :  OPA  ! 2001-02  (E. Durand)  Original code
7   !!   NEMO     1.0  ! 2002-06  (G. Madec)  F90: Free form and module
8   !!            3.0  ! 2006-08  (G. Madec)  Surface module
9   !!            3.2  ! 2009-07  (C. Talandier) emp mean s spread over erp area
10   !!            3.6  ! 2014-11  (P. Mathiot  ) add ice shelf melting
11   !!----------------------------------------------------------------------
12
13   !!----------------------------------------------------------------------
14   !!   sbc_fwb       : freshwater budget for global ocean configurations (free surface & forced mode)
15   !!----------------------------------------------------------------------
16   USE oce            ! ocean dynamics and tracers
17   USE dom_oce        ! ocean space and time domain
18   USE sbc_oce        ! surface ocean boundary condition
19   USE sbc_ice , ONLY : snwice_mass, snwice_mass_b, snwice_fmass
20   USE phycst         ! physical constants
21   USE sbcrnf         ! ocean runoffs
22   USE sbcisf         ! ice shelf melting contribution
23   USE sbcssr         ! Sea-Surface damping terms
24   !
25   USE in_out_manager ! I/O manager
26   USE iom            ! IOM
27   USE lib_mpp        ! distribued memory computing library
28   USE timing         ! Timing
29   USE lbclnk         ! ocean lateral boundary conditions
30   USE lib_fortran    !
31
32   IMPLICIT NONE
33   PRIVATE
34
35   PUBLIC   sbc_fwb    ! routine called by step
36
37   REAL(wp) ::   a_fwb_b   ! annual domain averaged freshwater budget
38   REAL(wp) ::   a_fwb     ! for 2 year before (_b) and before year.
39   REAL(wp) ::   fwfold    ! fwfold to be suppressed
40   REAL(wp) ::   area      ! global mean ocean surface (interior domain)
41
42   !! * Substitutions
43#  include "vectopt_loop_substitute.h90"
44   !!----------------------------------------------------------------------
45   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
46   !! $Id$
47   !! Software governed by the CeCILL license (see ./LICENSE)
48   !!----------------------------------------------------------------------
49CONTAINS
50
51   SUBROUTINE sbc_fwb( kt, kn_fwb, kn_fsbc )
52      !!---------------------------------------------------------------------
53      !!                  ***  ROUTINE sbc_fwb  ***
54      !!
55      !! ** Purpose :   Control the mean sea surface drift
56      !!
57      !! ** Method  :   several ways  depending on kn_fwb
58      !!                =0 no control
59      !!                =1 global mean of emp set to zero at each nn_fsbc time step
60      !!                =2 annual global mean corrected from previous year
61      !!                =3 global mean of emp set to zero at each nn_fsbc time step
62      !!                   & spread out over erp area depending its sign
63      !! Note: if sea ice is embedded it is taken into account when computing the budget
64      !!----------------------------------------------------------------------
65      INTEGER, INTENT( in ) ::   kt       ! ocean time-step index
66      INTEGER, INTENT( in ) ::   kn_fsbc  !
67      INTEGER, INTENT( in ) ::   kn_fwb   ! ocean time-step index
68      !
69      INTEGER  ::   inum, ikty, iyear     ! local integers
70      REAL(wp) ::   z_fwf, z_fwf_nsrf, zsum_fwf, zsum_erp                ! local scalars
71      REAL(wp) ::   zsurf_neg, zsurf_pos, zsurf_tospread, zcoef          !   -      -
72      REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   ztmsk_neg, ztmsk_pos, z_wgt ! 2D workspaces
73      REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   ztmsk_tospread, zerp_cor    !   -      -
74      REAL(wp)   ,DIMENSION(1) ::   z_fwfprv 
75      COMPLEX(wp),DIMENSION(1) ::   y_fwfnow 
76      !!----------------------------------------------------------------------
77      !
78      IF( kt == nit000 ) THEN
79         IF(lwp) THEN
80            WRITE(numout,*)
81            WRITE(numout,*) 'sbc_fwb : FreshWater Budget correction'
82            WRITE(numout,*) '~~~~~~~'
83            IF( kn_fwb == 1 )   WRITE(numout,*) '          instantaneously set to zero'
84            IF( kn_fwb == 2 )   WRITE(numout,*) '          adjusted from previous year budget'
85            IF( kn_fwb == 3 )   WRITE(numout,*) '          fwf set to zero and spread out over erp area'
86         ENDIF
87         !
88         IF( kn_fwb == 3 .AND. nn_sssr /= 2 )   CALL ctl_stop( 'sbc_fwb: nn_fwb = 3 requires nn_sssr = 2, we stop ' )
89         IF( kn_fwb == 3 .AND. ln_isfcav    )   CALL ctl_stop( 'sbc_fwb: nn_fwb = 3 with ln_isfcav = .TRUE. not working, we stop ' )
90         !
91         area = glob_sum( 'sbcfwb', e1e2t(:,:) * tmask(:,:,1))           ! interior global domain surface
92         ! isf cavities are excluded because it can feedback to the melting with generation of inhibition of plumes
93         ! and in case of no melt, it can generate HSSW.
94         !
95#if ! defined key_si3 && ! defined key_cice
96         snwice_mass_b(:,:) = 0.e0               ! no sea-ice model is being used : no snow+ice mass
97         snwice_mass  (:,:) = 0.e0
98         snwice_fmass (:,:) = 0.e0
99#endif
100         !
101      ENDIF
102
103      SELECT CASE ( kn_fwb )
104      !
105      CASE ( 1 )                             !==  global mean fwf set to zero  ==!
106         !
107         IF( MOD( kt-1, kn_fsbc ) == 0 ) THEN
108            y_fwfnow(1) = local_sum( e1e2t(:,:) * ( emp(:,:) - rnf(:,:) + fwfisf(:,:) - snwice_fmass(:,:) ) )
109            CALL mpp_delay_sum( 'sbcfwb', 'fwb', y_fwfnow(:), z_fwfprv(:), kt == nitend - nn_fsbc + 1 )
110            z_fwfprv(1) = z_fwfprv(1) / area
111            zcoef = z_fwfprv(1) * rcp
112            emp(:,:) = emp(:,:) - z_fwfprv(1)        * tmask(:,:,1)
113            qns(:,:) = qns(:,:) + zcoef * sst_m(:,:) * tmask(:,:,1) ! account for change to the heat budget due to fw correction
114            ! outputs
115            IF( iom_use('hflx_fwb_cea') )  CALL iom_put( 'hflx_fwb_cea', zcoef * sst_m(:,:) * tmask(:,:,1) )
116            IF( iom_use('vflx_fwb_cea') )  CALL iom_put( 'vflx_fwb_cea', z_fwfprv(1)        * tmask(:,:,1) )
117         ENDIF
118         !
119      CASE ( 2 )                             !==  fwf budget adjusted from the previous year  ==!
120         !
121         IF( kt == nit000 ) THEN                      ! initialisation
122            !                                         ! Read the corrective factor on precipitations (fwfold)
123            IF ( ln_rstart .AND. iom_varid( numror, 'a_fwb_b', ldstop = .FALSE. ) > 0     &
124               &           .AND. iom_varid( numror, 'a_fwb',   ldstop = .FALSE. ) > 0 ) THEN
125               IF(lwp) WRITE(numout,*) 'sbc_fwb : reading FW-budget adjustment from restart file'
126               CALL iom_get( numror, 'a_fwb_b', a_fwb_b, ldxios = lrxios )
127               CALL iom_get( numror, 'a_fwb',   a_fwb,   ldxios = lrxios )
128            ELSE
129               CALL ctl_opn( inum, 'EMPave_old.dat', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, numout, .FALSE. )
130               READ ( inum, "(24X,I8,2ES24.16)" ) iyear, a_fwb_b, a_fwb
131               CLOSE( inum )
132            END IF
133            fwfold = a_fwb                            ! current year freshwater budget correction
134            !                                         ! estimate from the previous year budget
135            IF(lwp)WRITE(numout,*)
136            IF(lwp)WRITE(numout,*)'sbc_fwb : year = ',iyear  , ' freshwater budget correction = ', fwfold
137            IF(lwp)WRITE(numout,*)'          year = ',iyear-1, ' freshwater budget read       = ', a_fwb
138            IF(lwp)WRITE(numout,*)'          year = ',iyear-2, ' freshwater budget read       = ', a_fwb_b
139            !
140            IF( lwxios ) THEN                         ! Activate output of restart variables
141               CALL iom_set_rstw_var_active( 'a_fwb_b' )
142               CALL iom_set_rstw_var_active( 'a_fwb'   )
143            END IF
144         ENDIF   
145         !                                         ! Update fwfold if new year start
146         ikty = 365 * 86400 / rdt                  !!bug  use of 365 days leap year or 360d year !!!!!!!
147         IF( MOD( kt, ikty ) == 0 ) THEN
148            a_fwb_b = a_fwb                           ! mean sea level taking into account the ice+snow
149                                                      ! sum over the global domain
150            a_fwb   = glob_sum( 'sbcfwb', e1e2t(:,:) * ( sshn(:,:) + snwice_mass(:,:) * r1_rau0 ) )
151            a_fwb   = a_fwb * 1.e+3 / ( area * rday * 365. )     ! convert in Kg/m3/s = mm/s
152!!gm        !                                                      !!bug 365d year
153            fwfold =  a_fwb                           ! current year freshwater budget correction
154            !                                         ! estimate from the previous year budget
155         ENDIF
156         !
157         IF( MOD( kt-1, kn_fsbc ) == 0 ) THEN         ! correct the freshwater fluxes
158            zcoef = fwfold * rcp
159            emp(:,:) = emp(:,:) + fwfold             * tmask(:,:,1)
160            qns(:,:) = qns(:,:) - zcoef * sst_m(:,:) * tmask(:,:,1) ! account for change to the heat budget due to fw correction
161            ! outputs
162            IF( iom_use('hflx_fwb_cea') )  CALL iom_put( 'hflx_fwb_cea', -zcoef * sst_m(:,:) * tmask(:,:,1) )
163            IF( iom_use('vflx_fwb_cea') )  CALL iom_put( 'vflx_fwb_cea', -fwfold             * tmask(:,:,1) )
164         ENDIF
165         ! Output restart information
166         IF( lrst_oce ) THEN
167            IF(lwp) WRITE(numout,*)
168            IF(lwp) WRITE(numout,*) 'sbc_fwb : writing FW-budget adjustment to ocean restart file at it = ', kt
169            IF(lwp) WRITE(numout,*) '~~~~'
170            IF( lwxios ) CALL iom_swap( cwxios_context )
171            CALL iom_rstput( kt, nitrst, numrow, 'a_fwb_b', a_fwb_b, ldxios = lwxios )
172            CALL iom_rstput( kt, nitrst, numrow, 'a_fwb',   a_fwb,   ldxios = lwxios )
173            IF( lwxios ) CALL iom_swap( cxios_context  )
174         END IF
175         !
176         IF( kt == nitend .AND. lwm ) THEN            ! save fwfold value in a file (only one required)
177            CALL ctl_opn( inum, 'EMPave.dat', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, .FALSE., narea )
178            WRITE( inum, "(24X,I8,2ES24.16)" ) nyear, a_fwb_b, a_fwb
179            CLOSE( inum )
180         ENDIF
181         !
182      CASE ( 3 )                             !==  global fwf set to zero and spread out over erp area  ==!
183         !
184         ALLOCATE( ztmsk_neg(jpi,jpj) , ztmsk_pos(jpi,jpj) , ztmsk_tospread(jpi,jpj) , z_wgt(jpi,jpj) , zerp_cor(jpi,jpj) )
185         !
186         IF( MOD( kt-1, kn_fsbc ) == 0 ) THEN
187            ztmsk_pos(:,:) = tmask_i(:,:)                      ! Select <0 and >0 area of erp
188            WHERE( erp < 0._wp )   ztmsk_pos = 0._wp
189            ztmsk_neg(:,:) = tmask_i(:,:) - ztmsk_pos(:,:)
190            !                                                  ! fwf global mean (excluding ocean to ice/snow exchanges)
191            z_fwf     = glob_sum( 'sbcfwb', e1e2t(:,:) * ( emp(:,:) - rnf(:,:) + fwfisf(:,:) - snwice_fmass(:,:) ) ) / area
192            !           
193            IF( z_fwf < 0._wp ) THEN         ! spread out over >0 erp area to increase evaporation
194               zsurf_pos = glob_sum( 'sbcfwb', e1e2t(:,:)*ztmsk_pos(:,:) )
195               zsurf_tospread      = zsurf_pos
196               ztmsk_tospread(:,:) = ztmsk_pos(:,:)
197            ELSE                             ! spread out over <0 erp area to increase precipitation
198               zsurf_neg = glob_sum( 'sbcfwb', e1e2t(:,:)*ztmsk_neg(:,:) )  ! Area filled by <0 and >0 erp
199               zsurf_tospread      = zsurf_neg
200               ztmsk_tospread(:,:) = ztmsk_neg(:,:)
201            ENDIF
202            !
203            zsum_fwf   = glob_sum( 'sbcfwb', e1e2t(:,:) * z_fwf )         ! fwf global mean over <0 or >0 erp area
204!!gm :  zsum_fwf   = z_fwf * area   ???  it is right?  I think so....
205            z_fwf_nsrf =  zsum_fwf / ( zsurf_tospread + rsmall )
206            !                                                  ! weight to respect erp field 2D structure
207            zsum_erp   = glob_sum( 'sbcfwb', ztmsk_tospread(:,:) * erp(:,:) * e1e2t(:,:) )
208            z_wgt(:,:) = ztmsk_tospread(:,:) * erp(:,:) / ( zsum_erp + rsmall )
209            !                                                  ! final correction term to apply
210            zerp_cor(:,:) = -1. * z_fwf_nsrf * zsurf_tospread * z_wgt(:,:)
211            !
212!!gm   ===>>>>  lbc_lnk should be useless as all the computation is done over the whole domain !
213            CALL lbc_lnk( 'sbcfwb', zerp_cor, 'T', 1. )
214            !
215            emp(:,:) = emp(:,:) + zerp_cor(:,:)
216            qns(:,:) = qns(:,:) - zerp_cor(:,:) * rcp * sst_m(:,:)  ! account for change to the heat budget due to fw correction
217            erp(:,:) = erp(:,:) + zerp_cor(:,:)
218            ! outputs
219            IF( iom_use('hflx_fwb_cea') )  CALL iom_put( 'hflx_fwb_cea', -zerp_cor(:,:) * rcp * sst_m(:,:) )
220            IF( iom_use('vflx_fwb_cea') )  CALL iom_put( 'vflx_fwb_cea', -zerp_cor(:,:) )
221            !
222            IF( nprint == 1 .AND. lwp ) THEN                   ! control print
223               IF( z_fwf < 0._wp ) THEN
224                  WRITE(numout,*)'   z_fwf < 0'
225                  WRITE(numout,*)'   SUM(erp+)     = ', SUM( ztmsk_tospread(:,:)*erp(:,:)*e1e2t(:,:) )*1.e-9,' Sv'
226               ELSE
227                  WRITE(numout,*)'   z_fwf >= 0'
228                  WRITE(numout,*)'   SUM(erp-)     = ', SUM( ztmsk_tospread(:,:)*erp(:,:)*e1e2t(:,:) )*1.e-9,' Sv'
229               ENDIF
230               WRITE(numout,*)'   SUM(empG)     = ', SUM( z_fwf*e1e2t(:,:) )*1.e-9,' Sv'
231               WRITE(numout,*)'   z_fwf         = ', z_fwf      ,' Kg/m2/s'
232               WRITE(numout,*)'   z_fwf_nsrf    = ', z_fwf_nsrf ,' Kg/m2/s'
233               WRITE(numout,*)'   MIN(zerp_cor) = ', MINVAL(zerp_cor) 
234               WRITE(numout,*)'   MAX(zerp_cor) = ', MAXVAL(zerp_cor) 
235            ENDIF
236         ENDIF
237         DEALLOCATE( ztmsk_neg , ztmsk_pos , ztmsk_tospread , z_wgt , zerp_cor )
238         !
239      CASE DEFAULT                           !==  you should never be there  ==!
240         CALL ctl_stop( 'sbc_fwb : wrong nn_fwb value for the FreshWater Budget correction, choose either 1, 2 or 3' )
241         !
242      END SELECT
243      !
244   END SUBROUTINE sbc_fwb
245
246   !!======================================================================
247END MODULE sbcfwb
Note: See TracBrowser for help on using the repository browser.