1 | MODULE dynhpg |
---|
2 | !!====================================================================== |
---|
3 | !! *** MODULE dynhpg *** |
---|
4 | !! Ocean dynamics: hydrostatic pressure gradient trend |
---|
5 | !!====================================================================== |
---|
6 | !! History : OPA ! 1987-09 (P. Andrich, M.-A. Foujols) hpg_zco: Original code |
---|
7 | !! 5.0 ! 1991-11 (G. Madec) |
---|
8 | !! 7.0 ! 1996-01 (G. Madec) hpg_sco: Original code for s-coordinates |
---|
9 | !! 8.0 ! 1997-05 (G. Madec) split dynber into dynkeg and dynhpg |
---|
10 | !! 8.5 ! 2002-07 (G. Madec) F90: Free form and module |
---|
11 | !! 8.5 ! 2002-08 (A. Bozec) hpg_zps: Original code |
---|
12 | !! NEMO 1.0 ! 2005-10 (A. Beckmann, B.W. An) various s-coordinate options |
---|
13 | !! ! Original code for hpg_ctl, hpg_hel hpg_wdj, hpg_djc, hpg_rot |
---|
14 | !! - ! 2005-11 (G. Madec) style & small optimisation |
---|
15 | !! 3.3 ! 2010-10 (C. Ethe, G. Madec) reorganisation of initialisation phase |
---|
16 | !! 3.4 ! 2011-11 (H. Liu) hpg_prj: Original code for s-coordinates |
---|
17 | !! ! (A. Coward) suppression of hel, wdj and rot options |
---|
18 | !! 3.6 ! 2014-11 (P. Mathiot) hpg_isf: original code for ice shelf cavity |
---|
19 | !!---------------------------------------------------------------------- |
---|
20 | |
---|
21 | !!---------------------------------------------------------------------- |
---|
22 | !! dyn_hpg : update the momentum trend with the now horizontal |
---|
23 | !! gradient of the hydrostatic pressure |
---|
24 | !! dyn_hpg_init : initialisation and control of options |
---|
25 | !! hpg_zco : z-coordinate scheme |
---|
26 | !! hpg_zps : z-coordinate plus partial steps (interpolation) |
---|
27 | !! hpg_sco : s-coordinate (standard jacobian formulation) |
---|
28 | !! hpg_isf : s-coordinate (sco formulation) adapted to ice shelf |
---|
29 | !! hpg_djc : s-coordinate (Density Jacobian with Cubic polynomial) |
---|
30 | !! hpg_prj : s-coordinate (Pressure Jacobian with Cubic polynomial) |
---|
31 | !!---------------------------------------------------------------------- |
---|
32 | USE oce ! ocean dynamics and tracers |
---|
33 | USE sbc_oce ! surface variable (only for the flag with ice shelf) |
---|
34 | USE dom_oce ! ocean space and time domain |
---|
35 | USE wet_dry ! wetting and drying |
---|
36 | USE phycst ! physical constants |
---|
37 | USE trd_oce ! trends: ocean variables |
---|
38 | USE trddyn ! trend manager: dynamics |
---|
39 | !jc USE zpshde ! partial step: hor. derivative (zps_hde routine) |
---|
40 | ! |
---|
41 | USE in_out_manager ! I/O manager |
---|
42 | USE prtctl ! Print control |
---|
43 | USE lbclnk ! lateral boundary condition |
---|
44 | USE lib_mpp ! MPP library |
---|
45 | USE eosbn2 ! compute density |
---|
46 | USE wrk_nemo ! Memory Allocation |
---|
47 | USE timing ! Timing |
---|
48 | USE iom |
---|
49 | |
---|
50 | IMPLICIT NONE |
---|
51 | PRIVATE |
---|
52 | |
---|
53 | PUBLIC dyn_hpg ! routine called by step module |
---|
54 | PUBLIC dyn_hpg_init ! routine called by opa module |
---|
55 | |
---|
56 | ! !!* Namelist namdyn_hpg : hydrostatic pressure gradient |
---|
57 | LOGICAL , PUBLIC :: ln_hpg_zco !: z-coordinate - full steps |
---|
58 | LOGICAL , PUBLIC :: ln_hpg_zps !: z-coordinate - partial steps (interpolation) |
---|
59 | LOGICAL , PUBLIC :: ln_hpg_sco !: s-coordinate (standard jacobian formulation) |
---|
60 | LOGICAL , PUBLIC :: ln_hpg_djc !: s-coordinate (Density Jacobian with Cubic polynomial) |
---|
61 | LOGICAL , PUBLIC :: ln_hpg_prj !: s-coordinate (Pressure Jacobian scheme) |
---|
62 | LOGICAL , PUBLIC :: ln_hpg_isf !: s-coordinate similar to sco modify for isf |
---|
63 | |
---|
64 | INTEGER , PUBLIC :: nhpg = 0 ! = 0 to 7, type of pressure gradient scheme used ! (deduced from ln_hpg_... flags) (PUBLIC for TAM) |
---|
65 | |
---|
66 | !! * Substitutions |
---|
67 | # include "vectopt_loop_substitute.h90" |
---|
68 | !!---------------------------------------------------------------------- |
---|
69 | !! NEMO/OPA 3.3 , NEMO Consortium (2010) |
---|
70 | !! $Id$ |
---|
71 | !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt) |
---|
72 | !!---------------------------------------------------------------------- |
---|
73 | CONTAINS |
---|
74 | |
---|
75 | SUBROUTINE dyn_hpg( kt ) |
---|
76 | !!--------------------------------------------------------------------- |
---|
77 | !! *** ROUTINE dyn_hpg *** |
---|
78 | !! |
---|
79 | !! ** Method : Call the hydrostatic pressure gradient routine |
---|
80 | !! using the scheme defined in the namelist |
---|
81 | !! |
---|
82 | !! ** Action : - Update (ua,va) with the now hydrastatic pressure trend |
---|
83 | !! - send trends to trd_dyn for futher diagnostics (l_trddyn=T) |
---|
84 | !!---------------------------------------------------------------------- |
---|
85 | INTEGER, INTENT(in) :: kt ! ocean time-step index |
---|
86 | REAL(wp), POINTER, DIMENSION(:,:,:) :: ztrdu, ztrdv |
---|
87 | !!---------------------------------------------------------------------- |
---|
88 | ! |
---|
89 | IF( nn_timing == 1 ) CALL timing_start('dyn_hpg') |
---|
90 | ! |
---|
91 | IF( l_trddyn ) THEN ! Temporary saving of ua and va trends (l_trddyn) |
---|
92 | CALL wrk_alloc( jpi,jpj,jpk, ztrdu, ztrdv ) |
---|
93 | ztrdu(:,:,:) = ua(:,:,:) |
---|
94 | ztrdv(:,:,:) = va(:,:,:) |
---|
95 | ENDIF |
---|
96 | ! |
---|
97 | SELECT CASE ( nhpg ) ! Hydrostatic pressure gradient computation |
---|
98 | CASE ( 0 ) ; CALL hpg_zco ( kt ) ! z-coordinate |
---|
99 | CASE ( 1 ) ; CALL hpg_zps ( kt ) ! z-coordinate plus partial steps (interpolation) |
---|
100 | CASE ( 2 ) ; CALL hpg_sco ( kt ) ! s-coordinate (standard jacobian formulation) |
---|
101 | CASE ( 3 ) ; CALL hpg_djc ( kt ) ! s-coordinate (Density Jacobian with Cubic polynomial) |
---|
102 | CASE ( 4 ) ; CALL hpg_prj ( kt ) ! s-coordinate (Pressure Jacobian scheme) |
---|
103 | CASE ( 5 ) ; CALL hpg_isf ( kt ) ! s-coordinate similar to sco modify for ice shelf |
---|
104 | END SELECT |
---|
105 | ! |
---|
106 | IF( l_trddyn ) THEN ! save the hydrostatic pressure gradient trends for momentum trend diagnostics |
---|
107 | ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:) |
---|
108 | ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:) |
---|
109 | CALL trd_dyn( ztrdu, ztrdv, jpdyn_hpg, kt ) |
---|
110 | CALL wrk_dealloc( jpi,jpj,jpk, ztrdu, ztrdv ) |
---|
111 | ENDIF |
---|
112 | ! |
---|
113 | IF(ln_ctl) CALL prt_ctl( tab3d_1=ua, clinfo1=' hpg - Ua: ', mask1=umask, & |
---|
114 | & tab3d_2=va, clinfo2= ' Va: ', mask2=vmask, clinfo3='dyn' ) |
---|
115 | ! |
---|
116 | IF( nn_timing == 1 ) CALL timing_stop('dyn_hpg') |
---|
117 | ! |
---|
118 | END SUBROUTINE dyn_hpg |
---|
119 | |
---|
120 | |
---|
121 | SUBROUTINE dyn_hpg_init |
---|
122 | !!---------------------------------------------------------------------- |
---|
123 | !! *** ROUTINE dyn_hpg_init *** |
---|
124 | !! |
---|
125 | !! ** Purpose : initializations for the hydrostatic pressure gradient |
---|
126 | !! computation and consistency control |
---|
127 | !! |
---|
128 | !! ** Action : Read the namelist namdyn_hpg and check the consistency |
---|
129 | !! with the type of vertical coordinate used (zco, zps, sco) |
---|
130 | !!---------------------------------------------------------------------- |
---|
131 | INTEGER :: ioptio = 0 ! temporary integer |
---|
132 | INTEGER :: ios ! Local integer output status for namelist read |
---|
133 | !! |
---|
134 | INTEGER :: ji, jj, jk, ikt ! dummy loop indices ISF |
---|
135 | REAL(wp) :: znad |
---|
136 | REAL(wp), POINTER, DIMENSION(:,:,:) :: ztstop, zrhd ! hypothesys on isf density |
---|
137 | REAL(wp), POINTER, DIMENSION(:,:) :: zrhdtop_isf ! density at bottom of ISF |
---|
138 | REAL(wp), POINTER, DIMENSION(:,:) :: ziceload ! density at bottom of ISF |
---|
139 | !! |
---|
140 | NAMELIST/namdyn_hpg/ ln_hpg_zco, ln_hpg_zps, ln_hpg_sco, & |
---|
141 | & ln_hpg_djc, ln_hpg_prj, ln_hpg_isf |
---|
142 | !!---------------------------------------------------------------------- |
---|
143 | ! |
---|
144 | REWIND( numnam_ref ) ! Namelist namdyn_hpg in reference namelist : Hydrostatic pressure gradient |
---|
145 | READ ( numnam_ref, namdyn_hpg, IOSTAT = ios, ERR = 901) |
---|
146 | 901 IF( ios /= 0 ) CALL ctl_nam ( ios , 'namdyn_hpg in reference namelist', lwp ) |
---|
147 | ! |
---|
148 | REWIND( numnam_cfg ) ! Namelist namdyn_hpg in configuration namelist : Hydrostatic pressure gradient |
---|
149 | READ ( numnam_cfg, namdyn_hpg, IOSTAT = ios, ERR = 902 ) |
---|
150 | 902 IF( ios /= 0 ) CALL ctl_nam ( ios , 'namdyn_hpg in configuration namelist', lwp ) |
---|
151 | IF(lwm) WRITE ( numond, namdyn_hpg ) |
---|
152 | ! |
---|
153 | IF(lwp) THEN ! Control print |
---|
154 | WRITE(numout,*) |
---|
155 | WRITE(numout,*) 'dyn_hpg_init : hydrostatic pressure gradient initialisation' |
---|
156 | WRITE(numout,*) '~~~~~~~~~~~~' |
---|
157 | WRITE(numout,*) ' Namelist namdyn_hpg : choice of hpg scheme' |
---|
158 | WRITE(numout,*) ' z-coord. - full steps ln_hpg_zco = ', ln_hpg_zco |
---|
159 | WRITE(numout,*) ' z-coord. - partial steps (interpolation) ln_hpg_zps = ', ln_hpg_zps |
---|
160 | WRITE(numout,*) ' s-coord. (standard jacobian formulation) ln_hpg_sco = ', ln_hpg_sco |
---|
161 | WRITE(numout,*) ' s-coord. (standard jacobian formulation) for isf ln_hpg_isf = ', ln_hpg_isf |
---|
162 | WRITE(numout,*) ' s-coord. (Density Jacobian: Cubic polynomial) ln_hpg_djc = ', ln_hpg_djc |
---|
163 | WRITE(numout,*) ' s-coord. (Pressure Jacobian: Cubic polynomial) ln_hpg_prj = ', ln_hpg_prj |
---|
164 | ENDIF |
---|
165 | ! |
---|
166 | IF( ln_hpg_djc ) & |
---|
167 | & CALL ctl_stop('dyn_hpg_init : Density Jacobian: Cubic polynominal method & |
---|
168 | & currently disabled (bugs under investigation). Please select & |
---|
169 | & either ln_hpg_sco or ln_hpg_prj instead') |
---|
170 | ! |
---|
171 | IF( .NOT.ln_linssh .AND. .NOT.(ln_hpg_sco.OR.ln_hpg_prj.OR.ln_hpg_isf) ) & |
---|
172 | & CALL ctl_stop('dyn_hpg_init : non-linear free surface requires either ', & |
---|
173 | & ' the standard jacobian formulation hpg_sco or ' , & |
---|
174 | & ' the pressure jacobian formulation hpg_prj' ) |
---|
175 | |
---|
176 | IF( ln_hpg_isf .AND. .NOT. ln_isfcav ) & |
---|
177 | & CALL ctl_stop( ' hpg_isf not available if ln_isfcav = false ' ) |
---|
178 | IF( .NOT. ln_hpg_isf .AND. ln_isfcav ) & |
---|
179 | & CALL ctl_stop( 'Only hpg_isf has been corrected to work with ice shelf cavity.' ) |
---|
180 | ! |
---|
181 | ! ! Set nhpg from ln_hpg_... flags |
---|
182 | IF( ln_hpg_zco ) nhpg = 0 |
---|
183 | IF( ln_hpg_zps ) nhpg = 1 |
---|
184 | IF( ln_hpg_sco ) nhpg = 2 |
---|
185 | IF( ln_hpg_djc ) nhpg = 3 |
---|
186 | IF( ln_hpg_prj ) nhpg = 4 |
---|
187 | IF( ln_hpg_isf ) nhpg = 5 |
---|
188 | ! |
---|
189 | ! ! Consistency check |
---|
190 | ioptio = 0 |
---|
191 | IF( ln_hpg_zco ) ioptio = ioptio + 1 |
---|
192 | IF( ln_hpg_zps ) ioptio = ioptio + 1 |
---|
193 | IF( ln_hpg_sco ) ioptio = ioptio + 1 |
---|
194 | IF( ln_hpg_djc ) ioptio = ioptio + 1 |
---|
195 | IF( ln_hpg_prj ) ioptio = ioptio + 1 |
---|
196 | IF( ln_hpg_isf ) ioptio = ioptio + 1 |
---|
197 | IF( ioptio /= 1 ) CALL ctl_stop( 'NO or several hydrostatic pressure gradient options used' ) |
---|
198 | ! |
---|
199 | ! initialisation of ice shelf load |
---|
200 | IF ( .NOT. ln_isfcav ) riceload(:,:)=0.0 |
---|
201 | IF ( ln_isfcav ) THEN |
---|
202 | CALL wrk_alloc( jpi,jpj, 2, ztstop) |
---|
203 | CALL wrk_alloc( jpi,jpj,jpk, zrhd ) |
---|
204 | CALL wrk_alloc( jpi,jpj, zrhdtop_isf, ziceload) |
---|
205 | ! |
---|
206 | IF(lwp) WRITE(numout,*) |
---|
207 | IF(lwp) WRITE(numout,*) 'dyn:hpg_isf : hydrostatic pressure gradient trend for ice shelf' |
---|
208 | IF(lwp) WRITE(numout,*) '~~~~~~~~~~~' |
---|
209 | |
---|
210 | ! To use density and not density anomaly |
---|
211 | znad=1._wp |
---|
212 | |
---|
213 | ! assume water displaced by the ice shelf is at T=-1.9 and S=34.4 (rude) |
---|
214 | ztstop(:,:,1)=-1.9_wp ; ztstop(:,:,2)=34.4_wp |
---|
215 | |
---|
216 | ! compute density of the water displaced by the ice shelf |
---|
217 | DO jk = 1, jpk |
---|
218 | CALL eos(ztstop(:,:,:),gdept_n(:,:,jk),zrhd(:,:,jk)) |
---|
219 | END DO |
---|
220 | |
---|
221 | ! compute rhd at the ice/oce interface (ice shelf side) |
---|
222 | CALL eos(ztstop,risfdep,zrhdtop_isf) |
---|
223 | |
---|
224 | ! Surface value + ice shelf gradient |
---|
225 | ! compute pressure due to ice shelf load (used to compute hpgi/j for all the level from 1 to miku/v) |
---|
226 | ! divided by 2 later |
---|
227 | ziceload = 0._wp |
---|
228 | DO jj = 1, jpj |
---|
229 | DO ji = 1, jpi |
---|
230 | ikt=mikt(ji,jj) |
---|
231 | ziceload(ji,jj) = ziceload(ji,jj) + (znad + zrhd(ji,jj,1) ) * e3w_n(ji,jj,1) * (1._wp - tmask(ji,jj,1)) |
---|
232 | DO jk=2,ikt-1 |
---|
233 | ziceload(ji,jj) = ziceload(ji,jj) + (2._wp * znad + zrhd(ji,jj,jk-1) + zrhd(ji,jj,jk)) * e3w_n(ji,jj,jk) & |
---|
234 | & * (1._wp - tmask(ji,jj,jk)) |
---|
235 | END DO |
---|
236 | IF (ikt >= 2) ziceload(ji,jj) = ziceload(ji,jj) + (2._wp * znad + zrhdtop_isf(ji,jj) + zrhd(ji,jj,ikt-1)) & |
---|
237 | & * ( risfdep(ji,jj) - gdept_1d(ikt-1) ) |
---|
238 | END DO |
---|
239 | END DO |
---|
240 | riceload(:,:)=ziceload(:,:) ! need to be saved for diaar5 |
---|
241 | |
---|
242 | CALL wrk_dealloc( jpi,jpj, 2, ztstop) |
---|
243 | CALL wrk_dealloc( jpi,jpj,jpk, zrhd ) |
---|
244 | CALL wrk_dealloc( jpi,jpj, zrhdtop_isf, ziceload) |
---|
245 | END IF |
---|
246 | ! |
---|
247 | END SUBROUTINE dyn_hpg_init |
---|
248 | |
---|
249 | |
---|
250 | SUBROUTINE hpg_zco( kt ) |
---|
251 | !!--------------------------------------------------------------------- |
---|
252 | !! *** ROUTINE hpg_zco *** |
---|
253 | !! |
---|
254 | !! ** Method : z-coordinate case, levels are horizontal surfaces. |
---|
255 | !! The now hydrostatic pressure gradient at a given level, jk, |
---|
256 | !! is computed by taking the vertical integral of the in-situ |
---|
257 | !! density gradient along the model level from the suface to that |
---|
258 | !! level: zhpi = grav ..... |
---|
259 | !! zhpj = grav ..... |
---|
260 | !! add it to the general momentum trend (ua,va). |
---|
261 | !! ua = ua - 1/e1u * zhpi |
---|
262 | !! va = va - 1/e2v * zhpj |
---|
263 | !! |
---|
264 | !! ** Action : - Update (ua,va) with the now hydrastatic pressure trend |
---|
265 | !!---------------------------------------------------------------------- |
---|
266 | INTEGER, INTENT(in) :: kt ! ocean time-step index |
---|
267 | ! |
---|
268 | INTEGER :: ji, jj, jk ! dummy loop indices |
---|
269 | REAL(wp) :: zcoef0, zcoef1 ! temporary scalars |
---|
270 | REAL(wp), POINTER, DIMENSION(:,:,:) :: zhpi, zhpj |
---|
271 | !!---------------------------------------------------------------------- |
---|
272 | ! |
---|
273 | CALL wrk_alloc( jpi,jpj,jpk, zhpi, zhpj ) |
---|
274 | ! |
---|
275 | IF( kt == nit000 ) THEN |
---|
276 | IF(lwp) WRITE(numout,*) |
---|
277 | IF(lwp) WRITE(numout,*) 'dyn:hpg_zco : hydrostatic pressure gradient trend' |
---|
278 | IF(lwp) WRITE(numout,*) '~~~~~~~~~~~ z-coordinate case ' |
---|
279 | ENDIF |
---|
280 | |
---|
281 | zcoef0 = - grav * 0.5_wp ! Local constant initialization |
---|
282 | |
---|
283 | ! Surface value |
---|
284 | DO jj = 2, jpjm1 |
---|
285 | DO ji = fs_2, fs_jpim1 ! vector opt. |
---|
286 | zcoef1 = zcoef0 * e3w_n(ji,jj,1) |
---|
287 | ! hydrostatic pressure gradient |
---|
288 | zhpi(ji,jj,1) = zcoef1 * ( rhd(ji+1,jj,1) - rhd(ji,jj,1) ) * r1_e1u(ji,jj) |
---|
289 | zhpj(ji,jj,1) = zcoef1 * ( rhd(ji,jj+1,1) - rhd(ji,jj,1) ) * r1_e2v(ji,jj) |
---|
290 | ! add to the general momentum trend |
---|
291 | ua(ji,jj,1) = ua(ji,jj,1) + zhpi(ji,jj,1) |
---|
292 | va(ji,jj,1) = va(ji,jj,1) + zhpj(ji,jj,1) |
---|
293 | END DO |
---|
294 | END DO |
---|
295 | |
---|
296 | ! |
---|
297 | ! interior value (2=<jk=<jpkm1) |
---|
298 | DO jk = 2, jpkm1 |
---|
299 | DO jj = 2, jpjm1 |
---|
300 | DO ji = fs_2, fs_jpim1 ! vector opt. |
---|
301 | zcoef1 = zcoef0 * e3w_n(ji,jj,jk) |
---|
302 | ! hydrostatic pressure gradient |
---|
303 | zhpi(ji,jj,jk) = zhpi(ji,jj,jk-1) & |
---|
304 | & + zcoef1 * ( ( rhd(ji+1,jj,jk)+rhd(ji+1,jj,jk-1) ) & |
---|
305 | & - ( rhd(ji ,jj,jk)+rhd(ji ,jj,jk-1) ) ) * r1_e1u(ji,jj) |
---|
306 | |
---|
307 | zhpj(ji,jj,jk) = zhpj(ji,jj,jk-1) & |
---|
308 | & + zcoef1 * ( ( rhd(ji,jj+1,jk)+rhd(ji,jj+1,jk-1) ) & |
---|
309 | & - ( rhd(ji,jj, jk)+rhd(ji,jj ,jk-1) ) ) * r1_e2v(ji,jj) |
---|
310 | ! add to the general momentum trend |
---|
311 | ua(ji,jj,jk) = ua(ji,jj,jk) + zhpi(ji,jj,jk) |
---|
312 | va(ji,jj,jk) = va(ji,jj,jk) + zhpj(ji,jj,jk) |
---|
313 | END DO |
---|
314 | END DO |
---|
315 | END DO |
---|
316 | ! |
---|
317 | CALL wrk_dealloc( jpi,jpj,jpk, zhpi, zhpj ) |
---|
318 | ! |
---|
319 | END SUBROUTINE hpg_zco |
---|
320 | |
---|
321 | |
---|
322 | SUBROUTINE hpg_zps( kt ) |
---|
323 | !!--------------------------------------------------------------------- |
---|
324 | !! *** ROUTINE hpg_zps *** |
---|
325 | !! |
---|
326 | !! ** Method : z-coordinate plus partial steps case. blahblah... |
---|
327 | !! |
---|
328 | !! ** Action : - Update (ua,va) with the now hydrastatic pressure trend |
---|
329 | !!---------------------------------------------------------------------- |
---|
330 | INTEGER, INTENT(in) :: kt ! ocean time-step index |
---|
331 | !! |
---|
332 | INTEGER :: ji, jj, jk ! dummy loop indices |
---|
333 | INTEGER :: iku, ikv ! temporary integers |
---|
334 | REAL(wp) :: zcoef0, zcoef1, zcoef2, zcoef3 ! temporary scalars |
---|
335 | REAL(wp), POINTER, DIMENSION(:,:,:) :: zhpi, zhpj |
---|
336 | !!---------------------------------------------------------------------- |
---|
337 | ! |
---|
338 | CALL wrk_alloc( jpi,jpj,jpk, zhpi, zhpj ) |
---|
339 | ! |
---|
340 | IF( kt == nit000 ) THEN |
---|
341 | IF(lwp) WRITE(numout,*) |
---|
342 | IF(lwp) WRITE(numout,*) 'dyn:hpg_zps : hydrostatic pressure gradient trend' |
---|
343 | IF(lwp) WRITE(numout,*) '~~~~~~~~~~~ z-coordinate with partial steps - vector optimization' |
---|
344 | ENDIF |
---|
345 | |
---|
346 | ! Partial steps: bottom before horizontal gradient of t, s, rd at the last ocean level |
---|
347 | !jc CALL zps_hde ( kt, jpts, tsn, gtsu, gtsv, rhd, gru , grv ) |
---|
348 | |
---|
349 | ! Local constant initialization |
---|
350 | zcoef0 = - grav * 0.5_wp |
---|
351 | |
---|
352 | ! Surface value (also valid in partial step case) |
---|
353 | DO jj = 2, jpjm1 |
---|
354 | DO ji = fs_2, fs_jpim1 ! vector opt. |
---|
355 | zcoef1 = zcoef0 * e3w_n(ji,jj,1) |
---|
356 | ! hydrostatic pressure gradient |
---|
357 | zhpi(ji,jj,1) = zcoef1 * ( rhd(ji+1,jj ,1) - rhd(ji,jj,1) ) * r1_e1u(ji,jj) |
---|
358 | zhpj(ji,jj,1) = zcoef1 * ( rhd(ji ,jj+1,1) - rhd(ji,jj,1) ) * r1_e2v(ji,jj) |
---|
359 | ! add to the general momentum trend |
---|
360 | ua(ji,jj,1) = ua(ji,jj,1) + zhpi(ji,jj,1) |
---|
361 | va(ji,jj,1) = va(ji,jj,1) + zhpj(ji,jj,1) |
---|
362 | END DO |
---|
363 | END DO |
---|
364 | |
---|
365 | ! interior value (2=<jk=<jpkm1) |
---|
366 | DO jk = 2, jpkm1 |
---|
367 | DO jj = 2, jpjm1 |
---|
368 | DO ji = fs_2, fs_jpim1 ! vector opt. |
---|
369 | zcoef1 = zcoef0 * e3w_n(ji,jj,jk) |
---|
370 | ! hydrostatic pressure gradient |
---|
371 | zhpi(ji,jj,jk) = zhpi(ji,jj,jk-1) & |
---|
372 | & + zcoef1 * ( ( rhd(ji+1,jj,jk) + rhd(ji+1,jj,jk-1) ) & |
---|
373 | & - ( rhd(ji ,jj,jk) + rhd(ji ,jj,jk-1) ) ) * r1_e1u(ji,jj) |
---|
374 | |
---|
375 | zhpj(ji,jj,jk) = zhpj(ji,jj,jk-1) & |
---|
376 | & + zcoef1 * ( ( rhd(ji,jj+1,jk) + rhd(ji,jj+1,jk-1) ) & |
---|
377 | & - ( rhd(ji,jj, jk) + rhd(ji,jj ,jk-1) ) ) * r1_e2v(ji,jj) |
---|
378 | ! add to the general momentum trend |
---|
379 | ua(ji,jj,jk) = ua(ji,jj,jk) + zhpi(ji,jj,jk) |
---|
380 | va(ji,jj,jk) = va(ji,jj,jk) + zhpj(ji,jj,jk) |
---|
381 | END DO |
---|
382 | END DO |
---|
383 | END DO |
---|
384 | |
---|
385 | ! partial steps correction at the last level (use gru & grv computed in zpshde.F90) |
---|
386 | DO jj = 2, jpjm1 |
---|
387 | DO ji = 2, jpim1 |
---|
388 | iku = mbku(ji,jj) |
---|
389 | ikv = mbkv(ji,jj) |
---|
390 | zcoef2 = zcoef0 * MIN( e3w_n(ji,jj,iku), e3w_n(ji+1,jj ,iku) ) |
---|
391 | zcoef3 = zcoef0 * MIN( e3w_n(ji,jj,ikv), e3w_n(ji ,jj+1,ikv) ) |
---|
392 | IF( iku > 1 ) THEN ! on i-direction (level 2 or more) |
---|
393 | ua (ji,jj,iku) = ua(ji,jj,iku) - zhpi(ji,jj,iku) ! subtract old value |
---|
394 | zhpi(ji,jj,iku) = zhpi(ji,jj,iku-1) & ! compute the new one |
---|
395 | & + zcoef2 * ( rhd(ji+1,jj,iku-1) - rhd(ji,jj,iku-1) + gru(ji,jj) ) * r1_e1u(ji,jj) |
---|
396 | ua (ji,jj,iku) = ua(ji,jj,iku) + zhpi(ji,jj,iku) ! add the new one to the general momentum trend |
---|
397 | ENDIF |
---|
398 | IF( ikv > 1 ) THEN ! on j-direction (level 2 or more) |
---|
399 | va (ji,jj,ikv) = va(ji,jj,ikv) - zhpj(ji,jj,ikv) ! subtract old value |
---|
400 | zhpj(ji,jj,ikv) = zhpj(ji,jj,ikv-1) & ! compute the new one |
---|
401 | & + zcoef3 * ( rhd(ji,jj+1,ikv-1) - rhd(ji,jj,ikv-1) + grv(ji,jj) ) * r1_e2v(ji,jj) |
---|
402 | va (ji,jj,ikv) = va(ji,jj,ikv) + zhpj(ji,jj,ikv) ! add the new one to the general momentum trend |
---|
403 | ENDIF |
---|
404 | END DO |
---|
405 | END DO |
---|
406 | ! |
---|
407 | CALL wrk_dealloc( jpi,jpj,jpk, zhpi, zhpj ) |
---|
408 | ! |
---|
409 | END SUBROUTINE hpg_zps |
---|
410 | |
---|
411 | |
---|
412 | SUBROUTINE hpg_sco( kt ) |
---|
413 | !!--------------------------------------------------------------------- |
---|
414 | !! *** ROUTINE hpg_sco *** |
---|
415 | !! |
---|
416 | !! ** Method : s-coordinate case. Jacobian scheme. |
---|
417 | !! The now hydrostatic pressure gradient at a given level, jk, |
---|
418 | !! is computed by taking the vertical integral of the in-situ |
---|
419 | !! density gradient along the model level from the suface to that |
---|
420 | !! level. s-coordinates (ln_sco): a corrective term is added |
---|
421 | !! to the horizontal pressure gradient : |
---|
422 | !! zhpi = grav ..... + 1/e1u mi(rhd) di[ grav dep3w ] |
---|
423 | !! zhpj = grav ..... + 1/e2v mj(rhd) dj[ grav dep3w ] |
---|
424 | !! add it to the general momentum trend (ua,va). |
---|
425 | !! ua = ua - 1/e1u * zhpi |
---|
426 | !! va = va - 1/e2v * zhpj |
---|
427 | !! |
---|
428 | !! ** Action : - Update (ua,va) with the now hydrastatic pressure trend |
---|
429 | !!---------------------------------------------------------------------- |
---|
430 | INTEGER, INTENT(in) :: kt ! ocean time-step index |
---|
431 | !! |
---|
432 | INTEGER :: ji, jj, jk, jii, jjj ! dummy loop indices |
---|
433 | REAL(wp) :: zcoef0, zuap, zvap, znad, ztmp ! temporary scalars |
---|
434 | LOGICAL :: ll_tmp1, ll_tmp2 ! local logical variables |
---|
435 | REAL(wp), POINTER, DIMENSION(:,:,:) :: zhpi, zhpj |
---|
436 | REAL(wp), POINTER, DIMENSION(:,:) :: zcpx, zcpy !W/D pressure filter |
---|
437 | !!---------------------------------------------------------------------- |
---|
438 | ! |
---|
439 | CALL wrk_alloc( jpi,jpj,jpk, zhpi, zhpj ) |
---|
440 | IF( ln_wd ) CALL wrk_alloc( jpi,jpj, zcpx, zcpy ) |
---|
441 | ! |
---|
442 | IF( kt == nit000 ) THEN |
---|
443 | IF(lwp) WRITE(numout,*) |
---|
444 | IF(lwp) WRITE(numout,*) 'dyn:hpg_sco : hydrostatic pressure gradient trend' |
---|
445 | IF(lwp) WRITE(numout,*) '~~~~~~~~~~~ s-coordinate case, OPA original scheme used' |
---|
446 | ENDIF |
---|
447 | ! |
---|
448 | zcoef0 = - grav * 0.5_wp |
---|
449 | IF ( ln_linssh ) THEN ; znad = 0._wp ! Fixed volume: density anomaly |
---|
450 | ELSE ; znad = 1._wp ! Variable volume: density |
---|
451 | ENDIF |
---|
452 | ! |
---|
453 | IF( ln_wd ) THEN |
---|
454 | DO jj = 2, jpjm1 |
---|
455 | DO ji = 2, jpim1 |
---|
456 | ll_tmp1 = MIN( sshn(ji,jj) , sshn(ji+1,jj) ) > & |
---|
457 | & MAX( -ht_wd(ji,jj) , -ht_wd(ji+1,jj) ) .AND. & |
---|
458 | & MAX( sshn(ji,jj) + ht_wd(ji,jj), sshn(ji+1,jj) + ht_wd(ji+1,jj) ) & |
---|
459 | & > rn_wdmin1 + rn_wdmin2 |
---|
460 | ll_tmp2 = ( ABS( sshn(ji,jj) - sshn(ji+1,jj) ) > 1.E-12 ) .AND. ( & |
---|
461 | & MAX( sshn(ji,jj) , sshn(ji+1,jj) ) > & |
---|
462 | & MAX( -ht_wd(ji,jj) , -ht_wd(ji+1,jj) ) + rn_wdmin1 + rn_wdmin2 ) |
---|
463 | |
---|
464 | IF(ll_tmp1) THEN |
---|
465 | zcpx(ji,jj) = 1.0_wp |
---|
466 | ELSE IF(ll_tmp2) THEN |
---|
467 | ! no worries about sshn(ji+1,jj) - sshn(ji ,jj) = 0, it won't happen ! here |
---|
468 | zcpx(ji,jj) = ABS( (sshn(ji+1,jj) + ht_wd(ji+1,jj) - sshn(ji,jj) - ht_wd(ji,jj)) & |
---|
469 | & / (sshn(ji+1,jj) - sshn(ji ,jj)) ) |
---|
470 | ELSE |
---|
471 | zcpx(ji,jj) = 0._wp |
---|
472 | END IF |
---|
473 | |
---|
474 | ll_tmp1 = MIN( sshn(ji,jj) , sshn(ji,jj+1) ) > & |
---|
475 | & MAX( -ht_wd(ji,jj) , -ht_wd(ji,jj+1) ) .AND. & |
---|
476 | & MAX( sshn(ji,jj) + ht_wd(ji,jj), sshn(ji,jj+1) + ht_wd(ji,jj+1) ) & |
---|
477 | & > rn_wdmin1 + rn_wdmin2 |
---|
478 | ll_tmp2 = ( ABS( sshn(ji,jj) - sshn(ji,jj+1) ) > 1.E-12 ) .AND. ( & |
---|
479 | & MAX( sshn(ji,jj) , sshn(ji,jj+1) ) > & |
---|
480 | & MAX( -ht_wd(ji,jj) , -ht_wd(ji,jj+1) ) + rn_wdmin1 + rn_wdmin2 ) |
---|
481 | |
---|
482 | IF(ll_tmp1) THEN |
---|
483 | zcpy(ji,jj) = 1.0_wp |
---|
484 | ELSE IF(ll_tmp2) THEN |
---|
485 | ! no worries about sshn(ji,jj+1) - sshn(ji,jj ) = 0, it won't happen ! here |
---|
486 | zcpy(ji,jj) = ABS( (sshn(ji,jj+1) + ht_wd(ji,jj+1) - sshn(ji,jj) - ht_wd(ji,jj)) & |
---|
487 | & / (sshn(ji,jj+1) - sshn(ji,jj )) ) |
---|
488 | ELSE |
---|
489 | zcpy(ji,jj) = 0._wp |
---|
490 | END IF |
---|
491 | END DO |
---|
492 | END DO |
---|
493 | CALL lbc_lnk( zcpx, 'U', 1._wp ) ; CALL lbc_lnk( zcpy, 'V', 1._wp ) |
---|
494 | END IF |
---|
495 | |
---|
496 | ! Surface value |
---|
497 | DO jj = 2, jpjm1 |
---|
498 | DO ji = fs_2, fs_jpim1 ! vector opt. |
---|
499 | ! hydrostatic pressure gradient along s-surfaces |
---|
500 | zhpi(ji,jj,1) = zcoef0 * ( e3w_n(ji+1,jj ,1) * ( znad + rhd(ji+1,jj ,1) ) & |
---|
501 | & - e3w_n(ji ,jj ,1) * ( znad + rhd(ji ,jj ,1) ) ) * r1_e1u(ji,jj) |
---|
502 | zhpj(ji,jj,1) = zcoef0 * ( e3w_n(ji ,jj+1,1) * ( znad + rhd(ji ,jj+1,1) ) & |
---|
503 | & - e3w_n(ji ,jj ,1) * ( znad + rhd(ji ,jj ,1) ) ) * r1_e2v(ji,jj) |
---|
504 | ! s-coordinate pressure gradient correction |
---|
505 | zuap = -zcoef0 * ( rhd (ji+1,jj,1) + rhd (ji,jj,1) + 2._wp * znad ) & |
---|
506 | & * ( gde3w_n(ji+1,jj,1) - gde3w_n(ji,jj,1) ) * r1_e1u(ji,jj) |
---|
507 | zvap = -zcoef0 * ( rhd (ji,jj+1,1) + rhd (ji,jj,1) + 2._wp * znad ) & |
---|
508 | & * ( gde3w_n(ji,jj+1,1) - gde3w_n(ji,jj,1) ) * r1_e2v(ji,jj) |
---|
509 | |
---|
510 | |
---|
511 | IF( ln_wd ) THEN |
---|
512 | |
---|
513 | zhpi(ji,jj,1) = zhpi(ji,jj,1) * zcpx(ji,jj) |
---|
514 | zhpj(ji,jj,1) = zhpj(ji,jj,1) * zcpy(ji,jj) |
---|
515 | zuap = zuap * zcpx(ji,jj) |
---|
516 | zvap = zvap * zcpy(ji,jj) |
---|
517 | ENDIF |
---|
518 | |
---|
519 | ! add to the general momentum trend |
---|
520 | ua(ji,jj,1) = ua(ji,jj,1) + zhpi(ji,jj,1) + zuap |
---|
521 | va(ji,jj,1) = va(ji,jj,1) + zhpj(ji,jj,1) + zvap |
---|
522 | END DO |
---|
523 | END DO |
---|
524 | |
---|
525 | ! interior value (2=<jk=<jpkm1) |
---|
526 | DO jk = 2, jpkm1 |
---|
527 | DO jj = 2, jpjm1 |
---|
528 | DO ji = fs_2, fs_jpim1 ! vector opt. |
---|
529 | ! hydrostatic pressure gradient along s-surfaces |
---|
530 | zhpi(ji,jj,jk) = zhpi(ji,jj,jk-1) + zcoef0 * r1_e1u(ji,jj) & |
---|
531 | & * ( e3w_n(ji+1,jj,jk) * ( rhd(ji+1,jj,jk) + rhd(ji+1,jj,jk-1) + 2*znad ) & |
---|
532 | & - e3w_n(ji ,jj,jk) * ( rhd(ji ,jj,jk) + rhd(ji ,jj,jk-1) + 2*znad ) ) |
---|
533 | zhpj(ji,jj,jk) = zhpj(ji,jj,jk-1) + zcoef0 * r1_e2v(ji,jj) & |
---|
534 | & * ( e3w_n(ji,jj+1,jk) * ( rhd(ji,jj+1,jk) + rhd(ji,jj+1,jk-1) + 2*znad ) & |
---|
535 | & - e3w_n(ji,jj ,jk) * ( rhd(ji,jj, jk) + rhd(ji,jj ,jk-1) + 2*znad ) ) |
---|
536 | ! s-coordinate pressure gradient correction |
---|
537 | zuap = -zcoef0 * ( rhd (ji+1,jj ,jk) + rhd (ji,jj,jk) + 2._wp * znad ) & |
---|
538 | & * ( gde3w_n(ji+1,jj ,jk) - gde3w_n(ji,jj,jk) ) * r1_e1u(ji,jj) |
---|
539 | zvap = -zcoef0 * ( rhd (ji ,jj+1,jk) + rhd (ji,jj,jk) + 2._wp * znad ) & |
---|
540 | & * ( gde3w_n(ji ,jj+1,jk) - gde3w_n(ji,jj,jk) ) * r1_e2v(ji,jj) |
---|
541 | |
---|
542 | IF( ln_wd ) THEN |
---|
543 | zhpi(ji,jj,jk) = zhpi(ji,jj,jk) * zcpx(ji,jj) |
---|
544 | zhpj(ji,jj,jk) = zhpj(ji,jj,jk) * zcpy(ji,jj) |
---|
545 | zuap = zuap * zcpx(ji,jj) |
---|
546 | zvap = zvap * zcpy(ji,jj) |
---|
547 | ENDIF |
---|
548 | |
---|
549 | ! add to the general momentum trend |
---|
550 | ua(ji,jj,jk) = ua(ji,jj,jk) + zhpi(ji,jj,jk) + zuap |
---|
551 | va(ji,jj,jk) = va(ji,jj,jk) + zhpj(ji,jj,jk) + zvap |
---|
552 | END DO |
---|
553 | END DO |
---|
554 | END DO |
---|
555 | ! |
---|
556 | CALL wrk_dealloc( jpi,jpj,jpk, zhpi, zhpj ) |
---|
557 | IF( ln_wd ) CALL wrk_dealloc( jpi,jpj, zcpx, zcpy ) |
---|
558 | ! |
---|
559 | END SUBROUTINE hpg_sco |
---|
560 | |
---|
561 | |
---|
562 | SUBROUTINE hpg_isf( kt ) |
---|
563 | !!--------------------------------------------------------------------- |
---|
564 | !! *** ROUTINE hpg_isf *** |
---|
565 | !! |
---|
566 | !! ** Method : s-coordinate case. Jacobian scheme. |
---|
567 | !! The now hydrostatic pressure gradient at a given level, jk, |
---|
568 | !! is computed by taking the vertical integral of the in-situ |
---|
569 | !! density gradient along the model level from the suface to that |
---|
570 | !! level. s-coordinates (ln_sco): a corrective term is added |
---|
571 | !! to the horizontal pressure gradient : |
---|
572 | !! zhpi = grav ..... + 1/e1u mi(rhd) di[ grav dep3w ] |
---|
573 | !! zhpj = grav ..... + 1/e2v mj(rhd) dj[ grav dep3w ] |
---|
574 | !! add it to the general momentum trend (ua,va). |
---|
575 | !! ua = ua - 1/e1u * zhpi |
---|
576 | !! va = va - 1/e2v * zhpj |
---|
577 | !! iceload is added and partial cell case are added to the top and bottom |
---|
578 | !! |
---|
579 | !! ** Action : - Update (ua,va) with the now hydrastatic pressure trend |
---|
580 | !!---------------------------------------------------------------------- |
---|
581 | INTEGER, INTENT(in) :: kt ! ocean time-step index |
---|
582 | !! |
---|
583 | INTEGER :: ji, jj, jk, ikt, iktp1i, iktp1j ! dummy loop indices |
---|
584 | REAL(wp) :: zcoef0, zuap, zvap, znad ! temporary scalars |
---|
585 | REAL(wp), POINTER, DIMENSION(:,:,:) :: zhpi, zhpj |
---|
586 | REAL(wp), POINTER, DIMENSION(:,:,:) :: ztstop |
---|
587 | REAL(wp), POINTER, DIMENSION(:,:) :: zrhdtop_oce |
---|
588 | !!---------------------------------------------------------------------- |
---|
589 | ! |
---|
590 | CALL wrk_alloc( jpi,jpj, 2, ztstop) |
---|
591 | CALL wrk_alloc( jpi,jpj,jpk, zhpi, zhpj) |
---|
592 | CALL wrk_alloc( jpi,jpj, zrhdtop_oce ) |
---|
593 | ! |
---|
594 | ! Local constant initialization |
---|
595 | zcoef0 = - grav * 0.5_wp |
---|
596 | |
---|
597 | ! To use density and not density anomaly |
---|
598 | znad=1._wp |
---|
599 | |
---|
600 | ! iniitialised to 0. zhpi zhpi |
---|
601 | zhpi(:,:,:)=0._wp ; zhpj(:,:,:)=0._wp |
---|
602 | |
---|
603 | ! compute rhd at the ice/oce interface (ocean side) |
---|
604 | ! usefull to reduce residual current in the test case ISOMIP with no melting |
---|
605 | DO ji=1,jpi |
---|
606 | DO jj=1,jpj |
---|
607 | ikt=mikt(ji,jj) |
---|
608 | ztstop(ji,jj,1)=tsn(ji,jj,ikt,1) |
---|
609 | ztstop(ji,jj,2)=tsn(ji,jj,ikt,2) |
---|
610 | END DO |
---|
611 | END DO |
---|
612 | CALL eos( ztstop, risfdep, zrhdtop_oce ) |
---|
613 | |
---|
614 | !================================================================================== |
---|
615 | !===== Compute surface value ===================================================== |
---|
616 | !================================================================================== |
---|
617 | DO jj = 2, jpjm1 |
---|
618 | DO ji = fs_2, fs_jpim1 ! vector opt. |
---|
619 | ikt = mikt(ji,jj) |
---|
620 | iktp1i = mikt(ji+1,jj) |
---|
621 | iktp1j = mikt(ji,jj+1) |
---|
622 | ! hydrostatic pressure gradient along s-surfaces and ice shelf pressure |
---|
623 | ! we assume ISF is in isostatic equilibrium |
---|
624 | zhpi(ji,jj,1) = zcoef0 / e1u(ji,jj) * ( 0.5_wp * e3w_n(ji+1,jj,iktp1i) & |
---|
625 | & * ( 2._wp * znad + rhd(ji+1,jj,iktp1i) + zrhdtop_oce(ji+1,jj) ) & |
---|
626 | & - 0.5_wp * e3w_n(ji,jj,ikt) & |
---|
627 | & * ( 2._wp * znad + rhd(ji,jj,ikt) + zrhdtop_oce(ji,jj) ) & |
---|
628 | & + ( riceload(ji+1,jj) - riceload(ji,jj)) ) |
---|
629 | zhpj(ji,jj,1) = zcoef0 / e2v(ji,jj) * ( 0.5_wp * e3w_n(ji,jj+1,iktp1j) & |
---|
630 | & * ( 2._wp * znad + rhd(ji,jj+1,iktp1j) + zrhdtop_oce(ji,jj+1) ) & |
---|
631 | & - 0.5_wp * e3w_n(ji,jj,ikt) & |
---|
632 | & * ( 2._wp * znad + rhd(ji,jj,ikt) + zrhdtop_oce(ji,jj) ) & |
---|
633 | & + ( riceload(ji,jj+1) - riceload(ji,jj)) ) |
---|
634 | ! s-coordinate pressure gradient correction (=0 if z coordinate) |
---|
635 | zuap = -zcoef0 * ( rhd (ji+1,jj,1) + rhd (ji,jj,1) + 2._wp * znad ) & |
---|
636 | & * ( gde3w_n(ji+1,jj,1) - gde3w_n(ji,jj,1) ) * r1_e1u(ji,jj) |
---|
637 | zvap = -zcoef0 * ( rhd (ji,jj+1,1) + rhd (ji,jj,1) + 2._wp * znad ) & |
---|
638 | & * ( gde3w_n(ji,jj+1,1) - gde3w_n(ji,jj,1) ) * r1_e2v(ji,jj) |
---|
639 | ! add to the general momentum trend |
---|
640 | ua(ji,jj,1) = ua(ji,jj,1) + (zhpi(ji,jj,1) + zuap) * umask(ji,jj,1) |
---|
641 | va(ji,jj,1) = va(ji,jj,1) + (zhpj(ji,jj,1) + zvap) * vmask(ji,jj,1) |
---|
642 | END DO |
---|
643 | END DO |
---|
644 | !================================================================================== |
---|
645 | !===== Compute interior value ===================================================== |
---|
646 | !================================================================================== |
---|
647 | ! interior value (2=<jk=<jpkm1) |
---|
648 | DO jk = 2, jpkm1 |
---|
649 | DO jj = 2, jpjm1 |
---|
650 | DO ji = fs_2, fs_jpim1 ! vector opt. |
---|
651 | ! hydrostatic pressure gradient along s-surfaces |
---|
652 | zhpi(ji,jj,jk) = zhpi(ji,jj,jk-1) + zcoef0 / e1u(ji,jj) & |
---|
653 | & * ( e3w_n(ji+1,jj,jk) * ( rhd(ji+1,jj,jk) + rhd(ji+1,jj,jk-1) + 2*znad ) * wmask(ji+1,jj,jk) & |
---|
654 | & - e3w_n(ji ,jj,jk) * ( rhd(ji ,jj,jk) + rhd(ji ,jj,jk-1) + 2*znad ) * wmask(ji ,jj,jk) ) |
---|
655 | zhpj(ji,jj,jk) = zhpj(ji,jj,jk-1) + zcoef0 / e2v(ji,jj) & |
---|
656 | & * ( e3w_n(ji,jj+1,jk) * ( rhd(ji,jj+1,jk) + rhd(ji,jj+1,jk-1) + 2*znad ) * wmask(ji,jj+1,jk) & |
---|
657 | & - e3w_n(ji,jj ,jk) * ( rhd(ji,jj, jk) + rhd(ji,jj ,jk-1) + 2*znad ) * wmask(ji,jj ,jk) ) |
---|
658 | ! s-coordinate pressure gradient correction |
---|
659 | zuap = -zcoef0 * ( rhd (ji+1,jj ,jk) + rhd (ji,jj,jk) + 2._wp * znad ) & |
---|
660 | & * ( gde3w_n(ji+1,jj ,jk) - gde3w_n(ji,jj,jk) ) / e1u(ji,jj) |
---|
661 | zvap = -zcoef0 * ( rhd (ji ,jj+1,jk) + rhd (ji,jj,jk) + 2._wp * znad ) & |
---|
662 | & * ( gde3w_n(ji ,jj+1,jk) - gde3w_n(ji,jj,jk) ) / e2v(ji,jj) |
---|
663 | ! add to the general momentum trend |
---|
664 | ua(ji,jj,jk) = ua(ji,jj,jk) + (zhpi(ji,jj,jk) + zuap) * umask(ji,jj,jk) |
---|
665 | va(ji,jj,jk) = va(ji,jj,jk) + (zhpj(ji,jj,jk) + zvap) * vmask(ji,jj,jk) |
---|
666 | END DO |
---|
667 | END DO |
---|
668 | END DO |
---|
669 | ! |
---|
670 | CALL wrk_dealloc( jpi,jpj,2 , ztstop) |
---|
671 | CALL wrk_dealloc( jpi,jpj,jpk, zhpi, zhpj) |
---|
672 | CALL wrk_dealloc( jpi,jpj , zrhdtop_oce ) |
---|
673 | ! |
---|
674 | END SUBROUTINE hpg_isf |
---|
675 | |
---|
676 | |
---|
677 | SUBROUTINE hpg_djc( kt ) |
---|
678 | !!--------------------------------------------------------------------- |
---|
679 | !! *** ROUTINE hpg_djc *** |
---|
680 | !! |
---|
681 | !! ** Method : Density Jacobian with Cubic polynomial scheme |
---|
682 | !! |
---|
683 | !! Reference: Shchepetkin and McWilliams, J. Geophys. Res., 108(C3), 3090, 2003 |
---|
684 | !!---------------------------------------------------------------------- |
---|
685 | INTEGER, INTENT(in) :: kt ! ocean time-step index |
---|
686 | !! |
---|
687 | INTEGER :: ji, jj, jk ! dummy loop indices |
---|
688 | REAL(wp) :: zcoef0, zep, cffw ! temporary scalars |
---|
689 | REAL(wp) :: z1_10, cffu, cffx ! " " |
---|
690 | REAL(wp) :: z1_12, cffv, cffy ! " " |
---|
691 | LOGICAL :: ll_tmp1, ll_tmp2 ! local logical variables |
---|
692 | REAL(wp), POINTER, DIMENSION(:,:,:) :: zhpi, zhpj |
---|
693 | REAL(wp), POINTER, DIMENSION(:,:,:) :: dzx, dzy, dzz, dzu, dzv, dzw |
---|
694 | REAL(wp), POINTER, DIMENSION(:,:,:) :: drhox, drhoy, drhoz, drhou, drhov, drhow |
---|
695 | REAL(wp), POINTER, DIMENSION(:,:,:) :: rho_i, rho_j, rho_k |
---|
696 | REAL(wp), POINTER, DIMENSION(:,:) :: zcpx, zcpy !W/D pressure filter |
---|
697 | !!---------------------------------------------------------------------- |
---|
698 | ! |
---|
699 | CALL wrk_alloc( jpi, jpj, jpk, dzx , dzy , dzz , dzu , dzv , dzw ) |
---|
700 | CALL wrk_alloc( jpi, jpj, jpk, drhox, drhoy, drhoz, drhou, drhov, drhow ) |
---|
701 | CALL wrk_alloc( jpi, jpj, jpk, rho_i, rho_j, rho_k, zhpi, zhpj ) |
---|
702 | IF( ln_wd ) CALL wrk_alloc( jpi,jpj, zcpx, zcpy ) |
---|
703 | ! |
---|
704 | ! |
---|
705 | IF( ln_wd ) THEN |
---|
706 | DO jj = 2, jpjm1 |
---|
707 | DO ji = 2, jpim1 |
---|
708 | ll_tmp1 = MIN( sshn(ji,jj) , sshn(ji+1,jj) ) > & |
---|
709 | & MAX( -ht_wd(ji,jj) , -ht_wd(ji+1,jj) ) .AND. & |
---|
710 | & MAX( sshn(ji,jj) + ht_wd(ji,jj), sshn(ji+1,jj) + ht_wd(ji+1,jj) ) & |
---|
711 | & > rn_wdmin1 + rn_wdmin2 |
---|
712 | ll_tmp2 = ( ABS( sshn(ji,jj) - sshn(ji+1,jj) ) > 1.E-12 ) .AND. ( & |
---|
713 | & MAX( sshn(ji,jj) , sshn(ji+1,jj) ) > & |
---|
714 | & MAX( -ht_wd(ji,jj) , -ht_wd(ji+1,jj) ) + rn_wdmin1 + rn_wdmin2 ) |
---|
715 | |
---|
716 | IF(ll_tmp1) THEN |
---|
717 | zcpx(ji,jj) = 1.0_wp |
---|
718 | ELSE IF(ll_tmp2) THEN |
---|
719 | ! no worries about sshn(ji+1,jj) - sshn(ji ,jj) = 0, it won't happen ! here |
---|
720 | zcpx(ji,jj) = ABS( (sshn(ji+1,jj) + ht_wd(ji+1,jj) - sshn(ji,jj) - ht_wd(ji,jj)) & |
---|
721 | & / (sshn(ji+1,jj) - sshn(ji ,jj)) ) |
---|
722 | ELSE |
---|
723 | zcpx(ji,jj) = 0._wp |
---|
724 | END IF |
---|
725 | |
---|
726 | ll_tmp1 = MIN( sshn(ji,jj) , sshn(ji,jj+1) ) > & |
---|
727 | & MAX( -ht_wd(ji,jj) , -ht_wd(ji,jj+1) ) .AND. & |
---|
728 | & MAX( sshn(ji,jj) + ht_wd(ji,jj), sshn(ji,jj+1) + ht_wd(ji,jj+1) ) & |
---|
729 | & > rn_wdmin1 + rn_wdmin2 |
---|
730 | ll_tmp2 = ( ABS( sshn(ji,jj) - sshn(ji,jj+1) ) > 1.E-12 ) .AND. ( & |
---|
731 | & MAX( sshn(ji,jj) , sshn(ji,jj+1) ) > & |
---|
732 | & MAX( -ht_wd(ji,jj) , -ht_wd(ji,jj+1) ) + rn_wdmin1 + rn_wdmin2 ) |
---|
733 | |
---|
734 | IF(ll_tmp1) THEN |
---|
735 | zcpy(ji,jj) = 1.0_wp |
---|
736 | ELSE IF(ll_tmp2) THEN |
---|
737 | ! no worries about sshn(ji,jj+1) - sshn(ji,jj ) = 0, it won't happen ! here |
---|
738 | zcpy(ji,jj) = ABS( (sshn(ji,jj+1) + ht_wd(ji,jj+1) - sshn(ji,jj) - ht_wd(ji,jj)) & |
---|
739 | & / (sshn(ji,jj+1) - sshn(ji,jj )) ) |
---|
740 | ELSE |
---|
741 | zcpy(ji,jj) = 0._wp |
---|
742 | END IF |
---|
743 | END DO |
---|
744 | END DO |
---|
745 | CALL lbc_lnk( zcpx, 'U', 1._wp ) ; CALL lbc_lnk( zcpy, 'V', 1._wp ) |
---|
746 | END IF |
---|
747 | |
---|
748 | IF( kt == nit000 ) THEN |
---|
749 | IF(lwp) WRITE(numout,*) |
---|
750 | IF(lwp) WRITE(numout,*) 'dyn:hpg_djc : hydrostatic pressure gradient trend' |
---|
751 | IF(lwp) WRITE(numout,*) '~~~~~~~~~~~ s-coordinate case, density Jacobian with cubic polynomial scheme' |
---|
752 | ENDIF |
---|
753 | |
---|
754 | ! Local constant initialization |
---|
755 | zcoef0 = - grav * 0.5_wp |
---|
756 | z1_10 = 1._wp / 10._wp |
---|
757 | z1_12 = 1._wp / 12._wp |
---|
758 | |
---|
759 | !---------------------------------------------------------------------------------------- |
---|
760 | ! compute and store in provisional arrays elementary vertical and horizontal differences |
---|
761 | !---------------------------------------------------------------------------------------- |
---|
762 | |
---|
763 | !!bug gm Not a true bug, but... dzz=e3w for dzx, dzy verify what it is really |
---|
764 | |
---|
765 | DO jk = 2, jpkm1 |
---|
766 | DO jj = 2, jpjm1 |
---|
767 | DO ji = fs_2, fs_jpim1 ! vector opt. |
---|
768 | drhoz(ji,jj,jk) = rhd (ji ,jj ,jk) - rhd (ji,jj,jk-1) |
---|
769 | dzz (ji,jj,jk) = gde3w_n(ji ,jj ,jk) - gde3w_n(ji,jj,jk-1) |
---|
770 | drhox(ji,jj,jk) = rhd (ji+1,jj ,jk) - rhd (ji,jj,jk ) |
---|
771 | dzx (ji,jj,jk) = gde3w_n(ji+1,jj ,jk) - gde3w_n(ji,jj,jk ) |
---|
772 | drhoy(ji,jj,jk) = rhd (ji ,jj+1,jk) - rhd (ji,jj,jk ) |
---|
773 | dzy (ji,jj,jk) = gde3w_n(ji ,jj+1,jk) - gde3w_n(ji,jj,jk ) |
---|
774 | END DO |
---|
775 | END DO |
---|
776 | END DO |
---|
777 | |
---|
778 | !------------------------------------------------------------------------- |
---|
779 | ! compute harmonic averages using eq. 5.18 |
---|
780 | !------------------------------------------------------------------------- |
---|
781 | zep = 1.e-15 |
---|
782 | |
---|
783 | !!bug gm drhoz not defined at level 1 and used (jk-1 with jk=2) |
---|
784 | !!bug gm idem for drhox, drhoy et ji=jpi and jj=jpj |
---|
785 | |
---|
786 | DO jk = 2, jpkm1 |
---|
787 | DO jj = 2, jpjm1 |
---|
788 | DO ji = fs_2, fs_jpim1 ! vector opt. |
---|
789 | cffw = 2._wp * drhoz(ji ,jj ,jk) * drhoz(ji,jj,jk-1) |
---|
790 | |
---|
791 | cffu = 2._wp * drhox(ji+1,jj ,jk) * drhox(ji,jj,jk ) |
---|
792 | cffx = 2._wp * dzx (ji+1,jj ,jk) * dzx (ji,jj,jk ) |
---|
793 | |
---|
794 | cffv = 2._wp * drhoy(ji ,jj+1,jk) * drhoy(ji,jj,jk ) |
---|
795 | cffy = 2._wp * dzy (ji ,jj+1,jk) * dzy (ji,jj,jk ) |
---|
796 | |
---|
797 | IF( cffw > zep) THEN |
---|
798 | drhow(ji,jj,jk) = 2._wp * drhoz(ji,jj,jk) * drhoz(ji,jj,jk-1) & |
---|
799 | & / ( drhoz(ji,jj,jk) + drhoz(ji,jj,jk-1) ) |
---|
800 | ELSE |
---|
801 | drhow(ji,jj,jk) = 0._wp |
---|
802 | ENDIF |
---|
803 | |
---|
804 | dzw(ji,jj,jk) = 2._wp * dzz(ji,jj,jk) * dzz(ji,jj,jk-1) & |
---|
805 | & / ( dzz(ji,jj,jk) + dzz(ji,jj,jk-1) ) |
---|
806 | |
---|
807 | IF( cffu > zep ) THEN |
---|
808 | drhou(ji,jj,jk) = 2._wp * drhox(ji+1,jj,jk) * drhox(ji,jj,jk) & |
---|
809 | & / ( drhox(ji+1,jj,jk) + drhox(ji,jj,jk) ) |
---|
810 | ELSE |
---|
811 | drhou(ji,jj,jk ) = 0._wp |
---|
812 | ENDIF |
---|
813 | |
---|
814 | IF( cffx > zep ) THEN |
---|
815 | dzu(ji,jj,jk) = 2._wp * dzx(ji+1,jj,jk) * dzx(ji,jj,jk) & |
---|
816 | & / ( dzx(ji+1,jj,jk) + dzx(ji,jj,jk) ) |
---|
817 | ELSE |
---|
818 | dzu(ji,jj,jk) = 0._wp |
---|
819 | ENDIF |
---|
820 | |
---|
821 | IF( cffv > zep ) THEN |
---|
822 | drhov(ji,jj,jk) = 2._wp * drhoy(ji,jj+1,jk) * drhoy(ji,jj,jk) & |
---|
823 | & / ( drhoy(ji,jj+1,jk) + drhoy(ji,jj,jk) ) |
---|
824 | ELSE |
---|
825 | drhov(ji,jj,jk) = 0._wp |
---|
826 | ENDIF |
---|
827 | |
---|
828 | IF( cffy > zep ) THEN |
---|
829 | dzv(ji,jj,jk) = 2._wp * dzy(ji,jj+1,jk) * dzy(ji,jj,jk) & |
---|
830 | & / ( dzy(ji,jj+1,jk) + dzy(ji,jj,jk) ) |
---|
831 | ELSE |
---|
832 | dzv(ji,jj,jk) = 0._wp |
---|
833 | ENDIF |
---|
834 | |
---|
835 | END DO |
---|
836 | END DO |
---|
837 | END DO |
---|
838 | |
---|
839 | !---------------------------------------------------------------------------------- |
---|
840 | ! apply boundary conditions at top and bottom using 5.36-5.37 |
---|
841 | !---------------------------------------------------------------------------------- |
---|
842 | drhow(:,:, 1 ) = 1.5_wp * ( drhoz(:,:, 2 ) - drhoz(:,:, 1 ) ) - 0.5_wp * drhow(:,:, 2 ) |
---|
843 | drhou(:,:, 1 ) = 1.5_wp * ( drhox(:,:, 2 ) - drhox(:,:, 1 ) ) - 0.5_wp * drhou(:,:, 2 ) |
---|
844 | drhov(:,:, 1 ) = 1.5_wp * ( drhoy(:,:, 2 ) - drhoy(:,:, 1 ) ) - 0.5_wp * drhov(:,:, 2 ) |
---|
845 | |
---|
846 | drhow(:,:,jpk) = 1.5_wp * ( drhoz(:,:,jpk) - drhoz(:,:,jpkm1) ) - 0.5_wp * drhow(:,:,jpkm1) |
---|
847 | drhou(:,:,jpk) = 1.5_wp * ( drhox(:,:,jpk) - drhox(:,:,jpkm1) ) - 0.5_wp * drhou(:,:,jpkm1) |
---|
848 | drhov(:,:,jpk) = 1.5_wp * ( drhoy(:,:,jpk) - drhoy(:,:,jpkm1) ) - 0.5_wp * drhov(:,:,jpkm1) |
---|
849 | |
---|
850 | |
---|
851 | !-------------------------------------------------------------- |
---|
852 | ! Upper half of top-most grid box, compute and store |
---|
853 | !------------------------------------------------------------- |
---|
854 | |
---|
855 | !!bug gm : e3w-gde3w = 0.5*e3w .... and gde3w(2)-gde3w(1)=e3w(2) .... to be verified |
---|
856 | ! true if gde3w is really defined as the sum of the e3w scale factors as, it seems to me, it should be |
---|
857 | |
---|
858 | DO jj = 2, jpjm1 |
---|
859 | DO ji = fs_2, fs_jpim1 ! vector opt. |
---|
860 | rho_k(ji,jj,1) = -grav * ( e3w_n(ji,jj,1) - gde3w_n(ji,jj,1) ) & |
---|
861 | & * ( rhd(ji,jj,1) & |
---|
862 | & + 0.5_wp * ( rhd (ji,jj,2) - rhd (ji,jj,1) ) & |
---|
863 | & * ( e3w_n (ji,jj,1) - gde3w_n(ji,jj,1) ) & |
---|
864 | & / ( gde3w_n(ji,jj,2) - gde3w_n(ji,jj,1) ) ) |
---|
865 | END DO |
---|
866 | END DO |
---|
867 | |
---|
868 | !!bug gm : here also, simplification is possible |
---|
869 | !!bug gm : optimisation: 1/10 and 1/12 the division should be done before the loop |
---|
870 | |
---|
871 | DO jk = 2, jpkm1 |
---|
872 | DO jj = 2, jpjm1 |
---|
873 | DO ji = fs_2, fs_jpim1 ! vector opt. |
---|
874 | |
---|
875 | rho_k(ji,jj,jk) = zcoef0 * ( rhd (ji,jj,jk) + rhd (ji,jj,jk-1) ) & |
---|
876 | & * ( gde3w_n(ji,jj,jk) - gde3w_n(ji,jj,jk-1) ) & |
---|
877 | & - grav * z1_10 * ( & |
---|
878 | & ( drhow (ji,jj,jk) - drhow (ji,jj,jk-1) ) & |
---|
879 | & * ( gde3w_n(ji,jj,jk) - gde3w_n(ji,jj,jk-1) - z1_12 * ( dzw (ji,jj,jk) + dzw (ji,jj,jk-1) ) ) & |
---|
880 | & - ( dzw (ji,jj,jk) - dzw (ji,jj,jk-1) ) & |
---|
881 | & * ( rhd (ji,jj,jk) - rhd (ji,jj,jk-1) - z1_12 * ( drhow(ji,jj,jk) + drhow(ji,jj,jk-1) ) ) & |
---|
882 | & ) |
---|
883 | |
---|
884 | rho_i(ji,jj,jk) = zcoef0 * ( rhd (ji+1,jj,jk) + rhd (ji,jj,jk) ) & |
---|
885 | & * ( gde3w_n(ji+1,jj,jk) - gde3w_n(ji,jj,jk) ) & |
---|
886 | & - grav* z1_10 * ( & |
---|
887 | & ( drhou (ji+1,jj,jk) - drhou (ji,jj,jk) ) & |
---|
888 | & * ( gde3w_n(ji+1,jj,jk) - gde3w_n(ji,jj,jk) - z1_12 * ( dzu (ji+1,jj,jk) + dzu (ji,jj,jk) ) ) & |
---|
889 | & - ( dzu (ji+1,jj,jk) - dzu (ji,jj,jk) ) & |
---|
890 | & * ( rhd (ji+1,jj,jk) - rhd (ji,jj,jk) - z1_12 * ( drhou(ji+1,jj,jk) + drhou(ji,jj,jk) ) ) & |
---|
891 | & ) |
---|
892 | |
---|
893 | rho_j(ji,jj,jk) = zcoef0 * ( rhd (ji,jj+1,jk) + rhd (ji,jj,jk) ) & |
---|
894 | & * ( gde3w_n(ji,jj+1,jk) - gde3w_n(ji,jj,jk) ) & |
---|
895 | & - grav* z1_10 * ( & |
---|
896 | & ( drhov (ji,jj+1,jk) - drhov (ji,jj,jk) ) & |
---|
897 | & * ( gde3w_n(ji,jj+1,jk) - gde3w_n(ji,jj,jk) - z1_12 * ( dzv (ji,jj+1,jk) + dzv (ji,jj,jk) ) ) & |
---|
898 | & - ( dzv (ji,jj+1,jk) - dzv (ji,jj,jk) ) & |
---|
899 | & * ( rhd (ji,jj+1,jk) - rhd (ji,jj,jk) - z1_12 * ( drhov(ji,jj+1,jk) + drhov(ji,jj,jk) ) ) & |
---|
900 | & ) |
---|
901 | |
---|
902 | END DO |
---|
903 | END DO |
---|
904 | END DO |
---|
905 | CALL lbc_lnk(rho_k,'W',1.) |
---|
906 | CALL lbc_lnk(rho_i,'U',1.) |
---|
907 | CALL lbc_lnk(rho_j,'V',1.) |
---|
908 | |
---|
909 | |
---|
910 | ! --------------- |
---|
911 | ! Surface value |
---|
912 | ! --------------- |
---|
913 | DO jj = 2, jpjm1 |
---|
914 | DO ji = fs_2, fs_jpim1 ! vector opt. |
---|
915 | zhpi(ji,jj,1) = ( rho_k(ji+1,jj ,1) - rho_k(ji,jj,1) - rho_i(ji,jj,1) ) * r1_e1u(ji,jj) |
---|
916 | zhpj(ji,jj,1) = ( rho_k(ji ,jj+1,1) - rho_k(ji,jj,1) - rho_j(ji,jj,1) ) * r1_e2v(ji,jj) |
---|
917 | IF( ln_wd ) THEN |
---|
918 | zhpi(ji,jj,1) = zhpi(ji,jj,1) * zcpx(ji,jj) |
---|
919 | zhpj(ji,jj,1) = zhpj(ji,jj,1) * zcpy(ji,jj) |
---|
920 | ENDIF |
---|
921 | ! add to the general momentum trend |
---|
922 | ua(ji,jj,1) = ua(ji,jj,1) + zhpi(ji,jj,1) |
---|
923 | va(ji,jj,1) = va(ji,jj,1) + zhpj(ji,jj,1) |
---|
924 | END DO |
---|
925 | END DO |
---|
926 | |
---|
927 | ! ---------------- |
---|
928 | ! interior value (2=<jk=<jpkm1) |
---|
929 | ! ---------------- |
---|
930 | DO jk = 2, jpkm1 |
---|
931 | DO jj = 2, jpjm1 |
---|
932 | DO ji = fs_2, fs_jpim1 ! vector opt. |
---|
933 | ! hydrostatic pressure gradient along s-surfaces |
---|
934 | zhpi(ji,jj,jk) = zhpi(ji,jj,jk-1) & |
---|
935 | & + ( ( rho_k(ji+1,jj,jk) - rho_k(ji,jj,jk ) ) & |
---|
936 | & - ( rho_i(ji ,jj,jk) - rho_i(ji,jj,jk-1) ) ) * r1_e1u(ji,jj) |
---|
937 | zhpj(ji,jj,jk) = zhpj(ji,jj,jk-1) & |
---|
938 | & + ( ( rho_k(ji,jj+1,jk) - rho_k(ji,jj,jk ) ) & |
---|
939 | & -( rho_j(ji,jj ,jk) - rho_j(ji,jj,jk-1) ) ) * r1_e2v(ji,jj) |
---|
940 | IF( ln_wd ) THEN |
---|
941 | zhpi(ji,jj,jk) = zhpi(ji,jj,jk) * zcpx(ji,jj) |
---|
942 | zhpj(ji,jj,jk) = zhpj(ji,jj,jk) * zcpy(ji,jj) |
---|
943 | ENDIF |
---|
944 | ! add to the general momentum trend |
---|
945 | ua(ji,jj,jk) = ua(ji,jj,jk) + zhpi(ji,jj,jk) |
---|
946 | va(ji,jj,jk) = va(ji,jj,jk) + zhpj(ji,jj,jk) |
---|
947 | END DO |
---|
948 | END DO |
---|
949 | END DO |
---|
950 | ! |
---|
951 | CALL wrk_dealloc( jpi, jpj, jpk, dzx , dzy , dzz , dzu , dzv , dzw ) |
---|
952 | CALL wrk_dealloc( jpi, jpj, jpk, drhox, drhoy, drhoz, drhou, drhov, drhow ) |
---|
953 | CALL wrk_dealloc( jpi, jpj, jpk, rho_i, rho_j, rho_k, zhpi, zhpj ) |
---|
954 | IF( ln_wd ) CALL wrk_dealloc( jpi,jpj, zcpx, zcpy ) |
---|
955 | ! |
---|
956 | END SUBROUTINE hpg_djc |
---|
957 | |
---|
958 | |
---|
959 | SUBROUTINE hpg_prj( kt ) |
---|
960 | !!--------------------------------------------------------------------- |
---|
961 | !! *** ROUTINE hpg_prj *** |
---|
962 | !! |
---|
963 | !! ** Method : s-coordinate case. |
---|
964 | !! A Pressure-Jacobian horizontal pressure gradient method |
---|
965 | !! based on the constrained cubic-spline interpolation for |
---|
966 | !! all vertical coordinate systems |
---|
967 | !! |
---|
968 | !! ** Action : - Update (ua,va) with the now hydrastatic pressure trend |
---|
969 | !!---------------------------------------------------------------------- |
---|
970 | INTEGER, PARAMETER :: polynomial_type = 1 ! 1: cubic spline, 2: linear |
---|
971 | INTEGER, INTENT(in) :: kt ! ocean time-step index |
---|
972 | !! |
---|
973 | INTEGER :: ji, jj, jk, jkk ! dummy loop indices |
---|
974 | REAL(wp) :: zcoef0, znad ! local scalars |
---|
975 | ! |
---|
976 | !! The local variables for the correction term |
---|
977 | INTEGER :: jk1, jis, jid, jjs, jjd |
---|
978 | LOGICAL :: ll_tmp1, ll_tmp2 ! local logical variables |
---|
979 | REAL(wp) :: zuijk, zvijk, zpwes, zpwed, zpnss, zpnsd, zdeps |
---|
980 | REAL(wp) :: zrhdt1 |
---|
981 | REAL(wp) :: zdpdx1, zdpdx2, zdpdy1, zdpdy2 |
---|
982 | REAL(wp), POINTER, DIMENSION(:,:,:) :: zdept, zrhh |
---|
983 | REAL(wp), POINTER, DIMENSION(:,:,:) :: zhpi, zu, zv, fsp, xsp, asp, bsp, csp, dsp |
---|
984 | REAL(wp), POINTER, DIMENSION(:,:) :: zsshu_n, zsshv_n |
---|
985 | REAL(wp), POINTER, DIMENSION(:,:) :: zcpx, zcpy !W/D pressure filter |
---|
986 | !!---------------------------------------------------------------------- |
---|
987 | ! |
---|
988 | CALL wrk_alloc( jpi,jpj,jpk, zhpi, zu, zv, fsp, xsp, asp, bsp, csp, dsp ) |
---|
989 | CALL wrk_alloc( jpi,jpj,jpk, zdept, zrhh ) |
---|
990 | CALL wrk_alloc( jpi,jpj, zsshu_n, zsshv_n ) |
---|
991 | IF( ln_wd ) CALL wrk_alloc( jpi,jpj, zcpx, zcpy ) |
---|
992 | ! |
---|
993 | IF( kt == nit000 ) THEN |
---|
994 | IF(lwp) WRITE(numout,*) |
---|
995 | IF(lwp) WRITE(numout,*) 'dyn:hpg_prj : hydrostatic pressure gradient trend' |
---|
996 | IF(lwp) WRITE(numout,*) '~~~~~~~~~~~ s-coordinate case, cubic spline pressure Jacobian' |
---|
997 | ENDIF |
---|
998 | |
---|
999 | ! Local constant initialization |
---|
1000 | zcoef0 = - grav |
---|
1001 | znad = 1._wp |
---|
1002 | IF( ln_linssh ) znad = 0._wp |
---|
1003 | |
---|
1004 | IF( ln_wd ) THEN |
---|
1005 | DO jj = 2, jpjm1 |
---|
1006 | DO ji = 2, jpim1 |
---|
1007 | ll_tmp1 = MIN( sshn(ji,jj) , sshn(ji+1,jj) ) > & |
---|
1008 | & MAX( -ht_wd(ji,jj) , -ht_wd(ji+1,jj) ) .AND. & |
---|
1009 | & MAX( sshn(ji,jj) + ht_wd(ji,jj), sshn(ji+1,jj) + ht_wd(ji+1,jj) ) & |
---|
1010 | & > rn_wdmin1 + rn_wdmin2 |
---|
1011 | ll_tmp2 = ( ABS( sshn(ji,jj) - sshn(ji+1,jj) ) > 1.E-12 ) .AND. ( & |
---|
1012 | & MAX( sshn(ji,jj) , sshn(ji+1,jj) ) > & |
---|
1013 | & MAX( -ht_wd(ji,jj) , -ht_wd(ji+1,jj) ) + rn_wdmin1 + rn_wdmin2 ) |
---|
1014 | |
---|
1015 | IF(ll_tmp1) THEN |
---|
1016 | zcpx(ji,jj) = 1.0_wp |
---|
1017 | ELSE IF(ll_tmp2) THEN |
---|
1018 | ! no worries about sshn(ji+1,jj) - sshn(ji ,jj) = 0, it won't happen ! here |
---|
1019 | zcpx(ji,jj) = ABS( (sshn(ji+1,jj) + ht_wd(ji+1,jj) - sshn(ji,jj) - ht_wd(ji,jj)) & |
---|
1020 | & / (sshn(ji+1,jj) - sshn(ji ,jj)) ) |
---|
1021 | ELSE |
---|
1022 | zcpx(ji,jj) = 0._wp |
---|
1023 | END IF |
---|
1024 | |
---|
1025 | ll_tmp1 = MIN( sshn(ji,jj) , sshn(ji,jj+1) ) > & |
---|
1026 | & MAX( -ht_wd(ji,jj) , -ht_wd(ji,jj+1) ) .AND. & |
---|
1027 | & MAX( sshn(ji,jj) + ht_wd(ji,jj), sshn(ji,jj+1) + ht_wd(ji,jj+1) ) & |
---|
1028 | & > rn_wdmin1 + rn_wdmin2 |
---|
1029 | ll_tmp2 = ( ABS( sshn(ji,jj) - sshn(ji,jj+1) ) > 1.E-12 ) .AND. ( & |
---|
1030 | & MAX( sshn(ji,jj) , sshn(ji,jj+1) ) > & |
---|
1031 | & MAX( -ht_wd(ji,jj) , -ht_wd(ji,jj+1) ) + rn_wdmin1 + rn_wdmin2 ) |
---|
1032 | |
---|
1033 | IF(ll_tmp1) THEN |
---|
1034 | zcpy(ji,jj) = 1.0_wp |
---|
1035 | ELSE IF(ll_tmp2) THEN |
---|
1036 | ! no worries about sshn(ji,jj+1) - sshn(ji,jj ) = 0, it won't happen ! here |
---|
1037 | zcpy(ji,jj) = ABS( (sshn(ji,jj+1) + ht_wd(ji,jj+1) - sshn(ji,jj) - ht_wd(ji,jj)) & |
---|
1038 | & / (sshn(ji,jj+1) - sshn(ji,jj )) ) |
---|
1039 | ELSE |
---|
1040 | zcpy(ji,jj) = 0._wp |
---|
1041 | END IF |
---|
1042 | END DO |
---|
1043 | END DO |
---|
1044 | CALL lbc_lnk( zcpx, 'U', 1._wp ) ; CALL lbc_lnk( zcpy, 'V', 1._wp ) |
---|
1045 | END IF |
---|
1046 | |
---|
1047 | ! Clean 3-D work arrays |
---|
1048 | zhpi(:,:,:) = 0._wp |
---|
1049 | zrhh(:,:,:) = rhd(:,:,:) |
---|
1050 | |
---|
1051 | ! Preparing vertical density profile "zrhh(:,:,:)" for hybrid-sco coordinate |
---|
1052 | DO jj = 1, jpj |
---|
1053 | DO ji = 1, jpi |
---|
1054 | jk = mbkt(ji,jj)+1 |
---|
1055 | IF( jk <= 0 ) THEN ; zrhh(ji,jj, : ) = 0._wp |
---|
1056 | ELSEIF( jk == 1 ) THEN ; zrhh(ji,jj,jk+1:jpk) = rhd(ji,jj,jk) |
---|
1057 | ELSEIF( jk < jpkm1 ) THEN |
---|
1058 | DO jkk = jk+1, jpk |
---|
1059 | zrhh(ji,jj,jkk) = interp1(gde3w_n(ji,jj,jkk ), gde3w_n(ji,jj,jkk-1), & |
---|
1060 | & gde3w_n(ji,jj,jkk-2), rhd (ji,jj,jkk-1), rhd(ji,jj,jkk-2)) |
---|
1061 | END DO |
---|
1062 | ENDIF |
---|
1063 | END DO |
---|
1064 | END DO |
---|
1065 | |
---|
1066 | ! Transfer the depth of "T(:,:,:)" to vertical coordinate "zdept(:,:,:)" |
---|
1067 | DO jj = 1, jpj |
---|
1068 | DO ji = 1, jpi |
---|
1069 | zdept(ji,jj,1) = 0.5_wp * e3w_n(ji,jj,1) - sshn(ji,jj) * znad |
---|
1070 | END DO |
---|
1071 | END DO |
---|
1072 | |
---|
1073 | DO jk = 2, jpk |
---|
1074 | DO jj = 1, jpj |
---|
1075 | DO ji = 1, jpi |
---|
1076 | zdept(ji,jj,jk) = zdept(ji,jj,jk-1) + e3w_n(ji,jj,jk) |
---|
1077 | END DO |
---|
1078 | END DO |
---|
1079 | END DO |
---|
1080 | |
---|
1081 | fsp(:,:,:) = zrhh (:,:,:) |
---|
1082 | xsp(:,:,:) = zdept(:,:,:) |
---|
1083 | |
---|
1084 | ! Construct the vertical density profile with the |
---|
1085 | ! constrained cubic spline interpolation |
---|
1086 | ! rho(z) = asp + bsp*z + csp*z^2 + dsp*z^3 |
---|
1087 | CALL cspline( fsp, xsp, asp, bsp, csp, dsp, polynomial_type ) |
---|
1088 | |
---|
1089 | ! Integrate the hydrostatic pressure "zhpi(:,:,:)" at "T(ji,jj,1)" |
---|
1090 | DO jj = 2, jpj |
---|
1091 | DO ji = 2, jpi |
---|
1092 | zrhdt1 = zrhh(ji,jj,1) - interp3( zdept(ji,jj,1), asp(ji,jj,1), bsp(ji,jj,1), & |
---|
1093 | & csp(ji,jj,1), dsp(ji,jj,1) ) * 0.25_wp * e3w_n(ji,jj,1) |
---|
1094 | |
---|
1095 | ! assuming linear profile across the top half surface layer |
---|
1096 | zhpi(ji,jj,1) = 0.5_wp * e3w_n(ji,jj,1) * zrhdt1 |
---|
1097 | END DO |
---|
1098 | END DO |
---|
1099 | |
---|
1100 | ! Calculate the pressure "zhpi(:,:,:)" at "T(ji,jj,2:jpkm1)" |
---|
1101 | DO jk = 2, jpkm1 |
---|
1102 | DO jj = 2, jpj |
---|
1103 | DO ji = 2, jpi |
---|
1104 | zhpi(ji,jj,jk) = zhpi(ji,jj,jk-1) + & |
---|
1105 | & integ_spline( zdept(ji,jj,jk-1), zdept(ji,jj,jk), & |
---|
1106 | & asp (ji,jj,jk-1), bsp (ji,jj,jk-1), & |
---|
1107 | & csp (ji,jj,jk-1), dsp (ji,jj,jk-1) ) |
---|
1108 | END DO |
---|
1109 | END DO |
---|
1110 | END DO |
---|
1111 | |
---|
1112 | ! Z coordinate of U(ji,jj,1:jpkm1) and V(ji,jj,1:jpkm1) |
---|
1113 | |
---|
1114 | ! Prepare zsshu_n and zsshv_n |
---|
1115 | DO jj = 2, jpjm1 |
---|
1116 | DO ji = 2, jpim1 |
---|
1117 | !!gm BUG ? if it is ssh at u- & v-point then it should be: |
---|
1118 | ! zsshu_n(ji,jj) = (e1e2t(ji,jj) * sshn(ji,jj) + e1e2t(ji+1,jj) * sshn(ji+1,jj)) * & |
---|
1119 | ! & r1_e1e2u(ji,jj) * umask(ji,jj,1) * 0.5_wp |
---|
1120 | ! zsshv_n(ji,jj) = (e1e2t(ji,jj) * sshn(ji,jj) + e1e2t(ji,jj+1) * sshn(ji,jj+1)) * & |
---|
1121 | ! & r1_e1e2v(ji,jj) * vmask(ji,jj,1) * 0.5_wp |
---|
1122 | !!gm not this: |
---|
1123 | zsshu_n(ji,jj) = (e1e2u(ji,jj) * sshn(ji,jj) + e1e2u(ji+1, jj) * sshn(ji+1,jj)) * & |
---|
1124 | & r1_e1e2u(ji,jj) * umask(ji,jj,1) * 0.5_wp |
---|
1125 | zsshv_n(ji,jj) = (e1e2v(ji,jj) * sshn(ji,jj) + e1e2v(ji+1, jj) * sshn(ji,jj+1)) * & |
---|
1126 | & r1_e1e2v(ji,jj) * vmask(ji,jj,1) * 0.5_wp |
---|
1127 | END DO |
---|
1128 | END DO |
---|
1129 | |
---|
1130 | CALL lbc_lnk (zsshu_n, 'U', 1.) |
---|
1131 | CALL lbc_lnk (zsshv_n, 'V', 1.) |
---|
1132 | |
---|
1133 | DO jj = 2, jpjm1 |
---|
1134 | DO ji = 2, jpim1 |
---|
1135 | zu(ji,jj,1) = - ( e3u_n(ji,jj,1) - zsshu_n(ji,jj) * znad) |
---|
1136 | zv(ji,jj,1) = - ( e3v_n(ji,jj,1) - zsshv_n(ji,jj) * znad) |
---|
1137 | END DO |
---|
1138 | END DO |
---|
1139 | |
---|
1140 | DO jk = 2, jpkm1 |
---|
1141 | DO jj = 2, jpjm1 |
---|
1142 | DO ji = 2, jpim1 |
---|
1143 | zu(ji,jj,jk) = zu(ji,jj,jk-1) - e3u_n(ji,jj,jk) |
---|
1144 | zv(ji,jj,jk) = zv(ji,jj,jk-1) - e3v_n(ji,jj,jk) |
---|
1145 | END DO |
---|
1146 | END DO |
---|
1147 | END DO |
---|
1148 | |
---|
1149 | DO jk = 1, jpkm1 |
---|
1150 | DO jj = 2, jpjm1 |
---|
1151 | DO ji = 2, jpim1 |
---|
1152 | zu(ji,jj,jk) = zu(ji,jj,jk) + 0.5_wp * e3u_n(ji,jj,jk) |
---|
1153 | zv(ji,jj,jk) = zv(ji,jj,jk) + 0.5_wp * e3v_n(ji,jj,jk) |
---|
1154 | END DO |
---|
1155 | END DO |
---|
1156 | END DO |
---|
1157 | |
---|
1158 | DO jk = 1, jpkm1 |
---|
1159 | DO jj = 2, jpjm1 |
---|
1160 | DO ji = 2, jpim1 |
---|
1161 | zu(ji,jj,jk) = MIN( zu(ji,jj,jk) , MAX( -zdept(ji,jj,jk) , -zdept(ji+1,jj,jk) ) ) |
---|
1162 | zu(ji,jj,jk) = MAX( zu(ji,jj,jk) , MIN( -zdept(ji,jj,jk) , -zdept(ji+1,jj,jk) ) ) |
---|
1163 | zv(ji,jj,jk) = MIN( zv(ji,jj,jk) , MAX( -zdept(ji,jj,jk) , -zdept(ji,jj+1,jk) ) ) |
---|
1164 | zv(ji,jj,jk) = MAX( zv(ji,jj,jk) , MIN( -zdept(ji,jj,jk) , -zdept(ji,jj+1,jk) ) ) |
---|
1165 | END DO |
---|
1166 | END DO |
---|
1167 | END DO |
---|
1168 | |
---|
1169 | |
---|
1170 | DO jk = 1, jpkm1 |
---|
1171 | DO jj = 2, jpjm1 |
---|
1172 | DO ji = 2, jpim1 |
---|
1173 | zpwes = 0._wp; zpwed = 0._wp |
---|
1174 | zpnss = 0._wp; zpnsd = 0._wp |
---|
1175 | zuijk = zu(ji,jj,jk) |
---|
1176 | zvijk = zv(ji,jj,jk) |
---|
1177 | |
---|
1178 | !!!!! for u equation |
---|
1179 | IF( jk <= mbku(ji,jj) ) THEN |
---|
1180 | IF( -zdept(ji+1,jj,jk) >= -zdept(ji,jj,jk) ) THEN |
---|
1181 | jis = ji + 1; jid = ji |
---|
1182 | ELSE |
---|
1183 | jis = ji; jid = ji +1 |
---|
1184 | ENDIF |
---|
1185 | |
---|
1186 | ! integrate the pressure on the shallow side |
---|
1187 | jk1 = jk |
---|
1188 | DO WHILE ( -zdept(jis,jj,jk1) > zuijk ) |
---|
1189 | IF( jk1 == mbku(ji,jj) ) THEN |
---|
1190 | zuijk = -zdept(jis,jj,jk1) |
---|
1191 | EXIT |
---|
1192 | ENDIF |
---|
1193 | zdeps = MIN(zdept(jis,jj,jk1+1), -zuijk) |
---|
1194 | zpwes = zpwes + & |
---|
1195 | integ_spline(zdept(jis,jj,jk1), zdeps, & |
---|
1196 | asp(jis,jj,jk1), bsp(jis,jj,jk1), & |
---|
1197 | csp(jis,jj,jk1), dsp(jis,jj,jk1)) |
---|
1198 | jk1 = jk1 + 1 |
---|
1199 | END DO |
---|
1200 | |
---|
1201 | ! integrate the pressure on the deep side |
---|
1202 | jk1 = jk |
---|
1203 | DO WHILE ( -zdept(jid,jj,jk1) < zuijk ) |
---|
1204 | IF( jk1 == 1 ) THEN |
---|
1205 | zdeps = zdept(jid,jj,1) + MIN(zuijk, sshn(jid,jj)*znad) |
---|
1206 | zrhdt1 = zrhh(jid,jj,1) - interp3(zdept(jid,jj,1), asp(jid,jj,1), & |
---|
1207 | bsp(jid,jj,1), csp(jid,jj,1), & |
---|
1208 | dsp(jid,jj,1)) * zdeps |
---|
1209 | zpwed = zpwed + 0.5_wp * (zrhh(jid,jj,1) + zrhdt1) * zdeps |
---|
1210 | EXIT |
---|
1211 | ENDIF |
---|
1212 | zdeps = MAX(zdept(jid,jj,jk1-1), -zuijk) |
---|
1213 | zpwed = zpwed + & |
---|
1214 | integ_spline(zdeps, zdept(jid,jj,jk1), & |
---|
1215 | asp(jid,jj,jk1-1), bsp(jid,jj,jk1-1), & |
---|
1216 | csp(jid,jj,jk1-1), dsp(jid,jj,jk1-1) ) |
---|
1217 | jk1 = jk1 - 1 |
---|
1218 | END DO |
---|
1219 | |
---|
1220 | ! update the momentum trends in u direction |
---|
1221 | |
---|
1222 | zdpdx1 = zcoef0 * r1_e1u(ji,jj) * ( zhpi(ji+1,jj,jk) - zhpi(ji,jj,jk) ) |
---|
1223 | IF( .NOT.ln_linssh ) THEN |
---|
1224 | zdpdx2 = zcoef0 * r1_e1u(ji,jj) * & |
---|
1225 | & ( REAL(jis-jid, wp) * (zpwes + zpwed) + (sshn(ji+1,jj)-sshn(ji,jj)) ) |
---|
1226 | ELSE |
---|
1227 | zdpdx2 = zcoef0 * r1_e1u(ji,jj) * REAL(jis-jid, wp) * (zpwes + zpwed) |
---|
1228 | ENDIF |
---|
1229 | IF( ln_wd ) THEN |
---|
1230 | zdpdx1 = zdpdx1 * zcpx(ji,jj) |
---|
1231 | zdpdx2 = zdpdx2 * zcpx(ji,jj) |
---|
1232 | ENDIF |
---|
1233 | ua(ji,jj,jk) = ua(ji,jj,jk) + (zdpdx1 + zdpdx2) * umask(ji,jj,jk) |
---|
1234 | ENDIF |
---|
1235 | |
---|
1236 | !!!!! for v equation |
---|
1237 | IF( jk <= mbkv(ji,jj) ) THEN |
---|
1238 | IF( -zdept(ji,jj+1,jk) >= -zdept(ji,jj,jk) ) THEN |
---|
1239 | jjs = jj + 1; jjd = jj |
---|
1240 | ELSE |
---|
1241 | jjs = jj ; jjd = jj + 1 |
---|
1242 | ENDIF |
---|
1243 | |
---|
1244 | ! integrate the pressure on the shallow side |
---|
1245 | jk1 = jk |
---|
1246 | DO WHILE ( -zdept(ji,jjs,jk1) > zvijk ) |
---|
1247 | IF( jk1 == mbkv(ji,jj) ) THEN |
---|
1248 | zvijk = -zdept(ji,jjs,jk1) |
---|
1249 | EXIT |
---|
1250 | ENDIF |
---|
1251 | zdeps = MIN(zdept(ji,jjs,jk1+1), -zvijk) |
---|
1252 | zpnss = zpnss + & |
---|
1253 | integ_spline(zdept(ji,jjs,jk1), zdeps, & |
---|
1254 | asp(ji,jjs,jk1), bsp(ji,jjs,jk1), & |
---|
1255 | csp(ji,jjs,jk1), dsp(ji,jjs,jk1) ) |
---|
1256 | jk1 = jk1 + 1 |
---|
1257 | END DO |
---|
1258 | |
---|
1259 | ! integrate the pressure on the deep side |
---|
1260 | jk1 = jk |
---|
1261 | DO WHILE ( -zdept(ji,jjd,jk1) < zvijk ) |
---|
1262 | IF( jk1 == 1 ) THEN |
---|
1263 | zdeps = zdept(ji,jjd,1) + MIN(zvijk, sshn(ji,jjd)*znad) |
---|
1264 | zrhdt1 = zrhh(ji,jjd,1) - interp3(zdept(ji,jjd,1), asp(ji,jjd,1), & |
---|
1265 | bsp(ji,jjd,1), csp(ji,jjd,1), & |
---|
1266 | dsp(ji,jjd,1) ) * zdeps |
---|
1267 | zpnsd = zpnsd + 0.5_wp * (zrhh(ji,jjd,1) + zrhdt1) * zdeps |
---|
1268 | EXIT |
---|
1269 | ENDIF |
---|
1270 | zdeps = MAX(zdept(ji,jjd,jk1-1), -zvijk) |
---|
1271 | zpnsd = zpnsd + & |
---|
1272 | integ_spline(zdeps, zdept(ji,jjd,jk1), & |
---|
1273 | asp(ji,jjd,jk1-1), bsp(ji,jjd,jk1-1), & |
---|
1274 | csp(ji,jjd,jk1-1), dsp(ji,jjd,jk1-1) ) |
---|
1275 | jk1 = jk1 - 1 |
---|
1276 | END DO |
---|
1277 | |
---|
1278 | |
---|
1279 | ! update the momentum trends in v direction |
---|
1280 | |
---|
1281 | zdpdy1 = zcoef0 * r1_e2v(ji,jj) * ( zhpi(ji,jj+1,jk) - zhpi(ji,jj,jk) ) |
---|
1282 | IF( .NOT.ln_linssh ) THEN |
---|
1283 | zdpdy2 = zcoef0 * r1_e2v(ji,jj) * & |
---|
1284 | ( REAL(jjs-jjd, wp) * (zpnss + zpnsd) + (sshn(ji,jj+1)-sshn(ji,jj)) ) |
---|
1285 | ELSE |
---|
1286 | zdpdy2 = zcoef0 * r1_e2v(ji,jj) * REAL(jjs-jjd, wp) * (zpnss + zpnsd ) |
---|
1287 | ENDIF |
---|
1288 | IF( ln_wd ) THEN |
---|
1289 | zdpdy1 = zdpdy1 * zcpy(ji,jj) |
---|
1290 | zdpdy2 = zdpdy2 * zcpy(ji,jj) |
---|
1291 | ENDIF |
---|
1292 | |
---|
1293 | va(ji,jj,jk) = va(ji,jj,jk) + (zdpdy1 + zdpdy2) * vmask(ji,jj,jk) |
---|
1294 | ENDIF |
---|
1295 | ! |
---|
1296 | END DO |
---|
1297 | END DO |
---|
1298 | END DO |
---|
1299 | ! |
---|
1300 | CALL wrk_dealloc( jpi,jpj,jpk, zhpi, zu, zv, fsp, xsp, asp, bsp, csp, dsp ) |
---|
1301 | CALL wrk_dealloc( jpi,jpj,jpk, zdept, zrhh ) |
---|
1302 | CALL wrk_dealloc( jpi,jpj, zsshu_n, zsshv_n ) |
---|
1303 | IF( ln_wd ) CALL wrk_dealloc( jpi,jpj, zcpx, zcpy ) |
---|
1304 | ! |
---|
1305 | END SUBROUTINE hpg_prj |
---|
1306 | |
---|
1307 | |
---|
1308 | SUBROUTINE cspline( fsp, xsp, asp, bsp, csp, dsp, polynomial_type ) |
---|
1309 | !!---------------------------------------------------------------------- |
---|
1310 | !! *** ROUTINE cspline *** |
---|
1311 | !! |
---|
1312 | !! ** Purpose : constrained cubic spline interpolation |
---|
1313 | !! |
---|
1314 | !! ** Method : f(x) = asp + bsp*x + csp*x^2 + dsp*x^3 |
---|
1315 | !! |
---|
1316 | !! Reference: CJC Kruger, Constrained Cubic Spline Interpoltation |
---|
1317 | !!---------------------------------------------------------------------- |
---|
1318 | REAL(wp), DIMENSION(:,:,:), INTENT(in ) :: fsp, xsp ! value and coordinate |
---|
1319 | REAL(wp), DIMENSION(:,:,:), INTENT( out) :: asp, bsp, csp, dsp ! coefficients of the interpoated function |
---|
1320 | INTEGER , INTENT(in ) :: polynomial_type ! 1: cubic spline ; 2: Linear |
---|
1321 | ! |
---|
1322 | INTEGER :: ji, jj, jk ! dummy loop indices |
---|
1323 | INTEGER :: jpi, jpj, jpkm1 |
---|
1324 | REAL(wp) :: zdf1, zdf2, zddf1, zddf2, ztmp1, ztmp2, zdxtmp |
---|
1325 | REAL(wp) :: zdxtmp1, zdxtmp2, zalpha |
---|
1326 | REAL(wp) :: zdf(size(fsp,3)) |
---|
1327 | !!---------------------------------------------------------------------- |
---|
1328 | ! |
---|
1329 | !!gm WHAT !!!!! THIS IS VERY DANGEROUS !!!!! |
---|
1330 | jpi = size(fsp,1) |
---|
1331 | jpj = size(fsp,2) |
---|
1332 | jpkm1 = MAX( 1, size(fsp,3) - 1 ) |
---|
1333 | ! |
---|
1334 | IF (polynomial_type == 1) THEN ! Constrained Cubic Spline |
---|
1335 | DO ji = 1, jpi |
---|
1336 | DO jj = 1, jpj |
---|
1337 | !!Fritsch&Butland's method, 1984 (preferred, but more computation) |
---|
1338 | ! DO jk = 2, jpkm1-1 |
---|
1339 | ! zdxtmp1 = xsp(ji,jj,jk) - xsp(ji,jj,jk-1) |
---|
1340 | ! zdxtmp2 = xsp(ji,jj,jk+1) - xsp(ji,jj,jk) |
---|
1341 | ! zdf1 = ( fsp(ji,jj,jk) - fsp(ji,jj,jk-1) ) / zdxtmp1 |
---|
1342 | ! zdf2 = ( fsp(ji,jj,jk+1) - fsp(ji,jj,jk) ) / zdxtmp2 |
---|
1343 | ! |
---|
1344 | ! zalpha = ( zdxtmp1 + 2._wp * zdxtmp2 ) / ( zdxtmp1 + zdxtmp2 ) / 3._wp |
---|
1345 | ! |
---|
1346 | ! IF(zdf1 * zdf2 <= 0._wp) THEN |
---|
1347 | ! zdf(jk) = 0._wp |
---|
1348 | ! ELSE |
---|
1349 | ! zdf(jk) = zdf1 * zdf2 / ( ( 1._wp - zalpha ) * zdf1 + zalpha * zdf2 ) |
---|
1350 | ! ENDIF |
---|
1351 | ! END DO |
---|
1352 | |
---|
1353 | !!Simply geometric average |
---|
1354 | DO jk = 2, jpkm1-1 |
---|
1355 | zdf1 = (fsp(ji,jj,jk) - fsp(ji,jj,jk-1)) / (xsp(ji,jj,jk) - xsp(ji,jj,jk-1)) |
---|
1356 | zdf2 = (fsp(ji,jj,jk+1) - fsp(ji,jj,jk)) / (xsp(ji,jj,jk+1) - xsp(ji,jj,jk)) |
---|
1357 | |
---|
1358 | IF(zdf1 * zdf2 <= 0._wp) THEN |
---|
1359 | zdf(jk) = 0._wp |
---|
1360 | ELSE |
---|
1361 | zdf(jk) = 2._wp * zdf1 * zdf2 / (zdf1 + zdf2) |
---|
1362 | ENDIF |
---|
1363 | END DO |
---|
1364 | |
---|
1365 | zdf(1) = 1.5_wp * ( fsp(ji,jj,2) - fsp(ji,jj,1) ) / & |
---|
1366 | & ( xsp(ji,jj,2) - xsp(ji,jj,1) ) - 0.5_wp * zdf(2) |
---|
1367 | zdf(jpkm1) = 1.5_wp * ( fsp(ji,jj,jpkm1) - fsp(ji,jj,jpkm1-1) ) / & |
---|
1368 | & ( xsp(ji,jj,jpkm1) - xsp(ji,jj,jpkm1-1) ) - 0.5_wp * zdf(jpkm1 - 1) |
---|
1369 | |
---|
1370 | DO jk = 1, jpkm1 - 1 |
---|
1371 | zdxtmp = xsp(ji,jj,jk+1) - xsp(ji,jj,jk) |
---|
1372 | ztmp1 = (zdf(jk+1) + 2._wp * zdf(jk)) / zdxtmp |
---|
1373 | ztmp2 = 6._wp * (fsp(ji,jj,jk+1) - fsp(ji,jj,jk)) / zdxtmp / zdxtmp |
---|
1374 | zddf1 = -2._wp * ztmp1 + ztmp2 |
---|
1375 | ztmp1 = (2._wp * zdf(jk+1) + zdf(jk)) / zdxtmp |
---|
1376 | zddf2 = 2._wp * ztmp1 - ztmp2 |
---|
1377 | |
---|
1378 | dsp(ji,jj,jk) = (zddf2 - zddf1) / 6._wp / zdxtmp |
---|
1379 | csp(ji,jj,jk) = ( xsp(ji,jj,jk+1) * zddf1 - xsp(ji,jj,jk)*zddf2 ) / 2._wp / zdxtmp |
---|
1380 | bsp(ji,jj,jk) = ( fsp(ji,jj,jk+1) - fsp(ji,jj,jk) ) / zdxtmp - & |
---|
1381 | & csp(ji,jj,jk) * ( xsp(ji,jj,jk+1) + xsp(ji,jj,jk) ) - & |
---|
1382 | & dsp(ji,jj,jk) * ((xsp(ji,jj,jk+1) + xsp(ji,jj,jk))**2 - & |
---|
1383 | & xsp(ji,jj,jk+1) * xsp(ji,jj,jk)) |
---|
1384 | asp(ji,jj,jk) = fsp(ji,jj,jk) - xsp(ji,jj,jk) * (bsp(ji,jj,jk) + & |
---|
1385 | & (xsp(ji,jj,jk) * (csp(ji,jj,jk) + & |
---|
1386 | & dsp(ji,jj,jk) * xsp(ji,jj,jk)))) |
---|
1387 | END DO |
---|
1388 | END DO |
---|
1389 | END DO |
---|
1390 | |
---|
1391 | ELSEIF ( polynomial_type == 2 ) THEN ! Linear |
---|
1392 | DO ji = 1, jpi |
---|
1393 | DO jj = 1, jpj |
---|
1394 | DO jk = 1, jpkm1-1 |
---|
1395 | zdxtmp =xsp(ji,jj,jk+1) - xsp(ji,jj,jk) |
---|
1396 | ztmp1 = fsp(ji,jj,jk+1) - fsp(ji,jj,jk) |
---|
1397 | |
---|
1398 | dsp(ji,jj,jk) = 0._wp |
---|
1399 | csp(ji,jj,jk) = 0._wp |
---|
1400 | bsp(ji,jj,jk) = ztmp1 / zdxtmp |
---|
1401 | asp(ji,jj,jk) = fsp(ji,jj,jk) - bsp(ji,jj,jk) * xsp(ji,jj,jk) |
---|
1402 | END DO |
---|
1403 | END DO |
---|
1404 | END DO |
---|
1405 | |
---|
1406 | ELSE |
---|
1407 | CALL ctl_stop( 'invalid polynomial type in cspline' ) |
---|
1408 | ENDIF |
---|
1409 | |
---|
1410 | END SUBROUTINE cspline |
---|
1411 | |
---|
1412 | |
---|
1413 | FUNCTION interp1(x, xl, xr, fl, fr) RESULT(f) |
---|
1414 | !!---------------------------------------------------------------------- |
---|
1415 | !! *** ROUTINE interp1 *** |
---|
1416 | !! |
---|
1417 | !! ** Purpose : 1-d linear interpolation |
---|
1418 | !! |
---|
1419 | !! ** Method : interpolation is straight forward |
---|
1420 | !! extrapolation is also permitted (no value limit) |
---|
1421 | !!---------------------------------------------------------------------- |
---|
1422 | REAL(wp), INTENT(in) :: x, xl, xr, fl, fr |
---|
1423 | REAL(wp) :: f ! result of the interpolation (extrapolation) |
---|
1424 | REAL(wp) :: zdeltx |
---|
1425 | !!---------------------------------------------------------------------- |
---|
1426 | ! |
---|
1427 | zdeltx = xr - xl |
---|
1428 | IF( abs(zdeltx) <= 10._wp * EPSILON(x) ) THEN |
---|
1429 | f = 0.5_wp * (fl + fr) |
---|
1430 | ELSE |
---|
1431 | f = ( (x - xl ) * fr - ( x - xr ) * fl ) / zdeltx |
---|
1432 | ENDIF |
---|
1433 | ! |
---|
1434 | END FUNCTION interp1 |
---|
1435 | |
---|
1436 | |
---|
1437 | FUNCTION interp2( x, a, b, c, d ) RESULT(f) |
---|
1438 | !!---------------------------------------------------------------------- |
---|
1439 | !! *** ROUTINE interp1 *** |
---|
1440 | !! |
---|
1441 | !! ** Purpose : 1-d constrained cubic spline interpolation |
---|
1442 | !! |
---|
1443 | !! ** Method : cubic spline interpolation |
---|
1444 | !! |
---|
1445 | !!---------------------------------------------------------------------- |
---|
1446 | REAL(wp), INTENT(in) :: x, a, b, c, d |
---|
1447 | REAL(wp) :: f ! value from the interpolation |
---|
1448 | !!---------------------------------------------------------------------- |
---|
1449 | ! |
---|
1450 | f = a + x* ( b + x * ( c + d * x ) ) |
---|
1451 | ! |
---|
1452 | END FUNCTION interp2 |
---|
1453 | |
---|
1454 | |
---|
1455 | FUNCTION interp3( x, a, b, c, d ) RESULT(f) |
---|
1456 | !!---------------------------------------------------------------------- |
---|
1457 | !! *** ROUTINE interp1 *** |
---|
1458 | !! |
---|
1459 | !! ** Purpose : Calculate the first order of derivative of |
---|
1460 | !! a cubic spline function y=a+b*x+c*x^2+d*x^3 |
---|
1461 | !! |
---|
1462 | !! ** Method : f=dy/dx=b+2*c*x+3*d*x^2 |
---|
1463 | !! |
---|
1464 | !!---------------------------------------------------------------------- |
---|
1465 | REAL(wp), INTENT(in) :: x, a, b, c, d |
---|
1466 | REAL(wp) :: f ! value from the interpolation |
---|
1467 | !!---------------------------------------------------------------------- |
---|
1468 | ! |
---|
1469 | f = b + x * ( 2._wp * c + 3._wp * d * x) |
---|
1470 | ! |
---|
1471 | END FUNCTION interp3 |
---|
1472 | |
---|
1473 | |
---|
1474 | FUNCTION integ_spline( xl, xr, a, b, c, d ) RESULT(f) |
---|
1475 | !!---------------------------------------------------------------------- |
---|
1476 | !! *** ROUTINE interp1 *** |
---|
1477 | !! |
---|
1478 | !! ** Purpose : 1-d constrained cubic spline integration |
---|
1479 | !! |
---|
1480 | !! ** Method : integrate polynomial a+bx+cx^2+dx^3 from xl to xr |
---|
1481 | !! |
---|
1482 | !!---------------------------------------------------------------------- |
---|
1483 | REAL(wp), INTENT(in) :: xl, xr, a, b, c, d |
---|
1484 | REAL(wp) :: za1, za2, za3 |
---|
1485 | REAL(wp) :: f ! integration result |
---|
1486 | !!---------------------------------------------------------------------- |
---|
1487 | ! |
---|
1488 | za1 = 0.5_wp * b |
---|
1489 | za2 = c / 3.0_wp |
---|
1490 | za3 = 0.25_wp * d |
---|
1491 | ! |
---|
1492 | f = xr * ( a + xr * ( za1 + xr * ( za2 + za3 * xr ) ) ) - & |
---|
1493 | & xl * ( a + xl * ( za1 + xl * ( za2 + za3 * xl ) ) ) |
---|
1494 | ! |
---|
1495 | END FUNCTION integ_spline |
---|
1496 | |
---|
1497 | !!====================================================================== |
---|
1498 | END MODULE dynhpg |
---|
1499 | |
---|