EMPIRE DA  v1.9.1
Data assimilation codes using EMPIRE communication
 All Classes Files Functions Variables Pages
letks_test.f90
Go to the documentation of this file.
1 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2 !!! Time-stamp: <2016-10-18 15:01:55 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
37  use letks_data
38  use output_empire
39  use timestep_data
40  use comms
41  use pf_control
42  use sizes
43  implicit none
44  include 'mpif.h'
45  integer :: i,j,k
46  integer :: mpi_err
47  real(kind=kind(1.0d0)) :: start_t,end_t
48 
49  real(kind=kind(1.0d0)), allocatable, dimension(:,:) :: analysis,&
50  & forecast,inc
51 
52  write(6,'(A)') 'PF: Starting PF code'
53  call flush(6)
54 
55 
57  call initialise_mpi
58 
60  call open_emp_o(pfrank)
61 
62  write(emp_o,*) 'PF: setting controls'
64  call set_pf_controls
65 
66 
67  write(emp_o,*) 'PF: configuring model'
69  call configure_model
70  call verify_sizes
71 
72  write(emp_o,*) 'allocating pf'
74  call allocate_pf
75 
76 
78  call random_seed_mpi(pfrank)
79  write(6,*) 'PF: starting to receive from model'
80 
81 
82 
83  start_t = mpi_wtime()
84  pf%time=mpi_wtime()
85 
86  if(.not. pf%gen_Q) then
87 
88  call recv_all_models(state_dim,pf%count,pf%psi)
89 
90  do k = 1,pf%count
91  call perturb_particle(pf%psi(:,k))
92  end do
93 
94  write(6,*) 'PF: All models received in pf couple'
95  call flush(6)
96 
97  call output_from_pf
98  if(pf%gen_data) call save_truth(pf%psi(:,1))
99  if(pf%use_traj) call trajectories
100  start_t = mpi_wtime()
101 
102  allocate(analysis(state_dim,pf%count))
103  allocate(forecast(state_dim,pf%count))
104  allocate(inc(state_dim,pf%count))
105 
106  call timestep_data_allocate_obs_times(pf%time_obs)
107 
108  !start the timestep loop
109  do j=1,pf%time_obs
110  write(6,*) 'PF: observation counter = ',j
111  call timestep_data_set_obs_times(j,pf%timestep+pf%time_bwn_obs)
112  call timestep_data_set_next_ob_time(pf%timestep+pf%time_bwn_obs)
113 
114  do i = 1,pf%time_bwn_obs-1
115  pf%timestep = pf%timestep + 1
116  call timestep_data_set_current(pf%timestep)
118  call timestep_data_set_tau(i)
119 
120  select case(pf%filter)
121  case('EW')
122  call proposal_filter
123  case('EZ')
124  call proposal_filter
125  case('SI')
126  call stochastic_model
127  case('SE')
128  call stochastic_model
129  case('LE')
130  call stochastic_model
131  case('LS')
132  call stochastic_model
133  case('LD')
135  case('DE')
137  case default
138  write(emp_e,*) 'Error -555: Incorrect pf%filter'
139  stop '-555'
140  end select
141  call timestep_data_set_completed(pf%timestep)
142  call flush(6)
143  if(pf%use_traj) call trajectories
144  call output_from_pf
145  end do
146 
147  pf%timestep = pf%timestep + 1
148  write(6,*) 'starting the observation timestep'
149  call timestep_data_set_current(pf%timestep)
151  call timestep_data_set_tau(pf%time_bwn_obs)
152 
153  call flush(6)
154 
155  select case(pf%filter)
156  case('EW')
158  case('EZ')
160  case('SI')
161  call sir_filter
162  case('SE')
163  call stochastic_model
164  call diagnostics
165  case('LE')
166  call stochastic_model
167  call letkf_analysis
168  case('LD')
170  call letkf_analysis
171  case('DE')
173  case('LS')
174  call stochastic_model
175  !Now we have a forecast. save it
176  forecast = pf%psi
177  !do letkf
178  call letkf_analysis
179  analysis = pf%psi
180 
181  pf%psi = forecast
182  call letks_filter_stage
183  !now check that filter stage agrees with analysis
184  print*,'Difference in letkf and letks_filter = ',sum( (pf%psi&
185  &-analysis)**2 )
186  call letks_increment(forecast,inc)
187  pf%psi = forecast + inc
188  print*,'Difference in letkf and letks = ',sum( (pf%psi&
189  &-analysis)**2 )
190 
191  case default
192  write(emp_e,*) 'Error -556: Incorrect pf%filter'
193  stop '-556'
194  end select
195 
196  call timestep_data_set_completed(pf%timestep)
197  write(6,*) 'PF: timestep = ',pf%timestep, 'after observation analysis'
198  call flush(6)
199 
200  if(pf%gen_data) call save_truth(pf%psi(:,1))
201  if(pf%use_traj) call trajectories
202  call output_from_pf
203 
204  call reconfigure_model
205  call verify_sizes
206  end do
207  call diagnostics
208  write(6,*) 'PF: finished the loop - now to tidy up'
209  call flush(6)
210 
211 
212 
213  !send the final state to the model to allow it to finish cleanly
214  call send_all_models(state_dim,pf%count,pf%psi,3)
215 
216  else
217 
218  call genq
219 
220  end if
221  end_t = mpi_wtime()
222 
223 
224 
225  call deallocate_pf
226 
227  write(6,*) 'PF: finished deallocate_data - off to mpi_finalize'
228  call flush(6)
229 
230  call mpi_finalize(mpi_err)
231  write(*,*) 'Program couple_pf terminated successfully.'
232  write(*,*) 'Time taken in running the model = ',end_t-start_t
233 
234  call close_emp_o
235 
236 end program empire
237 
238 
subroutine timestep_data_allocate_obs_times(n)
subroutine to allocate space for obs_times array
module for doing things related to the LETKS:
Definition: letks.f90:31
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
Module that stores the information about the timestepping process.
program empire
the main program
Definition: letks_test.f90:36
subroutine recv_all_models(stateDim, nrhs, x)
subroutine to receive all the model states from the models after
Definition: comms.f90:993
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 letks_increment(psi, inc)
subroutine to compute the LETKS increments
Definition: letks.f90:398
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 genq
Subroutine to estimate Q from a long model run.
Definition: genQ.f90:28
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 letks_filter_stage
subroutine to compute the data for the LETKS, so that the increments can subsquently be computed ...
Definition: letks.f90:54
subroutine equivalent_weights_filter
subroutine to do the equivalent weights step
subroutine open_emp_o(id_num)
subroutine to open the file for outputting