Overview
Comment: | Tidied up ode2odes code - reduced interweaving of STANDALONE/OCTAVEDLD sections |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | origin/master | trunk |
Files: | files | file ages | folders |
SHA3-256: |
80539fd341848ea61fe20705c02cd7af |
User & Date: | geraint@users.sourceforge.net on 2002-05-08 14:14:55 |
Other Links: | branch diff | manifest | tags |
Context
2002-05-08
| ||
14:51:04 | Moved matlab/octave data type conversion functions to a separate file. check-in: cdb81663cf user: geraint@users.sourceforge.net tags: origin/master, trunk | |
14:14:55 | Tidied up ode2odes code - reduced interweaving of STANDALONE/OCTAVEDLD sections check-in: 80539fd341 user: geraint@users.sourceforge.net tags: origin/master, trunk | |
11:39:36 | Added MTT_REP to PATH check-in: a3f28d5c6c user: gawthrop@users.sourceforge.net tags: origin/master, trunk | |
Changes
Modified mttroot/mtt/bin/trans/make_ode2odes from [1c09db5c78] to [1c01822bdf].
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.74 2002/05/01 17:30:56 geraint ## Improved pre-processor directives to better accommodate future alternatives (matlab) ## if necessary. ## ## Revision 1.73 2002/05/01 12:24:41 geraint ## Removed unnecessary inclusion of load-save.h. ## | > > > > | 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.75 2002/05/07 13:48:42 geraint ## Improved clarity of code generated for -cc and -oct (except ode2odes). ## Octave DEFUN_DLDs now call (rather than replace) their .cc equivalents. ## ## Revision 1.74 2002/05/01 17:30:56 geraint ## Improved pre-processor directives to better accommodate future alternatives (matlab) ## if necessary. ## ## Revision 1.73 2002/05/01 12:24:41 geraint ## Removed unnecessary inclusion of load-save.h. ## |
︙ | ︙ | |||
453 454 455 456 457 458 459 | #include "${sys}_def.h" #include "${sys}_sympar.h" #include "mtt_${algebraic_solver}.hh" #include <fstream> #if (CODEGENTARGET == STANDALONE) | < | 457 458 459 460 461 462 463 464 465 466 467 468 469 470 | #include "${sys}_def.h" #include "${sys}_sympar.h" #include "mtt_${algebraic_solver}.hh" #include <fstream> #if (CODEGENTARGET == STANDALONE) extern ColumnVector ${sys}_ae ( ColumnVector &x, ColumnVector &u, const double &t, ColumnVector &par); |
︙ | ︙ | |||
550 551 552 553 554 555 556 | const ColumnVector &open_switches); EOF ;; esac cat <<EOF >> $filename | < < | 553 554 555 556 557 558 559 560 561 562 563 564 565 566 | const ColumnVector &open_switches); EOF ;; esac cat <<EOF >> $filename #endif // (CODEGENTARGET == STANDALONE) ColumnVector mtt_ae (ColumnVector &x, ColumnVector &u, const double &t, ColumnVector &par) |
︙ | ︙ | |||
988 989 990 991 992 993 994 | set_global_value ("MTT_data", data); #endif // (CODEGENTARGET == STANDALONE) row = 0; fcputime.close(); } } | < < < < < < | < < < < < < < < < < < < < < < < < < < < < < < < < < < | < < < < < < < < < < < < < < < < < < | | | | | < < < | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 | set_global_value ("MTT_data", data); #endif // (CODEGENTARGET == STANDALONE) row = 0; fcputime.close(); } } void ${sys}_ode2odes (ColumnVector &state0, ColumnVector &numpar, ColumnVector &simpar) { static double first, dt, last, stepfactor; first = simpar (0); dt = simpar (1); last = simpar (2); stepfactor = simpar (3); static ColumnVector dx (MTTNX, 0.0); static ColumnVector x (MTTNX, 0.0); static ColumnVector u (MTTNU, 0.0); static ColumnVector y (MTTNY, 0.0); static Matrix AA (MTTNX, MTTNX, 0.0); static ColumnVector AAx (MTTNX, 0.0); |
︙ | ︙ | |||
1113 1114 1115 1116 1117 1118 1119 | for (register int i = 0; i < MTTNY; i++) { y (i) = 0.0; } for (register int i = 0; i < MTTNX; i++) { | | | | | 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 | 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") |
︙ | ︙ | |||
1144 1145 1146 1147 1148 1149 1150 | t2 = t + ddt; ColumnVector x1 (x), x2 (x), x3 (x); | | | | | | | | | | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | > > > | > > > > | > > > > > > > > > > > > > > > > > > > > > > | > | > | | 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 | t2 = t + ddt; ColumnVector x1 (x), x2 (x), x3 (x); k1 = ddt * mtt_rate (x , u, t , numpar); x1 += k1 * 0.5; k2 = ddt * mtt_rate (x1, u, t1, numpar); x2 += k2 * 0.5; k3 = ddt * mtt_rate (x2, u, t1, numpar); x3 += k3; k4 = ddt * mtt_rate (x3, u, t2, numpar); dx = (k1 + 2.0 * (k2 + k3) + k4) / (6.0 * ddt); } EOF ;; "dassl") ;; "implicit") cat << EOF >> $filename dx = mtt_rate (x, u, t, numpar); AA = mtt_smxa (x, u, ddt, numpar); AAx = mtt_smxax (x, u, ddt, numpar); EOF ;; "euler" | *) cat << EOF >> $filename dx = mtt_rate (x, u, t, numpar); EOF ;; esac ## Common stuff cat <<EOF >> $filename open_switches = mtt_logic (x, u, t, numpar); x = $algorithm; t += ddt; j++; j = (j == static_cast<int> (stepfactor)) ? 0 : j; } } #if (CODEGENTARGET == STANDALONE) #include <csignal> void set_signal_handlers (void); 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 (); static ColumnVector simpar (8), numpar (MTTNPAR), state0 (MTTNX); simpar = mtt_simpar (); numpar = mtt_numpar (); state0 = mtt_state (numpar); ${sys}_ode2odes (state0, numpar, simpar); return 0; } #elif (CODEGENTARGET == OCTAVEDLD) DEFUN_DLD (${sys}_ode2odes, args, , "Octave ode2odes representation of system with $method integration method\nUsage: mtt_data = ${sys}_ode2odes (state0, numpar, simpar)\n") { static octave_value_list retval; static ColumnVector state0 (MTTNX); static ColumnVector numpar (MTTNPAR); static ColumnVector simpar (8); int nargin = args.length (); switch (nargin) { case 3: simpar = args(2).${vector_value} (); numpar = args(1).${vector_value} (); state0 = args(0).${vector_value} (); break; case 2: simpar = mtt_simpar (); numpar = args(1).${vector_value} (); state0 = args(0).${vector_value} (); break; case 1: simpar = mtt_simpar (); numpar = mtt_numpar (); state0 = args(0).${vector_value} (); break; case 0: simpar = mtt_simpar (); numpar = mtt_numpar (); state0 = mtt_state (numpar); break; default: usage("${sys}_ode2odes (x par simpar)", nargin); error("aborting."); } ${sys}_ode2odes (state0, numpar, simpar); retval = octave_value (get_global_value ("MTT_data")); return (retval); } #endif // (CODEGENTARGET == STANDALONE) EOF } case ${lang} in m) make_m ;; cc) make_cc ;; *) echo Language ${lang} is not supported esac |