Overview
Comment:Now includes euler
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | origin/master | trunk
Files: files | file ages | folders
SHA3-256: 9384979d5f7d88a4fd554b8de1f0d42463cb5dab4e1bfc9916584d592d4d88f7
User & Date: gawthrop@users.sourceforge.net on 2000-08-01 12:25:06
Other Links: branch diff | manifest | tags
Context
2000-08-01
12:25:24
Some changes to include files check-in: eb6b4746fe user: gawthrop@users.sourceforge.net tags: origin/master, trunk
12:25:06
Now includes euler check-in: 9384979d5f user: gawthrop@users.sourceforge.net tags: origin/master, trunk
12:11:57
Added %Vars check-in: 7ea36c25e3 user: gawthrop@users.sourceforge.net tags: origin/master, trunk
Changes

Modified mttroot/mtt/bin/trans/make_ode2odes from [8b97c09cfe] to [be1e48d6ab].

1
2
3
4
5
6
7
8
9
10
11



12
13
14
15
16
17
18
#! /bin/sh

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

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



## Revision 1.35  2000/05/18 18:59:40  peterg
## Removed the First time stuff
##
## Revision 1.34  2000/05/16 18:56:14  peterg
## *** empty log message ***
##
## Revision 1.33  2000/05/11 19:33:18  peterg











>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#! /bin/sh

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

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
## Revision 1.36  2000/05/19 17:48:16  peterg
## Argument to state
##
## Revision 1.35  2000/05/18 18:59:40  peterg
## Removed the First time stuff
##
## Revision 1.34  2000/05/16 18:56:14  peterg
## *** empty log message ***
##
## Revision 1.33  2000/05/11 19:33:18  peterg
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
  method=$2    
else
  method=implicit  
fi

echo  "Creating $1_ode2odes.m with $method integration method"






if [ "$method" = "implicit" ]; then
    ode=cse
    odeo=cseo

else
    ode=ode
    odeo=odeo

fi

# Find system constants
Nx=`grep "MTTNx " <$Sys\_def.r | awk '{print $3}' | sed 's/;//'`
Nu=`grep "MTTNu " <$Sys\_def.r | awk '{print $3}' | sed 's/;//'`
Ny=`grep "MTTNy " <$Sys\_def.r | awk '{print $3}' | sed 's/;//'`
 

#cat << EOF > $1_ode2odes.m
# Program $1_ode2odes
#EOF

# Do the globals
#sympar2global_txt2m $1 >> $1_ode2odes.m
lang_header  $1 ode2odes m  'x,par,simpar' '[Y,X,t]' > $1_ode2odes.m







>
>
>
>
>



>



>


<
<
<
<
<
<







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
  method=$2    
else
  method=implicit  
fi

echo  "Creating $1_ode2odes.m with $method integration method"

# Find system constants
Nx=`mtt_getsize $Sys x` # States
Nu=`mtt_getsize $Sys u` # Inputs 
Ny=`mtt_getsize $Sys y` # Inputs  

if [ "$method" = "implicit" ]; then
    ode=cse
    odeo=cseo
    algorithm="mtt_implicit(x,dx,AA,AAx,ddt,$Nx,open_switches)"
else
    ode=ode
    odeo=odeo
    algorithm="mtt_euler(x,dx,ddt,$Nx,open_switches)"
fi







#cat << EOF > $1_ode2odes.m
# Program $1_ode2odes
#EOF

# Do the globals
#sympar2global_txt2m $1 >> $1_ode2odes.m
lang_header  $1 ode2odes m  'x,par,simpar' '[Y,X,t]' > $1_ode2odes.m
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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
  if nargin<1
    [x]  =  $1_state(par); 
    [x] = mtt_state_update(x);
  endif

  ## Initialise
  t = 0.0;

  ilast = round(simpar.last/simpar.dt)+1; # Total number of steps


  [u]  = zero_input(1);		# Zero the input

  for it = 1:ilast		#Integration loop
    [y] = $1_cseo(x,u,t,par);# Output 
    [u] = $1_input(t,x,y);	# Input

    mtt_write(t,x,y,$Nx,$Ny);   # Write it out

    [dx] = $1_cse(x,u,t,par);	# State derivative





    [AA] = $1_smxa(x,u,simpar.dt,par);	# (I-Adt) and (I-Adt)x
    [AAx] = $1_smxax(x,u,simpar.dt,par); # (I-Adt) and (I-Adt)x





    [open_switches] = $1_switchopen(x);	# Open switches



    [x] = mtt_implicit(x,dx,AA,AAx,simpar.dt,$Nx,open_switches); # Implicit update


    t = t + simpar.dt;
  endfor;			# Integration loop

  t = MTT_data(:,1);
  Y = MTT_data(:,2);
  X  = MTT_data(:,4);

endfunction

EOF

exit

### old stuff follows
if [ "$method" = "euler" ]; then
cat << EOF >> $1_ode2odes.m
MTTddt = mttdt/mttstepfactor; # The small sample interval
EOF
fi


cat << EOF >> $1_ode2odes.m
for MTTit = 1:MTTilast		#Integration loop
  [MTTy] = $1_$odeo(MTTx,MTTu,MTTt,MTTpar);     # Output 
  [MTTu] = $1_input(MTTt,MTTx,MTTy);	# Input
  mtt_write(MTTt,MTTx,MTTy,$Nx,$Ny);    # Write it out

  if $Nx>0			# Dont if no states
EOF

if [ "$method" = "euler" ]; then
cat << EOF >> $1_ode2odes.m
#    if mttmethod==1		# Euler
      for MTTjt = 1:mttstepfactor
	[MTTdx] = $1_$ode(MTTx,MTTu,MTTt,MTTpar); # State derivative
        [MTTopen] = $1_switchopen(MTTx);        # Open switches
	[MTTx] = mtt_euler(MTTx,MTTdx,MTTddt,$Nx,MTTopen); # Euler update
	MTTt = MTTt + MTTddt;
      endfor;
#    endif;
EOF
fi

if [ "$method" = "implicit" ]; then
cat << EOF >> $1_ode2odes.m
#    if mttmethod==2		# Implicit 
      [MTTdx] = $1_cse(MTTx,MTTu,MTTt,MTTpar); # State derivative
      [mttAA] = $1_smxa(MTTx,MTTu,mttdt,MTTpar);	# (I-Adt) and (I-Adt)x
      [mttAAx] = $1_smxax(MTTx,MTTu,mttdt,MTTpar);	# (I-Adt) and (I-Adt)x
      [MTTopen] = $1_switchopen(MTTx);        # Open switches
      [MTTx] = mtt_implicit(MTTx,MTTdx,mttAA,mttAAx,mttdt,$Nx,MTTopen); # Implicit update
      MTTt = MTTt + mttdt;
#    endif;
EOF
fi

cat << EOF >> $1_ode2odes.m
    else # NX is 0 - no states
      MTTt = MTTt + mttdt;
  endif;			# $Nx>0

endfor;				# Integration loop

EOF











>
|

>
|
|
|
|

>
|
>
|
>
>
>
>
>
|
|
>
>
>
>
>

>
>
>
|
>
>
|















|



















|
|








|



|













<
<
<
<
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
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
261
262
263
264
265
266
267
268
269
270
271




  if nargin<1
    [x]  =  $1_state(par); 
    [x] = mtt_state_update(x);
  endif

  ## Initialise
  t = 0.0;
  ddt = simpar.dt/simpar.stepfactor;
  ilast = round(simpar.last/ddt)+1; # Total number of steps

## Following remove due to p2c bug
##  [u]  = zero_input(1);		# Zero the input
  mttj = 0;
    for it = 1:ilast		#Integration loop
    [y] = $1_$odeo(x,u,t,par);# Output 
    [u] = $1_input(t,x,y);	# Input
    if mttj==0
     mtt_write(t,x,y,$Nx,$Ny);   # Write it out
    endif
    [dx] = $1_$ode(x,u,t,par);	# State derivative
EOF

if [ "$method" = "implicit" ]; then
cat<<EOF >> $1_ode2odes.m

    [AA] = $1_smxa(x,u,ddt,par);	# (I-Adt) and (I-Adt)x
    [AAx] = $1_smxax(x,u,ddt,par); # (I-Adt) and (I-Adt)x

EOF
fi

cat <<EOF >> $1_ode2odes.m
    [open_switches] = $1_switchopen(x);	# Open switches
    [x] = $algorithm; # Integration update
    t = t + ddt;   # Time update
    mttj = mttj+1;    # Increment counter
    if mttj==simpar.stepfactor
       mttj = 0;      # Reset counter
    endif

  endfor;			# Integration loop

  t = MTT_data(:,1);
  Y = MTT_data(:,2);
  X  = MTT_data(:,4);

endfunction

EOF

exit

### old stuff follows
if [ "$method" = "euler" ]; then
cat << EOF >> $1_ode2odes.m
ddt = mttdt/mttstepfactor; # The small sample interval
EOF
fi


cat << EOF >> $1_ode2odes.m
for MTTit = 1:MTTilast		#Integration loop
  [MTTy] = $1_$odeo(MTTx,MTTu,MTTt,MTTpar);     # Output 
  [MTTu] = $1_input(MTTt,MTTx,MTTy);	# Input
  mtt_write(MTTt,MTTx,MTTy,$Nx,$Ny);    # Write it out

  if $Nx>0			# Dont if no states
EOF

if [ "$method" = "euler" ]; then
cat << EOF >> $1_ode2odes.m
#    if mttmethod==1		# Euler
      for MTTjt = 1:mttstepfactor
	[MTTdx] = $1_$ode(MTTx,MTTu,MTTt,MTTpar); # State derivative
        [MTTopen] = $1_switchopen(MTTx);        # Open switches
	    [MTTx] = mtt_euler(MTTx,MTTdx,ddt,$Nx,MTTopen); # Euler update
	MTTt = MTTt + ddt;
      endfor;
#    endif;
EOF
fi

if [ "$method" = "implicit" ]; then
cat << EOF >> $1_ode2odes.m
#    if mttmethod==2		# Implicit 
      [MTTdx] = $1_$ode(MTTx,MTTu,MTTt,MTTpar); # State derivative
      [mttAA] = $1_smxa(MTTx,MTTu,mttdt,MTTpar);	# (I-Adt) and (I-Adt)x
      [mttAAx] = $1_smxax(MTTx,MTTu,mttdt,MTTpar);	# (I-Adt) and (I-Adt)x
      [MTTopen] = $1_switchopen(MTTx);        # Open switches
      [MTTx] = $algorithm(MTTx,MTTdx,mttAA,mttAAx,mttdt,$Nx,MTTopen); # Implicit update
      MTTt = MTTt + mttdt;
#    endif;
EOF
fi

cat << EOF >> $1_ode2odes.m
    else # NX is 0 - no states
      MTTt = MTTt + mttdt;
  endif;			# $Nx>0

endfor;				# Integration loop

EOF





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