source: codes/icosagcm/trunk/src/guided_ncar_mod.f90 @ 19

Last change on this file since 19 was 19, checked in by ymipsl, 12 years ago

Simplify the management of the module.

YM

File size: 5.0 KB
Line 
1MODULE guided_ncar_mod
2  USE icosa
3  PRIVATE
4 
5  REAL(rstd),SAVE :: dt
6  INTEGER,SAVE    :: test
7 
8  PUBLIC init_guided, guided
9
10CONTAINS
11
12
13  SUBROUTINE init_guided(dt_in)
14  IMPLICIT NONE
15    REAL(rstd),INTENT(IN) :: dt_in
16   
17    dt=dt_in
18    test=2
19   
20  END SUBROUTINE init_guided
21
22 
23  SUBROUTINE guided(it, f_ps, f_theta_rhodz, f_u, f_q)
24  USE icosa
25    IMPLICIT NONE
26    INTEGER, INTENT(IN)   :: it
27    TYPE(t_field),POINTER :: f_ps(:)
28    TYPE(t_field),POINTER :: f_phis(:)
29    TYPE(t_field),POINTER :: f_theta_rhodz(:)
30    TYPE(t_field),POINTER :: f_u(:) 
31    TYPE(t_field),POINTER :: f_q(:) 
32   
33    REAL(rstd),POINTER :: ue(:,:)
34    INTEGER :: ind
35   
36    DO ind = 1 , ndomain
37      CALL swap_dimensions(ind)
38      CALL swap_geometry(ind) 
39      ue = f_u(ind) 
40      CALL wind_profile(it,ue)
41    END DO   
42
43  END SUBROUTINE guided
44 
45
46  SUBROUTINE wind_profile(it,ue)
47  USE icosa
48  IMPLICIT NONE
49    INTEGER,INTENT(IN) :: it 
50    REAL(rstd),INTENT(OUT) :: ue(iim*3*jjm,llm)
51    REAL(rstd) :: lon, lat
52    REAL(rstd) :: nx(3),n_norm,Velocity(3,llm)
53    REAL(rstd), PARAMETER :: lon0=3*pi/2,lat0=0.0
54    REAL(rstd) :: rr1,rr2,bb,cc,aa,hmx
55    REAL(rstd) :: v1(3),v2(3),ny(3)
56    INTEGER :: i,j,n,l
57    REAL(rstd) :: zrl(llm)
58
59    CALL compute_zrl(zrl)
60!---------------------------------------------------------
61    DO l = 1,llm 
62      DO j=jj_begin-1,jj_end+1
63        DO i=ii_begin-1,ii_end+1
64          n=(j-1)*iim+i
65          CALL compute_velocity(xyz_e(n+u_right,:),l,velocity(:,l))
66          CALL cross_product2(xyz_v(n+z_rdown,:)/radius,xyz_v(n+z_rup,:)/radius,nx)       
67          ue(n+u_right,l)=1e-10
68          n_norm=sqrt(sum(nx(:)**2))
69          IF (n_norm>1e-30) THEN
70            nx=-nx/n_norm*ne(n,right)
71            ue(n+u_right,l)=sum(nx(:)*velocity(:,l))
72            IF (ABS(ue(n+u_right,l))<1e-100) PRINT *,"ue(n+u_right) ==0",i,j,velocity(:,1)
73          ENDIF
74             
75          CALL compute_velocity(xyz_e(n+u_lup,:),l,velocity(:,l))
76          CALL cross_product2(xyz_v(n+z_up,:)/radius,xyz_v(n+z_lup,:)/radius,nx)
77
78          ue(n+u_lup,l)=1e-10
79          n_norm=sqrt(sum(nx(:)**2))
80          IF (n_norm>1e-30) THEN
81            nx=-nx/n_norm*ne(n,lup)
82            ue(n+u_lup,l)=sum(nx(:)*velocity(:,l))
83          ENDIF
84       
85          CALL compute_velocity(xyz_e(n+u_ldown,:),l,velocity(:,l))
86          CALL cross_product2(xyz_v(n+z_ldown,:)/radius,xyz_v(n+z_down,:)/radius,nx)
87
88          ue(n+u_ldown,l)=1e-10
89          n_norm=sqrt(sum(nx(:)**2))
90          IF (n_norm>1e-30) THEN
91            nx=-nx/n_norm*ne(n,ldown)
92            ue(n+u_ldown,l)=sum(nx(:)*velocity(:,l))
93            IF (ABS(ue(n+u_ldown,l))<1e-100) PRINT *,"ue(n+u_ldown) ==0",i,j
94          ENDIF       
95        ENDDO
96      ENDDO
97    END DO
98 
99  CONTAINS
100           
101    SUBROUTINE compute_velocity(x,l,velocity)
102      IMPLICIT NONE
103      REAL(rstd),INTENT(IN)  :: x(3)
104      INTEGER,INTENT(IN)::l
105      REAL(rstd),INTENT(OUT) :: velocity(3)
106      REAL(rstd) :: u0
107      REAL(rstd)  :: e_lat(3), e_lon(3)
108      REAL(rstd) :: lon,lat
109      REAL(rstd),PARAMETER::alpha=0.0
110      REAL(rstd) :: u,v
111!--------------------------------- test 1
112      REAL(rstd),parameter:: nday=12,daysec=86400
113      REAL(rstd),PARAMETER :: tau = nday*daysec
114      REAL(rstd) :: tt, pitbytau,kk
115!---------------------------------- hadley
116      INTEGER,PARAMETER::K_hadly=5
117      REAL(rstd),PARAMETER::u0_hadly=40.,w0_hadly=0.25 ,ztop= 12000. 
118      REAL(rstd)::coff_hadly
119       
120       
121      tt = it*dt 
122      pitbytau = pi*tt/tau 
123      kk = 10*radius/tau 
124     
125      CALL xyz2lonlat(x/radius,lon,lat)
126      e_lat(1) = -cos(lon)*sin(lat)
127      e_lat(2) = -sin(lon)*sin(lat)
128      e_lat(3) = cos(lat)
129       
130      e_lon(1) = -sin(lon)
131      e_lon(2) = cos(lon)
132      e_lon(3) = 0
133
134      u = 0.0 ; v = 0.0
135      u0 = 2*pi*radius/tau
136   
137      SELECT CASE(test) 
138        CASE(0) 
139          u=u0*(cos(lat)*cos(alpha)+sin(lat)*sin(alpha)*cos(lon))
140          v=-u0*sin(lon)*sin(alpha)
141        CASE(1) 
142          lon = lon - 2*pitbytau 
143          u= kk*sin(lon)*sin(lon)*sin(2*lat)*cos(pitbytau)+ u0*cos(lat) 
144          v= kk*sin(2*lon)*cos(lat)*cos(pitbytau) 
145        CASE(2)
146          coff_hadly = -radius*w0_hadly*pi/(5.0*ztop) 
147          u= u0_hadly*cos(lat) 
148          v= coff_hadly*cos(lat)*sin(5.*lat)*cos(pi*zrl(l)/ztop)*cos(pitbytau)
149        CASE DEFAULT 
150          PRINT*,"not valid choice of wind" 
151       END SELECT
152
153      Velocity(:)=(u*e_lon(:)+v*e_lat(:)+1e-50)
154
155    END SUBROUTINE compute_velocity
156   
157    SUBROUTINE compute_zrl(zrl)
158    USE disvert_mod
159    IMPLICIT NONE
160      REAL(rstd),INTENT(OUT) :: zrl(llm)
161      INTEGER :: l
162      REAL(rstd) :: zr(llm+1)
163      REAl(rstd) :: pr
164      REAL(rstd), PARAMETER :: T0=300
165      REAL(rstd), PARAMETER :: R_d=287.0   
166      REAL(rstd), PARAMETER :: ps0=100000.0
167
168     
169      DO    l    = 1, llm+1
170        pr = ap(l) + bp(l)*ps0
171        zr(l) = -R_d*T0/g*log(pr/ps0) 
172      ENDDO   
173
174      DO l = 1, llm 
175        zrl(l) = 0.5*(zr(l) + zr(l+1)) 
176      END DO
177   
178    END SUBROUTINE compute_zrl
179 
180  END SUBROUTINE  wind_profile
181
182
183END MODULE guided_ncar_mod
Note: See TracBrowser for help on using the repository browser.