--- MITgcm_contrib/mlosch/optim_m1qn3/optim_sub.F 2012/04/27 09:50:46 1.2 +++ MITgcm_contrib/mlosch/optim_m1qn3/optim_sub.F 2016/05/09 09:37:17 1.8 @@ -1,9 +1,11 @@ -C $Header: /home/ubuntu/mnt/e9_copy/MITgcm_contrib/mlosch/optim_m1qn3/optim_sub.F,v 1.2 2012/04/27 09:50:46 mlosch Exp $ +C $Header: /home/ubuntu/mnt/e9_copy/MITgcm_contrib/mlosch/optim_m1qn3/optim_sub.F,v 1.8 2016/05/09 09:37:17 mlosch Exp $ C $Name: $ -c Include ECCO_CPPOPTIONS because the ecco_ctrl,cost files -c have headers with options for OBCS masks. -#include "ECCO_CPPOPTIONS.h" +C ECCO_CPPOPTIONS used to affect maxcvars and defined ALLOW_OBCS?_CONTROL +C#include "ECCO_CPPOPTIONS.h" +C now: +C CTRL_OPTIONS affects maxcvars and may define ALLOW_OBCS?_CONTROL +#include "CTRL_OPTIONS.h" subroutine optim_sub( I nn, ff @@ -35,6 +37,9 @@ #include "EEPARAMS.h" #include "SIZE.h" +#if (defined (ALLOW_GENARR2D_CONTROL) || defined (ALLOW_GENARR3D_CONTROL) || defined (ALLOW_GENTIM2D_CONTROL)) +# include "CTRL_SIZE.h" +#endif #include "ctrl.h" #include "optim.h" #include "m1qn3_common.h" @@ -56,7 +61,9 @@ _RL xx(nmax) _RL adxx(nmax) #endif + _RL xxmean +CML logical coldStart c formal parameters of m1qn3 integer reverse integer impres,imode(3),omode,niter,nsim,iz(5),indic @@ -137,7 +144,24 @@ rzs(1)=UNSET_RS dzs(1)=UNSET_RL - if ( optimcycle .eq. 0 ) then +c-- first read the model output into xx, adxx, and cost function +c value into objf + do i = 1,nn + xx(i) = 0. + adxx(i) = 0. + enddo +c + print *, ' OPTIM_SUB: read model state' + call optim_readdata( nn, ctrlname, .false., objf, xx ) + call optim_readdata( nn, costname, .false., objf, adxx ) + print *, ' OPTIM_SUB after reading ', + & ctrlname, ' and ', costname, ':' + print *, ' OPTIM_SUB nn = ', nn + print *, ' OPTIM_SUB objf = ', objf + print *, ' OPTIM_SUB xx(1) = ', xx(1) + print *, ' OPTIM_SUB adxx(1) = ', adxx(1) + + if ( coldStart ) then c-- cold start print *, ' OPTIM_SUB: cold start, optimcycle =', optimcycle imode(2) = 0 @@ -145,9 +169,16 @@ c that needs to be initialized here to make sure that we have a c clean start reentry = 0 -c ff has be read in optim_readparms, so we do not read it here again - objf = ff - df1 = objf-fmin +c compute expected decrease of cost function from objf and fmin; +c this value is only used for a cold start of m1qn3_offline, for a +c warm start df1 is overwritten with data from a restart file + df1=objf-fmin + if ( df1 .le. 0. ) then + print *, ' OPTIM_SUB: df1 = objf-fmin = ', df1, + & ' but should be > 0.' + stop 'ABNORMAL in S/R OPTIM_SUB' + endif + c open output file for m1qn3 open(io,file=fname_m1qn3,status='unknown') else @@ -161,22 +192,6 @@ c re-open output file for m1qn3 open(io,file=fname_m1qn3,status='old',position='append') endif -c-- read the model output into xx,adxx - if ( indic .eq. 4 ) then - do i = 1,nn - xx(i) = 0. - adxx(i) = 0. - enddo -c - print *, ' OPTIM_SUB: read model state' - call optim_readdata( nn, ctrlname, .false., objf, xx ) - call optim_readdata( nn, costname, .false., objf, adxx ) - print *, ' OPTIM_SUB after reading nn, objf = ', nn, objf, - & xx(1), adxx(1) - else - print *, ' OPTIM_SUB: indic = ', indic, ' is not possible' - stop 'ABNORMAL in S/R OPTIM_SUB' - endif c-- call the minimizer, a slightly modified version of m1qn3 v3.3 c (Gilbert & Lemarechal, 1989), downloaded in April 2012. @@ -184,20 +199,37 @@ c are provided within m1qn3. euclid, ctonbe, ctcabe can be replaced c by something more efficient, simul_rc is a dummy routine for c the reverse communication mode and should not be changed. - print *, ' OPTIM_SUB: call m1qn3_offline' + print *, ' OPTIM_SUB: call m1qn3_offline ........' call m1qn3_offline (simul_rc,euclid,ctonbe,ctcabe, & nn,xx,objf,adxx,dxmin,df1, & epsg,normtype,impres,io,imode,omode,niter,nsim, & iz,dz,ndz,reverse,indic,izs,rzs,dzs) close(io) + print *, ' OPTIM_SUB: ...........................' print *, ' OPTIM_SUB: returned from m1qn3_offline' - + print *, ' OPTIM_SUB: nn = ', nn + print *, ' OPTIM_SUB: xx(1) = ', xx(1), xx(2) + print *, ' OPTIM_SUB: adxx(1) = ', adxx(1), adxx(2) + print *, ' OPTIM_SUB: omode = ', omode + print *, ' OPTIM_SUB: niter = ', niter + print *, ' OPTIM_SUB: nsim = ', nsim + print *, ' OPTIM_SUB: reverse = ', reverse + +c compute min/max/mean/std of output vector see if it is within +c reasonable bounds (prior to scaling) + xxmean = sum(xx)/dble(nn) + print * + print *,' OPTIM_SUB: mean(xx) =', xxmean + print *,' OPTIM_SUB: max(xx) =', maxval(xx) + print *,' OPTIM_SUB: min(xx) =', minval(xx) + print *,' OPTIM_SUB: std(xx) =',sum((xx-xxmean)**2)/dble(nn) + print * c write state of m1qn3 into pickup file for warm restart call optim_store_m1qn3(ndz,iz,dz,niter,nsim,epsg,df1, I optimcycle, I .true.) c write model control vector - print *,' OPTIMS_SUB: writing ', nn,' sized control to file ', + print *,' OPTIM_SUB: writing ', nn,' sized control to file ', & ctrlname c give the cost function a funny value to make sure that nobody c mistakes it for the real one