source: ICOSA_LMDZ/src/phylmd/icolmdz_etat0.f90 @ 4966

Last change on this file since 4966 was 4857, checked in by yann meurdesoif, 8 months ago

Fix incomptability with recent version of dynamico due to convergence hexa<->unstruct

YM

  • Property svn:executable set to *
File size: 7.9 KB
Line 
1MODULE icolmdz_etat0
2
3
4CONTAINS
5
6  SUBROUTINE init_etat0
7      USE xios_mod
8      USE omp_para
9      USE getin_mod, ONLY: getin
10      IMPLICIT NONE
11      CHARACTER(LEN=256) :: etat0_lmdz
12
13      ! @getin_doc etat0_database_type realm=initial type=String default=`legacy`
14      !  When `etat0=="database"`, selects type of external file(s) from which initial state is read. Valid values :
15      !  * `legacy` : reads from XIOS group `read_files_legacy`, see `xml/context_dynamico.xml`
16      !  * `ERA5_forcing` : reads from XIOS group `read_files_ERA5_forcing`, see `xml/context_dynamico.xml`
17
18      etat0_lmdz = "legacy"
19      CALL getin("etat0_lmdz", etat0_lmdz)
20
21      IF (is_omp_master) THEN
22         CALL xios_set_fieldgroup_attr("read_fields", enabled=.TRUE.)
23         IF (TRIM(etat0_lmdz) == "legacy") THEN
24            CALL xios_set_filegroup_attr("read_files_legacy", enabled=.TRUE.)
25            CALL xios_set_field_attr("relief_db", field_ref="relief_db_legacy")
26            CALL xios_set_field_attr("ps_db", field_ref="ps_db_legacy")
27            CALL xios_set_field_attr("z_db", field_ref="z_db_legacy")
28            CALL xios_set_field_attr("ts_db", field_ref="ts_db_legacy")
29            CALL xios_set_field_attr("u_db", field_ref="u_db_legacy")
30            CALL xios_set_field_attr("v_db", field_ref="v_db_legacy")
31            CALL xios_set_field_attr("temp_db", field_ref="temp_db_legacy")
32            CALL xios_set_field_attr("q_db", field_ref="q_db_legacy")
33         ELSE IF (TRIM(etat0_lmdz) == "ERA5_forcing") THEN
34            CALL xios_set_filegroup_attr("read_files_ERA5_forcing", enabled=.TRUE.)
35            CALL xios_set_field_attr("relief_db", field_ref="relief_db_forcing")
36            CALL xios_set_field_attr("ps_db", field_ref="ps_db_forcing")
37            CALL xios_set_field_attr("z_db", field_ref="z_db_forcing")
38            CALL xios_set_field_attr("ts_db", field_ref="ts_db_forcing")
39            CALL xios_set_field_attr("u_db", field_ref="u_db_forcing")
40            CALL xios_set_field_attr("v_db", field_ref="v_db_forcing")
41            CALL xios_set_field_attr("temp_db", field_ref="temp_db_forcing")
42            CALL xios_set_field_attr("q_db", field_ref="q_db_forcing")
43         ELSE
44        PRINT*,"Bad selector for variable <etat0_lmdz> ",TRIM(etat0_lmdz), " option are <legacy> (default), <ERA5_forcing>"
45            STOP
46         END IF
47      END IF
48   END SUBROUTINE init_etat0
49
50
51   SUBROUTINE etat0(f_ps, f_phis, f_theta_rhodz, f_u, f_q)
52      USE icosa
53      USE restart_mod
54      USE wind_from_lonlat_mod
55      USE write_field_mod
56      USE time_mod
57      USE transfert_mod
58      USE xios_mod
59      USE write_field_mod
60      USE vertical_remap_mod
61      USE theta2theta_rhodz_mod
62      USE qsat_mod
63      USE pression_mod
64      USE omp_para
65      USE tracer_icosa_mod
66      IMPLICIT NONE
67      TYPE(t_field), POINTER :: f_ps(:)
68      TYPE(t_field), POINTER :: f_phis(:)
69      TYPE(t_field), POINTER :: f_theta_rhodz(:)
70      TYPE(t_field), POINTER :: f_u(:)
71      TYPE(t_field), POINTER :: f_q(:)
72
73      TYPE(t_field), POINTER, SAVE :: f_ulon_reg(:)
74      TYPE(t_field), POINTER, SAVE :: f_ulat_reg(:)
75      TYPE(t_field), POINTER, SAVE :: f_temp_reg(:)
76      TYPE(t_field), POINTER, SAVE :: f_q_reg(:)
77
78      TYPE(t_field), POINTER, SAVE :: f_ts(:)
79      TYPE(t_field), POINTER, SAVE :: f_z(:)
80      TYPE(t_field), POINTER, SAVE :: f_ulon(:)
81      TYPE(t_field), POINTER, SAVE :: f_ulat(:)
82      TYPE(t_field), POINTER, SAVE :: f_temp(:)
83      TYPE(t_field), POINTER, SAVE :: f_q1(:)
84      TYPE(t_field), POINTER, SAVE :: f_qsat(:)
85      TYPE(t_field), POINTER, SAVE :: f_p(:)
86      INTEGER :: nb_level
87      REAL, ALLOCATABLE:: levels(:)
88      INTEGER :: ind
89
90      CALL xios_read_field("relief_db", f_phis)
91
92      CALL writeField("relief_out", f_phis, once=.TRUE.)
93
94      IF (is_omp_level_master) THEN
95         DO ind = 1, ndomain
96            IF (.NOT. assigned_domain(ind)) CYCLE
97            f_phis(ind)%rval2d(:) = f_phis(ind)%rval2d(:)*g
98         END DO
99      END IF
100!$OMP BARRIER
101
102      IF (is_omp_master) CALL xios_get_axis_attr("lev_ecdyn", n_glo=nb_level)
103      CALL bcast_omp(nb_level)
104      ALLOCATE (levels(nb_level))
105
106      IF (is_omp_master) CALL xios_get_axis_attr("lev_ecdyn", value=levels)
107      CALL bcast_omp(levels)
108
109      levels = levels*100  ! hectoPascal -> Pascal
110
111      CALL allocate_field(f_ts, field_t, type_real, name="ts")
112      CALL allocate_field(f_z, field_t, type_real, name="z")
113      CALL allocate_field(f_ulon_reg, field_t, type_real, nb_level)
114      CALL allocate_field(f_ulat_reg, field_t, type_real, nb_level)
115      CALL allocate_field(f_temp_reg, field_t, type_real, nb_level)
116      CALL allocate_field(f_q_reg, field_t, type_real, nb_level)
117
118      CALL allocate_field(f_q1, field_t, type_real, llm)
119      CALL allocate_field(f_qsat, field_t, type_real, llm)
120      CALL allocate_field(f_p, field_t, type_real, llm + 1)
121      CALL allocate_field(f_temp, field_t, type_real, llm)
122      CALL allocate_field(f_ulon, field_t, type_real, llm)
123      CALL allocate_field(f_ulat, field_t, type_real, llm)
124
125      CALL xios_read_field("z_db", f_z)
126      CALL xios_read_field("ps_db", f_ps)
127      CALL xios_read_field("ts_db", f_ts)
128      CALL writeField("ps_out", f_ps)
129
130!$OMP BARRIER
131
132!    CALL writeField("phis_out",f_phis,once=.TRUE.)
133!    CALL writeField("ts_out",f_ts,once=.TRUE.)
134
135! make correction to ps due to relief at higher resolution
136! difference with LMDZ : tsol is taken from ECDYN.NC and not from ECPHY
137      IF (is_omp_level_master) THEN
138         DO ind = 1, ndomain
139            IF (.NOT. assigned_domain(ind)) CYCLE
140            f_ps(ind)%rval2d(:) = f_ps(ind)%rval2d(:)*(1.+(f_z(ind)%rval2d(:) - f_phis(ind)%rval2d(:))/287.0/f_ts(ind)%rval2d(:))
141         END DO
142      END IF
143!$OMP BARRIER
144      CALL transfert_request(f_ps, req_i0)
145      CALL writeField("ps_out", f_ps)
146
147      CALL xios_read_field("temp_db", f_temp_reg)
148      CALL vertical_remap(levels, f_temp_reg, f_ps, f_temp)
149      CALL transfert_request(f_temp, req_i0)
150      CALL temperature2theta_rhodz(f_ps, f_temp, f_theta_rhodz)
151
152      CALL xios_read_field("u_db", f_ulon_reg)
153      CALL vertical_remap(levels, f_ulon_reg, f_ps, f_ulon)
154      CALL xios_read_field("v_db", f_ulat_reg)
155      CALL vertical_remap(levels, f_ulat_reg, f_ps, f_ulat)
156      CALL transfert_request(f_ulat, req_i0)
157      CALL transfert_request(f_ulon, req_i0)
158      CALL ulonlat2un(f_ulon, f_ulat, f_u)
159
160      CALL xios_read_field("q_db", f_q_reg)
161      CALL vertical_remap(levels, f_q_reg, f_ps, f_q1)
162
163      CALL pression(f_ps, f_p)
164! difference with LMDZ : for qsat, pressure at mid layer is computed as a mean value pmid=(p(l)+p(l+1))/2
165      CALL qsat(f_temp, f_p, f_qsat)
166      CALL transfert_request(f_qsat, req_i0)
167
168      DO ind = 1, ndomain
169         IF (.NOT. assigned_domain(ind)) CYCLE
170
171         IF (tracers(2)%has_default_init_value) THEN
172            f_q(ind)%rval4d(:, :, 2) = tracers(2)%default_init_value
173         ELSE
174            f_q(ind)%rval4d(:, :, 2) = 1e-6
175         END IF
176         f_q(ind)%rval4d(:, :, 1) = f_q1(ind)%rval3d(:, :)*f_qsat(ind)%rval3d(:, :)*0.01
177         WHERE (f_q(ind)%rval4d(:, :, 1) < 0) f_q(ind)%rval4d(:, :, 1) = 0
178      END DO
179
180      tracers(1)%already_initialized = .TRUE.
181      tracers(2)%already_initialized = .TRUE.
182
183      CALL writeField("tempdb_out", f_temp_reg)
184      CALL writeField("temp_out", f_temp)
185
186      CALL deallocate_field(f_ts)
187      CALL deallocate_field(f_z)
188      CALL deallocate_field(f_ulon_reg)
189      CALL deallocate_field(f_ulat_reg)
190      CALL deallocate_field(f_temp_reg)
191      CALL deallocate_field(f_q_reg)
192
193      CALL deallocate_field(f_q1)
194      CALL deallocate_field(f_qsat)
195      CALL deallocate_field(f_p)
196      CALL deallocate_field(f_temp)
197      CALL deallocate_field(f_ulon)
198      CALL deallocate_field(f_ulat)
199
200   END SUBROUTINE etat0
201
202
203
204
205END MODULE icolmdz_etat0
Note: See TracBrowser for help on using the repository browser.