EMPIRE DA  v1.9.1
Data assimilation codes using EMPIRE communication
 All Classes Files Functions Variables Pages
output_variance.f90
Go to the documentation of this file.
1 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2 !!! Time-stamp: <2016-10-18 15:35:27 pbrowne>
3 !!!
4 !!! Subroutine to output RMSE
5 !!! Copyright (C) 2015 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 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
29 subroutine output_variance(mean)
30  use output_empire, only : unit_variance,emp_e
31  use pf_control
32  use timestep_data
33  use sizes
34  use comms, only : pf_ens_size,pf_ens_comm,pf_ens_rank,pf_member_rank
35  implicit none
36  include 'mpif.h'
37  integer, parameter :: rk = kind(1.0d0)
38  real(kind=rk), dimension(state_dim), intent(in) :: mean
39  !ensemble mean
40  real(kind=rk), dimension(state_dim) :: sum_perts
41  real(kind=rk), dimension(state_dim) :: variance
42  integer :: ios
43 
44  character(256) :: filename
45  integer :: i,mpi_err
46 
47  sum_perts = 0.0_rk
48  do i = 1,pf%count
49  sum_perts = sum_perts + (pf%psi(:,i) - mean)*(pf%psi(:,i) - mean)
50  end do
51 
52  !continue the sum across all da processes
53  call mpi_reduce(sum_perts,variance,state_dim,mpi_double_precision,mpi_sum&
54  &,pf_ens_size-1,pf_ens_comm,mpi_err)
55 
56  ! divide by Ne - 1 to get the sample variance
57  variance = variance/(pf%nens-1)
58 
59  if(pf_ens_rank .eq. pf_ens_size -1) then
60 
61  if(pf%timestep .eq. 0) then
62  write(filename,'(A,i0)') 'ensemble_variance_',pf_member_rank
63  open(unit_variance,file=trim(filename),iostat=ios,action='write',status='replace')
64  if(ios .ne. 0) then
65  write(emp_e,*) 'PARTICLE FILTER DATA ERROR!!!!! Cannot open &
66  &file ',filename
67  write(emp_e,*) 'Very strange that I couldnt open it. Im goin&
68  &g to stop now.'
69  stop
70  end if
71  end if
72 
73  write(unit_variance,*) variance
74 
75  if(tsdata%completed_timesteps .eq. tsdata%total_timesteps) close(unit_variance)
76 
77  end if !end if master process
78 end subroutine output_variance
Module containing EMPIRE coupling data.
Definition: comms.f90:57
Module that stores the information about the outputting from empire.
Module that stores the information about the timestepping process.
Module that stores the dimension of observation and state spaces.
Definition: sizes.f90:29
subroutine output_variance(mean)
subroutine to output ensemble variance
module pf_control holds all the information to control the the main program
Definition: pf_control.f90:29