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.4 1998/05/20 15:13:09 peterg
## Writes out algebraic equations (if any).
##
## Revision 1.3 1998/03/03 09:02:46 peterg
## Replaced MTTEyx*MTTEdX + MTTEyu*MTTdu; term
##
## Revision 1.2 1997/08/26 08:22:36 peterg
|
>
>
>
|
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.5 1998/05/20 15:23:26 peterg
## Put MTTYz := MTTYz outsise the BEGIN/END
##
## Revision 1.4 1998/05/20 15:13:09 peterg
## Writes out algebraic equations (if any).
##
## Revision 1.3 1998/03/03 09:02:46 peterg
## Replaced MTTEyx*MTTEdX + MTTEyu*MTTdu; term
##
## Revision 1.2 1997/08/26 08:22:36 peterg
|
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
64
65
66
67
68
69
70
|
## Sorted out bug when MTTNz=0
##
## Revision 1.1 1996/08/15 16:47:02 peter
## Initial revision
##
###############################################################
#Inform user
echo Creating $1_cse.r
# Remove the old log file
rm -f dae2cse_r.log
# Use reduce to accomplish the transformation
$SYMBOLIC >dae2cse_r.log << EOF
OFF Echo;
OFF Nat;
ON NERO;
in "$1_def.r";
MTTdxs := MTTdX; %Save the symbolic form of dX
in "$1_subs.r";
in "$1_dae.r";
%Create F_x, F_y matrices - assumming equations are linear in dZ
IF MTTNz>0 THEN
BEGIN
% Find MTTFx;
write "% Find MTTFx;";
matrix MTTFx(MTTNx,MTTNz);
FOR j := 1:MTTNz DO
|
|
>
>
>
>
>
>
>
|
>
|
>
|
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
## Sorted out bug when MTTNz=0
##
## Revision 1.1 1996/08/15 16:47:02 peter
## Initial revision
##
###############################################################
#Explicit solution option
Solving=$2;
if [ "$Solving" = "Solving" ]; then
solve=1
echo "Creating $1_cse.r (with explicit solution of algebraic equations)"
else
solve=0
echo "Creating $1_cse.r"
fi
# Remove the old log file
rm -f dae2cse_r.log
# Use reduce to accomplish the transformation
$SYMBOLIC >dae2cse_r.log << EOF
OFF Echo;
OFF Nat;
ON NERO;
in "$1_def.r";
MTTdxs := MTTdX; %Save the symbolic form of dX
in "$1_subs.r";
in "$1_dae.r";
%Create F_x, F_y matrices - assumming equations are
% linear in dZ
IF MTTNz>0 THEN
BEGIN
% Find MTTFx;
write "% Find MTTFx;";
matrix MTTFx(MTTNx,MTTNz);
FOR j := 1:MTTNz DO
|
143
144
145
146
147
148
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
|
MTTdZ17 := 0;
MTTdZ18 := 0;
MTTdZ19 := 0;
MTTEdX := MTTdX; %Ie MTTEdX is MTTdX with the dz terms deleted ie EdX.
MTTdX := MTTdXs; %Restore the symbolic dX
MTTY := MTTY + MTTEyx*MTTEdX;
%%% This causes the matrix mismatch
%%% MTTdXs and MTTdu need setting in _def.r file
%%MTTY := MTTY + MTTEyu*MTTdu;
MTTY := MTTY + MTTEyx*(MTTE^(-1))*MTTEdX;
END; %%of MTTNz>0
IF MTTNz=0 THEN
BEGIN
MTTEdX := MTTdX;
MTTE := MTTI;
END;
%IF MTTNyz>0 THEN
%BEGIN
% %%%% Try and solve algebraic loops!!
%
% %Create list of the relevant equations
% MTT_eqns := {};
% FOR i := 1:MTTNyz DO
% MTT_eqns := append(MTT_eqns,{MTTyz(i,1)});
%
% %Create list of the relevant unknowns
% MTT_unknowns := {};
% FOR i := 1:MTTNyz DO
% MTT_unknowns := append(MTT_unknowns,{MTTUi(i,1)});
%
% %Solve the algebraic equations symbolically
% MTT_sol := solve(MTT_eqns,MTT_unknowns);
%
% %Substitute back into the equations
% FOR i := 1:MTTNyz DO
% BEGIN
% MTT_sol_i := first(MTT_sol); MTT_sol := rest(MTT_sol);
% set(lhs(MTT_sol_i),rhs(MTT_sol_i));
% END;
%
%END; % IF MTTNyz>0
%%Create the _cse.r file
OUT "$1_cse.r";
IF MTTNx>0 THEN
BEGIN
write "matrix MTTEdX(", MTTNx, ",1)";
END;
MTTEdX := MTTEdX;
IF MTTNy>0 THEN
BEGIN
write "matrix MTTY(", MTTNy, ",1)";
END;
MTTY := MTTY;
IF MTTNu>0 THEN
BEGIN
write "matrix MTTU(", MTTNu, ",1)";
write "matrix MTTdU(", MTTNu, ",1)";
END;
|
>
>
<
<
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>
>
>
|
|
|
|
|
|
|
|
|
>
>
|
>
|
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
|
MTTdZ17 := 0;
MTTdZ18 := 0;
MTTdZ19 := 0;
MTTEdX := MTTdX; %Ie MTTEdX is MTTdX with the dz terms deleted ie EdX.
MTTdX := MTTdXs; %Restore the symbolic dX
%% Add on input derivative terms
MTTEdX := MTTEdX + MTTExu*MTTdu;
MTTY := MTTY + MTTEyx*MTTEdX;
%%% This causes the matrix mismatch
%%% MTTdXs and MTTdu need setting in _def.r file
%%MTTY := MTTY + MTTEyu*MTTdu;
MTTY := MTTY + MTTEyx*(MTTE^(-1))*MTTEdX;
END; %%of MTTNz>0
IF MTTNz=0 THEN
BEGIN
MTTEdX := MTTdX;
MTTE := MTTI;
END;
IF (MTTNyz>0) AND ($solve>0) THEN
BEGIN
%%%% Try and solve algebraic loops!!
%Create list of the relevant equations
MTT_eqns := {};
FOR i := 1:MTTNyz DO
MTT_eqns := append(MTT_eqns,{MTTyz(i,1)});
%Create list of the relevant unknowns
MTT_unknowns := {};
FOR i := 1:MTTNyz DO
MTT_unknowns := append(MTT_unknowns,{MTTUi(i,1)});
%Solve the algebraic equations symbolically
%The result seems to be in an extra list - I don't know why
% So remove the outer list with first.
MTT_sol := first(solve(MTT_eqns,MTT_unknowns));
%Substitute back into the equations
FOR i := 1:MTTNyz DO
BEGIN
MTT_sol_i := first(MTT_sol); MTT_sol := rest(MTT_sol);
set(lhs(MTT_sol_i),rhs(MTT_sol_i));
END;
% No algebraic variables left!
MTTNYz := 0;
END; % IF MTTNyz>0
%%Create the _cse.r file
OUT "$1_cse.r";
IF MTTNx>0 THEN
BEGIN
write "matrix MTTEdX(", MTTNx, ",1)";
END;
MTTEdX := MTTEdX;
IF MTTNy>0 THEN
BEGIN
write "matrix MTTY(", MTTNy, ",1)";
END;
MTTY := MTTY;
IF MTTNu>0 THEN
BEGIN
write "matrix MTTU(", MTTNu, ",1)";
write "matrix MTTdU(", MTTNu, ",1)";
END;
|
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
|
MTTEyx := MTTEyx;
%%%%% MTTdU := MTTdU;
END;
IF MTTNyz>0 THEN
BEGIN
write "matrix MTTYz(", MTTNyz, ",1)";
END;
MTTYz := MTTYz;
write ";END;";
SHUT "$1_cse.r";
quit;
EOF
# Now invoke the standard error handling.
mtt_error_r dae2cse_r.log
|
>
>
>
>
>
>
|
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
|
MTTEyx := MTTEyx;
%%%%% MTTdU := MTTdU;
END;
IF MTTNyz>0 THEN
BEGIN
write "matrix MTTYz(", MTTNyz, ",1)";
END
ELSE
BEGIN
write "MTTNYz := 0;";
MTTYz := 0;
END;
MTTYz := MTTYz;
write ";END;";
SHUT "$1_cse.r";
quit;
EOF
# Now invoke the standard error handling.
mtt_error_r dae2cse_r.log
|