My Project
Functions/Subroutines
vdif_ts.f90 File Reference

Go to the source code of this file.

Functions/Subroutines

subroutine vdif_ts (NCON1, F)
 

Function/Subroutine Documentation

◆ vdif_ts()

subroutine vdif_ts ( integer  NCON1,
real(sp), dimension(0:mt,kb)  F 
)

Definition at line 54 of file vdif_ts.f90.

54 
55  !------------------------------------------------------------------------------|
56 
57  USE all_vars
58  USE mod_utils
59  USE bcs
60  USE mod_wd
61 
62 
63  IMPLICIT NONE
64  INTEGER :: I,K,NCON1,J,KI,hutemp
65  ! REAL(SP) :: TMP,TMP1,TMP2,TMP3,QTMP,GW,ZDEP,FKH,UMOLPR,WETFAC
66  ! REAL(SP), DIMENSION(0:MT,KB) :: F
67  ! REAL(SP), DIMENSION(M,KB) :: FF,AF,CF,VHF,VHPF,RAD
68  ! REAL(SP), DIMENSION(M) :: KHBOTTOM,WFSURF,SWRADF
69  REAL(DP) :: TMP,TMP1,TMP2,TMP3,QTMP,GW,ZDEP,FKH,UMOLPR,WETFAC
70  REAL(SP), DIMENSION(0:MT,KB) :: F
71  REAL(DP), DIMENSION(M,KB) :: FF,AF,CF,VHF,VHPF,RAD
72  REAL(DP), DIMENSION(M) :: KHBOTTOM,WFSURF,SWRADF,SASURF
73  REAL(DP), DIMENSION(M) :: COSGAMA1,COSGAMA2
74 
75 
76  REAL(SP) :: WFTMP1, WFTMP2, WFTMP3
77 
78  IF(dbg_set(dbg_sbr)) WRITE(ipt,*)"Start: vdif_ts :", ncon1
79 
80  umolpr = umol*1.e0_sp
81  sasurf = 0.0_sp
82  gw = 0.0_dp
83  !
84  !------------------------------------------------------------------------------!
85  ! !
86  ! the following section solves the equation !
87  ! dti*(kh*f')'-f=-fb !
88  ! !
89  !------------------------------------------------------------------------------!
90 
91  DO k = 2, kbm1
92  DO i = 1, m
93  IF(iswetn(i) == 1)THEN
94  fkh = kh(i,k)
95 
96  IF(k == kbm1) THEN
97  khbottom(i)=fkh
98  END IF
99 
100  af(i,k-1)=-dti*(fkh+umolpr)/(dz(i,k-1)*dzz(i,k-1)*d(i)*d(i))
101  cf(i,k)=-dti*(fkh+umolpr)/(dz(i,k)*dzz(i,k-1)*d(i)*d(i))
102  END IF
103  END DO
104  END DO
105 
106 
107  !------------------------------------------------------------------------------!
108  ! the net heat flux input. !
109  ! the method shown below can be used when we turn off the !
110  ! body force in subroutine advt. be sure this method could !
111  ! cause the surface overheated if the vertical resolution !
112  ! is not high enough. !
113  !------------------------------------------------------------------------------!
114 
115  SELECT CASE(ncon1)
116  CASE(1)
117 
118  rad = 0.0_sp
119  wfsurf = 0.0_sp
120  swradf = 0.0_sp
121  IF(heating_type == 'flux')THEN
122  ! DO I=1,M
123  ! WFSURF(I)=WTSURF(I)
124  ! SWRADF(I)=SWRAD(I)
125  ! SASURF(I)=0.0_SP
126  ! END DO
127  wfsurf(1:m)=wtsurf(1:m)
128  swradf(1:m)=swrad(1:m)
129  sasurf=0.0_sp
130 
131 !
132 !-----------------------------------------------------------------------
133 ! If net heat flux is cooling and SST is at freezing point or below
134 ! then suppress further cooling. Note: net heat flux sign convention is that
135 ! positive (in FVCOM negitive - J. Qi) means heating the ocean (J Wilkin - ROMS).
136 !-----------------------------------------------------------------------
137 !
138 ! Below the surface heat flux WFSURF is ZERO if cooling AND
139 ! the SST is cooler than the threshold. The value is retained if
140 ! warming.
141 !
142 ! WFTMP3 = 0 if SST warmer than threshold (WFTMP1) - change nothing
143 ! WFTMP3 = 1 if SST colder than threshold (WFTMP1)
144 !
145 ! 0.5*(WFTMP2+ABS(WFTMP2)) = 0 if flux is warming
146 ! = WFSURF if flux is cooling
147 !
148  wftmp1=-2.0_sp ! nominal SST threshold to cease cooling
149  DO i=1,m
150  wftmp2=wfsurf(i)
151  wftmp3=0.5_sp*(1.0_sp+sign(1.0_sp,wftmp1-f(i,1)))
152  wfsurf(i) = wftmp2-wftmp3*0.5_sp*(wftmp2+abs(wftmp2))
153  END DO
154 
155  DO k = 1, kb
156  DO i = 1, m
157  IF(iswetn(i) == 1)THEN
158  zdep = z(i,k)*d(i)
159  rad(i,k)=swradf(i)*(rheat*exp(zdep/zeta1)+(1-rheat)*exp(zdep/zeta2))
160  END IF
161  END DO
162  END DO
163  END IF
164 
165  CASE(2)
166 
167  swradf = 0.0_sp
168  wfsurf =0.0_sp
169  cosgama1 =1.0_sp
170 !---Considering the salinity conservation, the sea surface salinity flux-----!
171 !---can be set as zero, that is----------------------------------------------!
172  sasurf = 0.0_sp
173  rad =0.0_sp
174 
175  CASE DEFAULT
176  CALL fatal_error('NCON NOT CORRECT IN VDIF_TS')
177  END SELECT
178 
179 
180  !------------------------------------------------------------------------------!
181  ! surface bcs; wfsurf !
182  !------------------------------------------------------------------------------!
183 
184  DO i = 1, m
185  IF(iswetn(i) == 1)THEN
186  vhf(i,1) = af(i,1) / (af(i,1)-1.)
187  vhpf(i,1) = -dti *(sasurf(i)+wfsurf(i)-swradf(i) &
188  +rad(i,1)-rad(i,2)) / (-dz(i,1)*d(i)) - f(i,1)
189  vhpf(i,1) = vhpf(i,1) / (af(i,1)-1.)
190  END IF
191  END DO
192 
193  DO k = 2, kbm2
194  DO i = 1, m
195  IF(iswetn(i) == 1)THEN
196  vhpf(i,k)=1./ (af(i,k)+cf(i,k)*(1.-vhf(i,k-1))-1.)
197  vhf(i,k) = af(i,k) * vhpf(i,k)
198  vhpf(i,k) = (cf(i,k)*vhpf(i,k-1)-dble(f(i,k)) &
199  +dti*(rad(i,k)-rad(i,k+1))/(d(i)*dz(i,k)))*vhpf(i,k)
200  END IF
201  END DO
202  END DO
203 
204 
205 !!$ DO K = 1, KBM1
206 !!$ DO I = 1, M
207 !!$# if !defined (1)
208 !!$ IF (D(I) > 0.0_SP) THEN
209 !!$# else
210 !!$ IF(ISWETN(I) == 1)THEN
211 !!$# endif
212 !!$ FF(I,K) = F(I,K)
213 !!$ END IF
214 !!$ END DO
215 !!$ END DO
216 
217 
218  DO k = 1, kbm1
219  DO i = 1, m
220  IF(iswetn(i) == 1)THEN
221  ff(i,k) = f(i,k)
222  END IF
223  END DO
224  END DO
225 
226  ! THIS PIECE OF CODE DESPERATELY NEEDS TO BE CLARIFIED
227  ! AND STREAMLINED
228 
229  DO i = 1, m
230  IF (isonb(i) /= 2) THEN
231  IF(iswetn(i) == 1)THEN
232  tmp1=pfpxb(i)*cos(sita_gd(i))+pfpyb(i)*sin(sita_gd(i))
233  tmp2=ah_bottom(i)*phpn(i)
234  tmp3=khbottom(i)+umolpr+ah_bottom(i)*phpn(i)*phpn(i)
235  tmp=tmp1*tmp2/tmp3*(khbottom(i)+umolpr)
236 
237  ! -------------------------------------------------------------------
238  IF(noflux_bot_condition)THEN
239  SELECT CASE(ncon1)
240  CASE(1)
241  IF (tmp1 > 0.0_sp) tmp=0.0_sp
242  CASE(2)
243 !!$ IF (TMP1 > 0.0_SP) TMP=0.0_SP
244  IF (tmp1 < 0.0_sp) tmp=0.0_sp
245  tmp = -tmp
246  CASE DEFAULT
247  CALL fatal_error('NCON NOT CORRECT IN VDIF_TS')
248  END SELECT
249  ELSE
250  tmp = 0.0_sp
251  END IF
252  ! -------------------------------------------------------------------
253 
254 !!$ THIS IS FOR AN OLDER VERSION OF GROUNDWATER
255 !!$ GW=0.0_SP
256 !!$ IF(NCON1 == 2) THEN ! MODIFIED FOR NEW BFWDIS
257 !!$ IF (BFWDIS(I) /= 0.0_SP) THEN
258 !!$
259 !!$ QTMP=-(F(I,KBM1)*D(I)*DZ(I,KBM1)*BFWDIS(I))/ &
260 !!$ (D(I)*DZ(I,KBM1)*ART1(I)+BFWDIS(I))
261 !!$ GW=DTI/D(I)/DZ(I,KBM1)*QTMP
262 !!$
263 !!$ TMP=0.0_SP
264 !!$
265 !!$ END IF
266 !!$ END IF
267 
268 
269  ff(i,kbm1) = (cf(i,kbm1)*vhpf(i,kbm2)-ff(i,kbm1)-gw+dti*(rad(i,kbm1)-rad(i,kb)-tmp)/(d(i)*dz(i,kbm1))) &
270  /(cf(i,kbm1)*(1._sp-vhf(i,kbm2))-1._sp)
271 
272 
273  END IF
274  END IF
275  END DO
276 
277  DO k = 2, kbm1
278  ki = kb - k
279  DO i = 1, m
280  IF(isonb(i) /= 2) THEN
281  IF(iswetn(i) == 1)THEN
282  ff(i,ki) = (vhf(i,ki)*ff(i,ki+1)+vhpf(i,ki))
283  END IF
284  END IF
285 
286 
287  END DO
288  END DO
289 
290  DO i = 1, m
291  IF(iswetn(i)*iswetnt(i) == 1 )then
292  DO k = 1, kbm1
293  f(i,k) = ff(i,k)
294  END DO
295  END IF
296  END DO
297 
298 
299  IF(dbg_set(dbg_sbr)) WRITE(ipt,*)"End: vdif_ts"
300  RETURN
real(sp), dimension(:), allocatable, target d
Definition: mod_main.f90:1132
real(sp) umol
Definition: mod_main.f90:365
logical function dbg_set(vrb)
Definition: mod_utils.f90:182
real(sp), dimension(:), allocatable, target pfpxb
Definition: mod_main.f90:1342
real(sp) dti
Definition: mod_main.f90:844
real(sp) zeta1
Definition: mod_main.f90:462
integer m
Definition: mod_main.f90:56
real(sp), dimension(:), allocatable, target pfpyb
Definition: mod_main.f90:1343
real(sp), dimension(:), allocatable, target phpn
Definition: mod_main.f90:1341
real(sp), dimension(:), allocatable, target swrad
Definition: mod_main.f90:1177
integer kb
Definition: mod_main.f90:64
character(len=80) heating_type
Definition: mod_main.f90:451
integer kbm2
Definition: mod_main.f90:66
real(sp) rheat
Definition: mod_main.f90:461
logical noflux_bot_condition
Definition: mod_main.f90:405
real(sp), dimension(:,:), allocatable, target dzz
Definition: mod_main.f90:1093
real(sp), dimension(:), allocatable, target sita_gd
Definition: mod_main.f90:1344
real(sp), dimension(:,:), allocatable, target dz
Definition: mod_main.f90:1092
integer, dimension(:), allocatable iswetnt
Definition: mod_wd.f90:53
real(sp), dimension(:,:), allocatable, target kh
Definition: mod_main.f90:1294
real(sp), dimension(:,:), allocatable, target z
Definition: mod_main.f90:1090
subroutine fatal_error(ER1, ER2, ER3, ER4)
Definition: mod_utils.f90:230
real(sp) zeta2
Definition: mod_main.f90:463
real(sp), dimension(:), allocatable, target ah_bottom
Definition: mod_main.f90:1345
integer ipt
Definition: mod_main.f90:922
real(sp), dimension(:), allocatable, target wtsurf
Definition: mod_main.f90:1178
integer, parameter dbg_sbr
Definition: mod_utils.f90:69
integer kbm1
Definition: mod_main.f90:65
integer, dimension(:), allocatable, target isonb
Definition: mod_main.f90:1024
integer, dimension(:), allocatable iswetn
Definition: mod_wd.f90:51
Here is the call graph for this function:
Here is the caller graph for this function: