limcons.F90 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. MODULE limcons
  2. !!======================================================================
  3. !! *** MODULE limcons ***
  4. !! LIM-3 Sea Ice : conservation check
  5. !!======================================================================
  6. !! History : - ! Original code from William H. Lipscomb, LANL
  7. !! 3.0 ! 2004-06 (M. Vancoppenolle) Energy Conservation
  8. !! 3.5 ! 2011-02 (G. Madec) add mpp considerations
  9. !! - ! 2014-05 (C. Rousset) add lim_cons_hsm
  10. !! - ! 2015-03 (C. Rousset) add lim_cons_final
  11. !!----------------------------------------------------------------------
  12. #if defined key_lim3
  13. !!----------------------------------------------------------------------
  14. !! 'key_lim3' LIM-3 sea-ice model
  15. !!----------------------------------------------------------------------
  16. !! lim_cons : checks whether energy, mass and salt are conserved
  17. !!----------------------------------------------------------------------
  18. USE phycst ! physical constants
  19. USE ice ! LIM-3 variables
  20. USE dom_ice ! LIM-3 domain
  21. USE dom_oce ! ocean domain
  22. USE in_out_manager ! I/O manager
  23. USE lib_mpp ! MPP library
  24. USE lib_fortran ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)
  25. USE sbc_oce , ONLY : sfx ! Surface boundary condition: ocean fields
  26. USE sbc_ice , ONLY : qevap_ice
  27. IMPLICIT NONE
  28. PRIVATE
  29. PUBLIC lim_column_sum
  30. PUBLIC lim_column_sum_energy
  31. PUBLIC lim_cons_check
  32. PUBLIC lim_cons_hsm
  33. PUBLIC lim_cons_final
  34. !!----------------------------------------------------------------------
  35. !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
  36. !! $Id: limcons.F90 8150 2017-06-07 14:37:36Z vancop $
  37. !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
  38. !!----------------------------------------------------------------------
  39. CONTAINS
  40. SUBROUTINE lim_column_sum( ksum, pin, pout )
  41. !!-------------------------------------------------------------------
  42. !! *** ROUTINE lim_column_sum ***
  43. !!
  44. !! ** Purpose : Compute the sum of xin over nsum categories
  45. !!
  46. !! ** Method : Arithmetics
  47. !!
  48. !! ** Action : Gets xin(ji,jj,jl) and computes xout(ji,jj)
  49. !!---------------------------------------------------------------------
  50. INTEGER , INTENT(in ) :: ksum ! number of categories/layers
  51. REAL(wp), DIMENSION(:,:,:), INTENT(in ) :: pin ! input field
  52. REAL(wp), DIMENSION(:,:) , INTENT( out) :: pout ! output field
  53. !
  54. INTEGER :: jl ! dummy loop indices
  55. !!---------------------------------------------------------------------
  56. !
  57. pout(:,:) = pin(:,:,1)
  58. DO jl = 2, ksum
  59. pout(:,:) = pout(:,:) + pin(:,:,jl)
  60. END DO
  61. !
  62. END SUBROUTINE lim_column_sum
  63. SUBROUTINE lim_column_sum_energy( ksum, klay, pin, pout)
  64. !!-------------------------------------------------------------------
  65. !! *** ROUTINE lim_column_sum_energy ***
  66. !!
  67. !! ** Purpose : Compute the sum of xin over nsum categories
  68. !! and nlay layers
  69. !!
  70. !! ** Method : Arithmetics
  71. !!---------------------------------------------------------------------
  72. INTEGER , INTENT(in ) :: ksum !: number of categories
  73. INTEGER , INTENT(in ) :: klay !: number of vertical layers
  74. REAL(wp), DIMENSION(jpi,jpj,nlay_i,jpl), INTENT(in ) :: pin !: input field
  75. REAL(wp), DIMENSION(jpi,jpj) , INTENT( out) :: pout !: output field
  76. !
  77. INTEGER :: jk, jl ! dummy loop indices
  78. !!---------------------------------------------------------------------
  79. !
  80. pout(:,:) = 0._wp
  81. DO jl = 1, ksum
  82. DO jk = 2, klay
  83. pout(:,:) = pout(:,:) + pin(:,:,jk,jl)
  84. END DO
  85. END DO
  86. !
  87. END SUBROUTINE lim_column_sum_energy
  88. SUBROUTINE lim_cons_check( px1, px2, pmax_err, cd_fieldid )
  89. !!-------------------------------------------------------------------
  90. !! *** ROUTINE lim_cons_check ***
  91. !!
  92. !! ** Purpose : Test the conservation of a certain variable
  93. !! For each physical grid cell, check that initial
  94. !! and final values
  95. !! of a conserved field are equal to within a small value.
  96. !!
  97. !! ** Method :
  98. !!---------------------------------------------------------------------
  99. REAL(wp), DIMENSION(:,:), INTENT(in ) :: px1 !: initial field
  100. REAL(wp), DIMENSION(:,:), INTENT(in ) :: px2 !: final field
  101. REAL(wp) , INTENT(in ) :: pmax_err !: max allowed error
  102. CHARACTER(len=15) , INTENT(in ) :: cd_fieldid !: field identifyer
  103. !
  104. INTEGER :: ji, jj ! dummy loop indices
  105. INTEGER :: inb_error ! number of g.c where there is a cons. error
  106. LOGICAL :: llconserv_err ! = .true. if conservation check failed
  107. REAL(wp) :: zmean_error ! mean error on error points
  108. !!---------------------------------------------------------------------
  109. !
  110. IF(lwp) WRITE(numout,*) ' lim_cons_check '
  111. IF(lwp) WRITE(numout,*) ' ~~~~~~~~~~~~~~ '
  112. llconserv_err = .FALSE.
  113. inb_error = 0
  114. zmean_error = 0._wp
  115. IF( MAXVAL( px2(:,:) - px1(:,:) ) > pmax_err ) llconserv_err = .TRUE.
  116. IF( llconserv_err ) THEN
  117. DO jj = 1, jpj
  118. DO ji = 1, jpi
  119. IF( ABS( px2(ji,jj) - px1(ji,jj) ) > pmax_err ) THEN
  120. inb_error = inb_error + 1
  121. zmean_error = zmean_error + ABS( px2(ji,jj) - px1(ji,jj) )
  122. !
  123. IF(lwp) THEN
  124. WRITE (numout,*) ' ALERTE 99 '
  125. WRITE (numout,*) ' Conservation error: ', cd_fieldid
  126. WRITE (numout,*) ' Point : ', ji, jj
  127. WRITE (numout,*) ' lat, lon : ', gphit(ji,jj), glamt(ji,jj)
  128. WRITE (numout,*) ' Initial value : ', px1(ji,jj)
  129. WRITE (numout,*) ' Final value : ', px2(ji,jj)
  130. WRITE (numout,*) ' Difference : ', px2(ji,jj) - px1(ji,jj)
  131. ENDIF
  132. ENDIF
  133. END DO
  134. END DO
  135. !
  136. ENDIF
  137. IF(lk_mpp) CALL mpp_sum( inb_error )
  138. IF(lk_mpp) CALL mpp_sum( zmean_error )
  139. !
  140. IF( inb_error > 0 .AND. lwp ) THEN
  141. zmean_error = zmean_error / REAL( inb_error, wp )
  142. WRITE(numout,*) ' Conservation check for : ', cd_fieldid
  143. WRITE(numout,*) ' Number of error points : ', inb_error
  144. WRITE(numout,*) ' Mean error on these pts: ', zmean_error
  145. ENDIF
  146. !
  147. END SUBROUTINE lim_cons_check
  148. SUBROUTINE lim_cons_hsm( icount, cd_routine, zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b )
  149. !!--------------------------------------------------------------------------------------------------------
  150. !! *** ROUTINE lim_cons_hsm ***
  151. !!
  152. !! ** Purpose : Test the conservation of heat, salt and mass for each ice routine
  153. !! + test if ice concentration and volume are > 0
  154. !!
  155. !! ** Method : This is an online diagnostics which can be activated with ln_limdiahsb=true
  156. !! It prints in ocean.output if there is a violation of conservation at each time-step
  157. !! The thresholds (zv_sill, zs_sill, zh_sill) which determine violations are set to
  158. !! a minimum of 1 mm of ice (over the ice area) that is lost/gained spuriously during 100 years.
  159. !! For salt and heat thresholds, ice is considered to have a salinity of 10
  160. !! and a heat content of 3e5 J/kg (=latent heat of fusion)
  161. !!--------------------------------------------------------------------------------------------------------
  162. INTEGER , INTENT(in) :: icount ! determine wether this is the beggining of the routine (0) or the end (1)
  163. CHARACTER(len=*), INTENT(in) :: cd_routine ! name of the routine
  164. REAL(wp) , INTENT(inout) :: zvi_b, zsmv_b, zei_b, zfs_b, zfw_b, zft_b
  165. REAL(wp) :: zvi, zsmv, zei, zfs, zfw, zft
  166. REAL(wp) :: zvmin, zamin, zamax
  167. REAL(wp) :: zvtrp, zetrp
  168. REAL(wp) :: zarea, zv_sill, zs_sill, zh_sill
  169. REAL(wp), PARAMETER :: zconv = 1.e-9 ! convert W to GW and kg to Mt
  170. IF( icount == 0 ) THEN
  171. ! salt flux
  172. zfs_b = glob_sum( ( sfx_bri(:,:) + sfx_bog(:,:) + sfx_bom(:,:) + sfx_sum(:,:) + sfx_sni(:,:) + &
  173. & sfx_opw(:,:) + sfx_res(:,:) + sfx_dyn(:,:) + sfx_sub(:,:) &
  174. & ) * e12t(:,:) * tmask(:,:,1) * zconv )
  175. ! water flux
  176. zfw_b = glob_sum( -( wfx_bog(:,:) + wfx_bom(:,:) + wfx_sum(:,:) + wfx_sni(:,:) + wfx_opw(:,:) + &
  177. & wfx_res(:,:) + wfx_dyn(:,:) + wfx_snw(:,:) + &
  178. & wfx_sub(:,:) + wfx_spr(:,:) &
  179. & ) * e12t(:,:) * tmask(:,:,1) * zconv )
  180. ! heat flux
  181. zft_b = glob_sum( ( hfx_sum(:,:) + hfx_bom(:,:) + hfx_bog(:,:) + hfx_dif(:,:) + hfx_opw(:,:) + hfx_snw(:,:) &
  182. & - hfx_thd(:,:) - hfx_dyn(:,:) - hfx_res(:,:) - hfx_sub(:,:) - hfx_spr(:,:) &
  183. & ) * e12t(:,:) * tmask(:,:,1) * zconv )
  184. zvi_b = glob_sum( SUM( v_i * rhoic + v_s * rhosn, dim=3 ) * e12t * tmask(:,:,1) * zconv )
  185. zsmv_b = glob_sum( SUM( smv_i * rhoic , dim=3 ) * e12t * tmask(:,:,1) * zconv )
  186. zei_b = glob_sum( ( SUM( SUM( e_i(:,:,1:nlay_i,:), dim=4 ), dim=3 ) + &
  187. & SUM( SUM( e_s(:,:,1:nlay_s,:), dim=4 ), dim=3 ) &
  188. ) * e12t * tmask(:,:,1) * zconv )
  189. ELSEIF( icount == 1 ) THEN
  190. ! salt flux
  191. zfs = glob_sum( ( sfx_bri(:,:) + sfx_bog(:,:) + sfx_bom(:,:) + sfx_sum(:,:) + sfx_sni(:,:) + &
  192. & sfx_opw(:,:) + sfx_res(:,:) + sfx_dyn(:,:) + sfx_sub(:,:) &
  193. & ) * e12t(:,:) * tmask(:,:,1) * zconv ) - zfs_b
  194. ! water flux
  195. zfw = glob_sum( -( wfx_bog(:,:) + wfx_bom(:,:) + wfx_sum(:,:) + wfx_sni(:,:) + wfx_opw(:,:) + &
  196. & wfx_res(:,:) + wfx_dyn(:,:) + wfx_snw(:,:) + &
  197. & wfx_sub(:,:) + wfx_spr(:,:) &
  198. & ) * e12t(:,:) * tmask(:,:,1) * zconv ) - zfw_b
  199. ! heat flux
  200. zft = glob_sum( ( hfx_sum(:,:) + hfx_bom(:,:) + hfx_bog(:,:) + hfx_dif(:,:) + hfx_opw(:,:) + hfx_snw(:,:) &
  201. & - hfx_thd(:,:) - hfx_dyn(:,:) - hfx_res(:,:) - hfx_sub(:,:) - hfx_spr(:,:) &
  202. & ) * e12t(:,:) * tmask(:,:,1) * zconv ) - zft_b
  203. ! outputs
  204. zvi = ( ( glob_sum( SUM( v_i * rhoic + v_s * rhosn, dim=3 ) &
  205. & * e12t * tmask(:,:,1) * zconv ) - zvi_b ) * r1_rdtice - zfw ) * rday
  206. zsmv = ( ( glob_sum( SUM( smv_i * rhoic , dim=3 ) &
  207. & * e12t * tmask(:,:,1) * zconv ) - zsmv_b ) * r1_rdtice + zfs ) * rday
  208. zei = glob_sum( ( SUM( SUM( e_i(:,:,1:nlay_i,:), dim=4 ), dim=3 ) + &
  209. & SUM( SUM( e_s(:,:,1:nlay_s,:), dim=4 ), dim=3 ) &
  210. & ) * e12t * tmask(:,:,1) * zconv ) * r1_rdtice - zei_b * r1_rdtice + zft
  211. ! zvtrp and zetrp must be close to 0 if the advection scheme is conservative
  212. zvtrp = glob_sum( ( diag_trp_vi * rhoic + diag_trp_vs * rhosn ) * e12t * tmask(:,:,1) * zconv ) * rday
  213. zetrp = glob_sum( ( diag_trp_ei + diag_trp_es ) * e12t * tmask(:,:,1) * zconv )
  214. zvmin = glob_min( v_i )
  215. zamax = glob_max( SUM( a_i, dim=3 ) )
  216. zamin = glob_min( a_i )
  217. ! set threshold values and calculate the ice area (+epsi10 to set a threshold > 0 when there is no ice)
  218. zarea = glob_sum( SUM( a_i + epsi10, dim=3 ) * e12t * zconv ) ! in 1.e9 m2
  219. zv_sill = zarea * 2.5e-5
  220. zs_sill = zarea * 25.e-5
  221. zh_sill = zarea * 10.e-5
  222. IF(lwp) THEN
  223. IF ( ABS( zvi ) > zv_sill ) WRITE(numout,*) 'violation volume [Mt/day] (',cd_routine,') = ',zvi
  224. IF ( ABS( zsmv ) > zs_sill ) WRITE(numout,*) 'violation saline [psu*Mt/day] (',cd_routine,') = ',zsmv
  225. IF ( ABS( zei ) > zh_sill ) WRITE(numout,*) 'violation enthalpy [GW] (',cd_routine,') = ',zei
  226. IF ( ABS(zvtrp ) > zv_sill .AND. cd_routine == 'limtrp' ) THEN
  227. WRITE(numout,*) 'violation vtrp [Mt/day] (',cd_routine,') = ',zvtrp
  228. WRITE(numout,*) 'violation etrp [GW] (',cd_routine,') = ',zetrp
  229. ENDIF
  230. IF ( zvmin < -epsi10 ) WRITE(numout,*) 'violation v_i<0 [m] (',cd_routine,') = ',zvmin
  231. IF ( zamax > MAX( rn_amax_n, rn_amax_s ) + epsi10 .AND. &
  232. & cd_routine /= 'limtrp' .AND. cd_routine /= 'limitd_me' ) THEN
  233. WRITE(numout,*) 'violation a_i>amax (',cd_routine,') = ',zamax
  234. ENDIF
  235. IF ( zamin < -epsi10 ) WRITE(numout,*) 'violation a_i<0 (',cd_routine,') = ',zamin
  236. ENDIF
  237. ENDIF
  238. END SUBROUTINE lim_cons_hsm
  239. SUBROUTINE lim_cons_final( cd_routine )
  240. !!---------------------------------------------------------------------------------------------------------
  241. !! *** ROUTINE lim_cons_final ***
  242. !!
  243. !! ** Purpose : Test the conservation of heat, salt and mass at the end of each ice time-step
  244. !!
  245. !! ** Method : This is an online diagnostics which can be activated with ln_limdiahsb=true
  246. !! It prints in ocean.output if there is a violation of conservation at each time-step
  247. !! The thresholds (zv_sill, zs_sill, zh_sill) which determine the violation are set to
  248. !! a minimum of 1 mm of ice (over the ice area) that is lost/gained spuriously during 100 years.
  249. !! For salt and heat thresholds, ice is considered to have a salinity of 10
  250. !! and a heat content of 3e5 J/kg (=latent heat of fusion)
  251. !!--------------------------------------------------------------------------------------------------------
  252. CHARACTER(len=*), INTENT(in) :: cd_routine ! name of the routine
  253. REAL(wp) :: zhfx, zsfx, zvfx
  254. REAL(wp) :: zarea, zv_sill, zs_sill, zh_sill
  255. REAL(wp), PARAMETER :: zconv = 1.e-9 ! convert W to GW and kg to Mt
  256. #if ! defined key_bdy
  257. ! heat flux
  258. zhfx = glob_sum( ( hfx_in - hfx_out - diag_heat - diag_trp_ei - diag_trp_es &
  259. ! & - SUM( qevap_ice * a_i_b, dim=3 ) & !!clem: I think this line must be commented (but need check)
  260. & ) * e12t * tmask(:,:,1) * zconv )
  261. ! salt flux
  262. zsfx = glob_sum( ( sfx + diag_smvi ) * e12t * tmask(:,:,1) * zconv ) * rday
  263. ! water flux
  264. zvfx = glob_sum( ( wfx_ice + wfx_snw + wfx_spr + wfx_sub + diag_vice + diag_vsnw ) * e12t * tmask(:,:,1) * zconv ) * rday
  265. ! set threshold values and calculate the ice area (+epsi10 to set a threshold > 0 when there is no ice)
  266. zarea = glob_sum( SUM( a_i + epsi10, dim=3 ) * e12t * zconv ) ! in 1.e9 m2
  267. zv_sill = zarea * 2.5e-5
  268. zs_sill = zarea * 25.e-5
  269. zh_sill = zarea * 10.e-5
  270. IF( ABS( zvfx ) > zv_sill ) WRITE(numout,*) 'violation vfx [Mt/day] (',cd_routine,') = ',(zvfx)
  271. IF( ABS( zsfx ) > zs_sill ) WRITE(numout,*) 'violation sfx [psu*Mt/day] (',cd_routine,') = ',(zsfx)
  272. IF( ABS( zhfx ) > zh_sill ) WRITE(numout,*) 'violation hfx [GW] (',cd_routine,') = ',(zhfx)
  273. #endif
  274. END SUBROUTINE lim_cons_final
  275. #else
  276. !!----------------------------------------------------------------------
  277. !! Default option Empty module NO LIM sea-ice model
  278. !!----------------------------------------------------------------------
  279. #endif
  280. !!======================================================================
  281. END MODULE limcons