Index: mttroot/mtt/bin/mtt ================================================================== --- mttroot/mtt/bin/mtt +++ mttroot/mtt/bin/mtt @@ -15,10 +15,13 @@ ############################################################### ## Version control history ############################################################### ## $Header$ ## $Log$ +## Revision 1.360 2002/08/20 15:51:16 gawthrop +## Update to work with ident DIY rep +## ## Revision 1.359 2002/08/07 14:27:14 geraint ## Changes to make "-i dassl" work again. ## ## Revision 1.358 2002/08/07 11:04:40 geraint ## Now updates timestamp on lbl.txt after processing in make. This eliminates the delay where MTT spends a long period of time uselessly recursing through the model on subsequent passes if the label file is older than the bondgraph. @@ -1459,12 +1462,16 @@ -oct ) fixcc='-fixcc' mtt_switches="$mtt_switches $1"; using_oct=yes; ;; - -opt ) mtt_switches="$mtt_switches $1"; - optimise='-optimise';; + -opt | -optl ) + mtt_switches="$mtt_switches $1"; + optimise='-optimise_local';; + -optg ) + mtt_switches="$mtt_switches $1"; + optimise='-optimise_global';; -partition ) mtt_switches="$mtt_switches $1"; partition='-partition'; ;; -pdf ) mtt_switches="$mtt_switches $1"; ps=pdf; @@ -1553,11 +1560,13 @@ echo ' -dc Maximise derivative (not integral) causality' echo ' -i Use implicit, euler, rk4 or dassl integration' echo ' -ae Solve algebraic equations with specified solver' echo ' -o ode is same as dae' echo ' -oct use oct files in place of m files where appropriate' - echo ' -opt optimise code generation' + echo ' -opt optimise code generation (equivalent to -lopt)' + echo ' -optl optimise code generation (local : line-by-line)' + echo ' -optg optimise code generation (global : full vector)' echo ' -p print environment variables' echo ' -partition partition hierachical system' echo ' -pdf generate pdf in place of ps' echo ' -r reset time stamp on representation' echo ' -s generate sensitivity BG (use mtt -s sSys rep lang)' Index: mttroot/mtt/bin/trans/cse2ode_r ================================================================== --- mttroot/mtt/bin/trans/cse2ode_r +++ mttroot/mtt/bin/trans/cse2ode_r @@ -12,10 +12,13 @@ ############################################################### ## Version control history ############################################################### ## $Id$ ## $Log$ +## Revision 1.3 2001/07/27 23:29:10 geraint +## Optimises only when requested (-opt). +## ## Revision 1.2 2001/07/13 04:54:04 geraint ## Branch merge: numerical-algebraic-solution back to main. ## ## Revision 1.1.4.1 2001/05/04 04:07:24 geraint ## Numerical solution of algebraic equations. @@ -34,13 +37,16 @@ ############################################################### optimise=''; optimise_msg='' while [ -n "`echo $1 | grep '^-'`" ]; do case $1 in - -optimise) - optimise='-optimise' - optimise_msg=' with optimisation' ;; + -optimise_global ) + optimise='-optimise_global' + optimise_msg=' with global optimisation' ;; + -optimise_local ) + optimise='-optimise_local' + optimise_msg=' with local optimisation' ;; *) echo "$1 is an invalid argument - ignoring" ;; esac shift done @@ -126,16 +132,13 @@ in ("$1_odeo_write.r"); write "END;"; SHUT "$1_odeo.r"; quit; EOF + +if [ ${optimise:-""} = "-optimise_global" ]; then + mtt_optimise_global $1 ode + mtt_optimise_global $1 odeo +fi # Now invoke the standard error handling. mtt_error_r cse2ode_r.log - - - - - - - - Index: mttroot/mtt/bin/trans/cse2smx_lang ================================================================== --- mttroot/mtt/bin/trans/cse2smx_lang +++ mttroot/mtt/bin/trans/cse2smx_lang @@ -23,11 +23,11 @@ parameters='-parameters'; ;; -matrix) matrix='yes'; ;; - -optimise) + -optimise_global | -optimise_local ) optimise='LOAD SCOPE; ON GENTRANOPT;'; iname='INAME mtt_o;'; ;; -fixcc ) fix_mtt_pow='FOR ALL x,y LET x^y = mtt_pow(x,y);' Index: mttroot/mtt/bin/trans/csm2sm_r ================================================================== --- mttroot/mtt/bin/trans/csm2sm_r +++ mttroot/mtt/bin/trans/csm2sm_r @@ -12,10 +12,13 @@ ############################################################### ## Version control history ############################################################### ## $Id$ ## $Log$ +## Revision 1.2 2001/07/27 23:29:10 geraint +## Optimises only when requested (-opt). +## ## Revision 1.1 2000/12/28 12:24:03 peterg ## Put under RCS ## ## Revision 1.2 1996/08/25 10:11:32 peter ## Added END in output file. @@ -27,14 +30,17 @@ ############################################################### optimise=''; optimise_msg='' while [ -n "`echo $1 | grep '^-'`" ]; do case $1 in - -optimise) - optimise='-optimise' - optimise_msg=' with optimisation' ;; - *) + -optimise_global ) + optimise='-optimise_global' + optimise_msg=' with global optimisation' ;; + -optimise_local ) + optimise='-optimise_local' + optimise_msg=' with local optimisation' ;; + * ) echo "$1 is an invalid argument - ignoring" ;; esac shift done @@ -135,8 +141,12 @@ quit; EOF cat $1_$2.r1 $1_$2.r2 > $1_$2.r + +if [ ${optimise:-""} = "-optimise_global" ]; then + mtt_optimise_global $1 $2 +fi # Now invoke the standard error handling. mtt_error_r csm2sm_r.log Index: mttroot/mtt/bin/trans/dae2cse_r ================================================================== --- mttroot/mtt/bin/trans/dae2cse_r +++ mttroot/mtt/bin/trans/dae2cse_r @@ -13,10 +13,13 @@ ############################################################### ## Version control history ############################################################### ## $Id$ ## $Log$ +## Revision 1.23 2002/07/10 17:43:05 geraint +## Added feature [ 562453 ] Optimisation of algebraic equations. +## ## Revision 1.22 2002/06/28 15:35:47 geraint ## Commented out aej.r generation (not used yet). ## ## Revision 1.21 2002/06/28 10:13:40 geraint ## Includes fix_c.r in ese2rdae and def2write_r to eliminate occurrances of x**y. @@ -132,13 +135,16 @@ -fixcc ) fixcc='-fixcc' include=`echo 'in "'$MTT_LIB'/reduce/fix_c.r";'` fix_msg='fixing c and cc code'; ;; - -optimise) - optimise='-optimise' - optimise_msg=' with optimisation' ;; + -optimise_global ) + optimise='-optimise_global' + optimise_msg=' with global optimisation' ;; + -optimise_local ) + optimise='-optimise_local' + optimise_msg=' with local optimisation' ;; *) echo "$1 is an invalid argument - ignoring" ;; esac shift done @@ -470,10 +476,17 @@ touch $1_cseo.r2 cat $1_ae.r1 $1_ae.r2 > $1_ae.r cat $1_cse.r1 $1_cse.r2 > $1_cse.r cat $1_csex.r1 $1_csex.r2 > $1_csex.r cat $1_cseo.r1 $1_cseo.r2 > $1_cseo.r + +if [ ${optimise:-""} = "-optimise_global" ]; then + mtt_optimise_global $1 ae +# TODO: mtt_optimise_global $1 cse +# TODO: mtt_optimise_global $1 cseo +# TODO: mtt_optimise_global $1 csex +fi if [ "$solve" = "1" ]; then echo "Setting MTTNyz=0 in $1_def.r and updating other $1_def files" gawk '{ if ($1=="MTTNyz") Index: mttroot/mtt/bin/trans/dae2lde_r ================================================================== --- mttroot/mtt/bin/trans/dae2lde_r +++ mttroot/mtt/bin/trans/dae2lde_r @@ -11,21 +11,27 @@ ############################################################### ## Version control history ############################################################### ## $Id$ ## $Log$ +## Revision 1.2 2001/07/27 23:29:10 geraint +## Optimises only when requested (-opt). +## ## Revision 1.1 2000/12/28 12:25:13 peterg ## Initial revision ## ############################################################### optimise=''; optimise_msg='' while [ -n "`echo $1 | grep '^-'`" ]; do case $1 in - -optimise) - optimise='-optimise' - optimise_msg=' with optimisation' ;; + -optimise_global ) + optimise='-optimise_global' + optimise_msg=' with global optimisation' ;; + -optimise_local ) + optimise='-optimise_local' + optimise_msg=' with local optimisation' ;; *) echo "$1 is an invalid argument - ignoring" ;; esac shift done @@ -116,10 +122,15 @@ in ("$1_ldeo_write.r"); write "END;"; SHUT "$1_ldeo.r"; quit; EOF + +if [ ${optimise:-""} = "-optimise_global" ]; then +# TODO: global_optimise $1 lde +# TODO: global_optimise $1 ldeo +fi # Now invoke the standard error handling. mtt_error_r cse2lde_r.log Index: mttroot/mtt/bin/trans/def2write_r ================================================================== --- mttroot/mtt/bin/trans/def2write_r +++ mttroot/mtt/bin/trans/def2write_r @@ -11,10 +11,13 @@ ############################################################### ## Version control history ############################################################### ## $Id$ ## $Log$ +## Revision 1.16 2002/09/03 19:34:15 geraint +## Write EdX regardless - csex is needed to create ode when not optimised. +## ## Revision 1.15 2002/08/29 15:45:20 geraint ## Tests for existence of matrix before entering shell loop. ## Tests for existence of expression before attempting to write or optimise. ## ## Revision 1.14 2002/08/09 14:34:45 geraint @@ -74,13 +77,16 @@ ############################################################### optimise='' while [ -n "`echo $1 | grep '^-'`" ]; do case $1 in - -optimise) - opt='-optimise' - optimise_msg=' with optimisation' ;; + -optimise_global ) + opt='' + optimise_msg='' ;; + -optimise_local ) + opt='-optimise_local' + optimise_msg=' with local optimisation' ;; -fixcc ) include=`echo 'in "'$MTT_LIB'/reduce/fix_c.r";'` ;; *) echo "$1 is an invalid argument - ignoring" ;; esac @@ -151,28 +157,11 @@ *) echo def2write_r: representation $rep not recognised exit esac - -mtt_fix_integers () -{ - gawk -F":=" -v RS="$" -v ORS="$\n" ' -(NF == 1) { - print $0 -} -(NF > 1) { - lhs=$1 ; - rhs=$2" " ; - rhs1 = gensub ( /([^A-Za-z_0-9\.\+])([0-9]+)([^\.0-9])/ , "\\1\\2.0\\3" , "g", rhs ); - rhs2 = gensub ( /([^e]\+)([0-9]+)([^\.0-9])/ , "\\1\\2.0\\3" , "g", rhs1 ); - rhs3 = gensub ( /([^A-Za-z_0-9\.\+])([0-9]+)e([0-9]+).0([^\.0-9])/ , "\\1\\2\\3\\4" , "g" , rhs) - printf "%s:=%s$\n", lhs, rhs3 ; - }' -} - -mtt_optimise () +mtt_optimise_local () { sys="$1" lhs="$2" rhs="$3" @@ -223,11 +212,11 @@ rm -f def2write_r1.log def2write_r2.log # Write out the code echo "" > $1_$2_write.r -if [ ${opt:-""} = "-optimise" ]; then +if [ ${opt:-""} = "-optimise_local" ]; then echo 'off nat$' # echo 'on echo$' else echo 'off echo$' echo 'load gentran$' @@ -241,13 +230,13 @@ is=`n2m 1 $n`; js=`n2m 1 $m`; if [ $n -ge 1 ]; then for i in $is; do for j in $js; do - if [ ${opt:-""} = "-optimise" ]; then + if [ ${opt:-""} = "-optimise_local" ]; then name=`echo MTT$matrix'('$i','$j')'` - mtt_optimise $1 "$comma$name" "$name" + mtt_optimise_local $1 "$comma$name" "$name" comma='' else echo 'write' name=`echo MTT$matrix'('$i','$j')'` echo ' '$comma$name ':=' $name '$' ADDED mttroot/mtt/bin/trans/mtt_fix_integers Index: mttroot/mtt/bin/trans/mtt_fix_integers ================================================================== --- /dev/null +++ mttroot/mtt/bin/trans/mtt_fix_integers @@ -0,0 +1,12 @@ +#! /bin/sh + +mttmatrix='\(mtt[A-Za-z][A-Za-z]*\)' +integer='\([0-9][0-9]*\)' + +exec gawk -v RS=${1:-"$"} -v ORS=${2:-"$\n"} ' { +str = $0; +str1 = gensub ( /([^A-Za-z_0-9\.\+])([0-9]+)([^\.0-9])/ , "\\1\\2.0\\3" , "g", str ); +str2 = gensub ( /([^e]\+)([0-9]+)([^\.0-9])/ , "\\1\\2.0\\3" , "g", str1 ); +str3 = gensub ( /([^A-Za-z_0-9\.\+])([0-9]+)e([0-9]+).0([^\.0-9])/ , "\\1\\2\\3\\4" , "g" , str2) +printf "%s$\n", str3 ; +}' | sed -e "s/$mttmatrix($integer\.0,/\1(\2,/g" ADDED mttroot/mtt/bin/trans/mtt_optimise_global Index: mttroot/mtt/bin/trans/mtt_optimise_global ================================================================== --- /dev/null +++ mttroot/mtt/bin/trans/mtt_optimise_global @@ -0,0 +1,63 @@ +#! /bin/sh + +# script uses Reduce + Scope to optimise an entire vector + +system=$1 +representation=$2 + +# error codes +E_REP_NOT_SUPPORTED=-19 +E_FILE_NOT_EXIST=-20 + +case $representation in + ae) + matrix=yz ; + nmatrix=`mtt_getsize $system yz` ;; + ode) + matrix=dx ; + nmatrix=`mtt_getsize $system x` ;; + cseo | odeo) + matrix=y ; + nmatrix=`mtt_getsize $system y` ;; + *) + exit $E_REP_NOT_SUPPORTED;; +esac + +# Generate a command of the form +# optimise mtt?(1,1) :=: mtt?(1,1), mtt?(2,1) :=: mtt?(2,1), ..., INAME mtt_tmp$ +command="optimize" +counter=1 +while [ $counter -le $nmatrix ]; do + command="$command mtt$matrix($counter,1) :=: mtt$matrix($counter,1)," + counter=`expr $counter + 1` +done +command="$command INAME mtt_tmp$" + +logfile=${system}_${representation}_global_optimisation.log +tmpfile=${system}_${representation}_global_optimisation.tmp +outfile=${system}_${representation}.r + +if [ ! -f $outfile ]; then + exit $E_FILE_NOT_EXIST +fi + +# Use Reduce to perform the optimisation +${SYMBOLIC:-reduce} < $logfile 2>&1 +off nat$ +in "${system}_def.r"$ +matrix mtt$matrix($nmatrix,1)$ +in "$outfile"$ +load scope$ +out "$tmpfile"$ +$command +shut "$tmpfile"$ +$end$ +EOF + +cp $outfile $outfile.unoptimised +cp $tmpfile $outfile.tmp +cat $tmpfile | mtt_fix_integers > $outfile +#cp $tmpfile $outfile +echo ";end;" >> $outfile + +mtt_error_r $logfile Index: mttroot/mtt/bin/trans/mtt_r2m ================================================================== --- mttroot/mtt/bin/trans/mtt_r2m +++ mttroot/mtt/bin/trans/mtt_r2m @@ -16,10 +16,13 @@ ############################################################### ## Version control history ############################################################### ## $Id$ ## $Log$ +## Revision 1.30 2002/03/26 11:59:54 geraint +## Added dummy -optimise switch to prevent falling over for -cc generation. +## ## Revision 1.29 2001/09/07 00:25:56 geraint ## Partial fix for insidious bug which eliminates lines of code when parameter ## names of the form (in* or off*) start continuation lines. ## ## Revision 1.28 2001/07/13 04:54:04 geraint @@ -127,11 +130,11 @@ ;; -parameters) parameters='-parameters'; par='mttpar' ;; - -optimise) + -optimise_local | -optimise_global ) ;; *) echo $1 is an unknown option exit;; esac