31 subroutine fcn( n, x, f, g )
33 integer,
intent(in) :: n
34 real(kind=kind(1.0d0)),
dimension(n),
intent(in) :: x
36 real(kind=kind(1.0d0)),
intent(out) :: f
37 real(kind=kind(1.0d0)),
dimension(n),
intent(out) :: g
41 print*,
'function = ',f
42 print*,
'gradient = ',g
109 integer,
parameter :: rk = kind(1.0d0)
110 integer,
intent(in) :: n
112 real(kind=rk),
dimension(n),
intent(in) :: v
114 real(kind=rk),
intent(out) :: f
115 real(kind=kind(1.0d0)),
dimension(n),
intent(out) :: g
121 if(pf_ens_rank .eq. 0)
then
123 if(comm_version .eq. 1 .or. comm_version .eq. 2)
then
127 if(pf_member_rank .eq. 0)
then
158 integer,
parameter :: rk = kind(1.0d0)
159 integer,
intent(in) :: n
160 real(kind=rk),
dimension(n),
intent(in) :: v
162 integer,
intent(in) :: stateDim
163 real(kind=rk),
dimension(stateDim),
intent(out) :: x
165 real(kind=rk),
dimension(stateDim) :: tempx
166 integer :: particle,mpi_err
170 call mpi_bcast(v,n,mpi_double_precision,&
171 0,pf_mpi_comm,mpi_err)
177 if(pfrank .ne. 0)
then
178 tempx = tempx + x0(:,particle )*v(particles(particle ))
179 elseif(particle .gt. 1)
then
180 tempx = tempx + x0(:,particle-1)*v(particles(particle-1))
186 call mpi_allreduce(tempx,x,statedim,mpi_double_precision,mpi_sum,&
187 &pf_mpi_comm,mpi_err)
204 use sizes, only : state_dim
207 integer,
parameter :: rk = kind(1.0d0)
208 integer,
intent(in) :: n
210 real(kind=rk),
dimension(n),
intent(in) :: v
212 real(kind=rk),
intent(out) :: f
213 real(kind=kind(1.0d0)),
dimension(n),
intent(out) :: g
215 logical,
intent(out) :: leave
216 real(kind=kind(1.0d0)),
dimension(n) :: tempg
219 real(kind=rk),
dimension(:),
allocatable :: y
220 real(kind=rk),
dimension(:,:),
allocatable :: hxt
221 real(kind=rk),
dimension(state_dim) :: xdet
222 real(kind=rk),
dimension(:),
allocatable :: RY_HMX
224 real(kind=rk) :: temp,sumhxtRY_HMX
225 integer :: message,mpi_err,particle
226 integer :: ensemble_comm
229 if(comm_version .eq. 1 .or. comm_version .eq. 2)
then
230 ensemble_comm = pf_mpi_comm
231 elseif(comm_version .eq. 3)
then
232 ensemble_comm = pf_ens_comm
234 write(emp_e,*)
'error. comm_version ',comm_version,
'in fourdenvar&
236 write(emp_e,*)
'stopping'
243 call mpi_bcast(message,1,mpi_integer,0,pf_mpi_comm,mpi_err)
245 if(pf_member_rank .ne. 0 .and. message .eq. 0)
then
251 if(comm_version .eq. 3)
then
252 call mpi_bcast(v,n,mpi_double_precision,0,pf_member_comm,mpi_err)
256 f = 0.5d0*sum(v*v)*
real(m-1,rk)
271 xt(:,particle) = x0(:,particle-1) + xdet(:)
277 do t = 1,vardata%total_timesteps
293 if(vardata%ny(t) .gt. 0)
then
298 allocate( y(vardata%ny(t)))
299 allocate( hxt(vardata%ny(t),cnt))
300 allocate(ry_hmx(vardata%ny(t)))
306 call mpi_bcast(xdet,state_dim,mpi_double_precision,&
307 0,ensemble_comm,mpi_err)
313 xt(:,particle) = (xt(:,particle) - xdet(:))
320 call
h(vardata%ny(t),cnt,xt,hxt,t)
326 xt(:,particle) = xt(:,particle) + xdet(:)
340 call
solve_r(vardata%ny(t),1,y,ry_hmx,t)
344 call mpi_bcast(ry_hmx,vardata%ny(t),mpi_double_precision,&
345 0,ensemble_comm,mpi_err)
351 if(comm_version .eq. 3)
then
353 call mpi_reduce(temp,ft,1,mpi_double_precision,mpi_sum&
354 &,0,pf_member_comm,mpi_err)
363 sumhxtry_hmx = sum(hxt(:,particle)*ry_hmx)
364 if(comm_version .eq. 3)
then
367 call mpi_allreduce(temp,sumhxtry_hmx,1&
368 &,mpi_double_precision,mpi_sum&
369 &,pf_member_comm,mpi_err)
372 tempg(particles(particle)-1) =&
373 & tempg(particles(particle)-1) &
394 call mpi_reduce(tempg,g,n,mpi_double_precision,mpi_sum&
395 &,0,ensemble_comm,mpi_err)
399 g = g + v*
real(m-1,rk)
410 use sizes, only : state_dim
413 integer,
parameter :: rk = kind(1.0d0)
414 integer,
intent(in) :: n
416 real(kind=rk),
dimension(n),
intent(in) :: v
418 logical,
intent(out) :: leave
419 real(kind=kind(1.0d0)),
dimension(n) :: tempg
420 real(kind=kind(1.0d0)),
dimension(n) :: g
423 real(kind=rk),
dimension(:,:),
allocatable :: hxt
424 real(kind=rk),
dimension(state_dim) :: xdet
425 real(kind=rk),
dimension(:),
allocatable :: RY_HMX
426 integer :: message,mpi_err,particle
427 integer :: ensemble_comm
432 call mpi_bcast(message,1,mpi_integer,0,pf_mpi_comm,mpi_err)
433 if(message .eq. -1)
then
443 xt(:,particle) = x0(:,particle) + xdet(:)
448 do t = 1,vardata%total_timesteps
463 if(vardata%ny(t) .gt. 0)
then
467 allocate( hxt(vardata%ny(t),cnt))
468 allocate(ry_hmx(vardata%ny(t)))
473 call mpi_bcast(xdet,state_dim,mpi_double_precision,&
474 0,ensemble_comm,mpi_err)
479 xt(:,particle) = xt(:,particle) - xdet(:)
485 call
h(vardata%ny(t),cnt,xt,hxt,t)
491 xt(:,particle) = xt(:,particle) + xdet(:)
496 call mpi_bcast(ry_hmx,vardata%ny(t),mpi_double_precision,&
497 0,ensemble_comm,mpi_err)
503 tempg(particles(particle)) = tempg(particles(particle)) &
504 &- sum(hxt(:,particle)*ry_hmx)
515 call mpi_reduce(tempg,g,n,mpi_double_precision,mpi_sum&
516 &,0,ensemble_comm,mpi_err)
518 elseif(message .eq. 0)
then
521 write(emp_e,*)
'4DEnVar ERROR: mpi_bcast had unknown integer&
subroutine convert_control_to_state(n, v, stateDim, x)
a subroutine to convert the optimization control variable to a model state vector ...
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 fourdenvar_fcn_slave(n, v, leave)
Module containing EMPIRE coupling data.
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...
Module that stores the information about the timestepping process.
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 fourdenvar_fcn_master(n, v, f, g, leave)
subroutine h(obsDim, nrhs, x, hx, t)
subroutine to take a full state vector x and return H(x) in observation space.
subroutine fourdenvar_fcn(n, v, f, g)
subroutine to provide the objective function and gradient for 4dEnVar.
subroutine fcn(n, x, f, g)
This is the subroutine which the optimization routines call to get the objective function value and i...
subroutine timestep_data_set_next_ob_time(ob_time)
subroutine to set the next observation timestep
subroutine get_observation_data(y, t)
Subroutine to read observation from a file .
module holding data for variational problems