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/trunk/src/OCE/SBC – NEMO

source: NEMO/trunk/src/OCE/SBC/sbcfwb.F90

Last change on this file was 15439, checked in by clem, 3 years ago

trunk: freshwater budget is now corrected for option nn_fwb=2. The option could be improved. There is a drift the 1st year and the correction applied can lead to oscillations in the solution. It is related to tickets #2718 and part of #2487 though the fix is somewhat different than proposed in the tickets.

  • Property svn:keywords set to Id
File size: 14.7 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 isf_oce , ONLY : fwfisf_cav, fwfisf_par                    ! ice shelf melting contribution
20   USE sbc_ice , ONLY : snwice_mass, snwice_mass_b, snwice_fmass
21   USE phycst         ! physical constants
22   USE sbcrnf         ! ocean runoffs
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) ::   rn_fwb0   ! initial freshwater adjustment flux [kg/m2/s] (nn_fwb = 2 only)
38   REAL(wp) ::   a_fwb     ! annual domain averaged freshwater budget from the previous year
39   REAL(wp) ::   a_fwb_b   ! annual domain averaged freshwater budget from the year before or at initial state
40   REAL(wp) ::   a_fwb_ini ! initial domain averaged freshwater budget
41   REAL(wp) ::   area      ! global mean ocean surface (interior domain)
42
43   !!----------------------------------------------------------------------
44   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
45   !! $Id$
46   !! Software governed by the CeCILL license (see ./LICENSE)
47   !!----------------------------------------------------------------------
48CONTAINS
49
50   SUBROUTINE sbc_fwb( kt, kn_fwb, kn_fsbc, Kmm )
51      !!---------------------------------------------------------------------
52      !!                  ***  ROUTINE sbc_fwb  ***
53      !!
54      !! ** Purpose :   Control the mean sea surface drift
55      !!
56      !! ** Method  :   several ways  depending on kn_fwb
57      !!                =0 no control
58      !!                =1 global mean of emp set to zero at each nn_fsbc time step
59      !!                =2 annual global mean corrected from previous year
60      !!                =3 global mean of emp set to zero at each nn_fsbc time step
61      !!                   & spread out over erp area depending its sign
62      !! Note: if sea ice is embedded it is taken into account when computing the budget
63      !!----------------------------------------------------------------------
64      INTEGER, INTENT( in ) ::   kt       ! ocean time-step index
65      INTEGER, INTENT( in ) ::   kn_fsbc  !
66      INTEGER, INTENT( in ) ::   kn_fwb   ! ocean time-step index
67      INTEGER, INTENT( in ) ::   Kmm      ! ocean time level index
68      !
69      INTEGER  ::   ios, inum, ikty       ! 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(dp),DIMENSION(1) ::   y_fwfnow 
76      !
77      NAMELIST/namsbc_fwb/rn_fwb0
78      !!----------------------------------------------------------------------
79      !
80      IF( kt == nit000 ) THEN
81         READ( numnam_ref, namsbc_fwb, IOSTAT = ios, ERR = 901 )
82901      IF( ios /= 0 ) CALL ctl_nam( ios, 'namsbc_fwb in reference namelist'     )
83         READ( numnam_cfg, namsbc_fwb, IOSTAT = ios, ERR = 902 )
84902      IF( ios >  0 ) CALL ctl_nam( ios, 'namsbc_fwb in configuration namelist' )
85         IF(lwm) WRITE( numond, namsbc_fwb )
86         IF(lwp) THEN
87            WRITE(numout,*)
88            WRITE(numout,*) 'sbc_fwb : FreshWater Budget correction'
89            WRITE(numout,*) '~~~~~~~'
90            IF( kn_fwb == 1 )   WRITE(numout,*) '          instantaneously set to zero'
91            IF( kn_fwb == 3 )   WRITE(numout,*) '          fwf set to zero and spread out over erp area'
92            IF( kn_fwb == 2 ) THEN
93               WRITE(numout,*) '          adjusted from previous year budget'
94               WRITE(numout,*)
95               WRITE(numout,*) '   Namelist namsbc_fwb'
96               WRITE(numout,*) '      Initial freshwater adjustment flux [kg/m2/s] = ', rn_fwb0
97            END IF
98         ENDIF
99         !
100         IF( kn_fwb == 3 .AND. nn_sssr /= 2 )   CALL ctl_stop( 'sbc_fwb: nn_fwb = 3 requires nn_sssr = 2, we stop ' )
101         IF( kn_fwb == 3 .AND. ln_isfcav    )   CALL ctl_stop( 'sbc_fwb: nn_fwb = 3 with ln_isfcav = .TRUE. not working, we stop ' )
102         !
103         area = glob_sum( 'sbcfwb', e1e2t(:,:) * tmask(:,:,1))           ! interior global domain surface
104         ! isf cavities are excluded because it can feedback to the melting with generation of inhibition of plumes
105         ! and in case of no melt, it can generate HSSW.
106         !
107#if ! defined key_si3 && ! defined key_cice
108         snwice_mass_b(:,:) = 0.e0               ! no sea-ice model is being used : no snow+ice mass
109         snwice_mass  (:,:) = 0.e0
110         snwice_fmass (:,:) = 0.e0
111#endif
112         !
113      ENDIF
114
115      SELECT CASE ( kn_fwb )
116      !
117      CASE ( 1 )                             !==  global mean fwf set to zero  ==!
118         !
119         IF( MOD( kt-1, kn_fsbc ) == 0 ) THEN
120            y_fwfnow(1) = local_sum( e1e2t(:,:) * ( emp(:,:) - rnf(:,:) - fwfisf_cav(:,:) - fwfisf_par(:,:) - snwice_fmass(:,:) ) )
121            CALL mpp_delay_sum( 'sbcfwb', 'fwb', y_fwfnow(:), z_fwfprv(:), kt == nitend - nn_fsbc + 1 )
122            z_fwfprv(1) = z_fwfprv(1) / area
123            zcoef = z_fwfprv(1) * rcp
124            emp(:,:) = emp(:,:) - z_fwfprv(1)        * tmask(:,:,1)
125            qns(:,:) = qns(:,:) + zcoef * sst_m(:,:) * tmask(:,:,1) ! account for change to the heat budget due to fw correction
126            ! outputs
127            IF( iom_use('hflx_fwb_cea') )  CALL iom_put( 'hflx_fwb_cea', zcoef * sst_m(:,:) * tmask(:,:,1) )
128            IF( iom_use('vflx_fwb_cea') )  CALL iom_put( 'vflx_fwb_cea', z_fwfprv(1)        * tmask(:,:,1) )
129         ENDIF
130         !
131      CASE ( 2 )                             !==  fw adjustment based on fw budget at the end of the previous year  ==!
132         !                                                simulation is supposed to start 1st of January
133         IF( kt == nit000 ) THEN                                                                 ! initialisation
134            !                                                                                    ! set the fw adjustment (a_fwb)
135            IF ( ln_rstart .AND. iom_varid( numror, 'a_fwb_b', ldstop = .FALSE. ) > 0     &      !    as read from restart file
136               &           .AND. iom_varid( numror, 'a_fwb',   ldstop = .FALSE. ) > 0 ) THEN
137               IF(lwp)   WRITE(numout,*) 'sbc_fwb : reading freshwater-budget from restart file'
138               CALL iom_get( numror, 'a_fwb_b', a_fwb_b )
139               CALL iom_get( numror, 'a_fwb'  , a_fwb )
140               !
141               a_fwb_ini = a_fwb_b
142            ELSE                                                                                 !    as specified in namelist
143               IF(lwp)   WRITE(numout,*) 'sbc_fwb : setting freshwater-budget from namelist rn_fwb0'
144               a_fwb   = rn_fwb0
145               a_fwb_b = 0._wp   ! used only the first year then it is replaced by a_fwb_ini
146               !
147               a_fwb_ini = glob_sum( 'sbcfwb', e1e2t(:,:) * ( ssh(:,:,Kmm) + snwice_mass(:,:) * r1_rho0 ) ) &
148                  &      * rho0 / ( area * rday * REAL(nyear_len(1), wp) )
149            END IF
150            !
151            IF(lwp)   WRITE(numout,*)
152            IF(lwp)   WRITE(numout,*)'sbc_fwb : freshwater-budget at the end of previous year = ', a_fwb    , 'kg/m2/s'
153            IF(lwp)   WRITE(numout,*)'          freshwater-budget at initial state            = ', a_fwb_ini, 'kg/m2/s'
154            !
155         ELSE
156            ! at the end of year n:
157            ikty = nyear_len(1) * 86400 / NINT(rn_Dt)
158            IF( MOD( kt, ikty ) == 0 ) THEN   ! Update a_fwb at the last time step of a year
159               !                                It should be the first time step of a year MOD(kt-1,ikty) but then the restart would be wrong
160               !                                Hence, we make a small error here but the code is restartable
161               a_fwb_b = a_fwb_ini
162               ! mean sea level taking into account ice+snow
163               a_fwb   = glob_sum( 'sbcfwb', e1e2t(:,:) * ( ssh(:,:,Kmm) + snwice_mass(:,:) * r1_rho0 ) )
164               a_fwb   = a_fwb * rho0 / ( area * rday * REAL(nyear_len(1), wp) )   ! convert in kg/m2/s
165            ENDIF
166            !
167         ENDIF
168         !
169         IF( MOD( kt-1, kn_fsbc ) == 0 ) THEN         ! correct the freshwater fluxes using previous year budget minus initial state
170            zcoef = ( a_fwb - a_fwb_b )
171            emp(:,:) = emp(:,:) + zcoef * tmask(:,:,1)
172            qns(:,:) = qns(:,:) - zcoef * rcp * sst_m(:,:) * tmask(:,:,1) ! account for change to the heat budget due to fw correction
173            ! outputs
174            IF( iom_use('hflx_fwb_cea') )  CALL iom_put( 'hflx_fwb_cea', -zcoef * rcp * sst_m(:,:) * tmask(:,:,1) )
175            IF( iom_use('vflx_fwb_cea') )  CALL iom_put( 'vflx_fwb_cea', -zcoef * tmask(:,:,1) )
176         ENDIF
177         ! Output restart information
178         IF( lrst_oce ) THEN
179            IF(lwp) WRITE(numout,*)
180            IF(lwp) WRITE(numout,*) 'sbc_fwb : writing FW-budget adjustment to ocean restart file at it = ', kt
181            IF(lwp) WRITE(numout,*) '~~~~'
182            CALL iom_rstput( kt, nitrst, numrow, 'a_fwb_b', a_fwb_b )
183            CALL iom_rstput( kt, nitrst, numrow, 'a_fwb',   a_fwb   )
184         END IF
185         !
186         IF( kt == nitend .AND. lwp ) THEN
187            WRITE(numout,*) 'sbc_fwb : freshwater-budget at the end of simulation (year now) = ', a_fwb  , 'kg/m2/s'
188            WRITE(numout,*) '          freshwater-budget at initial state                    = ', a_fwb_b, 'kg/m2/s'
189         ENDIF
190         !
191      CASE ( 3 )                             !==  global fwf set to zero and spread out over erp area  ==!
192         !
193         ALLOCATE( ztmsk_neg(jpi,jpj) , ztmsk_pos(jpi,jpj) , ztmsk_tospread(jpi,jpj) , z_wgt(jpi,jpj) , zerp_cor(jpi,jpj) )
194         !
195         IF( MOD( kt-1, kn_fsbc ) == 0 ) THEN
196            ztmsk_pos(:,:) = tmask_i(:,:)                      ! Select <0 and >0 area of erp
197            WHERE( erp < 0._wp )   ztmsk_pos = 0._wp
198            ztmsk_neg(:,:) = tmask_i(:,:) - ztmsk_pos(:,:)
199            !                                                  ! fwf global mean (excluding ocean to ice/snow exchanges)
200            z_fwf     = glob_sum( 'sbcfwb', e1e2t(:,:) * ( emp(:,:) - rnf(:,:) - fwfisf_cav(:,:) - fwfisf_par(:,:) - snwice_fmass(:,:) ) ) / area
201            !           
202            IF( z_fwf < 0._wp ) THEN         ! spread out over >0 erp area to increase evaporation
203               zsurf_pos = glob_sum( 'sbcfwb', e1e2t(:,:)*ztmsk_pos(:,:) )
204               zsurf_tospread      = zsurf_pos
205               ztmsk_tospread(:,:) = ztmsk_pos(:,:)
206            ELSE                             ! spread out over <0 erp area to increase precipitation
207               zsurf_neg = glob_sum( 'sbcfwb', e1e2t(:,:)*ztmsk_neg(:,:) )  ! Area filled by <0 and >0 erp
208               zsurf_tospread      = zsurf_neg
209               ztmsk_tospread(:,:) = ztmsk_neg(:,:)
210            ENDIF
211            !
212            zsum_fwf   = glob_sum( 'sbcfwb', e1e2t(:,:) * z_fwf )         ! fwf global mean over <0 or >0 erp area
213!!gm :  zsum_fwf   = z_fwf * area   ???  it is right?  I think so....
214            z_fwf_nsrf =  zsum_fwf / ( zsurf_tospread + rsmall )
215            !                                                  ! weight to respect erp field 2D structure
216            zsum_erp   = glob_sum( 'sbcfwb', ztmsk_tospread(:,:) * erp(:,:) * e1e2t(:,:) )
217            z_wgt(:,:) = ztmsk_tospread(:,:) * erp(:,:) / ( zsum_erp + rsmall )
218            !                                                  ! final correction term to apply
219            zerp_cor(:,:) = -1. * z_fwf_nsrf * zsurf_tospread * z_wgt(:,:)
220            !
221!!gm   ===>>>>  lbc_lnk should be useless as all the computation is done over the whole domain !
222            CALL lbc_lnk( 'sbcfwb', zerp_cor, 'T', 1.0_wp )
223            !
224            emp(:,:) = emp(:,:) + zerp_cor(:,:)
225            qns(:,:) = qns(:,:) - zerp_cor(:,:) * rcp * sst_m(:,:)  ! account for change to the heat budget due to fw correction
226            erp(:,:) = erp(:,:) + zerp_cor(:,:)
227            ! outputs
228            IF( iom_use('hflx_fwb_cea') )  CALL iom_put( 'hflx_fwb_cea', -zerp_cor(:,:) * rcp * sst_m(:,:) )
229            IF( iom_use('vflx_fwb_cea') )  CALL iom_put( 'vflx_fwb_cea', -zerp_cor(:,:) )
230            !
231            IF( lwp ) THEN                   ! control print
232               IF( z_fwf < 0._wp ) THEN
233                  WRITE(numout,*)'   z_fwf < 0'
234                  WRITE(numout,*)'   SUM(erp+)     = ', SUM( ztmsk_tospread(:,:)*erp(:,:)*e1e2t(:,:) )*1.e-9,' Sv'
235               ELSE
236                  WRITE(numout,*)'   z_fwf >= 0'
237                  WRITE(numout,*)'   SUM(erp-)     = ', SUM( ztmsk_tospread(:,:)*erp(:,:)*e1e2t(:,:) )*1.e-9,' Sv'
238               ENDIF
239               WRITE(numout,*)'   SUM(empG)     = ', SUM( z_fwf*e1e2t(:,:) )*1.e-9,' Sv'
240               WRITE(numout,*)'   z_fwf         = ', z_fwf      ,' Kg/m2/s'
241               WRITE(numout,*)'   z_fwf_nsrf    = ', z_fwf_nsrf ,' Kg/m2/s'
242               WRITE(numout,*)'   MIN(zerp_cor) = ', MINVAL(zerp_cor) 
243               WRITE(numout,*)'   MAX(zerp_cor) = ', MAXVAL(zerp_cor) 
244            ENDIF
245         ENDIF
246         DEALLOCATE( ztmsk_neg , ztmsk_pos , ztmsk_tospread , z_wgt , zerp_cor )
247         !
248      CASE DEFAULT                           !==  you should never be there  ==!
249         CALL ctl_stop( 'sbc_fwb : wrong nn_fwb value for the FreshWater Budget correction, choose either 1, 2 or 3' )
250         !
251      END SELECT
252      !
253   END SUBROUTINE sbc_fwb
254
255   !!======================================================================
256END MODULE sbcfwb
Note: See TracBrowser for help on using the repository browser.