My Project
mod_meanflow.f90
Go to the documentation of this file.
1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 !/===========================================================================/
13 ! Copyright (c) 2007, The University of Massachusetts Dartmouth
14 ! Produced at the School of Marine Science & Technology
15 ! Marine Ecosystem Dynamics Modeling group
16 ! All rights reserved.
17 !
18 ! FVCOM has been developed by the joint UMASSD-WHOI research team. For
19 ! details of authorship and attribution of credit please see the FVCOM
20 ! technical manual or contact the MEDM group.
21 !
22 !
23 ! This file is part of FVCOM. For details, see http://fvcom.smast.umassd.edu
24 ! The full copyright notice is contained in the file COPYRIGHT located in the
25 ! root directory of the FVCOM code. This original header must be maintained
26 ! in all distributed versions.
27 !
28 ! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
29 ! AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
30 ! THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
31 ! PURPOSE ARE DISCLAIMED.
32 !
33 !/---------------------------------------------------------------------------/
34 ! CVS VERSION INFORMATION
35 ! $Id$
36 ! $Name$
37 ! $Revision$
38 !/===========================================================================/
39 
41  USE all_vars
42  USE mod_prec
43  USE mod_types
44  IMPLICIT NONE
45  SAVE
46  INTEGER :: mf_rst_stcnt
49  INTEGER, ALLOCATABLE :: mf_gl2loc(:)
50  INTEGER, ALLOCATABLE :: i_mfcell_gl(:),i_mfcell_n(:)
51  REAL(sp),ALLOCATABLE :: dmfqdis(:,:),mfqdis(:),mfdist(:,:)
52  REAL(sp),ALLOCATABLE :: anglemf(:),mfarea(:),vlctymf(:)
53  TYPE(bc) :: mf_tm !!TIME MAP FOR MEAN FLOW DATA
54  REAL(sp),ALLOCATABLE :: rdismf(:,:)
55  INTEGER ,ALLOCATABLE :: node_mfcell(:,:)
56 
57  CONTAINS
58 
59 ! we still need to consider the case in which MEAN FLOW bring in/take out T & S
60 !==============================================================================|
61 ! READ IN MEAN FLOW OPEN BOUNDARY FLUX (m^3/s^1) TIME SERIES |
62 !==============================================================================|
63 
64  SUBROUTINE read_meanflow
65 
66 !------------------------------------------------------------------------------!
67  INTEGER :: k,i,j,i1,i2,i3,ii,NCNT,itemp,IERR
68  INTEGER, ALLOCATABLE :: temp1(:),temp2(:)
69  REAL(SP),ALLOCATABLE :: RTEMP1(:,:),RTEMP2(:,:)
70  REAL(SP) :: ttemp
71 
72  rewind(inmf)
73  READ(inmf,*) nmfcell_gl
74 
75  nmfcell_i = 0
76  nmfcell = 0
77  IF (nmfcell_gl > 0) THEN
78 
79  ALLOCATE(i_mfcell_gl(nmfcell_gl))
80  DO i=1,nmfcell_gl
81  READ(inmf,*)i_mfcell_gl(i)
82  ENDDO
83 
84 !----Read in Mean Flow Flux Vertical Distribution---------------------
85  ALLOCATE(rtemp1(nmfcell_gl,kbm1))
86  DO i = 1, nmfcell_gl
87  READ(inmf,*) j,(rtemp1(i,k),k = 1,kbm1)
88  END DO
89 
90 !----Read in Time Dependent DataSets ---------------------------------
91  READ(inmf,*) itemp
92  mf_tm%NTIMES = itemp
93  mf_tm%LABEL = "open boundary mean flow flux"
94  ALLOCATE(mf_tm%TIMES(itemp))
95  ALLOCATE(rtemp2(nmfcell_gl,itemp))
96  DO i = 1, itemp
97  READ(inmf,*) ttemp
98  mf_tm%TIMES(i) = ttemp
99  READ(inmf,*) (rtemp2(j,i),j = 1,nmfcell_gl)
100 !--------------------------------Jianzhong----------------------------
101  IF(msr)WRITE(ipt,*)maxval(rtemp2(1:nmfcell_gl,i))&
102  &,maxloc(rtemp2(1:nmfcell_gl,i)) ,minval(rtemp2(1:nmfcell_gl,i))&
103  &,minloc(rtemp2(1:nmfcell_gl,i))
104 !---------------------------------------------------------------------
105  ! WRITE(IOPRT,*) ttemp
106  ! WRITE(IOPRT,*) (RTEMP2(J,I),J = 1,nmfcell_GL)
107  END DO
108  CLOSE(inmf)
109 
110 !
111 !---Map to Local Domain----------------------------------------
112 
113  IF(serial)THEN
116  ALLOCATE(i_mfcell_n(nmfcell))
118  ALLOCATE(mfdist(nmfcell,kbm1))
119  mfdist = rtemp1
120  ALLOCATE(dmfqdis(nmfcell,mf_tm%NTIMES))
121  dmfqdis = rtemp2
122  END IF
123 
124 
125  DEALLOCATE(rtemp1,rtemp2)
126 
127  ELSE ! if statement end for nmfcell_GL > 0
128  close(inmf)
129  END IF
130 
131 !--------------------------------------Jianzhong----------------------
132  WRITE(ipt,*)'NMFCELL_I=',nmfcell_i,'NMFCELL=',nmfcell,'IN THREAD:',myid
133 !---------------------------------------------------------------------
134 
135  RETURN
136  END SUBROUTINE read_meanflow
137 !==============================================================================|
138 
139 
140 !==============================================================================|
141 ! SET METRICS FOR MEAN FLOW BOUNDARY CONDITIONS |
142 !==============================================================================|
143 
144  SUBROUTINE set_bndry_meanflow
146 !------------------------------------------------------------------------------!
147 
148  USE bcs
149  USE mod_obcs
150 
151  IMPLICIT NONE
152  REAL(DP) DX12,DY12,ATMP1,HTMP
153  INTEGER I,J,I1,I2,J1,J2,II,ITMP,JTMP
154 !------------------------------------------------------------------------------!
155 
156  IF(nmfcell > 0)THEN
157 
159  ALLOCATE(node_mfcell(nmfcell,2),rdismf(nmfcell,2))
160 
161  DO i=1,nmfcell
162  ii=i_mfcell_n(i)
163  IF(i <= nmfcell_i .and. isbce(ii) /= 2) THEN
164  print*, 'NO.',i,'MEAN FLOW CELL'
165  print*, 'IS NOT A OPEN BOUNDARY ONE'
166  CALL pstop
167  END IF
168  itmp=0
169  DO j=1,3
170  IF(nbe(ii,j) == 0 .and. isonb(nv(ii,j)) /= 2) THEN
171  jtmp=j
172  itmp=itmp+1
173  END IF
174  END DO
175  IF(itmp /= 1) THEN
176  print*, 'NO OPEN BOUNDARY OR MORE THAN ONE OPEN BOUNDARY'
177  print*, 'IN NO.',i,'MEAN FLOW CELL'
178  CALL pstop
179  END IF
180  j1=jtmp+1-int((jtmp+1)/4)*3
181  j2=jtmp+2-int((jtmp+2)/4)*3
182  i1=nv(ii,j1)
183  i2=nv(ii,j2)
184 
185  node_mfcell(i,1)=i1
186  node_mfcell(i,2)=i2
187 
188  htmp=0.5_sp*(h(i1)+h(i2)) ! may be a problem here, should be replaced dy D
189  dy12=vy(i1)-vy(i2)
190  dx12=vx(i1)-vx(i2)
191  atmp1=atan2(dy12,dx12)
192  mfarea(i)=sqrt(dx12**2+dy12**2)*htmp ! for spherical coordinates is Phthagolean Theorem still valid?
193  anglemf(i)=atmp1+3.1415927/2.0
194  rdismf(i,1)=art1(i1)/(art1(i1)+art1(i2))
195  rdismf(i,2)=art1(i2)/(art1(i1)+art1(i2))
196  END DO
197  END IF
198 
199  RETURN
200  END SUBROUTINE set_bndry_meanflow
201 !==============================================================================|
202 
203 !==============================================================================|
204 ! INTERPOLATION MEAN FLOW OPEN BOUNDARY FLUX (m^3/s^1) TIME SERIES |
205 !==============================================================================|
206 
207  SUBROUTINE bcond_meanflow
208 !
209 !------------------------------------------------------------------------------!
210  USE all_vars
211  USE bcs
212  USE mod_obcs
213 
214  INTEGER L1,L2,IERR,II
215  REAL(SP) :: FACT,UFACT
216  REAL(SP) :: THOUR
217 
218  thour = dti*float(iint)/3600.0
219  IF(nmfcell > 0)THEN
220  CALL bracket(mf_tm,thour,l1,l2,fact,ufact,ierr)
221  mfqdis(:) = ufact*dmfqdis(:,l1) + fact*dmfqdis(:,l2)
222  mfqdis = mfqdis*ramp
223  END IF
224 
225  RETURN
226  END SUBROUTINE bcond_meanflow
227 
228  SUBROUTINE bracket(TMAP,STIME,L1,L2,FACT,BACT,IERR)
229 !==============================================================================|
230 ! DETERMINE DATA INTERVAL IN WHICH CURRENT TIME LIES |
231 ! |
232 ! L1: DATA INTERVAL PROCEEDING TIME |
233 ! L2: DATA INTERVAL AFTER TIME |
234 ! FACT: LINEAR INTERPOLATION COEFFICIENT (0->1) |
235 ! FACT = .5 : STIME LIES EXACTLY BETWEEN TWO DATA TIMES |
236 ! FACT = 1. : STIME OCCURS AT SECOND DATA TIME |
237 ! BACT = 1.-FACT
238 ! IERR: RETURNS INTEGER ERROR |
239 ! IERR = 0 : NO ERROR, TIME IS BRACKETED BY DATA TIMES |
240 ! IERR =-1 : STIME PROCEEDS ALL DATA TIMES |
241 ! IERR = 1 : STIME IS GREATER THAN ALL DATA TIMES |
242 ! |
243 ! IF STIME PROCEEDS DATA, IERR IS SET TO -1, L1 TO 1, AND FACT TO 0. !
244 ! IF STIME SUPERCEEDS DATA, IERR IS SET TO -1, L2 TO LMAX, AND FACT TO 1. !
245 !==============================================================================|
246  USE mod_types
247  IMPLICIT NONE
248 !------------------------------------------------------------------------------!
249  TYPE(bc), INTENT(IN) :: TMAP
250  REAL(SP), INTENT(IN) :: STIME
251  INTEGER, INTENT(OUT) :: L1,L2
252  REAL(SP), INTENT(OUT) :: FACT,BACT
253  INTEGER, INTENT(OUT) :: IERR
254 !------------------------------------------------------------------------------!
255  REAL(SP) T1,T2
256  INTEGER I,NTMAX
257 !==============================================================================|
258 
259  ntmax = tmap%NTIMES
260  IF(stime < tmap%TIMES(1))THEN
261  fact = 0.0_sp
262  bact = 1.0_sp
263  l1 = 1
264  l2 = 1
265  ierr = -1
266  RETURN
267  END IF
268 
269  IF(stime > tmap%TIMES(ntmax))THEN
270  fact = 1.0_sp
271  bact = 0.0_sp
272  l1 = ntmax
273  l2 = ntmax
274  ierr = 1
275  RETURN
276  END IF
277 
278  IF(ntmax == 1)THEN
279  fact = 1.0_sp
280  bact = 0.0_sp
281  l1 = 1
282  l2 = 1
283  ierr = 0
284  RETURN
285  END IF
286 
287 
288  DO i=2,tmap%NTIMES
289  t1 = tmap%TIMES(i-1)
290  t2 = tmap%TIMES(i)
291  IF(stime >= t1 .AND. stime <= t2)THEN
292  l1 = i-1
293  l2 = i
294  ierr = 0
295  fact = (stime-t1)/(t2-t1)
296  bact = 1.0_sp-fact
297  END IF
298  END DO
299 
300 
301  RETURN
302  END SUBROUTINE bracket
303 !==============================================================================|
304 
305 
306 END MODULE mod_meanflow
integer nmfcell_gl
real(sp), dimension(:), allocatable vlctymf
type(bc) mf_tm
real(sp), dimension(:), allocatable, target h
Definition: mod_main.f90:1131
integer, dimension(:,:), allocatable node_mfcell
integer, dimension(:), allocatable i_mfcell_n
integer intelel
real(sp), dimension(:), allocatable, target art1
Definition: mod_main.f90:1010
real(sp), dimension(:,:), allocatable dmfqdis
integer mf_rst_stcnt
real(sp), dimension(:), allocatable, target vx
Definition: mod_main.f90:1001
integer, parameter sp
Definition: mod_prec.f90:48
real(sp), dimension(:), allocatable anglemf
real(sp), dimension(:), allocatable, target vy
Definition: mod_main.f90:1002
integer, dimension(:,:), allocatable, target nbe
Definition: mod_main.f90:1020
integer intnode
integer, dimension(:,:), allocatable, target nv
Definition: mod_main.f90:1018
integer nmfcell
integer, dimension(:), allocatable mf_gl2loc
subroutine read_meanflow
real(sp), dimension(:,:), allocatable mfdist
real(sp), dimension(:), allocatable mfqdis
integer, dimension(:), allocatable, target isbce
Definition: mod_main.f90:1027
real(sp), dimension(:), allocatable mfarea
subroutine bcond_meanflow
real(sp), dimension(:,:), allocatable rdismf
subroutine bracket(TMAP, STIME, L1, L2, FACT, BACT, IERR)
integer nmfcell_i
integer intcell
subroutine set_bndry_meanflow
integer, dimension(:), allocatable, target isonb
Definition: mod_main.f90:1024
integer, dimension(:), allocatable i_mfcell_gl