EMPIRE DA  v1.9.1
Data assimilation codes using EMPIRE communication
 All Classes Files Functions Variables Pages
output_ens_rmse.f90
Go to the documentation of this file.
1 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2 !!! Time-stamp: <2016-10-18 15:32:38 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_ens_rmse()
30  use output_empire, only : unit_ens_rmse,emp_e
31  use pf_control
32  use timestep_data
33  use sizes
34  use comms
35  implicit none
36  include 'mpif.h'
37  integer, parameter :: rk = kind(1.0d0)
38  real(kind=rk), dimension(state_dim,pf%count) :: e
39  real(kind=rk), dimension(state_dim) :: mse
40  real(kind=rk), dimension(state_dim) :: truth
41  integer :: ios,i
42  integer :: ensemble_comm,comm_root,mpi_err,rank
43 
44  character(256) :: filename
45 
46  call get_truth(truth)
47 
48 
49  !calculate the error
50  do i = 1,pf%count
51  e(:,i) = pf%psi(:,i) - truth
52  end do
53  !square the error
54  e = e*e
55 
56  !now let us sum the fields
57  !for memory usage we we store the summed across the ensemble
58  !members in the TRUTH variable
59  truth = sum(e,dim=2)
60 
61  !now the sum is only over those ensemble members on this mpi
62  !process. let us use an mpi reduce to sum up all the rest
63  !and store the result on the highest ranking empire process
64 
65 
66  select case(comm_version)
67  case(1,2,5)
68  ensemble_comm = pf_mpi_comm
69  comm_root = npfs-1
70  rank = pfrank
71  write(filename,'(A,A,A,i7.7)') 'ens_',trim(pf%rmse_filename),'_',pf%timestep
72  case(3)
73  ensemble_comm = pf_ens_comm
74  comm_root = pf_ens_size-1
75  rank = pf_ens_rank
76  write(filename,'(A,A,A,i7.7,A,i0)') 'ens_',trim(pf%rmse_filename),'_'&
77  &,pf%timestep,'.',pf_ens_rank
78  case default
79  write(emp_e,*) 'EMPIRE ERROR: output_ens_rmse comm_version'
80  write(emp_e,*) 'EMPIRE ERROR: comm_version',comm_version
81  write(emp_e,*) 'EMPIRE ERROR: is currently not supported. STOPPING'
82  stop '-9'
83  end select
84 
85  call mpi_reduce(truth,mse,state_dim,mpi_double_precision,mpi_sum&
86  &,comm_root,ensemble_comm,mpi_err)
87 
88  ! now need to ensure the mean is correct and take the root:
89  if( rank == comm_root ) then
90  mse = mse/real(nens,rk)
91  mse = sqrt(mse)
92 
93 
94  !mse is now the rmse that we want. Time to output it
95 
96  open(unit_ens_rmse,file=trim(filename),iostat=ios,action='write',status='replace'&
97  &,form='formatted')
98  if(ios .ne. 0) then
99  write(emp_e,*) 'EMPIRE ERROR: CANNOT open file ',filename
100  write(emp_e,*) 'Very strange that I couldnt open it. Im going to stop&
101  & now.'
102  stop '-12'
103  end if
104  write(unit_ens_rmse,*) mse
105  close(unit_ens_rmse)
106 
107 
108  end if
109 
110 
111 
112 
113 end subroutine output_ens_rmse
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.
subroutine output_ens_rmse()
subroutine to output RMSEs
Module that stores the dimension of observation and state spaces.
Definition: sizes.f90:29
subroutine get_truth(x)
Subroutine to read truth from the file written by save_truth .
Definition: data_io.f90:87
module pf_control holds all the information to control the the main program
Definition: pf_control.f90:29