MODULE diahsb !!====================================================================== !! *** MODULE diahsb *** !! Ocean diagnostics: Heat, salt and volume budgets !!====================================================================== !! History : 3.3 ! 2010-09 (M. Leclair) Original code !! ! 2012-10 (C. Rousset) add iom_put !!---------------------------------------------------------------------- !!---------------------------------------------------------------------- USE oce ! ocean dynamics and tracers USE dom_oce ! ocean space and time domain USE phycst ! physical constants USE sbc_oce ! surface thermohaline fluxes USE in_out_manager ! I/O manager USE domvvl ! vertical scale factors USE traqsr ! penetrative solar radiation USE trabbc ! bottom boundary condition USE lib_mpp ! distributed memory computing library USE trabbc ! bottom boundary condition USE obc_par ! (for lk_obc) USE bdy_par ! (for lk_bdy) USE timing ! preformance summary USE iom ! I/O manager USE lib_fortran ! glob_sum USE restart ! ocean restart USE wrk_nemo ! work arrays USE sbcrnf ! river runoffd IMPLICIT NONE PRIVATE PUBLIC dia_hsb ! routine called by step.F90 PUBLIC dia_hsb_init ! routine called by nemogcm.F90 PUBLIC dia_hsb_rst ! routine called by step.F90 LOGICAL, PUBLIC :: ln_diahsb !: check the heat and salt budgets REAL(dp), SAVE :: frc_t , frc_s , frc_v ! global forcing trends REAL(dp), ALLOCATABLE, SAVE, DIMENSION(:,:) :: ssh_ini ! REAL(dp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: hc_loc_ini, sc_loc_ini, e3t_ini ! REAL(dp), ALLOCATABLE, SAVE, DIMENSION(:,:) :: hcssh_loc_ini, scssh_loc_ini ! !! * Substitutions # include "domzgr_substitute.h90" # include "vectopt_loop_substitute.h90" !!---------------------------------------------------------------------- !! NEMO/OPA 3.3 , NEMO Consortium (2010) !! $Id$ !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt) !!---------------------------------------------------------------------- CONTAINS SUBROUTINE dia_hsb( kt ) !!--------------------------------------------------------------------------- !! *** ROUTINE dia_hsb *** !! !! ** Purpose: Compute the ocean global heat content, salt content and volume conservation !! !! ** Method : - Compute the deviation of heat content, salt content and volume !! at the current time step from their values at nit000 !! - Compute the contribution of forcing and remove it from these deviations !! !!--------------------------------------------------------------------------- INTEGER, INTENT(in) :: kt ! ocean time-step index !! INTEGER :: jk ! dummy loop indice REAL(dp) :: zdiff_hc , zdiff_sc ! heat and salt content variations REAL(dp) :: zdiff_v1 , zdiff_v2 ! volume variation REAL(dp) :: z_hc , z_sc ! heat and salt content REAL(dp) :: z_v1 , z_v2 ! volume REAL(dp) :: zdeltat ! - - REAL(dp) :: z_frc_trd_t , z_frc_trd_s ! - - REAL(dp) :: z_frc_trd_v ! - - REAL(dp), POINTER, DIMENSION(:,:) :: zsurf ! !!--------------------------------------------------------------------------- IF( nn_timing == 1 ) CALL timing_start('dia_hsb') CALL wrk_alloc( jpi, jpj, zsurf ) zsurf(:,:) = e1t(:,:) * e2t(:,:) * tmask(:,:,1) * tmask_i(:,:) ! masked surface grid cell area ! ------------------------- ! ! 1 - Trends due to forcing ! ! ------------------------- ! z_frc_trd_v = r1_rau0 * glob_sum( - ( emp(:,:) - rnf(:,:) ) * zsurf(:,:) ) ! volume fluxes z_frc_trd_t = glob_sum( sbc_tsc(:,:,jp_tem) * zsurf(:,:) ) ! heat fluxes z_frc_trd_s = glob_sum( sbc_tsc(:,:,jp_sal) * zsurf(:,:) ) ! salt fluxes ! IF( ln_rnf ) z_frc_trd_t = z_frc_trd_t + glob_sum( rnf_tsc(:,:,jp_tem) * zsurf(:,:) ) IF( ln_rnf_sal) z_frc_trd_s = z_frc_trd_s + glob_sum( rnf_tsc(:,:,jp_sal) * zsurf(:,:) ) ! Add penetrative solar radiation IF( ln_traqsr ) z_frc_trd_t = z_frc_trd_t + r1_rau0_rcp * glob_sum( qsr (:,:) * zsurf(:,:) ) ! Add geothermal heat flux IF( ln_trabbc ) z_frc_trd_t = z_frc_trd_t + glob_sum( qgh_trd0(:,:) * zsurf(:,:) ) ! frc_v = frc_v + z_frc_trd_v * rdt frc_t = frc_t + z_frc_trd_t * rdt frc_s = frc_s + z_frc_trd_s * rdt ! ------------------------ ! ! 2a - Content variations ! ! ------------------------ ! zdiff_v2 = 0._dp zdiff_hc = 0._dp zdiff_sc = 0._dp ! volume variation (calculated with ssh) zdiff_v1 = glob_sum( zsurf(:,:) * ( sshn(:,:) - ssh_ini(:,:) ) ) DO jk = 1, jpkm1 ! volume variation (calculated with scale factors) zdiff_v2 = zdiff_v2 & & + glob_sum( zsurf(:,:) * tmask(:,:,jk) * ( fse3t_n(:,:,jk) - e3t_ini(:,:,jk) ) ) ! heat content variation zdiff_hc = zdiff_hc & & + glob_sum( zsurf(:,:) * tmask(:,:,jk) * ( fse3t_n(:,:,jk) * tsn(:,:,jk,jp_tem) & & - hc_loc_ini(:,:,jk) ) ) ! salt content variation zdiff_sc = zdiff_sc & & + glob_sum( zsurf(:,:) * tmask(:,:,jk) * ( fse3t_n(:,:,jk) * tsn(:,:,jk,jp_sal) & & - sc_loc_ini(:,:,jk) ) ) ENDDO ! Substract forcing from heat content, salt content and volume variations !frc_v = zdiff_v2 - frc_v !frc_t = zdiff_hc - frc_t !frc_s = zdiff_sc - frc_s ! add ssh if not vvl IF( .NOT. lk_vvl ) THEN zdiff_v2 = zdiff_v2 + zdiff_v1 zdiff_hc = zdiff_hc + glob_sum( zsurf(:,:) * ( sshn(:,:) * tsn(:,:,1,jp_tem) & & - hcssh_loc_ini(:,:) ) ) zdiff_sc = zdiff_sc + glob_sum( zsurf(:,:) * ( sshn(:,:) * tsn(:,:,1,jp_sal) & & - scssh_loc_ini(:,:) ) ) ENDIF ! ! ----------------------- ! ! 2b - Content ! ! ----------------------- ! z_v2 = 0._dp z_hc = 0._dp z_sc = 0._dp ! volume (calculated with ssh) z_v1 = glob_sum( zsurf(:,:) * sshn(:,:) ) DO jk = 1, jpkm1 ! volume (calculated with scale factors) z_v2 = z_v2 & & + glob_sum( zsurf(:,:) * tmask(:,:,jk) * fse3t_n(:,:,jk) ) ! heat content z_hc = z_hc & & + glob_sum( zsurf(:,:) * tmask(:,:,jk) * fse3t_n(:,:,jk) * tsn(:,:,jk,jp_tem) ) ! salt content z_sc = z_sc & & + glob_sum( zsurf(:,:) * tmask(:,:,jk) * fse3t_n(:,:,jk) * tsn(:,:,jk,jp_sal) ) ENDDO ! add ssh if not vvl IF( .NOT. lk_vvl ) THEN z_v2 = z_v2 + z_v1 z_hc = z_hc + glob_sum( zsurf(:,:) * sshn(:,:) * tsn(:,:,1,jp_tem) ) z_sc = z_sc + glob_sum( zsurf(:,:) * sshn(:,:) * tsn(:,:,1,jp_sal) ) ENDIF ! ----------------------- ! ! 3 - Diagnostics writing ! ! ----------------------- ! zdeltat = 1.e0 / ( ( kt - nit000 + 1 ) * rdt ) ! CALL iom_put( 'bgtemper' , z_hc / z_v2 ) ! Temperature (C) CALL iom_put( 'bgsaline' , z_sc / z_v2 ) ! Salinity (psu) CALL iom_put( 'bgheatco' , zdiff_hc * rau0 * rcp * 1.e-9_dp ) ! Heat content variation (10^9 J) CALL iom_put( 'bgsaltco' , zdiff_sc * 1.e-9 ) ! Salt content variation (psu*km3) CALL iom_put( 'bgvolssh' , zdiff_v1 * 1.e-9 ) ! volume ssh (km3) CALL iom_put( 'bgsshtot' , zdiff_v1 / glob_sum(zsurf) ) ! ssh (m) CALL iom_put( 'bgvoltot' , zdiff_v2 * 1.e-9 ) ! volume total (km3) CALL iom_put( 'bgfrcvol' , frc_v * 1.e-9 ) ! vol - surface forcing (volume) CALL iom_put( 'bgfrctem' , frc_t * rau0 * rcp * 1.e-9_dp ) ! hc - surface forcing (heat content) CALL iom_put( 'bgfrcsal' , frc_s * 1.e-9 ) ! sc - surface forcing (salt content) ! CALL wrk_dealloc( jpi, jpj, zsurf ) ! IF( nn_timing == 1 ) CALL timing_stop('dia_hsb') ! END SUBROUTINE dia_hsb SUBROUTINE dia_hsb_init !!--------------------------------------------------------------------------- !! *** ROUTINE dia_hsb *** !! !! ** Purpose: Initialization for the heat salt volume budgets !! !! ** Method : Compute initial heat content, salt content and volume !! !! ** Action : - Compute initial heat content, salt content and volume !! - Initialize forcing trends !! - Compute coefficients for conversion !!--------------------------------------------------------------------------- INTEGER :: jk ! dummy loop indice INTEGER :: ierror ! local integer !! NAMELIST/namhsb/ ln_diahsb ! INTEGER :: ios !!---------------------------------------------------------------------- IF(lwp) THEN WRITE(numout,*) WRITE(numout,*) 'dia_hsb_init : check the heat and salt budgets' WRITE(numout,*) '~~~~~~~~ ' ENDIF REWIND( numnam_ref ) ! Namelist namhsb in reference namelist READ ( numnam_ref, namhsb, IOSTAT = ios, ERR = 901) 901 IF( ios /= 0 ) CALL ctl_nam ( ios , 'namhsb in reference namelist', lwp ) REWIND( numnam_cfg ) ! Namelist namhsb in configuration namelist READ ( numnam_cfg, namhsb, IOSTAT = ios, ERR = 902 ) 902 IF( ios /= 0 ) CALL ctl_nam ( ios , 'namhsb in configuration namelist', lwp ) WRITE ( numond, namhsb ) ! IF(lwp) THEN ! Control print WRITE(numout,*) WRITE(numout,*) ' Namelist namhsb : set hsb parameters' WRITE(numout,*) ' Switch for hsb diagnostic (T) or not (F) ln_diahsb = ', ln_diahsb ENDIF IF( .NOT. ln_diahsb ) RETURN ! ------------------- ! ! 1 - Allocate memory ! ! ------------------- ! ALLOCATE( hc_loc_ini(jpi,jpj,jpk), STAT=ierror ) IF( ierror > 0 ) THEN CALL ctl_stop( 'dia_hsb: unable to allocate hc_loc_ini' ) ; RETURN ENDIF ALLOCATE( sc_loc_ini(jpi,jpj,jpk), STAT=ierror ) IF( ierror > 0 ) THEN CALL ctl_stop( 'dia_hsb: unable to allocate sc_loc_ini' ) ; RETURN ENDIF ALLOCATE( hcssh_loc_ini(jpi,jpj), STAT=ierror ) IF( ierror > 0 ) THEN CALL ctl_stop( 'dia_hsb: unable to allocate hcssh_loc_ini' ) ; RETURN ENDIF ALLOCATE( scssh_loc_ini(jpi,jpj), STAT=ierror ) IF( ierror > 0 ) THEN CALL ctl_stop( 'dia_hsb: unable to allocate scssh_loc_ini' ) ; RETURN ENDIF ALLOCATE( e3t_ini(jpi,jpj,jpk) , STAT=ierror ) IF( ierror > 0 ) THEN CALL ctl_stop( 'dia_hsb: unable to allocate e3t_ini' ) ; RETURN ENDIF ALLOCATE( ssh_ini(jpi,jpj) , STAT=ierror ) IF( ierror > 0 ) THEN CALL ctl_stop( 'dia_hsb: unable to allocate ssh_ini' ) ; RETURN ENDIF ! ----------------------------------------------- ! ! 2 - Time independant variables and file opening ! ! ----------------------------------------------- ! IF(lwp) WRITE(numout,*) "dia_hsb: heat salt volume budgets activated" IF( lk_obc .or. lk_bdy ) THEN CALL ctl_warn( 'dia_hsb does not take open boundary fluxes into account' ) ENDIF ! CALL dia_hsb_rst( nit000, 'READ' ) !* read or initialize all required files ! END SUBROUTINE dia_hsb_init SUBROUTINE dia_hsb_rst( kt, cdrw ) !!--------------------------------------------------------------------- !! *** ROUTINE limdia_rst *** !! !! ** Purpose : Read or write DIA file in restart file !! !! ** Method : use of IOM library !!---------------------------------------------------------------------- INTEGER , INTENT(in) :: kt ! ocean time-step CHARACTER(len=*), INTENT(in) :: cdrw ! "READ"/"WRITE" flag ! INTEGER :: jk ! INTEGER :: id1 ! local integers !!---------------------------------------------------------------------- ! IF( TRIM(cdrw) == 'READ' ) THEN ! Read/initialise IF( ln_rstart ) THEN !* Read the restart file !id1 = iom_varid( numror, 'frc_vol' , ldstop = .FALSE. ) ! CALL iom_get( numror, 'frc_v', frc_v ) CALL iom_get( numror, 'frc_t', frc_t ) CALL iom_get( numror, 'frc_s', frc_s ) CALL iom_get( numror, jpdom_autoglo, 'ssh_ini', ssh_ini ) CALL iom_get( numror, jpdom_autoglo, 'e3t_ini', e3t_ini ) CALL iom_get( numror, jpdom_autoglo, 'hc_loc_ini', hc_loc_ini ) CALL iom_get( numror, jpdom_autoglo, 'sc_loc_ini', sc_loc_ini ) CALL iom_get( numror, jpdom_autoglo, 'hcssh_loc_ini', hcssh_loc_ini ) CALL iom_get( numror, jpdom_autoglo, 'scssh_loc_ini', scssh_loc_ini ) ELSE ssh_ini(:,:) = sshn(:,:) ! initial ssh DO jk = 1, jpk e3t_ini (:,:,jk) = fse3t_n(:,:,jk) ! initial vertical scale factors hc_loc_ini(:,:,jk) = tsn(:,:,jk,jp_tem) * fse3t_n(:,:,jk) ! initial heat content sc_loc_ini(:,:,jk) = tsn(:,:,jk,jp_sal) * fse3t_n(:,:,jk) ! initial salt content END DO hcssh_loc_ini(:,:) = tsn(:,:,1,jp_tem) * sshn(:,:) ! initial heat content in ssh scssh_loc_ini(:,:) = tsn(:,:,1,jp_sal) * sshn(:,:) ! initial salt content in ssh frc_v = 0._dp frc_t = 0._dp frc_s = 0._dp ENDIF ELSEIF( TRIM(cdrw) == 'WRITE' ) THEN ! Create restart file ! ! ------------------- IF(lwp) WRITE(numout,*) '---- dia-rst ----' CALL iom_rstput( kt, nitrst, numrow, 'frc_v' , frc_v ) CALL iom_rstput( kt, nitrst, numrow, 'frc_t' , frc_t ) CALL iom_rstput( kt, nitrst, numrow, 'frc_s' , frc_s ) CALL iom_rstput( kt, nitrst, numrow, 'ssh_ini', ssh_ini ) CALL iom_rstput( kt, nitrst, numrow, 'e3t_ini', e3t_ini ) CALL iom_rstput( kt, nitrst, numrow, 'hc_loc_ini', hc_loc_ini ) CALL iom_rstput( kt, nitrst, numrow, 'sc_loc_ini', sc_loc_ini ) CALL iom_rstput( kt, nitrst, numrow, 'hcssh_loc_ini', hcssh_loc_ini ) CALL iom_rstput( kt, nitrst, numrow, 'scssh_loc_ini', scssh_loc_ini ) ! ENDIF ! END SUBROUTINE dia_hsb_rst !!====================================================================== END MODULE diahsb