MODULE dynhpg !!====================================================================== !! *** MODULE dynhpg *** !! Ocean dynamics: hydrostatic pressure gradient trend !!====================================================================== !! History : OPA ! 1987-09 (P. Andrich, M.-A. Foujols) hpg_zco: Original code !! 5.0 ! 1991-11 (G. Madec) !! 7.0 ! 1996-01 (G. Madec) hpg_sco: Original code for s-coordinates !! 8.0 ! 1997-05 (G. Madec) split dynber into dynkeg and dynhpg !! 8.5 ! 2002-07 (G. Madec) F90: Free form and module !! 8.5 ! 2002-08 (A. Bozec) hpg_zps: Original code !! NEMO 1.0 ! 2005-10 (A. Beckmann, B.W. An) various s-coordinate options !! ! Original code for hpg_ctl, hpg_hel hpg_wdj, hpg_djc, hpg_rot !! - ! 2005-11 (G. Madec) style & small optimisation !! 3.3 ! 2010-10 (C. Ethe, G. Madec) reorganisation of initialisation phase !! 3.4 ! 2011-11 (H. Liu) hpg_prj: Original code for s-coordinates !! ! (A. Coward) suppression of hel, wdj and rot options !! 3.6 ! 2014-11 (P. Mathiot) hpg_isf: original code for ice shelf cavity !!---------------------------------------------------------------------- !!---------------------------------------------------------------------- !! dyn_hpg : update the momentum trend with the now horizontal !! gradient of the hydrostatic pressure !! dyn_hpg_init : initialisation and control of options !! hpg_zco : z-coordinate scheme !! hpg_zps : z-coordinate plus partial steps (interpolation) !! hpg_sco : s-coordinate (standard jacobian formulation) !! hpg_isf : s-coordinate (sco formulation) adapted to ice shelf !! hpg_djc : s-coordinate (Density Jacobian with Cubic polynomial) !! hpg_prj : s-coordinate (Pressure Jacobian with Cubic polynomial) !!---------------------------------------------------------------------- USE oce ! ocean dynamics and tracers USE sbc_oce ! surface variable (only for the flag with ice shelf) USE dom_oce ! ocean space and time domain USE phycst ! physical constants USE trd_oce ! trends: ocean variables USE trddyn ! trend manager: dynamics ! USE in_out_manager ! I/O manager USE prtctl ! Print control USE lbclnk ! lateral boundary condition USE lib_mpp ! MPP library USE eosbn2 ! compute density USE wrk_nemo ! Memory Allocation USE timing ! Timing IMPLICIT NONE PRIVATE PUBLIC dyn_hpg ! routine called by step module PUBLIC dyn_hpg_init ! routine called by opa module ! !!* Namelist namdyn_hpg : hydrostatic pressure gradient LOGICAL , PUBLIC :: ln_hpg_zco !: z-coordinate - full steps LOGICAL , PUBLIC :: ln_hpg_zps !: z-coordinate - partial steps (interpolation) LOGICAL , PUBLIC :: ln_hpg_sco !: s-coordinate (standard jacobian formulation) LOGICAL , PUBLIC :: ln_hpg_djc !: s-coordinate (Density Jacobian with Cubic polynomial) LOGICAL , PUBLIC :: ln_hpg_prj !: s-coordinate (Pressure Jacobian scheme) LOGICAL , PUBLIC :: ln_hpg_isf !: s-coordinate similar to sco modify for isf LOGICAL , PUBLIC :: ln_dynhpg_imp !: semi-implicite hpg flag INTEGER , PUBLIC :: nhpg = 0 ! = 0 to 7, type of pressure gradient scheme used ! (deduced from ln_hpg_... flags) (PUBLIC for TAM) !! * Substitutions # include "domzgr_substitute.h90" # include "vectopt_loop_substitute.h90" !!---------------------------------------------------------------------- !! NEMO/OPA 3.3 , NEMO Consortium (2010) !! $Id: dynhpg.F90 4990 2014-12-15 16:42:49Z timgraham $ !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt) !!---------------------------------------------------------------------- CONTAINS SUBROUTINE dyn_hpg( kt ) !!--------------------------------------------------------------------- !! *** ROUTINE dyn_hpg *** !! !! ** Method : Call the hydrostatic pressure gradient routine !! using the scheme defined in the namelist !! !! ** Action : - Update (ua,va) with the now hydrastatic pressure trend !! - send trends to trd_dyn for futher diagnostics (l_trddyn=T) !!---------------------------------------------------------------------- INTEGER, INTENT(in) :: kt ! ocean time-step index REAL(wp), POINTER, DIMENSION(:,:,:) :: ztrdu, ztrdv !!---------------------------------------------------------------------- ! IF( nn_timing == 1 ) CALL timing_start('dyn_hpg') ! IF( l_trddyn ) THEN ! Temporary saving of ua and va trends (l_trddyn) CALL wrk_alloc( jpi,jpj,jpk, ztrdu, ztrdv ) ztrdu(:,:,:) = ua(:,:,:) ztrdv(:,:,:) = va(:,:,:) ENDIF ! SELECT CASE ( nhpg ) ! Hydrostatic pressure gradient computation CASE ( 0 ) ; CALL hpg_zco ( kt ) ! z-coordinate CASE ( 1 ) ; CALL hpg_zps ( kt ) ! z-coordinate plus partial steps (interpolation) CASE ( 2 ) ; CALL hpg_sco ( kt ) ! s-coordinate (standard jacobian formulation) CASE ( 3 ) ; CALL hpg_djc ( kt ) ! s-coordinate (Density Jacobian with Cubic polynomial) CASE ( 4 ) ; CALL hpg_prj ( kt ) ! s-coordinate (Pressure Jacobian scheme) CASE ( 5 ) ; CALL hpg_isf ( kt ) ! s-coordinate similar to sco modify for ice shelf END SELECT ! IF( l_trddyn ) THEN ! save the hydrostatic pressure gradient trends for momentum trend diagnostics ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:) ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:) CALL trd_dyn( ztrdu, ztrdv, jpdyn_hpg, kt ) CALL wrk_dealloc( jpi,jpj,jpk, ztrdu, ztrdv ) ENDIF ! IF(ln_ctl) CALL prt_ctl( tab3d_1=ua, clinfo1=' hpg - Ua: ', mask1=umask, & & tab3d_2=va, clinfo2= ' Va: ', mask2=vmask, clinfo3='dyn' ) ! IF( nn_timing == 1 ) CALL timing_stop('dyn_hpg') ! END SUBROUTINE dyn_hpg SUBROUTINE dyn_hpg_init !!---------------------------------------------------------------------- !! *** ROUTINE dyn_hpg_init *** !! !! ** Purpose : initializations for the hydrostatic pressure gradient !! computation and consistency control !! !! ** Action : Read the namelist namdyn_hpg and check the consistency !! with the type of vertical coordinate used (zco, zps, sco) !!---------------------------------------------------------------------- INTEGER :: ioptio = 0 ! temporary integer INTEGER :: ios ! Local integer output status for namelist read !! NAMELIST/namdyn_hpg/ ln_hpg_zco, ln_hpg_zps, ln_hpg_sco, & & ln_hpg_djc, ln_hpg_prj, ln_hpg_isf, ln_dynhpg_imp !!---------------------------------------------------------------------- ! REWIND( numnam_ref ) ! Namelist namdyn_hpg in reference namelist : Hydrostatic pressure gradient READ ( numnam_ref, namdyn_hpg, IOSTAT = ios, ERR = 901) 901 IF( ios /= 0 ) CALL ctl_nam ( ios , 'namdyn_hpg in reference namelist', lwp ) REWIND( numnam_cfg ) ! Namelist namdyn_hpg in configuration namelist : Hydrostatic pressure gradient READ ( numnam_cfg, namdyn_hpg, IOSTAT = ios, ERR = 902 ) 902 IF( ios /= 0 ) CALL ctl_nam ( ios , 'namdyn_hpg in configuration namelist', lwp ) IF(lwm) WRITE ( numond, namdyn_hpg ) ! IF(lwp) THEN ! Control print WRITE(numout,*) WRITE(numout,*) 'dyn_hpg_init : hydrostatic pressure gradient initialisation' WRITE(numout,*) '~~~~~~~~~~~~' WRITE(numout,*) ' Namelist namdyn_hpg : choice of hpg scheme' WRITE(numout,*) ' z-coord. - full steps ln_hpg_zco = ', ln_hpg_zco WRITE(numout,*) ' z-coord. - partial steps (interpolation) ln_hpg_zps = ', ln_hpg_zps WRITE(numout,*) ' s-coord. (standard jacobian formulation) ln_hpg_sco = ', ln_hpg_sco WRITE(numout,*) ' s-coord. (standard jacobian formulation) for isf ln_hpg_isf = ', ln_hpg_isf WRITE(numout,*) ' s-coord. (Density Jacobian: Cubic polynomial) ln_hpg_djc = ', ln_hpg_djc WRITE(numout,*) ' s-coord. (Pressure Jacobian: Cubic polynomial) ln_hpg_prj = ', ln_hpg_prj WRITE(numout,*) ' time stepping: centered (F) or semi-implicit (T) ln_dynhpg_imp = ', ln_dynhpg_imp ENDIF ! IF( ln_hpg_djc ) & & CALL ctl_stop('dyn_hpg_init : Density Jacobian: Cubic polynominal method & & currently disabled (bugs under investigation). Please select & & either ln_hpg_sco or ln_hpg_prj instead') ! IF( lk_vvl .AND. .NOT. (ln_hpg_sco.OR.ln_hpg_prj.OR.ln_hpg_isf) ) & & CALL ctl_stop('dyn_hpg_init : variable volume key_vvl requires:& & the standard jacobian formulation hpg_sco or & & the pressure jacobian formulation hpg_prj') IF( ln_hpg_isf .AND. .NOT. ln_isfcav ) & & CALL ctl_stop( ' hpg_isf not available if ln_isfcav = false ' ) IF( .NOT. ln_hpg_isf .AND. ln_isfcav ) & & CALL ctl_stop( 'Only hpg_isf has been corrected to work with ice shelf cavity.' ) ! ! ! Set nhpg from ln_hpg_... flags IF( ln_hpg_zco ) nhpg = 0 IF( ln_hpg_zps ) nhpg = 1 IF( ln_hpg_sco ) nhpg = 2 IF( ln_hpg_djc ) nhpg = 3 IF( ln_hpg_prj ) nhpg = 4 IF( ln_hpg_isf ) nhpg = 5 ! ! ! Consistency check ioptio = 0 IF( ln_hpg_zco ) ioptio = ioptio + 1 IF( ln_hpg_zps ) ioptio = ioptio + 1 IF( ln_hpg_sco ) ioptio = ioptio + 1 IF( ln_hpg_djc ) ioptio = ioptio + 1 IF( ln_hpg_prj ) ioptio = ioptio + 1 IF( ln_hpg_isf ) ioptio = ioptio + 1 IF( ioptio /= 1 ) CALL ctl_stop( 'NO or several hydrostatic pressure gradient options used' ) ! ! initialisation of ice load riceload(:,:)=0.0 ! END SUBROUTINE dyn_hpg_init SUBROUTINE hpg_zco( kt ) !!--------------------------------------------------------------------- !! *** ROUTINE hpg_zco *** !! !! ** Method : z-coordinate case, levels are horizontal surfaces. !! The now hydrostatic pressure gradient at a given level, jk, !! is computed by taking the vertical integral of the in-situ !! density gradient along the model level from the suface to that !! level: zhpi = grav ..... !! zhpj = grav ..... !! add it to the general momentum trend (ua,va). !! ua = ua - 1/e1u * zhpi !! va = va - 1/e2v * zhpj !! !! ** Action : - Update (ua,va) with the now hydrastatic pressure trend !!---------------------------------------------------------------------- INTEGER, INTENT(in) :: kt ! ocean time-step index !! INTEGER :: ji, jj, jk ! dummy loop indices REAL(wp) :: zcoef0, zcoef1 ! temporary scalars REAL(wp), POINTER, DIMENSION(:,:,:) :: zhpi, zhpj !!---------------------------------------------------------------------- ! CALL wrk_alloc( jpi,jpj,jpk, zhpi, zhpj ) ! IF( kt == nit000 ) THEN IF(lwp) WRITE(numout,*) IF(lwp) WRITE(numout,*) 'dyn:hpg_zco : hydrostatic pressure gradient trend' IF(lwp) WRITE(numout,*) '~~~~~~~~~~~ z-coordinate case ' ENDIF zcoef0 = - grav * 0.5_wp ! Local constant initialization ! Surface value DO jj = 2, jpjm1 DO ji = fs_2, fs_jpim1 ! vector opt. zcoef1 = zcoef0 * fse3w(ji,jj,1) ! hydrostatic pressure gradient zhpi(ji,jj,1) = zcoef1 * ( rhd(ji+1,jj,1) - rhd(ji,jj,1) ) / e1u(ji,jj) zhpj(ji,jj,1) = zcoef1 * ( rhd(ji,jj+1,1) - rhd(ji,jj,1) ) / e2v(ji,jj) ! add to the general momentum trend ua(ji,jj,1) = ua(ji,jj,1) + zhpi(ji,jj,1) va(ji,jj,1) = va(ji,jj,1) + zhpj(ji,jj,1) END DO END DO ! ! interior value (2= 1 ) THEN ! on i-direction (level 2 or more) ua (ji,jj,iku) = ua(ji,jj,iku) - zhpi(ji,jj,iku) ! subtract old value zhpi(ji,jj,iku) = zhpi(ji,jj,iku-1) & ! compute the new one & + zcoef2 * ( rhd(ji+1,jj,iku-1) - rhd(ji,jj,iku-1) + gru(ji,jj) ) / e1u(ji,jj) ua (ji,jj,iku) = ua(ji,jj,iku) + zhpi(ji,jj,iku) ! add the new one to the general momentum trend ENDIF IF( ikv > 1 ) THEN ! on j-direction (level 2 or more) va (ji,jj,ikv) = va(ji,jj,ikv) - zhpj(ji,jj,ikv) ! subtract old value zhpj(ji,jj,ikv) = zhpj(ji,jj,ikv-1) & ! compute the new one & + zcoef3 * ( rhd(ji,jj+1,ikv-1) - rhd(ji,jj,ikv-1) + grv(ji,jj) ) / e2v(ji,jj) va (ji,jj,ikv) = va(ji,jj,ikv) + zhpj(ji,jj,ikv) ! add the new one to the general momentum trend ENDIF END DO END DO ! CALL wrk_dealloc( jpi,jpj,jpk, zhpi, zhpj ) ! END SUBROUTINE hpg_zps SUBROUTINE hpg_sco( kt ) !!--------------------------------------------------------------------- !! *** ROUTINE hpg_sco *** !! !! ** Method : s-coordinate case. Jacobian scheme. !! The now hydrostatic pressure gradient at a given level, jk, !! is computed by taking the vertical integral of the in-situ !! density gradient along the model level from the suface to that !! level. s-coordinates (ln_sco): a corrective term is added !! to the horizontal pressure gradient : !! zhpi = grav ..... + 1/e1u mi(rhd) di[ grav dep3w ] !! zhpj = grav ..... + 1/e2v mj(rhd) dj[ grav dep3w ] !! add it to the general momentum trend (ua,va). !! ua = ua - 1/e1u * zhpi !! va = va - 1/e2v * zhpj !! !! ** Action : - Update (ua,va) with the now hydrastatic pressure trend !!---------------------------------------------------------------------- INTEGER, INTENT(in) :: kt ! ocean time-step index !! INTEGER :: ji, jj, jk ! dummy loop indices REAL(wp) :: zcoef0, zuap, zvap, znad ! temporary scalars REAL(wp), POINTER, DIMENSION(:,:,:) :: zhpi, zhpj !!---------------------------------------------------------------------- ! CALL wrk_alloc( jpi,jpj,jpk, zhpi, zhpj ) ! IF( kt == nit000 ) THEN IF(lwp) WRITE(numout,*) IF(lwp) WRITE(numout,*) 'dyn:hpg_sco : hydrostatic pressure gradient trend' IF(lwp) WRITE(numout,*) '~~~~~~~~~~~ s-coordinate case, OPA original scheme used' ENDIF ! Local constant initialization zcoef0 = - grav * 0.5_wp ! To use density and not density anomaly IF ( lk_vvl ) THEN ; znad = 1._wp ! Variable volume ELSE ; znad = 0._wp ! Fixed volume ENDIF ! Surface value DO jj = 2, jpjm1 DO ji = fs_2, fs_jpim1 ! vector opt. ! hydrostatic pressure gradient along s-surfaces zhpi(ji,jj,1) = zcoef0 / e1u(ji,jj) * ( fse3w(ji+1,jj ,1) * ( znad + rhd(ji+1,jj ,1) ) & & - fse3w(ji ,jj ,1) * ( znad + rhd(ji ,jj ,1) ) ) zhpj(ji,jj,1) = zcoef0 / e2v(ji,jj) * ( fse3w(ji ,jj+1,1) * ( znad + rhd(ji ,jj+1,1) ) & & - fse3w(ji ,jj ,1) * ( znad + rhd(ji ,jj ,1) ) ) ! s-coordinate pressure gradient correction zuap = -zcoef0 * ( rhd (ji+1,jj,1) + rhd (ji,jj,1) + 2._wp * znad ) & & * ( fsde3w(ji+1,jj,1) - fsde3w(ji,jj,1) ) / e1u(ji,jj) zvap = -zcoef0 * ( rhd (ji,jj+1,1) + rhd (ji,jj,1) + 2._wp * znad ) & & * ( fsde3w(ji,jj+1,1) - fsde3w(ji,jj,1) ) / e2v(ji,jj) ! add to the general momentum trend ua(ji,jj,1) = ua(ji,jj,1) + zhpi(ji,jj,1) + zuap va(ji,jj,1) = va(ji,jj,1) + zhpj(ji,jj,1) + zvap END DO END DO ! interior value (2= zep) THEN drhow(ji,jj,jk) = 2._wp * drhoz(ji,jj,jk) * drhoz(ji,jj,jk-1) & & / ( drhoz(ji,jj,jk) + drhoz(ji,jj,jk-1) ) ELSE drhow(ji,jj,jk) = 0._wp ENDIF dzw(ji,jj,jk) = 2._wp * dzz(ji,jj,jk) * dzz(ji,jj,jk-1) & & / ( dzz(ji,jj,jk) + dzz(ji,jj,jk-1) ) IF( cffu > zep ) THEN drhou(ji,jj,jk) = 2._wp * drhox(ji+1,jj,jk) * drhox(ji,jj,jk) & & / ( drhox(ji+1,jj,jk) + drhox(ji,jj,jk) ) ELSE drhou(ji,jj,jk ) = 0._wp ENDIF IF( cffx > zep ) THEN dzu(ji,jj,jk) = 2._wp * dzx(ji+1,jj,jk) * dzx(ji,jj,jk) & & / ( dzx(ji+1,jj,jk) + dzx(ji,jj,jk) ) ELSE dzu(ji,jj,jk) = 0._wp ENDIF IF( cffv > zep ) THEN drhov(ji,jj,jk) = 2._wp * drhoy(ji,jj+1,jk) * drhoy(ji,jj,jk) & & / ( drhoy(ji,jj+1,jk) + drhoy(ji,jj,jk) ) ELSE drhov(ji,jj,jk) = 0._wp ENDIF IF( cffy > zep ) THEN dzv(ji,jj,jk) = 2._wp * dzy(ji,jj+1,jk) * dzy(ji,jj,jk) & & / ( dzy(ji,jj+1,jk) + dzy(ji,jj,jk) ) ELSE dzv(ji,jj,jk) = 0._wp ENDIF END DO END DO END DO !---------------------------------------------------------------------------------- ! apply boundary conditions at top and bottom using 5.36-5.37 !---------------------------------------------------------------------------------- drhow(:,:, 1 ) = 1.5_wp * ( drhoz(:,:, 2 ) - drhoz(:,:, 1 ) ) - 0.5_wp * drhow(:,:, 2 ) drhou(:,:, 1 ) = 1.5_wp * ( drhox(:,:, 2 ) - drhox(:,:, 1 ) ) - 0.5_wp * drhou(:,:, 2 ) drhov(:,:, 1 ) = 1.5_wp * ( drhoy(:,:, 2 ) - drhoy(:,:, 1 ) ) - 0.5_wp * drhov(:,:, 2 ) drhow(:,:,jpk) = 1.5_wp * ( drhoz(:,:,jpk) - drhoz(:,:,jpkm1) ) - 0.5_wp * drhow(:,:,jpkm1) drhou(:,:,jpk) = 1.5_wp * ( drhox(:,:,jpk) - drhox(:,:,jpkm1) ) - 0.5_wp * drhou(:,:,jpkm1) drhov(:,:,jpk) = 1.5_wp * ( drhoy(:,:,jpk) - drhoy(:,:,jpkm1) ) - 0.5_wp * drhov(:,:,jpkm1) !-------------------------------------------------------------- ! Upper half of top-most grid box, compute and store !------------------------------------------------------------- !!bug gm : e3w-de3w = 0.5*e3w .... and de3w(2)-de3w(1)=e3w(2) .... to be verified ! true if de3w is really defined as the sum of the e3w scale factors as, it seems to me, it should be DO jj = 2, jpjm1 DO ji = fs_2, fs_jpim1 ! vector opt. rho_k(ji,jj,1) = -grav * ( fse3w(ji,jj,1) - fsde3w(ji,jj,1) ) & & * ( rhd(ji,jj,1) & & + 0.5_wp * ( rhd(ji,jj,2) - rhd(ji,jj,1) ) & & * ( fse3w (ji,jj,1) - fsde3w(ji,jj,1) ) & & / ( fsde3w(ji,jj,2) - fsde3w(ji,jj,1) ) ) END DO END DO !!bug gm : here also, simplification is possible !!bug gm : optimisation: 1/10 and 1/12 the division should be done before the loop DO jk = 2, jpkm1 DO jj = 2, jpjm1 DO ji = fs_2, fs_jpim1 ! vector opt. rho_k(ji,jj,jk) = zcoef0 * ( rhd (ji,jj,jk) + rhd (ji,jj,jk-1) ) & & * ( fsde3w(ji,jj,jk) - fsde3w(ji,jj,jk-1) ) & & - grav * z1_10 * ( & & ( drhow (ji,jj,jk) - drhow (ji,jj,jk-1) ) & & * ( fsde3w(ji,jj,jk) - fsde3w(ji,jj,jk-1) - z1_12 * ( dzw (ji,jj,jk) + dzw (ji,jj,jk-1) ) ) & & - ( dzw (ji,jj,jk) - dzw (ji,jj,jk-1) ) & & * ( rhd (ji,jj,jk) - rhd (ji,jj,jk-1) - z1_12 * ( drhow(ji,jj,jk) + drhow(ji,jj,jk-1) ) ) & & ) rho_i(ji,jj,jk) = zcoef0 * ( rhd (ji+1,jj,jk) + rhd (ji,jj,jk) ) & & * ( fsde3w(ji+1,jj,jk) - fsde3w(ji,jj,jk) ) & & - grav* z1_10 * ( & & ( drhou (ji+1,jj,jk) - drhou (ji,jj,jk) ) & & * ( fsde3w(ji+1,jj,jk) - fsde3w(ji,jj,jk) - z1_12 * ( dzu (ji+1,jj,jk) + dzu (ji,jj,jk) ) ) & & - ( dzu (ji+1,jj,jk) - dzu (ji,jj,jk) ) & & * ( rhd (ji+1,jj,jk) - rhd (ji,jj,jk) - z1_12 * ( drhou(ji+1,jj,jk) + drhou(ji,jj,jk) ) ) & & ) rho_j(ji,jj,jk) = zcoef0 * ( rhd (ji,jj+1,jk) + rhd (ji,jj,jk) ) & & * ( fsde3w(ji,jj+1,jk) - fsde3w(ji,jj,jk) ) & & - grav* z1_10 * ( & & ( drhov (ji,jj+1,jk) - drhov (ji,jj,jk) ) & & * ( fsde3w(ji,jj+1,jk) - fsde3w(ji,jj,jk) - z1_12 * ( dzv (ji,jj+1,jk) + dzv (ji,jj,jk) ) ) & & - ( dzv (ji,jj+1,jk) - dzv (ji,jj,jk) ) & & * ( rhd (ji,jj+1,jk) - rhd (ji,jj,jk) - z1_12 * ( drhov(ji,jj+1,jk) + drhov(ji,jj,jk) ) ) & & ) END DO END DO END DO CALL lbc_lnk(rho_k,'W',1.) CALL lbc_lnk(rho_i,'U',1.) CALL lbc_lnk(rho_j,'V',1.) ! --------------- ! Surface value ! --------------- DO jj = 2, jpjm1 DO ji = fs_2, fs_jpim1 ! vector opt. zhpi(ji,jj,1) = ( rho_k(ji+1,jj ,1) - rho_k(ji,jj,1) - rho_i(ji,jj,1) ) / e1u(ji,jj) zhpj(ji,jj,1) = ( rho_k(ji ,jj+1,1) - rho_k(ji,jj,1) - rho_j(ji,jj,1) ) / e2v(ji,jj) ! add to the general momentum trend ua(ji,jj,1) = ua(ji,jj,1) + zhpi(ji,jj,1) va(ji,jj,1) = va(ji,jj,1) + zhpj(ji,jj,1) END DO END DO ! ---------------- ! interior value (2== -zdept(ji,jj,jk) ) THEN jis = ji + 1; jid = ji ELSE jis = ji; jid = ji +1 ENDIF ! integrate the pressure on the shallow side jk1 = jk DO WHILE ( -zdept(jis,jj,jk1) > zuijk ) IF( jk1 == mbku(ji,jj) ) THEN zuijk = -zdept(jis,jj,jk1) EXIT ENDIF zdeps = MIN(zdept(jis,jj,jk1+1), -zuijk) zpwes = zpwes + & integ_spline(zdept(jis,jj,jk1), zdeps, & asp(jis,jj,jk1), bsp(jis,jj,jk1), & csp(jis,jj,jk1), dsp(jis,jj,jk1)) jk1 = jk1 + 1 END DO ! integrate the pressure on the deep side jk1 = jk DO WHILE ( -zdept(jid,jj,jk1) < zuijk ) IF( jk1 == 1 ) THEN zdeps = zdept(jid,jj,1) + MIN(zuijk, sshn(jid,jj)*znad) zrhdt1 = zrhh(jid,jj,1) - interp3(zdept(jid,jj,1), asp(jid,jj,1), & bsp(jid,jj,1), csp(jid,jj,1), & dsp(jid,jj,1)) * zdeps zpwed = zpwed + 0.5_wp * (zrhh(jid,jj,1) + zrhdt1) * zdeps EXIT ENDIF zdeps = MAX(zdept(jid,jj,jk1-1), -zuijk) zpwed = zpwed + & integ_spline(zdeps, zdept(jid,jj,jk1), & asp(jid,jj,jk1-1), bsp(jid,jj,jk1-1), & csp(jid,jj,jk1-1), dsp(jid,jj,jk1-1) ) jk1 = jk1 - 1 END DO ! update the momentum trends in u direction zdpdx1 = zcoef0 / e1u(ji,jj) * (zhpi(ji+1,jj,jk) - zhpi(ji,jj,jk)) IF( lk_vvl ) THEN zdpdx2 = zcoef0 / e1u(ji,jj) * & ( REAL(jis-jid, wp) * (zpwes + zpwed) + (sshn(ji+1,jj)-sshn(ji,jj)) ) ELSE zdpdx2 = zcoef0 / e1u(ji,jj) * REAL(jis-jid, wp) * (zpwes + zpwed) ENDIF ua(ji,jj,jk) = ua(ji,jj,jk) + (zdpdx1 + zdpdx2) * & & umask(ji,jj,jk) * tmask(ji,jj,jk) * tmask(ji+1,jj,jk) ENDIF !!!!! for v equation IF( jk <= mbkv(ji,jj) ) THEN IF( -zdept(ji,jj+1,jk) >= -zdept(ji,jj,jk) ) THEN jjs = jj + 1; jjd = jj ELSE jjs = jj ; jjd = jj + 1 ENDIF ! integrate the pressure on the shallow side jk1 = jk DO WHILE ( -zdept(ji,jjs,jk1) > zvijk ) IF( jk1 == mbkv(ji,jj) ) THEN zvijk = -zdept(ji,jjs,jk1) EXIT ENDIF zdeps = MIN(zdept(ji,jjs,jk1+1), -zvijk) zpnss = zpnss + & integ_spline(zdept(ji,jjs,jk1), zdeps, & asp(ji,jjs,jk1), bsp(ji,jjs,jk1), & csp(ji,jjs,jk1), dsp(ji,jjs,jk1) ) jk1 = jk1 + 1 END DO ! integrate the pressure on the deep side jk1 = jk DO WHILE ( -zdept(ji,jjd,jk1) < zvijk ) IF( jk1 == 1 ) THEN zdeps = zdept(ji,jjd,1) + MIN(zvijk, sshn(ji,jjd)*znad) zrhdt1 = zrhh(ji,jjd,1) - interp3(zdept(ji,jjd,1), asp(ji,jjd,1), & bsp(ji,jjd,1), csp(ji,jjd,1), & dsp(ji,jjd,1) ) * zdeps zpnsd = zpnsd + 0.5_wp * (zrhh(ji,jjd,1) + zrhdt1) * zdeps EXIT ENDIF zdeps = MAX(zdept(ji,jjd,jk1-1), -zvijk) zpnsd = zpnsd + & integ_spline(zdeps, zdept(ji,jjd,jk1), & asp(ji,jjd,jk1-1), bsp(ji,jjd,jk1-1), & csp(ji,jjd,jk1-1), dsp(ji,jjd,jk1-1) ) jk1 = jk1 - 1 END DO ! update the momentum trends in v direction zdpdy1 = zcoef0 / e2v(ji,jj) * (zhpi(ji,jj+1,jk) - zhpi(ji,jj,jk)) IF( lk_vvl ) THEN zdpdy2 = zcoef0 / e2v(ji,jj) * & ( REAL(jjs-jjd, wp) * (zpnss + zpnsd) + (sshn(ji,jj+1)-sshn(ji,jj)) ) ELSE zdpdy2 = zcoef0 / e2v(ji,jj) * REAL(jjs-jjd, wp) * (zpnss + zpnsd ) ENDIF va(ji,jj,jk) = va(ji,jj,jk) + (zdpdy1 + zdpdy2)*& & vmask(ji,jj,jk)*tmask(ji,jj,jk)*tmask(ji,jj+1,jk) ENDIF END DO END DO END DO ! CALL wrk_dealloc( jpi,jpj,jpk, zhpi, zu, zv, fsp, xsp, asp, bsp, csp, dsp ) CALL wrk_dealloc( jpi,jpj,jpk, zdept, zrhh ) CALL wrk_dealloc( jpi,jpj, zsshu_n, zsshv_n ) ! END SUBROUTINE hpg_prj SUBROUTINE cspline(fsp, xsp, asp, bsp, csp, dsp, polynomial_type) !!---------------------------------------------------------------------- !! *** ROUTINE cspline *** !! !! ** Purpose : constrained cubic spline interpolation !! !! ** Method : f(x) = asp + bsp*x + csp*x^2 + dsp*x^3 !! !! Reference: CJC Kruger, Constrained Cubic Spline Interpoltation !!---------------------------------------------------------------------- IMPLICIT NONE REAL(wp), DIMENSION(:,:,:), INTENT(in) :: fsp, xsp ! value and coordinate REAL(wp), DIMENSION(:,:,:), INTENT(out) :: asp, bsp, csp, dsp ! coefficients of ! the interpoated function INTEGER, INTENT(in) :: polynomial_type ! 1: cubic spline ! 2: Linear ! INTEGER :: ji, jj, jk ! dummy loop indices INTEGER :: jpi, jpj, jpkm1 REAL(wp) :: zdf1, zdf2, zddf1, zddf2, ztmp1, ztmp2, zdxtmp REAL(wp) :: zdxtmp1, zdxtmp2, zalpha REAL(wp) :: zdf(size(fsp,3)) !!---------------------------------------------------------------------- jpi = size(fsp,1) jpj = size(fsp,2) jpkm1 = size(fsp,3) - 1 IF (polynomial_type == 1) THEN ! Constrained Cubic Spline DO ji = 1, jpi DO jj = 1, jpj !!Fritsch&Butland's method, 1984 (preferred, but more computation) ! DO jk = 2, jpkm1-1 ! zdxtmp1 = xsp(ji,jj,jk) - xsp(ji,jj,jk-1) ! zdxtmp2 = xsp(ji,jj,jk+1) - xsp(ji,jj,jk) ! zdf1 = ( fsp(ji,jj,jk) - fsp(ji,jj,jk-1) ) / zdxtmp1 ! zdf2 = ( fsp(ji,jj,jk+1) - fsp(ji,jj,jk) ) / zdxtmp2 ! ! zalpha = ( zdxtmp1 + 2._wp * zdxtmp2 ) / ( zdxtmp1 + zdxtmp2 ) / 3._wp ! ! IF(zdf1 * zdf2 <= 0._wp) THEN ! zdf(jk) = 0._wp ! ELSE ! zdf(jk) = zdf1 * zdf2 / ( ( 1._wp - zalpha ) * zdf1 + zalpha * zdf2 ) ! ENDIF ! END DO !!Simply geometric average DO jk = 2, jpkm1-1 zdf1 = (fsp(ji,jj,jk) - fsp(ji,jj,jk-1)) / (xsp(ji,jj,jk) - xsp(ji,jj,jk-1)) zdf2 = (fsp(ji,jj,jk+1) - fsp(ji,jj,jk)) / (xsp(ji,jj,jk+1) - xsp(ji,jj,jk)) IF(zdf1 * zdf2 <= 0._wp) THEN zdf(jk) = 0._wp ELSE zdf(jk) = 2._wp * zdf1 * zdf2 / (zdf1 + zdf2) ENDIF END DO zdf(1) = 1.5_wp * ( fsp(ji,jj,2) - fsp(ji,jj,1) ) / & & ( xsp(ji,jj,2) - xsp(ji,jj,1) ) - 0.5_wp * zdf(2) zdf(jpkm1) = 1.5_wp * ( fsp(ji,jj,jpkm1) - fsp(ji,jj,jpkm1-1) ) / & & ( xsp(ji,jj,jpkm1) - xsp(ji,jj,jpkm1-1) ) - & & 0.5_wp * zdf(jpkm1 - 1) DO jk = 1, jpkm1 - 1 zdxtmp = xsp(ji,jj,jk+1) - xsp(ji,jj,jk) ztmp1 = (zdf(jk+1) + 2._wp * zdf(jk)) / zdxtmp ztmp2 = 6._wp * (fsp(ji,jj,jk+1) - fsp(ji,jj,jk)) / zdxtmp / zdxtmp zddf1 = -2._wp * ztmp1 + ztmp2 ztmp1 = (2._wp * zdf(jk+1) + zdf(jk)) / zdxtmp zddf2 = 2._wp * ztmp1 - ztmp2 dsp(ji,jj,jk) = (zddf2 - zddf1) / 6._wp / zdxtmp csp(ji,jj,jk) = ( xsp(ji,jj,jk+1) * zddf1 - xsp(ji,jj,jk)*zddf2 ) / 2._wp / zdxtmp bsp(ji,jj,jk) = ( fsp(ji,jj,jk+1) - fsp(ji,jj,jk) ) / zdxtmp - & & csp(ji,jj,jk) * ( xsp(ji,jj,jk+1) + xsp(ji,jj,jk) ) - & & dsp(ji,jj,jk) * ((xsp(ji,jj,jk+1) + xsp(ji,jj,jk))**2 - & & xsp(ji,jj,jk+1) * xsp(ji,jj,jk)) asp(ji,jj,jk) = fsp(ji,jj,jk) - xsp(ji,jj,jk) * (bsp(ji,jj,jk) + & & (xsp(ji,jj,jk) * (csp(ji,jj,jk) + & & dsp(ji,jj,jk) * xsp(ji,jj,jk)))) END DO END DO END DO ELSE IF (polynomial_type == 2) THEN ! Linear DO ji = 1, jpi DO jj = 1, jpj DO jk = 1, jpkm1-1 zdxtmp =xsp(ji,jj,jk+1) - xsp(ji,jj,jk) ztmp1 = fsp(ji,jj,jk+1) - fsp(ji,jj,jk) dsp(ji,jj,jk) = 0._wp csp(ji,jj,jk) = 0._wp bsp(ji,jj,jk) = ztmp1 / zdxtmp asp(ji,jj,jk) = fsp(ji,jj,jk) - bsp(ji,jj,jk) * xsp(ji,jj,jk) END DO END DO END DO ELSE CALL ctl_stop( 'invalid polynomial type in cspline' ) ENDIF END SUBROUTINE cspline FUNCTION interp1(x, xl, xr, fl, fr) RESULT(f) !!---------------------------------------------------------------------- !! *** ROUTINE interp1 *** !! !! ** Purpose : 1-d linear interpolation !! !! ** Method : interpolation is straight forward !! extrapolation is also permitted (no value limit) !!---------------------------------------------------------------------- IMPLICIT NONE REAL(wp), INTENT(in) :: x, xl, xr, fl, fr REAL(wp) :: f ! result of the interpolation (extrapolation) REAL(wp) :: zdeltx !!---------------------------------------------------------------------- zdeltx = xr - xl IF(abs(zdeltx) <= 10._wp * EPSILON(x)) THEN f = 0.5_wp * (fl + fr) ELSE f = ( (x - xl ) * fr - ( x - xr ) * fl ) / zdeltx ENDIF END FUNCTION interp1 FUNCTION interp2(x, a, b, c, d) RESULT(f) !!---------------------------------------------------------------------- !! *** ROUTINE interp1 *** !! !! ** Purpose : 1-d constrained cubic spline interpolation !! !! ** Method : cubic spline interpolation !! !!---------------------------------------------------------------------- IMPLICIT NONE REAL(wp), INTENT(in) :: x, a, b, c, d REAL(wp) :: f ! value from the interpolation !!---------------------------------------------------------------------- f = a + x* ( b + x * ( c + d * x ) ) END FUNCTION interp2 FUNCTION interp3(x, a, b, c, d) RESULT(f) !!---------------------------------------------------------------------- !! *** ROUTINE interp1 *** !! !! ** Purpose : Calculate the first order of deriavtive of !! a cubic spline function y=a+b*x+c*x^2+d*x^3 !! !! ** Method : f=dy/dx=b+2*c*x+3*d*x^2 !! !!---------------------------------------------------------------------- IMPLICIT NONE REAL(wp), INTENT(in) :: x, a, b, c, d REAL(wp) :: f ! value from the interpolation !!---------------------------------------------------------------------- f = b + x * ( 2._wp * c + 3._wp * d * x) END FUNCTION interp3 FUNCTION integ_spline(xl, xr, a, b, c, d) RESULT(f) !!---------------------------------------------------------------------- !! *** ROUTINE interp1 *** !! !! ** Purpose : 1-d constrained cubic spline integration !! !! ** Method : integrate polynomial a+bx+cx^2+dx^3 from xl to xr !! !!---------------------------------------------------------------------- IMPLICIT NONE REAL(wp), INTENT(in) :: xl, xr, a, b, c, d REAL(wp) :: za1, za2, za3 REAL(wp) :: f ! integration result !!---------------------------------------------------------------------- za1 = 0.5_wp * b za2 = c / 3.0_wp za3 = 0.25_wp * d f = xr * ( a + xr * ( za1 + xr * ( za2 + za3 * xr ) ) ) - & & xl * ( a + xl * ( za1 + xl * ( za2 + za3 * xl ) ) ) END FUNCTION integ_spline !!====================================================================== END MODULE dynhpg