Overview
Comment:Includes the sympar.h file
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | origin/master | trunk
Files: files | file ages | folders
SHA3-256: 0f6bed5ddbd04a86d5a3bf9922f3f4590daf42cecb2dce38e01f29d12ba14af0
User & Date: gawthrop@users.sourceforge.net on 1997-03-20 14:36:56
Other Links: branch diff | manifest | tags
Context
1997-03-20
14:51:11
Includes the sympar.c file. check-in: eca91ad38b user: gawthrop@users.sourceforge.net tags: origin/master, trunk
14:36:56
Includes the sympar.h file check-in: 0f6bed5ddb user: gawthrop@users.sourceforge.net tags: origin/master, trunk
12:05:31
Now just writes out the cr name. check-in: 55bdf75941 user: gawthrop@users.sourceforge.net tags: origin/master, trunk
Changes

Modified mttroot/mtt/bin/trans/ode2odes_r2c from [3ca0bda72c] to [0070fc8449].

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

193
194

195

196
197
198
199
200
201

202
203
204
205
206






-
+















+
+
+




-
+





-
+

















-
+






-
+







+

-
-
-
-
-


-
-
-
-
+
+
+
+













-
+



-
-
+
+





-
-
-
-
-


-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
-
+
+



-
+


-
+

-
+
+












+
+



+
+
+
-
+
+
+

+
+
+



+


+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+


+
+
-
+


+
+
+


+
+
+
+
+
-
+

-
-
+
+

+
+
+
+
+
-
+

-

-
+
+




-
+




#! /bin/sh

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

# Bourne shell script: ode2odesol_r2c
# Bourne shell script: ode2odes_r2c
# Reduce ordinary differential equations to  differential-algebraic 
# equations solution in the form of a c program.

# Euler integration of the state is included.

# NB Arrays should are  defined to be one larger than expected 
# - the 0 element is not used.

# Copyright (c) P.J.Gawthrop 1997.

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
## Revision 1.1  1997/01/21 22:54:54  peterg
## Initial revision
##
###############################################################


# Inform user
echo Creating $1_odesol.c
echo Creating $1_odes.c

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

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

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

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

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

ON BigFloat, NumVal;
PRECISION 16; %Compatible with Matlab
%OFF Nat;

ON NERO;        % Suppress zero elements

%Generate the Header part
OUT "$1_odesol.c";
OUT "$1_odes.c";

write "/*"$
write "Program to solve ode for system $1"$
write "NB Arrays are defined to be one larger than expected"$
write " - the 0 element is not used."$

write "File $1_odesol.c"$
write "File $1_odes.c"$
write "Generated by MTT"$
write "*/"$
write " "$


%Program heading
write "#include <stdio.h>"$
write "#include ""$1_sympar.h"" "$

%Set up some variables - need to do this better sometime
write "/* Set up some variables - need to do this better sometime */"$
write "#define DT 0.1 /* Time step (for printing) */"$
write "#define LAST 10.0 /* Last time */"$
write "#define STEPFACTOR 1000 /* Integration steps per time step */"$

write "/* Declare standard arrays */"$
write "float y[", MTTNy+1, "]; /* $1_ode output */"$
write "float dx[", MTTNx+1, "]; /* $1_ode state derivative */"$ 
write "float x[", MTTNx+1, "]; /* $1_ode state */"$ 
write "float u[", MTTNu+1, "]; /* $1_ode input */"$
write "double y[", MTTNy+1, "]; /* $1_ode output */"$
write "double dx[", MTTNx+1, "]; /* $1_ode state derivative */"$ 
write "double x[", MTTNx+1, "]; /* $1_ode state */"$ 
write "double u[", MTTNu+1, "]; /* $1_ode input */"$

%External (global) variable list
write "/* External (global) variable list */ "$
IF MTTNvar>0 THEN
BEGIN
  FOR i := 1:MTTNvar DO
    IF numberp(MTTVar(i,1)) 
      THEN 
      BEGIN
      % Do nowt
      END
      ELSE
      BEGIN
         write "float ", MTTVar(i,1), ";"$
         write "double ", MTTVar(i,1), ";"$
      END$
END$

write "/* File */ "$
write "  FILE *fopen(), *fp;"$
write "/* Files */ "$
write "  FILE *fopen(), *fps, *fpso;"$

write "main()"$
write "  "$
write "{"$

write "/* Declare standard arrays */"$
write "  extern float y[", MTTNy+1, "]; /* $1_ode output */"$
write "  extern float dx[", MTTNx+1, "]; /* $1_ode state derivative */"$ 
write "  extern float x[", MTTNx+1, "]; /* $1_ode state */"$ 
write "  extern float u[", MTTNu+1, "]; /* $1_ode input */"$


%External (global) variable list
write "/* External (global) variable list */ "$
IF MTTNvar>0 THEN
BEGIN
  FOR i := 1:MTTNvar DO
    IF numberp(MTTVar(i,1)) 
      THEN 
      BEGIN
      % Do nowt
      END
      ELSE
      BEGIN
         write "  extern float ", MTTVar(i,1), ";"$
      END$
END$



write "/* Counters etc*/ "$
write "  float time;"$
write "  float dt;"$
write "  double time;"$
write "  double dt;"$
write "  int i;"$
write "  int k;"$

write "/* functions */ "$
write "/*functions */ "$
write "  extern  $1_numpar();"$

%Open the output file
%Open the output files
write "/* %Open the output file */"$
write "fp = fopen(""$1_odes.m"", ""w"");  "$
write "fps = fopen(""$1_odes.m"", ""w"");  "$
write "fpso = fopen(""$1_odeso.m"", ""w"");  "$

%Set up user-defined constants
write "/* Set up user-defined constants */"$
write "  $1_numpar();"$

%Initialise main (Euler) integration loop
write "/* Initialise main (Euler) integration loop */"$
write "  time = 0;"$
write "  dt = DT/STEPFACTOR;"$
write "  for (i=1; i<=", MTTNx, "; i++)"$
write "      x[i] = 0.0;"$

%Set up system inputs
write "/* Set up system inputs */"$
write "  for (i=1; i<=", MTTNu, "; i++)"$
write "      u[i] = 1.0;"$

write "  $1_input(0.0);"$

write "    fprintf(fps, ""function data = ", "$1_odes \n"");"$
write "    fprintf(fp, ""data = [\n"");"$
write "    fprintf(fps, ""data = [\n"");"$
write "    fprintf(fpso, ""function data = ", "$1_odeso \n"");"$
write "    fprintf(fpso, ""data = [\n"");"$

% Compute the first output
write "/* Compute the first output */"$
write "  $1_ode(y,dx,x,u);"$

%Main (Euler) integration loop
write "/* Main (Euler) integration loop */"$

write "  while (time<LAST)"$
write "  {"$

%Write to output to file
write "/* Write to output file */"$
write "    fprintf(fpso, ""%5.4f "",time);"$
write "    for (i=1; i<=", MTTNy, "; i++)"$
write "      fprintf(fpso, ""%5.4f "", y[i]);"$
write "    fprintf(fpso, ""\n"");"$

%Write to state to file
write "/* Write to state file */"$
write "    fprintf(fps, ""%5.4f "",time);"$
write "    for (i=1; i<=", MTTNx, "; i++)"$
write "      fprintf(fps, ""%5.4f "", x[i]);"$
write "    fprintf(fps, ""\n"");"$

% Inner integration loop
write "/* Inner integration loop */"$
write "    for (k=1; k<=STEPFACTOR; k++)"$
write "    {"$
%Set up system inputs
write "      /* Set up system inputs */"$
write "      $1_ode(y,dx,x,u);"$
write "      $1_input(time);"$
write "      for (i=1; i<=", MTTNx, "; i++)"$
write "        x[i] = x[i] + dx[i]*dt;"$
write "      $1_ode();"$
write "      time = time + dt;"$

write "    }"$

write "  }"$

%Write to files
%Write to output to file
write "/* Write to output file */"$
write "    fprintf(fp, ""%5.4f "",time);"$
write "    fprintf(fpso, ""%5.4f "",time);"$
write "    for (i=1; i<=", MTTNy, "; i++)"$
write "      fprintf(fp, ""%5.4f "", y[i]);"$
write "    fprintf(fp, ""\n"");"$
write "      fprintf(fpso, ""%5.4f "", y[i]);"$
write "    fprintf(fpso, ""\n"");"$

%Write to state to file
write "/* Write to state file */"$
write "    fprintf(fps, ""%5.4f "",time);"$
write "    for (i=1; i<=", MTTNx, "; i++)"$
write "      fprintf(fps, ""%5.4f "", x[i]);"$
write "    time = time + DT;"$
write "    fprintf(fps, ""\n"");"$

write "  }"$

write "    fprintf(fp, ""];\n"");"$
write "  fprintf(fps, ""];\n"");"$
write "  fprintf(fpso, ""];\n"");"$

write "}"$


SHUT "$1_odesol.c";
SHUT "$1_odes.c";


EOF


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