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.
diahsb.F90 in branches/2014/dev_r4650_UKMO2_ice_shelves/NEMOGCM/NEMO/OPA_SRC/DIA – NEMO

source: branches/2014/dev_r4650_UKMO2_ice_shelves/NEMOGCM/NEMO/OPA_SRC/DIA/diahsb.F90 @ 4704

Last change on this file since 4704 was 4704, checked in by mathiot, 10 years ago

Ice Shelf: correction of minor bugs if running without ice shelf

  • Property svn:keywords set to Id
File size: 17.6 KB
Line 
1MODULE diahsb
2   !!======================================================================
3   !!                       ***  MODULE  diahsb  ***
4   !! Ocean diagnostics: Heat, salt and volume budgets
5   !!======================================================================
6   !! History :  3.3  ! 2010-09  (M. Leclair)  Original code
7   !!                 ! 2012-10  (C. Rousset)  add iom_put
8   !!----------------------------------------------------------------------
9
10   !!----------------------------------------------------------------------
11   USE oce             ! ocean dynamics and tracers
12   USE dom_oce         ! ocean space and time domain
13   USE phycst          ! physical constants
14   USE sbc_oce         ! surface thermohaline fluxes
15   USE in_out_manager  ! I/O manager
16   USE domvvl          ! vertical scale factors
17   USE traqsr          ! penetrative solar radiation
18   USE trabbc          ! bottom boundary condition
19   USE lib_mpp         ! distributed memory computing library
20   USE trabbc          ! bottom boundary condition
21   USE bdy_par         ! (for lk_bdy)
22   USE timing          ! preformance summary
23   USE iom             ! I/O manager
24   USE lib_fortran     ! glob_sum
25   USE restart         ! ocean restart
26   USE wrk_nemo        ! work arrays
27   USE sbcrnf          ! river runoff
28   USE sbcisf          ! ice shelves
29
30   IMPLICIT NONE
31   PRIVATE
32
33   PUBLIC   dia_hsb        ! routine called by step.F90
34   PUBLIC   dia_hsb_init   ! routine called by nemogcm.F90
35   PUBLIC   dia_hsb_rst    ! routine called by step.F90
36
37   LOGICAL, PUBLIC ::   ln_diahsb   !: check the heat and salt budgets
38
39   REAL(dp)                                ::   surf_tot                !
40   REAL(dp)                                ::   frc_t      , frc_s     , frc_v   ! global forcing trends
41   REAL(dp)                                ::   frc_wn_t      , frc_wn_s ! global forcing trends
42   REAL(dp), DIMENSION(:,:)  , ALLOCATABLE ::   surf      , ssh_ini              !
43   REAL(dp), DIMENSION(:,:,:), ALLOCATABLE ::   hc_loc_ini, sc_loc_ini, e3t_ini  !
44   REAL(dp), DIMENSION(:,:)  , ALLOCATABLE ::   ssh_hc_loc_ini, ssh_sc_loc_ini
45
46   !! * Substitutions
47#  include "domzgr_substitute.h90"
48#  include "vectopt_loop_substitute.h90"
49
50   !!----------------------------------------------------------------------
51   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
52   !! $Id$
53   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
54   !!----------------------------------------------------------------------
55
56CONTAINS
57
58   SUBROUTINE dia_hsb( kt )
59      !!---------------------------------------------------------------------------
60      !!                  ***  ROUTINE dia_hsb  ***
61      !!     
62      !! ** Purpose: Compute the ocean global heat content, salt content and volume conservation
63      !!
64      !! ** Method : - Compute the deviation of heat content, salt content and volume
65      !!             at the current time step from their values at nit000
66      !!             - Compute the contribution of forcing and remove it from these deviations
67      !!
68      !!---------------------------------------------------------------------------
69      INTEGER, INTENT(in) ::   kt   ! ocean time-step index
70      !!
71      INTEGER    ::   jk                          ! dummy loop indice
72      REAL(dp)   ::   zdiff_hc    , zdiff_sc      ! heat and salt content variations
73      REAL(dp)   ::   zdiff_hc1   , zdiff_sc1     ! -   -   -   -   -   -   -   -
74      REAL(dp)   ::   zdiff_v1    , zdiff_v2      ! volume variation
75      REAL(dp)   ::   zerr_hc1    , zerr_sc1       ! heat and salt content misfit
76      REAL(dp)   ::   zvol_tot                    ! volume
77      REAL(dp)   ::   z_frc_trd_t , z_frc_trd_s   !    -     -
78      REAL(dp)   ::   z_frc_trd_v                 !    -     -
79      REAL(dp)   ::   z_wn_trd_t , z_wn_trd_s   !    -     -
80      REAL(dp)   ::   z_ssh_hc , z_ssh_sc   !    -     -
81      !!---------------------------------------------------------------------------
82      IF( nn_timing == 1 )   CALL timing_start('dia_hsb')     
83
84      ! ------------------------- !
85      ! 1 - Trends due to forcing !
86      ! ------------------------- !
87      z_frc_trd_v = r1_rau0 * glob_sum( - ( emp(:,:) - rnf(:,:) + rdivisf * fwfisf(:,:)) * surf(:,:) ) ! volume fluxes
88      z_frc_trd_t =           glob_sum( sbc_tsc(:,:,jp_tem) * surf(:,:) )       ! heat fluxes
89      z_frc_trd_s =           glob_sum( sbc_tsc(:,:,jp_sal) * surf(:,:) )       ! salt fluxes
90      ! Add runoff heat & salt input
91      IF( ln_rnf    )   z_frc_trd_t = z_frc_trd_t + glob_sum( rnf_tsc(:,:,jp_tem) * surf(:,:) )
92      IF( ln_rnf_sal)   z_frc_trd_s = z_frc_trd_s + glob_sum( rnf_tsc(:,:,jp_sal) * surf(:,:) )
93
94      ! Add penetrative solar radiation
95      IF( ln_traqsr )   z_frc_trd_t = z_frc_trd_t + r1_rau0_rcp * glob_sum( qsr     (:,:) * surf(:,:) )
96      ! Add geothermal heat flux
97      IF( ln_trabbc )   z_frc_trd_t = z_frc_trd_t +               glob_sum( qgh_trd0(:,:) * surf(:,:) )
98      !
99      IF( .NOT. lk_vvl ) THEN
100         z_wn_trd_t = - glob_sum( surf(:,:) * wn(:,:,1) * tsb(:,:,1,jp_tem) )
101         z_wn_trd_s = - glob_sum( surf(:,:) * wn(:,:,1) * tsb(:,:,1,jp_sal) )
102      ENDIF
103
104      frc_v = frc_v + z_frc_trd_v * rdt
105      frc_t = frc_t + z_frc_trd_t * rdt
106      frc_s = frc_s + z_frc_trd_s * rdt
107      !                                          ! Advection flux through fixed surface (z=0)
108      IF( .NOT. lk_vvl ) THEN
109         frc_wn_t = frc_wn_t + z_wn_trd_t * rdt
110         frc_wn_s = frc_wn_s + z_wn_trd_s * rdt
111      ENDIF
112
113      ! ------------------------ !
114      ! 2 -  Content variations !
115      ! ------------------------ !
116      zdiff_v2 = 0.d0
117      zdiff_hc = 0.d0
118      zdiff_sc = 0.d0
119
120      ! volume variation (calculated with ssh)
121      zdiff_v1 = glob_sum( surf(:,:) * ( sshn(:,:) - ssh_ini(:,:) ) )
122
123      ! heat & salt content variation (associated with ssh)
124      IF( .NOT. lk_vvl ) THEN
125         z_ssh_hc = glob_sum( surf(:,:) * ( tsn(:,:,1,jp_tem) * sshn(:,:) - ssh_hc_loc_ini(:,:) ) )
126         z_ssh_sc = glob_sum( surf(:,:) * ( tsn(:,:,1,jp_sal) * sshn(:,:) - ssh_sc_loc_ini(:,:) ) )
127      ENDIF
128
129      DO jk = 1, jpkm1
130         ! volume variation (calculated with scale factors)
131         zdiff_v2 = zdiff_v2 + glob_sum( surf(:,:) * tmask(:,:,jk) &
132            &                           * ( fse3t_n(:,:,jk) - e3t_ini(:,:,jk) ) )
133         ! heat content variation
134         zdiff_hc = zdiff_hc + glob_sum(  surf(:,:) * tmask(:,:,jk) & 
135            &                           * ( fse3t_n(:,:,jk) * tsn(:,:,jk,jp_tem) - hc_loc_ini(:,:,jk) ) )
136         ! salt content variation
137         zdiff_sc = zdiff_sc + glob_sum(  surf(:,:) * tmask(:,:,jk)   &
138            &                           * ( fse3t_n(:,:,jk) * tsn(:,:,jk,jp_sal) - sc_loc_ini(:,:,jk) ) )
139      ENDDO
140
141      ! Substract forcing from heat content, salt content and volume variations
142      zdiff_v1 = zdiff_v1 - frc_v
143      IF( lk_vvl )   zdiff_v2 = zdiff_v2 - frc_v
144      zdiff_hc = zdiff_hc - frc_t
145      zdiff_sc = zdiff_sc - frc_s
146      IF( .NOT. lk_vvl ) THEN
147         zdiff_hc1 = zdiff_hc + z_ssh_hc 
148         zdiff_sc1 = zdiff_sc + z_ssh_sc
149         zerr_hc1  = z_ssh_hc - frc_wn_t
150         zerr_sc1  = z_ssh_sc - frc_wn_s
151      ENDIF
152
153      ! ----------------------- !
154      ! 3 - Diagnostics writing !
155      ! ----------------------- !
156      zvol_tot   = 0.d0                                                   ! total ocean volume
157      DO jk = 1, jpkm1
158         zvol_tot  = zvol_tot + glob_sum( surf(:,:) * tmask(:,:,jk) * fse3t_n(:,:,jk) )
159      END DO
160
161      IF( lk_vvl ) THEN
162        CALL iom_put( 'bgtemper' , zdiff_hc / zvol_tot )              ! Temperature variation (C)
163        CALL iom_put( 'bgsaline' , zdiff_sc / zvol_tot )              ! Salinity    variation (psu)
164        CALL iom_put( 'bgheatco' , zdiff_hc * 1.e-20 * rau0 * rcp )   ! Heat content variation (1.e20 J)
165        CALL iom_put( 'bgsaltco' , zdiff_sc * 1.e-9    )              ! Salt content variation (psu*km3)
166        CALL iom_put( 'bgvolssh' , zdiff_v1 * 1.e-9    )              ! volume ssh variation (km3) 
167        CALL iom_put( 'bgvole3t' , zdiff_v2 * 1.e-9    )              ! volume e3t variation (km3) 
168        CALL iom_put( 'bgfrcvol' , frc_v    * 1.e-9    )              ! vol - surface forcing (km3)
169        CALL iom_put( 'bgfrctem' , frc_t / zvol_tot    )              ! hc  - surface forcing (C)
170        CALL iom_put( 'bgfrcsal' , frc_s / zvol_tot    )              ! sc  - surface forcing (psu)
171      ELSE
172        CALL iom_put( 'bgtemper' , zdiff_hc1 / zvol_tot)              ! Heat content variation (C)
173        CALL iom_put( 'bgsaline' , zdiff_sc1 / zvol_tot)              ! Salt content variation (psu)
174        CALL iom_put( 'bgheatco' , zdiff_hc1 * 1.e-20 * rau0 * rcp )  ! Heat content variation (1.e20 J)
175        CALL iom_put( 'bgsaltco' , zdiff_sc1 * 1.e-9    )             ! Salt content variation (psu*km3)
176        CALL iom_put( 'bgvolssh' , zdiff_v1 * 1.e-9    )              ! volume ssh variation (km3) 
177        CALL iom_put( 'bgfrcvol' , frc_v    * 1.e-9    )              ! vol - surface forcing (km3)
178        CALL iom_put( 'bgfrctem' , frc_t / zvol_tot    )              ! hc  - surface forcing (C)
179        CALL iom_put( 'bgfrcsal' , frc_s / zvol_tot    )              ! sc  - surface forcing (psu)
180        CALL iom_put( 'bgmistem' , zerr_hc1 / zvol_tot )              ! hc  - error due to free surface (C)
181        CALL iom_put( 'bgmissal' , zerr_sc1 / zvol_tot )              ! sc  - error due to free surface (psu)
182      ENDIF
183      !
184      IF( lrst_oce )   CALL dia_hsb_rst( kt, 'WRITE' )
185
186      IF( nn_timing == 1 )   CALL timing_stop('dia_hsb')
187!
188   END SUBROUTINE dia_hsb
189
190
191   SUBROUTINE dia_hsb_init
192      !!---------------------------------------------------------------------------
193      !!                  ***  ROUTINE dia_hsb  ***
194      !!     
195      !! ** Purpose: Initialization for the heat salt volume budgets
196      !!
197      !! ** Method : Compute initial heat content, salt content and volume
198      !!
199      !! ** Action : - Compute initial heat content, salt content and volume
200      !!             - Initialize forcing trends
201      !!             - Compute coefficients for conversion
202      !!---------------------------------------------------------------------------
203      INTEGER            ::   jk       ! dummy loop indice
204      INTEGER            ::   ierror   ! local integer
205      !!
206      NAMELIST/namhsb/ ln_diahsb
207      !
208      INTEGER  ::   ios
209      !!----------------------------------------------------------------------
210
211      IF(lwp) THEN
212         WRITE(numout,*)
213         WRITE(numout,*) 'dia_hsb_init : check the heat and salt budgets'
214         WRITE(numout,*) '~~~~~~~~ '
215      ENDIF
216
217      REWIND( numnam_ref )              ! Namelist namhsb in reference namelist
218      READ  ( numnam_ref, namhsb, IOSTAT = ios, ERR = 901)
219901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namhsb in reference namelist', lwp )
220
221      REWIND( numnam_cfg )              ! Namelist namhsb in configuration namelist
222      READ  ( numnam_cfg, namhsb, IOSTAT = ios, ERR = 902 )
223902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namhsb in configuration namelist', lwp )
224      IF(lwm) WRITE ( numond, namhsb )
225
226      !
227      IF(lwp) THEN                   ! Control print
228         WRITE(numout,*)
229         WRITE(numout,*) 'dia_hsb_init : check the heat and salt budgets'
230         WRITE(numout,*) '~~~~~~~~~~~~'
231         WRITE(numout,*) '   Namelist namhsb : set hsb parameters'
232         WRITE(numout,*) '      Switch for hsb diagnostic (T) or not (F)  ln_diahsb  = ', ln_diahsb
233         WRITE(numout,*)
234      ENDIF
235
236      IF( .NOT. ln_diahsb )   RETURN
237!      IF( .NOT. lk_mpp_rep ) &
238!        CALL ctl_stop (' Your global mpp_sum if performed in single precision - 64 bits -', &
239!             &         ' whereas the global sum to be precise must be done in double precision ',&
240!             &         ' please add key_mpp_rep')
241
242      ! ------------------- !
243      ! 1 - Allocate memory !
244      ! ------------------- !
245      ALLOCATE( hc_loc_ini(jpi,jpj,jpk), sc_loc_ini(jpi,jpj,jpk), &
246         &      e3t_ini(jpi,jpj,jpk), surf(jpi,jpj),  ssh_ini(jpi,jpj), STAT=ierror )
247      IF( ierror > 0 ) THEN
248         CALL ctl_stop( 'dia_hsb: unable to allocate hc_loc_ini' )   ;   RETURN
249      ENDIF
250
251      IF(.NOT. lk_vvl ) ALLOCATE( ssh_hc_loc_ini(jpi,jpj), ssh_sc_loc_ini(jpi,jpj),STAT=ierror )
252      IF( ierror > 0 ) THEN
253         CALL ctl_stop( 'dia_hsb: unable to allocate hc_loc_ini' )   ;   RETURN
254      ENDIF
255
256      ! ----------------------------------------------- !
257      ! 2 - Time independant variables and file opening !
258      ! ----------------------------------------------- !
259      IF(lwp) WRITE(numout,*) "dia_hsb: heat salt volume budgets activated"
260      IF(lwp) WRITE(numout,*) '~~~~~~~'
261      surf(:,:) = e1t(:,:) * e2t(:,:) * tmask_i(:,:)      ! masked surface grid cell area
262      surf_tot  = glob_sum( surf(:,:) )                                       ! total ocean surface area
263
264      IF( lk_bdy ) CALL ctl_warn( 'dia_hsb does not take open boundary fluxes into account' )         
265      !
266      ! ---------------------------------- !
267      ! 4 - initial conservation variables !
268      ! ---------------------------------- !
269      CALL dia_hsb_rst( nit000, 'READ' )  !* read or initialize all required files
270      !
271   END SUBROUTINE dia_hsb_init
272
273   SUBROUTINE dia_hsb_rst( kt, cdrw )
274     !!---------------------------------------------------------------------
275     !!                   ***  ROUTINE limdia_rst  ***
276     !!                     
277     !! ** Purpose :   Read or write DIA file in restart file
278     !!
279     !! ** Method  :   use of IOM library
280     !!----------------------------------------------------------------------
281     INTEGER         , INTENT(in) ::   kt     ! ocean time-step
282     CHARACTER(len=*), INTENT(in) ::   cdrw   ! "READ"/"WRITE" flag
283     !
284     INTEGER ::   jk   !
285     INTEGER ::   id1   ! local integers
286     !!----------------------------------------------------------------------
287     !
288     IF( TRIM(cdrw) == 'READ' ) THEN        ! Read/initialise
289        IF( ln_rstart ) THEN                   !* Read the restart file
290           !id1 = iom_varid( numror, 'frc_vol'  , ldstop = .FALSE. )
291           !
292           IF(lwp) WRITE(numout,*) '~~~~~~~'
293           IF(lwp) WRITE(numout,*) ' dia_hsb_rst at it= ', kt,' date= ', ndastp
294           IF(lwp) WRITE(numout,*) '~~~~~~~'
295           CALL iom_get( numror, 'frc_v', frc_v )
296           CALL iom_get( numror, 'frc_t', frc_t )
297           CALL iom_get( numror, 'frc_s', frc_s )
298           IF( .NOT. lk_vvl ) THEN
299              CALL iom_get( numror, 'frc_wn_t', frc_wn_t )
300              CALL iom_get( numror, 'frc_wn_s', frc_wn_s )
301           ENDIF
302           CALL iom_get( numror, jpdom_autoglo, 'ssh_ini', ssh_ini )
303           CALL iom_get( numror, jpdom_autoglo, 'e3t_ini', e3t_ini )
304           CALL iom_get( numror, jpdom_autoglo, 'hc_loc_ini', hc_loc_ini )
305           CALL iom_get( numror, jpdom_autoglo, 'sc_loc_ini', sc_loc_ini )
306           IF( .NOT. lk_vvl ) THEN
307              CALL iom_get( numror, jpdom_autoglo, 'ssh_hc_loc_ini', ssh_hc_loc_ini )
308              CALL iom_get( numror, jpdom_autoglo, 'ssh_sc_loc_ini', ssh_sc_loc_ini )
309           ENDIF
310       ELSE
311          IF(lwp) WRITE(numout,*) '~~~~~~~'
312          IF(lwp) WRITE(numout,*) ' dia_hsb at initial state '
313          IF(lwp) WRITE(numout,*) '~~~~~~~'
314          ssh_ini(:,:) = sshn(:,:)                                       ! initial ssh
315          DO jk = 1, jpk
316             e3t_ini   (:,:,jk) = fse3t_n(:,:,jk)                        ! initial vertical scale factors
317             hc_loc_ini(:,:,jk) = tsn(:,:,jk,jp_tem) * fse3t_n(:,:,jk)   ! initial heat content
318             sc_loc_ini(:,:,jk) = tsn(:,:,jk,jp_sal) * fse3t_n(:,:,jk)   ! initial salt content
319          END DO
320          frc_v = 0.d0                                           ! volume       trend due to forcing
321          frc_t = 0.d0                                           ! heat content   -    -   -    -   
322          frc_s = 0.d0                                           ! salt content   -    -   -    -       
323          IF( .NOT. lk_vvl ) THEN
324             ssh_hc_loc_ini(:,:) = tsn(:,:,1,jp_tem) * sshn(:,:)   ! initial heat content in ssh
325             ssh_sc_loc_ini(:,:) = tsn(:,:,1,jp_sal) * sshn(:,:)   ! initial salt content in ssh
326             frc_wn_t = 0.d0                                       ! initial heat content misfit due to free surface
327             frc_wn_s = 0.d0                                       ! initial salt content misfit due to free surface
328          ENDIF
329       ENDIF
330
331     ELSEIF( TRIM(cdrw) == 'WRITE' ) THEN   ! Create restart file
332        !                                   ! -------------------
333        IF(lwp) WRITE(numout,*) '~~~~~~~'
334        IF(lwp) WRITE(numout,*) ' dia_hsb_rst at it= ', kt,' date= ', ndastp
335        IF(lwp) WRITE(numout,*) '~~~~~~~'
336
337        CALL iom_rstput( kt, nitrst, numrow, 'frc_v'   , frc_v     )
338        CALL iom_rstput( kt, nitrst, numrow, 'frc_t'   , frc_t     )
339        CALL iom_rstput( kt, nitrst, numrow, 'frc_s'   , frc_s     )
340        IF( .NOT. lk_vvl ) THEN
341           CALL iom_rstput( kt, nitrst, numrow, 'frc_wn_t', frc_wn_t )
342           CALL iom_rstput( kt, nitrst, numrow, 'frc_wn_s', frc_wn_s )
343        ENDIF
344        CALL iom_rstput( kt, nitrst, numrow, 'ssh_ini', ssh_ini )
345        CALL iom_rstput( kt, nitrst, numrow, 'e3t_ini', e3t_ini )
346        CALL iom_rstput( kt, nitrst, numrow, 'hc_loc_ini', hc_loc_ini )
347        CALL iom_rstput( kt, nitrst, numrow, 'sc_loc_ini', sc_loc_ini )
348        IF( .NOT. lk_vvl ) THEN
349           CALL iom_rstput( kt, nitrst, numrow, 'ssh_hc_loc_ini', ssh_hc_loc_ini )
350           CALL iom_rstput( kt, nitrst, numrow, 'ssh_sc_loc_ini', ssh_sc_loc_ini )
351        ENDIF
352        !
353     ENDIF
354     !
355   END SUBROUTINE dia_hsb_rst
356
357   !!======================================================================
358END MODULE diahsb
Note: See TracBrowser for help on using the repository browser.