Overview
Comment:Initial revision
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | origin/master | trunk
Files: files | file ages | folders
SHA3-256: c38431afc2dac1d353b202e4c4e0f4f191bb1402fa42f103f3461f1ed6896859
User & Date: gawthrop@users.sourceforge.net on 1996-08-15 16:46:06
Other Links: branch diff | manifest | tags
Context
1996-08-15
16:47:47
DAE solution (experimental) included. check-in: c7c8b3075d user: gawthrop@users.sourceforge.net tags: origin/master, trunk
16:46:06
Initial revision check-in: c38431afc2 user: gawthrop@users.sourceforge.net tags: origin/master, trunk
16:24:55
Initial revision check-in: 26f89d6fe2 user: gawthrop@users.sourceforge.net tags: origin/master, trunk
Changes

Added mttroot/mtt/bin/trans/dae_r2m version [b4cda47e9b].

































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
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
#! /bin/sh

     ###################################### 
     ##### Model Transformation Tools #####
     ######################################

# Bourne shell script: dae_r2m
# Reduce DAE to simulab  DAE  
# P.J.Gawthrop 14 June 1991, 12 Jan 1994, April 1994, Jan 95.
# Copyright (c) P.J.Gawthrop 1991, 1994, 1995, 1996

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


# WARNING this is experimental!!
# It asumes that the output y is NOT dependent on derivatives of
#  z or u.


#Inform user
echo Creating $1_dae.m
echo Creating $1_daeo.m


# Remove the old log file
rm -f dae_r2m.log

# Use reduce to accomplish the transformation
reduce >dae_r2m.log << EOF

%Read the reduce definitions file
in "$1_def.r";

%Read the reduce  DAE   file
in "$1_dae.r";

%Set up the number of argument variables to zero in case the user has forgotten
MTTNVar := 0;

%Read the parameter file
in "$1_sympar.r";


ON NERO;        % Suppress zero elements

%Define the common part of the functions.

PROCEDURE common;
BEGIN
  IF MTTNvar>0 THEN
  BEGIN
    write "% Read in the parameters";
    write "[ ...;;";
    FOR i := 1:MTTNvar DO
    BEGIN
       IF i<MTTNvar THEN write MTTVar(i,1), ",..."
                    ELSE write MTTVar(i,1), "] = $1_numpar"
    END;
  END;
  
  write "% Read in the arguments";
  write "$1_args";
  
  write "% check that u is defined and default it if not";
  write "if exist('u')==0";
  write "  u = ones(", MTTNu, ",1);";
  write "end";
  
  write "% Set up the State variables";
  FOR i := 1:MTTNx DO
  BEGIN
    write "MTTx", i, " = MTTx(", i, ");";
  END;

  write "% Set up the non-state variables";
  FOR i := 1:MTTNz DO
  BEGIN
    write "MTTz", i, " = MTTx(", MTTNx+ i, ");";
  END;
  
  write "% Set up the Input variables";
  IF MTTNu>0 THEN
  FOR i := 1:MTTNu DO
  BEGIN
    write "MTTu", i, " = u(", i, ");";
  END;
END;
  
% Firstly do the residual = f(dx,x,t) function.

%MTTGx and u are the derivatives of z wrt x and u respectively

% Find MTTGx;
matrix MTTGx(MTTNz,MTTNx);
FOR j := 1:MTTNx DO
  BEGIN
  xj := MTTX(j,1);
  FOR i := 1:MTTNz DO
    MTTGx(i,j) := df(MTTZ(i,1), xj, 1);
  END;

% Find MTTGu;
matrix MTTGu(MTTNz,MTTNu);
FOR j := 1:MTTNu DO
  BEGIN
  uj := MTTu(j,1);
  FOR i := 1:MTTNz DO
    MTTGu(i,j) := df(MTTZ(i,1), uj, 1);
  END;


OUT "$1_dae.m";
write "function residual = $1_dae(MTTdX0,MTTx,t);";
write "% residuals = $1_dae(dx,x,t);";
write "%DAE in DASSL $1;;";
write "%File $1_dae.m;;";
write "%Generated by MTT;;";


common();
  write "% Set up the non-state derivatives";
  FOR i := 1:MTTNz DO
  BEGIN
    write "MTTdz", i, " = MTTdx0(", MTTNx+ i, ");";
  END;
  

%Fortran switches - one line expressions
OFF echo;
ON fort$
cardno!* := 1$
fortwidth!* := 100$
OFF period$


MTTdx := MTTdx;
MTTGx := MTTGx;

OFF fort;

write "for i=1:", MTTNy, ";;";
write "  residual(i) = MTTdX(i)-MTTdX0(i);";
write "end;";

IF MTTNz>0 THEN
BEGIN
  write "dxz = MTTGx*MTTdx";
  write "for i=1:", MTTNz, ";;";
  write "  residual(i+", MTTNx, ") = dxz(i)-MTTdX0(i+", MTTNx,");";
  write "end;";
END;



SHUT "$1_dae.m";

OFF fort;

% Now do the y = g(x,t) function.
OUT "$1_daeo.m";
  
write "function MTTy = $1_daeo(MTTx,t);";
write "% dX = $1_daeo(MTTx,t);";
write "%DAE in Simulab form for system $1;;";
write "%File $1_daeo.m;;";
write "%Generated by MTT;;";

common();

%Fortran switches - one line expressions
OFF echo;
ON fort$
cardno!* := 1$
fortwidth!* := 100$
OFF period$

MTTy := MTTy;

SHUT "$1_daeo.m";









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