Overview
Comment:Branch merge: numerical-algebraic-solution back to main.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | origin/master | trunk
Files: files | file ages | folders
SHA3-256: 1a563890dc6f6fa93387740ed7cfda05638e789abef6022daa3bd3d2ad097a1b
User & Date: geraint@users.sourceforge.net on 2001-07-13 04:54:06
Other Links: branch diff | manifest | tags
Context
2001-07-16
22:23:00
Fixed misleading variable name in .cc rep. check-in: fb1bac6240 user: geraint@users.sourceforge.net tags: origin/master, trunk
2001-07-13
04:54:06
Branch merge: numerical-algebraic-solution back to main. check-in: 1a563890dc user: geraint@users.sourceforge.net tags: origin/master, trunk
04:19:03
Now loads _subs.r with _cr.r file when using -cr option check-in: d3d4ae7245 user: gawthrop@users.sourceforge.net tags: origin/master, trunk
Changes

Modified mttroot/mtt/bin/mtt from [6369d2b780] to [652b7bd578].

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
# Copyright (C) 2001 by Peter J. Gawthrop

###############################################################
## Version control history
###############################################################
## $Header$
## $Log$



## Revision 1.313  2001/06/13 14:53:59  gawthrop
## MTT now gas the double-colon option in the abg.fig file
## eg R:r:a^2+3*b
##
## Revision 1.312  2001/06/11 19:43:49  gawthrop
## MTT is now much more sophisticated in generating lbl files
## Labels can contain maths
## Repetative components are now broken
##
## Revision 1.311  2001/05/26 18:36:43  gawthrop
## Further modifications. Now works on rcPPP
##  -- next jobs:
##     add identification to ppp_nlin_sim
##     create real-time ppp_nlin_run
##
## Revision 1.310  2001/05/08 08:30:12  gawthrop
## Added line to reverse the x^y --> pow(x,y) in default  _simp file to
## prettyfy LaTeX
##











## Revision 1.309  2001/04/28 03:15:03  geraint
## Fixed comment (interfered with "mtt help representations").
##
## Revision 1.308  2001/04/25 22:17:45  geraint
## Fixed icd.txt2 dependency.
##
## Revision 1.307  2001/04/15 21:15:41  geraint







>
>
>



















>
>
>
>
>
>
>
>
>
>
>







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
# Copyright (C) 2001 by Peter J. Gawthrop

###############################################################
## Version control history
###############################################################
## $Header$
## $Log$
## Revision 1.314  2001/07/13 04:19:03  gawthrop
## Now loads _subs.r with _cr.r file when using -cr option
##
## Revision 1.313  2001/06/13 14:53:59  gawthrop
## MTT now gas the double-colon option in the abg.fig file
## eg R:r:a^2+3*b
##
## Revision 1.312  2001/06/11 19:43:49  gawthrop
## MTT is now much more sophisticated in generating lbl files
## Labels can contain maths
## Repetative components are now broken
##
## Revision 1.311  2001/05/26 18:36:43  gawthrop
## Further modifications. Now works on rcPPP
##  -- next jobs:
##     add identification to ppp_nlin_sim
##     create real-time ppp_nlin_run
##
## Revision 1.310  2001/05/08 08:30:12  gawthrop
## Added line to reverse the x^y --> pow(x,y) in default  _simp file to
## prettyfy LaTeX
##
## Revision 1.309.2.3  2001/07/13 04:02:31  geraint
## Implemented numerical algebraic solution for _ode2odes.oct.
##
## Revision 1.309.2.2  2001/06/05 03:20:39  geraint
## added -ae option to select algebraic equation solution method.
##
## Revision 1.309.2.1  2001/05/04 04:07:24  geraint
## Numerical solution of algebraic equations.
## sys_ae.cc written for unsolved inputs.
## Solution of equations using hybrd from MINPACK (as used by Octave fsolve).
##
## Revision 1.309  2001/04/28 03:15:03  geraint
## Fixed comment (interfered with "mtt help representations").
##
## Revision 1.308  2001/04/25 22:17:45  geraint
## Fixed icd.txt2 dependency.
##
## Revision 1.307  2001/04/15 21:15:41  geraint
1106
1107
1108
1109
1110
1111
1112



1113
1114
1115
1116
1117
1118
1119

# Default not verbose
verbose=' -s'

# Default integration method
integration_method=implicit;




# Default no info
info_switch=''

# Default use m, not oct files
m='m';

# Default use ps files







>
>
>







1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136

# Default not verbose
verbose=' -s'

# Default integration method
integration_method=implicit;

# Default algebraic equation solver
algebraic_solver=Reduce_Solver;

# Default no info
info_switch=''

# Default use m, not oct files
m='m';

# Default use ps files
1174
1175
1176
1177
1178
1179
1180























1181
1182
1183
1184
1185
1186
1187
			integration_method=rk4;
			mtt_switches="$mtt_switches rk4";
			;;
		    *)
			echo $1 is an unknown integration method - use euler, rk4 or implicit;
                        exit;;
		esac;;























	-s )
                sensitivity_switch='-s';
                mtt_switches="$mtt_switches $1";
		sensitivity=sensitivity ;;
	-ss )
                mtt_switches="$mtt_switches $1";
		steadystate_computation=yes ;;







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
			integration_method=rk4;
			mtt_switches="$mtt_switches rk4";
			;;
		    *)
			echo $1 is an unknown integration method - use euler, rk4 or implicit;
                        exit;;
		esac;;
	-ae )
                mtt_switches="$mtt_switches $1";
		case $2 in
		    fsolve | hybrd)
			mtt_switches="$mtt_switches $2";
			algebraic_solver=Hybrd_Solver;
			shift;
			;;
		    hooke)
			mtt_switches="$mtt_switches $2";
			algebraic_solver=HJ_Solver;
			shift;
			;;
		    reduce)
			mtt_switches="$mtt_switches $2";
			algebraic_solver=Reduce_Solver;			
			Solve='-A';
			shift;
			;;
		    *)
			echo $1 is an unknown solver - use hybrd, hooke or reduce;
			exit;;
	        esac;;
	-s )
                sensitivity_switch='-s';
                mtt_switches="$mtt_switches $1";
		sensitivity=sensitivity ;;
	-ss )
                mtt_switches="$mtt_switches $1";
		steadystate_computation=yes ;;
1312
1313
1314
1315
1316
1317
1318

1319
1320
1321
1322
1323
1324
1325
    echo '         -abg start at abg.m representation'
    echo '         -c  c-code generation'
    echo '         -cr Use cr before resolving equations'
    echo '         -d  <dir>  use directory <dir>'
    echo '         -dc Maximise derivative (not integral) causality'
    echo '         -dc Maximise derivative (not integral) causality'
    echo '         -i <implicit|euler|rk4>   Use implicit, euler or rk4 integration'

    echo '         -o ode is same as dae'
    echo '         -oct use oct files in place of m files where appropriate'
    echo '         -opt optimise code generation'
    echo '         -p  print environment variables'
    echo '         -partition partition hierachical system'
    echo '         -pdf generate pdf in place of ps'
    echo '         -r  reset time stamp on representation'







>







1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
    echo '         -abg start at abg.m representation'
    echo '         -c  c-code generation'
    echo '         -cr Use cr before resolving equations'
    echo '         -d  <dir>  use directory <dir>'
    echo '         -dc Maximise derivative (not integral) causality'
    echo '         -dc Maximise derivative (not integral) causality'
    echo '         -i <implicit|euler|rk4>   Use implicit, euler or rk4 integration'
    echo '         -ae <reduce|hybrd|hooke>   Solve algebraic equations with Reduce, hybrd (fsolve) or "Hooke and Jeeves"'
    echo '         -o ode is same as dae'
    echo '         -oct use oct files in place of m files where appropriate'
    echo '         -opt optimise code generation'
    echo '         -p  print environment variables'
    echo '         -partition partition hierachical system'
    echo '         -pdf generate pdf in place of ps'
    echo '         -r  reset time stamp on representation'
1454
1455
1456
1457
1458
1459
1460

1461
1462
1463
1464
1465
1466
1467
  rm -f *_csex.cc *_numpar.cc *_smxa.cc *_state.cc 
  rm -f *_ode.cc *_odeo.cc
  rm -f *_logic.m *_logic.cc *_logic.oct
  rm -f *_state.m *_state.cc *_state.oct
  rm -f *_ode2odes.* *.dat2 MTT.core
  rm -f *_modpar.txt *_modpar.r
  rm -f *_ICD.txt *_ICD.c *_ICD.cc *_ICD.m

  rm -fR *_rep MTT_work
  exit
fi

# Clean up named system
if [ "$2" = "Clean" ] && [ "$3" = "" ]; then
  echo 'Removing all generated files for system ' $1







>







1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
  rm -f *_csex.cc *_numpar.cc *_smxa.cc *_state.cc 
  rm -f *_ode.cc *_odeo.cc
  rm -f *_logic.m *_logic.cc *_logic.oct
  rm -f *_state.m *_state.cc *_state.oct
  rm -f *_ode2odes.* *.dat2 MTT.core
  rm -f *_modpar.txt *_modpar.r
  rm -f *_ICD.txt *_ICD.c *_ICD.cc *_ICD.m
  rm -f *_ae.r *_ae.m *_ae.cc *_ae.oct
  rm -fR *_rep MTT_work
  exit
fi

# Clean up named system
if [ "$2" = "Clean" ] && [ "$3" = "" ]; then
  echo 'Removing all generated files for system ' $1
1490
1491
1492
1493
1494
1495
1496

1497
1498
1499
1500
1501
1502
1503
  rm -f $1_csex.cc $1_numpar.cc $1_smxa.cc $1_state.cc 
  rm -f $1_ode.cc $1_odeo.cc
  rm -f $1_logic.m $1_logic.cc $1_logic.oct 
  rm -f $1_state.m $1_state.cc $1_state.oct
  rm -f $1_ode2odes.* $1.dat2
  rm -f $1_modpar.txt $1_modpar.r
  rm -f $1_ICD.txt $1_ICD.c $1_ICD.cc $1_ICD.m

  rm -fR $1_rep MTT_work
  exit
fi

if [ "$2" = "rep" ]; then
     documenttype=article
      # See if we are making a book -- ie representation rep on a directory







>







1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
  rm -f $1_csex.cc $1_numpar.cc $1_smxa.cc $1_state.cc 
  rm -f $1_ode.cc $1_odeo.cc
  rm -f $1_logic.m $1_logic.cc $1_logic.oct 
  rm -f $1_state.m $1_state.cc $1_state.oct
  rm -f $1_ode2odes.* $1.dat2
  rm -f $1_modpar.txt $1_modpar.r
  rm -f $1_ICD.txt $1_ICD.c $1_ICD.cc $1_ICD.m
  rm -f $1_ae.r $1_ae.m $1_ae.cc $1_ae.oct
  rm -fR $1_rep MTT_work
  exit
fi

if [ "$2" = "rep" ]; then
     documenttype=article
      # See if we are making a book -- ie representation rep on a directory
1947
1948
1949
1950
1951
1952
1953



1954
1955
1956
1957
1958
1959
1960
.PRECIOUS: %.cc # Don't let mtt delete them
$1_%.cc:  $1_%.m
	mtt_m2cc.sh  $1 \$* cat 

mtt_%.cc: ${MTT_LIB}/cc/mtt_%.cc
	cp ${MTT_LIB}/cc/mtt_\$*.cc mtt_\$*.cc




## .o files
.PRECIOUS: $1_%.o
$1_%.o: $1_%.cc $1_def.h $1_sympar.h $1_cr.h
	echo Compiling $1_\$*.cc
	${MTT_CXX} ${MTT_CXXFLAGS} ${MTT_CXXINCS} -c $< -DSTANDALONE

.PRECIOUS: mtt_%.o







>
>
>







1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
.PRECIOUS: %.cc # Don't let mtt delete them
$1_%.cc:  $1_%.m
	mtt_m2cc.sh  $1 \$* cat 

mtt_%.cc: ${MTT_LIB}/cc/mtt_%.cc
	cp ${MTT_LIB}/cc/mtt_\$*.cc mtt_\$*.cc

mtt_%.hh: ${MTT_LIB}/cc/mtt_%.hh
	cp ${MTT_LIB}/cc/mtt_\$*.hh mtt_\$*.hh

## .o files
.PRECIOUS: $1_%.o
$1_%.o: $1_%.cc $1_def.h $1_sympar.h $1_cr.h
	echo Compiling $1_\$*.cc
	${MTT_CXX} ${MTT_CXXFLAGS} ${MTT_CXXINCS} -c $< -DSTANDALONE

.PRECIOUS: mtt_%.o
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
else
	mtt_update $1 logic
endif

# Dummy target
FORCE:

$1_ode2odes_common.m    : $1_input.m   $1_logic.m   $1_numpar.m   $1_simpar.m   $1_state.m
	@echo > /dev/null
$1_ode2odes_common.cc   : $1_input.cc  $1_logic.cc  $1_numpar.cc  $1_simpar.cc  $1_state.cc
	@echo > /dev/null
$1_ode2odes_common.o    : $1_input.o   $1_logic.o   $1_numpar.o   $1_simpar.o   $1_state.o
	@echo "Creating $1_ode2odes_common.o"
	ar -cr \$@ \$^
$1_ode2odes_common.oct  : $1_input.oct $1_logic.oct $1_numpar.oct $1_simpar.oct $1_state.oct
	@echo > /dev/null

$1_ode2odes_euler.m  $1_ode2odes_rk4.m    : $1_ode.m     $1_odeo.m
	@echo > /dev/null
$1_ode2odes_euler.cc $1_ode2odes_rk4.cc   : $1_ode.cc    $1_odeo.cc
	@echo > /dev/null
$1_ode2odes_euler.o  $1_ode2odes_rk4.o    : $1_ode.o     $1_odeo.o   mtt_euler.o







|

|

|


|







2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
else
	mtt_update $1 logic
endif

# Dummy target
FORCE:

$1_ode2odes_common.m    : $1_ae.m   $1_input.m   $1_logic.m   $1_numpar.m   $1_simpar.m   $1_state.m
	@echo > /dev/null
$1_ode2odes_common.cc   : $1_ae.cc  $1_input.cc  $1_logic.cc  $1_numpar.cc  $1_simpar.cc  $1_state.cc
	@echo > /dev/null
$1_ode2odes_common.o    : $1_ae.o   $1_input.o   $1_logic.o   $1_numpar.o   $1_simpar.o   $1_state.o
	@echo "Creating $1_ode2odes_common.o"
	ar -cr \$@ \$^
$1_ode2odes_common.oct  : $1_ae.oct $1_input.oct $1_logic.oct $1_numpar.oct $1_simpar.oct $1_state.oct
	@echo > /dev/null

$1_ode2odes_euler.m  $1_ode2odes_rk4.m    : $1_ode.m     $1_odeo.m
	@echo > /dev/null
$1_ode2odes_euler.cc $1_ode2odes_rk4.cc   : $1_ode.cc    $1_odeo.cc
	@echo > /dev/null
$1_ode2odes_euler.o  $1_ode2odes_rk4.o    : $1_ode.o     $1_odeo.o   mtt_euler.o
2250
2251
2252
2253
2254
2255
2256





2257
2258
2259
2260
2261
2262
2263
	@echo > /dev/null
$1_ode2odes_implicit.o  : $1_cseo.o    $1_csex.o   $1_smxa.o   $1_smxax.o   mtt_implicit.o
	@echo "Creating $1_ode2odes_implicit.o"
	ar -cr \$@ \$^
$1_ode2odes_implicit.oct: $1_cseo.oct  $1_csex.oct $1_smxa.oct $1_smxax.oct mtt_implicit.oct
	@echo > /dev/null







#SUMMARY numpar	numerical parameter declaration (m) 
$1_numpar.m:  $1_numpar.txt $1_sympars.txt
	mtt_txt2m $1 numpar

#SUMMARY numpar	numerical parameter declaration (c) 
#SUMMARY numpar	numerical parameter declaration (view) 







>
>
>
>
>







2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
	@echo > /dev/null
$1_ode2odes_implicit.o  : $1_cseo.o    $1_csex.o   $1_smxa.o   $1_smxax.o   mtt_implicit.o
	@echo "Creating $1_ode2odes_implicit.o"
	ar -cr \$@ \$^
$1_ode2odes_implicit.oct: $1_cseo.oct  $1_csex.oct $1_smxa.oct $1_smxax.oct mtt_implicit.oct
	@echo > /dev/null

mtt_Solver.cc:	mtt_Solver.hh
$1_ode2odes_${algebraic_solver}.cc:	mtt_Solver.cc mtt_${algebraic_solver}.hh mtt_${algebraic_solver}.cc
$1_ode2odes_${algebraic_solver}.o:	mtt_Solver.o mtt_${algebraic_solver}.o
	@echo "Creating $1_ode2odes_${algebraic_solver}.o"
	ar -cr \$@ \$^

#SUMMARY numpar	numerical parameter declaration (m) 
$1_numpar.m:  $1_numpar.txt $1_sympars.txt
	mtt_txt2m $1 numpar

#SUMMARY numpar	numerical parameter declaration (c) 
#SUMMARY numpar	numerical parameter declaration (view) 
2433
2434
2435
2436
2437
2438
2439









2440
2441
2442
2443
2444
2445
2446

$1_dae.m: $1_def.r $1_dae.r  $1_sympars.txt
	dae_r2m $1; matlab_tidy $1_dae.m; matlab_tidy $1_daeo.m
$1_dae.c: $1_def.r $1_dae.r  $1_sympar.r
	dae_r2c $1; c_tidy $1_dae.c
$1_dae.tex: $1_dae.r $1_simp.r
	dae_r2tex $partition $1; latex_tidy $1_dae.tex










#SUMMARY cse	constrained-state equations (r)
#SUMMARY cse*	constrained-state equations (m)
#SUMMARY cse*	constrained-state equations (oct)
#SUMMARY cse	constrained-state equations (tex)
#SUMMARY cse*	constrained-state equations (view)
#SUMMARY cse	constrained-state equations (ps)







>
>
>
>
>
>
>
>
>







2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506

$1_dae.m: $1_def.r $1_dae.r  $1_sympars.txt
	dae_r2m $1; matlab_tidy $1_dae.m; matlab_tidy $1_daeo.m
$1_dae.c: $1_def.r $1_dae.r  $1_sympar.r
	dae_r2c $1; c_tidy $1_dae.c
$1_dae.tex: $1_dae.r $1_simp.r
	dae_r2tex $partition $1; latex_tidy $1_dae.tex

#SUMMARY ae	algebraic equations - unknown inputs (r)
#SUMMARY ae	algebraic equations - unknown inputs (m)
#SUMMARY ae	algebraic equations - unknown inputs (cc)

$1_ae.r: $1_cse.r
	touch $1_ae.r
$1_ae.m: $1_ae.r
	mtt_r2m $1 ae

#SUMMARY cse	constrained-state equations (r)
#SUMMARY cse*	constrained-state equations (m)
#SUMMARY cse*	constrained-state equations (oct)
#SUMMARY cse	constrained-state equations (tex)
#SUMMARY cse*	constrained-state equations (view)
#SUMMARY cse	constrained-state equations (ps)
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
                $1_smxa.m $1_smxax.m\
                $1_simpar.m $1_numpar.m $1_state.m $1_input.m \
                $1_csex.m $1_cseo.m  $1_logic.m
ifeq ($using_oct,yes)
	touch $1_ode2odes.m # Create a dummy which wont' be used
	mtt $mtt_switches -q -u $1 ode2odes oct
else
	make_ode2odes $1 m $integration_method
endif
endif
ifneq ($integration_method,implicit)
$1_ode2odes.m : $1_def.r $1_sympars.txt\
		$1_simpar.m $1_numpar.m $1_state.m $1_input.m \
		$1_ode.m $1_odeo.m  $1_logic.m
ifeq ($using_oct,yes)
	echo "*** Warning: Shouldn't be here! Creating dummy $1_ode2odes.m"
	touch $1_ode2odes.m # Create a dummy which wont' be used
	mtt $mtt_switches -q -u $1 ode2odes oct
else
	make_ode2odes $1 m $integration_method
endif

endif

#SUMMARY ode2odes Simulation function (m)
#SUMMARY ode2odes Simulation function (cc)
#SUMMARY ode2odes Simulation function (oct)
#SUMMARY ode2odes Simulation function (exe)
$1_ode2odes.exe: $1_def.h $1_sympar.h\
		 $1_ode2odes.o $1_ode2odes_common.o $1_ode2odes_${integration_method}.o
	echo Creating $1_ode2odes.exe
	${MTT_CXX} ${MTT_CXXFLAGS} -o $1_ode2odes.exe\
	$1_ode2odes.o $1_ode2odes_common.o $1_ode2odes_${integration_method}.o\
	${MTT_LDFLAGS} ${MTT_CXXLIBS}

$1_ode2odes.o: $1_ode2odes.cc $1_ode2odes_common.o $1_ode2odes_${integration_method}.o
	echo Creating $1_ode2odes.o
	${MTT_CXX} ${MTT_CXXFLAGS} ${MTT_CXXINCS} -c $1_ode2odes.cc -DSTANDALONE

$1_ode2odes.oct: $1_ode2odes.cc $1_ode2odes_common.oct $1_ode2odes_${integration_method}.oct
	touch $1_ode2odes.m
	echo Creating $1_ode2odes.oct
	$MKOCTFILE $1_ode2odes.cc

$1_ode2odes.cc: $1_def.r $1_sympars.txt\
		$1_ode2odes_common.m $1_ode2odes_common.cc\
		$1_ode2odes_${integration_method}.m $1_ode2odes_${integration_method}.cc
	touch $1_ode2odes.m
	make_ode2odes $1 cc $integration_method

#Conversion of m to p to c
#SUMMARY ode	ordinary differential equations (c)
#SUMMARY ode	ordinary differential equations (p)
#SUMMARY state	state declaration (c) 
#SUMMARY state	state declaration (p) 
$1_simpar.p : $1_def.r $1_simpar.m







|











|









|


|


|



|


|



|

|







2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
                $1_smxa.m $1_smxax.m\
                $1_simpar.m $1_numpar.m $1_state.m $1_input.m \
                $1_csex.m $1_cseo.m  $1_logic.m
ifeq ($using_oct,yes)
	touch $1_ode2odes.m # Create a dummy which wont' be used
	mtt $mtt_switches -q -u $1 ode2odes oct
else
	make_ode2odes $1 m $integration_method $algebraic_solver
endif
endif
ifneq ($integration_method,implicit)
$1_ode2odes.m : $1_def.r $1_sympars.txt\
		$1_simpar.m $1_numpar.m $1_state.m $1_input.m \
		$1_ode.m $1_odeo.m  $1_logic.m
ifeq ($using_oct,yes)
	echo "*** Warning: Shouldn't be here! Creating dummy $1_ode2odes.m"
	touch $1_ode2odes.m # Create a dummy which wont' be used
	mtt $mtt_switches -q -u $1 ode2odes oct
else
	make_ode2odes $1 m $integration_method $algebraic_solver
endif

endif

#SUMMARY ode2odes Simulation function (m)
#SUMMARY ode2odes Simulation function (cc)
#SUMMARY ode2odes Simulation function (oct)
#SUMMARY ode2odes Simulation function (exe)
$1_ode2odes.exe: $1_def.h $1_sympar.h\
		 $1_ode2odes.o $1_ode2odes_common.o $1_ode2odes_${integration_method}.o $1_ode2odes_${algebraic_solver}.o
	echo Creating $1_ode2odes.exe
	${MTT_CXX} ${MTT_CXXFLAGS} -o $1_ode2odes.exe\
	$1_ode2odes.o $1_ode2odes_common.o $1_ode2odes_${integration_method}.o $1_ode2odes_${algebraic_solver}.o\
	${MTT_LDFLAGS} ${MTT_CXXLIBS}

$1_ode2odes.o: $1_ode2odes.cc $1_ode2odes_common.o $1_ode2odes_${integration_method}.o $1_ode2odes_${algebraic_solver}.o
	echo Creating $1_ode2odes.o
	${MTT_CXX} ${MTT_CXXFLAGS} ${MTT_CXXINCS} -c $1_ode2odes.cc -DSTANDALONE

$1_ode2odes.oct: $1_ode2odes.cc $1_ode2odes_common.oct $1_ode2odes_${integration_method}.oct $1_ode2odes_${algebraic_solver}.o
	touch $1_ode2odes.m
	echo Creating $1_ode2odes.oct
	$MKOCTFILE $1_ode2odes.cc mtt_${algebraic_solver}.cc mtt_Solver.cc

$1_ode2odes.cc: $1_def.r $1_sympars.txt\
		$1_ode2odes_common.m $1_ode2odes_common.cc\
		$1_ode2odes_${integration_method}.m $1_ode2odes_${integration_method}.cc mtt_Solver.cc mtt_${algebraic_solver}.cc mtt_${algebraic_solver}.hh
	touch $1_ode2odes.m
	make_ode2odes $1 cc $integration_method $algebraic_solver

#Conversion of m to p to c
#SUMMARY ode	ordinary differential equations (c)
#SUMMARY ode	ordinary differential equations (p)
#SUMMARY state	state declaration (c) 
#SUMMARY state	state declaration (p) 
$1_simpar.p : $1_def.r $1_simpar.m

Added mttroot/mtt/bin/mtt_xargs.sh version [0e001e0d54].















>
>
>
>
>
>
>
1
2
3
4
5
6
7
#! /bin/sh

cmd=$1
for arg in $2; do
	eval $cmd $arg
done

Modified mttroot/mtt/bin/trans/cbg2ese_m2r from [906b34eb53] to [0a2c9156c8].

12
13
14
15
16
17
18







19
20
21
22
23
24
25

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







## Revision 1.29  2001/03/29 19:24:14  gawthrop
## Can now use c representations of crs when using -c option
##
## Revision 1.28  2001/02/05 17:19:52  gawthrop
## Now gives unique names to the states of multiports. Second name
## onwards labeled with port number
##







>
>
>
>
>
>
>







12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

###############################################################
## Version control history
###############################################################
## $Id$
##
## $Log$
## Revision 1.30  2001/07/12 04:02:53  gawthrop
## Now fixes multiports for input and output as well as state
##
## Revision 1.29.2.1  2001/06/26 22:29:05  geraint
## mtt_xargs.sh eliminates Arg list too long error for large models.
## (UNIX xargs does not work if the environment is too large).
##
## Revision 1.29  2001/03/29 19:24:14  gawthrop
## Can now use c representations of crs when using -c option
##
## Revision 1.28  2001/02/05 17:19:52  gawthrop
## Now gives unique names to the states of multiports. Second name
## onwards labeled with port number
##
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
  cat $infofile
fi

if [ -z "$partition" ]; then
  ## Don't partition

  # Create the composite ese file
  cat $1_ese.r $1_*_ese.r $1_modpar.r  > $1_ese.tmp 2>> /dev/null

  mv $1_ese.tmp $1_ese.r

  # Zap the sub ese files
  rm -f $1_*_ese.r

  echo "END;" >> $1_ese.r

else # Partition the system

  # Save up the full def file
  mv $1_def.r mtt_all_def.r







|




|







191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
  cat $infofile
fi

if [ -z "$partition" ]; then
  ## Don't partition

  # Create the composite ese file
  mtt_xargs.sh cat "$1_ese.r $1_*_ese.r $1_modpar.r"  > $1_ese.tmp 2>> /dev/null

  mv $1_ese.tmp $1_ese.r

  # Zap the sub ese files
  mtt_xargs.sh "rm -f" "$1_*_ese.r"

  echo "END;" >> $1_ese.r

else # Partition the system

  # Save up the full def file
  mv $1_def.r mtt_all_def.r
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
    for i=1:$Nu
      printf("MTT_%s_uc(%i,1) := %s_1_MTTu%i;\n", "$subsystem", i, "$subsystem", i);
    endfor;
EOF
  ## Subsystems (Only works when no repetitions at this level)
  esefile=${subsystem}_ese.r
  echo Creating $esefile
  cat ${subsystem}_1_ese.r ${subsystem}_1_*_ese.r > $esefile 2> /dev/null
  echo "END;" >> $esefile

  ## Def file for subsystem
  makedef ${subsystem}
  
  echo Creating ${subsystem}_struc.txt
  grep $subsystem < $1_struc.txt > ${subsystem}_struc.txt







|







309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
    for i=1:$Nu
      printf("MTT_%s_uc(%i,1) := %s_1_MTTu%i;\n", "$subsystem", i, "$subsystem", i);
    endfor;
EOF
  ## Subsystems (Only works when no repetitions at this level)
  esefile=${subsystem}_ese.r
  echo Creating $esefile
  mtt_xargs.sh cat "${subsystem}_1_ese.r ${subsystem}_1_*_ese.r" > $esefile 2> /dev/null
  echo "END;" >> $esefile

  ## Def file for subsystem
  makedef ${subsystem}
  
  echo Creating ${subsystem}_struc.txt
  grep $subsystem < $1_struc.txt > ${subsystem}_struc.txt

Modified mttroot/mtt/bin/trans/cse2ode_r from [b0e0e060b2] to [4586038e86].

10
11
12
13
14
15
16








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

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








## Revision 1.2  1997/01/06 21:17:10  peterg
## Removed:  OFF Exp; OFF GCD;
##
## Revision 1.1  1996/08/25 10:05:45  peter
## Initial revision
##
###############################################################







>
>
>
>
>
>
>
>







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

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
## Revision 1.1.4.1  2001/05/04 04:07:24  geraint
## Numerical solution of algebraic equations.
## sys_ae.cc written for unsolved inputs.
## Solution of equations using hybrd from MINPACK (as used by Octave fsolve).
##
## Revision 1.1  2000/12/28 12:21:31  peterg
## Put under RCS
##
## Revision 1.2  1997/01/06 21:17:10  peterg
## Removed:  OFF Exp; OFF GCD;
##
## Revision 1.1  1996/08/25 10:05:45  peter
## Initial revision
##
###############################################################
43
44
45
46
47
48
49



50
51
52
53
54
55
56
in "$1_def.r";

%Read the substitution file
in "$1_subs.r";

%Read the constrained-state equations file
in "$1_cse.r";




IF MTTNx>0 THEN
 IF MTTNz>0 THEN
   MTTdXX := MTTE^(-1)*MTTEdX
 ELSE
   MTTdXX := MTTEdX;








>
>
>







51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
in "$1_def.r";

%Read the substitution file
in "$1_subs.r";

%Read the constrained-state equations file
in "$1_cse.r";

%Read the algebraic equations file
in "$1_ae.r";

IF MTTNx>0 THEN
 IF MTTNz>0 THEN
   MTTdXX := MTTE^(-1)*MTTEdX
 ELSE
   MTTdXX := MTTEdX;

Modified mttroot/mtt/bin/trans/dae2cse_r from [2f584317f5] to [58cb32da86].

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.14.2.1  2001/03/19 00:29:08  geraint
## Parse switches (-A) before calling def2write_r.
## Update $1_def.* instead of removing.
##
## Revision 1.14  2000/12/28 12:24:35  peterg
## *** empty log message ***
##







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







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
# Copyright (c) P.J.Gawthrop 1991, 1992, 1994.

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
## Revision 1.15.2.4  2001/06/26 00:55:48  geraint
## Writes algebraic equation Jacobian _aej.r (not used yet).
##
## Revision 1.15.2.3  2001/05/09 00:19:22  geraint
## Fixed EOF error when MTTNYZ=0.
##
## Revision 1.15.2.2  2001/05/05 20:50:16  geraint
## Fixed errors when MTTNx=0.
##
## Revision 1.15.2.1  2001/05/04 04:07:24  geraint
## Numerical solution of algebraic equations.
## sys_ae.cc written for unsolved inputs.
## Solution of equations using hybrd from MINPACK (as used by Octave fsolve).
##
## Revision 1.15  2001/03/19 02:28:52  geraint
## Branch merge: merging-ode2odes-exe back to MAIN.
##
## Revision 1.14.2.1  2001/03/19 00:29:08  geraint
## Parse switches (-A) before calling def2write_r.
## Update $1_def.* instead of removing.
##
## Revision 1.14  2000/12/28 12:24:35  peterg
## *** empty log message ***
##
279
280
281
282
283
284
285
286
287


























288
289
290



291
292

293
294
295


296
297
298
299
300
301
302
303
304
305
306
307
308
309
  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 matrix declarations
OUT "$1_cse.r1";



write "MATRIX MTTEdx(", MTTNx, ",", 1, ")$"; 
write "MATRIX MTTE(", MTTNx, ",", MTTNx, ")$"; 

SHUT "$1_cse.r1";

OUT "$1_csex.r1";


write "MATRIX MTTEdx(", MTTNx, ",", 1, ")$"; 
SHUT "$1_csex.r1";

IF MTTNy>0 THEN
BEGIN
  OUT "$1_cseo.r1";
  write "MATRIX MTTY(", MTTNy, ",", MTTNx, ")$"; 
  SHUT "$1_cseo.r1";
END;

%%Create the _cse.r file
OUT "$1_cse.r2";
write "%File: $1_cse.r";
in ("$1_cse_write.r");







|

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>



>
>
>
|
|
>



>
>
|





|







296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
  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 and $solve

OUT "$1_ae.r";
IF (MTTNyz>0) THEN % not $solve (or perhaps solution failed?)
BEGIN
    WRITE "MATRIX MTTyz(",MTTNyz,",1)";
    WRITE "%File: $1_ae.r";
    FOR i := 1:MTTNyz DO
	WRITE "MTTyz(",i,",1) := ",MTTyz(i,1);
END; % if MTTNyz>0 (and !$solve)
WRITE ";END;";
SHUT "$1_ae.r";

OUT "$1_aej.r";
IF (MTTNyz>0) THEN % as above
BEGIN
    WRITE "MATRIX MTTyzj(",MTTNyz,",",MTTNyz,")";
    WRITE "%File: $1_aej.r";
    FOR i := 1:MTTNyz DO
	FOR j := 1:MTTNyz DO
	BEGIN
	   didj := df(MTTyz(i,1),mkid('mttui,j));
	   IF (didj NEQ 0) THEN
	      WRITE "MTTyzj(",i,",",j,") := ",didj;
	END;
END;
WRITE ";END;";
SHUT "$1_aej.r";

% Create the matrix declarations
OUT "$1_cse.r1";
write "%";
IF (MTTNx > 0) THEN
BEGIN
    write "MATRIX MTTEdx(", MTTNx, ",", 1, ")$"; 
    write "MATRIX MTTE(", MTTNx, ",", MTTNx, ")$"; 
END;
SHUT "$1_cse.r1";

OUT "$1_csex.r1";
write "%File:$1_csex.r1";
IF (MTTNx > 0) THEN
    write "MATRIX MTTEdx(", MTTNx, ",", 1, ")$"; 
SHUT "$1_csex.r1";

IF MTTNy>0 THEN
BEGIN
  OUT "$1_cseo.r1";
  write "MATRIX MTTY(", MTTNy, ",", 1, ")$"; 
  SHUT "$1_cseo.r1";
END;

%%Create the _cse.r file
OUT "$1_cse.r2";
write "%File: $1_cse.r";
in ("$1_cse_write.r");

Modified mttroot/mtt/bin/trans/dat2sdat from [8c6cd455bb] to [e7c1c34fa1].

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
# Copyright (c) P.J.Gawthrop, 1997, 1999

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






## Revision 1.1  1999/03/28 21:29:40  peterg
## Initial revision
##
###############################################################

if [ "$2" = "odes" ]; then
    which="state"
else
    which="output"
fi

awk '
BEGIN{
printf("Time");
}
{ 
  if ($1==which)
    printf(" %s(%s)", $3, $5);
}
END{
printf("\n");
}
'  SYSTEM=$1 which=$which  < $1_struc.txt

cat $1_$2.dat










>
>
>
>
>
>

















|










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
# Copyright (c) P.J.Gawthrop, 1997, 1999

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
## Revision 1.1.4.1  2001/06/26 00:57:21  geraint
## Prints more useful name.
##
## Revision 1.1  2000/12/28 12:26:34  peterg
## Put under RCS
##
## Revision 1.1  1999/03/28 21:29:40  peterg
## Initial revision
##
###############################################################

if [ "$2" = "odes" ]; then
    which="state"
else
    which="output"
fi

awk '
BEGIN{
printf("Time");
}
{ 
  if ($1==which)
    printf(" %s(%s)", $4, $5);
}
END{
printf("\n");
}
'  SYSTEM=$1 which=$which  < $1_struc.txt

cat $1_$2.dat



Modified mttroot/mtt/bin/trans/def2write_r from [7008801453] to [4a06362261].

9
10
11
12
13
14
15










16
17
18
19
20
21
22
# Copyright (C) 2000 by Peter J. Gawthrop

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










## Revision 1.6  2000/11/29 20:48:53  peterg
## Zapped unnecessary Npar creation
##
## Revision 1.5  2000/11/09 10:12:24  peterg
## Removed debugging line
##
## Revision 1.4  2000/10/14 16:19:54  peterg







>
>
>
>
>
>
>
>
>
>







9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# Copyright (C) 2000 by Peter J. Gawthrop

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
## Revision 1.7.2.1  2001/05/04 04:07:24  geraint
## Numerical solution of algebraic equations.
## sys_ae.cc written for unsolved inputs.
## Solution of equations using hybrd from MINPACK (as used by Octave fsolve).
##
## Revision 1.7  2001/04/11 09:44:26  gawthrop
## Fixed cc and c problems to do with pow(x,y) and integers
## mtt/lib/reduce/fix_c.r is included in rdae2dae and cse2smx_lang for
## -c, -cc and -oct options
##
## Revision 1.6  2000/11/29 20:48:53  peterg
## Zapped unnecessary Npar creation
##
## Revision 1.5  2000/11/09 10:12:24  peterg
## Removed debugging line
##
## Revision 1.4  2000/10/14 16:19:54  peterg
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
	;;
    ode)
        matrices='dX'
        ns="$Nx"
        ms="1"
	;;
    odeo)
        matrices='Y Yz'
        ns="$Ny $Nyz"
        ms="1 1"
	;;
    sm)
        matrices='A B C D'
        ns="$Nx $Nx $Ny $Ny"
        ms="$Nx $Nu $Nx $Nu"
	;;







|
|







86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
	;;
    ode)
        matrices='dX'
        ns="$Nx"
        ms="1"
	;;
    odeo)
        matrices='Y'
        ns="$Ny"
        ms="1 1"
	;;
    sm)
        matrices='A B C D'
        ns="$Nx $Nx $Ny $Ny"
        ms="$Nx $Nu $Nx $Nu"
	;;

Modified mttroot/mtt/bin/trans/make_ode2odes from [fc0a627e05] to [7c877050c5].

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.57  2001/04/01 03:38:54  geraint
## Reset row to zero after write to file, ready for subsequent runs.
## Eliminates SIGSEGV in Octave when _ode2odes called multiple times.
##
## Revision 1.56  2001/03/30 15:13:58  gawthrop
## Rationalised simulation modes to each return mtt_data
##











>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







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
#! /bin/sh

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

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
## Revision 1.58  2001/07/13 00:51:39  geraint
## Fixed generation of odes.sg from .m and .oct simulations.
## .cc, .m and .oct simulations now all write mtt_data (lower case).
##
## Revision 1.57.2.5  2001/07/13 04:02:31  geraint
## Implemented numerical algebraic solution for _ode2odes.oct.
##
## Revision 1.57.2.4  2001/07/02 00:34:56  geraint
## gcc-3.0 compatibility.
##
## Revision 1.57.2.3  2001/06/25 23:28:29  geraint
## Generic mtt_rate and mtt_output - allows method independent calls.
##
## Revision 1.57.2.2  2001/06/05 03:20:40  geraint
## added -ae option to select algebraic equation solution method.
##
## Revision 1.57.2.1  2001/05/04 04:07:24  geraint
## Numerical solution of algebraic equations.
## sys_ae.cc written for unsolved inputs.
## Solution of equations using hybrd from MINPACK (as used by Octave fsolve).
##
## Revision 1.57  2001/04/01 03:38:54  geraint
## Reset row to zero after write to file, ready for subsequent runs.
## Eliminates SIGSEGV in Octave when _ode2odes called multiple times.
##
## Revision 1.56  2001/03/30 15:13:58  gawthrop
## Rationalised simulation modes to each return mtt_data
##
221
222
223
224
225
226
227






228
229
230
231
232
233
234
filename=${sys}_ode2odes.${lang}

if [ -n "$3" ]; then
  method=$3    
else
  method=implicit  
fi







echo Creating $filename 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  







>
>
>
>
>
>







242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
filename=${sys}_ode2odes.${lang}

if [ -n "$3" ]; then
  method=$3    
else
  method=implicit  
fi

if [ -n "$4" ]; then
    algebraic_solver=$4
else
  algebraic_solver="Reduce_Solver"
fi

echo Creating $filename 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  
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362


363
364
365






366
367
368
369
370
371
372
	feval_header=parse.h
	save_ascii_data_function=save_ascii_data_for_plotting
	;;
esac

cat <<EOF  > $filename
#include <octave/oct.h>
#include <octave/ov-struct.h>
#include <octave/load-save.h>
#include <octave/lo-mappers.h>
#include <octave/variables.h>

#ifndef STANDALONE
#include <octave/${feval_header}>
#endif

#include "${sys}_def.h"
#include "${sys}_sympar.h"



#ifdef STANDALONE
#include <csignal>
#include <fstream>







extern ColumnVector F${sys}_input (
	ColumnVector &x,
	ColumnVector &y,
	const double &t,
	ColumnVector &par);








|
|
|









>
>



>
>
>
>
>
>







371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
	feval_header=parse.h
	save_ascii_data_function=save_ascii_data_for_plotting
	;;
esac

cat <<EOF  > $filename
#include <octave/oct.h>
#include <octave/load-save.h>
#include <octave/lo-mappers.h>
#include <octave/ov-struct.h>
#include <octave/variables.h>

#ifndef STANDALONE
#include <octave/${feval_header}>
#endif

#include "${sys}_def.h"
#include "${sys}_sympar.h"

#include "mtt_${algebraic_solver}.hh"

#ifdef STANDALONE
#include <csignal>
#include <fstream>

extern ColumnVector F${sys}_ae (
	ColumnVector &x,
	ColumnVector &u,
	const double &t,
	ColumnVector &par);

extern ColumnVector F${sys}_input (
	ColumnVector &x,
	ColumnVector &y,
	const double &t,
	ColumnVector &par);

430
431
432
433
434
435
436



437
438


















439
440
441
442
443
444
445



446
447
448
449
450
451
452
453
454
455
456








457
458
459
460
461
462
463
	ColumnVector &u,
	const double &t,
	ColumnVector &par);
 
EOF
fi
cat <<EOF >> $filename



#endif // STANDALONE




















inline ColumnVector
mtt_input (ColumnVector &x,
	   ColumnVector &y,
	   const double &t,
	   ColumnVector &par)
{



#ifdef STANDALONE
  return F${sys}_input (x, y, t, par);
#else
  static octave_value_list args, f;
  args (0) = octave_value (x);
  args (1) = octave_value (y);
  args (2) = octave_value (t);
  args (3) = octave_value (par);
  f = feval ("${sys}_input", args, 1);
  return f(0).${vector_value} ();
#endif








}

inline ColumnVector
mtt_logic (ColumnVector &x,
	   ColumnVector &u,
	   const double &t,
	   ColumnVector &par)







>
>
>


>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







>
>
>

|







|

>
>
>
>
>
>
>
>







465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
	ColumnVector &u,
	const double &t,
	ColumnVector &par);
 
EOF
fi
cat <<EOF >> $filename

void set_signal_handlers (void);

#endif // STANDALONE

ColumnVector
mtt_ae (ColumnVector &x,
	ColumnVector &u,
	const double &t,
	ColumnVector &par)
{
#ifdef STANDALONE
    return F${sys}_ae(x,u,t,par);
#else
    static octave_value_list args, f;
    args (0) = octave_value (x);
    args (1) = octave_value (u);
    args (2) = octave_value (t);
    args (3) = octave_value (par);
    f = feval ("${sys}_ae", args, 1);
    return f(0).${vector_value} ();
#endif
}

inline ColumnVector
mtt_input (ColumnVector &x,
	   ColumnVector &y,
	   const double &t,
	   ColumnVector &par)
{
  static ${algebraic_solver} ae(mtt_ae,MTTNPAR,MTTNU,MTTNX,MTTNY,MTTNYZ);
  static ColumnVector u  (MTTNU);

#ifdef STANDALONE
  u = F${sys}_input (x, y, t, par);
#else
  static octave_value_list args, f;
  args (0) = octave_value (x);
  args (1) = octave_value (y);
  args (2) = octave_value (t);
  args (3) = octave_value (par);
  f = feval ("${sys}_input", args, 1);
  u = f(0).${vector_value} ();
#endif
  if (MTTNYZ == 0)
    {
      return u;
    }
  else
    {
      return ae.solve(x,u,t,par);
    }
}

inline ColumnVector
mtt_logic (ColumnVector &x,
	   ColumnVector &u,
	   const double &t,
	   ColumnVector &par)
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
  args (0) = octave_value (x);
  f = feval ("${sys}_state", args, 1);
  return f(0).${vector_value} ();
#endif
}

inline ColumnVector
mtt_${ode} (ColumnVector &x,
	    ColumnVector &u,
	    const double &t,
	    ColumnVector &par)
{
#ifdef STANDALONE
  return F${sys}_${ode} (x, u, t, par);
#else
  static octave_value_list args, f;
  args (0) = octave_value (x);
  args (1) = octave_value (u);
  args (2) = octave_value (t);
  args (3) = octave_value (par);
  f = feval ("${sys}_${ode}", args, 1);
  return f(0).${vector_value} ();
#endif
}

inline ColumnVector
mtt_${odeo} (ColumnVector &x,
	     ColumnVector &u,
	     const double &t,
	     ColumnVector &par)
{
#ifdef STANDALONE
  return F${sys}_${odeo} (x, u, t, par);
#else







|
|
|
|















|







584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
  args (0) = octave_value (x);
  f = feval ("${sys}_state", args, 1);
  return f(0).${vector_value} ();
#endif
}

inline ColumnVector
mtt_rate (ColumnVector &x,
	  ColumnVector &u,
	  const double &t,
	  ColumnVector &par)
{
#ifdef STANDALONE
  return F${sys}_${ode} (x, u, t, par);
#else
  static octave_value_list args, f;
  args (0) = octave_value (x);
  args (1) = octave_value (u);
  args (2) = octave_value (t);
  args (3) = octave_value (par);
  f = feval ("${sys}_${ode}", args, 1);
  return f(0).${vector_value} ();
#endif
}

inline ColumnVector
mtt_output (ColumnVector &x,
	     ColumnVector &u,
	     const double &t,
	     ColumnVector &par)
{
#ifdef STANDALONE
  return F${sys}_${odeo} (x, u, t, par);
#else
654
655
656
657
658
659
660
661
662
663
664
665
666
667


668
669

670
671
672
673
674
675
676

inline void
mtt_write (const double &t,
	   ColumnVector &x,
	   ColumnVector &y,
	   const int &nrows,
	   const bool dump_data = false,
	   ostream &file = cout)
{
  static Matrix data;
  static int row;

  if (dump_data)
    {


       Matrix written_data = data.extract (0, 0, row-1, data.cols ()-1);
       $save_ascii_data_function (file, written_data, "mtt_data");

       return;
    }

  const int nx = x.length (), ny = y.length ();
  register int col = 0;

  if (0 == row)







|






>
>
|
|
>







721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746

inline void
mtt_write (const double &t,
	   ColumnVector &x,
	   ColumnVector &y,
	   const int &nrows,
	   const bool dump_data = false,
	   std::ostream &file = std::cout)
{
  static Matrix data;
  static int row;

  if (dump_data)
    {
       if (row > 0)
         {
           Matrix written_data = data.extract (0, 0, row-1, data.cols ()-1);
           $save_ascii_data_function (file, written_data, "mtt_data");
	 }
       return;
    }

  const int nx = x.length (), ny = y.length ();
  register int col = 0;

  if (0 == row)
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757

  row++;

  if (nrows == row)
    {
#ifdef STANDALONE
      $save_ascii_data_function (file, data, "mtt_data");
//    cout << data << endl;
#else // ! STANDALONE
  set_global_value ("MTT_data", data);
#endif
    row = 0;
    }
}

#ifdef STANDALONE
void dump_data (ostream &file)
{
  ColumnVector null (0.0);
  mtt_write (0.0, null, null, 0, true, file);
}

void set_signal_handlers (void);

void handle_signal (int signum)
{
  // handle some signals to ensure data is written.
  cerr << "# Writing data to MTT.core (signal " << signum << ")" << endl;
  ofstream corefile ("MTT.core");
  dump_data (corefile);
  switch (signum)
    {
      case SIGFPE:
        // Intel chips do not raise SIGFPE for DIVZERO :-(
        raise (SIGABRT);
        break;
      case SIGINT:
	break;
      case SIGQUIT:
	signal (SIGQUIT, SIG_DFL);
	raise (SIGQUIT);
	break;
      default:
        cerr << "# Warning: make_ode2odes needs updating!" << endl;
	signal (signum, SIG_DFL);
	raise (signum);
        break;
    }
  corefile.close ();
  set_signal_handlers ();
}

void set_signal_handlers (void)
{
  signal (SIGFPE,	handle_signal);
  signal (SIGINT,	handle_signal);
  signal (SIGQUIT,	handle_signal);
}

int main (void) {
  set_signal_handlers ();
#else
DEFUN_DLD (${sys}_ode2odes, args, ,
"Octave ode2odes representation of system with $method integration method
Usage: mtt_data = ${sys}_ode2odes (x0, par, simpar)
")
{
  static octave_value_list retval;
#endif // STANDALONE
  static ColumnVector	x0;
  static ColumnVector	par;
  static Octave_map	simpar;








|








|

|



<
<



|
|





|








|



















|
<
<







755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776


777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816


817
818
819
820
821
822
823

  row++;

  if (nrows == row)
    {
#ifdef STANDALONE
      $save_ascii_data_function (file, data, "mtt_data");
//    std::cout << data << std::endl;
#else // ! STANDALONE
  set_global_value ("MTT_data", data);
#endif
    row = 0;
    }
}

#ifdef STANDALONE
void dump_data (std::ostream &file)
{
  ColumnVector null (0);
  mtt_write (0.0, null, null, 0, true, file);
}



void handle_signal (int signum)
{
  // handle some signals to ensure data is written.
  std::cerr << "# Writing data to MTT.core (signal " << signum << ")" << std::endl;
  std::ofstream corefile ("MTT.core");
  dump_data (corefile);
  switch (signum)
    {
      case SIGFPE:
        // Intel chips do not raise SIGFPE for DIVZERO :-(
//        raise (SIGABRT);
        break;
      case SIGINT:
	break;
      case SIGQUIT:
	signal (SIGQUIT, SIG_DFL);
	raise (SIGQUIT);
	break;
      default:
        std::cerr << "# Warning: make_ode2odes needs updating!" << std::endl;
	signal (signum, SIG_DFL);
	raise (signum);
        break;
    }
  corefile.close ();
  set_signal_handlers ();
}

void set_signal_handlers (void)
{
  signal (SIGFPE,	handle_signal);
  signal (SIGINT,	handle_signal);
  signal (SIGQUIT,	handle_signal);
}

int main (void) {
  set_signal_handlers ();
#else
DEFUN_DLD (${sys}_ode2odes, args, ,
"Octave ode2odes representation of system with $method integration method\nUsage: mtt_data = ${sys}_ode2odes (x0, par, simpar)\n")


{
  static octave_value_list retval;
#endif // STANDALONE
  static ColumnVector	x0;
  static ColumnVector	par;
  static Octave_map	simpar;

828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
    {
      x (i) = x0 (i);
    }

  for (register int j = 0, i = 1; i <= ilast; i++)
    {
      u	= mtt_input (x, y, t, par);
      y	= mtt_${odeo} (x, u, t, par);
      if (0 == j)
	{
           mtt_write (t, x, y, nrows);
	}
EOF
if [ "$method" = "rk4" ]; then
cat << EOF >> $filename







|







894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
    {
      x (i) = x0 (i);
    }

  for (register int j = 0, i = 1; i <= ilast; i++)
    {
      u	= mtt_input (x, y, t, par);
      y	= mtt_output (x, u, t, par);
      if (0 == j)
	{
           mtt_write (t, x, y, nrows);
	}
EOF
if [ "$method" = "rk4" ]; then
cat << EOF >> $filename
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
          t2 = t + ddt;

        ColumnVector
          x1 (x),
          x2 (x),
          x3 (x);

        k1 = ddt * mtt_${ode} (x , u, t , par); x1 += k1 * 0.5;
        k2 = ddt * mtt_${ode} (x1, u, t1, par); x2 += k2 * 0.5;
        k3 = ddt * mtt_${ode} (x2, u, t1, par); x3 += k3;
        k4 = ddt * mtt_${ode} (x3, u, t2, par);
        dx = (k1 + 2.0 * (k2 + k3) + k4) / (6.0 * ddt);
      }
EOF
else
cat << EOF >> $filename
      dx = mtt_${ode} (x, u, t, par);
EOF
fi

if [ "$method" = "implicit" ]; then
cat <<EOF >> $filename

      AA = mtt_smxa (x, u, ddt, par);







|
|
|
|





|







918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
          t2 = t + ddt;

        ColumnVector
          x1 (x),
          x2 (x),
          x3 (x);

        k1 = ddt * mtt_rate (x , u, t , par); x1 += k1 * 0.5;
        k2 = ddt * mtt_rate (x1, u, t1, par); x2 += k2 * 0.5;
        k3 = ddt * mtt_rate (x2, u, t1, par); x3 += k3;
        k4 = ddt * mtt_rate (x3, u, t2, par);
        dx = (k1 + 2.0 * (k2 + k3) + k4) / (6.0 * ddt);
      }
EOF
else
cat << EOF >> $filename
      dx = mtt_rate (x, u, t, par);
EOF
fi

if [ "$method" = "implicit" ]; then
cat <<EOF >> $filename

      AA = mtt_smxa (x, u, ddt, par);

Modified mttroot/mtt/bin/trans/mtt_header from [2bd64ee2d2] to [d88a1bf0c6].

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
# Copyright (C) 2000 by Peter J. Gawthrop

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



## Revision 1.35  2001/06/13 10:39:51  gawthrop
## Zeros output matices in csex and cseo just in case some elements are
## actually zero and not set in code. Works for m and oct.
##
## Revision 1.34  2001/05/26 18:36:43  gawthrop
## Further modifications. Now works on rcPPP
##  -- next jobs:
##     add identification to ppp_nlin_sim
##     create real-time ppp_nlin_run
##
## Revision 1.33  2001/05/26 15:46:38  gawthrop
## Updated to account for new nonlinear ppp
##
## Revision 1.32  2001/05/24 07:42:12  gawthrop
## Included and updated the missing tf_r2m
##








## Revision 1.31  2001/04/03 14:49:42  gawthrop
## Revised to incorporate new ssim (sensitivity simulation)
## representation (m only just now).
##
## Revision 1.30  2001/03/30 15:13:58  gawthrop
## Rationalised simulation modes to each return mtt_data
##







>
>
>
















>
>
>
>
>
>
>
>







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
# Copyright (C) 2000 by Peter J. Gawthrop

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
## Revision 1.36  2001/07/12 04:00:51  gawthrop
## Now zeros y correctly - ie Ny NOT Nx elements
##
## Revision 1.35  2001/06/13 10:39:51  gawthrop
## Zeros output matices in csex and cseo just in case some elements are
## actually zero and not set in code. Works for m and oct.
##
## Revision 1.34  2001/05/26 18:36:43  gawthrop
## Further modifications. Now works on rcPPP
##  -- next jobs:
##     add identification to ppp_nlin_sim
##     create real-time ppp_nlin_run
##
## Revision 1.33  2001/05/26 15:46:38  gawthrop
## Updated to account for new nonlinear ppp
##
## Revision 1.32  2001/05/24 07:42:12  gawthrop
## Included and updated the missing tf_r2m
##
## Revision 1.31.2.2  2001/07/02 00:34:56  geraint
## gcc-3.0 compatibility.
##
## Revision 1.31.2.1  2001/05/04 04:07:24  geraint
## Numerical solution of algebraic equations.
## sys_ae.cc written for unsolved inputs.
## Solution of equations using hybrd from MINPACK (as used by Octave fsolve).
##
## Revision 1.31  2001/04/03 14:49:42  gawthrop
## Revised to incorporate new ssim (sensitivity simulation)
## representation (m only just now).
##
## Revision 1.30  2001/03/30 15:13:58  gawthrop
## Rationalised simulation modes to each return mtt_data
##
180
181
182
183
184
185
186







187
188
189
190
191
192
193


# Representation-specific stuff

eqnargs='mttx,mttu,mttt,mttpar'
inputeqnargs='mttx,mtty,mttt,mttpar'
case $rep in







    cse)
	states=yes;
        inputs=yes;
	parameters=yes;
        output='mttdx,mtte'
        args=$eqnargs
	;;







>
>
>
>
>
>
>







191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211


# Representation-specific stuff

eqnargs='mttx,mttu,mttt,mttpar'
inputeqnargs='mttx,mtty,mttt,mttpar'
case $rep in
    ae)
	states=yes;
	inputs=yes;
	parameters=yes;
	output=mttyz;
	args=$eqnargs;
	;;
    cse)
	states=yes;
        inputs=yes;
	parameters=yes;
        output='mttdx,mtte'
        args=$eqnargs
	;;
223
224
225
226
227
228
229

230
231
232
233
234
235
236
	  states=no;
	  parameters=no;
          declareinputs=no;
        else
	  states=yes;
	  parameters=yes;
          declareinputs=yes

        fi
	;;
    logic)
	states=no;
	inputs=no;
	parameters=yes;
        output=mttopen







>







241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
	  states=no;
	  parameters=no;
          declareinputs=no;
        else
	  states=yes;
	  parameters=yes;
          declareinputs=yes
	  declarestates=yes
        fi
	;;
    logic)
	states=no;
	inputs=no;
	parameters=yes;
        output=mttopen
519
520
521
522
523
524
525









526
527
528
529
530
531
532
$Lc Inputs $Rc
EOF

N=`n2m 1 $Nu`
for i in $N; do
  echo $constant_declaration 'mttu'$i' = mttu('$i$minusone');'
done









fi

if [ "$declareinputs" = "yes" ]; then
  declare_vars input
fi

if [ "$declaredummies" = "yes" ]; then







>
>
>
>
>
>
>
>
>







538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
$Lc Inputs $Rc
EOF

N=`n2m 1 $Nu`
for i in $N; do
  echo $constant_declaration 'mttu'$i' = mttu('$i$minusone');'
done
cat <<EOF

$Lc Unknown Inputs $Rc
EOF

Ni=`n2m 1 $Nyz`
for i in $Ni; do
  echo $constant_declaration 'mttui'$i' = mttu('$Nu+$i$minusone');'
done
fi

if [ "$declareinputs" = "yes" ]; then
  declare_vars input
fi

if [ "$declaredummies" = "yes" ]; then
574
575
576
577
578
579
580




581
582
583
584
585
586
587
	    arg_type="Octave_map"
	    arg_size="";
	    ;;
	mttu)
	    arg_type="ColumnVector"
	    arg_size="(MTTNU)"
	    ;;




	mtty)
	    arg_type="ColumnVector"
	    arg_size="(MTTNY)"
	    ;;
	mttt)
	    arg_type="const double"
	    arg_size=""







>
>
>
>







602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
	    arg_type="Octave_map"
	    arg_size="";
	    ;;
	mttu)
	    arg_type="ColumnVector"
	    arg_size="(MTTNU)"
	    ;;
	mttyz)
	    arg_type="ColumnVector"
	    arg_size="(MTTNYZ)"
	    ;;
	mtty)
	    arg_type="ColumnVector"
	    arg_size="(MTTNY)"
	    ;;
	mttt)
	    arg_type="const double"
	    arg_size=""
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
#include <math.h>
#include "useful-functions.hh"
#include "${system}_cr.h"
#include "${system}_def.h"
#include "${system}_sympar.h"

DEFUN_DLD (${system}_${rep}, args, ,
"Usage: [$output] = ${system}_${rep}($args)
Octave ${rep} representation of system ${system}
Generated by MTT on `date`")
{

  octave_value_list retval;
#endif // ! STANDALONE

EOF
}







|
<
<







688
689
690
691
692
693
694
695


696
697
698
699
700
701
702
#include <math.h>
#include "useful-functions.hh"
#include "${system}_cr.h"
#include "${system}_def.h"
#include "${system}_sympar.h"

DEFUN_DLD (${system}_${rep}, args, ,
"Usage: [$output] = ${system}_${rep}($args)\nOctave ${rep} representation of system ${system}\nGenerated by MTT on `date`")


{

  octave_value_list retval;
#endif // ! STANDALONE

EOF
}

Modified mttroot/mtt/bin/trans/mtt_multi from [ee371ab031] to [c98cabcb91].

10
11
12
13
14
15
16
17
18
19
20
21
22

current_level=`echo $system | awk '{N=split($1,foo,"_"); print N-1}'`

if [ -z "$relative_level" ]; then
  relative_level=0;    
fi

ls $2*_$3.$4  |\
awk '{
  level=split($1,foo,"_")-2;
  maxlevel = current_level +  relative_level;
  if (level<=maxlevel) print command, $0, "&";
'} command=$command relative_level=$relative_level current_level=$current_level







|





10
11
12
13
14
15
16
17
18
19
20
21
22

current_level=`echo $system | awk '{N=split($1,foo,"_"); print N-1}'`

if [ -z "$relative_level" ]; then
  relative_level=0;    
fi

mtt_xargs.sh "ls" "$2*_$3.$4"  |\
awk '{
  level=split($1,foo,"_")-2;
  maxlevel = current_level +  relative_level;
  if (level<=maxlevel) print command, $0, "&";
'} command=$command relative_level=$relative_level current_level=$current_level

Modified mttroot/mtt/bin/trans/mtt_r2m from [2c1a02abfa] to [ac7fcfc5be].

14
15
16
17
18
19
20








21
22
23
24
25
26
27
# Copyright (C) 2000 by Peter J. Gawthrop

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








## Revision 1.26  2000/11/27 11:52:10  peterg
## Changed some greps to be case insensitive
##
## Revision 1.25  2000/10/14 08:50:07  peterg
## Use new mtt_header
##
## Revision 1.24  2000/10/11 09:07:53  peterg







>
>
>
>
>
>
>
>







14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# Copyright (C) 2000 by Peter J. Gawthrop

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
## Revision 1.27.4.1  2001/05/04 04:07:24  geraint
## Numerical solution of algebraic equations.
## sys_ae.cc written for unsolved inputs.
## Solution of equations using hybrd from MINPACK (as used by Octave fsolve).
##
## Revision 1.27  2001/02/08 00:39:56  geraint
## Removed clear from code generated by: mtt -c -i euler -o
##
## Revision 1.26  2000/11/27 11:52:10  peterg
## Changed some greps to be case insensitive
##
## Revision 1.25  2000/10/14 08:50:07  peterg
## Use new mtt_header
##
## Revision 1.24  2000/10/11 09:07:53  peterg
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
echo Creating $out

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

#Header
case $rep in
    csex|cseo|ode|odeo)
    vectorise=yes
       ;;
    *)
esac

    mtt_header  $1 $rep $ext  > mtt_junk








|







138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
echo Creating $out

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

#Header
case $rep in
    ae|csex|cseo|ode|odeo)
    vectorise=yes
       ;;
    *)
esac

    mtt_header  $1 $rep $ext  > mtt_junk

Modified mttroot/mtt/bin/trans/mtt_txt2m from [abf1c9f144] to [50de47aa6e].

11
12
13
14
15
16
17










18
19
20
21
22
23
24


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










# %% Revision 1.12  2000/11/08 11:20:49  peterg
# %% removed the empty matrix stuff
# %%
# %% Revision 1.11  2000/10/17 09:55:21  peterg
# %% Added logic rep
# %%
# %% Revision 1.10  2000/10/15 09:51:50  peterg







>
>
>
>
>
>
>
>
>
>







11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34


# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %% Version control history
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %% $Id$
# %% $Log$
# %% Revision 1.13.4.2  2001/07/09 00:24:58  geraint
# %% input rep: Removed input name mapping, left state name mapping.
# %%
# %% Revision 1.13.4.1  2001/06/26 01:01:28  geraint
# %% Makes input and state names available for input rep.
# %%
# %% Revision 1.13  2001/02/05 03:33:18  geraint
# %% Convert user-defined txt to lower-case in translation.
# %% Required by logic.m (Octave is case sensitive).
# %%
# %% Revision 1.12  2000/11/08 11:20:49  peterg
# %% removed the empty matrix stuff
# %%
# %% Revision 1.11  2000/10/17 09:55:21  peterg
# %% Added logic rep
# %%
# %% Revision 1.10  2000/10/15 09:51:50  peterg
162
163
164
165
166
167
168







169
170
171
172
173
174
175

## Special for logic rep
if [ "$representation" = "logic" ]; then
  echo >> $outfile
  echo "## Inputs" >> $outfile
  mtt_name2array $system input >> $outfile # Set up input by name
  echo >> $outfile







  echo "## States" >>$outfile
  mtt_name2array $system state >> $outfile # Set up state by name
fi

# Write out the code from the txt file
echo >> $outfile
echo "## User defined code from $1_$2.txt" >> $outfile







>
>
>
>
>
>
>







172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192

## Special for logic rep
if [ "$representation" = "logic" ]; then
  echo >> $outfile
  echo "## Inputs" >> $outfile
  mtt_name2array $system input >> $outfile # Set up input by name
  echo >> $outfile
  echo "## States" >>$outfile
  mtt_name2array $system state >> $outfile # Set up state by name
fi

## Special for input rep
if [ "$representation" = "input" ]; then
  echo >> $outfile
  echo "## States" >>$outfile
  mtt_name2array $system state >> $outfile # Set up state by name
fi

# Write out the code from the txt file
echo >> $outfile
echo "## User defined code from $1_$2.txt" >> $outfile

Modified mttroot/mtt/bin/trans/multi_command from [32e416603b] to [b29c24f12c].

12
13
14
15
16
17
18






19
20
21
22
23
24
25
26
# Each command is of the form $1 $2_*_$3 &

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






# Revision 1.1  1996/10/21  12:31:40  peterg
# Initial revision
#
###############################################################


(ls $2*_$3 \
| sed "s/\(.*_*\)$3/$1 \1$3 \&/")







>
>
>
>
>
>






|

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# Each command is of the form $1 $2_*_$3 &

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
## Revision 1.2.4.1  2001/06/28 22:58:27  geraint
## Using mtt_xargs.sh to prevent Arg list too long error.
##
## Revision 1.2  1996/11/09 21:16:06  peterg
## *** empty log message ***
##
# Revision 1.1  1996/10/21  12:31:40  peterg
# Initial revision
#
###############################################################


(mtt_xargs.sh "ls" "$2*_$3" \
| sed "s/\(.*_*\)$3/$1 \1$3 \&/")

Modified mttroot/mtt/bin/trans/multi_command2 from [c9a8d61923] to [407726c4d3].

12
13
14
15
16
17
18






19
20
21
22
23
24
25
# Each command is of the form $1 $2_*_$3 > $2_*_$4

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






# Revision 1.1  1996/10/21  12:34:47  peterg
# Initial revision
#
###############################################################

(ls $2*_$3 \
| sed "s/\(.*_*\)$3/$1 \1$3 > \1$4 /")







>
>
>
>
>
>





|

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Each command is of the form $1 $2_*_$3 > $2_*_$4

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
## Revision 1.2.4.1  2001/06/28 22:58:27  geraint
## Using mtt_xargs.sh to prevent Arg list too long error.
##
## Revision 1.2  1996/11/09 21:16:19  peterg
## *** empty log message ***
##
# Revision 1.1  1996/10/21  12:34:47  peterg
# Initial revision
#
###############################################################

(mtt_xargs.sh "ls" "$2*_$3" \
| sed "s/\(.*_*\)$3/$1 \1$3 > \1$4 /")

Modified mttroot/mtt/cc/include/Bracket.hh from [206254c8d0] to [5787729a17].

1
2






3
4
5
6
7
8
9
10
11
12
13

14
15
16
17
18
19
20
/* $Id$
 * $Log$






 * Revision 1.1  2000/10/31 04:29:11  geraint
 * Initial revision
 *
 */



#include <iostream>
#include <string>




class Bracket
{
public:
  friend ostream &operator<< (ostream &str, Bracket *b);
  friend string  &operator<< (string  &str, Bracket *b);
  friend string  &operator+= (string  &str, Bracket *b);


>
>
>
>
>
>











>







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
/* $Id$
 * $Log$
 * Revision 1.1.4.1  2001/06/30 03:26:20  geraint
 * gcc-3.0 compatibility.
 *
 * Revision 1.1  2000/12/28 09:47:29  peterg
 * put under RCS
 *
 * Revision 1.1  2000/10/31 04:29:11  geraint
 * Initial revision
 *
 */



#include <iostream>
#include <string>


using namespace std;

class Bracket
{
public:
  friend ostream &operator<< (ostream &str, Bracket *b);
  friend string  &operator<< (string  &str, Bracket *b);
  friend string  &operator+= (string  &str, Bracket *b);

Modified mttroot/mtt/cc/include/useful-functions.hh from [61119a71b8] to [c2133a509b].

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
#define pi 3.14159 // Predefine pi

#ifndef HAVE_USEFUL_FUNCTIONS_HH
#define HAVE_USEFUL_FUNCTIONS_HH


#ifndef __cplusplus
#define inline			/* strip */
typedef double  doubleref_t;
#else
typedef double &doubleref_t;
#endif // ! __cplusplus


static inline double
max (const doubleref_t x1, const doubleref_t x2)
{
  return static_cast<double>((x1 >= x2) ? x1 : (x1 < x2) ? x2 : 0);
}

static inline double
min (const doubleref_t x1, const doubleref_t x2)
{
  return static_cast<double>((x1 <= x2) ? x1 : (x1 > x2) ? x2 : 0);
}

static inline double
nonsingular (const doubleref_t x)
{
  return static_cast<double>((x == 0) ? 1.0e-30 : x);
}

static inline double
sign (const doubleref_t x)
{
  return static_cast<double>((x > 0) ? +1 : (x < 0) ? -1 : 0);
}


// Octave functions
#ifdef __cplusplus
static Matrix
ones (const int r = 1, const int c = 1)
{
  Matrix m (r, c, 1.0);
  return m;
}

static ColumnVector
nozeros (const ColumnVector v0, const double tol = 0.0)
{
  ColumnVector v (v0.length ());
  register int i, j;
  for (i = j = 0; i < v.length (); i++)
    if (tol < abs (v0 (i)))
      {
	v (j) = v0 (i);
	j++;
      }
  if (0 == j)
    {
      return *new ColumnVector ();








<
<
<




|





|





|





|




















|







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
#define pi 3.14159 // Predefine pi

#ifndef HAVE_USEFUL_FUNCTIONS_HH
#define HAVE_USEFUL_FUNCTIONS_HH


#ifndef __cplusplus
#define inline			/* strip */



#endif // ! __cplusplus


static inline double
max (const double x1, const double x2)
{
  return static_cast<double>((x1 >= x2) ? x1 : (x1 < x2) ? x2 : 0);
}

static inline double
min (const double x1, const double x2)
{
  return static_cast<double>((x1 <= x2) ? x1 : (x1 > x2) ? x2 : 0);
}

static inline double
nonsingular (const double x)
{
  return static_cast<double>((x == 0) ? 1.0e-30 : x);
}

static inline double
sign (const double x)
{
  return static_cast<double>((x > 0) ? +1 : (x < 0) ? -1 : 0);
}


// Octave functions
#ifdef __cplusplus
static Matrix
ones (const int r = 1, const int c = 1)
{
  Matrix m (r, c, 1.0);
  return m;
}

static ColumnVector
nozeros (const ColumnVector v0, const double tol = 0.0)
{
  ColumnVector v (v0.length ());
  register int i, j;
  for (i = j = 0; i < v.length (); i++)
    if (tol < std::abs (v0 (i)))
      {
	v (j) = v0 (i);
	j++;
      }
  if (0 == j)
    {
      return *new ColumnVector ();
76
77
78
79
80
81
82
83
84
85
86
87

static Matrix
zeros (const int r, const int c)
{
  Matrix m (r, c, 0.0);
  return m;
}
#endif __cplusplus



#endif // HAVE_USEFUL_FUNCTIONS_HH







|




73
74
75
76
77
78
79
80
81
82
83
84

static Matrix
zeros (const int r, const int c)
{
  Matrix m (r, c, 0.0);
  return m;
}
#endif // __cplusplus



#endif // HAVE_USEFUL_FUNCTIONS_HH

Modified mttroot/mtt/cc/parse_m2cc.cc from [9dadb09da4] to [7241edf764].

1
2






3
4
5
6
7
8
9
/* $Id$
 * $Log$






 * Revision 1.1.2.2  2001/03/09 04:01:20  geraint
 * \ escapes newline.
 *
 * Revision 1.1.2.1  2001/03/09 02:59:26  geraint
 * got_comment: (char)c no longer compared to (int)EOF.
 *
 * Revision 1.1  2000/12/28 09:46:05  peterg


>
>
>
>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/* $Id$
 * $Log$
 * Revision 1.2.2.1  2001/06/30 03:26:17  geraint
 * gcc-3.0 compatibility.
 *
 * Revision 1.2  2001/03/19 02:28:53  geraint
 * Branch merge: merging-ode2odes-exe back to MAIN.
 *
 * Revision 1.1.2.2  2001/03/09 04:01:20  geraint
 * \ escapes newline.
 *
 * Revision 1.1.2.1  2001/03/09 02:59:26  geraint
 * got_comment: (char)c no longer compared to (int)EOF.
 *
 * Revision 1.1  2000/12/28 09:46:05  peterg
26
27
28
29
30
31
32


33
34
35
36
37
38
39
/*
 * Bracket.hh deals with nesting levels of parenthesis
 * just add Bracket pointer to string / stream
 */
#include "Bracket.hh"





/*
 * use lbrace, etc. in expressions to automate nesting calculations
 */
LeftBrace	*lbrace = new LeftBrace;
RightBrace	*rbrace = new RightBrace;








>
>







32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
 * Bracket.hh deals with nesting levels of parenthesis
 * just add Bracket pointer to string / stream
 */
#include "Bracket.hh"



using namespace std;

/*
 * use lbrace, etc. in expressions to automate nesting calculations
 */
LeftBrace	*lbrace = new LeftBrace;
RightBrace	*rbrace = new RightBrace;

Added mttroot/mtt/lib/cc/mtt_HJ_Solver.hh version [0452c911f4].











































































































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

#include "mtt_Solver.hh"

class HJ_Solver : public Solver {

  // http://www.netlib.org/opt/hooke.c
  // Hooke and Jeeves solution
  
public:
  
  HJ_Solver (sys_ae ae,
	     const int npar,
	     const int nu,
	     const int nx,
	     const int ny,
	     const int nyz)
    : Solver (ae,npar,nu,nx,ny,nyz)
  { static_ptr = this; VARS = nyz; };
  
  static double
  f (double tryUi[], int nyz);
  
  ~HJ_Solver (void) {};

protected:

  void
  Solve (void);

  double
  best_nearby (double    	delta[],
	       double   	point[],
	       double   	prevbest,
	       int      	nvars);
  
  int
  hooke (int	nvars,			  // MTTNYZ
	 double	startpt[],		  // user's initial guess
	 double	endpt[],		  // result
	 double	rho		= 0.05,	  // geometric shrink factor
	 double	epsilon		= 1e-3,	  // end value stepsize
	 int	itermax		= 5000);  // max # iterations 

private:

  int VARS;

public:

  static HJ_Solver *static_ptr;

};

Added mttroot/mtt/lib/cc/mtt_Hybrd_Solver.cc version [db6613b9c5].







































































































































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

#include "mtt_Hybrd_Solver.hh"

// http://www.netlib.org/minpack/hybrd.f
// used by Octave's fsolve
  
Hybrd_Solver *Hybrd_Solver::static_ptr;

ColumnVector
Hybrd_Solver::f_hybrd (const ColumnVector &tryUi)
{
  Hybrd_Solver::static_ptr->_yz = Hybrd_Solver::static_ptr->eval(tryUi);
  return Hybrd_Solver::static_ptr->_yz;
}

void
Hybrd_Solver::Solve (void)
{    
  int info;
  static int input_errors;
  static int user_errors;
  static int convergences;
  static int progress_errors;
  static int limit_errors;
  static int unknown_errors;
  
  NLFunc fcn(&Hybrd_Solver::f_hybrd);
  NLEqn	 eqn(Solver::_ui,fcn);
  eqn.set_tolerance(0.000001);
  Solver::_ui = eqn.solve(info);

  switch (info)
    {
    case 1:
      convergences++;
      break;
    case -2:
      input_errors++;
      break;
    case -1:
      user_errors++;
      break;
    case 3:
      progress_errors++;
      break;
    case 4:
      //      if (abs(eval(_ui).max()) > 1.0e-6)
      limit_errors++;
      //      else
      //	convergences++;
      break;
    default:
      unknown_errors++;
      break;
    }
  if (1 != info)
    {
      std::cerr << "input (" << input_errors << ") "
		<< "  user (" << user_errors << ") "
		<< "  converge (" << convergences << ") "
		<< "  progress (" << progress_errors << ") "
		<< "  limit (" << limit_errors << ")"
		<< "  unknown (" << unknown_errors << ")"
		<< "  (max error = " << std::abs(eval(_ui).max()) << ")" << std::endl;
    }
}

Added mttroot/mtt/lib/cc/mtt_Hybrd_Solver.hh version [a398dadfdb].













































































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

#include "mtt_Solver.hh"
#include <octave/NLEqn.h>

class Hybrd_Solver : public Solver {

  // http://www.netlib.org/minpack/hybrd.f
  // used by Octave's fsolve
  
public:

  Hybrd_Solver (sys_ae ae,
		const int npar,
		const int nu,
		const int nx,
		const int ny,
		const int nyz)
  : Solver (ae,npar,nu,nx,ny,nyz)
  {
    static_ptr = this;
  }

  static ColumnVector
  f_hybrd (const ColumnVector &tryUi);

  ~Hybrd_Solver (void) {};

protected:

  void
  Solve (void);

public:

  static Hybrd_Solver *static_ptr;

};

Added mttroot/mtt/lib/cc/mtt_Reduce_Solver.cc version [708e6aadb5].























>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11

#include "mtt_Reduce_Solver.hh"


void
Reduce_Solver::Solve (void)
{
  std::cerr << "Error:"
	    << " Symbolic solution of equations failed during model build" << std::endl
	    << "       Try using one of the other algebraic solution methods" << std::endl;
}

Added mttroot/mtt/lib/cc/mtt_Reduce_Solver.hh version [64e757e6a7].























































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

#include "mtt_Solver.hh"

class Reduce_Solver : public Solver {

  // Dummy class
  // This will not be used unless the Reduce solver has failed earlier
  // in the model build process

public:

  Reduce_Solver (sys_ae ae,
		 const int npar,
		 const int nu,
		 const int nx,
		 const int ny,
		 const int nyz)
    : Solver (ae,npar,nu,nx,ny,nyz)
  { ; };
	
  void
  Solve (void);

  ~Reduce_Solver (void) {};

};
   

Added mttroot/mtt/lib/cc/mtt_Solver.cc version [3335bb6d91].





















































































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

#include "mtt_Solver.hh"

Solver::Solver (sys_ae ae,
		const int npar,
		const int nu,
		const int nx,
		const int ny,
		const int nyz)
{
  _ae  = ae;
  _np  = npar; 
  _nu  = nu;
  _nx  = nx;
  _ny  = ny;
  _nyz = nyz;

  _uui = ColumnVector (_nu+_nyz);
};

ColumnVector
Solver::solve (const ColumnVector	&x,
	       const ColumnVector	&u,
	       const double		&t,
	       const ColumnVector	&par)
{
  _x = x;
  _uui.insert(u,0);
  _t = t;
  _par = par;
  _ui = ColumnVector(_nyz,1.0);
  Solve ();
  _uui.insert(_ui,_nu);
  return _uui;
}    

ColumnVector
Solver::eval (const ColumnVector &ui)
{
  _uui.insert(ui,_nu);
  return _ae (_x, _uui, _t, _par);
}

Added mttroot/mtt/lib/cc/mtt_Solver.hh version [12e52b9aa6].































































































































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

#ifndef MTT_SOLVER
#define MTT_SOLVER

#include <cmath>
#include <cstdlib>
#include <iostream>

#include <octave/oct.h>

class Solver {

protected:
  typedef ColumnVector (*sys_ae) // pointer to F${sys}_ae function
    (ColumnVector &,ColumnVector &,const double &t,ColumnVector &);

public:

  Solver (sys_ae ae,
	  const int npar,
	  const int nu,
	  const int nx,
	  const int ny,
	  const int nyz);

  ColumnVector
  solve (const ColumnVector	&x,
	 const ColumnVector	&u,
	 const double		&t,
	 const ColumnVector	&par);
  
  ColumnVector
  eval (const ColumnVector	&ui);

  virtual ~Solver (void) {};
  
protected:
  
  virtual void
  Solve (void) = 0;

protected:

  ColumnVector			_x;
  ColumnVector			_uui;
  double			_t;
  ColumnVector			_par;

  ColumnVector  		_ui;
  ColumnVector          	_yz;

  int   			_nu;
  int				_np;
  int				_nx;
  int				_ny;
  int				_nyz;
  
  sys_ae			_ae;

};

#endif // MTT_SOLVER


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