Differences From Artifact [1d787a7f7c]:

To Artifact [44c1c59f19]:


10
11
12
13
14
15
16



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

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



## Revision 1.4  1996/08/18 20:02:21  peter
## Include zero outputs.
##
## Revision 1.3  1996/08/16 13:10:53  peter
## Fixed bug Ny changed to Nx in redidual loop.
##
## Revision 1.2  1996/08/16 08:57:34  peter







>
>
>







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

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
# Revision 1.5  1996/08/24  14:27:29  peter
# Global parameters.
#
## Revision 1.4  1996/08/18 20:02:21  peter
## Include zero outputs.
##
## Revision 1.3  1996/08/16 13:10:53  peter
## Fixed bug Ny changed to Nx in redidual loop.
##
## Revision 1.2  1996/08/16 08:57:34  peter
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
  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:", MTTNx, ";;";
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";








|


>
>
















|


|










|











|
>
>
|




|




|

|







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
  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;
if MTTNz>0 THEN
BEGIN
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;
END;

OUT "$1_dae.m";
write "function residual = $1_dae(mttderiv0,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, " = mttderiv0(", MTTNx+ i, ");";
  END;
  

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


Mttderiv := MTTdX;

IF MTTNz>0 THEN
 MTTGx := MTTGx;

OFF fort;

write "for i=1:", MTTNx, ";;";
write "  residual(i) = mttderiv(i)-mttderiv0(i);";
write "end;";

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



SHUT "$1_dae.m";


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