sbcfwb.F90 15 KB

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