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.
limcons.F90 in branches/UKMO/dev_1d_bugfixes_tocommit/NEMOGCM/NEMO/LIM_SRC_3 – NEMO

source: branches/UKMO/dev_1d_bugfixes_tocommit/NEMOGCM/NEMO/LIM_SRC_3/limcons.F90 @ 13354

Last change on this file since 13354 was 6498, checked in by timgraham, 8 years ago

Merge head of nemo_v3_6_STABLE into package branch

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