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/2013/dev_LOCEAN_2013/NEMOGCM/NEMO/OPA_SRC/DIA – NEMO

source: branches/2013/dev_LOCEAN_2013/NEMOGCM/NEMO/OPA_SRC/DIA/diahsb.F90 @ 4205

Last change on this file since 4205 was 4205, checked in by clem, 10 years ago
  • Property svn:keywords set to Id
File size: 15.3 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 obc_par         ! (for lk_obc)
22   USE bdy_par         ! (for lk_bdy)
23   USE timing          ! preformance summary
24   USE iom             ! I/O manager
25   USE lib_fortran     ! glob_sum
26   USE restart         ! ocean restart
27   USE wrk_nemo         ! work arrays
28   USE sbcrnf         ! river runoffd
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), SAVE                                ::   frc_t      , frc_s     , frc_v   ! global forcing trends
40   REAL(dp), ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   ssh_ini              !
41   REAL(dp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   hc_loc_ini, sc_loc_ini, e3t_ini  !
42   REAL(dp), ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   hcssh_loc_ini, scssh_loc_ini     !
43
44   !! * Substitutions
45#  include "domzgr_substitute.h90"
46#  include "vectopt_loop_substitute.h90"
47
48   !!----------------------------------------------------------------------
49   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
50   !! $Id$
51   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
52   !!----------------------------------------------------------------------
53
54CONTAINS
55
56   SUBROUTINE dia_hsb( kt )
57      !!---------------------------------------------------------------------------
58      !!                  ***  ROUTINE dia_hsb  ***
59      !!     
60      !! ** Purpose: Compute the ocean global heat content, salt content and volume conservation
61      !!
62      !! ** Method : - Compute the deviation of heat content, salt content and volume
63      !!             at the current time step from their values at nit000
64      !!             - Compute the contribution of forcing and remove it from these deviations
65      !!
66      !!---------------------------------------------------------------------------
67      INTEGER, INTENT(in) ::   kt   ! ocean time-step index
68      !!
69      INTEGER    ::   jk                          ! dummy loop indice
70      REAL(dp)   ::   zdiff_hc    , zdiff_sc      ! heat and salt content variations
71      REAL(dp)   ::   zdiff_v1    , zdiff_v2      ! volume variation
72      REAL(dp)   ::   z_hc        , z_sc          ! heat and salt content
73      REAL(dp)   ::   z_v1        , z_v2          ! volume
74      REAL(dp)   ::   zdeltat                     !    -     -
75      REAL(dp)   ::   z_frc_trd_t , z_frc_trd_s   !    -     -
76      REAL(dp)   ::   z_frc_trd_v                 !    -     -
77      REAL(dp), POINTER, DIMENSION(:,:)   ::   zsurf              !
78      !!---------------------------------------------------------------------------
79      IF( nn_timing == 1 )   CALL timing_start('dia_hsb')     
80
81      CALL wrk_alloc( jpi, jpj, zsurf )
82 
83      zsurf(:,:) = e1t(:,:) * e2t(:,:) * tmask(:,:,1) * tmask_i(:,:)      ! masked surface grid cell area
84     
85      ! ------------------------- !
86      ! 1 - Trends due to forcing !
87      ! ------------------------- !
88      z_frc_trd_v = r1_rau0 * glob_sum( - ( emp(:,:) - rnf(:,:) ) * zsurf(:,:) ) ! volume fluxes
89      z_frc_trd_t =           glob_sum( sbc_tsc(:,:,jp_tem) * zsurf(:,:) )       ! heat fluxes
90      z_frc_trd_s =           glob_sum( sbc_tsc(:,:,jp_sal) * zsurf(:,:) )       ! salt fluxes
91      !
92      IF( ln_rnf    )   z_frc_trd_t = z_frc_trd_t + glob_sum( rnf_tsc(:,:,jp_tem) * zsurf(:,:) )
93      IF( ln_rnf_sal)   z_frc_trd_s = z_frc_trd_s + glob_sum( rnf_tsc(:,:,jp_sal) * zsurf(:,:) )
94
95      ! Add penetrative solar radiation
96      IF( ln_traqsr )   z_frc_trd_t = z_frc_trd_t + r1_rau0_rcp * glob_sum( qsr     (:,:) * zsurf(:,:) )
97      ! Add geothermal heat flux
98      IF( ln_trabbc )   z_frc_trd_t = z_frc_trd_t +               glob_sum( qgh_trd0(:,:) * zsurf(:,:) )
99      !
100      frc_v = frc_v + z_frc_trd_v * rdt
101      frc_t = frc_t + z_frc_trd_t * rdt
102      frc_s = frc_s + z_frc_trd_s * rdt
103
104      ! ------------------------ !
105      ! 2a -  Content variations !
106      ! ------------------------ !
107      zdiff_v2 = 0._dp
108      zdiff_hc = 0._dp
109      zdiff_sc = 0._dp
110      ! volume variation (calculated with ssh)
111      zdiff_v1 = glob_sum( zsurf(:,:) * ( sshn(:,:) - ssh_ini(:,:) ) )
112      DO jk = 1, jpkm1
113         ! volume variation (calculated with scale factors)
114         zdiff_v2 = zdiff_v2 + glob_sum( zsurf(:,:) * tmask(:,:,jk) * ( fse3t_n(:,:,jk) - e3t_ini(:,:,jk) ) )
115         ! heat content variation
116         zdiff_hc = zdiff_hc + glob_sum( zsurf(:,:) * tmask(:,:,jk) * ( fse3t_n(:,:,jk) * tsn(:,:,jk,jp_tem)   &
117            &                           - hc_loc_ini(:,:,jk) ) )
118         ! salt content variation
119         zdiff_sc = zdiff_sc + glob_sum( zsurf(:,:) * tmask(:,:,jk) * ( fse3t_n(:,:,jk) * tsn(:,:,jk,jp_sal)   &
120            &                           - sc_loc_ini(:,:,jk) ) )
121      ENDDO
122
123      ! Substract forcing from heat content, salt content and volume variations
124      !frc_v = zdiff_v2 - frc_v
125      !frc_t = zdiff_hc - frc_t
126      !frc_s = zdiff_sc - frc_s
127     
128      ! add ssh if not vvl
129      IF( .NOT. lk_vvl ) THEN
130        zdiff_v2 = zdiff_v2 + zdiff_v1
131        zdiff_hc = zdiff_hc + glob_sum( zsurf(:,:) * ( sshn(:,:) * tsn(:,:,1,jp_tem)   &
132               &                           - hcssh_loc_ini(:,:) ) )
133        zdiff_sc = zdiff_sc + glob_sum( zsurf(:,:) * ( sshn(:,:) * tsn(:,:,1,jp_sal)   &
134               &                           - scssh_loc_ini(:,:) ) )
135      ENDIF
136      !
137      ! ----------------------- !
138      ! 2b -  Content           !
139      ! ----------------------- !
140      z_v2 = 0._dp
141      z_hc = 0._dp
142      z_sc = 0._dp
143      ! volume (calculated with ssh)
144      z_v1 = glob_sum( zsurf(:,:) * sshn(:,:) )
145      DO jk = 1, jpkm1
146         ! volume (calculated with scale factors)
147         z_v2 = z_v2 + glob_sum( zsurf(:,:) * tmask(:,:,jk) * fse3t_n(:,:,jk) )
148         ! heat content
149         z_hc = z_hc + glob_sum( zsurf(:,:) * tmask(:,:,jk) * fse3t_n(:,:,jk) * tsn(:,:,jk,jp_tem) )
150         ! salt content
151         z_sc = z_sc + glob_sum( zsurf(:,:) * tmask(:,:,jk) * fse3t_n(:,:,jk) * tsn(:,:,jk,jp_sal) )
152      ENDDO
153      ! add ssh if not vvl
154      IF( .NOT. lk_vvl ) THEN
155        z_v2 = z_v2 + z_v1
156        z_hc = z_hc + glob_sum( zsurf(:,:) * sshn(:,:) * tsn(:,:,1,jp_tem) )
157        z_sc = z_sc + glob_sum( zsurf(:,:) * sshn(:,:) * tsn(:,:,1,jp_sal) )
158      ENDIF
159
160      ! ----------------------- !
161      ! 3 - Diagnostics writing !
162      ! ----------------------- !
163      zdeltat  = 1.e0 / ( ( kt - nit000 + 1 ) * rdt )
164!
165      CALL iom_put( 'bgtemper' , z_hc / z_v2 )                      ! Temperature (C)
166      CALL iom_put( 'bgsaline' , z_sc / z_v2 )                      ! Salinity (psu)
167      CALL iom_put( 'bgheatco' , zdiff_hc * rau0 * rcp * 1.e-9_dp ) ! Heat content variation (10^9 J)
168      CALL iom_put( 'bgsaltco' , zdiff_sc * 1.e-9 )                 ! Salt content variation (psu*km3)
169      CALL iom_put( 'bgvolssh' , zdiff_v1 * 1.e-9 )                    ! volume ssh (km3) 
170      CALL iom_put( 'bgsshtot' , zdiff_v1 / glob_sum(zsurf) )          ! ssh (m) 
171      CALL iom_put( 'bgvoltot' , zdiff_v2 * 1.e-9 )                 ! volume total (km3)
172      CALL iom_put( 'bgfrcvol' , frc_v * 1.e-9 )                     ! vol - surface forcing (volume)
173      CALL iom_put( 'bgfrctem' , frc_t * rau0 * rcp * 1.e-9_dp ) ! hc  - surface forcing (heat content)
174      CALL iom_put( 'bgfrcsal' , frc_s * 1.e-9 )                     ! sc  - surface forcing (salt content)
175      !
176      CALL wrk_dealloc( jpi, jpj, zsurf )
177      !
178      IF( nn_timing == 1 )   CALL timing_stop('dia_hsb')
179!
180   END SUBROUTINE dia_hsb
181
182
183   SUBROUTINE dia_hsb_init
184      !!---------------------------------------------------------------------------
185      !!                  ***  ROUTINE dia_hsb  ***
186      !!     
187      !! ** Purpose: Initialization for the heat salt volume budgets
188      !!
189      !! ** Method : Compute initial heat content, salt content and volume
190      !!
191      !! ** Action : - Compute initial heat content, salt content and volume
192      !!             - Initialize forcing trends
193      !!             - Compute coefficients for conversion
194      !!---------------------------------------------------------------------------
195      INTEGER            ::   jk       ! dummy loop indice
196      INTEGER            ::   ierror   ! local integer
197      !!
198      NAMELIST/namhsb/ ln_diahsb
199      !
200      INTEGER  ::   ios
201      !!----------------------------------------------------------------------
202
203      IF(lwp) THEN
204         WRITE(numout,*)
205         WRITE(numout,*) 'dia_hsb_init : check the heat and salt budgets'
206         WRITE(numout,*) '~~~~~~~~ '
207      ENDIF
208
209      REWIND( numnam_ref )              ! Namelist namhsb in reference namelist
210      READ  ( numnam_ref, namhsb, IOSTAT = ios, ERR = 901)
211901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namhsb in reference namelist', lwp )
212
213      REWIND( numnam_cfg )              ! Namelist namhsb in configuration namelist
214      READ  ( numnam_cfg, namhsb, IOSTAT = ios, ERR = 902 )
215902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namhsb in configuration namelist', lwp )
216      WRITE ( numond, namhsb )
217
218      !
219      IF(lwp) THEN                   ! Control print
220         WRITE(numout,*)
221         WRITE(numout,*) '   Namelist namhsb : set hsb parameters'
222         WRITE(numout,*) '      Switch for hsb diagnostic (T) or not (F)  ln_diahsb  = ', ln_diahsb
223      ENDIF
224
225      IF( .NOT. ln_diahsb )   RETURN
226
227         ! ------------------- !
228         ! 1 - Allocate memory !
229         ! ------------------- !
230         ALLOCATE( hc_loc_ini(jpi,jpj,jpk), STAT=ierror )
231         IF( ierror > 0 ) THEN
232            CALL ctl_stop( 'dia_hsb: unable to allocate hc_loc_ini' )   ;   RETURN
233         ENDIF
234         ALLOCATE( sc_loc_ini(jpi,jpj,jpk), STAT=ierror )
235         IF( ierror > 0 ) THEN
236            CALL ctl_stop( 'dia_hsb: unable to allocate sc_loc_ini' )   ;   RETURN
237         ENDIF
238         ALLOCATE( hcssh_loc_ini(jpi,jpj), STAT=ierror )
239         IF( ierror > 0 ) THEN
240            CALL ctl_stop( 'dia_hsb: unable to allocate hcssh_loc_ini' )   ;   RETURN
241         ENDIF
242         ALLOCATE( scssh_loc_ini(jpi,jpj), STAT=ierror )
243         IF( ierror > 0 ) THEN
244            CALL ctl_stop( 'dia_hsb: unable to allocate scssh_loc_ini' )   ;   RETURN
245         ENDIF
246         ALLOCATE( e3t_ini(jpi,jpj,jpk)   , STAT=ierror )
247         IF( ierror > 0 ) THEN
248            CALL ctl_stop( 'dia_hsb: unable to allocate e3t_ini' )      ;   RETURN
249         ENDIF
250         ALLOCATE( ssh_ini(jpi,jpj)       , STAT=ierror )
251         IF( ierror > 0 ) THEN
252            CALL ctl_stop( 'dia_hsb: unable to allocate ssh_ini' )      ;   RETURN
253         ENDIF
254         
255         ! ----------------------------------------------- !
256         ! 2 - Time independant variables and file opening !
257         ! ----------------------------------------------- !
258         IF(lwp) WRITE(numout,*) "dia_hsb: heat salt volume budgets activated"
259         IF( lk_obc .or. lk_bdy ) THEN
260            CALL ctl_warn( 'dia_hsb does not take open boundary fluxes into account' )         
261         ENDIF
262         !
263         CALL dia_hsb_rst( nit000, 'READ' )  !* read or initialize all required files
264      !
265   END SUBROUTINE dia_hsb_init
266
267   SUBROUTINE dia_hsb_rst( kt, cdrw )
268     !!---------------------------------------------------------------------
269     !!                   ***  ROUTINE limdia_rst  ***
270     !!                     
271     !! ** Purpose :   Read or write DIA file in restart file
272     !!
273     !! ** Method  :   use of IOM library
274     !!----------------------------------------------------------------------
275     INTEGER         , INTENT(in) ::   kt     ! ocean time-step
276     CHARACTER(len=*), INTENT(in) ::   cdrw   ! "READ"/"WRITE" flag
277     !
278     INTEGER ::   jk   !
279     INTEGER ::   id1   ! local integers
280     !!----------------------------------------------------------------------
281     !
282     IF( TRIM(cdrw) == 'READ' ) THEN        ! Read/initialise
283        IF( ln_rstart ) THEN                   !* Read the restart file
284           !id1 = iom_varid( numror, 'frc_vol'  , ldstop = .FALSE. )
285           !
286           CALL iom_get( numror, 'frc_v', frc_v )
287           CALL iom_get( numror, 'frc_t', frc_t )
288           CALL iom_get( numror, 'frc_s', frc_s )
289
290           CALL iom_get( numror, jpdom_autoglo, 'ssh_ini', ssh_ini )
291           CALL iom_get( numror, jpdom_autoglo, 'e3t_ini', e3t_ini )
292           CALL iom_get( numror, jpdom_autoglo, 'hc_loc_ini', hc_loc_ini )
293           CALL iom_get( numror, jpdom_autoglo, 'sc_loc_ini', sc_loc_ini )
294           CALL iom_get( numror, jpdom_autoglo, 'hcssh_loc_ini', hcssh_loc_ini )
295           CALL iom_get( numror, jpdom_autoglo, 'scssh_loc_ini', scssh_loc_ini )
296       ELSE
297          ssh_ini(:,:) = sshn(:,:)                                       ! initial ssh
298          DO jk = 1, jpk
299             e3t_ini   (:,:,jk) = fse3t_n(:,:,jk)                        ! initial vertical scale factors
300             hc_loc_ini(:,:,jk) = tsn(:,:,jk,jp_tem) * fse3t_n(:,:,jk)   ! initial heat content
301             sc_loc_ini(:,:,jk) = tsn(:,:,jk,jp_sal) * fse3t_n(:,:,jk)   ! initial salt content
302          END DO
303          hcssh_loc_ini(:,:) = tsn(:,:,1,jp_tem) * sshn(:,:)   ! initial heat content in ssh
304          scssh_loc_ini(:,:) = tsn(:,:,1,jp_sal) * sshn(:,:)   ! initial salt content in ssh
305          frc_v = 0._dp                                           
306          frc_t = 0._dp                                           
307          frc_s = 0._dp                                                 
308       ENDIF
309
310     ELSEIF( TRIM(cdrw) == 'WRITE' ) THEN   ! Create restart file
311        !                                   ! -------------------
312        IF(lwp) WRITE(numout,*) '---- dia-rst ----'
313        CALL iom_rstput( kt, nitrst, numrow, 'frc_v'   , frc_v     )
314        CALL iom_rstput( kt, nitrst, numrow, 'frc_t'   , frc_t     )
315        CALL iom_rstput( kt, nitrst, numrow, 'frc_s'   , frc_s     )
316       
317        CALL iom_rstput( kt, nitrst, numrow, 'ssh_ini', ssh_ini )
318        CALL iom_rstput( kt, nitrst, numrow, 'e3t_ini', e3t_ini )
319        CALL iom_rstput( kt, nitrst, numrow, 'hc_loc_ini', hc_loc_ini )
320        CALL iom_rstput( kt, nitrst, numrow, 'sc_loc_ini', sc_loc_ini )
321        CALL iom_rstput( kt, nitrst, numrow, 'hcssh_loc_ini', hcssh_loc_ini )
322        CALL iom_rstput( kt, nitrst, numrow, 'scssh_loc_ini', scssh_loc_ini )
323        !
324     ENDIF
325     !
326   END SUBROUTINE dia_hsb_rst
327
328   !!======================================================================
329END MODULE diahsb
Note: See TracBrowser for help on using the repository browser.