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 @ 4161

Last change on this file since 4161 was 4161, checked in by cetlod, 10 years ago

dev_LOCEAN_2013 : merge in the 3rd dev branch dev_r4028_CNRS_LIM3, see ticket #1169

  • Property svn:keywords set to Id
File size: 14.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 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
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(wp), SAVE                                ::   frc_t      , frc_s     , frc_v   ! global forcing trends
39   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   ssh_ini              !
40   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   hc_loc_ini, sc_loc_ini, e3t_ini  !
41   REAL(wp), 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(wp)   ::   zdiff_hc    , zdiff_sc      ! heat and salt content variations
70      REAL(wp)   ::   zdiff_v1    , zdiff_v2      ! volume variation
71      REAL(wp)   ::   z_hc        , z_sc          ! heat and salt content
72      REAL(wp)   ::   z_v1        , z_v2          ! volume
73      REAL(wp)   ::   zdeltat                     !    -     -
74      REAL(wp)   ::   z_frc_trd_t , z_frc_trd_s   !    -     -
75      REAL(wp)   ::   z_frc_trd_v                 !    -     -
76      REAL(wp), 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      ! Add penetrative solar radiation
91      IF( ln_traqsr )   z_frc_trd_t = z_frc_trd_t + r1_rau0_rcp * glob_sum( qsr     (:,:) * zsurf(:,:) )
92      ! Add geothermal heat flux
93      IF( ln_trabbc )   z_frc_trd_t = z_frc_trd_t +               glob_sum( qgh_trd0(:,:) * zsurf(:,:) )
94      !
95      frc_v = frc_v + z_frc_trd_v * rdt
96      frc_t = frc_t + z_frc_trd_t * rdt
97      frc_s = frc_s + z_frc_trd_s * rdt
98
99      ! ------------------------ !
100      ! 2a -  Content variations !
101      ! ------------------------ !
102      zdiff_v2 = 0._wp
103      zdiff_hc = 0._wp
104      zdiff_sc = 0._wp
105      ! volume variation (calculated with ssh)
106      zdiff_v1 = glob_sum( zsurf(:,:) * ( sshn(:,:) - ssh_ini(:,:) ) )
107      DO jk = 1, jpkm1
108         ! volume variation (calculated with scale factors)
109         zdiff_v2 = zdiff_v2 + glob_sum( zsurf(:,:) * tmask(:,:,jk) * ( fse3t_n(:,:,jk) - e3t_ini(:,:,jk) ) )
110         ! heat content variation
111         zdiff_hc = zdiff_hc + glob_sum( zsurf(:,:) * tmask(:,:,jk) * ( fse3t_n(:,:,jk) * tsn(:,:,jk,jp_tem)   &
112            &                           - hc_loc_ini(:,:,jk) ) )
113         ! salt content variation
114         zdiff_sc = zdiff_sc + glob_sum( zsurf(:,:) * tmask(:,:,jk) * ( fse3t_n(:,:,jk) * tsn(:,:,jk,jp_sal)   &
115            &                           - sc_loc_ini(:,:,jk) ) )
116      ENDDO
117
118      ! Substract forcing from heat content, salt content and volume variations
119      !frc_v = zdiff_v2 - frc_v
120      !frc_t = zdiff_hc - frc_t
121      !frc_s = zdiff_sc - frc_s
122     
123      ! add ssh if not vvl
124#if ! defined key_vvl
125     zdiff_v2 = zdiff_v2 + zdiff_v1
126     zdiff_hc = zdiff_hc + glob_sum( zsurf(:,:) * ( sshn(:,:) * tsn(:,:,1,jp_tem)   &
127            &                           - hcssh_loc_ini(:,:) ) )
128     zdiff_sc = zdiff_sc + glob_sum( zsurf(:,:) * ( sshn(:,:) * tsn(:,:,1,jp_sal)   &
129            &                           - scssh_loc_ini(:,:) ) )
130#endif 
131      !
132      ! ----------------------- !
133      ! 2b -  Content           !
134      ! ----------------------- !
135      z_v2 = 0._wp
136      z_hc = 0._wp
137      z_sc = 0._wp
138      ! volume (calculated with ssh)
139      z_v1 = glob_sum( zsurf(:,:) * sshn(:,:) )
140      DO jk = 1, jpkm1
141         ! volume (calculated with scale factors)
142         z_v2 = z_v2 + glob_sum( zsurf(:,:) * tmask(:,:,jk) * fse3t_n(:,:,jk) )
143         ! heat content
144         z_hc = z_hc + glob_sum( zsurf(:,:) * tmask(:,:,jk) * fse3t_n(:,:,jk) * tsn(:,:,jk,jp_tem) )
145         ! salt content
146         z_sc = z_sc + glob_sum( zsurf(:,:) * tmask(:,:,jk) * fse3t_n(:,:,jk) * tsn(:,:,jk,jp_sal) )
147      ENDDO
148      ! add ssh if not vvl
149#if ! defined key_vvl
150     z_v2 = z_v2 + z_v1
151     z_hc = z_hc + glob_sum( zsurf(:,:) * sshn(:,:) * tsn(:,:,1,jp_tem) )
152     z_sc = z_sc + glob_sum( zsurf(:,:) * sshn(:,:) * tsn(:,:,1,jp_sal) )
153#endif 
154
155      ! ----------------------- !
156      ! 3 - Diagnostics writing !
157      ! ----------------------- !
158      zdeltat  = 1.e0 / ( ( kt - nit000 + 1 ) * rdt )
159!
160      CALL iom_put( 'bgtemper' , z_hc / z_v2 )                      ! Temperature (C)
161      CALL iom_put( 'bgsaline' , z_sc / z_v2 )                      ! Salinity (psu)
162      CALL iom_put( 'bgheatco' , zdiff_hc * rau0 * rcp * 1.e-9_wp ) ! Heat content variation (10^9 J)
163      CALL iom_put( 'bgsaltco' , zdiff_sc * 1.e-9 )                 ! Salt content variation (psu*km3)
164      CALL iom_put( 'bgvolssh' , zdiff_v1 * 1.e-9 )                    ! volume ssh (km3) 
165      CALL iom_put( 'bgsshtot' , zdiff_v1 / glob_sum(zsurf) )          ! ssh (m) 
166      CALL iom_put( 'bgvoltot' , zdiff_v2 * 1.e-9 )                 ! volume total (km3)
167      CALL iom_put( 'bgfrcvol' , frc_v * 1.e-9 )                     ! vol - surface forcing (volume)
168      CALL iom_put( 'bgfrctem' , frc_t * rau0 * rcp * 1.e-9_wp ) ! hc  - surface forcing (heat content)
169      CALL iom_put( 'bgfrcsal' , frc_s * 1.e-9 )                     ! sc  - surface forcing (salt content)
170      !
171      CALL wrk_dealloc( jpi, jpj, zsurf )
172      !
173      IF( nn_timing == 1 )   CALL timing_stop('dia_hsb')
174!
175   END SUBROUTINE dia_hsb
176
177
178   SUBROUTINE dia_hsb_init
179      !!---------------------------------------------------------------------------
180      !!                  ***  ROUTINE dia_hsb  ***
181      !!     
182      !! ** Purpose: Initialization for the heat salt volume budgets
183      !!
184      !! ** Method : Compute initial heat content, salt content and volume
185      !!
186      !! ** Action : - Compute initial heat content, salt content and volume
187      !!             - Initialize forcing trends
188      !!             - Compute coefficients for conversion
189      !!---------------------------------------------------------------------------
190      INTEGER            ::   jk       ! dummy loop indice
191      INTEGER            ::   ierror   ! local integer
192      !!
193      NAMELIST/namhsb/ ln_diahsb
194      !!----------------------------------------------------------------------
195      !
196      REWIND ( numnam )              ! Read Namelist namhsb
197      READ   ( numnam, namhsb )
198      !
199      IF(lwp) THEN                   ! Control print
200         WRITE(numout,*)
201         WRITE(numout,*) 'dia_hsb_init : check the heat and salt budgets'
202         WRITE(numout,*) '~~~~~~~~~~~~'
203         WRITE(numout,*) '   Namelist namhsb : set hsb parameters'
204         WRITE(numout,*) '      Switch for hsb diagnostic (T) or not (F)  ln_diahsb  = ', ln_diahsb
205      ENDIF
206
207      IF( .NOT. ln_diahsb )   RETURN
208
209         ! ------------------- !
210         ! 1 - Allocate memory !
211         ! ------------------- !
212         ALLOCATE( hc_loc_ini(jpi,jpj,jpk), STAT=ierror )
213         IF( ierror > 0 ) THEN
214            CALL ctl_stop( 'dia_hsb: unable to allocate hc_loc_ini' )   ;   RETURN
215         ENDIF
216         ALLOCATE( sc_loc_ini(jpi,jpj,jpk), STAT=ierror )
217         IF( ierror > 0 ) THEN
218            CALL ctl_stop( 'dia_hsb: unable to allocate sc_loc_ini' )   ;   RETURN
219         ENDIF
220         ALLOCATE( hcssh_loc_ini(jpi,jpj), STAT=ierror )
221         IF( ierror > 0 ) THEN
222            CALL ctl_stop( 'dia_hsb: unable to allocate hcssh_loc_ini' )   ;   RETURN
223         ENDIF
224         ALLOCATE( scssh_loc_ini(jpi,jpj), STAT=ierror )
225         IF( ierror > 0 ) THEN
226            CALL ctl_stop( 'dia_hsb: unable to allocate scssh_loc_ini' )   ;   RETURN
227         ENDIF
228         ALLOCATE( e3t_ini(jpi,jpj,jpk)   , STAT=ierror )
229         IF( ierror > 0 ) THEN
230            CALL ctl_stop( 'dia_hsb: unable to allocate e3t_ini' )      ;   RETURN
231         ENDIF
232         ALLOCATE( ssh_ini(jpi,jpj)       , STAT=ierror )
233         IF( ierror > 0 ) THEN
234            CALL ctl_stop( 'dia_hsb: unable to allocate ssh_ini' )      ;   RETURN
235         ENDIF
236         
237         ! ----------------------------------------------- !
238         ! 2 - Time independant variables and file opening !
239         ! ----------------------------------------------- !
240         IF(lwp) WRITE(numout,*) "dia_hsb: heat salt volume budgets activated"
241         IF( lk_obc .or. lk_bdy ) THEN
242            CALL ctl_warn( 'dia_hsb does not take open boundary fluxes into account' )         
243         ENDIF
244                                                   
245         !
246         CALL dia_hsb_rst( nit000, 'READ' )  !* read or initialize all required files
247      !
248   END SUBROUTINE dia_hsb_init
249
250   SUBROUTINE dia_hsb_rst( kt, cdrw )
251     !!---------------------------------------------------------------------
252     !!                   ***  ROUTINE limdia_rst  ***
253     !!                     
254     !! ** Purpose :   Read or write DIA file in restart file
255     !!
256     !! ** Method  :   use of IOM library
257     !!----------------------------------------------------------------------
258     INTEGER         , INTENT(in) ::   kt     ! ocean time-step
259     CHARACTER(len=*), INTENT(in) ::   cdrw   ! "READ"/"WRITE" flag
260     !
261     INTEGER ::   jk   !
262     INTEGER ::   id1   ! local integers
263     !!----------------------------------------------------------------------
264     !
265     IF( TRIM(cdrw) == 'READ' ) THEN        ! Read/initialise
266        IF( ln_rstart ) THEN                   !* Read the restart file
267           !id1 = iom_varid( numror, 'frc_vol'  , ldstop = .FALSE. )
268           !
269           CALL iom_get( numror, 'frc_v', frc_v )
270           CALL iom_get( numror, 'frc_t', frc_t )
271           CALL iom_get( numror, 'frc_s', frc_s )
272
273           CALL iom_get( numror, jpdom_autoglo, 'ssh_ini', ssh_ini )
274           CALL iom_get( numror, jpdom_autoglo, 'e3t_ini', e3t_ini )
275           CALL iom_get( numror, jpdom_autoglo, 'hc_loc_ini', hc_loc_ini )
276           CALL iom_get( numror, jpdom_autoglo, 'sc_loc_ini', sc_loc_ini )
277           CALL iom_get( numror, jpdom_autoglo, 'hcssh_loc_ini', hcssh_loc_ini )
278           CALL iom_get( numror, jpdom_autoglo, 'scssh_loc_ini', scssh_loc_ini )
279       ELSE
280          ssh_ini(:,:) = sshn(:,:)                                       ! initial ssh
281          DO jk = 1, jpk
282             e3t_ini   (:,:,jk) = fse3t_n(:,:,jk)                        ! initial vertical scale factors
283             hc_loc_ini(:,:,jk) = tsn(:,:,jk,jp_tem) * fse3t_n(:,:,jk)   ! initial heat content
284             sc_loc_ini(:,:,jk) = tsn(:,:,jk,jp_sal) * fse3t_n(:,:,jk)   ! initial salt content
285          END DO
286          hcssh_loc_ini(:,:) = tsn(:,:,1,jp_tem) * sshn(:,:)   ! initial heat content in ssh
287          scssh_loc_ini(:,:) = tsn(:,:,1,jp_sal) * sshn(:,:)   ! initial salt content in ssh
288          frc_v = 0._wp                                           
289          frc_t = 0._wp                                           
290          frc_s = 0._wp                                                 
291       ENDIF
292
293     ELSEIF( TRIM(cdrw) == 'WRITE' ) THEN   ! Create restart file
294        !                                   ! -------------------
295        IF(lwp) WRITE(numout,*) '---- dia-rst ----'
296        CALL iom_rstput( kt, nitrst, numrow, 'frc_v'   , frc_v     )
297        CALL iom_rstput( kt, nitrst, numrow, 'frc_t'   , frc_t     )
298        CALL iom_rstput( kt, nitrst, numrow, 'frc_s'   , frc_s     )
299       
300        CALL iom_rstput( kt, nitrst, numrow, 'ssh_ini', ssh_ini )
301        CALL iom_rstput( kt, nitrst, numrow, 'e3t_ini', e3t_ini )
302        CALL iom_rstput( kt, nitrst, numrow, 'hc_loc_ini', hc_loc_ini )
303        CALL iom_rstput( kt, nitrst, numrow, 'sc_loc_ini', sc_loc_ini )
304        CALL iom_rstput( kt, nitrst, numrow, 'hcssh_loc_ini', hcssh_loc_ini )
305        CALL iom_rstput( kt, nitrst, numrow, 'scssh_loc_ini', scssh_loc_ini )
306        !
307     ENDIF
308     !
309   END SUBROUTINE dia_hsb_rst
310
311   !!======================================================================
312END MODULE diahsb
Note: See TracBrowser for help on using the repository browser.