38 integer,
parameter :: rk = kind(1.0d0)
39 real(kind=rk),
dimension(pf%count) :: a,b,alpha,c
40 real(kind=rk),
dimension(pf%nens) :: csorted
42 integer :: particle,i,mpi_err
43 real(kind=rk),
dimension(obs_dim) :: y
44 real(kind=rk),
dimension(obs_dim,pf%count) :: Hfpsi
45 real(kind=rk),
dimension(obs_dim,pf%count) :: y_Hfpsin1
46 real(kind=rk),
dimension(state_dim,pf%count) :: fpsi
47 real(kind=rk),
dimension(state_dim) :: psimean
48 real(kind=rk),
dimension(state_dim,pf%count) :: kgain
49 real(kind=rk),
dimension(state_dim,pf%count) :: betan
50 real(kind=rk),
dimension(state_dim,pf%count) :: statev
51 real(kind=rk),
dimension(obs_dim,pf%count) :: obsv,obsvv
53 real(kind=rk),
dimension(pf%count) :: e
54 real(kind=rk),
parameter :: pi = 4.0D0*atan(1.0d0)
55 logical,
dimension(pf%count) :: uniform
57 real(kind=rk) :: ddot,wtemp,betanTbetan
58 integer :: ensemble_comm
60 if(comm_version .eq. 1 .or. comm_version .eq. 2)
then
61 ensemble_comm = pf_mpi_comm
62 elseif(comm_version .eq. 3)
then
63 ensemble_comm = pf_ens_comm
65 write(emp_e,*)
'EMPIRE VERSION ',comm_version,
' NOT SUPPORTED IN &
66 &equivalent_weights_filter'
67 write(emp_e,*)
'THIS IS AN ERROR. STOPPING'
79 call
h(obs_dim,pf%count,fpsi,hfpsi,pf%timestep)
83 particle = pf%particles(i)
84 y_hfpsin1(:,i) = y - hfpsi(:,i)
88 if(comm_version .eq. 3)
then
91 call mpi_allreduce(wtemp,w,1,mpi_double_precision,mpi_sum&
92 &,pf_member_comm,mpi_err)
95 c(i) = pf%weight(particle) + 0.5d0*w
100 call mpi_allgatherv(c,pf%count,mpi_double_precision,csorted,gblcount&
101 &,gbldisp,mpi_double_precision,ensemble_comm,mpi_err)
105 cmax = csorted(nint(pf%keep*pf%nens))
110 call
k(y_hfpsin1,kgain)
111 call
h(obs_dim,pf%count,kgain,obsv,pf%timestep)
112 call
solve_r(obs_dim,pf%count,obsv,obsvv,pf%timestep)
116 a(i) = 0.5d0*ddot(obs_dim,obsvv(:,i),1,y_hfpsin1(:,i),1)
118 if(comm_version .eq. 3)
then
121 call mpi_allreduce(wtemp,a(i),1,mpi_double_precision,mpi_sum&
122 &,pf_member_comm,mpi_err)
126 call
innerr_1(obs_dim,pf%count,y_hfpsin1,e,pf%timestep)
130 particle = pf%particles(i)
131 b(i) = 0.5d0*e(i) - cmax + pf%weight(particle)
133 alpha(i) = 1.0d0 + sqrt(1.0d0 - b(i)/a(i) + 1.0d-6)
135 if(alpha(i) .ne. alpha(i)) alpha(i) = 1.0d0
142 &,pf%count,statev,uniform)
143 call
qhalf(pf%count,statev,betan)
147 if(c(i) .le. cmax)
then
148 particle = pf%particles(i)
150 pf%weight(particle) = pf%weight(particle) +&
151 (alpha(i)**2.0_rk - 2.0_rk*alpha(i))*a(i) + &
154 betantbetan = sum(betan(:,i)*betan(:,i))
155 if(comm_version .eq. 3)
then
158 call mpi_allreduce(wtemp,betantbetan,1,mpi_double_precision,mpi_sum&
159 &,pf_member_comm,mpi_err)
161 pf%weight(particle) = pf%weight(particle) +&
162 (alpha(i)**2.0_rk - 2.0_rk*alpha(i))*a(i) + &
164 + 2**(-
real(state_dim_g,rk)/2.0_rk)*pi**(
real(state_dim_g,rk)&
165 &/2.0_rk)*pf%nfac*pf%ufac**(-real(state_dim_g,rk))*((1.0_rk&
166 &-pf%efac)/pf%efac)*exp(0.5_rk*(betanTbetan))
171 call
update_state(pf%psi(:,i),fpsi(:,i),alpha(i)*kgain(:,i)&
173 psimean = psimean + pf%psi(:,i)
175 pf%weight(pf%particles(i)) = huge(1.0d0)
186 print*,
'time until resample = ',mpi_wtime()-pf%time
subroutine solve_r(obsDim, nrhs, y, v, t)
subroutine to take an observation vector y and return v in observation space.
subroutine send_all_models(stateDim, nrhs, x, tag)
subroutine to send all the model states to the models
subroutine resample
Subroutine to perform Universal Importance Resampling.
Module containing EMPIRE coupling data.
Module that stores the information about the outputting from empire.
Module that stores the information about the timestepping process.
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
Module that stores the dimension of observation and state spaces.
subroutine diagnostics
Subroutine to give output diagnositics such as rank histograms.
subroutine innerr_1(n, c, y, w, t)
subroutine to compute the inner product with
subroutine h(obsDim, nrhs, x, hx, t)
subroutine to take a full state vector x and return H(x) in observation space.
subroutine innerhqht_plus_r_1(y, w, t)
subroutine to compute the inner product with
module pf_control holds all the information to control the the main program
subroutine timestep_data_set_is_analysis
subroutine to define if the current ensemble is an analysis
subroutine get_observation_data(y, t)
Subroutine to read observation from a file .
A module for random number generation from the following distributions:
subroutine qhalf(nrhs, x, Qx)
subroutine to take a full state vector x and return in state space.
subroutine mixturerandomnumbers2d(mean, stdev, ufac, epsi, n, k, phi, uniform)
generate two dimensional vector, each drawn from mixture density
subroutine equivalent_weights_filter
subroutine to do the equivalent weights step
recursive subroutine quicksort_d(a, na)
subroutine to sort using the quicksort algorithm
subroutine k(y, x)
Subroutine to apply to a vector y in observation space where .