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

Last change on this file since 469 was 468, checked in by ymipsl, 8 years ago

Add missing state for init_etat0 forgotten from last commit

YM

File size: 16.3 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, init_etat0, etat0_type
12
13CONTAINS
14 
15  SUBROUTINE init_etat0
16  USE etat0_database_mod
17  IMPLICIT NONE
18
19    CALL getin("etat0",etat0_type)
20
21    SELECT CASE (TRIM(etat0_type))
22      CASE ('isothermal')
23      CASE ('temperature_profile')
24      CASE ('jablonowsky06')
25      CASE ('dcmip5')
26      CASE ('williamson91.6')
27      CASE ('start_file')
28      CASE ('database')
29        CALL init_etat0_database
30      CASE ('academic')
31      CASE ('held_suarez')
32      CASE ('venus')
33      CASE ('dcmip1')
34      CASE ('dcmip2_mountain','dcmip2_schaer_noshear','dcmip2_schaer_shear')
35      CASE ('dcmip3')
36      CASE ('dcmip4')
37      CASE ('dcmip2016_baroclinic_wave')
38      CASE ('dcmip2016_cyclone')
39      CASE ('dcmip2016_supercell')
40      CASE DEFAULT
41         PRINT*, 'Bad selector for variable etat0 <',TRIM(etat0_type),'>'// &
42            ' options are  <isothermal>, <temperature_profile>, <jablonowsky06>, <dcmip5>, <williamson91.6>,'& 
43                         //' <start_file>, <database>, <academic>, <held_suarez>, <venus>, <dcmip1>,'         &
44                         //' <dcmip2_mountain,dcmip2_schaer_noshear,dcmip2_schaer_shear>, <dcmip3>, <dcmip4>,'&
45                         //' <dcmip2016_baroclinic_wave>, <dcmip2016_cyclone>, <dcmip2016_supercell>'
46         STOP
47    END SELECT
48
49  END SUBROUTINE init_etat0
50
51  SUBROUTINE etat0(f_ps,f_mass,f_phis,f_theta_rhodz,f_u, f_geopot,f_w, f_q)
52    USE mpipara, ONLY : is_mpi_root
53    USE disvert_mod
54    ! Generic interface
55    USE etat0_dcmip1_mod, ONLY : getin_etat0_dcmip1=>getin_etat0
56    USE etat0_dcmip2_mod, ONLY : getin_etat0_dcmip2=>getin_etat0
57    USE etat0_dcmip4_mod, ONLY : getin_etat0_dcmip4=>getin_etat0
58    USE etat0_dcmip5_mod, ONLY : getin_etat0_dcmip5=>getin_etat0
59    USE etat0_bubble_mod, ONLY : getin_etat0_bubble=>getin_etat0
60    USE etat0_williamson_mod, ONLY : getin_etat0_williamson=>getin_etat0
61    USE etat0_temperature_mod, ONLY: getin_etat0_temperature=>getin_etat0
62    USE etat0_dcmip2016_baroclinic_wave_mod, ONLY : getin_etat0_dcmip2016_baroclinic_wave=>getin_etat0
63    USE etat0_dcmip2016_cyclone_mod, ONLY : getin_etat0_dcmip2016_cyclone=>getin_etat0
64    USE etat0_dcmip2016_supercell_mod, ONLY : getin_etat0_dcmip2016_supercell=>getin_etat0
65    ! Ad hoc interfaces
66    USE etat0_academic_mod, ONLY : etat0_academic=>etat0
67    USE etat0_heldsz_mod, ONLY : etat0_heldsz=>etat0
68    USE etat0_venus_mod,  ONLY : etat0_venus=>etat0
69    USE etat0_database_mod, ONLY : etat0_database=>etat0
70    USE etat0_start_file_mod, ONLY : etat0_start_file=>etat0 
71
72    IMPLICIT NONE
73    TYPE(t_field),POINTER :: f_ps(:)
74    TYPE(t_field),POINTER :: f_mass(:)
75    TYPE(t_field),POINTER :: f_phis(:)
76    TYPE(t_field),POINTER :: f_theta_rhodz(:)
77    TYPE(t_field),POINTER :: f_u(:)
78    TYPE(t_field),POINTER :: f_geopot(:)
79    TYPE(t_field),POINTER :: f_w(:)
80    TYPE(t_field),POINTER :: f_q(:)
81   
82    REAL(rstd),POINTER :: ps(:), mass(:,:)
83    LOGICAL :: autoinit_mass, autoinit_geopot, collocated
84    INTEGER :: ind,i,j,ij,l
85
86    ! most etat0 routines set ps and not mass
87    ! in that case and if caldyn_eta == eta_lag
88    ! the initial distribution of mass is taken to be the same
89    ! as what the mass coordinate would dictate
90    ! however if etat0_XXX defines mass then the flag autoinit_mass must be set to .FALSE.
91    ! otherwise mass will be overwritten
92    autoinit_mass = (caldyn_eta == eta_lag)
93
94    etat0_type='jablonowsky06'
95    CALL getin("etat0",etat0_type)
96   
97    !------------------- Generic interface ---------------------
98    collocated=.TRUE.
99    SELECT CASE (TRIM(etat0_type))
100    CASE ('isothermal')
101       CALL getin_etat0_isothermal
102    CASE ('temperature_profile')
103       CALL getin_etat0_temperature
104    CASE ('jablonowsky06')
105    CASE ('dcmip1')
106        CALL getin_etat0_dcmip1
107    CASE ('dcmip2_mountain','dcmip2_schaer_noshear','dcmip2_schaer_shear')
108       CALL getin_etat0_dcmip2
109    CASE ('dcmip3')
110    CASE ('dcmip4')
111        CALL getin_etat0_dcmip4
112    CASE ('dcmip5')
113        CALL getin_etat0_dcmip5
114    CASE ('bubble')
115        CALL getin_etat0_bubble
116    CASE ('williamson91.6')
117       autoinit_mass=.FALSE.
118       CALL getin_etat0_williamson
119    CASE ('dcmip2016_baroclinic_wave')
120        CALL getin_etat0_dcmip2016_baroclinic_wave
121    CASE ('dcmip2016_cyclone')
122        CALL getin_etat0_dcmip2016_cyclone
123    CASE ('dcmip2016_supercell')
124        CALL getin_etat0_dcmip2016_supercell
125    CASE DEFAULT
126       collocated=.FALSE.
127       autoinit_mass = .FALSE.
128    END SELECT
129
130    !------------------- Ad hoc interfaces --------------------
131    SELECT CASE (TRIM(etat0_type))
132     CASE ('database')
133        CALL etat0_database(f_ps,f_phis,f_theta_rhodz,f_u, f_q)
134    CASE ('start_file')
135       CALL etat0_start_file(f_ps,f_phis,f_theta_rhodz,f_u, f_q)
136    CASE ('academic')
137       CALL etat0_academic(f_ps,f_phis,f_theta_rhodz,f_u, f_q)
138    CASE ('held_suarez')
139       PRINT *,"Held & Suarez (1994) test case"
140       CALL etat0_heldsz(f_ps,f_phis,f_theta_rhodz,f_u, f_q)
141    CASE ('venus')
142       CALL etat0_venus(f_ps, f_phis, f_theta_rhodz, f_u, f_q)
143       PRINT *, "Venus (Lebonnois et al., 2012) test case"
144   CASE DEFAULT
145      IF(collocated) THEN
146         CALL etat0_collocated(f_phis,f_ps,f_mass,f_theta_rhodz,f_u, f_geopot,f_W, f_q)
147      ELSE
148         PRINT*, 'Bad selector for variable etat0 <',TRIM(etat0_type),'>'// &
149            ' options are  <isothermal>, <temperature_profile>, <jablonowsky06>, <dcmip5>, <williamson91.6>,'& 
150                         //' <start_file>, <database>, <academic>, <held_suarez>, <venus>, <dcmip1>,'         &
151                         //' <dcmip2_mountain,dcmip2_schaer_noshear,dcmip2_schaer_shear>, <dcmip3>, <dcmip4>,'&
152                         //' <dcmip2016_baroclinic_wave>, <dcmip2016_cyclone>, <dcmip2016_supercell>'
153         STOP
154      END IF
155    END SELECT
156
157!       !$OMP BARRIER
158    IF(autoinit_mass) THEN
159       DO ind=1,ndomain
160          IF (.NOT. assigned_domain(ind)) CYCLE
161          CALL swap_dimensions(ind)
162          CALL swap_geometry(ind)
163          mass=f_mass(ind); ps=f_ps(ind)
164          CALL compute_rhodz(.TRUE., ps, mass) ! initialize mass distribution using ps
165       END DO
166    END IF
167 
168  END SUBROUTINE etat0
169
170  SUBROUTINE etat0_collocated(f_phis,f_ps,f_mass,f_theta_rhodz,f_u, f_geopot,f_W, f_q)
171    USE theta2theta_rhodz_mod
172    IMPLICIT NONE
173    TYPE(t_field),POINTER :: f_ps(:)
174    TYPE(t_field),POINTER :: f_mass(:)
175    TYPE(t_field),POINTER :: f_phis(:)
176    TYPE(t_field),POINTER :: f_theta_rhodz(:)
177    TYPE(t_field),POINTER :: f_u(:)
178    TYPE(t_field),POINTER :: f_geopot(:)
179    TYPE(t_field),POINTER :: f_W(:)
180    TYPE(t_field),POINTER :: f_q(:)
181 
182    TYPE(t_field),POINTER,SAVE :: f_temp(:)
183    REAL(rstd),POINTER :: ps(:)
184    REAL(rstd),POINTER :: mass(:,:)
185    REAL(rstd),POINTER :: phis(:)
186    REAL(rstd),POINTER :: theta_rhodz(:,:,:)
187    REAL(rstd),POINTER :: temp(:,:)
188    REAL(rstd),POINTER :: u(:,:)
189    REAL(rstd),POINTER :: geopot(:,:)
190    REAL(rstd),POINTER :: W(:,:)
191    REAL(rstd),POINTER :: q(:,:,:)
192    INTEGER :: ind
193
194    CALL allocate_field(f_temp,field_t,type_real,llm,name='temp')
195
196    DO ind=1,ndomain
197      IF (.NOT. assigned_domain(ind)) CYCLE
198      CALL swap_dimensions(ind)
199      CALL swap_geometry(ind)
200      ps=f_ps(ind)
201      mass=f_mass(ind)
202      phis=f_phis(ind)
203      theta_rhodz=f_theta_rhodz(ind)
204      temp=f_temp(ind)
205      u=f_u(ind)
206      geopot=f_geopot(ind)
207      w=f_w(ind)
208      q=f_q(ind)
209
210      IF( TRIM(etat0_type)=='williamson91.6' ) THEN
211         CALL compute_etat0_collocated(ps,mass, phis, theta_rhodz(:,:,1), u, geopot, W, q)
212      ELSE
213         CALL compute_etat0_collocated(ps,mass, phis, temp, u, geopot, W, q)
214      ENDIF
215
216      IF( TRIM(etat0_type)/='williamson91.6' ) CALL compute_temperature2entropy(ps,temp,q,theta_rhodz, 1)
217   
218    ENDDO
219   
220    CALL deallocate_field(f_temp)
221   
222  END SUBROUTINE etat0_collocated
223
224  SUBROUTINE compute_temperature2entropy(ps,temp,q,theta_rhodz,offset)
225    USE icosa
226    USE pression_mod
227    USE exner_mod
228    USE omp_para
229    IMPLICIT NONE
230    REAL(rstd),INTENT(IN)  :: ps(iim*jjm)
231    REAL(rstd),INTENT(IN)  :: temp(iim*jjm,llm)
232    REAL(rstd),INTENT(IN)  :: q(iim*jjm,llm,nqtot)
233    REAL(rstd),INTENT(OUT) :: theta_rhodz(iim*jjm,llm)
234    INTEGER,INTENT(IN) :: offset
235
236    REAL(rstd) :: p(iim*jjm,llm+1)
237    REAL(rstd) :: cppd,Rd, mass, p_ij, q_ij,r_ij, chi,nu, entropy, theta
238    INTEGER :: i,j,ij,l
239
240    cppd=cpp
241    Rd=kappa*cppd
242
243    CALL compute_pression(ps,p,offset)
244    ! flush p
245    !$OMP BARRIER
246    DO    l    = ll_begin, ll_end
247       DO j=jj_begin-offset,jj_end+offset
248          DO i=ii_begin-offset,ii_end+offset
249             ij=(j-1)*iim+i
250             mass = (p(ij,l)-p(ij,l+1))/g ! dry+moist mass
251             p_ij = .5*(p(ij,l)+p(ij,l+1))  ! pressure at full level
252             SELECT CASE(caldyn_thermo)
253             CASE(thermo_theta)
254                theta = temp(ij,l)*(p_ij/preff)**(-kappa) 
255                theta_rhodz(ij,l) = mass * theta
256             CASE(thermo_entropy)
257                nu = log(p_ij/preff)
258                chi = log(temp(ij,l)/Treff)
259                entropy = cppd*chi-Rd*nu
260                theta_rhodz(ij,l) = mass * entropy
261!             CASE(thermo_moist)
262!                q_ij=q(ij,l,1)
263!                r_ij=1.-q_ij
264!                mass=mass*(1-q_ij) ! dry mass
265!                nu = log(p_ij/preff)
266!                chi = log(temp(ij,l)/Treff)
267!                entropy = r_ij*(cppd*chi-Rd*nu) + q_ij*(cppv*chi-Rv*nu)
268!                theta_rhodz(ij,l) = mass * entropy               
269                CASE DEFAULT
270                   STOP
271             END SELECT
272          ENDDO
273       ENDDO
274    ENDDO
275    !$OMP BARRIER 
276  END SUBROUTINE compute_temperature2entropy
277
278  SUBROUTINE compute_etat0_collocated(ps,mass,phis,temp_i,u, geopot,W, q)
279    USE wind_mod
280    USE disvert_mod
281    USE etat0_jablonowsky06_mod, ONLY : compute_jablonowsky06 => compute_etat0
282    USE etat0_dcmip1_mod, ONLY : compute_dcmip1 => compute_etat0
283    USE etat0_dcmip2_mod, ONLY : compute_dcmip2 => compute_etat0
284    USE etat0_dcmip3_mod, ONLY : compute_dcmip3 => compute_etat0
285    USE etat0_dcmip4_mod, ONLY : compute_dcmip4 => compute_etat0
286    USE etat0_dcmip5_mod, ONLY : compute_dcmip5 => compute_etat0
287    USE etat0_bubble_mod, ONLY : compute_bubble => compute_etat0 
288    USE etat0_williamson_mod, ONLY : compute_w91_6 => compute_etat0
289    USE etat0_temperature_mod, ONLY: compute_etat0_temperature => compute_etat0
290    USE etat0_dcmip2016_baroclinic_wave_mod, ONLY : compute_dcmip2016_baroclinic_wave => compute_etat0
291    USE etat0_dcmip2016_cyclone_mod, ONLY : compute_dcmip2016_cyclone => compute_etat0
292    USE etat0_dcmip2016_supercell_mod, ONLY : compute_dcmip2016_supercell => compute_etat0
293    IMPLICIT NONE
294    REAL(rstd),INTENT(INOUT) :: ps(iim*jjm)
295    REAL(rstd),INTENT(INOUT) :: mass(iim*jjm,llm)
296    REAL(rstd),INTENT(OUT) :: phis(iim*jjm)
297    REAL(rstd),INTENT(OUT) :: temp_i(iim*jjm,llm)
298    REAL(rstd),INTENT(OUT) :: u(3*iim*jjm,llm)
299    REAL(rstd),INTENT(OUT) :: W(iim*jjm,llm+1)
300    REAL(rstd),INTENT(OUT) :: geopot(iim*jjm,llm+1)
301    REAL(rstd),INTENT(OUT) :: q(iim*jjm,llm,nqtot)
302
303    REAL(rstd) :: ulon_i(iim*jjm,llm)
304    REAL(rstd) :: ulat_i(iim*jjm,llm)
305
306    REAL(rstd) :: ps_e(3*iim*jjm)
307    REAL(rstd) :: mass_e(3*iim*jjm,llm)
308    REAL(rstd) :: phis_e(3*iim*jjm)
309    REAL(rstd) :: temp_e(3*iim*jjm,llm)
310    REAL(rstd) :: geopot_e(3*iim*jjm,llm+1)
311    REAL(rstd) :: ulon_e(3*iim*jjm,llm)
312    REAL(rstd) :: ulat_e(3*iim*jjm,llm)
313    REAL(rstd) :: q_e(3*iim*jjm,llm,nqtot)
314
315    INTEGER :: l,i,j,ij
316    REAL :: p_ik, v_ik, mass_ik
317    LOGICAL :: autoinit_mass, autoinit_NH
318
319    ! For NH geopotential and vertical momentum must be initialized.
320    ! Unless autoinit_NH is set to .FALSE. , they will be initialized
321    ! to hydrostatic geopotential and zero
322    autoinit_mass = .TRUE.
323    autoinit_NH = .NOT. hydrostatic
324    w(:,:) = 0
325
326    !$OMP BARRIER
327
328    SELECT CASE (TRIM(etat0_type))
329    CASE ('isothermal')
330       CALL compute_etat0_isothermal(iim*jjm, phis, ps, temp_i, ulon_i, ulat_i, q)
331       CALL compute_etat0_isothermal(3*iim*jjm, phis_e, ps_e, temp_e, ulon_e, ulat_e, q_e)
332    CASE ('temperature_profile')
333       CALL compute_etat0_temperature(iim*jjm, phis, ps, temp_i, ulon_i, ulat_i, q)
334       CALL compute_etat0_temperature(3*iim*jjm, phis_e, ps_e, temp_e, ulon_e, ulat_e, q_e)
335    CASE('jablonowsky06')
336       CALL compute_jablonowsky06(iim*jjm,lon_i,lat_i, phis, ps, temp_i, ulon_i, ulat_i)
337       CALL compute_jablonowsky06(3*iim*jjm,lon_e,lat_e, phis_e, ps_e, temp_e, ulon_e, ulat_e)
338    CASE('dcmip1')
339       CALL compute_dcmip1(iim*jjm,lon_i,lat_i, phis, ps, temp_i, ulon_i, ulat_i, q)
340       CALL compute_dcmip1(3*iim*jjm,lon_e,lat_e, phis_e, ps_e, temp_e, ulon_e, ulat_e, q_e)
341    CASE ('dcmip2_mountain','dcmip2_schaer_noshear','dcmip2_schaer_shear')
342       CALL compute_dcmip2(iim*jjm,lon_i,lat_i, phis, ps, temp_i, ulon_i, ulat_i)
343       CALL compute_dcmip2(3*iim*jjm,lon_e,lat_e, phis_e, ps_e, temp_e, ulon_e, ulat_e)     
344    CASE('dcmip3')
345       CALL compute_dcmip3(iim*jjm,lon_i,lat_i, phis, ps, temp_i, ulon_i, ulat_i, geopot, q)
346       CALL compute_dcmip3(3*iim*jjm,lon_e,lat_e, phis_e, ps_e, temp_e, ulon_e, ulat_e, geopot_e, q_e)
347       autoinit_NH = .FALSE. ! compute_dcmip3 initializes geopot
348    CASE('dcmip4')
349       CALL compute_dcmip4(iim*jjm,lon_i,lat_i, phis, ps, temp_i, ulon_i, ulat_i, q)
350       CALL compute_dcmip4(3*iim*jjm,lon_e,lat_e, phis_e, ps_e, temp_e, ulon_e, ulat_e, q_e)
351    CASE('dcmip5')
352       CALL compute_dcmip5(iim*jjm,lon_i,lat_i, phis, ps, temp_i, ulon_i, ulat_i, q)
353       CALL compute_dcmip5(3*iim*jjm,lon_e,lat_e, phis_e, ps_e, temp_e, ulon_e, ulat_e, q_e)
354    CASE('bubble')
355       CALL compute_bubble(iim*jjm,lon_i,lat_i, phis, ps, temp_i, ulon_i, ulat_i, geopot, q)
356       CALL compute_bubble(3*iim*jjm,lon_e,lat_e, phis_e, ps_e, temp_e, ulon_e, ulat_e, geopot_e, q_e)
357!       autoinit_NH = .FALSE. ! compute_bubble initializes geopot
358    CASE('williamson91.6')
359       CALL compute_w91_6(iim*jjm,lon_i,lat_i, phis, mass(:,1), temp_i(:,1), ulon_i(:,1), ulat_i(:,1))
360       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))
361       autoinit_mass = .FALSE. ! do not overwrite mass
362    CASE('dcmip2016_baroclinic_wave')
363       CALL compute_dcmip2016_baroclinic_wave(iim*jjm,lon_i,lat_i, phis, ps, temp_i, ulon_i, ulat_i, q)
364       CALL compute_dcmip2016_baroclinic_wave(3*iim*jjm,lon_e,lat_e, phis_e, ps_e, temp_e, ulon_e, ulat_e, q_e)
365    CASE('dcmip2016_cyclone')
366       CALL compute_dcmip2016_cyclone(iim*jjm,lon_i,lat_i, phis, ps, temp_i, ulon_i, ulat_i, q)
367       CALL compute_dcmip2016_cyclone(3*iim*jjm,lon_e,lat_e, phis_e, ps_e, temp_e, ulon_e, ulat_e, q_e)
368    CASE('dcmip2016_supercell')
369       CALL compute_dcmip2016_supercell(iim*jjm,lon_i,lat_i, phis, ps, temp_i, ulon_i, ulat_i, q)
370       CALL compute_dcmip2016_supercell(3*iim*jjm,lon_e,lat_e, phis_e, ps_e, temp_e, ulon_e, ulat_e, q_e)
371    END SELECT
372
373    IF(autoinit_mass) CALL compute_rhodz(.TRUE., ps, mass) ! initialize mass distribution using ps
374    IF(autoinit_NH) THEN
375       geopot(:,1) = phis(:) ! surface geopotential
376       DO l = 1, llm
377          DO ij=1,iim*jjm
378             ! hybrid pressure coordinate
379             p_ik = ptop + mass_ak(l) + mass_bk(l)*ps(ij)
380             mass_ik = (mass_dak(l) + mass_dbk(l)*ps(ij))/g
381             ! v=R.T/p, R=kappa*cpp
382             v_ik = kappa*cpp*temp_i(ij,l)/p_ik
383             geopot(ij,l+1) = geopot(ij,l) + mass_ik*v_ik*g
384          END DO
385       END DO
386    END IF
387
388    !$OMP BARRIER
389
390    CALL compute_wind_perp_from_lonlat_compound(ulon_e, ulat_e, u)
391
392  END SUBROUTINE compute_etat0_collocated
393
394!----------------------------- Resting isothermal state --------------------------------
395
396  SUBROUTINE getin_etat0_isothermal
397    etat0_temp=300
398    CALL getin("etat0_isothermal_temp",etat0_temp)
399  END SUBROUTINE getin_etat0_isothermal
400
401  SUBROUTINE compute_etat0_isothermal(ngrid, phis, ps, temp, ulon, ulat, q)
402    IMPLICIT NONE 
403    INTEGER, INTENT(IN)    :: ngrid
404    REAL(rstd),INTENT(OUT) :: phis(ngrid)
405    REAL(rstd),INTENT(OUT) :: ps(ngrid)
406    REAL(rstd),INTENT(OUT) :: temp(ngrid,llm)
407    REAL(rstd),INTENT(OUT) :: ulon(ngrid,llm)
408    REAL(rstd),INTENT(OUT) :: ulat(ngrid,llm)
409    REAL(rstd),INTENT(OUT) :: q(ngrid,llm,nqtot)
410    phis(:)=0
411    ps(:)=preff
412    temp(:,:)=etat0_temp
413    ulon(:,:)=0
414    ulat(:,:)=0
415    q(:,:,:)=0
416  END SUBROUTINE compute_etat0_isothermal
417
418END MODULE etat0_mod
Note: See TracBrowser for help on using the repository browser.