Index: mttroot/mtt/bin/trans/make_ode2odes ================================================================== --- mttroot/mtt/bin/trans/make_ode2odes +++ mttroot/mtt/bin/trans/make_ode2odes @@ -7,10 +7,13 @@ ############################################################### ## Version control history ############################################################### ## $Id$ ## $Log$ +## Revision 1.48 2001/02/11 07:08:59 geraint +## Static declarations of octave_value_lists: small .exe speed improvement +## ## Revision 1.47 2001/02/11 05:25:52 geraint ## Reduced number of matrix operations during .oct simulation data write ## ## Revision 1.46 2001/02/05 08:32:31 geraint ## typo @@ -270,253 +273,285 @@ feval_header=toplev.h fi cat < $filename #include - -#include #include #include #include #include + +#ifndef STANDALONE +#include +#endif #include "${sys}_def.h" #include "${sys}_sympar.h" #ifdef STANDALONE -#define DECLARE(name) extern octave_value_list F##name (const octave_value_list &, int); -DECLARE(mtt_euler) -DECLARE(mtt_implicit) -DECLARE(${sys}_${ode}) -DECLARE(${sys}_${odeo}) -DECLARE(${sys}_input) -DECLARE(${sys}_numpar) -DECLARE(${sys}_simpar) -DECLARE(${sys}_smxa) -DECLARE(${sys}_smxax) -DECLARE(${sys}_state) -DECLARE(${sys}_logic) -#endif // STANDALONE - -inline ColumnVector -mtt_${ode} (const ColumnVector &x, - const ColumnVector &u, - const double &t, - const ColumnVector &par) -{ - 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); -#ifdef STANDALONE - f = F${sys}_${ode} (args, 1); -#else - f = feval ("${sys}_${ode}", args, 1); -#endif - return f(0).${vector_value} (); -} - -inline ColumnVector -mtt_${odeo} (const ColumnVector &x, - const ColumnVector &u, - const double &t, - const ColumnVector &par) -{ - 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); -#ifdef STANDALONE - f = F${sys}_${odeo} (args, 1); -#else - f = feval ("${sys}_${odeo}", args, 1); -#endif - return f(0).${vector_value} (); -} - -inline ColumnVector -mtt_implicit (const ColumnVector &x, +extern ColumnVector Fmtt_euler ( ColumnVector &x, + const ColumnVector &dx, + const double &ddt, + const int &nx, + const ColumnVector &open_switches); + +extern ColumnVector Fmtt_implicit ( ColumnVector &x, + const ColumnVector &dx, + const Matrix &AA, + const ColumnVector &AAx, + const double &ddt, + const int &nx, + const ColumnVector &open_switches); + +extern ColumnVector F${sys}_${ode} ( ColumnVector &x, + ColumnVector &u, + const double &t, + ColumnVector &par); + +extern ColumnVector F${sys}_${odeo} ( ColumnVector &x, + ColumnVector &u, + const double &t, + ColumnVector &par); + +extern ColumnVector F${sys}_input ( ColumnVector &x, + ColumnVector &y, + const double &t, + ColumnVector &par); + +extern ColumnVector F${sys}_numpar ( void); + +extern Octave_map F${sys}_simpar ( void); + +extern Matrix F${sys}_smxa ( ColumnVector &x, + ColumnVector &u, + const double &t, + ColumnVector &par); + +extern ColumnVector F${sys}_smxax ( ColumnVector &x, + ColumnVector &u, + const double &t, + ColumnVector &par); + +extern ColumnVector F${sys}_state ( ColumnVector &x); + +extern ColumnVector F${sys}_logic ( ColumnVector &x, + ColumnVector &u, + const double &t, + ColumnVector &par); +#endif // STANDALONE + + +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 + 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}_${odeo}", args, 1); + return f(0).${vector_value} (); +#endif +} + +inline ColumnVector +mtt_implicit (ColumnVector &x, const ColumnVector &dx, const Matrix &AA, const ColumnVector &AAx, const double &ddt, const int &nx, const ColumnVector &open_switches) { +#ifdef STANDALONE + return Fmtt_implicit (x, dx, AA, AAx, ddt, nx, open_switches); +#else static octave_value_list args, f; args (0) = octave_value (x); args (1) = octave_value (dx); args (2) = octave_value (AA); args (3) = octave_value (AAx); args (4) = octave_value (ddt); args (5) = octave_value ((double)nx); args (6) = octave_value (open_switches); -#ifdef STANDALONE - f = Fmtt_implicit (args, 1); -#else f = feval ("mtt_implicit", args, 1); -#endif return f(0).${vector_value} (); +#endif } inline ColumnVector -mtt_euler (const ColumnVector &x, +mtt_euler (ColumnVector &x, const ColumnVector &dx, const double &ddt, const int &nx, const ColumnVector &open_switches) { +#ifdef STANDALONE + return Fmtt_euler (x, dx, ddt, nx, open_switches); +#else static octave_value_list args, f; args (0) = octave_value (x); args (1) = octave_value (dx); args (2) = octave_value (ddt); args (3) = octave_value ((double)nx); args (4) = octave_value (open_switches); -#ifdef STANDALONE - f = Fmtt_euler (args, 1); -#else f = feval ("mtt_euler", args, 1); -#endif return f(0).${vector_value} (); +#endif } inline ColumnVector -mtt_input (const ColumnVector &x, - const ColumnVector &y, +mtt_input (ColumnVector &x, + ColumnVector &y, const double &t, - const ColumnVector &par) + 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); -#ifdef STANDALONE - f = F${sys}_input (args, 1); -#else f = feval ("${sys}_input", args, 1); -#endif return f(0).${vector_value} (); +#endif } inline ColumnVector mtt_numpar (void) { - static octave_value_list args, f; #ifdef STANDALONE - f = F${sys}_numpar (args, 1); + return F${sys}_numpar (); #else + static octave_value_list args, f; f = feval ("${sys}_numpar", args, 1); -#endif return f(0).${vector_value} (); +#endif } inline Octave_map mtt_simpar (void) { +#ifdef STANDALONE + return F${sys}_simpar (); +#else static octave_value_list args; static Octave_map f; -#ifdef STANDALONE - f["first"] = F${sys}_simpar (args, 1)(0).map_value ()["first"]; - f["dt"] = F${sys}_simpar (args, 1)(0).map_value ()["dt"]; - f["last"] = F${sys}_simpar (args, 1)(0).map_value ()["last"]; - f["stepfactor"] = F${sys}_simpar (args, 1)(0).map_value ()["stepfactor"]; - f["wmin"] = F${sys}_simpar (args, 1)(0).map_value ()["wmin"]; - f["wmax"] = F${sys}_simpar (args, 1)(0).map_value ()["wmax"]; - f["wsteps"] = F${sys}_simpar (args, 1)(0).map_value ()["wsteps"]; - f["input"] = F${sys}_simpar (args, 1)(0).map_value ()["input"]; -#else f["first"] = feval ("${sys}_simpar", args, 1)(0).map_value ()["first"]; f["dt"] = feval ("${sys}_simpar", args, 1)(0).map_value ()["dt"]; f["last"] = feval ("${sys}_simpar", args, 1)(0).map_value ()["last"]; f["stepfactor"] = feval ("${sys}_simpar", args, 1)(0).map_value ()["stepfactor"]; f["wmin"] = feval ("${sys}_simpar", args, 1)(0).map_value ()["wmin"]; f["wmax"] = feval ("${sys}_simpar", args, 1)(0).map_value ()["wmax"]; f["wsteps"] = feval ("${sys}_simpar", args, 1)(0).map_value ()["wsteps"]; f["input"] = feval ("${sys}_simpar", args, 1)(0).map_value ()["input"]; -#endif - return (f); -} - -inline Matrix -mtt_smxa (const ColumnVector &x, - const ColumnVector &u, - const double &t, - const ColumnVector &par) -{ - 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); -#ifdef STANDALONE - f = F${sys}_smxa (args, 1); -#else - f = feval ("${sys}_smxa", args, 1); -#endif - return f(0).matrix_value (); -} - -inline ColumnVector -mtt_smxax (const ColumnVector &x, - const ColumnVector &u, - const double &t, - const ColumnVector &par) -{ - 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); -#ifdef STANDALONE - f = F${sys}_smxax (args, 1); -#else - f = feval ("${sys}_smxax", args, 1); -#endif - return f(0).${vector_value} (); -} - -inline ColumnVector -mtt_state (const ColumnVector &x) -{ - static octave_value_list args, f; - args (0) = octave_value (x); -#ifdef STANDALONE - f = F${sys}_state (args, 1); -#else - f = feval ("${sys}_state", args, 1); -#endif - return f(0).${vector_value} (); -} - -inline ColumnVector -mtt_logic (const ColumnVector &x, - const ColumnVector &u, - const double &t, - const ColumnVector &par) -{ - 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); - -#ifdef STANDALONE - f = F${sys}_logic (args, 1); -#else - f = feval ("${sys}_logic", args, 1); -#endif - return f(0).${vector_value} (); -} - - -inline void -mtt_write (const double &t, - const ColumnVector &x, - const ColumnVector &y, + return (f); +#endif +} + +inline Matrix +mtt_smxa (ColumnVector &x, + ColumnVector &u, + const double &t, + ColumnVector &par) +{ +#ifdef STANDALONE + return F${sys}_smxa (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}_smxa", args, 1); + return f(0).matrix_value (); +#endif +} + +inline ColumnVector +mtt_smxax (ColumnVector &x, + ColumnVector &u, + const double &t, + ColumnVector &par) +{ +#ifdef STANDALONE + return F${sys}_smxax (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}_smxax", args, 1); + return f(0).${vector_value} (); +#endif +} + +inline ColumnVector +mtt_state (ColumnVector &x) +{ +#ifdef STANDALONE + return F${sys}_state (x); +#else + static octave_value_list args, f; + args (0) = octave_value (x); + f = feval ("${sys}_state", args, 1); + return f(0).${vector_value} (); +#endif +} + +inline ColumnVector +mtt_logic (ColumnVector &x, + ColumnVector &u, + const double &t, + ColumnVector &par) +{ +#ifdef STANDALONE + return F${sys}_logic (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}_logic", args, 1); + return f(0).${vector_value} (); +#endif +} + + +inline void +mtt_write (const double &t, + ColumnVector &x, + ColumnVector &y, const int &nrows) { static Matrix data; static int row; const int nx = x.length (), ny = y.length (); @@ -541,28 +576,30 @@ set_global_value ("MTT_data", data); #endif } - +#ifdef STANDALONE +int main (void) { +#else DEFUN_DLD (${sys}_ode2odes, args, , "Octave ode2odes representation of system Usage: ${sys}_ode2odes (x, par, simpar) ") { static octave_value_list retval; - +#endif // STANDALONE static ColumnVector x; static ColumnVector par; static Octave_map simpar; static double first = 0.0, dt = 0.0, last = 0.0, stepfactor = 0.0; - +#ifndef STANDALONE int nargin = args.length (); switch (nargin) { case 3: first = args (2).map_value ()["first"].double_value (); @@ -587,22 +624,24 @@ stepfactor = mtt_simpar ()["stepfactor"].double_value (); par = mtt_numpar (); x = args (0).${vector_value} (); break; case 0: +#endif // ! STANDALONE first = mtt_simpar ()["first"].double_value (); dt = mtt_simpar ()["dt"].double_value (); last = mtt_simpar ()["last"].double_value (); stepfactor = mtt_simpar ()["stepfactor"].double_value (); par = mtt_numpar (); x = mtt_state (par); +#ifndef STANDALONE break; default: usage("${sys}_ode2odes (x par simpar)", nargin); error("aborting."); } - +#endif // STANDALONE static ColumnVector dx (MTTNX); static ColumnVector u (MTTNU); static ColumnVector y (MTTNY); static Matrix AA (MTTNX, MTTNX); @@ -642,24 +681,19 @@ t += ddt; j++; j = (j == static_cast (stepfactor)) ? 0 : j; } +#ifdef STANDALONE + return 0; +#else retval (0) = octave_value (y); retval (1) = octave_value (x); retval (2) = octave_value (t); return (retval); -} - -#ifdef STANDALONE -int main (void) -{ - octave_value_list args; - F${sys}_ode2odes (args, 3); - return 0; -} -#endif +#endif // STANDALONE +} EOF } case ${lang} in m) Index: mttroot/mtt/bin/trans/mtt_header ================================================================== --- mttroot/mtt/bin/trans/mtt_header +++ mttroot/mtt/bin/trans/mtt_header @@ -10,10 +10,13 @@ ############################################################### ## Version control history ############################################################### ## $Id$ ## $Log$ +## Revision 1.26 2001/02/05 08:50:58 geraint +## Octave 2.1.x compatability. +## ## Revision 1.28 2001/01/17 21:16:15 geraint ## uncomment parameter assignments in .m reps ## ## Revision 1.27 2001/01/14 23:51:26 geraint ## declare parameters as variables instead of constants @@ -557,38 +560,38 @@ write_DLD_header() { cat < #include #include #include - #include "useful-functions.hh" +#include "${system}_cr.h" #include "${system}_def.h" #include "${system}_sympar.h" -#include "${system}_cr.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 } map_DLD_inputs () { s=${1:-""} # comma separated input list if [ -z ${s:-""} ];then return; fi + printf "#ifndef STANDALONE\n" c=`get_field ${s} 0` # count of inputs i=0 printf " if (${c} != args.length ()) usage (\"${fun_name} expected ${c} argument(s): ${s}\");\n\n" while [ ${i} -lt ${c} ]; do j=${i} @@ -602,11 +605,11 @@ ColumnVector | Matrix | *) printf " ${arg_type}\t${w}\t= args(${j}).%s ();\n" ${vector_value} ;; esac done - printf "\n" + printf "#endif // ! STANDALONE\n\n" } declare_DLD_outputs () { @@ -627,22 +630,75 @@ s=${1:-""} # comma separated output list c=`get_field ${s} 0` # count of outputs i=0 cat < +#include +#include "useful-functions.hh" +#include "${system}_cr.h" +#include "${system}_def.h" +#include "${system}_sympar.h" + +${arg_type} F${system}_${rep} ( +EOF + if [ -z ${args:-""} ]; then + printf "\tvoid" + else + c=`get_field ${args:-""} 0` + i=0 + while [ ${i} -lt ${c} ]; do + i=`expr ${i} + 1` + if [ ${i} -lt ${c} ]; then + comma="," + else + comma="" + fi + w=`get_field ${args} ${i}` + get_arg_specific_stuff ${w} + printf "\t${arg_type}\t&${w}${comma}\n" + done + fi + cat < +#ifdef STANDALONE +ColumnVector Fmtt_euler ( ColumnVector &x, + const ColumnVector &dx, + const double &ddt, + const int &Nx, + const ColumnVector &openx) +{ +#else // !STANDALONE DEFUN_DLD (mtt_euler, args, , "euler integration method") { #ifdef OCTAVE_DEV - ColumnVector x = args(0).column_vector_value (); + static ColumnVector x = args(0).column_vector_value (); const ColumnVector dx = args(1).column_vector_value (); const double ddt = args(2).double_value (); const int Nx = static_cast (args(3).double_value ()); const ColumnVector openx = args(4).column_vector_value (); -#else - const ColumnVector x = args(0).vector_value (); +#else // !OCTAVE_DEV + static ColumnVector x = args(0).vector_value (); const ColumnVector dx = args(1).vector_value (); const double ddt = args(2).double_value (); const int Nx = static_cast (args(3).double_value ()); const ColumnVector openx = args(4).vector_value (); -#endif +#endif // OCTAVE_DEV +#endif // STANDALONE register int i, n; n = Nx; for (i = 0; i < Nx; i++) @@ -29,8 +38,11 @@ else { x (i) += dx (i) * ddt; } } - +#ifdef STANDALONE + return x; +#else // !STANDALONE return octave_value (x); +#endif // STANDALONE } Index: mttroot/mtt/lib/cc/mtt_implicit.cc ================================================================== --- mttroot/mtt/lib/cc/mtt_implicit.cc +++ mttroot/mtt/lib/cc/mtt_implicit.cc @@ -55,10 +55,20 @@ int rank; return a.lssolve (b, info, rank); } +#ifdef STANDALONE +ColumnVector Fmtt_implicit ( ColumnVector &x, + const ColumnVector &dx, + const Matrix &AA, + const ColumnVector &AAx, + const double &t, + const int &Nx, + const ColumnVector &openx) +{ +#else // !STANDALONE DEFUN_DLD (mtt_implicit, args, , "implicit integration method") { #ifdef OCTAVE_DEV static ColumnVector x = args(0).column_vector_value (); @@ -66,19 +76,20 @@ const Matrix AA = args(2).matrix_value (); const ColumnVector AAx = args(3).column_vector_value (); const double t = args(4).double_value (); const int Nx = (int) (args(5).double_value ()); const ColumnVector openx = args(6).column_vector_value (); -#else +#else // !OCTAVE_DEV static ColumnVector x = args(0).vector_value (); const ColumnVector dx = args(1).vector_value (); const Matrix AA = args(2).matrix_value (); const ColumnVector AAx = args(3).vector_value (); const double t = args(4).double_value (); const int Nx = (int) (args(5).double_value ()); const ColumnVector openx = args(6).vector_value (); -#endif +#endif // OCTAVE_DEV +#endif // STANDALONE register int i, n; register int col_old, col_new; register int row_old, row_new; @@ -131,9 +142,11 @@ { x (row_old) = 0.0; } } +#ifdef STANDALONE + return x; +#else // !STANDALONE return octave_value (x); +#endif // STANDALONE } - - Index: mttroot/mtt/lib/rep/standalone_rep.make ================================================================== --- mttroot/mtt/lib/rep/standalone_rep.make +++ mttroot/mtt/lib/rep/standalone_rep.make @@ -3,14 +3,14 @@ .POSIX: MTTFLAGS = -q -u -oct $(OPTS) # Adapt according to local set-up and mkoctfile -CC = g++ +CXX = g++ CXXFLAGS = $(DEBUG) $(OPTIM) $(DEFINES) $(ARCHFLAGS) -fno-rtti -fno-exceptions -fno-implicit-templates -DEBUG = -v -pg -g +DEBUG = -g OPTIM = -O3 PREFIX = /usr/local INCLUDES = -I$(PREFIX)/include/octave @@ -36,11 +36,11 @@ all: $(SYS)_standalone.$(LANG) $(SYS)_standalone.exe: $(SYS)_ode2odes.cc $(SYS)_def.h $(SYS)_sympar.h cp $(MTT_LIB)/cc/*.cc . - $(CC) *.cc -o $@ $(CXXFLAGS) $(INCLUDES) $(LIBOCTAVE) $(LIBKPATHSEA) $(LIBREADLINE) $(LIBBLAS) $(LIBF2C) $(LIBRARIES) + $(CXX) *.cc -o $@ $(CXXFLAGS) $(INCLUDES) $(LIBOCTAVE) $(LIBKPATHSEA) $(LIBREADLINE) $(LIBBLAS) $(LIBF2C) $(LIBRARIES) .PHONY: $(SYS)_standalone.clean $(SYS)_ode2odes.cc: mtt $(MTTFLAGS) $(SYS) ode2odes m