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.
dynspg.F90 in branches/UKMO/dev_r5518_GO6_under_ice_relax_dr_hook/NEMOGCM/NEMO/OPA_SRC/DYN – NEMO

source: branches/UKMO/dev_r5518_GO6_under_ice_relax_dr_hook/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg.F90 @ 11738

Last change on this file since 11738 was 11738, checked in by marc, 5 years ago

The Dr Hook changes from my perl code.

File size: 15.0 KB
Line 
1MODULE dynspg
2   !!======================================================================
3   !!                       ***  MODULE  dynspg  ***
4   !! Ocean dynamics:  surface pressure gradient control
5   !!======================================================================
6   !! History :  1.0  ! 2005-12  (C. Talandier, G. Madec, V. Garnier)  Original code
7   !!            3.2  ! 2009-07  (R. Benshila)  Suppression of rigid-lid option
8   !!----------------------------------------------------------------------
9
10   !!----------------------------------------------------------------------
11   !!   dyn_spg     : update the dynamics trend with the lateral diffusion
12   !!   dyn_spg_ctl : initialization, namelist read, and parameters control
13   !!----------------------------------------------------------------------
14   USE oce            ! ocean dynamics and tracers variables
15   USE dom_oce        ! ocean space and time domain variables
16   USE c1d            ! 1D vertical configuration
17   USE phycst         ! physical constants
18   USE sbc_oce        ! surface boundary condition: ocean
19   USE sbcapr         ! surface boundary condition: atmospheric pressure
20   USE dynspg_oce     ! surface pressure gradient variables
21   USE dynspg_exp     ! surface pressure gradient     (dyn_spg_exp routine)
22   USE dynspg_ts      ! surface pressure gradient     (dyn_spg_ts  routine)
23   USE dynspg_flt     ! surface pressure gradient     (dyn_spg_flt routine)
24   USE dynadv         ! dynamics: vector invariant versus flux form
25   USE dynhpg, ONLY: ln_dynhpg_imp
26   USE sbctide
27   USE updtide
28   USE trd_oce        ! trends: ocean variables
29   USE trddyn         ! trend manager: dynamics
30   !
31   USE prtctl         ! Print control                     (prt_ctl routine)
32   USE in_out_manager ! I/O manager
33   USE lib_mpp        ! MPP library
34   USE solver         ! solver initialization
35   USE wrk_nemo       ! Memory Allocation
36   USE timing         ! Timing
37
38
39   USE yomhook, ONLY: lhook, dr_hook
40   USE parkind1, ONLY: jprb, jpim
41
42   IMPLICIT NONE
43   PRIVATE
44
45   PUBLIC   dyn_spg        ! routine called by step module
46   PUBLIC   dyn_spg_init   ! routine called by opa module
47
48   INTEGER ::   nspg = 0   ! type of surface pressure gradient scheme defined from lk_dynspg_...
49
50   !! * Substitutions
51#  include "domzgr_substitute.h90"
52#  include "vectopt_loop_substitute.h90"
53   !!----------------------------------------------------------------------
54   !! NEMO/OPA 3.2 , LODYC-IPSL  (2009)
55   !! $Id$
56   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
57   !!----------------------------------------------------------------------
58CONTAINS
59
60   SUBROUTINE dyn_spg( kt, kindic )
61      !!----------------------------------------------------------------------
62      !!                  ***  ROUTINE dyn_spg  ***
63      !!
64      !! ** Purpose :   achieve the momentum time stepping by computing the
65      !!              last trend, the surface pressure gradient including the
66      !!              atmospheric pressure forcing (ln_apr_dyn=T), and performing
67      !!              the Leap-Frog integration.
68      !!gm              In the current version only the filtered solution provide
69      !!gm            the after velocity, in the 2 other (ua,va) are still the trends
70      !!
71      !! ** Method  :   Three schemes:
72      !!              - explicit computation      : the spg is evaluated at now
73      !!              - filtered computation      : the Roulet & madec (2000) technique is used
74      !!              - split-explicit computation: a time splitting technique is used
75      !!
76      !!              ln_apr_dyn=T : the atmospheric pressure forcing is applied
77      !!             as the gradient of the inverse barometer ssh:
78      !!                apgu = - 1/rau0 di[apr] = 0.5*grav di[ssh_ib+ssh_ibb]
79      !!                apgv = - 1/rau0 dj[apr] = 0.5*grav dj[ssh_ib+ssh_ibb]
80      !!             Note that as all external forcing a time averaging over a two rdt
81      !!             period is used to prevent the divergence of odd and even time step.
82      !!
83      !! N.B. : When key_esopa is used all the scheme are tested, regardless
84      !!        of the physical meaning of the results.
85      !!----------------------------------------------------------------------
86      !
87      INTEGER, INTENT(in   ) ::   kt       ! ocean time-step index
88      INTEGER, INTENT(  out) ::   kindic   ! solver flag
89      !
90      INTEGER  ::   ji, jj, jk                             ! dummy loop indices
91      REAL(wp) ::   z2dt, zg_2, zintp, zgrau0r             ! temporary scalar
92      REAL(wp), POINTER, DIMENSION(:,:,:) ::  ztrdu, ztrdv
93      REAL(wp), POINTER, DIMENSION(:,:)   ::  zpice
94      INTEGER(KIND=jpim), PARAMETER :: zhook_in = 0
95      INTEGER(KIND=jpim), PARAMETER :: zhook_out = 1
96      REAL(KIND=jprb)               :: zhook_handle
97
98      CHARACTER(LEN=*), PARAMETER :: RoutineName='DYN_SPG'
99
100      IF (lhook) CALL dr_hook(RoutineName,zhook_in,zhook_handle)
101
102      !!----------------------------------------------------------------------
103      !
104      IF( nn_timing == 1 )  CALL timing_start('dyn_spg')
105      !
106
107!!gm NOTA BENE : the dynspg_exp and dynspg_ts should be modified so that
108!!gm             they return the after velocity, not the trends (as in trazdf_imp...)
109!!gm             In this case, change/simplify dynnxt
110
111
112      IF( l_trddyn )   THEN                      ! temporary save of ta and sa trends
113         CALL wrk_alloc( jpi, jpj, jpk, ztrdu, ztrdv ) 
114         ztrdu(:,:,:) = ua(:,:,:)
115         ztrdv(:,:,:) = va(:,:,:)
116      ENDIF
117
118      IF(      ln_apr_dyn                                                &   ! atmos. pressure
119         .OR.  ( .NOT.lk_dynspg_ts .AND. (ln_tide_pot .AND. lk_tide) )   &   ! tide potential (no time slitting)
120         .OR.  nn_ice_embd == 2  ) THEN                                      ! embedded sea-ice
121         !
122         DO jj = 2, jpjm1
123            DO ji = fs_2, fs_jpim1   ! vector opt.
124               spgu(ji,jj) = 0._wp
125               spgv(ji,jj) = 0._wp
126            END DO
127         END DO         
128         !
129         IF( ln_apr_dyn .AND. (.NOT. lk_dynspg_ts) ) THEN                    !==  Atmospheric pressure gradient (added later in time-split case) ==!
130            zg_2 = grav * 0.5
131            DO jj = 2, jpjm1                          ! gradient of Patm using inverse barometer ssh
132               DO ji = fs_2, fs_jpim1   ! vector opt.
133                  spgu(ji,jj) = spgu(ji,jj) + zg_2 * (  ssh_ib (ji+1,jj) - ssh_ib (ji,jj)    &
134                     &                      + ssh_ibb(ji+1,jj) - ssh_ibb(ji,jj)  ) /e1u(ji,jj)
135                  spgv(ji,jj) = spgv(ji,jj) + zg_2 * (  ssh_ib (ji,jj+1) - ssh_ib (ji,jj)    &
136                     &                      + ssh_ibb(ji,jj+1) - ssh_ibb(ji,jj)  ) /e2v(ji,jj)
137               END DO
138            END DO
139         ENDIF
140         !
141         !                                    !==  tide potential forcing term  ==!
142         IF( .NOT.lk_dynspg_ts .AND. ( ln_tide_pot .AND. lk_tide )  ) THEN   ! N.B. added directly at sub-time-step in ts-case
143            !
144            CALL upd_tide( kt )                      ! update tide potential
145            !
146            DO jj = 2, jpjm1                         ! add tide potential forcing
147               DO ji = fs_2, fs_jpim1   ! vector opt.
148                  spgu(ji,jj) = spgu(ji,jj) + grav * ( pot_astro(ji+1,jj) - pot_astro(ji,jj) ) / e1u(ji,jj)
149                  spgv(ji,jj) = spgv(ji,jj) + grav * ( pot_astro(ji,jj+1) - pot_astro(ji,jj) ) / e2v(ji,jj)
150               END DO
151            END DO
152         ENDIF
153         !
154         IF( nn_ice_embd == 2 ) THEN          !== embedded sea ice: Pressure gradient due to snow-ice mass ==!
155            CALL wrk_alloc( jpi, jpj, zpice )
156            !                                           
157            zintp = REAL( MOD( kt-1, nn_fsbc ) ) / REAL( nn_fsbc )
158            zgrau0r     = - grav * r1_rau0
159            zpice(:,:) = (  zintp * snwice_mass(:,:) + ( 1.- zintp ) * snwice_mass_b(:,:)  ) * zgrau0r
160            DO jj = 2, jpjm1
161               DO ji = fs_2, fs_jpim1   ! vector opt.
162                  spgu(ji,jj) = spgu(ji,jj) + ( zpice(ji+1,jj) - zpice(ji,jj) ) / e1u(ji,jj)
163                  spgv(ji,jj) = spgv(ji,jj) + ( zpice(ji,jj+1) - zpice(ji,jj) ) / e2v(ji,jj)
164               END DO
165            END DO
166            !
167            CALL wrk_dealloc( jpi, jpj, zpice )         
168         ENDIF
169         !
170         DO jk = 1, jpkm1                     !== Add all terms to the general trend
171            DO jj = 2, jpjm1
172               DO ji = fs_2, fs_jpim1   ! vector opt.
173                  ua(ji,jj,jk) = ua(ji,jj,jk) + spgu(ji,jj)
174                  va(ji,jj,jk) = va(ji,jj,jk) + spgv(ji,jj)
175               END DO
176            END DO
177         END DO   
178         
179!!gm add here a call to dyn_trd for ice pressure gradient, the surf pressure trends ????
180             
181      ENDIF
182
183      SELECT CASE ( nspg )                       ! compute surf. pressure gradient trend and add it to the general trend
184      !                                                     
185      CASE (  0 )   ;   CALL dyn_spg_exp( kt )              ! explicit
186      CASE (  1 )   ;   CALL dyn_spg_ts ( kt )              ! time-splitting
187      CASE (  2 )   ;   CALL dyn_spg_flt( kt, kindic )      ! filtered
188      !                                                   
189      CASE ( -1 )                                ! esopa: test all possibility with control print
190                        CALL dyn_spg_exp( kt )
191                        CALL prt_ctl( tab3d_1=ua, clinfo1=' spg0 - Ua: ', mask1=umask, &
192         &                            tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
193                        CALL dyn_spg_ts ( kt )
194                        CALL prt_ctl( tab3d_1=ua, clinfo1=' spg1 - Ua: ', mask1=umask, &
195         &                           tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
196                        CALL dyn_spg_flt( kt, kindic )
197                        CALL prt_ctl( tab3d_1=ua, clinfo1=' spg2 - Ua: ', mask1=umask, &
198         &                            tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
199      END SELECT
200      !                   
201      IF( l_trddyn )   THEN                      ! save the surface pressure gradient trends for further diagnostics
202         SELECT CASE ( nspg )
203         CASE ( 0, 1 )
204            ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:)
205            ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
206         CASE( 2 )
207            z2dt = 2. * rdt
208            IF( neuler == 0 .AND. kt == nit000 )   z2dt = rdt
209            ztrdu(:,:,:) = ( ua(:,:,:) - ub(:,:,:) ) / z2dt - ztrdu(:,:,:)
210            ztrdv(:,:,:) = ( va(:,:,:) - vb(:,:,:) ) / z2dt - ztrdv(:,:,:)
211         END SELECT
212         CALL trd_dyn( ztrdu, ztrdv, jpdyn_spg, kt )
213         !
214         CALL wrk_dealloc( jpi, jpj, jpk, ztrdu, ztrdv ) 
215      ENDIF
216      !                                          ! print mean trends (used for debugging)
217      IF(ln_ctl)   CALL prt_ctl( tab3d_1=ua, clinfo1=' spg  - Ua: ', mask1=umask, &
218         &                       tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
219      !
220      IF( nn_timing == 1 )  CALL timing_stop('dyn_spg')
221      !
222      IF (lhook) CALL dr_hook(RoutineName,zhook_out,zhook_handle)
223   END SUBROUTINE dyn_spg
224
225
226   SUBROUTINE dyn_spg_init
227      !!---------------------------------------------------------------------
228      !!                  ***  ROUTINE dyn_spg_init  ***
229      !!               
230      !! ** Purpose :   Control the consistency between cpp options for
231      !!              surface pressure gradient schemes
232      !!----------------------------------------------------------------------
233      INTEGER ::   ioptio
234      INTEGER(KIND=jpim), PARAMETER :: zhook_in = 0
235      INTEGER(KIND=jpim), PARAMETER :: zhook_out = 1
236      REAL(KIND=jprb)               :: zhook_handle
237
238      CHARACTER(LEN=*), PARAMETER :: RoutineName='DYN_SPG_INIT'
239
240      IF (lhook) CALL dr_hook(RoutineName,zhook_in,zhook_handle)
241
242      !!----------------------------------------------------------------------
243      !
244      IF( nn_timing == 1 )  CALL timing_start('dyn_spg_init')
245      !
246      IF(lwp) THEN             ! Control print
247         WRITE(numout,*)
248         WRITE(numout,*) 'dyn_spg_init : choice of the surface pressure gradient scheme'
249         WRITE(numout,*) '~~~~~~~~~~~'
250         WRITE(numout,*) '     Explicit free surface                  lk_dynspg_exp = ', lk_dynspg_exp
251         WRITE(numout,*) '     Free surface with time splitting       lk_dynspg_ts  = ', lk_dynspg_ts
252         WRITE(numout,*) '     Filtered free surface cst volume       lk_dynspg_flt = ', lk_dynspg_flt
253      ENDIF
254
255      IF( lk_dynspg_ts ) CALL dyn_spg_ts_init( nit000 )
256      ! (do it now, to set nn_baro, used to allocate some arrays later on)
257      !                        ! allocate dyn_spg arrays
258      IF( lk_dynspg_ts ) THEN
259         IF( dynspg_oce_alloc() /= 0 )   CALL ctl_stop('STOP', 'dyn_spg_init: failed to allocate dynspg_oce arrays')
260         IF( dyn_spg_ts_alloc() /= 0 )   CALL ctl_stop('STOP', 'dyn_spg_init: failed to allocate dynspg_ts  arrays')
261         IF ((neuler/=0).AND.(ln_bt_fw)) CALL ts_rst( nit000, 'READ' )
262      ENDIF
263
264      !                        ! Control of surface pressure gradient scheme options
265      ioptio = 0
266      IF(lk_dynspg_exp)   ioptio = ioptio + 1
267      IF(lk_dynspg_ts )   ioptio = ioptio + 1
268      IF(lk_dynspg_flt)   ioptio = ioptio + 1
269      !
270      IF( ( ioptio > 1 .AND. .NOT. lk_esopa ) .OR. ( ioptio == 0 .AND. .NOT. lk_c1d ) )   &
271           &   CALL ctl_stop( ' Choose only one surface pressure gradient scheme with a key cpp' )
272      IF( ( lk_dynspg_ts .OR. lk_dynspg_exp ) .AND. ln_isfcav )   &
273           &   CALL ctl_stop( ' dynspg_ts and dynspg_exp not tested with ice shelf cavity ' )
274      !
275      IF( lk_esopa     )   nspg = -1
276      IF( lk_dynspg_exp)   nspg =  0
277      IF( lk_dynspg_ts )   nspg =  1
278      IF( lk_dynspg_flt)   nspg =  2
279      !
280      IF( lk_esopa     )   nspg = -1
281      !
282      IF(lwp) THEN
283         WRITE(numout,*)
284         IF( nspg == -1 )   WRITE(numout,*) '     ESOPA test All scheme used'
285         IF( nspg ==  0 )   WRITE(numout,*) '     explicit free surface'
286         IF( nspg ==  1 )   WRITE(numout,*) '     free surface with time splitting scheme'
287         IF( nspg ==  2 )   WRITE(numout,*) '     filtered free surface'
288      ENDIF
289
290#if defined key_dynspg_flt || defined key_esopa
291      CALL solver_init( nit000 )   ! Elliptic solver initialisation
292#endif
293
294      !                        ! Control of timestep choice
295      IF( lk_dynspg_ts .OR. lk_dynspg_exp ) THEN
296         IF( nn_cla == 1 )   CALL ctl_stop( 'Crossland advection not implemented for this free surface formulation' )
297      ENDIF
298
299      !               ! Control of hydrostatic pressure choice
300      IF( lk_dynspg_ts .AND. ln_dynhpg_imp ) THEN
301         CALL ctl_stop( 'Semi-implicit hpg not compatible with time splitting' )
302      ENDIF
303      !
304      IF( nn_timing == 1 )  CALL timing_stop('dyn_spg_init')
305      !
306      IF (lhook) CALL dr_hook(RoutineName,zhook_out,zhook_handle)
307   END SUBROUTINE dyn_spg_init
308
309  !!======================================================================
310END MODULE dynspg
Note: See TracBrowser for help on using the repository browser.