Mercurial > hg > octave-terminal
changeset 4231:1032fb9ec0d1
[project @ 2002-12-19 19:58:29 by jwe]
author | jwe |
---|---|
date | Thu, 19 Dec 2002 19:59:13 +0000 |
parents | 1feaee8df4ff |
children | b032ebd54586 |
files | liboctave/ChangeLog liboctave/LSODE-opts.in liboctave/LSODE.cc liboctave/LSODE.h liboctave/ODESSA-opts.in liboctave/ODESSA.cc liboctave/ODESSA.h src/ChangeLog src/load-save.cc |
diffstat | 9 files changed, 159 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,11 @@ +2002-12-19 John W. Eaton <jwe@bevo.che.wisc.edu> + + * ODESSA.cc (ODESSA::integrate): Handle maxord. + * ODESSA-opts.in: Likewise. + + * LSODE.cc (ODESSA::integrate): Handle maxord. + * LSODE-opts.in: Likewise. + 2002-12-18 John W. Eaton <jwe@bevo.che.wisc.edu> * ODESSA.cc (ODESSA::ODESSA): Initialize "initialized" data member
--- a/liboctave/LSODE-opts.in +++ b/liboctave/LSODE-opts.in @@ -46,6 +46,7 @@ OPTION NAME = "integration method" + DOC_ITEM A string specifing the method of integration to use to solve the ODE system. Valid values are @@ -59,7 +60,6 @@ function to compute the Jacobian is not supplied, @code{lsode} will compute a finite difference approximation of the Jacobian matrix. @end table - DOC_ITEM END_DOC_ITEM TYPE = "std::string" SET_ARG_TYPE = "const $TYPE&" @@ -87,6 +87,18 @@ END_OPTION OPTION + NAME = "maximum order" + DOC_ITEM +Restrict the maximum order of the solution method. If using the Adams +method, this option must be between 1 and 12. Otherwise, it must be +between 1 and 5, inclusive. + END_DOC_ITEM + TYPE = "int" + INIT_VALUE = "-1" + SET_EXPR = "val" +END_OPTION + +OPTION NAME = "maximum step size" DOC_ITEM Setting the maximum stepsize will avoid passing over very large
--- a/liboctave/LSODE.cc +++ b/liboctave/LSODE.cc @@ -123,8 +123,12 @@ nn = n; + int max_maxord = 0; + if (integration_method () == "stiff") { + max_maxord = 5; + if (jac) method_flag = 21; else @@ -135,12 +139,32 @@ } else { + max_maxord = 12; + method_flag = 10; liw = 20; lrw = 22 + 16 * n; } + maxord = maximum_order (); + + if (maxord >= 0) + { + if (maxord > 0 && maxord <= max_maxord) + { + iwork(4) = maxord; + iopt = 1; + } + else + { + (*current_liboctave_error_handler) + ("lsode: invalid value for maximum order"); + integration_error = true; + return retval; + } + } + iwork.resize (liw); for (int i = 4; i < 9; i++)
--- a/liboctave/LSODE.h +++ b/liboctave/LSODE.h @@ -57,6 +57,7 @@ bool initialized; int method_flag; + int maxord; int itask; int iopt; int itol;
--- a/liboctave/ODESSA-opts.in +++ b/liboctave/ODESSA-opts.in @@ -29,13 +29,6 @@ OPTION NAME = "relative tolerance" - TYPE = "double" - INIT_VALUE = "::sqrt (DBL_EPSILON)" - SET_EXPR = "(val > 0.0) ? val : ::sqrt (DBL_EPSILON)" -END_OPTION - -OPTION - NAME = "integration method" DOC_ITEM Relative tolerance parameter. Unlike the absolute tolerance, this parameter may only be a scalar. @@ -46,6 +39,28 @@ abs (local error in x(i)) <= rtol * abs (y(i)) + atol(i) @end example END_DOC_ITEM + TYPE = "double" + INIT_VALUE = "::sqrt (DBL_EPSILON)" + SET_EXPR = "(val > 0.0) ? val : ::sqrt (DBL_EPSILON)" +END_OPTION + +OPTION + NAME = "integration method" + DOC_ITEM +A string specifing the method of integration to use to solve the ODE +system. Valid values are + +@table @asis +@item \"adams\" +@itemx \"non-stiff\" +No Jacobian used (even if it is available). +@item \"bdf\" +@item \"stiff\" +Use stiff backward differentiation formula (BDF) method. If a +function to compute the Jacobian is not supplied, @code{lsode} will +compute a finite difference approximation of the Jacobian matrix. +@end table + END_DOC_ITEM TYPE = "std::string" SET_ARG_TYPE = "const $TYPE&" INIT_VALUE = {"stiff"} @@ -72,6 +87,18 @@ END_OPTION OPTION + NAME = "maximum order" + DOC_ITEM +Restrict the maximum order of the solution method. If using the Adams +method, this option must be between 1 and 12. Otherwise, it must be +between 1 and 5, inclusive. + END_DOC_ITEM + TYPE = "int" + INIT_VALUE = "-1" + SET_EXPR = "val" +END_OPTION + +OPTION NAME = "maximum step size" DOC_ITEM Setting the maximum stepsize will avoid passing over very large
--- a/liboctave/ODESSA.cc +++ b/liboctave/ODESSA.cc @@ -278,20 +278,24 @@ idf = 0; iopt(2) = idf; - - + if (restart) { restart = false; istate = 1; } - + + int max_maxord = 0; + if (integration_method () == "stiff") { if (user_jsub) method_flag = 21; else method_flag = 22; + + max_maxord = 5; + if (isopt) { liw = 21 + n + npar; @@ -305,6 +309,8 @@ } else { + max_maxord = 12; + if (isopt) { if (user_jsub) @@ -338,8 +344,27 @@ rwork.elem (i) = 0.0; } + maxord = maximum_order (); + + if (maxord >= 0) + { + if (maxord > 0 && maxord <= max_maxord) + { + iwork(4) = maxord; + iopt(0) = 1; + } + else + { + (*current_liboctave_error_handler) + ("odessa: invalid value for maximum order"); + integration_error = true; + return; + } + } + initialized = true; } + integration_error = false; // NOTE: this won't work if LSODE passes copies of the state vector.
--- a/liboctave/ODESSA.h +++ b/liboctave/ODESSA.h @@ -98,6 +98,7 @@ int liw; int lrw; int method_flag; + int maxord; Array<int> iwork; Array<double> rwork; int itask;
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +2002-12-19 John W. Eaton <jwe@bevo.che.wisc.edu> + + * load-save.cc (read_mat_ascii_data): Allow commas to separate values. + 2002-12-18 John W. Eaton <jwe@bevo.che.wisc.edu> * Makefile.in: No need to add $(LIBKPATHSEA) to LINK_DEPS, since
--- a/src/load-save.cc +++ b/src/load-save.cc @@ -1899,7 +1899,7 @@ file_line_number++; - size_t beg = buf.find_first_not_of (" \t"); + size_t beg = buf.find_first_not_of (", \t"); // If we see a CR as the last character in the buffer, we had a // CRLF pair as the line separator. Any other CR in the text @@ -1918,11 +1918,11 @@ { tmp_nc++; - size_t end = buf.find_first_of (" \t", beg); + size_t end = buf.find_first_of (", \t", beg); if (end != NPOS) { - beg = buf.find_first_not_of (" \t", end); + beg = buf.find_first_not_of (", \t", end); if (buf[beg] == '\r' && beg == buf.length () - 1) { @@ -1994,6 +1994,8 @@ int nr = 0; int nc = 0; + int total_count = 0; + get_lines_and_columns (is, filename, nr, nc); OCTAVE_QUIT; @@ -2010,6 +2012,7 @@ for (int i = 0; i < nr; i++) { std::string buf = get_mat_data_input_line (is); + std::cerr << buf<< std::endl; #ifdef HAVE_SSTREAM std::istringstream tmp_stream (buf); @@ -2023,8 +2026,30 @@ d = octave_read_double (tmp_stream); - if (tmp_stream) - tmp.elem (i, j) = d; + if (tmp_stream || tmp_stream.eof ()) + { + tmp.elem (i, j) = d; + total_count++; + + // Skip whitespace and commas. + char c; + while (1) + { + tmp_stream >> c; + + if (! tmp_stream) + break; + + if (! (c == ' ' || c == '\t' || c == ',')) + { + tmp_stream.putback (c); + break; + } + } + + if (tmp_stream.eof ()) + break; + } else { error ("load: failed to read matrix from file `%s'", @@ -2037,11 +2062,23 @@ } } - if (is) + if (is || is.eof ()) { - tc = tmp; - - retval = varname; + // XXX FIXME XXX -- not sure this is best, but it works. + + if (is.eof ()) + is.clear (); + + int expected = nr * nc; + + if (expected == total_count) + { + tc = tmp; + retval = varname; + } + else + error ("load: expected %d elements, found %d", + expected, total_count); } else error ("load: failed to read matrix from file `%s'",