uvtrop.f 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. ! ==================================================================
  2. ! ------------------------------------------------------------------
  3. !
  4. subroutine uvtrop(b1)
  5. use lsgvar
  6. implicit none
  7. !
  8. ! ------------------------------------------------------------------
  9. !
  10. !**** *uvtrop*.
  11. !
  12. ! by E. Maier-Reimer.
  13. ! last modified by U. Mikolajewicz 9/87.
  14. ! optimized by E. Kirk 2/2008
  15. !
  16. ! Purpose.
  17. ! --------
  18. ! *uvtrop* computes barotropic velocities and stream function
  19. ! according to the equation for the barotropic velocities.
  20. ! *uvtrop* computes the surface elevation *zeta* and its
  21. ! time derivative *zetado* from the depth-integrated equation
  22. ! of continuity.
  23. !
  24. !** Input.
  25. ! ------
  26. ! b1 right hand side of the equation (from *prefor1*).
  27. ! skal scaling factors. )
  28. ! elim elimination factors. ) via common /lsgmat/.
  29. ! trisys tridiagonalsystem. )
  30. ! zeta old surface elevation. (common /lsgsur/).
  31. !
  32. ! Output.
  33. ! -------
  34. ! ub ) barotropic velocities (common /lsgfie/).
  35. ! vb )
  36. ! psi barotropic stream function.
  37. ! zeta surface elevation. (common /lsgsur/).
  38. ! zetado time derivative of *zeta*.(common /lsgsur/).
  39. !
  40. ! Interface.
  41. ! ----------
  42. ! *call* *uvtrop(b1)*.
  43. ! parameter b1, dimension b1(matrx).
  44. !
  45. !
  46. ! Parameter declaration.
  47. ! ----------------------
  48. real (kind=8) :: b1(matrx)
  49. !
  50. !
  51. ! Declaration of local variables.
  52. ! -------------------------------
  53. integer,save :: ncall = 0
  54. integer :: i,j,k,l,jem2,itgar,itgrr,matrx1
  55. real (kind=8) :: xr,psi1,dti,fact,aree,areo,zetame,zetamo
  56. real (kind=8) :: apafac
  57. real (kind=8) :: b(matot),x(matot)
  58. real (kind=8) :: ubla(ienjen),vbla(ienjen)
  59. real (kind=8) :: zetas(ienjen)
  60. !
  61. !
  62. !
  63. !* 1. Set initial values and constants.
  64. ! ---------------------------------
  65. !
  66. jem2=jen-2
  67. itgar=33
  68. matrx1=matrx-1
  69. itgrr=31
  70. mindi=0
  71. mindj=0
  72. !
  73. x(:) = 0.0
  74. !
  75. !
  76. ! * 2. Comput. of the right side of the triangular matrix.
  77. ! ---------------------------------------------------
  78. !
  79. ! Scaling.
  80. !
  81. b(1:matrx) = b1(:) * skal(:) * dt
  82. b(matrx+1:) = 0.0
  83. !
  84. ! Elimination.
  85. !
  86. do j=1,matrx1
  87. b(j+1:j+kb) = b(j+1:j+kb) - elim(:,j) * b(j)
  88. end do
  89. !
  90. !
  91. !* 3. Computation of the barotropic velocities.
  92. ! -----------------------------------------
  93. !
  94. ! Solving the matrix equation.
  95. !
  96. x(matrx)=b(matrx)/trisys(1,matrx)
  97. do l=matrx1,1,-1
  98. xr = dot_product(x(l+1:l+kb),trisys(2:kb+1,l))
  99. x(l)=(b(l)-xr)/trisys(1,l)
  100. end do
  101. !
  102. !
  103. ! Computation of *ub* and *vb*.
  104. !
  105. where (numxa(:) > 0)
  106. uba(:) = x(2*numxa(:)-1)
  107. vba(:) = x(2*numxa(:) )
  108. else where
  109. uba(:) = 0.0
  110. vba(:) = 0.0
  111. end where
  112. !
  113. !
  114. !* 4. Computation of the barotropic stream function.
  115. ! ----------------------------------------------
  116. ! with zero at Antarctica.
  117. psi(:,jem2:jen) = 0.0
  118. do j=jem2,1,-1
  119. psi(ien,j)=psi(1,j+2)+depth(ien,j+1)*dphi*ub(ien,j+1)*1.e-6
  120. do i=1,ien-1
  121. psi(i,j)=psi(i+1,j+2)+depth(i,j+1)*dphi*ub(i,j+1)*1.e-6
  122. end do
  123. end do
  124. !
  125. psimax=0.0
  126. do j=3,jen-2
  127. do i=1,ien
  128. psi1=abs(psi(i,j))
  129. if (psi1<psimax) cycle
  130. psimax=psi1
  131. mindi=i
  132. mindj=j
  133. end do
  134. end do
  135. !
  136. !
  137. !* 5. New surface elevation.
  138. ! ----------------------
  139. !
  140. ! Defines arrays containing velocities of next grid points.
  141. !
  142. do i=1,ienjen,ien
  143. ubla(i) = uba(i+ien-1)
  144. vbla(i) = vba(i+ien-1)
  145. ubla(i+1:i+ien-1) = uba(i:i+ien-2)
  146. vbla(i+1:i+ien-1) = vba(i:i+ien-2)
  147. end do
  148. !
  149. ! Computes surface elevation.
  150. !
  151. zetas(:) = zetaa(:) ! Save zetaa for later use
  152. l=ien*(jen-2)
  153. do i=ien+1,ien+l
  154. zetaa(i)=zetaa(i)+dt*dliha(i) &
  155. & *(ubla(i)*depthla(i)-uba(i)*deptha(i) &
  156. & +dpin*(vba(i+ien)*deptha(i+ien)*dlha(i+ien)-vbla(i-ien)&
  157. & *depthla(i-ien)*dlha(i-ien)))
  158. end do
  159. !
  160. ! Surface elevation at the poles.
  161. !
  162. do i=1,ien
  163. zeta(i,1)=0.
  164. zeta(i,2)=0.
  165. zeta(i,jen)=0.
  166. zeta(i,jen-1)=0.
  167. end do
  168. !
  169. dti=1./dt
  170. !
  171. ! Computes time derivative of surface elevation.
  172. !
  173. do i=ien+1,ien+l
  174. fact=1.
  175. zetadoa(i)=dti*(zetaa(i)-zetas(i))*fact
  176. zetadoa(i)=dmax1(zetadoa(i),-dw(1)/4.)
  177. zetadoa(i)=dmin1(zetadoa(i),dw(1)/4.)
  178. end do
  179. !
  180. ! Compensation for cutoff errors of zeta.
  181. !
  182. aree=0.
  183. areo=0.
  184. zetame=0.
  185. zetamo=0.
  186. do j=2,jen-1,1
  187. do i=1,ien
  188. zetamo=zetamo+wet(i,j,1)*dlh(i,j)*dphi*zeta(i,j)
  189. areo=areo+wet(i,j,1)*dlh(i,j)*dphi
  190. zetame=zetame+wet(i,j+1,1)*dlh(i,j+1)*dphi*zeta(i,j+1)
  191. aree=aree+wet(i,j+1,1)*dlh(i,j+1)*dphi
  192. end do
  193. end do
  194. apafac=1./120.
  195. zetame=apafac*zetame/aree
  196. zetamo=apafac*zetamo/areo
  197. print *,"ZETAM0",zetamo,zetame
  198. do j=3,jen-2,2
  199. do i=1,ien
  200. zeta(i,j)=wet(i,j,1)*(zeta(i,j)-zetamo)
  201. zeta(i,j+1)=wet(i,j+1,1)*(zeta(i,j+1)-zetame)
  202. end do
  203. end do
  204. !if (ncall == 0) then
  205. write (87,'(4e20.9)') ub
  206. write (87,'(4e20.9)') vb
  207. write (87,'(4e20.9)') psi
  208. write (87,'(4e20.9)') zeta
  209. write (87,'(4e20.9)') zetado
  210. !ncall = 1
  211. !endif
  212. return
  213. end subroutine uvtrop