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

source: branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/DIA/diahsb.F90 @ 4328

Last change on this file since 4328 was 4328, checked in by davestorkey, 10 years ago

Remove OBC module at NEMO 3.6. See ticket #1189.

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