dynhpg.F90 70 KB

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