source: codes/icosagcm/trunk/src/etat0.f90 @ 375

Last change on this file since 375 was 366, checked in by dubos, 9 years ago

Progress towards NH

File size: 10.8 KB
Line 
1MODULE etat0_mod
2  USE icosa
3  IMPLICIT NONE         
4  PRIVATE
5
6    CHARACTER(len=255),SAVE :: etat0_type
7!$OMP THREADPRIVATE(etat0_type)
8
9    REAL(rstd) :: etat0_temp
10
11    PUBLIC :: etat0, etat0_type
12
13CONTAINS
14 
15  SUBROUTINE etat0(f_ps,f_mass,f_phis,f_theta_rhodz,f_u, f_geopot,f_w, f_q)
16    USE mpipara, ONLY : is_mpi_root
17    USE disvert_mod
18    ! Generic interface
19    USE etat0_dcmip1_mod, ONLY : getin_etat0_dcmip1=>getin_etat0
20    USE etat0_dcmip2_mod, ONLY : getin_etat0_dcmip2=>getin_etat0
21    USE etat0_dcmip4_mod, ONLY : getin_etat0_dcmip4=>getin_etat0
22    USE etat0_dcmip5_mod, ONLY : getin_etat0_dcmip5=>getin_etat0
23    USE etat0_williamson_mod, ONLY : getin_etat0_williamson=>getin_etat0
24    USE etat0_temperature_mod, ONLY: getin_etat0_temperature=>getin_etat0
25    ! Ad hoc interfaces
26    USE etat0_academic_mod, ONLY : etat0_academic=>etat0 
27    USE etat0_heldsz_mod, ONLY : etat0_heldsz=>etat0 
28    USE etat0_venus_mod,  ONLY : etat0_venus=>etat0 
29    USE etat0_start_file_mod, ONLY : etat0_start_file=>etat0 
30
31    IMPLICIT NONE
32    TYPE(t_field),POINTER :: f_ps(:)
33    TYPE(t_field),POINTER :: f_mass(:)
34    TYPE(t_field),POINTER :: f_phis(:)
35    TYPE(t_field),POINTER :: f_theta_rhodz(:)
36    TYPE(t_field),POINTER :: f_u(:)
37    TYPE(t_field),POINTER :: f_geopot(:)
38    TYPE(t_field),POINTER :: f_w(:)
39    TYPE(t_field),POINTER :: f_q(:)
40   
41    REAL(rstd),POINTER :: ps(:), mass(:,:)
42    LOGICAL :: autoinit_mass, autoinit_geopot, collocated
43    INTEGER :: ind,i,j,ij,l
44
45    ! most etat0 routines set ps and not mass
46    ! in that case and if caldyn_eta == eta_lag
47    ! the initial distribution of mass is taken to be the same
48    ! as what the mass coordinate would dictate
49    ! however if etat0_XXX defines mass then the flag autoinit_mass must be set to .FALSE.
50    ! otherwise mass will be overwritten
51    autoinit_mass = (caldyn_eta == eta_lag)
52
53    etat0_type='jablonowsky06'
54    CALL getin("etat0",etat0_type)
55   
56    !------------------- Generic interface ---------------------
57    collocated=.TRUE.
58    SELECT CASE (TRIM(etat0_type))
59    CASE ('isothermal')
60       CALL getin_etat0_isothermal
61    CASE ('temperature_profile')
62       CALL getin_etat0_temperature
63    CASE ('jablonowsky06')
64    CASE ('dcmip1')
65        CALL getin_etat0_dcmip1
66    CASE ('dcmip2_mountain','dcmip2_schaer_noshear','dcmip2_schaer_shear')
67       CALL getin_etat0_dcmip2
68    CASE ('dcmip3')
69    CASE ('dcmip4')
70        CALL getin_etat0_dcmip4
71    CASE ('dcmip5')
72        CALL getin_etat0_dcmip5
73    CASE ('williamson91.6')
74       autoinit_mass=.FALSE.
75       CALL getin_etat0_williamson
76    CASE DEFAULT
77       collocated=.FALSE.
78       autoinit_mass = .FALSE.
79    END SELECT
80
81    !------------------- Ad hoc interfaces --------------------
82    SELECT CASE (TRIM(etat0_type))
83    CASE ('start_file')
84       CALL etat0_start_file(f_ps,f_phis,f_theta_rhodz,f_u, f_q)
85    CASE ('academic')
86       CALL etat0_academic(f_ps,f_phis,f_theta_rhodz,f_u, f_q)
87    CASE ('held_suarez')
88       PRINT *,"Held & Suarez (1994) test case"
89       CALL etat0_heldsz(f_ps,f_phis,f_theta_rhodz,f_u, f_q)
90    CASE ('venus')
91       CALL etat0_venus(f_ps, f_phis, f_theta_rhodz, f_u, f_q)
92       PRINT *, "Venus (Lebonnois et al., 2012) test case"
93   CASE DEFAULT
94      IF(collocated) THEN
95         CALL etat0_collocated(f_phis,f_ps,f_mass,f_theta_rhodz,f_u, f_geopot,f_W, f_q)
96      ELSE
97         PRINT*, 'Bad selector for variable etat0 <',etat0_type, &
98              '> options are <jablonowsky06>, <academic>, <dcmip[1-4]> '
99         STOP
100      END IF
101    END SELECT
102
103!       !$OMP BARRIER
104    IF(autoinit_mass) THEN
105       DO ind=1,ndomain
106          IF (.NOT. assigned_domain(ind)) CYCLE
107          CALL swap_dimensions(ind)
108          CALL swap_geometry(ind)
109          mass=f_mass(ind); ps=f_ps(ind)
110          CALL compute_rhodz(.TRUE., ps, mass) ! initialize mass distribution using ps
111       END DO
112    END IF
113 
114  END SUBROUTINE etat0
115
116  SUBROUTINE etat0_collocated(f_phis,f_ps,f_mass,f_theta_rhodz,f_u, f_geopot,f_W, f_q)
117    USE theta2theta_rhodz_mod
118    IMPLICIT NONE
119    TYPE(t_field),POINTER :: f_ps(:)
120    TYPE(t_field),POINTER :: f_mass(:)
121    TYPE(t_field),POINTER :: f_phis(:)
122    TYPE(t_field),POINTER :: f_theta_rhodz(:)
123    TYPE(t_field),POINTER :: f_u(:)
124    TYPE(t_field),POINTER :: f_geopot(:)
125    TYPE(t_field),POINTER :: f_W(:)
126    TYPE(t_field),POINTER :: f_q(:)
127 
128    TYPE(t_field),POINTER,SAVE :: f_temp(:)
129    REAL(rstd),POINTER :: ps(:)
130    REAL(rstd),POINTER :: mass(:,:)
131    REAL(rstd),POINTER :: phis(:)
132    REAL(rstd),POINTER :: theta_rhodz(:,:)
133    REAL(rstd),POINTER :: temp(:,:)
134    REAL(rstd),POINTER :: u(:,:)
135    REAL(rstd),POINTER :: geopot(:,:)
136    REAL(rstd),POINTER :: W(:,:)
137    REAL(rstd),POINTER :: q(:,:,:)
138    INTEGER :: ind
139
140    CALL allocate_field(f_temp,field_t,type_real,llm,name='temp')
141
142    DO ind=1,ndomain
143      IF (.NOT. assigned_domain(ind)) CYCLE
144      CALL swap_dimensions(ind)
145      CALL swap_geometry(ind)
146      ps=f_ps(ind)
147      mass=f_mass(ind)
148      phis=f_phis(ind)
149      theta_rhodz=f_theta_rhodz(ind)
150      temp=f_temp(ind)
151      u=f_u(ind)
152      geopot=f_geopot(ind)
153      w=f_w(ind)
154      q=f_q(ind)
155
156      IF( TRIM(etat0_type)=='williamson91.6' ) THEN
157       CALL compute_etat0_collocated(ps,mass, phis, theta_rhodz, u, geopot, W, q)
158      ELSE
159       CALL compute_etat0_collocated(ps,mass, phis, temp, u, geopot, W, q)
160      ENDIF
161    ENDDO
162   
163    IF( TRIM(etat0_type)/='williamson91.6' ) CALL temperature2theta_rhodz(f_ps,f_temp,f_theta_rhodz)
164   
165    CALL deallocate_field(f_temp)
166   
167  END SUBROUTINE etat0_collocated
168
169  SUBROUTINE compute_etat0_collocated(ps,mass,phis,temp_i,u, geopot,W, q)
170    USE wind_mod
171    USE disvert_mod
172    USE etat0_jablonowsky06_mod, ONLY : compute_jablonowsky06 => compute_etat0
173    USE etat0_dcmip1_mod, ONLY : compute_dcmip1 => compute_etat0
174    USE etat0_dcmip2_mod, ONLY : compute_dcmip2 => compute_etat0
175    USE etat0_dcmip3_mod, ONLY : compute_dcmip3 => compute_etat0
176    USE etat0_dcmip4_mod, ONLY : compute_dcmip4 => compute_etat0
177    USE etat0_dcmip5_mod, ONLY : compute_dcmip5 => compute_etat0
178    USE etat0_williamson_mod, ONLY : compute_w91_6 => compute_etat0
179    USE etat0_temperature_mod, ONLY: compute_etat0_temperature => compute_etat0
180    IMPLICIT NONE
181    REAL(rstd),INTENT(INOUT) :: ps(iim*jjm)
182    REAL(rstd),INTENT(INOUT) :: mass(iim*jjm,llm)
183    REAL(rstd),INTENT(OUT) :: phis(iim*jjm)
184    REAL(rstd),INTENT(OUT) :: temp_i(iim*jjm,llm)
185    REAL(rstd),INTENT(OUT) :: u(3*iim*jjm,llm)
186    REAL(rstd),INTENT(OUT) :: W(iim*jjm,llm+1)
187    REAL(rstd),INTENT(OUT) :: geopot(iim*jjm,llm+1)
188    REAL(rstd),INTENT(OUT) :: q(iim*jjm,llm,nqtot)
189
190    REAL(rstd) :: ulon_i(iim*jjm,llm)
191    REAL(rstd) :: ulat_i(iim*jjm,llm)
192
193    REAL(rstd) :: ps_e(3*iim*jjm)
194    REAL(rstd) :: mass_e(3*iim*jjm,llm)
195    REAL(rstd) :: phis_e(3*iim*jjm)
196    REAL(rstd) :: temp_e(3*iim*jjm,llm)
197    REAL(rstd) :: geopot_e(3*iim*jjm,llm+1)
198    REAL(rstd) :: ulon_e(3*iim*jjm,llm)
199    REAL(rstd) :: ulat_e(3*iim*jjm,llm)
200    REAL(rstd) :: q_e(3*iim*jjm,llm,nqtot)
201
202    INTEGER :: l,i,j,ij
203    REAL :: p_ik, v_ik, mass_ik
204    LOGICAL :: autoinit_mass, autoinit_NH
205
206    ! For NH geopotential and vertical momentum must be initialized.
207    ! Unless autoinit_mass is set to .FALSE. , they will be initialized
208    ! to hydrostatic geopotential and zero
209    autoinit_mass = .TRUE.
210    autoinit_NH = .NOT. hydrostatic
211    w(:,:) = 0
212
213    !$OMP BARRIER
214
215    SELECT CASE (TRIM(etat0_type))
216    CASE ('isothermal')
217       CALL compute_etat0_isothermal(iim*jjm, phis, ps, temp_i, ulon_i, ulat_i, q)
218       CALL compute_etat0_isothermal(3*iim*jjm, phis_e, ps_e, temp_e, ulon_e, ulat_e, q_e)
219    CASE ('temperature_profile')
220       CALL compute_etat0_temperature(iim*jjm, phis, ps, temp_i, ulon_i, ulat_i, q)
221       CALL compute_etat0_temperature(3*iim*jjm, phis_e, ps_e, temp_e, ulon_e, ulat_e, q_e)
222    CASE('jablonowsky06')
223       CALL compute_jablonowsky06(iim*jjm,lon_i,lat_i, phis, ps, temp_i, ulon_i, ulat_i)
224       CALL compute_jablonowsky06(3*iim*jjm,lon_e,lat_e, phis_e, ps_e, temp_e, ulon_e, ulat_e)
225    CASE('dcmip1')
226       CALL compute_dcmip1(iim*jjm,lon_i,lat_i, phis, ps, temp_i, ulon_i, ulat_i, q)
227       CALL compute_dcmip1(3*iim*jjm,lon_e,lat_e, phis_e, ps_e, temp_e, ulon_e, ulat_e, q_e)
228    CASE ('dcmip2_mountain','dcmip2_schaer_noshear','dcmip2_schaer_shear')
229       CALL compute_dcmip2(iim*jjm,lon_i,lat_i, phis, ps, temp_i, ulon_i, ulat_i)
230       CALL compute_dcmip2(3*iim*jjm,lon_e,lat_e, phis_e, ps_e, temp_e, ulon_e, ulat_e)     
231    CASE('dcmip3')
232       CALL compute_dcmip3(iim*jjm,lon_i,lat_i, phis, ps, temp_i, ulon_i, ulat_i, geopot, q)
233       CALL compute_dcmip3(3*iim*jjm,lon_e,lat_e, phis_e, ps_e, temp_e, ulon_e, ulat_e, geopot_e, q_e)
234       autoinit_NH = .FALSE. ! compute_dcmip3 initializes geopot
235    CASE('dcmip4')
236       CALL compute_dcmip4(iim*jjm,lon_i,lat_i, phis, ps, temp_i, ulon_i, ulat_i, q)
237       CALL compute_dcmip4(3*iim*jjm,lon_e,lat_e, phis_e, ps_e, temp_e, ulon_e, ulat_e, q_e)
238    CASE('dcmip5')
239       CALL compute_dcmip5(iim*jjm,lon_i,lat_i, phis, ps, temp_i, ulon_i, ulat_i, q)
240       CALL compute_dcmip5(3*iim*jjm,lon_e,lat_e, phis_e, ps_e, temp_e, ulon_e, ulat_e, q_e)
241    CASE('williamson91.6')
242       CALL compute_w91_6(iim*jjm,lon_i,lat_i, phis, mass(:,1), temp_i(:,1), ulon_i(:,1), ulat_i(:,1))
243       CALL compute_w91_6(3*iim*jjm,lon_e,lat_e, phis_e, mass_e(:,1), temp_e(:,1), ulon_e(:,1), ulat_e(:,1))
244       autoinit_mass = .FALSE. ! do not overwrite mass
245    END SELECT
246
247    IF(autoinit_mass) CALL compute_rhodz(.TRUE., ps, mass) ! initialize mass distribution using ps
248    IF(autoinit_NH) THEN
249       geopot(:,1) = phis(:) ! surface geopotential
250       DO l = 1, llm
251          DO ij=1,iim*jjm
252             ! hybrid pressure coordinate
253             p_ik = ptop + mass_ak(l) + mass_bk(l)*ps(ij)
254             mass_ik = (mass_dak(l) + mass_dbk(l)*ps(ij))/g
255             ! v=R.T/p, R=kappa*cpp
256             v_ik = kappa*cpp*temp_i(ij,l)/p_ik
257             geopot(ij,l+1) = geopot(ij,l) + mass_ik*v_ik*g
258          END DO
259       END DO
260    END IF
261
262    !$OMP BARRIER
263
264    CALL compute_wind_perp_from_lonlat_compound(ulon_e, ulat_e, u)
265
266  END SUBROUTINE compute_etat0_collocated
267
268!----------------------------- Resting isothermal state --------------------------------
269
270  SUBROUTINE getin_etat0_isothermal
271    etat0_temp=300
272    CALL getin("etat0_isothermal_temp",etat0_temp)
273  END SUBROUTINE getin_etat0_isothermal
274
275  SUBROUTINE compute_etat0_isothermal(ngrid, phis, ps, temp, ulon, ulat, q)
276    IMPLICIT NONE 
277    INTEGER, INTENT(IN)    :: ngrid
278    REAL(rstd),INTENT(OUT) :: phis(ngrid)
279    REAL(rstd),INTENT(OUT) :: ps(ngrid)
280    REAL(rstd),INTENT(OUT) :: temp(ngrid,llm)
281    REAL(rstd),INTENT(OUT) :: ulon(ngrid,llm)
282    REAL(rstd),INTENT(OUT) :: ulat(ngrid,llm)
283    REAL(rstd),INTENT(OUT) :: q(ngrid,llm,nqtot)
284    phis(:)=0
285    ps(:)=preff
286    temp(:,:)=etat0_temp
287    ulon(:,:)=0
288    ulat(:,:)=0
289    q(:,:,:)=0
290  END SUBROUTINE compute_etat0_isothermal
291
292END MODULE etat0_mod
Note: See TracBrowser for help on using the repository browser.