source: codes/icosagcm/trunk/src/initial/etat0.f90 @ 548

Last change on this file since 548 was 548, checked in by dubos, 7 years ago

trunk : reorganize source tree

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