EMPIRE DA  v1.9.1
Data assimilation codes using EMPIRE communication
 All Classes Files Functions Variables Pages
proposal_filter.f90
Go to the documentation of this file.
1 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2 !!! Time-stamp: <2015-09-09 13:37:50 pbrowne>
3 !!!
4 !!! Subroutine to perform nudging in the proposal step of EWPF
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 !subroutine proposal_filter based on subroutine IntegrateModel
29 !given from the Particle filter code of Mel and Peter Jan
30 !PAB 04-02-2013
31 
33 subroutine proposal_filter
34  use pf_control
35  use sizes
36  use comms
37 
38  IMPLICIT NONE
39  include 'mpif.h'
40  integer, parameter :: rk = kind(1.0d0)
41 
42  real(kind=rk) :: pWeight
43  real(kind=rk), dimension(state_dim,pf%count) :: normaln !vector to store uncorrelated random error
44  real(kind=rk), dimension(state_dim,pf%count) :: betan !vector to store sqrtQ correlated random error
45  real(kind=rk), dimension(obs_dim) :: y !y, the observations
46  real(kind=rk), dimension(obs_dim,pf%count) :: Hpsi !H(psi^(n-1))
47  real(kind=rk), dimension(obs_dim,pf%count) :: y_Hpsin1 !y-H(psi^(n-1))
48  real(kind=rk), dimension(state_dim,pf%count) :: fpsi !f(psi^(n-1))
49  real(kind=rk), dimension(state_dim,pf%count) :: kgain !QH^T(HQH^T+R)^(-1)(y-H(psi^(n-1)))
50  real(kind=rk), dimension(state_dim,pf%count) :: Qkgain
51  integer :: particle,k
52  integer :: mpi_err
53  real(kind=rk) :: pweighttemp,ddot
54 
55  !get the model to provide f(x)
56  call send_all_models(state_dim,pf%count,pf%psi,1)
57 
58 
59  !get the next observations and store it in vector y
60  call get_observation_data(y,pf%timestep)
61 
62 
63  !compute y - H(x)
64  call h(obs_dim,pf%count,pf%psi,hpsi,pf%timestep)
65 
66  !$omp parallel do
67  do k = 1,pf%count
68  y_hpsin1(:,k) = y - hpsi(:,k)
69  end do
70  !$omp end parallel do
71 
72 
73  !draw from a Gaussian for the random noise
74  call normalrandomnumbers2d(0.0d0,1.0d0,state_dim,pf%count,normaln)
75 
76  call recv_all_models(state_dim,pf%count,fpsi)
77 
78 
79  !compute the relaxation term Qkgain, the intermediate
80  !term kgain and apply correlation to noise
81  call bprime(y_hpsin1,kgain,qkgain,normaln,betan)
82 
83 
84  !update the new state and weights based on these terms
85  !$omp parallel do private(particle,pweight)
86  DO k = 1,pf%count
87  particle = pf%particles(k)
88  ! print*,'|fpsi-psi|_2 = ',dnrm2(state_dim,(fpsi(:,k)-pf%psi(:,k)),1)
89  call update_state(pf%psi(:,k),fpsi(:,k),qkgain(:,k),betan(:,k))
90 
91 ! pweight = sum(Qkgain(:,k)*kgain(:,k))+2.0D0*sum(betan(:,k)*kgain(:,k))
92  pweight = ddot(state_dim,qkgain(:,k),1,kgain(:,k),1) + 2.0d0&
93  &*ddot(state_dim, betan(:,k),1,kgain(:,k),1)
94 
95  if(comm_version .eq. 3) then
96  !need to perform the sum across all parts of the state vector
97  pweighttemp=pweight
98  call mpi_allreduce(pweighttemp,pweight,1,mpi_double_precision,mpi_sum&
99  &,pf_member_comm,mpi_err)
100  end if
101 
102  pf%weight(particle) = pf%weight(particle) + 0.5*pweight
103  end DO
104  !$omp end parallel do
105 
106 end subroutine proposal_filter
subroutine normalrandomnumbers2d(mean, stdev, n, k, phi)
generate two dimensional Normal random numbers
Definition: gen_rand.f90:109
subroutine send_all_models(stateDim, nrhs, x, tag)
subroutine to send all the model states to the models
Definition: comms.f90:945
Module containing EMPIRE coupling data.
Definition: comms.f90:57
subroutine update_state(state, fpsi, kgain, betan)
Subroutine to update the state.
subroutine recv_all_models(stateDim, nrhs, x)
subroutine to receive all the model states from the models after
Definition: comms.f90:993
subroutine bprime(y, x, QHtR_1y, normaln, betan)
subroutine to calculate nudging term and correlated random errors efficiently
Module that stores the dimension of observation and state spaces.
Definition: sizes.f90:29
subroutine proposal_filter
Subroutine to perform nudging in the proposal step of EWPF.
subroutine h(obsDim, nrhs, x, hx, t)
subroutine to take a full state vector x and return H(x) in observation space.
module pf_control holds all the information to control the the main program
Definition: pf_control.f90:29
subroutine get_observation_data(y, t)
Subroutine to read observation from a file .