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

source: branches/2013/dev_r4028_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/DIA/diahsb.F90 @ 4220

Last change on this file since 4220 was 4220, checked in by clem, 10 years ago

corrections for restartability

  • Property svn:keywords set to Id
File size: 14.9 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  = .FALSE.   !: check the heat and salt budgets
38
39   REAL(wp), SAVE                                ::   frc_t      , frc_s     , frc_v   ! global forcing trends
40   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   ssh_ini              !
41   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   hc_loc_ini, sc_loc_ini, e3t_ini  !
42   REAL(wp), 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(wp)   ::   zdiff_hc    , zdiff_sc      ! heat and salt content variations
71      REAL(wp)   ::   zdiff_v1    , zdiff_v2      ! volume variation
72      REAL(wp)   ::   z_hc        , z_sc          ! heat and salt content
73      REAL(wp)   ::   z_v1        , z_v2          ! volume
74      REAL(wp)   ::   zdeltat                     !    -     -
75      REAL(wp)   ::   z_frc_trd_t , z_frc_trd_s   !    -     -
76      REAL(wp)   ::   z_frc_trd_v                 !    -     -
77      REAL(wp), 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._wp
108      zdiff_hc = 0._wp
109      zdiff_sc = 0._wp
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._wp
141      z_hc = 0._wp
142      z_sc = 0._wp
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_wp ) ! 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_wp ) ! 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      !
201      REWIND ( numnam )              ! Read Namelist namhsb
202      READ   ( numnam, namhsb )
203      !
204      IF(lwp) THEN                   ! Control print
205         WRITE(numout,*)
206         WRITE(numout,*) 'dia_hsb_init : check the heat and salt budgets'
207         WRITE(numout,*) '~~~~~~~~~~~~'
208         WRITE(numout,*) '   Namelist namhsb : set hsb parameters'
209         WRITE(numout,*) '      Switch for hsb diagnostic (T) or not (F)  ln_diahsb  = ', ln_diahsb
210      ENDIF
211
212      IF( .NOT. ln_diahsb )   RETURN
213
214         ! ------------------- !
215         ! 1 - Allocate memory !
216         ! ------------------- !
217         ALLOCATE( hc_loc_ini(jpi,jpj,jpk), STAT=ierror )
218         IF( ierror > 0 ) THEN
219            CALL ctl_stop( 'dia_hsb: unable to allocate hc_loc_ini' )   ;   RETURN
220         ENDIF
221         ALLOCATE( sc_loc_ini(jpi,jpj,jpk), STAT=ierror )
222         IF( ierror > 0 ) THEN
223            CALL ctl_stop( 'dia_hsb: unable to allocate sc_loc_ini' )   ;   RETURN
224         ENDIF
225         ALLOCATE( hcssh_loc_ini(jpi,jpj), STAT=ierror )
226         IF( ierror > 0 ) THEN
227            CALL ctl_stop( 'dia_hsb: unable to allocate hcssh_loc_ini' )   ;   RETURN
228         ENDIF
229         ALLOCATE( scssh_loc_ini(jpi,jpj), STAT=ierror )
230         IF( ierror > 0 ) THEN
231            CALL ctl_stop( 'dia_hsb: unable to allocate scssh_loc_ini' )   ;   RETURN
232         ENDIF
233         ALLOCATE( e3t_ini(jpi,jpj,jpk)   , STAT=ierror )
234         IF( ierror > 0 ) THEN
235            CALL ctl_stop( 'dia_hsb: unable to allocate e3t_ini' )      ;   RETURN
236         ENDIF
237         ALLOCATE( ssh_ini(jpi,jpj)       , STAT=ierror )
238         IF( ierror > 0 ) THEN
239            CALL ctl_stop( 'dia_hsb: unable to allocate ssh_ini' )      ;   RETURN
240         ENDIF
241         
242         ! ----------------------------------------------- !
243         ! 2 - Time independant variables and file opening !
244         ! ----------------------------------------------- !
245         IF(lwp) WRITE(numout,*) "dia_hsb: heat salt volume budgets activated"
246         IF( lk_obc .or. lk_bdy ) THEN
247            CALL ctl_warn( 'dia_hsb does not take open boundary fluxes into account' )         
248         ENDIF
249         !
250         CALL dia_hsb_rst( nit000, 'READ' )  !* read or initialize all required files
251      !
252   END SUBROUTINE dia_hsb_init
253
254   SUBROUTINE dia_hsb_rst( kt, cdrw )
255     !!---------------------------------------------------------------------
256     !!                   ***  ROUTINE limdia_rst  ***
257     !!                     
258     !! ** Purpose :   Read or write DIA file in restart file
259     !!
260     !! ** Method  :   use of IOM library
261     !!----------------------------------------------------------------------
262     INTEGER         , INTENT(in) ::   kt     ! ocean time-step
263     CHARACTER(len=*), INTENT(in) ::   cdrw   ! "READ"/"WRITE" flag
264     !
265     INTEGER ::   jk   !
266     INTEGER ::   id1   ! local integers
267     !!----------------------------------------------------------------------
268     !
269     IF( TRIM(cdrw) == 'READ' ) THEN        ! Read/initialise
270        IF( ln_rstart ) THEN                   !* Read the restart file
271           !id1 = iom_varid( numror, 'frc_vol'  , ldstop = .FALSE. )
272           !
273           CALL iom_get( numror, 'frc_v', frc_v )
274           CALL iom_get( numror, 'frc_t', frc_t )
275           CALL iom_get( numror, 'frc_s', frc_s )
276
277           CALL iom_get( numror, jpdom_autoglo, 'ssh_ini', ssh_ini )
278           CALL iom_get( numror, jpdom_autoglo, 'e3t_ini', e3t_ini )
279           CALL iom_get( numror, jpdom_autoglo, 'hc_loc_ini', hc_loc_ini )
280           CALL iom_get( numror, jpdom_autoglo, 'sc_loc_ini', sc_loc_ini )
281           CALL iom_get( numror, jpdom_autoglo, 'hcssh_loc_ini', hcssh_loc_ini )
282           CALL iom_get( numror, jpdom_autoglo, 'scssh_loc_ini', scssh_loc_ini )
283       ELSE
284          ssh_ini(:,:) = sshn(:,:)                                       ! initial ssh
285          DO jk = 1, jpk
286             e3t_ini   (:,:,jk) = fse3t_n(:,:,jk)                        ! initial vertical scale factors
287             hc_loc_ini(:,:,jk) = tsn(:,:,jk,jp_tem) * fse3t_n(:,:,jk)   ! initial heat content
288             sc_loc_ini(:,:,jk) = tsn(:,:,jk,jp_sal) * fse3t_n(:,:,jk)   ! initial salt content
289          END DO
290          hcssh_loc_ini(:,:) = tsn(:,:,1,jp_tem) * sshn(:,:)   ! initial heat content in ssh
291          scssh_loc_ini(:,:) = tsn(:,:,1,jp_sal) * sshn(:,:)   ! initial salt content in ssh
292          frc_v = 0._wp                                           
293          frc_t = 0._wp                                           
294          frc_s = 0._wp                                                 
295       ENDIF
296
297     ELSEIF( TRIM(cdrw) == 'WRITE' ) THEN   ! Create restart file
298        !                                   ! -------------------
299        IF(lwp) WRITE(numout,*) '---- dia-rst ----'
300        CALL iom_rstput( kt, nitrst, numrow, 'frc_v'   , frc_v     )
301        CALL iom_rstput( kt, nitrst, numrow, 'frc_t'   , frc_t     )
302        CALL iom_rstput( kt, nitrst, numrow, 'frc_s'   , frc_s     )
303       
304        CALL iom_rstput( kt, nitrst, numrow, 'ssh_ini', ssh_ini )
305        CALL iom_rstput( kt, nitrst, numrow, 'e3t_ini', e3t_ini )
306        CALL iom_rstput( kt, nitrst, numrow, 'hc_loc_ini', hc_loc_ini )
307        CALL iom_rstput( kt, nitrst, numrow, 'sc_loc_ini', sc_loc_ini )
308        CALL iom_rstput( kt, nitrst, numrow, 'hcssh_loc_ini', hcssh_loc_ini )
309        CALL iom_rstput( kt, nitrst, numrow, 'scssh_loc_ini', scssh_loc_ini )
310        !
311     ENDIF
312     !
313   END SUBROUTINE dia_hsb_rst
314
315   !!======================================================================
316END MODULE diahsb
Note: See TracBrowser for help on using the repository browser.