MODULE step_tam_cpd #ifdef key_tam !!====================================================================== !! *** MODULE step_tam *** !! Time-stepping : manager of the adjoint ocean time stepping !! Tangent and Adjoint module !!====================================================================== !! History of !! the direct: ! 91-03 () Original code !! ! 91-11 (G. Madec) !! ! 92-06 (M. Imbard) add a first output record !! ! 96-04 (G. Madec) introduction of dynspg !! ! 96-04 (M.A. Foujols) introduction of passive tracer !! 8.0 ! 97-06 (G. Madec) new architecture of call !! 8.2 ! 97-06 (G. Madec, M. Imbard, G. Roullet) free surface !! 8.2 ! 99-02 (G. Madec, N. Grima) hpg implicit !! 8.2 ! 00-07 (J-M Molines, M. Imbard) Open Bondary Conditions !! 9.0 ! 02-06 (G. Madec) free form, suppress macro-tasking !! " " ! 04-08 (C. Talandier) New trends organization !! " " ! 05-01 (C. Ethe) Add the KPP closure scheme !! " " ! 05-11 (V. Garnier) Surface pressure gradient organization !! " " ! 05-11 (G. Madec) Reorganisation of tra and dyn calls !! " " ! 06-01 (L. Debreu, C. Mazauric) Agrif implementation !! " " ! 06-07 (S. Masson) restart using iom !! " " " ! 07-04 (K. Mogensen, A. Weaver, M. Martin) Assimilation interface !! History of the TAM !! ! 08-06 (A. Vidard and A. Weaver) Tangent and Adjoint version of 9.0 !! ! 08-11 (A. Vidard) Nemo v3 update !! ! 06-09 (F. Vigilant) Modified to split NEMOVAR / NEMOTAM !!---------------------------------------------------------------------- !! stp_tam : OPA system time-stepping (tangent linear) !! stp_adj : OPA system time-stepping (adjoint) !!---------------------------------------------------------------------- USE par_kind , ONLY: & ! Precision variables & wp USE par_oce , ONLY: & ! Ocean space and time domain variables & jpi, & & jpj, & & jpk, & & jpiglo USE oce , ONLY: & ! ocean dynamics and tracers variables & tb, sb, tn, sn, ta, & & un, vn, sshn, sshb, & & sa, ub, vb, & & ln_dynhpg_imp USE zdfkpp , ONLY: & & lk_zdfkpp ! KPP vertical mixing flag USE dynspg_oce , ONLY: & & lk_dynspg_rl ! Rigid-lid flag USE dom_oce , ONLY: & ! ocean space and time domain variables & n_cla, e1u, e2u, & & e1v, e2v, e1t, e2t, & # if defined key_vvl & e3t_1, & # else # if defined key_zco & e3t_0, e3w_0, & # else & e3t, e3u, e3v, e3w, & # endif # endif & nldi, nldj, nlei, & & nlej, lk_vvl, ln_zps,& & narea, mig, mjg, & & umask, vmask, tmask USE in_out_manager, ONLY: & ! I/O manager & numout, lwp, & & nit000, nitend, & & nstop, ctl_stop USE daymod , ONLY: & & adatrj USE trabbc , ONLY: &! bottom boundary condition & lk_trabbc USE traqsr , ONLY: & & ln_traqsr ! solar radiation penetration flag USE oce_tam , ONLY: & ! Tangent linear and adjoint variables & oce_tam_init, & & un_tl, vn_tl, tn_tl, & & sn_tl, ua_tl, va_tl, & & ta_tl, sa_tl, ub_tl, & & vb_tl, tb_tl, sb_tl, & & un_ad, vn_ad, tn_ad, & & sn_ad, ua_ad, va_ad, & & ta_ad, sa_ad, ub_ad, & & vb_ad, tb_ad, sb_ad, & & sshn_tl, sshn_ad, & & rn2_tl, rn2_ad, & & rhd_tl, rhop_tl, & & rhd_ad, rhop_ad, & & gtu_tl, gsu_tl, & & gru_tl, gtv_tl, & & gsv_tl, grv_tl, & & gtu_ad, gsu_ad, & & gru_ad, gtv_ad, & & gsv_ad, grv_ad, & & ssha_tl, sshb_tl USE lbclnk_tam USE daymod_tam ! calendar (adjoint of day routine) USE sbc_oce_tam USE sbcmod_tam USE traqsr_tam ! solar radiation penetration (adjoint of tra_qsr routine) USE trasbc_tam ! surface boundary condition (adjoint of tra_sbc routine) USE trabbc_tam ! bottom boundary condition (adjoint of tra_bbc routine) USE tradmp_tam ! internal damping (adjoint of tra_dmp routine) USE traadv_tam ! advection scheme control (adjoint of tra_adv_ctl routine) USE traldf_tam ! lateral mixing (adjoint of tra_ldf routine) USE cla_tam ! cross land advection (adjoint of tra_cla routine) ! zdfkpp ! KPP non-local tracer fluxes (adjoint of tra_kpp routine) USE trazdf_tam ! vertical mixing (adjoint of tra_zdf routine) USE tranxt_tam ! time-stepping (adjoint of tra_nxt routine) USE eosbn2_tam ! equation of state (adjoint of eos_bn2 routine) USE dynadv_tam ! advection (adjoint of dyn_adv routine) USE dynvor_tam ! vorticity term (adjoint of dyn_vor routine) USE dynhpg_tam ! hydrostatic pressure grad. (adjoint of dyn_hpg routine) USE dynldf_tam ! lateral momentum diffusion (adjoint of dyn_ldf routine) USE dynzdf_tam ! vertical diffusion (adjoint of dyn_zdf routine) USE dynspg_tam ! surface pressure gradient (adjoint of dyn_spg routine) USE dynnxt_tam ! time-stepping (adjoint of dyn_nxt routine) ! USE bdy_par_tam ! USE bdydta_tam USE divcur_tam ! hor. divergence and curl (adjoint of div & cur routines) USE cla_div_tam ! cross land: hor. divergence (adjoint of div_cla routine) USE wzvmod_tam ! vertical velocity (adjoint of wzv routine) USE zdfkpp_tam ! KPP vertical mixing USE zpshde_tam ! partial step: hor. derivative (adjoint of zps_hde routine) !! USE diaobs_tam ! obs-minus-model (adjoint of assimilation) (adjoint of dia_obs routine) USE trj_tam USE stpctl_tam ! time stepping control (adjoint of stp_ctl routine) USE gridrandom, ONLY: & ! Random Gaussian noise on grids & grid_random, & & grid_rd_sd USE dotprodfld, ONLY: & ! Computes dot product for 3D and 2D fields & dot_product USE tstool_tam, ONLY: & & prntst_adj, & & prntst_tlm, & & stdemp, & & stdu,stdv, & & stdt, & & stds, stdssh, & & stdr USE paresp, ONLY: & ! Weights for an energy-type scalar product & wesp_t, & & wesp_s, & & wesp_u, & & wesp_ssh USE istate_tam !: Initial state setting (istate_init routine) USE sol_oce_tam USE trc_oce_tam USE step #if defined key_agrif #error 'agrif not yet implemented in nemotam' #endif IMPLICIT NONE PRIVATE PUBLIC stp_tan_cpd !! * Substitutions # include "domzgr_substitute.h90" # include "zdfddm_substitute.h90" CONTAINS #if defined key_agrif #error 'agrif not yet implemented in nemotam' ! SUBROUTINE stp_tan( ) #else SUBROUTINE stp_tan_cpd( kstp ) #endif !!---------------------------------------------------------------------- !! *** ROUTINE stp_tan *** !! !! ** Purpose of the direct routine: !! - Time stepping of OPA (momentum and active tracer eqs.) !! - Time stepping of LIM (dynamic and thermodynamic eqs.) !! - Tme stepping of TRC (passive tracer eqs.) !! !! ** Method of the direct routine: !! -1- Update forcings and data !! -2- Update ocean physics !! -3- Compute the t and s trends !! -4- Update t and s !! -5- Compute the momentum trends !! -6- Update the horizontal velocity !! -7- Compute the diagnostics variables (rd,N2, div,cur,w) !! -8- Outputs and diagnostics !!---------------------------------------------------------------------- !! * Arguments #if defined key_agrif INTEGER :: kstp ! ocean time-step index #else INTEGER, INTENT( in ) :: kstp ! ocean time-step index #endif !! * local declarations INTEGER :: indic ! error indicator if < 0 REAL(wp), DIMENSION(jpi,jpj,jpk) :: zta_tmp, zsa_tmp !! --------------------------------------------------------------------- #if defined key_agrif kstp = nit000 + Agrif_Nb_Step() ! IF ( Agrif_Root() .and. lwp) Write(*,*) '---' ! IF (lwp) Write(*,*) 'Grid Number',Agrif_Fixed(),' time step ',kstp #endif indic = 1 ! reset to no error condition CALL day_tam( kstp, 0 ) ! Calendar !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ! Update data, open boundaries, surface boundary condition (including sea-ice) !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ! update 3D temperature data ... not needed in tangent ! update 3D salinity data ... not needed in tangent (to be investigated, see sbc_ssr) CALL sbc_tan ( kstp ) ! Sea boundary condition (including sea-ice) ! update dynamic and tracer data at open boundaries ... not needed for the time being, to investigate whenever we do obc. ! compute phase velocities at open boundaries ... not needed for the time being, to investigate whenever we do obc. ! IF( lk_bdy ) CALL bdy_dta_tan( kstp ) ! update dynamic and tracer data at unstructured open boundary ! Output the initial state and forcings ... not needed in tangent ! saving direct variables ua,va, ta, sa before entering in tracer zta_tmp (:,:,:) = ta (:,:,:) zsa_tmp (:,:,:) = sa (:,:,:) !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ! Ocean physics update !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< !----------------------------------------------------------------------- ! VERTICAL PHYSICS !----------------------------------------------------------------------- ! N.B. ua, va, ta, sa arrays are used as workspace in this section !----------------------------------------------------------------------- CALL bn2_tan( tb, sb, tb_tl, sb_tl, rn2_tl ) ! before Brunt-Vaisala frequency ! ! Vertical eddy viscosity and diffusivity coefficients ! Richardson number dependent Kz ... not available ! TKE closure scheme for Kz ... not available ! KPP closure scheme for Kz ... not available ! Constant Kz (reset avt, avm[uv] to the background value)... not available ! lk_zdfcst_tan: Constant Kz read from the reference trajectory ! ! increase diffusivity at rivers mouths... not needed in tangent ! enhanced vertical eddy diffusivity ... not needed in tangent with lk_zdfcst_tan ! double diffusive mixing ... not needed in tangent with lk_zdfcst_tan ! bottom friction... not needed in tangent with lk_zdfcst_tan ! mixed layer depth... not needed in tangent with lk_zdfcst_tan !----------------------------------------------------------------------- ! LATERAL PHYSICS !----------------------------------------------------------------------- ! N.B. ua, va, ta, sa arrays are used as workspace in this section !----------------------------------------------------------------------- ! before slope of the lateral mixing... not needed in tangent with lk_zdfcst_tan #if defined key_traldf_c2d ! eddy induced velocity coefficient... not needed in tangent with lk_zdfcst_tan #endif #if defined key_top !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ! Passive Tracer Model !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ! N.B. ua, va, ta, sa arrays are used as workspace in this section !----------------------------------------------------------------------- ! time-stepping... not needed in tangent for the time being #endif ta (:,:,:) = zta_tmp (:,:,:) sa (:,:,:) = zsa_tmp (:,:,:) !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ! Active tracers !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ! N.B. ua, va arrays are used as workspace in this section !----------------------------------------------------------------------- ta_tl(:,:,:) = 0.e0 ! set tracer trends to zero sa_tl(:,:,:) = 0.e0 ! apply tracer assimilation increment ... not needed in tangent ! apply bias directly to tn, sn, tb, sb ... not needed in tangent CALL tra_sbc_tan( kstp ) ! surface boundary condition IF( ln_traqsr ) CALL tra_qsr_tan( kstp ) ! penetrative solar radiation qsr IF( lk_trabbc ) CALL tra_bbc_tan( kstp ) ! bottom heat flux ! diffusive bottom boundary layer scheme ... currently not available ! advective (and/or diffusive) bottom boundary layer scheme ... currently not available IF( lk_tradmp ) CALL tra_dmp_tan( kstp ) ! internal damping trends ! CALL tra_adv_tan( kstp ) ! horizontal & vertical advection ! IF( n_cla == 1 ) CALL tra_cla_tan( kstp ) ! Cross Land Advection (Update Hor. advection) !! IF( lk_zdfkpp ) CALL tra_kpp_tan( kstp ) ! KPP non-local tracer fluxes ! CALL tra_ldf_tan( kstp ) ! lateral mixing #if defined key_agrif ! tracers sponge ... not available #endif CALL tra_zdf_tan( kstp ) ! vertical mixing ! update the new (t,s) fields by non ! penetrative convective adjustment ... not available ! CALL tra_nxt_tan( kstp ) ! tracer fields at next time step IF( ln_dynhpg_imp ) THEN ! semi-implicit hpg CALL eos_tan( ta, sa, ta_tl, sa_tl, rhd_tl, rhop_tl ) ! Time-filtered in situ density used in dynhpg module IF( ln_zps ) CALL zps_hde_tan( kstp, ta, sa, ta_tl, sa_tl, rhd_tl,& ! Partial steps: time filtered hor. gradient & gtu_tl, gsu_tl, gru_tl, & ! of t, s, rd at the bottom ocean level & gtv_tl, gsv_tl, grv_tl ) ELSE ! centered hpg (default case) CALL eos_tan( tb, sb, tb_tl, sb_tl, rhd_tl, rhop_tl ) ! now (swap=before) in situ density for dynhpg module IF( ln_zps ) CALL zps_hde_tan( kstp, tb, sb, tb_tl, sb_tl, rhd_tl,& ! Partial steps: now horizontal gradient & gtu_tl, gsu_tl, gru_tl, & ! of t, s, rd at the bottom ocean level & gtv_tl, gsv_tl, grv_tl ) ENDIF !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ! Dynamics !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ! N.B. ta, sa arrays are used as workspace in this section !----------------------------------------------------------------------- ua_tl(:,:,:) = 0.e0 ! set dynamics trends to zero va_tl(:,:,:) = 0.e0 ! apply dynamics assimilation increment ... not needed in tangent CALL dyn_adv_tan( kstp ) ! advection (vector or flux form) CALL dyn_vor_tan( kstp ) ! vorticity term including Coriolis CALL dyn_ldf_tan( kstp ) ! lateral mixing #if defined key_agrif ! momemtum sponge ... not available #endif CALL dyn_hpg_tan( kstp ) ! horizontal gradient of Hydrostatic pressure CALL dyn_zdf_tan( kstp ) ! vertical diffusion !PRINT*,'dynspg' IF( lk_dynspg_rl ) THEN ! surface pressure gradient at open boundaries ... not available ENDIF indic=0 !i CALL dyn_spg_tan( kstp, indic ) ! surface pressure gradient CALL dyn_nxt_tan( kstp ) ! lateral velocity at next time step ! vertical mesh at next time step ... not available !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ! Computation of diagnostic variables !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ! N.B. ua, va, ta, sa arrays are used as workspace in this section !----------------------------------------------------------------------- CALL div_cur_tan( kstp ) ! Horizontal divergence & Relative vorticity IF( n_cla == 1 ) CALL div_cla_tan( kstp ) ! Cross Land Advection (Update Hor. divergence) CALL wzv_tan( kstp ) ! Vertical velocity CALL trj_rea( kstp, 1) ! ... Read basic state trajectory at end of current step !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ! Control, and restarts !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ! N.B. ua, va, ta, sa arrays are used as workspace in this section !----------------------------------------------------------------------- ! ! Time loop: control and print CALL stp_ctl_tan( kstp, indic, 0 ) IF( indic < 0 ) CALL ctl_stop( 'step_tan: indic < 0' ) ! close input ocean restart file ... not needed in tangent ! write output ocean restart file... not needed in tangent ! write open boundary restart file... not needed in tangent !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ! diagnostics and outputs !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ! N.B. ua, va, ta, sa arrays are used as workspace in this section !----------------------------------------------------------------------- IF ( nstop == 0 ) THEN ! Diagnostics ! drifting Floats... not needed in tangent ! trends: dynamics ... not needed in tangent ! trends: active tracers... not needed in tangent ! trends: Mixed-layer ... not needed in tangent ! trends: vorticity budget... not needed in tangent ! Surface pressure diagnostics... not needed in tangent ! Thermocline depth (20 degres isotherm depth)... not needed in tangent ! basin averaged diagnostics... not needed in tangent ! dynamical heigh diagnostics... not needed in tangent ! Fresh water budget diagnostics... not needed in tangent !!! IF( lk_diaobs ) CALL dia_obs_tan( kstp ) ! obs-minus-model (assimilation) diagnostics NOTE: may be better off outside this module ! Poleward TRansports diagnostics... not needed in tangent ! ! Outputs ! ocean model: outputs... not needed in tangent ENDIF !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ! Coupled mode !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ! coupled mode : field exchanges ... not available for the next 20 years ! END SUBROUTINE stp_tan_cpd #endif END MODULE step_tam_cpd