Index: mttroot/mtt/bin/mttrc.csh ================================================================== --- mttroot/mtt/bin/mttrc.csh +++ mttroot/mtt/bin/mttrc.csh @@ -1,7 +1,7 @@ #!/bin/csh -## Automatically generated from bashrc on Tue Apr 10 14:02:38 BST 2001 - DO NOT EDIT +## Automatically generated from bashrc on Wed May 9 09:02:08 BST 2001 - DO NOT EDIT #! /bin/sh ###################################### ##### Model Transformation Tools ##### ###################################### @@ -15,10 +15,19 @@ ############################################################### ## Version control history ############################################################### ## $Id$ ## $Log$ +## Revision 1.22 2001/04/12 03:08:00 geraint +## Improved sh->csh conversion, reduces environment namespace pollution. +## +## Revision 1.21 2001/04/10 13:56:13 gawthrop +## Uses standard mkoctfile +## +## Revision 1.20 2001/04/10 13:08:19 gawthrop +## Smoother translation to .cs using sh2csh +## ## Revision 1.19 2001/03/30 15:13:49 gawthrop ## Rationalised simulation modes to each return mtt_data ## ## Revision 1.18 2001/03/19 02:28:52 geraint ## Branch merge: merging-ode2odes-exe back to MAIN. @@ -39,11 +48,10 @@ ## ## Revision 1.17 2000/12/27 16:46:13 peterg ## Stripped the mtt- from paths ## ## Revision 1.16 2000/12/27 15:16:44 peterg -## If then else format ## ## Revision 1.15 2000/12/27 14:57:43 peterg ## Now takes the base path as an argument ## ## Revision 1.14 2000/12/27 13:11:43 peterg @@ -73,11 +81,11 @@ ## ## Revision 1.6 1998/03/13 11:53:29 peterg ## reduce --> reduce 64 ## ## Revision 1.5 1998/01/16 08:55:01 peterg -## MAKE make +## MAKE=make ## ## Revision 1.4 1998/01/06 09:14:51 peterg ## Added latex2html to setup ## # Revision 1.3 1998/01/06 09:11:26 peterg @@ -87,16 +95,13 @@ # Put under RCS at last # Added CC variable # ############################################################### -## When using csh, replace $1 by the mtt base path, eg /usr/share/mtt/latest +## When using csh, replace /home/peterg/Development/mttroot/mtt by the mtt base path, eg /usr/share/mtt/latest setenv MTT_BASE /home/peterg/Development/mttroot/mtt -#if [ -z "$MTT_BASE" ]; then -# echo mttrc requires one argument: eg mttrc /usr/share/mtt/latest -#else echo Setting paths with base $MTT_BASE # The following line sets up the make to use -- gmake is the standard # but you may wish to use lsmake for parallelism setenv MAKE 'make' @@ -157,49 +162,49 @@ # Ascend stuff setenv ASCENDLIBRARY $MTTPATH/ascend/lib # Oct file generation - use version with no optimisation. - setenv MKOCTFILE $MTT_LIB/octave/mkoctfile + #setenv MKOCTFILE $MTT_LIB/octave/mkoctfile # This for no optimisation + setenv MKOCTFILE mkoctfile # ode2odes.exe stuff # local system - setenv PLAT "i686-pc-linux-gnu" -# PREFIX "/usr/local" - setenv PREFIX "/usr" - setenv GCCVERS "2.95.2" - setenv SRCOCTAVE "/cvs/octave" - -# PLAT "mips-sgi-irix6.5" -# PREFIX "/usr/people/bevangp/GNU" -# GCCVERS "2.95.2" -# SRCOCTAVE "${PREFIX}/../build/octave-2.1.33" +set PLAT="i686-pc-linux-gnu" +# PREFIX="/usr/local" +set PREFIX="/usr" +set GCCVERS="2.95.2" +set SRCOCTAVE="/cvs/octave" + +# PLAT="mips-sgi-irix6.5" +# PREFIX="/usr/people/bevangp/GNU" +# GCCVERS="2.95.2" +# SRCOCTAVE="${PREFIX}/../build/octave-2.1.33" # include paths - setenv IOCTAVE "-I${PREFIX}/include/octave" +set IOCTAVE="-I${PREFIX}/include/octave" # library paths -# LOCTAVE "-L${PREFIX}/lib/octave -loctave -lcruft -loctinterp" - setenv LOCTAVE "-L${PREFIX}/lib/octave -loctave -lcruft -loctinterp" - setenv LKPATHSEA "-L${SRCOCTAVE}/kpathsea -lkpathsea" - setenv LREADLINE " -L${SRCOCTAVE}/readline -lreadline" - setenv LSYSTEM "-ldl -lm -lncurses" - setenv LF2C "-L${PREFIX}/lib/gcc-lib/${PLAT}/${GCCVERS} -lg2c" +# LOCTAVE="-L${PREFIX}/lib/octave -loctave -lcruft -loctinterp" +set LOCTAVE="-L${PREFIX}/lib/octave -loctave -lcruft -loctinterp" +set LKPATHSEA="-L${SRCOCTAVE}/kpathsea -lkpathsea" +set LREADLINE=" -L${SRCOCTAVE}/readline -lreadline" +set LSYSTEM="-ldl -lm -lncurses" +set LF2C="-L${PREFIX}/lib/gcc-lib/${PLAT}/${GCCVERS} -lg2c" # compiler options - setenv DEBUG "-g" - setenv OPTIM "-O3" - setenv FLAGS "-fno-rtti -fno-exceptions -fno-implicit-templates" +set DEBUG="-g" +set OPTIM="-O3" +set FLAGS="-fno-rtti -fno-exceptions -fno-implicit-templates" - # setenved variables + # exported variables setenv MTT_CXX "g++" setenv MTT_CXXFLAGS "${DEBUG} ${OPTIM} ${FLAGS}" setenv MTT_CXXLIBS "${LOCTAVE} ${LKPATHSEA} ${LREADLINE} ${LF2C} ${LSYSTEM}" setenv MTT_CXXINCS "-I. ${IOCTAVE}" setenv MTT_LDFLAGS " " -#fi Index: mttroot/mtt/bin/trans/make_ssim ================================================================== --- mttroot/mtt/bin/trans/make_ssim +++ mttroot/mtt/bin/trans/make_ssim @@ -13,32 +13,40 @@ mtt_header ${sys} ssim m > ${outfile} cat >> ${outfile} <4 + [n,m] = size(index); + if (n>m) # Make sure its a row vector + index = index'; + endif + endif [nx2,ny2] = ${sys}_def; - ny = ny2/2; y_par = []; MTT_input = u; [MTT_input_last,m] = size(u); if nargin<5 # No index given MTT_input_index = 0; [mtt_data] = ${sys}_ode2odes(x0,par,simpar); - y = mtt_data(:,2:2:1+2*ny); + y = mtt_data(:,2:2:1+ny2); + x = mtt_data(:,3+ny2:2:2+ny2+nx2); ypar = []; else # Compute sensitivities as well for i=index MTT_input_index = 0; p = par; # Reset parameters p(i) = 1; # Set sensitivity index to 1 [mtt_data] = ${sys}_ode2odes(x0,p,simpar); if (i==index(1)) - y = mtt_data(:,2:2:1+2*ny); + y = mtt_data(:,2:2:1+ny2); endif - y_par = [y_par, mtt_data(:,3:2:2+2*ny)]; + y_par = [y_par, mtt_data(:,3:2:2+ny2)]; + x = []; endfor endif endfunction EOF Index: mttroot/mtt/bin/trans/mtt_header ================================================================== --- mttroot/mtt/bin/trans/mtt_header +++ mttroot/mtt/bin/trans/mtt_header @@ -10,10 +10,13 @@ ############################################################### ## Version control history ############################################################### ## $Id$ ## $Log$ +## Revision 1.32 2001/05/24 07:42:12 gawthrop +## Included and updated the missing tf_r2m +## ## Revision 1.31 2001/04/03 14:49:42 gawthrop ## Revised to incorporate new ssim (sensitivity simulation) ## representation (m only just now). ## ## Revision 1.30 2001/03/30 15:13:58 gawthrop @@ -286,11 +289,11 @@ ;; ssim) states=no; inputs=no; parameters=no; - output='y,y_par' + output='y,y_par,x' args='x0,par,simpar,u,index' ;; tf) states=no; inputs=no; Index: mttroot/mtt/lib/comp/compound/Sensitivity/sCS/sCS_lbl.txt ================================================================== --- mttroot/mtt/lib/comp/compound/Sensitivity/sCS/sCS_lbl.txt +++ mttroot/mtt/lib/comp/compound/Sensitivity/sCS/sCS_lbl.txt @@ -5,10 +5,13 @@ % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % %% Version control history % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % %% $Id$ % %% $Log$ +% %% Revision 1.1 2000/12/28 10:31:35 peterg +% %% Put under RCS +% %% % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Port aliases %ALIAS in in_1,in_2 @@ -25,14 +28,14 @@ % blank % ---- Component labels ---- % Component type C - c lin effort,c;c_s + c slin effort,c;c_s % Component type SS [in] SS external,external % Component type Se e_0 SS e_0;e_0s Index: mttroot/mtt/lib/control/PPP/ppp_nlin.m ================================================================== --- mttroot/mtt/lib/control/PPP/ppp_nlin.m +++ mttroot/mtt/lib/control/PPP/ppp_nlin.m @@ -1,8 +1,8 @@ -function [U, U_all, Error, Y] = ppp_nlin (system_name,x_0,us,t,par_0,free,w,extras) +function [U, U_all, Error, Y] = ppp_nlin (system_name,x_0,par_0,sim,us,w,free,extras) - ## usage: U = ppp_nlin (system_name,x_0,u,t,par_0,free,w,weight) + ## usage: [U, U_all, Error, Y] = ppp_nlin (system_name,x_0,par_0,sim,us,w,free,extras) ## ## if nargin<8 extras.criterion = 1e-8; @@ -9,22 +9,24 @@ extras.max_iterations = 10; extras.v = 0.1; extras.verbose = 1; endif + s_system_name = sprintf("s%s", system_name); # Name of sensitivity system + ## Details [n_x,n_y,n_u] = eval(sprintf("%s_def;", system_name)); - [n_us,n_tau] = size(us); + [n_tau,n_us] = size(us); ## Checks if (n_us<>n_u) error(sprintf("Inputs (%i) not equal to system inputs (%i)", n_us, n_u)); endif - [par,Par,Error,Y] = ppp_optimise(system_name,x_0,us,t,par_0,free,w,extras); + [par,Par,Error,Y] = ppp_optimise(s_system_name,x_0,par_0,sim,us,w,free,extras); U = par(free(:,1)); U_all = Par(free(:,1),:); endfunction Index: mttroot/mtt/lib/control/PPP/ppp_nlin_sim.m ================================================================== --- mttroot/mtt/lib/control/PPP/ppp_nlin_sim.m +++ mttroot/mtt/lib/control/PPP/ppp_nlin_sim.m @@ -1,6 +1,6 @@ -function [y,x,u,t,U,U_c,U_l] = ppp_nlin_sim (system_name,A_u,tau,t_ol,N_ol,w,extras) +function [y,x,u,t,UU,UU_c,UU_l] = ppp_nlin_sim (system_name,i_ppp,i_par,A_u,w_s,N_ol,extras) ## usage: [y,x,u,t,U,U_c,U_l] = ppp_nlin_sim (system_name,A_u,tau,t_ol,N,w) ## ## @@ -20,58 +20,68 @@ ## Names s_system_name = sprintf("s%s", system_name); - ## System details + ## System details -- defines simulation within ol interval par = eval(sprintf("%s_numpar;", system_name)); - x_0 = eval(sprintf("%s_state;", system_name)) + simpar = eval(sprintf("%s_simpar;", system_name)) + x_0 = eval(sprintf("%s_state(par);", system_name)) [n_x,n_y,n_u] = eval(sprintf("%s_def;", system_name)); - ## Sensitivity system details + ## Sensitivity system details -- defines moving horizon simulation + simpars = eval(sprintf("%s_simpar;", s_system_name)) sympars = eval(sprintf("%s_sympar;", s_system_name)); pars = eval(sprintf("%s_numpar;", s_system_name)); ## Times - n_tau = length(tau); - dtau = tau(2)-tau(1); # Optimisation sample time - Tau = [0:dtau:tau(n_tau)+eps]; # Time in the moving axes - n_Tau = length(Tau); - dt = t_ol(2)-t_ol(1); - n_t = length(t_ol); - T_ol = t_ol(n_t)+dt - + ## -- within opt horizon + n_Tau = round(simpars.last/simpars.dt) + dtau = simpars.dt + Tau = [0:n_Tau-1]'*dtau; + [n_tau,n_w] = size(w_s); + tau = Tau(n_Tau-n_tau+1:n_Tau); + w = w_s(length(w_s)); # Final value of setpoint + + ## -- within ol interval + n_t = round(simpar.last/simpar.dt) + dt = simpar.dt; + t_ol = [0:n_t-1]'*dt; + T_ol = n_t*dt; ## Weight and moving-horizon setpoint - weight = [zeros(n_y,n_Tau-n_tau), ones(n_y,n_tau)]; - ws = w*ones(1,n_tau); +# weight = [zeros(n_y,n_Tau-n_tau), ones(n_y,n_tau)]; +# w_s = w*ones(n_tau,1); ## Create input basis functions [n_U,junk] = size(A_u); ## For moving horizon eA = expm(A_u*dtau); u_star_i = ones(n_U,1); u_star_tau = []; for i = 1:n_Tau - u_star_tau = [u_star_tau, u_star_i]; + u_star_tau = [u_star_tau; u_star_i']; u_star_i = eA*u_star_i; endfor ## and for actual implementation eA = expm(A_u*dt); u_star_i = ones(n_U,1); u_star_t = []; for i = 1:n_t - u_star_t = [u_star_t, u_star_i]; + u_star_t = [u_star_t; u_star_i']; u_star_i = eA*u_star_i; endfor if extras.verbose title("U*(tau)") xlabel("tau"); plot(Tau,u_star_tau) + title("U*(t)") + xlabel("t_ol"); + plot(t_ol,u_star_t) endif ## Check number of inputs adjust if necessary if n_u>n_U @@ -82,31 +92,15 @@ if n_u0 - [U, U_all, Error, Y] = ppp_nlin(s_system_name,x_0s,u_star_tau,tau,pars,free,ws,extras); + [U, U_all, Error, Y] = ppp_nlin(system_name,x_0s,pars,simpars,u_star_tau,w_s,i_ppp,extras); + pars(i_ppp(:,1)) = U; # Put final value of U into the parameter vector else Error = []; endif opt_time = time-tick; printf("Optimisation %i took %i iterations and %2.2f sec\n", i, \ length(Error), opt_time); -# title(sprintf("Moving horizon trajectories: Interval %i",i)); -# grid; -# plot(tau,Y) - + ##title(sprintf("Moving horizon trajectories: Interval %i",i)); + ##grid; + ##plot(tau,Y) + ## Generate control - - u_ol = U'*u_star_t(1:n_U,:); + u_ol = u_star_t*U; # Not used - just for show - ## Simulate system + ## Simulate system over one ol interval ## (Assumes that first gain parameter is one) - U_ol = [u_ol; zeros(n_u-1,n_t)]; # Generate the vector input - [y_ol,x_ol] = eval(sprintf("%s_sim(x_0, U_ol, t_ol, par);", system_name)); - - ## Extract state for next time - x_0 = x_ol(:,n_t); - - y = [y y_ol(:,1:n_t)]; - x = [x x_ol(:,1:n_t)]; - u = [u u_ol(:,1:n_t)]; - - UU = [UU, U]; - UU_l = [UU_l, U_l]; - UU_c = [UU_c, U_c]; - - t = [t, t_ol(:,1:n_t)+t_last*ones(1,n_t) ]; - t_last = t_last + t_ol(n_t); + ##U = [u_ol zeros(n_t,n_u-1)]; # Generate the vector input + [y_ol,y_s,x_ol] = eval(sprintf("%s_ssim(x_0s, pars, simpar, u_star_t);", s_system_name)); + + x_0 = x_ol(n_t+1,:)'; # Extract state for next time + y_ol = y_ol(1:n_t,:); # Avoid extra points due to rounding error + x_ol = x_ol(1:n_t,:); # Avoid extra points due to rounding error + + + y = [y; y_ol]; + x = [x; x_ol]; + u = [u; u_ol]; + + UU = [UU; U']; + UU_l = [UU_l; U_l']; + UU_c = [UU_c; U_c']; + + t = [t; t_ol+t_last*ones(n_t,1) ]; + t_last = t_last + T_ol; endfor - ## Rename returned matrices - U = UU; - U_l = UU_l; - U_c = UU_c; endfunction - - - - Index: mttroot/mtt/lib/control/PPP/ppp_optimise.m ================================================================== --- mttroot/mtt/lib/control/PPP/ppp_optimise.m +++ mttroot/mtt/lib/control/PPP/ppp_optimise.m @@ -26,10 +26,13 @@ ############################################################### ## Version control history ############################################################### ## $Id$ ## $Log$ + ## Revision 1.3 2001/04/05 11:50:12 gawthrop + ## Tidied up documentation + verbose mode + ## ## Revision 1.2 2001/04/04 08:36:25 gawthrop ## Restuctured to be more logical. ## Data is now in columns to be compatible with MTT. ## ## Revision 1.1 2000/12/28 11:58:07 peterg @@ -53,10 +56,13 @@ extras.verbose = 0; endif [n_data,n_y] = size(y_0); + if n_data