EMPIRE DA  v1.9.1
Data assimilation codes using EMPIRE communication
 All Classes Files Functions Variables Pages
stochastic_model.f90
Go to the documentation of this file.
1 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2 !!! Time-stamp: <2016-10-18 15:03:36 pbrowne>
3 !!!
4 !!! subroutine to simply move the model forward in time one timestep
5 !!! then add model error
6 !!! Copyright (C) 2014 Philip A. Browne
7 !!!
8 !!! This program is free software: you can redistribute it and/or modify
9 !!! it under the terms of the GNU General Public License as published by
10 !!! the Free Software Foundation, either version 3 of the License, or
11 !!! (at your option) any later version.
12 !!!
13 !!! This program is distributed in the hope that it will be useful,
14 !!! but WITHOUT ANY WARRANTY; without even the implied warranty of
15 !!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 !!! GNU General Public License for more details.
17 !!!
18 !!! You should have received a copy of the GNU General Public License
19 !!! along with this program. If not, see <http://www.gnu.org/licenses/>.
20 !!!
21 !!! Email: p.browne @ reading.ac.uk
22 !!! Mail: School of Mathematical and Physical Sciences,
23 !!! University of Reading,
24 !!! Reading, UK
25 !!! RG6 6BB
26 !!!
27 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
32 
33 subroutine stochastic_model
34  use output_empire, only : emp_o,emp_e
35  use timestep_data
36  use pf_control
37  use sizes
38  use comms
39 
40  IMPLICIT NONE
41  include 'mpif.h'
42  integer, parameter :: rk = kind(1.0d0)
43 
44  real(kind=rk), dimension(state_dim,pf%count) :: normaln !vector to store uncorrelated random error
45  real(kind=rk), dimension(state_dim,pf%count) :: betan !vector to store sqrtQ correlated random error
46  real(kind=rk), dimension(state_dim,pf%count) :: fpsi !f(psi^(n-1))
47 ! real(kind=rk), dimension(state_dim,pf%count) :: kgain !QH^T(HQH^T+R)^(-1)(y-H(psi^(n-1)))
48  real(kind=rk), dimension(state_dim,pf%count) :: Qkgain
49  integer :: particle,k
50 
51  real(kind=rk), dimension(obs_dim) :: obsv,obsvv,y
52 
53  call send_all_models(state_dim,pf%count,pf%psi,1)
54 
55  call normalrandomnumbers2d(0.0d0,1.0d0,state_dim,pf%count,normaln)
56 
57  call qhalf(pf%count,normaln,betan)
58  qkgain = 0.0_rk
59 
60  call recv_all_models(state_dim,pf%count,fpsi)
61 
62  !$omp parallel do private(particle)
63  DO k = 1,pf%count
64  particle = pf%particles(k)
65  call update_state(pf%psi(:,k),fpsi(:,k),qkgain(:,k),betan(:,k))
66  end DO
67  !$omp end parallel do
68 
69 
70  if(pf%gen_data .and. tsdata%do_analysis) then
71  if(pf%count .ne. 1 .and. pf%nens .ne. 1) then
72  write(emp_e,*) 'OBS GEN ERROR -558: PLEASE RUN WITH ONLY A SINGLE &
73  &ENSEMBLE MEMBER'
74  stop '-558'
75  end if
76 
77  write(emp_o,*) 'generating the data'
78  call flush(emp_o)
79 
80 
81  !get model equivalent of observations
82  call h(obs_dim,1,pf%psi,y,pf%timestep)
83 
84  !generate uncorrelated random vector obsv
85  call normalrandomnumbers1d(0.0d0,1.0d0,obs_dim,obsv)
86 
87  !turn this into correlated random observation noise
88  call rhalf(obs_dim,1,obsv,obsvv,pf%timestep)
89 
90  !add the noise to the model equivalent obs
91  y = y + obsvv
92 
93  !output the observation to a file
94  call save_observation_data(y)
95 
96  !call diagnostics to save things like the truth etc
97  call diagnostics
98  end if
99 
100 end subroutine stochastic_model
101 
102 
subroutine normalrandomnumbers2d(mean, stdev, n, k, phi)
generate two dimensional Normal random numbers
Definition: gen_rand.f90:109
subroutine save_observation_data(y)
Subroutine to save observation to a file Uses pftimestep to determine which observation to save...
Definition: data_io.f90:61
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
Module that stores the information about the outputting from empire.
subroutine stochastic_model
subroutine to simply move the model forward in time one timestep PAB 21-05-2013
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
Definition: comms.f90:993
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 normalrandomnumbers1d(mean, stdev, n, phi)
generate one dimension of Normal random numbers
Definition: gen_rand.f90:74
subroutine h(obsDim, nrhs, x, hx, t)
subroutine to take a full state vector x and return H(x) in observation space.
subroutine rhalf(obsDim, nrhs, y, Ry, t)
subroutine to take an observation vector x and return Rx in observation space.
module pf_control holds all the information to control the the main program
Definition: pf_control.f90:29
subroutine qhalf(nrhs, x, Qx)
subroutine to take a full state vector x and return in state space.