Overview
Comment:adding global optimisation (-optg).
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | origin/global-optimisation | trunk
Files: files | file ages | folders
SHA3-256: a3bcf662f166a4e5c125846941ce69fe39bfde0ca52f433445c7695692d3ed3d
User & Date: geraint@users.sourceforge.net on 2002-09-03 23:44:43
Other Links: branch diff | manifest | tags
Context
2002-09-04
07:12:19
lines are joined before fixing integers - required to prevent vector indices becoming floating point. check-in: 85aae2b1e6 user: geraint@users.sourceforge.net tags: origin/global-optimisation, trunk
2002-09-03
23:44:43
adding global optimisation (-optg). check-in: a3bcf662f1 user: geraint@users.sourceforge.net tags: origin/global-optimisation, trunk
19:34:16
Created branch global-optimisation check-in: d53bcb0661 user: gawthrop@users.sourceforge.net tags: origin/global-optimisation, trunk
Changes

Modified mttroot/mtt/bin/mtt from [51a5ec4d55] to [cfe9634686].

13
14
15
16
17
18
19



20
21
22
23
24
25
26
# Copyright (C) 2001 by Peter J. Gawthrop

###############################################################
## Version control history
###############################################################
## $Header$
## $Log$



## 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.
##
## Revision 1.357  2002/06/28 10:13:40  geraint







>
>
>







13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Copyright (C) 2001 by Peter J. Gawthrop

###############################################################
## 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.
##
## Revision 1.357  2002/06/28 10:13:40  geraint
1457
1458
1459
1460
1461
1462
1463

1464
1465



1466
1467
1468
1469
1470
1471
1472
                subsystem="_"$2;
                shift;;
	-oct )
                fixcc='-fixcc'
                mtt_switches="$mtt_switches $1";
                using_oct=yes;
                ;;

	-opt )  mtt_switches="$mtt_switches $1";
                optimise='-optimise';;



	-partition ) mtt_switches="$mtt_switches $1";
                     partition='-partition';
                ;;
	-pdf )   mtt_switches="$mtt_switches $1";
                 ps=pdf; 
                 eps=pdf;
                 pdf='-pdf';







>
|
|
>
>
>







1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
                subsystem="_"$2;
                shift;;
	-oct )
                fixcc='-fixcc'
                mtt_switches="$mtt_switches $1";
                using_oct=yes;
                ;;
	-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; 
                 eps=pdf;
                 pdf='-pdf';
1551
1552
1553
1554
1555
1556
1557
1558


1559
1560
1561
1562
1563
1564
1565
    echo '         -d  <dir>  use directory <dir>'
    echo '         -dr <dir>  use files contained in <dir>'
    echo '         -dc Maximise derivative (not integral) causality'
    echo '         -i <implicit|euler|rk4|dassl>   Use implicit, euler, rk4 or dassl integration'
    echo '         -ae <reduce|hybrd|dassl|hooke>   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 '         -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)'
    echo '         -ss use steady-state info to initialise simulations'
    echo '         -stdin read input data from standard input for  simulations'







|
>
>







1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
    echo '         -d  <dir>  use directory <dir>'
    echo '         -dr <dir>  use files contained in <dir>'
    echo '         -dc Maximise derivative (not integral) causality'
    echo '         -i <implicit|euler|rk4|dassl>   Use implicit, euler, rk4 or dassl integration'
    echo '         -ae <reduce|hybrd|dassl|hooke>   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 (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)'
    echo '         -ss use steady-state info to initialise simulations'
    echo '         -stdin read input data from standard input for  simulations'

Modified mttroot/mtt/bin/trans/cse2ode_r from [945a7d1a16] to [70c1f00663].

10
11
12
13
14
15
16



17
18
19
20
21
22
23
# Copyright (c) P.J.Gawthrop, 1991, 1994.

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$



## 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.
## sys_ae.cc written for unsolved inputs.
## Solution of equations using hybrd from MINPACK (as used by Octave fsolve).







>
>
>







10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# Copyright (c) P.J.Gawthrop, 1991, 1994.

###############################################################
## 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.
## sys_ae.cc written for unsolved inputs.
## Solution of equations using hybrd from MINPACK (as used by Octave fsolve).
32
33
34
35
36
37
38
39
40
41



42
43
44
45
46
47
48
## Initial revision
##
###############################################################

optimise=''; optimise_msg=''
while [ -n "`echo $1 | grep '^-'`" ]; do
    case $1 in
	-optimise)
	    optimise='-optimise'
	    optimise_msg=' with optimisation' ;;



	*)
	    echo "$1 is an invalid argument - ignoring" ;;
    esac
    shift
done

# Create the reduce output code







|
|
|
>
>
>







35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
## Initial revision
##
###############################################################

optimise=''; optimise_msg=''
while [ -n "`echo $1 | grep '^-'`" ]; do
    case $1 in
	-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

# Create the reduce output code
124
125
126
127
128
129
130





131
132
133
134
135
136
137
138
139
140
141
OUT "$1_odeo.r";
write "%File: $1_odeo.r";
in ("$1_odeo_write.r");
write "END;";
SHUT "$1_odeo.r";
quit;
EOF






# Now invoke the standard error handling.
mtt_error_r cse2ode_r.log















>
>
>
>
>



<
<
<
<
<
<
<
<
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144








OUT "$1_odeo.r";
write "%File: $1_odeo.r";
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








Modified mttroot/mtt/bin/trans/cse2smx_lang from [6253408dee] to [a64f19c513].

21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
	;;
    -parameters)
	parameters='-parameters';
	;;
    -matrix)
	matrix='yes';
	;;
    -optimise)
	optimise='LOAD SCOPE; ON GENTRANOPT;';
        iname='INAME mtt_o;';
	;;
    -fixcc )
        fix_mtt_pow='FOR ALL x,y LET x^y = mtt_pow(x,y);'
        operator='OPERATOR mtt_pow;'
        blurb2='fixing c and cc code';







|







21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
	;;
    -parameters)
	parameters='-parameters';
	;;
    -matrix)
	matrix='yes';
	;;
    -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);'
        operator='OPERATOR mtt_pow;'
        blurb2='fixing c and cc code';

Modified mttroot/mtt/bin/trans/csm2sm_r from [d62d77923d] to [9197d41677].

10
11
12
13
14
15
16



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34



35
36
37
38
39
40
41
42
# Copyright (c) P.J.Gawthrop, 1991, 1994, 1996

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$



## 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.
## Error handling.
##
## Revision 1.1  1996/08/19 15:06:16  peter
## Initial revision
##
###############################################################

optimise=''; optimise_msg=''
while [ -n "`echo $1 | grep '^-'`" ]; do
    case $1 in
	-optimise)
	    optimise='-optimise'
	    optimise_msg=' with optimisation' ;;



	*)
	    echo "$1 is an invalid argument - ignoring" ;;
    esac
    shift
done

# Create the reduce output code
def2write_r $optimise $1 $2







>
>
>















|
|
|
>
>
>
|







10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# Copyright (c) P.J.Gawthrop, 1991, 1994, 1996

###############################################################
## 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.
## Error handling.
##
## Revision 1.1  1996/08/19 15:06:16  peter
## Initial revision
##
###############################################################

optimise=''; optimise_msg=''
while [ -n "`echo $1 | grep '^-'`" ]; do
    case $1 in
	-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

# Create the reduce output code
def2write_r $optimise $1 $2
133
134
135
136
137
138
139




140
141
142

SHUT "$1_$2.r2";
quit;

EOF

cat $1_$2.r1 $1_$2.r2 > $1_$2.r





# Now invoke the standard error handling.
mtt_error_r csm2sm_r.log







>
>
>
>



139
140
141
142
143
144
145
146
147
148
149
150
151
152

SHUT "$1_$2.r2";
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

Modified mttroot/mtt/bin/trans/dae2cse_r from [1e44bd3303] to [4b9ab23fb1].

11
12
13
14
15
16
17



18
19
20
21
22
23
24
# Copyright (c) P.J.Gawthrop 1991, 1992, 1994.

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$



## 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.
##
## Revision 1.20.2.1  2002/06/05 11:14:50  geraint







>
>
>







11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# Copyright (c) P.J.Gawthrop 1991, 1992, 1994.

###############################################################
## 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.
##
## Revision 1.20.2.1  2002/06/05 11:14:50  geraint
130
131
132
133
134
135
136
137
138
139



140
141
142
143
144
145
146
                solve=1
		solve_msg=' with explicit solution of algebraic equations' ;;
	-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' ;;



        *)
                echo "$1 is an invalid argument - ignoring" ;;
  esac
  shift
done

# Create the reduce output code







|
|
|
>
>
>







133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
                solve=1
		solve_msg=' with explicit solution of algebraic equations' ;;
	-fixcc )
		fixcc='-fixcc'
                include=`echo 'in "'$MTT_LIB'/reduce/fix_c.r";'`
                fix_msg='fixing c and cc code';
		;;
        -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

# Create the reduce output code
468
469
470
471
472
473
474







475
476
477
478
479
480
481
touch $1_ae.r1 $1_ae.r2
touch $1_cseo.r1
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 [ "$solve" = "1" ]; then
    echo "Setting MTTNyz=0 in $1_def.r and updating other $1_def files"
    gawk '{
     if ($1=="MTTNyz") 
       print "MTTNyz := 0;" 
     else print $0







>
>
>
>
>
>
>







474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
touch $1_ae.r1 $1_ae.r2
touch $1_cseo.r1
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") 
       print "MTTNyz := 0;" 
     else print $0

Modified mttroot/mtt/bin/trans/dae2lde_r from [ec8a1424aa] to [23baf7d704].

9
10
11
12
13
14
15



16
17
18
19
20
21
22
23
24
25
26



27
28
29
30
31
32
33
# Copyright (C) 2000 by Peter J. Gawthrop

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$



## 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' ;;



	*)
	    echo "$1 is an invalid argument - ignoring" ;;
    esac
    shift
done

# Create the reduce output code







>
>
>








|
|
|
>
>
>







9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# Copyright (C) 2000 by Peter J. Gawthrop

###############################################################
## 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_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

# Create the reduce output code
114
115
116
117
118
119
120





121
122
123
124
125
126
127
128
129
130
131
OUT "$1_ldeo.r";
write "%File: $1_ldeo.r";
in ("$1_ldeo_write.r");
write "END;";
SHUT "$1_ldeo.r";
quit;
EOF






# Now invoke the standard error handling.
mtt_error_r cse2lde_r.log















>
>
>
>
>











120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
OUT "$1_ldeo.r";
write "%File: $1_ldeo.r";
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








Modified mttroot/mtt/bin/trans/def2write_r from [bdaa78ff6b] to [31e9ce13cc].

9
10
11
12
13
14
15



16
17
18
19
20
21
22
# Copyright (C) 2000 by Peter J. Gawthrop

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$



## 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
## Fix to prevent numbers being formed with a decimal point in the exponent, Reduce cannot handle these.
##







>
>
>







9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# Copyright (C) 2000 by Peter J. Gawthrop

###############################################################
## 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
## Fix to prevent numbers being formed with a decimal point in the exponent, Reduce cannot handle these.
##
72
73
74
75
76
77
78
79



80
81
82
83
84
85
86
87
88
## Initial revision
##
###############################################################

optimise=''
while [ -n "`echo $1 | grep '^-'`" ]; do
    case $1 in
	-optimise)



	    opt='-optimise'
	    optimise_msg=' with optimisation' ;;
	-fixcc )
	    include=`echo 'in "'$MTT_LIB'/reduce/fix_c.r";'` ;;
	*)
	    echo "$1 is an invalid argument - ignoring" ;;
    esac
    shift
done







|
>
>
>
|
|







75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
## Initial revision
##
###############################################################

optimise=''
while [ -n "`echo $1 | grep '^-'`" ]; do
    case $1 in
	-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
    shift
done
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
        ms="$Nx $Nu $Nx $Nu"
	;;
    *)
        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 ()
{
    sys="$1"
    lhs="$2"
    rhs="$3"
    
    dae="${sys}_dae.r"
    tmp="mtt_optimise.tmp"







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|







155
156
157
158
159
160
161

















162
163
164
165
166
167
168
169
        ms="$Nx $Nu $Nx $Nu"
	;;
    *)
        echo def2write_r: representation $rep not recognised
        exit
esac


















mtt_optimise_local ()
{
    sys="$1"
    lhs="$2"
    rhs="$3"
    
    dae="${sys}_dae.r"
    tmp="mtt_optimise.tmp"
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260

# Remove log files
rm -f def2write_r1.log def2write_r2.log

# Write out the code
echo "" > $1_$2_write.r

if [ ${opt:-""} = "-optimise" ]; then
    echo 'off nat$'
#    echo 'on echo$'
else
    echo 'off echo$'
    echo 'load gentran$'
fi >> $1_$2_write.r

for matrix in $matrices; do
    matrix_exists=`grep -i MTT${matrix} ${sys}_dae.r | wc -l | gawk '{print $1}'`
    if [ "$matrix" = "EdX" -o $matrix_exists -gt 0 ]; then
	n=`first "$ns"`; ns=`rest "$ns"` 
	m=`first "$ms"`; ms=`rest "$ms"`
	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
			name=`echo MTT$matrix'('$i','$j')'`
			mtt_optimise $1 "$comma$name" "$name"
			comma=''
		    else
			echo 'write'
			name=`echo MTT$matrix'('$i','$j')'`
			echo '  '$comma$name ':=' $name '$'
		    fi >> $1_$2_write.r
		done
	    done
	fi
    fi
done
echo ';END;'                           >>$1_$2_write.r







|

















|

|












210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249

# Remove log files
rm -f def2write_r1.log def2write_r2.log

# Write out the code
echo "" > $1_$2_write.r

if [ ${opt:-""} = "-optimise_local" ]; then
    echo 'off nat$'
#    echo 'on echo$'
else
    echo 'off echo$'
    echo 'load gentran$'
fi >> $1_$2_write.r

for matrix in $matrices; do
    matrix_exists=`grep -i MTT${matrix} ${sys}_dae.r | wc -l | gawk '{print $1}'`
    if [ "$matrix" = "EdX" -o $matrix_exists -gt 0 ]; then
	n=`first "$ns"`; ns=`rest "$ns"` 
	m=`first "$ms"`; ms=`rest "$ms"`
	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_local" ]; then
			name=`echo MTT$matrix'('$i','$j')'`
			mtt_optimise_local $1 "$comma$name" "$name"
			comma=''
		    else
			echo 'write'
			name=`echo MTT$matrix'('$i','$j')'`
			echo '  '$comma$name ':=' $name '$'
		    fi >> $1_$2_write.r
		done
	    done
	fi
    fi
done
echo ';END;'                           >>$1_$2_write.r

Added mttroot/mtt/bin/trans/mtt_fix_integers version [370a813d90].

























>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
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 version [895e4d685d].































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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} <<EOF > $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

Modified mttroot/mtt/bin/trans/mtt_r2m from [6308144dd1] to [b2cdafb9ae].

14
15
16
17
18
19
20



21
22
23
24
25
26
27
# Copyright (C) 2000 by Peter J. Gawthrop

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$



## 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
## Branch merge: numerical-algebraic-solution back to main.
##







>
>
>







14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# Copyright (C) 2000 by Peter J. Gawthrop

###############################################################
## 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
## Branch merge: numerical-algebraic-solution back to main.
##
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
    -noglobals)
	noglobals='-noglobals';
	;;
    -parameters)
	parameters='-parameters';
        par='mttpar'
	;;
    -optimise)
	;;
    *)
	echo $1 is an unknown option
        exit;;
  esac
  shift
done







|







128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
    -noglobals)
	noglobals='-noglobals';
	;;
    -parameters)
	parameters='-parameters';
        par='mttpar'
	;;
    -optimise_local | -optimise_global )
	;;
    *)
	echo $1 is an unknown option
        exit;;
  esac
  shift
done


MTT: Model Transformation Tools
GitHub | SourceHut | Sourceforge | Fossil RSS ]