EMPIRE DA  v1.9.1
Data assimilation codes using EMPIRE communication
 All Classes Files Functions Variables Pages
4dEnVar.f90
Go to the documentation of this file.
1 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2 !!! Time-stamp: <2015-10-16 15:32:33 pbrowne>
3 !!!
4 !!! Program to implement 4dEnVar
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 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
27 
29 program fourdenvar
30  use sizes
31  use comms
32  use var_data
33  use output_empire
34  use fourdenvardata
35 ! use pf_control
36  implicit none
37  include 'mpif.h'
38 
39  integer :: message,mpi_err
40  real(kind=kind(1.0d0)), dimension(3) :: xbar
41 
42  print*,'Starting 4DEnVar'
43  call flush(6)
45  call initialise_mpi
46 
48  call open_emp_o(pfrank)
49 
50 
51  call random_seed_mpi(pfrank)
53  call set_var_controls
54  vardata%n = nens-1
56  call configure_model
57 
59 
60 
61  call allocate_vardata
62 
64 
65  !get initial states from ensemble members
66  call recv_all_models(state_dim,cnt,xt)
67 
68 
69  !get the initial ensemble perturbation matrix
71 
72 
73  !get the initial guess
75 
76 
77  vardata%x0 = 0.0d0
78 
79 
80  call convert_control_to_state(vardata%n,vardata%x0,state_dim,xbar)
81  print*,'init guess = ',xbar
82 
83 
85 
86 ! vardata%ny = 0
87 ! call NormalRandomNumbers1d(0.0d0,1.0d0,vardata%n,vardata%x0)
88  !run optimization method
89 
90  if(pfrank == 0) then
91  print*,'vardata%n = ',vardata%n
92 
93  select case (vardata%opt_method)
94  case('cg')
95 
96  call subroutine_cg(vardata%cg_method,vardata%n,vardata%cg_eps,vardata%x0)
97 
98  case('lbfgs')
99  call lbfgs_sub(vardata%n,vardata%lbfgs_factr,vardata%lbfgs_pgtol,vardata%x0)
100 
101  case('lbfgsb')
102  call read_lbfgsb_bounds
103  call lbfgsb_sub(vardata%n,vardata%lbfgs_factr,vardata%lbfgs_pgtol,&
104  vardata%x0,vardata%nbd,vardata%l,vardata%u)
105 
106  case default
107 
108  end select
109 
110 
111  !finish other mpi loops with a broadcast
112  message = 0
113  call mpi_bcast(message,1,mpi_integer,0,pf_mpi_comm,mpi_err)
114 
115  else
116  call fourdenvar_fcn
117  end if
118 
119  print*,'optimization solution is:'
120  print*,vardata%x0
121 
122  print*,'that means optimal state is:'
123  call convert_control_to_state(vardata%n,vardata%x0,state_dim,xt(:&
124  &,1))
125  print*,xt(:,1)
126  print*,'background state was:'
127  print*,xb
128 
129  !finish model by sending state with tag = 3
130  call send_all_models(state_dim,cnt,xt,3)
131 
132  call mpi_finalize(mpi_err)
133 
134 
135 end program fourdenvar
subroutine allocate_vardata
subroutine to allocate space for 4denvar
Definition: var_data.f90:328
subroutine convert_control_to_state(n, v, stateDim, x)
a subroutine to convert the optimization control variable to a model state vector ...
subroutine send_all_models(stateDim, nrhs, x, tag)
subroutine to send all the model states to the models
Definition: comms.f90:945
subroutine configure_model
subroutine called initially to set up details and data for model specific functions ...
Module containing EMPIRE coupling data.
Definition: comms.f90:57
Module that stores the information about the outputting from empire.
module holding data specific for 4denvar, not var itself. this is necessary because of the difference...
subroutine read_ensemble_perturbation_matrix
subroutine to read in the ensemble perturbation matrix
subroutine recv_all_models(stateDim, nrhs, x)
subroutine to receive all the model states from the models after
Definition: comms.f90:993
subroutine lbfgsb_sub(n, factr_in, pgtol_in, x, nbd, l, u)
Limited memory BFGS bound constrained optimization code as callable subroutine.
Definition: lbfgsb_sub.f90:210
subroutine initialise_mpi(mdl_id, cpl_root, cpl_mpi_comm)
subroutine read_observation_numbers
subroutine to somehow read in observation numbers
Definition: var_data.f90:357
program fourdenvar
the main program to run 4DEnVar
Definition: 4dEnVar.f90:29
Module that stores the dimension of observation and state spaces.
Definition: sizes.f90:29
subroutine fourdenvar_fcn(n, v, f, g)
subroutine to provide the objective function and gradient for 4dEnVar.
subroutine random_seed_mpi(pfid)
Subroutine to set the random seed across MPI threads.
Definition: gen_rand.f90:233
subroutine allocate4denvardata
subroutine subroutine_cg(method, n, epsin, x)
Nonlinear Conjugate gradient method as callable subroutine.
Definition: cgsub.f90:27
subroutine read_lbfgsb_bounds
subroutine to somehow read in bounds data
Definition: var_data.f90:353
subroutine lbfgs_sub(n, factr_in, pgtol_in, x)
Limited memory BFGS unconstrained optimization code as callable subroutine.
Definition: lbfgs_sub.f90:198
subroutine read_background_term()
subroutine to read xb from file
subroutine set_var_controls
subroutine to ensure vardata is ok
Definition: var_data.f90:98
module holding data for variational problems
Definition: var_data.f90:29
subroutine open_emp_o(id_num)
subroutine to open the file for outputting