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.77 2002/05/08 16:03:32 geraint
## Added mex support for ode2odes: mtt sys ode2odes mexglx.
## This mex stuff seems to require octave2.1-headers.
##
## Revision 1.76 2002/05/08 14:14:55 geraint
## Tidied up ode2odes code - reduced interweaving of STANDALONE/OCTAVEDLD sections
##
|
>
>
>
>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
#! /bin/sh
######################################
##### Model Transformation Tools #####
######################################
###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
## Revision 1.78 2002/05/11 01:14:17 geraint
## Fix for [ 553218 ] simpar.oct and simpar.m different.
## Translation added between ColumnVector in base .cc and Octave_map in .oct.
##
## Revision 1.77 2002/05/08 16:03:32 geraint
## Added mex support for ode2odes: mtt sys ode2odes mexglx.
## This mex stuff seems to require octave2.1-headers.
##
## Revision 1.76 2002/05/08 14:14:55 geraint
## Tidied up ode2odes code - reduced interweaving of STANDALONE/OCTAVEDLD sections
##
|
︙ | | | ︙ | |
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
|
esac
make_m()
{
#lang_header $1 ode2odes m 'x,par,simpar' '[Y,X,t]' > $filename
mtt_header ${sys} ode2odes m > $filename
cat <<EOF >> $filename
global MTT_data;
if nargin<3
simpar = ${sys}_simpar();
[simpar.dt] = mtt_simpar_update;
endif
if nargin<2
par = ${sys}_numpar();
|
|
|
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
|
esac
make_m()
{
#lang_header $1 ode2odes m 'x,par,simpar' '[Y,X,t]' > $filename
mtt_header ${sys} ode2odes m > $filename
cat <<EOF >> $filename
global MTT_data
if nargin<3
simpar = ${sys}_simpar();
[simpar.dt] = mtt_simpar_update;
endif
if nargin<2
par = ${sys}_numpar();
|
︙ | | | ︙ | |
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
|
endfor;
mttj = 0;
for it = 1:ilast #Integration loop
[u] = ${sys}_input(x,y,t,par); # Input
[y] = ${sys}_$odeo(x,u,t,par); # Output
if mttj==0
mtt_write(t,x,y,$Nx,$Ny); # Write it out
endif
EOF
if [ "$method" = "rk4" ]; then
cat << EOF >> $filename
[k1] = ddt * ${sys}_${ode}(x,u,t,par);
[k2] = ddt * ${sys}_${ode}(x+k1/2,u,t+ddt/2,par);
|
|
|
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
|
endfor;
mttj = 0;
for it = 1:ilast #Integration loop
[u] = ${sys}_input(x,y,t,par); # Input
[y] = ${sys}_$odeo(x,u,t,par); # Output
if mttj==0
mtt_write(t,x,y,$Nx,$Ny,simpar.first); # Write it out
endif
EOF
if [ "$method" = "rk4" ]; then
cat << EOF >> $filename
[k1] = ddt * ${sys}_${ode}(x,u,t,par);
[k2] = ddt * ${sys}_${ode}(x+k1/2,u,t+ddt/2,par);
|
︙ | | | ︙ | |
934
935
936
937
938
939
940
941
942
943
944
945
946
947
|
esac
cat <<EOF >> $filename
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;
|
>
|
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
|
esac
cat <<EOF >> $filename
inline void
mtt_write (const double &t,
ColumnVector &x,
ColumnVector &y,
const double &first,
const int &nrows,
const bool dump_data = false,
std::ostream &file = std::cout)
{
static Matrix data;
static int row;
|
︙ | | | ︙ | |
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
|
const int nx = x.length (), ny = y.length ();
register int col = 0;
if (0 == row)
data = Matrix (nrows, 1+ny+1+nx, 0.0);
data.elem (row, col) = t;
for (register int i = 0; i < ny; i++)
data.elem (row, ++col) = y.elem (i);
data.elem (row, ++col) = t;
for (register int i = 0; i < nx; i++)
data.elem (row, ++col) = x.elem (i);
row++;
static std::fstream fcputime ("MTT.cputime", std::ios::out | std::ios::trunc | std::ios::app);
static clock_t cputime0 = clock();
static clock_t cputime1 = cputime0;
clock_t cputime = clock();
fcputime << t << '\t'
<< static_cast <double> (cputime - cputime0) / CLOCKS_PER_SEC << '\t'
|
>
>
|
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
|
const int nx = x.length (), ny = y.length ();
register int col = 0;
if (0 == row)
data = Matrix (nrows, 1+ny+1+nx, 0.0);
if (t >= first) {
data.elem (row, col) = t;
for (register int i = 0; i < ny; i++)
data.elem (row, ++col) = y.elem (i);
data.elem (row, ++col) = t;
for (register int i = 0; i < nx; i++)
data.elem (row, ++col) = x.elem (i);
row++;
};
static std::fstream fcputime ("MTT.cputime", std::ios::out | std::ios::trunc | std::ios::app);
static clock_t cputime0 = clock();
static clock_t cputime1 = cputime0;
clock_t cputime = clock();
fcputime << t << '\t'
<< static_cast <double> (cputime - cputime0) / CLOCKS_PER_SEC << '\t'
|
︙ | | | ︙ | |
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
|
static ColumnVector AAx (MTTNX, 0.0);
static ColumnVector open_switches (MTTNX, 0.0);
register double t = 0.0;
const double ddt = dt / stepfactor;
const int ilast = static_cast<int> (round ((last - first) / ddt)) + 1;
const int nrows = static_cast<int> (round ((last - first) / dt)) + 1;
for (register int i = 0; i < MTTNY; i++)
{
y (i) = 0.0;
}
for (register int i = 0; i < MTTNX; i++)
{
x (i) = state0 (i);
}
for (register int j = 0, i = 1; i <= ilast; i++)
{
u = mtt_input (x, y, t, numpar);
y = mtt_output (x, u, t, numpar);
if (0 == j)
{
mtt_write (t, x, y, nrows);
}
EOF
case "$method" in
"rk4")
cat << EOF >> $filename
{
static ColumnVector
|
|
|
|
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
|
static ColumnVector AAx (MTTNX, 0.0);
static ColumnVector open_switches (MTTNX, 0.0);
register double t = 0.0;
const double ddt = dt / stepfactor;
const int ilast = static_cast<int> (round ( last / ddt)) + 1;
const int nrows = static_cast<int> (round ((last - first) / dt)) + 1;
for (register int i = 0; i < MTTNY; i++)
{
y (i) = 0.0;
}
for (register int i = 0; i < MTTNX; i++)
{
x (i) = state0 (i);
}
for (register int j = 0, i = 1; i <= ilast; i++)
{
u = mtt_input (x, y, t, numpar);
y = mtt_output (x, u, t, numpar);
if (0 == j)
{
mtt_write (t, x, y, first, nrows);
}
EOF
case "$method" in
"rk4")
cat << EOF >> $filename
{
static ColumnVector
|
︙ | | | ︙ | |