Merge remote-tracking branch 'origin/release-v4.5.2'
[WRF.git] / var / da / da_4dvar / da_ad_model.inc
blobf9bc29034f17f1aeb08224aeb2b5eb63a64ca966
1 subroutine da_ad_model ()
3    !-----------------------------------------------------------------------
4    ! Purpose: Acrivate nonlinear model
5    !    Author: Xin Zhang,  MMM/ESSL/NCAR,  Date: 05/19/2010
6    !-----------------------------------------------------------------------
8    implicit none
10    integer :: time_step, alarmid, gwd_opt
12    if (trace_use_dull) call da_trace_entry("da_ad_model")
14 #ifdef _OPENMP
15    call setfeenv()
16 #endif
18    ! Set the file names and interval for reading basic states.
19    model_config_rec%auxinput6_inname = "auxhist6_d<domain>_<date>"
20    call nl_get_time_step ( head_grid%id, time_step )
21    call nl_set_auxinput6_interval_s (head_grid%id, time_step )
22    call nl_set_io_form_auxinput6 ( head_grid%id, 2 )
23    call nl_set_frames_per_auxinput6 ( head_grid%id, 1 )
25    ! Set the file names and interval for reading adjoint forcing.
26    model_config_rec%auxinput7_inname = "af_d<domain>_<date>"
27    call nl_set_auxinput7_interval_s ( head_grid%id, var4d_bin )
28    call nl_set_io_form_auxinput7 ( head_grid%id, 2 )
29    call nl_set_frames_per_auxinput7 ( head_grid%id, 1 )
30    call nl_get_gwd_opt ( head_grid%id, gwd_opt )
32    ! Set all perturbation to ZERO
34    head_grid%a_h_diabatic = 0.0
36    head_grid%a_rainnc  = 0.0
37    head_grid%a_rainncv = 0.0
38    head_grid%a_rainc  = 0.0
39    head_grid%a_raincv = 0.0
40    head_grid%a_pratec = 0.0
42 ! I&O variables
43    head_grid%a_scalar = 0.0
44    head_grid%a_tke_2 = 0.0
45    head_grid%a_p=0.0
46    head_grid%a_al=0.0
48 ! O variables
49    head_grid%a_tke_1 = 0.0
51    head_grid%a_ru = 0.0
52    head_grid%a_rv = 0.0
53    head_grid%a_rw = 0.0
54    head_grid%a_ww = 0.0
55    head_grid%a_alt = 0.0
56    head_grid%a_php = 0.0
57    head_grid%a_mut = 0.0
58    head_grid%a_muu = 0.0
59    head_grid%a_muv = 0.0
60    head_grid%a_p_hyd_w = 0.0
61    head_grid%a_p_hyd = 0.0
62    head_grid%a_z_at_w = 0.0
63    head_grid%a_z = 0.0
64    head_grid%a_zx = 0.0
65    head_grid%a_zy = 0.0
66    head_grid%a_rdz = 0.0
67    head_grid%a_rdzw = 0.0
68    head_grid%a_div = 0.0
69    head_grid%a_nba_mij = 0.0
70    head_grid%a_nba_rij = 0.0
71    head_grid%a_defor11 = 0.0
72    head_grid%a_defor22 = 0.0
73    head_grid%a_defor33 = 0.0
74    head_grid%a_defor12 = 0.0
75    head_grid%a_defor13 = 0.0
76    head_grid%a_defor23 = 0.0
77    head_grid%a_bn2 = 0.0
78    head_grid%a_xkmh = 0.0
79    head_grid%a_xkmv = 0.0
80    head_grid%a_xkhh = 0.0
81    head_grid%a_xkhv = 0.0
82    head_grid%a_ru_tend = 0.0
83    head_grid%a_rv_tend = 0.0
84    head_grid%a_u_save = 0.0
85    head_grid%a_v_save = 0.0
86    head_grid%a_t_save = 0.0
87    head_grid%a_rthften = 0.0
88    head_grid%a_rqvften = 0.0
89    head_grid%a_rthcuten = 0.0
90    head_grid%a_rqvcuten = 0.0
91    head_grid%a_muts = 0.0
92    head_grid%a_mudf = 0.0
93    head_grid%a_ru_m = 0.0
94    head_grid%a_rv_m = 0.0
95    head_grid%a_ww_m = 0.0
97 ! I variables
98    head_grid%a_ustm=0.0
99    head_grid%a_hfx=0.0
100    head_grid%a_qfx=0.0
102    IF ( gwd_opt .EQ. 1 ) THEN
103       head_grid%a_dtaux3d = 0.0
104       head_grid%a_dtauy3d = 0.0
105       head_grid%a_dusfcg = 0.0
106       head_grid%a_dvsfcg = 0.0
107    ENDIF
109    head_grid%a_u_1 = 0.0
110    head_grid%a_v_1 = 0.0
111    head_grid%a_w_1 = 0.0
112    head_grid%a_t_1 = 0.0
113    head_grid%a_ph_1 = 0.0
114    head_grid%a_mu_1 = 0.0
116    head_grid%a_u_2 = 0.0
117    head_grid%a_v_2 = 0.0
118    head_grid%a_w_2 = 0.0
119    head_grid%a_t_2 = 0.0
120    head_grid%a_ph_2 = 0.0
121    head_grid%a_mu_2 = 0.0
123    head_grid%a_moist = 0.0
125    head_grid%a_u_bxs = 0.0; head_grid%a_u_bxe = 0.0; head_grid%a_u_bys = 0.0; head_grid%a_u_bye = 0.0
126    head_grid%a_v_bxs = 0.0; head_grid%a_v_bxe = 0.0; head_grid%a_v_bys = 0.0; head_grid%a_v_bye = 0.0
127    head_grid%a_w_bxs = 0.0; head_grid%a_w_bxe = 0.0; head_grid%a_w_bys = 0.0; head_grid%a_w_bye = 0.0
128    head_grid%a_ph_bxs = 0.0; head_grid%a_ph_bxe = 0.0; head_grid%a_ph_bys = 0.0; head_grid%a_ph_bye = 0.0
129    head_grid%a_t_bxs = 0.0; head_grid%a_t_bxe = 0.0; head_grid%a_t_bys = 0.0; head_grid%a_t_bye = 0.0
130    head_grid%a_mu_bxs = 0.0; head_grid%a_mu_bxe = 0.0; head_grid%a_mu_bys = 0.0; head_grid%a_mu_bye = 0.0
131    head_grid%a_moist_bxs = 0.0; head_grid%a_moist_bxe = 0.0; head_grid%a_moist_bys = 0.0; head_grid%a_moist_bye = 0.0
132    head_grid%a_scalar_bxs = 0.0; head_grid%a_scalar_bxe = 0.0; head_grid%a_scalar_bys = 0.0; head_grid%a_scalar_bye = 0.0
134    head_grid%a_u_btxs = 0.0; head_grid%a_u_btxe = 0.0; head_grid%a_u_btys = 0.0; head_grid%a_u_btye = 0.0
135    head_grid%a_v_btxs = 0.0; head_grid%a_v_btxe = 0.0; head_grid%a_v_btys = 0.0; head_grid%a_v_btye = 0.0
136    head_grid%a_w_btxs = 0.0; head_grid%a_w_btxe = 0.0; head_grid%a_w_btys = 0.0; head_grid%a_w_btye = 0.0
137    head_grid%a_ph_btxs = 0.0; head_grid%a_ph_btxe = 0.0; head_grid%a_ph_btys = 0.0; head_grid%a_ph_btye = 0.0
138    head_grid%a_t_btxs = 0.0; head_grid%a_t_btxe = 0.0; head_grid%a_t_btys = 0.0; head_grid%a_t_btye = 0.0
139    head_grid%a_mu_btxs = 0.0; head_grid%a_mu_btxe = 0.0; head_grid%a_mu_btys = 0.0; head_grid%a_mu_btye = 0.0
140    head_grid%a_moist_btxs = 0.0; head_grid%a_moist_btxe = 0.0; head_grid%a_moist_btys = 0.0; head_grid%a_moist_btye = 0.0
141    head_grid%a_scalar_btxs = 0.0; head_grid%a_scalar_btxe = 0.0; head_grid%a_scalar_btys = 0.0; head_grid%a_scalar_btye = 0.0
143    head_grid%g_u_1 = 0.0  
144    head_grid%g_v_1 = 0.0
145    head_grid%g_w_1 = 0.0
146    head_grid%g_t_1 = 0.0
147    head_grid%g_ph_1 = 0.0
148    head_grid%g_mu_1 = 0.0
150    head_grid%g_u_2 = 0.0
151    head_grid%g_v_2 = 0.0
152    head_grid%g_w_2 = 0.0
153    head_grid%g_t_2 = 0.0
154    head_grid%g_ph_2 = 0.0
155    head_grid%g_mu_2 = 0.0
157    head_grid%g_p = 0.0
159    head_grid%g_moist = 0.0
161    head_grid%g_scalar = 0.0
162    head_grid%g_rainnc  = 0.0
163    head_grid%g_rainncv = 0.0
164    head_grid%g_rainc  = 0.0
165    head_grid%g_raincv = 0.0
166    head_grid%g_pratec = 0.0
168    ! Set the physics options to what they are in TL and AD
169    if (original_mp_physics .NE. 0 .and. original_mp_physics .NE. 98 .and. original_mp_physics .NE. 99) &
170       call nl_set_mp_physics (head_grid%id, original_mp_physics_ad) 
171    call nl_set_ra_lw_physics (head_grid%id, 0)
172    call nl_set_ra_sw_physics (head_grid%id, 0)
173    call nl_set_sf_sfclay_physics (head_grid%id, 0)
174    if ( original_bl_pbl_physics .gt. 0 ) &
175       call nl_set_bl_pbl_physics (head_grid%id, 98)
176    if ( original_cu_physics .gt. 0 ) then
177       call nl_set_cu_physics (head_grid%id, 98) 
178       head_grid%cudt =0
179    endif
180    !call nl_set_mp_zero_out (head_grid%id, 0)
181    !call nl_set_sf_surface_physics (head_grid%id, 1)
182    call nl_set_ifsnow (head_grid%id, 1)
183    call nl_set_icloud (head_grid%id, 0)
184    !call nl_set_isfflx (head_grid%id, 0)
186    if ( model_config_rec%var4d_detail_out ) gradient_out = .true.
188    ! WRF model time-stepping.  Calls integrate().
189    call nl_set_var4d_run (head_grid%id, .true.)
190    call wrf_run_ad
191         
192    ! restore the physics options to the originals
193    call nl_set_mp_physics (head_grid%id, original_mp_physics)
194    call nl_set_ra_lw_physics (head_grid%id, original_ra_lw_physics)
195    call nl_set_ra_sw_physics (head_grid%id, original_ra_sw_physics)
196    call nl_set_sf_sfclay_physics (head_grid%id, original_sf_sfclay_physics)
197    call nl_set_bl_pbl_physics (head_grid%id, original_bl_pbl_physics)
198    call nl_set_cu_physics (head_grid%id, original_cu_physics)
199    head_grid%cudt = original_cudt
200    !call nl_set_mp_zero_out (head_grid%id, original_mp_zero_out)
201    !call nl_set_sf_surface_physics (head_grid%id, original_sf_surface_physics)
202    call nl_set_ifsnow (head_grid%id, original_ifsnow)
203    call nl_set_icloud (head_grid%id, original_icloud)
204    !call nl_set_isfflx (head_grid%id, original_isfflx)
206    ! Turn off auxinput6,7 reading and auxhist7 output
208    call nl_set_auxinput6_interval_s (head_grid%id, 0 )
209    call nl_set_auxinput7_interval_s ( head_grid%id, 0 )
211    IF ( ASSOCIATED( head_grid%domain_clock ) ) THEN
212      IF ( head_grid%domain_clock_created ) THEN
213        CALL WRFU_ClockDestroy( head_grid%domain_clock )
214        head_grid%domain_clock_created = .FALSE.
215      ENDIF
216    ENDIF
217    IF ( ASSOCIATED( head_grid%alarms ) .AND. &
218         ASSOCIATED( head_grid%alarms_created ) ) THEN
219      DO alarmid = 1, MAX_WRF_ALARMS
220        IF ( head_grid%alarms_created( alarmid ) ) THEN
221          CALL WRFU_AlarmDestroy( head_grid%alarms( alarmid ) )
222          head_grid%alarms_created( alarmid ) = .FALSE.
223        ENDIF
224      ENDDO
225    ENDIF
226    call Setup_Timekeeping ( head_grid )
228    if (trace_use_dull) call da_trace_exit("da_ad_model")
230 end subroutine da_ad_model