EMPIRE DA  v1.9.1
Data assimilation codes using EMPIRE communication
 All Classes Files Functions Variables Pages
empire_main.f90
Go to the documentation of this file.
1 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2 !!! Time-stamp: <2016-10-18 14:59:45 pbrowne>
3 !!!
4 !!! The main program to run EMPIRE
5 !!! Copyright (C) 2014 Philip A. Browne
6 !!!
7 !!! This program is free software: you can redistribute it and/or modify
8 !!! it under the terms of the GNU General Public License as published by
9 !!! the Free Software Foundation, either version 3 of the License, or
10 !!! (at your option) any later version.
11 !!!
12 !!! This program is distributed in the hope that it will be useful,
13 !!! but WITHOUT ANY WARRANTY; without even the implied warranty of
14 !!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 !!! GNU General Public License for more details.
16 !!!
17 !!! You should have received a copy of the GNU General Public License
18 !!! along with this program. If not, see <http://www.gnu.org/licenses/>.
19 !!!
20 !!! Email: p.browne @ reading.ac.uk
21 !!! Mail: School of Mathematical and Physical Sciences,
22 !!! University of Reading,
23 !!! Reading, UK
24 !!! RG6 6BB
25 !!!
26 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
27 
28 !program to run the particle filter on the model HadCM3.
29 !this shall hopefully have minimal changes specific to the model.
30 !Simon Wilson and Philip Browne 2013
31 !----------------------------------------------------------------
32 
33 
36 program empire_main
37  use output_empire
38  use timestep_data
39  use comms
40  use pf_control
41  use sizes
42  implicit none
43  include 'mpif.h'
44  integer :: i,j,k
45  integer :: mpi_err
46  real(kind=kind(1.0d0)) :: start_t,end_t
47 
48 
49  write(emp_o,'(A)') 'PF: Starting PF code'
50  call flush(emp_o)
51 
52 
54  call initialise_mpi
55 
57  call open_emp_o(pfrank)
58 
59  write(emp_o,*) 'PF: setting controls'
61  call set_pf_controls
62 
63 
64  write(emp_o,*) 'PF: configuring model'
66  call configure_model
67  call verify_sizes
68 
69  write(emp_o,*) 'allocating pf'
71  call allocate_pf
72 
73 
75  call random_seed_mpi(pfrank)
76  write(emp_o,*) 'PF: starting to receive from model'
77 
78 
79 
80  start_t = mpi_wtime()
81  pf%time=mpi_wtime()
82 
83  !if(.not. pf%gen_Q) then
84 
85  call recv_all_models(state_dim,pf%count,pf%psi)
86  do k = 1,pf%count
87  call perturb_particle(pf%psi(:,k))
88  end do
89 
90  write(emp_o,*) 'PF: All models received in pf couple'
91  call flush(emp_o)
92 
93  call output_from_pf
94  if(pf%gen_data) call save_truth(pf%psi(:,1))
95  if(pf%use_traj) call trajectories
96  if(pf%use_ens_rmse) call output_ens_rmse
97  start_t = mpi_wtime()
98 
99 
100  call timestep_data_allocate_obs_times(pf%time_obs)
101 
102  !start the timestep loop
103  do j=1,pf%time_obs
104  write(emp_o,*) 'PF: observation counter = ',j
105  call timestep_data_set_obs_times(j,pf%timestep+pf%time_bwn_obs)
106  call timestep_data_set_next_ob_time(pf%timestep+pf%time_bwn_obs)
107 
108  do i = 1,pf%time_bwn_obs-1
109  pf%timestep = pf%timestep + 1
110  call timestep_data_set_current(pf%timestep)
112  call timestep_data_set_tau(i)
113 
114  select case(pf%filter)
115  case('EW')
116  call proposal_filter
117  case('EZ')
118  call proposal_filter
119  case('SI')
120  call stochastic_model
121  case('SE')
122  call stochastic_model
123  case('LE')
124  call stochastic_model
125  case('LD')
127  case('DE')
129  case('3D')
130  call stochastic_model
131  case default
132  write(emp_e,*) 'Error -555: Incorrect pf%filter'
133  stop '-555'
134  end select
135  call timestep_data_set_completed(pf%timestep)
136  call flush(emp_o)
137  if(pf%gen_data) call save_truth(pf%psi(:,1))
138  if(pf%use_traj) call trajectories
139  if(pf%use_ens_rmse) call output_ens_rmse
140  if(pf%output_forecast) call output_forecast
141  call output_from_pf
142  end do
143 
144  pf%timestep = pf%timestep + 1
145  write(emp_o,*) 'starting the observation timestep'
146  call timestep_data_set_current(pf%timestep)
148  call timestep_data_set_tau(pf%time_bwn_obs)
149 
150  call flush(emp_o)
151 
152  select case(pf%filter)
153  case('EW')
155  case('EZ')
157  case('SI')
158  call sir_filter
159  case('SE')
160  call stochastic_model
161  if(pf%output_forecast) call output_forecast
162  call diagnostics
163  case('LE')
164  call stochastic_model
165  if(pf%output_forecast) call output_forecast
166  call letkf_analysis
167  case('LD')
169  if(pf%output_forecast) call output_forecast
170  call letkf_analysis
171  case('DE')
173  case('3D')
174  call stochastic_model
175  if(pf%output_forecast) call output_forecast
177  case default
178  write(emp_e,*) 'Error -556: Incorrect pf%filter'
179  stop '-556'
180  end select
181 
182  call timestep_data_set_completed(pf%timestep)
183  write(emp_o,*) 'PF: timestep = ',pf%timestep, 'after observation analysis'
184  call flush(emp_o)
185 
186  if(pf%gen_data) call save_truth(pf%psi(:,1))
187  if(pf%use_traj) call trajectories
188  if(pf%use_ens_rmse) call output_ens_rmse
189  call output_from_pf
190 
191  call reconfigure_model
192  call verify_sizes
193  end do
194  call diagnostics
195  write(emp_o,*) 'PF: finished the loop - now to tidy up'
196  call flush(emp_o)
197 
198 
199 
200  !send the final state to the model to allow it to finish cleanly
201  call send_all_models(state_dim,pf%count,pf%psi,3)
202 
203  !else
204  !
205  ! call genQ
206  !
207  !end if
208  end_t = mpi_wtime()
209 
210 
211 
212  call deallocate_pf
213 
214  write(emp_o,*) 'PF: finished deallocate_data - off to mpi_finalize'
215  call flush(emp_o)
216 
217  call mpi_finalize(mpi_err)
218  write(emp_o,*) 'Program couple_pf terminated successfully.'
219  write(emp_o,*) 'Time taken in running the model = ',end_t-start_t
220 
221  call close_emp_o
222 
223 end program empire_main
224 
225 
subroutine timestep_data_allocate_obs_times(n)
subroutine to allocate space for obs_times array
subroutine send_all_models(stateDim, nrhs, x, tag)
subroutine to send all the model states to the models
Definition: comms.f90:945
subroutine deallocate_pf
subroutine to deallocate space for the filtering code
Definition: pf_control.f90:519
subroutine deterministic_model
subroutine to simply move the model forward in time one timestep
subroutine configure_model
subroutine called initially to set up details and data for model specific functions ...
Module containing EMPIRE coupling data.
Definition: comms.f90:57
subroutine equivalent_weights_filter_zhu
subroutine to do the new scheme equal weights last time-step
subroutine close_emp_o()
subroutine to close the output file
Module that stores the information about the outputting from empire.
subroutine timestep_data_set_completed(t)
subroutine to define the number of completed timesteps
subroutine stochastic_model
subroutine to simply move the model forward in time one timestep PAB 21-05-2013
subroutine reconfigure_model
subroutine to reset variables that may change when the observation network changes ...
subroutine sir_filter
Subroutine to perform SIR filter (Sequential Importance Resampling)
Definition: sir_filter.f90:28
program empire_main
the main program
Definition: empire_main.f90:36
Module that stores the information about the timestepping process.
subroutine output_ens_rmse()
subroutine to output RMSEs
subroutine recv_all_models(stateDim, nrhs, x)
subroutine to receive all the model states from the models after
Definition: comms.f90:993
subroutine three_d_var_all_particles
subroutine to call 3DVar for each particle
subroutine initialise_mpi(mdl_id, cpl_root, cpl_mpi_comm)
subroutine letkf_analysis
subroutine to perform the ensemble transform Kalman filter as part of L-ETKF
subroutine save_truth(x)
Subroutine to save truth to a file .
Definition: data_io.f90:117
subroutine timestep_data_set_tau(pseudotimestep)
subroutine to define the current number of timesteps between observations
subroutine timestep_data_set_current(t)
subroutine to define the current timestep
Module that stores the dimension of observation and state spaces.
Definition: sizes.f90:29
subroutine diagnostics
Subroutine to give output diagnositics such as rank histograms.
Definition: diagnostics.f90:31
subroutine proposal_filter
Subroutine to perform nudging in the proposal step of EWPF.
subroutine timestep_data_set_do_no_analysis
subroutine to define if the current timestep should not perform an analysis
subroutine trajectories
subroutine to output trajectories
subroutine output_from_pf
subroutine to output data from the filter
Definition: data_io.f90:147
subroutine allocate_pf
subroutine to allocate space for the filtering code
Definition: allocate_pf.f90:28
subroutine random_seed_mpi(pfid)
Subroutine to set the random seed across MPI threads.
Definition: gen_rand.f90:233
subroutine timestep_data_set_obs_times(obs_num_in_time, timestep)
subroutine to set the timestep corresponding to the observation number in time
subroutine perturb_particle(x)
Subroutine to perturb state vector governed by the init option.
subroutine set_pf_controls
subroutine to ensure pf_control data is ok
Definition: pf_control.f90:146
module pf_control holds all the information to control the the main program
Definition: pf_control.f90:29
subroutine verify_sizes
Definition: comms.f90:1108
subroutine timestep_data_set_do_analysis
subroutine to define if the current timestep should perform an analysis
subroutine timestep_data_set_next_ob_time(ob_time)
subroutine to set the next observation timestep
subroutine output_forecast
subroutine to output forecast ensemble to forecast_path
subroutine equivalent_weights_filter
subroutine to do the equivalent weights step
subroutine open_emp_o(id_num)
subroutine to open the file for outputting